15 auto s = std::istringstream(t);
21 std::istringstream x(time_step);
27 const Options::TimeStep t = Options::toTimeStep(type);
31 case Options::TimeStep::hour:
32 case Options::TimeStep::hours:
33 case Options::TimeStep::h:
34 return TimeStep(std::chrono::hours(length ));
35 case Options::TimeStep::minute:
36 case Options::TimeStep::minutes:
37 case Options::TimeStep::min:
38 return TimeStep(std::chrono::minutes(length));
39 case Options::TimeStep::second:
40 case Options::TimeStep::seconds:
41 case Options::TimeStep::s:
42 return TimeStep(std::chrono::seconds(length));
43 case Options::TimeStep::FINAL: {
52 auto dt_internal = std::chrono::duration_cast<Time::InternalTimeStep>(dt);
54 if (dt_internal.count())
55 return t + dt_internal - t.
EpochTime() % dt_internal;
61 Index N = times.
nelem();
63 "Can only find time steps for 2-long or longer time grids");
66 const TimeStep dt = std::chrono::abs(DT);
92 std::array <char, 2 + 1 + 9 + 100> sec;
94 snprintf(sec.data(), sec.size(),
"%.9lf", seconds);
97 return os << 1900 + x.tm_year <<
'-' << std::setfill(
'0') << std::setw(2)
98 << 1 + x.tm_mon <<
'-' << std::setfill(
'0') << std::setw(2)
99 << x.tm_mday <<
' ' << std::setfill(
'0') << std::setw(2)
100 << x.tm_hour <<
':' << std::setfill(
'0') << std::setw(2)
101 << x.tm_min <<
':' << std::setfill(
'0') << std::setw(12) << sec.data();
114 "Time stream must look like \"year-month-day hour:min:seconds\"\n"
115 "\"year-month-day\" looks like: ", ymd,
'\n',
116 "\"hour:min:seconds\" looks like: ", hms);
120 x.tm_year = std::stoi(YMD[0]) - 1900;
121 x.tm_mon = std::stoi(YMD[1]) - 1;
122 x.tm_mday = std::stoi(YMD[2]);
123 x.tm_hour = std::stoi(HMS[0]);
124 x.tm_min = std::stoi(HMS[1]);
136 if (e == -1) e = ts.
nelem();
138 "Bad last index, valid options are [-1, ts.nelem()], got: ", E);
141 "Bad first index, valid options are [0, ts.nelem()], got: ", s);
144 for (Index i=s+1; i<e; i++)
145 dt += (ts[i] - ts[s]) / (e - s);
150 Vector t(times.
nelem());
151 for (Index i=0; i<times.
nelem(); i++) t[i] = Numeric(times[i]);
157 for (Index i=0; i<times.nelem(); i++) t[i].Seconds(times[i]);
162 const auto n = dt.size();
164 std::sort(dt.begin(), dt.end());
167 return (dt[(n-1)/2] + dt[n/2]) / 2;
174 const auto n = dt.size();
175 for (std::size_t i=0; i<n; i++) {
182 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
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...
Class to handle time in ARTS.
InternalTimeStep EpochTime() const
Numeric PartOfSecond() const
decltype(time)::duration InternalTimeStep