Skip to content

Commit 304c966

Browse files
committed
EAMxx: fix handling of diags depending on diags in IO
1 parent 07db3ac commit 304c966

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

components/eamxx/src/share/io/scorpio_output.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,6 @@ compute_diagnostics(const bool allow_invalid_fields)
927927
void AtmosphereOutput::
928928
process_requested_fields(const std::string& stream_name)
929929
{
930-
using stratts_t = std::map<std::string,std::string>;
931-
932930
// So far, all fields (on the output grid) that ARE in the model FM have been added
933931
// to the FM stored in this class for the FromModel phase. Anything missing
934932
// must be either a diagnostic or an alias.
@@ -1071,7 +1069,10 @@ process_requested_fields(const std::string& stream_name)
10711069
remaining.insert(it.second);
10721070
}
10731071
while (not done) {
1074-
std::set<std::string> remove_these;
1072+
// We can't add-to/rm-form a std:;set while iterating on it, as that could
1073+
// change the end iterator. Hence, keep track of what we add or remove,
1074+
// and add/remove after the for loop ends
1075+
std::set<std::string> remove_these, add_these;
10751076
for (const auto& name : remaining) {
10761077
if (fm_model->has_field(name)) {
10771078
// This is a regular field, not a diagnostic nor an alias.
@@ -1096,8 +1097,15 @@ process_requested_fields(const std::string& stream_name)
10961097
auto diag = name2diag[name];
10971098
bool ready_to_init = true;
10981099
for (const auto& freq : diag->get_required_field_requests()) {
1099-
if (not fm_model->has_field(freq.fid.name())) {
1100+
const auto& dep_name = freq.fid.name();
1101+
if (not fm_model->has_field(dep_name)) {
11001102
ready_to_init = false;
1103+
if (not remaining.count(dep_name)) {
1104+
// This requirement MUST be another diagnostic, since it was not in the original m_fields_names
1105+
// Create the diag, and add it to the list of fields to process
1106+
name2diag[freq.fid.name()] = create_diagnostic(freq.fid.name(),fm_model->get_grid());
1107+
add_these.insert(freq.fid.name());
1108+
}
11011109
break;
11021110
}
11031111
}
@@ -1108,13 +1116,16 @@ process_requested_fields(const std::string& stream_name)
11081116
}
11091117
}
11101118

1111-
EKAT_REQUIRE_MSG (remove_these.size()>0,
1119+
EKAT_REQUIRE_MSG (add_these.size()>0 or remove_these.size()>0,
11121120
"Error! We're stuck in an endless loop while processing output fields.\n"
11131121
" - stream name: " + stream_name + "\n");
11141122

11151123
for (const auto& n : remove_these) {
11161124
remaining.erase(n);
11171125
}
1126+
for (const auto& n : add_these) {
1127+
remaining.insert(n);
1128+
}
11181129

11191130
done = remaining.size()==0;
11201131
}

0 commit comments

Comments
 (0)