Skip to content

Commit 913397d

Browse files
committed
Address TODOs; consistent checks before reading and writing
1 parent 1032cdc commit 913397d

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

core/src/ParaGridIO_Xios.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@ ModelState ParaGridIO::getModelState(const std::string& filePath, ModelMetadata&
5555
state.merge(ModelState { { { fieldId, field } }, {} });
5656
}
5757
// Assume that all fields in the supplied ModelState are necessary, and so read them from file.
58+
std::set<std::string> restartFieldIds = xiosHandler.configGetInputRestartFieldNames();
5859
for (auto& entry : state.data) {
5960
const std::string fieldId = entry.first;
6061
if (!xiosHandler.getFieldReadAccess(fieldId)) {
6162
throw std::runtime_error("ParaGridIO::getModelState: field " + fieldId
6263
+ " is not configured for reading, but is being read from file.");
6364
};
65+
if (restartFieldIds.count(fieldId) == 0) {
66+
throw std::runtime_error(
67+
"ParaGridIO::getModelState: field " + fieldId + " is not configured as a restart.");
68+
}
6469
xiosHandler.read(fieldId, entry.second);
6570
}
6671
return state;
@@ -86,10 +91,14 @@ ModelState ParaGridIO::readForcingTimeStatic(
8691
const bool readAccess = true;
8792
std::set<std::string> forcingFieldIds = xiosHandler.configGetForcingFieldNames();
8893
for (const std::string& fieldId : forcings) {
89-
if (forcingFieldIds.count(fieldId) == 0 || !xiosHandler.getFieldReadAccess(fieldId)) {
94+
if (!xiosHandler.getFieldReadAccess(fieldId)) {
9095
throw std::runtime_error("ParaGridIO::readForcingTimeStatic: forcing " + fieldId
9196
+ " is not configured for reading, but is being read from file.");
9297
}
98+
if (forcingFieldIds.count(fieldId) == 0) {
99+
throw std::runtime_error("ParaGridIO::readForcingTimeStatic: field " + fieldId
100+
+ " is not configured as a forcing.");
101+
}
93102
// ASSUME all forcings are HFields: finite volume fields on the same
94103
// grid as ice thickness
95104
HField field(ModelArray::Type::H);
@@ -112,15 +121,18 @@ void ParaGridIO::dumpModelState(
112121
{
113122
Xios& xiosHandler = Xios::getInstance();
114123

115-
// Assume that all fields in the supplied ModelState are necessary, and so write them to
116-
// file.
117-
// TODO: Check they are indeed restarts
124+
// Assume that all fields in the supplied ModelState are necessary, and so write them to file.
125+
std::set<std::string> restartFieldIds = xiosHandler.configGetOutputRestartFieldNames();
118126
for (auto entry : state.data) {
119127
const std::string fieldId = entry.first;
120128
if (xiosHandler.getFieldReadAccess(fieldId)) {
121129
throw std::runtime_error("ParaGridIO::dumpModelState: field " + fieldId
122130
+ " is not configured for writing, but is being written to file.");
123131
};
132+
if (restartFieldIds.count(fieldId) == 0) {
133+
throw std::runtime_error("ParaGridIO::dumpModelState: field " + fieldId
134+
+ " is not configured as a restart.");
135+
}
124136
xiosHandler.write(fieldId, entry.second);
125137
}
126138
}
@@ -130,19 +142,20 @@ void ParaGridIO::writeDiagnosticTime(
130142
{
131143
Xios& xiosHandler = Xios::getInstance();
132144

133-
// Assume that all fields in the supplied ModelState are necessary, and so write them to
134-
// file.
135-
// TODO: Check they are indeed diagnostics
145+
// Assume that all fields in the supplied ModelState are necessary, and so write them to file.
146+
std::set<std::string> diagnosticFieldIds = xiosHandler.configGetDiagnosticFieldNames();
136147
for (auto entry : state.data) {
137148
const std::string fieldId = entry.first;
138149
if (xiosHandler.getFieldReadAccess(fieldId)) {
139150
throw std::runtime_error("ParaGridIO::writeDiagnosticTime: field " + fieldId
140151
+ " is not configured for writing, but is being written to file.");
141152
};
153+
if (diagnosticFieldIds.count(fieldId) == 0) {
154+
throw std::runtime_error("ParaGridIO::writeDiagnosticTime: field " + fieldId
155+
+ " is not configured as a diagnostic.");
156+
}
142157
xiosHandler.write(fieldId, entry.second);
143158
}
144-
// TODO: Create a special timeless set of dimensions for the landmask - use 'once' operation
145-
// TODO: Put the time axis variable
146159
}
147160

148161
} /* namespace Nextsim */

0 commit comments

Comments
 (0)