2013-03-25 12:04:10 +00:00
|
|
|
#!/bin/sh
|
2020-01-28 14:32:34 +00:00
|
|
|
# (C) Copyright 2005- ECMWF.
|
2013-03-25 12:04:10 +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.
|
2014-08-28 09:03:16 +00:00
|
|
|
#
|
2013-03-25 12:04:10 +00:00
|
|
|
# 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
|
2013-03-25 12:04:10 +00:00
|
|
|
|
|
|
|
REDIRECT=/dev/null
|
|
|
|
|
|
|
|
infile=${data_dir}/regular_gaussian_surface.grib1
|
2021-08-27 18:38:46 +00:00
|
|
|
outfile=${data_dir}/temp.grib_set.grib
|
|
|
|
temp=temp.grib_set.out
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2017-11-30 17:49:46 +00:00
|
|
|
rm -f $outfile
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2023-08-24 16:59:02 +00:00
|
|
|
${tools_dir}/grib_set -V
|
|
|
|
|
2022-02-24 11:58:17 +00:00
|
|
|
${tools_dir}/grib_set -v -p levtype,centre,levtype,centre:l -s levtype=pl,centre=80 $infile $outfile >$REDIRECT
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
levtype=`${tools_dir}/grib_get -p levtype $outfile`
|
2013-03-25 12:04:10 +00:00
|
|
|
[ $levtype = "pl" ]
|
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
centre=`${tools_dir}/grib_get -p centre $outfile`
|
2013-03-25 12:04:10 +00:00
|
|
|
[ $centre = "cnmc" ]
|
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
centre=`${tools_dir}/grib_get -p centre:l $outfile`
|
2013-03-25 12:04:10 +00:00
|
|
|
[ $centre -eq 80 ]
|
|
|
|
|
2017-11-30 17:49:46 +00:00
|
|
|
rm -f $outfile
|
2015-01-26 15:50:33 +00:00
|
|
|
|
2014-08-28 09:03:16 +00:00
|
|
|
infile=${data_dir}/regular_gaussian_surface.grib2
|
2013-03-25 12:04:10 +00:00
|
|
|
outfile=${data_dir}/set.grib2
|
|
|
|
|
2017-11-30 17:49:46 +00:00
|
|
|
rm -f $outfile
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2022-02-24 11:58:17 +00:00
|
|
|
${tools_dir}/grib_set -v -p levtype:s,centre:s -s typeOfLevel=isobaricInhPa,centre:s=cnmc $infile $outfile >$REDIRECT
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
levtype=`${tools_dir}/grib_get -p levtype $outfile`
|
2013-03-25 12:04:10 +00:00
|
|
|
[ $levtype = "pl" ]
|
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
centre=`${tools_dir}/grib_get -p centre $outfile`
|
2013-03-25 12:04:10 +00:00
|
|
|
[ $centre = "cnmc" ]
|
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
centre=`${tools_dir}/grib_get -p centre:l $outfile`
|
2013-03-25 12:04:10 +00:00
|
|
|
[ $centre -eq 80 ]
|
|
|
|
|
2021-08-27 18:38:46 +00:00
|
|
|
# Set without -s. Expected to fail
|
|
|
|
# ----------------------------------------------------
|
2013-03-25 12:04:10 +00:00
|
|
|
set +e
|
2023-08-08 09:41:36 +00:00
|
|
|
${tools_dir}/grib_set -p levtype $infile $outfile > $temp 2>&1
|
2021-08-27 18:38:46 +00:00
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
2023-08-08 09:41:36 +00:00
|
|
|
grep -q "provide some keys to set" $temp
|
|
|
|
|
|
|
|
# Set with empty -s. Expected to fail
|
|
|
|
# ----------------------------------------------------
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s '' $infile $outfile > $temp 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "provide some keys to set" $temp
|
2021-08-27 18:38:46 +00:00
|
|
|
|
|
|
|
# Out-of-bounds value. Expected to fail
|
|
|
|
# ----------------------------------------------------
|
|
|
|
input=${data_dir}/reduced_gaussian_sub_area.grib2
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s perturbationNumber=1000 $input $outfile 2>$temp
|
|
|
|
status=$?
|
2016-03-07 18:05:27 +00:00
|
|
|
set -e
|
2021-08-27 18:38:46 +00:00
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "Trying to encode value of 1000 but the maximum allowable value is 255 (number of bits=8)" $temp
|
2016-03-10 16:05:06 +00:00
|
|
|
|
2021-08-27 18:38:46 +00:00
|
|
|
# Negative value for an unsigned key. Expected to fail
|
|
|
|
# ----------------------------------------------------
|
|
|
|
input=${data_dir}/reduced_gaussian_sub_area.grib2
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s perturbationNumber=-1 $input $outfile 2>$temp
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "Trying to encode a negative value of -1 for key of type unsigned" $temp
|
|
|
|
|
2023-08-24 16:59:02 +00:00
|
|
|
# Bad value for -d
|
|
|
|
# ----------------
|
|
|
|
input=${data_dir}/reduced_gaussian_sub_area.grib2
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -d hello $input $outfile 2>$temp
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "Invalid number" $temp
|
|
|
|
|
|
|
|
|
2023-06-01 16:12:35 +00:00
|
|
|
# ECC-1605: Out-of-bounds value for signed keys
|
|
|
|
# ----------------------------------------------------
|
2023-06-01 22:02:41 +00:00
|
|
|
if [ $ECCODES_ON_WINDOWS -eq 0 ]; then
|
|
|
|
input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s forecastTime=2147483648 $input $outfile 2>$temp
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
2023-06-02 16:48:32 +00:00
|
|
|
grep -q "Trying to encode value of 2147483648 but the allowable range is -2147483647 to 2147483647" $temp
|
2023-06-01 22:02:41 +00:00
|
|
|
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s forecastTime=-2147483650 $input $outfile 2>$temp
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
fi
|
2021-08-27 18:38:46 +00:00
|
|
|
|
|
|
|
# GRIB-941: encoding of GRIB2 angles
|
|
|
|
# -----------------------------------
|
2016-03-07 17:52:07 +00:00
|
|
|
angleInDegrees=130.9989
|
|
|
|
angleInMicroDegrees=130998900
|
|
|
|
files="GRIB2.tmpl regular_gg_pl_grib2.tmpl reduced_gg_pl_320_grib2.tmpl polar_stereographic_pl_grib2.tmpl"
|
|
|
|
for f in $files; do
|
|
|
|
f=$ECCODES_SAMPLES_PATH/$f
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s longitudeOfFirstGridPointInDegrees=$angleInDegrees $f $outfile
|
2016-03-07 17:52:07 +00:00
|
|
|
grib_check_key_equals $outfile longitudeOfFirstGridPoint $angleInMicroDegrees
|
|
|
|
done
|
|
|
|
|
2016-03-10 16:05:06 +00:00
|
|
|
# GRIB-943: centre code table
|
2021-08-27 18:38:46 +00:00
|
|
|
# ----------------------------
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s centre=289 $ECCODES_SAMPLES_PATH/GRIB2.tmpl $outfile
|
2022-03-25 20:41:34 +00:00
|
|
|
${tools_dir}/grib_dump -O $outfile > $temp
|
|
|
|
grep -q 'centre = 289.*Zambia' $temp
|
2016-03-10 16:05:06 +00:00
|
|
|
|
2021-01-25 15:44:30 +00:00
|
|
|
# ECC-539: avoid output being the same as input
|
2021-08-27 18:38:46 +00:00
|
|
|
# -----------------------------------------------
|
2021-01-25 15:44:30 +00:00
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s centre=0 $outfile $outfile
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
2016-03-10 16:05:06 +00:00
|
|
|
|
2022-02-19 13:33:31 +00:00
|
|
|
# offsetValuesBy
|
|
|
|
# ------------------
|
|
|
|
input=${data_dir}/reduced_latlon_surface.grib2
|
2022-03-04 15:27:16 +00:00
|
|
|
${tools_dir}/grib_set -s offsetValuesBy=0.5 $input $outfile
|
2022-02-19 13:33:31 +00:00
|
|
|
|
|
|
|
max=`${tools_dir}/grib_get -F%.3f -p max $input`
|
|
|
|
[ "$max" = "12.597" ]
|
2022-03-04 15:27:16 +00:00
|
|
|
max=`${tools_dir}/grib_get -F%.3f -p max $outfile`
|
2022-02-19 13:33:31 +00:00
|
|
|
[ "$max" = "13.097" ]
|
|
|
|
|
2022-03-02 17:43:41 +00:00
|
|
|
# ECC-1359: string that can be converted to an integer
|
|
|
|
# ---------------------------------------------------
|
2022-03-04 15:27:16 +00:00
|
|
|
${tools_dir}/grib_set -s month:s=6 $ECCODES_SAMPLES_PATH/GRIB2.tmpl $outfile
|
|
|
|
grib_check_key_equals $outfile month 6
|
2022-03-02 17:56:15 +00:00
|
|
|
# Now try an illegal value: a string that cannot be converted to an integer
|
|
|
|
set +e
|
2022-03-04 15:27:16 +00:00
|
|
|
${tools_dir}/grib_set -s month=BAD $ECCODES_SAMPLES_PATH/GRIB2.tmpl $outfile 2> $temp
|
2022-03-02 17:56:15 +00:00
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
2022-03-04 15:27:16 +00:00
|
|
|
grep -q "String cannot be converted to an integer" $temp
|
2022-03-02 17:56:15 +00:00
|
|
|
|
2021-08-27 18:38:46 +00:00
|
|
|
|
2022-03-04 15:27:16 +00:00
|
|
|
# ECC-1363: Does not fail for invalid value for key of type 'double'
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
${tools_dir}/grib_set -s angleOfRotation:s=10.66 $ECCODES_SAMPLES_PATH/rotated_ll_sfc_grib2.tmpl $outfile
|
|
|
|
grib_check_key_equals $outfile angleOfRotation 10.66
|
|
|
|
# Now try an illegal value: a string that cannot be converted to an integer
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s angleOfRotation=BAD $ECCODES_SAMPLES_PATH/rotated_ll_sfc_grib2.tmpl $outfile 2>$temp
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "String cannot be converted to a double" $temp
|
|
|
|
|
|
|
|
|
2023-07-23 16:14:42 +00:00
|
|
|
# Set ascii key via double or long
|
|
|
|
# --------------------------------
|
|
|
|
${tools_dir}/grib_set -s setLocalDefinition=1,localDefinitionNumber=21 $ECCODES_SAMPLES_PATH/GRIB2.tmpl $outfile
|
|
|
|
${tools_dir}/grib_set -s marsDomain=x $outfile $temp
|
|
|
|
grib_check_key_equals $temp 'marsDomain' 'x'
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s marsDomain=9 $outfile $temp
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s marsDomain=1.2 $outfile $temp
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
|
2022-05-16 13:26:29 +00:00
|
|
|
# Strict option
|
|
|
|
# ---------------
|
|
|
|
# There is only one field in this file with shortName=2t
|
|
|
|
input=${data_dir}/tigge_cf_ecmwf.grib2
|
|
|
|
# This copies all messages to the output changing one of them
|
|
|
|
${tools_dir}/grib_set -w shortName=2t -s offsetValuesBy=0.5 $input $outfile
|
|
|
|
count=`${tools_dir}/grib_count $outfile`
|
|
|
|
[ $count -eq 43 ]
|
|
|
|
# Now we copy only what was changed
|
|
|
|
${tools_dir}/grib_set -w shortName=2t -S -s offsetValuesBy=0.5 $input $outfile
|
|
|
|
count=`${tools_dir}/grib_count $outfile`
|
|
|
|
[ $count -eq 1 ]
|
|
|
|
grib_check_key_equals $outfile shortName '2t'
|
|
|
|
|
2023-09-02 14:37:33 +00:00
|
|
|
# Key with no_fail flag
|
|
|
|
# ------------------------
|
|
|
|
input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
|
|
|
grib_check_key_equals $input 'typeOfProcessedData:i' '2'
|
|
|
|
${tools_dir}/grib_set -s typeOfProcessedData=rubbish $input $outfile
|
|
|
|
grib_check_key_equals $outfile 'typeOfProcessedData:i' '255' # set to default
|
|
|
|
|
|
|
|
# Codetable mismatch
|
|
|
|
# ------------------------
|
|
|
|
input=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s stepUnits=d $input $outfile > $temp 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "stepUnits: No such code table entry.*Did you mean" $temp
|
2022-05-16 13:26:29 +00:00
|
|
|
|
2023-12-19 14:47:35 +00:00
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s centre=ECMF $input $outfile > $temp 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "centre: No such code table entry.*Did you mean.*ecmf" $temp
|
|
|
|
|
|
|
|
|
2023-08-24 16:59:02 +00:00
|
|
|
# ------------------------
|
|
|
|
# Unreadable message
|
|
|
|
# ------------------------
|
|
|
|
echo GRIB > $outfile
|
|
|
|
set +e
|
|
|
|
${tools_dir}/grib_set -s edition=2 $outfile /dev/null > $temp 2>&1
|
|
|
|
status=$?
|
|
|
|
set -e
|
|
|
|
[ $status -ne 0 ]
|
|
|
|
grep -q "unreadable message" $temp
|
|
|
|
|
|
|
|
|
2022-03-04 15:27:16 +00:00
|
|
|
# Clean up
|
2021-08-27 18:38:46 +00:00
|
|
|
rm -f $outfile $temp
|