;+ ; ; The GRIB_EX routine is an example program for showing how to use the 3 main GRIB file ; query and read programs. ; ; @Author ; Andy Pursch ; ITT Visual Information Solutions ; ; @Copyright ; ITT-VIS 2006 ; ; @Categories ; File I/O ; ; @History ; Original June 2006 ; ; @Requires ; IDL 6.2 ; ; @Restrictions ; Requires idl_grib.dll, idl_grib.dlm ; ; @Version ; 1.0 ;- ;====================================================== PRO GRIB_EX ; ; This program demonstrates the use of the 3 GRIB routines. ; fname = DIALOG_PICKFILE() ; Query a GRIB file, returning full documentation for each record. t1=systime(1) status = QUERY_GRIB_FILE(fname, info,/full) print,t1-systime(1) IF status eq -1 THEN RETURN ; PRINT,' ' PRINT, '***** Sample output from full metadata query *****' HELP,info HELP,info,/str HELP, info[0].info, /str HELP, info[0].projection, /str PRINT, ' ' PRINT, '***** Sample output from reduced metadata query *****' t1=systime(1) status = QUERY_GRIB_FILE(fname, info) print,t1-systime(1) IF status eq -1 THEN RETURN HELP,info HELP, info, /str PRINT, ' ' ; PRINT,'***** Sample output from selected metadata record query *****' records = [1,3,5,7] ; Make sure there are at least 7 records in the file. Adjust accordingly t1=systime(1) status = QUERY_GRIB_RECORD(fname, info, records) print,t1-systime(1) IF status eq -1 THEN RETURN HELP,info HELP,info,/str HELP, info[0].info, /str HELP, info[0].projection, /str PRINT, ' ' PRINT,'***** Sample output from selected data record retrieval *****' records = [1,5,8,17] ; Make sure there are at least 17 records in the file. Adjust accordingly t1=systime(1) data = READ_GRIB_RECORD(fname, records) print,t1-systime(1) HELP,data PRINT, ' ' ;=============================================================== PRINT, '***** ' t1=systime(1) status = QUERY_GRIB_FILE(fname, info) print,t1-systime(1) IF status EQ -1 THEN RETURN ; For this example look for all records that contain temperature data, Quantity='tmp' res=STRCMP('tmp', info.quantity, /fold) ; Record numbers in the file start with 1. Since IDL will return the elements of where ; the QUANTITY is found as a zero based subscript, we must add one to each value ; in order to query / retrieve the correct record. records = WHERE(res EQ 1, count) + 1 ; ; If there are records that match the query, retrieve the info structure for each one ; and then read those records to get the data. IF count GT 0 THEN BEGIN status = QUERY_GRIB_RECORD(fname, info, records) IF status EQ -1 THEN RETURN data = READ_GRIB_RECORD(fname, records) ENDIF ; Step through the display of all images that were found IF COUNT GT 0 THEN FOR i=0, count -1 DO IIMAGE,data[*,*,i], view_number=1, view_title=info[i].info.description END