From e3abac828bbaf3537bd687f10f319ab7e94d4220 Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 14 Oct 2024 12:42:40 +0100 Subject: [PATCH 01/11] Definitions: Cosmetics --- definitions/mars/grib.oper.ep.def | 4 +--- definitions/mars/mars.quantile.def | 34 ++++++++++++++++-------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/definitions/mars/grib.oper.ep.def b/definitions/mars/grib.oper.ep.def index 0edfd8d01..1b744d28a 100644 --- a/definitions/mars/grib.oper.ep.def +++ b/definitions/mars/grib.oper.ep.def @@ -1,5 +1,3 @@ -if (class is "ai") -{ +if (class is "ai") { alias mars.step = stepRange; } - diff --git a/definitions/mars/mars.quantile.def b/definitions/mars/mars.quantile.def index 60431fc38..83bebb5d1 100644 --- a/definitions/mars/mars.quantile.def +++ b/definitions/mars/mars.quantile.def @@ -1,17 +1,19 @@ -if ((stream is "eehs" or stream is "efhs" or stream is "wees" or stream is "wehs") and (type is "cd")){ - if (edition == 1){ - # defined in local section 19 - alias mars.quantile = quantile; - } else { - meta marsQuantile sprintf("%d:%d",quantileValue,totalNumberOfQuantiles); - alias mars.quantile = marsQuantile; - } - } else { -if (edition == 1){ - meta marsQuantile sprintf("%d:%d",perturbationNumber,numberOfForecastsInEnsemble); - alias mars.quantile = marsQuantile; - } else { - meta marsQuantile sprintf("%d:%d",quantileValue,totalNumberOfQuantiles); - alias mars.quantile = marsQuantile; - } +if ((stream is "eehs" or stream is "efhs" or stream is "wees" or stream is "wehs") and (type is "cd")) { + if (edition == 1) { + # defined in local section 19 + alias mars.quantile = quantile; + } else { + meta marsQuantile sprintf("%d:%d",quantileValue,totalNumberOfQuantiles); + alias mars.quantile = marsQuantile; + } +} +else +{ + if (edition == 1) { + meta marsQuantile sprintf("%d:%d",perturbationNumber,numberOfForecastsInEnsemble); + alias mars.quantile = marsQuantile; + } else { + meta marsQuantile sprintf("%d:%d",quantileValue,totalNumberOfQuantiles); + alias mars.quantile = marsQuantile; + } } From ca384c2f48a3e6208dbb9f1f0f7024055197ff74 Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 14 Oct 2024 15:56:25 +0100 Subject: [PATCH 02/11] Formatting --- src/accessor/grib_accessor_class_ascii.cc | 4 +-- .../grib_accessor_class_bufr_data_element.cc | 8 ++---- ...sor_class_bufr_extract_datetime_subsets.cc | 28 +++++++------------ .../grib_accessor_class_cf_var_name.cc | 4 +-- ...ccessor_class_g1end_of_interval_monthly.cc | 4 +-- .../grib_accessor_class_g2_aerosol.cc | 5 +--- .../grib_accessor_class_g2_chemical.cc | 5 +--- src/accessor/grib_accessor_class_g2_eps.cc | 5 +--- .../grib_accessor_class_g2_mars_labeling.cc | 4 +-- .../grib_accessor_class_local_definition.cc | 4 +-- src/accessor/grib_accessor_class_lookup.cc | 12 ++------ 11 files changed, 23 insertions(+), 60 deletions(-) diff --git a/src/accessor/grib_accessor_class_ascii.cc b/src/accessor/grib_accessor_class_ascii.cc index 86bde1fb2..e6d9a3436 100644 --- a/src/accessor/grib_accessor_class_ascii.cc +++ b/src/accessor/grib_accessor_class_ascii.cc @@ -98,9 +98,7 @@ int grib_accessor_ascii_t::pack_double(const double* v, size_t* len) int grib_accessor_ascii_t::unpack_long(long* v, size_t* len) { - char val[1024] = { - 0, - }; + char val[1024] = {0,}; size_t l = sizeof(val); size_t i = 0; char* last = NULL; diff --git a/src/accessor/grib_accessor_class_bufr_data_element.cc b/src/accessor/grib_accessor_class_bufr_data_element.cc index 53f6fb8ba..938266fa0 100644 --- a/src/accessor/grib_accessor_class_bufr_data_element.cc +++ b/src/accessor/grib_accessor_class_bufr_data_element.cc @@ -175,9 +175,7 @@ int grib_accessor_bufr_data_element_t::unpack_string(char* val, size_t* len) grib_context* c = context_; if (type_ != BUFR_DESCRIPTOR_TYPE_STRING) { - char sval[32] = { - 0, - }; + char sval[32] = {0,}; err = unpack_double(&dval, &dlen); if (err) return err; snprintf(sval, sizeof(sval), "%g", dval); @@ -539,9 +537,7 @@ int grib_accessor_bufr_data_element_t::is_missing() grib_context_free(c, values); } else { - char value[MAX_STRING_SIZE] = { - 0, - }; /* See ECC-710 */ + char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */ size = MAX_STRING_SIZE; err = unpack_string(value, &size); if (err) return 0; /* TODO: no way of propagating the error up */ diff --git a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc index 45a55a326..9b5df9995 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc +++ b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc @@ -85,9 +85,7 @@ static int build_long_array(grib_context* c, grib_handle* h, int compressed, } else { /* uncompressed */ - char keystr[32] = { - 0, - }; + char keystr[32] = {0,}; size_t values_len = 0; for (i = 0; i < numberOfSubsets; ++i) { long lVal = 0; @@ -108,21 +106,15 @@ static int build_long_array(grib_context* c, grib_handle* h, int compressed, int grib_accessor_bufr_extract_datetime_subsets_t::select_datetime() { - int ret = 0; - long compressed = 0; - grib_handle* h = grib_handle_of_accessor(this); - grib_context* c = h->context; - size_t n; + int ret = 0; + long compressed = 0; + grib_handle* h = grib_handle_of_accessor(this); + grib_context* c = h->context; + double julianStart = 0, julianEnd = 0, julianDT = 0; - char start_str[80] = { - 0, - }, - end_str[80] = { - 0, - }, - datetime_str[80] = { - 0, - }; + char start_str[80] = {0,}, + end_str[80] = {0,}, + datetime_str[80] = {0,}; long yearRank, monthRank, dayRank, hourRank, minuteRank, secondRank; long yearStart, monthStart, dayStart, hourStart, minuteStart, secondStart; long yearEnd, monthEnd, dayEnd, hourEnd, minuteEnd, secondEnd; @@ -196,7 +188,7 @@ int grib_accessor_bufr_extract_datetime_subsets_t::select_datetime() if (ret) return ret; /* SECOND: Double array */ - n = numberOfSubsets; + size_t n = numberOfSubsets; second = (double*)grib_context_malloc_clear(c, sizeof(double) * numberOfSubsets); if (compressed) { ret = grib_get_double_array(h, secondstr, second, &n); diff --git a/src/accessor/grib_accessor_class_cf_var_name.cc b/src/accessor/grib_accessor_class_cf_var_name.cc index 93e808c4f..8685e1dfb 100644 --- a/src/accessor/grib_accessor_class_cf_var_name.cc +++ b/src/accessor/grib_accessor_class_cf_var_name.cc @@ -23,9 +23,7 @@ void grib_accessor_cf_var_name_t::init(const long l, grib_arguments* arg) int grib_accessor_cf_var_name_t::unpack_string(char* val, size_t* len) { grib_handle* h = grib_handle_of_accessor(this); - char defaultKey[256] = { - 0, - }; + char defaultKey[256] = {0,}; size_t size = sizeof(defaultKey) / sizeof(*defaultKey); char* pDefaultKey = defaultKey; diff --git a/src/accessor/grib_accessor_class_g1end_of_interval_monthly.cc b/src/accessor/grib_accessor_class_g1end_of_interval_monthly.cc index 9977c68bf..43f7dbbb4 100644 --- a/src/accessor/grib_accessor_class_g1end_of_interval_monthly.cc +++ b/src/accessor/grib_accessor_class_g1end_of_interval_monthly.cc @@ -33,9 +33,7 @@ void grib_accessor_g1end_of_interval_monthly_t::init(const long l, grib_argument int grib_accessor_g1end_of_interval_monthly_t::unpack_double(double* val, size_t* len) { int ret = 0; - char verifyingMonth[7] = { - 0, - }; + char verifyingMonth[7] = {0,}; size_t slen = 7; long year = 0, month = 0, date = 0; const long mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; diff --git a/src/accessor/grib_accessor_class_g2_aerosol.cc b/src/accessor/grib_accessor_class_g2_aerosol.cc index a941f0c30..f32d51e7c 100644 --- a/src/accessor/grib_accessor_class_g2_aerosol.cc +++ b/src/accessor/grib_accessor_class_g2_aerosol.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -46,9 +45,7 @@ int grib_accessor_g2_aerosol_t::pack_long(const long* val, size_t* len) // long type=-1; // long stream=-1; long eps = -1; - char stepType[15] = { - 0, - }; + char stepType[15] = {0,}; size_t slen = 15; // int aerosol = *val; int isInstant = 0; diff --git a/src/accessor/grib_accessor_class_g2_chemical.cc b/src/accessor/grib_accessor_class_g2_chemical.cc index 58ed9e55c..624463699 100644 --- a/src/accessor/grib_accessor_class_g2_chemical.cc +++ b/src/accessor/grib_accessor_class_g2_chemical.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -54,9 +53,7 @@ int grib_accessor_g2_chemical_t::pack_long(const long* val, size_t* len) // long type=-1; // long stream=-1; long eps = -1; - char stepType[15] = { - 0, - }; + char stepType[15] = {0,}; size_t slen = 15; // int chemical = *val; int isInstant = 0; diff --git a/src/accessor/grib_accessor_class_g2_eps.cc b/src/accessor/grib_accessor_class_g2_eps.cc index a9f49a60a..31c4bf6b9 100644 --- a/src/accessor/grib_accessor_class_g2_eps.cc +++ b/src/accessor/grib_accessor_class_g2_eps.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -54,9 +53,7 @@ int grib_accessor_g2_eps_t::pack_long(const long* val, size_t* len) long stream = -1; long chemical = -1; long aerosol = -1; - char stepType[15] = { - 0, - }; + char stepType[15] = {0,}; size_t slen = 15; int eps = *val; int isInstant = 0; diff --git a/src/accessor/grib_accessor_class_g2_mars_labeling.cc b/src/accessor/grib_accessor_class_g2_mars_labeling.cc index 509ebf8b8..2ec962251 100644 --- a/src/accessor/grib_accessor_class_g2_mars_labeling.cc +++ b/src/accessor/grib_accessor_class_g2_mars_labeling.cc @@ -81,9 +81,7 @@ int grib_accessor_g2_mars_labeling_t::extra_set(long val) { int ret = 0; grib_handle* hand = grib_handle_of_accessor(this); - char stepType[30] = { - 0, - }; + char stepType[30] = {0,}; size_t stepTypelen = 30; long derivedForecast = -1; long productDefinitionTemplateNumberNew = -1; diff --git a/src/accessor/grib_accessor_class_local_definition.cc b/src/accessor/grib_accessor_class_local_definition.cc index 0a45b96ef..6f3d8a3a7 100644 --- a/src/accessor/grib_accessor_class_local_definition.cc +++ b/src/accessor/grib_accessor_class_local_definition.cc @@ -48,9 +48,7 @@ int grib_accessor_local_definition_t::pack_long(const long* val, size_t* len) long eps = -1; long chemical = -1; long aerosol = -1; - char stepType[15] = { - 0, - }; + char stepType[15] = {0,}; size_t slen = 15; int localDefinitionNumber = *val; int isInstant = 0; diff --git a/src/accessor/grib_accessor_class_lookup.cc b/src/accessor/grib_accessor_class_lookup.cc index b716b4d56..0ec0c62e1 100644 --- a/src/accessor/grib_accessor_class_lookup.cc +++ b/src/accessor/grib_accessor_class_lookup.cc @@ -32,12 +32,8 @@ void grib_accessor_lookup_t::post_init() void grib_accessor_lookup_t::dump(grib_dumper* dumper) { - unsigned char bytes[1024] = { - 0, - }; - char msg[1024] = { - 0, - }; + unsigned char bytes[1024] = {0,}; + char msg[1024] = {0,}; char buf[2048]; unsigned long v = 0; @@ -59,9 +55,7 @@ void grib_accessor_lookup_t::dump(grib_dumper* dumper) int grib_accessor_lookup_t::unpack_string(char* v, size_t* len) { - unsigned char bytes[1024] = { - 0, - }; + unsigned char bytes[1024] = {0,}; size_t llen = llength_; unpack_bytes(bytes, &llen); From 87b73caa49c68387a31a9ca4571cbc617eb74280 Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 14 Oct 2024 17:05:22 +0100 Subject: [PATCH 03/11] Definitions: Cosmetics --- definitions/grib1/mars_labeling.def | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/definitions/grib1/mars_labeling.def b/definitions/grib1/mars_labeling.def index 51eae2bdf..1d081c6d8 100644 --- a/definitions/grib1/mars_labeling.def +++ b/definitions/grib1/mars_labeling.def @@ -1,11 +1,10 @@ -codetable[1] marsClass "mars/class.table" = "od" : dump, string_type, lowercase; +codetable[1] marsClass "mars/class.table" = "od" : dump, string_type, lowercase; codetable[1] marsType "mars/type.table" = "an" : dump, string_type, lowercase; -codetable[2] marsStream "mars/stream.table" = "oper" : dump, string_type, lowercase ; +codetable[2] marsStream "mars/stream.table" = "oper" : dump, string_type, lowercase; ksec1expver[4] experimentVersionNumber = "0001" : dump; #alias typeOfProcessedData=marsType; alias ls.dataType = marsType; - alias mars.class = marsClass; alias mars.type = marsType; alias mars.stream = marsStream; From 45e9c8a38ac10b89cf004e689cbe5d8ba107e638 Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 14 Oct 2024 17:05:47 +0100 Subject: [PATCH 04/11] Testing: GRIB2 product def templates --- tests/grib2_templates.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/grib2_templates.sh b/tests/grib2_templates.sh index bb295b73a..800a5aca9 100755 --- a/tests/grib2_templates.sh +++ b/tests/grib2_templates.sh @@ -8,7 +8,6 @@ # virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. # . ./include.ctest.sh -set -u label="grib2_templates_test" @@ -32,6 +31,25 @@ awk '$1 !~ /#/ && $1 < 65000 {print $1}' $latest_codetable_file | while read pdt fi done +rm -f $tempText +pdtns=$( awk '!/^#/ && $1 < 65000 {print $1}' $latest_codetable_file ) +for p in $pdtns; do + $tools_dir/grib_set -s tablesVersion=$latestOfficial,productDefinitionTemplateNumber=$p $sample2 $temp + $tools_dir/grib_dump -O -p section_4 $temp >> $tempText + # Expect the grep to fail and not find 'unknown' in the dump output + set +e + grep -q -i unknown $tempText + status=$? + set -e + if [ $status -ne 1 ]; then + echo "GRIB2 PDTN $p produced a dump with unknown!" + grep -i unknown $tempText + exit 1 + fi +done +rm -f $tempText + + # ECC-1746 # ------------- $tools_dir/grib_set -s tablesVersion=31,productDefinitionTemplateNumber=34 $sample2 $temp From 99304fc7fcd5e4a26337cab2289ea1b46854fb68 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 15 Oct 2024 12:01:06 +0000 Subject: [PATCH 05/11] ECC-1939: BUFR: Definition of new mucape descriptor for 49r1 --- definitions/bufr/tables/0/local/1/98/0/element.table | 1 + definitions/bufr/tables/0/local/101/98/0/element.table | 1 + definitions/bufr/tables/3/local/1/98/0/element.table | 1 + 3 files changed, 3 insertions(+) diff --git a/definitions/bufr/tables/0/local/1/98/0/element.table b/definitions/bufr/tables/0/local/1/98/0/element.table index d38196d6a..ac381eb74 100644 --- a/definitions/bufr/tables/0/local/1/98/0/element.table +++ b/definitions/bufr/tables/0/local/1/98/0/element.table @@ -129,6 +129,7 @@ 013234|snowDepthWaterEquivalentSdGrib|double|SNOW DEPTH (WATER EQUIVALENT SD GRIB)|m|4|0|14|NA|0|0 013240|airDensity|double|AIR DENSITY|kg m-3|3|0|10|NA|0|0 013241|cape|double|CONVECTIVE AVAILABLE POTENTIAL ENERGY|J/kg|1|0|17|NA|0|0 +013242|mucape|long|MOST UNSTABLE CAPE|J/kg|0|0|14|NA|0|0 014200|surfaceSolarRadiationDownwardsSsrdGrib|long|SURFACE SOLAR RADIATION DOWNWARDS (SSRD GRIB)|W m-2 s|-2|0|24|NA|0|0 015202|integratedElectronDensity|double|INTEGRATED ELECTRON DENSITY|m-2|3|13000|12|NA|0|0 015231|atmosphericPathDelayInSatelliteSignal|double|ATMOSPHERIC PATH DELAY IN SATELLITE SIGNAL|m|4|0|15|NA|0|0 diff --git a/definitions/bufr/tables/0/local/101/98/0/element.table b/definitions/bufr/tables/0/local/101/98/0/element.table index 5f9b1adf7..b05377149 100644 --- a/definitions/bufr/tables/0/local/101/98/0/element.table +++ b/definitions/bufr/tables/0/local/101/98/0/element.table @@ -110,6 +110,7 @@ 013231|largeScalePrecipitation|double|LARGE SCALE PRECIPITATION|kg m-2|1|-1|14|NA|0|0 013240|airDensity|double|AIR DENSITY|kg m-3|3|0|10|NA|0|0 013241|cape|double|CONVECTIVE AVAILABLE POTENTIAL ENERGY|J/kg|1|0|17|NA|0|0 +013242|mucape|long|MOST UNSTABLE CAPE|J/kg|0|0|14|NA|0|0 015008|significandOfVolumetricMixingRatio|long|(VAL) SCALED VOLUMETRIC MIXING RATIO|Numeric|0|0|24|NA|0|0 015021|integratedMassDensity|long|(VAL) SCALED INTEGRATED MASS DENSITY|kg m-2|0|0|24|NA|0|0 015042|reflectance|long|(VAL) REFLECTANCE|Numeric|6|0|20|NA|0|0 diff --git a/definitions/bufr/tables/3/local/1/98/0/element.table b/definitions/bufr/tables/3/local/1/98/0/element.table index f80a82c2a..2b3f2eb01 100644 --- a/definitions/bufr/tables/3/local/1/98/0/element.table +++ b/definitions/bufr/tables/3/local/1/98/0/element.table @@ -123,6 +123,7 @@ 013234|snowDepthWaterEquivalentSdGrib|double|SNOW DEPTH (WATER EQUIVALENT SD GRIB)|m|4|0|14|NA|0|0 013240|airDensity|double|AIR DENSITY|kg m-3|3|0|10|NA|0|0 013241|cape|double|CONVECTIVE AVAILABLE POTENTIAL ENERGY|J/kg|1|0|17|NA|0|0 +013242|mucape|long|MOST UNSTABLE CAPE|J/kg|0|0|14|NA|0|0 014200|surfaceSolarRadiationDownwardsSsrdGrib|long|SURFACE SOLAR RADIATION DOWNWARDS (SSRD GRIB)|W m-2 s|-2|0|24|NA|0|0 015202|integratedElectronDensity|double|INTEGRATED ELECTRON DENSITY|m-2|3|13000|12|NA|0|0 015231|atmosphericPathDelayInSatelliteSignal|double|ATMOSPHERIC PATH DELAY IN SATELLITE SIGNAL|m|4|0|15|NA|0|0 From e4adcb2cf85a5610493c46f09695dda38cebe9f7 Mon Sep 17 00:00:00 2001 From: Sebastien Date: Tue, 15 Oct 2024 13:59:56 +0100 Subject: [PATCH 06/11] ECC-1940 adding grib.olda.tpa.def (#253) * ECC-1940 adding grib.olda.tpa.def * ECC-1940: Fix error --------- Co-authored-by: shahramn --- definitions/mars/grib.olda.tpa.def | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 definitions/mars/grib.olda.tpa.def diff --git a/definitions/mars/grib.olda.tpa.def b/definitions/mars/grib.olda.tpa.def new file mode 100644 index 000000000..198e4144f --- /dev/null +++ b/definitions/mars/grib.olda.tpa.def @@ -0,0 +1,15 @@ +# aliasing MARS date and Time to the date and time defined in local section, +# corresponding to the end of the Ocean NRT data assimilation +alias mars.date = dateOfAnalysis; +alias mars.time = timeOfAnalysis; + +# aliasing the new offset date and time to the date and time +# coming fron the section 1, i.e. reference date and time +alias mars.offsetdate = dataDate; +alias mars.offsettime = dataTime; + +unalias mars.step; +alias mars.step = stepRange; +if (defined(perturbationNumber)) { + alias mars.number = perturbationNumber; +} From 66bfe1fbab1c694037970a0dcd23d9088073bdf0 Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 15 Oct 2024 14:51:27 +0100 Subject: [PATCH 07/11] Testing: Check for duplicate parameter encodings --- tests/grib_check_param_concepts.sh | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/grib_check_param_concepts.sh b/tests/grib_check_param_concepts.sh index 3fb716f46..fd112b4d3 100755 --- a/tests/grib_check_param_concepts.sh +++ b/tests/grib_check_param_concepts.sh @@ -37,19 +37,21 @@ check_grib_defs() # ----------------------------------- echo "Check for duplicate encodings" # ----------------------------------- -paramIdFile=$ECCODES_DEFINITION_PATH/grib2/paramId.def +paramIdFiles="$ECCODES_DEFINITION_PATH/grib2/paramId.def $ECCODES_DEFINITION_PATH/grib2/localConcepts/ecmf/paramId.def" + # Flatten the file so we get just the encoding part. # uniq -d outputs a single copy of each line that is repeated in the input -cat $paramIdFile | tr '\n' ' ' | tr '\t' ' ' | tr '#' '\n' | sed "s/^.* '//" | sed "s/'//" | awk '{$1="";print}' | sort |uniq -d > $tempText -if [ -s "$tempText" ]; then - # File exists and has a size greater than zero - echo "ERROR: Duplicate parameter encoding(s) found in $paramIdFile" >&2 - cat $tempText | sed -e 's/ ;/;/g' - exit 1 -else - echo "No duplicates in $paramIdFile" -fi - +for paramIdFile in $paramIdFiles; do + cat $paramIdFile | tr '\n' ' ' | tr '\t' ' ' | tr '#' '\n' | sed "s/^.* '//" | sed "s/'//" | awk '{$1="";print}' | sort |uniq -d > $tempText + if [ -s "$tempText" ]; then + # File exists and has a size greater than zero + echo "ERROR: Duplicate parameter encoding(s) found in $paramIdFile" >&2 + cat $tempText | sed -e 's/ ;/;/g' + exit 1 + else + echo "No duplicates in $paramIdFile" + fi +done # First check the GRIB2 paramId.def and shortName.def # ---------------------------------------------------- From e5e0952fb447b28dd2d686be197cd668add43172 Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 15 Oct 2024 17:03:51 +0100 Subject: [PATCH 08/11] GRIB2: Support for chemical source/sink --- ...grib_accessor_class_select_step_template.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/accessor/grib_accessor_class_select_step_template.cc b/src/accessor/grib_accessor_class_select_step_template.cc index 4b5a2c28b..e37f62fa3 100644 --- a/src/accessor/grib_accessor_class_select_step_template.cc +++ b/src/accessor/grib_accessor_class_select_step_template.cc @@ -75,12 +75,21 @@ int grib_accessor_select_step_template_t::pack_long(const long* val, size_t* len case 47: // ENS aerosol productDefinitionTemplateNumberNew = 45; break; + case 67: // DET chemical distrib func productDefinitionTemplateNumberNew = 57; break; case 68: // ENS chemical distrib func productDefinitionTemplateNumberNew = 58; break; + + case 78: // DET chemical source/sink + productDefinitionTemplateNumberNew = 76; + break; + case 79: // ENS chemical source/sink + productDefinitionTemplateNumberNew = 77; + break; + case 72: // DET post-processing productDefinitionTemplateNumberNew = 70; break; @@ -136,12 +145,21 @@ int grib_accessor_select_step_template_t::pack_long(const long* val, size_t* len case 45: // ENS aerosol productDefinitionTemplateNumberNew = 85; // 47 is deprecated break; + case 57: // DET chemical distrib func productDefinitionTemplateNumberNew = 67; break; case 58: // ENS chemical distrib func productDefinitionTemplateNumberNew = 68; break; + + case 76: // DET chemical source/sink + productDefinitionTemplateNumberNew = 78; + break; + case 77: // ENS chemical source/sink + productDefinitionTemplateNumberNew = 79; + break; + case 70: // DET post-processing productDefinitionTemplateNumberNew = 72; break; From d35518ec462f4b32dcce215ec73229511c275784 Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 15 Oct 2024 17:20:12 +0100 Subject: [PATCH 09/11] Debugging: print grib_values key/value pair array --- src/eccodes_prototypes.h | 2 +- src/grib_value.cc | 20 +++++++++++--------- tests/unit_tests.cc | 6 +++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/eccodes_prototypes.h b/src/eccodes_prototypes.h index 55f889dea..0bf5baac2 100644 --- a/src/eccodes_prototypes.h +++ b/src/eccodes_prototypes.h @@ -733,7 +733,7 @@ int grib_get_long_array_internal(grib_handle* h, const char* name, long* val, si int grib_get_long_array(const grib_handle* h, const char* name, long* val, size_t* length); int grib_set_values(grib_handle* h, grib_values* args, size_t count); int grib_get_nearest_smaller_value(grib_handle* h, const char* name, double val, double* nearest); -void grib_print_values(const char* title, grib_values* values, FILE* out); +void grib_print_values(const char* title, const grib_values* values, FILE* out, int count); int grib_values_check(grib_handle* h, grib_values* values, int count); int codes_copy_key(grib_handle* h1, grib_handle* h2, const char* key, int type); int codes_compare_key(grib_handle* h1, grib_handle* h2, const char* key, int compare_flags); diff --git a/src/grib_value.cc b/src/grib_value.cc index 4b5b71ec7..277966bfc 100644 --- a/src/grib_value.cc +++ b/src/grib_value.cc @@ -1801,7 +1801,7 @@ int grib_set_values(grib_handle* h, grib_values* args, size_t count) if (h->context->debug) { for (i = 0; i < count; i++) { - grib_print_values("ECCODES DEBUG about to set key/value pair", &args[i], stderr); + grib_print_values("ECCODES DEBUG about to set key/value pair", &args[i], stderr, 1); } } @@ -1875,22 +1875,24 @@ int grib_get_nearest_smaller_value(grib_handle* h, const char* name, return act->nearest_smaller_value(val, nearest); } -void grib_print_values(const char* title, grib_values* values, FILE* out) +void grib_print_values(const char* title, const grib_values* values, FILE* out, int count) { - if (values) { - fprintf(out, "%s: %s=", title, values->name); - switch (values->type) { + Assert(values); + for (int i = 0; i < count; ++i) { + const grib_values aVal = values[i]; + fprintf(out, "%s: %s=", title, aVal.name); + switch (aVal.type) { case GRIB_TYPE_LONG: - fprintf(out, "%ld", values->long_value); + fprintf(out, "%ld", aVal.long_value); break; case GRIB_TYPE_DOUBLE: - fprintf(out, "%g", values->double_value); + fprintf(out, "%g", aVal.double_value); break; case GRIB_TYPE_STRING: - fprintf(out, "%s", values->string_value); + fprintf(out, "%s", aVal.string_value); break; } - fprintf(out, " (type=%s)\n", grib_get_type_name(values->type)); + fprintf(out, " (type=%s)\n", grib_get_type_name(aVal.type)); } } diff --git a/tests/unit_tests.cc b/tests/unit_tests.cc index 4ab3ead6d..aad854fec 100644 --- a/tests/unit_tests.cc +++ b/tests/unit_tests.cc @@ -486,7 +486,7 @@ static void test_parse_keyval_string() values_required, GRIB_TYPE_UNDEFINED, values1, &count); Assert( !err ); Assert( count == 2 ); - grib_print_values("print values test: values1", values1, stdout); + grib_print_values("print values test: values1", values1, stdout, count); Assert( strcmp(values1[0].name, "key1")==0 ); Assert( strcmp(values1[0].string_value, "value1")==0 ); @@ -506,7 +506,7 @@ static void test_parse_keyval_string() values_required, GRIB_TYPE_LONG, values2, &count); Assert( !err ); Assert( count == 1 ); - grib_print_values("print values test: values2", values2, stdout); + grib_print_values("print values test: values2", values2, stdout, count); Assert( strcmp(values2[0].name, "x")==0 ); Assert( values2[0].long_value == 14 ); Assert( values2[0].equal == 1 ); @@ -517,7 +517,7 @@ static void test_parse_keyval_string() values_required, GRIB_TYPE_DOUBLE, values3, &count); Assert( !err ); Assert( count == 1 ); - grib_print_values("print values test: values3", values3, stdout); + grib_print_values("print values test: values3", values3, stdout, count); Assert( strcmp(values3[0].name, "mars.level")==0 ); free( (void*)values3[0].name ); } From 9b49125133a6a2dfbe5faa61e79a53824f0b5219 Mon Sep 17 00:00:00 2001 From: shahramn Date: Tue, 15 Oct 2024 17:54:45 +0100 Subject: [PATCH 10/11] ECC-1941: GRIB: Setting paramId=131060 fails if typeOfFirstFixedSurface=255 --- definitions/grib2/typeOfLevelConcept.def | 2 +- tests/CMakeLists.txt | 1 + tests/grib_ecc-1941.sh | 34 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100755 tests/grib_ecc-1941.sh diff --git a/definitions/grib2/typeOfLevelConcept.def b/definitions/grib2/typeOfLevelConcept.def index 946b0722d..34ee22bda 100644 --- a/definitions/grib2/typeOfLevelConcept.def +++ b/definitions/grib2/typeOfLevelConcept.def @@ -98,4 +98,4 @@ 'road' = {typeOfFirstFixedSurface=187; typeOfSecondFixedSurface=255;} 'roadLayer' = {typeOfFirstFixedSurface=187; typeOfSecondFixedSurface=187;} 'urbanCanyon' = {typeOfFirstFixedSurface=187; typeOfSecondFixedSurface=185;} -'unknown' = {dummy=0;} +'unknown' = {dummyc=0;} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1bca272ab..b14566ea2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -277,6 +277,7 @@ if( HAVE_BUILD_TOOLS ) grib_ecc-1792 grib_ecc-1806 grib_ecc-1907 + grib_ecc-1941 grib_modelName grib_sub_hourly grib_set_bytes diff --git a/tests/grib_ecc-1941.sh b/tests/grib_ecc-1941.sh new file mode 100755 index 000000000..e4fd8d417 --- /dev/null +++ b/tests/grib_ecc-1941.sh @@ -0,0 +1,34 @@ +#!/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 + +# ------------------------------------------------------------ +# This is the test for the JIRA issue ECC-1941 +# Setting paramId=131060 fails if typeOfFirstFixedSurface=255 +# ------------------------------------------------------------ + +label="grib_ecc-1941_test" +tempGribA=temp.$label.A.grib +tempGribB=temp.$label.B.grib + +sample_grib2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl + +${tools_dir}/grib_set -s paramId=131060 $sample_grib2 $tempGribA +grib_check_key_equals $tempGribA paramId,shortName '131060 tpg1' + +${tools_dir}/grib_set -s typeOfFirstFixedSurface=255 $sample_grib2 $tempGribA +grib_check_key_equals $tempGribA typeOfLevel unknown + +${tools_dir}/grib_set -s paramId=131060 $tempGribA $tempGribB +grib_check_key_equals $tempGribB paramId,shortName '131060 tpg1' + +# Clean up +rm -f $tempGribA $tempGribB From 041f521e37ce3594d1cb18359ec5bf4ded25efd1 Mon Sep 17 00:00:00 2001 From: shahramn Date: Wed, 16 Oct 2024 11:02:01 +0100 Subject: [PATCH 11/11] Fix nightly regression test (grib_check_typeOfLevels_ecmf) --- definitions/grib2/typeOfLevelConcept.def | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/definitions/grib2/typeOfLevelConcept.def b/definitions/grib2/typeOfLevelConcept.def index 34ee22bda..aaea705ad 100644 --- a/definitions/grib2/typeOfLevelConcept.def +++ b/definitions/grib2/typeOfLevelConcept.def @@ -98,4 +98,4 @@ 'road' = {typeOfFirstFixedSurface=187; typeOfSecondFixedSurface=255;} 'roadLayer' = {typeOfFirstFixedSurface=187; typeOfSecondFixedSurface=187;} 'urbanCanyon' = {typeOfFirstFixedSurface=187; typeOfSecondFixedSurface=185;} -'unknown' = {dummyc=0;} +'unknown' = {dummyc=1;}