This is a field whose data values are all the same. When encoding such fields, ecCodes drastically reduces the message size by storing just the value itself (once) and leaving the Data Section empty. It also sets the key "bitsPerValue" to 0.

The field value is stored in the "referenceValue" key and encoded as a floating-point number (32 bit IEEE float in GRIB2). When we decode such a field, we fill in the array with this value as many times as needed (key "numberOfDataPoints").

To see an example, let's change a non-constant GRIB2 file to create a constant field with the value 344.663:

Create a constant field
% grib_set -d 344.663 gg_sfc_grib2.tmpl const.grib2
 
% ls -l gg_sfc_grib2.tmpl const.grib2
-rw-r--r-- 1    388 May 16 15:21 const.grib2
-rw-r--r-- 1  26948 May 11 16:46 gg_sfc_grib2.tmpl
 
% grib_dump -Ot const.grib2
...
======================   SECTION_5 ( length=21, padding=0 )    ======================
1-4       section_length (int) section5Length = 21
5         unsigned (int) numberOfSection = 5
6-9       unsigned (int) numberOfValues = 13280
10-11     codetable (int) dataRepresentationTemplateNumber = 0
12-15     ieeefloat (double) referenceValue = 344.663
16-17     signed (int) binaryScaleFactor = -9
18-19     signed (int) decimalScaleFactor = 0
20        unsigned (int) bitsPerValue = 0
21        codetable (int) typeOfOriginalFieldValues = 0
======================   SECTION_6 ( length=6, padding=0 )     ======================
1-4       section_length (int) section6Length = 6
5         unsigned (int) numberOfSection = 6
6         codetable (int) bitMapIndicator = 255
======================   SECTION_7 ( length=5, padding=0 )     ======================
1-4       section_length (int) section7Length = 5
5         unsigned (int) numberOfSection = 7
======================   SECTION_8 ( length=4, padding=0 )     ======================
1-4       ascii (str) 7777 = 7777


Several things to note:

  • the referenceValue now stores the number 344.663 as a 4 byte float (octets 12 to 15 inclusive)
  • the Data Section (Section 7) is very small (just 5 bytes) as it does not store the array of values
  • the key bitsPerValue has been set to 0
  • the new file is very much smaller than the original

When you decode this field, you will get back an array with 13280 elements all equal to 344.663.