diff --git a/src/monio/Monio.cc b/src/monio/Monio.cc index 85dd8dc..28d8567 100644 --- a/src/monio/Monio.cc +++ b/src/monio/Monio.cc @@ -61,7 +61,6 @@ void monio::Monio::readState(atlas::FieldSet& localFieldSet, if (mpiCommunicator_.rank() == mpiRankOwner_) { auto& functionSpace = globalField.functionspace(); auto& grid = atlas::functionspace::NodeColumns(functionSpace).mesh().grid(); - // Initialise file int variableConvention = initialiseFile(grid.name(), filePath, true); // getFileData returns a copy of FileData (with required LFRic mesh data), so read data @@ -72,13 +71,18 @@ void monio::Monio::readState(atlas::FieldSet& localFieldSet, if (variableConvention == consts::eJediConvention) { readName = fieldMetadata.jediName; } - oops::Log::debug() << "Monio::readState() processing data for> \"" << - readName << "\"..." << std::endl; - // Read fields into memory - reader_.readDatumAtTime(fileData, readName, dateTime, - std::string(consts::kTimeDimName)); - atlasReader_.populateFieldWithFileData(globalField, fileData, fieldMetadata, readName, - variableConvention == consts::eLfricConvention); + if (utils::findInVector(consts::kMissingVariableNames, readName) == false) { + oops::Log::debug() << "Monio::readState() processing data for> \"" << + readName << "\"..." << std::endl; + // Read fields into memory + reader_.readDatumAtTime(fileData, readName, dateTime, + std::string(consts::kTimeDimName)); + atlasReader_.populateFieldWithFileData(globalField, fileData, fieldMetadata, readName, + variableConvention == consts::eLfricConvention); + } else { + oops::Log::info() << "Monio::readState()> Variable \"" + fieldMetadata.jediName + + "\" not defined in LFRic. Skipping read..." << std::endl; + } } auto& functionSpace = globalField.functionspace(); functionSpace.scatter(globalField, localField); diff --git a/src/monio/Utils.cc b/src/monio/Utils.cc index 78dc8b3..193f04f 100644 --- a/src/monio/Utils.cc +++ b/src/monio/Utils.cc @@ -8,7 +8,10 @@ ******************************************************************************/ #include "Utils.h" +#include + #include +#include #include #include @@ -54,8 +57,22 @@ bool strToBool(std::string input) { (cleanStr.size() == 5 && cleanStr == "false")) { return false; } else { - throw std::invalid_argument("ERROR> Input value of \"" + input + "\" is not valid."); + throw std::invalid_argument("utils::strToBool> Input value of \"" + input + "\" is not valid."); + } +} + +std::string exec(const std::string& cmd) { + std::array buffer; + std::string result; + std::string extCmd = "sh -c '" + cmd + "' 2>&1"; + std::unique_ptr pipe(popen(extCmd.c_str(), "r"), pclose); + if (!pipe) { + throw std::runtime_error("popen() failed!"); + } + while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { + result += buffer.data(); } + return result; } bool fileExists(std::string path) { diff --git a/src/monio/Utils.h b/src/monio/Utils.h index bcf11fc..b1fcd1e 100644 --- a/src/monio/Utils.h +++ b/src/monio/Utils.h @@ -27,6 +27,8 @@ namespace utils { bool strToBool(std::string input); bool fileExists(std::string path); + std::string exec(const std::string& cmd); + template std::vector extractKeys(std::map const& inputMap);