Commit c5b4dc04 authored by thomas.forbriger's avatar thomas.forbriger
Browse files

libtsxx [FIX]: fix sample time calculation in interpolator

The calculation of the time of the current sample failed to handle time series
containers where the index of the first sample was finite. A finite first
sample index is a standard feature supported by libaff.
parent 48623bda
......@@ -28,11 +28,12 @@
*
* REVISIONS and CHANGES
* - 13/07/2005 V1.0 Thomas Forbriger
* - 14/11/2017 V1.1 fix index value error in calculation of sample time
*
* ============================================================================
*/
#define TF_IPOLIN_CC_VERSION \
"TF_IPOLIN_CC V1.0 "
"TF_IPOLIN_CC V1.1"
#include<iostream>
#include <tsxx/ipolin.h>
......@@ -88,23 +89,30 @@ namespace ts {
* that the operator round to the nearest integer and not to the lower
* integer. For this reason we use the adjusted time of first sample.
*/
aff::Tsubscript ileft=s.f()+(t-Madjustedfirst)/Mdt;
aff::Tsubscript ileft=s.first()+(t-Madjustedfirst)/Mdt;
TSXX_assert((Minputwindow.includes(t) && (ileft<=s.last())),
"requested sample lies outside time series");
aff::Tsubscript iright= (ileft < s.l()) ? ileft+1 : ileft;
double f=libtime::time2double(t-sff::wid2isample(hd, ileft))/hd.dt;
aff::Tsubscript iright= (ileft < s.last()) ? ileft+1 : ileft;
double f=libtime::time2double(t-sff::wid2isample(hd, ileft-s.f()))/hd.dt;
TSXX_debug(this->debug(), "LinearInterpolator::operator():",
TSXX_value(ileft) << " " <<
TSXX_value(iright) << " " <<
TSXX_value(f) << " " <<
TSXX_value(hd.dt) << std::endl <<
" " << TSXX_value(Mdt.timestring())
<< std::endl <<
" " << TSXX_value(sff::wid2isample(hd, ileft).timestring())
<< std::endl <<
" " << TSXX_value(t.timestring())
<< std::endl <<
" " << TSXX_value(sff::wid2isample(hd, iright).timestring())
TSXX_value(ileft) << " " <<
TSXX_value(iright) << " " <<
TSXX_value(s.f()) << " " <<
TSXX_value(f) << " " <<
TSXX_value(hd.dt) << std::endl <<
" " << TSXX_value(Mdt.timestring())
<< std::endl <<
" " << TSXX_value(Madjustedfirst.timestring())
<< std::endl <<
" " << TSXX_value(sff::wid2isample(hd, ileft-s.f()).timestring())
<< std::endl <<
" " << TSXX_value(t.timestring())
<< std::endl <<
" " << TSXX_value(sff::wid2isample(hd, iright-s.f()).timestring())
<< std::endl <<
" " << TSXX_value((t-Madjustedfirst).timestring())
<< std::endl <<
" " << TSXX_value((t-Madjustedfirst)/Mdt)
);
Tvalue retval=((1.-f)*s(ileft)+f*s(iright));
return(retval);
......
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