ECC-302: bufr_compare does not compare attributes (part 2)

This commit is contained in:
Shahram Najm 2016-08-09 17:22:16 +01:00
parent 488b1007c2
commit a6b4c04ce9
2 changed files with 54 additions and 44 deletions

View File

@ -10,8 +10,6 @@
. ./include.sh
#set -x
#Enter data dir
cd ${data_dir}/bufr
@ -31,7 +29,6 @@ fBufrInput2=${label}".bufr.input2"
#----------------------------------------------------
# Test: comparing same files
#----------------------------------------------------
f="syno_1.bufr"
echo "Test: comparing the same files" >> $fLog
echo "file: $f" >> $fLog
@ -40,26 +37,21 @@ ${tools_dir}/bufr_compare $f $f >> $fLog
#----------------------------------------------------
# Test: comparing two completely different files
#----------------------------------------------------
set +e
f1="syno_1.bufr"
f2="aaen_55.bufr"
echo "Test: comparing two completely different files" >> $fLog
echo "file: $f" >> $fLog
${tools_dir}/bufr_compare $f1 $f2 >> $fLog
if [ $? -eq 0 ]; then
echo "bufr_compare should have failed if files are completely different" >&2
exit 1
fi
set -e
#----------------------------------------------------
# Test: comparing with and witout the -b switch
#----------------------------------------------------
f="syno_1.bufr"
echo "Test: comparing with and witout the -b switch" >> $fLog
echo "file: $f" >> $fLog
@ -69,59 +61,65 @@ ${tools_dir}/bufr_set -s dataCategory=2 $f ${fBufrTmp} >> $fLog
set +e
${tools_dir}/bufr_compare $f ${fBufrTmp}>> $fLog
if [ $? -eq 0 ]; then
echo "bufr_compare should have failed if files are different" >&2
exit 1
fi
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
#----------------------------------------------------
# Test: comparing with the -r switch
#----------------------------------------------------
#Create a bufr file with various message types
cat syno_multi.bufr temp_101.bufr > $fBufrInput1
cat temp_101.bufr syno_multi.bufr > $fBufrInput2
set +e
${tools_dir}/bufr_compare ${fBufrInput1} ${fBufrInput2} >> $fLog
if [ $? -eq 0 ]; then
echo "bufr_compare should have failed if the message order in the files is different" >&2
exit 1
fi
set -e
${tools_dir}/bufr_compare -r ${fBufrInput1} ${fBufrInput2}>> $fLog
#----------------------------------------------------
# Change subCentre and compare
#----------------------------------------------------
${tools_dir}bufr_set -s subCentre=12 aaen_55.bufr $fBufrTmp
${tools_dir}bufr_set -s bufrHeaderSubCentre=12 aaen_55.bufr $fBufrTmp
set +e
${tools_dir}bufr_compare aaen_55.bufr $fBufrTmp >/dev/null
${tools_dir}bufr_compare aaen_55.bufr $fBufrTmp > $fLog 2>&1
status=$?
set -e
[ $status -eq 1 ]
fgrep -q "[bufrHeaderSubCentre]: [70] != [12]" $fLog
#----------------------------------------------------
# Compare file with directory
# Second argument of bufr_compare is a directory
#----------------------------------------------------
temp_dir=tempdir.bufr_compare
temp_dir=tempdir.${label}
mkdir -p $temp_dir
infile=aaen_55.bufr
cp $infile $temp_dir
${tools_dir}bufr_compare $infile $temp_dir >/dev/null
rm -rf $temp_dir
#----------------------------------------------------
# Compare attributes
#----------------------------------------------------
set +e
${tools_dir}bufr_compare amv2_87.bufr amv3_87.bufr > $fLog 2>&1
status=$?
set -e
[ $status -eq 1 ]
grep -q "#1#pressure->percentConfidence" $fLog
grep -q "#1#windDirection->percentConfidence" $fLog
grep -q "#1#windSpeed->percentConfidence" $fLog
grep -q "#1#coldestClusterTemperature->percentConfidence" $fLog
#Clean up
rm -f $fLog
rm -f $fBufrTmp | true
rm -f $fBufrInput1 | true
rm -f $fBufrInput2 | true
rm -rf $temp_dir
rm -f $fLog $fBufrTmp $fBufrInput1 $fBufrInput2

View File

@ -1011,7 +1011,27 @@ static int compare_values(grib_runtime_options* options, grib_handle* handle1, g
return GRIB_SUCCESS;
}
/*#define ECC302 1*/
void reset_all_keys()
{
/* Clear the list of all keys from any previous handle */
grib_string_list* next=allkeys;
grib_string_list* cur=allkeys;
grib_context* c = grib_context_get_default();
while(next) {
cur=next;
next=next->next;
grib_context_free(c,cur->value);
grib_context_free(c,cur);
}
/* Allocate a new one */
allkeys=grib_context_malloc_clear(c, sizeof(grib_string_list));
if (!allkeys) {
fprintf(stderr, "Failed to allocate memory for keys");
exit(1);
}
}
static int compare_all_dump_keys(grib_handle* handle1, grib_handle* handle2, grib_runtime_options* options, int *err)
{
int ret=0;
@ -1020,34 +1040,33 @@ static int compare_all_dump_keys(grib_handle* handle1, grib_handle* handle2, gri
grib_set_long(handle1,"unpack",1);
grib_set_long(handle2,"unpack",1);
iter=grib_keys_iterator_new(handle1,0,NULL);
allkeys=grib_context_malloc_clear(handle1->context,sizeof(grib_string_list));
if (!iter) {
grib_context_log(handle1->context, GRIB_LOG_ERROR, "unable to create keys iterator");
exit(1);
}
reset_all_keys();
while(grib_keys_iterator_next(iter))
{
int rank = 0;
int i = 0;
int rank = 0, i = 0;
int dofree = 0;
char fullname[512] = {0,};
char fullname[1024] = {0,};
char* prefix = NULL;
grib_accessor* xa=grib_keys_iterator_get_accessor(iter);
name=grib_keys_iterator_get_name(iter);
/* printf("----- comparing %s\n",name); */
if (blacklisted(name)) continue;
if (xa==NULL || ( xa->flags & GRIB_ACCESSOR_FLAG_DUMP )==0 ) continue;
/* Compare the key itself */
if (compare_values(options,handle1,handle2,name,GRIB_TYPE_UNDEFINED)) {
err++;
write_messages(handle1,handle2);
ret=1;
}
/* attributes */
#ifdef ECC302
/* Now compare the key attributes (if any) */
rank = get_key_rank(handle1, allkeys, xa->name);
if (rank != 0) {
sprintf(fullname, "#%d#%s", rank, xa->name);
@ -1058,10 +1077,9 @@ static int compare_all_dump_keys(grib_handle* handle1, grib_handle* handle2, gri
sprintf(fullname, "%s", xa->name);
prefix = (char*)xa->name;
}
/* not a leaf */
i=0;
while (i < MAX_ACCESSOR_ATTRIBUTES && xa->attributes[i]) {
int isLeaf = 0;
/*int isLeaf = 0;*/
long native_type = 0;
grib_accessor* aa = NULL;
if ( (xa->attributes[i]->flags & GRIB_ACCESSOR_FLAG_DUMP)== 0 ) {
@ -1069,15 +1087,10 @@ static int compare_all_dump_keys(grib_handle* handle1, grib_handle* handle2, gri
continue;
}
aa = xa->attributes[i]; /*dump_long_attribute*/
native_type = grib_accessor_get_native_type(aa);
/* read only check?? */
native_type = grib_accessor_get_native_type(aa); /* read only check?? */
sprintf(fullname, "%s->%s", prefix, aa->name);
isLeaf=aa->attributes[0]==NULL ? 1 : 0;
if (native_type == GRIB_TYPE_LONG ||
native_type == GRIB_TYPE_DOUBLE)
{
/*printf("++ i=%d fullname='%s' (leaf=%d)\n",i,fullname,isLeaf);*/
/*printf(" Comparing %s\n", fullname);*/
/*isLeaf=aa->attributes[0]==NULL ? 1 : 0;*/
if (native_type == GRIB_TYPE_LONG || native_type == GRIB_TYPE_DOUBLE) {
if (compare_values(options,handle1,handle2,fullname,GRIB_TYPE_UNDEFINED)) {
err++;
write_messages(handle1,handle2);
@ -1087,7 +1100,6 @@ static int compare_all_dump_keys(grib_handle* handle1, grib_handle* handle2, gri
++i;
}
if (dofree) grib_context_free(handle1->context, prefix);
#endif
}
grib_keys_iterator_delete(iter);