diff --git a/include/actiondep.h b/include/actiondep.h index 08f7f35..50e2db5 100644 --- a/include/actiondep.h +++ b/include/actiondep.h @@ -85,29 +85,16 @@ template std::pair GetTIndexes(const D& data, const CL if(beg > data.Time(nt - 1)) return {tindexes, "Begin time " + b.ToTString() + " is greater then end time in the dataset " + data.Time(nt - 1).ToTString()}; if(end < data.Time(0)) return {tindexes, "End time " + e.ToTString() + " is lesser then begin time in the dataset " + data.Time(0).ToTString()}; - size_t ib = 0, ie = nt - 1; for(size_t i = 0; i < nt; i++) - if(data.Time(i) >= beg) - { - ib = i; - break; - } - - for(size_t i = nt; i != 0; i--) - if(data.Time(i - 1) <= end) - { - ie = i - 1; - break; - } - - tindexes.resize(ie - ib + 1); - for(size_t i = 0; i < ie - ib + 1; i++) tindexes[i] = i + ib; + if(data.Time(i) >= beg && data.Time(i) <= end) tindexes.push_back(i); if(tindexes.size() == 0) return {tindexes, "There are no times between " + b.ToString() + " and " + e.ToString()}; pars.SetParameter("timeb", b.ToTString()); pars.SetParameter("timee", e.ToTString()); } + std::ranges::sort(tindexes, [&data = std::as_const(data)](size_t a, size_t b) { return data.Time(a) < data.Time(b); }); + return {tindexes, ""}; }