Skip to content

Commit a5452e0

Browse files
committed
EAMxx: fix sanity check in print_field_hyperslab
Also, add test to verify the check works
1 parent 25c15f2 commit a5452e0

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

components/eamxx/src/share/field/field_utils.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,12 @@ void print_field_hyperslab (const Field& f,
323323

324324
const int num_indices = indices.size();
325325
for (int i=0; i<num_indices; ++i) {
326-
EKAT_REQUIRE_MSG ( indices[i]>=0 && indices[i]<fl.dim(i),
327-
"Error! Requested index is invalid.\n"
326+
EKAT_REQUIRE_MSG ( indices[i]>=0 && indices[i]<fl.dim(tags[i],false),
327+
"Error! Requested slice index is out of bound.\n"
328328
" - field name: " + f.name() + "\n"
329329
" - field layout: " + fl.to_string() + "\n"
330-
" - requested indices: (" + ekat::join(indices,",") + ")\n");
330+
" - hyperslab tags: (" + ekat::join(tags2str(tags),",") + ")\n"
331+
" - hyperslab indices: (" + ekat::join(indices,",") + ")\n");
331332
}
332333

333334
switch (dt) {

components/eamxx/src/share/field/tests/field_utils.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,11 @@ TEST_CASE ("print_field_hyperslab") {
773773
}
774774

775775
REQUIRE (out.str()==expected.str());
776+
777+
loc_idxs[0] = nel;
778+
REQUIRE_THROWS(print_field_hyperslab(f,loc_tags,loc_idxs,out));
779+
loc_idxs[0] = -1;
780+
REQUIRE_THROWS(print_field_hyperslab(f,loc_tags,loc_idxs,out));
776781
}
777782
SECTION ("slice_0234") {
778783
std::vector<FieldTag> loc_tags = {EL,GP,GP,LEV};

0 commit comments

Comments
 (0)