1. Use grib_get to print the shortName, dataDate, dataTime and level for the  500 and 1000 hPa levels only in tz_an_pl.grib1.

Use:


% grib_get -w level=500/1000 -p shortName,dataDate,dataTime,level tz_an_pl.grib1 z 20190201 0 1000 t 20190201 0 1000 z 20190201 0 500 t 20190201 0 500

2. Use grib_get to print the stepRange for the field in surface.grib1 in (a) hours (b) minutes and (c) seconds. What happens ?

	% grib_get -p stepRange surface.grib1
	3
	ECCODES ERROR   :  unable to represent the step in h
   	                 	Hint: try changing the step units
	ECCODES ERROR   :  Decoding invalid

The error occurs because the stepRange of one of the fields cannot be represented in hours. Similarly, using the “-s” option to set stepUnits=m to obtain the stepRange in (b) minutes gives:

 

	% grib_get -s stepUnits=m -p stepRange surface.grib1
	180
	190
	ECCODES ERROR   :  unable to represent the step in m
    	                Hint: try changing the step units
	ECCODES ERROR   :  Decoding invalid

Finally, with stepUnits=s we obtain:


% grib_get –s stepUnits=s -p stepRange surface.grib1 10800
 11400
10830

3. Use grib_get_data to print the latitude, longitude and values for the first field in surface.grib1.

  • Output the data values in decimal format with 5 decimal places
  • Output the data values in exponential format with 10 decimal places
  • Are there any missing values ?
Use grib_get_data with "-w count=1" to restrict to the first field only and specify the format with the "-F" option
	% grib_get_data -w count=1 -F "%.5f" surface.grib1      
    Latitude, Longitude, Value
        2.500  -20.000 301.91162
        2.500  -17.500 301.55762
        2.500  -15.000 302.04150
        2.500  -12.500 302.22510
        2.500  -10.000 301.88477
        2.500   -7.500 302.10645
        2.500   -5.000 302.19580
        2.500   -2.500 302.41895
        2.500    0.000 302.48877
		...

Exponential format with 10 decimal places is the default !


% grib_get_data -w count=1 surface.grib1
    Latitude, Longitude, Value
        2.500  -20.000 3.0191162109e+02
        2.500  -17.500 3.0155761719e+02
        2.500  -15.000 3.0204150391e+02
        2.500  -12.500 3.0222509766e+02
        2.500  -10.000 3.0188476562e+02
        2.500   -7.500 3.0210644531e+02
        2.500   -5.000 3.0219580078e+02
        2.500   -2.500 3.0241894531e+02
        2.500    0.000 3.0248876953e+02
	    ...

Additional information can be printed along with the latitude, longitude and value by using the -p option.  For example:


% grib_get_data -w count=1 -p centre,dataDate,stepRange surface.grib1
    Latitude, Longitude, Value, centre, dataDate, stepRange
        2.500  -20.000 3.0191162109e+02 ecmf 20190201 3
        2.500  -17.500 3.0155761719e+02 ecmf 20190201 3
        2.500  -15.000 3.0204150391e+02 ecmf 20190201 3
        2.500  -12.500 3.0222509766e+02 ecmf 20190201 3
        2.500  -10.000 3.0188476562e+02 ecmf 20190201 3
        2.500   -7.500 3.0210644531e+02 ecmf 20190201 3
        2.500   -5.000 3.0219580078e+02 ecmf 20190201 3
        2.500   -2.500 3.0241894531e+02 ecmf 20190201 3
        2.500    0.000 3.0248876953e+02 ecmf 20190201 3
	    ...

Note that the additional keys are always printed after the latitude, longitude and values.

To check for missing values use grib_get_data with the –m option:
 
	% grib_get_data -w count=1 –m MISSING surface.grib1
	Latitude, Longitude, Value
      ...
        2.500    5.000 3.0241015625e+02
        2.500    7.500 3.0208398438e+02
        2.500   10.000 MISSING
        0.000  -20.000 3.0081640625e+02
        0.000  -17.500 3.0092626953e+02
        0.000  -15.000 3.0108740234e+02
		... 

4. Use grib_get_data to print the data values in temperature at 500hPa only from the file in tz_an_pl.grib1

  • Make sure you print only the data for T500

  • What is printed ?

Use grib_get_data with the where option to specify only shortName=t and level=500:


   % grib_get_data -w shortName=t,level=500 tz_an_pl.grib1
   Value
   2.5802954102e+02
   0.0000000000e+00
   -3.0743484497e+00
   0.0000000000e+00
   -1.0166581154e+01
   0.0000000000e+00
   4.6563935280e-01
   0.0000000000e+00
   -9.5908552408e-01

In this case, only the data values are printed; there are no values of latitude and longitude. This is because the field is stored in spectral representation. The values shown are not the values of temperature at 500 hPa. Instead, the data values printed are those of the spectral components of the field. In this case, it is not possible for grib_get_data to determine latitude-longitude values.

5.  Use grib_compare to compare the GRIB messages contained in the files file1.grib and file2.grib

  • Which keys does grib_compare report as different ? What is the exit code returned ?


To compare the headers only of the GRIB messages in file1.grib and file2.grib use


% grib_compare –H file1.grib file2.grib -- GRIB #1 -- shortName=2t paramId=167 stepRange=0 levelType=sfc level=0 packingType= gridType= -- long [generatingProcessIdentifier]: [146] != [147] string [experimentVersionNumber]: [0001] != [0070] % echo $? 1

Here, the "echo $?" prints the return code which in this case is equal to 1.  The keys different between the two messages are shown in the [ ]’s.

Note that the line "-- GRIB #1 --" refers to the GRIB message number in the file.  If there is more than one message to compare additional lines "-- GRIB #2 --", etc, are printed.

By default, messages are compared in the order in which they are found in the file.


6.  Compare the data namespaces (use “grib_compare -c data:n …” )  for file1.grib and file2.grib.  What values need to be set for the absolute (with -A) and relative (with -R) error tolerances for the comparison to be successful ?

To compare only the data namespaces we use the -c option and specify data:n


% grib_compare -c data:n file1.grib file2.grib
    -- GRIB #1 -- shortName=t paramId=130 stepRange=0 levelType=pl level=1000 packingType=grid_simple gridType=regular_ll --
    double [packedValues]: 2235 out of 259920 different
     max absolute diff. = 3.2539062500000000e+00, relative diff. = 0.0133981
          max diff. element 259353: 2.39608581542968750000e+02 2.42862487792968750000e+02
          tolerance=0.0000000000000000e+00 packingError: [0.000984192] [0.000984192]
          values max= [315.052]  [315.052]         min= [235.53] [235.53]
	% echo $?
	1

The maximum absolute error reported is 3.25390625.  If we now set the tolerance to be an absolute error not greater than, say, 3.3, the comparison is successful.


% grib_compare -A 3.3 -c data:n file1.grib file2.grib % echo $? 0

We can also use the relative error as the tolerance for the key packedValues:


% grib_compare -R packedValues=0.014 -c data:n file1.grib file2.grib % echo $? 0

To find out how many values differ by more than twice the packing error, use the -P option with -T 2:


    % grib_compare -P -T 2 -c data:n file1.grib file2.grib              
    -- GRIB #1 -- shortName=t paramId=130 stepRange=0 levelType=pl level=1000 packingType=grid_simple gridType=regular_ll --
    double [packedValues]: 1726 out of 259920 different
     max absolute diff. = 3.2539062500000000e+00, relative diff. = 0.0133981
        max diff. element 259353: 2.39608581542968750000e+02 2.42862487792968750000e+02
        tolerance=1.9683837890625000e-03 packingError: [0.000984192] [0.000984192]
        values max= [315.052]  [315.052]         min= [235.53] [235.53]


There are 1726 values reported as different when twice the packing error is used as the tolerance for the compare.