I see what you're trying to do, but there's definitely an easier way
to go about it. You're attempting to create a binary ENVI Spectral
Library file that contains the spectral response curves for MASTER's
first 25 channels (VNIR and SWIR) from the individual SRF ASCII
files. Because of how ENVI Spectral Library files are constructed, an
entry for a particular channel must contain response values for the
entire wavelength range of the 25 channels, combined--even if the
recorded values for a channel (in a single SRF file) fall over a much
smaller range. As a result, you have to provide "filler" values of 0
to compensate. Because each SRF file covers a different range and
contains a variable number of entries, getting everything into one
ENVI Spectral Library file is a bit challenging. The program below
will build the library for you, as long as all of the individual SRF
files and the associated header file (*.ph) are in the same folder on
your computer. It makes liberal use of array and structure
concatenation, subscripting, and the WHERE function to build the
library. SORT is used in a few places to ensure that all response
values end up in the right locations. The program is provided as is.
pro create_master_spectral_reponse_sli
compile_opt idl2
header_file = dialog_pickfile(title='Select Spectral Response Header
File', filter='*.ph', $
get_path=header_path)
if header_file eq '' then return
out_name = dialog_pickfile(title='Select Output Library Name',
path=header_path)
if out_name eq '' then return
spec_search = file_search(header_path, '*.c*', count=spec_count)
if spec_count ne 50 then begin
ok = dialog_message('You must have all 50 MASTER spectral response
curve files to proceed', $
/error)
return
endif
;Sort response files from lowest to highest band
spec_sort = sort(spec_search)
spec_search = spec_search[spec_sort]
envi_read_cols, header_file, parameters
band_nums = lindgen(25)+1
band_names = replicate('Band',25) + ' ' + strtrim(string(band_nums),
2)
;Read in spectral response files and create
;structure array to hold all returned info
spec_struct = {sensor_type:'MASTER'}
wl_array = dblarr(1)
for i=0,24 do begin
envi_read_cols, spec_search[i], spec_data
spec_struct = create_struct(spec_struct, band_names[i], spec_data)
wl_array = [wl_array, reform(transpose(spec_data[0,*]))]
endfor
wl_array = wl_array[1:*]
wl_array = wl_array[sort(wl_array)]
num_measure = n_elements(wl_array)
openw, lun, out_name, /get_lun
;Write out band-specific spectral response library entries
for j=1,25 do begin
cur_wl = (spec_struct.(j))[0,*]
sort_cur = sort(cur_wl)
num_cur = n_elements(cur_wl)
where_cur = where(wl_array eq cur_wl[sort_cur[0]], where_count)
response = reform((spec_struct.(j))[1,sort_cur])
response_array = dblarr(num_measure)
response_array[where_cur[0]:(where_cur[0]+num_cur-1)] = response
writeu, lun, response_array
endfor
free_lun, lun
file_type=envi_file_type('ENVI Spectral Library')
envi_setup_head, fname=out_name, data_type=5, file_type=file_type, $
interleave=0, nb=1, ns=num_measure, $
nl=25, wl=wl_array, /write, /open, r_fid=lib_fid, $
wavelength_unit=0, spec_names=band_names
end
On Nov 20, 12:19 pm, Marsh...@gmu.edu wrote:
> Hi Guys:
>
> I tried to make ASCII file for Spectral Response Curves obtained atftp://asapdata.arc.nasa.gov/MASTER/srf/May_03/however, it is not
> working. Can someone give suggestions how to build ASCII file for
> Spectral Response Curves.
>
> Best Regards,
>
> Arshad
|