Commit 5828a100 authored by thomas.forbriger's avatar thomas.forbriger
Browse files

libtsxx [WP][FEATURE]: provide function TimeSeriesCollection::overlap

parent ea762cda
......@@ -80,6 +80,27 @@ namespace ts {
* of time series headers in the collection
*/
bool are_consistent(const ::sff::WID2compare comparer) const;
/*! \brief Check is all time series have a common time window
*
* Check whether all time series overlap in time. This is a necessary
* prerequisite for trimming all time series to a common time window.
*
* \return true, if time series overlap
*/
bool overlap() const;
/*! \brief Trim to same start time
*
* Check the consistency of the time series in the collections based on
* header data. For example this can be used to check whether all time
* series have the same number of samples.
*
* \param comparer defines the header fields to be compared
* \return true, if comparer returns true for comparison of all pairs
* of time series headers in the collection
*/
bool trim_to_date(const ::sff::WID2compare comparer) const;
}; // class TimeSeriesCollection
......@@ -103,6 +124,36 @@ namespace ts {
return(retval);
} // bool TimeSeriesCollection<T>::are_consistent(const ::sff::WID2compare comparer) const
/* ---------------------------------------------------------------------- */
template<typename T>
bool TimeSeriesCollection<T>::overlap() const
{
bool retval=true;
if (this->size() > 1)
{
typename Tbase::const_iterator i_series=this->begin();
Theader header=i_series->header;
libtime::TAbsoluteTime begin=header.date;
libtime::TRelativeTime dt=libtime::double2time(header.dt);
libtime::TAbsoluteTime end=header.date+(dt*(header.nsamples-1));
++i_series;
while ((i_series != this->end()) && retval)
{
header=i_series->header;
libtime::TAbsoluteTime thisbegin=header.date;
libtime::TRelativeTime thisdt=libtime::double2time(header.dt);
libtime::TAbsoluteTime thisend=
header.date+(thisdt*(header.nsamples-1));
begin = thisbegin > begin ? thisbegin : begin;
end = thisend < end ? thisend : end;
++i_series;
}
retval=(end >= begin);
}
return(retval);
} // bool TimeSeriesCollection<T>::overlap() const
} // namespace ts
#endif // TS_TSCOLLECTION_H_VERSION (includeguard)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment