From cac077117ff39a32d90dee6b1cca727eb43c7578 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 12 Oct 2017 11:52:26 +0100 Subject: [PATCH] ECC-556: BUFR: 'typicalDate' calculation should cater for invalid year in BUFR4 --- definitions/bufr/section.1.4.def | 14 ++++++++++---- tests/CMakeLists.txt | 1 + tests/ecc-556.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100755 tests/ecc-556.sh diff --git a/definitions/bufr/section.1.4.def b/definitions/bufr/section.1.4.def index c8951e367..5d1f57faf 100644 --- a/definitions/bufr/section.1.4.def +++ b/definitions/bufr/section.1.4.def @@ -28,8 +28,14 @@ unsigned[1] masterTablesVersionNumber : dump; unsigned[1] localTablesVersionNumber : dump; unsigned[2] typicalYear : dump; -transient typicalYearOfCentury = typicalYear % 100; -transient typicalCentury = ( typicalYear - typicalYearOfCentury ) / 100 + 1 ; +transient typicalYear2 = typicalYear : hidden, no_copy; +if (typicalYear<100) { + # ECC-556: invalid year corrected. Assume 21st century! + transient typicalYear2 = (2000 + typicalYear) : hidden, no_copy; +} + +transient typicalYearOfCentury = typicalYear2 % 100; +transient typicalCentury = ( typicalYear2 - typicalYearOfCentury ) / 100 + 1 ; unsigned[1] typicalMonth : dump; unsigned[1] typicalDay : dump; @@ -37,10 +43,10 @@ unsigned[1] typicalHour : dump; unsigned[1] typicalMinute : dump; unsigned[1] typicalSecond : dump; -meta ls.typicalDate sprintf("%.4d%.2d%.2d",typicalYear,typicalMonth,typicalDay) : dump,no_copy,read_only; +meta ls.typicalDate sprintf("%.4d%.2d%.2d",typicalYear2,typicalMonth,typicalDay) : dump,no_copy,read_only; meta ls.typicalTime sprintf("%.2d%.2d%.2d",typicalHour,typicalMinute,typicalSecond) :dump,no_copy,read_only; -meta typicalDateTime julian_date(typicalYear,typicalMonth,typicalDay,typicalHour,typicalMinute,typicalSecond) ; +meta typicalDateTime julian_date(typicalYear2,typicalMonth,typicalDay,typicalHour,typicalMinute,typicalSecond) ; alias ls.masterTablesVersionNumber=masterTablesVersionNumber; alias ls.localTablesVersionNumber=localTablesVersionNumber; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 399c59f3e..7e44e19e5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -81,6 +81,7 @@ list( APPEND tests_data_reqd ecc-393 ecc-433 ecc-490 + ecc-556 gts_get gts_ls gts_compare diff --git a/tests/ecc-556.sh b/tests/ecc-556.sh new file mode 100755 index 000000000..4bd365e56 --- /dev/null +++ b/tests/ecc-556.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# Copyright 2005-2017 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.sh +set -u + +# --------------------------------------------------------- +# This is the test for the JIRA issue ECC-556. +# It tests typicalDate for BUFR edition 4 +# --------------------------------------------------------- +label="ecc-556-test" + +# In this BUFR message the typicalYear should have been encoded +# as 2012 but it is actually 12! +input=${data_dir}/bufr/aaen_55.bufr +res=`${tools_dir}/bufr_get -p edition,typicalYear,typicalDate $input` +[ "$res" = "4 12 20121102" ] + +# Now try a BUFR4 file with correctly coded year +input=${data_dir}/bufr/PraticaTemp.bufr +res=`${tools_dir}/bufr_get -p edition,typicalYear,typicalDate $input` +[ "$res" = "4 2015 20151202" ]