Excerpt |
---|
|
For the moment there is no simple way of knowing what To find out 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, use grib_dump or the API. |
Step-by-step guide
You can either use the API or the grib_dump tool for this.
The 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.The function, available only in the C API, is called 'grib_get_native_type'. Possible key value types are the following: undefined, long, double, string, bytes, section, label or missing.
In the Python interface there is a function called "codes_get_native_type" which returns one of: "int", "float" or "str". E.g.
Code Block |
---|
|
gid = codes_grib_new_from_samples("GRIB2")
codes_get_native_type(gid, "date") # returns int
codes_get_native_type(gid, "referenceValue") # returns float
codes_get_native_type(gid, "stepType") # returns 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.
Let's look at the types of various keys in a GRIB2 message:
Code Block |
---|
|
% 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)
- "codetable" means an integer whose values come from entries in the given Code Table e.g. 1.4
- "unsigned" is a non-negative integer
- "signed" means an integer which can be negative
- "ieeefloat" is a floating-point number (https://en.wikipedia.org/wiki/IEEE_754)
Note: The above command could be run passing in all the keys in one go:
Code Block |
---|
% grib_dump -t -p identifier,typeOfProcessedData,numberOfDataPoints,scaleFactorOfFirstFixedSurface,referenceValue my.grib |
Related articles
Content by Label |
---|
showLabels | false |
---|
max | 5 |
---|
spaces | ~usa |
---|
showSpace | false |
---|
sort | modified |
---|
reverse | true |
---|
type | page |
---|
cql | label = in ("kb-how-to-article","eccodes-faqs","grib","keys","type") and type = "page" and space = "UDOC" |
---|
labels | kb-how-to-article |
---|
|
...