DESCRIPTION

Compare GRIB messages contained in two files. If some differences are found it fails returning an error code. Floating point values are compared exactly by default, different tolerance can be defined see -P -A -R. Default behaviour: absolute error=0, bit-by-bit compare, same order in files.

USAGE

grib_compare [options] grib_file1 grib_file2

OPTIONS


-r

Compare files in which the messages are not in the same order. This option is time expensive.


-b key,key,...

All the keys in this list are skipped in the comparison. Bit-by-bit compare on.


-e

Edition independent compare. It is used to compare grib edition 1 and 2.


-2

Enable two-way comparison.


-c key[:i|d|s|n],key[:i|d|s|n],...

Only the listed keys or namespaces (:n) are compared. The optional letter after the colon is used to force the type in the comparison: i->integer, d->float, s->string, n->namespace. See -a option. Incompatible with -H option.


-S start

First field to be processed.


-E end

Last field to be processed.


-a

-c option modifier. The keys listed with the option -c will be added to the list of keys compared without -c.


-H

Compare only message headers (everything except data and bitmap). Bit-by-bit compare on. Incompatible with -c option.


-R key1=relative_error1,key2=relative_error2,...

Compare floating point values using the relative error as tolerance. key1=relative_error will compare key1 using relative_error1. all=relative_error will compare all the floating point keys using relative_error. Default all=0.


-A absolute error

Compare floating point values using the absolute error as tolerance. Default is absolute error=0


-P

Compare data values using the packing error as tolerance.


-T factor

Compare data values using factor multiplied by the tolerance specified in options -P -R -A.


-w key[:{s|d|i}]{=|!=}value,key[:{s|d|i}]{=|!=}value,...

Where clause. 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), a double (key:d) or an integer (key:i) type can be specified. Default type is string. In the value you can also use the forward-slash character '/' to specify an OR condition (i.e. a logical disjunction) Note: only one -w clause is allowed.


-f

Forcefully compare, do not stop after first difference. 


-V

Version.


-7

Does not fail when the message has wrong length


-v

Verbose.

grib_compare examples

  1. The default behaviour for grib_compare without any option is to perform a bit by bit comparison of the two messages. If the messages are found to be bitwise different then grib_compare switches to a "key based" mode to find out which coded keys are different. To see how grib_compare works we first set the shortName=2d (2 metre dew point temperature) in the file regular_latlon_surface.grib1

     
    > grib_set -s shortName=2d regular_latlon_surface.grib1 2d.grib1
    
    Then we can compare the two fields with grib_compare.
     
    > grib_compare regular_latlon_surface.grib1 2d.grib1
    
    -- GRIB #1 -- shortName=2t paramId=167 stepRange=0 levelType=sfc level=0 packingType=grid_simple gridType=regular_ll --
    long [indicatorOfParameter]: [167] != [168]
    
    In the output we see that the only "coded" key with different values in the two messages is indicatorOfParameter which is the relevant key for the parameter information. The comparison can be forced to be successful listing the keys with different values in the -b option.
     
    > grib_compare -b indicatorOfParameter regular_latlon_surface.grib1 2d.grib1
    


  2. Two grib messages can be very different because they have different edition, but they can contain the same identical information in the header and the same data. To see how grib_compare can help in comparing messages with different edition we do

     
    > grib_set edition=2 reduced_gaussian_model_level.grib1 reduced_gaussian_model_level.grib2
    
    Then we compare the two fields with grib_compare.
     
    > grib_compare reduced_gaussian_model_level.grib1 reduced_gaussian_model_level.grib2
    
    -- GRIB #1 -- shortName=t paramId=130 stepRange=0 levelType=ml level=1 packingType=grid_simple gridType=reduced_gg --
    long [totalLength]: [10908] != [10996]
    long [editionNumber]: [1] != [2]
    long [section1Length]: [52] != [21]
    [table2Version] not found in 2nd field
    [gridDefinition] not found in 2nd field
    [indicatorOfParameter] not found in 2nd field
    [indicatorOfTypeOfLevel] not found in 2nd field
    [yearOfCentury] not found in 2nd field
    [unitOfTimeRange] not found in 2nd field
    [P1] not found in 2nd field
    [P2] not found in 2nd field
    [numberIncludedInAverage] not found in 2nd field
    [numberMissingFromAveragesOrAccumulations] not found in 2nd field
    [centuryOfReferenceTimeOfData] not found in 2nd field
    [reservedNeedNotBePresent] not found in 2nd field
    [perturbationNumber] not found in 2nd field
    [numberOfForecastsInEnsemble] not found in 2nd field
    [padding_local1_1] not found in 2nd field
    long [section2Length]: [896] != [17]
    [pvlLocation] not found in 2nd field
    [dataRepresentationType] not found in 2nd field
    long [latitudeOfFirstGridPoint]: [87864] != [87863799]
    long [latitudeOfLastGridPoint]: [-87864] != [-87863799]
    long [longitudeOfLastGridPoint]: [357188] != [357187500]
    [padding_grid4_1] not found in 2nd field
    long [section4Length]: [9948] != [770]
    [dataFlag] not found in 2nd field
    
    It is clear that the two messages are coded in a very different way. If we now add the -e option, the tool will compare only the higher level information common between the two messages.
     
    > grib_compare -e reduced_gaussian_model_level.grib1 reduced_gaussian_model_level.grib2
    
    -- GRIB #1 -- shortName=t paramId=130 stepRange=0 levelType=ml level=1 packingType=grid_simple gridType=reduced_gg --
    string [param]: [130.128] != [130]
    
    The comparison is successful because the two messages contain the same information coded in two different ways. We can display the list of keys used by grib_compare adding the option -v (verbose).
     
    > grib_compare -ve reduced_gaussian_model_level.grib1 reduced_gaussian_model_level.grib2
    reduced_gaussian_model_level.grib2
      comparing centre as string
      comparing paramId as long
      comparing units as string
      comparing name as string
      comparing shortName as string
      comparing typeOfLevel as string
      comparing level as long
      comparing pv as double
      (184 values) tolerance=0 	using compare_double_absolute
      comparing bitmapPresent as long
      comparing latitudeOfFirstGridPointInDegrees as double
      (1 values) tolerance=0.0005 	using compare_double_absolute
      comparing longitudeOfFirstGridPointInDegrees as double
      (1 values) tolerance=0.0005 	using compare_double_absolute
      comparing latitudeOfLastGridPointInDegrees as double
      (1 values) tolerance=0.0005 	using compare_double_absolute
      comparing longitudeOfLastGridPointInDegrees as double
      (1 values) tolerance=0.0005 	using compare_double_absolute
      comparing iDirectionIncrementInDegrees is set to missing in both fields
      comparing N as long
      comparing iScansNegatively as long
      comparing jScansPositively as long
      comparing jPointsAreConsecutive as long
      comparing pl as long
      comparing gridType as string
      comparing packedValues as double
      (6114 values) tolerance=0 	using compare_double_absolute
      comparing domain as string
      comparing levtype as string
      comparing levelist as long
      comparing date as long
      comparing time as long
      comparing step as long
      comparing param as string
    
    -- GRIB #1 -- shortName=t paramId=130 stepRange=0 levelType=ml level=1 packingType=grid_simple gridType=reduced_gg --
    string [param]: [130.128] != [130]
      comparing class as string
      comparing type as string
      comparing stream as string
      comparing expver as string
    
    For each key the type used in the comparison is reported and for the floating point keys also the tolerance used is printed.