/*! \file sigfit.cc * \brief fit signal by trial-signals * * ---------------------------------------------------------------------------- * * $Id: sigfit.cc,v 1.2 2004-01-28 15:55:41 tforb Exp $ * \author Thomas Forbriger * \date 28/01/2004 * * fit signal by trial-signals * * Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach) * * REVISIONS and CHANGES * - 28/01/2004 V1.0 Thomas Forbriger * * ============================================================================ */ #define SIGFIT_VERSION \ "SIGFIT V1.0 fit signal by trial-signals" #define SIGFIT_CVSID \ "$Id: sigfit.cc,v 1.2 2004-01-28 15:55:41 tforb Exp $" #include #include #include #include #include #include #include #include typedef std::list Tnamelist; typedef ts::TDsffbundle Tbundle; typedef Tbundle::Tseries Tseries; typedef std::vector Tbundlevec; using std::cout; using std::cerr; using std::endl; // structure to store commandline options struct Options { bool verbose; }; // struct Options int main(int iargc, char* argv[]) { // define usage information char usage_text[]= { SIGFIT_VERSION "\n" "usage: sigfit [-v] signal trial [trial ...]" "\n" " or: sigfit --help|-h" "\n" }; // define full help text char help_text[]= { SIGFIT_CVSID "\n" "\n" "-v be verbose" "\n" "-Sramp add a ramp to the set of trial signals" "\n" "-Sconst add a constant to the set of trial signals" "\n" "\n" "signal signal to by explained by a linear combination" "\n" " of trial signals" "\n" "trial any set of trial signals" }; // define commandline options using namespace tfxx::cmdline; static Declare options[]= { // 0: print help {"help",arg_no,"-"}, // 1: verbose mode {"v",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; } */ // read options Options opt; opt.verbose=cmdline.optset(1); /*----------------------------------------------------------------------*/ // read file names TFXX_assert(cmdline.extra(),"ERROR: missing signal file name!"); std::string signalname=cmdline.next(); TFXX_assert(cmdline.extra(),"ERROR: missing trial signal file name!"); Tnamelist namelist; while (cmdline.extra()) { namelist.push_back(cmdline.next()); } // read signal file Tbundle signal; { if (opt.verbose) { cout << "read signal file \"" << signalname << "\"" << endl; } std::ifstream is(signalname.c_str()); sff::FileHeader fileheader(is); if (opt.verbose) { cout << " read trace" << endl; } sff::InputWaveform inputwaveform(is); sff::TraceHeader traceheader=inputwaveform.header(); signal.header=traceheader.wid2(); signal.series=inputwaveform.series(); bool last=traceheader.last(); std::string wid2line=signal.header.line(); if (opt.verbose) { cout << " " << wid2line.substr(0,69) << endl; if (!last) { cout << "there are more traces in that files" << endl << "ignoring them..." << endl; } } } // read trial files if (opt.verbose) { cout << namelist.size() << " trial data files to read" << endl; } Tbundlevec bundlevec; for (Tnamelist::const_iterator i=namelist.begin(); i!=namelist.end(); i++) { if (opt.verbose) { cout << "read trial data file \"" << *i << "\"" << endl; } std::ifstream is(i->c_str()); sff::FileHeader fileheader(is); bool last=false; while(!last) { if (opt.verbose) { cout << " read trial signal #" << bundlevec.size()+1 << endl; } sff::InputWaveform inputwaveform(is); sff::TraceHeader traceheader=inputwaveform.header(); Tbundle bundle; bundle.header=traceheader.wid2(); bundle.series=inputwaveform.series(); bundlevec.push_back(bundle); last=traceheader.last(); std::string wid2line=bundle.header.line(); if (opt.verbose) { cout << " " << wid2line.substr(0,69) << endl; } } } /*----------------------------------------------------------------------*/ sff::WID2compare compare(sff::Fnsamples | sff::Fdt); if (opt.verbose) { cout << "checking consistency..." << endl; } for (Tbundlevec::const_iterator i=bundlevec.begin(); i!=bundlevec.end(); i++) { if (!compare (i->header,signal.header)) { cerr << "ERROR: header signature mismatch:" << endl; cerr << "signal:" << endl; cerr << signal.header.line(); cerr << "trial signal:" << endl; cerr << i->header.line(); TFXX_abort("baling out..."); } } } /* ----- END OF sigfit.cc ----- */