Skip to content

Commit

Permalink
Merge pull request #29 from MetOffice/feature/hofx_io_compare
Browse files Browse the repository at this point in the history
Minor modifications to Monio::readState for HofX
  • Loading branch information
phlndrwd authored Jan 5, 2024
2 parents 083e3c1 + d65ea1f commit e406a1b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/monio/Monio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
19 changes: 18 additions & 1 deletion src/monio/Utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
******************************************************************************/
#include "Utils.h"

#include <stdio.h>

#include <algorithm>
#include <array>
#include <fstream>
#include <memory>

Expand Down Expand Up @@ -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<char, 128> buffer;
std::string result;
std::string extCmd = "sh -c '" + cmd + "' 2>&1";
std::unique_ptr<FILE, decltype(&pclose)> 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) {
Expand Down
2 changes: 2 additions & 0 deletions src/monio/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace utils {
bool strToBool(std::string input);
bool fileExists(std::string path);

std::string exec(const std::string& cmd);

template<typename T1, typename T2>
std::vector<T1> extractKeys(std::map<T1, T2> const& inputMap);

Expand Down

0 comments on commit e406a1b

Please sign in to comment.