TS++ library: time series library
ipo.cc
Go to the documentation of this file.
1 
39 #define TF_IPO_CC_VERSION \
40  "TF_IPO_CC V1.2"
41 
42 #include <tsxx/ipo.h>
43 #include <tsxx/debug.h>
44 
45 namespace ts {
46 
47  namespace ipo {
48 
49  // exception constructor
51  const char* file,
52  const int& line,
53  const char* cond)
54  : Exception(message, file, line, cond)
55  { }
56 
57  /* ----------------------------------------------------------------------
58  */
59 
60  // exception constructor
62  const char* file,
63  const int& line,
64  const char* cond)
65  : Exception(message, file, line, cond)
66  { }
67 
68  /* ======================================================================
69  */
70 
73  const libtime::TAbsoluteTime& first,
74  const libtime::TRelativeTime& dt,
75  const int& n,
76  const bool& shrink)
77  {
79  typedef Ttimeseries::Theader Theader;
81  using libtime::TAbsoluteTime;
82  using libtime::TRelativeTime;
83  using libtime::TRange;
84  Theader hd=ip.header();
85  TAbsoluteTime old_first=hd.date;
86  TAbsoluteTime old_last=sff::wid2lastsample(hd);
87  TAbsoluteTime new_first=first;
88  TAbsoluteTime new_last=new_first+(n-1)*dt;
89  int nsamples=n;
90  // if requested, shrink time window to available data
91  if (shrink)
92  {
93  if (old_first > new_first)
94  {
95  int noff=(old_first-new_first)/dt;
96  new_first += (dt*noff);
97  nsamples -= noff;
98  while (new_first < old_first) { new_first += dt; nsamples--; }
99  }
100  if (old_last < new_last)
101  {
102  int noff=(new_last-old_last)/dt;
103  new_last -= (dt*noff);
104  nsamples -= noff;
105  while (new_last > old_last) { new_last -= dt; nsamples--; }
106  }
107  TSXX_Xassert(nsamples > 0,
108  "new time window is empty",
110  }
111  TSXX_debug(ip.debug(), "resample",
112  "window covered by input series:\n "
113  << old_first.timestring() << " - "
114  << old_last.timestring());
115  TSXX_debug(ip.debug(), "resample",
116  "window requested for output series:\n "
117  << new_first.timestring() << " - "
118  << new_last.timestring());
119  TRange inputwindow(old_first, old_last);
120  TRange outputwindow(new_first, new_last);
121  TSXX_Xassert((inputwindow.includes(outputwindow)),
122  "new time span is outside time series",
124  Ttimeseries retval=Ttimeseries(Tseries(nsamples), hd);
125  retval.header.date=new_first;
126  retval.header.nsamples=nsamples;
127  retval.header.dt=libtime::time2double(dt);
128  TAbsoluteTime it=new_first;
129  for (int i=0; i<nsamples; ++i) { retval(i)=ip(it); it += dt; }
130  return(retval);
131  } // ts::TDsfftimeseries resample(...)
132 
133  } // namespace ipo
134 
135 } // namespace ts
136 
137 
138 /* ----- END OF ipo.cc ----- */
Exception in case time windows are not overlapping.
Definition: ipo.h:69
void first(const Tseries &s)
Definition: seifexx.cc:117
debug macro (prototypes)
Exception in case resulting time window is empty.
Definition: ipo.h:87
Theader header() const
Definition: ipo.h:122
#define TSXX_debug(C, N, M)
produce debug output
Definition: debug.h:51
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
ts::TDsfftimeseries resample(const Interpolator &ip, const libtime::TAbsoluteTime &first, const libtime::TRelativeTime &dt, const int &n, const bool &shrink)
resample a time series
Definition: ipo.cc:72
ts::TDtimeseries Ttimeseries
use double precision time series
Definition: filterbase.h:56
All stuff in this library will be placed within namespace ts.
Definition: anyfilter.cc:43
Ttimeseries::Tseries Tseries
Definition: filter.cc:84
bool debug() const
indicate whether interpolator is in debug mode
Definition: ipo.h:126
#define TSXX_Xassert(C, M, E)
Check an assertion and report by throwing an exception.
Definition: error.h:118
interpolation interface (prototypes)
ExceptionTimeWindowEmpty(const char *message, const char *file, const int &line, const char *condition)
Definition: ipo.cc:61
ExceptionTimeWindowOutside(const char *message, const char *file, const int &line, const char *condition)
Definition: ipo.cc:50