40 #define SOUTIFU_VERSION \ 41 "SOUTIFU V1.4 inversion for source wavelet correction filter" 45 #include <tfxx/error.h> 46 #include <tfxx/commandline.h> 47 #include <tfxx/seitosh.h> 48 #include <tsioxx/tsioxx.h> 49 #include <datrwxx/readany.h> 50 #include <datrwxx/writeany.h> 51 #include <stfinv/stfinvany.h> 61 #define PAROUT( par ) cout << #par << "=" << par << " "; 66 bool sameineps(
const double &a,
const double& b,
const double& eps=1.e-8)
68 double reldif=std::abs(a-b);
69 return(reldif<=(std::abs(b*eps)));
85 int main(
int iargc,
char* argv[])
92 "usage: soutifu [-v] [-o] [-wc f] [-ws f] [--type f] [--Type f]\n" 95 " parameters data synthetics" "\n" 96 " or: soutifu --help|-h" "\n" 97 " or: soutifu --xhelp | --iohelp | --phelp p" "\n" 103 "Calculate optimized source wavelet correction filter to\n" 104 "minimize misfit between recorded data and synthetic waveforms.\n" 106 "data name of file containing recorded data\n" 107 "synthetics name of file containing synthetic data\n" 108 "parameters parameterstring to select STF engine\n" 109 " The string consists of an ID selecting one of the\n" 110 " available engines and a set of options an parameters\n" 111 " to be passed to this engine.\n" 113 "--xhelp print summary of usage instructions for available procedures\n" 114 "--iohelp print detailed usage instructions for file input/output\n" 115 "--phelp p print detailed usage instructions for procedure \"p\"\n" 118 "-DEBUG=level produce debug output at level \"level\"\n" 119 "-o overwrite existing output files\n" 120 "--type f use file format type \"f\" for file input\n" 121 "--Type f use file format type \"f\" for file output\n" 122 " if --Type is not used input and output format will\n" 124 "-wc f write convolved synthetics to file \"f\"\n" 125 "-ws f write source wavelet correction filter \n" 126 " impulse response to file \"f\"\n" 127 "-add f read additional time series to be convolved from file \"f\"\n" 128 "-wa f write additional time series after convolved to file \"f\"\n" 130 "Upon input the consistency of recorded and synthetic data are\n" 131 "checked. For coordinates only receiver positions relative to\n" 132 "source coordinates are checked, not absolute locations.\n" 136 using namespace tfxx::cmdline;
137 static Declare options[]=
146 {
"type",arg_yes,
"sff"},
152 {
"xhelp",arg_no,
"-"},
154 {
"DEBUG",arg_yes,
"0"},
156 {
"Type",arg_yes,
"-"},
162 {
"iohelp",arg_no,
"-"},
164 {
"phelp",arg_yes,
"-"},
171 cerr << usage_text << endl;
172 cerr << tfxx::seitosh::repository_reference << endl;
177 Commandline cmdline(iargc, argv, options);
180 if (cmdline.optset(0) || cmdline.optset(6) || cmdline.optset(11)
181 || cmdline.optset(12))
183 cerr << usage_text << endl;
185 cerr << help_text << endl;
186 datrw::supported_data_types(cerr);
187 if (cmdline.optset(11))
190 datrw::online_help(cerr);
192 if (cmdline.optset(6))
199 cerr << help_text << endl;
200 stfinv::engines(cerr);
202 if (cmdline.optset(12))
205 stfinv::usage(cmdline.string_arg(12), cerr);
207 cerr << endl << tfxx::seitosh::repository_reference << endl;
221 opt.
debug=cmdline.optset(7);
227 if (cmdline.optset(10))
230 "ERROR: provide input for additional series");
234 TFXX_assert(cmdline.extra(),
"missing parameter string");
235 std::string parameters=cmdline.next();
236 TFXX_assert(cmdline.extra(),
"missing recorded data file name");
237 std::string datafilename=cmdline.next();
238 TFXX_assert(cmdline.extra(),
"missing synthetics data file name");
239 std::string syntheticsfilename=cmdline.next();
247 typedef aff::Series<float>
Tseries;
248 typedef ts::sff::File<Tseries>
Tfile;
254 std::ios_base::openmode iopenmode
256 if (opt.
verbose) { cout <<
"open input file " << datafilename << endl; }
258 std::ifstream ifs(datafilename.c_str(), iopenmode);
260 recordeddata.read(is.idatstream(), opt.
verbose);
263 if (opt.
verbose) { cout <<
"open input file " << syntheticsfilename << endl; }
265 std::ifstream ifs(syntheticsfilename.c_str(), iopenmode);
267 syntheticdata.read(is.idatstream(), opt.
verbose);
277 seriesdata.read(is.idatstream(), opt.
verbose);
285 cout <<
"check input data consistency,\n" 286 <<
"prepare output data containers, and\n" 287 <<
"prepare waveform data workspace" << endl;
291 TFXX_assert(recordeddata.size() == syntheticdata.size(),
292 "ERROR: inconsitent number of traces");
293 const unsigned int ntraces=recordeddata.size();
296 Tfile convolvedsynthetics;
300 stfinv::Tvectoroftriples vectoroftriples;
301 stfinv::Waveform stfwaveform;
303 convolvedsynthetics.fileheader=syntheticdata.fileheader;
306 for (
unsigned int itrace=0; itrace<ntraces; ++itrace)
310 cout <<
" check trace #" << itrace+1 << endl;
321 sdtseries.header, sdtseries.traceindex());
324 stfinv::WaveformTriple tracetriple;
325 tracetriple.data=rdtseries;
326 tracetriple.synthetics=sdtseries;
327 tracetriple.convolvedsynthetics=cstseries;
328 tracetriple.header.sampling.dt=rdtseries.header.wid2().dt;
329 tracetriple.header.sampling.n=rdtseries.header.wid2().nsamples;
331 TFXX_assert((rdtseries.header.wid2().nsamples
332 == sdtseries.header.wid2().nsamples),
333 "ERROR: inconsistent trace size");
334 TFXX_assert(
sameineps(rdtseries.header.wid2().dt,
335 sdtseries.header.wid2().dt),
336 "ERROR: inconsistent sampling interval");
339 tracetriple.header.sx=recordeddata.fileheader.srce().cx;
340 tracetriple.header.sy=recordeddata.fileheader.srce().cy;
341 tracetriple.header.sz=recordeddata.fileheader.srce().cz;
344 tracetriple.header.rx=rdtseries.header.info().cx;
345 tracetriple.header.ry=rdtseries.header.info().cy;
346 tracetriple.header.rz=rdtseries.header.info().cz;
349 double ddx=rdtseries.header.info().cx-recordeddata.fileheader.srce().cx;
350 double ddy=rdtseries.header.info().cy-recordeddata.fileheader.srce().cy;
351 double ddz=rdtseries.header.info().cz-recordeddata.fileheader.srce().cz;
352 double sdx=sdtseries.header.info().cx-syntheticdata.fileheader.srce().cx;
353 double sdy=sdtseries.header.info().cy-syntheticdata.fileheader.srce().cy;
354 double sdz=sdtseries.header.info().cz-syntheticdata.fileheader.srce().cz;
373 "ERROR: inconsistent receiver positions");
376 TFXX_assert((rdtseries.header.wid2().date
377 == recordeddata.fileheader.srce().date),
378 "ERROR: trigger delay not supported");
379 TFXX_assert((sdtseries.header.wid2().date
380 == syntheticdata.fileheader.srce().date),
381 "ERROR: trigger delay not supported");
384 vectoroftriples.push_back(tracetriple);
387 convolvedsynthetics.push_back(cstseries);
396 stfwaveform.sampling.dt=tracetriple.header.sampling.dt;
397 stfwaveform.sampling.n=tracetriple.header.sampling.n;
398 stfwaveform.series=stftseries;
400 ::sff::WID2 wid2=stftseries.header.wid2();
401 wid2.nsamples=stfwaveform.sampling.n;
402 wid2.dt=stfwaveform.sampling.dt;
403 wid2.date=libtime::now();
404 stftseries.header.wid2(wid2);
405 ::sff::SRCE srce=stffile.fileheader.srce();
406 srce.date=stftseries.header.wid2().date;
407 stffile.fileheader.srce(srce);
409 stffile.push_back(stftseries);
417 Tfile convolvedseries;
420 stfinv::Tvectorofpairs vectorofpairs;
421 vectorofpairs.clear();
426 convolvedseries.fileheader=seriesdata.fileheader;
429 cout <<
"prepare additional series to be convolved" << endl;
433 for (
unsigned int itrace=0; itrace<seriesdata.size(); ++itrace)
437 cout <<
" check trace #" << itrace+1 << endl;
447 sdtseries.header, sdtseries.traceindex());
450 stfinv::WaveformPair tracepair;
451 tracepair.synthetics=sdtseries;
452 tracepair.convolvedsynthetics=cstseries;
453 tracepair.sampling.dt=sdtseries.header.wid2().dt;
454 tracepair.sampling.n=sdtseries.header.wid2().nsamples;
457 vectorofpairs.push_back(tracepair);
460 convolvedseries.push_back(cstseries);
472 parameters +=
":verbose";
473 cout <<
"create STF engine" << endl;
476 stfinv::STFEngine engine(vectoroftriples, stfwaveform,
477 vectorofpairs, parameters);
481 if (opt.
verbose) { cout <<
"run engine" << endl; }
491 cout <<
"write STF to file " << opt.
stffilename << endl;
495 std::ifstream file(opt.
stffilename.c_str(),std::ios_base::in);
496 TFXX_assert((!file.good()),
"ERROR: output file exists!");
498 std::ios_base::openmode oopenmode
500 std::ofstream ofs(opt.
stffilename.c_str(), oopenmode);
503 os << stffile.fileheader.srce();
504 for (
unsigned int itrace=0; itrace<stffile.size(); ++itrace)
506 os << stffile[itrace];
514 cout <<
"write convolved synthetics to file " 520 TFXX_assert((!file.good()),
"ERROR: output file exists!");
522 std::ios_base::openmode oopenmode
527 os << convolvedsynthetics.fileheader.srce();
528 for (
unsigned int itrace=0; itrace<convolvedsynthetics.size(); ++itrace)
530 os << convolvedsynthetics[itrace];
538 cout <<
"write additional convolved series to file " 544 TFXX_assert((!file.good()),
"ERROR: output file exists!");
546 std::ios_base::openmode oopenmode
551 os << convolvedseries.fileheader.srce();
552 for (
unsigned int itrace=0; itrace<convolvedseries.size(); ++itrace)
554 os << convolvedseries[itrace];
ts::sff::SFFTimeSeries< Tseries > Ttimeseries
std::string datafileformat
int main(int iargc, char *argv[])
std::string additionalseries
std::string convolvedfilename
std::string additionaloutput
bool sameineps(const double &a, const double &b, const double &eps=1.e-8)
std::string outputfileformat
aff::Series< double > Tseries
ts::sff::File< Tseries > Tfile