Grib API Ref
Grib API Ref
0 Reference Manual
Author: Enrico Fucile
Contents
1 GRIB API 1.1 1.2 1.3 2 Tools 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 Grib tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . grib_ls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . grib_get . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . grib_get_data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . grib_set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . grib_dump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . grib_dump examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . grib_debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . grib_convert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Compiling and linking on ECMWF platforms . . . . . . . . . . . . . . . . . . . . . . . . grib_api installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Grib API keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 3 4 7 7 8 10 12 14 16 20 21 31 32 35 41 44 47 47 48 51 52 54 56 58 59
2.10 grib_lter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.11 grib_compare . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.12 grib_keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.13 grib_copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Examples 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 Grib API examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . clone.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . copy_message.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . count_messages.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . get.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . get_data.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . get_pl.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . get_pv.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ii 3.9
CONTENTS index.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 62 64 65 66 68 70 72 74 76 78 79 81 83 85 87 89 91 93 95 97 97
3.10 keys_iterator.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.11 multi_write.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.12 multi.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.13 nearest.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.14 precision.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.15 print_data.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.16 samples.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.17 set.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.18 set_bitmap.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.19 set_missing.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.20 set_pv.f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.21 get.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.22 iterator.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.23 keys_iterator.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.24 multi.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.25 multi_write.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.26 nearest.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.27 precision.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.28 set.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Fortran 90 interface 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 grib_api Namespace Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
grib_nd_nearest Interface Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 grib_get Interface Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 grib_get_data Interface Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 grib_get_element Interface Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 grib_get_size Interface Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 grib_index_get Interface Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 grib_index_get_size Interface Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 grib_index_select Interface Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
4.10 grib_set Interface Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 5 C interface 5.1 5.2 5.3 139
iii
Handling coded messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Iterating on latitude/longitude/values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Accessing header and data values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 The context object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 Iterating on keys names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 179
Chapter 1
GRIB API
The grib_api is the application program interface developed at ECMWF to provide an easy and realiable way for encoding and decoding WMO FM-92 GRIB edition 1 and edition 2 messages. With the grib_api library, that is written entirely in C, some command line tools are provided to give a quick way to manipulate grib data. Moreover a Fortran interface 90 is available giving access to the main features of the C library. The library is designed to access and modify messages in both editions with the same function calls using a set of Grib API keys to access the coded information ( examples: get.f90 set.f90, get.c, set.c, grib_get, grib_set ). The keys available for a message are different depending not only on the edition but also and mainly on the type of each message and the information it contains. A list of all the available keys in a message can be obtained dynamically using the library as shown in keys_iterator.c or using the Grib tools as shown in grib_dump or grib_keys. GRIB API will replace the GRIBEX function and a table of conversion between the numeric encoding of GRIBEX and the alphanumeric keys of GRIB API is provided to help the migration. To learn how to use the grib_api we recommend the user works through the Grib API examples. Reference manuals are also provided for the C library (organized in C interface) and for the Fortran 90 interface. Installation instructions are also provided.
1.1
The grib API is installed on all systems at ECMWF with both its components: the library and the tools. The latest version of the tools is always available in the system PATH so that users can begin using the tools immediately by typing directly the tool name (see tools reference). The latest version of the library is also installed on any platform and it is available for linking through the following two environment variables: $GRIB_API_INCLUDE $GRIB_API_LIB. Here is a short summary on how to compile and link on ECMWF systems: ecgate, hpce, hpcf
> xlc -o foo foo.c $GRIB_API_INCLUDE $GRIB_API_LIB -lm
2
> xlf90 -o foo foo.f90 $GRIB_API_INCLUDE $GRIB_API_LIB
GRIB API
workstation (C programs)
> gcc -o foo foo.c $GRIB_API_INCLUDE $GRIB_API_LIB
1.2
grib_api installation
The grib_api installation is based on the standard congure utility. It is tested on several platforms and with several compilers. However for some platforms modications to the installation engine may be required. If you encounter any problem during the installation procedure please send an e-mail with your problem to [email protected]. The only required package for a standard installation is jasper which enables the jpeg2000 packing/unpacking algorithm. It is possible to build grib_api without jasper, by using the disable-jpeg congure option, but to install a fully functional library, its download is recommended.
1.2.1
Standard installation
GRIB API
1.3
The GRIBEX routine used at ECMWF to encode and decode GRIB messages works on a number based table to retrive all the information from the message. This approach forces the user either to learn a code table or to use the documentation intensively. With grib_api a key name based access is provided so that all the information contained in the GRIB message is retrieved through alphanumeric names. All the key names are built from the ofcial WMO documentation on the GRIB edition 1 and 2 coding standard removing the spaces in the key description and capitalizing the initials so that the caption:
identification of originating generating centre
Some short names (aliases) are also provided, e.g. "centre" is an alias for identicationOfOriginatingGeneratingCentre. The names are always easily releated to the meaning of their value. A different set of keys is available for each message because the content is different. It is easy to nd the keys available in a message by using the GRIB tools (grib_dump) or the library (keys_iterator.c).
1.3.1
There are two different types of keys: coded and computed. The coded keys are directly linked to octets of the GRIB message and their value is obtained by only decoding the octets. A list of all the coded keys in a message can be obtained using grib_dump without any option (use the -a option to obtain also their aliases). The computed keys are obtained by combining other keys (coded or computed) and when their value is set all the related keys are set in a cascade process. These keys provide a synthesis of the information contained in the GRIB message and are a safe way to set complex attributes such as the type of grid or the type of packing. They are also helpful in the interpretation of some octets such as the scanning mode whose bits are related to the way of scanning the grid. In this case the computed keys:
iScansNegatively jScansPositively jPointsAreConsecutive alternativeRowScanning (available only for edition 2)
will provide access to single bits of the scanning mode octect hiding its structure from the user. The keys can also have some attributes as read only, which means that the key cannot be set (e.g. 7777 at the end of the message), or edition specic that is the attribute of all the keys having different values in the two editions (e.g. longitudeOfFirstGridPoint) or being present in one edition only (e.g. alternativeRowScanning). Moreover there are some computed keys that cannot be "get" and can be considered as functions acting on the grib in some way. These keys are always characterised by a predicate in their name (e.g. setDecimalPrecision). For the computed keys we provide the following preliminary documentation that will be extended soon.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
1.3 Grib API keys MARS keywords. All MARS keywords are available. Some examples are: date param levtype levelist step stream angles in degrees.
All the angle variables are provided in two versions, a native one with the units coded into the GRIB le and an edition independent one in degrees. It is always better to work with the "in degrees" version that is always provided through the key which has the same name of the native version with the sufx InDegrees
longitudeOfFirstGridPoint -> longitudeOfFirstGridPointInDegrees latitudeOfFirstGridPoint -> latitudeOfFirstGridPointInDegrees longitudeOfLastGridPoint -> longitudeOfLastGridPointInDegrees latitudeOfFirstGridPoint -> latitudeOfLastGridPointInDegrees latitudeOfFirstGridPoint -> latitudeOfFirstGridPointInDegrees iDirectionIncrement -> iDirectionIncrementInDegrees jDirectionIncrement -> jDirectionIncrementInDegrees
gridType The type of grid computed from the grid description section. For both editions: * * * * * * * * * * * * * * * * * * * * * * regular_ll reduced_ll mercator lambert polar_stereographic UTM simple_polyconic albers miller rotated_ll stretched_ll stretched_rotated_ll regular_gg rotated_gg stretched_gg stretched_rotated_gg reduced_gg sh rotated_sh stretched_sh stretched_rotated_sh space_view
GRIB API
packingType The alghorithm used to pack data into the GRIB message. For GRIB edition 1: * grid_simple * grid_simple_matrix * grid_simple_matrix_bitmap * grid_second_order * grid_second_order_different_width * spectral_complex * spectral_simple * grid_unknown * spectral_unknown For GRIB edition 2: * * * * * * * * * * * grid_simple grid_simple_matrix grid_simple_matrix_bitmap grid_complex grid_complex_spatial_differencing grid_jpeg grid_png grid_ieee spectral_simple spectral_complex grid_simple_log_preprocessing
setDecimalPrecision is a function key used to set the decimal precision see the grib_set page for usage. getNumberOfValues The number of values coded into the data section of the GRIB message
Chapter 2
Tools
2.1 Grib tools
The following command line tools are provided to help users in all interactive and batch processing of grib data. Use of the tools is recommended whenever possible. They provide a ready and tested solution for many situations and their use will avoid the need to write new cod and thus speeding up your work. To make easier their use the tools are provided with a common set of options so that its quick to apply the same options to different tools. We suggest to begin with grib_dump, grib_ls and grib_get to inspect the content of some les and then to learn about the other tools to change the content of the grib message (grib_set, grib_convert, grib_lter) or to copy some messages from a le (grib_copy) or to get a latitude/longitude/values list of data. A smart compare tool (grib_compare) is also provided to compare grib messages focusing on some keys or comparing data with a given precision. grib_dump grib_ls grib_get grib_copy grib_set grib_convert grib_lter grib_compare grib_get_data grib_keys
Tools
2.2
2.2.1
grib_ls
DESCRIPTION
List content of grib les printing values of some keys. It does not fail when a key is not found.
2.2.2
USAGE
2.2.3
OPTIONS
-p key[:{s/d/l}],key[:{s/d/l}],... Declaration of keys to print. For each key a string (key:s) or a double (key:d) or a long (key:l) type can be requested. Default type is string. -F format C style format for oating point values. -P key[:{s/d/l}],key[:{s/d/l}],... As -p adding the declared keys to the default list. -w key[:{s/d/l}]{=/!=}value,key[:{s/d/l}]{=/!=}value,... Where clause. Grib messages are processed only if they match all the key/value constraints. A valid constraint is of type key=value or key!=value. For each key a string (key:s) or a double (key:d) or a long (key:l) type can be specied. Default type is string. -B order by directive Order by. The output will be ordered according the order by directive. Order by example: "step asc, centre desc" (step ascending and centre discending) -l Latitude,Longitude[,MODE,le] Value close to the point of a Latitude/Longitude. Allowed values for MODE are: 4 (4 values in the nearest points are printed) Default 1 (the value at the nearest point is printed) le (le is used as mask. The closer point with mask value>=0.5 is printed) -i index Data value corresponding to the given index is printed. -n namespace All the keys belonging to namespace are printed. -m Mars keys are printed. -V Version. -W width Minimum width of each column in output. Default is 10. -M
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
2.2 grib_ls Multi-grib support off. Turn off support for multiple elds in single grib message -g Copy GTS header. -G GRIBEX compatibility mode. -7 Does not fail when the message has wrong length
2.2.4
grib_ls examples
1. Without options a default list of keys is printed. The default list is different depending on the type of grib message.
> grib_ls ../data/reduced*.grib1 ../data/regular*.grib1 ../data/reduced*.grib2 \n
2. To print offset and count number in le use the keys offset and count Also the total count in a set of les is available as countTotal
> grib_ls -p offset,count,countTotal ../data/reduced*.grib1
3. To list only a subset of messages use the -w (where option). Only the pressure levels are listed with the following line.
> grib_ls -w levType=pl ../tigge_pf_ecmwf.grib2
4. All the grib messages not on pressure levels are listed as follows:
> grib_ls -w levType!=pl ../tigge_pf_ecmwf.grib2
10
Tools
2.3
2.3.1
grib_get
DESCRIPTION
Get values of some keys from a grib le. It is similar to grib_ls, but fails returning an error code when an error occurs (e.g. key not found).
2.3.2
USAGE
2.3.3
-f
OPTIONS
Force. Force the execution not to fail on error. -p key[:{s/d/l}],key[:{s/d/l}],... Declaration of keys to print. For each key a string (key:s) or a double (key:d) or a long (key:l) type can be requested. Default type is string. -F format C style format for oating point values. -l Latitude,Longitude[,MODE,le] Value close to the point of a Latitude/Longitude. Allowed values for MODE are: 4 (4 values in the nearest points are printed) Default 1 (the value at the nearest point is printed) le (le is used as mask. The closer point with mask value>=0.5 is printed) -P key[:{s/d/l}],key[:{s/d/l}],... As -p adding the declared keys to the default list. -w key[:{s/d/l}]{=/!=}value,key[:{s/d/l}]{=/!=}value,... Where clause. Grib messages are processed only if they match all the key/value constraints. A valid constraint is of type key=value or key!=value. For each key a string (key:s) or a double (key:d) or a long (key:l) type can be specied. Default type is string. -n namespace All the keys belonging to namespace are printed. -V Version. -W width Minimum width of each column in output. Default is 10. -m Mars keys are printed. -M Multi-grib support off. Turn off support for multiple elds in single grib message -g
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
2.3 grib_get Copy GTS header. -G GRIBEX compatibility mode. -7 Does not fail when the message has wrong length
11
2.3.4
grib_get examples
12
Tools
2.4
2.4.1
grib_get_data
DESCRIPTION
2.4.2
USAGE
2.4.3
-M
OPTIONS
Multi-grib support off. Turn off support for multiple elds in single grib message -m missingValue The missing value is given through this option. Any string is allowed and it is printed in place of the missing values. Default is to skip the missing values. -p key[:{s/d/l}],key[:{s/d/l}],... Declaration of keys to print. For each key a string (key:s) or a double (key:d) or a long (key:l) type can be requested. Default type is string. -R key1=relative_error1,key2=relative_error2,... Compare oating point values using the relative error as tolerance. key1=relative_error will compare key1 using relative_error1. all=relative_error will compare all the oating point keys using relative_error. Default all=0. -F format C style format for values. Default is "%.10e" -w key[:{s/d/l}]{=/!=}value,key[:{s/d/l}]{=/!=}value,... Where clause. Grib messages are processed only if they match all the key/value constraints. A valid constraint is of type key=value or key!=value. For each key a string (key:s) or a double (key:d) or a long (key:l) type can be specied. Default type is string. -f Force. Force the execution not to fail on error. -G GRIBEX compatibility mode. -7 Does not fail when the message has wrong length -V Version.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
2.4 grib_get_data
13
2.4.4
grib_get_data examples
2. If you want to dene your missing value=1111 and to print the string missing in place of it
>grib_get_data -m 1111:missing ../data/reduced_gaussian_model_level.grib2
3. If you want to print the value of other keys with the data value list
>grib_get_data -p centre,level,step ../data/reduced_gaussian_model_level.grib2
14
Tools
2.5
2.5.1
grib_set
DESCRIPTION
Sets key/value pairs in the input grib le and writes each message to the output_grib_le. It fails when an error occurs (e.g. key not found).
2.5.2
USAGE
2.5.3
OPTIONS
-s key[:{s/d/l}]=value,key[:{s/d/l}]=value,... Key/values to set. For each key a string (key:s) or a double (key:d) or a long (key:l) type can be dened. By default the native type is set. -r Repack data. Sometimes after setting some keys involving properties of the packing algorithm a repacking of data is needed. This repacking is performed setting this -r option. -d value Set all the data values to "value". -p key[:{s/d/l}],key[:{s/d/l}],... Declaration of keys to print. For each key a string (key:s) or a double (key:d) or a long (key:l) type can be requested. Default type is string. -P key[:{s/d/l}],key[:{s/d/l}],... As -p adding the declared keys to the default list. -w key[:{s/d/l}]=value,key[:{s/d/l}]=value,... Where clause. Set is only executed for grib messages matching all the key/value constraints. If a grib message does not match the constraints it is copied unchanged to the output_grib_le. This behaviour can be changed setting the option -S. For each key a string (key:s) or a double (key:d) or a long (key:l) type can be dened. Default type is string. -7 Does not fail when the message has wrong length -S Strict. Only grib messages matching all the constraints are copied to the output le -V Version. -M Multi-grib support off. Turn off support for multiple elds in single grib message -g Copy GTS header.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
2.5 grib_set -G GRIBEX compatibility mode. -f Force. Force the execution not to fail on error. -v Verbose.
15
2.5.4
grib_set examples
2. To set productDenitionTemplateNumber=2 only for the elds for which productDenitionTemplateNumber is not equal to 11
3. When a key is not used all the bits of its value should be set to 1 to indicate that it is missing. Since the length (number of octet) is different from a key to another, the value that we have to code for missing keys is not unique. To give an easy way to set a key to missing a string "missing" or "MISSING" is accepted by grib_set as follows:
Since some values can not be set to missing you can get an error for those keys. 4. To set scaleFactorOfSecondFixedSurface to missing only for the elds for which scaleFactorOfSecondFixedSurface is not missing:
5. Its possible to produce a grib edition 2 le from a grib edition 1 just changing the edition number with grib_set. At this stage of development all the geography parameters, level and time information is correctly translated, for the product denition extra set calls must be done. To do this properly grib_convert is suggested.
grib_set -s editionNumber=2 ../data/reduced_gaussian_pressure_level.grib1
6. With grib edition 2 is possible to compress data using the jpeg algorithm. To change packing algorithm from grid_simple (simple packing) to grid_jpeg (jpeg2000 packing):
>grib_set -s packingType=grid_jpeg ../data/regular_gaussian_model_level.grib2 out.grib2
7. Its possible to ask grib_api to calculate the number of bits per value needed to pack a given eld with a xed number of decimal digits of precision. For example if we want to pack a temperature expressed in Kelvin with 1 digits of precision after the decimal point we can set changeDecimalPrecision=1
>grib_set -s changeDecimalPrecision=1 ../data/regular_latlon_surface.grib2 ../data/out.grib2 rm -f ../data/out.grib2 | true ./grib_set -s changeDecimalPrecision=1 ../data/regular_latlon_surface.grib2 ../data/out.grib2
16
Tools
2.6
2.6.1
grib_dump
DESCRIPTION
2.6.2
USAGE
2.6.3
-O
OPTIONS
Octet mode. WMO documentation style dump. -D Debug mode. -P key[:{s/d/l}],key[:{s/d/l}],... As -p adding the declared keys to the default list. -d Print all data values. Available only in C mode -C C code mode. A C code program generating the grib message is dumped. -t Print type information. -H Print octet content in hexadecimal format. -a Dump aliases. -w key[:{s/d/l}]{=/!=}value,key[:{s/d/l}]{=/!=}value,... Where clause. Grib messages are processed only if they match all the key/value constraints. A valid constraint is of type key=value or key!=value. For each key a string (key:s) or a double (key:d) or a long (key:l) type can be specied. Default type is string. -M Multi-grib support off. Turn off support for multiple elds in single grib message -7 Does not fail when the message has wrong length -V Version. -G
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
17
2.6.4
grib_dump examples
int main(int argc,const char** argv) { grib_handle *h = NULL; size_t size = 0; double* vdouble = NULL; long* vlong = NULL; FILE* f = NULL; const char* p = NULL; const void* buffer = NULL; if(argc != 2) { fprintf(stderr,"usage: %s out\n",argv[0]); exit(1); } h = grib_handle_new_from_samples(NULL,"GRIB1"); if(!h) { fprintf(stderr,"Cannot create grib handle\n"); exit(1); } GRIB_CHECK(grib_set_long(h,"editionNumber",1),0); GRIB_CHECK(grib_set_long(h,"table2Version",128),0); /* 98 = European Center for Medium-Range Weather Forecasts (grib1/0.table) GRIB_CHECK(grib_set_long(h,"centre",98),0); GRIB_CHECK(grib_set_long(h,"generatingProcessIdentifier",130),0); GRIB_CHECK(grib_set_long(h,"gridDefinition",255),0); /* 128 = 10000000 (1=1) Section 2 included (2=0) Section 3 omited See grib1/1.table */ GRIB_CHECK(grib_set_long(h,"section1Flags",128),0); */
(grib1/3.table)
*/
18
Tools
GRIB_CHECK(grib_set_long(h,"level",0),0); GRIB_CHECK(grib_set_long(h,"yearOfCentury",8),0); GRIB_CHECK(grib_set_long(h,"month",2),0); GRIB_CHECK(grib_set_long(h,"day",6),0); GRIB_CHECK(grib_set_long(h,"hour",12),0); GRIB_CHECK(grib_set_long(h,"minute",0),0); /* 1 = Hour (grib1/4.table) */ GRIB_CHECK(grib_set_long(h,"unitOfTimeRange",1),0); GRIB_CHECK(grib_set_long(h,"P1",0),0); GRIB_CHECK(grib_set_long(h,"P2",0),0); /* 0 = Forecast product valid at reference time + P1 (P1>0) GRIB_CHECK(grib_set_long(h,"timeRangeIndicator",0),0); (grib1/5.table) */
GRIB_CHECK(grib_set_long(h,"numberIncludedInAverage",0),0); GRIB_CHECK(grib_set_long(h,"numberMissingFromAveragesOrAccumulations",0),0); GRIB_CHECK(grib_set_long(h,"centuryOfReferenceTimeOfData",21),0); /* 0 = Unknown code table entry (grib1/0.ecmf.table) GRIB_CHECK(grib_set_long(h,"subCentre",0),0); GRIB_CHECK(grib_set_long(h,"decimalScaleFactor",0),0); /* 1 = MARS labelling or ensemble forecast data (grib1/localDefinitionNumber.98.table) GRIB_CHECK(grib_set_long(h,"localDefinitionNumber",1),0); */ */
*/
/* 1025 = Atmospheric model (mars/stream.table) */ GRIB_CHECK(grib_set_long(h,"marsStream",1025),0); p = "0001"; size = strlen(p)+1; GRIB_CHECK(grib_set_string(h,"experimentVersionNumber",p,&size),0); GRIB_CHECK(grib_set_long(h,"perturbationNumber",0),0); GRIB_CHECK(grib_set_long(h,"numberOfForecastsInEnsemble",0),0); GRIB_CHECK(grib_set_long(h,"numberOfVerticalCoordinateValues",0),0); GRIB_CHECK(grib_set_long(h,"pvlLocation",255),0); /* 0 = Latitude/Longitude Grid (grib1/6.table) */ GRIB_CHECK(grib_set_long(h,"dataRepresentationType",0),0); GRIB_CHECK(grib_set_long(h,"Ni",16),0); GRIB_CHECK(grib_set_long(h,"Nj",31),0); GRIB_CHECK(grib_set_long(h,"latitudeOfFirstGridPoint",60000),0); GRIB_CHECK(grib_set_long(h,"longitudeOfFirstGridPoint",0),0); /* 128 = 10000000 (1=1) Direction increments given (2=0) Earth assumed spherical with radius = 6367.47 km (5=0) u and v components resolved relative to easterly and northerly directions See grib1/7.table */ GRIB_CHECK(grib_set_long(h,"resolutionAndComponentFlags",128),0); GRIB_CHECK(grib_set_long(h,"latitudeOfLastGridPoint",0),0); GRIB_CHECK(grib_set_long(h,"longitudeOfLastGridPoint",30000),0); GRIB_CHECK(grib_set_long(h,"iDirectionIncrement",2000),0);
2.6 grib_dump
GRIB_CHECK(grib_set_long(h,"jDirectionIncrement",2000),0); /* 0 = 00000000 (1=0) Points scan in +i direction (2=0) Points scan in -j direction (3=0) Adjacent points in i direction are consecutive See grib1/8.table */ GRIB_CHECK(grib_set_long(h,"scanningMode",0),0);
19
/* ITERATOR */
/* NEAREST */ GRIB_CHECK(grib_set_long(h,"bitsPerValue",16),0); GRIB_CHECK(grib_set_long(h,"sphericalHarmonics",0),0); GRIB_CHECK(grib_set_long(h,"complexPacking",0),0); GRIB_CHECK(grib_set_long(h,"integerPointValues",0),0); GRIB_CHECK(grib_set_long(h,"additionalFlagPresent",0),0); /* gribSection5 */ /* Save the message */ f = fopen(argv[1],"w"); if(!f) { perror(argv[1]); exit(1); } GRIB_CHECK(grib_get_message(h,&buffer,&size),0); if(fwrite(buffer,1,size,f) != size) { perror(argv[1]); exit(1); } if(fclose(f)) { perror(argv[1]); exit(1); } grib_handle_delete(h); return 0; }
20
Tools
2.7
grib_dump examples
With the -O option you can get only the keys actually coded into the message, with the -a option the aliases of each key are printed. grib_dump -Oa "grib_le"
2.8 grib_debug
21
2.8
2.8.1
grib_debug
DESCRIPTION
2.8.2
USAGE
2.8.3
-V Version.
OPTIONS
2.8.4
grib_debug examples
Dumping in a WMO documentation style with hexadecimal octet values (-H) and with the aliases of each key listed in square brackets (-a). grib_dump -Ha ../data/reduced_gaussian_model_level.grib1
***** FILE: ../data/reduced_gaussian_model_level.grib1 ====================== MESSAGE 1 ( length=10142 ) ====================== ====================== SECTION_0 ( length=0, padding=0 ) ====================== 1-4 identifier = GRIB 5-7 totalLength = 10142 ( 0x00 0x27 0x9E ) 8 editionNumber = 1 ( 0x01 ) [ls.edition] ====================== SECTION_1 ( length=52, padding=0 ) ====================== 1-3 section1Length = 52 ( 0x00 0x00 0x34 ) 4 gribTablesVersionNo = 128 ( 0x80 ) [table2Version] 5 identificationOfOriginatingGeneratingCentre = 98 ( 0x62 ) [European Center for Medium-Range Weat 6 generatingProcessIdentifier = 128 ( 0x80 ) [generatingProcessIdentificationNumber, process] 7 gridDefinition = 255 ( 0xFF ) 8 section1Flags = 128 [10000000] 9 indicatorOfParameter = 130 ( 0x82 ) [T Temperature K (grib1/2.98.128.table) ] 10 indicatorOfTypeOfLevel = 109 ( 0x6D ) [Hybrid level level number (2 octets) (grib1/3.table) ] [l 11-12 lev = 1 ( 0x00 0x01 ) [topLevel, bottomLevel, ls.level, mars.levelist] 13 yearOfCentury = 7 ( 0x07 ) 14 month = 3 ( 0x03 ) 15 day = 18 ( 0x12 ) 16 hour = 12 ( 0x0C ) 17 minute = 0 ( 0x00 ) 18 indicatorOfUnitOfTimeRange = 1 ( 0x01 ) [Hour (grib1/4.table) ] 19 periodOfTime = 0 ( 0x00 ) [P1] 20 periodOfTimeIntervals = 0 ( 0x00 ) [P2] 21 timeRangeIndicator = 0 ( 0x00 ) [Forecast product valid at reference time + P1 (P1>0) (grib1/5.t 22-23 numberIncludedInAverage = 0 ( 0x00 0x00 ) 24 numberMissingFromAveragesOrAccumulations = 0 ( 0x00 ) 25 centuryOfReferenceTimeOfData = 21 ( 0x15 ) 26 identificationOfOriginatingGeneratingSubCentre = 0 ( 0x00 ) [Absent (grib1/0.table) ] [subCentre 27-28 decimalScaleFactor = 2 ( 0x00 0x02 ) 29-40 reservedNeedNotBePresent = 12 { 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 } # pad reservedNeedNotBePresent 41 localDefinitionNumber = 1 ( 0x01 ) 42 marsClass = 1 ( 0x01 ) [Operational archive (mars/class.table) ] [mars.class]
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
22
43 44-45 46-49 50 51 52
Tools
marsType = 2 ( 0x02 ) [Analysis (mars/type.table) ] [ls.dataType, mars.type] marsStream = 1025 ( 0x04 0x01 ) [Atmospheric model (mars/stream.table) ] [mars.stream] experimentVersionNumber = 0001 [mars.expver] perturbationNumber = 0 ( 0x00 ) numberOfForecastsInEnsemble = 0 ( 0x00 ) padding_local1_1 = 1 { 00 } # pad padding_local1_1 ====================== SECTION_2 ( length=896, padding=0 ) ====================== 1-3 section2Length = 896 ( 0x00 0x03 0x80 ) 4 numberOfVerticalCoordinateValues = 184 ( 0xB8 ) [NV, numberOfCoordinatesValues] 5 pvlLocation = 33 ( 0x21 ) 6 dataRepresentationType = 4 ( 0x04 ) [Gaussian Latitude/Longitude Grid (grib1/6.table) ] 7-8 numberOfPointsAlongAParallel = MISSING ( 0xFF 0xFF ) [geography.Ni] 9-10 numberOfPointsAlongAMeridian = 64 ( 0x00 0x40 ) [geography.Nj] 11-13 latitudeOfFirstGridPoint = 87864 ( 0x01 0x57 0x38 ) [La1] 14-16 longitudeOfFirstGridPoint = 0 ( 0x00 0x00 0x00 ) [Lo1] 17 resolutionAndComponentFlags = 0 [00000000] 18-20 latitudeOfLastGridPoint = -87864 ( 0x81 0x57 0x38 ) [La2] 21-23 longitudeOfLastGridPoint = 357188 ( 0x05 0x73 0x44 ) [Lo2] 24-25 iDirectionIncrement = MISSING ( 0xFF 0xFF ) [Di] 26-27 numberOfParallelsBetweenAPoleAndTheEquator = 32 ( 0x00 0x20 ) 28 scanningMode = 0 [00000000] 29-32 padding_grid4_1 = 4 { 00, 00, 00, 00 } # pad padding_grid4_1 33-768 pv = (184,736) { 0, 2.00004, 3.98083, 7.38719, 12.9083, 21.4136, 33.9529, 51.7466, 76.1677, 108.716, 150.986, 204.637, 271.356, 352.824, 450.686, 566.519, 701.813, 857.946, 1036.17, 1237.59, 1463.16, 1713.71, 1989.87, 2292.16, 2620.9, 2976.3, 3358.43, 3767.2, 4202.42, 4663.78, 5150.86, 5663.16, 6199.84, 6759.73, 7341.47, 7942.93, 8564.62, 9208.3, 9873.56, 10558.9, 11262.5, 11982.7, 12713.9, 13453.2, 14192, 14922.7, 15638.1, 16329.6, 16990.6, 17613.3, 18191, 18717, 19184.5, 19587.5, 19919.8, 20175.4, 20348.9, 20434.2, 20426.2, 20319, 20107, 19785.4, 19348.8, 18798.8, 18141.3, 17385.6, 16544.6, 15633.6, 14665.6, 13653.2, 12608.4, 11543.2, 10471.3, 9405.22, 8356.25, 7335.16, 6353.92, 5422.8, 4550.21, 3743.46, 3010.15, 2356.2, 1784.85, 1297.66, 895.194, 576.314, 336.772, 162.043, 54.2083, 6.57563, 0.00316, 0, 0, 0, 0, 0, 0, 0, 0, 0 ... 84 more values } # ibmfloat pv 769-896 pl = (64,128) { 20, 27, 36, 40, 45, 50, 60, 64, 72, 75, 80, 90, 90, 96, 100, 108, 108, 120, 120, 120, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 120, 120, 120, 108, 108, 100, 96, 90, 90, 80, 75, 72, 64, 60, 50, 45, 40, 36, 27, 20 } # unsigned pl ====================== SECTION_4 ( length=9182, padding=0 ) ====================== 1-3 section4Length = 9182 ( 0x00 0x23 0xDE ) 4 dataFlag = 0 [00000000] 5-6 binaryScaleFactor = 0 ( 0x00 0x00 ) 7-10 referenceValue = 17402.8 11 numberOfBitsContainingEachPackedValue = 12 ( 0x0C ) [nbp, numberOfBits, bitsPerValue] 12-9182 values = (6114,9171) { 203.778, 203.468, 202.958, 202.348, 201.758, 201.278, 200.888, 200.558, 200.268, 200.078, 200.068, 200.318, 200.808, 201.458, 202.138, 202.758, 203.248, 203.588, 203.798, 203.878, 205.968, 205.418, 204.438, 203.218, 202.008, 201.128, 200.708, 200.598, 200.478, 200.228, 199.908, 199.528, 199.108, 198.708, 198.528, 198.748, 199.458, 200.488, 201.548, 202.478, 203.358, 204.178, 204.808, 205.198, 205.508, 205.838, 206.068, 207.338, 206.488, 205.198, 203.798, 202.548, 201.528, 200.848, 200.638, 200.818, 201.028, 200.888, 200.308, 199.638, 199.228, 199.018, 198.738, 198.328,
2.8 grib_debug
197.868, 197.358, 196.928, 196.858, 197.348, 201.538, 202.288, 203.338, 204.438, 205.158, 207.008, 207.468, 207.638, 207.178, 206.658, 201.338, 200.298, 199.938, 200.318, 200.608, 198.278, 197.708, 197.558, 197.318 ... 6014 more values } # data_g1simple_packing values ====================== SECTION_5 ( length=4, padding=0 ) 1-4 7777 = 7777 198.368, 205.558, 205.398, 200.478, 199.638, 205.938, 203.788, 200.008,
23
200.758, 206.438, 202.468, 199.208,
======================
How to obtain all the key names available in a grib le. grib_dump -D ../data/regular_latlon_surface.grib1
***** FILE: ../data/regular_latlon_surface.grib1 ====================== MESSAGE 1 ( length=1100 ) ====================== 0-0 constant oneConstant = 1 0-0 constant oneMillionConstant = 1000000 0-0 offset_file offset = 0 0-0 count_file count = 1 0-0 count_total countTotal = 1 0-0 lookup kindOfProduct = 1196575042 [GRIB 1196575042 0-4] 0-0 lookup GRIBEditionNumber = 1 [? 1 7-1] ======> section GRIB (1100,1100,0) 0-0 constant grib1divider = 1000 0-0 constant ieeeFloats = 0 0-0 transient dummy = 1 ======> section section_0 (0,0,0) ----> label empty <===== section section_0 0-4 ascii identifier = GRIB 4-7 g1_message_length totalLength = 1100 7-8 unsigned editionNumber = 1 [ls.edition] ======> section section_1 (52,52,0) 8-8 constant ECMWF = 98 8-8 position offsetSection1 = 8 8-11 section_length section1Length = 52 11-12 unsigned gribTablesVersionNo = 128 [table2Version] 12-13 codetable identificationOfOriginatingGeneratingCentre = 98 [European Center for Medium-Range W 13-14 unsigned generatingProcessIdentifier = 128 [generatingProcessIdentificationNumber, process] 14-15 unsigned gridDefinition = 255 15-16 codeflag section1Flags = 128 [10000000:(1=1) Section 2 included;(2=0) Section 3 omited:grib1 16-17 codetable indicatorOfParameter = 167 [2T 2 metre temperature K (grib1/2.98.128.table) ] 17-17 sprintf marsParam = 167.128 [mars.param, ls.param] 17-18 codetable indicatorOfTypeOfLevel = 1 [Surface (of the Earth, which includes sea surface) (grib 18-20 unsigned lev = 0 [topLevel, bottomLevel, ls.level, mars.levelist] 20-21 unsigned yearOfCentury = 7 21-22 unsigned month = 3 22-23 unsigned day = 18 23-24 unsigned hour = 12 24-25 unsigned minute = 0 25-25 constant second = 0 25-26 codetable indicatorOfUnitOfTimeRange = 1 [Hour (grib1/4.table) ] 26-27 unsigned periodOfTime = 0 [P1] 27-28 unsigned periodOfTimeIntervals = 0 [P2] 28-29 codetable timeRangeIndicator = 0 [Forecast product valid at reference time + P1 (P1>0) (grib1/ 29-31 unsigned numberIncludedInAverage = 0 31-32 unsigned numberMissingFromAveragesOrAccumulations = 0 32-33 unsigned centuryOfReferenceTimeOfData = 21 33-34 codetable identificationOfOriginatingGeneratingSubCentre = 0 [Absent (grib1/0.table) ] [subCen 34-36 signed decimalScaleFactor = 0 36-36 transient setLocalDefinition = 0 36-48 pad reservedNeedNotBePresent = 12 { 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 } # pad reservedNeedNotBePresent 48-48 g1date dataDate = 20070318 [mars.date, ls.date] 48-48 evaluate year = 2007
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
24
Tools
48-48 g1monthlydate monthlyDate = 20070301 48-48 time dataTime = 1200 [mars.time] 48-48 g1startstep marsStartStep = 0 [mars.startStep] 48-48 g1endstep marsEndStep = 0 [mars.endStep] 48-48 g1step marsStep = 0 [mars.step, ls.step, forecastTime] 48-48 g1verificationdate verificationDate = 20070318 48-48 g1monthlydate monthlyVerificationDate = 20070301 48-48 g1day_of_the_year_date dayOfTheYearDate = 2007-078 48-48 constant wrongPadding = 0 48-48 constant localUsePresent = 1 48-48 g1param parameter = 167 48-49 unsigned localDefinitionNumber = 1 ======> section localDefinition (11,11,0) ======> section mars_labeling (8,8,0) 49-50 codetable marsClass = 1 [Operational archive (mars/class.table) ] [mars.class] 50-51 codetable marsType = 2 [Analysis (mars/type.table) ] [ls.dataType, mars.type] 51-53 codetable marsStream = 1025 [Atmospheric model (mars/stream.table) ] [mars.stream] 53-57 ksec1expver experimentVersionNumber = 0001 [mars.expver] 57-57 constant SimulationsOf30Days = s3 57-57 constant TYPE_S3 = 22 <===== section mars_labeling 57-58 unsigned perturbationNumber = 0 58-59 unsigned numberOfForecastsInEnsemble = 0 59-60 pad padding_local1_1 = 1 { 00 } # pad padding_local1_1 <===== section localDefinition 60-60 transient centreForTableNumber = 98 60-60 section_padding localExtensionPadding = 0 {} 60-60 section_padding section1Padding = 0 {} 60-60 padtoeven evenpadding_sec1 = 0 {} 60-60 concept grib1_short_name = 2T [ls.short_name] 60-60 concept grib1_name = 2_metre_temperature [name] 60-60 concept grib1_units = K [units] <===== section section_1 60-60 bit gridDescriptionSectionPresent = 1 [GDSPresent] 60-60 bit bitmapPresent = 0 [bitmapSectionPresent] ======> section section_2 (32,32,0) 60-60 position offsetSection2 = 60 60-63 section_length section2Length = 32 63-64 unsigned numberOfVerticalCoordinateValues = 0 [NV, numberOfCoordinatesValues] 64-64 constant neitherPresent = 255 64-65 unsigned pvlLocation = 255 65-66 codetable dataRepresentationType = 0 [Latitude/Longitude Grid (grib1/6.table) ] ======> section dataRepresentation (22,22,0) 66-66 constant gridDefinitionTemplateNumber = 0 66-68 unsigned numberOfPointsAlongAParallel = 16 [Ni] 68-70 unsigned numberOfPointsAlongAMeridian = 31 [Nj] 70-73 signed latitudeOfFirstGridPoint = 60000 [La1] 73-73 scale latitudeOfFirstGridPointInDegrees = 60 [geography.laFirst] 73-76 signed longitudeOfFirstGridPoint = 0 [Lo1] 76-76 scale longitudeOfFirstGridPointInDegrees = 0 [geography.loFirst] 76-77 codeflag resolutionAndComponentFlags = 128 [10000000:(1=1) Direction increments given;(2=0 77-77 bit ijDirectionIncrementGiven = 1 [iDirectionIncrementGiven, jDirectionIncrementGiven, DiGi 77-77 bit earthIsOblate = 0 77-77 bit resolutionAndComponentFlags3 = 0 77-77 bit resolutionAndComponentFlags4 = 0 77-77 bit uvRelativeToGrid = 0 77-77 bit resolutionAndComponentFlags6 = 0 77-77 bit resolutionAndComponentFlags7 = 0 77-77 bit resolutionAndComponentFlags8 = 0 77-80 signed latitudeOfLastGridPoint = 0 [La2] 80-80 scale latitudeOfLastGridPointInDegrees = 0 [geography.laLast] 80-83 signed longitudeOfLastGridPoint = 30000 [Lo2] 83-83 transient longitudeOfLastGridPointG1to2 = 30000 83-83 scale longitudeOfLastGridPointInDegrees = 30 [geography.loLast] 83-85 unsigned iDirectionIncrement = 2000 [Di]
2.8 grib_debug
25
85-87 unsigned jDirectionIncrement = 2000 [Dj] 87-88 codeflag scanningMode = 0 [00000000:(1=0) Points scan in +i direction;(2=0) Points scan i 88-88 bit iScansNegatively = 0 88-88 bit jScansPositively = 0 88-88 bit jPointsAreConsecutive = 0 88-88 constant iScansPositively = 1 88-88 bit scanningMode4 = 0 88-88 bit scanningMode5 = 0 88-88 bit scanningMode6 = 0 88-88 bit scanningMode7 = 0 88-88 bit scanningMode8 = 0 88-88 latlon_increment jDirectionIncrementInDegrees = 2 [geography.jInc, geography.gridNorthSouth 88-88 latlon_increment iDirectionIncrementInDegrees = 2 [geography.iInc, geography.gridWestEast] ----> iterator ITERATOR <===== section dataRepresentation 88-88 position endGridDefinition = 88 88-88 transient PVPresent = 0 88-88 position offsetBeforePV = 88 88-88 position offsetBeforePL = 88 88-88 transient PLPresent = 0 [reducedGrid] 88-92 padto padding_sec2_1 = 4 { 00, 00, 00, 00 } # padto padding_sec2_1 92-92 padtoeven padding_sec2_3 = 0 {} <===== section section_2 92-92 position endOfHeadersMaker = 92 92-92 transient missingValue = 9999 92-92 constant tableReference = 0 ======> section section_4 (1004,1004,0) 92-92 position offsetSection4 = 92 92-95 g1_section4_length section4Length = 1004 95-95 g1_half_byte_codeflag halfByte = 8 95-96 codeflag dataFlag = 8 [00001000:(1=0) Grid-point data;(2=0) Simple packing;(3=0) Floating p 96-98 signed binaryScaleFactor = -10 98-102 ibmfloat referenceValue = 269.587 102-103 unsigned numberOfBitsContainingEachPackedValue = 16 [nbp, numberOfBits, bitsPerValue] 103-103 bit sphericalHarmonics = 0 103-103 bit complexPacking = 0 103-103 bit integerPointValues = 0 103-103 bit additionalFlagPresent = 0 ======> section dataValues (993,993,0) 103-103 constant dataRepresentationTemplateNumber = 0 103-103 position offsetBeforeData = 103 103-103 constant bitMapIndicator = 255 103-1096 data_g1simple_packing values = (496,993) { 277.704, 277.797, 278.103, 274.598, 269.587, 278.345, 277.213, 278.19 277.853, 276.747, 274.361, 273.636, 274.593, 273.782, 273.016, 274.316 278.492, 278.792, 278.836, 278.333, 277.389, 278.525, 278.175, 277.255 277.383, 278.047, 277.877, 276.213, 273.99, 278.333, 278.58, 277.642 278.865, 278.997, 278.509, 278.983, 279.527, 279.414, 278.8, 278.749 278.895, 279.056, 278.699, 278.426, 276.601, 277.491, 279.646, 279.198 279.108, 279.156, 279.406, 279.527, 280.344, 280.869, 279.951, 281.621 281.221, 280.676, 281.049, 280.354, 279.025, 278.192, 280.05, 280.375 280.68, 281.269, 281.406, 281.483, 279.454, 280.641, 282.984, 282.578 281.797, 281.542, 281.854, 281.5, 279.917, 280.529, 282.008, 281.102 282.223, 282.727, 280.315, 278.539, 280.066, 280.789, 280.517, 282.883 283.897, 285.161, 285.779, 285.847, 281.973, 282.869, 281.926, 280.816 282.48, 281.894, 281.035, 281.722 ... 396 more values } # data_g1simple_packing values <===== section dataValues 1096-1096 size valuesCount = 496 1096-1096 concept typeOfGrid = regular_ll [ls.gridType] 1096-1096 concept typeOfPacking = grid_simple [ls.packingType, dataRepresentation] 1096-1096 padtoeven padding_sec4_1 = 0 {} <===== section section_4 ======> section section_5 (4,4,0)
26
----> label gribSection5 1096-1096 position offsetSection5 = 1096 1096-1100 ascii 7777 = 7777 <===== section section_5 <===== section GRIB
Tools
int main(int argc,const char** argv) { grib_handle *h = NULL; size_t size = 0; double* v = NULL; FILE* f = NULL; const char* p = NULL; const void* buffer = NULL; if(argc != 2) { fprintf(stderr,"usage: %s out\n",argv[0]); exit(1); } h = grib_handle_new_from_template(NULL,"GRIB2"); if(!h) { fprintf(stderr,"Cannot create grib handle\n"); exit(1); }
/* empty */ GRIB_CHECK(grib_set_long(h,"editionNumber",1),0); GRIB_CHECK(grib_set_long(h,"gribTablesVersionNo",128),0); /* 98 = European Center for Medium-Range Weather Forecasts (grib1/0.table) */ GRIB_CHECK(grib_set_long(h,"identificationOfOriginatingGeneratingCentre",98),0); GRIB_CHECK(grib_set_long(h,"generatingProcessIdentifier",128),0); GRIB_CHECK(grib_set_long(h,"gridDefinition",255),0); /* 128 = 10000000 (1=1) Section 2 included (2=0) Section 3 omited See grib1/1.table */ GRIB_CHECK(grib_set_long(h,"section1Flags",128),0);
/* 1 = Surface (of the Earth, which includes sea surface) (grib1/3.table) GRIB_CHECK(grib_set_long(h,"indicatorOfTypeOfLevel",1),0); GRIB_CHECK(grib_set_long(h,"lev",0),0); GRIB_CHECK(grib_set_long(h,"yearOfCentury",7),0); GRIB_CHECK(grib_set_long(h,"month",3),0); GRIB_CHECK(grib_set_long(h,"day",18),0); GRIB_CHECK(grib_set_long(h,"hour",12),0); GRIB_CHECK(grib_set_long(h,"minute",0),0);
*/
2.8 grib_debug
27
/* 1 = Hour (grib1/4.table) */ GRIB_CHECK(grib_set_long(h,"indicatorOfUnitOfTimeRange",1),0); GRIB_CHECK(grib_set_long(h,"periodOfTime",0),0); GRIB_CHECK(grib_set_long(h,"periodOfTimeIntervals",0),0); /* 0 = Forecast product valid at reference time + P1 (P1>0) (grib1/5.table) GRIB_CHECK(grib_set_long(h,"timeRangeIndicator",0),0); GRIB_CHECK(grib_set_long(h,"numberIncludedInAverage",0),0); GRIB_CHECK(grib_set_long(h,"numberMissingFromAveragesOrAccumulations",0),0); GRIB_CHECK(grib_set_long(h,"centuryOfReferenceTimeOfData",21),0); /* 0 = Absent (grib1/0.table) */ GRIB_CHECK(grib_set_long(h,"identificationOfOriginatingGeneratingSubCentre",0),0); GRIB_CHECK(grib_set_long(h,"decimalScaleFactor",0),0); GRIB_CHECK(grib_set_long(h,"localDefinitionNumber",1),0); /* 1 = Operational archive (mars/class.table) GRIB_CHECK(grib_set_long(h,"marsClass",1),0); */ */
/* 1025 = Atmospheric model (mars/stream.table) */ GRIB_CHECK(grib_set_long(h,"marsStream",1025),0); p = "0001"; size = strlen(p)+1; GRIB_CHECK(grib_set_string(h,"experimentVersionNumber",p,&size),0); GRIB_CHECK(grib_set_long(h,"perturbationNumber",0),0); GRIB_CHECK(grib_set_long(h,"numberOfForecastsInEnsemble",0),0); GRIB_CHECK(grib_set_long(h,"numberOfVerticalCoordinateValues",0),0); GRIB_CHECK(grib_set_long(h,"pvlLocation",255),0); /* 0 = Latitude/Longitude Grid (grib1/6.table) */ GRIB_CHECK(grib_set_long(h,"dataRepresentationType",0),0); GRIB_CHECK(grib_set_long(h,"numberOfPointsAlongAParallel",16),0); GRIB_CHECK(grib_set_long(h,"numberOfPointsAlongAMeridian",31),0); GRIB_CHECK(grib_set_long(h,"latitudeOfFirstGridPoint",60000),0); GRIB_CHECK(grib_set_long(h,"longitudeOfFirstGridPoint",0),0); /* 128 = 10000000 (1=1) Direction increments given (2=0) Earth assumed spherical with radius = 6367.47 km (5=0) u and v components resolved relative to easterly and northerly directions See grib1/7.table */ GRIB_CHECK(grib_set_long(h,"resolutionAndComponentFlags",128),0); GRIB_CHECK(grib_set_long(h,"latitudeOfLastGridPoint",0),0); GRIB_CHECK(grib_set_long(h,"longitudeOfLastGridPoint",30000),0); GRIB_CHECK(grib_set_long(h,"iDirectionIncrement",2000),0); GRIB_CHECK(grib_set_long(h,"jDirectionIncrement",2000),0); /* 0 = 00000000 (1=0) Points scan in +i direction (2=0) Points scan in -j direction (3=0) Adjacent points in i direction are consecutive See grib1/8.table */ GRIB_CHECK(grib_set_long(h,"scanningMode",0),0);
28
/* ITERATOR */
Tools
/* 8 = 00001000 (1=0) Grid-point data (2=0) Simple packing (3=0) Floating point values are represented (4=0) No additional flags at octet 14 See grib1/11.table */ GRIB_CHECK(grib_set_long(h,"dataFlag",8),0); GRIB_CHECK(grib_set_long(h,"numberOfBitsContainingEachPackedValue",16),0); size = 496; v = (double*)calloc(size,sizeof(double)); if(!v) { fprintf(stderr,"failed to allocate %d bytes\n",size*sizeof(double)); exit(1); } v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ 0] 4] 8] 12] 16] 20] 24] 28] 32] 36] 40] 44] 48] 52] 56] 60] 64] 68] 72] 76] 80] 84] 88] 92] 96] 100] 104] 108] 112] 116] 120] 124] 128] 132] 136] 140] 144] 148] 152] 156] 160] 164] 168] 172] 176] 180] 184] 188] = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 277.704; 269.587; 277.853; 274.593; 278.492; 277.389; 277.383; 273.99; 278.865; 279.527; 278.895; 276.601; 279.108; 280.344; 281.221; 279.025; 280.68; 279.454; 281.797; 279.917; 282.223; 280.066; 283.897; 281.973; 282.48; 279.978; 288.452; 281.466; 284.723; 276.881; 291.798; 284.24; 285.417; 287.031; 289.926; 290.394; 289.132; 287.645; 289.7; 286.208; 289.244; 289.881; 284.105; 289.116; 289.239; 290.301; 289.823; 291.941; v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ 1] 5] 9] 13] 17] 21] 25] 29] 33] 37] 41] 45] 49] 53] 57] 61] 65] 69] 73] 77] 81] 85] 89] 93] 97] 101] 105] 109] 113] 117] 121] 125] 129] 133] 137] 141] 145] 149] 153] 157] 161] 165] 169] 173] 177] 181] 185] 189] = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 277.797; 278.345; 276.747; 273.782; 278.792; 278.525; 278.047; 278.333; 278.997; 279.414; 279.056; 277.491; 279.156; 280.869; 280.676; 278.192; 281.269; 280.641; 281.542; 280.529; 282.727; 280.789; 285.161; 282.869; 281.894; 284.138; 289.882; 284.771; 280.869; 283.388; 291.607; 280.884; 283.823; 287.949; 289.535; 290.294; 287.316; 289.492; 289.189; 291.093; 288.263; 290.215; 290.686; 289.576; 289.525; 289.429; 290.313; 290.783; v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ 2] 6] 10] 14] 18] 22] 26] 30] 34] 38] 42] 46] 50] 54] 58] 62] 66] 70] 74] 78] 82] 86] 90] 94] 98] 102] 106] 110] 114] 118] 122] 126] 130] 134] 138] 142] 146] 150] 154] 158] 162] 166] 170] 174] 178] 182] 186] 190] = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 278.103; 277.213; 274.361; 273.016; 278.836; 278.175; 277.877; 278.58; 278.509; 278.8; 278.699; 279.646; 279.406; 279.951; 281.049; 280.05; 281.406; 282.984; 281.854; 282.008; 280.315; 280.517; 285.779; 281.926; 281.035; 287.234; 287.776; 283.343; 285.693; 287.295; 290.086; 286.866; 289.898; 289.263; 289.817; 287.069; 287.548; 288.956; 287.704; 284.818; 289.545; 289.999; 288.128; 291.8; 289.45; 290.005; 290.792; 290.818; v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ 3] 7] 11] 15] 19] 23] 27] 31] 35] 39] 43] 47] 51] 55] 59] 63] 67] 71] 75] 79] 83] 87] 91] 95] 99] 103] 107] 111] 115] 119] 123] 127] 131] 135] 139] 143] 147] 151] 155] 159] 163] 167] 171] 175] 179] 183] 187] 191] = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 274.598; 278.19; 273.636; 274.316; 278.333; 277.255; 276.213; 277.642; 278.983; 278.749; 278.426; 279.198; 279.527; 281.621; 280.354; 280.375; 281.483; 282.578; 281.5; 281.102; 278.539; 282.883; 285.847; 280.816; 281.722; 287.831; 287.946; 282.477; 284.132; 286.764; 286.769; 284.694; 290.317; 289.869; 287.768; 281.759; 287.181; 286.634; 291.151; 282.097; 290.018; 289.447; 290.241; 286.35; 290.114; 287.195; 286.693; 287.234;
2.8 grib_debug
v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ 192] 196] 200] 204] 208] 212] 216] 220] 224] 228] 232] 236] 240] 244] 248] 252] 256] 260] 264] 268] 272] 276] 280] 284] 288] 292] 296] 300] 304] 308] 312] 316] 320] 324] 328] 332] 336] 340] 344] 348] 352] 356] 360] 364] 368] 372] 376] 380] 384] 388] 392] 396] 400] 404] 408] 412] 416] 420] 424] 428] 432] 436] 440] 444] 448] 452] 456] = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 287.001; 287.182; 290.056; 290.502; 290.326; 294.048; 291.478; 290.126; 291.05; 293.301; 292.629; 296.16; 294.69; 292.863; 296.665; 297.105; 298.003; 295.811; 299.167; 296.47; 300.407; 295.676; 300.815; 296.632; 303.051; 301.846; 300.74; 298.443; 306.254; 304.458; 303.514; 297.935; 309.596; 306.11; 304.18; 297.061; 309.837; 307.399; 304.829; 296.397; 311.829; 306.384; 304.673; 297.377; 310.353; 306.711; 304.885; 303.073; 311.264; 305.619; 308.429; 306.15; 309.947; 308.055; 309.219; 306.611; 308.4; 309.778; 308.715; 306.716; 303.033; 309.819; 301.171; 303.189; 302.315; 302.132; 302.355; v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ 193] 197] 201] 205] 209] 213] 217] 221] 225] 229] 233] 237] 241] 245] 249] 253] 257] 261] 265] 269] 273] 277] 281] 285] 289] 293] 297] 301] 305] 309] 313] 317] 321] 325] 329] 333] 337] 341] 345] 349] 353] 357] 361] 365] 369] 373] 377] 381] 385] 389] 393] 397] 401] 405] 409] 413] 417] 421] 425] 429] 433] 437] 441] 445] 449] 453] 457] = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 287.49; 290.49; 289.915; 290.782; 285.912; 291.771; 290.939; 291.021; 291.556; 291.821; 292.25; 290.221; 294.224; 293.005; 298.566; 294.729; 296.402; 297.203; 298.919; 295.208; 301.659; 298.434; 299.277; 294.887; 304.741; 300.793; 301.164; 293.905; 307.698; 303.097; 304.001; 295.495; 308.059; 303.994; 305.511; 296.252; 309.568; 303.002; 303.815; 298.184; 309.43; 304.862; 304.326; 296.722; 309.716; 305.75; 305.735; 300.87; 311.085; 307; 309.358; 305.126; 309.562; 307.565; 310.801; 306.033; 307.615; 311.715; 307.201; 307.307; 302.76; 305.046; 302.783; 304.585; 302.922; 305.953; 304.042; v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ 194] 198] 202] 206] 210] 214] 218] 222] 226] 230] 234] 238] 242] 246] 250] 254] 258] 262] 266] 270] 274] 278] 282] 286] 290] 294] 298] 302] 306] 310] 314] 318] 322] 326] 330] 334] 338] 342] 346] 350] 354] 358] 362] 366] 370] 374] 378] 382] 386] 390] 394] 398] 402] 406] 410] 414] 418] 422] 426] 430] 434] 438] 442] 446] 450] 454] 458] = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 286.791; 290.322; 289.917; 291.367; 290.003; 290.675; 290.555; 291.243; 292.386; 290.157; 294.59; 290.882; 294.332; 292.814; 298.846; 294.968; 295.03; 298.222; 298.372; 294.647; 300.621; 298.906; 298.643; 295.411; 304.555; 302.141; 299.811; 295.545; 307.503; 303.69; 299.346; 295.846; 305.473; 304.602; 300.083; 296.508; 308.175; 303.582; 302.952; 297.765; 307.672; 304.397; 303.948; 298.711; 309.28; 304.74; 307.71; 300.858; 310.432; 306.413; 309.365; 305.611; 309.339; 310.605; 310.525; 307.988; 307.404; 308.409; 310.448; 309.062; 303.071; 309.764; 301.107; 303.709; 302.593; 300.132; 302.175; v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ v[ 195] 199] 203] 207] 211] 215] 219] 223] 227] 231] 235] 239] 243] 247] 251] 255] 259] 263] 267] 271] 275] 279] 283] 287] 291] 295] 299] 303] 307] 311] 315] 319] 323] 327] 331] 335] 339] 343] 347] 351] 355] 359] 363] 367] 371] 375] 379] 383] 387] 391] 395] 399] 403] 407] 411] 415] 419] 423] 427] 431] 435] 439] 443] 447] 451] 455] 459] = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 286.71; 289.957; 290.251; 291.025; 294.341; 291.203; 289.821; 290.761; 293.149; 293.427; 296.421; 290.864; 293.917; 295.443; 298.165; 293.305; 295.649; 297.12; 297.932; 294.034; 297.093; 302.369; 298.381; 293.665; 301.901; 300.521; 298.146; 296.185; 304.62; 303.482; 298.529; 296.122; 305.581; 304.286; 299.69; 298.427; 306.983; 303.765; 301.263; 299.807; 307.068; 303.944; 302.827; 300.744; 308.163; 305.384; 303.764; 302.205; 308.94; 307.649; 307.933; 303.336; 310.316; 308.4; 309.65; 308.941; 308.381; 307.156; 309.24; 309.776; 306.578; 307.857; 300.429; 307.132; 302.476; 301.361; 297.057;
29
30
v[ v[ v[ v[ v[ v[ v[ v[ v[ 460] 464] 468] 472] 476] 480] 484] 488] 492] = = = = = = = = = 296.072; 300.897; 302.709; 303.598; 295.564; 300.801; 302.885; 304.547; 297.975; v[ v[ v[ v[ v[ v[ v[ v[ v[ 461] 465] 469] 473] 477] 481] 485] 489] 493] = = = = = = = = = 296.644; 300.839; 301.495; 304.599; 296.015; 300.724; 305.413; 303.334; 295.379; v[ v[ v[ v[ v[ v[ v[ v[ v[ 462] 466] 470] 474] 478] 482] 486] 490] 494] = = = = = = = = = 296.895; 300.899; 302.248; 299.779; 293.688; 301.204; 305.523; 301.616; 293.83; v[ v[ v[ v[ v[ v[ v[ v[ v[ 463] 467] 471] 475] 479] 483] 487] 491] 495] = = = = = = = = = 296.22; 301.941; 301.468; 297.9; 294.294; 302.463; 303.672; 298.654; 300.082;
Tools
GRIB_CHECK(grib_set_double_array(h,"values",v,size),0); free(v); /* gribSection5 */ /* Save the message */ f = fopen(argv[1],"w"); if(!f) { perror(argv[1]); exit(1); } GRIB_CHECK(grib_get_message(h,&buffer,&size),0); if(fwrite(buffer,1,size,f) != size) { perror(argv[1]); exit(1); } if(fclose(f)) { perror(argv[1]); exit(1); } grib_handle_delete(h); return 0; }
2.9 grib_convert
31
2.9
2.9.1
grib_convert
DESCRIPTION
It converts grib messages applying the rules from a conversion_rules le. The rules are of the type "keyname = value;" and if blocks are allowed as if ( keyname1 == value1 || keyname2 != value2 && keyname3 == value3 ) { keyname4 = value4; }
2.9.2
USAGE
2.9.3
-f
OPTIONS
Force. Force the execution not to fail on error. -M Multi-grib support off. Turn off support for multiple elds in single grib message -g Copy GTS header. -G GRIBEX compatibility mode. -V Version. -7 Does not fail when the message has wrong length -v Verbose.
2.9.4
grib_convert examples
The following grib_convert rules convert all the grib messages contained in the input les in grib edition 2 and if a 2 metre temperature is found also the keys contained in the culy bracket are changed.
editionNumber = 2; if( indicatorOfParameter == 11 && indicatorOfTypeOfLevel == 105) { productDefinitionTemplateNumber = 1; typeOfFirstFixedSurface = 103; scaleFactorOfFirstFixedSurface = 0; scaledValueOfFirstFixedSurface = 2; }
32
Tools
2.10
2.10.1
grib_lter
DESCRIPTION
Apply the rules dened in rules_le to each grib message in the grib les provided as arguments.
2.10.2
USAGE
2.10.3
-f
OPTIONS
Force. Force the execution not to fail on error. -o output_grib_le Output grib is written to ouput_grib_le. If an ouput grib le is required and -o is not used, theouput grib is written to ltered.out -M Multi-grib support off. Turn off support for multiple elds in single grib message -V Version. -g Copy GTS header. -G GRIBEX compatibility mode. -7 Does not fail when the message has wrong length -v Verbose.
2.10.4
grib_lter examples
1. The rules accepted by grib_lter are different from the grib_convert rules due to the kind of work grib_lter it is supposed to do. The main difference between grib_lter and grib_convert is that the convert is a 1 eld in input 1 eld in output tool, while the lter is a 1 eld in input as many eld you need in output. At this aim the lter syntax allows a write in the form: write "lename". So that it is possible repeating as many write you need or using a parametrised write to send the output to many les. The grib_lter processes sequentially all the grib messages contained in the input le and it applies the rules to each one. Since the lename used in the write statement can contain some key values, taken from the grib processed when applying the "write rule", several les are produced in output containing elds with the same value of the keys used in the le name.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
33
Applying this rules_le to the ../data/tigge_pf_ecmwf.grib2 grib le we obtain several les in the ../data/split directory containting elds splitted according their keys values
>grib_filter rules_file ../data/tigge_pf_ecmwf.grib2 >ls ../data/split ecmf_20060619_pf_sfc.grib2 ecmf_20060630_pf_sfc.grib2 ecmf_20070122_pf_pl.grib2 ecmf_20070122_pf_pt.grib2 ecmf_20070122_pf_pv.grib2 ecmf_20070122_pf_sfc.grib2
2. The key values in the le name can also be obtained in a different format by indicating explicitly the type required after a colon. :l for long :d for double :s for string The following statement works in a slightly different way from the previous example, including in the output le name the long values for centre and dataType.
write "../data/split/[centre:l]_[date]_[dataType:l]_[levelType].grib[editionNumber]";
3. Other statements are allowed in the grib_lter syntax: if ( condition ) { statement;} The condition can be made using ==,!= and joining single block conditions with || and && The statement can be any valid statement also another nested condition set keyname = keyvalue; print "string to print also with key values like in the le name" transient keyname1 = keyname2; comments beginning with # A complex example of grib_lter rules is the following to change temperature in a grib edition 1 le.
# Temperature if ( level == 850 && indicatorOfParameter == 11 ) { print "found indicatorOfParameter=[indicatorOfParameter] level=[level] date=[date]"; transient oldtype = type ; set identificationOfOriginatingGeneratingSubCentre=98; set gribTablesVersionNo = 128;
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
34
Tools
set indicatorOfParameter = 130; set localDefinitionNumber=1; set marsClass="od"; set marsStream="kwbc"; # Negatively/Positively Perturbed Forecast if ( oldtype == 2 || oldtype == 3 ) { set marsType="pf"; set experimentVersionNumber="4001"; } # Control Forecast if ( oldtype == 1 ) { set marsType="cf"; set experimentVersionNumber="0001"; } set numberOfForecastsInEnsemble=11; write; print "indicatorOfParameter=[indicatorOfParameter] level=[level] date=[date]"; print; }
2.11 grib_compare
35
2.11
2.11.1
grib_compare
DESCRIPTION
Compare grib messages contained in two les. If some differences are found it fails returning an error code. Floating point values are compared exactly by default, different tolerance can be dened see -P -A -R. Default behaviour: absolute error=0, bit-by-bit compare, same order in les.
2.11.2
USAGE
2.11.3
-r
OPTIONS
Compare les in which the messages are not in the same order. This option is time expensive. -b key,key,... All the keys in this list are skipped in the comparison. Bit-by-bit compare on. -e edition independent compare. It is used to compare grib edition 1 and 2. -c key[:l/d/s/n],key[:l/d/s/n],... Only the listed keys or namespaces (:n) are compared. The optional letter after the colon is used to force the type in the comparison: l->integer, d->oat, s->string, n->namespace. See -a option. Incompatible with -H option. -a -c option modier. The keys listed with the option -c will be added to the list of keys compared without -c. -H Compare only message headers. Bit-by-bit compare on. Incompatible with -c option. -R key1=relative_error1,key2=relative_error2,... Compare oating point values using the relative error as tolerance. key1=relative_error will compare key1 using relative_error1. all=relative_error will compare all the oating point keys using relative_error. Default all=0. -A absolute error Compare oating point values using the absolute error as tolerance. Default is absolute error=0 -P Compare data values using the packing error as tolerance. -T factor Compare data values using factor multipied by the tolerance specied in options -P -R -A. -w key[:{s/d/l}]{=/!=}value,key[:{s/d/l}]{=/!=}value,... Where clause. Grib messages are processed only if they match all the key/value constraints. A valid constraint is of type key=value or key!=value. For each key a string (key:s) or a double (key:d) or a long
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
36 (key:l) type can be specied. Default type is string. -f Force. Force the execution not to fail on error. -V Version. -7 Does not fail when the message has wrong length -v Verbose.
Tools
2.11.4
grib_compare examples
1. The default behaviour for grib_compare without any option is to perform a bit by bit comparison of the two messages. If the messages are found to be bitwise different then grib_compare switches to a "key based" mode to nd out which coded keys are different. To see how grib_compare works we rst set the shortName=2d (2 metre dew point temperature) in the le regular_latlon_surface.grib1
>grib_set -s shortName=2d regular_latlon_surface.grib1 2d.grib1
-- GRIB #1 -- shortName=2t paramId=167 stepRange=0 levelType=sfc level=0 packingType=grid_simple grid long [indicatorOfParameter]: [167] != [168]
In the output we see that the only "coded" key with different values in the two messages is indicatorOfParameter which is the relevant key for the parameter information. The comparison can be forced to be successful listing the keys with different values in the -b option.
>grib_compare -b indicatorOfParameter regular_latlon_surface.grib1 2d.grib1
2. Two grib messages can be very different because they have different edition, but they can contain the same identical information in the header and the same data. To see how grib_compare can help in comparing messages with different edition we do
>grib_set edition=2 reduced_gaussian_model_level.grib1 reduced_gaussian_model_level.grib2
-- GRIB #1 -- shortName=t paramId=130 stepRange=0 levelType=ml level=1 packingType=grid_simple gridTy long [totalLength]: [10908] != [10996] long [editionNumber]: [1] != [2] long [section1Length]: [52] != [21] [table2Version] not found in 2nd field [gridDefinition] not found in 2nd field [indicatorOfParameter] not found in 2nd field [indicatorOfTypeOfLevel] not found in 2nd field [yearOfCentury] not found in 2nd field [unitOfTimeRange] not found in 2nd field
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
2.11 grib_compare
[P1] not found in 2nd field [P2] not found in 2nd field [numberIncludedInAverage] not found in 2nd field [numberMissingFromAveragesOrAccumulations] not found in 2nd field [centuryOfReferenceTimeOfData] not found in 2nd field [reservedNeedNotBePresent] not found in 2nd field [localDefinitionNumber] not found in 2nd field [perturbationNumber] not found in 2nd field [numberOfForecastsInEnsemble] not found in 2nd field [padding_local1_1] not found in 2nd field long [section2Length]: [896] != [17] [pvlLocation] not found in 2nd field [dataRepresentationType] not found in 2nd field long [latitudeOfFirstGridPoint]: [87864] != [87864000] long [latitudeOfLastGridPoint]: [-87864] != [-87864000] long [longitudeOfLastGridPoint]: [357188] != [357188000] [padding_grid4_1] not found in 2nd field long [section4Length]: [9948] != [770] [dataFlag] not found in 2nd field
37
It is clear that the two messages are coded in a very different way. If we now add the -e option, the tool will compare only the higher level information common between the two messages.
>grib_compare -e reduced_gaussian_model_level.grib1 reduced_gaussian_model_level.grib2
The comparison is successful because the two messages contain the same information coded in two different ways. We can display the list of keys used by grib_compare adding the option -v (verbose).
>grib_compare -ve reduced_gaussian_model_level.grib1 reduced_gaussian_model_level.grib2 reduced_gaussian_model_level.grib2 comparing centre as string comparing paramId as string comparing shortName as string comparing typeOfLevel as string comparing level as long comparing pv as double (184 values) tolerance=0 comparing latitudeOfFirstGridPointInDegrees as double (1 values) tolerance=0.0005 comparing longitudeOfFirstGridPointInDegrees as double (1 values) tolerance=0.0005 comparing latitudeOfLastGridPointInDegrees as double (1 values) tolerance=0.0005 comparing longitudeOfLastGridPointInDegrees as double (1 values) tolerance=0.0005 comparing iDirectionIncrementInDegrees is set to missing in both fields comparing iScansNegatively as long comparing jScansPositively as long comparing jPointsAreConsecutive as long comparing pl as long comparing gridType as string comparing packedValues as double (6114 values) tolerance=0 comparing param as string comparing levtype as string comparing levelist as long comparing date as long comparing time as long comparing step as long comparing class as long comparing type as long comparing stream as long comparing expver as string comparing domain as string 1 of 1 grib messages in reduced_gaussian_model_level.grib2 1 of 1 total grib messages in 1 files
For each key the type used in the comparison is reported and for the oating point keys also the tolerance used is printed.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
38
Tools 3. Some options are provided to compare only a set of keys in the messages. The option -H is used to compare only the headers coded in the message, it doesnt compare the data values. The option "-c key1:[l/d/s/n],key2:[l/d/s/n],... " can be used to compare a set of keys or namespaces. The letter after the colon is optional and it is used to force the type used in the comparison which is otherwise assumed to be the native type of the key. The possible types are: :l -> integer (C type long) :d -> oating point (C type double) :s -> string :n -> namespace. When the type "n" is used all the set of keys belonging to the specied namespace are compared assuming their own native type. To illustrate how these options work we change the values coded in a message using grib_lter with the following rules le (see grib_lter).
set bitsPerValue=10; set values={1,2.5,3,4,5,6,70}; write "first.grib1"; set values={1,2.5,5,4,5,6,70}; write "second.grib1";
We rst compare the two les using the -H option (only headers are compared).
>grib_compare -H first.grib1 second.grib1
The comparison is successful because the data are not compared. To compare only the data we have to compare the "data namespace".
>grib_compare -c data:n first.grib1 second.grib1
-- GRIB #1 -- shortName=t paramId=130 stepRange=0 levelType=ml level=1 packingType=grid_simple gridTy double [packedValues]: 1 out of 7 different, max absolute diff. = 2, relative diff. = 0.4 max diff. element 2: 3.00000000000000000000e+00 5.00000000000000000000e+00 tolerance=0 packingError: [0.04] [0.04] values max= [70.04] [70.04] min= [1] [1]
The comparison is showing that one of seven values is different in a comparison with the (default) absolute tolerance=0. We can change the tolerance with the -A option:
>grib_compare -A 2 -c data:n first.grib1 second.grib1
and we see that the comparison is successful if the absolute tolerance is set to 2. We can also set the relative tolerance for each key with the option -R:
>grib_compare -R packedValues=0.4 -c data:n first.grib1 second.grib1
and we get again a successful comparison because the relative tolerance is bigger than the relative absolute difference of two corresponding values. Another possible choice for the tolerance is to be equal to the packingError, which is the error due to the packing algorithm. If we change the decimalPrecision of a packed eld we introduce a packing error sometimes bigger than the original packing error.
>grib_set -s changeDecimalPrecision=0 first.grib1 third.grib1
2.11 grib_compare
>grib_compare -P -c data:n first.grib1 third.grib1
39
the comparison is successful because their difference is within the biggest of the two packing error. With the option -P the comparison is failing only if the original data coded are different, not if the packing precision is changed. If we try again to compare the elds without the -P option:
>grib_compare -c data:n first.grib1 third.grib1
-- GRIB #1 -- shortName=t paramId=130 stepRange=0 levelType=ml level=1 packingType=grid_simple gridTy double [packedValues]: 4 out of 7 different, max absolute diff. = 0.48, relative diff. = 0.16 max diff. element 1: 2.52000000000000001776e+00 3.00000000000000000000e+00 tolerance=0 packingError: [0.04] [0.5] values max= [70.04] [70] min= [1] [1]
we see that some values are different and that the maximum absolute differenc is close to the biggest packing error (max diff=0.48 packingError=0.5). The packing error was chosen to be 0.5 by setting decimalPrecision to 0 which means that we dont need to preserve any decimal gure. 4. When we already know that the elds are not numerically identical, but have similar statistical characteristics we can compare their statistics namespaces:
>grib_compare -c statistics:n first.grib1 third.grib1
-- GRIB #1 -- shortName=t paramId=130 stepRange=0 levelType=ml level=1 packingType=grid_simple gridTy double [max]: [7.00400000000000062528e+01] != [7.00000000000000000000e+01] absolute diff. = 0.04, relative diff. = 0.000571102 tolerance=0 double [avg]: [1.30914285714285707485e+01] != [1.31428571428571423496e+01] absolute diff. = 0.0514286, relative diff. = 0.00391304 tolerance=0 double [sd]: [2.32994686809877009637e+01] != [2.32589679873534969090e+01] absolute diff. = 0.0405007, relative diff. = 0.00173827 tolerance=0 double [skew]: [-1.41592875700515623549e+01] != [-1.41669971380493855406e+01] absolute diff. = 0.00770957, relative diff. = 0.000544192 tolerance=0 double [kurt]: [7.32364710785659567271e-01] != [7.32723797489455375143e-01] absolute diff. = 0.000359087, relative diff. = 0.000490071 tolerance=0
and we see that maximum, minimum, average, standard deviation, skewness and kurtosis are compared. While the values are different by 0.48 the statistics comparison shows that the difference in the statistical values is never bigger than 0.052
>grib_compare -A 0.052 -c statistics:n first.grib1 third.grib1
The statistics namespace is available also for spherical harmonics data and provides information about the eld in the geographic space computing them in the spectral space for performance reasons. 5. When a le contains several elds and some keys are different, it is useful to have a summary report of the keys found different in the messages. This can be obtained with the option -f. We change few keys in a le:
>grib_set -w typeOfLevel=surface -s step=48 tigge_pf_ecmwf.grib2 out.grib2
40
>grib_compare -f tigge_pf_ecmwf.grib2 out.grib2
Tools
-- GRIB #9 -- shortName=skt paramId=235 stepRange=96 levelType=sfc level=0 packingType=grid_simple gr long [forecastTime]: [96] != [48]
-- GRIB #10 -- shortName=sd paramId=228141 stepRange=96 levelType=sfc level=0 packingType=grid_simple long [forecastTime]: [96] != [48]
-- GRIB #11 -- shortName=sf paramId=228144 stepRange=0-96 levelType=sfc level=0 packingType=grid_simp long [dayOfEndOfOverallTimeInterval]: [26] != [24] long [lengthOfTimeRange]: [96] != [48] ... ## ## ## ## ## ## ## ## output deleted ERRORS SUMMARY ####### Summary of different key values forecastTime ( 3 different ) dayOfEndOfOverallTimeInterval ( 11 different ) lengthOfTimeRange ( 11 different ) 14 different messages out of 38
we get a list of all the different messages in the les and a summary report of the different keys. 6. We can change the order of the messages in a le using grib_copy with the -B option:
>grib_copy -B typeOfLevel tigge_pf_ecmwf.grib2 out.grib2
-- GRIB #1 -- shortName=10u paramId=165 stepRange=96 levelType=sfc level=10 packingType=grid_simple g long [discipline]: [0] != [2] long [totalLength]: [1555] != [990] long [parameterCategory]: [2] != [0] long [parameterNumber]: [2] != [22] long [scaledValueOfFirstFixedSurface]: [10] != [0] long [typeOfSecondFixedSurface]: [255] != [106] scaleFactorOfSecondFixedSurface is set to missing in 1st field is not missing in 2nd field scaledValueOfSecondFixedSurface is set to missing in 1st field is not missing in 2nd field long [numberOfValues]: [684] != [239] double [referenceValue]: [-1.57229328155517578125e+01] != [4.15843811035156250000e+01] absolute diff. = 57.3073, relative diff. = 1.3781 tolerance=3.8147e-06 long [binaryScaleFactor]: [-10] != [-15] long [bitsPerValue]: [16] != [24] long [section6Length]: [6] != [92] long [bitMapIndicator]: [255] != [0] long [section7Length]: [1373] != [722] [codedValues] has different size: 1st field: 684, 2nd field: 239 ... very long output
the comparison is failing because of the different order of the messages. We can use the -r option to compare the les assuming that the messages are not in the same order:
>grib_compare -r tigge_pf_ecmwf.grib2 out.grib2
and we have a successful comparison because for each message in the rst le an identical message is found in the second le. This option should be used carefully as it is very time expensive.
2.12 grib_keys
41
2.12
2.12.1
grib_keys
DESCRIPTION
Lists the keys available for a type of grib (-T option) or in a grib message from a le (-F option).
2.12.2
USAGE
grib_keys [options]
2.12.3
-T type
OPTIONS
To print the keys available in the given grib type. For a list of the availeble types see -L option. -F le To print the keys available in the grib le. -x Print the extended set of keys. -c Print only coded keys. -L List of available types. -t Print type information. -a Dump aliases.
2.12.4
grib_keys examples
42
regular_ll_sfc_grib2 regular_ll_pl_grib1 regular_ll_pl_grib2 sh_ml_grib1 sh_ml_grib2 sh_pl_grib1 sh_pl_grib2
Tools
2.12 grib_keys
integerPointValues additionalFlagPresent typeOfPacking values numberOfCodedValues (read only) max (read only) min (read only) average (read only) numberOfMissing (read only) typeOfGrid getNumberOfValues (read only) ====> SECTION 5 <====
43
44
Tools
2.13
2.13.1
grib_copy
DESCRIPTION
2.13.2
USAGE
2.13.3
-f
OPTIONS
Force. Force the execution not to fail on error. -r Repack data. Sometimes after setting some keys involving properties of the packing algorithm a repacking of data is needed. This repacking is performed setting this -r option. -p key[:{s/d/l}],key[:{s/d/l}],... Declaration of keys to print. For each key a string (key:s) or a double (key:d) or a long (key:l) type can be requested. Default type is string. -P key[:{s/d/l}],key[:{s/d/l}],... As -p adding the declared keys to the default list. -w key[:{s/d/l}]=value,key[:{s/d/l}]=value,... Where clause. Only grib messages matching the key/value constraints are copied to the output_grib_le. For each key a string (key:s) or a double (key:d) or a long (key:l) type can be dened. Default type is string. -B order by directive Order by. The output will be ordered according the order by directive. Order by example: "step asc, centre desc" (step ascending and centre discending) -V Version. -W width Minimum width of each column in output. Default is 10. -M Multi-grib support off. Turn off support for multiple elds in single grib message -g Copy GTS header. -G GRIBEX compatibility mode. -7 Does not fail when the message has wrong length
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
45
2.13.4
grib_copy examples
2. To copy only the elds that are not on pressure levels from a le
> grib_copy -w levtype!=pl ../data/tigge_pf_ecmwf.grib2 out.grib
3. A grib_le with multi eld messages can be converted in single eld messages with a simple grib_copy.
> grib_copy multi.grib simple.grib
46
Tools
Chapter 3
Examples
3.1 Grib API examples
The main features of the grib_api are explained here through some simple examples that can be taken as a starting point to write more complex programs.
3.1.1
Fortran 90
index.f90 how to access a grib le through an index. get.f90 how to get values through the key names. count_messages.f90 count the messages in a le and loop through them. get_pl.f90 how to get the list of number of points for each parallel in reduced grids. get_pv.f90 how to get the list of levels. get_data.f90 how to get latitude/longitude/values. set.f90 how to set values through the key names. set_bitmap.f90 how to set and use a bitmap. set_missing.f90 how to set a missing value in the header. set_pv.f90 how to set the list of levels. samples.f90 how to create a new message from a template. clone.f90 how to clone a message. copy_message.f90 how to copy a message in memory and create a new message. keys_iterator.f90 how to get the names of all the keys dened in a message and how to iterate through them. precision.f90 how to control precision when coding a grib eld. multi_write.f90 how to encode a grib message containing many elds. multi.f90 how to decode a grib message containing many elds.
48 print_data.f90 how to print all the data contained in a grib le. nearest.f90 how to nd the nearest grid points.
Examples
3.1.2
get.c is an example showing how to get values through the key names. set.c is an example illustrating how to set values through the key names. keys_iterator.c explains how to get the names of all the keys dened in a message and how to iterate through them. iterator.c shows how to use an iterator on latitude, longitude, values. precision.c illustrates how to control precision when coding a grib eld. multi.c is an example describing how to decode a grib message containing many elds. print_data.c is an example on how to print all the data contained in a grib le. nearest.c is an example on how to nd the nearest grid points. multi_write.c how to encode a grib message containing many elds. multi.c how to decode a grib message containing many elds.
3.1.3
Fortran 77
get_fortran.F is an example showing how to get values through the key names. set_fortran.F is an example illustrating how to set values through the key names. keys_iterator_fortran.F explains how to get the names of all the keys dened in a message and how to iterate through them. iterator_fortran.F shows how to use an iterator on latitude, longitude, values. precision_fortran.F illustrates how to control precision when coding a grib eld. multi_fortran.F is an example describing how to decode a grib message containing many elds. print_data_fortran.F is an example on how to print all the data contained in a grib le.
3.2
clone.f90
3.2 clone.f90
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 ! ! ! Author: Anne Fouilloux ! ! program clone use grib_api implicit none integer integer integer integer integer character(len=2) double precision, dimension(:,:), allocatable
49
:: :: :: :: :: :: ::
call grib_open_file(infile,../../data/constant_field.grib1,r) call grib_open_file(outfile,out.grib1,w) ! a new grib message is loaded from file ! igrib is the grib id to be used in subsequent calls call grib_new_from_file(infile,igrib_in) call grib_get(igrib_in,"numberOfPointsAlongAParallel", nx) call grib_get(igrib_in,"numberOfPointsAlongAMeridian",ny) allocate(field2D(nx,ny),stat=err) if (err .ne. 0) then print*, Failed to allocate , nx*ny, values STOP end if ! clone the constant field to create 4 new GRIB messages do i=0,18,6 call grib_clone(igrib_in, igrib_out) write(step,(i2)) i ! Careful: stepRange is a string (could be 0-6, 12-24, etc.) ! use adjustl to remove blank from the left. call grib_set(igrib_out,stepRange,adjustl(step)) call generate_field(field2D) ! use pack to create 1D values call grib_set(igrib_out,values,pack(field2D, mask=.true.)) ! write cloned messages to a file call grib_write(igrib_out,outfile) call grib_release(igrib_out) end do call grib_release(igrib_in) call grib_close_file(infile) call grib_close_file(outfile) deallocate(field2D) contains !====================================== subroutine generate_field(gfield2D) double precision, dimension(:,:) :: gfield2D call random_number(gfield2D) end subroutine generate_field !======================================
50
78 79 end program clone
Examples
3.3 copy_message.f90
51
3.3
copy_message.f90
52
Examples
3.4
count_messages.f90
3.4 count_messages.f90
53
63 64 ! get as a real 65 call grib_get(igrib(i), latitudeOfFirstGridPointInDegrees, & 66 latitudeOfFirstPointInDegrees) 67 write(*,*) latitudeOfFirstGridPointInDegrees=, & 68 latitudeOfFirstPointInDegrees 69 70 ! get as a real 71 call grib_get(igrib(i), longitudeOfFirstGridPointInDegrees, & 72 longitudeOfFirstPointInDegrees) 73 write(*,*) longitudeOfFirstGridPointInDegrees=, & 74 longitudeOfFirstPointInDegrees 75 76 ! get as a real 77 call grib_get(igrib(i), latitudeOfLastGridPointInDegrees, & 78 latitudeOfLastPointInDegrees) 79 write(*,*) latitudeOfLastGridPointInDegrees=, & 80 latitudeOfLastPointInDegrees 81 82 ! get as a real 83 call grib_get(igrib(i), longitudeOfLastGridPointInDegrees, & 84 longitudeOfLastPointInDegrees) 85 write(*,*) longitudeOfLastGridPointInDegrees=, & 86 longitudeOfLastPointInDegrees 87 88 89 ! get the size of the values array 90 call grib_get_size(igrib(i),values,numberOfValues) 91 write(*,*) numberOfValues=,numberOfValues 92 93 allocate(values(numberOfValues), stat=iret) 94 ! get data values 95 call grib_get(igrib(i),values,values) 96 call grib_get(igrib(i),min,min_val) ! can also be obtained through minval(values) 97 call grib_get(igrib(i),max,max_val) ! can also be obtained through maxval(values) 98 call grib_get(igrib(i),average,average) ! can also be obtained through maxval(values) 99 100 write(*,*)There are ,numberOfValues, & 101 average is ,average, & 102 min is , min_val, & 103 max is , max_val 104 write(*,*) --------------------- 105 END DO 106 107 DO i=1,n 108 call grib_release(igrib(i)) 109 END DO 110 111 deallocate(values) 112 deallocate(igrib) 113 114 end program get
54
Examples
3.5
get.f90
3.5 get.f90
55
63 call grib_get(igrib, latitudeOfFirstGridPointInDegrees, & 64 latitudeOfFirstPointInDegrees) 65 write(*,*) latitudeOfFirstGridPointInDegrees=, & 66 latitudeOfFirstPointInDegrees 67 68 ! get as a real 69 call grib_get(igrib, longitudeOfFirstGridPointInDegrees, & 70 longitudeOfFirstPointInDegrees) 71 write(*,*) longitudeOfFirstGridPointInDegrees=, & 72 longitudeOfFirstPointInDegrees 73 74 ! get as a real 75 call grib_get(igrib, latitudeOfLastGridPointInDegrees, & 76 latitudeOfLastPointInDegrees) 77 write(*,*) latitudeOfLastGridPointInDegrees=, & 78 latitudeOfLastPointInDegrees 79 80 ! get as a real 81 call grib_get(igrib, longitudeOfLastGridPointInDegrees, & 82 longitudeOfLastPointInDegrees) 83 write(*,*) longitudeOfLastGridPointInDegrees=, & 84 longitudeOfLastPointInDegrees 85 86 87 ! get the size of the values array 88 call grib_get_size(igrib,values,numberOfValues) 89 write(*,*) numberOfValues=,numberOfValues 90 91 allocate(values(numberOfValues), stat=iret) 92 ! get data values 93 call grib_get(igrib,values,values) 94 call grib_get(igrib,min,min_val) ! can also be obtained through minval(values) 95 call grib_get(igrib,max,max_val) ! can also be obtained through maxval(values) 96 call grib_get(igrib,average,average) ! can also be obtained through maxval(values) 97 98 write(*,*)There are ,numberOfValues, & 99 average is ,average, & 100 min is , min_val, & 101 max is , max_val 102 103 call grib_release(igrib) 104 105 call grib_new_from_file(ifile,igrib, iret) 106 107 end do LOOP 108 109 call grib_close_file(ifile) 110 111 deallocate(values) 112 end program get
56
Examples
3.6
get_data.f90
3.6 get_data.f90
63 end do 64 65 66 call grib_close_file(ifile) 67 68 end program
57
58
Examples
3.7
get_pl.f90
How to get the list of number of points for each parallel in reduced grids.
1 ! Copyright 2005-2007 ECMWF 2 ! 3 ! Licensed under the GNU Lesser General Public License which 4 ! incorporates the terms and conditions of version 3 of the GNU 5 ! General Public License. 6 ! See LICENSE and gpl-3.0.txt for details. 7 ! 8 ! 9 ! Description: how to get PL values. 10 ! 11 ! 12 ! Author: Anne Fouilloux 13 ! 14 ! 15 program get_pl 16 use grib_api 17 implicit none 18 integer :: infile 19 integer :: igrib 20 integer :: PLPresent, nb_pl 21 real, dimension(:), allocatable :: pl 22 23 24 call grib_open_file(infile, & 25 ../../data/reduced_gaussian_surface.grib1,r) 26 27 ! a new grib message is loaded from file 28 ! igrib is the grib id to be used in subsequent calls 29 call grib_new_from_file(infile,igrib) 30 31 ! set PVPresent as an integer 32 call grib_get(igrib,PLPresent,PLPresent) 33 print*, "PLPresent= ", PLPresent 34 if (PLPresent == 1) then 35 call grib_get_size(igrib,pl,nb_pl) 36 print*, "there are ", nb_pl, " PL values" 37 allocate(pl(nb_pl)) 38 call grib_get(igrib,pl,pl) 39 print*, "pl = ", pl 40 deallocate(pl) 41 else 42 print*, "There is no PL values in your GRIB message!" 43 end if 44 call grib_release(igrib) 45 46 call grib_close_file(infile) 47 48 end program get_pl
3.8 get_pv.f90
59
3.8
get_pv.f90
60
Examples
3.9
index.f90
3.9 index.f90
63 do i=1,paramIdSize ! loop on paramId 64 ! select paramId=paramId(i) 65 call grib_index_select(idx,paramId,paramId(i)) 66 67 do j=1,numberSize ! loop on number 68 ! select number=number(j) 69 call grib_index_select(idx,number,number(j)) 70 71 do k=1,levelSize ! loop on level 72 ! select level=level(k) 73 call grib_index_select(idx,level,level(k)) 74 75 do l=1,stepSize ! loop on step 76 ! select step=step(l) 77 call grib_index_select(idx,step,step(l)) 78 79 call grib_new_from_index(idx,igrib, iret) 80 do while (iret /= GRIB_END_OF_INDEX) 81 count=count+1 82 call grib_get(igrib,paramId,oparamId) 83 call grib_get(igrib,number,onumber) 84 call grib_get(igrib,level,olevel) 85 call grib_get(igrib,step,ostep) 86 write(*,(A,i3,A,i2,A,i4,A,i3)) paramId=,oparamId,& 87 number=,onumber,& 88 level= ,olevel, & 89 step= ,ostep 90 91 call grib_new_from_index(idx,igrib, iret) 92 end do 93 94 end do ! loop on step 95 end do ! loop on level 96 end do ! loop on number 97 end do ! loop on paramId 98 write(*,(i4,a)) count, messages selected 99 call grib_index_release(idx) 100 101 end program index 102
61
62
Examples
3.10
keys_iterator.f90
How to get the names of all the keys dened in a message and how to iterate through them.
1 ! Copyright 2005-2007 ECMWF 2 ! 3 ! Licensed under the GNU Lesser General Public License which 4 ! incorporates the terms and conditions of version 3 of the GNU 5 ! General Public License. 6 ! See LICENSE and gpl-3.0.txt for details. 7 ! 8 ! 9 ! Description: 10 ! How to use keys_iterator to get all the available 11 ! keys in a message. 12 ! 13 ! Author: Enrico Fucile 14 ! 15 ! 16 program keys_iterator 17 use grib_api 18 implicit none 19 character(len=20) :: name_space 20 integer :: kiter,ifile,igrib,iret 21 character(len=256) :: key 22 character(len=256) :: value 23 character(len=512) :: all 24 integer :: grib_count 25 26 call grib_open_file(ifile, & 27 ../../data/regular_latlon_surface.grib1,r) 28 29 ! Loop on all the messages in a file. 30 31 call grib_new_from_file(ifile,igrib, iret) 32 33 do while (iret /= GRIB_END_OF_FILE) 34 35 grib_count=grib_count+1 36 write(*,*) -- GRIB N. ,grib_count, -- 37 38 ! valid name_spaces are ls and mars 39 name_space=ls 40 41 call grib_keys_iterator_new(igrib,kiter,name_space) 42 43 do 44 call grib_keys_iterator_next(kiter, iret) 45 46 if (iret .ne. 1) exit 47 48 call grib_keys_iterator_get_name(kiter,key) 49 call grib_get(igrib,trim(key),value) 50 all=trim(key)// = // trim(value) 51 write(*,*) trim(all) 52 53 end do 54 55 call grib_keys_iterator_delete(kiter) 56 call grib_release(igrib) 57 call grib_new_from_file(ifile,igrib, iret) 58 end do 59 60 61 call grib_close_file(ifile) 62
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
3.10 keys_iterator.f90
63 end program keys_iterator 64
63
64
Examples
3.11
multi_write.f90
3.12 multi.f90
65
3.12
multi.f90
66
Examples
3.13
nearest.f90
1 ! Copyright 2005-2007 ECMWF 2 ! 3 ! Licensed under the GNU Lesser General Public License which 4 ! incorporates the terms and conditions of version 3 of the GNU 5 ! General Public License. 6 ! See LICENSE and gpl-3.0.txt for details. 7 ! 8 ! 9 ! Description: how to use grib_find_nearest and grib_get_element 10 ! 11 ! 12 ! Author: Enrico Fucile 13 ! 14 ! 15 ! 16 program find 17 use grib_api 18 implicit none 19 integer :: npoints 20 integer :: infile 21 integer :: igrib, ios, i 22 real(8), dimension(:), allocatable :: lats, lons 23 real(8), dimension(:), allocatable :: nearest_lats, nearest_lons 24 real(8), dimension(:), allocatable :: distances, values, lsm_values 25 integer(kind=kindOfInt), dimension(:), allocatable :: indexes 26 real(kind=8) :: value 27 28 ! initialization 29 open( unit=1, file="../../data/list_points",form="formatted",action="read") 30 read(unit=1,fmt=*) npoints 31 allocate(lats(npoints)) 32 allocate(lons(npoints)) 33 allocate(nearest_lats(npoints)) 34 allocate(nearest_lons(npoints)) 35 allocate(distances(npoints)) 36 allocate(lsm_values(npoints)) 37 allocate(values(npoints)) 38 allocate(indexes(npoints)) 39 do i=1,npoints 40 read(unit=1,fmt=*, iostat=ios) lats(i), lons(i) 41 if (ios /= 0) then 42 npoints = i - 1 43 exit 44 end if 45 end do 46 close(unit=1) 47 call grib_open_file(infile, & 48 ../../data/reduced_gaussian_lsm.grib1,r) 49 50 ! a new grib message is loaded from file 51 ! igrib is the grib id to be used in subsequent calls 52 call grib_new_from_file(infile,igrib) 53 54 55 call grib_find_nearest(igrib, .true., lats, lons, nearest_lats, nearest_lons,lsm_values, distances, i 56 call grib_release(igrib) 57 58 call grib_close_file(infile) 59 60 ! will apply it to another GRIB 61 call grib_open_file(infile, & 62 ../../data/reduced_gaussian_pressure_level.grib1,r)
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
3.13 nearest.f90
67
63 call grib_new_from_file(infile,igrib) 64 65 call grib_get_element(igrib,"values", indexes, values) 66 call grib_release(igrib) 67 call grib_close_file(infile) 68 69 do i=1, npoints 70 print*,lats(i), lons(i), nearest_lats(i), nearest_lons(i), distances(i), lsm_values(i), values(i) 71 end do 72 73 deallocate(lats) 74 deallocate(lons) 75 deallocate(nearest_lats) 76 deallocate(nearest_lons) 77 deallocate(distances) 78 deallocate(lsm_values) 79 deallocate(values) 80 deallocate(indexes) 81 82 end program find
68
Examples
3.14
precision.f90
3.14 precision.f90
63 maxa=0 64 maxr=0 65 maxv=values2(1) 66 minv=maxv 67 do i=1,size 68 a=abs(values2(i)-values1(i)) 69 if ( values2(i) .gt. maxv ) maxv=values2(i) 70 if ( values2(i) .lt. maxv ) minv=values2(i) 71 if ( values2(i) .ne. 0 ) then 72 r=abs((values2(i)-values1(i))/values2(i)) 73 endif 74 if ( a .gt. maxa ) maxa=a 75 if ( r .gt. maxr ) maxr=r 76 enddo 77 write(*,*) "max absolute error = ",maxa 78 write(*,*) "max relative error = ",maxr 79 write(*,*) "min value = ",minv 80 write(*,*) "max value = ",maxv 81 82 write(*,*) "old number of bits per value=",bitsPerValue1 83 write(*,*) "new number of bits per value=",bitsPerValue2 84 85 ! write modified message to a file 86 call grib_write(igrib,outfile) 87 88 call grib_release(igrib) 89 90 call grib_close_file(infile) 91 92 call grib_close_file(outfile) 93 94 deallocate(values1) 95 deallocate(values2) 96 end program precision 97
69
70
Examples
3.15
print_data.f90
3.15 print_data.f90
63 64 deallocate(values) 65 66 end program print_data
71
72
Examples
3.16
samples.f90
3.16 samples.f90
63 call grib_set(igribclone,endStep,endStep) 64 65 call grib_set(igribclone,decimalPrecision,decimalPrecision) 66 67 call grib_set(igribclone,values,v) 68 69 call grib_write(igribclone,outfile) 70 71 call grib_new_from_file(datafile,igribdata,err) 72 73 if (err==0) then 74 call grib_get(igribdata,values,v2) 75 76 v2=v2*1000.0 ! different units for the output grib 77 78 v=v2-v1 ! accumulation from startStep to endStep 79 80 v1=v2 ! save previous step field 81 82 startStep=startStep+12 83 endStep=endStep+12 84 85 endif 86 87 enddo 88 89 deallocate(v) 90 deallocate(v1) 91 deallocate(v2) 92 93 call grib_close_file(outfile) 94 95 end program sample
73
74
Examples
3.17
set.f90
3.17 set.f90
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 !====================================== subroutine check_settings(gribid) use grib_api implicit none integer, intent(in) :: gribid integer(kind = 4) character(len = 10) :: int_value :: string_value
75
! get centre as a integer call grib_get(gribid,centre,int_value) write(*,*) "get centre as a integer - centre = ",int_value ! get centre as a string call grib_get(gribid,centre,string_value) write(*,*) "get centre as a string - centre = ",string_value ! get date as a string call grib_get(gribid,dataDate,string_value) write(*,*) "get date as a string - date = ",string_value end subroutine check_settings end program set
76
Examples
3.18
set_bitmap.f90
3.18 set_bitmap.f90
63 values(1:10) = missingValue 64 65 ! set the values (the bitmap will be automatically built) 66 call grib_set(igrib,values, values) 67 68 ! write modified message to a file 69 call grib_write(igrib,outfile) 70 71 ! FREE MEMORY 72 call grib_release(igrib) 73 74 call grib_close_file(infile) 75 76 call grib_close_file(outfile) 77 78 deallocate(values) 79 80 end program set_bitmap
77
78
Examples
3.19
set_missing.f90
3.20 set_pv.f90
79
3.20
set_pv.f90
80
63 call grib_set(igrib,pv,pv) 64 65 ! write modified message to a file 66 call grib_write(igrib,outfile) 67 68 ! FREE MEMORY 69 call grib_release(igrib) 70 deallocate(pv) 71 72 call grib_close_file(outfile) 73 74 end program set_pv
Examples
3.21 get.c
81
3.21
get.c
/* * C Implementation: get * * Description: how to get values using keys. * * Author: Enrico Fucile <[email protected]> * * */ #include <stdio.h> #include <stdlib.h> #include "grib_api.h" int main(int argc, char** argv) { int err = 0; double *values = NULL; size_t values_len= 0; size_t i = 0; double double double double latitudeOfFirstGridPointInDegrees; longitudeOfFirstGridPointInDegrees; latitudeOfLastGridPointInDegrees; longitudeOfLastGridPointInDegrees;
double jDirectionIncrementInDegrees; double iDirectionIncrementInDegrees; long numberOfPointsAlongAParallel; long numberOfPointsAlongAMeridian; double average = 0; FILE* in = NULL; char* filename = "../../data/regular_latlon_surface.grib1"; grib_handle *h = NULL; in = fopen(filename,"r"); if(!in) { printf("ERROR: unable to open file %s\n",filename); return 1; } /* create new handle from a message in a file*/ h = grib_handle_new_from_file(0,in,&err); if (h == NULL) { printf("Error: unable to create handle from file %s\n",filename); } /* get as a long*/ GRIB_CHECK(grib_get_long(h,"numberOfPointsAlongAParallel",&numberOfPointsAlongAParallel),0); printf("numberOfPointsAlongAParallel=%ld\n",numberOfPointsAlongAParallel); /* get as a long*/ GRIB_CHECK(grib_get_long(h,"numberOfPointsAlongAMeridian",&numberOfPointsAlongAMeridian),0); printf("numberOfPointsAlongAMeridian=%ld\n",numberOfPointsAlongAMeridian);
82
Examples
71 72 /* get as a double*/ 73 GRIB_CHECK(grib_get_double(h,"longitudeOfFirstGridPointInDegrees",&longitudeOfFirstGridPointInDegrees 74 printf("longitudeOfFirstGridPointInDegrees=%g\n",longitudeOfFirstGridPointInDegrees); 75 76 /* get as a double*/ 77 GRIB_CHECK(grib_get_double(h,"latitudeOfLastGridPointInDegrees",&latitudeOfLastGridPointInDegrees),0) 78 printf("latitudeOfLastGridPointInDegrees=%g\n",latitudeOfLastGridPointInDegrees); 79 80 /* get as a double*/ 81 GRIB_CHECK(grib_get_double(h,"longitudeOfLastGridPointInDegrees",&longitudeOfLastGridPointInDegrees), 82 printf("longitudeOfLastGridPointInDegrees=%g\n",longitudeOfLastGridPointInDegrees); 83 84 /* get as a double*/ 85 GRIB_CHECK(grib_get_double(h,"jDirectionIncrementInDegrees",&jDirectionIncrementInDegrees),0); 86 printf("jDirectionIncrementInDegrees=%g\n",jDirectionIncrementInDegrees); 87 88 /* get as a double*/ 89 GRIB_CHECK(grib_get_double(h,"iDirectionIncrementInDegrees",&iDirectionIncrementInDegrees),0); 90 printf("iDirectionIncrementInDegrees=%g\n",iDirectionIncrementInDegrees); 91 92 /* get the size of the values array*/ 93 GRIB_CHECK(grib_get_size(h,"values",&values_len),0); 94 95 values = malloc(values_len*sizeof(double)); 96 97 /* get data values*/ 98 GRIB_CHECK(grib_get_double_array(h,"values",values,&values_len),0); 99 100 average = 0; 101 for(i = 0; i < values_len; i++) 102 average += values[i]; 103 104 average /=(double)values_len; 105 106 free(values); 107 108 printf("There are %d values, average is %g\n",(int)values_len,average); 109 110 grib_handle_delete(h); 111 112 fclose(in); 113 return 0; 114 }
3.22 iterator.c
83
3.22
iterator.c
/* * C Implementation: iterator * * Description: how to use an iterator on lat/lon/values. * * * Author: Enrico Fucile <[email protected]> * * */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "grib_api.h" void usage(char* prog) { printf("Usage: %s grib_file\n",prog); exit(1); } int main(int argc, char** argv) { FILE* in = NULL; int err = 0; double lat,lon,value,missingValue=0; int n=0; char* filename = NULL; /* Message handle. Required in all the grib_api calls acting on a message.*/ grib_handle *h = NULL; /* Iterator on lat/lon/values.*/ grib_iterator* iter=NULL; if (argc != 2) usage(argv[0]); filename=strdup(argv[1]); in = fopen(filename,"r"); if(!in) { printf("ERROR: unable to open file %s\n",filename); return 1; } /* Loop on all the messages in a file.*/ while ((h = grib_handle_new_from_file(0,in,&err)) != NULL ) { /* Check of errors after reading a message. */ if (err != GRIB_SUCCESS) GRIB_CHECK(err,0); /* Get the double representing the missing value in the field. */ GRIB_CHECK(grib_get_double(h,"missingValue",&missingValue),0); /* A new iterator on lat/lon/values is created from the message handle h. */ iter=grib_iterator_new(h,0,&err); if (err != GRIB_SUCCESS) GRIB_CHECK(err,0); n = 0; /* Loop on all the lat/lon/values. */ while(grib_iterator_next(iter,&lat,&lon,&value)) { /* You can now print lat and lon, */ printf("- %d - lat=%f lon=%f value=",n,lat,lon);
84
71 /* decide what to print if a missing value is found. */ 72 if (value == missingValue ) printf("missing\n"); 73 /* and print the value if is not missing. */ 74 else printf("%f\n",value); 75 n++; 76 } 77 78 /* At the end the iterator is deleted to free memory. */ 79 grib_iterator_delete(iter); 80 81 /* At the end the grib_handle is deleted to free memory. */ 82 grib_handle_delete(h); 83 } 84 85 86 fclose(in); 87 88 return 0; 89 }
Examples
3.23 keys_iterator.c
85
3.23
keys_iterator.c
keys_iterator.c How to get the names of all the keys dened in a message and how to iterate through them.
1 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
/* * C Implementation: keys_iterator * * Description: * Example on how to use keys_iterator functions and the * grib_keys_iterator structure to get all the available * keys in a message. * * Author: Enrico Fucile <[email protected]> * * */ #include #include #include #include <assert.h> <stdlib.h> <stdio.h> <unistd.h>
static void usage(char* progname); int main(int argc, char *argv[]) { /* To skip read only and not coded keys unsigned long key_iterator_filter_flags=GRIB_KEYS_ITERATOR_SKIP_READ_ONLY || GRIB_KEYS_ITERATOR_SKIP_COMPUTED; */ unsigned long key_iterator_filter_flags=GRIB_KEYS_ITERATOR_ALL_KEYS; /* valid name_spaces are ls and mars */ char* name_space="ls"; /* name_space=NULL to get all the keys */ /* char* name_space=0; */ FILE* f; grib_handle* h=NULL; grib_keys_iterator* kiter=NULL; int err=0; int grib_count=0; char value[MAX_VAL_LEN]; size_t vlen=MAX_VAL_LEN; if (argc != 2) usage(argv[0]); f = fopen(argv[1],"r"); if(!f) { perror(argv[1]); exit(1); } while((h = grib_handle_new_from_file(0,f,&err)) != NULL) { grib_count++; printf("-- GRIB N. %d --\n",grib_count); if(!h) {
86
71 printf("ERROR: Unable to create grib handle\n"); 72 exit(1); 73 } 74 75 kiter=grib_keys_iterator_new(h,key_iterator_filter_flags,name_space); 76 if (!kiter) { 77 printf("ERROR: Unable to create keys iterator\n"); 78 exit(1); 79 } 80 81 while(grib_keys_iterator_next(kiter)) 82 { 83 const char* name = grib_keys_iterator_get_name(kiter); 84 vlen=MAX_VAL_LEN; 85 GRIB_CHECK(grib_get_string(h,name,value,&vlen),name); 86 printf("%s = %s\n",name,value); 87 } 88 89 grib_keys_iterator_delete(kiter); 90 91 } 92 93 return 0; 94 95 } 96 97 static void usage(char* progname) { 98 printf("\nUsage: %s grib_file\n",progname); 99 exit(1); 100 } 101
Examples
3.24 multi.c
87
3.24
multi.c
/* * C Implementation: multi * * Description: How to decode grib messages containing multiple fields. Try to turn on and off multi support to * see the difference. Default is OFF. * For all the tools defalut is multi support ON. * * * * Author: Enrico Fucile <[email protected]> * * */ #include <stdio.h> #include <stdlib.h> #include "grib_api.h" int main(int argc, char** argv) { int err = 0; long parameterCategory=0,parameterNumber=0,discipline=0; FILE* in = NULL; char* filename = "../../data/multi.grib2"; grib_handle *h = NULL; /* turn on support for multi fields messages */ grib_multi_support_on(0); /* turn off support for multi fields messages */ /* grib_multi_support_off(0); */ in = fopen(filename,"r"); if(!in) { printf("ERROR: unable to open file %s\n",filename); return 1; }
while ((h = grib_handle_new_from_file(0,in,&err)) != NULL ) { GRIB_CHECK(err,0); GRIB_CHECK(grib_get_long(h,"discipline",&discipline),0); printf("discipline=%ld\n",discipline); GRIB_CHECK(grib_get_long(h,"parameterCategory",¶meterCategory),0); printf("parameterCategory=%ld\n",parameterCategory); GRIB_CHECK(grib_get_long(h,"parameterNumber",¶meterNumber),0); printf("parameterNumber=%ld\n",parameterNumber); if ( discipline == 0 && parameterCategory==2) { if (parameterNumber == 2) printf("-------- u -------\n"); if (parameterNumber == 3) printf("-------- v -------\n"); } } grib_handle_delete(h); fclose(in); return 0;
88
71 }
Examples
3.25 multi_write.c
89
3.25
multi_write.c
/* * C Implementation: multi * * Description: How to encode grib messages containing multiple fields. * * * Author: Enrico Fucile <[email protected]> * * */ #include <stdio.h> #include <stdlib.h> #include "grib_api.h" void usage(char* prog) { printf("usage: %s in.grib out.grib\n",prog); exit(1); } int main(int argc, char** argv) { int err = 0; FILE* in = NULL; FILE* of = NULL; long step; char* filename=NULL; char* ofilename=NULL; grib_handle *h = NULL; grib_multi_handle *mh=NULL; if (argc < 3) usage(argv[0]); filename=argv[1]; ofilename=argv[2]; /* open input file */ in = fopen(filename,"r"); if(!in) { printf("ERROR: unable to open file %s\n",filename); return 1; } /* new grib handle from input file */ h = grib_handle_new_from_file(0,in,&err); GRIB_CHECK(err,0); /* create a new empty multi field handle */ mh=grib_multi_handle_new(0); if (!mh) { printf("unable to create multi field handle\n"); exit(1); } for (step=12;step<=120;step+=12) { /* set step */ grib_set_long(h,"step",step); /* append h to mh repeating the sections preceding section 4 */ grib_multi_handle_append(h,4,mh); } /* open output file */ of=fopen(ofilename,"w"); if(!of) {
90
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 } printf("ERROR: unable to open file %s\n",ofilename); exit(1); } /* write multi fields handle to output file */ grib_multi_handle_write(mh,of); fclose(of); /* clean memory */ grib_handle_delete(h); grib_multi_handle_delete(mh); fclose(in); return 0;
Examples
3.26 nearest.c
91
3.26
nearest.c
/* * C Implementation: fieldset * * Description: how to use a fieldset. * * * Author: Enrico Fucile <[email protected]> * * */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "grib_api.h" void usage(char* prog) { printf("Usage: %s grib_file grib_file ...\n",prog); exit(1); } int main(int argc, char** argv) { int err = 0; long step=0; size_t nfiles; int i=0; grib_fieldset* set=NULL; grib_handle* h=NULL; char param[20]={0,}; size_t len=20; double lats[4]={0,}; double lons[4]={0,}; double values[4]={0,}; double distances[4]={0,}; int indexes[4]={0,}; char* order_by="param,step"; size_t size=4; double lat=-40,lon=15; int mode=0; int count; char** filenames; grib_nearest* nearest=NULL; if (argc < 2) usage(argv[0]); nfiles=argc-1; filenames=(char**)malloc(sizeof(char*)*nfiles); for (i=0;i<nfiles;i++) filenames[i]=(char*)strdup(argv[i+1]); set=grib_fieldset_new_from_files(0,filenames,nfiles,0,0,0,order_by,&err); GRIB_CHECK(err,0); printf("\nordering by %s\n",order_by); printf("\n%d fields in the fieldset\n",grib_fieldset_count(set)); printf("n,step,param\n"); mode=GRIB_NEAREST_SAME_GRID | count=1; GRIB_NEAREST_SAME_POINT;
92
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 } while ((h=grib_fieldset_next_handle(set,&err))!=NULL) { GRIB_CHECK(grib_get_long(h,"step",&step),0); len=20; GRIB_CHECK(grib_get_string(h,"param",param,&len),0);
Examples
printf("%d %ld %s ",count,step,param); if (!nearest) nearest=grib_nearest_new(h,&err); GRIB_CHECK(err,0); GRIB_CHECK(grib_nearest_find(nearest,h,lat,lon,mode,lats,lons,values,distances,indexes,&size),0); for (i=0;i<4;i++) printf("%d %.2f %.2f %g %g - ", (int)indexes[i],lats[i],lons[i],distances[i],values[i]); printf("\n"); grib_handle_delete(h); count++; } if (nearest) grib_nearest_delete(nearest); if (set) grib_fieldset_delete(set); return 0;
3.27 precision.c
93
3.27
precision.c
/* * C Implementation: precision * * Description: how to control decimal precision when packing fields. * * * Author: Enrico Fucile <[email protected]> * * */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include "grib_api.h" int main(int argc, char** argv) { int err = 0; size_t size=0; FILE* in = NULL; char* infile = "../../data/regular_latlon_surface.grib1"; FILE* out = NULL; char* outfile = "out.grib1"; grib_handle *h = NULL; const void* buffer = NULL; double* values1=NULL; double* values2=NULL; double maxa=0,a=0; double maxv=0,minv=0; double maxr=0,r=0; long decimalPrecision; long bitsPerValue1=0, bitsPerValue2=0; int i=0; in = fopen(infile,"r"); if(!in) { printf("ERROR: unable to open file %s\n",infile); return 1; } out = fopen(outfile,"w"); if(!in) { printf("ERROR: unable to open file %s\n",outfile); return 1; } /* create a new handle from a message in a file */ h = grib_handle_new_from_file(0,in,&err); if (h == NULL) { printf("Error: unable to create handle from file %s\n",infile); } /* bitsPerValue before changing the packing parameters */ GRIB_CHECK(grib_get_long(h,"bitsPerValue",&bitsPerValue1),0); /* get the size of the values array*/ GRIB_CHECK(grib_get_size(h,"values",&size),0); values1 = malloc(size*sizeof(double)); /* get data values before changing the packing parameters*/
94
71 GRIB_CHECK(grib_get_double_array(h,"values",values1,&size),0); 72 73 /* changing decimal precition to 2 means that 2 decimal digits 74 are preserved when packing. */ 75 decimalPrecision=2; 76 GRIB_CHECK(grib_set_long(h,"changeDecimalPrecision",decimalPrecision),0); 77 78 /* bitsPerValue after changing the packing parameters */ 79 GRIB_CHECK(grib_get_long(h,"bitsPerValue",&bitsPerValue2),0); 80 81 values2 = malloc(size*sizeof(double)); 82 /* get data values after changing the packing parameters*/ 83 GRIB_CHECK(grib_get_double_array(h,"values",values2,&size),0); 84 85 /* computing error */ 86 maxa=0; 87 maxr=0; 88 maxv=values2[0]; 89 minv=maxv; 90 for (i=0;i<size;i++) { 91 a=fabs(values2[i]-values1[i]); 92 if ( values2[i] > maxv ) maxv=values2[i]; 93 if ( values2[i] < maxv ) minv=values2[i]; 94 if ( values2[i] !=0 ) r=fabs((values2[i]-values1[i])/values2[i]); 95 if ( a > maxa ) maxa=a; 96 if ( r > maxr ) maxr=r; 97 } 98 printf("max absolute error = %g\n",maxa); 99 printf("max relative error = %g\n",maxr); 100 printf("min value = %g\n",minv); 101 printf("max value = %g\n",maxv); 102 103 printf("old number of bits per value=%ld\n",(long)bitsPerValue1); 104 printf("new number of bits per value=%ld\n",(long)bitsPerValue2); 105 106 /* get the coded message in a buffer */ 107 GRIB_CHECK(grib_get_message(h,&buffer,&size),0); 108 109 /* write the buffer in a file*/ 110 if(fwrite(buffer,1,size,out) != size) 111 { 112 perror(argv[1]); 113 exit(1); 114 } 115 116 /* delete handle */ 117 grib_handle_delete(h); 118 119 fclose(in); 120 fclose(out); 121 122 return 0; 123 } 124
Examples
3.28 set.c
95
3.28
set.c
/* * C Implementation: set * * Description: how to set key values. * * * Author: Enrico Fucile <[email protected]> * * */ #include <stdio.h> #include <stdlib.h> #include "grib_api.h" int main(int argc, char** argv) { int err = 0; long centre=80; long long_value=0; char string_value[100]; size_t len = sizeof(string_value)/sizeof(char); size_t size=0; FILE* in = NULL; char* infile = "../../data/regular_latlon_surface.grib1"; FILE* out = NULL; char* outfile = "out.grib1"; grib_handle *h = NULL; const void* buffer = NULL; in = fopen(infile,"r"); if(!in) { printf("ERROR: unable to open file %s\n",infile); return 1; } out = fopen(outfile,"w"); if(!in) { printf("ERROR: unable to open file %s\n",outfile); return 1; } /* create a new handle from a message in a file */ h = grib_handle_new_from_file(0,in,&err); if (h == NULL) { printf("Error: unable to create handle from file %s\n",infile); } /* set centre as a long */ GRIB_CHECK(grib_set_long(h,"centre",centre),0); /* get centre as a long */ GRIB_CHECK(grib_get_long(h,"centre",&long_value),0); printf("centre long value=%ld\n",long_value); /* get centre as a string */ GRIB_CHECK(grib_get_string(h,"centre",string_value,&len),0); printf("centre string value=%s\n",string_value); /* get the coded message in a buffer */ GRIB_CHECK(grib_get_message(h,&buffer,&size),0);
96
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 }
Examples
/* write the buffer in a file*/ if(fwrite(buffer,1,size,out) != size) { perror(argv[1]); exit(1); } /* delete handle */ grib_handle_delete(h); fclose(in); fclose(out); return 0;
Chapter 4
Fortran 90 interface
4.1 grib_api Namespace Reference
Module grib_api.
Data Structures
interface grib_index_get
Get the distinct values of the key in argument contained in the index.
interface grib_index_get_size
Get the number of distinct values of the key in argument contained in the index.
interface grib_index_select
Select the message subset with key==value.
interface grib_get
Get the value for a key from a grib message.
interface grib_get_size
Get the size of an array key.
interface grib_set
Set the value for a key in a grib message.
interface grib_get_element
Get a value of specied index from an array key.
interface grib_nd_nearest
Find the nearest point/points of a given latitude/longitude point.
interface grib_get_data
Get latitude/longitude and data values.
98
Fortran 90 interface
Functions
subroutine grib_set_missing (gribid, key, status)
Set as missing the value for a key in a grib message.
99
Fortran 90 interface
101
subroutine grib_nd_nearest_multiple (gribid, is_lsm, inlats, inlons, outlats, outlons, values, distances, indexes, status)
Find the nearest point of a given latitude/longitude point.
102
Fortran 90 interface subroutine grib_nd_nearest_single (gribid, is_lsm, inlat, inlon, outlat, outlon, value, distance, index, status)
Find the nearest point of a given latitude/longitude point.
subroutine grib_nd_nearest_four_single (gribid, is_lsm, inlat, inlon, outlat, outlon, value, distance, index, status)
Find the nearest point of a given latitude/longitude point.
4.1.1
Detailed Description
Module grib_api. The grib_api module provides the Fortran 90 interface of the GRIB API.
4.1.2
4.1.2.1
Function Documentation
subroutine grib_api::grib_check (integer,intent(in) status, character(len=),intent(in) caller, character(len=),intent(in) string)
Check the status returned by a subroutine. In case of error it stops the program, returns the error code to the shell and prints the error message. Parameters: status the status to be checked
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
4.1 grib_api Namespace Reference caller name of the caller soubroutine string a string variable from the caller routine (e.g. key,lename)
103
4.1.2.2
Create a copy of a message. Create a copy of a given message (gribid_src) giving a new message in memory (gribid_dest) exactly identical to the original one. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: clone.f90 Parameters: gribid_src grib to be cloned gribid_dest new grib returned status GRIB_SUCCESS if OK, integer value on error
4.1.2.3
Close a le. If the leid does not refer to an opened le an error code is returned in status. Examples: get.f90 In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: ile is the id of the le to be closed. status GRIB_SUCCESS if OK, integer value on error
4.1.2.4
Copy the coded message into an integer array. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
104 message integer array containing the coded message to be copied status GRIB_SUCCESS if OK, integer value on error
Fortran 90 interface
4.1.2.5
subroutine grib_api::grib_copy_namespace (integer(kind=kindOfInt),intent(in) gribid_src, character(LEN=),intent(in) namespace, integer(kind=kindOfInt),intent(in) gribid_dest, integer(kind=kindOfInt),intent(out),optional status)
Copy the value of all the keys belonging to a namespace from the source message to the destination message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid_src source message gribid_dest destination message namespace namespace to be copied status GRIB_SUCCESS if OK, integer value on error
4.1.2.6
Counts the messages in a le. Examples: count_messages.f90 Parameters: ile id of the le opened with grib_open_le n number of messages in the le status GRIB_SUCCESS if OK or error code
4.1.2.7
Dump the content of a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory status GRIB_SUCCESS if OK, integer value on error
105
subroutine grib_api::grib_nd_nearest_four_single (integer(kind=kindOfInt),intent(in) gribid, logical,intent(in) is_lsm, real(kind = kindOfDouble),intent(in) inlat, real(kind = kindOfDouble),intent(in) inlon, real(kind = kindOfDouble),dimension(4),intent(out) outlat, real(kind = kindOfDouble),dimension(4),intent(out) outlon, real(kind = kindOfDouble),dimension(4),intent(out) value, real(kind = kindOfDouble),dimension(4),intent(out) distance, integer(kind = kindOfInt),dimension(4),intent(out) index, integer(kind=kindOfInt),intent(out),optional status)
Find the nearest point of a given latitude/longitude point. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory is_lsm .true. if the nearest land point is required otherwise .false. inlat latitude of the point inlon longitudes of the point outlat latitude of the nearest point outlon longitude of the nearest point distance distance between the given point and its nearest index zero based index value value of the eld in the nearest point status GRIB_SUCCESS if OK, integer value on error
4.1.2.9
subroutine grib_api::grib_nd_nearest_multiple (integer(kind=kindOfInt),intent(in) gribid, logical,intent(in) is_lsm, real(kind = kindOfDouble),dimension(:),intent(in) inlats, real(kind = kindOfDouble),dimension(:),intent(in) inlons, real(kind = kindOfDouble),dimension(:),intent(out) outlats, real(kind = kindOfDouble),dimension(:),intent(out) outlons, real(kind = kindOfDouble),dimension(:),intent(out) values, real(kind = kindOfDouble),dimension(:),intent(out) distances, integer(kind = kindOfInt),dimension(:),intent(out) indexes, integer(kind=kindOfInt),intent(out),optional status)
Find the nearest point of a given latitude/longitude point. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory is_lsm .true. if the nearest land point is required otherwise .false. inlats input real(8) array of the latitudes of the points inlons input real(8) array of the longitudes of the points outlats output real(8) array of the latitudes of the nearest points
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
106 outlons output real(8) array of the longitudes of the nearest points distances output real(8) array of the distances indexes output integer(4) array of the zero based indexes values output real(8) array of the values status GRIB_SUCCESS if OK, integer value on error
Fortran 90 interface
4.1.2.10
subroutine grib_api::grib_nd_nearest_single (integer(kind=kindOfInt),intent(in) gribid, logical,intent(in) is_lsm, real(kind = kindOfDouble),intent(in) inlat, real(kind = kindOfDouble),intent(in) inlon, real(kind = kindOfDouble),intent(out) outlat, real(kind = kindOfDouble),intent(out) outlon, real(kind = kindOfDouble),intent(out) value, real(kind = kindOfDouble),intent(out) distance, integer(kind = kindOfInt),intent(out) index, integer(kind=kindOfInt),intent(out),optional status)
Find the nearest point of a given latitude/longitude point. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory is_lsm .true. if the nearest land point is required otherwise .false. inlat latitude of the point inlon longitudes of the point outlat latitude of the nearest point outlon longitude of the nearest point distance distance between the given point and its nearest index zero based index value value of the eld in the nearest point status GRIB_SUCCESS if OK, integer value on error
4.1.2.11
subroutine grib_api::grib_get_data_real4 (integer(kind=kindOfInt),intent(in) gribid, real ( kind = kindOfFloat ),dimension(:),intent(out) lats, real ( kind = kindOfFloat ),dimension(:),intent(out) lons, real ( kind = kindOfFloat ),dimension(:),intent(out) values, integer(kind=kindOfInt),intent(out),optional status)
Get latitudes/longitudes/data values (real(4)). Latitudes, longitudes, data values arrays are returned. They must be properly allocated by the caller and their required dimension can be obtained with grib_get_size or by getting (with grib_get) the value of the integer key "numberOfPoints". In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
4.1 grib_api Namespace Reference lats latitudes array with dimension "size" lons longitudes array with dimension "size" values data values array with dimension "size" status GRIB_SUCCESS if OK, integer value on error
107
4.1.2.12
subroutine grib_api::grib_get_data_real8 (integer(kind=kindOfInt),intent(in) gribid, real ( kind = kindOfDouble ),dimension(:),intent(out) lats, real ( kind = kindOfDouble ),dimension(:),intent(out) lons, real ( kind = kindOfDouble ),dimension(:),intent(out) values, integer(kind=kindOfInt),intent(out),optional status)
Get latitudes/longitudes/data values (real(8)). Latitudes, longitudes, data values arrays are returned. They must be properly allocated by the calling program/function. Their required dimension can be obtained by getting (with grib_get) the value of the integer key "numberOfPoints". In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory lats latitudes array lons longitudes array values data values array status GRIB_SUCCESS if OK, integer value on error
4.1.2.13
Get the error message given an error code. Parameters: error error code error_message error message status GRIB_SUCCESS if OK, integer value on error
4.1.2.14
subroutine grib_api::grib_get_int (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind = kindOfInt),intent(out) value, integer(kind=kindOfInt),intent(out),optional status)
Get the integer value of a key from a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
108 Parameters: gribid id of the grib loaded in memory key key name value the integer(4) value status GRIB_SUCCESS if OK, integer value on error
Fortran 90 interface
4.1.2.15
subroutine grib_api::grib_get_int_array (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind=kindOfInt),dimension(:),intent(out) value, integer(kind=kindOfInt),intent(out),optional status)
Get the integer array of values for a key from a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name value integer(4) array value status GRIB_SUCCESS if OK, integer value on error
4.1.2.16
subroutine grib_api::grib_get_long (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind = kindOfLong),intent(out) value, integer(kind=kindOfInt),intent(out),optional status)
Get the integer value of a key from a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name value the integer(4) value status GRIB_SUCCESS if OK, integer value on error
4.1.2.17
subroutine grib_api::grib_get_long_array (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind=kindOfLong),dimension(:),intent(out) value, integer(kind=kindOfInt),intent(out),optional status)
Get the integer array of values for a key from a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
4.1 grib_api Namespace Reference Parameters: gribid id of the grib loaded in memory key key name value integer(4) array value status GRIB_SUCCESS if OK, integer value on error
109
4.1.2.18
Get the size of a coded message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory byte_size size in bytes of the message status GRIB_SUCCESS if OK, integer value on error
4.1.2.19
subroutine grib_api::grib_get_real4 (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, real(kind = kindOfFloat),intent(out) value, integer(kind=kindOfInt),intent(out),optional status)
Get the real(4) value of a key from a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name value the real(4) value status GRIB_SUCCESS if OK, integer value on error
4.1.2.20
subroutine grib_api::grib_get_real4_array (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, real(kind = kindOfFloat),dimension(:),intent(out) value, integer(kind=kindOfInt),intent(out),optional status)
Get the real(4) array of values for a key from a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
110 key key name value real(4) array value status GRIB_SUCCESS if OK, integer value on error
Fortran 90 interface
4.1.2.21
subroutine grib_api::grib_get_real4_element (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind=kindOfInt),intent(in) index, real(kind = kindOfFloat),intent(out) value, integer(kind=kindOfInt),intent(out),optional status)
Get a real(4) value of specied index from an array key. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name index integer(4) index value real(4) value status GRIB_SUCCESS if OK, integer value on error
4.1.2.22
subroutine grib_api::grib_get_real4_elements (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind=kindOfInt),dimension(:),intent(in) index, real(kind = kindOfFloat),dimension(:),intent(out) value, integer(kind=kindOfInt),intent(out),optional status)
Get the real(4) values whose indexes are stored in the array "index" from an array key. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name index integer(4) array indexes value real(4) array value status GRIB_SUCCESS if OK, integer value on error
4.1.2.23
subroutine grib_api::grib_get_real8 (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, real(kind = kindOfDouble),intent(out) value, integer(kind=kindOfInt),intent(out),optional status)
Get the real(8) value of a key from a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
4.1 grib_api Namespace Reference Parameters: gribid id of the grib loaded in memory key key name value the real(8) value status GRIB_SUCCESS if OK, integer value on error
111
4.1.2.24
subroutine grib_api::grib_get_real8_array (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, real(kind = kindOfDouble),dimension(:),intent(out) value, integer(kind=kindOfInt),intent(out),optional status)
Get the real(8) array of values for a key from a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name value real(8) array value status GRIB_SUCCESS if OK, integer value on error
4.1.2.25
subroutine grib_api::grib_get_real8_element (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind=kindOfInt),intent(in) index, real(kind = kindOfDouble),intent(out) value, integer(kind=kindOfInt),intent(out),optional status)
Get a real(8) value of specied index from an array key. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name index integer(4) index value real(8) value status GRIB_SUCCESS if OK, integer value on error
4.1.2.26
subroutine grib_api::grib_get_real8_elements (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind=kindOfInt),dimension(:),intent(in) index, real(kind = kindOfDouble),dimension(:),intent(out) value, integer(kind=kindOfInt),intent(out),optional status)
Get the real(8) values whose indexes are stored in the array "index" from an array key. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
112 Parameters: gribid id of the grib loaded in memory key key name index integer(4) array index value real(8) array value status GRIB_SUCCESS if OK, integer value on error
Fortran 90 interface
4.1.2.27
subroutine grib_api::grib_get_size_int (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind=kindOfInt),intent(out) size, integer(kind=kindOfInt),intent(out),optional status)
Get the size of an array key. To get the size of a key representing an array. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key name of the key size size of the array key status GRIB_SUCCESS if OK, integer value on error
4.1.2.28
subroutine grib_api::grib_get_size_long (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind=kindOfLong),intent(out) size, integer(kind=kindOfInt),intent(out),optional status)
Get the size of an array key. To get the size of a key representing an array. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key name of the key size size of the array key status GRIB_SUCCESS if OK, integer value on error
4.1.2.29
subroutine grib_api::grib_get_string (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, character(len=),intent(out) value, integer(kind=kindOfInt),intent(out),optional status)
113
In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name value the real(8) value status GRIB_SUCCESS if OK, integer value on error
4.1.2.30
Turn off the compatibility mode with gribex. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: status GRIB_SUCCESS if OK, integer value on error
4.1.2.31
Turn on the compatibility mode with gribex. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: status GRIB_SUCCESS if OK, integer value on error
4.1.2.32
subroutine grib_api::grib_index_create (integer(kind=kindOfInt),intent(inout) indexid, character(len=),intent(in) lename, character(len=),intent(in) keys, integer(kind=kindOfInt),intent(out),optional status)
Create a new index form a le. The le is indexed with the keys in argument. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: index.f90 Parameters: indexid id of the newly created index
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
Fortran 90 interface
keys : comma separated list of keys for the index. The type of the key can be explicitly declared appending :l for long, :d for double, :s for string to the key name. If the type is not declared explicitly, the native type is assumed. status GRIB_SUCCESS if OK, integer value on error
4.1.2.33
subroutine grib_api::grib_index_get_int (integer(kind=kindOfInt),intent(in) indexid, character(len=),intent(in) key, integer(kind=kindOfInt),dimension(:),intent(out) values, integer(kind=kindOfInt),intent(out),optional status)
Get the distinct values of the key in argument contained in the index. The key must belong to the index. This function is used when the type of the key was explicitly dened as long or when the native type of the key is long. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: index.f90 Parameters: indexid id of an index created from a le. The index must have been created with the key in argument. key key for wich the values are returned values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values. status GRIB_SUCCESS if OK, integer value on error
4.1.2.34
subroutine grib_api::grib_index_get_long (integer(kind=kindOfInt),intent(in) indexid, character(len=),intent(in) key, integer(kind=kindOfLong),dimension(:),intent(out) values, integer(kind=kindOfInt),intent(out),optional status)
Get the distinct values of the key in argument contained in the index. The key must belong to the index. This function is used when the type of the key was explicitly dened as long or when the native type of the key is long. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: index.f90 Parameters: indexid id of an index created from a le. The index must have been created with the key in argument. key key for wich the values are returned values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values. status GRIB_SUCCESS if OK, integer value on error
115
subroutine grib_api::grib_index_get_real8 (integer(kind=kindOfInt),intent(in) indexid, character(len=),intent(in) key, real(kind=kindOfDouble),dimension(:),intent(out) values, integer(kind=kindOfInt),intent(out),optional status)
Get the distinct values of the key in argument contained in the index. The key must belong to the index. This function is used when the type of the key was explicitly dened as long or when the native type of the key is long. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: index.f90 Parameters: indexid id of an index created from a le. The index must have been created with the key in argument. key key for wich the values are returned values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values. status GRIB_SUCCESS if OK, integer value on error
4.1.2.36
subroutine grib_api::grib_index_get_size_int (integer(kind=kindOfInt),intent(in) indexid, character(len=),intent(in) key, integer(kind=kindOfInt),intent(out) size, integer(kind=kindOfInt),intent(out),optional status)
Get the number of distinct values of the key in argument contained in the index. The key must belong to the index. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: index.f90 Parameters: indexid id of an index created from a le. The index must have been created with the key in argument. key key for which the number of values is computed size number of distinct values of the key in the index status GRIB_SUCCESS if OK, integer value on error
4.1.2.37
subroutine grib_api::grib_index_get_size_long (integer(kind=kindOfInt),intent(in) indexid, character(len=),intent(in) key, integer(kind=kindOfLong),intent(out) size, integer(kind=kindOfInt),intent(out),optional status)
Get the number of distinct values of the key in argument contained in the index. The key must belong to the index. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: index.f90
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
116 Parameters:
Fortran 90 interface
indexid id of an index created from a le. The index must have been created with the key in argument. key key for which the number of values is computed size number of distinct values of the key in the index status GRIB_SUCCESS if OK, integer value on error
4.1.2.38
Delete the index. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: indexid id of an index created from a le. status GRIB_SUCCESS if OK, integer value on error
4.1.2.39
subroutine grib_api::grib_index_select_int (integer(kind=kindOfInt),intent(in) indexid, character(len=),intent(in) key, integer(kind=kindOfInt),intent(in) value, integer(kind=kindOfInt),intent(out),optional status)
Select the message subset with key==value. The value is a integer. The key must have been created with integer type or have integer as native type if the type was not explicitly dened in the index creation. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: index.f90 Parameters: indexid id of an index created from a le. The index must have been created with the key in argument. key key to be selected value value of the key to select status GRIB_SUCCESS if OK, integer value on error
4.1.2.40
subroutine grib_api::grib_index_select_long (integer(kind=kindOfInt),intent(in) indexid, character(len=),intent(in) key, integer(kind=kindOfLong),intent(in) value, integer(kind=kindOfInt),intent(out),optional status)
Select the message subset with key==value. The value is a integer. The key must have been created with integer type or have integer as native type if the type was not explicitly dened in the index creation. In case of error, if the status parameter (optional) is not given, the program will exit with an error message.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
4.1 grib_api Namespace Reference Otherwise the error message can be gathered with grib_get_error_string. Examples: index.f90 Parameters:
117
indexid id of an index created from a le. The index must have been created with the key in argument. key key to be selected value value of the key to select status GRIB_SUCCESS if OK, integer value on error
4.1.2.41
subroutine grib_api::grib_index_select_real8 (integer(kind=kindOfInt),intent(in) indexid, character(len=),intent(in) key, real(kind=kindOfDouble),intent(in) value, integer(kind=kindOfInt),intent(out),optional status)
Select the message subset with key==value. The value is a real. The key must have been created with real type or have real as native type if the type was not explicitly dened in the index creation. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: index.f90 Parameters: indexid id of an index created from a le. The index must have been created with the key in argument. key key to be selected value value of the key to select status GRIB_SUCCESS if OK, integer value on error
4.1.2.42
subroutine grib_api::grib_is_missing (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind = kindOfInt),intent(out) is_missing, integer(kind=kindOfInt),intent(out),optional status)
Check if the value of a key is MISSING. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name is_missing 0->not missing, 1->missing status GRIB_SUCCESS if OK, integer value on error
118 4.1.2.43
Delete a keys iterator and free memory. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: iterid keys iterator id created with grib_keys_iterator_new status GRIB_SUCCESS if OK, integer value on error
4.1.2.44
Get the name of a key from a keys iterator. If the status parameter (optional) is not given the program will exit with an error message otherwise the error message can be gathered with grib_get_error_string. Parameters: iterid keys iterator id created with grib_keys_iterator_new name key name to be retrieved status GRIB_SUCCESS if OK, integer value on error
4.1.2.45
subroutine grib_api::grib_keys_iterator_new (integer(kind=kindOfInt),intent(in) gribid, integer(kind=kindOfInt),intent(out) iterid, character(LEN=),intent(in) namespace, integer(kind=kindOfInt),intent(out),optional status)
Create a new iterator on the keys. The keys iterator can be navigated to give all the key names which can then be used to get or set the key values with grib_get or grib_set. The set of keys returned can be controlled with the input variable namespace or using the functions grib_skip_read_only, grib_skip_duplicates, grib_skip_coded,grib_skip_computed. If namespace is a non empty string only the keys belonging to that namespace are returned. Available namespaces are "ls" (to get the same default keys as the grib_ls and "mars" to get the keys used by mars. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory iterid keys iterator id to be used in the keys iterator functions namespace the namespace of the keys to search for (all the keys if empty) status GRIB_SUCCESS if OK, integer value on error
119
Advance to the next keys iterator value. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: iterid keys iterator id created with grib_keys_iterator_new status GRIB_SUCCESS if OK, integer value on error
4.1.2.47
Rewind a keys iterator. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: iterid keys iterator id created with grib_keys_iterator_new status GRIB_SUCCESS if OK, integer value on error
4.1.2.48
subroutine grib_api::grib_multi_append (integer(kind=kindOfInt),intent(in) ingribid, integer(kind=kindOfInt),intent(in) startsection, integer(kind=kindOfInt),intent(out) multigribid, integer(kind=kindOfInt),intent(out),optional status)
Append a single eld grib message to a multi eld grib message. Only the sections with section number greather or equal "startsection" are copied from the input single message to the multi eld output grib. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: ingribid id of the input single grib startsection starting from startsection (included) all the sections are copied from the input single grib to the output multi grib multigribid id of the output multi led grib status GRIB_SUCCESS if OK, integer value on error
4.1.2.49
120
Fortran 90 interface
In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: status GRIB_SUCCESS if OK, integer value on error
4.1.2.50
Turn on the support for multiple elds in a single message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: status GRIB_SUCCESS if OK, integer value on error
4.1.2.51
Write a multi eld message to a le. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: multigribid id of the multi eld grib loaded in memory ile le id of a le opened with grib_open_le status GRIB_SUCCESS if OK, integer value on error
4.1.2.52
Load in memory a grib message from a le. The message can be accessed through its gribid and it will be available until grib_release is called. Examples: get.f90 Parameters: ile id of the le opened with grib_open_le gribid id of the grib loaded in memory status GRIB_SUCCESS if OK, GRIB_END_OF_FILE at the end of le, or error code
121
Create a new handle from an index after having selected the key values. All the keys belonging to the index must be selected before calling this function. Successive calls to this function will return all the handles compatible with the constraints dened selecting the values of the index keys. When no more handles are available from the index a NULL pointer is returned and the err variable is set to GRIB_END_OF_INDEX. The message can be accessed through its gribid and it will be available until grib_release is called. Examples: index.f90 Parameters: indexid id of an index created from a le. gribid id of the grib loaded in memory status GRIB_SUCCESS if OK, GRIB_END_OF_FILE at the end of le, or error code
4.1.2.54
Create a new message in memory from an integer array containting the coded message. The message can be accessed through its gribid and it will be available until grib_release is called. A reference to the original coded message is kept in the new message structure. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: copy_message.f90 Parameters: gribid id of the grib loaded in memory message integer(4) array containing the coded message status GRIB_SUCCESS if OK, integer value on error
4.1.2.55
Create a new valid gribid from a sample contained in a samples directory pointed by the environment variable GRIB_SAMPLES_PATH. To know where the samples directory is run the grib_info tool. In case of error, if the status parameter (optional) is not given, the program will exit with an error message.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
122 Otherwise the error message can be gathered with grib_get_error_string. Examples: sample.f90 Parameters: gribid id of the grib loaded in memory samplename name of the sample to be used status GRIB_SUCCESS if OK, integer value on error
Fortran 90 interface
4.1.2.56
THIS FUNCTION IS DEPRECATED AND IT WILL DISAPPEAR FROM THE VERSION 2.0 Create a new valid gribid from a template. Valid templates are stored in the directory pointed by the environment variable GRIB_TEMPLATES_PATH or in a templates default directory if this variable is not dened. To know where the templates directory is run the grib_info tool. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: template.f90 Parameters: gribid id of the grib loaded in memory templatename name of the template to be used status GRIB_SUCCESS if OK, integer value on error
4.1.2.57
subroutine grib_api::grib_open_le (integer(kind=kindOfInt),intent(out) ile, character(len=),intent(in) lename, character(LEN=),intent(in) mode, integer(kind=kindOfInt),intent(out),optional status)
Open a le according to a mode. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: get.f90 Parameters: ile id of the opened le to be used in all the le functions. lename name of the le to be open mode open mode can be r (read only) or w (write only) status GRIB_SUCCESS if OK, integer value on error
4.1 grib_api Namespace Reference 4.1.2.58 subroutine grib_api::grib_pbopen (integer(kind=kindOfInt),intent(out) ile, character(len=),intent(in) lename, character(LEN=),intent(in) mode, integer(kind=kindOfInt),intent(out),optional status)
123
Open a le according to a mode. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: get.f90 Parameters: ile id of the opened le to be used in all the le functions. lename name of the le to be open mode open mode can be r (read only) or w (write only) status GRIB_SUCCESS if OK, integer value on error
4.1.2.59
subroutine grib_api::grib_pbread (integer(kind=kindOfInt),intent(in) ile, character(len=1),intent(out) buffer, integer(kind=kindOfInt),intent(in) nbytes, integer(kind=kindOfInt),intent(out),optional status)
Reads nbytes bytes into the buffer from a le opened with grib_open_le. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: ile id of the opened le to be used in all the le functions. buffer binary buffer to be read nbytes number of bytes to be read status GRIB_SUCCESS if OK, integer value on error
4.1.2.60
Free the memory for the message referred as gribid. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: get.f90 Parameters: gribid id of the grib loaded in memory status GRIB_SUCCESS if OK, integer value on error
124 4.1.2.61
Fortran 90 interface subroutine grib_api::grib_set_int (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind=kindOfInt),intent(in) value, integer(kind=kindOfInt),intent(out),optional status)
Set the integer value for a key in a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name value integer(4) value status GRIB_SUCCESS if OK, integer value on error
4.1.2.62
subroutine grib_api::grib_set_int_array (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind=kindOfInt),dimension(:),intent(in) value, integer(kind=kindOfInt),intent(out),optional status)
Set the integers values for an array key in a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name value integer(4) array value status GRIB_SUCCESS if OK, integer value on error
4.1.2.63
subroutine grib_api::grib_set_long (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind=kindOfLong),intent(in) value, integer(kind=kindOfInt),intent(out),optional status)
Set the integer value for a key in a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name value integer(4) value status GRIB_SUCCESS if OK, integer value on error
125
subroutine grib_api::grib_set_long_array (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, integer(kind=kindOfLong),dimension(:),intent(in) value, integer(kind=kindOfInt),intent(out),optional status)
Set the integers values for an array key in a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name value integer(4) array value status GRIB_SUCCESS if OK, integer value on error
4.1.2.65
Set as missing the value for a key in a grib message. It can be used to set a missing value in the grib header but not in the data values. To set missing data values see the bitmap examples. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: set_missing.f90 Parameters: gribid id of the grib loaded in memory key key name status GRIB_SUCCESS if OK, integer value on error
4.1.2.66
subroutine grib_api::grib_set_real4 (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, real(kind = kindOfFloat),intent(in) value, integer(kind=kindOfInt),intent(out),optional status)
Set the real(4) value for a key in a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name value real(4) value status GRIB_SUCCESS if OK, integer value on error
126 4.1.2.67
Fortran 90 interface subroutine grib_api::grib_set_real4_array (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, real(kind = kindOfFloat),dimension(:),intent(in) value, integer(kind=kindOfInt),intent(out),optional status)
Set the real(4) values for an array key in a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name value real(4) array value status GRIB_SUCCESS if OK, integer value on error
4.1.2.68
subroutine grib_api::grib_set_real8 (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, real(kind = kindOfDouble),intent(in) value, integer(kind=kindOfInt),intent(out),optional status)
Set the real(8) value for a key in a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name value real(8) value status GRIB_SUCCESS if OK, integer value on error
4.1.2.69
subroutine grib_api::grib_set_real8_array (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, real(kind = kindOfDouble),dimension(:),intent(in) value, integer(kind=kindOfInt),intent(out),optional status)
Set the real(8) values for an array key in a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name value real(8) array value status GRIB_SUCCESS if OK, integer value on error
4.1 grib_api Namespace Reference 4.1.2.70 subroutine grib_api::grib_set_string (integer(kind=kindOfInt),intent(in) gribid, character(len=),intent(in) key, character(len=),intent(in) value, integer(kind=kindOfInt),intent(out),optional status)
127
Set the character value for a string key in a grib message. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key key name value character value status GRIB_SUCCESS if OK, integer value on error
4.1.2.71
Skip the coded keys in a keys iterator. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. The coded keys are actually coded in the message. See also: grib_keys_iterator_new,grib_keys_iterator_next,grib_keys_iterator_release Parameters: iterid keys iterator id status GRIB_SUCCESS if OK, integer value on error
4.1.2.72
Skip the computed keys in a keys iterator. The computed keys are not coded in the message they are computed from other keys. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. See also: grib_keys_iterator_new,grib_keys_iterator_next,grib_keys_iterator_release Parameters: iterid keys iterator id status GRIB_SUCCESS if OK, integer value on error
128 4.1.2.73
Skip the duplicated keys in a keys iterator. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. See also: grib_keys_iterator_new,grib_keys_iterator_next,grib_keys_iterator_release Parameters: iterid keys iterator id status GRIB_SUCCESS if OK, integer value on error
4.1.2.74
Skip the read_only keys in a keys iterator. Read only keys cannot be set. See also: grib_keys_iterator_new,grib_keys_iterator_next,grib_keys_iterator_release Parameters: iterid keys iterator id status GRIB_SUCCESS if OK, integer value on error
4.1.2.75
Write the coded message to a le. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory ile le id of a le opened with grib_open_le status GRIB_SUCCESS if OK, integer value on error
4.2
129
4.2.1
Detailed Description
Find the nearest point/points of a given latitude/longitude point. The value in the nearest point (or the four nearest points) is returned as well as the zero based index (which can be used in grib_get_element) and its distance from the given point using the following formula (acos(sin(lat1)sin(lat2)+cos(lat1)cos(lat2)cos(lon1-lon2))). If the is_lsm ag is .true. the input eld gribid is considered as a land sea mask and the nearest land point is returned. The nearest land point among the four neighbours is: the nearest point with land sea mask value >= 0.5 the nearest without any other condition if all the four have land sea mask value <0.5. Arrays (real(8)) of latitude/longitude can be provided to nd with one call the values,indexes and distances for all the lat/lon points listed in the arrays. If a single latitude/longitude point is provided and outlat,outlon,value,distance,index are dened as arrays with four elements the lat/lon coordinates and values, distances and indexes of the four nearest points are returned. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: nearest.f90 Parameters: gribid id of the grib loaded in memory is_lsm .true. if the nearest land point is required otherwise .false. inlat latitude of the point in degrees inlon longitudes of the point in degrees outlat latitude of the nearest point in degrees outlon longitude of the nearest point in degrees distance distance between the given point and its nearest index zero based index value value of the eld in the nearest point status GRIB_SUCCESS if OK, integer value on error The documentation for this interface was generated from the following le: grib_f90.f90
130
Fortran 90 interface
4.3
4.3.1
Detailed Description
Get the value for a key from a grib message. Given a gribid and key as input a value for the key is returned. In some cases the value can be an array rather than a scalar. As examples of array keys we have "values","pl", "pv" respectively the data values, the list of number of points for each latitude in a reduced grid and the list of vertical levels. In these cases the value array must be allocated by the caller and their required dimension can be obtained with grib_get_size. The value can be integer(4), real(4), real(8), character. Although each key has its own native type, a key of type integer can be retrieved (with grib_get) as real(4), real(8) or character. Analogous conversions are always provided when possible. Illegal conversions are real to integer and character to any other type. The gribid references to a grib message loaded in memory. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: get.f90, print_data.f90 See also: grib_new_from_le, grib_release, grib_set Parameters: gribid id of the grib loaded in memory key key name value value can be a scalar or array of integer(4),real(4),real(8),character status GRIB_SUCCESS if OK, integer value on error The documentation for this interface was generated from the following le: grib_f90.f90
131
4.4
4.4.1
Detailed Description
Get latitude/longitude and data values. Latitudes, longitudes, data values arrays are returned. They must be properly allocated by the caller and their required dimension can be obtained with grib_get_size or by getting (with grib_get) the value of the integer key "numberOfPoints". In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: get_data.f90 Parameters: gribid id of the grib loaded in memory lats latitudes array with dimension "size" lons longitudes array with dimension "size" values data values array with dimension "size" status GRIB_SUCCESS if OK, integer value on error The documentation for this interface was generated from the following le: grib_f90.f90
132
Fortran 90 interface
4.5
4.5.1
Detailed Description
Get a value of specied index from an array key. Given a gribid and key name as input a value corresponding to the given index is returned. The index is zero based i.e. the rst element has zero index, the second element index one and so on. If the parameter index is an array all the values correspondig to the indexes list is returned. The gribid references to a grib message loaded in memory. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: nearest.f90 See also: grib_new_from_le, grib_release, grib_get Parameters: gribid id of the grib loaded in memory key key name index index can be a scalar or array of integer(4) value value can be a scalar or array of integer(4),real(4),real(8) status GRIB_SUCCESS if OK, integer value on error The documentation for this interface was generated from the following le: grib_f90.f90
133
4.6
4.6.1
Detailed Description
Get the size of an array key. To get the size of a key representing an array. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Parameters: gribid id of the grib loaded in memory key name of the key size size of the array key status GRIB_SUCCESS if OK, integer value on error The documentation for this interface was generated from the following le: grib_f90.f90
134
Fortran 90 interface
4.7
Get the distinct values of the key in argument contained in the index.
4.7.1
Detailed Description
Get the distinct values of the key in argument contained in the index. The key must belong to the index. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: index.f90 Parameters: indexid id of an index created from a le. The index must have been created with the key in argument. key key for wich the values are returned values array of values. The array must be allocated before entering this function and its size must be enough to contain all the values. status GRIB_SUCCESS if OK, integer value on error The documentation for this interface was generated from the following le: grib_f90.f90
135
4.8
Get the number of distinct values of the key in argument contained in the index.
4.8.1
Detailed Description
Get the number of distinct values of the key in argument contained in the index. The key must belong to the index. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: index.f90 Parameters: indexid id of an index created from a le. The index must have been created with the key in argument. key key for which the number of values is computed size number of distinct values of the key in the index status GRIB_SUCCESS if OK, integer value on error The documentation for this interface was generated from the following le: grib_f90.f90
136
Fortran 90 interface
4.9
4.9.1
Detailed Description
Select the message subset with key==value. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: index.f90 Parameters: indexid id of an index created from a le. The index must have been created with the key in argument. key key to be selected value value of the key to select status GRIB_SUCCESS if OK, integer value on error The documentation for this interface was generated from the following le: grib_f90.f90
137
4.10
4.10.1
Detailed Description
Set the value for a key in a grib message. The given value is set for the key in the gribid message. In some cases the value can be an array rather than a scalar. As examples of array keys we have "values","pl", "pv" respectively the data values, the list of number of points for each latitude in a reduced grid and the list of vertical levels. In these cases the value array must be allocated by the caller and their required dimension can be obtained with grib_get_size. The gribid references to a grib message loaded in memory. In case of error, if the status parameter (optional) is not given, the program will exit with an error message. Otherwise the error message can be gathered with grib_get_error_string. Examples: set.f90 See also: grib_new_from_le, grib_release, grib_get Parameters: gribid id of the grib loaded in memory key key name value value can be a scalar or array of integer(4),real(4),real(8) status GRIB_SUCCESS if OK, integer value on error The documentation for this interface was generated from the following le: grib_f90.f90
138
Fortran 90 interface
Chapter 5
C interface
5.1 grib_api Modules
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 144 150 151 156 164 174
Here is a list of all modules: The grib_index . . . . . . . . . . . The grib_handle . . . . . . . . . . . Handling coded messages . . . . . . Iterating on latitude/longitude/values Accessing header and data values . . The context object . . . . . . . . . . Iterating on keys names . . . . . . .
5.2
The grib_index
Typedefs
typedef struct grib_index grib_index
Functions
grib_index grib_index_new_from_le (grib_context c, char lename, const char keys, int err)
Create a new index form a le.
int grib_index_get_long (grib_index index, const char key, long values, size_t size)
Get the distinct values of the key in argument contained in the index.
int grib_index_get_double (grib_index index, const char key, double values, size_t size)
Get the distinct values of the key in argument contained in the index.
int grib_index_get_string (grib_index index, const char key, char values, size_t size)
140
Get the distinct values of the key in argument contained in the index.
C interface
5.2.1
Detailed Description
5.2.2
5.2.2.1
Typedef Documentation
typedef struct grib_index grib_index
5.2.3
5.2.3.1
Function Documentation
grib_handle grib_handle_new_from_index (grib_index index, int err)
Create a new handle from an index after having selected the key values. All the keys belonging to the index must be selected before calling this function. Successive calls to this function will return all the handles compatible with the constraints dened selecting the values of the index keys. When no more handles are available from the index a NULL pointer is returned and the err variable is set to GRIB_END_OF_INDEX. Parameters: index : an index created from a le. err : 0 if OK, integer value on error. GRIB_END_OF_INDEX when no more handles are contained in the index. Returns: grib handle.
141
5.2.3.3
int grib_index_get_double (grib_index index, const char key, double values, size_t size)
Get the distinct values of the key in argument contained in the index. The key must belong to the index. This function is used when the type of the key was explicitly dened as double or when the native type of the key is double. Parameters: index : an index created from a le. The index must have been created with the key in argument. key : key for wich the values are returned values : array of values. The array must be allocated before entering this function and its size must be enough to contain all the values. size : size of the values array Returns: 0 if OK, integer value on error
5.2.3.4
int grib_index_get_long (grib_index index, const char key, long values, size_t size)
Get the distinct values of the key in argument contained in the index. The key must belong to the index. This function is used when the type of the key was explicitly dened as long or when the native type of the key is long. Parameters: index : an index created from a le. The index must have been created with the key in argument. key : key for wich the values are returned values : array of values. The array must be allocated before entering this function and its size must be enough to contain all the values. size : size of the values array Returns: 0 if OK, integer value on error
142 5.2.3.5 int grib_index_get_size (grib_index index, const char key, size_t size)
C interface
Get the number of distinct values of the key in argument contained in the index. The key must belong to the index. Parameters: index : an index created from a le. The index must have been created with the key in argument. key : key for which the number of values is computed size : number of distinct values of the key in the index Returns: 0 if OK, integer value on error Examples: index.f90.
5.2.3.6
int grib_index_get_string (grib_index index, const char key, char values, size_t size)
Get the distinct values of the key in argument contained in the index. The key must belong to the index. This function is used when the type of the key was explicitly dened as string or when the native type of the key is string. Parameters: index : an index created from a le. The index must have been created with the key in argument. key : key for wich the values are returned values : array of values. The array must be allocated before entering this function and its size must be enough to contain all the values. size : size of the values array Returns: 0 if OK, integer value on error
5.2.3.7
grib_index grib_index_new_from_le (grib_context c, char lename, const char keys, int err)
Create a new index form a le. The le is indexed with the keys in argument. Parameters: c : context (NULL for default context) lename : name of the le of messages to be indexed keys : comma separated list of keys for the index. The type of the key can be explicitly declared appending :l for long, :d for double, :s for string to the key name. If the type is not declared explicitly, the native type is assumed.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
5.2 The grib_index err : 0 if OK, integer value on error Returns: the newly created index
143
5.2.3.8
Select the message subset with key==value. The value is a double. The key must have been created with double type or have double as native type if the type was not explicitly dened in the index creation. Parameters: index : an index created from a le. The index must have been created with the key in argument. key : key to be selected value : value of the key to select Returns: 0 if OK, integer value on error
5.2.3.9
Select the message subset with key==value. The value is a long. The key must have been created with long type or have long as native type if the type was not explicitly dened in the index creation. Parameters: index : an index created from a le. The index must have been created with the key in argument. key : key to be selected value : value of the key to select Returns: 0 if OK, integer value on error
5.2.3.10
Select the message subset with key==value. The value is a string. The key must have been created with string type or have string as native type if the type was not explicitly dened in the index creation. Parameters: index : an index created from a le. The index must have been created with the key in argument. key : key to be selected value : value of the key to select Returns: 0 if OK, integer value on error
144
C interface
5.3
The grib_handle
Typedefs
typedef struct grib_handle grib_handle typedef struct grib_multi_handle grib_multi_handle
Functions
int grib_count_in_le (grib_context c, FILE f, int n)
Counts the messages contained in a le resource.
145
5.3.1
Detailed Description
The grib_handle is the structure giving access to parsed grib values by keys.
5.3.2
5.3.2.1
Typedef Documentation
typedef struct grib_handle grib_handle
Grib handle, structure giving access to parsed grib values by keys Examples: get.c, iterator.c, keys_iterator.c, multi.c, multi_write.c, nearest.c, precision.c, print_data.c, and set.c.
5.3.2.2
Grib multi eld handle, structure used to build multi elds messages. Examples: multi_write.c.
5.3.3
5.3.3.1
Function Documentation
int grib_count_in_le (grib_context c, FILE f, int n)
Counts the messages contained in a le resource. Parameters: c : the context from wich the handle will be created (NULL for default context) f : the le resource n : the number of messages in the le Returns: 0 if OK, integer value on error Examples: count_messages.f90.
5.3.3.2
Clone an existing handle using the context of the original handle, The message is copied and reparsed. Parameters: h : The handle to be cloned Returns: the new handle, NULL if the message is invalid or a problem is encountered
C interface
Frees a handle, also frees the message if it is not a user message. See also: grib_handle_new_from_message Parameters: h : The handle to be deleted Returns: 0 if OK, integer value on error Examples: get.c, iterator.c, multi.c, multi_write.c, nearest.c, precision.c, print_data.c, and set.c.
5.3.3.4
Create a handle from a le resource. The le is read until a message is found. The message is then copied. Remember always to delete the handle when it is not needed any more to avoid memory leaks. Parameters: c : the context from wich the handle will be created (NULL for default context) f : the le resource error : error code set if the returned handle is NULL and the end of le is not reached Returns: the new handle, NULL if the resource is invalid or a problem is encountered Examples: get.c, iterator.c, keys_iterator.c, multi.c, multi_write.c, precision.c, print_data.c, and set.c.
5.3.3.5
Create a handle from a user message in memory. The message will not be freed at the end. The message will be copied as soon as a modication is needed. Parameters: c : the context from which the handle will be created (NULL for default context) data : the actual message data_len : the length of the message in number of bytes Returns: the new handle, NULL if the message is invalid or a problem is encountered
147
Create a handle from a user message. The message is copied and will be freed with the handle Parameters: c : the context from wich the handle will be created (NULL for default context) data : the actual message data_len : the length of the message in number of bytes Returns: the new handle, NULL if the message is invalid or a problem is encountered
5.3.3.7
Create a handle from a user message in memory. The message will not be freed at the end. The message will be copied as soon as a modication is needed. This function works also with multi eld messages. Parameters: c : the context from which the handle will be created (NULL for default context) data : the actual message data_len : the length of the message in number of bytes error : error code Returns: the new handle, NULL if the message is invalid or a problem is encountered
5.3.3.8
Create a handle from a message contained in a samples directory. The message is copied at the creation of the handle Parameters: c : the context from wich the handle will be created (NULL for default context) res_name : the resource name Returns: the new handle, NULL if the resource is invalid or a problem is encountered
148 5.3.3.9
Create a handle from a read_only template resource. The message is copied at the creation of the handle Parameters: c : the context from wich the handle will be created (NULL for default context) res_name : the resource name Returns: the new handle, NULL if the resource is invalid or a problem is encountered
5.3.3.10
Append the sections starting with start_section of the message pointed by h at the end of the multi eld handle mh. Remember always to delete the multi handle when it is not needed any more to avoid memory leaks. Parameters: h : The handle from which the sections are copied. start_section : section number. Starting from this section all the sections to then end of the message will be copied. mh : The multi eld handle on which the sections are appended. Returns: 0 if OK, integer value on error Examples: multi_write.c.
5.3.3.11
Delete multi eld handle. Parameters: mh : The multi eld handle to be deleted. Returns: 0 if OK, integer value on error Examples: multi_write.c.
149
Create an empty multi eld handle. Remember always to delete the multi handle when it is not needed any more to avoid memory leaks. Parameters: c : the context from wich the handle will be created (NULL for default context) Examples: multi_write.c.
5.3.3.13
Write a multi eld handle in a le. Remember always to delete the multi handle when it is not needed any more to avoid memory leaks. Parameters: mh : The multi eld handle to be written. f : File on which the le handle is written. Returns: 0 if OK, integer value on error Examples: multi_write.c.
150
C interface
5.4
Functions
int grib_get_message (grib_handle h, const void message, size_t message_length)
getting the message attached to a handle
5.4.1 5.4.2
5.4.2.1
getting the message attached to a handle Parameters: h : the grib handle to wich the buffer should be gathered message : the pointer to be set to the handles data message_length : at exist, the message size in number of bytes Returns: 0 if OK, integer value on error Examples: precision.c, and set.c.
5.4.2.2
getting a copy of the message attached to a handle Parameters: h : the grib handle to wich the buffer should be returned message : the pointer to the data buffer to be lled message_length : at entry, the size in number of bytes of the allocated empty message. At exist, the actual message length in number of bytes Returns: 0 if OK, integer value on error
151
5.5
Iterating on latitude/longitude/values
Functions
grib_iterator grib_iterator_new (grib_handle h, unsigned long ags, int error)
Create a new iterator from a handle, using current geometry and values.
int grib_nearest_nd (grib_nearest nearest, grib_handle h, double inlat, double inlon, unsigned long ags, double outlats, double outlons, double values, double distances, int indexes, size_t len)
Find the 4 nearest points of a latitude longitude point.
int grib_nearest_nd_multiple (grib_handle h, int is_lsm, double inlats, double inlons, long npoints, double outlats, double outlons, double values, double distances, int indexes)
Find the nearest point of a set of points whose latitudes and longitudes are given in the inlats, inlons arrays respectively.
5.5.1 5.5.2
5.5.2.1
152 Returns: 0 if OK, integer value on error Examples: iterator.c, and iterator_fortran.F.
C interface
5.5.2.2
Test procedure for values in an iterator. Parameters: i : the iterator Returns: boolean, 1 if the iterator still nave next values, 0 otherwise
5.5.2.3
Create a new iterator from a handle, using current geometry and values. Parameters: h : the handle from which the iterator will be created ags : ags for future use. error : error code Returns: the new iterator, NULL if no iterator can be created Examples: iterator.c, and iterator_fortran.F.
5.5.2.4
Get the next value from an iterator. Parameters: i : the iterator lat : on output latitude in degree lon : on output longitude in degree value : on output value of the point Returns: positive value if successful, 0 if no more data are available Examples: iterator.c, and iterator_fortran.F.
5.5 Iterating on latitude/longitude/values 5.5.2.5 int grib_iterator_previous (grib_iterator i, double lat, double lon, double value)
153
Get the previous value from an iterator. Parameters: i : the iterator lat : on output latitude in degree lon : on output longitude in degree value : on output value of the point Returns: positive value if successful, 0 if no more data are available
5.5.2.6
Test procedure for values in an iterator. Parameters: i : the iterator Returns: 0 if OK, integer value on error
5.5.2.7
Frees an nearest from memory. Parameters: nearest : the nearest Returns: 0 if OK, integer value on error Examples: nearest.c.
5.5.2.8
int grib_nearest_nd (grib_nearest nearest, grib_handle h, double inlat, double inlon, unsigned long ags, double outlats, double outlons, double values, double distances, int indexes, size_t len)
Find the 4 nearest points of a latitude longitude point. The ags are provided to speed up the process of searching. If you are sure that the point you are asking for is not changing from a call to another you can use GRIB_NEAREST_SAME_POINT. The same is valid for the grid. Flags can be used together duing an or.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
154 Parameters: nearest : nearest structure h : handle from which geography and data values are taken inlat : latitude of the point to search for inlon : longitude of the point to search for ags : GRIB_NEAREST_SAME_POINT, GRIB_NEAREST_SAME_GRID outlats : returned array of latitudes of the nearest points outlons : returned array of longitudes of the nearest points values : returned array of data values of the nearest points distances : returned array of distances from the nearest points indexes : returned array of indexes of the nearest points len : size of the arrays Returns: 0 if OK, integer value on error Examples: nearest.c.
C interface
5.5.2.9
int grib_nearest_nd_multiple (grib_handle h, int is_lsm, double inlats, double inlons, long npoints, double outlats, double outlons, double values, double distances, int indexes)
Find the nearest point of a set of points whose latitudes and longitudes are given in the inlats, inlons arrays respectively. If the ag is_lsm is 1 the nearest land point is returned and the grib passed as handle (h) is considered a land sea mask. The land nearest point is the nearest point with land sea mask value>=0.5. If no nearest land points are found the nearest value is returned. If the ag is_lsm is 0 the nearest point is returned. values, distances, indexes (in the "values" array) for the nearest points (ilons,ilats) are returned. Parameters: h : handle from which geography and data values are taken is_lsm : lsm ag (1-> nearest land, 0-> nearest) inlats : latitudes of the points to search for inlons : longitudes of the points to search for npoints : number of points (size of the inlats,inlons,outlats,outlons,values,distances,indexes arrays) outlats : returned array of latitudes of the nearest points outlons : returned array of longitudes of the nearest points values : returned array of data values of the nearest points distances : returned array of distances from the nearest points indexes : returned array of indexes of the nearest points Returns: 0 if OK, integer value on error
155
Create a new nearest from a handle, using current geometry . Parameters: h : the handle from which the iterator will be created error : error code Returns: the new nearest, NULL if no nearest can be created Examples: nearest.c.
156
C interface
5.6
Functions
int grib_get_offset (grib_handle h, const char key, size_t offset)
Get the number offset of a key, in a message if several keys of the same name are present, the offset of the last one is returned.
int grib_get_double_elements (grib_handle h, const char key, int i, long size, double value)
Get as double array the elements of the "key" array whose indexes are listed in the input array i.
int grib_get_string (grib_handle h, const char key, char mesg, size_t length)
Get a string value from a key, if several keys of the same name are present, the last one is returned.
int grib_get_bytes (grib_handle h, const char key, unsigned char bytes, size_t length)
Get raw bytes values from a key.
int grib_get_double_array (grib_handle h, const char key, double vals, size_t length)
Get double array values from a key.
int grib_get_long_array (grib_handle h, const char key, long vals, size_t length)
Get long array values from a key.
int grib_set_string (grib_handle h, const char key, const char mesg, size_t length)
Set a string value from a key.
int grib_set_bytes (grib_handle h, const char key, const unsigned char bytes, size_t length)
Set a bytes array from a key.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
157
int grib_set_double_array (grib_handle h, const char key, const double vals, size_t length)
Set a double array from a key.
int grib_set_long_array (grib_handle h, const char key, const long vals, size_t length)
Set a long array from a key.
5.6.1 5.6.2
5.6.2.1
Copy the keys belonging to a given namespace from a source handle to a destination handle. Parameters: dest : destination handle name : namespace src : source handle Returns: 0 if OK, integer value on error
5.6.2.2
int grib_get_bytes (grib_handle h, const char key, unsigned char bytes, size_t length)
Get raw bytes values from a key. If several keys of the same name are present, the last one is returned See also: grib_set_bytes Parameters: h : the handle to get the data from key : the key to be searched bytes : the address of a byte array where the data will be retreived length : the address of a size_t that contains allocated length of the byte array on input, and that contains the actual length of the byte array on output Returns: 0 if OK, integer value on error
158 5.6.2.3 int grib_get_double (grib_handle h, const char key, double value)
C interface
Get a double value from a key, if several keys of the same name are present, the last one is returned. See also: grib_set_double Parameters: h : the handle to get the data from key : the key to be searched value : the address of a double where the data will be retreived Returns: 0 if OK, integer value on error Examples: get.c, iterator.c, and print_data.c.
5.6.2.4
int grib_get_double_array (grib_handle h, const char key, double vals, size_t length)
Get double array values from a key. If several keys of the same name are present, the last one is returned See also: grib_set_double_array Parameters: h : the handle to get the data from key : the key to be searched vals : the address of a double array where the data will be retreived length : the address of a size_t that contains allocated length of the double array on input, and that contains the actual length of the double array on output Returns: 0 if OK, integer value on error Examples: get.c, precision.c, and print_data.c.
5.6.2.5
5.6 Accessing header and data values Parameters: h : the handle to get the data from key : the key to be searched i : zero based index value : the address of a double where the data will be retreived Returns: 0 if OK, integer value on error
159
5.6.2.6
int grib_get_double_elements (grib_handle h, const char key, int i, long size, double value)
Get as double array the elements of the "key" array whose indexes are listed in the input array i. Parameters: h : the handle to get the data from key : the key to be searched i : zero based array of indexes size : size of the i and value arrays value : the address of a double where the data will be retreived Returns: 0 if OK, integer value on error
5.6.2.7
Get a long value from a key, if several keys of the same name are present, the last one is returned. See also: grib_set_long Parameters: h : the handle to get the data from key : the key to be searched value : the address of a long where the data will be retreived Returns: 0 if OK, integer value on error Examples: get.c, multi.c, nearest.c, precision.c, and set.c.
160 5.6.2.8
C interface int grib_get_long_array (grib_handle h, const char key, long vals, size_t length)
Get long array values from a key. If several keys of the same name are present, the last one is returned See also: grib_set_long_array Parameters: h : the handle to get the data from key : the key to be searched vals : the address of a long array where the data will be retreived length : the address of a size_t that contains allocated length of the long array on input, and that contains the actual length of the long array on output Returns: 0 if OK, integer value on error
5.6.2.9
Get the number offset of a key, in a message if several keys of the same name are present, the offset of the last one is returned. Parameters: h : the handle to get the offset from key : the key to be searched offset : the address of a size_t where the offset will be set Returns: 0 if OK, integer value on error
5.6.2.10
Get the number of coded value from a key, if several keys of the same name are present, the total sum is returned. Parameters: h : the handle to get the offset from key : the key to be searched size : the address of a size_t where the size will be set Returns: 0 if OK, integer value on error Examples: count_messages.f90, get.c, get.f90, get_fortran.F, get_pl.f90, get_pv.f90, precision.c, precision.f90, precision_fortran.F, print_data.c, print_data.f90, print_data_fortran.F, samples.f90, and set_bitmap.f90.
5.6 Accessing header and data values 5.6.2.11 int grib_get_string (grib_handle h, const char key, char mesg, size_t length)
161
Get a string value from a key, if several keys of the same name are present, the last one is returned. See also: grib_set_string Parameters: h : the handle to get the data from key : the key to be searched mesg : the address of a string where the data will be retreived length : the address of a size_t that contains allocated length of the string on input, and that contains the actual length of the string on output Returns: 0 if OK, integer value on error Examples: keys_iterator.c, keys_iterator_fortran.F, nearest.c, set.c, and set_fortran.F.
5.6.2.12
int grib_set_bytes (grib_handle h, const char key, const unsigned char bytes, size_t length)
Set a bytes array from a key. If several keys of the same name are present, the last one is set See also: grib_get_bytes Parameters: h : the handle to set the data to key : the key to be searched bytes : the address of a byte array where the data will be read length : the address of a size_t that contains the length of the byte array on input, and that contains the actual packed length of the byte array on output Returns: 0 if OK, integer value on error
5.6.2.13
Set a double value from a key. If several keys of the same name are present, the last one is set
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
162 See also: grib_get_double Parameters: h : the handle to set the data to key : the key to be searched val : a double where the data will be read Returns: 0 if OK, integer value on error
C interface
5.6.2.14
int grib_set_double_array (grib_handle h, const char key, const double vals, size_t length)
Set a double array from a key. If several keys of the same name are present, the last one is set See also: grib_get_double_array Parameters: h : the handle to set the data to key : the key to be searched vals : the address of a double array where the data will be read length : a size_t that contains the length of the byte array on input Returns: 0 if OK, integer value on error
5.6.2.15
Set a long value from a key. If several keys of the same name are present, the last one is set See also: grib_get_long Parameters: h : the handle to set the data to key : the key to be searched val : a long where the data will be read Returns: 0 if OK, integer value on error
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
5.6 Accessing header and data values Examples: multi_write.c, precision.c, and set.c.
163
5.6.2.16
int grib_set_long_array (grib_handle h, const char key, const long vals, size_t length)
Set a long array from a key. If several keys of the same name are present, the last one is set See also: grib_get_long_array Parameters: h : the handle to set the data to key : the key to be searched vals : the address of a long array where the data will be read length : a size_t that contains the length of the long array on input Returns: 0 if OK, integer value on error
5.6.2.17
int grib_set_string (grib_handle h, const char key, const char mesg, size_t length)
Set a string value from a key. If several keys of the same name are present, the last one is set See also: grib_get_string Parameters: h : the handle to set the data to key : the key to be searched mesg : the address of a string where the data will be read length : the address of a size_t that contains the length of the string on input, and that contains the actual packed length of the string on output Returns: 0 if OK, integer value on error
164
C interface
5.7
Typedefs
typedef void( grib_free_proc )(const grib_context c, void data)
Grib free procedure, format of a procedure referenced in the context that is used to free memory.
typedef void( grib_log_proc )(const grib_context c, int level, const char mesg)
Grib loc proc, format of a procedure referenced in the context that is used to log internal messages.
typedef void( grib_print_proc )(const grib_context c, void descriptor, const char mesg)
Grib print proc, format of a procedure referenced in the context that is used to print external messages.
typedef size_t( grib_data_read_proc )(const grib_context c, void ptr, size_t size, void stream)
Grib data read proc, format of a procedure referenced in the context that is used to read from a stream in a resource.
typedef size_t( grib_data_write_proc )(const grib_context c, const void ptr, size_t size, void stream)
Grib data read write, format of a procedure referenced in the context that is used to write to a stream from a resource.
typedef off_t( grib_data_seek_proc )(const grib_context c, off_t offset, int whence, void stream)
Grib data seek, format of a procedure referenced in the context that is used to seek the current position in a stream.
Functions
grib_context grib_get_context (grib_handle h)
Retreive the context from a handle.
165
C interface
5.7.1
Detailed Description
The context is a long life conguration object of the grib_api. It is used to dene special allocation and free routines or to set special grib_api behaviours and variables.
5.7.2
5.7.2.1
Typedef Documentation
typedef int( grib_data_eof_proc)(const grib_context c, void stream)
Grib data eof, format of a procedure referenced in the context that is used to test end of le. Parameters: c : the context where the tell will apply stream : the stream Returns: the position in the stream
5.7.2.2
typedef size_t( grib_data_read_proc)(const grib_context c, void ptr, size_t size, void stream)
Grib data read proc, format of a procedure referenced in the context that is used to read from a stream in a resource. Parameters: c : the context where the read will apply ptr : the resource size : size to read stream : the stream Returns: size read
5.7.2.3
typedef off_t( grib_data_seek_proc)(const grib_context c, off_t offset, int whence, void stream)
Grib data seek, format of a procedure referenced in the context that is used to seek the current position in a stream. Parameters: c : the context where the tell will apply
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
167
whence : If whence is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to the start of the le, the current position indicator, or end-of-le, respectively. stream : the stream Returns: 0 if OK, integer value on error
5.7.2.4
Grib data tell, format of a procedure referenced in the context that is used to tell the current position in a stream. Parameters: c : the context where the tell will apply stream : the stream Returns: the position in the stream
5.7.2.5
typedef size_t( grib_data_write_proc)(const grib_context c, const void ptr, size_t size, void stream)
Grib data read write, format of a procedure referenced in the context that is used to write to a stream from a resource. Parameters: c : the context where the write will apply ptr : the resource size : size to read stream : the stream Returns: size written
5.7.2.6
Grib free procedure, format of a procedure referenced in the context that is used to free memory. Parameters: c : the context where the memory freeing will apply data : pointer to the data to be freed must match See also: grib_malloc_proc
168 5.7.2.7
C interface typedef void( grib_log_proc)(const grib_context c, int level, const char mesg)
Grib loc proc, format of a procedure referenced in the context that is used to log internal messages. Parameters: c : the context where the logging will apply level : the log level, as dened in log modes mesg : the message to be logged
5.7.2.8
Grib malloc procedure, format of a procedure referenced in the context that is used to allocate memory. Parameters: c : the context where the memory allocation will apply length : length to be allocated in number of bytes Returns: a pointer to the alocated memory, NULL if no memory can be allocated must match See also: grib_free_proc
5.7.2.9
Grib print proc, format of a procedure referenced in the context that is used to print external messages. Parameters: c : the context where the logging will apply descriptor : the structure to be printed on, must match the implementation mesg : the message to be printed
5.7.2.10
Grib realloc procedure, format of a procedure referenced in the context that is used to reallocate memory. Parameters: c : the context where the memory allocation will apply data : pointer to the data to be reallocated length : length to be allocated in number of bytes Returns: a pointer to the alocated memory
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
169
5.7.3
5.7.3.1
Function Documentation
void grib_context_delete (grib_context c)
Frees the cached denition les of the context. Parameters: c : the context to be deleted
5.7.3.2
Get the static default context. Returns: the default context, NULL it the context is not available
5.7.3.3
get userData from a context Parameters: c : the context from which the user data will be retreived Returns: the user data referenced in the context
5.7.3.4
Create and allocate a new context from a parent context. Parameters: c : the context to be cloned, NULL for default context Returns: the new and empty context, NULL if error
5.7.3.5
Sets memory procedures of the context for large buffers. Parameters: c : the context to be modied griballoc : the memory allocation procedure to be set
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
170 See also: grib_malloc_proc Parameters: gribfree : the memory freeing procedure to be set See also: grib_free_proc
C interface
5.7.3.6
Sets context dump mode. Parameters: c : the context to be modied mode : the log mode to be set
5.7.3.7
Sets the context logging procedure used for system (warning, errors, infos . ..) messages Parameters: c : the context to be modied logp : the logging procedure to be set See also: grib_log_proc
5.7.3.8
Sets memory procedures of the context. Parameters: c : the context to be modied griballoc : the memory allocation procedure to be set See also: grib_malloc_proc Parameters: gribfree : the memory freeing procedure to be set See also: grib_free_proc
5.7 The context object 5.7.3.9 void grib_context_set_path (grib_context c, const char path)
171
Sets the context search path for denition les. Parameters: c : the context to be modied path : the search path to be set
5.7.3.10
Sets memory procedures of the context for persistent data. Parameters: c : the context to be modied griballoc : the memory allocation procedure to be set See also: grib_malloc_proc Parameters: gribfree : the memory freeing procedure to be set See also: grib_free_proc
5.7.3.11
Sets the context printing procedure used for user interaction. Parameters: c : the context to be modied printp : the printing procedure to be set See also: grib_print_proc
5.7.3.12
Sets user data in a context. Parameters: c : the context to be modied udata : the user data to set
C interface
Retreive the context from a handle. Parameters: h : the handle used to retreive the context from Returns: The handles context, NULL it the handle is invalid
5.7.3.14
Set the gribex mode off. Grib les wont be always compatible with gribex. Parameters: c : the context to be deleted
5.7.3.15
Set the gribex mode on. Grib les will be compatible with gribex. Parameters: c : the context to be deleted
5.7.3.16
Set the gts header mode off. The GTS headers will be deleted. Parameters: c : the context to be deleted
5.7.3.17
Set the gts header mode on. The GTS headers will be preserved. Parameters: c : the context to be deleted
173
Turn off support for multiple elds in single grib messages. Parameters: c : the context to be modied Examples: multi.f90, and multi_fortran.F.
5.7.3.19
Turn on support for multiple elds in single grib messages. Parameters: c : the context to be modied Examples: multi.c, multi.f90, and multi_fortran.F.
174
C interface
5.8
Denes
#dene GRIB_KEYS_ITERATOR_ALL_KEYS 0 #dene GRIB_KEYS_ITERATOR_SKIP_READ_ONLY (1<<0) #dene GRIB_KEYS_ITERATOR_SKIP_OPTIONAL (1<<1) #dene GRIB_KEYS_ITERATOR_SKIP_EDITION_SPECIFIC (1<<2) #dene GRIB_KEYS_ITERATOR_SKIP_CODED (1<<3) #dene GRIB_KEYS_ITERATOR_SKIP_COMPUTED (1<<4) #dene GRIB_KEYS_ITERATOR_SKIP_DUPLICATES (1<<5) #dene GRIB_KEYS_ITERATOR_SKIP_FUNCTION (1<<6)
Typedefs
typedef struct grib_keys_iterator grib_keys_iterator
Functions
grib_keys_iterator grib_keys_iterator_new (grib_handle h, unsigned long lter_ags, char name_space) int grib_keys_iterator_next (grib_keys_iterator kiter) const char grib_keys_iterator_get_name (grib_keys_iterator kiter) int grib_keys_iterator_delete (grib_keys_iterator kiter) int grib_keys_iterator_rewind (grib_keys_iterator kiter) int grib_keys_iterator_set_ags (grib_keys_iterator kiter, unsigned long ags)
5.8.1
Detailed Description
The keys iterator is designed to get the key names dened in a message. Key names on which the iteration is carried out can be ltered through their attributes or by the namespace they belong to.
5.8.2
5.8.2.1
Dene Documentation
#dene GRIB_KEYS_ITERATOR_ALL_KEYS 0
Iteration is carried out on all the keys available in the message See also: grib_keys_iterator_new Examples: keys_iterator.c.
175
5.8.2.3
5.8.2.4
5.8.2.5
edition specic keys are skipped by keys iterator. See also: grib_keys_iterator_new
5.8.2.6
5.8.2.7
C interface
read only keys are skipped by keys iterator. See also: grib_keys_iterator_new
5.8.3
5.8.3.1
Typedef Documentation
typedef struct grib_keys_iterator grib_keys_iterator
Grib keys iterator. Iterator over keys. Examples: keys_iterator.c, and keys_iterator_fortran.F.
5.8.4
5.8.4.1
Function Documentation
int grib_keys_iterator_delete (grib_keys_iterator kiter)
Delete the iterator. Parameters: kiter : valid grib_keys_iterator Returns: 0 if OK, integer value on error Examples: keys_iterator.c, keys_iterator.f90, and keys_iterator_fortran.F.
5.8.4.2
get the key name from the iterator Parameters: kiter : valid grib_keys_iterator Returns: key name Examples: keys_iterator.c, keys_iterator.f90, and keys_iterator_fortran.F.
177
Create a new iterator from a valid and initialized handle. Parameters: h : the handle whose keys you want to iterate lter_ags : ags to lter out some of the keys through their attributes name_space : if not null the iteration is carried out only on keys belongin to the namespace passed. (NULL for all the keys) Returns: keys iterator ready to iterate through keys according to lter_ags and namespace Examples: keys_iterator.c, and keys_iterator.f90.
5.8.4.4
Step to the next iterator. Parameters: kiter : valid grib_keys_iterator Returns: 1 if next iterator exitsts, 0 if no more elements to iterate on Examples: keys_iterator.c, keys_iterator.f90, and keys_iterator_fortran.F.
5.8.4.5
Rewind the iterator. Parameters: kiter : valid grib_keys_iterator Returns: 0 if OK, integer value on error
178
C interface
Chapter 6
Denes
#dene GRIB_API_VERSION (GRIB_API_MAJOR_VERSION10000+GRIB_API_MINOR_VERSION100+GRIB_API_REVISION_VERSION) #dene GRIB_LOG_INFO 0 #dene GRIB_LOG_WARNING 1 #dene GRIB_LOG_ERROR 2 #dene GRIB_LOG_FATAL 3 #dene GRIB_LOG_DEBUG 4 #dene GRIB_TYPE_UNDEFINED 0 #dene GRIB_TYPE_LONG 1 #dene GRIB_TYPE_DOUBLE 2 #dene GRIB_TYPE_STRING 3 #dene GRIB_TYPE_BYTES 4 #dene GRIB_TYPE_SECTION 5 #dene GRIB_TYPE_LABEL 6 #dene GRIB_TYPE_MISSING 7 #dene GRIB_MISSING_LONG 0xffffffff #dene GRIB_MISSING_DOUBLE -1e+100 #dene GRIB_DUMP_FLAG_READ_ONLY (1<<0) #dene GRIB_DUMP_FLAG_DUMP_OK (1<<1) #dene GRIB_DUMP_FLAG_VALUES (1<<2) #dene GRIB_DUMP_FLAG_CODED (1<<3) #dene GRIB_DUMP_FLAG_OCTECT (1<<4) #dene GRIB_DUMP_FLAG_ALIASES (1<<5) #dene GRIB_DUMP_FLAG_TYPE (1<<6) #dene GRIB_DUMP_FLAG_HEXADECIMAL (1<<7) #dene GRIB_DUMP_FLAG_NO_DATA (1<<8) #dene GRIB_DUMP_FLAG_ALL_DATA (1<<9) #dene GRIB_NEAREST_SAME_GRID (1<<0)
180
grib_api.h File Documentation #dene GRIB_NEAREST_SAME_DATA (1<<1) #dene GRIB_NEAREST_SAME_POINT (1<<2) #dene GRIB_KEYS_ITERATOR_ALL_KEYS 0 #dene GRIB_KEYS_ITERATOR_SKIP_READ_ONLY (1<<0) #dene GRIB_KEYS_ITERATOR_SKIP_OPTIONAL (1<<1) #dene GRIB_KEYS_ITERATOR_SKIP_EDITION_SPECIFIC (1<<2) #dene GRIB_KEYS_ITERATOR_SKIP_CODED (1<<3) #dene GRIB_KEYS_ITERATOR_SKIP_COMPUTED (1<<4) #dene GRIB_KEYS_ITERATOR_SKIP_DUPLICATES (1<<5) #dene GRIB_KEYS_ITERATOR_SKIP_FUNCTION (1<<6) #dene GRIB_CHECK(a, msg) grib_check(#a,__FILE__,__LINE__,a,msg) #dene GRIB_SUCCESS 0
No error.
#dene GRIB_END_OF_FILE -1
End of ressource reached.
#dene GRIB_INTERNAL_ERROR -2
Internal error.
#dene GRIB_BUFFER_TOO_SMALL -3
Passed buffer is too small.
#dene GRIB_NOT_IMPLEMENTED -4
Function not yet implemented.
#dene GRIB_7777_NOT_FOUND -5
Missing 7777 at end of message.
#dene GRIB_ARRAY_TOO_SMALL -6
Passed array is too small.
#dene GRIB_FILE_NOT_FOUND -7
File not found.
#dene GRIB_CODE_NOT_FOUND_IN_TABLE -8
Code not found in code table.
#dene GRIB_STRING_TOO_SMALL_FOR_CODE_NAME -9
Code cannot unpack because of string too small.
181
182
183
Typedefs
typedef struct grib_key_value_list grib_key_value_list typedef struct grib_values grib_values typedef struct grib_handle grib_handle typedef struct grib_multi_handle grib_multi_handle typedef struct grib_context grib_context typedef struct grib_iterator grib_iterator typedef struct grib_nearest grib_nearest typedef struct grib_keys_iterator grib_keys_iterator typedef struct grib_eldset grib_eldset typedef struct grib_order_by grib_order_by typedef struct grib_where grib_where typedef struct grib_darray grib_darray typedef struct grib_iarray grib_iarray typedef struct grib_index grib_index typedef void( grib_free_proc )(const grib_context c, void data)
Grib free procedure, format of a procedure referenced in the context that is used to free memory.
typedef void( grib_log_proc )(const grib_context c, int level, const char mesg)
Grib loc proc, format of a procedure referenced in the context that is used to log internal messages.
typedef void( grib_print_proc )(const grib_context c, void descriptor, const char mesg)
Grib print proc, format of a procedure referenced in the context that is used to print external messages.
typedef size_t( grib_data_read_proc )(const grib_context c, void ptr, size_t size, void stream)
Grib data read proc, format of a procedure referenced in the context that is used to read from a stream in a resource.
typedef size_t( grib_data_write_proc )(const grib_context c, const void ptr, size_t size, void stream)
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
184
typedef off_t( grib_data_seek_proc )(const grib_context c, off_t offset, int whence, void stream)
Grib data seek, format of a procedure referenced in the context that is used to seek the current position in a stream.
Functions
grib_eldset grib_eldset_new_from_les (grib_context c, char lenames[ ], int nles, char keys, int nkeys, char where_string, char order_by_string, int err) void grib_eldset_delete (grib_eldset set) void grib_eldset_rewind (grib_eldset set) int grib_eldset_apply_order_by (grib_eldset set, const char order_by_string) grib_handle grib_eldset_next_handle (grib_eldset set, int err) int grib_eldset_count (grib_eldset set) grib_index grib_index_new_from_le (grib_context c, char lename, const char keys, int err)
Create a new index form a le.
int grib_index_get_long (grib_index index, const char key, long values, size_t size)
Get the distinct values of the key in argument contained in the index.
int grib_index_get_double (grib_index index, const char key, double values, size_t size)
Get the distinct values of the key in argument contained in the index.
int grib_index_get_string (grib_index index, const char key, char values, size_t size)
Get the distinct values of the key in argument contained in the index.
6.1 grib_api.h File Reference grib_handle grib_handle_new_from_index (grib_index index, int err)
Create a new handle from an index after having selected the key values.
185
186
int grib_nearest_nd (grib_nearest nearest, grib_handle h, double inlat, double inlon, unsigned long ags, double outlats, double outlons, double values, double distances, int indexes, size_t len)
Find the 4 nearest points of a latitude longitude point.
int grib_nearest_nd_multiple (grib_handle h, int is_lsm, double inlats, double inlons, long npoints, double outlats, double outlons, double values, double distances, int indexes)
Find the nearest point of a set of points whose latitudes and longitudes are given in the inlats, inlons arrays respectively.
187
int grib_get_double_elements (grib_handle h, const char key, int i, long size, double value)
Get as double array the elements of the "key" array whose indexes are listed in the input array i.
int grib_get_string (grib_handle h, const char key, char mesg, size_t length)
Get a string value from a key, if several keys of the same name are present, the last one is returned.
int grib_get_bytes (grib_handle h, const char key, unsigned char bytes, size_t length)
Get raw bytes values from a key.
int grib_get_double_array (grib_handle h, const char key, double vals, size_t length)
Get double array values from a key.
int grib_get_long_array (grib_handle h, const char key, long vals, size_t length)
Get long array values from a key.
int grib_set_string (grib_handle h, const char key, const char mesg, size_t length)
Set a string value from a key.
int grib_set_bytes (grib_handle h, const char key, const unsigned char bytes, size_t length)
Set a bytes array from a key.
int grib_set_double_array (grib_handle h, const char key, const double vals, size_t length)
Set a double array from a key.
int grib_set_long_array (grib_handle h, const char key, const long vals, size_t length)
Set a long array from a key.
void grib_dump_content (grib_handle h, FILE out, const char mode, unsigned long option_ags, void arg)
Print all keys, with the context print procedure and dump mode to a resource.
188
189
grib_keys_iterator grib_keys_iterator_new (grib_handle h, unsigned long lter_ags, char name_space) int grib_keys_iterator_next (grib_keys_iterator kiter) const char grib_keys_iterator_get_name (grib_keys_iterator kiter) int grib_keys_iterator_delete (grib_keys_iterator kiter) int grib_keys_iterator_rewind (grib_keys_iterator kiter) int grib_keys_iterator_set_ags (grib_keys_iterator kiter, unsigned long ags) void grib_update_sections_lengths (grib_handle h) const char grib_get_error_message (int code)
Convert an error code into a string.
const char grib_get_type_name (int type) int grib_get_native_type (grib_handle h, const char name, int type) void grib_check (const char call, const char le, int line, int e, const char msg) int grib_set_values (grib_handle h, grib_values grib_values, size_t arg_count) grib_handle grib_handle_new_from_partial_message_copy (grib_context c, const void data, size_t size) grib_handle grib_handle_new_from_partial_message (grib_context c, void data, size_t buen) int grib_is_missing (grib_handle h, const char key, int err) int grib_set_missing (grib_handle h, const char key) int grib_get_gaussian_latitudes (long truncation, double latitudes) int grib_julian_to_datetime (double jd, long year, long month, long day, long hour, long minute, long second) int grib_datetime_to_julian (long year, long month, long day, long hour, long minute, long second, double jd) long grib_julian_to_date (long jdate) long grib_date_to_julian (long ddate) int wmo_read_any_from_le (FILE f, void buffer, size_t len) int wmo_read_any_from_stream (void stream_data, long(stream_proc)(void , void buffer, long len), void buffer, size_t len) void wmo_read_any_from_le_malloc (FILE f, int err)
190
6.1.1
Detailed Description
Copyright 2005-2007 ECMWF. Licensed under the GNU Lesser General Public License which incorporates the terms and conditions of version 3 of the GNU General Public License. See LICENSE and gpl-3.0.txt for details. grib_api C header le This is the only le that must be included to use the grib_api library from C.
6.1.2
6.1.2.1
Dene Documentation
#dene GRIB_7777_NOT_FOUND -5
End of resource.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
191
End of ressource reached. Examples: get.f90, get_data.f90, keys_iterator.f90, multi.f90, and samples.f90.
6.1.2.11
6.1.2.12
#dene GRIB_FILE_NOT_FOUND -7
6.1.2.21
6.1.2.22
Message invalid.
6.1.2.23
6.1.2.24
6.1.2.25
6.1.2.26
6.1.2.27
6.1.2.28
6.1.2.29
6.1.2.30
193
6.1.2.32
6.1.2.33
6.1.2.34
#dene GRIB_NOT_IMPLEMENTED -4
6.1.2.35
Null handle.
6.1.2.36
Null index.
6.1.2.37
6.1.2.38
Out of memory.
6.1.2.39
6.1.2.40
6.1.2.41
#dene GRIB_STRING_TOO_SMALL_FOR_CODE_NAME -9
6.1.2.43
Wrong units for step (step must be integer). 6.1.2.50 #dene GRIB_WRONG_TYPE -39
6.1.3
6.1.3.1
Typedef Documentation
typedef struct grib_context grib_context
Grib context, structure containing the memory methods, the parsers and the formats.
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
195
Grib iterator, structure supporting a geographic iteration of values on a grib message. Examples: iterator.c.
6.1.3.3
Grib nearest, structure used to nd the nearest points of a latitude longitude point. Examples: nearest.c.
6.1.4
6.1.4.1
Function Documentation
void grib_dump_action_tree (grib_context c, FILE f)
Print all keys from the parsed denition les available in a context. Parameters: f : the File used to print the keys on c : the context that containd the cached denition les to be printed
6.1.4.2
void grib_dump_content (grib_handle h, FILE out, const char mode, unsigned long option_ags, void arg)
Print all keys, with the context print procedure and dump mode to a resource. Parameters: h : the handle to be printed out : output le handle mode : available dump modes are: debug wmo c_code option_ags : all the GRIB_DUMP_FLAG_x ags can be used arg : used to provide a format to output data (experimental)
6.1.4.3
Gather all names available in a handle to a string, using a space as separator. Parameters: h : the handle used to gather the keys names : the sting to be lled with the names
6.1.4.5
Convert an error code into a string. Parameters: code : the error code Returns: the error message
6.1.4.6
Index
Accessing header and data values, 156 context grib_context_delete, 169 grib_context_get_default, 169 grib_context_get_user_data, 169 grib_context_new, 169 grib_context_set_buffer_memory_proc, 169 grib_context_set_dump_mode, 170 grib_context_set_logging_proc, 170 grib_context_set_memory_proc, 170 grib_context_set_path, 170 grib_context_set_persistent_memory_proc, 171 grib_context_set_print_proc, 171 grib_context_set_user_data, 171 grib_data_eof_proc, 166 grib_data_read_proc, 166 grib_data_seek_proc, 166 grib_data_tell_proc, 167 grib_data_write_proc, 167 grib_free_proc, 167 grib_get_context, 171 grib_gribex_mode_off, 172 grib_gribex_mode_on, 172 grib_gts_header_off, 172 grib_gts_header_on, 172 grib_log_proc, 167 grib_malloc_proc, 168 grib_multi_support_off, 172 grib_multi_support_on, 173 grib_print_proc, 168 grib_realloc_proc, 168 get_set grib_copy_namespace, 157 grib_get_bytes, 157 grib_get_double, 157 grib_get_double_array, 158 grib_get_double_element, 158 grib_get_double_elements, 159 grib_get_long, 159 grib_get_long_array, 159 grib_get_offset, 160 grib_get_size, 160 grib_get_string, 160 grib_set_bytes, 161 grib_set_double, 161 grib_set_double_array, 162 grib_set_long, 162 grib_set_long_array, 163 grib_set_string, 163 grib_api, 97 grib_check, 102 grib_clone, 103 grib_close_le, 103 grib_copy_message, 103 grib_copy_namespace, 104 grib_count_in_le, 104 grib_dump, 104 grib_nd_nearest_four_single, 104 grib_nd_nearest_multiple, 105 grib_nd_nearest_single, 106 grib_get_data_real4, 106 grib_get_data_real8, 107 grib_get_error_string, 107 grib_get_int, 107 grib_get_int_array, 108 grib_get_long, 108 grib_get_long_array, 108 grib_get_message_size, 109 grib_get_real4, 109 grib_get_real4_array, 109 grib_get_real4_element, 110 grib_get_real4_elements, 110 grib_get_real8, 110 grib_get_real8_array, 111 grib_get_real8_element, 111 grib_get_real8_elements, 111 grib_get_size_int, 112 grib_get_size_long, 112 grib_get_string, 112 grib_gribex_mode_off, 113 grib_gribex_mode_on, 113 grib_index_create, 113 grib_index_get_int, 114 grib_index_get_long, 114 grib_index_get_real8, 114 grib_index_get_size_int, 115 grib_index_get_size_long, 115
198 grib_index_release, 116 grib_index_select_int, 116 grib_index_select_long, 116 grib_index_select_real8, 117 grib_is_missing, 117 grib_keys_iterator_delete, 117 grib_keys_iterator_get_name, 118 grib_keys_iterator_new, 118 grib_keys_iterator_next, 118 grib_keys_iterator_rewind, 119 grib_multi_append, 119 grib_multi_support_off, 119 grib_multi_support_on, 120 grib_multi_write, 120 grib_new_from_le, 120 grib_new_from_index, 120 grib_new_from_message, 121 grib_new_from_samples, 121 grib_new_from_template, 122 grib_open_le, 122 grib_pbopen, 122 grib_pbread, 123 grib_release, 123 grib_set_int, 123 grib_set_int_array, 124 grib_set_long, 124 grib_set_long_array, 124 grib_set_missing, 125 grib_set_real4, 125 grib_set_real4_array, 125 grib_set_real8, 126 grib_set_real8_array, 126 grib_set_string, 126 grib_skip_coded, 127 grib_skip_computed, 127 grib_skip_duplicates, 127 grib_skip_read_only, 128 grib_write, 128 grib_api::grib_nd_nearest, 128 grib_api::grib_get, 130 grib_api::grib_get_data, 131 grib_api::grib_get_element, 132 grib_api::grib_get_size, 133 grib_api::grib_index_get, 134 grib_api::grib_index_get_size, 135 grib_api::grib_index_select, 136 grib_api::grib_set, 137 grib_check grib_api, 102 grib_clone grib_api, 103 grib_close_le grib_api, 103 grib_copy_message grib_api, 103 grib_copy_namespace grib_api, 104 grib_count_in_le grib_api, 104 grib_dump grib_api, 104 grib_nd_nearest_four_single grib_api, 104 grib_nd_nearest_multiple grib_api, 105 grib_nd_nearest_single grib_api, 106 grib_get_data_real4 grib_api, 106 grib_get_data_real8 grib_api, 107 grib_get_error_string grib_api, 107 grib_get_int grib_api, 107 grib_get_int_array grib_api, 108 grib_get_long grib_api, 108 grib_get_long_array grib_api, 108 grib_get_message_size grib_api, 109 grib_get_real4 grib_api, 109 grib_get_real4_array grib_api, 109 grib_get_real4_element grib_api, 110 grib_get_real4_elements grib_api, 110 grib_get_real8 grib_api, 110 grib_get_real8_array grib_api, 111 grib_get_real8_element grib_api, 111 grib_get_real8_elements grib_api, 111 grib_get_size_int grib_api, 112 grib_get_size_long grib_api, 112 grib_get_string grib_api, 112 grib_gribex_mode_off grib_api, 113 grib_gribex_mode_on
INDEX
INDEX grib_api, 113 grib_index_create grib_api, 113 grib_index_get_int grib_api, 114 grib_index_get_long grib_api, 114 grib_index_get_real8 grib_api, 114 grib_index_get_size_int grib_api, 115 grib_index_get_size_long grib_api, 115 grib_index_release grib_api, 116 grib_index_select_int grib_api, 116 grib_index_select_long grib_api, 116 grib_index_select_real8 grib_api, 117 grib_is_missing grib_api, 117 grib_keys_iterator_delete grib_api, 117 grib_keys_iterator_get_name grib_api, 118 grib_keys_iterator_new grib_api, 118 grib_keys_iterator_next grib_api, 118 grib_keys_iterator_rewind grib_api, 119 grib_multi_append grib_api, 119 grib_multi_support_off grib_api, 119 grib_multi_support_on grib_api, 120 grib_multi_write grib_api, 120 grib_new_from_le grib_api, 120 grib_new_from_index grib_api, 120 grib_new_from_message grib_api, 121 grib_new_from_samples grib_api, 121 grib_new_from_template grib_api, 122 grib_open_le grib_api, 122 grib_pbopen
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
199 grib_api, 122 grib_pbread grib_api, 123 grib_release grib_api, 123 grib_set_int grib_api, 123 grib_set_int_array grib_api, 124 grib_set_long grib_api, 124 grib_set_long_array grib_api, 124 grib_set_missing grib_api, 125 grib_set_real4 grib_api, 125 grib_set_real4_array grib_api, 125 grib_set_real8 grib_api, 126 grib_set_real8_array grib_api, 126 grib_set_string grib_api, 126 grib_skip_coded grib_api, 127 grib_skip_computed grib_api, 127 grib_skip_duplicates grib_api, 127 grib_skip_read_only grib_api, 128 grib_write grib_api, 128 GRIB_7777_NOT_FOUND grib_api.h, 190 grib_api.h, 179 GRIB_7777_NOT_FOUND, 190 GRIB_ARRAY_TOO_SMALL, 190 GRIB_BUFFER_TOO_SMALL, 190 GRIB_CODE_NOT_FOUND_IN_TABLE, 190 GRIB_CONCEPT_NO_MATCH, 190 GRIB_CONSTANT_FIELD, 190 grib_context, 194 GRIB_DECODING_ERROR, 190 grib_dump_action_tree, 195 grib_dump_content, 195 GRIB_ENCODING_ERROR, 190 GRIB_END, 190 GRIB_END_OF_FILE, 190 GRIB_END_OF_INDEX, 191 GRIB_FILE_NOT_FOUND, 191
200 GRIB_GEOCALCULUS_PROBLEM, 191 grib_get_all_names, 195 grib_get_api_version, 195 grib_get_error_message, 196 GRIB_INTERNAL_ARRAY_TOO_SMALL, 191 GRIB_INTERNAL_ERROR, 191 GRIB_INVALID_ARGUMENT, 191 GRIB_INVALID_FILE, 191 GRIB_INVALID_GRIB, 191 GRIB_INVALID_INDEX, 191 GRIB_INVALID_ITERATOR, 191 GRIB_INVALID_KEYS_ITERATOR, 192 GRIB_INVALID_MESSAGE, 192 GRIB_INVALID_NEAREST, 192 GRIB_INVALID_ORDERBY, 192 GRIB_INVALID_SECTION_NUMBER, 192 GRIB_INVALID_TYPE, 192 GRIB_IO_PROBLEM, 192 grib_iterator, 194 GRIB_MESSAGE_TOO_LARGE, 192 GRIB_MISSING_KEY, 192 grib_nearest, 195 GRIB_NO_DEFINITIONS, 192 GRIB_NO_MORE_IN_SET, 192 GRIB_NO_VALUES, 193 GRIB_NOT_FOUND, 193 GRIB_NOT_IMPLEMENTED, 193 GRIB_NULL_HANDLE, 193 GRIB_NULL_INDEX, 193 GRIB_OUT_OF_AREA, 193 GRIB_OUT_OF_MEMORY, 193 GRIB_PREMATURE_END_OF_FILE, 193 grib_print_api_version, 196 GRIB_READ_ONLY, 193 GRIB_STRING_TOO_SMALL_FOR_CODE_NAME, 193 GRIB_SUCCESS, 193 GRIB_SWITCH_NO_MATCH, 194 GRIB_VALUE_CANNOT_BE_MISSING, 194 GRIB_WRONG_ARRAY_SIZE, 194 GRIB_WRONG_GRID, 194 GRIB_WRONG_LENGTH, 194 GRIB_WRONG_STEP, 194 GRIB_WRONG_STEP_UNIT, 194 GRIB_WRONG_TYPE, 194 GRIB_ARRAY_TOO_SMALL grib_api.h, 190 GRIB_BUFFER_TOO_SMALL grib_api.h, 190 GRIB_CODE_NOT_FOUND_IN_TABLE grib_api.h, 190 GRIB_CONCEPT_NO_MATCH grib_api.h, 190 GRIB_CONSTANT_FIELD grib_api.h, 190 grib_context grib_api.h, 194 grib_context_delete context, 169 grib_context_get_default context, 169 grib_context_get_user_data context, 169 grib_context_new context, 169 grib_context_set_buffer_memory_proc context, 169 grib_context_set_dump_mode context, 170 grib_context_set_logging_proc context, 170 grib_context_set_memory_proc context, 170 grib_context_set_path context, 170 grib_context_set_persistent_memory_proc context, 171 grib_context_set_print_proc context, 171 grib_context_set_user_data context, 171 grib_copy_namespace get_set, 157 grib_count_in_le grib_handle, 145 grib_data_eof_proc context, 166 grib_data_read_proc context, 166 grib_data_seek_proc context, 166 grib_data_tell_proc context, 167 grib_data_write_proc context, 167 GRIB_DECODING_ERROR grib_api.h, 190 grib_dump_action_tree grib_api.h, 195 grib_dump_content grib_api.h, 195 GRIB_ENCODING_ERROR grib_api.h, 190 GRIB_END grib_api.h, 190 GRIB_END_OF_FILE
INDEX
INDEX grib_api.h, 190 GRIB_END_OF_INDEX grib_api.h, 191 GRIB_FILE_NOT_FOUND grib_api.h, 191 grib_free_proc context, 167 GRIB_GEOCALCULUS_PROBLEM grib_api.h, 191 grib_get_all_names grib_api.h, 195 grib_get_api_version grib_api.h, 195 grib_get_bytes get_set, 157 grib_get_context context, 171 grib_get_double get_set, 157 grib_get_double_array get_set, 158 grib_get_double_element get_set, 158 grib_get_double_elements get_set, 159 grib_get_error_message grib_api.h, 196 grib_get_long get_set, 159 grib_get_long_array get_set, 159 grib_get_message handling_coded_messages, 150 grib_get_message_copy handling_coded_messages, 150 grib_get_offset get_set, 160 grib_get_size get_set, 160 grib_get_string get_set, 160 grib_gribex_mode_off context, 172 grib_gribex_mode_on context, 172 grib_gts_header_off context, 172 grib_gts_header_on context, 172 grib_handle grib_count_in_le, 145 grib_handle, 145 grib_handle_clone, 145 grib_handle_delete, 145
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
201 grib_handle_new_from_le, 146 grib_handle_new_from_message, 146 grib_handle_new_from_message_copy, 146 grib_handle_new_from_multi_message, 147 grib_handle_new_from_samples, 147 grib_handle_new_from_template, 147 grib_multi_handle, 145 grib_multi_handle_append, 148 grib_multi_handle_delete, 148 grib_multi_handle_new, 148 grib_multi_handle_write, 149 grib_handle_clone grib_handle, 145 grib_handle_delete grib_handle, 145 grib_handle_new_from_le grib_handle, 146 grib_handle_new_from_index grib_index, 140 grib_handle_new_from_message grib_handle, 146 grib_handle_new_from_message_copy grib_handle, 146 grib_handle_new_from_multi_message grib_handle, 147 grib_handle_new_from_samples grib_handle, 147 grib_handle_new_from_template grib_handle, 147 grib_index grib_handle_new_from_index, 140 grib_index, 140 grib_index_delete, 140 grib_index_get_double, 141 grib_index_get_long, 141 grib_index_get_size, 141 grib_index_get_string, 142 grib_index_new_from_le, 142 grib_index_select_double, 143 grib_index_select_long, 143 grib_index_select_string, 143 grib_index_delete grib_index, 140 grib_index_get_double grib_index, 141 grib_index_get_long grib_index, 141 grib_index_get_size grib_index, 141 grib_index_get_string grib_index, 142 grib_index_new_from_le grib_index, 142 grib_index_select_double
202 grib_index, 143 grib_index_select_long grib_index, 143 grib_index_select_string grib_index, 143 GRIB_INTERNAL_ARRAY_TOO_SMALL grib_api.h, 191 GRIB_INTERNAL_ERROR grib_api.h, 191 GRIB_INVALID_ARGUMENT grib_api.h, 191 GRIB_INVALID_FILE grib_api.h, 191 GRIB_INVALID_GRIB grib_api.h, 191 GRIB_INVALID_INDEX grib_api.h, 191 GRIB_INVALID_ITERATOR grib_api.h, 191 GRIB_INVALID_KEYS_ITERATOR grib_api.h, 192 GRIB_INVALID_MESSAGE grib_api.h, 192 GRIB_INVALID_NEAREST grib_api.h, 192 GRIB_INVALID_ORDERBY grib_api.h, 192 GRIB_INVALID_SECTION_NUMBER grib_api.h, 192 GRIB_INVALID_TYPE grib_api.h, 192 GRIB_IO_PROBLEM grib_api.h, 192 grib_iterator grib_api.h, 194 grib_iterator_delete iterators, 151 grib_iterator_has_next iterators, 152 grib_iterator_new iterators, 152 grib_iterator_next iterators, 152 grib_iterator_previous iterators, 152 grib_iterator_reset iterators, 153 grib_keys_iterator keys_iterator, 176 GRIB_KEYS_ITERATOR_ALL_KEYS keys_iterator, 174 grib_keys_iterator_delete keys_iterator, 176 grib_keys_iterator_get_name
INDEX keys_iterator, 176 grib_keys_iterator_new keys_iterator, 176 grib_keys_iterator_next keys_iterator, 177 grib_keys_iterator_rewind keys_iterator, 177 GRIB_KEYS_ITERATOR_SKIP_CODED keys_iterator, 174 GRIB_KEYS_ITERATOR_SKIP_COMPUTED keys_iterator, 175 GRIB_KEYS_ITERATOR_SKIP_DUPLICATES keys_iterator, 175 GRIB_KEYS_ITERATOR_SKIP_EDITION_SPECIFIC keys_iterator, 175 GRIB_KEYS_ITERATOR_SKIP_FUNCTION keys_iterator, 175 GRIB_KEYS_ITERATOR_SKIP_OPTIONAL keys_iterator, 175 GRIB_KEYS_ITERATOR_SKIP_READ_ONLY keys_iterator, 175 grib_log_proc context, 167 grib_malloc_proc context, 168 GRIB_MESSAGE_TOO_LARGE grib_api.h, 192 GRIB_MISSING_KEY grib_api.h, 192 grib_multi_handle grib_handle, 145 grib_multi_handle_append grib_handle, 148 grib_multi_handle_delete grib_handle, 148 grib_multi_handle_new grib_handle, 148 grib_multi_handle_write grib_handle, 149 grib_multi_support_off context, 172 grib_multi_support_on context, 173 grib_nearest grib_api.h, 195 grib_nearest_delete iterators, 153 grib_nearest_nd iterators, 153 grib_nearest_nd_multiple iterators, 154 grib_nearest_new iterators, 154
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
INDEX GRIB_NO_DEFINITIONS grib_api.h, 192 GRIB_NO_MORE_IN_SET grib_api.h, 192 GRIB_NO_VALUES grib_api.h, 193 GRIB_NOT_FOUND grib_api.h, 193 GRIB_NOT_IMPLEMENTED grib_api.h, 193 GRIB_NULL_HANDLE grib_api.h, 193 GRIB_NULL_INDEX grib_api.h, 193 GRIB_OUT_OF_AREA grib_api.h, 193 GRIB_OUT_OF_MEMORY grib_api.h, 193 GRIB_PREMATURE_END_OF_FILE grib_api.h, 193 grib_print_api_version grib_api.h, 196 grib_print_proc context, 168 GRIB_READ_ONLY grib_api.h, 193 grib_realloc_proc context, 168 grib_set_bytes get_set, 161 grib_set_double get_set, 161 grib_set_double_array get_set, 162 grib_set_long get_set, 162 grib_set_long_array get_set, 163 grib_set_string get_set, 163 GRIB_STRING_TOO_SMALL_FOR_CODE_NAME grib_api.h, 193 GRIB_SUCCESS grib_api.h, 193 GRIB_SWITCH_NO_MATCH grib_api.h, 194 GRIB_VALUE_CANNOT_BE_MISSING grib_api.h, 194 GRIB_WRONG_ARRAY_SIZE grib_api.h, 194 GRIB_WRONG_GRID grib_api.h, 194 GRIB_WRONG_LENGTH
Generated on Wed Jul 22 16:12:40 2009 for grib_api by Doxygen
203 grib_api.h, 194 GRIB_WRONG_STEP grib_api.h, 194 GRIB_WRONG_STEP_UNIT grib_api.h, 194 GRIB_WRONG_TYPE grib_api.h, 194 Handling coded messages, 150 handling_coded_messages grib_get_message, 150 grib_get_message_copy, 150 Iterating on keys names, 174 Iterating on latitude/longitude/values, 151 iterators grib_iterator_delete, 151 grib_iterator_has_next, 152 grib_iterator_new, 152 grib_iterator_next, 152 grib_iterator_previous, 152 grib_iterator_reset, 153 grib_nearest_delete, 153 grib_nearest_nd, 153 grib_nearest_nd_multiple, 154 grib_nearest_new, 154 keys_iterator grib_keys_iterator, 176 GRIB_KEYS_ITERATOR_ALL_KEYS, 174 grib_keys_iterator_delete, 176 grib_keys_iterator_get_name, 176 grib_keys_iterator_new, 176 grib_keys_iterator_next, 177 grib_keys_iterator_rewind, 177 GRIB_KEYS_ITERATOR_SKIP_CODED, 174 GRIB_KEYS_ITERATOR_SKIP_COMPUTED, 175 GRIB_KEYS_ITERATOR_SKIP_DUPLICATES, 175 GRIB_KEYS_ITERATOR_SKIP_EDITION_SPECIFIC, 175 GRIB_KEYS_ITERATOR_SKIP_FUNCTION, 175 GRIB_KEYS_ITERATOR_SKIP_OPTIONAL, 175 GRIB_KEYS_ITERATOR_SKIP_READ_ONLY, 175 The context object, 164 The grib_handle, 144 The grib_index, 139