Skip to content

Commit

Permalink
Merge pull request #33 from MetOffice/feature/update_no_levels
Browse files Browse the repository at this point in the history
Feature/update no levels
  • Loading branch information
phlndrwd authored Jan 29, 2024
2 parents 65d6d7a + 7a503d7 commit 8236bff
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
6 changes: 2 additions & 4 deletions src/monio/AtlasReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ void monio::AtlasReader::populateField(atlas::Field& field,
oops::Log::debug() << "AtlasReader::populateField()" << std::endl;
auto fieldView = atlas::array::make_view<T, 2>(field);
// Field with noFirstLevel == true should have been adjusted to have 70 levels.
std::vector<atlas::idx_t> fieldShape = field.shape();
atlas::idx_t numLevels = fieldShape[consts::eVertical];
atlas::idx_t numLevels = field.shape(consts::eVertical);
if (noFirstLevel == true && numLevels == consts::kVerticalFullSize) {
Monio::get().closeFiles();
utils::throwException("AtlasReader::populateField()> Field levels misconfiguration...");
Expand Down Expand Up @@ -206,9 +205,8 @@ template void monio::AtlasReader::populateField<int>(atlas::Field& field,

atlas::Field monio::AtlasReader::getReadField(atlas::Field& field,
const bool noFirstLevel) {
std::vector<atlas::idx_t> fieldShape = field.shape();
// Check to ensure field has not been initialised with 71 levels
if (noFirstLevel == true && fieldShape[consts::eVertical] == consts::kVerticalFullSize) {
if (noFirstLevel == true && field.shape(consts::eVertical) == consts::kVerticalFullSize) {
atlas::array::DataType atlasType = field.datatype();
if (atlasType != atlasType.KIND_REAL64 &&
atlasType != atlasType.KIND_REAL32 &&
Expand Down
11 changes: 5 additions & 6 deletions src/monio/AtlasWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void monio::AtlasWriter::populateDataWithField(Data& data,

void monio::AtlasWriter::populateDataWithField(Data& data,
const atlas::Field& field,
const std::vector<atlas::idx_t> dimensions) {
const std::vector<atlas::idx_t>& dimensions) {
oops::Log::debug() << "AtlasWriter::populateDataWithField()" << std::endl;
std::shared_ptr<DataContainerBase> dataContainer = nullptr;
populateDataContainerWithField(dataContainer, field, dimensions);
Expand Down Expand Up @@ -271,8 +271,7 @@ void monio::AtlasWriter::populateDataVec(std::vector<T>& dataVec,
const atlas::Field& field,
const std::vector<size_t>& lfricToAtlasMap) {
oops::Log::debug() << "AtlasWriter::populateDataVec() " << field.name() << std::endl;
std::vector<atlas::idx_t> fieldShape = field.shape();
atlas::idx_t numLevels = fieldShape[consts::eVertical];
atlas::idx_t numLevels = field.shape(consts::eVertical);
if ((lfricToAtlasMap.size() * numLevels) != dataVec.size()) {
Monio::get().closeFiles();
utils::throwException("AtlasWriter::populateDataVec()> "
Expand Down Expand Up @@ -333,15 +332,15 @@ atlas::Field monio::AtlasWriter::getWriteField(atlas::Field& field,
Monio::get().closeFiles();
utils::throwException("AtlasWriter::getWriteField())> Data type not coded for...");
}
std::vector<atlas::idx_t> fieldShape = field.shape();
atlas::idx_t numLevels = field.shape(consts::eVertical);
// Erroneous case. For noFirstLevel == true field should have 70 levels
if (noFirstLevel == true && fieldShape[consts::eVertical] == consts::kVerticalFullSize) {
if (noFirstLevel == true && numLevels == consts::kVerticalFullSize) {
Monio::get().closeFiles();
utils::throwException("AtlasWriter::getWriteField()> Field levels misconfiguration...");
}
// WARNING - This name-check is an LFRic-Lite specific convention...
if (utils::findInVector(consts::kMissingVariableNames, writeName) == false) {
if (noFirstLevel == true && fieldShape[consts::eVertical] == consts::kVerticalHalfSize) {
if (noFirstLevel == true && numLevels == consts::kVerticalHalfSize) {
atlas::util::Config atlasOptions = atlas::option::name(writeName) |
atlas::option::global(0) |
atlas::option::levels(consts::kVerticalFullSize);
Expand Down
2 changes: 1 addition & 1 deletion src/monio/AtlasWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class AtlasWriter {
/// populateFileDataWithField where metadata are created.
void populateDataWithField(Data& data,
const atlas::Field& field,
const std::vector<atlas::idx_t> dimensions);
const std::vector<atlas::idx_t>& dimensions);

/// \brief Derives the container type and makes the call to populate it. Used where metadata are
/// provided and data are written in LFRic order.
Expand Down
4 changes: 2 additions & 2 deletions src/monio/UtilsAtlas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ std::vector<size_t> createLfricAtlasMap(const std::vector<atlas::PointLonLat>& a
atlas::Field getGlobalField(const atlas::Field& field) {
if (field.metadata().get<bool>("global") == false) {
atlas::array::DataType atlasType = field.datatype();
std::vector<atlas::idx_t> fieldShape = field.shape();
atlas::idx_t numLevels = field.shape(consts::eVertical);
atlas::util::Config atlasOptions = atlas::option::name(field.name()) |
atlas::option::levels(fieldShape[consts::eVertical]) |
atlas::option::levels(numLevels) |
atlas::option::datatype(atlasType) |
atlas::option::global(0);
if (atlasType != atlasType.KIND_REAL64 &&
Expand Down

0 comments on commit 8236bff

Please sign in to comment.