Skip to content

Commit

Permalink
Exposed AxisOrder class
Browse files Browse the repository at this point in the history
  • Loading branch information
danovaro committed Oct 12, 2023
1 parent c49adaf commit 8a7948d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 37 deletions.
42 changes: 12 additions & 30 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 @@ -308,5 +291,4 @@ size_t HyperCube::fieldOrdinal(const metkit::mars::MarsRequest& r, bool noholes)
return idx;
}

} // namespace hypercube
} // namespace metkit
} // namespace metkit::hypercube
15 changes: 15 additions & 0 deletions 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 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

0 comments on commit 8a7948d

Please sign in to comment.