;+ ; ; The READ_GRIB_RECORD routine reads the data contents of selected records of ; a Gridded Binary (GRIB) file and returns the data in an IDL array variable. ; ; @Param ; filename {in} {required} {type=string} {default=none} ; A scalar string specifying the full pathname of the GRIB file to read ; ; @Param ; records {in} {required} {type=integer array} {default=none} ; An integer array used to specify the record numbers to be read. ; ; @Author ; Andy Pursch ; ITT Visual Information Solutions ; ; @Copyright ; ITT-VIS 2006 ; ; @Categories ; File I/O ; ; @History ; Original June 2006 ; @Returns ; Data, a 3 dimensional floating point array of GRIB variables. ; ; @Requires ; IDL 6.2 ; ; @Restrictions ; Requires idl_grib.dll, idl_grib.dlm ; ; @Version ; 1.0 ;- FUNCTION READ_GRIB_RECORD, filename, records ; Define value for error code status = -1 ; Make sure the record numbers are specified. IF N_ELEMENTS(records) EQ 0 THEN BEGIN a = DIALOG_MESSAGE('You must specify a list of record numbers that need to be read',/error) RETURN, status ENDIF ; Since we have already done a query on the file to determine its contents ; all we need to do is extract the datafor the specified records. pData = READ_GRIB(filename, records=records, /data_only) ; If this is not a valid GRIB file then return error status. A valid file should return ; a pointer to an array of pointers. The type code for an IDL pointer is 10. IF SIZE(pdata,/type) NE 10 THEN RETURN, status nparams = N_ELEMENTS(records) ; Create the array that will return the gridded data for each record ds = SIZE((*pdata[0])) data = FLTARR(ds[1], ds[2], nparams) ; For each record / parameter assign the data to the output array FOR i=0, nparams-1 DO data[*,*,i] = (*pData[i]) ; Clean up the pointers before returning HEAP_FREE, pData, /ptr RETURN, data END