You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

Step-by-step guide

For the moment there is no simple way of knowing what the type of a key value is. However, the library provides a function that can be used to find out what the native type of a key value is.
In the C API, there is a function called "codes_get_native_type" which returns an integer which can be checked against the following macros:

CODES_TYPE_UNDEFINED
CODES_TYPE_LONG
CODES_TYPE_DOUBLE
CODES_TYPE_STRING
CODES_TYPE_BYTES
CODES_TYPE_SECTION
CODES_TYPE_LABEL
CODES_TYPE_MISSING

In the Python interface, the same function "codes_get_native_type" has a simpler interface and returns one of: "int", "float" or "str".


As of version 2.14.0, one can use the grib_dump tool with the "-p" option to dump a given key and query its type with the "-t" option.
E.g.

% grib_dump -t -p identifier my.grib
  # type ascii (str)
  #-READ ONLY- identifier = GRIB;

% grib_dump -t -p typeOfProcessedData my.grib
  # type codetable (int)
  # Analysis and forecast products (grib2/tables/4/1.4.table)  
  typeOfProcessedData = 2;

% grib_dump -t -p numberOfDataPoints my.grib
  # type unsigned (int)
  numberOfDataPoints = 496;

% grib_dump -t -p scaleFactorOfFirstFixedSurface my.grib
  # type signed (int)
  scaleFactorOfFirstFixedSurface = MISSING;

% grib_dump -t -p referenceValue my.grib
  # type ieeefloat (double)
  #-READ ONLY- referenceValue = 45.67;

Here we see several keys in a GRIB2 message with their respective types:

  • "ascii" means a string (character array)
  • "signed" means an integer which can be negative
  • "unsigned" is a non-negative integer
  • "codetable" means an integer whose values come from entries in the given Code Table e.g. 1.4
  • "ieeefloat" is a floating-point number (https://en.wikipedia.org/wiki/IEEE_754)


  • No labels