2015-02-02 15:16:32 +00:00
|
|
|
#!/bin/sh
|
2020-01-28 14:32:34 +00:00
|
|
|
# (C) Copyright 2005- ECMWF.
|
2015-02-02 15:16:32 +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
|
|
|
|
|
|
|
|
#set -x
|
|
|
|
|
2020-07-04 14:30:10 +00:00
|
|
|
# Enter data dir
|
2015-02-02 15:16:32 +00:00
|
|
|
cd ${data_dir}/bufr
|
|
|
|
|
2020-07-04 14:30:10 +00:00
|
|
|
# Define a common label for all the tmp files
|
2015-02-02 15:16:32 +00:00
|
|
|
label="bufr_set_test"
|
|
|
|
|
2020-07-04 14:30:10 +00:00
|
|
|
# Create log file
|
2015-02-02 15:16:32 +00:00
|
|
|
fLog=${label}".log"
|
|
|
|
rm -f $fLog
|
|
|
|
touch $fLog
|
|
|
|
|
2020-07-04 14:30:10 +00:00
|
|
|
# Define tmp bufr file
|
2015-02-02 15:16:32 +00:00
|
|
|
fBufrTmp=${label}".bufr.tmp"
|
|
|
|
|
|
|
|
#----------------------------------------------------
|
|
|
|
# Test: setting header for single message file
|
|
|
|
#----------------------------------------------------
|
|
|
|
|
2017-11-30 17:49:46 +00:00
|
|
|
rm -f $fBufrTmp
|
2015-02-02 15:16:32 +00:00
|
|
|
|
|
|
|
f="syno_1.bufr"
|
|
|
|
echo "Test: setting header for single message file" >> $fLog
|
|
|
|
echo "file: $f" >> $fLog
|
2015-03-04 17:15:48 +00:00
|
|
|
${tools_dir}/bufr_set -v -p bufrHeaderCentre,bufrHeaderCentre:l -s bufrHeaderCentre=222 $f $fBufrTmp >> $fLog
|
2015-02-02 15:16:32 +00:00
|
|
|
|
2015-03-04 17:15:48 +00:00
|
|
|
centre=`${tools_dir}/bufr_get -p bufrHeaderCentre $fBufrTmp`
|
2015-02-02 15:16:32 +00:00
|
|
|
[ $centre = "222" ]
|
|
|
|
|
|
|
|
#----------------------------------------------------
|
|
|
|
# Test: setting header for multi-message file
|
|
|
|
#----------------------------------------------------
|
|
|
|
|
2017-11-30 17:49:46 +00:00
|
|
|
rm -f $fBufrTmp
|
2015-02-02 15:16:32 +00:00
|
|
|
|
|
|
|
f="syno_multi.bufr"
|
|
|
|
echo "Test: setting header for multi-message file" >> $fLog
|
|
|
|
echo "file: $f" >> $fLog
|
2015-03-04 17:15:48 +00:00
|
|
|
${tools_dir}/bufr_set -v -p bufrHeaderCentre,bufrHeaderCentre:l -s bufrHeaderCentre=222 $f $fBufrTmp >> $fLog
|
2015-02-02 15:16:32 +00:00
|
|
|
|
|
|
|
for i in 1 2 3 ;do
|
2015-03-04 17:15:48 +00:00
|
|
|
centre=`${tools_dir}/bufr_get -w count=$i -p bufrHeaderCentre $fBufrTmp`
|
2015-02-02 15:16:32 +00:00
|
|
|
[ $centre = "222" ]
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
#-----------------------------------------------------
|
|
|
|
# Test: setting data values for single message file
|
|
|
|
#-----------------------------------------------------
|
|
|
|
|
2020-07-04 14:30:10 +00:00
|
|
|
# TODO: when ECC-37 is fixed we need to enable it.
|
2015-02-02 15:16:32 +00:00
|
|
|
|
2017-11-30 17:49:46 +00:00
|
|
|
rm -f $fBufrTmp
|
2015-02-02 15:16:32 +00:00
|
|
|
|
|
|
|
f="syno_1.bufr"
|
|
|
|
echo "Test: setting data values" >> $fLog
|
|
|
|
echo "file: $f" >> $fLog
|
|
|
|
#${tools_dir}/bufr_set -v -p airTemperatureAt2M -s airTemperatureAt2M=234.5 $f $fBufrTmp >> $fLog
|
|
|
|
|
|
|
|
#t2m=`${tools_dir}/bufr_get -p airTemperatureAt2M $fBufrTmp`
|
|
|
|
#[ $t2m = "234.5" ]
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------
|
|
|
|
# Test: setting header for multi-message file
|
|
|
|
#----------------------------------------------------
|
|
|
|
|
2020-07-04 14:30:10 +00:00
|
|
|
# TODO: when ECC-37 is fixed we need to enable it.
|
2015-02-02 15:16:32 +00:00
|
|
|
|
2017-11-30 17:49:46 +00:00
|
|
|
rm -f $fBufrTmp
|
2015-02-02 15:16:32 +00:00
|
|
|
|
|
|
|
f="syno_multi.bufr"
|
|
|
|
echo "Test: setting data values for multi-message file" >> $fLog
|
|
|
|
echo "file: $f" >> $fLog
|
|
|
|
#${tools_dir}/bufr_set -v -p airTemperatureAt2M -s airTemperatureAt2M=234.5 $f $fBufrTmp >> $fLog
|
|
|
|
|
|
|
|
#for i in 1 2 3 ;do
|
|
|
|
# centre=`${tools_dir}/bufr_get -F%.1f -w count=$i -p airTemperatureAt2M $fBufrTmp`
|
|
|
|
# [ $centre = "234.5" ]
|
|
|
|
#done
|
|
|
|
|
2015-02-04 13:52:37 +00:00
|
|
|
#-----------------------------------------------------------
|
|
|
|
# Test: with nonexistent keys.
|
|
|
|
#-----------------------------------------------------------
|
2020-07-04 14:30:10 +00:00
|
|
|
# Key "center" does not exist!!
|
2015-02-04 13:52:37 +00:00
|
|
|
|
|
|
|
# Invoke without -f i.e. should fail if error encountered
|
|
|
|
set +e
|
|
|
|
|
|
|
|
f="syno_1.bufr"
|
|
|
|
echo "Test: nonexistent keys" >> $fLog
|
|
|
|
echo "file: $f" >> $fLog
|
|
|
|
${tools_dir}/bufr_set -s center=98 $f $fBufrTmp 2>> $fLog 1>> $fLog
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "bufr_set should have failed if key not found" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Now repeat with -f option (do not exit on error)
|
|
|
|
${tools_dir}/bufr_set -f -s center=98 $f $fBufrTmp 2>>$fLog 1>>$fLog
|
|
|
|
|
|
|
|
|
|
|
|
#-----------------------------------------------------------
|
|
|
|
# Test: with not allowed key values
|
|
|
|
#-----------------------------------------------------------
|
|
|
|
|
2020-07-04 14:30:10 +00:00
|
|
|
# Here 1024 is out of range for centre (it is 8-bit only for edition=3 files)
|
2015-02-04 13:52:37 +00:00
|
|
|
|
|
|
|
# Invoke without -f i.e. should fail if error encountered
|
|
|
|
set +e
|
|
|
|
|
|
|
|
f="syno_1.bufr"
|
|
|
|
echo "Test: nonexistent keys" >> $fLog
|
|
|
|
echo "file: $f" >> $fLog
|
2015-03-04 17:15:48 +00:00
|
|
|
${tools_dir}/bufr_set -s bufrHeaderCentre=1024 $f $fBufrTmp 2>> $fLog 1>> $fLog
|
2015-02-04 13:52:37 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "bufr_set should have failed if key not found" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Now repeat with -f option (do not exit on error)
|
2015-03-04 17:15:48 +00:00
|
|
|
${tools_dir}/bufr_set -f -s bufrHeaderCentre=1024 -f $f $fBufrTmp 2>>$fLog 1>>$fLog
|
2015-02-04 13:52:37 +00:00
|
|
|
|
2015-02-04 17:12:56 +00:00
|
|
|
#-----------------------------------------------------------
|
|
|
|
# Test: key values out of range
|
|
|
|
#-----------------------------------------------------------
|
|
|
|
f=aaen_55.bufr
|
2015-02-05 16:29:49 +00:00
|
|
|
|
2015-02-04 17:12:56 +00:00
|
|
|
# The correction1 key is of type "bits" and only 6 bits wide
|
|
|
|
# So its range is 0 -> 63 inclusive
|
|
|
|
${tools_dir}/bufr_set -s correction1=63 $f $fBufrTmp 2>>$fLog 1>>$fLog
|
|
|
|
|
|
|
|
set +e
|
|
|
|
${tools_dir}/bufr_set -s correction1=65 $f $fBufrTmp 2>>$fLog 1>>$fLog
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "bufr_set should have failed if value too large" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
${tools_dir}/bufr_set -s correction1=-1 $f $fBufrTmp 2>>$fLog 1>>$fLog
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "bufr_set should have failed if value negative" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
set -e
|
|
|
|
|
2018-10-30 11:38:36 +00:00
|
|
|
#-----------------------------------------------------------
|
|
|
|
# Test: Local ECMWF section. The 'ident' key
|
|
|
|
#-----------------------------------------------------------
|
|
|
|
f=temp_101.bufr
|
|
|
|
${tools_dir}/bufr_set -s ident=ABCD $f $fBufrTmp
|
|
|
|
result=`${tools_dir}/bufr_get -p ident $fBufrTmp`
|
|
|
|
[ "$result" = "ABCD" ]
|
|
|
|
${tools_dir}/bufr_set -s keyMore=ABCD $f $fBufrTmp
|
|
|
|
result=`${tools_dir}/bufr_get -p keyMore,ident $fBufrTmp`
|
|
|
|
[ "$result" = "ABCD ABCD" ]
|
|
|
|
|
2020-06-26 22:55:07 +00:00
|
|
|
${tools_dir}/bufr_set -s ident=' AB CD ' $f $fBufrTmp
|
|
|
|
result=`${tools_dir}/bufr_get -p ident $fBufrTmp`
|
|
|
|
[ "$result" = "AB CD" ]
|
|
|
|
|
2018-10-30 11:38:36 +00:00
|
|
|
# ${tools_dir}/bufr_compare $f $fBufrTmp
|
2015-02-02 15:16:32 +00:00
|
|
|
|
2022-03-02 17:43:41 +00:00
|
|
|
|
|
|
|
#-----------------------------------------------------------
|
|
|
|
# ECC-1359: string that can be converted to an integer
|
|
|
|
# ----------------------------------------------------------
|
|
|
|
${tools_dir}/bufr_set -s messageLength:s=333 $ECCODES_SAMPLES_PATH/BUFR4_local.tmpl $fBufrTmp
|
|
|
|
result=`${tools_dir}/bufr_get -p messageLength $fBufrTmp`
|
|
|
|
[ "$result" = "333" ]
|
|
|
|
|
2020-07-04 14:30:10 +00:00
|
|
|
# Clean up
|
2015-02-02 15:16:32 +00:00
|
|
|
rm -f $fLog
|
2017-11-30 17:49:46 +00:00
|
|
|
rm -f $fBufrTmp
|