On Aug 21, 7:13 pm, "anniebry...@gmail.com" <anniebry...@gmail.com>
wrote:
> The question is:
>
> 1. How do I give each of the files a unique name when I use the
> writeu (or if there is a better command), i.e. something similar to
> their initial MODIS input name.
You need to decide some rule to generate a new name from the input
file name. From what you wrote, I am guessing it may be to make a file
with the same name, in another directory.
> 2. Using openr and a * after the initial few letters, is it finding
> each individual file in the folder?
Open only opens one file, which gets associated to a unit number. I do
not know what it will do if the name has a * in it, it probably will
not work.
I suggest putting the code to do the reorder of a file in a separate
routine:
pro MOD09GA_file_bandreorder,filein,fileout
;reads a (ns,nl,nb) float array from filein, and writes it reordered
in fileout
;contants
ns=4578
nl=2367
nb=7
b_order[2,3,0,1,4,5,6] ; band order should be (3,4,1,2,5,6,7)
;read the input file
image = fltarr(ns,nl,nb)
openr,unit,filein,/get_lun
readu,unit,image
free_lun,unit
;make the reordered array
morder=image[*,*,b_order]
;write the reodered array
print, "Now processing:" ,fileout
openw,unit,fileout,/get_lun
writeu,unit,morder
free_lun,unit
print, 'Done!'
end
Then a separate program makes a list of files to read, and from it
makes a list of files to write, and calls the one above:
pro MOD09GA_bandreorder
;make a list of files to read
filesin=file_search('/users/u0609216/documents/modis/2009/Ge o_2009/
MOD09GA.*')
;make the names of the output files
filesout='/users/u0609216/documents/modis/2009/
reorder_2009/'+file_basename(filesin)
;reorder each file
for i=0,n_elements(filesin)-1 do MOD09GA_file_bandreorder,filesin
[i],filesout[i]
end
|