mirror of https://github.com/ecmwf/eccodes.git
ECC-651: grib_compare/bufr_compare: Enable a 'two-way' switch for symmetric comparison
This commit is contained in:
commit
2eb1b016e9
|
@ -35,7 +35,7 @@ fRules=${label}.filter
|
||||||
f="syno_1.bufr"
|
f="syno_1.bufr"
|
||||||
echo "Test: comparing the same files" >> $fLog
|
echo "Test: comparing the same files" >> $fLog
|
||||||
echo "file: $f" >> $fLog
|
echo "file: $f" >> $fLog
|
||||||
${tools_dir}//bufr_compare $f $f >> $fLog
|
${tools_dir}/bufr_compare $f $f >> $fLog
|
||||||
|
|
||||||
#----------------------------------------------------
|
#----------------------------------------------------
|
||||||
# Test: comparing two completely different files
|
# Test: comparing two completely different files
|
||||||
|
@ -45,7 +45,7 @@ f1="syno_1.bufr"
|
||||||
f2="aaen_55.bufr"
|
f2="aaen_55.bufr"
|
||||||
echo "Test: comparing two completely different files" >> $fLog
|
echo "Test: comparing two completely different files" >> $fLog
|
||||||
echo "file: $f" >> $fLog
|
echo "file: $f" >> $fLog
|
||||||
${tools_dir}//bufr_compare $f1 $f2 >> $fLog
|
${tools_dir}/bufr_compare $f1 $f2 >> $fLog
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "bufr_compare should have failed if files are completely different" >&2
|
echo "bufr_compare should have failed if files are completely different" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -60,10 +60,10 @@ echo "Test: comparing with and witout the -b switch" >> $fLog
|
||||||
echo "file: $f" >> $fLog
|
echo "file: $f" >> $fLog
|
||||||
|
|
||||||
#Alter a key in the file
|
#Alter a key in the file
|
||||||
${tools_dir}//bufr_set -s dataCategory=2 $f ${fBufrTmp} >> $fLog
|
${tools_dir}/bufr_set -s dataCategory=2 $f ${fBufrTmp} >> $fLog
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
${tools_dir}//bufr_compare $f ${fBufrTmp}>> $fLog
|
${tools_dir}/bufr_compare $f ${fBufrTmp}>> $fLog
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "bufr_compare should have failed if files are different" >&2
|
echo "bufr_compare should have failed if files are different" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -71,7 +71,7 @@ fi
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Now compare with -b switch. No difference should be found.
|
# Now compare with -b switch. No difference should be found.
|
||||||
${tools_dir}//bufr_compare -b dataCategory $f ${fBufrTmp}>> $fLog
|
${tools_dir}/bufr_compare -b dataCategory $f ${fBufrTmp}>> $fLog
|
||||||
|
|
||||||
#----------------------------------------------------
|
#----------------------------------------------------
|
||||||
# Test: comparing with the -r switch
|
# Test: comparing with the -r switch
|
||||||
|
@ -81,13 +81,13 @@ ${tools_dir}//bufr_compare -b dataCategory $f ${fBufrTmp}>> $fLog
|
||||||
#cat temp_101.bufr syno_multi.bufr > $fBufrInput2
|
#cat temp_101.bufr syno_multi.bufr > $fBufrInput2
|
||||||
|
|
||||||
#set +e
|
#set +e
|
||||||
#${tools_dir}//bufr_compare ${fBufrInput1} ${fBufrInput2} >> $fLog
|
#${tools_dir}/bufr_compare ${fBufrInput1} ${fBufrInput2} >> $fLog
|
||||||
#if [ $? -eq 0 ]; then
|
#if [ $? -eq 0 ]; then
|
||||||
# echo "bufr_compare should have failed if the message order in the files is different" >&2
|
# echo "bufr_compare should have failed if the message order in the files is different" >&2
|
||||||
# exit 1
|
# exit 1
|
||||||
#fi
|
#fi
|
||||||
#set -e
|
#set -e
|
||||||
#${tools_dir}//bufr_compare -r ${fBufrInput1} ${fBufrInput2}>> $fLog
|
#${tools_dir}/bufr_compare -r ${fBufrInput1} ${fBufrInput2}>> $fLog
|
||||||
|
|
||||||
#----------------------------------------------------
|
#----------------------------------------------------
|
||||||
# Change subCentre and compare
|
# Change subCentre and compare
|
||||||
|
@ -138,5 +138,22 @@ ${tools_dir}/codes_bufr_filter -o $fBufrTmp $fRules $f
|
||||||
# Header keys have not changed
|
# Header keys have not changed
|
||||||
${tools_dir}/bufr_compare -H $f $fBufrTmp
|
${tools_dir}/bufr_compare -H $f $fBufrTmp
|
||||||
|
|
||||||
#Clean up
|
#----------------------------------------------------
|
||||||
|
# Compare two-way (symmetric mode)
|
||||||
|
#----------------------------------------------------
|
||||||
|
f=$ECCODES_SAMPLES_PATH/BUFR3.tmpl
|
||||||
|
# Add a local section
|
||||||
|
${tools_dir}/bufr_set -s section2Present=1 $f $fBufrTmp
|
||||||
|
# Compare A with B will pass
|
||||||
|
${tools_dir}/bufr_compare $f $fBufrTmp
|
||||||
|
# Compare with -2 option
|
||||||
|
set +e
|
||||||
|
${tools_dir}/bufr_compare -2 $f $fBufrTmp > $fLog 2>&1
|
||||||
|
status=$?
|
||||||
|
set -e
|
||||||
|
[ $status -eq 1 ]
|
||||||
|
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
# -------------
|
||||||
rm -f $fLog $fBufrTmp $fBufrInput1 $fBufrInput2 $fRules
|
rm -f $fLog $fBufrTmp $fBufrInput1 $fBufrInput2 $fRules
|
||||||
|
|
|
@ -20,6 +20,7 @@ rm -f $outfile
|
||||||
${tools_dir}/grib_set -s shortName=2d $infile $outfile
|
${tools_dir}/grib_set -s shortName=2d $infile $outfile
|
||||||
${tools_dir}/grib_compare -b indicatorOfParameter,paramId,shortName $infile $outfile > $REDIRECT
|
${tools_dir}/grib_compare -b indicatorOfParameter,paramId,shortName $infile $outfile > $REDIRECT
|
||||||
|
|
||||||
|
# ----------------------------------------
|
||||||
# Test the -r switch
|
# Test the -r switch
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
infile=${data_dir}/v.grib2
|
infile=${data_dir}/v.grib2
|
||||||
|
@ -34,6 +35,7 @@ ${tools_dir}/grib_compare -r temp_comp.123 temp_comp.321
|
||||||
|
|
||||||
rm -f temp_comp.1 temp_comp.2 temp_comp.3 temp_comp.123 temp_comp.321
|
rm -f temp_comp.1 temp_comp.2 temp_comp.3 temp_comp.123 temp_comp.321
|
||||||
|
|
||||||
|
# ----------------------------------------
|
||||||
# GRIB-797: test last argument being a directory
|
# GRIB-797: test last argument being a directory
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
temp_dir=tempdir.grib_compare
|
temp_dir=tempdir.grib_compare
|
||||||
|
@ -42,6 +44,7 @@ cp $infile $temp_dir
|
||||||
${tools_dir}/grib_compare $infile $temp_dir
|
${tools_dir}/grib_compare $infile $temp_dir
|
||||||
rm -rf $temp_dir
|
rm -rf $temp_dir
|
||||||
|
|
||||||
|
# ----------------------------------------
|
||||||
# ECC-245: blacklist and 2nd order packing
|
# ECC-245: blacklist and 2nd order packing
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
temp1=grib_compare_temp1.grib
|
temp1=grib_compare_temp1.grib
|
||||||
|
@ -67,6 +70,7 @@ set -e
|
||||||
[ $status -eq 1 ]
|
[ $status -eq 1 ]
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------
|
||||||
# ECC-355: -R with "all" option
|
# ECC-355: -R with "all" option
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
${tools_dir}/grib_copy -w count=1 ${data_dir}/tigge_cf_ecmwf.grib2 $temp1
|
${tools_dir}/grib_copy -w count=1 ${data_dir}/tigge_cf_ecmwf.grib2 $temp1
|
||||||
|
@ -77,6 +81,56 @@ ${tools_dir}/grib_compare -b $BLACKLIST -R referenceValue=0.03,codedValues=2 $te
|
||||||
# Now try the "all" option with the highest relative diff value
|
# Now try the "all" option with the highest relative diff value
|
||||||
${tools_dir}/grib_compare -b $BLACKLIST -R all=2 $temp1 $temp2
|
${tools_dir}/grib_compare -b $BLACKLIST -R all=2 $temp1 $temp2
|
||||||
|
|
||||||
|
# ----------------------------------------
|
||||||
|
# ECC-651: Two-way (symmetric) comparison
|
||||||
|
# ----------------------------------------
|
||||||
|
sample_g1=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
|
||||||
|
temp_nold=$temp1
|
||||||
|
${tools_dir}/grib_set -s deleteLocalDefinition=1 $sample_g1 $temp_nold
|
||||||
|
# Now the sample has a local definition but $temp_nold does not
|
||||||
|
set +e
|
||||||
|
${tools_dir}/grib_compare $temp_nold $sample_g1 > $outfile
|
||||||
|
status=$?
|
||||||
|
set -e
|
||||||
|
[ $status -eq 1 ]
|
||||||
|
reffile=grib_compare_temp1.ref
|
||||||
|
cat > $reffile <<EOF
|
||||||
|
|
||||||
|
-- GRIB #1 -- shortName=z paramId=129 stepRange=0 levelType=pl level=500 packingType=grid_simple gridType=regular_ll --
|
||||||
|
long [totalLength]: [84] != [107]
|
||||||
|
long [section1Length]: [28] != [52]
|
||||||
|
long [section4Length]: [12] != [11]
|
||||||
|
EOF
|
||||||
|
|
||||||
|
diff $reffile $outfile
|
||||||
|
|
||||||
|
# Two-way mode enabled
|
||||||
|
set +e
|
||||||
|
${tools_dir}/grib_compare -2 $temp_nold $sample_g1 > $outfile
|
||||||
|
status=$?
|
||||||
|
set -e
|
||||||
|
[ $status -eq 1 ]
|
||||||
|
cat > $reffile <<EOF
|
||||||
|
|
||||||
|
-- GRIB #1 -- shortName=z paramId=129 stepRange=0 levelType=pl level=500 packingType=grid_simple gridType=regular_ll --
|
||||||
|
long [totalLength]: [84] != [107]
|
||||||
|
long [section1Length]: [28] != [52]
|
||||||
|
long [section4Length]: [12] != [11]
|
||||||
|
[reservedNeedNotBePresent] not found in 1st field
|
||||||
|
[localDefinitionNumber] not found in 1st field
|
||||||
|
[marsClass] not found in 1st field
|
||||||
|
[marsType] not found in 1st field
|
||||||
|
[marsStream] not found in 1st field
|
||||||
|
[experimentVersionNumber] not found in 1st field
|
||||||
|
[perturbationNumber] not found in 1st field
|
||||||
|
[numberOfForecastsInEnsemble] not found in 1st field
|
||||||
|
[padding_local1_1] not found in 1st field
|
||||||
|
EOF
|
||||||
|
|
||||||
|
diff $reffile $outfile
|
||||||
|
rm -f $reffile
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
# --------------
|
||||||
rm -f $temp1 $temp2
|
rm -f $temp1 $temp2
|
||||||
rm -f $outfile
|
rm -f $outfile
|
||||||
|
|
|
@ -59,6 +59,15 @@ int error=0;
|
||||||
int count=0;
|
int count=0;
|
||||||
int lastPrint=0;
|
int lastPrint=0;
|
||||||
int force=0;
|
int force=0;
|
||||||
|
|
||||||
|
/* ECC-651: Boolean 'two_way' set to 1 when '-2' option used */
|
||||||
|
int two_way=0;
|
||||||
|
/* Boolean 'handles_swapped' relevant in 'two_way' mode:
|
||||||
|
* 0 means: h1 is first file, h2 is second file
|
||||||
|
* 1 means: h1 is second file, h2 is first file
|
||||||
|
*/
|
||||||
|
int handles_swapped=0;
|
||||||
|
|
||||||
double maxAbsoluteError = 1e-19;
|
double maxAbsoluteError = 1e-19;
|
||||||
int onlyListed=1;
|
int onlyListed=1;
|
||||||
int headerMode=0;
|
int headerMode=0;
|
||||||
|
@ -185,7 +194,8 @@ grib_option grib_options[]={
|
||||||
/* {id, args, help}, on, command_line, value*/
|
/* {id, args, help}, on, command_line, value*/
|
||||||
/*{"r",0,"Compare files in which the messages are not in the same order. This option is time expensive.\n",0,1,0},*/
|
/*{"r",0,"Compare files in which the messages are not in the same order. This option is time expensive.\n",0,1,0},*/
|
||||||
{"b:",0,0,0,1,0},
|
{"b:",0,0,0,1,0},
|
||||||
{"d",0,"Write different messages on files\n",0,1,0},
|
{"d",0,"Write different messages on files.\n",0,1,0},
|
||||||
|
{"2",0,"Enable two-way comparison.\n",0,1,0},
|
||||||
{"T:",0,0,1,0,"B"},
|
{"T:",0,0,1,0,"B"},
|
||||||
{"c:",0,0,0,1,0},
|
{"c:",0,0,0,1,0},
|
||||||
{"S:","start","First field to be processed.\n",0,1,0},
|
{"S:","start","First field to be processed.\n",0,1,0},
|
||||||
|
@ -251,6 +261,9 @@ int grib_tool_init(grib_runtime_options* options)
|
||||||
if (grib_options_on("f")) force=1;
|
if (grib_options_on("f")) force=1;
|
||||||
else force=0;
|
else force=0;
|
||||||
|
|
||||||
|
if (grib_options_on("2")) two_way=1;
|
||||||
|
else two_way=0;
|
||||||
|
|
||||||
if (grib_options_on("d")) write_error=1;
|
if (grib_options_on("d")) write_error=1;
|
||||||
else write_error=0;
|
else write_error=0;
|
||||||
|
|
||||||
|
@ -474,7 +487,23 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
||||||
|
|
||||||
if(compare_handles(global_handle,h,options)) {
|
if(compare_handles(global_handle,h,options)) {
|
||||||
error++;
|
error++;
|
||||||
if (!force) exit(1);
|
if (!two_way) {
|
||||||
|
/* If two_way mode: Don't exit yet. Show further differences */
|
||||||
|
if (!force) exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (two_way) {
|
||||||
|
/* ECC-651 and ECC-431 */
|
||||||
|
handles_swapped = 1;
|
||||||
|
if(compare_handles(h, global_handle, options)) {
|
||||||
|
error++;
|
||||||
|
if (!force) exit(1);
|
||||||
|
} else {
|
||||||
|
if (error) {
|
||||||
|
/* Error from first pass */
|
||||||
|
if (!force) exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
grib_handle_delete(global_handle);
|
grib_handle_delete(global_handle);
|
||||||
|
@ -611,6 +640,8 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
||||||
double packingError1=0,packingError2=0;
|
double packingError1=0,packingError2=0;
|
||||||
double value_tolerance=0;
|
double value_tolerance=0;
|
||||||
grib_context* c=handle1->context;
|
grib_context* c=handle1->context;
|
||||||
|
char* first_str = (handles_swapped==0? "1st" : "2nd");
|
||||||
|
char* second_str = (handles_swapped==0? "2nd" : "1st");
|
||||||
|
|
||||||
type1=type;
|
type1=type;
|
||||||
type2=type;
|
type2=type;
|
||||||
|
@ -619,7 +650,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
||||||
if( type1==GRIB_TYPE_UNDEFINED && (err = grib_get_native_type(handle1,name,&type1)) != GRIB_SUCCESS)
|
if( type1==GRIB_TYPE_UNDEFINED && (err = grib_get_native_type(handle1,name,&type1)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("Oops... cannot get type of [%s] in 1st field: %s\n",name,grib_get_error_message(err));
|
printf("Oops... cannot get type of [%s] in %s field: %s\n",name, first_str, grib_get_error_message(err));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -629,12 +660,12 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
||||||
if(err == GRIB_NOT_FOUND)
|
if(err == GRIB_NOT_FOUND)
|
||||||
{
|
{
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("[%s] not found in 2nd field\n",name);
|
printf("[%s] not found in %s field\n",name, second_str);
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("Oops... cannot get type of [%s] in 2nd field: %s\n",name,grib_get_error_message(err));
|
printf("Oops... cannot get type of [%s] in %s field: %s\n",name, second_str, grib_get_error_message(err));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -655,7 +686,7 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
||||||
if((err = grib_get_size(handle1,name,&len1)) != GRIB_SUCCESS)
|
if((err = grib_get_size(handle1,name,&len1)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("Oops... cannot get size of [%s] in 1st field: %s\n",name,grib_get_error_message(err));
|
printf("Oops... cannot get size of [%s] in %s field: %s\n",name, first_str, grib_get_error_message(err));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -665,17 +696,21 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
||||||
if(err == GRIB_NOT_FOUND)
|
if(err == GRIB_NOT_FOUND)
|
||||||
{
|
{
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("[%s] not found in 2nd field\n",name);
|
printf("[%s] not found in %s field\n",name,second_str);
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("Oops... cannot get size of [%s] in 2nd field: %s\n",name,grib_get_error_message(err));
|
printf("Oops... cannot get size of [%s] in %s field: %s\n",name, second_str, grib_get_error_message(err));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (handles_swapped) {
|
||||||
|
/* Comparing a second time with handles swapped. Do not compare keys common to both handles */
|
||||||
|
return GRIB_SUCCESS;
|
||||||
|
}
|
||||||
/* if(len1 != len2 && type1 != GRIB_TYPE_STRING) {
|
/* if(len1 != len2 && type1 != GRIB_TYPE_STRING) {
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("[%s] has different size: 1st field: %ld, 2nd field: %ld\n",name,(long)len1,(long)len2);
|
printf("[%s] has different size: 1st field: %ld, 2nd field: %ld\n",name,(long)len1,(long)len2);
|
||||||
|
@ -695,18 +730,18 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMissing1==1) {
|
if (isMissing1==1) {
|
||||||
if (verbose) printf(" is set to missing in 1st field\n");
|
if (verbose) printf(" is set to missing in %s field\n", first_str);
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("%s is set to missing in 1st field is not missing in 2nd field\n",name);
|
printf("%s is set to missing in %s field is not missing in %s field\n",name,first_str,second_str);
|
||||||
err1 = GRIB_VALUE_MISMATCH;
|
err1 = GRIB_VALUE_MISMATCH;
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return GRIB_VALUE_MISMATCH;
|
return GRIB_VALUE_MISMATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMissing2==1) {
|
if (isMissing2==1) {
|
||||||
if (verbose) printf(" is set to missing in 1st field\n");
|
if (verbose) printf(" is set to missing in %s field\n", first_str);
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("%s is set to missing in 2nd field is not missing in 1st field\n",name);
|
printf("%s is set to missing in %s field is not missing in %s field\n",name, second_str, first_str);
|
||||||
err1 = GRIB_VALUE_MISMATCH;
|
err1 = GRIB_VALUE_MISMATCH;
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return GRIB_VALUE_MISMATCH;
|
return GRIB_VALUE_MISMATCH;
|
||||||
|
@ -724,16 +759,16 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
||||||
if((err1 = grib_get_string(handle1,name,sval1,&len1)) != GRIB_SUCCESS)
|
if((err1 = grib_get_string(handle1,name,sval1,&len1)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("Oops... cannot get string value of [%s] in 1st field: %s\n",
|
printf("Oops... cannot get string value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err1));
|
name, first_str, grib_get_error_message(err1));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((err2 = grib_get_string(handle2,name,sval2,&len2)) != GRIB_SUCCESS)
|
if((err2 = grib_get_string(handle2,name,sval2,&len2)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("Oops... cannot get string value of [%s] in 2nd field: %s\n",
|
printf("Oops... cannot get string value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err2));
|
name, second_str, grib_get_error_message(err2));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -777,16 +812,16 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
||||||
if((err1 = grib_get_long_array(handle1,name,lval1,&len1)) != GRIB_SUCCESS)
|
if((err1 = grib_get_long_array(handle1,name,lval1,&len1)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("Oops... cannot get long value of [%s] in 1st field: %s\n",
|
printf("Oops... cannot get long value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err1));
|
name, first_str, grib_get_error_message(err1));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((err2 = grib_get_long_array(handle2,name,lval2,&len2)) != GRIB_SUCCESS)
|
if((err2 = grib_get_long_array(handle2,name,lval2,&len2)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("Oops... cannot get long value of [%s] in 2nd field: %s\n",
|
printf("Oops... cannot get long value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err2));
|
name,second_str,grib_get_error_message(err2));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -869,16 +904,16 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
||||||
if((err1 = grib_get_double_array(handle1,name,dval1,&len1)) != GRIB_SUCCESS)
|
if((err1 = grib_get_double_array(handle1,name,dval1,&len1)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("Oops... cannot get double value of [%s] in 1st field: %s\n",
|
printf("Oops... cannot get double value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err1));
|
name, first_str, grib_get_error_message(err1));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((err2 = grib_get_double_array(handle2,name,dval2,&len2)) != GRIB_SUCCESS)
|
if((err2 = grib_get_double_array(handle2,name,dval2,&len2)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
printf("Oops... cannot get double value of [%s] in 2nd field: %s\n",
|
printf("Oops... cannot get double value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err2));
|
name,second_str,grib_get_error_message(err2));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -987,16 +1022,16 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
|
||||||
{
|
{
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
printf("Oops... cannot get bytes value of [%s] in 1st field: %s\n",
|
printf("Oops... cannot get bytes value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err1));
|
name,first_str,grib_get_error_message(err1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if((err2 = grib_get_bytes(handle2,name,uval2,&len2)) != GRIB_SUCCESS)
|
if((err2 = grib_get_bytes(handle2,name,uval2,&len2)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(handle1);
|
printInfo(handle1);
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
printf("Oops... cannot get bytes value of [%s] in 2nd field: %s\n",
|
printf("Oops... cannot get bytes value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err2));
|
name,second_str,grib_get_error_message(err2));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS)
|
if(err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS)
|
||||||
|
@ -1249,7 +1284,6 @@ static int compare_handles(grib_handle* handle1, grib_handle* handle2, grib_runt
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if ( listFromCommandLine ) {
|
if ( listFromCommandLine ) {
|
||||||
for (i=0; i< options->compare_count; i++) {
|
for (i=0; i< options->compare_count; i++) {
|
||||||
if (blacklisted(name)) continue;
|
if (blacklisted(name)) continue;
|
||||||
|
|
|
@ -52,6 +52,15 @@ int error=0;
|
||||||
int count=0;
|
int count=0;
|
||||||
int lastPrint=0;
|
int lastPrint=0;
|
||||||
int force=0;
|
int force=0;
|
||||||
|
|
||||||
|
/* ECC-651: Boolean 'two_way' set to 1 when '-2' option used */
|
||||||
|
int two_way=0;
|
||||||
|
/* Boolean 'handles_swapped' relevant in 'two_way' mode:
|
||||||
|
* 0 means: h1 is first file, h2 is second file
|
||||||
|
* 1 means: h1 is second file, h2 is first file
|
||||||
|
*/
|
||||||
|
int handles_swapped=0;
|
||||||
|
|
||||||
double maxAbsoluteError = 1e-19;
|
double maxAbsoluteError = 1e-19;
|
||||||
int onlyListed=1;
|
int onlyListed=1;
|
||||||
int headerMode=0;
|
int headerMode=0;
|
||||||
|
@ -119,6 +128,7 @@ grib_option grib_options[]={
|
||||||
{"r",0,"Compare files in which the messages are not in the same order. This option is time expensive.\n",0,1,0},
|
{"r",0,"Compare files in which the messages are not in the same order. This option is time expensive.\n",0,1,0},
|
||||||
{"b:",0,0,0,1,0},
|
{"b:",0,0,0,1,0},
|
||||||
{"e",0,"Edition independent compare. It is used to compare grib edition 1 and 2.\n",0,1,0},
|
{"e",0,"Edition independent compare. It is used to compare grib edition 1 and 2.\n",0,1,0},
|
||||||
|
{"2",0,"Enable two-way comparison.\n",0,1,0},
|
||||||
{"c:",0,0,0,1,0},
|
{"c:",0,0,0,1,0},
|
||||||
{"S:","start","First field to be processed.\n",0,1,0},
|
{"S:","start","First field to be processed.\n",0,1,0},
|
||||||
{"E:","end","Last field to be processed.\n",0,1,0},
|
{"E:","end","Last field to be processed.\n",0,1,0},
|
||||||
|
@ -183,6 +193,9 @@ int grib_tool_init(grib_runtime_options* options)
|
||||||
if (grib_options_on("f")) force=1;
|
if (grib_options_on("f")) force=1;
|
||||||
else force=0;
|
else force=0;
|
||||||
|
|
||||||
|
if (grib_options_on("2")) two_way=1;
|
||||||
|
else two_way=0;
|
||||||
|
|
||||||
verbose = grib_options_on("v");
|
verbose = grib_options_on("v");
|
||||||
|
|
||||||
listFromCommandLine=0;
|
listFromCommandLine=0;
|
||||||
|
@ -431,7 +444,23 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
|
||||||
|
|
||||||
if(compare_handles(global_handle,h,options)) {
|
if(compare_handles(global_handle,h,options)) {
|
||||||
error++;
|
error++;
|
||||||
if (!force) exit(1);
|
if (!two_way) {
|
||||||
|
/* If two_way mode: Don't exit yet. Show further differences */
|
||||||
|
if (!force) exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (two_way) {
|
||||||
|
/* ECC-651 and ECC-431 */
|
||||||
|
handles_swapped = 1;
|
||||||
|
if(compare_handles(h, global_handle, options)) {
|
||||||
|
error++;
|
||||||
|
if (!force) exit(1);
|
||||||
|
} else {
|
||||||
|
if (error) {
|
||||||
|
/* Error from first pass */
|
||||||
|
if (!force) exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
grib_handle_delete(global_handle);
|
grib_handle_delete(global_handle);
|
||||||
|
@ -562,6 +591,8 @@ static int compare_values(grib_runtime_options* options,grib_handle* h1,grib_han
|
||||||
double packingError1=0,packingError2=0;
|
double packingError1=0,packingError2=0;
|
||||||
double value_tolerance=0;
|
double value_tolerance=0;
|
||||||
grib_context* c=h1->context;
|
grib_context* c=h1->context;
|
||||||
|
char* first_str = (handles_swapped==0? "1st" : "2nd");
|
||||||
|
char* second_str = (handles_swapped==0? "2nd" : "1st");
|
||||||
|
|
||||||
type1=type;
|
type1=type;
|
||||||
type2=type;
|
type2=type;
|
||||||
|
@ -573,7 +604,7 @@ static int compare_values(grib_runtime_options* options,grib_handle* h1,grib_han
|
||||||
if( type1==GRIB_TYPE_UNDEFINED && (err = grib_get_native_type(h1,name,&type1)) != GRIB_SUCCESS)
|
if( type1==GRIB_TYPE_UNDEFINED && (err = grib_get_native_type(h1,name,&type1)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
printf("Oops... cannot get type of [%s] in 1st field: %s\n",name,grib_get_error_message(err));
|
printf("Oops... cannot get type of [%s] in %s field: %s\n",name,first_str,grib_get_error_message(err));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -583,24 +614,22 @@ static int compare_values(grib_runtime_options* options,grib_handle* h1,grib_han
|
||||||
if(err == GRIB_NOT_FOUND)
|
if(err == GRIB_NOT_FOUND)
|
||||||
{
|
{
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
printf("[%s] not found in 2nd field\n",name);
|
printf("[%s] not found in %s field\n",name,second_str);
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
printf("Oops... cannot get type of [%s] in 2nd field: %s\n",name,grib_get_error_message(err));
|
printf("Oops... cannot get type of [%s] in %s field: %s\n",name,second_str,grib_get_error_message(err));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* if(type1 != type2) {
|
||||||
if(type1 != type2)
|
printInfo(h1);
|
||||||
{
|
printf("Warning, [%s] has different types: 1st field: [%s], 2nd field: [%s]\n",
|
||||||
printInfo(h1);
|
name,grib_get_type_name(type1),grib_get_type_name(type2));
|
||||||
printf("Warning, [%s] has different types: 1st field: [%s], 2nd field: [%s]\n",
|
return GRIB_TYPE_MISMATCH;
|
||||||
name,grib_get_type_name(type1),grib_get_type_name(type2));
|
}
|
||||||
return GRIB_TYPE_MISMATCH;
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(type1 == GRIB_TYPE_LABEL)
|
if(type1 == GRIB_TYPE_LABEL)
|
||||||
|
@ -613,7 +642,7 @@ static int compare_values(grib_runtime_options* options,grib_handle* h1,grib_han
|
||||||
if((err = grib_get_size(h1,name,&len1)) != GRIB_SUCCESS)
|
if((err = grib_get_size(h1,name,&len1)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
printf("Oops... cannot get size of [%s] in 1st field: %s\n",name,grib_get_error_message(err));
|
printf("Oops... cannot get size of [%s] in %s field: %s\n",name,first_str,grib_get_error_message(err));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -623,25 +652,28 @@ static int compare_values(grib_runtime_options* options,grib_handle* h1,grib_han
|
||||||
if(err == GRIB_NOT_FOUND)
|
if(err == GRIB_NOT_FOUND)
|
||||||
{
|
{
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
printf("[%s] not found in 2nd field\n",name);
|
printf("[%s] not found in %s field\n",name,second_str);
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
printf("Oops... cannot get size of [%s] in 2nd field: %s\n",name,grib_get_error_message(err));
|
printf("Oops... cannot get size of [%s] in %s field: %s\n",name,second_str,grib_get_error_message(err));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (handles_swapped) {
|
||||||
if(len1 != len2 && type1 != GRIB_TYPE_STRING)
|
/* Comparing a second time with handles swapped. Do not compare keys common to both handles */
|
||||||
{
|
return GRIB_SUCCESS;
|
||||||
printInfo(h1);
|
}
|
||||||
printf("[%s] has different size: 1st field: %ld, 2nd field: %ld\n",name,(long)len1,(long)len2);
|
|
||||||
save_error(c,name);
|
/* if(len1 != len2 && type1 != GRIB_TYPE_STRING) {
|
||||||
return GRIB_COUNT_MISMATCH;
|
printInfo(h1);
|
||||||
}
|
printf("[%s] has different size: 1st field: %ld, 2nd field: %ld\n",name,(long)len1,(long)len2);
|
||||||
|
save_error(c,name);
|
||||||
|
return GRIB_COUNT_MISMATCH;
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
isMissing1= ( (grib_is_missing(h1,name,&err1)==1) && (err1 == 0) ) ? 1 : 0;
|
isMissing1= ( (grib_is_missing(h1,name,&err1)==1) && (err1 == 0) ) ? 1 : 0;
|
||||||
|
@ -653,18 +685,18 @@ static int compare_values(grib_runtime_options* options,grib_handle* h1,grib_han
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMissing1==1) {
|
if (isMissing1==1) {
|
||||||
if (verbose) printf(" is set to missing in 1st field\n");
|
if (verbose) printf(" is set to missing in %s field\n",first_str);
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
printf("%s is set to missing in 1st field is not missing in 2nd field\n",name);
|
printf("%s is set to missing in %s field is not missing in %s field\n",name,first_str,second_str);
|
||||||
err1 = GRIB_VALUE_MISMATCH;
|
err1 = GRIB_VALUE_MISMATCH;
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return GRIB_VALUE_MISMATCH;
|
return GRIB_VALUE_MISMATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMissing2==1) {
|
if (isMissing2==1) {
|
||||||
if (verbose) printf(" is set to missing in 1st field\n");
|
if (verbose) printf(" is set to missing in %s field\n",first_str);
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
printf("%s is set to missing in 2nd field is not missing in 1st field\n",name);
|
printf("%s is set to missing in %s field is not missing in %s field\n",name,second_str,first_str);
|
||||||
err1 = GRIB_VALUE_MISMATCH;
|
err1 = GRIB_VALUE_MISMATCH;
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
return GRIB_VALUE_MISMATCH;
|
return GRIB_VALUE_MISMATCH;
|
||||||
|
@ -682,16 +714,16 @@ static int compare_values(grib_runtime_options* options,grib_handle* h1,grib_han
|
||||||
if((err1 = grib_get_string(h1,name,sval1,&len1)) != GRIB_SUCCESS)
|
if((err1 = grib_get_string(h1,name,sval1,&len1)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
printf("Oops... cannot get string value of [%s] in 1st field: %s\n",
|
printf("Oops... cannot get string value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err1));
|
name,first_str,grib_get_error_message(err1));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((err2 = grib_get_string(h2,name,sval2,&len2)) != GRIB_SUCCESS)
|
if((err2 = grib_get_string(h2,name,sval2,&len2)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
printf("Oops... cannot get string value of [%s] in 2nd field: %s\n",
|
printf("Oops... cannot get string value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err2));
|
name,second_str,grib_get_error_message(err2));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -724,16 +756,16 @@ static int compare_values(grib_runtime_options* options,grib_handle* h1,grib_han
|
||||||
if((err1 = grib_get_long_array(h1,name,lval1,&len1)) != GRIB_SUCCESS)
|
if((err1 = grib_get_long_array(h1,name,lval1,&len1)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
printf("Oops... cannot get long value of [%s] in 1st field: %s\n",
|
printf("Oops... cannot get long value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err1));
|
name,first_str,grib_get_error_message(err1));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((err2 = grib_get_long_array(h2,name,lval2,&len2)) != GRIB_SUCCESS)
|
if((err2 = grib_get_long_array(h2,name,lval2,&len2)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
printf("Oops... cannot get long value of [%s] in 2nd field: %s\n",
|
printf("Oops... cannot get long value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err2));
|
name,second_str,grib_get_error_message(err2));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -837,16 +869,16 @@ static int compare_values(grib_runtime_options* options,grib_handle* h1,grib_han
|
||||||
if((err1 = grib_get_double_array(h1,name,dval1,&len1)) != GRIB_SUCCESS)
|
if((err1 = grib_get_double_array(h1,name,dval1,&len1)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
printf("Oops... cannot get double value of [%s] in 1st field: %s\n",
|
printf("Oops... cannot get double value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err1));
|
name,first_str,grib_get_error_message(err1));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((err2 = grib_get_double_array(h2,name,dval2,&len2)) != GRIB_SUCCESS)
|
if((err2 = grib_get_double_array(h2,name,dval2,&len2)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
printf("Oops... cannot get double value of [%s] in 2nd field: %s\n",
|
printf("Oops... cannot get double value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err2));
|
name,second_str,grib_get_error_message(err2));
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -945,16 +977,16 @@ static int compare_values(grib_runtime_options* options,grib_handle* h1,grib_han
|
||||||
{
|
{
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
printf("Oops... cannot get bytes value of [%s] in 1st field: %s\n",
|
printf("Oops... cannot get bytes value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err1));
|
name,first_str,grib_get_error_message(err1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if((err2 = grib_get_bytes(h2,name,uval2,&len2)) != GRIB_SUCCESS)
|
if((err2 = grib_get_bytes(h2,name,uval2,&len2)) != GRIB_SUCCESS)
|
||||||
{
|
{
|
||||||
printInfo(h1);
|
printInfo(h1);
|
||||||
save_error(c,name);
|
save_error(c,name);
|
||||||
printf("Oops... cannot get bytes value of [%s] in 2nd field: %s\n",
|
printf("Oops... cannot get bytes value of [%s] in %s field: %s\n",
|
||||||
name,grib_get_error_message(err2));
|
name,second_str,grib_get_error_message(err2));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS)
|
if(err1 == GRIB_SUCCESS && err2 == GRIB_SUCCESS)
|
||||||
|
|
Loading…
Reference in New Issue