Browse Source

The code for obtaining time point indices has been simplified. The indexes are returned sorted by the time points they represent.

lintest
Michael Uleysky 10 months ago
parent
commit
f27ad2ce72
  1. 19
      include/actiondep.h

19
include/actiondep.h

@ -85,29 +85,16 @@ template<class D> std::pair<TIndex, MString> 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(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()}; 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++) for(size_t i = 0; i < nt; i++)
if(data.Time(i) >= beg) if(data.Time(i) >= beg && data.Time(i) <= end) tindexes.push_back(i);
{
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(tindexes.size() == 0) return {tindexes, "There are no times between " + b.ToString() + " and " + e.ToString()}; if(tindexes.size() == 0) return {tindexes, "There are no times between " + b.ToString() + " and " + e.ToString()};
pars.SetParameter("timeb", b.ToTString()); pars.SetParameter("timeb", b.ToTString());
pars.SetParameter("timee", e.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, ""}; return {tindexes, ""};
} }

Loading…
Cancel
Save