Skip to content

Commit

Permalink
Merge branch 'develop' into feature/requestManipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
danovaro committed Dec 9, 2024
2 parents a0a3ea2 + 963c295 commit cb8c468
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 35 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.11.22
1.11.23
63 changes: 31 additions & 32 deletions src/metkit/mars/StepRange.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ using namespace eckit;

namespace {

enum TimeUnit {
Second = 0,
Minute = 1,
Hour = 2,
Day = 3
};

TimeUnit maxUnit(const eckit::Time& t) {
if (t.seconds() == 0) {
if (t.minutes() == 0) {
if (t.hours() == 0) {
return TimeUnit::Day;
}
return TimeUnit::Hour;
}
return TimeUnit::Minute;
}
return TimeUnit::Second;
}
// enum TimeUnit {
// Second = 0,
// Minute = 1,
// Hour = 2,
// Day = 3
// };

// TimeUnit maxUnit(const eckit::Time& t) {
// if (t.seconds() == 0) {
// if (t.minutes() == 0) {
// if (t.hours() == 0) {
// return TimeUnit::Day;
// }
// return TimeUnit::Hour;
// }
// return TimeUnit::Minute;
// }
// return TimeUnit::Second;
// }

std::string canonical(const eckit::Time& time) {

Expand All @@ -65,24 +65,23 @@ std::string canonical(const eckit::Time& time) {
return out;
}

std::string canonical(const eckit::Time& time, TimeUnit unit) {
switch (unit) {
case TimeUnit::Second:
return std::to_string(time.seconds()+60*time.minutes()+3600*time.hours()) + "s";
case TimeUnit::Minute:
return std::to_string(time.minutes()+60*time.hours()) + "m";
case TimeUnit::Day:
case TimeUnit::Hour:
default:
return std::to_string(time.hours());
}
}
// std::string canonical(const eckit::Time& time, TimeUnit unit) {
// switch (unit) {
// case TimeUnit::Second:
// return std::to_string(time.seconds()+60*time.minutes()+3600*time.hours()) + "s";
// case TimeUnit::Minute:
// return std::to_string(time.minutes()+60*time.hours()) + "m";
// case TimeUnit::Day:
// case TimeUnit::Hour:
// default:
// return std::to_string(time.hours());
// }
// }

}

namespace metkit::mars {


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

StepRange::operator std::string() const
Expand Down
2 changes: 1 addition & 1 deletion src/tools/bufr-sanity-check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ void BufrCheck::process(const PathName& input, const PathName& output) {
numMessage++;
}
}
catch(eckit::Exception e) {
catch(eckit::Exception& e) {
Log::warning() << " Error parsing message " << numMessage << " - offset " << pos << std::endl;
if (verbose_) {
e.dumpStackTrace(Log::warning());
Expand Down
97 changes: 96 additions & 1 deletion tests/test_expand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ CASE( "test_metkit_expand_3" ) {
expand(text, "retrieve", expected, {-5,-4,-3,-2,-1});
}


CASE( "test_metkit_expand_4" ) {
const char* text = "ret,date=-5/to/-1,grid=o640";
std::map<std::string, std::vector<std::string>> expected{
Expand Down Expand Up @@ -599,6 +598,102 @@ CASE( "test_metkit_expand_param" ) {
}
}

CASE( "test_metkit_expand_d1" ) {
{
const char* text = "retrieve,class=d1,dataset=extremes-dt,date=-1";
std::map<std::string, std::vector<std::string>> expected{
{"class", {"d1"}},
{"dataset", {"extremes-dt"}},
{"domain", {"g"}},
{"expver", {"0001"}},
{"levelist", {"1000","850","700","500","400","300"}},
{"levtype", {"pl"}},
{"param", {"129"}},
{"step", {"0"}},
{"stream", {"oper"}},
{"time", {"1200"}},
{"type", {"an"}}
};
expand(text, "retrieve", expected, {-1});
} {
const char* text = "retrieve,class=d1,dataset=extreme-dt,date=-1";
std::map<std::string, std::vector<std::string>> expected{
{"class", {"d1"}},
{"dataset", {"extremes-dt"}},
{"expver", {"0001"}},
{"levelist", {"1000","850","700","500","400","300"}},
{"levtype", {"pl"}},
{"param", {"129"}},
{"step", {"0"}},
{"stream", {"oper"}},
{"time", {"1200"}},
{"type", {"an"}}
};
expand(text, "retrieve", expected, {-1});
}
// {
// const char* text = "retrieve,class=d1,dataset=extreme-dt,date=-1";
// std::istringstream in(text);
// MarsParser parser(in);
// MarsExpension expand(false, true);
// EXPECT_THROWS(expand.expand(parser.parse()));
// }
{
const char* text = "retrieve,class=d1,dataset=climate-dt,levtype=pl,date=20000101,activity=CMIP6,experiment=hist,model=IFS-NEMO,generation=1,realization=1,resolution=high,stream=clte,type=fc,param=134/137";
std::map<std::string, std::vector<std::string>> expected{
{"class", {"d1"}},
{"dataset", {"climate-dt"}},
{"activity", {"cmip6"}},
{"experiment", {"hist"}},
{"model", {"ifs-nemo"}},
{"generation", {"1"}},
{"realization", {"1"}},
{"resolution", {"high"}},
{"expver", {"0001"}},
{"date", {"20000101"}},
{"time", {"1200"}},
{"stream", {"clte"}},
{"type", {"fc"}},
{"levtype", {"pl"}},
{"levelist", {"1000","850","700","500","400","300"}},
{"param", {"134","137"}}
};
expand(text, "retrieve", expected, {20000101});
}
}


CASE( "test_metkit_expand_ng" ) {
{
const char* text = "retrieve,class=ng,date=20000101,activity=CMIP6,experiment=hist,model=IFS-NEMO,generation=1,realization=1,resolution=high,stream=clte,type=fc,levtype=pl,param=134/137";
std::map<std::string, std::vector<std::string>> expected {
{"class", {"ng"}},
{"levtype", {"pl"}},
{"levelist", {"1000","850","700","500","400","300"}},
{"activity", {"cmip6"}},
{"experiment", {"hist"}},
{"model", {"ifs-nemo"}},
{"generation", {"1"}},
{"realization", {"1"}},
{"resolution", {"high"}},
{"expver", {"0001"}},
{"date", {"20000101"}},
{"time", {"1200"}},
{"stream", {"clte"}},
{"type", {"fc"}},
{"param", {"134","137"}}
};
expand(text, "retrieve", expected, {20000101});
}
{
const char* text = "retrieve,class=ng,dataset=climate-dt,date=20000101,activity=CMIP6,experiment=hist,model=IFS-NEMO,generation=1,realization=1,resolution=high,stream=clte,type=fc,levtype=sfc,param=134/137";
std::istringstream in(text);
MarsParser parser(in);
MarsExpension expand(false, true);
EXPECT_THROWS(expand.expand(parser.parse()));
}
}

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

} // namespace test
Expand Down

0 comments on commit cb8c468

Please sign in to comment.