eccodes/tests/grib_level.sh

128 lines
5.8 KiB
Bash
Raw 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.
2013-03-25 14:23:07 +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
#set -x
sample_g1=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
sample_g2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
temp=temp.level.grib
2017-11-15 18:21:38 +00:00
temp2=temp2.level.grib
2023-04-17 16:30:47 +00:00
temp3=temp3.level.grib
2013-03-25 12:04:10 +00:00
file=${data_dir}/regular_gaussian_pressure_level.grib1
cat >temp.level.good<<EOF
2013-03-25 12:04:10 +00:00
grib1: level=850 isobaricInhPa indicatorOfTypeOfLevel=100
grib2: level=850 isobaricInhPa pl 85000
grib1: level=850 isobaricInhPa indicatorOfTypeOfLevel=100
grib1: level=50 isobaricInPa indicatorOfTypeOfLevel=210
grib2: level=50 isobaricInPa pl 50
grib1: level=50 isobaricInPa indicatorOfTypeOfLevel=210
grib1: level=1 topLevel=1 bottomLevel=2 depthBelowLandLayer indicatorOfTypeOfLevel=112
grib2: level=1 topLevel=1 bottomLevel=2 depthBelowLandLayer first= sfc 1 second= sfc 2
grib1: level=1 topLevel=1 bottomLevel=2 depthBelowLandLayer indicatorOfTypeOfLevel=112
EOF
cat >level.filter<<EOF
set typeOfLevel="isobaricInhPa";
set level=850;
print "grib[edition]: level=[level] [typeOfLevel] indicatorOfTypeOfLevel=[indicatorOfTypeOfLevel:l]";
set edition=2;
print "grib[edition]: level=[level] [typeOfLevel] [typeOfFirstFixedSurface:s] [scaledValueOfFirstFixedSurface]";
set edition=1;
print "grib[edition]: level=[level] [typeOfLevel] indicatorOfTypeOfLevel=[indicatorOfTypeOfLevel:l]";
set edition=1;
set typeOfLevel="isobaricInPa";
set level=50;
print "grib[edition]: level=[level] [typeOfLevel] indicatorOfTypeOfLevel=[indicatorOfTypeOfLevel:l]";
set edition=2;
print "grib[edition]: level=[level] [typeOfLevel] [typeOfFirstFixedSurface:s] [scaledValueOfFirstFixedSurface]";
set edition=1;
print "grib[edition]: level=[level] [typeOfLevel] indicatorOfTypeOfLevel=[indicatorOfTypeOfLevel:l]";
set typeOfLevel="depthBelowLandLayer";
set topLevel=1;
set bottomLevel=2;
print "grib[edition]: level=[level] topLevel=[topLevel] bottomLevel=[bottomLevel] [typeOfLevel] indicatorOfTypeOfLevel=[indicatorOfTypeOfLevel:l]";
set edition=2;
print "grib[edition]: level=[level] topLevel=[topLevel] bottomLevel=[bottomLevel] [typeOfLevel] first= [typeOfFirstFixedSurface:s] [scaledValueOfFirstFixedSurface] second= [typeOfSecondFixedSurface:s] [scaledValueOfSecondFixedSurface]";
set edition=1;
print "grib[edition]: level=[level] topLevel=[topLevel] bottomLevel=[bottomLevel] [typeOfLevel] indicatorOfTypeOfLevel=[indicatorOfTypeOfLevel:l]";
EOF
2017-02-03 14:21:24 +00:00
${tools_dir}/grib_filter level.filter $file > test.dump
diff temp.level.good test.dump
2013-03-25 12:04:10 +00:00
2017-11-08 17:43:47 +00:00
# Use of 'level' key for GRIB2
${tools_dir}/grib_set -s typeOfFirstFixedSurface=103,level=24 $sample_g2 $temp
grib_check_key_equals $temp level,scaledValueOfFirstFixedSurface,scaleFactorOfFirstFixedSurface '24 24 0'
${tools_dir}/grib_set -s typeOfFirstFixedSurface=103,level=2.4 $sample_g2 $temp
grib_check_key_equals $temp level:d,scaledValueOfFirstFixedSurface,scaleFactorOfFirstFixedSurface '2.4 24 1'
2017-11-08 17:43:47 +00:00
2017-11-08 18:01:24 +00:00
# Use a parameter which has two levels
${tools_dir}/grib_set -s paramId=228086,topLevel=1.3,bottomLevel=5.4 $sample_g2 $temp
grib_check_key_equals $temp 'topLevel:d,bottomLevel:d' '1.3 5.4'
grib_check_key_equals $temp scaleFactorOfFirstFixedSurface,scaledValueOfFirstFixedSurface '1 13'
grib_check_key_equals $temp scaleFactorOfSecondFixedSurface,scaledValueOfSecondFixedSurface '1 54'
2017-11-08 18:01:24 +00:00
# GRIB-492
2017-02-03 14:21:24 +00:00
${tools_dir}/grib_set -s indicatorOfTypeOfLevel=110 $sample_g1 $temp
res=`${tools_dir}/grib_get -p indicatorOfTypeOfLevel:l,topLevel,bottomLevel $temp`
[ "$res" = "110 0 0" ]
2013-03-25 12:04:10 +00:00
2014-07-21 12:22:30 +00:00
# GRIB-415 evaluate level as a double
2017-02-03 14:21:24 +00:00
${tools_dir}/grib_set -s scaledValueOfFirstFixedSurface=15,scaleFactorOfFirstFixedSurface=1 $sample_g2 $temp
res=`${tools_dir}/grib_get -p level:d $temp`
2014-07-21 12:22:30 +00:00
[ "$res" = "1.5" ]
# ECC-1081: 'level' is not edition-independent for potential vorticity levels
${tools_dir}/grib_set -s typeOfLevel=potentialVorticity,shortName=q,level=1500 $sample_g1 $temp
${tools_dir}/grib_set -s edition=2 $temp $temp2
grib_check_key_equals $temp2 'mars.levelist,level,typeOfLevel' '1500 1500 potentialVorticity'
grib_check_key_equals $temp2 'scaleFactorOfFirstFixedSurface,scaledValueOfFirstFixedSurface' '9 1500'
2023-04-17 16:30:47 +00:00
${tools_dir}/grib_set -s level=1500 $temp2 $temp3
grib_check_key_equals $temp3 level 1500
${tools_dir}/grib_compare $temp2 $temp3
# GRIB-637 grib2 Potential vorticity surface
input=${data_dir}/tigge_pf_ecmwf.grib2
2017-02-03 14:21:24 +00:00
res=`${tools_dir}/grib_get -wcount=7 -F%.20f -p level:d $input`
[ "$res" = "2.00000000000000000000" ]
2013-03-25 12:04:10 +00:00
2017-11-15 18:21:38 +00:00
# Setting productDefinitionTemplateNumber should keep level info
${tools_dir}/grib_set -s typeOfFirstFixedSurface=100,level=5 $sample_g2 $temp
${tools_dir}/grib_set -s productDefinitionTemplateNumber=1 $temp $temp2
grib_check_key_equals $temp2 level 5
2017-11-09 11:25:25 +00:00
# ECC-530: Setting typeOfSecondFixedSurface should not overwrite
# scale factor and scaled value of first fixed surface
2017-11-15 18:21:38 +00:00
# cat >level.filter<<EOF
# set typeOfFirstFixedSurface=106;
# set scaleFactorOfFirstFixedSurface=-2;
# set scaledValueOfFirstFixedSurface=4;
# set typeOfSecondFixedSurface=106; # Should not overwrite
# assert(scaledValueOfFirstFixedSurface == 4);
# assert(scaleFactorOfFirstFixedSurface == -2);
# assert(level==400);
# EOF
# ${tools_dir}/grib_filter level.filter $sample_g2
2017-11-09 11:25:25 +00:00
2018-04-18 13:04:23 +00:00
# Related to ECC-530: make sure GRIB2 parameters with typeOfSecondFixedSurface
2024-07-09 12:39:11 +00:00
# have correct parameter definitions (grib_set does not cause scale factor/value loss)
params="228086 228087 228095 228096 228170 228171"
2018-04-18 13:04:23 +00:00
for pid in $params; do
${tools_dir}/grib_set -s paramId=$pid $sample_g2 $temp
grib_check_key_equals $temp paramId $pid
done
2023-04-17 16:30:47 +00:00
rm -f level.filter temp.level.good test.dump $temp $temp2 $temp3