ECC-1315: Keys like parameterName and nameOfFirstFixedSurface have a trailing space

This commit is contained in:
Shahram Najm 2021-12-01 14:56:51 +00:00
parent 3309c8e82d
commit 5076bc3c9f
6 changed files with 69 additions and 16 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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

51
tests/grib_ecc-1315.sh Executable file
View File

@ -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

View File

@ -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
}