...
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
Code Block > grib_set -s shortName=2d regular_latlon_surface.grib1 2d.grib1
Then we can compare the two fields with grib_compare
Code Block > 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
Code Block > grib_compare -b indicatorOfParameter regular_latlon_surface.grib1 2d.grib1
Some options are provided to compare only a set of keys in the messages. The option -H is used to compare only the headers coded in the message, it doesn't compare the data values. The option "-c key1:[i|d|s|n],key2:[i|d|s|n],... " can be used to compare a set of keys or namespaces. The letter after the colon is optional and it is used to force the type used in the comparison which is otherwise assumed to be the native type of the key. The possible types are:
- :i -> integer
- :d -> floating point (C type double)
- :s -> string
- :n -> namespace.
We first compare the two files using the -H option (only headers are compared)Code Block set bitsPerValue=10; set values={1,2.5,3,4,5,6,70}; write "first.grib1"; set values={1,2.5,5,4,5,6,70}; write "second.grib1";
The comparison is successful because the data are not compared. To compare only the data we have to compare the "data namespace".Code Block > grib_compare -H first.grib1 second.grib1
Code Block > grib_compare -c data:n first.grib1 second.grib1 -- GRIB #1 -- shortName=t paramId=130 stepRange=0 levelType=ml level=1 packingType=grid_simple gridType=reduced_gg -- double [packedValues]: 1 out of 7 different max absolute diff. = 2.0000000000000000e+00, relative diff. = 0.4 max diff. element 2: 3.00000000000000000000e+00 5.00000000000000000000e+00 tolerance=0.0000000000000000e+00 packingError: [0.0625005] [0.0625005] values max= [70] [70] min= [1] [1]