2015-07-21 13:24:02 +00:00
|
|
|
#!/bin/sh
|
2019-04-15 13:44:45 +00:00
|
|
|
# Copyright 2005-2019 ECMWF.
|
2015-07-21 13:24:02 +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.sh
|
2016-09-23 14:10:36 +00:00
|
|
|
#test_dir="valgrind --error-exitcode=1 "$test_dir
|
2015-07-21 13:24:02 +00:00
|
|
|
|
2016-09-23 14:10:36 +00:00
|
|
|
# --------------------------------------------------
|
|
|
|
# Regular Lat/Lon Grid
|
|
|
|
# --------------------------------------------------
|
2015-07-21 13:24:02 +00:00
|
|
|
infile=../data/latlon.grib
|
|
|
|
outfile=out.grib_util_set_spec.grib
|
2016-09-23 14:10:36 +00:00
|
|
|
tempOut=temp.grib_util_set_spec.grib
|
2017-08-02 14:18:38 +00:00
|
|
|
grib_util_set_spec=${test_dir}/grib_util_set_spec
|
|
|
|
|
2015-09-23 14:30:30 +00:00
|
|
|
rm -f $outfile
|
2015-07-21 13:24:02 +00:00
|
|
|
|
2016-10-10 18:14:34 +00:00
|
|
|
# GRIB1 with local definition for MARS. Convert to edition2 and remove local def
|
2018-09-06 13:56:41 +00:00
|
|
|
$EXEC $grib_util_set_spec -e 2 -r $infile $outfile > /dev/null
|
2015-07-21 13:24:02 +00:00
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
res=`${tools_dir}/grib_get -p edition,section2Used,Ni,Nj,numberOfValues,bitsPerValue $outfile`
|
2016-09-22 15:52:56 +00:00
|
|
|
[ "$res" = "2 0 17 14 238 24" ]
|
2015-07-21 13:24:02 +00:00
|
|
|
|
2016-08-31 16:38:31 +00:00
|
|
|
# Check output file geometry
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_get_data $outfile > /dev/null
|
2015-07-21 13:24:02 +00:00
|
|
|
|
2016-09-23 14:10:36 +00:00
|
|
|
# Remove the local definition from input
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s deleteLocalDefinition=1 $infile $tempOut
|
2018-09-06 13:56:41 +00:00
|
|
|
$EXEC $grib_util_set_spec $tempOut $outfile > /dev/null
|
2016-09-23 14:10:36 +00:00
|
|
|
|
|
|
|
# Add another grib1 local definition (which is not in grib2)
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_set -s setLocalDefinition=1,localDefinitionNumber=5 $infile $tempOut
|
2016-09-23 14:10:36 +00:00
|
|
|
infile=$tempOut
|
2018-09-06 13:56:41 +00:00
|
|
|
$EXEC $grib_util_set_spec -r -e 2 $tempOut $outfile > /dev/null
|
2017-02-03 14:21:24 +00:00
|
|
|
res=`${tools_dir}/grib_get -p edition,section2Used $outfile`
|
2016-09-23 14:10:36 +00:00
|
|
|
[ "$res" = "2 0" ]
|
|
|
|
|
|
|
|
# GRIB2 input with local definition
|
|
|
|
infile=../data/regular_latlon_surface.grib2
|
2018-09-06 13:56:41 +00:00
|
|
|
$EXEC $grib_util_set_spec -r $infile $outfile > /dev/null
|
2016-09-23 14:10:36 +00:00
|
|
|
grib_check_key_equals $outfile section2Used 0
|
|
|
|
# GRIB2 input without local definition
|
|
|
|
infile=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
2018-09-06 13:56:41 +00:00
|
|
|
$EXEC $grib_util_set_spec $infile $outfile > /dev/null
|
2016-09-23 14:10:36 +00:00
|
|
|
grib_check_key_equals $outfile section2Used 0
|
|
|
|
|
2016-10-10 18:14:34 +00:00
|
|
|
# Convert to edition2 and use JPEG for packing
|
2018-07-19 13:31:28 +00:00
|
|
|
if [ $HAVE_JPEG -eq 1 ]; then
|
2016-11-18 13:40:14 +00:00
|
|
|
infile=../data/latlon.grib
|
2018-09-06 13:56:41 +00:00
|
|
|
$EXEC $grib_util_set_spec -e 2 -p grid_jpeg $infile $outfile > /dev/null
|
2017-02-03 14:21:24 +00:00
|
|
|
res=`${tools_dir}/grib_get -p edition,section2Used,packingType $outfile`
|
2016-11-18 13:40:14 +00:00
|
|
|
[ "$res" = "2 1 grid_jpeg" ]
|
2016-11-03 18:20:22 +00:00
|
|
|
fi
|
2016-10-10 18:14:34 +00:00
|
|
|
|
2019-10-01 11:12:18 +00:00
|
|
|
# Convert to edition2 and use CCSDS for packing
|
|
|
|
if [ $HAVE_AEC -eq 1 ]; then
|
|
|
|
infile=../data/latlon.grib
|
|
|
|
$EXEC $grib_util_set_spec -e 2 -p grid_ccsds $infile $outfile > /dev/null
|
|
|
|
res=`${tools_dir}/grib_get -p edition,section2Used,packingType $outfile`
|
|
|
|
[ "$res" = "2 1 grid_ccsds" ]
|
|
|
|
fi
|
|
|
|
|
2016-09-23 14:10:36 +00:00
|
|
|
# --------------------------------------------------
|
|
|
|
# Reduced Gaussian Grid N=32 second order packing
|
|
|
|
# --------------------------------------------------
|
2019-10-01 12:40:49 +00:00
|
|
|
# The gaussian tests intentionally cause an error so need to stop it failing
|
|
|
|
unset ECCODES_FAIL_IF_LOG_MESSAGE
|
|
|
|
|
2016-08-31 16:38:31 +00:00
|
|
|
infile=../data/reduced_gaussian_model_level.grib2
|
2015-09-23 14:30:30 +00:00
|
|
|
outfile=out.grib_util_set_spec.grib
|
|
|
|
rm -f $outfile
|
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
stats_old=`${tools_dir}/grib_get -F%.2f -p min,max $infile`
|
2016-09-01 12:43:09 +00:00
|
|
|
[ "$stats_old" = "160.25 224.45" ]
|
|
|
|
|
2018-09-06 13:56:41 +00:00
|
|
|
$EXEC $grib_util_set_spec -p grid_second_order $infile $outfile
|
2015-09-23 14:30:30 +00:00
|
|
|
|
2016-09-01 12:43:09 +00:00
|
|
|
# Check output file. Values are scaled up by 1.1
|
2016-08-31 16:38:31 +00:00
|
|
|
grib_check_key_equals $outfile packingType grid_second_order
|
2017-02-03 14:21:24 +00:00
|
|
|
stats_new=`${tools_dir}/grib_get -F%.2f -p min,max $outfile`
|
2016-09-01 12:43:09 +00:00
|
|
|
[ "$stats_new" = "176.28 246.90" ]
|
|
|
|
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_get_data $outfile > /dev/null
|
|
|
|
CHECK_TOOL="${tools_dir}/grib_check_gaussian_grid"
|
2016-08-31 16:38:31 +00:00
|
|
|
if [ -x $CHECK_TOOL ]; then
|
|
|
|
$CHECK_TOOL $outfile
|
|
|
|
fi
|
|
|
|
|
|
|
|
### Constant field N=32
|
|
|
|
###########################################
|
|
|
|
infile=$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl
|
|
|
|
rm -f $outfile
|
|
|
|
|
2018-09-06 13:56:41 +00:00
|
|
|
$EXEC $grib_util_set_spec $infile $outfile
|
2016-08-31 16:38:31 +00:00
|
|
|
grib_check_key_equals $outfile "packingType,const" "grid_simple 1"
|
2017-02-03 14:21:24 +00:00
|
|
|
${tools_dir}/grib_get_data $outfile > /dev/null
|
2015-09-23 14:30:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
### Clean up
|
2016-09-23 14:10:36 +00:00
|
|
|
rm -f $outfile $tempOut
|