Skip to content

Commit

Permalink
Merge Pull Request #2902 from E3SM-Project/scream/aarondonahue/io/bug…
Browse files Browse the repository at this point in the history
…_2898

Automatically Merged using E3SM Pull Request AutoTester
PR Title: Fix bug in io with registering avg_cnt vars in Append mode.
PR Author: AaronDonahue
PR LABELS: I/O, AT: AUTOMERGE, bugfix
  • Loading branch information
E3SM-Bot authored Jul 16, 2024
2 parents e2d8d0c + b019f2e commit 94496f4
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions components/eamxx/src/share/io/scorpio_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,11 +1038,42 @@ register_variables(const std::string& filename,
}
// Now register the average count variables
if (m_track_avg_cnt) {
std::string unitless = "unitless";
for (const auto& name : m_avg_cnt_names) {
const auto layout = m_layouts.at(name);
auto vec_of_dims = set_vec_of_dims(layout);
scorpio::define_var(filename, name, "unitless", vec_of_dims,
"real",fp_precision, m_add_time_dim);
if (mode==scorpio::FileMode::Append) {
// Similar to the regular fields above, check that the var is in the file, and has the right properties
EKAT_REQUIRE_MSG (scorpio::has_var(filename,name),
"Error! Cannot append, due to variable missing from the file.\n"
" - filename : " + filename + "\n"
" - varname : " + name + "\n");
const auto& var = scorpio::get_var(filename,name);
EKAT_REQUIRE_MSG (var.dim_names()==vec_of_dims,
"Error! Cannot append, due to variable dimensions mismatch.\n"
" - filename : " + filename + "\n"
" - varname : " + name + "\n"
" - var dims : " + ekat::join(vec_of_dims,",") + "\n"
" - var dims from file: " + ekat::join(var.dim_names(),",") + "\n");
EKAT_REQUIRE_MSG (var.units==unitless,
"Error! Cannot append, due to variable units mismatch.\n"
" - filename : " + filename + "\n"
" - varname : " + name + "\n"
" - var units: " + unitless + "\n"
" - var units from file: " + var.units + "\n");
EKAT_REQUIRE_MSG (var.time_dep==m_add_time_dim,
"Error! Cannot append, due to time dependency mismatch.\n"
" - filename : " + filename + "\n"
" - varname : " + name + "\n"
" - var time dep: " + (m_add_time_dim ? "yes" : "no") + "\n"
" - var time dep from file: " + (var.time_dep ? "yes" : "no") + "\n");
} else {
// Note, unlike with regular output variables, for the average counting
// variables we don't need to add all of the extra metadata. So we simply
// define the variable.
scorpio::define_var(filename, name, unitless, vec_of_dims,
"real",fp_precision, m_add_time_dim);
}
}
}
} // register_variables
Expand Down

0 comments on commit 94496f4

Please sign in to comment.