- Main Page
- Modules
- Files
- Related Pages
- Examples

# grib_dump

## DESCRIPTION

Dump the content of a grib file in different formats.

## USAGE

grib_dump [options] grib_file grib_file ...

## OPTIONS

-O
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 specified. Default type is string.
-M
Multi-grib support off. Turn off support for multiple fields in single grib message
-7
Does not fail when the message has wrong length
-V
Version.
-G
GRIBEX compatibility mode.

## grib_dump examples

1. To dump in a WMO documentation style with hexadecimal octet values (-H)

       >grib_dump -H ../data/reduced_gaussian_model_level.grib1

2. To obtain all the key names available in a grib file.

       > grib_dump -D ../data/regular_latlon_surface.grib1

3. To obtain a C code example from a grib file.

       >grib_dump -C ../data/regular_latlon_surface.grib1
       #include <grib_api.h>

       /* This code was generated automatically */

       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);

           /* 167 = 2 metre temperature  (K)  (grib1/2.98.128.table)  */
           GRIB_CHECK(grib_set_long(h,"indicatorOfParameter",167),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,"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)  (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 = 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);

           /* 1 = Operational archive (mars/class.table)  */
           GRIB_CHECK(grib_set_long(h,"marsClass",1),0);

           /* 2 = Analysis (mars/type.table)  */
           GRIB_CHECK(grib_set_long(h,"marsType",2),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);
           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);

           /* 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;
       }