You will find some example data in $SCRATCH/ectrain/trx/openifs or you can use output from one of your own experiments. Let's play !
Running any of the GRIB API tools without options or input files will produce a UNIX 'man page' style output describing the usage. Try:
grib_ls |
An inventory of the contents of GRIB files can be obtained with the grib_ls command.
For a single file, try:
grib_ls ICMGGepc8+000000 |
Multiple files:
grib_ls ICMGG* |
Counting the number of messages in a file
grib_count ICMGGepc8+000000 |
Specifying the information to display:
grib_ls -p dataDate,dataTime,stepRange,shortName,typeOfLevel,level ICMGGepc8+000000 |
Specifying the type of key (s: string, i: integer). To output the centre as a string (default):
grib_ls -p centre:s ICMGGepc8+000000 |
or as an integer:
grib_ls -p centre:i ICMGGepc8+000000 |
Listing specific namespace information. Try:
grib_ls -n parameter ICMGGepc8+000000 |
and
grib_ls -n statistics ICMGGepc8+000000 |
Other namespaces to try are time, vertical and geography.
Order the output. Try:
grib_ls -B "level desc" ICMSHepc8+000000 |
Compare and contrast with:
grib_ls -B "level:i desc" ICMSHepc8+000000 |
The where option: IS
grib_ls -w shortName=stl1 ICMGGepc8+000000 |
IS NOT
grib_ls -w shortName!=stl1 ICMGGepc8+000000 |
OR
grib_ls -w shortName=stl1/z ICMGGepc8+000000 |
AND
grib_ls -w shortName=q,level=10 ICMGGepc8+000000 |
Specifying the step unit. Compare the output from:
grib_ls -n time ICMGGepc8+000000 |
and
grib_ls -s stepUnits=m -n time ICMGGepc8+000012 |
The stepUnits can be set to s,m,h,3h,6h,12h,D,M,Y,10Y,30Y or C. The result must be expressible as an integer (try setting stepUnits=D above). This is a temporary change for display purposes only !
grib_ls is a tool meant mainly for interactive use. If you want to use the tools in a shell script then take a look at grib_get instead. It works in much the same way as grib_ls but is less verbose and also fails if an error occurs. |
To print all of the keys available for a particular GRIB message:
grib_dump -w shortName=stl1 ICMGGepc8+000012 |
To obtain a listing which is more like the WMO tables:
grib_dump -O -w shortName=stl1 ICMGGepc8+000012 |
To obtain even more detail:
grib_dump -OatH -w shortName=stl1 ICMGGepc8+000012 |
For grid point data, the grib_get_data tool prints a list of latitude, longitude and data values from one or more GRIB files.
Try
grib_get_data -w shortName=z ICMGGepc8+000000 |
The format of the data values can be controlled with a C-style format statement. Try:
grib_get_data -w shortName=z -F"%.4f" ICMGGepc8+000000 |
Other information can be printed along with the lat-lon-values triplet:
grib_get_data -p dataDate,dataTime,stepRange -w shortName=stl1 -F"%.4f" ICMGGepc8+000000 |
If you need the values in a program then do not be tempted to use grib_get_data to output the information to a file and then read the file in your program. It is more efficient to use the appropriate Fortran 90, C or Python interface to GRIB API to access the data values directly. |
The structure of GRIB allows files to be simply copied and concatenated with the UNIX 'cat' command. However, it's sometimes desirable to do something more sophisticated. The grib_copy tool provides a way to copy only selected content from GRIB files.
To copy all of the pressure level data at 1000 hPa from a number of separate files and store the output in a single file, try:
grib_copy -w level=1000 ICMSHepc8* lev1000.grib |
To do the same with only temperature field and to store in descending forecast step order, try:
grib_copy -w level=1000,shortName=t -B "stepRange:i desc" ICMSHepc8* lev1000_ordered.grib |
Now let's gather all of the temperature fields and store in order of decreasing level and decreasing step:
grib_copy -w shortName=t -B "level:i desc, stepRange:i desc" ICMSHepc8* all_t_ordered.grib |
It is important when using the "order by" (-B) option to specify the key type with, e.g., "level:i" to avoid unexpected (unwanted ?) results. Remember that the keys are strings by default. Usually,. we want a numeric order. |
Key names can be used to specify the output file names. Try:
grib_copy ICMGGepc8* "[shortName]_[level].grib[edition]" |
This provides a very convenient way to filter GRIB messages into separate files.