;+NAME/ONE LINE DESCRIPTION OF ROUTINE: ; GET_HDF_ATTR returns the data in a named attribute of an hdf file. ; ; TEST_IDHDF from Mila Mitra, SAIC GSC March 1998 FUNCTION TEST_ISHDF,filename CATCH, err IF (err EQ 0) THEN RETURN, HDF_ISHDF(filename) $ ELSE RETURN, 0 END ; GET_HDF_ATTR Returns the data in a named attribute of an hdf file. ; ; Alice Isaacman SAIC GSC April 1998 function get_hdf_attr, fileID=fileID, filename = filename, sdsname = sdsname, $ attrname = attrname, datatt = datatt ; if the name of an SDS is specified, returns the attribute value for that ; particular SDS. Otherwise, returns the named global attribute value. error_status = 0 catch, error_status if error_status ne 0 then begin error = -999 print,!err_string return, error endif error = 0 if n_elements(attrname) eq 0 then begin error = -999 print, 'GET_HDF_ATTR Error: Keyword "attrname" must be specified.' return , error endif ; IF N_ELEMENTS(filename) EQ 0 THEN filename = $ ; PICKFILE4(title = 'Pick the HDF file to open:') ; gg = findfile(filename) ; if gg(0) eq '' then begin ; error = -999 ; print, 'GET_HDF_ATTR Error: The file' ; print, ' "' + filename + '"' ; print, ' does not exist.' ; return , error ; endif ;Open file and initialize the SDS interface. ; IF NOT(TEST_ISHDF(filename)) THEN BEGIN ; error = -999 ; PRINT, 'GET_HDF_ATTR Error: "' + filename + '"' ; print, ' is not an HDF file ...' ; RETURN,error ; ENDIF ; NOT(TEST_ISHDF(filename)) if (n_elements(fileID) eq 0) then $ newFileID = HDF_SD_START(filename, /READ) $ else $ newFileID = fileID if n_elements(newfileid) eq 0 then begin error = -999 print, ' GET_HDF_ATTR Error: No file ID from HDF_SD_START!' return, error endif if n_elements(sdsname) eq 0 then begin attr_index = hdf_sd_attrfind(newFileID, attrname) if attr_index eq -1 then begin datatt = -999 print, 'GET_HDF_ATTR Error: The attribute "' + attrname + '"' print, ' does not exist in the file "' + filename + '".' endif else begin hdf_sd_attrinfo, newFileID, attr_index, data = datatt endelse ;attr_index eq -1 endif else begin sds_index = hdf_sd_nametoindex(newFileID, sdsname) sds_id = hdf_sd_select(newFileID, sds_index) if sds_index eq -1 then begin datatt = -999 print, 'GET_HDF_ATTR Error: The science data set ' print, ' "' + sdsname + '" in the file' print, ' "' + filename + '".' print, ' does not exist.' endif else begin sds_id = hdf_sd_select(newFileID, sds_index) attr_index = hdf_sd_attrfind(sds_id, attrname) if attr_index eq -1 then begin datatt = -999 print, 'GET_HDF_ATTR Error: The attribute "' + attrname + $ '"' print, ' ' + $ 'does not exist in the science data set' print, ' "' + sdsname + '" in the file' print, ' "' + filename + '".' endif else begin hdf_sd_attrinfo, sds_id, attr_index, data = datatt endelse ; attr_index eq -1 endelse ; sds_index eq -1 endelse ; n_elements(sdsname) eq 0 ; Close the HDF file. if (n_elements(fileID) eq 0) then $ HDF_SD_END, newFileID if (n_elements(datatt) eq 1) then datatt=datatt(0) return, datatt end