Skip to content

Commit

Permalink
Merge branch 'hotfix/1.11.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
danovaro committed Jan 31, 2024
2 parents 543cd9c + b76820a commit c639f2f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 26 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.11.1
1.11.4
7 changes: 7 additions & 0 deletions share/metkit/language.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ _field: &_field
flatten: false
type: enum
values:
- [ai, operational aifs]
- [at, austria]
- [be, belgium]
- [c3, c3s]
- [ce, cems]
- [ch, switzerland]
- [ci, cerise]
- [co, cosmo]
- [cr, cams research]
- [cs, ecsn]
Expand Down Expand Up @@ -552,6 +554,8 @@ _field: &_field
default: 0
type: range
never:
- dataset:
- climate-dt
- stream:
- msmm
- mmsa
Expand Down Expand Up @@ -603,6 +607,9 @@ _field: &_field
default: g
flatten: false
type: enum
never:
- dataset:
- climate-dt
values:
- [a, north west europe]
- [b, north east europe, baltic and black sea]
Expand Down
32 changes: 15 additions & 17 deletions src/metkit/mars/StepRange.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ std::string canonical(const eckit::Time& time) {
long m = time.minutes();
long s = time.seconds();

// std::cout << h << "h" << m << "m" << s << "s\n";
std::string out = "";
if (h!=0 || (m==0 && s==0)) {
out += std::to_string(h);
Expand Down Expand Up @@ -96,17 +95,20 @@ StepRange::operator std::string() const
void StepRange::print(std::ostream& s) const
{
if(from_ == to_) {
s << canonical(from_);
s << canonical(eckit::Time(from_*3600, true));
}
else {
TimeUnit unit = std::min(maxUnit(from_), maxUnit(to_));
s << canonical(from_,unit) << '-' << canonical(to_,unit);
eckit::Time f{static_cast<long>(from_*3600.), true};
eckit::Time t{static_cast<long>(to_*3600.), true};

TimeUnit unit = std::min(maxUnit(f), maxUnit(t));
s << canonical(f, unit) << '-' << canonical(t, unit);
}
}

StepRange::StepRange(const std::string& s):
from_(0),
to_(0)
from_(0.),
to_(0.)
{
Tokenizer parse("-");
std::vector<std::string> result;
Expand All @@ -116,12 +118,12 @@ StepRange::StepRange(const std::string& s):
switch(result.size())
{
case 1:
to_ = from_ = eckit::Time(result[0], true);
to_ = from_ = eckit::Time(result[0], true)/3600.;
break;

case 2:
from_ = eckit::Time(result[0], true);
to_ = eckit::Time(result[1], true);
from_ = eckit::Time(result[0], true)/3600.;
to_ = eckit::Time(result[1], true)/3600.;
break;

default:
Expand All @@ -134,18 +136,14 @@ StepRange::StepRange(const std::string& s):

void StepRange::dump(DumpLoad& a) const
{
a.dump(from_.seconds()/3600.);
a.dump(to_.seconds()/3600.);
a.dump(from_);
a.dump(to_);
}

void StepRange::load(DumpLoad& a)
{
double from, to;
a.load(from);
a.load(to);

from_ = eckit::Time(from*3600., true);
to_ = eckit::Time(to*3600., true);
a.load(from_);
a.load(to_);
}

//----------------------------------------------------------------------------------------------------------------------
Expand Down
16 changes: 8 additions & 8 deletions src/metkit/mars/StepRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ class StepRange {

StepRange(const std::string&);

StepRange(eckit::Time from = eckit::Time(0), eckit::Time to = eckit::Time(0)):
from_(from),to_(to) {
explicit StepRange(eckit::Time from = eckit::Time(0), eckit::Time to = eckit::Time(0)) :
from_(from/3600.), to_(to/3600.) {

if (from_ != eckit::Time(0) && to_ == eckit::Time(0)) {
if (from != eckit::Time(0) && to == eckit::Time(0)) {
to_ = from_;
}
}

StepRange(double from, double to = 0):
explicit StepRange(double from, double to = 0):
StepRange(eckit::Time(from*3600, true), eckit::Time(to*3600, true)) {}


Expand Down Expand Up @@ -74,8 +74,8 @@ class StepRange {

// -- Methods

double from() const { return from_/3600.; }
double to() const { return to_/3600.; }
double from() const { return from_; }
double to() const { return to_; }

void dump(eckit::DumpLoad&) const;
void load(eckit::DumpLoad&);
Expand Down Expand Up @@ -115,8 +115,8 @@ class StepRange {

// -- Members

eckit::Time from_;
eckit::Time to_;
double from_;
double to_;

// -- Methods
// None
Expand Down
4 changes: 4 additions & 0 deletions tests/test_expand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ CASE( "test_metkit_expand_13_step" ) {
step({"0:45"}, {"45m"});
step({"0:50"}, {"50m"});
step({"0:55"}, {"55m"});
step({"0-24"}, {"0-24"});
step({"0-24s"}, {"0s-24s"});
step({"0-120s"}, {"0m-2m"});
step({"0s-120m"}, {"0-2"});
step({"1-2"}, {"1-2"});
step({"30m-1"}, {"30m-60m"});

Expand Down
30 changes: 30 additions & 0 deletions tests/test_steprange_axis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@ namespace test {

//-----------------------------------------------------------------------------

CASE("steprange") {

{
StepRange sr{0,24};
EXPECT(sr.from()==0);
std::cout << sr.to() << std::endl;
EXPECT(sr.to()==24);
}
{
StepRange sr{"0-24"};
EXPECT(sr.from()==0);
EXPECT(sr.to()==24);
}
{
StepRange sr{0,.5};
EXPECT(sr.from()==0);
EXPECT(sr.to()==0.5);
}
{
StepRange sr{"0-30m"};
EXPECT(sr.from()==0);
EXPECT(sr.to()==0.5);
}
{
StepRange sr{"0-24s"};
EXPECT(sr.from()==0);
EXPECT(sr.to()==(24./3600.));
}
}


static void test_steprange_axis(
const std::vector<std::string>& user,
Expand Down

0 comments on commit c639f2f

Please sign in to comment.