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

proceeding slowly

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: 1488
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 154d1fe0
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sffostream.h,v 1.1 2004-02-14 15:21:22 tforb Exp $
* $Id: sffostream.h,v 1.2 2004-02-14 17:43:49 tforb Exp $
* \author Thomas Forbriger
* \date 10/02/2004
*
......@@ -23,10 +23,11 @@
#define TF_SFFOSTREAM_H_VERSION \
"TF_SFFOSTREAM_H V1.0 "
#define TF_SFFOSTREAM_H_CVSID \
"$Id: sffostream.h,v 1.1 2004-02-14 15:21:22 tforb Exp $"
"$Id: sffostream.h,v 1.2 2004-02-14 17:43:49 tforb Exp $"
#include<sffxx.h>
#include<iostream>
#include<new>
namespace sff {
......@@ -61,6 +62,7 @@ namespace helper {
} // namespace helper
//! SFF output stream
template<class C>
class SFFostream: public helper::ostream_manager {
public:
......@@ -95,6 +97,26 @@ namespace helper {
bool Mhasseries;
}; // class SFFostream
/*
* sorry, this does not work yet
*
//! wrapper class to cunstruct from filename
template<class C>
class SFFofile: public SFFostream<C> {
public:
typedef C Tseries;
typedef typename C::Tcoc Tcseries;
typedef SFFostream<C> Tbase;
SFFofile(const char* ofile):
Tbase(*Mos), Mos(new std::ofstream(ofile)) { }
SFFofile(const std::string& ofile):
Tbase(*Mos), Mos(new std::ofstream(ofile.c_str())) { }
~SFFofile() { delete Mos; }
private:
std::ofstream* Mos;
}; // class SFFofile
*/
template<class C>
SFFostream<C>& operator<<(SFFostream<C>& os, const typename C::Tcoc& c)
{ os.setseries(c); return(os); }
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sffxx.h,v 1.14 2004-02-10 21:15:24 tforb Exp $
* $Id: sffxx.h,v 1.15 2004-02-14 17:43:49 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.14 2004-02-10 21:15:24 tforb Exp $"
"$Id: sffxx.h,v 1.15 2004-02-14 17:43:49 tforb Exp $"
#include<string>
#include<cmath>
......@@ -248,6 +248,7 @@ namespace sff {
const bool& hasfree() const { return(Mdast.hasfree); }
void setlast(const bool& flag) { Mdast.last=flag; }
void setwid2(const WID2& wid2line) { Mwid2=wid2line; }
void setnsamples(const long int& n) { Mwid2.nsamples=n; }
void setinfo(const INFO& infoline)
{ Mdast.hasinfo=true; Minfo=infoline; }
void setfree(const FREE& free)
......@@ -273,7 +274,7 @@ namespace sff {
void write(std::ostream& os) const;
private:
Tcoc Mseries;
TraceHeader Mheader;
mutable TraceHeader Mheader;
}; // class Waveform
template<class C>
......@@ -365,6 +366,7 @@ namespace sff {
inline
void OutputWaveform<C>::write(std::ostream& os) const
{
Mheader.setnsamples(Mseries.size());
Mheader.writeheader(os);;
GSE2::waveform::TDAT2writeCM6 fwriter(Mheader.wid2().nsamples);
int idata;
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sigfit.cc,v 1.7 2004-02-10 21:15:25 tforb Exp $
* $Id: sigfit.cc,v 1.8 2004-02-14 17:43:49 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.7 2004-02-10 21:15:25 tforb Exp $"
"$Id: sigfit.cc,v 1.8 2004-02-14 17:43:49 tforb Exp $"
#include <fstream>
#include <iostream>
......@@ -51,8 +51,18 @@ struct Options {
bool verbose;
double Tdate;
bool truncate;
std::string residualname;
bool writeresidual;
}; // struct Options
// formatted number output
std::string formatfloat(const double &v)
{
char seq[20];
std::sprintf(seq, "%8.5f ", v);
return(std::string(seq));
}
int main(int iargc, char* argv[])
{
......@@ -76,6 +86,7 @@ int main(int iargc, char* argv[])
"-Tdate v tolerance for comparison of date of first sample" "\n"
" v give the tolerance in units of the sampling interval" "\n"
"-truncate truncate all series to the same number of samples" "\n"
"-residual f write waveforms containing residual to file \"f\"" "\n"
"\n"
"signal signal to by explained by a linear combination" "\n"
" of trial signals" "\n"
......@@ -94,6 +105,8 @@ int main(int iargc, char* argv[])
{"Tdate",arg_yes,"0."},
// 3: truncate to a common number of samples
{"truncate",arg_no,"-"},
// 4: output SFF file
{"residual",arg_yes,"-"},
{NULL}
};
......@@ -144,6 +157,8 @@ int main(int iargc, char* argv[])
opt.verbose=cmdline.optset(1);
opt.Tdate=cmdline.double_arg(2);
opt.truncate=cmdline.optset(3);
opt.writeresidual=cmdline.optset(4);
opt.residualname=cmdline.string_arg(4);
/*----------------------------------------------------------------------*/
......@@ -293,23 +308,54 @@ int main(int iargc, char* argv[])
residual=signal-synthetics;
residual.header=signal.header;
residual.header.channel="diff";
// write waveforms
if (opt.writeresidual)
{
if (opt.verbose)
{
cout << "write residual waveform to "
<< opt.residualname << endl;
}
std::ofstream ofs(opt.residualname.c_str());
sff::SFFostream<Tseries> os(ofs);
os << signal;
os << synthetics;
os << residual;
for (Tbundlevec::const_iterator i=bundlevec.begin();
i!=bundlevec.end(); i++)
{ os << *i; }
}
// calculate rms values
double signalrms=ts::rms(signal);
double residualrms=ts::rms(residual);
double explained=1.-(residualrms/signalrms);
cout << "signalrms: " << signalrms << endl;
cout << "residualrms: " << residualrms << endl;
cout << "coefficients: " << endl;
std::string timestring(signal.header.date.timestring());
cout << " time: " << timestring.substr(4,21) << endl;
cout << " channel: " << signal.header.channel << endl;
cout << " station: " << signal.header.station << endl;
cout << " signalrms: " << signalrms << endl;
cout << " residualrms: " << residualrms << endl;
cout << "explained rms: " << explained << endl;
cout << " coefficients: ";
for (int i=1; i<=N; ++i)
{ cout << coeff(i) << " "; }
cout << endl;
std::ofstream ofs("junkname");
sff::SFFostream<Tseries> os(ofs);
os << signal;
os << synthetics;
os << residual;
// reportline
cout << signal.header.station << " "
<< signal.header.channel << " "
<< timestring << " ";
cout << formatfloat(explained);
cout << formatfloat(signalrms);
cout << formatfloat(residualrms);
for (int i=1; i<=N; ++i)
{
cout << formatfloat(coeff(i));
}
cout << endl;
}
/* ----- 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