1212
1313#include " GribEncoder.h"
1414
15+ #include " atlas/grid/SpecRegistry.h"
1516#include " atlas/grid/Grid.h"
1617#include " atlas/grid/Iterator.h"
1718#include " atlas/library.h"
@@ -79,6 +80,10 @@ AtlasInstance& AtlasInstance::instance() {
7980GridDownloader::GridDownloader (const config::ComponentConfiguration& compConf) :
8081 encoder_ (createEncoder(compConf)), templateMetadata_(), gridCoordinatesCache_(), gridUIDCache_() {
8182
83+ ScopedAtlasInstance scopedAtlasInstance;
84+
85+ populateUIDCache (compConf);
86+
8287 if (encoder_ != nullptr ) {
8388 initTemplateMetadata ();
8489
@@ -109,6 +114,23 @@ std::optional<GridCoordinates> GridDownloader::getGridCoords(const GridDownloade
109114 return GridCoordinates{encodedLat, encodedLon};
110115}
111116
117+ void GridDownloader::populateUIDCache (const config::ComponentConfiguration& compConf) {
118+ if (compConf.parsedConfig ().has (" unstructured-grid-type" )) {
119+ atlas::mpi::Scope mpi_scope (" self" );
120+
121+ const auto baseGridName = compConf.parsedConfig ().getString (" unstructured-grid-type" );
122+ for (auto const & unstructuredGridSubtype : {" T" , " U" , " V" , " W" , " F" }) {
123+ const auto completeGridName = baseGridName + " _" + unstructuredGridSubtype;
124+
125+ const auto gridSpec = atlas::grid::SpecRegistry::get (completeGridName);
126+ const auto gridUID = gridSpec.getString (" uid" );
127+
128+ gridUIDCache_.emplace (std::piecewise_construct, std::tuple (std::string (unstructuredGridSubtype) + " grid" ),
129+ std::tuple (gridUID));
130+ }
131+ }
132+ }
133+
112134void GridDownloader::initTemplateMetadata () {
113135 templateMetadata_.set (" step" , 0 );
114136 templateMetadata_.set (" typeOfLevel" , " oceanSurface" );
@@ -133,8 +155,6 @@ multio::message::Metadata GridDownloader::createMetadataFromCoordsData(size_t gr
133155}
134156
135157void GridDownloader::downloadOrcaGridCoordinates (const config::ComponentConfiguration& compConf) {
136- ScopedAtlasInstance scopedAtlasInstance;
137-
138158 const auto baseGridName = compConf.parsedConfig ().getString (" unstructured-grid-type" );
139159 for (auto const & unstructuredGridSubtype : {" T" , " U" , " V" , " W" , " F" }) {
140160 const auto completeGridName = baseGridName + " _" + unstructuredGridSubtype;
@@ -147,9 +167,6 @@ void GridDownloader::downloadOrcaGridCoordinates(const config::ComponentConfigur
147167
148168 const auto gridUID = grid.uid ();
149169
150- gridUIDCache_.emplace (std::piecewise_construct, std::tuple (std::string (unstructuredGridSubtype) + " grid" ),
151- std::tuple (gridUID));
152-
153170 if (encoder_ != nullptr ) {
154171 const auto gridSize = grid.size ();
155172
0 commit comments