2015-02-03 13:27:57 +00:00
|
|
|
#!/bin/sh
|
2015-12-31 12:44:51 +00:00
|
|
|
# Copyright 2005-2016 ECMWF.
|
2015-02-03 13:27:57 +00:00
|
|
|
#
|
|
|
|
# This software is licensed under the terms of the Apache Licence Version 2.0
|
|
|
|
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
#
|
|
|
|
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
|
|
|
|
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
|
|
|
#
|
|
|
|
|
|
|
|
. ./include.sh
|
|
|
|
|
|
|
|
#Enter data dir
|
|
|
|
cd ${data_dir}/bufr
|
|
|
|
|
|
|
|
#Define a common label for all the tmp files
|
|
|
|
label="bufr_compare_test"
|
|
|
|
|
|
|
|
#Create log file
|
|
|
|
fLog=${label}".log"
|
|
|
|
rm -f $fLog
|
|
|
|
touch $fLog
|
|
|
|
|
|
|
|
#Define tmp bufr file
|
|
|
|
fBufrTmp=${label}".bufr.tmp"
|
|
|
|
fBufrInput1=${label}".bufr.input1"
|
|
|
|
fBufrInput2=${label}".bufr.input2"
|
|
|
|
|
|
|
|
#----------------------------------------------------
|
|
|
|
# Test: comparing same files
|
|
|
|
#----------------------------------------------------
|
|
|
|
f="syno_1.bufr"
|
|
|
|
echo "Test: comparing the same files" >> $fLog
|
|
|
|
echo "file: $f" >> $fLog
|
|
|
|
${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
|
2015-02-04 13:52:37 +00:00
|
|
|
${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
|
2015-02-03 13:27:57 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
#Alter a key in the file
|
2015-02-04 13:52:37 +00:00
|
|
|
${tools_dir}/bufr_set -s dataCategory=2 $f ${fBufrTmp} >> $fLog
|
2015-02-03 13:27:57 +00:00
|
|
|
|
|
|
|
set +e
|
2015-02-04 13:52:37 +00:00
|
|
|
${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
|
2015-02-03 13:27:57 +00:00
|
|
|
set -e
|
|
|
|
|
2016-08-09 16:22:16 +00:00
|
|
|
# Now compare with -b switch. No difference should be found.
|
2015-02-04 13:52:37 +00:00
|
|
|
${tools_dir}/bufr_compare -b dataCategory $f ${fBufrTmp}>> $fLog
|
2015-02-03 13:27:57 +00:00
|
|
|
|
|
|
|
#----------------------------------------------------
|
|
|
|
# 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
|
2015-02-04 13:52:37 +00:00
|
|
|
${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
|
2016-08-09 16:22:16 +00:00
|
|
|
set -e
|
2015-02-03 13:27:57 +00:00
|
|
|
${tools_dir}/bufr_compare -r ${fBufrInput1} ${fBufrInput2}>> $fLog
|
|
|
|
|
2015-02-09 17:04:26 +00:00
|
|
|
#----------------------------------------------------
|
|
|
|
# Change subCentre and compare
|
|
|
|
#----------------------------------------------------
|
2016-08-09 16:22:16 +00:00
|
|
|
${tools_dir}bufr_set -s bufrHeaderSubCentre=12 aaen_55.bufr $fBufrTmp
|
2015-02-09 17:04:26 +00:00
|
|
|
set +e
|
2016-08-09 16:22:16 +00:00
|
|
|
${tools_dir}bufr_compare aaen_55.bufr $fBufrTmp > $fLog 2>&1
|
2015-02-09 17:04:26 +00:00
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -eq 1 ]
|
2016-08-09 16:22:16 +00:00
|
|
|
fgrep -q "[bufrHeaderSubCentre]: [70] != [12]" $fLog
|
2015-02-09 17:04:26 +00:00
|
|
|
|
2015-07-17 10:23:43 +00:00
|
|
|
#----------------------------------------------------
|
2016-08-09 16:22:16 +00:00
|
|
|
# Second argument of bufr_compare is a directory
|
2015-07-17 10:23:43 +00:00
|
|
|
#----------------------------------------------------
|
2016-08-09 16:22:16 +00:00
|
|
|
temp_dir=tempdir.${label}
|
2015-07-17 10:23:43 +00:00
|
|
|
mkdir -p $temp_dir
|
|
|
|
infile=aaen_55.bufr
|
|
|
|
cp $infile $temp_dir
|
2016-07-06 08:49:00 +00:00
|
|
|
${tools_dir}bufr_compare $infile $temp_dir >/dev/null
|
2016-08-09 16:22:16 +00:00
|
|
|
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
|
2015-07-17 10:23:43 +00:00
|
|
|
|
|
|
|
|
2015-02-03 13:27:57 +00:00
|
|
|
#Clean up
|
2016-08-09 16:22:16 +00:00
|
|
|
rm -f $fLog $fBufrTmp $fBufrInput1 $fBufrInput2
|