function read_grid_field,filename,gridname,fieldname,fielddata,FILLVALUE=fillvalue,$ BLOCKRANGE=blockrange ; This function reads the named data field 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 field to ; be read ; gridname - the name of the grid structure in which the data field is located ; fieldname - the name of the data field to be read ; ; OUTPUT PARAMETERS ; fielddata - the variable in which the field's data are returned ; ; KEYWORD PARAMETERS ; fillvalue - a variable to receive the fill value stored for the data field ; blockrange - A two dimensional array specifying the range of block numbers (from 1-180) ; for which data is to be extracted for the specified field. The first value in the ; array is the first block in the range, and its value must be less than the second ; value in the array, which is the last block in the range. ; If no value is specified for this keyword, the entire field is extracted. ; Note, however, that it may not be possible to extract an entire ; data field, depending on the total byte size of the field and the available ; memory on the computer. If insufficient memory is available, IDL will halt ; execution of the program with the message ; Unable to allocate memory: to make array. ; ; 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 EXAMPLES ; ; filename = DIALOG_PICKFILE(TITLE="Select MISR Level 2 Aerosol File") ; read the whole optical depth data field ; status = read_grid_field(filename,"RegParamsAer","RegBestEstimateSpectralOptDepth",$ ; optical_depth) ; read 6 blocks from the optical depth field as well as the fill value set for this field ; status = read_grid_field(filename,"RegParamsAer",RegBestEstimateSpectralOptDepth",$ ; optical_depth,BLOCKRANGE=[50,55],FILLVALUE=fill) 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 if KEYWORD_SET(BLOCKRANGE) then begin numblocks = blockrange[1] - blockrange[0] + 1 ; get the dimensions of the field and set up the START and EDGE arrays ; NOTE: the dimensions are always ordered such that the last three dimensions ; are YDim, XDim, and SOMBlockDim status = EOS_GD_FIELDINFO(gid,fieldname,rank,dims,numtype,dimlist) ; start is the index in each dimension where the read should start ; we want to read everything except the block dimension from the beginning start = lonarr(rank) start[*] = 0 start[rank-1] = blockrange[0]-1 ; block dimension goes from 0-179 so map from 1-180 ; edge is how many values to read in each dimension ; we want to read everything in each dimension except the block dimension, ; where we want to read only specified number of blocks edge = dims edge[rank-1] = numblocks ; read the specified subset of the field status = EOS_GD_READFIELD(gid,fieldname,fielddata,START=start,EDGE=edge) if (status lt 0) then begin msg_text = "Problem reading field " + fieldname goto, error endif endif else begin status = EOS_GD_READFIELD(gid,fieldname,fielddata) if (status lt 0) then begin msg_text = "Problem reading field " + fieldname goto, error endif endelse if KEYWORD_SET(FILLVALUE) then begin status = EOS_GD_GETFILLVALUE(gid,fieldname,fillvalue) if (status lt 0) then begin msg_text = "Problem getting fill value for field " + fieldname goto, error endif endif 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 handler error: status = DIALOG_MESSAGE(msg_text,/INFORMATION,TITLE='read_grid_field message') fielddata = 0 return,-1 end