;+ ; ; The QUERY_GRIB_RECORD routine reads the metadata contents of selected records of ; a Gridded Binary (GRIB) file and returns the metadata in an IDL structure variable. ; ; @Param ; filename {in} {optional} {type=string} {default=none} ; A scalar string specifying the full pathname of the GRIB file to read ; ; @Param ; info {out} {required} {type=structure} {default=none} ; An IDL structure that contains the metadata information for each record ; ; @Param ; records {in} {required} {type=integer array} {default=none} ; An integer array used to specify the record numbers to be queried. ; ; @Author ; Andy Pursch ; ITT Visual Information Solutions ; ; @Copyright ; ITT-VIS 2006 ; ; @Categories ; File I/O ; ; @History ; Original June 2006 ; ; @Returns ; status = 1 for successful query ; status = -1 for unsuccessful query ; ; @Requires ; IDL 6.2 ; ; @Restrictions ; Requires idl_grib.dll, idl_grib.dlm ; ; @Version ; 1.0 ;- FUNCTION QUERY_GRIB_RECORD, filename, info, 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 queried',/error) RETURN, status ENDIF ; Since we are only doing a query on the file to determine its contents ; all we need to do is extract the header records. pData = READ_GRIB(filename, /header, records=records) ; 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 info structure that will return the descriptive info ; that is contained in the header records. info = REPLICATE({info:(*pData[0]).info, projection:(*pData[0]).projection}, nparams) ; For each record FOR i=1, nparams-1 DO BEGIN info[i].info = (*pData[i]).info info[i].projection = (*pData[i]).projection ENDFOR ; Clean up the pointers before returning HEAP_FREE, pData, /ptr status=1 RETURN, status END