Skip to content

Commit

Permalink
Merge pull request #20 from MetOffice/feature/state_read
Browse files Browse the repository at this point in the history
Feature/state read
  • Loading branch information
phlndrwd authored Oct 3, 2023
2 parents 4dd6bdd + c967682 commit 94a4526
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
6 changes: 5 additions & 1 deletion src/monio/AtlasWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,11 @@ atlas::Field monio::AtlasWriter::getWriteField(atlas::Field& field,
oops::Log::debug() << "AtlasWriter::getWriteField()" << std::endl;
atlas::FunctionSpace functionSpace = field.functionspace();
atlas::array::DataType atlasType = field.datatype();

if (atlasType != atlasType.KIND_REAL64 &&
atlasType != atlasType.KIND_REAL32 &&
atlasType != atlasType.KIND_INT32) {
utils::throwException("AtlasWriter::getWriteField())> Data type not coded for...");
}
// Erroneous case. For noFirstLevel == true field should have 70 levels
if (noFirstLevel == true && field.levels() == consts::kVerticalFullSize) {
utils::throwException("AtlasWriter::getWriteField()> Field levels misconfiguration...");
Expand Down
42 changes: 18 additions & 24 deletions src/monio/Monio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,25 @@ void monio::Monio::readState(atlas::FieldSet& localFieldSet,
auto& localField = localFieldSet[fieldMetadata.jediName];
atlas::Field globalField = utilsatlas::getGlobalField(localField);
if (mpiCommunicator_.rank() == mpiRankOwner_) {
oops::Log::debug() << "Monio::readState() processing data for> \"" <<
fieldMetadata.jediName << "\"..." << std::endl;
auto& functionSpace = globalField.functionspace();
auto& grid = atlas::functionspace::NodeColumns(functionSpace).mesh().grid();

// Initialise file
int namingConvention = consts::eNotDefined;
if (fileDataExists(grid.name()) == false) {
namingConvention = initialiseFile(grid.name(), filePath, dateTime);
}
int namingConvention = initialiseFile(grid.name(), filePath, dateTime);
// getFileData returns a copy of FileData (with required LFRic mesh data), so read data
// is discarded when FileData goes out-of-scope for reading subsequent fields.
FileData fileData = getFileData(grid.name());
// Configure read name
std::string readName = fieldMetadata.lfricReadName;
if (namingConvention == consts::eJediNaming) {
readName = fieldMetadata.jediName;
}
oops::Log::debug() << "Monio::readState() processing data for> \"" <<
readName << "\"..." << std::endl;
// Read fields into memory
reader_.readDatumAtTime(fileData,
fieldMetadata.lfricReadName,
dateTime,
reader_.readDatumAtTime(fileData, readName, dateTime,
std::string(consts::kTimeDimName));
atlasReader_.populateFieldWithFileData(globalField, fileData, fieldMetadata,
fieldMetadata.lfricReadName);
atlasReader_.populateFieldWithFileData(globalField, fileData, fieldMetadata, readName);
}
auto& functionSpace = globalField.functionspace();
functionSpace.scatter(globalField, localField);
Expand Down Expand Up @@ -146,8 +148,6 @@ void monio::Monio::readIncrements(atlas::FieldSet& localFieldSet,
auto& localField = localFieldSet[fieldMetadata.jediName];
atlas::Field globalField = utilsatlas::getGlobalField(localField);
if (mpiCommunicator_.rank() == mpiRankOwner_) {
oops::Log::debug() << "Monio::readIncrements() processing data for> \"" <<
fieldMetadata.jediName << "\"..." << std::endl;
auto& functionSpace = globalField.functionspace();
auto& grid = atlas::functionspace::NodeColumns(functionSpace).mesh().grid();

Expand All @@ -157,18 +157,12 @@ void monio::Monio::readIncrements(atlas::FieldSet& localFieldSet,
// is discarded when FileData goes out-of-scope for reading subsequent fields.
FileData fileData = getFileData(grid.name());
// Configure read name
std::string readName;
switch (namingConvention) {
case consts::eLfricNaming:
readName = fieldMetadata.lfricReadName;
break;
case consts::eJediNaming:
readName = fieldMetadata.jediName;
break;
default:
utils::throwException("Monio::readIncrements()> "
"File naming convention not defined...");
std::string readName = fieldMetadata.lfricReadName;
if (namingConvention == consts::eJediNaming) {
readName = fieldMetadata.jediName;
}
oops::Log::debug() << "Monio::readIncrements() processing data for> \"" <<
readName << "\"..." << std::endl;
// Read fields into memory
reader_.readFullDatum(fileData, readName);
atlasReader_.populateFieldWithFileData(globalField, fileData, fieldMetadata, readName);
Expand Down

0 comments on commit 94a4526

Please sign in to comment.