From 5076bc3c9f39b6d42d3f95b7a3354e047634aeb4 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 1 Dec 2021 14:56:51 +0000 Subject: [PATCH] ECC-1315: Keys like parameterName and nameOfFirstFixedSurface have a trailing space --- data/bitmap.diff | 6 ++-- data/no_bitmap.diff | 6 ++-- src/grib_accessor_class_codetable.c | 13 ++++---- tests/CMakeLists.txt | 1 + tests/grib_ecc-1315.sh | 51 +++++++++++++++++++++++++++++ tests/utils.sh | 8 ++--- 6 files changed, 69 insertions(+), 16 deletions(-) create mode 100755 tests/grib_ecc-1315.sh diff --git a/data/bitmap.diff b/data/bitmap.diff index 22ea9aa68..a9d7527d0 100644 --- a/data/bitmap.diff +++ b/data/bitmap.diff @@ -5,12 +5,12 @@ GRIB { # European Centre for Medium-Range Weather Forecasts (common/c-1.table) centre = 98; generatingProcessIdentifier = 130; - # Temperature (K) (grib1/2.98.128.table) + # Temperature (K) (grib1/2.98.128.table) indicatorOfParameter = 130; - # Hybrid level level number (2 octets) (grib1/local/ecmf/3.table , grib1/3.table) + # Hybrid level level number (2 octets) (grib1/local/ecmf/3.table , grib1/3.table) indicatorOfTypeOfLevel = 109; level = 1; - # Forecast product valid at reference time + P1 (P1>0) (grib1/local/ecmf/5.table , grib1/5.table) + # Forecast product valid at reference time + P1 (P1>0) (grib1/local/ecmf/5.table , grib1/5.table) timeRangeIndicator = 0; # Unknown code table entry (grib1/0.ecmf.table) subCentre = 0; diff --git a/data/no_bitmap.diff b/data/no_bitmap.diff index dc6dc9221..a79a11110 100644 --- a/data/no_bitmap.diff +++ b/data/no_bitmap.diff @@ -5,12 +5,12 @@ GRIB { # European Centre for Medium-Range Weather Forecasts (common/c-1.table) centre = 98; generatingProcessIdentifier = 130; - # Temperature (K) (grib1/2.98.128.table) + # Temperature (K) (grib1/2.98.128.table) indicatorOfParameter = 130; - # Hybrid level level number (2 octets) (grib1/local/ecmf/3.table , grib1/3.table) + # Hybrid level level number (2 octets) (grib1/local/ecmf/3.table , grib1/3.table) indicatorOfTypeOfLevel = 109; level = 1; - # Forecast product valid at reference time + P1 (P1>0) (grib1/local/ecmf/5.table , grib1/5.table) + # Forecast product valid at reference time + P1 (P1>0) (grib1/local/ecmf/5.table , grib1/5.table) timeRangeIndicator = 0; # Unknown code table entry (grib1/0.ecmf.table) subCentre = 0; diff --git a/src/grib_accessor_class_codetable.c b/src/grib_accessor_class_codetable.c index c504aef76..77466221e 100644 --- a/src/grib_accessor_class_codetable.c +++ b/src/grib_accessor_class_codetable.c @@ -427,8 +427,8 @@ static int grib_load_codetable(grib_context* c, const char* filename, int code = 0; char abbreviation[1024] = {0,}; char title[1024] = {0,}; - char* q = abbreviation; - char* r = title; + char* pAbbrev = abbreviation; + char* pTitle = title; char* units = 0; char unknown[] = "unknown"; char* last_open_paren = NULL; @@ -477,9 +477,9 @@ static int grib_load_codetable(grib_context* c, const char* filename, while (*p != '\0') { if (isspace(*p)) break; - *q++ = *p++; + *pAbbrev++ = *p++; } - *q = 0; + *pAbbrev = 0; while (*p != '\0' && isspace(*p)) p++; @@ -487,9 +487,9 @@ static int grib_load_codetable(grib_context* c, const char* filename, while (*p != '\0') { if (last_open_paren && p >= last_open_paren && *p == '(') break; - *r++ = *p++; + *pTitle++ = *p++; } - *r = 0; + *pTitle = 0; /* units at the end */ if (last_open_paren) { @@ -506,6 +506,7 @@ static int grib_load_codetable(grib_context* c, const char* filename, Assert(*abbreviation); Assert(*title); + rtrim(title); /* ECC-1315 */ if (t->entries[code].abbreviation != NULL) { grib_context_log(c, GRIB_LOG_WARNING, "code_table_entry: duplicate code in %s: %d (table size=%ld)", filename, code, size); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f49aa6ab4..3f04acf26 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -90,6 +90,7 @@ if( HAVE_BUILD_TOOLS ) grib_ecc-1260 grib_ecc-1261 grib_ecc-1271 + grib_ecc-1315 bufr_ecc-1028 bufr_ecc-1195 bufr_ecc-1259 diff --git a/tests/grib_ecc-1315.sh b/tests/grib_ecc-1315.sh new file mode 100755 index 000000000..4dd37d97c --- /dev/null +++ b/tests/grib_ecc-1315.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# (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.sh +set -u +REDIRECT=/dev/null +label="grib_ecc-1313-test" +tempOut=temp.$label.text +tempRef=temp.$label.ref +tempFilt=temp.$label.filt +tempGrb=temp.$label.grib + +sample_grib1=$ECCODES_SAMPLES_PATH/GRIB1.tmpl +sample_grib2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl + +cat > $tempFilt << EOF + set centre = 34; # Japan + print "parameterName = |[parameterName]|"; + print "centreDescription = |[centreDescription]|"; + print "gridDefinitionDescription = |[gridDefinitionDescription]|"; + print "nameOfFirstFixedSurface = |[nameOfFirstFixedSurface]|"; +EOF + +${tools_dir}/grib_filter $tempFilt $sample_grib2 > $tempOut +cat $tempOut + +cat > $tempRef << EOF +parameterName = |Temperature| +centreDescription = |Japanese Meteorological Agency - Tokyo| +gridDefinitionDescription = |Latitude/longitude| +nameOfFirstFixedSurface = |Ground or water surface| +EOF + +diff $tempRef $tempOut + +# GRIB2: Chemicals and Probability templates +${tools_dir}/grib_set -s tablesVersion=28,productDefinitionTemplateNumber=40,constituentType=10009 $sample_grib2 $tempGrb +grib_check_key_equals $tempGrb constituentTypeName 'Ethene' + +${tools_dir}/grib_set -s tablesVersion=28,productDefinitionTemplateNumber=5,probabilityType=2 $sample_grib2 $tempGrb +grib_check_key_equals $tempGrb probabilityTypeName 'Probability of event between lower and upper limits' + + +rm -f $tempOut $tempRef $tempFilt $tempGrb diff --git a/tests/utils.sh b/tests/utils.sh index 93f0b4348..ea13741cd 100644 --- a/tests/utils.sh +++ b/tests/utils.sh @@ -22,10 +22,10 @@ grib_check_key_equals() a_expected=$3 a_result=`${tools_dir}/grib_get -p $a_key $a_file` if [ "$a_result" != "$a_expected" ]; then - echo "File: $a_file" - echo "Key(s): $a_key" - echo "Expected: $a_expected" - echo "Result: $a_result" + echo "File: '$a_file'" + echo "Key(s): '$a_key'" + echo "Expected: '$a_expected'" + echo "Result: '$a_result'" exit 1 fi }