To illustrate how templates change / extend the content of a GRIB2 message, the following figure shows an example of the product definition templates 4.0 and 4.1.
Template 4.0: instantaneous deterministic product | Template 4.1: instantaneous probabilistic product | ||
10 | Parameter category (Code table 4.1) | 10 | Parameter category (Code table 4.1) |
---|---|---|---|
11 | Parameter number (Code table 4.2) | 11 | Parameter number (Code table 4.2) |
12 | Type of generating process (Code table 4.3) | 12 | Type of generating process (Code table 4.3) |
13 | Background generating process identifier | 13 | Background generating process identifier |
14 | Forecast generating process identifier | 14 | Forecast generating process identifier |
15-16 | Hours after reference time of data cut-off | 15-16 | Hours after reference time of data cut-off |
17 | Minutes after reference time of data cut-off | 17 | Minutes after reference time of data cut-off |
18 | Indicator of unit of time range ( Code table 4.4) | 18 | Indicator of unit of time range (Code table 4.4) |
19-22 | Forecast time in units defined by octet 18 | 19-22 | Forecast time in units defined by octet 18 |
23 | Type of first fixed surface (Code table 4.5) | 23 | Type of first fixed surface (Code table 4.5) |
24 | Scale factor of first fixed surface | 24 | Scale factor of first fixed surface |
25-28 | Scaled value of first fixed surface | 25-28 | Scaled value of first fixed surface |
29 | Type of second fixed surface (Code table 4.5) | 29 | Type of second fixed surface (Code table 4.5) |
30 | Scale factor of second fixed surface | 30 | Scale factor of second fixed surface |
31-34 | Scaled value of second fixed surface | 31-34 | Scaled value of second fixed surface |
35 | Type of ensemble forecast (Code table 4.6) | ||
36 | Perturbation number | ||
37 | Number of forecasts in ensemble |
The number in the first column means that at this/(these) specific byte(s) in the section 4, the coded integer value(s) either refer to a specific WMO table, which is specified in the brackets, or contain a value for a specific key like the Forecast time. For example, the first entry in both templates, 10, refers to the Parameter Category which is listed in the WMO code table 4.1. The template 4.1 has the same bytes and keys from byte 10 to byte 34 of the section 4 as the template 4.0, but includes thereafter three additional bytes to add three extra keys. These three extra keys extend the instantaneous deterministic template, 4.0 to a probabilistic one, 4.1. The section length is encoded at the beginning of each section so that the decoder knows how long each section is. For template 4.0, the section 4 length is 34 and for template 4.1 37 bytes long. Which template is used, is encoded in the section itself. Bytes 8 to 9 of the section 4 contain the Product Definition Template Number, which would be set for the examples shown here to 0 respectively 1. In the same way, the Grid Definition Template Number in section 3 and the Data Representation Template Number in section 5 are defined. This means that the decoder has to know the structure of the template to be able to decode the message. New templates can therefore not be decoded with old versions of the decoder that doesn't include the new template layout. In ecCodes, the engine and definitions of parameters / templates are separated, and the latter can be changed for an existing installation, see here, but it is recommended to upgrade ecCodes instead.
Here's an example showing how to generate and compare the contents of two GRIB2 messages with the templates 4.0 and 4.1:
# generate two GRIB2 files with templates 4.0 and 4.1 grib_set -s productDefinitionTemplateNumber=0 $(codes_info -s)/GRIB2.tmpl PDTN_4_0.grib2 grib_set -s productDefinitionTemplateNumber=1 $(codes_info -s)/GRIB2.tmpl PDTN_4_1.grib2 # compare the dumps of section 4 grib_dump -O -p section_4 PDTN_4_0.grib2 grib_dump -O -p section_4 PDTN_4_1.grib2 diff <(grib_dump -O -p section_4 PDTN_4_0.grib2) <(grib_dump -O -p section_4 PDTN_4_1.grib2)