Skip to content

Commit

Permalink
Merge branch 'hotfix/1.10.18' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
danovaro committed Oct 24, 2023
2 parents dc46433 + ee46514 commit 49b6b55
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 44 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.15
1.10.18
48 changes: 15 additions & 33 deletions src/metkit/hypercube/HyperCube.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& 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<std::string> axes_;
};
AxisOrder& AxisOrder::instance() {
static AxisOrder instance;
return instance;
}


class Axis {
public:
Axis(const std::string& name, const std::vector<std::string>& values) :
Expand Down Expand Up @@ -256,14 +239,14 @@ std::vector<std::pair<metkit::mars::MarsRequest, size_t>> HyperCube::request(std
return requests;
}

std::vector<metkit::mars::MarsRequest> HyperCube::vacantRequests() const {
std::vector<metkit::mars::MarsRequest> HyperCube::aggregatedRequests(bool remaining) const {

if (countVacant() == 0)
if (countVacant() == (remaining ? 0 : size()))
return std::vector<metkit::mars::MarsRequest>{};

std::set<size_t> idxs;
for(size_t i = 0; i < set_.size(); ++i) {
if (set_[i])
if (set_[i] == remaining)
idxs.emplace(i);
}

Expand Down Expand Up @@ -308,5 +291,4 @@ size_t HyperCube::fieldOrdinal(const metkit::mars::MarsRequest& r, bool noholes)
return idx;
}

} // namespace hypercube
} // namespace metkit
} // namespace metkit::hypercube
19 changes: 18 additions & 1 deletion src/metkit/hypercube/HyperCube.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ namespace hypercube {

class Axis;

class AxisOrder {
public: // methods
static AxisOrder& instance();

const std::vector<std::string>& axes() { return axes_; }

private: // methods
AxisOrder();

eckit::PathName axisYamlFile() { return "~metkit/share/metkit/axis.yaml"; }

private: // members
std::vector<std::string> axes_;
};

class HyperCube {
public:
HyperCube(const metkit::mars::MarsRequest&);
Expand All @@ -44,9 +59,11 @@ class HyperCube {
size_t size() const {return cube_.count(); }

size_t fieldOrdinal(const metkit::mars::MarsRequest&, bool noholes = true) const;
std::vector<metkit::mars::MarsRequest> vacantRequests() const;
std::vector<metkit::mars::MarsRequest> vacantRequests() const { return aggregatedRequests(true); }
std::vector<metkit::mars::MarsRequest> requests() const { return aggregatedRequests(false); }

protected:
std::vector<metkit::mars::MarsRequest> aggregatedRequests(bool remaining) const;
int indexOf(const metkit::mars::MarsRequest&) const;
bool clear(int index);
metkit::mars::MarsRequest requestOf(size_t index) const;
Expand Down
14 changes: 8 additions & 6 deletions src/metkit/mars/MarsRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Parameter>::const_iterator begin = params_.begin();
std::list<Parameter>::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<Parameter>::const_iterator i = begin; i != end; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion src/metkit/mars/MarsRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>&);

Expand Down
10 changes: 8 additions & 2 deletions tests/test_codes_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down Expand Up @@ -213,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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 49b6b55

Please sign in to comment.