grib_compare

DESCRIPTION

Compares the grib messages contained in two files one by one in the same order. If some differences are found it fails returning an error code. All the keys are compared except those listed with the -b option and those that are specific of a different grib edition. Also data values are compared and are considered as different if their maximum absolute difference is greater than the absolute error, that by default is 0.000001. The value used by the absolute error can be set with te -e option.

USAGE

grib_compare [options] grib_file grib_file

OPTIONS

-b key,key,...
Black list. All the keys in this list are skipped when comparing the two files.

-c key,key,...
Keys to compare. Only the listed keys are compared.

-e tolerance
Only values whose difference is more than tolerance are considered different.

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

-f
Force. Force the execution not to fail on error.

-V
Version.

-7
Does not fail when the message has wrong length

-v
Verbose.

grib_compare examples

  1. If we want to know exactly which keys are different in two grib messages a bit by bit comparison does not help us. Moreover if we know that two grib messages are different by only a few keys and we want to be sure that only those keys are different a smart compare tool is needed.
    The grib_compare is made to deal with both cases.
    To see how grib_compare works we first set the short_name=2D (2 metre dew point temperature) in the file ../data/regular_latlon_surface.grib1
    >grib_set -s short_name=2D ../data/regular_latlon_surface.grib1 ../data/2D.grib1
    
    Then we can compare the two fields with grib_compare.
    >grib_compare ../data/regular_latlon_surface.grib1 ../data/2D.grib1
    ------ 1 --------
    [gribTablesVersionNo] long  values are different: [128] and [0]
    [indicatorOfParameter] long  values are different: [167] and [0]
    
    In the output we see that not only is the short_name is changed from 2T to 2D, but also marsParam,parameter and grib1_name are changed. This is because all the keys related to the short name are changed simultaneously. The exit code for the previous command is 1 as the comparison failed.
    If we already know that the keys short_name, marsParam, parameter, grib1_name are different in the two grib messages, we can check that those are the only different keys grouping them in a blacklist with the -b option.
    >grib_compare -b grib1_short_name,marsParam,parameter,grib1_name ../data/regular_latlon_surface.grib1 ../data/2D.grib1
    ------ 1 --------
    [gribTablesVersionNo] long  values are different: [128] and [0]
    [indicatorOfParameter] long  values are different: [167] and [0]
    
    In this case the exit code is 0 because the comparison is considered successful according to the blacklist provided.

  2. grib_compare can also compare data values between two grib messages. In this case a precision can be provided through the -e option otherwise a the default (0.000001) is used. To show how data values are compared we can first repack a field with a different precision to see what grib_compare is giving in output to highlight this difference.
    For example if we want to pack a temperature expressed in Kelvin with 1 digit of precision after the decimal point we can set setDecimalPrecision=1
    >grib_set -s setDecimalPrecision=1 ../data/regular_latlon_surface.grib2 ../data/precision_1.grib2
    

    Now we can compare the two fields to see what is the difference between the values:
    >grib_compare ../data/regular_latlon_surface.grib2 precision_1.grib2
    ------ 1 --------
    [decimalScaleFactor] long  values are different: [0] and [1]
    [numberOfBitsContainingEachPackedValue] long  values are different: [16] and [9]
    
    The exit code in this case is again 1 because the comparison failed and the difference (last line) is of the order of 0.05.
    If we group in a blacklist referenceValue,binaryScaleFactor,decimalScaleFactor,numberOfBitsContainingEachPackedValue and we set the precision to 0.06 (-e 0.06) we can run again the grib_compare getting 0 as exit code because the comparison is successuful according to the blacklist and the precision required.
    >grib_compare -b referenceValue,binaryScaleFactor,decimalScaleFactor,numberOfBitsContainingEachPackedValue -e 0.06 ../data/regular_latlon_surface.grib2 precision_1.grib2
    ------ 1 --------
    

Generated on Tue Jul 8 10:17:28 2008 for grib_api by  doxygen 1.5.4