mirror of https://github.com/ecmwf/eccodes.git
Merge branch 'feature/ECC-1620_sub-hourly' into feature/ECC-1620_sub-hourly_string
This commit is contained in:
commit
538aa336c5
11
src/step.cc
11
src/step.cc
|
@ -75,16 +75,14 @@ bool Step::operator<(const Step& step) const
|
||||||
|
|
||||||
Step Step::operator+(const Step& step) const
|
Step Step::operator+(const Step& step) const
|
||||||
{
|
{
|
||||||
Step tmp = step;
|
auto [a, b] = find_common_units(this->copy().optimize_unit(), step.copy().optimize_unit());
|
||||||
auto [a, b] = find_common_units(this->copy().optimize_unit(), tmp.copy().optimize_unit());
|
|
||||||
assert(a.internal_unit_ == b.internal_unit_);
|
assert(a.internal_unit_ == b.internal_unit_);
|
||||||
return Step(a.internal_value_ + b.internal_value_, a.internal_unit_);
|
return Step(a.internal_value_ + b.internal_value_, a.internal_unit_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Step Step::operator-(const Step& step) const
|
Step Step::operator-(const Step& step) const
|
||||||
{
|
{
|
||||||
Step tmp = step;
|
auto [a, b] = find_common_units(this->copy().optimize_unit(), step.copy().optimize_unit());
|
||||||
auto [a, b] = find_common_units(this->copy().optimize_unit(), tmp.copy().optimize_unit());
|
|
||||||
assert(a.internal_unit_ == b.internal_unit_);
|
assert(a.internal_unit_ == b.internal_unit_);
|
||||||
return Step(a.internal_value_ - b.internal_value_, a.internal_unit_);
|
return Step(a.internal_value_ - b.internal_value_, a.internal_unit_);
|
||||||
}
|
}
|
||||||
|
@ -155,10 +153,11 @@ Step& Step::optimize_unit()
|
||||||
|
|
||||||
unit_ = internal_unit_;
|
unit_ = internal_unit_;
|
||||||
Seconds<long> seconds = to_seconds<long>(internal_value_, internal_unit_);
|
Seconds<long> seconds = to_seconds<long>(internal_value_, internal_unit_);
|
||||||
|
long abs_seconds = seconds.count() < 0 ? -seconds.count() : seconds.count();
|
||||||
|
|
||||||
for (auto it = Unit::grib_selected_units.rbegin(); it != Unit::grib_selected_units.rend(); ++it) {
|
for (auto it = Unit::grib_selected_units.rbegin(); it != Unit::grib_selected_units.rend(); ++it) {
|
||||||
auto multiplier = Unit::get_converter().unit_to_duration(*it);
|
long multiplier = Unit::get_converter().unit_to_duration(*it);
|
||||||
if (seconds.count() % multiplier == 0) {
|
if (abs_seconds % multiplier == 0) {
|
||||||
internal_value_ = seconds.count() / multiplier;
|
internal_value_ = seconds.count() / multiplier;
|
||||||
internal_unit_ = *it;
|
internal_unit_ = *it;
|
||||||
unit_ = *it;
|
unit_ = *it;
|
||||||
|
|
|
@ -81,7 +81,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
Seconds<long> seconds = to_seconds<long>(internal_value_, internal_unit_);
|
Seconds<long> seconds = to_seconds<long>(internal_value_, internal_unit_);
|
||||||
auto multiplier = Unit::get_converter().unit_to_duration(unit_.value<Unit::Value>());
|
long multiplier = Unit::get_converter().unit_to_duration(unit_.value<Unit::Value>());
|
||||||
internal_value_ = seconds.count() / multiplier;
|
internal_value_ = seconds.count() / multiplier;
|
||||||
internal_unit_ = unit_;
|
internal_unit_ = unit_;
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,9 @@ grib_check_key_equals $temp "-s stepUnits:s=h -p startStep:s,endStep:s" "-6 0"
|
||||||
grib_check_key_equals $temp "-s stepUnits:s=m -p startStep:s,endStep:s" "-360m 0m"
|
grib_check_key_equals $temp "-s stepUnits:s=m -p startStep:s,endStep:s" "-360m 0m"
|
||||||
grib_check_key_equals $temp "-s stepUnits:s=s -p startStep:s,endStep:s" "-21600s 0s"
|
grib_check_key_equals $temp "-s stepUnits:s=s -p startStep:s,endStep:s" "-21600s 0s"
|
||||||
|
|
||||||
|
${tools_dir}/grib_set -s forecastTime=-48,indicatorOfUnitOfTimeRange=h,lengthOfTimeRange=0,indicatorOfUnitForTimeRange=h $fn $temp
|
||||||
|
grib_check_key_equals $temp "-p stepRange" "-48"
|
||||||
|
|
||||||
|
|
||||||
#### CHECK: check optimal units are set correctly in GRIB files
|
#### CHECK: check optimal units are set correctly in GRIB files
|
||||||
fn="${data_dir}/reduced_gaussian_sub_area.grib2"
|
fn="${data_dir}/reduced_gaussian_sub_area.grib2"
|
||||||
|
|
Loading…
Reference in New Issue