eccodes/tests/grib_set.sh

110 lines
3.3 KiB
Bash
Raw Permalink Normal View History

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.
#
. ./include.ctest.sh
2013-03-25 12:04:10 +00:00
2023-12-20 12:34:55 +00:00
label="grib_set_test"
2013-03-25 12:04:10 +00:00
REDIRECT=/dev/null
infile=${data_dir}/regular_gaussian_surface.grib1
2023-12-20 12:34:55 +00:00
outfile=${data_dir}/temp.$label.grib
temp=${data_dir}/temp.$label.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
${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
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
${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 ]
# 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
# GRIB-943: centre code table
# ----------------------------
2017-02-03 14:21:24 +00:00
${tools_dir}/grib_set -s centre=289 $ECCODES_SAMPLES_PATH/GRIB2.tmpl $outfile
${tools_dir}/grib_dump -O $outfile > $temp
grep -q 'centre = 289.*Zambia' $temp
# offsetValuesBy
# ------------------
input=${data_dir}/reduced_latlon_surface.grib2
${tools_dir}/grib_set -s offsetValuesBy=0.5 $input $outfile
max=`${tools_dir}/grib_get -F%.3f -p max $input`
[ "$max" = "12.597" ]
max=`${tools_dir}/grib_get -F%.3f -p max $outfile`
[ "$max" = "13.097" ]
2023-07-23 16:14:42 +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
2023-12-26 20:05:56 +00:00
# GDSPresent
# ------------
input=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
${tools_dir}/grib_set -s GDSPresent=1 $input $outfile
2023-08-24 16:59:02 +00:00
# Clean up
rm -f $outfile $temp