Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Warning

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.

Using the 'smart' copy

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.

  1. 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:

    Code Block
    grib_copy -w level=1000 ICMSHepc8* lev1000.grib
  2. To do the same with only temperature field and to store in descending forecast step order, try:

    Code Block
    grib_copy -w level=1000,shortName=t -B "stepRange:i desc" ICMSHepc8* lev1000_ordered.grib
  3. Now let's gather all of the temperature fields and store in order of decreasing level and decreasing step:

    Code Block
    grib_copy -w shortName=t -B "level:i desc, stepRange:i desc" ICMSHepc8* all_t_ordered.grib
    Note

    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.

  4. Key names can be used to specify the output file names.  Try:

    Code Block
    grib_copy ICMGGepc8* "[shortName]_[level].grib[edition]"

    This provides a very convenient way to filter GRIB messages into separate files.

Resources and further reading

...