Re: create a loop on IDL [message #93342 is a reply to message #93336] |
Fri, 17 June 2016 23:01  |
andrewcool777
Messages: 27 Registered: November 2012
|
Junior Member |
|
|
On Friday, 17 June 2016 05:07:08 UTC+9:30, Shereen Nadoum wrote:
> Thank you very much. Your code makes more sense than mine.
>
> I am trying to write a code to read all 534 bsq files and extract data for specific pixel values.
> I am creating a time series for soil data for 12 years. I am very new to IDL.. been unsuccessful in writing this code.
> 1) read the bsq data
> 2)write the data in an array
> 3) extract the data specific pixel values.
>
> I don't really know if the code I have is complete yet.
Shereen,
Try this.
Regards,
Andrew
pro soil_timeseries, dir, soil, outarr
files = file_search(dir, '*.bsq', count = nfiles)
help,files
If files[0] EQ '' then begin
message,'No files found'
Endif
; file= 'F:\soil\MCD43A4.2000.049_soil.bsq\'
; how many files were found?
nfiles = N_Elements(files)
; as you have 534 files, and are reading just 1 element from the data in each file, then create an
; array that is simply 534 elements long
outarr = FLTARR(nfiles)
data=intarr(2400,2400,/nozero)
for i = 0, nfiles - 1 do begin
print, i, ' ', files(i)
openr, read_lun, files(i), /get_lun
READF,read_lun, data
; this is reading just 1 element out of a 2D array)
; so copy single element into "ith" position of output array
outarr[i] = data[28,1759]*0.0001
free_lun,read_lun
endfor
end
|
|
|