function read_grid_attr,filename,gridname,attrname,attrdata ; This function reads the named grid attribute from the specified file which is written ; in the HDF-EOS grid format. ; ; INPUT PARAMETERS: ; filename - the full path and file name of the data file containing the attribute to ; be read ; gridname - the name of the grid structure with which the attribute is associated ; attrname - the name of the data field to be read ; ; OUTPUT PARAMETERS ; attrdata - the variable in which the attribute's value is returned ; ; FUNCTION RETURN VALUE ; A value of 0 is returned if the read operation was successsful; -1 is returned ; in the case of failure. A message dialog box is also displayed to indicate the ; source of the failure. ; ; USAGE EXAMPLE ; ; filename = DIALOG_PICKFILE(TITLE="Select MISR Level 2 Land File") ; status = read_grid_attr(filename,'SubregParamsLnd','Scale LandBRF',attrdata) fid = EOS_GD_OPEN(filename,/READ) if (fid lt 0) then begin msg_text = "Problem opening HDF-EOS file " + filename goto, error endif gid = EOS_GD_ATTACH(fid,gridname) if (gid lt 0) then begin msg_text = "Problem attaching grid " + gridname goto, error endif status = EOS_GD_ATTRINFO(gid, attrname, attrtype, attrcount) if (status lt 0) then begin msg_text = "Problem getting attribute info for " + attrname goto, error endif status = EOS_GD_READATTR(gid,attrname,attrdata) if (status lt 0) then begin msg_text = "Problem reading attribute " + attrname goto, error endif ; account for bug in HDF-EOS attributes that makes data array length = number of bytes ; rather than number of data items case attrtype of 3 : ; unsigned character 4 : ; charcter (string) 5 : attrdata = attrdata[0:(attrcount/4)-1]; float 32 6 : attrdata = attrdata[0:(attrcount/8)-1]; float 64 (double) 20 : ; int8 21 : ; uint8 22 : attrdata = attrdata[0:(attrcount/2)-1]; int16 23 : attrdata = attrdata[0:(attrcount/2)-1]; uint16 24 : attrdata = attrdata[0:(attrcount/4)-1]; int32 25 : attrdata = attrdata[0:(attrcount/4)-1]; uint32 else : ;unknown so treat as 1 byte length endcase status = EOS_GD_DETACH(gid) if (status lt 0) then begin msg_text = "Problem detaching grid " + gridname goto, error endif status = EOS_GD_CLOSE(fid) if (status lt 0) then begin msg_text = "Problem closing HDF-EOS file " + filename goto, error endif return,0 error: status = DIALOG_MESSAGE(msg_text,/INFORMATION,TITLE='read_grid_attr message') attrdata = 0 return,-1 end