ECC-1644: GRIB2: Changing the PDTN changes the scale factor and scaled value keys

This commit is contained in:
Shahram Najm 2023-07-24 18:45:26 +00:00 committed by shahramn
parent d92f2b01d5
commit e511e0b259
8 changed files with 38 additions and 24 deletions

View File

@ -1,26 +1,26 @@
# (C) Copyright 2005- ECMWF.
# Type of first fixed surface
codetable[1] typeOfFirstFixedSurface ('4.5.table',masterDir,localDir) : dump,no_copy,edition_specific,string_type;
codetable[1] typeOfFirstFixedSurface ('4.5.table',masterDir,localDir) : dump,edition_specific,string_type;
meta unitsOfFirstFixedSurface codetable_units(typeOfFirstFixedSurface) : dump;
meta nameOfFirstFixedSurface codetable_title(typeOfFirstFixedSurface) : dump;
# Scale factor of first fixed surface
signed[1] scaleFactorOfFirstFixedSurface = missing() : can_be_missing,dump,no_copy,edition_specific;
signed[1] scaleFactorOfFirstFixedSurface = missing() : can_be_missing,dump,edition_specific;
# Scaled value of first fixed surface
unsigned[4] scaledValueOfFirstFixedSurface = missing() : can_be_missing,dump,no_copy,edition_specific;
unsigned[4] scaledValueOfFirstFixedSurface = missing() : can_be_missing,dump,edition_specific;
# Type of second fixed surface
codetable[1] typeOfSecondFixedSurface ('4.5.table',masterDir,localDir) = 255 : dump,no_copy,edition_specific;
codetable[1] typeOfSecondFixedSurface ('4.5.table',masterDir,localDir) = 255 : dump,edition_specific;
meta unitsOfSecondFixedSurface codetable_units(typeOfSecondFixedSurface) : dump;
meta nameOfSecondFixedSurface codetable_title(typeOfSecondFixedSurface) : dump;
# Scale factor of second fixed surface
signed[1] scaleFactorOfSecondFixedSurface = missing() : can_be_missing,dump,no_copy,edition_specific;
signed[1] scaleFactorOfSecondFixedSurface = missing() : can_be_missing,dump,edition_specific;
# Scaled value of second fixed surface
unsigned[4] scaledValueOfSecondFixedSurface = missing() : can_be_missing,dump,no_copy,edition_specific;
unsigned[4] scaledValueOfSecondFixedSurface = missing() : can_be_missing,dump,edition_specific;
transient pressureUnits="hPa";

View File

@ -1,26 +1,26 @@
# (C) Copyright 2005- ECMWF.
# Type of first fixed surface
codetable[1] typeOfFirstFixedSurface ('4.5.table',masterDir,localDir) : dump,no_copy,edition_specific,string_type;
codetable[1] typeOfFirstFixedSurface ('4.5.table',masterDir,localDir) : dump,edition_specific,string_type;
meta unitsOfFirstFixedSurface codetable_units(typeOfFirstFixedSurface) : dump;
meta nameOfFirstFixedSurface codetable_title(typeOfFirstFixedSurface) : dump;
# Scale factor of first fixed surface
signed[1] scaleFactorOfFirstFixedSurface = missing() : can_be_missing,dump,no_copy,edition_specific;
signed[1] scaleFactorOfFirstFixedSurface = missing() : can_be_missing,dump,edition_specific;
# Scaled value of first fixed surface
unsigned[4] scaledValueOfFirstFixedSurface = missing() : can_be_missing,dump,no_copy,edition_specific;
unsigned[4] scaledValueOfFirstFixedSurface = missing() : can_be_missing,dump,edition_specific;
# Type of second fixed surface
codetable[1] typeOfSecondFixedSurface ('4.5.table',masterDir,localDir) = 255 : dump,no_copy,edition_specific;
codetable[1] typeOfSecondFixedSurface ('4.5.table',masterDir,localDir) = 255 : dump,edition_specific;
meta unitsOfSecondFixedSurface codetable_units(typeOfSecondFixedSurface) : dump;
meta nameOfSecondFixedSurface codetable_title(typeOfSecondFixedSurface) : dump;
# Scale factor of second fixed surface
signed[1] scaleFactorOfSecondFixedSurface = missing() : can_be_missing,dump,no_copy,edition_specific;
signed[1] scaleFactorOfSecondFixedSurface = missing() : can_be_missing,dump,edition_specific;
# Scaled value of second fixed surface
unsigned[4] scaledValueOfSecondFixedSurface = missing() : can_be_missing,dump,no_copy,edition_specific;
unsigned[4] scaledValueOfSecondFixedSurface = missing() : can_be_missing,dump,edition_specific;
transient pressureUnits="hPa";

View File

@ -1,15 +1,15 @@
# Vertical Coordinate Template Component 5.0 - Vertical level
# Type of first fixed surface
codetable[1] typeOfFirstFixedSurface ('5.1.table',masterDir,localDir) : dump,no_copy,edition_specific,string_type;
codetable[1] typeOfFirstFixedSurface ('5.1.table',masterDir,localDir) : dump,edition_specific,string_type;
meta unitsOfFirstFixedSurface codetable_units(typeOfFirstFixedSurface) : dump;
meta nameOfFirstFixedSurface codetable_title(typeOfFirstFixedSurface) : dump;
# Scale factor of first fixed surface
signed[1] scaleFactorOfFirstFixedSurface = missing() : can_be_missing,dump,no_copy,edition_specific;
signed[1] scaleFactorOfFirstFixedSurface = missing() : can_be_missing,dump,edition_specific;
# Scaled value of first fixed surface
unsigned[4] scaledValueOfFirstFixedSurface = missing() : can_be_missing,dump,no_copy,edition_specific;
unsigned[4] scaledValueOfFirstFixedSurface = missing() : can_be_missing,dump,edition_specific;
####
transient pressureUnits="hPa";

View File

@ -1,26 +1,26 @@
# Vertical Coordinate Template Component 5.1 - Vertical layer
# Type of first fixed surface
codetable[1] typeOfFirstFixedSurface ('5.1.table',masterDir,localDir) : dump,no_copy,edition_specific,string_type;
codetable[1] typeOfFirstFixedSurface ('5.1.table',masterDir,localDir) : dump,edition_specific,string_type;
meta unitsOfFirstFixedSurface codetable_units(typeOfFirstFixedSurface) : dump;
meta nameOfFirstFixedSurface codetable_title(typeOfFirstFixedSurface) : dump;
# Scale factor of first fixed surface
signed[1] scaleFactorOfFirstFixedSurface = missing() : can_be_missing,dump,no_copy,edition_specific;
signed[1] scaleFactorOfFirstFixedSurface = missing() : can_be_missing,dump,edition_specific;
# Scaled value of first fixed surface
unsigned[4] scaledValueOfFirstFixedSurface = missing() : can_be_missing,dump,no_copy,edition_specific;
unsigned[4] scaledValueOfFirstFixedSurface = missing() : can_be_missing,dump,edition_specific;
# Type of second fixed surface
codetable[1] typeOfSecondFixedSurface ('5.1.table',masterDir,localDir) = 255 : dump,no_copy,edition_specific;
codetable[1] typeOfSecondFixedSurface ('5.1.table',masterDir,localDir) = 255 : dump,edition_specific;
meta unitsOfSecondFixedSurface codetable_units(typeOfSecondFixedSurface) : dump;
meta nameOfSecondFixedSurface codetable_title(typeOfSecondFixedSurface) : dump;
# Scale factor of second fixed surface
signed[1] scaleFactorOfSecondFixedSurface = missing() : can_be_missing,dump,no_copy,edition_specific;
signed[1] scaleFactorOfSecondFixedSurface = missing() : can_be_missing,dump,edition_specific;
# Scaled value of second fixed surface
unsigned[4] scaledValueOfSecondFixedSurface = missing() : can_be_missing,dump,no_copy,edition_specific;
unsigned[4] scaledValueOfSecondFixedSurface = missing() : can_be_missing,dump,edition_specific;
#######

View File

@ -121,6 +121,8 @@ static void init(grib_accessor* a, const long l, grib_arguments* c)
self->scale_first = grib_arguments_get_name(hand, c, n++);
self->value_first = grib_arguments_get_name(hand, c, n++);
self->pressure_units = grib_arguments_get_name(hand, c, n++);
a->flags |= GRIB_ACCESSOR_FLAG_COPY_IF_CHANGING_EDITION;
}
static void dump(grib_accessor* a, grib_dumper* dumper)

View File

@ -574,6 +574,7 @@ struct grib_accessor
#define GRIB_ACCESSOR_FLAG_DOUBLE_TYPE (1 << 16)
#define GRIB_ACCESSOR_FLAG_LOWERCASE (1 << 17)
#define GRIB_ACCESSOR_FLAG_BUFR_COORD (1 << 18)
#define GRIB_ACCESSOR_FLAG_COPY_IF_CHANGING_EDITION (1 << 19)
/**
* a section accessor

View File

@ -156,9 +156,12 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_
pack_missing = 1;
}
long ga_type = grib_accessor_get_native_type(ga);
if (STR_EQUAL(name,"level")) { // See ECC-1560
ga_type = GRIB_TYPE_DOUBLE;
const long ga_type = grib_accessor_get_native_type(ga);
if ((ga->flags & GRIB_ACCESSOR_FLAG_COPY_IF_CHANGING_EDITION) && !loader->changing_edition) {
// See ECC-1560 and ECC-1644
grib_context_log(h->context, GRIB_LOG_DEBUG, "Skipping %s (only copied if changing edition)", ga->name);
return GRIB_SUCCESS;
}
switch (ga_type) {

View File

@ -11,11 +11,19 @@
. ./include.ctest.sh
label="grib_ecc-1560_test"
temp_PDTN00_Grib=temp.$label.PDTN00.grib
temp_PDTN08_Grib=temp.$label.PDTN08.grib
temp_PDTN11_Grib=temp.$label.PDTN11.grib
tempGrib=temp.$label.grib
sample_grib2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
# scale factor/value set to 0 vs. MISSING
${tools_dir}/grib_set -s scaleFactorOfFirstFixedSurface=0,scaledValueOfFirstFixedSurface=0 \
$sample_grib2 $temp_PDTN00_Grib
${tools_dir}/grib_set -s productDefinitionTemplateNumber=11 $temp_PDTN00_Grib $temp_PDTN11_Grib
${tools_dir}/grib_compare -b totalLength,section4Length,productDefinitionTemplateNumber $temp_PDTN00_Grib $temp_PDTN11_Grib
# We set PDTN=8 and level to 1.5 metres above ground
${tools_dir}/grib_set -s \
productDefinitionTemplateNumber=8,typeOfFirstFixedSurface=103,scaledValueOfFirstFixedSurface=15,scaleFactorOfFirstFixedSurface=1 \