TS++ library: time series library
ipolin.cc
Go to the documentation of this file.
1 
35 #define TF_IPOLIN_CC_VERSION \
36  "TF_IPOLIN_CC V1.1"
37 
38 #include<iostream>
39 #include <tsxx/ipolin.h>
40 #include <tsxx/debug.h>
41 
42 namespace ts {
43 
44  namespace ipo {
45 
49  const bool& debug):
50  Tbase(ts, debug),
51  Mlast(sff::wid2lastsample(Mts.header)),
52  Mdt(libtime::double2time(Mts.header.dt)),
53  Madjustedfirst(Mts.header.date+(Mdt/2)),
54  Minputwindow(Mts.header.date,Mlast)
55  {
56  TSXX_debug(this->debug(),
57  "LinearInterpolator::LinearInterpolatorperator(...):",
58  TSXX_value(ts.first()) << " " <<
59  TSXX_value(ts.last()) << " "
60  << std::endl <<
61  " " << TSXX_value(Mts.header.date.timestring())
62  << std::endl <<
63  " " << TSXX_value(Mlast.timestring())
64  << std::endl <<
65  " " << TSXX_value(Mdt.timestring())
66  << std::endl <<
67  " " << TSXX_value(Madjustedfirst.timestring())
68  );
69  } // LinearInterpolator::LinearInterpolator(...)
70 
71  /*----------------------------------------------------------------------*/
72 
79  LinearInterpolator::operator()(const libtime::TAbsoluteTime& t) const
80  {
81  using libtime::TAbsoluteTime;
82  using libtime::TRelativeTime;
83  const Tconst_series& s=this->Mts;
84  const Theader& hd=this->Mts.header;
85  //aff::Tsubscript ileft=s.f()+int(libtime::time2double(t-first)/hd.dt);
86  /*
87  * Notice that the division in libtime is defined to return the number
88  * of samples that will come closest to the time interval. That means
89  * that the operator round to the nearest integer and not to the lower
90  * integer. For this reason we use the adjusted time of first sample.
91  */
92  aff::Tsubscript ileft=s.first()+(t-Madjustedfirst)/Mdt;
93  TSXX_assert((Minputwindow.includes(t) && (ileft<=s.last())),
94  "requested sample lies outside time series");
95  aff::Tsubscript iright= (ileft < s.last()) ? ileft+1 : ileft;
96  double f=libtime::time2double(t-sff::wid2isample(hd, ileft-s.f()))/hd.dt;
97  TSXX_debug(this->debug(), "LinearInterpolator::operator():",
98  TSXX_value(ileft) << " " <<
99  TSXX_value(iright) << " " <<
100  TSXX_value(s.f()) << " " <<
101  TSXX_value(f) << " " <<
102  TSXX_value(hd.dt) << std::endl <<
103  " " << TSXX_value(Mdt.timestring())
104  << std::endl <<
105  " " << TSXX_value(Madjustedfirst.timestring())
106  << std::endl <<
107  " " << TSXX_value(sff::wid2isample(hd, ileft-s.f()).timestring())
108  << std::endl <<
109  " " << TSXX_value(t.timestring())
110  << std::endl <<
111  " " << TSXX_value(sff::wid2isample(hd, iright-s.f()).timestring())
112  << std::endl <<
113  " " << TSXX_value((t-Madjustedfirst).timestring())
114  << std::endl <<
115  " " << TSXX_value((t-Madjustedfirst)/Mdt)
116  );
117  Tvalue retval=((1.-f)*s(ileft)+f*s(iright));
118  return(retval);
119  }
120 
121  } // namespace ipo
122 
123 } // namespace ts
124 
125 /* ----- END OF ipolin.cc ----- */
Tconst_timeseries Mts
here we hold a copy
Definition: ipo.h:131
debug macro (prototypes)
Tconst_timeseries::Theader Theader
Definition: ipo.h:118
linear interpolation (prototypes)
LinearInterpolator(const Tconst_timeseries &ts, const bool &debug=false)
initialize the linear interpolator
Definition: ipolin.cc:48
#define TSXX_value(V)
report value
Definition: debug.h:66
libtime::TAbsoluteTime Madjustedfirst
Definition: ipolin.h:67
Ttimeseries::Tvalue Tvalue
Definition: ipo.h:119
#define TSXX_debug(C, N, M)
produce debug output
Definition: debug.h:51
libtime::TAbsoluteTime Mlast
Definition: ipolin.h:65
libtime::TRelativeTime Mdt
Definition: ipolin.h:66
Interface to time series interpolator.
Definition: ipo.h:113
Structure to hold the data samples of a series together with header information to form a time series...
Definition: tsxx.h:83
Tvalue operator()(const libtime::TAbsoluteTime &t) const
calculate interpolated value
Definition: ipolin.cc:79
All stuff in this library will be placed within namespace ts.
Definition: anyfilter.cc:43
libtime::TRange Minputwindow
Definition: ipolin.h:68
Theader header
data header fields
Definition: tsxx.h:134
bool debug() const
indicate whether interpolator is in debug mode
Definition: ipo.h:126
#define TSXX_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:127
Ttimeseries::Tvalue Tvalue
Definition: ipo.h:119
Tconst_timeseries::Tseries Tconst_series
Definition: ipo.h:117