From 24d45c486fc136ae2d022255501c0e0d700b2b6b Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 13 Nov 2014 16:47:32 +0000 Subject: [PATCH] GRIB-601: GRIB edition 2: Support the new identification templates in section 1 --- definitions/Makefile.am | 5 +++ definitions/grib2/section.1.def | 9 ++++ definitions/grib2/template.1.0.def | 12 +++++ definitions/grib2/template.1.1.def | 12 +++++ definitions/grib2/template.1.2.def | 13 ++++++ definitions/grib2/template.1.calendar.def | 11 +++++ definitions/grib2/template.1.offset.def | 12 +++++ tests/CMakeLists.txt | 1 + tests/Makefile.am | 2 +- tests/calendar.sh | 54 +++++++++++++++++++++++ 10 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 definitions/grib2/template.1.0.def create mode 100644 definitions/grib2/template.1.1.def create mode 100644 definitions/grib2/template.1.2.def create mode 100644 definitions/grib2/template.1.calendar.def create mode 100644 definitions/grib2/template.1.offset.def create mode 100755 tests/calendar.sh diff --git a/definitions/Makefile.am b/definitions/Makefile.am index a5697c011..536d7749f 100644 --- a/definitions/Makefile.am +++ b/definitions/Makefile.am @@ -4655,6 +4655,11 @@ dist_definitionsgrib2_DATA = \ grib2/section.8.def\ grib2/sections.def\ grib2/shortName.def\ + grib2/template.1.0.def\ + grib2/template.1.1.def\ + grib2/template.1.2.def\ + grib2/template.1.calendar.def\ + grib2/template.1.offset.def\ grib2/template.3.0.def\ grib2/template.3.1.def\ grib2/template.3.10.def\ diff --git a/definitions/grib2/section.1.def b/definitions/grib2/section.1.def index 0ad90ba66..9182051c8 100644 --- a/definitions/grib2/section.1.def +++ b/definitions/grib2/section.1.def @@ -111,3 +111,12 @@ concept stepType { "ratio" = {selectStepTemplateInterval=1; stepTypeInternal="ratio";} } +transient setCalendarId = 0 ; +transient deleteCalendarId = 0 ; +alias calendarIdPresent = zero; +if ( ((section1Length > 21) or setCalendarId > 0) and deleteCalendarId == 0) { + alias calendarIdPresent = present; + codetable[2] calendarIdentificationTemplateNumber ('1.5.table',masterDir,localDir) : dump,string_type,no_fail; + template calendarIdentification "grib2/template.1.[calendarIdentificationTemplateNumber:l].def"; +} + diff --git a/definitions/grib2/template.1.0.def b/definitions/grib2/template.1.0.def new file mode 100644 index 000000000..9b7d9de9c --- /dev/null +++ b/definitions/grib2/template.1.0.def @@ -0,0 +1,12 @@ +# Copyright 2005-2014 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. +# + +# TEMPLATE 1.0, Calendar Definition + +include "template.1.calendar.def"; diff --git a/definitions/grib2/template.1.1.def b/definitions/grib2/template.1.1.def new file mode 100644 index 000000000..4e3e042dc --- /dev/null +++ b/definitions/grib2/template.1.1.def @@ -0,0 +1,12 @@ +# Copyright 2005-2014 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. +# + +# TEMPLATE 1.1, Paleontological Offset + +include "template.1.offset.def"; diff --git a/definitions/grib2/template.1.2.def b/definitions/grib2/template.1.2.def new file mode 100644 index 000000000..9e6afa07b --- /dev/null +++ b/definitions/grib2/template.1.2.def @@ -0,0 +1,13 @@ +# Copyright 2005-2014 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. +# + +# TEMPLATE 1.2, Calendar Definition and Paleontological Offset + +include "template.1.calendar.def"; +include "template.1.offset.def"; diff --git a/definitions/grib2/template.1.calendar.def b/definitions/grib2/template.1.calendar.def new file mode 100644 index 000000000..453aa10ff --- /dev/null +++ b/definitions/grib2/template.1.calendar.def @@ -0,0 +1,11 @@ +# Copyright 2005-2014 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. +# + +# Type of Calendar (see Code Table 1.6) +codetable[1] typeOfCalendar ('1.6.table',masterDir,localDir) = 255 : dump,no_copy,edition_specific; diff --git a/definitions/grib2/template.1.offset.def b/definitions/grib2/template.1.offset.def new file mode 100644 index 000000000..dfa4c6022 --- /dev/null +++ b/definitions/grib2/template.1.offset.def @@ -0,0 +1,12 @@ +# Copyright 2005-2014 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. +# + +# Number of tens of thousands of years of offset +signed[2] numberOfTensOfThousandsOfYearsOfOffset = missing() : can_be_missing,dump,no_copy,edition_specific; +alias paleontologicalOffset=numberOfTensOfThousandsOfYearsOfOffset ; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ca1f2c781..2fcbb36be 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -28,6 +28,7 @@ endforeach() ################################################# list( APPEND tests definitions + calendar bufr_dump bufrdc_desc_ref bufrdc_ref diff --git a/tests/Makefile.am b/tests/Makefile.am index 2dd6c7342..f895a8032 100755 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ -TESTS = definitions.sh \ +TESTS = definitions.sh calendar.sh \ bufrdc_desc_ref.sh bufrdc_ref.sh bufr_dump.sh \ ieee.sh grib1to2.sh \ unit_tests.sh \ diff --git a/tests/calendar.sh b/tests/calendar.sh new file mode 100755 index 000000000..a61f7732a --- /dev/null +++ b/tests/calendar.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# Copyright 2005-2014 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 + +REDIRECT=/dev/null + +temp1=temp1.calendar.$$ +temp2=temp2.calendar.$$ +sample=$GRIB_SAMPLES_PATH/GRIB2.tmpl + +########### Utility function ############## +check_key_equals() +{ + file=$1 + key=$2 + val=$3 + result=`${tools_dir}grib_get -p $key $file` + [ "$result" = "$val" ] +} +########################################### + +${tools_dir}grib_set -s tablesVersion=13,setCalendarId=1,typeOfCalendar=0 $sample $temp1 +check_key_equals $temp1 calendarIdPresent 1 +check_key_equals $temp1 section1Length 24 +check_key_equals $temp1 calendarIdentificationTemplateNumber 0 +check_key_equals $temp1 typeOfCalendar 0 + +${tools_dir}grib_set -s tablesVersion=13,setCalendarId=1,calendarIdentificationTemplateNumber=1 $sample $temp1 +check_key_equals $temp1 calendarIdPresent 1 +check_key_equals $temp1 section1Length 25 +check_key_equals $temp1 calendarIdentificationTemplateNumber 1 +check_key_equals $temp1 numberOfTensOfThousandsOfYearsOfOffset MISSING + +${tools_dir}grib_set -s tablesVersion=13,setCalendarId=1,calendarIdentificationTemplateNumber=2 $sample $temp1 +check_key_equals $temp1 calendarIdPresent 1 +check_key_equals $temp1 section1Length 26 +check_key_equals $temp1 calendarIdentificationTemplateNumber 2 +check_key_equals $temp1 typeOfCalendar 255 +check_key_equals $temp1 numberOfTensOfThousandsOfYearsOfOffset MISSING + +# Remove the calendar section +${tools_dir}grib_set -s deleteCalendarId=1 $temp1 $temp2 +check_key_equals $temp2 section1Length 21 +check_key_equals $temp2 calendarIdPresent 0 + +rm -f $temp1 $temp2