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

ECC-1958 BUFR encoding: Delayed replication: Too many elements #268

Merged
merged 6 commits into from
Nov 13, 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
19 changes: 10 additions & 9 deletions src/accessor/grib_accessor_class_expanded_descriptors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,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;
}
grib_bufr_descriptor_set_code(uidx, (size - 1) * 1000 + 100000);
Assert( uidx->type == BUFR_DESCRIPTOR_TYPE_REPLICATION );
Assert( uidx->F == 1 );
Assert( uidx->Y == 0 );
// 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++;
}
else {
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ if( HAVE_BUILD_TOOLS )
bufr_ecc-1476
bufr_ecc-1623
bufr_ecc-1785
bufr_ecc-1958
bufr_ecc-1938
grib_ecc-490
grib_ecc-756
Expand Down
61 changes: 61 additions & 0 deletions tests/bufr_ecc-1958.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/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

# 005074 indexInRangeDirection
# 005075 indexInAzimuthalDirection
# 008085 beamIdentifier
# 022161 waveSpectra
# 002134 antennaBeamAzimuth

cat >$tempFilt<<EOF
set numberOfSubsets = 1;
set inputExtendedDelayedDescriptorReplicationFactor = {32};
set masterTablesVersionNumber = 41;
set updateSequenceNumber = 0;
set bufrHeaderSubCentre = 0;
set unexpandedDescriptors = { 109000,31002,5074,107024,5075,8085,22161,8085,102003,2134,22161 };
write;
EOF
${tools_dir}/codes_bufr_filter -o $tempBufr $tempFilt $sample_bufr4

# 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 ]

# 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
Loading