eccodes/tests/bufr_get.sh

157 lines
4.4 KiB
Bash
Raw Permalink Normal View History

2015-02-02 17:17:29 +00:00
#!/bin/sh
2020-01-28 14:32:34 +00:00
# (C) Copyright 2005- ECMWF.
2015-02-02 17:17:29 +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.ctest.sh
2015-02-02 17:17:29 +00:00
2020-06-27 14:39:05 +00:00
# Enter data dir
2015-02-02 17:17:29 +00:00
cd ${data_dir}/bufr
2020-06-27 14:39:05 +00:00
# Define a common label for all the tmp files
2015-02-02 17:17:29 +00:00
label="bufr_get_test"
2020-06-27 14:39:05 +00:00
# Create log file
2015-02-02 17:17:29 +00:00
fLog=${label}".log"
rm -f $fLog
touch $fLog
2020-06-27 14:39:05 +00:00
# Define tmp file
2015-02-02 17:17:29 +00:00
fTmp=${label}".tmp.txt"
2020-06-27 14:39:05 +00:00
tempRef=${label}".tmp.ref.txt"
rm -f $fTmp $tempRef
2015-02-02 17:17:29 +00:00
2020-06-27 14:39:05 +00:00
# Define another tmp file to store the test results
2015-02-02 17:17:29 +00:00
res_get=${label}".get.test"
rm -f $res_get
# Check identidier. Edition 3 and 4
id=`${tools_dir}/bufr_get -p edition,identifier avhn_87.bufr`
[ "$id" = "3 BUFR" ]
id=`${tools_dir}/bufr_get -p edition,identifier aaen_55.bufr`
[ "$id" = "4 BUFR" ]
2023-08-22 19:35:46 +00:00
set +e
${tools_dir}/bufr_get -p identifier:d avhn_87.bufr
status=$?
set -e
[ $status -ne 0 ]
2015-02-02 17:17:29 +00:00
#-------------------------------------------
# Test "-p" switch
#-------------------------------------------
f="aaen_55.bufr"
2020-06-27 14:39:05 +00:00
# The reference is the same as for ls
2015-02-02 17:17:29 +00:00
ref_get=$f".ls.ref"
echo "Test: -p switch" >> $fLog
echo "file: $f" >> $fLog
2016-07-05 12:10:01 +00:00
${tools_dir}/bufr_get -p totalLength,bufrHeaderCentre,bufrHeaderSubCentre,masterTableNumber,masterTablesVersionNumber,localTablesVersionNumber,numberOfSubsets,localNumberOfObservations $f > $fTmp
2015-02-02 17:17:29 +00:00
2020-06-27 14:39:05 +00:00
# Write the values into a file and compare with ref
2015-02-02 17:17:29 +00:00
cat $fTmp | awk '{split($0,a," "); for (i=1; i<=8; i++) print a[i]}' > $res_get
diff $ref_get $res_get
2015-02-02 17:17:29 +00:00
#-------------------------------------------
# ECC-236
#-------------------------------------------
result=`${tools_dir}/bufr_get -s unpack=1 -p nonCoordinatePressure syno_1.bufr`
[ "$result" = "100910" ]
result=`${tools_dir}/bufr_get -s unpack=1 -p stationOrSiteName bssh_176.bufr`
[ "$result" = "Helgoland" ]
result=`${tools_dir}/bufr_get -s unpack=1 -p majorFrameCount aaen_55.bufr`
[ "$result" = "MISSING" ]
result=`${tools_dir}/bufr_get -s unpack=1 -p satelliteIdentifier wavb_134.bufr`
[ "$result" = "MISSING" ]
2018-05-10 14:53:22 +00:00
#-------------------------------------------
# ECC-315: BUFR keys in the MARS namespace
#-------------------------------------------
result=`${tools_dir}/bufr_get -m aaen_55.bufr`
[ "$result" = "55 20121102 0000" ]
2018-05-10 14:53:22 +00:00
result=`${tools_dir}/bufr_get -m syno_1.bufr`
[ "$result" = "1 20121030 0000 91334" ]
2020-06-27 14:39:05 +00:00
${tools_dir}/bufr_ls -j -m syno_1.bufr > $fTmp
cat > $tempRef <<EOF
{ "messages" : [
{
"obstype": 1,
"date": 20121030,
"time": "0000",
"ident": 91334
}
]}
EOF
cat $tempRef
diff $tempRef $fTmp
#-------------------------------------------
# Local ECMWF section: 'ident' key
#-------------------------------------------
result=`${tools_dir}/bufr_get -p isSatellite,ident syno_1.bufr`
[ "$result" = "0 91334" ]
result=`${tools_dir}/bufr_get -p isSatellite,ident temp_102.bufr`
[ "$result" = "0 ASDE3" ]
result=`${tools_dir}/bufr_get -p isSatellite,ident b004_145.bufr`
[ "$result" = "0 FAVRTLZA" ]
result=`${tools_dir}/bufr_get -f -p isSatellite,ident b003_56.bufr`
[ "$result" = "1 not_found" ]
2022-12-16 17:42:31 +00:00
# Check key 'file'
result=`${tools_dir}/bufr_get -p file b004_145.bufr`
[ "$result" = "b004_145.bufr" ]
# Decoding the "unpack" key also decodes the whole Data Section
result=`${tools_dir}/bufr_get -f -p heightOfStation aaen_55.bufr`
[ "$result" = "not_found" ]
result=`${tools_dir}/bufr_get -p unpack,heightOfStation aaen_55.bufr`
[ "$result" = "0 858000" ]
result=`${tools_dir}/bufr_get -p unpack:d,heightOfStation aaen_55.bufr`
[ "$result" = "0 858000" ]
result=`${tools_dir}/bufr_get -p unpack:s,heightOfStation aaen_55.bufr`
[ "$result" = "0 858000" ]
# ----------------------------------------
# Wrong message type
# ----------------------------------------
f=$data_dir/sample.grib2
set +e
${tools_dir}/bufr_get -p edition $f > $fLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "Input file seems to be GRIB" $fLog
f=$ECCODES_SAMPLES_PATH/budg.tmpl
set +e
${tools_dir}/bufr_get -p edition $f > $fLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "Input file seems to be GRIB" $fLog
2022-12-16 17:42:31 +00:00
# ----------------------------------------
# Unreadable message
# ----------------------------------------
echo BUFR > $fTmp
set +e
${tools_dir}/bufr_get -p edition $fTmp > $fLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "unreadable message" $fLog
# Clean up
2020-06-27 14:39:05 +00:00
rm -f $fLog $fTmp $res_get $tempRef
2022-12-16 17:42:31 +00:00