Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/mtg2_tablesVersion_switc…
Browse files Browse the repository at this point in the history
…h' into feature/mtg2_tablesVersion_switch_chem
  • Loading branch information
mjg41 committed Feb 6, 2025
2 parents 6f0b9a2 + 5fdc370 commit ae284ab
Show file tree
Hide file tree
Showing 10 changed files with 7,373 additions and 7,159 deletions.
16 changes: 7 additions & 9 deletions definitions/grib2/section.4.def
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ alias numberOfCoordinatesValues=NV;
# For table 4.5, code 150 Generalized vertical height coordinate
alias numberOfVerticalGridDescriptors=NV ;

# Product Definition Template Number

transient neitherPresent = 0;

if (centre==7 || centre==46) {
alias disableGrib1LocalSection=true;
}
# if (centre==7 || centre==46) {
# alias disableGrib1LocalSection=true;
# }

concept datasetForLocal(unknown) {
"tigge" = {productionStatusOfProcessedData=4;}
Expand Down Expand Up @@ -94,9 +92,9 @@ if (section2Used == 1) {
transient genVertHeightCoords = 0;

if (productDefinitionTemplateNumber >= 32768) {
template productDefinition "grib2/local/[centreForLocal]/template.4.[productDefinitionTemplateNumber:l].def";
template productDefinition "grib2/local/[centreForLocal]/template.4.[productDefinitionTemplateNumber:l].def";
} else {
template productDefinition "grib2/templates/template.4.[productDefinitionTemplateNumber:l].def";
template productDefinition "grib2/templates/template.4.[productDefinitionTemplateNumber:l].def";
}

if (defined(marsStream) && defined(marsType)) {
Expand Down Expand Up @@ -130,9 +128,9 @@ if (genVertHeightCoords) {
}
else {
if (NV == 0){
transient PVPresent = 0;
transient PVPresent = 0;
} else {
transient PVPresent = 1;
transient PVPresent = 1;
}
# See GRIB-547
if (PVPresent || NV>0){
Expand Down
10 changes: 6 additions & 4 deletions src/accessor/grib_accessor_class_g2_param_concept_filename.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ void grib_accessor_g2_param_concept_filename_t::init(const long len, grib_argume
grib_accessor_gen_t::init(len, arg);
grib_handle* h = grib_handle_of_accessor(this);

const int numArgs = arg->get_count();
if (numArgs != 3) {
grib_context_log(context_, GRIB_LOG_FATAL, "Accessor %s (key %s): %d arguments provided but expected 3",
class_name_, name_, numArgs);
if (context_->debug) {
const int numArgs = arg->get_count();
if (numArgs != 3) {
grib_context_log(context_, GRIB_LOG_FATAL, "Accessor %s (key %s): %d arguments provided but expected 3",
class_name_, name_, numArgs);
}
}

basename_ = arg->get_string(h, 0);
Expand Down
11 changes: 7 additions & 4 deletions src/accessor/grib_accessor_class_mtg2_switch_default.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ void grib_accessor_mtg2_switch_default_t::init(const long len, grib_arguments* a
grib_accessor_long_t::init(len, arg);

grib_handle* h = grib_handle_of_accessor(this);
const int numArgs = arg->get_count();
if (numArgs != 4) {
grib_context_log(context_, GRIB_LOG_FATAL, "Accessor %s (key %s): %d arguments provided but expected 4",
class_name_, name_, numArgs);

if (context_->debug) {
const int numArgs = arg->get_count();
if (numArgs != 4) {
grib_context_log(context_, GRIB_LOG_FATAL, "Accessor %s (key %s): %d arguments provided but expected 4",
class_name_, name_, numArgs);
}
}

tablesVersion_ = arg->get_name(h, 0);
Expand Down
9,787 changes: 4,948 additions & 4,839 deletions src/grib_hash_keys.cc

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ list(APPEND test_c_bins
grib_ecc-1431
grib_ecc-1433
grib_ecc-1764
grib_ecc-2019
bufr_ecc-517
bufr_ecc-1288
bufr_ecc-2011
Expand Down
4 changes: 4 additions & 0 deletions tests/grib_ecc-136.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ set -e
${tools_dir}/grib_set -s typeOfFirstFixedSurface=1 $sample2 $temp1
${tools_dir}/grib_set -s typeOfFirstFixedSurface=103 $sample2 $temp2

# Native type of typeOfFirstFixedSurface is string
grib_check_key_equals $temp1 'typeOfFirstFixedSurface,typeOfFirstFixedSurface:s' 'sfc sfc'
grib_check_key_equals $temp2 'typeOfFirstFixedSurface,typeOfFirstFixedSurface:s' 'sfc sfc'

# This should fail
set +e
${tools_dir}/grib_compare $temp1 $temp2
Expand Down
59 changes: 59 additions & 0 deletions tests/grib_ecc-2019.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* (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.
*/

#undef NDEBUG
#include <assert.h>
#include "eccodes.h"

#define MAX_VAL_LEN 1024

static void check_for_levelist(codes_handle* h, bool should_exist)
{
codes_keys_iterator* kiter = codes_keys_iterator_new(h, 0, "mars");
bool mars_levelist_found = false;
char value[MAX_VAL_LEN];

while (codes_keys_iterator_next(kiter)) {
const char* name = codes_keys_iterator_get_name(kiter);
size_t vlen = MAX_VAL_LEN;
memset(value, 0, vlen);
CODES_CHECK(codes_get_string(h, name, value, &vlen), name);
// printf(" name=%s val=%s\n", name, value);
if (strcmp(name, "levelist")) {
mars_levelist_found = true;
assert( strcmp(value, "42") );
}
}
assert( mars_levelist_found == should_exist );
codes_keys_iterator_delete(kiter);
}

int main(int argc, char* argv[])
{
codes_handle* h = grib_handle_new_from_samples(0, "GRIB2");
size_t alen = 1000;
CODES_CHECK(codes_set_string(h, "typeOfLevel", "isobaricInhPa", &alen), 0);
CODES_CHECK(codes_set_long(h, "level", 42), 0);
//codes_dump_content(h, stdout, "wmo", GRIB_DUMP_FLAG_CODED | GRIB_DUMP_FLAG_OCTET | GRIB_DUMP_FLAG_VALUES | GRIB_DUMP_FLAG_READ_ONLY, 0);
check_for_levelist(h, true);

// TODO(maee): This is related to
// ECC-1898: GRIB: Key 'levelist' persists despite being taken out of the mars namespace
// Once the bug is fixed we should remove the comments
// alen = 1000;
// CODES_CHECK(codes_set_string(h, "typeOfLevel", "surface", &alen), 0);
// CODES_CHECK(codes_set_missing(h, "scaleFactorOfFirstFixedSurface"), 0);
// CODES_CHECK(codes_set_missing(h, "scaledValueOfFirstFixedSurface"), 0);
// check_for_levelist(h, false);

codes_handle_delete(h);

return 0;
}
2 changes: 2 additions & 0 deletions tests/grib_ecc-2019.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ grib_check_key_equals $tempGrib mars.levelist "42"
${tools_dir}/grib_set -s typeOfLevel=isobaricInhPa,levelist=900 $sample_grib2 $tempGrib
grib_check_key_equals $tempGrib mars.levelist "900"

# Check keys iterator too
$EXEC $test_dir/grib_ecc-2019

# Clean up
rm -f $tempGrib $tempFilt $tempLog $tempOut $tempRef $tempGribA $tempGribB
11 changes: 11 additions & 0 deletions tests/grib_levtype.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@ fi

sample2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
tempGrib=temp.${label}.grib
tempText=temp.${label}.txt
latestAvailable=`${tools_dir}/grib_get -p tablesVersionLatest $sample2`
latestOfficial=`${tools_dir}/grib_get -p tablesVersionLatestOfficial $sample2`

# ECC-1333: levtype should be read-only in GRIB2
set +e
${tools_dir}/grib_set -s mars.levtype=o2d $sample2 $tempGrib 2>$tempText
status=$?
set -e
[ $status -ne 0 ]
grep -q "Value is read only" $tempText


# These level types are S2S ocean parameters and are dealt with differently (See products_s2s.def)
exclude="20 160 169"

Expand Down Expand Up @@ -60,3 +70,4 @@ done


rm -f $tempGrib
rm -f $tempText
Loading

0 comments on commit ae284ab

Please sign in to comment.