comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » for loop isn't working
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
for loop isn't working [message #71745] Thu, 15 July 2010 12:48
Snow53 is currently offline  Snow53
Messages: 32
Registered: July 2010
Member
Hi, you all are so wonderful to help me with my silly questions. Many
thanks!

I have this program that converts files to EASE grid within a folder
and outputs them as a different file. It works fine, but the problem I
have is that it doesn't loop through all the files in the folder. It
stops after the first. I can change the file output by changing i
(example: changing to i=2 gives me output for the second file in the
list resulting from the search function), but still I only get one
file output.

It must be something obvious, but I'm not seeing it.

Thanks again. :)


; This program reads in the fw parameter, applies the
; scale factor and returns the grid in EASE grid global format
; which is 1383x586 (columns x rows). Returned data type is float.

; Fill values for flagged pixels or no data value pixels
; are set to -9999.0


;define path
path = 'W:\AMSRE_results\global\2003\fw\test'
;find all fw files that are AM (decending) in the folder
file_array=file_search(path, '*.bin', count=num_file)
file=file_array

print, num_file
print, file



; loops through and extracts pixel data based on the above-determined
pixel location.
for i=1, num_file-1 do begin

file_name=file_basename(file[i], '.bin')
print, file_name


vector = intarr(209087)
openr, lun1, file[i], /get_lun
readu, lun1, vector
close, lun1
free_lun, lun1

vector = float(vector)

; Check for nodata values - only scale real data values
index = where(vector NE -9999.0, count)
if (count GT 0) then vector[index] = vector[index]*.0001


globland_cols = intarr(209087)
openr, lun2, 'w:\amsre_results\global\ancil\globland_c', /get_lun ;
Linux path
;openr, lun2, 'X:\AMSRE_results\tools\globland_c', /get_lun ; If using
local windows path, change this appropriately
readu, lun2, globland_cols
close, lun2,/file
free_lun, lun2

globland_rows = intarr(209087)
openr, lun3, 'w:\amsre_results\global\ancil\globland_r', /get_lun ;
Linux path
;openr, lun3, 'X:\AMSRE_results\tools\globland_r', /get_lun ; If
using local windows path, change this appropriately
readu, lun3, globland_rows
close, lun3, /file
grid = fltarr(1383,586)
grid(*,*) = -9999.0

for i=0l, 209087-1 do begin

grid[globland_cols[i]-1,globland_rows[i]-1] = vector[i]
endfor


out_path ='X:\AMSRE\Lena\2003\'
out_name = file_name + '_ease_grid.bin'
out_file=out_path+out_name
openw, out_lun, out_file, /get_lun
writeu, out_lun, grid
close, out_lun
free_lun, out_lun

return


endfor

end
[Message index]
 
Read Message
Previous Topic: read XML with IDL
Next Topic: Re: for loop isn't working

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:38:30 PDT 2025

Total time taken to generate the page: 0.00374 seconds