40void ConfigOutput::configure()
42 std::string periodString = Configured::getConfiguration(keyMap.at(PERIOD_KEY), std::string(
""));
43 if (periodString.empty()) {
46 outputPeriod.parse(periodString);
48 std::string startString = Configured::getConfiguration(keyMap.at(START_KEY), std::string(
""));
49 if (startString.empty()) {
51 lastOutput.parse(defaultLastOutput);
53 lastOutput.parse(startString);
55 lastOutput -= outputPeriod;
59 std::string outputFields
60 = Configured::getConfiguration(keyMap.at(FIELDNAMES_KEY), std::string(
""));
61 if (outputFields == all || outputFields.empty()) {
62 outputAllTheFields =
true;
64 std::istringstream fieldStream;
65 fieldStream.str(outputFields);
66 for (std::string line; std::getline(fieldStream, line,
',');) {
67 fieldsForOutput.insert(line);
71 for (
const std::string& fieldName : fieldsForOutput) {
72 if (sharedExternalNames.count(fieldName)) {
73 sharedArraysForOutput.insert(
74 sharedArrayNames.at(sharedExternalNames.at(fieldName)));
75 }
else if (protectedExternalNames.count(fieldName)) {
76 protectedArraysForOutput.insert(
77 protectedArrayNames.at(protectedExternalNames.at(fieldName)));
80 "ConfigOutput: No field with the name \"" + fieldName +
"\" was found.");
88 if (currentFileName ==
"") {
89 std::stringstream startStream;
90 startStream << meta.
time();
91 currentFileName = m_filePrefix +
".nc";
95 if (outputAllTheFields) {
96 for (
const auto& entry : protectedArrayNames) {
98 = getProtectedArray().at(
static_cast<size_t>(entry.second));
100 state.data[entry.first] = *macr;
102 for (
const auto& entry : sharedArrayNames) {
105 state.data[entry.first] = *mar;
109 for (
const auto& fieldExtName : fieldsForOutput) {
110 if (protectedExternalNames.count(fieldExtName)) {
112 protectedArrayNames.at(protectedExternalNames.at(fieldExtName))));
114 state.data[fieldExtName] = *macr;
115 }
else if (sharedExternalNames.count(fieldExtName)) {
117 static_cast<size_t>(sharedArrayNames.at(sharedExternalNames.at(fieldExtName))));
119 state.data[fieldExtName] = *mar;
130 if ((everyTS && meta.
time() >= lastOutput)
131 || (std::fmod((meta.
time() - lastOutput).seconds(), outputPeriod.seconds()) == 0.)) {
132 Logged::info(
"ConfigOutput: Outputting " + std::to_string(state.data.size()) +
" fields to "
133 + currentFileName +
" at " + meta.
time().format() +
"\n");
134 StructureFactory::fileFromState(state, meta, currentFileName,
false);
135 lastOutput = meta.
time();
148ModelState ConfigOutput::getStateRecursive(
const OutputSpec& os)
const
152 { keyMap.at(PERIOD_KEY), outputPeriod.format() },
153 { keyMap.at(START_KEY), lastOutput.format() },
154 { keyMap.at(FIELDNAMES_KEY), concatenateFields(fieldsForOutput) },