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

teseco compiles

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: 1876
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 0df13280
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.31 2005-07-15 16:31:02 tforb Exp $
# $Id: Makefile,v 1.32 2005-07-18 15:18:44 tforb Exp $
#
# Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
#
......@@ -71,7 +71,7 @@ phasedsignals hamres siggen smoos dise: %: %.o
-L$(LOCLIBDIR)
newprog $@
resaseda gatherdiff autocorr cross tidofi fredofi sigfit: %: %.o
teseco resaseda gatherdiff autocorr cross tidofi fredofi sigfit: %: %.o
$(CXX) -o $@ $^ -I$(LOCINCLUDEDIR) -lsffxx -ldatreadxx -llinearxx \
-ltsxx -ltfxx -lsffxx -lgsexx -ltime++ -laff \
-llapack -lblas -lcseife -lsffxx -lg2c -lm\
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: teseco.cc,v 1.1 2005-07-13 14:44:11 tforb Exp $
* $Id: teseco.cc,v 1.2 2005-07-18 15:18:44 tforb Exp $
* \author Thomas Forbriger
* \date 13/07/2005
*
......@@ -19,15 +19,29 @@
#define TESECO_VERSION \
"TESECO V1.0 time series corrections"
#define TESECO_CVSID \
"$Id: teseco.cc,v 1.1 2005-07-13 14:44:11 tforb Exp $"
"$Id: teseco.cc,v 1.2 2005-07-18 15:18:44 tforb Exp $"
#include <fstream>
#include <iostream>
#include <tfxx/commandline.h>
#include <tfxx/xcmdline.h>
#include <tfxx/error.h>
#include <tfxx/misc.h>
#include <tfxx/rangestring.h>
#include <tsxx/sffheaders.h>
#include <datreadxx/readany.h>
using std::cout;
using std::cerr;
using std::endl;
typedef aff::Series<double> Tseries;
struct Options {
bool verbose, overwrite, add, debug;
std::string inputformat;
}; // struct Options
int main(int iargc, char* argv[])
{
......@@ -35,14 +49,35 @@ int main(int iargc, char* argv[])
char usage_text[]=
{
TESECO_VERSION "\n"
"usage: teseco" "\n"
"usage: teseco [-v] [-o] [-a] [-t type]" "\n"
" outfile signal [t:T] infile [t:T] [f:F] [infile [t:T] [f:F] ... ]"
"\n"
" or: teseco --help|-h" "\n"
};
// define full help text
char help_text[]=
{
TESECO_CVSID
"The program reads time series traces and adds or subtracts other" "\n"
"time series scaled by individual factors. This way a barometric" "\n"
"pressure correction or magentic field correction may be applied" "\n"
"to seismic recordings." "\n"
"\n"
TESECO_CVSID "\n"
"\n"
"outfile output filename" "\n"
"signal signal filename (these trace will be corrected)" "\n"
" t:T select traces T, where T may be any range" "\n"
" specification like \'3-4\' or \'5,6,7-12,20\'" "\n"
"infile name of file containing correction" "\n"
" each of the traces will be scaled by the factor \'F\'" "\n"
" and be subtraced from (or added to) the signals" "\n"
" (default: F=1.)" "\n"
"\n"
"-v verbose mode" "\n"
"-o overwrite existing output file" "\n"
"-a rather add than subtract correction signals" "\n"
"-t type input file type (default: sff)" "\n"
};
// define commandline options
......@@ -53,9 +88,27 @@ int main(int iargc, char* argv[])
{"help",arg_no,"-"},
// 1: verbose mode
{"v",arg_no,"-"},
// 2: overwrite mode
{"o",arg_no,"-"},
// 3: add mode
{"a",arg_no,"-"},
// 4: input file type
{"t",arg_yes,"sff"},
// 5: debug mode
{"D",arg_no,"-"},
{NULL}
};
static const char tracekey[]="t";
static const char factorkey[]="f";
// define commandline argument modifier keys
static const char* cmdlinekeys[]={
tracekey,
factorkey,
0
}; // cmdlinekeys
// no arguments? print usage...
if (iargc<2)
{
......@@ -74,27 +127,106 @@ int main(int iargc, char* argv[])
exit(0);
}
// dummy operation: print option settings
for (int iopt=0; iopt<2; iopt++)
Options opt;
opt.verbose=cmdline.optset(1);
opt.overwrite=cmdline.optset(2);
opt.add=cmdline.optset(3);
opt.inputformat=cmdline.string_arg(4);
opt.debug=cmdline.optset(5);
if (opt.verbose)
{ cout << TESECO_VERSION << endl << TESECO_CVSID << endl; }
// extract commandline arguments
TFXX_assert(cmdline.extra(), "missing output file");
std::string outfile=cmdline.next();
TFXX_assert(cmdline.extra(), "missing signal file");
tfxx::cmdline::Tparsed infiles=parse_cmdline(cmdline, cmdlinekeys);
TFXX_assert((infiles.size()<2), "missing correction file");
tfxx::cmdline::Filename sigfile=infiles.front();
infiles.pop_front();
/*======================================================================*/
// start processing
// open output file
// ----------------
if (opt.verbose) { cout << "open output file " << outfile << endl; }
// check if output file exists and open
if (!opt.overwrite)
{
std::ifstream file(outfile.c_str(),std::ios_base::in);
TFXX_assert((!file.good()),"ERROR: output file exists!");
}
std::ofstream ofs(outfile.c_str());
sff::SFFostream<Tseries> os(ofs, opt.debug);
// prepare file FREE block
sff::FREE filefree;
filefree.append(TESECO_VERSION);
// read signal file
typedef ts::sff::File<Tseries> Tfile;
typedef Tfile::Trangelist Trangelist;
Tfile signal;
{
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;
bool doselect=sigfile.haskey(tracekey);
Trangelist traceranges=
tfxx::string::rangelist<Trangelist::Tvalue>(sigfile.value(tracekey));
if (opt.verbose) { cout << "open signal file " << sigfile.name << endl; }
std::ifstream ifs(sigfile.name.c_str());
datread::ianystream is(ifs, datread::anyID(opt.inputformat));
if (doselect)
{ signal.read(is.idatstream(), traceranges, opt.verbose); }
else
{ signal.read(is.idatstream(), opt.verbose); }
}
while (cmdline.extra()) { cout << cmdline.next() << endl; }
TFXX_assert((signal.size()>0), "missing signal");
signal.fileheader.append(filefree);
// dummy operation: print rest of command line
while (cmdline.extra()) { cout << cmdline.next() << endl; }
// cycle through all input files
// -----------------------------
tfxx::cmdline::Tparsed::const_iterator infile=infiles.begin();
while (infile != infiles.end())
{
// open input file
if (opt.verbose) { cout << "open input file " << infile->name << endl; }
std::ifstream ifs(infile->name.c_str());
datread::ianystream is(ifs, datread::anyID(opt.inputformat));
// cycle through traces of input file
// ----------------------------------
// setup trace selection
typedef tfxx::RangeList<int> Trangelist;
bool doselect=infile->haskey(tracekey);
Trangelist traceranges=
tfxx::string::rangelist<Trangelist::Tvalue>(infile->value(tracekey));
int itrace=0;
while (is.good())
{
++itrace;
if ((!doselect) || traceranges.contains(itrace))
{
{ std::cout << " process trace #" << itrace << std::endl; }
Tseries series;
is >> series;
sff::WID2 wid2;
is >> wid2;
}
else
{
TFXX_debug(opt.debug, "main", "skip trace #" << itrace );
if (opt.verbose)
{ std::cout << " skip trace #" << itrace << std::endl; }
is.skipseries();
}
}
// go to next file
++infile;
}
os << signal;
}
/* ----- END OF teseco.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