Skip to content

Commit 72b0990

Browse files
authored
ECC-2230: GRIB2: Potential rounding bug in the 'wavelength' key
1 parent d93ef95 commit 72b0990

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

definitions/grib2/templates/template.4.optical.def

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ meta secondWavelength from_scale_factor_scaled_value(scaleFactorOfSecondWaveleng
1414
alias firstWavelengthInMetres = firstWavelength;
1515
alias secondWavelengthInMetres = secondWavelength;
1616

17-
constant billion = 1000000000 : hidden;
18-
meta firstWavelengthInNanometres multdouble(firstWavelength, billion) : read_only;
19-
meta secondWavelengthInNanometres multdouble(secondWavelength, billion) : read_only;
17+
# See ECC-2230
18+
if (scaleFactorOfFirstWavelength == 9) {
19+
alias firstWavelengthInNanometres = scaledValueOfFirstWavelength;
20+
alias secondWavelengthInNanometres = scaledValueOfSecondWavelength;
21+
} else {
22+
constant billion = 1000000000 : hidden;
23+
meta firstWavelengthInNanometres multdouble(firstWavelength, billion) : read_only;
24+
meta secondWavelengthInNanometres multdouble(secondWavelength, billion) : read_only;
25+
}
2026

2127
# MARS include
2228
# mars.wavelength is aliased for MTG2Switch > 0
23-
# this was done originally here, but the MTG2SwitchConcept uses the generatingProcessIdenfiert
29+
# this was done originally here, but the MTG2SwitchConcept uses the generatingProcessIdentifier
2430
# to implement an exception for 50r1
25-
# as template.4.optical.def is evaluated before template.4.generating_process.def"
31+
# as template.4.optical.def is evaluated before template.4.generating_process.def
2632
# the aliasing has to happen later, this is why in the optical templates the following is included:
2733
#
2834
# include "mars/mars.wavelength.def"

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ if( HAVE_BUILD_TOOLS )
331331
grib_ecc-2052
332332
grib_ecc-2137
333333
grib_ecc-2188
334+
grib_ecc-2230
334335
grib_modelName
335336
grib_sub_hourly
336337
grib_set_bytes

tests/grib_ecc-2230.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/sh
2+
# (C) Copyright 2005- ECMWF.
3+
#
4+
# This software is licensed under the terms of the Apache Licence Version 2.0
5+
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6+
#
7+
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
8+
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
9+
#
10+
11+
. ./include.ctest.sh
12+
13+
# ---------------------------------------------------------
14+
# This is the test for JIRA issue ECC-2230
15+
# GRIB2: Potential rounding bug in the 'wavelength' key
16+
# ---------------------------------------------------------
17+
18+
label=`basename $0 | sed -e 's/\.sh/_test/'`
19+
20+
if [ $ECCODES_ON_WINDOWS -eq 1 ]; then
21+
echo "$0: This test is currently disabled on Windows"
22+
exit 0
23+
fi
24+
25+
tempGrib=temp.$label.grib
26+
tempFilt=temp.$label.filt
27+
tempLog=temp.$label.log
28+
tempOut=temp.$label.txt
29+
tempRef=temp.$label.ref
30+
31+
sample_grib2=$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl
32+
cat >$tempFilt<<EOF
33+
set class = 'mc';
34+
set tablesVersion = 35;
35+
set productDefinitionTemplateNumber = 48;
36+
set paramId = 457000;
37+
set typeOfSizeInterval = 3;
38+
set scaleFactorOfFirstSize = 0;
39+
set scaledValueOfFirstSize = 0;
40+
set typeOfWavelengthInterval = 11;
41+
set scaleFactorOfFirstWavelength = 9;
42+
set scaledValueOfFirstWavelength = 469;
43+
set enableChemSplit = 1;
44+
set chemId = 922;
45+
write;
46+
EOF
47+
${tools_dir}/grib_filter -o $tempGrib $tempFilt $sample_grib2
48+
result=$( ${tools_dir}/grib_get -p wavelength:d -F%.15f $tempGrib )
49+
[ "$result" = "469.000000000000000" ] || exit 1
50+
51+
grib_check_key_equals $tempGrib "wavelength" "469"
52+
53+
# Clean up
54+
rm -f $tempGrib $tempFilt $tempLog $tempOut $tempRef

0 commit comments

Comments
 (0)