Page tree
Skip to end of metadata
Go to start of metadata

Solution to grib_dump practical

1.  To view the keys available for GRIB1 and GRIB2 have a look at the parameter database at http://apps.ecmwf.int/codes/grib/

2.  To use grib_dump to inspect the contents of file1.grib1:

  % grib_dump file1.grib1

By using grib_dump on its own and with the various options, (-O, -a, etc), you should find:

•    the message is encoded using GRIB edition 1 (editionNumber=1);
•    it contains the 2 metre temperature field (shortName=2t, marsParam=167.128);
•    the dataDate= 20110225, the dataTime=12 and the forecast step=12;
•    the data is on a reduced Gaussian grid (typeOfGrid=reduced_gg) with N=128 (Nj=256);

Alternatively, with grib_dump inspect some templates in the “GRIB_SAMPLES_PATH” directory.
 
3.  For the file file2.grib2

   % grib_dump file1.grib2

By using grib_dump on its own and with various options, (-O, -a etc), you should find:

•    the message is encoded using GRIB edition 2 - grib_edition=2;
•    it contains the temperature field on a specified height of 2 m above ground (shortName=2t, paramId = 167, discipline = 0, parameterCategory = 0, parameterNumber = 0, typeOfFirstFixedSurface = 103);
•    the dataDate=20110225, the dataTime=12 and the forecast step=12;
•    the data is on a reduced Gaussian grid (typeOfGrid=reduced_gg) with N=128 (Nj=256);

4. To quickly find the maximum, minimum and average values of the field, look for the computed keys max, min, and average.  

For both files you should find:

•    maximum = 314.204
•    minimum = 222.44
•    average = 285.261
 
Solution to grib_ls practical


1.  To list the GRIB messages in msl.grib1

%  grib_ls msl.grib1
edition      centre       typeOfLevel  level        dataDate     stepRange    dataType     shortName    packingType  gridType
1            ecmf         surface      0            20110225     0            cf           msl          grid_simple  regular_gg
1            ecmf         surface      0            20110225     6            cf           msl          grid_simple  regular_gg
1            ecmf         surface      0            20110225     12           cf           msl          grid_simple  regular_gg
1            ecmf         surface      0            20110225     18           cf           msl          grid_simple  regular_gg
1            ecmf         surface      0            20110225     24           cf           msl          grid_simple  regular_gg
5 of 5 grib messages in msl.grib1


The file contains mean sea-level pressure (shortName=msl) from the ECMWF EPS control forecast (dataType=cf) for 6-hourly steps from 0 to 24 hours for dataDate=20110225.  The messages are encoded in GRIB edition 1.


2.  To list the GRIB messages in msl.grib2

%  grib_ls msl.grib2
edition      centre       date         dataType     gridType     stepRange    typeOfLevel  level        shortName    packingType
2            ecmf         20110225     cf           regular_gg   0            meanSea      0            msl          grid_simple
2            ecmf         20110225     cf           regular_gg   6            meanSea      0            msl          grid_simple
2            ecmf         20110225     cf           regular_gg   12           meanSea      0            msl          grid_simple
2            ecmf         20110225     cf           regular_gg   18           meanSea      0            msl          grid_simple
2            ecmf         20110225     cf           regular_gg   24           meanSea      0            msl          grid_simple
5 of 5 grib messages in msl.grib2


The file also contains mean sea-level pressure (shortName=msl) from the ECMWF EPS control forecast (dataType=cf) for 6-hourly steps from 0 to 24 hours for dataDate=20110225.  In this file the messages are encoded in GRIB edition 2.

The lists show the default keys printed by grib_ls for GRIB 1 and GRIB 2.


3.  To print the mars keys, use grib_ls -m:
% grib_ls -m msl.grib1
domain      levtype     date        time        step        param       class       type        stream      expver
   g           sfc         20110225    0000        0           151.128     od          cf          enfo        0001
   g           sfc         20110225    0000        6           151.128     od          cf          enfo        0001
   g           sfc         20110225    0000        12          151.128     od          cf          enfo        0001
   g           sfc         20110225    0000        18          151.128     od          cf          enfo        0001
   g           sfc         20110225    0000        24          151.128     od          cf          enfo        0001
  5 of 5 grib messages in msl.grib1

% grib_ls -m msl.grib1
   msl.grib2
   domain      date        time        expver      class       type        stream      step        levtype     levelist    param
   g           20110225    0000        0001        od          cf          enfo        0           sfc         0           151
   g           20110225    0000        0001        od          cf          enfo        6           sfc         0           151
   g           20110225    0000        0001        od          cf          enfo        12          sfc         0           151
   g           20110225    0000        0001        od          cf          enfo        18          sfc         0           151
   g           20110225    0000        0001        od          cf          enfo        24          sfc         0           151
   5 of 5 grib messages in msl.grib2

   5 of 5 total grib messages in 1 files


4.  Output can be printed in descending step order using grib_ls with the -B option.  Note it is necessary to use “step:i” here as step has a default type of ‘string’.

   % grib_ls -B "step:i desc" msl.grib1
   edition      centre       typeOfLevel  level        dataDate     stepRange    dataType     shortName    packingType  gridType
   1            ecmf         surface      0            20110225     24           cf           msl          grid_simple  regular_gg
   1            ecmf         surface      0            20110225     18           cf           msl          grid_simple  regular_gg
   1            ecmf         surface      0            20110225     12           cf           msl          grid_simple  regular_gg
   1            ecmf         surface      0            20110225     6            cf           msl          grid_simple  regular_gg
   1            ecmf         surface      0            20110225     0            cf           msl          grid_simple  regular_gg

   % grib_ls -B "step:i desc" msl.grib2
   edition      centre       date         dataType     gridType     stepRange    typeOfLevel  level        shortName    packingType
   2            ecmf         20110225     cf           regular_gg   24           meanSea      0            msl          grid_simple
   2            ecmf         20110225     cf           regular_gg   18           meanSea      0            msl          grid_simple
   2            ecmf         20110225     cf           regular_gg   12           meanSea      0            msl          grid_simple
   2            ecmf         20110225     cf           regular_gg   6            meanSea      0            msl          grid_simple
   2            ecmf         20110225     cf           regular_gg   0            meanSea      0            msl          grid_simple


5.  To specify a set of keys to print, use the -p option:

  % grib_ls -p centre,dataDate,stepRange,typeOfLevel,shortName  msl.grib1
centre       dataDate     stepRange     typeOfLevel  shortName
ecmf         20110225     0             surface      msl
ecmf         20110225     6             surface      msl
ecmf         20110225     12            surface      msl
ecmf         20110225     18            surface      msl
ecmf         20110225     24            surface      msl
5 of 5 grib messages in msl.grib1


Using the "key:i" for centre and levelType prints these keys as their integer values rather than strings:

  % grib_ls -p centre:i,dataDate,stepRange,levelType:i,shortName,paramId msl.grib1
centre       dataDate     stepRange    levelType   shortName    paramId
98           20110225     0            1            msl          151
98           20110225     6            1            msl          151
98           20110225     12           1            msl          151
98           20110225     18           1            msl          151
98           20110225     24           1            msl          151
5 of 5 grib messages in msl.grib1


Similarly for msl.grib2:

  % grib_ls -p centre:i,dataDate,stepRange,levelType:i,shortName,paramId msl.grib2
centre       dataDate     stepRange    levelType  shortName    paramId
98           20110225     0            101          msl          151
98           20110225     6            101          msl          151
98           20110225     12           101          msl          151
98           20110225     18           101          msl          151
98           20110225     24           101          msl          151
5 of 5 grib messages in msl.grib2

 
Solution to grib_ls -l  practical

1.  To list the nearest points to ECMWF (Lat 51.42 N, Lon 0.95 W) use

   % grib_ls -l 51.42,-0.95 msl.grib1
   …

   5 of 5 total grib messages in 1 files
   Input Point: latitude=51.42  longitude=-0.95
   Grid Point chosen #3 index=17199 latitude=51.62 longitude=359.10 distance=22.57 (Km)
   Other grid Points
   - 1 - index=17599 latitude=50.72 longitude=359.10 distance=77.54 (Km)
   - 2 - index=17598 latitude=50.72 longitude=358.20 distance=97.59 (Km)
   - 3 - index=17199 latitude=51.62 longitude=359.10 distance=22.57 (Km)
   - 4 - index=17198 latitude=51.62 longitude=358.20 distance=62.87 (Km)
   
   Note we specify the longitude of 0.95 W with -0.95 !
   The nearest grid point is at latitude=51.62 longitude=359.10 (=0.9 W) and is 22.57 km from ECMWF.


2. To output only the forecast step and MSLP value at the nearest grid point use:

% grib_ls -l 51.42,-0.95,1 -p stepRange msl.grib1
   stepRange    value
   0           102527
   6           102365
   12          102456
   18          102289
   24          101862
   5 of 5 grib messages in msl.grib1

   Input Point: latitude=51.42  longitude=-0.95
   Grid Point chosen #3 index=17199 latitude=51.62 longitude=359.10 distance=22.57 (Km)
   Other grid Points
   - 1 - index=17599 latitude=50.72 longitude=359.10 distance=77.54 (Km)
   - 2 - index=17598 latitude=50.72 longitude=358.20 distance=97.59 (Km)
   - 3 - index=17199 latitude=51.62 longitude=359.10 distance=22.57 (Km)
   - 4 - index=17198 latitude=51.62 longitude=358.20 distance=62.87 (Km)
 
Note it is necessary to specify MODE=1 in order to print the value of the nearest grid point only.  

To output the values at the four grid points nearest to ECMWF, use MODE=4 which is the default:

% grib_ls -l 51.42,-0.95 -p stepRange msl.grib1
   stepRange          value1  value2  value3  value4
   0           102674 102663 102527 102501
   6           102532 102516 102365 102333
   12          102633 102585 102456 102426
   18          102444 102390 102289 102259
   24          102057 101959 101862 101760
   5 of 5 grib messages in msl.grib1

   Input Point: latitude=51.42  longitude=-0.95
   Grid Point chosen #3 index=17199 latitude=51.62 longitude=359.10 distance=22.57 (Km)
   Other grid Points
   - 1 - index=17599 latitude=50.72 longitude=359.10 distance=77.54 (Km)
   - 2 - index=17598 latitude=50.72 longitude=358.20 distance=97.59 (Km)
   - 3 - index=17199 latitude=51.62 longitude=359.10 distance=22.57 (Km)
   - 4 - index=17198 latitude=51.62 longitude=358.20 distance=62.87 (Km)
 
3. To specify the land-sea mask, use:

% grib_ls -l 51.42,-0.95,1,lsm.grib1 -p stepRange msl.grib1
stepRange    value
0           102527
6           102365
12          102456
18          102289
24          101862
5 of 5 grib messages in msl.grib1

Input Point: latitude=51.42  longitude=-0.95
Grid Point chosen #3 index=17199 latitude=51.62 longitude=359.10 distance=22.57 (Km)
Mask values:
- 1 - index=17599 latitude=50.72 longitude=359.10 distance=77.54 (Km) value=0.00
- 2 - index=17598 latitude=50.72 longitude=358.20 distance=97.59 (Km) value=1.00
- 3 - index=17199 latitude=51.62 longitude=359.10 distance=22.57 (Km) value=1.00
- 4 - index=17198 latitude=51.62 longitude=358.20 distance=62.87 (Km) value=1.00

Here the mask value at the end of the line showing the four nearest grid points indicates which are land points: Land points have mask ≥ 0.5; sea points have mask<0.5.

  • No labels