2018-08-22 11:39:40 +00:00
|
|
|
#!/bin/sh
|
2020-01-28 14:32:34 +00:00
|
|
|
# (C) Copyright 2005- ECMWF.
|
2018-08-22 11:39:40 +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.
|
|
|
|
#
|
|
|
|
|
2022-04-03 22:02:48 +00:00
|
|
|
. ./include.ctest.sh
|
2018-08-22 11:39:40 +00:00
|
|
|
|
2020-07-04 14:30:10 +00:00
|
|
|
# Enter data dir
|
2018-08-22 11:39:40 +00:00
|
|
|
cd ${data_dir}
|
|
|
|
|
2020-07-04 14:30:10 +00:00
|
|
|
# Define a common label for all the tmp files
|
2018-08-22 11:39:40 +00:00
|
|
|
label="grib_copy_test"
|
2023-08-24 16:32:37 +00:00
|
|
|
temp=temp.$label.grib
|
|
|
|
fLog=temp.$label.log
|
2018-08-22 11:39:40 +00:00
|
|
|
|
2020-02-10 17:48:41 +00:00
|
|
|
echo "Test: The -g option..."
|
|
|
|
# -----------------------------------
|
|
|
|
input=gts.grib
|
|
|
|
${tools_dir}/grib_copy -w count=1 -g $input $temp
|
|
|
|
val1=`${tools_dir}/gts_get -wcount=1 -p AA $input`
|
|
|
|
val2=`${tools_dir}/gts_get -p AA $temp`
|
|
|
|
[ "$val1" = "$val2" ]
|
|
|
|
[ "$val1" = "XK" ]
|
|
|
|
|
2024-01-10 12:42:45 +00:00
|
|
|
${tools_dir}/grib_copy -p edition -w count=1 $input $temp
|
|
|
|
${tools_dir}/grib_copy -p shortName -w count=2 $input $temp
|
2020-02-10 17:48:41 +00:00
|
|
|
set +e
|
|
|
|
${tools_dir}/gts_get -p AA $temp
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
|
|
|
|
|
|
|
|
echo "Test: The -X option..."
|
|
|
|
# -------------------------------
|
2018-08-22 11:39:40 +00:00
|
|
|
echo "Test: use of -X option"
|
|
|
|
input=tigge_pf_ecmwf.grib2
|
|
|
|
${tools_dir}/grib_copy -w count=1 -X 0 $input $temp #First msg
|
|
|
|
r1=`${tools_dir}/grib_get -w count=1 -n ls $input`
|
|
|
|
r2=`${tools_dir}/grib_get -n ls $temp`
|
|
|
|
[ "$r1" = "$r2" ]
|
|
|
|
|
2020-03-04 17:26:01 +00:00
|
|
|
|
2021-01-25 15:44:30 +00:00
|
|
|
echo "Test: ECC-1086 invalid message ..."
|
2020-03-03 17:28:56 +00:00
|
|
|
# -------------------------
|
|
|
|
# This file is 179 bytes long. We chop the last byte to create
|
|
|
|
# an invalid GRIB message (Final 7777 is 777)
|
|
|
|
input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
2023-08-24 16:32:37 +00:00
|
|
|
badGrib=temp.$label.bad.grib
|
2020-03-03 17:28:56 +00:00
|
|
|
head -c 178 $input > $badGrib
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_copy $badGrib /dev/null # Only the bad GRIB
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_copy $input $badGrib /dev/null # Good followed by bad
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_copy $badGrib $input /dev/null # Bad followed by good
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
|
2020-03-04 17:26:01 +00:00
|
|
|
# If there is a bad message, make sure the rest (good ones) get copied
|
|
|
|
combinedGrib=${label}".combined.grib"
|
|
|
|
cat $badGrib tigge_cf_ecmwf.grib2 > $combinedGrib
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_copy $combinedGrib $temp
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
count=`${tools_dir}/grib_count $temp`
|
|
|
|
[ $count -eq 43 ]
|
2020-03-03 17:28:56 +00:00
|
|
|
|
2021-01-25 15:44:30 +00:00
|
|
|
|
|
|
|
echo "Test: ECC-539 input=output ..."
|
|
|
|
# -----------------------
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_copy $temp $temp
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
|
2023-08-24 16:32:37 +00:00
|
|
|
#-------------------------------------------------------------------
|
|
|
|
echo "Test: corner cases ..."
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
echo GRIB > $badGrib
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_copy $badGrib /dev/null > $fLog 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -w "unreadable message" $fLog
|
|
|
|
|
2021-01-25 15:44:30 +00:00
|
|
|
|
2024-01-10 16:20:12 +00:00
|
|
|
#-------------------------------------------------------------------
|
|
|
|
echo "Test: dummy field ..."
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
input=${data_dir}/missing_field.grib1
|
|
|
|
${tools_dir}/grib_copy -r $input $temp
|
|
|
|
|
2018-08-22 13:53:01 +00:00
|
|
|
#${tools_dir}/grib_copy -w count=1 -X 57143 $input $temp #Last msg
|
|
|
|
#r1=`${tools_dir}/grib_get -w count=37 -n ls $input`
|
|
|
|
#r2=`${tools_dir}/grib_get -n ls $temp`
|
|
|
|
#[ "$r1" = "$r2" ]
|
2018-08-22 11:39:40 +00:00
|
|
|
|
|
|
|
# Get two messages
|
2018-08-22 13:53:01 +00:00
|
|
|
#${tools_dir}/grib_copy -w count=1/2 -X 25071 $input $temp
|
|
|
|
#count=`${tools_dir}/grib_count $temp`
|
|
|
|
#[ $count -eq 2 ]
|
|
|
|
|
|
|
|
#r=`${tools_dir}/grib_get -w count=1 -p typeOfLevel,level,shortName $temp`
|
|
|
|
#[ "$r" = "heightAboveGround 2 mx2t6" ]
|
|
|
|
#r=`${tools_dir}/grib_get -w count=2 -p typeOfLevel,level,shortName $temp`
|
|
|
|
#[ "$r" = "heightAboveGround 2 mn2t6" ]
|
2018-08-22 11:39:40 +00:00
|
|
|
|
|
|
|
# Clean up
|
|
|
|
#-----------
|
2023-08-24 16:32:37 +00:00
|
|
|
rm -f $temp $badGrib $combinedGrib $fLog
|