Skip to content

Commit

Permalink
Use replaceCurly for unstructured-grid-type
Browse files Browse the repository at this point in the history
  • Loading branch information
Razvan Aguridan authored and dsarmany committed Sep 12, 2024
1 parent 2f6d940 commit 6bb736e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
16 changes: 13 additions & 3 deletions src/multio/action/encode/GribEncoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "multio/LibMultio.h"
#include "multio/util/DateTime.h"
#include "multio/util/Metadata.h"

#include "multio/util/Substitution.h"

#include "multio/util/PrecisionTag.h"

Expand Down Expand Up @@ -236,6 +236,16 @@ std::optional<ValueSetter> valueSetter(GribEncoder& g, const std::string& key) {
}
}

std::string getUnstructuredGridType(const eckit::LocalConfiguration& config) {
return multio::util::replaceCurly(
config.getString("unstructured-grid-type"),
[](std::string_view replace) {
std::string lookUpKey{replace};
char* env = ::getenv(lookUpKey.c_str());
return env ? std::optional<std::string>{env} : std::optional<std::string>{};
});
}

} // namespace

GribEncoder::GribEncoder(codes_handle* handle, const eckit::LocalConfiguration& config) :
Expand Down Expand Up @@ -850,7 +860,7 @@ void GribEncoder::setOceanMetadata(message::Metadata& md) {
setValue(glossary().unstructuredGridType, searchGridType->second.template get<std::string>());
}
else {
setValue(glossary().unstructuredGridType, config_.getString("unstructured-grid-type"));
setValue(glossary().unstructuredGridType, getUnstructuredGridType(config_));
}

if (auto searchGridSubtype = md.find(glossary().unstructuredGridSubtype); searchGridSubtype != md.end()) {
Expand Down Expand Up @@ -886,7 +896,7 @@ void GribEncoder::setOceanCoordMetadata(message::Metadata& md) {
setValue(glossary().typeOfLevel, md.get<std::string>(glossary().typeOfLevel));

// Set ocean grid information
setValue(glossary().unstructuredGridType, config_.getString("unstructured-grid-type"));
setValue(glossary().unstructuredGridType, getUnstructuredGridType(config_));

const auto& gridSubtype
= md.get<std::string>("gridSubtype"); // TO BE REMOVED IN THE FUTURE - should be named unstructuredGridType
Expand Down
21 changes: 17 additions & 4 deletions src/multio/action/encode/GridDownloader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "eckit/mpi/Comm.h"

#include "multio/message/Glossary.h"

#include "multio/util/Substitution.h"

namespace {
const std::unordered_map<std::string, int> latParamIds{
Expand Down Expand Up @@ -62,6 +62,16 @@ atlas::Grid readGrid(const std::string& name) {
return atlas::Grid{name};
}

std::string getUnstructuredGridType(const multio::config::ComponentConfiguration& compConf) {
return multio::util::replaceCurly(
compConf.parsedConfig().getString("unstructured-grid-type"),
[](std::string_view replace) {
std::string lookUpKey{replace};
char* env = ::getenv(lookUpKey.c_str());
return env ? std::optional<std::string>{env} : std::optional<std::string>{};
});
}

} // namespace

namespace multio::action {
Expand Down Expand Up @@ -92,7 +102,8 @@ GridDownloader::GridDownloader(const config::ComponentConfiguration& compConf) :
initTemplateMetadata();

if (compConf.parsedConfig().has("unstructured-grid-type")) {
const auto unstructuredGridType = compConf.parsedConfig().getString("unstructured-grid-type");
const auto unstructuredGridType = getUnstructuredGridType(compConf);

if (unstructuredGridType.find("ORCA") != std::string::npos) {
eckit::Log::info() << "Grid downloader initialized, starting ORCA grid download!" << std::endl;

Expand Down Expand Up @@ -122,7 +133,8 @@ void GridDownloader::populateUIDCache(const config::ComponentConfiguration& comp
if (compConf.parsedConfig().has("unstructured-grid-type")) {
atlas::mpi::Scope mpi_scope("self");

const auto baseGridName = compConf.parsedConfig().getString("unstructured-grid-type");
const auto baseGridName = getUnstructuredGridType(compConf);

for (auto const& unstructuredGridSubtype : {"T", "U", "V", "W", "F"}) {
const auto completeGridName = baseGridName + "_" + unstructuredGridSubtype;

Expand Down Expand Up @@ -159,7 +171,8 @@ multio::message::Metadata GridDownloader::createMetadataFromCoordsData(size_t gr
}

void GridDownloader::downloadOrcaGridCoordinates(const config::ComponentConfiguration& compConf) {
const auto baseGridName = compConf.parsedConfig().getString("unstructured-grid-type");
const auto baseGridName = getUnstructuredGridType(compConf);

for (auto const& unstructuredGridSubtype : {"T", "U", "V", "W", "F"}) {
const auto completeGridName = baseGridName + "_" + unstructuredGridSubtype;

Expand Down

0 comments on commit 6bb736e

Please sign in to comment.