X
7256

How to call ENVI_LAYER_STACKING_DOIT with multiple files and bands in batch mode

pro envi_layer_stacking_doit_multi_file
compile_opt idl2

;first restore all the base save files and initialize batch.
envi, /restore_base_save_files
envi_batch_init, log_file='batch.txt'

;go to directory with several files
;this example stacks a set of .TIF files
cd, 'mydir'
files = file_search('*.tif', count=count, /fold_case)

;open and gather file information in arrays
in_fid=lonarr(count)
in_nb=lonarr(count)
in_dims=lonarr(5, count)
in_dt=lonarr(count)

for i=0L, count-1 do begin
envi_open_file, files[i], r_fid=r_fid
if (r_fid eq -1) then begin
envi_batch_exit
return
endif

envi_file_query, r_fid, ns=ns, nl=nl, nb=nb, dims=dims, data_type=dt
in_fid[i]=r_fid
in_nb[i]=nb
in_dims[*,i]=dims
in_dt[i]=dt
endfor

;set up output fid, pos, and dims arrays
out_fid = replicate(in_fid[0], in_nb[0])
for i=1, count-1 do out_fid = [out_fid, replicate(in_fid[i], in_nb[i])]

out_pos = lindgen(in_nb[0])
for i = 1, count-1 do out_pos = [out_pos, lindgen(in_nb[i])]

rep_dims = (intarr(in_nb[0])+1) # in_dims[*,0]
for i = 1, count-1 do $
rep_dims = [rep_dims, (intarr(in_nb[i]) + 1) # in_dims[*,i]]
out_dims = transpose(rep_dims)

;set the output projection and pixel size from the first file.
;save the result to disk and use max data type
out_proj = envi_get_projection(fid=in_fid[0], pixel_size=out_ps)
out_dt = max(in_dt)
out_name = 'stacked_layers.dat'

;call the layer stacking routine. Do not set the exclusive keyword allow for an
;inclusive result. Use nearest neighbor for the interpolation method.

envi_doit, 'envi_layer_stacking_doit', fid=out_fid, pos=out_pos, dims=out_dims, $
out_dt=out_dt, out_name=out_name, interp=0, out_ps=out_ps, $
out_proj=out_proj, r_fid=r_fid

;exit ENVI
envi_batch_exit

end

Review on 12/31/2013 MM