Hi all,
I am running an IDL script with ENVI routines to automatically read in
daily (Day of year) MODIS tiles, import layers and mosaic them
together. The script works fine for about 5-6 iterations but at the
7th or 8th iteration, the MOSAICKING part of the script stops
abruptly. I thought it was a memory related issue, or something to do
with the number of FIDs that are open. So, i used the envi_file_mng
function to make sure i don't use FIDs when not required. But it
doesn't seem to have solved the problem. **If i close the program and
open it, the script works for about 5-6 iterations again. So, the
problem doesn't seem to be with the files but maybe something to do
with memory or some other issue i'm not able to figure out.
In brief, I am importing 6 MODIS tiles using the convert_MODIS_data
procedure, and then using georeference-based mosaic.
In the following code, the FOR loop at the beginning sets the
iteration starting from day of year (DOY) 088 and is supposed to end
at 097. However, the script (the mosaic section) stops running at 095.
The imports run without a problem. If i close the program and reset
the start of FOR loop to 095 and end to 105, it runs till about 101
and stops. Initially i thought it was a systematic error with 6 files
running each time but there are cases when 7 files run. So, it is
quite random.
Here's my code. I have put in some comments which i hope will help
locate where the problem is occuring.
pro A_Z
compile_opt idl2
ENVI, /RESTORE_BASE_SAVE_FILES
ENVI_BATCH_INIT
startDOY=088
finishDOY=097
for date=startDOY,finishDOY do begin
range=finishDOY-date
;print,'Processing MODIS images of DOY',date
input_path='I:\MODIS_snow\2008_snowhdfs\'
dir=input_path
cd,dir
files=FILE_SEARCH('MOD10A1*'+strtrim(string(date,format='(I0 3)'),
2)+'.h*.hdf',count=num_inputfiles)
;print,numfiles
output_path = 'I:\ASR_outputs\'
;MODIS grid file
format='MOD10A1.A2005145.h10v02.005.2008031132120.hdf'
;START IMPORTING MODIS LAYERS
for i=0,num_inputfiles-1 do begin
grid_file=files[i]
output_rootname = 'snowinputs_'+strtrim((strmid(grid_file,
9,7)+'_'+strmid(grid_file,17,6)),2)+'_'
year=strmid(grid_file,9,4)
grid_name = 'MOD_Grid_Snow_500m'
sd_names = ['Fractional_Snow_Cover','Snow_Albedo_Daily_Tile']
out_method = 0
convert_modis_data,in_file=grid_file, $
out_path=output_path, out_root=output_rootname, $
/higher_product, /grid, gd_name=grid_name, sd_names=sd_names, $
out_method=out_method,background=255, fill_replace_value=255
endfor
cd,output_path
inputs=file_search('snowinputs*'+strtrim(string(date,format= '(I03)'),
2)+'*.img',count=inputfiles)
fids=lindgen(inputfiles)
print,'inputfiles',inputfiles
for i=0,inputfiles-1 do begin
envi_open_file,inputs[i],r_fid=afile
fids[i]=afile
endfor
numfiles=n_elements(fids)
;***********************THE code stops at this
point**************************************
if numfiles eq 6 then begin
;*******START MOSAIC
pos=[[0,1],[0,1],[0,1],[0,1],[0,1],[0,1]]
out_ps=[[463.31271653,463.31271653]]
use_see_through = [[1L],[1],[1],[1],[1],[1]]
see_through_val = [[0L],[0],[0],[0],[0],[0]]
bandnames=['Fractional snow cover','Snow albedo']
;out_name=input_path+'mosaicking'+strtrim(date,2)+'.dat'
georef_mosaic_setup, fids=fids, out_ps=out_ps, dims=dims, xsize=xsize,
ysize=ysize,$
x0=x0, y0=y0, map_info=map_info
envi_doit,'mosaic_doit',fid=fids,pos=pos,dims=dims,/
in_memory,x0=x0,y0=y0,background=0,out_dt=2,map_info=map_inf o,/georef,
$
xsize=xsize,ysize=ysize,pixel_size=out_ps,see_through_val=se e_through_val,use_see_through=use_see_through,out_bname=band names,r_fid=mosaic
;******REMOVE FIDS AND DELETE INPUTS
for i=0,numfiles-1 do begin
envi_file_mng,id=fids[i],/remove,/delete
endfor
endif
print,'processing is done'
end
Please let me know if you need more information.
Thanks,
Raghu
|