diff --git a/definitions/grib1/localConcepts/ecmf/paramIdForConversion.def b/definitions/grib1/localConcepts/ecmf/paramIdForConversion.def new file mode 100644 index 000000000..67de48733 --- /dev/null +++ b/definitions/grib1/localConcepts/ecmf/paramIdForConversion.def @@ -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;} diff --git a/definitions/grib1/localConcepts/ecmf/stepTypeForConversion.def b/definitions/grib1/localConcepts/ecmf/stepTypeForConversion.def index e74860061..25aae31d8 100644 --- a/definitions/grib1/localConcepts/ecmf/stepTypeForConversion.def +++ b/definitions/grib1/localConcepts/ecmf/stepTypeForConversion.def @@ -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;} @@ -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;} diff --git a/definitions/grib1/paramIdForConversion.def b/definitions/grib1/paramIdForConversion.def new file mode 100644 index 000000000..8cd3ea212 --- /dev/null +++ b/definitions/grib1/paramIdForConversion.def @@ -0,0 +1,3 @@ +# Concept paramIdForConversion +# See ECC-1806 +0 = {dummy=0;} diff --git a/definitions/grib1/section.1.def b/definitions/grib1/section.1.def index 2bda52ec7..d62300f27 100644 --- a/definitions/grib1/section.1.def +++ b/definitions/grib1/section.1.def @@ -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; diff --git a/definitions/grib2/boot.def b/definitions/grib2/boot.def index d2c44fb74..7cba8747b 100644 --- a/definitions/grib2/boot.def +++ b/definitions/grib2/boot.def @@ -53,3 +53,6 @@ concept isTemplateDeprecated(false) { concept isTemplateExperimental(false) { 1 = { template_is_experimental = 1; } } + +# ECC-1806 +transient paramIdForConversion = 0; diff --git a/src/grib_accessor_class_concept.cc b/src/grib_accessor_class_concept.cc index efda63e55..56ec86e30 100644 --- a/src/grib_accessor_class_concept.cc +++ b/src/grib_accessor_class_concept.cc @@ -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); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d3fbc795a..dac9083c1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 diff --git a/tests/grib_ecc-1806.sh b/tests/grib_ecc-1806.sh new file mode 100755 index 000000000..596158b8d --- /dev/null +++ b/tests/grib_ecc-1806.sh @@ -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