87 "usage: resaseda [-tf time] [-tl time] [-n n] [-dt dt] [-ts time]" "\n" 88 " [-v] [-o] [-sf time] [-sl time] [-edge s]" "\n" 89 " [-delay d] [-type type] [-Type type]\n" 90 " [-sof n] [-sol n] [-shrink]" "\n" 91 " outfile infile [t:T] [infile [t:T] ...]" "\n" 92 " or: resaseda --help|-h" "\n" 93 " or: resaseda --xhelp" "\n" 99 "outfile output filename" "\n" 100 "infile input filename" "\n" 101 " t:T select traces T, where T may be any range" "\n" 102 " specification like \'3-4\' or \'5,6,7-12,20\'" "\n" 105 "-o overwrite output" "\n" 106 "-tf time time of first sample" "\n" 107 " (default: time of first input sample)" "\n" 108 "-tl time time of last sample" "\n" 109 "-sf time time of first sample" "\n" 110 " (default: time of first input sample)" "\n" 111 "-sl time time of last sample" "\n" 112 "-sf and -sl are alternatives to -tf and -tl" "\n" 113 "-n n number of samples" "\n" 114 "-ts time duration of output time series" "\n" 115 "-dt dt new sampling interval in seconds" "\n" 116 "-edge s reduce time window by \"s\" seconds at the edges" "\n" 117 "-type type input format is \'type\'" "\n" 118 "-Type type output format is \'type\'" "\n" 119 "-delay d apply delay of \"d\" seconds by shifting the time\n" 120 " of the first sample in the input series\n" 121 "-sof n define first sample index by offset n\n" 122 " positive sample index: define by offset from first sample\n" 123 " negative sample index: define by offset from last sample\n" 124 "-sol n define last sample index by offset n\n" 125 " positive sample index: define by offset from last sample\n" 126 " negative sample index: define by offset from first sample\n" 127 "-shrink if defined output time window is larger than time span\n" 128 " for which input data is available, reduce output time\n" 129 " window approrpiate for each input trace while maintaining\n" 130 " the defined Ń•ampling raster (useful for input data\n" 131 " containing gaps)\n" 135 using namespace tfxx::cmdline;
136 static Declare options[]=
145 {
"tf",arg_yes,
"1/1/1"},
147 {
"tl",arg_yes,
"1/1/1"},
149 {
"ts",arg_yes,
"1/1/1"},
157 {
"type",arg_yes,
"sff"},
159 {
"sf",arg_yes,
"1/1/1"},
161 {
"sl",arg_yes,
"1/1/1"},
163 {
"edge",arg_yes,
"0."},
165 {
"delay",arg_yes,
"0."},
171 {
"Type",arg_yes,
"sff"},
173 {
"xhelp",arg_no,
"-"},
175 {
"shrink",arg_no,
"-"},
187 cerr << usage_text << endl;
188 cerr << tfxx::seitosh::repository_reference << endl;
193 Commandline cmdline(iargc, argv, options);
196 if (cmdline.optset(0))
198 cerr << usage_text << endl;
199 cerr << help_text << endl;
200 cerr << libtime::usage_time_format_string << endl;
201 cerr << tfxx::seitosh::repository_reference << endl;
206 if (cmdline.optset(17))
208 cerr << usage_text << endl;
210 datrw::online_help(cerr);
211 cerr << endl << tfxx::seitosh::repository_reference << endl;
219 opt.
timefirst=TAbsoluteTime(cmdline.string_arg(3));
221 opt.
timelast=TAbsoluteTime(cmdline.string_arg(4));
223 opt.
timespan=TRelativeTime(cmdline.string_arg(5));
224 opt.
nset=cmdline.optset(6);
225 opt.
n=cmdline.int_arg(6);
226 opt.
dtset=cmdline.optset(7);
227 opt.
dt=cmdline.double_arg(7);
228 opt.
debug=cmdline.optset(8);
230 if (cmdline.optset(10))
233 opt.
timefirst=TAbsoluteTime(cmdline.string_arg(10));
235 if (cmdline.optset(11))
238 opt.
timelast=TAbsoluteTime(cmdline.string_arg(11));
240 opt.
edge=libtime::double2time(cmdline.double_arg(12));
241 opt.
delay=cmdline.optset(13);
248 opt.
shrink=cmdline.optset(18);
255 if (opt.
nset) ++nopt;
258 "only specify one of the options that " 259 "limit the end of the output time window");
268 "only specify one of the options that " 269 "limit the begin of the output time window");
276 TFXX_assert(cmdline.extra(),
"missing output file");
277 std::string outfile=cmdline.next();
278 TFXX_assert(cmdline.extra(),
"missing input file");
279 tfxx::cmdline::Tparsed arguments=parse_cmdline(cmdline,
cmdlinekeys);
280 if ((arguments.size()>1) && opt.
verbose)
282 cout <<
"NOTICE: file specific information (SRCE line and file FREE)" <<
284 <<
" will be taken from first file only!" << endl;
292 if (opt.
verbose) { cout <<
"open output file " << outfile << endl; }
296 std::ifstream file(outfile.c_str(),std::ios_base::in);
297 TFXX_assert((!file.good()),
"ERROR: output file exists!");
300 std::ofstream ofs(outfile.c_str(),
311 tfxx::cmdline::Tparsed::const_iterator infile=arguments.begin();
312 while (infile != arguments.end())
315 if (opt.
verbose) { cout <<
"open input file " << infile->name << endl; }
316 std::ifstream ifs(infile->name.c_str());
323 sff::FREE infilefree;
325 filefree.append(
"block read from first input file:");
326 filefree.append(infilefree);
331 sff::SRCE insrceline;
340 typedef tfxx::RangeList<int> Trangelist;
341 bool doselect=infile->haskey(
tracekey);
342 Trangelist traceranges=
343 tfxx::string::rangelist<Trangelist::Tvalue>(infile->value(
tracekey));
348 if ((!doselect) || traceranges.contains(itrace))
350 TFXX_debug(opt.
debug,
"main",
"process trace #" << itrace );
352 { std::cout <<
" process trace #" << itrace << std::endl; }
357 TFXX_debug(opt.
debug,
"main",
358 " series and WID2 are read");
361 TAbsoluteTime firstsample=wid2.date+opt.
edge;
366 TAbsoluteTime timeofs=firstsample;
369 timeofs = sff::wid2lastsample(wid2)-
376 if (timeofs>sff::wid2lastsample(wid2))
377 { timeofs=sff::wid2lastsample(wid2); }
378 if (timeofs<wid2.date)
379 { timeofs=wid2.date; }
384 TAbsoluteTime lastsample=sff::wid2lastsample(wid2)-opt.
edge;
387 TAbsoluteTime timeols=lastsample;
390 timeols = firstsample+
397 if (timeols>lastsample)
398 { timeols=lastsample; }
399 if (timeols<firstsample)
400 { timeols=firstsample; }
405 TRelativeTime newdt=libtime::double2time(wid2.dt);
407 { newdt=libtime::double2time(opt.
dt); }
408 int nsamples=(sff::wid2lastsample(wid2)-opt.
edge-firstsample)/newdt;
414 { nsamples=1+(opt.
timelast-opt.
edge-firstsample)/newdt; }
418 { nsamples=1+(lastsample-opt.
edge-firstsample)/newdt; }
420 TFXX_assert(nsamples>0,
421 "ERROR: unreasonable time window");
425 cout <<
" resampling parameters are:" << endl
426 <<
" time of first sample: " 427 << firstsample.timestring() << endl
428 <<
" sampling interval: " << newdt.timestring() << endl
429 <<
" number of samples: " << nsamples << endl;
430 if (newdt > libtime::double2time(wid2.dt))
433 <<
"New sampling interval is larger than old one." 435 <<
" You are responsible to apply an appropriate" 436 <<
" anti-alias filter" 438 <<
" prior to resampling!" 443 cout <<
" shrink output time window to available input" <<
445 <<
" data while maintaining the defined sampling" <<
447 <<
" raster" << endl;
452 typedef ts::ipo::Interpolator Tinterpolator;
453 ::sff::WID2 inwid2=wid2;
458 inwid2.date-=libtime::double2time(-opt.
delaytime);
461 cout <<
" advance series by " 462 << libtime::double2time(-opt.
delaytime).timestring() << endl;
467 inwid2.date+=libtime::double2time(opt.
delaytime);
468 cout <<
" delay series by " 469 << libtime::double2time(opt.
delaytime).timestring() << endl;
472 Tinterpolator::Tconst_timeseries inseries(series, inwid2);
473 typedef tfxx::Handle<Tinterpolator> Thipo;
474 Thipo hipo(
new ts::ipo::LinearInterpolator(inseries, opt.
debug));
479 outseries=ts::ipo::resample(*hipo, firstsample, newdt, nsamples,
482 catch (ts::ipo::ExceptionTimeWindowOutside)
484 cout <<
"NOTICE: skipping this trace silently..." << endl;
487 catch (ts::ipo::ExceptionTimeWindowEmpty)
489 cout <<
"NOTICE: skipping this trace silently..." << endl;
496 cout <<
" time window returned from interpolator:" << endl
498 << outseries.header.date.timestring() << endl
500 << sff::wid2lastsample(outseries.header).timestring() << endl
501 <<
" number of samples: " 502 << outseries.header.nsamples << endl;
504 TFXX_debug(opt.
debug,
"main",
505 " series is resampled");
506 os << outseries.header;
507 TFXX_debug(opt.
debug,
"main",
508 " series and WID are written");
509 if (is.hasinfo()) { sff::INFO info; is >> info; os << info; }
510 if (is.hasfree() ||
true)
515 tracefree.append(
"read from file " + infile->name);
519 TFXX_debug(opt.
debug,
"main",
520 "trace #" << itrace <<
" successfully processed");
525 TFXX_debug(opt.
debug,
"main",
"skip trace #" << itrace );
527 { std::cout <<
" skip trace #" << itrace << std::endl; }
ts::sff::SFFTimeSeries< Tseries > Ttimeseries
static const char * cmdlinekeys[]
bool sampleoffsetbeginset
Ttimeseries::Tseries Tseries
const char *const tracekey
key to select traces
aff::Series< double > Tseries