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

new code

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: 1631
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 8bd01dbf
# ---------------------------------------
#
# $Id: Makefile,v 1.23 2005-01-26 17:52:13 tforb Exp $
# $Id: Makefile,v 1.24 2005-02-01 14:49:52 tforb Exp $
#
# Makefile fuer tools /src/ts/wf
#
......@@ -57,7 +57,7 @@ phasedsignals hamres siggen smoos dise: %: %.o
-L$(LOCLIBDIR)
newprog $@
cross tidofi fredofi sigfit: %: %.o
autocorr cross tidofi fredofi sigfit: %: %.o
$(CXX) -o $@ $^ -I$(LOCINCLUDEDIR) -lsffxx -llinearxx -lgsexx -laff \
-ltsxx -ldatreadxx -ltfxx -ltime++ \
-llapack -lblas -lg2c -lm\
......
/*! \file autocorr.cc
* \brief autocorrelation
*
* ----------------------------------------------------------------------------
*
* $Id: autocorr.cc,v 1.1 2005-02-01 14:49:52 tforb Exp $
* \author Thomas Forbriger
* \date 01/02/2005
*
* autocorrelation
*
* Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 01/02/2005 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define AUTOCORR_VERSION \
"AUTOCORR V1.0 autocorrelation"
#define AUTOCORR_CVSID \
"$Id: autocorr.cc,v 1.1 2005-02-01 14:49:52 tforb Exp $"
#include <fstream>
#include <iostream>
#include <list>
#include <string>
#include <tfxx/commandline.h>
#include <tfxx/error.h>
#include <sffxx.h>
#include <tsxx/tsxx.h>
#include <tsxx/correlate.h>
#include <datreadxx/sff.h>
#include <aff/seriesoperators.h>
using std::cout;
using std::cerr;
using std::endl;
typedef std::list<std::string> Tnames;
typedef ts::TDsfftimeseries Tts;
struct Options {
bool verbose, overwrite, debug;
}; // struct Options
int main(int iargc, char* argv[])
{
// define usage information
char usage_text[]=
{
AUTOCORR_VERSION "\n"
"usage: autocorr -v -o -D file [file [...]] outfile" "\n"
" or: autocorr --help|-h" "\n"
};
// define full help text
char help_text[]=
{
AUTOCORR_CVSID "\n"
"\n"
"-v be verbose" "\n"
"-D debug mode" "\n"
"-o overwrite existing output file" "\n"
"file ... input file(s)" "\n"
"outfile output file" "\n"
};
// define commandline options
using namespace tfxx::cmdline;
static Declare options[]=
{
// 0: print help
{"help",arg_no,"-"},
// 1: verbose mode
{"v",arg_no,"-"},
// 2: overwrite mode
{"o",arg_no,"-"},
// 3: debug mode
{"D",arg_no,"-"},
{NULL}
};
// no arguments? print usage...
if (iargc<2)
{
cerr << usage_text << endl;
exit(0);
}
// collect options from commandline
Commandline cmdline(iargc, argv, options);
// help requested? print full help text...
if (cmdline.optset(0))
{
cerr << usage_text << endl;
cerr << help_text << endl;
exit(0);
}
/*
// dummy operation: print option settings
for (int iopt=0; iopt<2; iopt++)
{
cout << "option: '" << options[iopt].opt_string << "'" << endl;
if (cmdline.optset(iopt)) { cout << " option was set"; }
else { cout << "option was not set"; }
cout << endl;
cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
cout << " argument (bool): '";
if (cmdline.bool_arg(iopt))
{ cout << "true"; } else { cout << "false"; }
cout << "'" << endl;
}
while (cmdline.extra()) { cout << cmdline.next() << endl; }
// dummy operation: print rest of command line
while (cmdline.extra()) { cout << cmdline.next() << endl; }
*/
Options opt;
opt.verbose=cmdline.optset(1);
opt.overwrite=cmdline.optset(2);
opt.debug=cmdline.optset(3);
TFXX_assert(cmdline.extra(), "missing input file!");
std::string outfile=cmdline.next();
TFXX_assert(cmdline.extra(), "missing output file!");
Tnames infiles;
while (cmdline.extra())
{
infiles.push_back(outfile);
outfile=cmdline.next();
}
if (opt.verbose) { cout << "open output file " << outfile << endl; }
std::ofstream ofs(outfile.c_str());
sff::SFFostream<Tts::Tseries> os(ofs);
sff::SRCE srce=sff::srce_reference();
os << srce;
Tnames::const_iterator I=infiles.begin();
while (I!=infiles.end())
{
if (opt.verbose) { cout << "open " << std::string(*I) << endl; }
std::ifstream ifs(I->c_str());
datread::isffstream is(ifs, opt.debug);
while (is.good())
{
if (opt.verbose) { cout << "read trace" << endl; }
Tts data;
Tts::Tseries samples;
is >> samples >> data.header;
data.series()=samples;
sff::INFO info;
is >> info;
if (opt.verbose) { cout << data.header.line() << endl; }
Tts result=ts::correlate(data,data)/Tts::Tvalue(data.size());
result.header=data.header;
result.header.auxid="corr";
result.header.date=srce.date
+(result.first()*libtime::double2time(result.header.dt));
os << result.series() << result.header;
if (is.hasinfo()) { os << info; }
}
++I;
}
}
/* ----- END OF autocorr.cc ----- */
Supports Markdown
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