PRO read_airmisr ;================================================================================= ; Program: read_airmisr.pro ; ; Version: 2.0 ; ; Date: July 8, 2002 ; ; Function: Open and read AIRMISR L1B2 GP (Georectified Radiance ; Product) HDF-EOS data files. ; ; Write file information and the values of selected parameter(s) ; to an output file. The output file is created in the ; current default directory with the same name as the input ; file but with the '.hdf' suffix replaced with '_output'. ; ; Compute radiance for a given band from the scaled radiance ; and the scale factor for that band. ; ; A call to the IDL dialog_pickfile functionis used to create ; a dialog box for filename choice. This routine assumes those ; files are in the current directory. The 'FILTER' parameter may ; need to be modified to correspond to the location of the input ; files. ; ; ; *** Please see the README file for further details *** ; ; Parameters: none ; ; Algorithm: Radiances are computed by multiplying the integer scaled ; value by the appropriate scale factor for the band. ; ; Invocation: idl> .compile read_airmisr ; idl> read_airmisr ; ; External Routines: none ; ; Language/Compiler Version: Tested with IDL 5.3-5.5 ; ; Point of Contact: Comments or questions should be directed to: ; ; Langley Atmospheric Sciences Data Center ; NASA Langley Research Center ; Mail Code 157D, 2 South Wright Street ; Hampton, Virginia 23681-2199 ; U.S.A. ; ; E-mail: larc@eos.nasa.gov ; Phone: (757)864-8656 ; FAX: (757)864-8807 ; ; ;================================================================================= ; --- banner print, '*****************************************************************' print, '* *' print, '* *' print, '* read_airmisr.pro *' print, '* *' print, '* Version: 2.0 *' print, '* *' print, '* Date: July 8, 2002 *' print, '* *' print, '* Contact: Langley Atmospheric Sciences Data Center *' print, '* NASA Langley Research Center *' print, '* Mail Stop 157D *' print, '* 2 South Wright Street *' print, '* Hampton, Virginia 23681-2199 *' print, '* U.S.A. *' print, '* *' print, '* E-mail: larc@eos.nasa.gov *' print, '* Phone: (757)864-8656 *' print, '* FAX: (757)864-8807 *' print, '* *' print, '*****************************************************************' ; --- dialog box containing filenames. ; --- The filter parameter may be added to suit your system. ; --- Change the filter= '/path/' to the correct path to find your data files ; or add a PATH keyword value. filename = dialog_pickfile(/read,filter= '*hdf',title='Select AirMISR file') print,'Input Filename ',filename print," " ; extract file name from path, without the '.hdf' suffix for use in ; output file name fname = STRMID(filename, strlen(filename)-38, 34) ; --- open output file openw,out_lun,fname+'_output',/get_lun ; --- CHECK FOR VALID HDF FILE if (HDF_ISHDF(filename) ne 1) then begin print," " print,"Error, not an HDF file: ",filename print," " goto, exit endif ; --- OPEN HDF FILE fileid = HDF_OPEN(filename,/read) if (fileid lt 0) then begin print," " print,"Error: problem opening HDF file ',filename print," " goto, exit endif ; --- Select parameters to output to file print, " " print, " CHOOSE THE PARAMETERS TO BE WRITTEN TO THE OUTPUT FILE" make_list,filename,var_list vsize = size(var_list) if (vsize[0] eq 0) then begin print,"Error: does not appear to be an AirMISR file ",filename HDF_CLOSE,fileid goto, exit endif selectTool,var_list,selected_vars print_var=var_list[selected_vars] print, " " print,'The following ',strtrim(string(n_elements(selected_vars)),2),' parameters were chosen:' for i=0,n_elements(selected_vars)-1 do print,var_list[selected_vars[i]] print, " " print, " " print, " **************** Begin reading data *********************" GET_FILE_INFO,fileid,image_time,grid_info,RAD_SCALES WRITE_OUTPUT,out_lun,/INIT,FILENAME=filename,IMAGE_TIME=image_time,GRID_INFO=grid_info GET_METADATA,fileid,print_var,selected_vars,out_lun,filename GET_GRID_FIELDS,filename,out_lun,print_var,selected_vars,RAD_SCALES ; --- CLOSE OUTPUT FILE close,out_lun free_lun,out_lun print," " print," **************** THE PROGRAM HAS RUN TO COMPLETION!! *********************" print," " exit: END PRO GET_METADATA,fileid,print_var,selected_vars,out_lun,filename ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Function: This routine reads the selected grid attribues (or file ; attribute, in the case of structural metadata) and writes ; the data values to the output file ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; first_met = 1 fid = EOS_GD_OPEN (filename,/READ) gid = EOS_GD_ATTACH(fid,'AirMisr') num_fields = EOS_GD_INQFIELDS(gid,field_list,rank,num_type) sel_attr = where(selected_vars ge num_fields,attr_count) ; indices into print_var for attributes, ; since fields are first in the list for i=0,attr_count-1 do begin vdref = 1 status = 0 attr_name = print_var[sel_attr[i]] if (attr_name eq 'HDF-EOS Structural Metadata') then begin ; the quickest way to get the structural metadata is from the underlying HDF vdata ; used to store this file attribute vdref = HDF_VD_FIND(fileid,'StructMetadata.0') if (vdref ne 0) then begin handle = HDF_VD_ATTACH(fileid,vdref) num_rec = HDF_VD_READ(handle,data) data = STRING(data) endif endif else begin ; get the grid attribute data status = EOS_GD_ATTRINFO(gid, attr_name, attr_type, attr_count) status = EOS_GD_READATTR(gid,attr_name,data) case attr_type of 4 : begin ; no modification needed for string data end 6 : begin data = data[0:(attr_count/8)-1] end else : begin ; no other data types currently used for attributes end endcase endelse if ((vdref eq 0) or (status lt 0)) then begin print,'Problem getting data value(s) for ',attr_name endif else begin print,'WRITING TO OUTPUT ---> ',attr_name WRITE_OUTPUT,out_lun,/METADATA,FIRST_MET=first_met,NAME=attr_name,DATA=data first_met = 0 endelse endfor status = EOS_GD_DETACH(gid) status = EOS_GD_CLOSE(fid) END PRO GET_GRID_FIELDS,filename,out_lun,print_var,selected_vars,RAD_SCALES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Function: This routine reads the SDSdata fields for the ; AIRMISR data set and returns the selected parameters. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; first_gf = 1 scale = 0 fid = EOS_GD_OPEN (filename,/READ) gid = EOS_GD_ATTACH(fid,'AirMisr') num_fields = EOS_GD_INQFIELDS(gid,field_list,rank,num_type) sel_fields = where(selected_vars lt num_fields,field_count) ; indices into print_var for fields, ; since fields are first in the list for i=0,field_count -1 do begin field_name = print_var[sel_fields[i]] status = EOS_GD_READFIELD(gid,field_name,data) if (status lt 0) then begin print,'Problem getting data values for field ',field_name endif else begin status = EOS_GD_GETFILLVALUE(gid,field_name,data_fill) if (status lt 0) then begin print,'Problem getting fill value for field ',field_name data_fill = 'Undefined' ; should never need this since AirMISR fields all have ; fill values specified endif ; scale radiance data case strtrim(field_name,2) of 'Terrain Blue': begin data = data * ((data ne data_fill) * RAD_SCALES[0] + (data eq data_fill)) scale = RAD_SCALES[0] end 'Terrain Green': begin data = data * ((data ne data_fill) * RAD_SCALES[1] + (data eq data_fill)) scale = RAD_SCALES[1] end 'Terrain Red': begin data = data * ((data ne data_fill) * RAD_SCALES[2] + (data eq data_fill)) scale = RAD_SCALES[2] end 'Terrain Infrared': begin data = data * ((data ne data_fill) * RAD_SCALES[3] + (data eq data_fill)) scale = RAD_SCALES[3] end 'Ellipsoid Blue': begin data = data * ((data ne data_fill) * RAD_SCALES[0] + (data eq data_fill)) scale = RAD_SCALES[0] end 'Ellipsoid Green': begin data = data * ((data ne data_fill) * RAD_SCALES[1] + (data eq data_fill)) scale = RAD_SCALES[1] end 'Ellipsoid Red': begin data = data * ((data ne data_fill) * RAD_SCALES[2] + (data eq data_fill)) scale = RAD_SCALES[2] end 'Ellipsoid Infrared': begin data = data * ((data ne data_fill) * RAD_SCALES[3] + (data eq data_fill)) scale = RAD_SCALES[3] end else: begin ; no adjustment needed for other variables end endcase print,'WRITING TO OUTPUT ---> ',field_name init = 0 WRITE_OUTPUT,out_lun,/GRIDFIELD,FIRST_GF=first_gf,NAME=field_name,DATA=data,FILL=data_fill,SCALE=scale first_gf = 0 endelse endfor ; iteration through selected fieldds status = EOS_GD_DETACH(gid) status = EOS_GD_CLOSE(fid) END PRO make_list,filename,var_list ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Function: This routine builds the list of AIRMISR grid fields and grid ; attributes for the selection list and adds structural ; metadata to the list ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; var_list = '' fid = EOS_GD_OPEN (filename,/READ) gid = EOS_GD_ATTACH(fid,'AirMisr') if (gid lt 0) then begin print,"Can't find AirMisr grid in file ",filename return end num_fields = EOS_GD_INQFIELDS(gid,field_list,rank,num_type) num_attrs = EOS_GD_INQATTRS(gid,attr_list) fields = strsplit(field_list,',',/EXTRACT) attrs = strsplit(attr_list,',',/EXTRACT) var_list = strarr(num_fields+num_attrs+1) for i=0,num_fields-1 do var_list[i] = fields[i] for i=0,num_attrs-1 do var_list[num_fields+i] = attrs[i] var_list[num_fields+num_attrs] = 'HDF-EOS Structural Metadata' status = EOS_GD_DETACH(gid) status = EOS_GD_CLOSE(fid) return END PRO WRITE_OUTPUT,out_lun, $ INIT=init,FILENAME=filename,IMAGE_TIME=image_time,GRID_INFO=grid_info,$ METADATA=metadata,FIRST_MET=first_met,NAME=name,DATA=data, $ GRIDFIELD=gridfield,FIRST_GF=first_gf,FILL=data_fill,SCALE=scale ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Function: This routine writes data selected from the ; AIRMISR file to the output file. ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; if KEYWORD_SET(INIT) then begin printf,out_lun,' ' printf,out_lun,'File: ',filename printf,out_lun,' ' printf,out_lun,'Image Start Time = ',image_time[0] printf,out_lun,'Image End Time = ',image_time[1] printf,out_lun,' ' printf,out_lun,grid_info printf,out_lun,' ' endif if KEYWORD_SET(METADATA) then begin if KEYWORD_SET(FIRST_MET) then begin printf,out_lun,' VALUES for Metadata' printf,out_lun,'================================================================================' endif printf,out_lun,'Name = ',name printf,out_lun,' ' printf,out_lun,'Data =' printf,out_lun,data printf,out_lun,'--------------------------------------------------------------------------------' endif if KEYWORD_SET(GRIDFIELD) then begin if KEYWORD_SET(FIRST_GF) then begin printf,out_lun,' ' printf,out_lun,' VALUES for Grid Fields' printf,out_lun,'================================================================================' endif printf,out_lun,'Name = ',name if (scale ne 0) then printf,out_lun,'Scale Value = ',scale printf,out_lun,'Fill Value = ',data_fill printf,out_lun,' ' printf,out_lun,'Data =' printf,out_lun,data printf,out_lun,'--------------------------------------------------------------------------------' printf,out_lun,' ' endif return END PRO GET_FILE_INFO,fileid,image_time,grid_info,RAD_SCALES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Function: This routine obtains the image time, grid info, and radiance ; scale factors from the AirMISR file ; Note that the vdatas are the underlying structures used to store ; the grid and file attributes ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; image_time = strarr(2) vdref = HDF_VD_FIND(fileid,'Minimum_image_time') handle = HDF_VD_ATTACH(fileid,vdref) num_rec = HDF_VD_READ(handle,data) image_time[0] = STRING(data) vdref = HDF_VD_FIND(fileid,'Maximum_image_time') handle = HDF_VD_ATTACH(fileid,vdref) num_rec = HDF_VD_READ(handle,data) image_time[1] = STRING(data) vdref = HDF_VD_FIND(fileid,'StructMetadata.0') handle = HDF_VD_ATTACH(fileid,vdref) num_rec = HDF_VD_READ(handle,data) structmeta = STRING(data) grid_info = STRMID(structmeta, 82, 196) vdref = HDF_VD_FIND(fileid,'Rad_scale_factor (1=Blue;2=Green;3=Red;4=Nir)') handle = HDF_VD_ATTACH(fileid,vdref) num_rec = HDF_VD_READ(handle,data) RAD_SCALES = DOUBLE(data) END ;------------------------------------------------------------------------------- ;------------------------------------------------------------------------------- ; Routines to implement the variable selection GUI ; ; Pro selectTool,title,selected_vars,help=help ;=============================================================================== ; Program: selectTool ; ; Version: 1.0 ; ; Date: August 5, 1999 ; ; Purpose/Function: ; This procedure will make a gui to display for a user to choose variables ; from a list of variable names. ; ; Variables: ; title strarr List of variables ; vars intarr Indices of variables chosen (common) ; selected_vars intarr Indices of variables chosen (returned) ; state structure Holds internal GUI information ; ; ; ; Invocation: idl> selectTool, parameter_list,index_list ; ; ; Language/Compiler Version: ; This routine has been tested on the systems listed below. ; Computer Operating System IDL Version ; --------------- ---------------- ----------- ; Sun, Ultra-4 Solaris 5.6 5.2 ; ; ; Updates: ; ;=============================================================================== common selectTool, vars,help_string ;Create a GUI base base=widget_base(/column,title='Select AirMISR Parameters',mbar=menubase) ;Set up the menu bar void=cw_pdmenu(menubase,/mbar,['1\File','2\Abort Read'],/return_name) ;Create a subBase to put buttons at the top subBaseB=widget_base(base,column=3) void=widget_button(subBaseB,value='Selection Complete') void=widget_button(subBaseB,value='Select All') void=widget_button(subBaseB,value='Help') ;Create a subBase for the variable list subBase=widget_base(base,/row) listID=widget_list(subBase,value=Title,ysize=7,/multiple) ;Draw the window widget_control,base,/realize ;Initialize the UValue structure state={listID:listID, all:indgen(n_elements(title))} widget_control,base,set_uvalue=state xmanager,'selectTool',base ;,cleanup='vtClean' selected_vars=vars print,"End of selection" return End PRO selectTool_event,event ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; This procedure manages events generated by the selectTool GUI ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; common selectTool,vars widget_control,event.top,get_uvalue=state thisType=widget_info(event.id,/name) widget_control,event.top,get_uvalue=state if (thisType eq'LIST') then thisValue='LIST' else $ if (thisType eq 'BUTTON') then widget_control,event.id,get_value=thisValue $ else thisValue=event.value case thisValue of 'Quit':Begin widget_control,event.top,/destroy retall end 'Help': begin print,'' print,' Select the variables to be saved.' if (!d.name eq 'X') then begin print,' Holding down the Shift key and clicking an item selects the range ' print,' from the previously selected item to the new item. Holding down the' print,' mouse button when selecting items also selects a range. Holding ' print,' down the Control key and clicking an item toggles that item between' print,' the selected and unselected state.' print,'' endif else if (!d.name eq 'WIN') or (!d.name eq 'MAC') then begin print,' Holding down the Shift key and clicking an item selects the range ' print,' from the previously selected item to the new item. Holding down the' print,' Control key and clicking an item toggles that item between the ' print,' selected and unselected state.' print,'' endif end 'LIST': 'Selection Complete': Begin widget_control,event.top,get_uvalue=state vars=widget_info(state.listID,/list_select) if (vars[0] eq -1) then begin print,'NOT DONE. No variables were selected.' endif else widget_control,event.top,/destroy END 'Exit': Begin widget_control,event.top,/destroy return end 'Select All':widget_control,state.listID,set_list_select=state.all 'Abort Read': begin widget_control,event.top,/destroy retall end else: print,'Unknown Event' endcase return end