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

first version of cross works

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: 1628
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent e66066cc
# ---------------------------------------
#
# $Id: Makefile,v 1.22 2005-01-12 15:37:19 tforb Exp $
# $Id: Makefile,v 1.23 2005-01-26 17:52:13 tforb Exp $
#
# Makefile fuer tools /src/ts/wf
#
......@@ -57,9 +57,10 @@ phasedsignals hamres siggen smoos dise: %: %.o
-L$(LOCLIBDIR)
newprog $@
tidofi fredofi sigfit: %: %.o
cross tidofi fredofi sigfit: %: %.o
$(CXX) -o $@ $^ -I$(LOCINCLUDEDIR) -lsffxx -llinearxx -lgsexx -laff \
-ltfxx -ltime++ -llapack -lblas -lg2c -lm\
-ltsxx -ldatreadxx -ltfxx -ltime++ \
-llapack -lblas -lg2c -lm\
-L$(LOCLIBDIR) $(CXXFLAGS) $(FLAGS)
newprog $@
......
/*! \file cross.cc
* \brief cross correlation
*
* ----------------------------------------------------------------------------
*
* $Id: cross.cc,v 1.1 2005-01-26 17:52:14 tforb Exp $
* \author Thomas Forbriger
* \date 26/01/2005
*
* cross correlation
*
* Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 26/01/2005 V1.0 Thomas Forbriger
*
* ============================================================================
*/
#define CROSS_VERSION \
"CROSS V1.0 cross correlation"
#define CROSS_CVSID \
"$Id: cross.cc,v 1.1 2005-01-26 17:52:14 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>
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[]=
{
CROSS_VERSION "\n"
"usage: cross -v -o -D file [file [...]] outfile" "\n"
" or: cross --help|-h" "\n"
};
// define full help text
char help_text[]=
{
CROSS_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"
"\n"
"The last first read is the trace with which all others are" "\n"
"crosscorrelated." "\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;
Tts reference, data;
bool referenceread=false;
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 (referenceread) {
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; }
TFXX_assert((data.header.dt == reference.header.dt),
"sampling intervals do not match!");
Tts result=ts::correlate(reference,data);
result.header=data.header;
result.header.auxid="corr";
result.header.date=srce.date
+(result.first()*libtime::double2time(result.header.dt))
+(data.header.date-reference.header.date);
os << result.series() << result.header;
if (is.hasinfo()) { os << info; }
}
else
{
if (opt.verbose) { cout << "read reference trace" << endl; }
is >> reference.series() >> reference.header;
if (opt.verbose) { cout << reference.header.line() << endl; }
referenceread=true;
}
}
++I;
}
}
/* ----- END OF cross.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