From a80c531969e934011edda0d51366922f5a2f7889 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 4 Nov 2024 13:33:56 +0000 Subject: [PATCH 1/4] ECC-1958: BUFR encoding: Delayed replication: Too many elements --- .../grib_accessor_class_expanded_descriptors.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/accessor/grib_accessor_class_expanded_descriptors.cc b/src/accessor/grib_accessor_class_expanded_descriptors.cc index 6acb4e878a..fd86db4644 100644 --- a/src/accessor/grib_accessor_class_expanded_descriptors.cc +++ b/src/accessor/grib_accessor_class_expanded_descriptors.cc @@ -211,15 +211,16 @@ void grib_accessor_expanded_descriptors_t::__expand(bufr_descriptors_array* unex #endif expanded = grib_bufr_descriptors_array_append(expanded, inner_expanded); uidx = grib_bufr_descriptors_array_get(expanded, idx); - if (size > 100) { - grib_context_log(c, GRIB_LOG_ERROR, - "Delayed replication %06ld: Too many elements (%lu). " - "Hint: This may be due to associated field descriptors", - uidx->code, size); - *err = GRIB_DECODING_ERROR; - return; + // ECC-1958 + if (size <= 100) { + grib_bufr_descriptor_set_code(uidx, (size - 1) * 1000 + 100000); + } + else { + grib_context_log(c, GRIB_LOG_DEBUG, + "WARNING : Delayed replication %06ld: Too many elements (%lu). " + "Hint: This may be due to associated field descriptors", + uidx->code, size); } - grib_bufr_descriptor_set_code(uidx, (size - 1) * 1000 + 100000); size++; } else { From cf7fab255bc12d65b7e37cde5c24ed9e7f29382f Mon Sep 17 00:00:00 2001 From: shahramn Date: Mon, 4 Nov 2024 15:19:16 +0000 Subject: [PATCH 2/4] ECC-1958: Test --- tests/CMakeLists.txt | 1 + tests/bufr_ecc-1958.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100755 tests/bufr_ecc-1958.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fa685fd447..0f7701b33a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -258,6 +258,7 @@ if( HAVE_BUILD_TOOLS ) bufr_ecc-1476 bufr_ecc-1623 bufr_ecc-1785 + bufr_ecc-1958 grib_ecc-490 grib_ecc-756 grib_ecc-806 diff --git a/tests/bufr_ecc-1958.sh b/tests/bufr_ecc-1958.sh new file mode 100755 index 0000000000..8a92256806 --- /dev/null +++ b/tests/bufr_ecc-1958.sh @@ -0,0 +1,41 @@ +#!/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="bufr_ecc-1958_test" +tempBufr=temp.$label.bufr +tempFilt=temp.$label.filt +tempLog=temp.$label.log +tempOut=temp.$label.txt +tempRef=temp.$label.ref + +sample_bufr4=$ECCODES_SAMPLES_PATH/BUFR4.tmpl + +#... +#infile=${data_dir}/SOME_FILE +cat >$tempFilt< $tempOut + +# Clean up +rm -f $tempBufr $tempFilt $tempLog $tempOut $tempRef From 341e170304d769f64b3cb55d7265d88eeb4db263 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 13 Nov 2024 16:39:37 +0000 Subject: [PATCH 3/4] ECC-1958: Add test --- ...rib_accessor_class_expanded_descriptors.cc | 7 ++++++- tests/bufr_ecc-1958.sh | 21 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/accessor/grib_accessor_class_expanded_descriptors.cc b/src/accessor/grib_accessor_class_expanded_descriptors.cc index 7297a84d78..f2a4060890 100644 --- a/src/accessor/grib_accessor_class_expanded_descriptors.cc +++ b/src/accessor/grib_accessor_class_expanded_descriptors.cc @@ -212,7 +212,12 @@ void grib_accessor_expanded_descriptors_t::__expand(bufr_descriptors_array* unex Assert( uidx->type == BUFR_DESCRIPTOR_TYPE_REPLICATION ); Assert( uidx->F == 1 ); Assert( uidx->Y == 0 ); - uidx->X = (int)(size - 1); // ECC-1958: X here is not limited to 6bits! + // ECC-1958 and ECC-1054: + // Here size can exceed 63 (num bits in X is 6) + // We need to set X but not the descriptor code + uidx->X = (int)(size - 1); + if (size < 64) + uidx->code = (size - 1) * 1000 + 100000; //grib_bufr_descriptor_set_code(uidx, (size - 1) * 1000 + 100000); size++; } diff --git a/tests/bufr_ecc-1958.sh b/tests/bufr_ecc-1958.sh index 8a92256806..b7996d85ce 100755 --- a/tests/bufr_ecc-1958.sh +++ b/tests/bufr_ecc-1958.sh @@ -21,8 +21,12 @@ tempRef=temp.$label.ref sample_bufr4=$ECCODES_SAMPLES_PATH/BUFR4.tmpl -#... -#infile=${data_dir}/SOME_FILE +# 005074 indexInRangeDirection +# 005075 indexInAzimuthalDirection +# 008085 beamIdentifier +# 022161 waveSpectra +# 002134 antennaBeamAzimuth + cat >$tempFilt<$tempFilt< $tempOut +c=$( grep -c -w indexInRangeDirection $tempOut ) +[ $c -eq 32 ] + +# 32*24 = 768 +c=$( grep -c -w indexInAzimuthalDirection $tempOut ) +[ $c -eq 768 ] + +# 32*24*3 = 2304 +c=$( grep -c -w antennaBeamAzimuth $tempOut ) +[ $c -eq 2304 ] + + # Clean up rm -f $tempBufr $tempFilt $tempLog $tempOut $tempRef From ce461a97917e2da2680d7c1245431f81fa8a79e8 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 13 Nov 2024 17:06:58 +0000 Subject: [PATCH 4/4] ECC-1958: Add test for -d --- tests/bufr_ecc-1958.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/bufr_ecc-1958.sh b/tests/bufr_ecc-1958.sh index b7996d85ce..0a5a92c697 100755 --- a/tests/bufr_ecc-1958.sh +++ b/tests/bufr_ecc-1958.sh @@ -38,8 +38,13 @@ cat >$tempFilt< $tempOut +# Check descriptor dump +${tools_dir}/bufr_dump -d $tempBufr > $tempOut +c=$( grep -c -w antennaBeamAzimuth $tempOut ) +[ $c -eq 72 ] +# Check full dump +${tools_dir}/bufr_dump -p $tempBufr > $tempOut c=$( grep -c -w indexInRangeDirection $tempOut ) [ $c -eq 32 ]