Step-by-step guide

GRIB messages are at the moment exchanged in edition 1 or 2. Although the information content of two messages in different editions is almost the same, their binary format is very different and organised in a different way.

The conversion from GRIB edition 1 (GRIB1) to edition 2 (GRIB2) is a format translation without any loss of information. Conversely the conversion from GRIB2 to GRIB1 is not always lossless because the edition 2 format has been extended to allow a wider set of scientific fields to be coded. Note: Converting to edition 1 is not supported.

The conversion algorithm should be easy to implement, but there are some factors making it challenging. First of all the new designed GRIB2 is in some points semantically different from GRIB1. Therefore it doesn't allow an easy mapping of the meaning across the two versions. Moreover some of the numeric code tables semantically identical are numerically different, which again doesn't allow an easy mapping between them, because the numeric codes for the same information element are different. We refer in particular to the type of level which is numerically different in the two editions.

Another element to be considered in a conversion algorithm is that many meteorological operational centres have been developing local patches to the GRIB specification to overcome the limitations of GRIB1. This local extensions or local tables are not coherent and sometimes are not properly organised. It is widespread, for example, the use of local parameter tables.

The aim of the conversion facilities provided in ecCodes is to be flexible enough to define conversion rules also for local tables and local extensions and to allow the user to configure locally the library to interpret fields coded in a local flavour of the GRIB specifications.

Conversion technique

To convert a GRIB message from edition 1 to edition 2 it is enough to set the key edition=2 (see grib_set). The conversion is performed automatically provided that the library is configured properly to translate the parameter information. The information regarding time and space is always translated automatically, while the parameter information, which is sometime dependent on local tables, has to be configured by the user if it is not included in the main set of parameter conversion rules contained in ecCodes distribution.

Parameters conversion

A list of all the parameters recognised by ecCodes is reported for consultation. The list contains their representation in edition 1 and 2 and for some of them the NetCDF CF compliant name.

Each parameter is identified by a paramId, which is a valid ecCodes key, and is described through the keys shortName, name, units.

For each parameter we can have one or more GRIB1 and/or GRIB2 representations. A GRIB representation is a set of keys describing the parameter in the coding format (GRIB1 or GRIB2). If for a parameter the GRIB1 and GRIB2 representations are both present in the list then the conversion from GRIB1 to GRIB2 is defined and can be automatically performed by ecCodes just setting edition=2.

A parameter can have more than one representation for a single format, because local representations are allowed depending on the centre defined in the GRIB message.

A local description can be added just editing the following definition files: paramId.def, shortName.def, name.def, units.def. The syntax of these files is:

  value = { key1=value1; key2=value2; key3=value3; ... }

A definition file containing the rules for a given centre and edition has to be placed in the directory grib[edition]/localConcepts/[centre:s]. Where [edition] is 1 or 2 and [centre:s] is the string describing the centre in the official table 0 of GRIB1 (e.g. centre code 98 is "ecmf")

The files describing the local parameters for ECMWF GRIB1 are located in grib1/localConcepts/ecmf. If for example we need to define "2 metre temperature" for ECMWF we have to add the following lines to the corresponding files:

paramId.def 
'167' = {table2Version=128; indicatorOfParameter=167;}

shortName.def 
'2t' = {table2Version=128; indicatorOfParameter=167;}

name.def 
'2 metre temperature' = {table2Version=128; indicatorOfParameter=167;}

units.def 
'K' = {table2Version=128; indicatorOfParameter=167;}

The same syntax can be used to describe the same parameter in GRIB2 to be able to convert the information from GRIB1 to GRIB2 and to be able to have the same paramId, name, shortName, units for both editions.

Local configuration

A site or user configuration is possible to allow interpretation and conversion of grib 1 messages encoded in non standard local ways. To separate the definition files contained in the installation directory from the definition files described in the previous section, in which the user can put some extra and local parameter definitions, the environment variable ECCODES_DEFINITION_PATH can be used.

To set this environment variable properly we have first to find the definitions files directory used by ecCodes. For this we can use the tool codes_info which provides some configuration information about the library:

% codes_info
ecCodes Version 2.26.0

Default definition files path is used: /usr/local/apps/eccodes/2.26.0/share/eccodes/definitions
Definition files path can be changed by setting ECCODES_DEFINITION_PATH environment variable

Default SAMPLES path is used: /usr/local/apps/eccodes/2.26.0/share/eccodes/samples
SAMPLES path can be changed by setting ECCODES_SAMPLES_PATH environment variable

To enable the parameter definitions described in the files contained in our directory

/home/u/definitions

we have to set the environment variable ECCODES_DEFINITION_PATH as follows:

export ECCODES_DEFINITION_PATH=/home/u/definitions:/usr/local/apps/eccodes/2.26.0/share/eccodes/definitions

so that our definition of the parameters will be read by ecCodes during run time. The content of the definition files in the directory /home/u/definitions has to be properly written following the instructions of the previous section.