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-1898 GRIB: Key 'levelist' persists despite being taken out of the mars namespace #260

Merged
merged 4 commits into from
Oct 28, 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
9 changes: 9 additions & 0 deletions src/action_class_alias.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h)
if (x->name_space_ == NULL)
x->name_space_ = act->name_space;

// TODO(maee): Make sure that the accessor is added to the trie

grib_context_log(p->h->context, GRIB_LOG_DEBUG, "alias: add only namespace: %s.%s",
act->name_space, act->name);
i = 0;
Expand Down Expand Up @@ -178,6 +180,13 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h)
act->name_space, act->name, y->name_);
/* printf("[%s %s]\n",y->all_names_[i], y->all_name_spaces_[i]); */

// ECC-1898: Remove accessor from cache
grib_handle* hand = grib_handle_of_accessor(y);
if (hand->use_trie && y->all_name_spaces_[i] != NULL && strcmp(y->name_, act->name) != 0) {
int id = grib_hash_keys_get_id(hand->context->keys, act->name);
hand->accessors[id] = NULL;
}

while (i < MAX_ACCESSOR_NAMES - 1) {
y->all_names_[i] = y->all_names_[i + 1];
y->all_name_spaces_[i] = y->all_name_spaces_[i + 1];
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ if( HAVE_BUILD_TOOLS )
grib_ecc-1764
grib_ecc-1792
grib_ecc-1806
grib_ecc-1898
grib_ecc-1907
grib_ecc-1941
grib_ecc-1942
Expand Down
38 changes: 38 additions & 0 deletions tests/grib_ecc-1898.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/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

label="grib_ecc-1898_test"

tempGrib=temp.$label.grib
tempOut=temp.${label}.txt

$tools_dir/grib_dump -Da $samp_dir/reduced_gg_pl_32_grib2.tmpl > $tempOut
grep -q '288-288 g2level level = 1000 \[vertical.level, mars.levelist\]' $tempOut

# For given MARS stream/types, we unalias the mars.levelist key
$tools_dir/grib_set -s stream=gfas,type=gsd $samp_dir/reduced_gg_pl_32_grib2.tmpl $tempGrib

# Check that the key is unaliased
$tools_dir/grib_dump -Da $tempGrib > $tempOut
grep -q '288-288 g2level level = 1000 \[vertical.level\]' $tempOut

$tools_dir/grib_dump -p levelist -Da $tempGrib 2> $tempOut
grep -q 'levelist: Key/value not found' $tempOut

result=$($tools_dir/grib_get -fp levelist $tempGrib)
[ "$result" = "not_found" ]

result=$($tools_dir/grib_get -fp mars.levelist $tempGrib)
[ "$result" = "not_found" ]

# Clean up
rm -f $tempGrib $tempOut
11 changes: 11 additions & 0 deletions tests/grib_uerra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,16 @@ $grib2_sample $temp1
grib_check_key_equals $temp1 'marsExpver,mars.expver' '0078 0078'


# Stream 'dame'
${tools_dir}/grib_set -s productionStatusOfProcessedData=10 $grib2_sample $temp1
grib_check_key_equals $temp1 'mars.time,mars.step' '1200 0'

${tools_dir}/grib_set -s \
productionStatusOfProcessedData=10,productDefinitionTemplateNumber=8,outerLoopTypeOfTimeIncrement=1,outerLoopLengthOfTimeRange=21 \
$grib2_sample $temp1
grib_check_key_equals $temp1 'mars.stream' 'dame'
result=$(${tools_dir}/grib_get -fp mars.time,mars.step $temp1)
[ "$result" = "not_found not_found" ]

# Clean up
rm -f $temp1 $temp2 $tempSample
Loading