eccodes/tests/grib_util_set_spec.sh

169 lines
5.8 KiB
Bash
Raw Permalink Normal View History

#!/bin/sh
2020-01-28 14:32:34 +00:00
# (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
2016-09-23 14:10:36 +00:00
#test_dir="valgrind --error-exitcode=1 "$test_dir
2016-09-23 14:10:36 +00:00
# --------------------------------------------------
# Regular Lat/Lon Grid
# --------------------------------------------------
2023-02-18 15:52:11 +00:00
infile=${data_dir}/latlon.grib # edition 1
outfile=out.grib_util_set_spec.grib
2016-09-23 14:10:36 +00:00
tempOut=temp.grib_util_set_spec.grib
grib_util_set_spec=${test_dir}/grib_util_set_spec
rm -f $outfile
# GRIB1 with local definition for MARS. Convert to edition2 and remove local def
$EXEC $grib_util_set_spec -e 2 -r $infile $outfile > /dev/null
2017-02-03 14:21:24 +00:00
res=`${tools_dir}/grib_get -p edition,section2Used,Ni,Nj,numberOfValues,bitsPerValue $outfile`
[ "$res" = "2 0 17 14 238 24" ]
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
# Check output file geometry
${tools_dir}/grib_get_data $outfile > /dev/null
fi
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
$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
$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
2023-02-18 15:52:11 +00:00
infile=${data_dir}/regular_latlon_surface.grib2
$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
$EXEC $grib_util_set_spec $infile $outfile > /dev/null
2016-09-23 14:10:36 +00:00
grib_check_key_equals $outfile section2Used 0
# Convert to edition2 and use JPEG for packing
if [ $HAVE_JPEG -eq 1 ]; then
2023-02-18 15:52:11 +00:00
infile=${data_dir}/latlon.grib
$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" ]
fi
2023-02-18 15:52:11 +00:00
# CCSDS for packing and different editions
if [ $HAVE_AEC -eq 1 ]; then
2023-02-18 15:52:11 +00:00
infile=${data_dir}/sample.grib2
$EXEC $grib_util_set_spec -p grid_ccsds $infile $outfile
grib_check_key_equals $outfile packingType grid_ccsds
infile=${data_dir}/latlon.grib #grib1
$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" ]
2023-02-18 15:52:11 +00:00
# If we don't convert, then should leave it as grid_simple (No CCSDS in grib1)
$EXEC $grib_util_set_spec -p grid_ccsds $infile $outfile
grib_check_key_equals $outfile packingType grid_simple
fi
2024-01-14 21:16:30 +00:00
if [ $ECCODES_ON_WINDOWS -eq 0 ]; then
2024-01-14 21:54:37 +00:00
infile=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
2024-01-14 21:16:30 +00:00
$EXEC $grib_util_set_spec -p grid_ieee $infile $outfile
2024-01-14 21:54:37 +00:00
grib_check_key_equals $outfile 'packingType' 'grid_ieee'
2024-01-14 21:16:30 +00:00
fi
infile=${data_dir}/sample.grib2
$EXEC $grib_util_set_spec -p grid_second_order $infile $outfile
grib_check_key_equals $outfile 'packingType' 'grid_second_order'
infile=${data_dir}/sample.grib2
$EXEC $grib_util_set_spec -p grid_complex $infile $outfile
# $tools_dir/grib_ls $outfile
grib_check_key_equals $outfile 'packingType' 'grid_complex'
2016-09-23 14:10:36 +00:00
# --------------------------------------------------
# Reduced Gaussian Grid N=32 second order packing
# --------------------------------------------------
# The gaussian tests intentionally cause an error so need to stop it failing
unset ECCODES_FAIL_IF_LOG_MESSAGE
2023-02-18 15:52:11 +00:00
infile=${data_dir}/reduced_gaussian_model_level.grib2
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" ]
$EXEC $grib_util_set_spec -p grid_second_order $infile $outfile
2016-09-01 12:43:09 +00:00
# Check output file. Values are scaled up by 1.1
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`
[ "$stats_new" = "4.84 246.90" ]
2016-09-01 12:43:09 +00:00
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
${tools_dir}/grib_get_data $outfile > /dev/null
CHECK_TOOL="${tools_dir}/grib_check_gaussian_grid"
if [ -x $CHECK_TOOL ]; then
$CHECK_TOOL $outfile
fi
fi
### Constant field N=32
2023-02-16 19:47:03 +00:00
# ---------------------------
infile=$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl
rm -f $outfile
$EXEC $grib_util_set_spec $infile $outfile
grib_check_key_equals $outfile "packingType,const" "grid_simple 0"
if [ $HAVE_GEOGRAPHY -eq 1 ]; then
${tools_dir}/grib_get_data $outfile > /dev/null
fi
2023-02-16 19:47:03 +00:00
# CCSDS input
# ---------------------------
if [ $HAVE_AEC -eq 1 ]; then
infile=${data_dir}/ccsds.grib2
$EXEC $grib_util_set_spec $infile $outfile
grib_check_key_equals $outfile packingType grid_ccsds
2023-02-16 19:47:03 +00:00
$EXEC $grib_util_set_spec -p grid_simple $infile $outfile
grib_check_key_equals $outfile packingType grid_simple
2023-02-16 19:47:03 +00:00
$EXEC $grib_util_set_spec -p grid_second_order $infile $outfile
grib_check_key_equals $outfile packingType grid_second_order
fi
2023-02-16 19:47:03 +00:00
2023-02-19 16:15:27 +00:00
# Second order input/output
# ---------------------------
${tools_dir}/grib_set -r -s packingType=grid_second_order ${data_dir}/sample.grib2 $tempOut
grib_check_key_equals $tempOut packingType grid_second_order
$EXEC $grib_util_set_spec $tempOut $outfile
grib_check_key_equals $outfile packingType grid_second_order
2023-02-16 19:47:03 +00:00
2023-02-19 16:15:27 +00:00
$EXEC $grib_util_set_spec -p grid_second_order ${data_dir}/simple.grib $outfile
grib_check_key_equals $outfile packingType grid_second_order
2023-02-19 14:57:19 +00:00
# Check DEBUG output
# ---------------------------
export ECCODES_DEBUG=-1
$EXEC $grib_util_set_spec ${data_dir}/sample.grib2 $outfile > $tempOut 2>&1
grep -q "ECCODES DEBUG grib_util:" $tempOut
### Clean up
2016-09-23 14:10:36 +00:00
rm -f $outfile $tempOut
2020-04-10 16:26:00 +00:00
rm -f error.data