-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/eckit geo #275
Merged
Merged
Feature/eckit geo #275
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d5f6316
eckit::geo iterator
pmaciel 76418fb
eckit::geo iterator force-init main without tools
pmaciel 5c76091
eckit::geo - improve detection of eckit
iainrussell f5ea8b6
eckit::geo - fixed detection of eckit
pmaciel 6cc614d
eckit::geo - fixed detection of eckit
iainrussell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* (C) Copyright 2024- ECMWF. | ||
* | ||
* This software is licensed under the terms of the Apache Licence Version 2.0 | ||
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by | ||
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. | ||
*/ | ||
|
||
|
||
#include "eccodes/geo/GeoIterator.h" | ||
|
||
#include "eckit/exception/Exceptions.h" | ||
|
||
#include "eccodes/geo/GribSpec.h" | ||
|
||
|
||
namespace eccodes::geo | ||
{ | ||
|
||
|
||
GeoIterator::GeoIterator(grib_handle* h, unsigned long flags) : | ||
spec_(new GribSpec(h)), grid_(eckit::geo::GridFactory::build(*spec_)), iter_(grid_->cbegin().release()), end_(grid_->cend().release()) | ||
{ | ||
h_ = h; | ||
class_name_ = "geo_iterator"; | ||
flags_ = flags; | ||
Assert(h_ != nullptr); | ||
|
||
CODES_CHECK(codes_get_size(h_, "values", &nv_), ""); | ||
Assert(nv_ > 0); | ||
|
||
data_ = (flags_ & GRIB_GEOITERATOR_NO_VALUES) ? nullptr : static_cast<double*>(grib_context_malloc(h_->context, nv_ * sizeof(double))); | ||
Assert(data_ != nullptr); | ||
|
||
auto size = nv_; | ||
CODES_CHECK(codes_get_double_array(h_, "values", data_, &size), ""); | ||
Assert(nv_ == size); | ||
} | ||
|
||
|
||
int GeoIterator::init(grib_handle*, grib_arguments*) | ||
{ | ||
NOTIMP; | ||
} | ||
|
||
|
||
int GeoIterator::next(double* lat, double* lon, double* val) const | ||
{ | ||
if (iter_ == end_) { | ||
return 0; // (false) | ||
} | ||
|
||
const auto p = *iter_; | ||
const auto& q = std::get<eckit::geo::PointLonLat>(p); | ||
|
||
*lat = q.lat; | ||
*lon = q.lon; | ||
if (val != nullptr && data_ != nullptr) { | ||
*val = data_[iter_->index()]; | ||
} | ||
|
||
++iter_; | ||
return 1; // (true) | ||
} | ||
|
||
|
||
int GeoIterator::previous(double*, double*, double*) const | ||
{ | ||
return GRIB_NOT_IMPLEMENTED; | ||
} | ||
|
||
|
||
int GeoIterator::reset() | ||
{ | ||
iter_.reset(grid_->cbegin().release()); | ||
return GRIB_SUCCESS; | ||
} | ||
|
||
|
||
int GeoIterator::destroy() | ||
{ | ||
if (data_ != nullptr) { | ||
grib_context_free(h_->context, data_); | ||
} | ||
return Iterator::destroy(); | ||
} | ||
|
||
|
||
bool GeoIterator::has_next() const | ||
{ | ||
return iter_ != end_; | ||
} | ||
|
||
|
||
geo_iterator::Iterator* | ||
GeoIterator::create() const | ||
{ | ||
return new GeoIterator{ h_, flags_ }; | ||
} | ||
|
||
|
||
} // namespace eccodes::geo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* (C) Copyright 2024- ECMWF. | ||
* | ||
* This software is licensed under the terms of the Apache Licence Version 2.0 | ||
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by | ||
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. | ||
*/ | ||
|
||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "eckit/geo/Grid.h" | ||
|
||
// eccodes macros conflict with eckit | ||
#ifdef Assert | ||
#undef Assert | ||
#endif | ||
|
||
#include "geo_iterator/grib_iterator.h" | ||
|
||
|
||
namespace eccodes::geo | ||
{ | ||
|
||
|
||
class GeoIterator : public geo_iterator::Iterator | ||
{ | ||
public: | ||
explicit GeoIterator(grib_handle*, unsigned long flags); | ||
|
||
private: | ||
std::unique_ptr<const eckit::geo::Spec> spec_; | ||
std::unique_ptr<const eckit::geo::Grid> grid_; | ||
mutable eckit::geo::Grid::Iterator iter_; | ||
eckit::geo::Grid::Iterator end_; | ||
|
||
int init(grib_handle*, grib_arguments*) override; | ||
int next(double* lat, double* lon, double* val) const override; | ||
int previous(double* lat, double* lon, double* val) const override; | ||
int reset() override; | ||
int destroy() override; | ||
bool has_next() const override; | ||
geo_iterator::Iterator* create() const override; | ||
}; | ||
|
||
|
||
} // namespace eccodes::geo |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a problem. It will be difficult to remove the usage of the eckit ASSERT macro from not only eckit, atlas and mir, but also metkit, pgen, mars-client, mars-client-c++ (and very likely metview Regrid). Internally, it calls global namespace "Assert" which clashes with the same symbol in eccodes.
In my opinion, libraries such as eckit should NOT export any macros, but this one does. And so does eccodes, and so there is a conflict. I believe the changin of this function in "the right way" is a very large refactoring which should be out of scope of this one.