netxsimdg
Loading...
Searching...
No Matches
SimpleOutput.cpp
Go to the documentation of this file.
1
9
10#include "include/Logged.hpp"
13
14#include <sstream>
15
16namespace Nextsim {
17
19{
20 std::stringstream startStream;
21 startStream << meta.time();
22 std::string timeFileName = m_filePrefix + "." + startStream.str() + ".nc";
23 Logged::info("Outputting "
24 + std::to_string(protectedArrayNames.size() + sharedArrayNames.size()) + " fields to "
25 + timeFileName + "\n");
26
27 // Create the output by iterating over all fields referenced in ModelState
28 ModelState state;
29 for (const auto& entry : protectedArrayNames) {
30 ModelArrayConstReference macr = getProtectedArray().at(static_cast<size_t>(entry.second));
31 if (macr) state.data[entry.first] = *macr;
32 }
33 for (const auto& entry : sharedArrayNames) {
34 ModelArrayReference mar = getSharedArray().at(static_cast<size_t>(entry.second));
35 if (mar) state.data[entry.first] = *mar;
36 }
37 StructureFactory::fileFromState(state, meta, timeFileName);
38}
39} /* namespace Nextsim */
static void info(const std::string &message)
Logs a message at level::INFO, intended for informational messages that would not normally be shown.
Definition Logged.hpp:70
A class that holds the array data for the model.
static const MARBackingStore & getSharedArray()
Returns a const reference to the store for SharedArray fields.
static const MARConstBackingStore & getProtectedArray()
Returns a const reference to the store for ProtectedArray fields.
const TimePoint & time() const
Returns the current model time.
void outputState(const ModelMetadata &meta) override
Outputs the passed ModelState.
static void fileFromState(const ModelState &state, const ModelMetadata &meta, const std::string &filePath, bool isRestart=false)
Takes a ModelState and a template file name to write the state out to a target file path.