/*! \file croposp.cc * \brief Cross power spectral density * * ---------------------------------------------------------------------------- * * \author Thomas Forbriger * \date 25/12/2018 * * Cross power spectral density * * Copyright (c) 2018 by Thomas Forbriger (BFO Schiltach) * * REVISIONS and CHANGES * - 25/12/2018 V1.0 Thomas Forbriger * * ============================================================================ */ #define CROPOSP_VERSION \ "CROPOSP V1.0 Cross power spectral density" #include #include #include #include #include using std::cout; using std::cerr; using std::endl; struct Options { bool verbose, trim; std::string inputformat; double datetolerance; }; // struct Options int main(int iargc, char* argv[]) { // define usage information char usage_text[]= { CROPOSP_VERSION "\n" "usage: croposp" "\n" " or: croposp --help|-h" "\n" }; // define full help text char help_text[]= { "-verbose be verbose\n" "-itype f set default input file format (this value can\n" " be overwritten by the format key at a file name)\n" "-trim trim time series to identical begin and length\n" "-datetolerance t set tolerance as a fraction of sampling interval\n" " when comparing time series header date values\n" "\n" "keys to be appended to file names if required:\n" "t:sel trace selection\n" "f:format file format\n" }; // define commandline options using namespace tfxx::cmdline; static Declare options[]= { // 0: print help {"help",arg_no,"-"}, // 1: verbose mode {"verbose",arg_no,"-"}, // 2: default input file format {"itype",arg_yes,"sff"}, // 3: trim time series {"trim",arg_no,"-"}, // 4: default input file format {"datetolerance",arg_yes,"0."}, {NULL} }; // define command line keys for input files static const char tracekey[]="t"; static const char formatkey[]="f"; // define commandline argument modifier keys static const char* cmdlinekeys[]={tracekey, formatkey, 0}; // 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); } Options opt; opt.verbose=cmdline.optset(1); opt.inputformat=cmdline.string_arg(2); opt.trim=cmdline.optset(3); opt.datetolerance=cmdline.double_arg(4); TFXX_assert(((opt.datetolerance >= 0.) && (opt.datetolerance <=1.)), "datetolerance is out of accepted range"); // extract commandline arguments TFXX_assert(cmdline.extra(), "missing input file"); tfxx::cmdline::Tparsed arguments=parse_cmdline(cmdline, cmdlinekeys); // read data files if (opt.verbose) { cout << "Read time series data" << endl; } ts::sff::TDFileList input_file_list; tfxx::cmdline::Tparsed::const_iterator file=arguments.begin(); while (file != arguments.end()) { std::string format=opt.inputformat; if (file->haskey(formatkey)) { format=file->value(formatkey); } input_file_list.push_back(ts::sff::readDSFF(*file, opt.verbose, tracekey, format)); ++file; } // collect traces typedef ts::TimeSeriesCollection TCollection; TCollection collection_of_series; typedef ts::sff::DFile::Tfile Tfile; typedef Tfile::Ttracevector Ttracevector; ts::sff::TDFileList::const_iterator i_file=input_file_list.begin(); while (i_file != input_file_list.end()) { Ttracevector::const_iterator i_trace=i_file->data.begin(); while (i_trace != i_file->data.end()) { collection_of_series.push_back(*i_trace); ++i_trace; } ++i_file; } // report traces if (opt.verbose) { cout << "Time series to be analyzed:" << endl; TCollection::const_iterator i_series=collection_of_series.begin(); while (i_series != collection_of_series.end()) { cout << " " << i_series->header.station << " " << i_series->header.channel << " " << i_series->header.auxid << " " << "dt=" << i_series->header.dt << "s " << "begin: " << i_series->header.date.timestring() << " " << "n: " << i_series->header.nsamples << endl; ++i_series; } } // trim time series if (opt.trim) { TFXX_assert(collection_of_series.overlap(), "time series do not overlap"); collection_of_series.trim_to_date(); collection_of_series.trim_to_nsamples(); } // check consistency ::sff::WID2compare comparer(::sff::Fdt | ::sff::Fnsamples | ::sff::Fdate); comparer.setdatetolerance(opt.datetolerance); TFXX_assert(collection_of_series.are_consistent(comparer), "time series are inconsistent"); } // main() /* ----- END OF croposp.cc ----- */