eccodes/tests/extract_offsets.sh

92 lines
2.2 KiB
Bash
Raw Normal View History

2020-11-30 21:08:16 +00:00
#!/bin/sh
# (C) Copyright 2005- ECMWF.
#
# 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
2020-11-30 21:08:16 +00:00
# Define a common label for all the tmp files
2023-06-22 11:59:17 +00:00
label="extract_offsets_test"
2020-11-30 21:08:16 +00:00
temp1="temp.${label}.1"
temp2="temp.${label}.2"
2023-06-22 11:59:17 +00:00
tempLog="temp.${label}.log"
tempRef="temp.${label}.ref"
2020-11-30 21:08:16 +00:00
2024-02-02 17:57:59 +00:00
if [ $ECCODES_ON_WINDOWS -eq 1 ]; then
echo "$0: This test is currently disabled on Windows"
exit 0
fi
2020-11-30 21:08:16 +00:00
echo "Multi-message BUFR..."
# ---------------------------
input=${data_dir}/bufr/aeolus_wmo_26.bufr
$EXEC ${test_dir}/extract_offsets -o $input > $temp1
2023-06-22 11:59:17 +00:00
${tools_dir}/bufr_get -p offset:i $input > $temp2
2020-11-30 21:08:16 +00:00
diff $temp1 $temp2
$EXEC ${test_dir}/extract_offsets -s $input > $temp1
${tools_dir}/bufr_get -p totalLength $input > $temp2
diff $temp1 $temp2
2023-06-22 11:59:17 +00:00
echo "Multi-message GRIBs..."
2020-11-30 21:08:16 +00:00
# --------------------------
2023-06-22 11:59:17 +00:00
inputs="${data_dir}/mixed.grib ${data_dir}/test.grib1 ${data_dir}/v.grib2"
for input in $inputs; do
$EXEC ${test_dir}/extract_offsets -o $input > $temp1
2023-06-22 11:59:17 +00:00
${tools_dir}/grib_get -p offset:i $input > $temp2
diff $temp1 $temp2
$EXEC ${test_dir}/extract_offsets -s $input > $temp1
${tools_dir}/grib_get -p totalLength $input > $temp2
diff $temp1 $temp2
2023-06-22 11:59:17 +00:00
done
2020-11-30 21:08:16 +00:00
echo "GTS headers and padding..."
# -------------------------------
input=${data_dir}/gts.grib
$EXEC ${test_dir}/extract_offsets -o -s $input > $temp1
cat > $tempRef << EOF
41
170
299
428
84
84
84
84
EOF
diff $tempRef $temp1
2020-11-30 21:08:16 +00:00
echo "Test with invalid inputs..."
# ---------------------------------
set +e
$EXEC ${test_dir}/extract_offsets -o ${data_dir} > $tempLog 2>&1
2023-06-22 11:59:17 +00:00
status=$?
set -e
[ $status -ne 0 ]
2023-06-22 15:44:25 +00:00
grep -q "is a directory" $tempLog
2023-06-22 11:59:17 +00:00
set +e
$EXEC ${test_dir}/extract_offsets -o ${data_dir}/bad.grib > $tempLog 2>&1
2020-11-30 21:08:16 +00:00
status=$?
set -e
[ $status -ne 0 ]
2023-06-22 11:59:17 +00:00
grep -q "Wrong message length" $tempLog
2020-11-30 21:08:16 +00:00
2024-01-07 16:20:03 +00:00
set +e
$EXEC ${test_dir}/extract_offsets -o nonexistentfile > $tempLog 2>&1
2024-01-07 16:20:03 +00:00
status=$?
set -e
[ $status -ne 0 ]
grep -q "Unable to read file" $tempLog
2023-06-22 11:59:17 +00:00
# Clean up
rm -f $temp1 $temp2 $tempLog $tempRef