Skip to content

Commit 522bac7

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feature/mtg2_tablesVersion_switch
2 parents 882cc3f + 006c759 commit 522bac7

3 files changed

+43
-10
lines changed

src/accessor/grib_accessor_class_g2_param_concept_filename.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ void grib_accessor_g2_param_concept_filename_t::init(const long len, grib_argume
1818
grib_accessor_gen_t::init(len, arg);
1919
grib_handle* h = grib_handle_of_accessor(this);
2020

21+
const int numArgs = arg->get_count();
22+
if (numArgs != 3) {
23+
grib_context_log(context_, GRIB_LOG_FATAL, "Accessor %s (key %s): %d arguments provided but expected 3",
24+
class_name_, name_, numArgs);
25+
}
26+
2127
basename_ = arg->get_string(h, 0);
2228
MTG2Switch_ = arg->get_name(h, 1);
2329
tablesVersionMTG2Switch_ = arg->get_name(h, 2);

src/accessor/grib_accessor_class_message_is_valid.cc

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,8 @@ int grib_accessor_message_is_valid_t::check_grid_pl_array()
6868

6969
char gridType[128] = {0,};
7070
size_t len = 128;
71-
ret = grib_get_string(handle_, "gridType", gridType, &len);
72-
if (ret == GRIB_SUCCESS && STR_EQUAL(gridType, "reduced_ll")) {
73-
// Unfortunately in our archive we have such grids with zeroes in the pl!
74-
return GRIB_SUCCESS;
75-
}
76-
71+
ret = grib_get_string_internal(handle_, "gridType", gridType, &len);
72+
if (ret != GRIB_SUCCESS) return ret;
7773

7874
if ((ret = grib_get_size(handle_, "pl", &plsize)) != GRIB_SUCCESS)
7975
return ret;
@@ -90,16 +86,42 @@ int grib_accessor_message_is_valid_t::check_grid_pl_array()
9086

9187
pl = (long*)grib_context_malloc_clear(c, sizeof(long) * plsize);
9288
if (!pl) return GRIB_OUT_OF_MEMORY;
93-
if ((ret = grib_get_long_array(handle_, "pl", pl, &plsize)) != GRIB_SUCCESS)
89+
if ((ret = grib_get_long_array_internal(handle_, "pl", pl, &plsize)) != GRIB_SUCCESS)
9490
return ret;
9591

96-
for (size_t j = 0; j < plsize; j++) {
97-
if (pl[j] == 0) {
98-
grib_context_log(c, GRIB_LOG_ERROR, "%s: Invalid PL array: entry at index=%zu is zero", TITLE, j);
92+
long numberOfDataPoints = 0;
93+
if ((ret = grib_get_long_internal(handle_, "numberOfDataPoints", &numberOfDataPoints)) != GRIB_SUCCESS)
94+
return ret;
95+
size_t sum_pl = 0;
96+
for (size_t j = 0; j < plsize; j++) sum_pl += pl[j];
97+
98+
if (STR_EQUAL(gridType, "reduced_ll")) {
99+
// For reduced_ll grids, sum(pl) must equal numberOfDataPoints in every situation
100+
if (sum_pl != (size_t)numberOfDataPoints) {
101+
grib_context_log(c, GRIB_LOG_ERROR, "%s: Sum of PL array (=%zu) must equal numberOfDataPoints (=%ld)",
102+
TITLE, sum_pl, numberOfDataPoints);
103+
grib_context_free(c, pl);
104+
return GRIB_WRONG_GRID;
105+
}
106+
}
107+
else {
108+
// Other reduced grids
109+
// Unfortunately in our archive we have reduced_ll grids with zeroes in the pl!
110+
for (size_t j = 0; j < plsize; j++) {
111+
if (pl[j] == 0) {
112+
grib_context_log(c, GRIB_LOG_ERROR, "%s: Invalid PL array: entry at index=%zu is zero", TITLE, j);
113+
grib_context_free(c, pl);
114+
return GRIB_WRONG_GRID;
115+
}
116+
}
117+
if (sum_pl < (size_t)numberOfDataPoints) {
118+
grib_context_log(c, GRIB_LOG_ERROR, "%s: Sum of PL array (=%zu) cannot be less than numberOfDataPoints (=%ld)",
119+
TITLE, sum_pl, numberOfDataPoints);
99120
grib_context_free(c, pl);
100121
return GRIB_WRONG_GRID;
101122
}
102123
}
124+
103125
grib_context_free(c, pl);
104126

105127
return GRIB_SUCCESS;

src/accessor/grib_accessor_class_mtg2_switch_default.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ void grib_accessor_mtg2_switch_default_t::init(const long len, grib_arguments* a
1818
grib_accessor_long_t::init(len, arg);
1919

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

2227
tablesVersion_ = arg->get_name(h, 0);
2328
tablesVersionMTG2Switch_ = arg->get_name(h, 1);

0 commit comments

Comments
 (0)