Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. By default grib_index_build will index on the MARS keys.

    Code Block
     
    >  grib_index_build ../data/reduced*.grib1 ../data/regular*.grib1 ../data/reduced*.grib2
    



  2. To specify a custom list of keys to index on, use the -k option.

    Code Block
     
    >  grib_index_build -k paramId,dataDate ../data/reduced*.grib1 ../data/regular*.grib1 ../data/reduced*.grib2
    




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.

    Code Block
     
    >  grib_ls ../data/reduced*.grib1 ../data/regular*.grib1 ../data/reduced*.grib2 
    



  2. To print offset and count number in file use the keys offset and count Also the total count in a set of files is available as countTotal

    Code Block
     
    >  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.

    Code Block
     
    >  grib_ls -w levelType=pl ../tigge_pf_ecmwf.grib2 
    



  4. All the grib messages not on pressure levels are listed as follows:

    Code Block
     
    >  grib_ls -w levelType!=pl ../tigge_pf_ecmwf.grib2 
    



  5. To get the closest grid point to a latitude/longitude.

    Code Block
     
    > grib_ls -l 51.46,-1.33,1 -p paramId,name ../data/reduced_gaussian_surface.grib2
    ../data/reduced_gaussian_surface.grib2
    paramId     shortName    value 
    167         2t          282.002     
    1 of 1 messages in ../data/reduced_gaussian_surface.grib2
    
    1 of 1 total messages in 1 files
    Input Point: latitude=51.46  longitude=-1.33
    Grid Point chosen #3 index=749 latitude=51.63 longitude=0.00 distance=93.81 (Km)
    Other grid Points
    <ul><li>1 - index=845 latitude=48.84 longitude=0.00 distance=306.86 (Km)
    </li><li>2 - index=944 latitude=48.84 longitude=356.40 distance=333.66 (Km)
    </li><li>3 - index=749 latitude=51.63 longitude=0.00 distance=93.81 (Km)
    </li><li>4 - index=844 latitude=51.63 longitude=356.25 distance=168.37 (Km)
    



  6. To get a list ordered by the 'level' key (ascending order).

    Code Block
     
    >  grib_ls -B 'level:i asc' tigge_af_ecmwf.grib2
    

    Note: we need to specify the ':i' to get a numerical sort. By default values are sorted as strings so a level of 100 would come before 20!



grib_set examples

  1. To set productDefinitionTemplateNumber=2 only for the fields with productDefinitionTemplateNumber=11

    Code Block
    > grib_set -s productDefinitionTemplateNumber=2 -w productDefinitionTemplateNumber=11 ../data/tigge_pf_ecmwf.grib2 out.grib2
    



  2. To set productDefinitionTemplateNumber=2 only for the fields for which productDefinitionTemplateNumber is not equal to 11

    Code Block
    > grib_set -s productDefinitionTemplateNumber=2 -w productDefinitionTemplateNumber!=11 tigge_pf_ecmwf.grib2 out.grib2
    



  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:

    Code Block
    > grib_set -s scaleFactorOfFirstFixedSurface=missing,scaledValueOfFirstFixedSurface=MISSING ../data/regular_latlon_surface.grib2 out.grib2
    

    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 fields for which scaleFactorOfSecondFixedSurface is not missing:

    Code Block
     
    > grib_set -s scaleFactorOfSecondFixedSurface=missing -w scaleFactorOfSecondFixedSurface!=missing tigge_pf_ecmwf.grib2 out.grib2
    



  5. It is possible to produce a GRIB edition 2 file from a GRIB edition 1 by just changing the edition number with grib_set. However it is important that you carefully inspect the output and check the information is correctly translated.

    Code Block
     
    grib_set -s edition=2 ../data/reduced_gaussian_pressure_level.grib1 out.grib2
    

    For more details please see: https://software.ecmwf.int/wiki/display/ECC/GRIB%3A+Converting+edition+1+to+2


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

    Code Block
     
    > grib_set -s packingType=grid_jpeg ../data/regular_gaussian_model_level.grib2 out.grib2
    



  7. It's possible to ask ecCodes to calculate the number of bits per value needed to pack a given field with a fixed 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

    Code Block
     
    > grib_set -s changeDecimalPrecision=1 ../data/regular_latlon_surface.grib2 ../data/out.grib2
    




grib_to_netcdf examples

  1. Produce a NetCDF file from grib edition 1

    Code Block
    > grib_to_netcdf -o output.nc input.grib1
    



  2. If your grib file has analysis and 6-hour forecast, then ignore keys 'type' and 'step'. Thus type=an/fc and step=00/06 will not be considered as netcdf dimensions.

    Code Block
    > grib_to_netcdf -I type,step -o output.nc input.grib
    



  3. Do not use time of validity. If time of validity is used, it means the 1D time coordinate is considered as date+time+step, otherwise 3 different dimensions are created. The default behaviour is to use the time of validity.

    Code Block
    > grib_to_netcdf -T -o output.nc input.grib
    



  4. Produce NetCDF with data type of FLOAT (32bit floating-point, for higher precision). Note these types were chosen to provide a reasonably wide range of trade-offs between data precision and number of bits required for each value

    Code Block
    > grib_to_netcdf -D NC_FLOAT -o output.nc input.grib
    



  5. Set the netcdf dimension 'time' to be unlimited i.e. time can have unlimited length so variables using this dimension can grow along this dimension.

    Code Block
    > grib_to_netcdf -u time -o output.nc input.grib