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

introduced new concept of ts::TimeSeries

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.
and of sff::SFFostream


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1486
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 04fcb2db
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.8 2004-02-07 17:38:12 tforb Exp $
# $Id: Makefile,v 1.9 2004-02-10 21:15:23 tforb Exp $
#
# Copyright (c) 2003 by Thomas Forbriger (BFO Schiltach)
#
......@@ -49,8 +49,8 @@ clean: ;
# ------------
LIBSRC=sffxx.cc wid2compare.cc wid2inrange.cc wid2isample.cc \
wid2lastsample.cc
INCSRC=sffxx.h
wid2lastsample.cc sffistream.cc sffostream.cc
INCSRC=sffxx.h sffostream.h sffistream.h
-include $(patsubst %.cc,%.d,$(LIBSRC))
......@@ -59,7 +59,7 @@ libsffxx.a: $(patsubst %.cc,%.o,$(LIBSRC))
ranlib $@
newlib $@
install-include: ; newinclude sffxx.h
install-include: ; newinclude $(INCSRC)
#======================================================================
# documentation part
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sffxx.h,v 1.13 2004-02-07 17:38:12 tforb Exp $
* $Id: sffxx.h,v 1.14 2004-02-10 21:15:24 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2003
*
......@@ -29,7 +29,7 @@
#define TF_SFFXX_H_VERSION \
"TF_SFFXX_H V1.2 "
#define TF_SFFXX_H_CVSID \
"$Id: sffxx.h,v 1.13 2004-02-07 17:38:12 tforb Exp $"
"$Id: sffxx.h,v 1.14 2004-02-10 21:15:24 tforb Exp $"
#include<string>
#include<cmath>
......@@ -43,6 +43,16 @@
*/
namespace sff {
/*======================================================================*/
// basic error handling
// --------------------
class Terror: public GSE2::Terror
{
public:
Terror(char* message): GSE2::Terror(message) { }
}; // class Terror
/*======================================================================*/
// enum
// ----
......@@ -89,6 +99,7 @@ namespace sff {
FREE(std::istream& is) { read(is); }
void write(std::ostream& os) const;
void read(std::istream& is);
void append(const std::string& line) { lines.push_back(line); }
Tlines lines;
}; // struct FREE
......@@ -180,6 +191,8 @@ namespace sff {
const bool& hasfree() const { return(Mstat.hasfree); }
void appendfree(const std::string& line)
{ Mstat.hasfree=true; Mfree.lines.push_back(line); }
void setfree(const FREE& free)
{ Mstat.hasfree=true; Mfree=free; }
void setsrce(const SRCE& srce)
{ Mstat.hassrce=true; Msrce=srce; }
private:
......@@ -237,6 +250,8 @@ namespace sff {
void setwid2(const WID2& wid2line) { Mwid2=wid2line; }
void setinfo(const INFO& infoline)
{ Mdast.hasinfo=true; Minfo=infoline; }
void setfree(const FREE& free)
{ Mdast.hasfree=true; Mfree=free; }
void appendfree(const std::string& line)
{ Mdast.hasfree=true; Mfree.lines.push_back(line); }
private:
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: wid2isample.cc,v 1.1 2004-02-07 17:38:13 tforb Exp $
* $Id: wid2isample.cc,v 1.2 2004-02-10 21:15:24 tforb Exp $
* \author Thomas Forbriger
* \date 06/02/2004
*
......@@ -19,7 +19,7 @@
#define TF_WID2ISAMPLE_CC_VERSION \
"TF_WID2ISAMPLE_CC V1.0 "
#define TF_WID2ISAMPLE_CC_CVSID \
"$Id: wid2isample.cc,v 1.1 2004-02-07 17:38:13 tforb Exp $"
"$Id: wid2isample.cc,v 1.2 2004-02-10 21:15:24 tforb Exp $"
#include <sffxx.h>
......@@ -29,7 +29,7 @@ namespace sff {
long int wid2isample(const WID2& wid2,
const libtime::TAbsoluteTime& idate)
{
libtime::TRelativeTime dt=double2time(wid2.dt);
libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
long int retval=(idate-wid2.date)/dt;
return(retval);
}
......@@ -38,7 +38,7 @@ namespace sff {
libtime::TAbsoluteTime wid2isample(const WID2& wid2,
const long int& i)
{
libtime::TRelativeTime dt=double2time(wid2.dt);
libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
libtime::TAbsoluteTime retval=wid2.date+i*dt;
return(retval);
}
......@@ -47,7 +47,7 @@ namespace sff {
libtime::TRelativeTime wid2isamplerest(const WID2& wid2,
const libtime::TAbsoluteTime& idate)
{
libtime::TRelativeTime dt=double2time(wid2.dt);
libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
libtime::TRelativeTime retval=(idate-wid2.date)/dt;
return(retval);
}
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: bundles.h,v 1.2 2004-02-10 16:05:00 tforb Exp $
* $Id: bundles.h,v 1.3 2004-02-10 21:15:24 tforb Exp $
* \author Thomas Forbriger
* \date 28/01/2004
*
......@@ -23,7 +23,7 @@
#define TF_BUNDLES_H_VERSION \
"TF_BUNDLES_H V1.0 "
#define TF_BUNDLES_H_CVSID \
"$Id: bundles.h,v 1.2 2004-02-10 16:05:00 tforb Exp $"
"$Id: bundles.h,v 1.3 2004-02-10 21:15:24 tforb Exp $"
#include<aff/series.h>
#include<sffxx.h>
......@@ -42,6 +42,16 @@ namespace ts {
S series;
}; // struct Bundle
//! write a bundle to an output stream
template<class T>
sff::SFFostream<aff::Series<T> >&
operator<<(sff::SFFostream<aff::Series<T> >& os,
const Bundle<sff::WID2, aff::Series<T> >& b)
{
os << b.header << b.series;
return(os);
}
//! write a bundle to an output stream
template<class T>
std::ostream& operator<<(std::ostream& os,
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tsxx.h,v 1.3 2004-02-02 09:42:31 tforb Exp $
* $Id: tsxx.h,v 1.4 2004-02-10 21:15:25 tforb Exp $
* \author Thomas Forbriger
* \date 19/12/2003
*
......@@ -13,6 +13,9 @@
*
* REVISIONS and CHANGES
* - 19/12/2003 V1.0 Thomas Forbriger
* - 10/02/2004 V1.1
* - deleted all old code
* - started from scratch with TimeSeries
*
* ============================================================================
*/
......@@ -23,67 +26,46 @@
#define TF_TSXX_H_VERSION \
"TF_TSXX_H V1.0 "
#define TF_TSXX_H_CVSID \
"$Id: tsxx.h,v 1.3 2004-02-02 09:42:31 tforb Exp $"
"$Id: tsxx.h,v 1.4 2004-02-10 21:15:25 tforb Exp $"
#include<aff/series.h>
#include<sffostream.h>
//! All stuff in this library will be placed within namespace ts
namespace ts {
class Header
{
public:
Header(): Mt0(0.), Mdt(1.) { }
Header(const double& d): Mt0(0.), Mdt(d) { }
private:
double Mt0;
double Mdt;
}; // class Header
/*! \brief A structure to conatin a time series
*
* \param T type of sample value (int, double, etc.)
* \param C series container type (usually aff::Series)
*/
template<class T, class H, class C=aff::Series<T> >
class ConstWaveform
{
public:
typedef C Tseries;
typedef typename Tseries::Tcoc Tconst_series;
template<class S, class H>
struct TimeSeries: public S
{
public:
ConstWaveform(const H& h, const C& c):
Mheader(h), Mseries(c) { }
const Tconst_series& series() const { return(Mseries); }
protected:
H Mheader;
C Mseries;
}; // template class ConstWaveform
typedef S Tseries;
typedef H Theader;
typedef typename Tseries::Tvalue Tvalue;
typedef typename Tseries::Tcoc Tcoc;
typedef TimeSeries<Tseries, Theader> Ttimeseries;
TimeSeries() { }
TimeSeries(const Tseries& s): Tseries(s) { }
TimeSeries(const Theader& h): header(h) { }
TimeSeries(const Tseries& s, const Theader& h):
Tseries(s), header(h) { }
Tseries& series() { return(*this); }
Ttimeseries& operator=(const Tseries& s)
{ this->Tseries::operator=(s); return(*this); }
operator TimeSeries<Tcoc, Theader>() const
{ return(TimeSeries<Tcoc, Theader>(*this, header)); }
Theader header;
}; // struct TimeSeries
/*! \brief A structure to conatin a time series
*
* \param T type of sample value (int, double, etc.)
* \param C series container type (usually aff::Series)
*/
template<class T, class H, class C>
class Waveform:
public ConstWaveform<T, H, C>
{
typedef aff::Series<T> Tbase;
using Tbase::size;
using Tbase::first;
using Tbase::last;
using Tbase::operator();
Waveform() { Mt0=0.; Mdt=1.; }
Waveform(const int& n, const double& d=1.):
Tbase(n) { Mt0=0.; Mdt=1.; }
Waveform(const Tbase& s, const double& d=1.):
Tbase(s) { Mt0=0.; Mdt=1.; }
operator aff::ConstSeries<T>() const { return(*this); }
double Mt0;
double Mdt;
}; // template class Waveform
//! write a bundle to an output stream
template<class C>
sff::SFFostream<C>&
operator<<(sff::SFFostream<C>& os,
const TimeSeries<C, sff::WID2>& b)
{ os << b.header << C(b); return(os); }
// define bundle typedefs
typedef TimeSeries<aff::Series<double>, sff::WID2> TDsfftimeseries;
typedef TimeSeries<aff::Series<float>, sff::WID2> TSsfftimeseries;
} // namespace ts
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sigfit.cc,v 1.6 2004-02-10 16:05:00 tforb Exp $
* $Id: sigfit.cc,v 1.7 2004-02-10 21:15:25 tforb Exp $
* \author Thomas Forbriger
* \date 28/01/2004
*
......@@ -19,7 +19,7 @@
#define SIGFIT_VERSION \
"SIGFIT V1.0 fit signal by trial-signals"
#define SIGFIT_CVSID \
"$Id: sigfit.cc,v 1.6 2004-02-10 16:05:00 tforb Exp $"
"$Id: sigfit.cc,v 1.7 2004-02-10 21:15:25 tforb Exp $"
#include <fstream>
#include <iostream>
......@@ -28,7 +28,8 @@
#include <tfxx/commandline.h>
#include <tfxx/error.h>
#include <sffxx.h>
#include <tsxx/bundles.h>
#include <sffostream.h>
#include <tsxx/tsxx.h>
#include <tsxx/innerproduct.h>
#include <aff/array.h>
#include <aff/dump.h>
......@@ -36,7 +37,7 @@
#include <linearxx/lapackxx.h>
typedef std::list<std::string> Tnamelist;
typedef ts::TDsffbundle Tbundle;
typedef ts::TDsfftimeseries Tbundle;
typedef Tbundle::Tseries Tseries;
typedef std::vector<Tbundle> Tbundlevec;
typedef aff::Array<Tbundle::Tseries::Tvalue> Tmatrix;
......@@ -166,7 +167,7 @@ int main(int iargc, char* argv[])
sff::InputWaveform<Tseries> inputwaveform(is);
sff::TraceHeader traceheader=inputwaveform.header();
signal.header=traceheader.wid2();
signal.series=inputwaveform.series();
signal=inputwaveform.series();
bool last=traceheader.last();
std::string wid2line=signal.header.line();
if (opt.verbose)
......@@ -199,7 +200,7 @@ int main(int iargc, char* argv[])
sff::TraceHeader traceheader=inputwaveform.header();
Tbundle bundle;
bundle.header=traceheader.wid2();
bundle.series=inputwaveform.series();
bundle=inputwaveform.series();
bundlevec.push_back(bundle);
last=traceheader.last();
std::string wid2line=bundle.header.line();
......@@ -214,24 +215,24 @@ int main(int iargc, char* argv[])
if (opt.truncate)
{
if (opt.verbose) { cout << "truncate signals if necessary..." << endl; }
long int n=signal.series.last();
long int n=signal.last();
for (Tbundlevec::const_iterator i=bundlevec.begin();
i!=bundlevec.end(); i++)
{ n=n<i->series.last() ? n : i->series.last(); }
if (signal.series.last()>n)
{ n=n<i->last() ? n : i->last(); }
if (signal.last()>n)
{
signal.series.setlastindex(n);
signal.header.nsamples=signal.series.size();
signal.setlastindex(n);
signal.header.nsamples=signal.size();
if (opt.verbose) { cout << "truncate signal to "
<< signal.header.nsamples << " samples" << endl; }
}
for (Tbundlevec::iterator i=bundlevec.begin();
i!=bundlevec.end(); i++)
{
if (i->series.last()>n)
if (i->last()>n)
{
i->series.setlastindex(n);
i->header.nsamples=signal.series.size();
i->setlastindex(n);
i->header.nsamples=signal.size();
if (opt.verbose) { cout << "truncate trial signal" << endl
<< i->header.line() << endl; }
}
......@@ -268,11 +269,10 @@ int main(int iargc, char* argv[])
{
for (int k=i; k<=N; ++k)
{
Matrix(i,k)=ts::innerproduct(bundlevec[i-1].series,
bundlevec[k-1].series);
Matrix(i,k)=ts::innerproduct(bundlevec[i-1], bundlevec[k-1]);
Matrix(k,i)=Matrix(i,k);
}
rhs(i)=ts::innerproduct(bundlevec[i-1].series, signal.series);
rhs(i)=ts::innerproduct(bundlevec[i-1], signal);
}
// solve
......@@ -280,23 +280,23 @@ int main(int iargc, char* argv[])
// set up synthetics
Tbundle synthetics;
synthetics.series=Tseries(signal.series.shape());
synthetics.series=0;
synthetics=Tseries(signal.shape());
synthetics.series()=0.;
for (int i=1; i<=N; ++i)
{ synthetics.series += coeff(i) * bundlevec[i-1].series; }
{ synthetics += coeff(i) * bundlevec[i-1]; }
synthetics.header=signal.header;
synthetics.header.channel="synt";
// set up residual
Tbundle residual;
residual.series=Tseries(signal.series.shape());
residual.series=signal.series-synthetics.series;
residual=Tseries(signal.shape());
residual=signal-synthetics;
residual.header=signal.header;
residual.header.channel="diff";
// calculate rms values
double signalrms=ts::rms(signal.series);
double residualrms=ts::rms(residual.series);
double signalrms=ts::rms(signal);
double residualrms=ts::rms(residual);
cout << "signalrms: " << signalrms << endl;
cout << "residualrms: " << residualrms << endl;
......@@ -305,12 +305,11 @@ int main(int iargc, char* argv[])
{ cout << coeff(i) << " "; }
cout << endl;
std::ofstream os("junkname");
sff::FileHeader fileheader;
os << fileheader;
std::ofstream ofs("junkname");
sff::SFFostream<Tseries> os(ofs);
os << signal;
os << synthetics;
os << ts::lastbundle(residual);
os << residual;
}
/* ----- END OF sigfit.cc ----- */
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