Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https://jira.ecmwf.int/browse/ECC-1806 #205

Merged
merged 6 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions definitions/grib1/localConcepts/ecmf/paramIdForConversion.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Concept paramIdForConversion for ECMWF
# ECC-1806

# 55 -> 228004
228004 = {gribTablesVersionNo=128; indicatorOfParameter=55; centre=98;}
# 56 -> 235168
235168 = {gribTablesVersionNo=128; indicatorOfParameter=56; centre=98;}
# 130232 -> 235135
235135 = {gribTablesVersionNo=130; indicatorOfParameter=232; centre=98;}
# 151163 -> 262104
262104 = {gribTablesVersionNo=151; indicatorOfParameter=163; centre=98;}
# 151145 -> 262124
262124 = {gribTablesVersionNo=151; indicatorOfParameter=145; centre=98;}
# 172146 -> 235033
235033 = {gribTablesVersionNo=172; indicatorOfParameter=146; centre=98;}
# 172147 -> 235034
235034 = {gribTablesVersionNo=172; indicatorOfParameter=147; centre=98;}
# 172169 -> 235035
235035 = {gribTablesVersionNo=172; indicatorOfParameter=169; centre=98;}
# 172175 -> 235036
235036 = {gribTablesVersionNo=172; indicatorOfParameter=175; centre=98;}
# 172176 -> 235037
235037 = {gribTablesVersionNo=172; indicatorOfParameter=176; centre=98;}
# 172177 -> 235038
235038 = {gribTablesVersionNo=172; indicatorOfParameter=177; centre=98;}
# 172178 -> 235039
235039 = {gribTablesVersionNo=172; indicatorOfParameter=178; centre=98;}
# 172179 -> 235040
235040 = {gribTablesVersionNo=172; indicatorOfParameter=179; centre=98;}
# 174098 -> 262000
262000 = {gribTablesVersionNo=174; indicatorOfParameter=98; centre=98;}
32 changes: 26 additions & 6 deletions definitions/grib1/localConcepts/ecmf/stepTypeForConversion.def
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Concept stepTypeForConversion for ECMWF
# set uses the FIRST one
# get returns the LAST match

# ECC-457: ECMWF Total Precipitation
"accum" = {timeRangeIndicator=0;indicatorOfParameter=228;gribTablesVersionNo=128;centre=98;}
"accum" = {timeRangeIndicator=1;indicatorOfParameter=228;gribTablesVersionNo=128;centre=98;}
"accum" = {timeRangeIndicator=10;indicatorOfParameter=228;gribTablesVersionNo=128;centre=98;}
# ECC-457: total precipitation
"accum"={timeRangeIndicator=0;indicatorOfParameter=228;gribTablesVersionNo=128;centre=98;}
"accum"={timeRangeIndicator=1;indicatorOfParameter=228;gribTablesVersionNo=128;centre=98;}
"accum"={timeRangeIndicator=10;indicatorOfParameter=228;gribTablesVersionNo=128;centre=98;}

# sro
"accum"={gribTablesVersionNo=128;indicatorOfParameter=8;centre=98;}
Expand Down Expand Up @@ -198,3 +196,25 @@
"accum"={gribTablesVersionNo=162;indicatorOfParameter=112;centre=98;}
# vtpha
"accum"={gribTablesVersionNo=162;indicatorOfParameter=113;centre=98;}
# mvv
"avg"={gribTablesVersionNo=130;indicatorOfParameter=232;centre=98;}
# msshfl
"avg"={gribTablesVersionNo=172;indicatorOfParameter=146;centre=98;}
# mslhfl
"avg"={gribTablesVersionNo=172;indicatorOfParameter=147;centre=98;}
# mean2t24
"avg"={gribTablesVersionNo=128;indicatorOfParameter=55;centre=98;}
# mn2d24
"avg"={gribTablesVersionNo=128;indicatorOfParameter=56;centre=98;}
# msdsrf
"avg"={gribTablesVersionNo=172;indicatorOfParameter=169;centre=98;}
# msdtrf
"avg"={gribTablesVersionNo=172;indicatorOfParameter=175;centre=98;}
# msnsrf
"avg"={gribTablesVersionNo=172;indicatorOfParameter=176;centre=98;}
# msntrf
"avg"={gribTablesVersionNo=172;indicatorOfParameter=177;centre=98;}
# mtnsrf
"avg"={gribTablesVersionNo=172;indicatorOfParameter=178;centre=98;}
# mtntrf
"avg"={gribTablesVersionNo=172;indicatorOfParameter=179;centre=98;}
3 changes: 3 additions & 0 deletions definitions/grib1/paramIdForConversion.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Concept paramIdForConversion
# See ECC-1806
0 = {dummy=0;}
3 changes: 3 additions & 0 deletions definitions/grib1/section.1.def
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,6 @@ if (stepTypeForConversion is "accum" || stepTypeForConversion is "max" || stepTy
meta md5Section1 md5(offsetSection1,section1Length);
# md5(start,length,blacklisted1,blacklisted2,...);
meta md5Product md5(offsetSection1,section1Length,gridDefinition,section1Flags,decimalScaleFactor);

# ECC-1806
concept_nofail paramIdForConversion(zero, "paramIdForConversion.def", conceptsDir2, conceptsDir1) : long_type,read_only;
3 changes: 3 additions & 0 deletions definitions/grib2/boot.def
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ concept isTemplateDeprecated(false) {
concept isTemplateExperimental(false) {
1 = { template_is_experimental = 1; }
}

# ECC-1806
transient paramIdForConversion = 0;
17 changes: 17 additions & 0 deletions src/grib_accessor_class_concept.cc
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,23 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
//if(*len > 1)
// return GRIB_NOT_IMPLEMENTED;

// ECC-1806: GRIB: Change of paramId in conversion from GRIB1 to GRIB2
if (STR_EQUAL(a->name, "paramId")) {
grib_handle* h = grib_handle_of_accessor(a);
long edition = 0;
if (grib_get_long(h, "edition", &edition) == GRIB_SUCCESS && edition == 2) {
long newParamId = 0;
if (grib_get_long(h, "paramIdForConversion", &newParamId) == GRIB_SUCCESS && newParamId > 0) {
if (a->context->debug) {
const char* cclass_name = a->cclass->name;
fprintf(stderr, "ECCODES DEBUG %s::%s: Changing %s from %ld to %ld\n",
cclass_name, __func__, a->name, *val, newParamId);
}
snprintf(buf, sizeof(buf), "%ld", newParamId);
}
}
}

s = strlen(buf) + 1;
return pack_string(a, buf, &s);
}
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ if( HAVE_BUILD_TOOLS )
grib_ecc-1708
grib_ecc-1691
grib_ecc-1766
grib_ecc-1806
bufr_ecc-1028
bufr_ecc-1195
bufr_ecc-1259
Expand Down
59 changes: 59 additions & 0 deletions tests/grib_ecc-1806.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/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.ctest.sh

REDIRECT=/dev/null

label="grib_ecc-1806_test"
tempGrib1=temp.$label.1.grib
tempGrib2=temp.$label.2.grib
tempLog=temp.$label.log

sampleGrib1=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
sampleGrib2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl

test_conversion()
{
param1=$1 # old paramId in GRIB1
param2=$2 # new paramId in GRIB2
short=$3 # new shortName

${tools_dir}/grib_set -s paramId=$param1 $sampleGrib1 $tempGrib1
${tools_dir}/grib_set -s edition=2 $tempGrib1 $tempGrib2
grib_check_key_equals $tempGrib2 paramId,shortName "$param2 $short"

# Check the old paramId has been removed from GRIB2
set +e
${tools_dir}/grib_set -s paramId=$param1 $sampleGrib2 $tempGrib2 >$tempLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "no match for paramId" $tempLog
}

test_conversion 174098 262000 sithick
test_conversion 151163 262104 t20d
test_conversion 151145 262124 zos
test_conversion 130232 235135 mw
test_conversion 172146 235033 msshf
test_conversion 172147 235034 mslhf
test_conversion 55 228004 mean2t
test_conversion 56 235168 m2d
test_conversion 172169 235035 msdwswrf
test_conversion 172175 235036 msdwlwrf
test_conversion 172176 235037 msnswrf
test_conversion 172177 235038 msnlwrf
test_conversion 172178 235039 mtnswrf
test_conversion 172179 235040 mtnlwrf


# Clean up
rm -f $tempGrib1 $tempGrib2 $tempLog
Loading