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

Question 1

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 ?


 Solution...

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=t paramId=130 stepRange=0 levelType=pl level=1000 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.

Question 2

Now use the –b option to ‘black list’ the keys that you know are different and use grib_compare to compare the messages again

  • Are any keys reported as different ? What is the exit code ?


 Solution...

Set those keys that are shown to be different in a 'black list' with the -b option and re-run grib_compare


% grib_compare -b generatingProcessIdentifier,experimentVersionNumber file1.grib file2.grib % echo $? 0

Here the files are considered to be identical subject to the 'black list'  and the return code is 0.

Question 3

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 ? How many data values compare to within twice the packing error ?

 

 Solution...

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 compare to within twice the packing error, use the -P option together with -T 2 to specify that the tolerance used should be the packing error multiplied by a factor of 2:


% grib_compare -c data:n -P -T 2 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]

We see that 1726 values out of 259920 differ by more than twice the packing error so 258194 can be considered to be the same.


 

 

 

  • No labels