From 79d5aff9d3d050e47cd7a426ef116717b3c7df6b Mon Sep 17 00:00:00 2001 From: Emanuele Danovaro Date: Thu, 12 Oct 2023 00:15:44 +0100 Subject: [PATCH 1/6] added HyperCube::requests() to print out request(s) corresponding to selected fields --- VERSION | 2 +- src/metkit/hypercube/HyperCube.cc | 6 +++--- src/metkit/hypercube/HyperCube.h | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index eb2ca0f1..ccb12466 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.10.15 +1.10.16 diff --git a/src/metkit/hypercube/HyperCube.cc b/src/metkit/hypercube/HyperCube.cc index 6c538f18..7c7ee5ef 100644 --- a/src/metkit/hypercube/HyperCube.cc +++ b/src/metkit/hypercube/HyperCube.cc @@ -256,14 +256,14 @@ std::vector> HyperCube::request(std return requests; } -std::vector HyperCube::vacantRequests() const { +std::vector HyperCube::aggregatedRequests(bool remaining) const { - if (countVacant() == 0) + if (countVacant() == (remaining ? 0 : size())) return std::vector{}; std::set idxs; for(size_t i = 0; i < set_.size(); ++i) { - if (set_[i]) + if (set_[i] == remaining) idxs.emplace(i); } diff --git a/src/metkit/hypercube/HyperCube.h b/src/metkit/hypercube/HyperCube.h index 818d99ff..32134987 100644 --- a/src/metkit/hypercube/HyperCube.h +++ b/src/metkit/hypercube/HyperCube.h @@ -44,9 +44,11 @@ class HyperCube { size_t size() const {return cube_.count(); } size_t fieldOrdinal(const metkit::mars::MarsRequest&, bool noholes = true) const; - std::vector vacantRequests() const; + std::vector vacantRequests() const { return aggregatedRequests(true); } + std::vector requests() const { return aggregatedRequests(false); } protected: + std::vector aggregatedRequests(bool remaining) const; int indexOf(const metkit::mars::MarsRequest&) const; bool clear(int index); metkit::mars::MarsRequest requestOf(size_t index) const; From 8a7948d3528fb75e39eed0cfa004d0442ff599f2 Mon Sep 17 00:00:00 2001 From: Emanuele Danovaro Date: Thu, 12 Oct 2023 13:01:36 +0100 Subject: [PATCH 2/6] Exposed AxisOrder class --- src/metkit/hypercube/HyperCube.cc | 42 +++++++++---------------------- src/metkit/hypercube/HyperCube.h | 15 +++++++++++ src/metkit/mars/MarsRequest.cc | 14 ++++++----- src/metkit/mars/MarsRequest.h | 2 +- 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/metkit/hypercube/HyperCube.cc b/src/metkit/hypercube/HyperCube.cc index 7c7ee5ef..2b1820e1 100644 --- a/src/metkit/hypercube/HyperCube.cc +++ b/src/metkit/hypercube/HyperCube.cc @@ -19,45 +19,28 @@ #include "metkit/mars/MarsRequest.h" #include "metkit/mars/Type.h" -namespace metkit { -namespace hypercube { +namespace metkit::hypercube { static metkit::mars::Type& type(const std::string& name) { static metkit::mars::MarsLanguage language("retrieve"); return *language.type(name); } -namespace { -class AxisOrder { -public: // methods - static AxisOrder& instance() { - static AxisOrder instance; - return instance; - } - - const std::vector& axes() { - return axes_; - } - -private: // methods - AxisOrder() { - eckit::Value axis = eckit::YAMLParser::decodeFile(axisYamlFile()); - const eckit::Value axesNames = axis["axes"]; - - for (size_t i = 0; i < axesNames.size(); ++i) { - axes_.push_back(axesNames[i]); - } - } +AxisOrder::AxisOrder() { + eckit::Value axis = eckit::YAMLParser::decodeFile(axisYamlFile()); + const eckit::Value axesNames = axis["axes"]; - eckit::PathName axisYamlFile() { - return "~metkit/share/metkit/axis.yaml"; + for (size_t i = 0; i < axesNames.size(); ++i) { + axes_.push_back(axesNames[i]); } +} -private: // members - std::vector axes_; -}; +AxisOrder& AxisOrder::instance() { + static AxisOrder instance; + return instance; } + class Axis { public: Axis(const std::string& name, const std::vector& values) : @@ -308,5 +291,4 @@ size_t HyperCube::fieldOrdinal(const metkit::mars::MarsRequest& r, bool noholes) return idx; } -} // namespace hypercube -} // namespace metkit +} // namespace metkit::hypercube diff --git a/src/metkit/hypercube/HyperCube.h b/src/metkit/hypercube/HyperCube.h index 32134987..8c720896 100644 --- a/src/metkit/hypercube/HyperCube.h +++ b/src/metkit/hypercube/HyperCube.h @@ -31,6 +31,21 @@ namespace hypercube { class Axis; +class AxisOrder { +public: // methods + static AxisOrder& instance(); + + const std::vector& axes() { return axes_; } + +private: // methods + AxisOrder(); + + eckit::PathName axisYamlFile() { return "~metkit/share/metkit/axis.yaml"; } + +private: // members + std::vector axes_; +}; + class HyperCube { public: HyperCube(const metkit::mars::MarsRequest&); diff --git a/src/metkit/mars/MarsRequest.cc b/src/metkit/mars/MarsRequest.cc index 124cfeb5..bb9f725e 100644 --- a/src/metkit/mars/MarsRequest.cc +++ b/src/metkit/mars/MarsRequest.cc @@ -121,18 +121,20 @@ bool MarsRequest::empty() const { void MarsRequest::print(std::ostream& s) const { - dump(s, "", ""); + dump(s, "", "", true); } -void MarsRequest::dump(std::ostream& s, const char* cr, const char* tab) const { +void MarsRequest::dump(std::ostream& s, const char* cr, const char* tab, bool verb) const { std::list::const_iterator begin = params_.begin(); std::list::const_iterator end = params_.end(); - - s << verb_; - + if (verb) { + s << verb_ << ','; + } + std::string separator = ""; if (begin != end) { - s << ',' << cr << tab; + s << separator << cr << tab; + separator = ","; int a = 0; for (std::list::const_iterator i = begin; i != end; ++i) { diff --git a/src/metkit/mars/MarsRequest.h b/src/metkit/mars/MarsRequest.h index 96edecf8..42985197 100644 --- a/src/metkit/mars/MarsRequest.h +++ b/src/metkit/mars/MarsRequest.h @@ -94,7 +94,7 @@ class MarsRequest { void md5(eckit::MD5&) const; - void dump(std::ostream&, const char* cr = "\n", const char* tab = "\t") const; + void dump(std::ostream&, const char* cr = "\n", const char* tab = "\t", bool verb = true) const; void setValuesTyped(Type*, const std::vector&); From 24fb431d2c226037e43ed47f9c17924df8d26b68 Mon Sep 17 00:00:00 2001 From: Emanuele Danovaro Date: Fri, 13 Oct 2023 10:18:18 +0100 Subject: [PATCH 3/6] version bump --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index ccb12466..0e73a4b8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.10.16 +1.10.17 From dc9d065f1a655926ec191c0a98b8410e95e16151 Mon Sep 17 00:00:00 2001 From: Emanuele Danovaro Date: Fri, 13 Oct 2023 13:53:11 +0100 Subject: [PATCH 4/6] fix unit test - added support for new validityTime encoding format (hhmm) --- tests/test_codes_decoder.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/test_codes_decoder.cc b/tests/test_codes_decoder.cc index 26c36eab..bf84226e 100644 --- a/tests/test_codes_decoder.cc +++ b/tests/test_codes_decoder.cc @@ -76,6 +76,12 @@ static unsigned char unstr_latlon[] = {0x47, 0x52, 0x49, 0x42, 0xff, 0xff, 0x02, std::cout << "expect string for " << name << " to equal " << eq << " (got " << md.getString(name) << ")" << std::endl; \ EXPECT(md.getString(name) == eq); +// we accept two possible encodings, to enable testing with different versions of ecCodes (ECC-1704) +#define MD_EXPECT_STRINGS(md, name, eq1, eq2) \ + EXPECT(md.has(name)); \ + std::cout << "expect string for " << name << " to equal " << eq1 << " or " << eq2 << " (got " << md.getString(name) << ")" << std::endl; \ + EXPECT(md.getString(name) == eq1 || md.getString(name) == eq2); + #define MD_EXPECT_LONG(md, name, eq) \ EXPECT(md.has(name)); \ std::cout << "expect long for " << name << " to equal " << eq << " (got " << md.getLong(name) << ")" << std::endl; \ @@ -397,7 +403,7 @@ CASE("test codessplitter unstr_latlot.tmpl String") { MD_EXPECT_STRING(md, "endStep", "0"); MD_EXPECT_STRING(md, "stepRange", "0"); MD_EXPECT_STRING(md, "validityDate", "10101"); - MD_EXPECT_STRING(md, "validityTime", "0"); + MD_EXPECT_STRINGS(md, "validityTime", "0", "0000"); MD_EXPECT_STRING(md, "typeOfFirstFixedSurface", "168"); MD_EXPECT_STRING(md, "unitsOfFirstFixedSurface", "Numeric"); MD_EXPECT_STRING(md, "nameOfFirstFixedSurface", "Ocean model level"); From 54cd4e3af41b78021459878ac10b260578acf689 Mon Sep 17 00:00:00 2001 From: Emanuele Danovaro Date: Fri, 20 Oct 2023 11:33:36 +0200 Subject: [PATCH 5/6] version bump --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 0e73a4b8..e5c453e2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.10.17 +1.10.18 From ee46514f74b7279cbbc5e1107681884f5018bd00 Mon Sep 17 00:00:00 2001 From: Emanuele Danovaro Date: Sat, 21 Oct 2023 11:28:36 +0200 Subject: [PATCH 6/6] fix unit test - added support for new validityTime encoding format (hhmm) --- tests/test_codes_decoder.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_codes_decoder.cc b/tests/test_codes_decoder.cc index bf84226e..224ca574 100644 --- a/tests/test_codes_decoder.cc +++ b/tests/test_codes_decoder.cc @@ -219,7 +219,7 @@ CASE("test codessplitter unstr_latlot.tmpl Native") { MD_EXPECT_LONG(md, "endStep", 0); MD_EXPECT_STRING(md, "stepRange", "0"); MD_EXPECT_LONG(md, "validityDate", 10101); - MD_EXPECT_LONG(md, "validityTime", 0); + MD_EXPECT_STRINGS(md, "validityTime", "0", "0000"); MD_EXPECT_STRING(md, "typeOfFirstFixedSurface", "168"); MD_EXPECT_STRING(md, "unitsOfFirstFixedSurface", "Numeric"); MD_EXPECT_STRING(md, "nameOfFirstFixedSurface", "Ocean model level");