33 auto s = std::istringstream(t);
39 std::istringstream x(time_step);
45 const Options::TimeStep t = Options::toTimeStep(type);
49 case Options::TimeStep::hour:
50 case Options::TimeStep::hours:
51 case Options::TimeStep::h:
52 return TimeStep(std::chrono::hours(length ));
53 case Options::TimeStep::minute:
54 case Options::TimeStep::minutes:
55 case Options::TimeStep::min:
56 return TimeStep(std::chrono::minutes(length));
57 case Options::TimeStep::second:
58 case Options::TimeStep::seconds:
59 case Options::TimeStep::s:
60 return TimeStep(std::chrono::seconds(length));
61 case Options::TimeStep::FINAL: {
70 auto dt_internal = std::chrono::duration_cast<Time::InternalTimeStep>(dt);
72 if (dt_internal.count())
73 return t + dt_internal - t.
EpochTime() % dt_internal;
81 "Can only find time steps for 2-long or longer time grids");
84 const TimeStep dt = std::chrono::abs(DT);
110 std::array <char, 2 + 1 + 9 + 100> sec;
112 snprintf(sec.data(), sec.size(),
"%.9lf", seconds);
115 return os << 1900 + x.tm_year <<
'-' << std::setfill(
'0') << std::setw(2)
116 << 1 + x.tm_mon <<
'-' << std::setfill(
'0') << std::setw(2)
117 << x.tm_mday <<
' ' << std::setfill(
'0') << std::setw(2)
118 << x.tm_hour <<
':' << std::setfill(
'0') << std::setw(2)
119 << x.tm_min <<
':' << std::setfill(
'0') << std::setw(12) << sec.data();
132 "Time stream must look like \"year-month-day hour:min:seconds\"\n"
133 "\"year-month-day\" looks like: ", ymd,
'\n',
134 "\"hour:min:seconds\" looks like: ", hms);
138 x.tm_year = std::stoi(YMD[0]) - 1900;
139 x.tm_mon = std::stoi(YMD[1]) - 1;
140 x.tm_mday = std::stoi(YMD[2]);
141 x.tm_hour = std::stoi(HMS[0]);
142 x.tm_min = std::stoi(HMS[1]);
154 if (e == -1) e = ts.
nelem();
156 "Bad last index, valid options are [-1, ts.nelem()], got: ", E);
159 "Bad first index, valid options are [0, ts.nelem()], got: ", s);
162 for (
Index i=s+1; i<e; i++)
163 dt += (ts[i] - ts[s]) / (e - s);
175 for (
Index i=0; i<times.
nelem(); i++) t[i].Seconds(times[i]);
180 const auto n = dt.size();
182 std::sort(dt.begin(), dt.end());
185 return (dt[(n-1)/2] + dt[n/2]) / 2;
192 const auto n = dt.size();
193 for (std::size_t i=0; i<n; i++) {
200 return os << dt.count() <<
" seconds";
Options for ARTS from enumeration (including error handling)
TimeStep mean(const ArrayOfTimeStep &dt)
Returns the mean time step.
ArrayOfIndex time_steps(const ArrayOfTime ×, const TimeStep &DT)
Finds the index matching demands in a list of times.
TimeStep time_stepper_selection(const String &time_step)
Returns a time step from valid string.
Vector time_vector(const ArrayOfTime ×)
Converts from each Time to seconds and returns as Vector.
Time mean_time(const ArrayOfTime &ts, Index s, Index E)
Computes the average time in a list.
TimeStep median(ArrayOfTimeStep dt)
Returns the median time step.
std::istream & operator>>(std::istream &is, Time &t)
std::ostream & operator<<(std::ostream &os, const Time &t)
Time next_even(const Time &t, const TimeStep &dt)
Returns the next time after t with an even time-step.
Stuff related to time in ARTS.
std::chrono::duration< Numeric > TimeStep
A duration of time, 1 full tick should be 1 second.
Index nelem() const ARTS_NOEXCEPT
Index nelem() const noexcept
Returns the number of elements.
void split(Array< my_basic_string< charT > > &aos, const my_basic_string< charT > &delim) const
void tolower()
Convert to lower case.
#define ARTS_USER_ERROR_IF(condition,...)
constexpr void check_enum_error(EnumType type, Messages... args)
Checks if the enum class type is good and otherwise throws an error message composed by variadic inpu...
NUMERIC Numeric
The type to use for all floating point numbers.
INDEX Index
The type to use for all integer numbers and indices.
Class to handle time in ARTS.
InternalTimeStep EpochTime() const
Numeric PartOfSecond() const
decltype(time)::duration InternalTimeStep