Skip to content

Commit

Permalink
griddef
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaciel committed Nov 22, 2024
1 parent 60fc361 commit beb6273
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 42 deletions.
57 changes: 19 additions & 38 deletions src/mir/input/GribInput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
#include "eckit/config/Resource.h"
#include "eckit/io/Buffer.h"
#include "eckit/io/MemoryHandle.h"
#include "eckit/io/StdFile.h"
#include "eckit/serialisation/HandleStream.h"
#include "eckit/types/FloatCompare.h"
#include "eckit/types/Fraction.h"

#include "mir/config/LibMir.h"
#include "mir/data/MIRField.h"
#include "mir/grib/Config.h"
#include "mir/input/GriddefInput.h"
#include "mir/param/DefaultParametrisation.h"
#include "mir/repres/Representation.h"
#include "mir/util/Exceptions.h"
#include "mir/util/Grib.h"
Expand Down Expand Up @@ -1141,52 +1142,32 @@ bool GribInput::handle(grib_handle* h) {
}


void GribInput::auxilaryValues(const std::string& path, std::vector<double>& values) const {
void GribInput::setAuxiliaryInformation(const util::ValueMap& map) {
util::lock_guard<util::recursive_mutex> lock(mutex_);

eckit::AutoStdFile f(path);

int e;
grib_handle* h = nullptr;

// We cannot use GribFileInput to read these files, because lat/lon files are also
// has grid_type = triangular_grid, and we will create a loop

try {
h = codes_grib_handle_new_from_file(nullptr, f, &e);
grib_call(e, path.c_str());
size_t count;
GRIB_CALL(codes_get_size(h, "values", &count));

size_t size = count;
values.resize(count);
GRIB_CALL(codes_get_double_array(h, "values", values.data(), &size));
ASSERT(count == size);
auto load = [](const eckit::PathName& path, std::vector<double>& values) {
Log::info() << "GribInput::setAuxiliaryInformation: '" << path << "'" << std::endl;

long missingValuesPresent;
GRIB_CALL(codes_get_long(h, "missingValuesPresent", &missingValuesPresent));
ASSERT(!missingValuesPresent);

codes_handle_delete(h);
}
catch (...) {
codes_handle_delete(h);
throw;
}
}
static const param::DefaultParametrisation param;
std::unique_ptr<input::MIRInput> input(input::MIRInputFactory::build(path.asString(), param));
ASSERT(input->next());

auto field = input->field();
ASSERT(field.dimensions() == 1);

void GribInput::setAuxiliaryInformation(const util::ValueMap& map) {
util::lock_guard<util::recursive_mutex> lock(mutex_);
values = field.values(0);
};

for (const auto& kv : map) {
if (kv.first == "latitudes") {
Log::debug() << "Loading auxilary file '" << kv.second << "'" << std::endl;
auxilaryValues(kv.second, latitudes_);
if (kv.first == "griddef") {
GriddefInput::load(kv.second, latitudes_, longitudes_);
ASSERT(latitudes_.size() == longitudes_.size());
}
else if (kv.first == "latitudes") {
load(kv.second, latitudes_);
}
else if (kv.first == "longitudes") {
Log::debug() << "Loading auxilary file '" << kv.second << "'" << std::endl;
auxilaryValues(kv.second, longitudes_);
load(kv.second, longitudes_);
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/mir/input/GribInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ class GribInput : public MIRInput, public param::FieldParametrisation {
std::vector<double> latitudes_;
std::vector<double> longitudes_;

// -- Methods

void auxilaryValues(const std::string&, std::vector<double>& values) const;

// -- Overridden methods

// From MIRInput
Expand Down

0 comments on commit beb6273

Please sign in to comment.