77 "usage: teseco [-v] [-o] [-a] [-type type] [-Type type]" "\n" 78 " [-datetolerance t] [-trim]" "\n" 79 " outfile signal [t:T] [f:F]\n" 80 " infile [t:T] [f:F] [infile [t:T] [f:F] ... ]" "\n" 81 " or: teseco --help|-h" "\n" 82 " or: teseco --xhelp" "\n" 88 "The program reads time series traces and adds or subtracts other" "\n" 89 "time series scaled by individual factors. This way a barometric" "\n" 90 "pressure correction or magentic field correction may be applied" "\n" 91 "to seismic recordings." "\n" 93 "All input traces (all traces in signal and correction files) are\n" 94 "expected to cover the same time window. This program is not able\n" 95 "to handle time series containing gaps properly.\n" 97 "outfile output filename" "\n" 98 "signal signal filename (multiple traces may be selected;\n" 99 " each correction will be applied to each of them)\n" 100 "infile name of file containing correction; scaled traces" "\n" 101 " will be subtraced from (or added to) the signals" "\n" 102 " t:T select traces T, where T may be any range" "\n" 103 " specification like \'3-4\' or \'5,6,7-12,20\'" "\n" 104 " f:F each of the traces will be scaled by the factor \'F\'\n" 105 " (default: F=1.)" "\n" 107 "-v verbose mode" "\n" 108 "-o overwrite existing output file" "\n" 109 "-a rather add than subtract correction signals" "\n" 110 "-type type input file type (default: sff)" "\n" 111 "-Type type output file type (default: sff)" "\n" 113 " set a tolerance level f for comparison of date of\n" 114 " input time series; dates will be considered as different\n" 115 " if they differ by more than a fraction f of the average\n" 116 " sampling interval\n" 117 "-trim trim all series to the shortest series provided\n" 118 " if not set, providing series of different number of samples\n" 119 " is considered to be an error\n" 123 using namespace tfxx::cmdline;
124 static Declare options[]=
135 {
"type",arg_yes,
"sff"},
139 {
"Type",arg_yes,
"sff"},
141 {
"xhelp",arg_no,
"-"},
143 {
"datetolerance",arg_yes,
"0."},
150 static const char factorkey[]=
"f";
162 cerr << usage_text << endl;
163 cerr << tfxx::seitosh::repository_reference << endl;
168 Commandline cmdline(iargc, argv, options);
171 if (cmdline.optset(0))
173 cerr << usage_text << endl;
174 cerr << help_text << endl;
176 datrw::supported_data_types(cerr);
177 cerr << endl << tfxx::seitosh::repository_reference << endl;
182 if (cmdline.optset(7))
184 cerr << usage_text << endl;
186 datrw::online_help(cerr);
187 cerr << endl << tfxx::seitosh::repository_reference << endl;
194 opt.
add=cmdline.optset(3);
196 opt.
debug=cmdline.optset(5);
205 TFXX_assert(cmdline.extra(),
"missing output file");
206 std::string outfile=cmdline.next();
207 TFXX_assert(cmdline.extra(),
"missing signal file");
208 tfxx::cmdline::Tparsed infiles=parse_cmdline(cmdline,
cmdlinekeys);
209 TFXX_assert((infiles.size()>1),
"missing correction file");
210 tfxx::cmdline::Filename sigfile=infiles.front();
218 if (opt.
verbose) { cout <<
"open output file " << outfile << endl; }
222 std::ifstream file(outfile.c_str(),std::ios_base::in);
223 TFXX_assert((!file.good()),
"ERROR: output file exists!");
225 std::ios_base::openmode oopenmode
227 std::ofstream ofs(outfile.c_str(), oopenmode);
232 unsigned int maxsamples=0;
239 typedef ts::sff::File<Tseries>
Tfile;
240 typedef Tfile::Trangelist Trangelist;
243 bool doselect=sigfile.haskey(
tracekey);
244 Trangelist traceranges=
245 tfxx::string::rangelist<Trangelist::Tvalue>(sigfile.value(
tracekey));
247 if (opt.
verbose) { cout <<
"open signal file " << sigfile.name << endl; }
249 std::ios_base::openmode iopenmode
251 std::ifstream ifs(sigfile.name.c_str(), iopenmode);
256 { signal.read(is.idatstream(), traceranges, opt.
verbose); }
258 { signal.read(is.idatstream(), opt.
verbose); }
260 TFXX_assert(signal.size()>0,
261 "set of input signals is empty");
264 if (sigfile.haskey(factorkey))
267 std::istringstream sfactor(sigfile.value(factorkey));
269 for (Tfile::Ttracevector::iterator isig=signal.begin();
270 isig != signal.end(); ++isig)
279 for (Tfile::Ttracevector::iterator isig=signal.begin();
280 isig != signal.end(); ++isig)
282 TFXX_assert(isig->size()>0,
"missing samples in input signal");
283 if ((maxsamples == 0) || (maxsamples > isig->size()))
285 maxsamples = isig->size();
291 TFXX_assert((signal.size()>0),
"missing signal");
292 signal.fileheader.append(filefree);
296 sff::WID2compare compare(sff::Fdt | sff::Fdate);
301 tfxx::cmdline::Tparsed::const_iterator infile=infiles.begin();
302 while (infile != infiles.end())
305 if (opt.
verbose) { cout <<
"open correction file " 306 << infile->name << endl; }
308 std::ios_base::openmode iopenmode
310 std::ifstream ifs(infile->name.c_str(), iopenmode);
317 typedef tfxx::RangeList<int> Trangelist;
318 bool doselect=infile->haskey(
tracekey);
319 Trangelist traceranges=
320 tfxx::string::rangelist<Trangelist::Tvalue>(infile->value(
tracekey));
324 if (infile->haskey(factorkey))
326 std::istringstream sfactor(infile->value(factorkey));
329 if (opt.
add) { factor *= -1.; }
335 if ((!doselect) || traceranges.contains(itrace))
337 { std::cout <<
" process trace #" << itrace << std::endl; }
344 for (Tfile::Ttracevector::iterator isig=signal.begin();
345 isig != signal.end(); ++isig)
348 if (!compare (isig->header.wid2(),wid2))
350 cerr <<
"ERROR: header signature mismatch:" << endl;
351 cerr <<
"signal:" << endl;
352 cerr << isig->header.wid2().line();
353 cerr <<
"correction signal:" << endl;
357 sff::WID2compare cmpdate(sff::Fdate);
359 if (!cmpdate(isig->header.wid2(),wid2))
361 cerr <<
"*** date mismatch " 362 <<
"(consider to use option -datetolerance)" << endl;
363 cerr <<
"*** signal: ";
364 cerr << isig->header.wid2().date.timestring() << endl;
365 cerr <<
"*** correction signal: ";
366 cerr << wid2.date.timestring() << endl;
368 TFXX_abort(
"bailing out...");
372 if (isig->size() != series.size())
376 if (maxsamples > isig->size()) { maxsamples = isig->size(); }
377 if (maxsamples > series.size()) { maxsamples = series.size(); }
378 isig->setlastindex(isig->first()-1+maxsamples);
379 series.setlastindex(series.first()-1+maxsamples);
383 cerr <<
"ERROR: inconsistent number of samples:" << endl;
384 cerr << isig->size() <<
" samples for signal" << endl;
385 cerr << isig->header.wid2().line();
386 cerr << series.size() <<
" samples for correction signal" 389 cerr <<
"consider to use option -trim" << endl;
390 TFXX_abort(
"bailing out...");
401 TFXX_debug(opt.
debug,
"main",
"skip trace #" << itrace );
403 { std::cout <<
" skip trace #" << itrace << std::endl; }
static const char * cmdlinekeys[]
const char *const tracekey
key to select traces
aff::Series< double > Tseries
ts::sff::File< Tseries > Tfile