Commit ebc922fd authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

first interpolators - not very efficient

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1852
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent cebbd9f7
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.13 2005-07-07 11:23:43 tforb Exp $
# $Id: Makefile,v 1.14 2005-07-13 14:41:33 tforb Exp $
#
# Copyright (c) 2003 by Thomas Forbriger (BFO Schiltach)
#
......@@ -13,8 +13,7 @@
HEADERS=$(shell find . -name \*.h)
LIBSRC=tsxx.cc filter.cc seifexx.cc seifeclass.cc \
anyfilter.cc \
filterbase.cc
anyfilter.cc filterbase.cc ipo.cc ipolin.cc
INCINSTALLPATH=$(LOCINCLUDEDIR)/tsxx
LIBINSTALLPATH=$(LOCLIBDIR)
......
......@@ -199,7 +199,7 @@ MULTILINE_CPP_IS_BRIEF = NO
# If set to NO, the detailed description appears after the member
# documentation.
DETAILS_AT_TOP = NO
DETAILS_AT_TOP = YES
# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
# member inherits the documentation from any documented member that it
......@@ -377,7 +377,7 @@ EXCLUDE =
# The EXCLUDE_SYMLINKS tag can be used select whether or not files or directories
# that are symbolic links (a Unix filesystem feature) are excluded from the input.
EXCLUDE_SYMLINKS = NO
EXCLUDE_SYMLINKS = YES
# If the value of the INPUT tag contains directories, you can use the
# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
......@@ -604,7 +604,7 @@ TREEVIEW_WIDTH = 250
# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
# generate Latex output.
GENERATE_LATEX = YES
GENERATE_LATEX = NO
# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
# If a relative path is entered the value of OUTPUT_DIRECTORY will be
......@@ -681,7 +681,7 @@ LATEX_HIDE_INDICES = NO
# The RTF output is optimised for Word 97 and may not look very pretty with
# other RTF readers or editors.
GENERATE_RTF = YES
GENERATE_RTF = NO
# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
# If a relative path is entered the value of OUTPUT_DIRECTORY will be
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: filter.h,v 1.13 2005-07-11 14:56:40 tforb Exp $
* $Id: filter.h,v 1.14 2005-07-13 14:41:34 tforb Exp $
* \author Thomas Forbriger
* \date 05/07/2005
*
......@@ -23,12 +23,21 @@
#define TF_FILTER_H_VERSION \
"TF_FILTER_H V1.0 "
#define TF_FILTER_H_CVSID \
"$Id: filter.h,v 1.13 2005-07-11 14:56:40 tforb Exp $"
"$Id: filter.h,v 1.14 2005-07-13 14:41:34 tforb Exp $"
#include<tsxx/filterbase.h>
namespace ts {
/*! \brief time series filters
*
* \defgroup filter Time series filters
*/
/*! \brief time series filters
*
* \ingroup filter
*/
namespace filter {
/*! \brief remove trend
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: filterbase.h,v 1.4 2005-07-08 07:07:59 tforb Exp $
* $Id: filterbase.h,v 1.5 2005-07-13 14:41:34 tforb Exp $
* \author Thomas Forbriger
* \date 05/07/2005
*
......@@ -23,7 +23,7 @@
#define TF_FILTERBASE_H_VERSION \
"TF_FILTERBASE_H V1.0 "
#define TF_FILTERBASE_H_CVSID \
"$Id: filterbase.h,v 1.4 2005-07-08 07:07:59 tforb Exp $"
"$Id: filterbase.h,v 1.5 2005-07-13 14:41:34 tforb Exp $"
#include<list>
#include<string>
......@@ -38,16 +38,8 @@ namespace ts {
//! we always work in double precision
typedef double Tvalue;
/*! simple header
*/
struct DTHeader {
DTHeader(const Tvalue& sdt): dt(sdt) { }
//! sampling interval
Tvalue dt;
}; // DTHeader
//! the way we use time series
typedef ts::TimeSeries<aff::Series<Tvalue>, DTHeader> Ttimeseries;
//! use double precision time series
typedef ts::TDtimeseries Ttimeseries;
/*! base class for any filter
*
......
/*! \file ipo.cc
* \brief interpolation interface (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: ipo.cc,v 1.1 2005-07-13 14:41:34 tforb Exp $
* \author Thomas Forbriger
* \date 13/07/2005
*
* interpolation interface (implementation)
*
* Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 13/07/2005 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_IPO_CC_VERSION \
"TF_IPO_CC V1.0 "
#define TF_IPO_CC_CVSID \
"$Id: ipo.cc,v 1.1 2005-07-13 14:41:34 tforb Exp $"
#include <tsxx/ipo.h>
namespace ts {
namespace ipo {
//! resample a time series
ts::TDsfftimeseries resample(const Interpolator& ip,
const libtime::TAbsoluteTime& first,
const libtime::TRelativeTime& dt,
const int& n)
{
typedef Interpolator::Ttimeseries Ttimeseries;
typedef Ttimeseries::Theader Theader;
typedef Ttimeseries::Tseries Tseries;
using libtime::TAbsoluteTime;
using libtime::TRelativeTime;
Theader hd=ip.header();
TAbsoluteTime old_first=hd.date;
TAbsoluteTime old_last=sff::wid2lastsample(hd);
TAbsoluteTime new_first=first;
TAbsoluteTime new_last=new_first+(n-1)*dt;
TSXX_assert(((old_first <= new_first) && (old_last >= new_last)),
"new time span is outside time series");
Ttimeseries retval=Ttimeseries(Tseries(n), hd);
retval.header.date=new_first;
retval.header.dt=libtime::time2double(dt);
TAbsoluteTime it=new_first;
for (int i=0; i<n; ++i) { retval(i)=ip(it); it += dt; }
return(retval);
}
} // namespace ipo
} // namespace ts
/* ----- END OF ipo.cc ----- */
/*! \file ipo.h
* \brief interpolation interface (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: ipo.h,v 1.1 2005-07-13 14:41:34 tforb Exp $
* \author Thomas Forbriger
* \date 13/07/2005
*
* interpolation interface (prototypes)
*
* Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 13/07/2005 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef TF_IPO_H_VERSION
#define TF_IPO_H_VERSION \
"TF_IPO_H V1.0 "
#define TF_IPO_H_CVSID \
"$Id: ipo.h,v 1.1 2005-07-13 14:41:34 tforb Exp $"
#include<tsxx/tsxx.h>
namespace ts {
/*! \brief time series interpolation
*
* \defgroup ipo Time series interpolation
*/
/*! \brief time series interpolation
*
* This namespace provides tools for time series interpolation
*
* \ingroup ipo
*/
namespace ipo {
/*! \brief Interface to time series interpolator
*
* \ingroup ipo
*/
class Interpolator {
public:
typedef ts::TDsfftimeseries Ttimeseries;
typedef Ttimeseries::Tconsttimeseries Tconst_timeseries;
typedef Tconst_timeseries::Tseries Tconst_series;
typedef Tconst_timeseries::Theader Theader;
typedef Ttimeseries::Tvalue Tvalue;
virtual ~Interpolator() { }
virtual Tvalue operator()(const libtime::TAbsoluteTime& t) const =0;
Theader header() const { return(Mts.header); }
Tconst_series series() const { return(Mts); }
Tconst_timeseries timeseries() const { return(Mts); }
protected:
Interpolator(Tconst_timeseries ts): Mts(ts) { }
//! here we hold a copy
Tconst_timeseries Mts;
}; // class Interpolator
/*! \brief function to resample data
*
* \param ip reference to a waveform interpolator
* \param first time of first sample in new time series
* \param dt sampling interval of new time series
* \param n number of samples in new time series
* \return resampled time series with time header fields adjusted
*
* \ingroup ipo
*/
ts::TDsfftimeseries resample(const Interpolator& ip,
const libtime::TAbsoluteTime& first,
const libtime::TRelativeTime& dt,
const int& n);
} // namespace ipo
} // namespace ts
#endif // TF_IPO_H_VERSION (includeguard)
/* ----- END OF ipo.h ----- */
/*! \file ipolin.cc
* \brief linear interpolation (implementation)
*
* ----------------------------------------------------------------------------
*
* $Id: ipolin.cc,v 1.1 2005-07-13 14:41:35 tforb Exp $
* \author Thomas Forbriger
* \date 13/07/2005
*
* linear interpolation (implementation)
*
* Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 13/07/2005 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define TF_IPOLIN_CC_VERSION \
"TF_IPOLIN_CC V1.0 "
#define TF_IPOLIN_CC_CVSID \
"$Id: ipolin.cc,v 1.1 2005-07-13 14:41:35 tforb Exp $"
#include <tsxx/ipolin.h>
namespace ts {
namespace ipo {
/*! \brief calculate interpolated value
*
* \param t time for value to return
* \return new sample value at time t
*/
LinearInterpolator::Tvalue
LinearInterpolator::operator()(const libtime::TAbsoluteTime& t)
{
using libtime::TAbsoluteTime;
using libtime::TRelativeTime;
Tconst_series& s=this->Mts.series();
Theader& hd=this->Mts.header;
TAbsoluteTime last=sff::wid2lastsample(hd);
TAbsoluteTime& first=hd.date;
TRelativeTime dt=libtime::double2time(hd.dt);
aff::Tsubscript ileft=s.f()+(t-first)/dt;
TSXX_assert(((t>=first) && (t<=last) && (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;
Tvalue retval=((1.-f)*s(ileft)+f*s(iright));
return(retval);
}
} // namespace ipo
} // namespace ts
/* ----- END OF ipolin.cc ----- */
/*! \file ipolin.h
* \brief linear interpolation (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: ipolin.h,v 1.1 2005-07-13 14:41:35 tforb Exp $
* \author Thomas Forbriger
* \date 13/07/2005
*
* linear interpolation (prototypes)
*
* Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 13/07/2005 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef TF_IPOLIN_H_VERSION
#define TF_IPOLIN_H_VERSION \
"TF_IPOLIN_H V1.0 "
#define TF_IPOLIN_H_CVSID \
"$Id: ipolin.h,v 1.1 2005-07-13 14:41:35 tforb Exp $"
#include<tsxx/ipo.h>
namespace ts {
namespace ipo {
/*! \brief very simple linear interpolator
*
* locates position of new sample and uses linear interpolation between
* neighbouring samples to calculate new value.
*/
class LinearInterpolator: public Interpolator {
public:
typedef Interpolator Tbase;
using Tbase::Ttimeseries;
using Tbase::Tconst_timeseries;
using Tbase::Tconst_series;
using Tbase::Theader;
using Tbase::Tvalue;
LinearInterpolator(const Tconst_timeseries& ts): Tbase(ts) { }
~LinearInterpolator() { }
Tvalue operator()(const libtime::TAbsoluteTime& t);
}; // class LinearInterpolator
} // namespace ipo
} // namespace ts
#endif // TF_IPOLIN_H_VERSION (includeguard)
/* ----- END OF ipolin.h ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: seifexx.h,v 1.6 2005-07-11 09:04:08 tforb Exp $
* $Id: seifexx.h,v 1.7 2005-07-13 14:41:35 tforb Exp $
* \author Thomas Forbriger
* \date 14/01/2005
*
......@@ -24,12 +24,21 @@
#define TF_SEIFEXX_H_VERSION \
"TF_SEIFEXX_H V1.1"
#define TF_SEIFEXX_H_CVSID \
"$Id: seifexx.h,v 1.6 2005-07-11 09:04:08 tforb Exp $"
"$Id: seifexx.h,v 1.7 2005-07-13 14:41:35 tforb Exp $"
#include<aff/series.h>
namespace ts {
/*! \brief interface to seife C-functions
*
* \defgroup seife Interface to seife C-functions
*/
/*! \brief interface to seife C-functions
*
* \ingroup seife
*/
namespace seife {
//! seife functions use double precision
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsxx.cc,v 1.2 2005-01-26 12:35:21 tforb Exp $
* $Id: tsxx.cc,v 1.3 2005-07-13 14:41:35 tforb Exp $
* \author Thomas Forbriger
* \date 19/12/2003
*
......@@ -13,18 +13,102 @@
*
* REVISIONS and CHANGES
* - 19/12/2003 V1.0 Thomas Forbriger
* - 13/07/2005 V1.1 added exception
*
* ============================================================================
*/
#define TF_TSXX_CC_VERSION \
"TF_TSXX_CC V1.0 "
"TF_TSXX_CC V1.1"
#define TF_TSXX_CC_CVSID \
"$Id: tsxx.cc,v 1.2 2005-01-26 12:35:21 tforb Exp $"
"$Id: tsxx.cc,v 1.3 2005-07-13 14:41:35 tforb Exp $"
#include <tsxx.h>
#include <iostream>
#include <tsxx/tsxx.h>
using std::cerr;
using std::endl;
namespace ts {
}
namespace error {
//! initialize and instantiate
bool Exception::Mreport_on_construct=true;
//! construct from nothing
Exception::Exception():
Mmessage(NULL), Mfile(NULL), Mline(0), Mcondition(NULL)
{ if (Mreport_on_construct) { report(); } }
//! construct with message
Exception::Exception(const char* message):
Mmessage(message), Mfile(NULL), Mline(0), Mcondition(NULL)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* condition):
Mmessage(message), Mfile(NULL), Mline(0), Mcondition(condition)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* file,
const int& line):
Mmessage(message), Mfile(file), Mline(line), Mcondition(NULL)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info and condition
Exception::Exception(const char* message,
const char* file,
const int& line,
const char* condition):
Mmessage(message), Mfile(file), Mline(line), Mcondition(condition)
{ if (Mreport_on_construct) { report(); } }
//! switch on
void Exception::report_on_construct()
{
Mreport_on_construct=true;
}
//! switch off
void Exception::dont_report_on_construct()
{
Mreport_on_construct=false;
}
//! report
void Exception::report() const
{
base_report();
}
//! report
void Exception::base_report() const
{
cerr << "Exception report:" << endl;
if (Mmessage==NULL)
{
cerr << " No message" << endl;
}
else
{
cerr << " message: " << Mmessage << endl;
}
if (Mfile!=NULL)
{
cerr << " triggered in \"" << Mfile << "\" at line #" << Mline << endl;
}
if (Mcondition!=NULL)
{
cerr << " by condition:" << endl
<< " \"" << Mcondition << "\"" << endl;
}
}
} // namespace error
} // namespace ts
/* ----- END OF tsxx.cc ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsxx.h,v 1.6 2005-01-26 16:05:38 tforb Exp $
* $Id: tsxx.h,v 1.7 2005-07-13 14:41:35 tforb Exp $
* \author Thomas Forbriger
* \date 19/12/2003
*
......@@ -16,6 +16,7 @@
* - 10/02/2004 V1.1
* - deleted all old code
* - started from scratch with TimeSeries
* - 13/07/2005 V1.2 added exception
*
* ============================================================================
*/
......@@ -24,14 +25,15 @@
#ifndef TF_TSXX_H_VERSION
#define TF_TSXX_H_VERSION \
"TF_TSXX_H V1.0 "
"TF_TSXX_H V1.2"
#define TF_TSXX_H_CVSID \
"$Id: tsxx.h,v 1.6 2005-01-26 16:05:38 tforb Exp $"
"$Id: tsxx.h,v 1.7 2005-07-13 14:41:35 tforb Exp $"
#include<aff/series.h>
#include<sffostream.h>
//! All stuff in this library will be placed within namespace ts
/*! \brief All stuff in this library will be placed within namespace ts
*/
namespace ts {
/*! \brief Structure to hold the data samples of a series together with
......@@ -83,6 +85,9 @@ namespace ts {
Theader header;
}; // struct TimeSeries
/*----------------------------------------------------------------------*/
// SFF version
//! write an SFF bundle to an SFF output stream
template<class C>
sff::SFFostream<C>&
......@@ -95,8 +100,129 @@ namespace ts {
//! single precision data with SFF header
typedef TimeSeries<aff::Series<float>, sff::WID2> TSsfftimeseries;
/*----------------------------------------------------------------------*/
// generic version
/*! \brief simple header
*
* Adding a sampling interval to a series qualifies it to represent a time
* series. That's the bare minimum required to make a time series.
*/
template<class T>
struct DTHeader {
typedef T Tvalue;
DTHeader(const Tvalue& sdt): dt(sdt) { }
//! sampling interval
Tvalue dt;
}; // DTHeader
//! double precision version of simple time series
typedef ts::TimeSeries<aff::Series<double>, DTHeader<double> > TDtimeseries;
//! single precision version of simple time series
typedef ts::TimeSeries<aff::Series<float>, DTHeader<float> > TStimeseries;
//! write a generic bundle to an SFF output stream
template<class T>
sff::SFFostream<aff::Series<T> >&
operator<<(sff::SFFostream<aff::Series<T> >& os,
const TimeSeries<aff::Series<T>, DTHeader<T> >& b)
{ os << C(b) << b.header; return(os); }
/*----------------------------------------------------------------------*/
// assertions
namespace error {
/*! \brief Base class for exceptions
*
* This is an exception base class. It holds some information about the
* reason for throwing the exception. The information is printed to cerr
* through function report(). This function may be overloaded by a derived
* type. But its functionality is still accessible through base_report().
*
* The standard behaviour is to print ou the message during object
* initialization. If you don't like this, call dont_report_on_construct().
*
* \ingroup group_error
* \sa TFXX_Xassert
*/
class Exception
{