ECC-1875: GRIB2: Unwanted PDT change if setting localDefinitionNumber

This commit is contained in:
shahramn 2024-07-17 15:28:11 +01:00
parent 4f78b500f7
commit 5b2e13fd82
4 changed files with 23 additions and 5 deletions

View File

@ -100,7 +100,6 @@ static int extra_set(grib_accessor* a, long val)
long is_chemical_srcsink = 0;
long is_aerosol = 0;
long is_aerosol_optical = 0;
long is_wave = 0, is_wave_prange = 0;
grib_get_long(hand, "is_chemical", &is_chemical);
grib_get_long(hand, "is_chemical_srcsink", &is_chemical_srcsink);
@ -108,8 +107,8 @@ static int extra_set(grib_accessor* a, long val)
grib_get_long(hand, "is_aerosol", &is_aerosol);
grib_get_long(hand, "is_aerosol_optical", &is_aerosol_optical);
is_wave = grib_is_defined(hand, "waveDirectionNumber");
is_wave_prange = grib_is_defined(hand, "typeOfWavePeriodInterval");
const int is_wave = grib_is_defined(hand, "waveDirectionNumber");
const int is_wave_prange = grib_is_defined(hand, "typeOfWavePeriodInterval");
switch (self->index) {
case 0:

View File

@ -96,6 +96,9 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo
// if (grib2_is_PDTN_EPS(productDefinitionTemplateNumber))
// eps = 1;
// Is this a plain vanilla product?
const int is_plain = grib2_is_PDTN_Plain(productDefinitionTemplateNumber);
switch (localDefinitionNumber) {
case 0:
productDefinitionTemplateNumberNew = productDefinitionTemplateNumber;
@ -216,6 +219,11 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo
break;
}
if (!is_plain) {
// ECC-1875
productDefinitionTemplateNumberNew = -1; // disable PDT selection
}
// Adjust for atmospheric chemical constituents
if (chemical == 1) {
if (eps == 1) {
@ -309,9 +317,9 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo
}
}
if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) {
if (productDefinitionTemplateNumberNew >=0 && productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) {
if (a->context->debug) {
fprintf(stderr, "ECCODES DEBUG grib_accessor_local_definition_t: ldNumber=%d, newPDTN=%ld\n",
fprintf(stderr, "ECCODES DEBUG %s %s: ldNumber=%d, newPDTN=%ld\n", a->cclass->name, __func__,
localDefinitionNumber, productDefinitionTemplateNumberNew);
}
if (tooEarly)

View File

@ -861,6 +861,7 @@ grib_string_list* grib_util_get_param_id(const char* mars_param);
grib_string_list* grib_util_get_mars_param(const char* param_id);
grib_handle* grib_util_set_spec(grib_handle* h, const grib_util_grid_spec* spec, const grib_util_packing_spec* packing_spec, int flags, const double* data_values, size_t data_values_count, int* err);
int parse_keyval_string(const char* grib_tool, char* arg, int values_required, int default_type, grib_values values[], int* count);
int grib2_is_PDTN_Plain(long productDefinitionTemplateNumber);
int grib2_is_PDTN_EPS(long productDefinitionTemplateNumber);
int grib2_is_PDTN_Chemical(long productDefinitionTemplateNumber);
int grib2_is_PDTN_ChemicalSourceSink(long productDefinitionTemplateNumber);

View File

@ -1882,6 +1882,16 @@ int grib2_is_PDTN_EPS(long pdtn)
return 0;
}
// Return 1 if the productDefinitionTemplateNumber (GRIB2) is for plain (vanilla) products
int grib2_is_PDTN_Plain(long pdtn)
{
return (
pdtn == 0 ||
pdtn == 1 ||
pdtn == 8 ||
pdtn == 11);
}
// Return 1 if the productDefinitionTemplateNumber (GRIB2) is for atmospheric chemical constituents
int grib2_is_PDTN_Chemical(long pdtn)
{