103 "usage: sigval [-format s] [-type f] file [t:l] [file [t:l] ...]" "\n" 105 " or: sigval --help|-h" "\n" 106 " or: sigval --xhelp" "\n" 112 "-format s define a format string for output lines" "\n" 113 "-type f define file format of input files" "\n" 114 "-rms Calculate total rms value over all traces assuming that\n" 115 " all traces have the same physical sample units.\n" 117 "Patterns that may be used in format descriptions are:" "\n" 119 "%NT number of trace in file" "\n" 120 "%COO trace coordinates" "\n" 121 "%SCO source coordinates" "\n" 122 "%OFF trace offset" "\n" 123 "%D date of first sample" "\n" 124 "%T time of first sample" "\n" 125 "%UT time of first sample including microsecond" "\n" 126 "%HT hierarchical time string (can be used as control parameter\n" 127 " for programs selecting a time window - like resaseda)\n" 128 "%L time duration of signal" "\n" 129 "%SI sampling interval in seconds" "\n" 130 "%NS number of samples" "\n" 131 "%S station identifier" "\n" 132 "%C channel identifier" "\n" 133 "%A auxiliary identifier" "\n" 134 "%I instrument identifier" "\n" 135 "%MEAN signal average" "\n" 136 "%MIN minimum value in signal" "\n" 137 "%MAX maximum value in signal" "\n" 138 "%PPA peak-to-peak amplitude" "\n" 139 "%RMS rms of signal" "\n" 140 "%XT tab character" "\n" 141 "%% will be replaced by a literal \'%\'" "\n" 145 using namespace tfxx::cmdline;
146 static Declare options[]=
151 {
"format",arg_yes,
"%F(t#%NT) %S %C"},
153 {
"type",arg_yes,
"sff"},
155 {
"xhelp",arg_no,
"-"},
169 cerr << usage_text << endl;
170 cerr << tfxx::seitosh::repository_reference << endl;
175 Commandline cmdline(iargc, argv, options);
178 if (cmdline.optset(0))
180 cerr << usage_text << endl;
181 cerr << help_text << endl;
182 datrw::supported_data_types(cerr);
183 cerr << endl << tfxx::seitosh::repository_reference << endl;
187 if (cmdline.optset(3))
189 cerr << usage_text << endl;
190 datrw::online_help(cerr);
191 cerr << endl << tfxx::seitosh::repository_reference << endl;
201 TFXX_assert(cmdline.extra(),
"missing input file");
202 tfxx::cmdline::Tparsed arguments=parse_cmdline(cmdline,
cmdlinekeys);
208 double overallrms=0., totaltime=0.;
212 tfxx::cmdline::Tparsed::const_iterator infile=arguments.begin();
213 while (infile != arguments.end())
216 std::ifstream ifs(infile->name.c_str());
224 typedef tfxx::RangeList<int> Trangelist;
225 bool doselect=infile->haskey(
tracekey);
226 Trangelist traceranges=
227 tfxx::string::rangelist<Trangelist::Tvalue>(infile->value(
tracekey));
232 if ((!doselect) || traceranges.contains(itrace))
243 std::ostringstream oss;
246 retval=tfxx::string::patsubst(retval,
"%F",
251 if (info.cs == sff::CS_cartesian)
253 oss <<
"cartesian coordinates:";
255 else if (info.cs == sff::CS_spherical)
257 oss <<
"spherical coordinates:";
261 oss <<
"unknown coordinate system:";
263 oss <<
" c1=" << info.cx;
264 oss <<
" c2=" << info.cy;
265 oss <<
" c3=" << info.cz;
266 retval=tfxx::string::patsubst(retval,
"%COO",
267 tfxx::string::trimws(oss.str()));
271 if (srce.cs == sff::CS_cartesian)
273 oss <<
"cartesian source coordinates:";
275 else if (srce.cs == sff::CS_spherical)
277 oss <<
"spherical source coordinates:";
281 oss <<
"unknown source coordinate system:";
283 oss <<
" s1=" << srce.cx;
284 oss <<
" s2=" << srce.cy;
285 oss <<
" s3=" << srce.cz;
286 retval=tfxx::string::patsubst(retval,
"%SCO",
287 tfxx::string::trimws(oss.str()));
290 if (is.hassrce() && is.hasinfo())
293 oss <<
" r=" << sff::offset(srce, info) <<
"m";
294 retval=tfxx::string::patsubst(retval,
"%OFF",
295 tfxx::string::trimws(oss.str()));
299 TFXX_assert(retval.find(
"%OFF") == std::string::npos,
300 "offset cannot be calculated, because either SRCE or INFO\n" 301 "is missing in input file");
307 retval=tfxx::string::patsubst(retval,
"%NT",
308 tfxx::string::trimws(oss.str()));
310 std::string timestring=wid2.date.timestring();
312 retval=tfxx::string::patsubst(retval,
"%D",
313 timestring.substr(4,10));
315 retval=tfxx::string::patsubst(retval,
"%T",
316 timestring.substr(15,8));
318 retval=tfxx::string::patsubst(retval,
"%UT",
319 timestring.substr(15,15));
322 retval=tfxx::string::patsubst(retval,
"%HT",
323 wid2.date.hierarchicalstring());
325 libtime::TRelativeTime duration=
326 libtime::double2time(wid2.dt)*(series.size()-1);
327 retval=tfxx::string::patsubst(retval,
"%L",
328 duration.timestring());
332 retval=tfxx::string::patsubst(retval,
"%SI",
333 tfxx::string::trimws(oss.str()));
336 oss << series.size();
337 retval=tfxx::string::patsubst(retval,
"%NS",
338 tfxx::string::trimws(oss.str()));
340 retval=tfxx::string::patsubst(retval,
"%S",
341 tfxx::string::trimws(wid2.station));
343 retval=tfxx::string::patsubst(retval,
"%C",
344 tfxx::string::trimws(wid2.channel));
346 retval=tfxx::string::patsubst(retval,
"%A",
347 tfxx::string::trimws(wid2.auxid));
349 retval=tfxx::string::patsubst(retval,
"%I",
350 tfxx::string::trimws(wid2.instype));
353 retval=tfxx::string::patsubst(retval,
"%XT",
"\t");
356 double avg=aff::func::avg(series);
359 retval=tfxx::string::patsubst(retval,
"%MEAN",
360 tfxx::string::trimws(oss.str()));
362 double max=aff::func::max(series);
365 retval=tfxx::string::patsubst(retval,
"%MAX",
366 tfxx::string::trimws(oss.str()));
368 double min=aff::func::min(series);
371 retval=tfxx::string::patsubst(retval,
"%MIN",
372 tfxx::string::trimws(oss.str()));
374 double ppamp=(max-min);
375 if (ppamp < 0) { ppamp *= -1; }
378 retval=tfxx::string::patsubst(retval,
"%PPA",
379 tfxx::string::trimws(oss.str()));
381 double rms=aff::func::rms(series);
384 retval=tfxx::string::patsubst(retval,
"%RMS",
385 tfxx::string::trimws(oss.str()));
388 retval=tfxx::string::patsubst(retval,
"%%",
"%");
390 cout << retval << endl;
393 overallrms+=aff::func::sqrsum(series);
395 totaltime += (wid2.dt*series.size());
412 overallrms=std::sqrt(overallrms/totaltime);
414 <<
"The overall rms value is: " << overallrms <<
"\n" 415 <<
" This value is calculated by integration of the total signal\n" 416 <<
" power of all traces over time. This integral is divided by\n" 417 <<
" the total time of integration and the square root of this\n" 418 <<
" is presented as the overall rms values. Notice that this\n" 419 <<
" implies that all trace have the same physical units for\n" 420 <<
" their sample values. If not, the outcome is meaningless."
static const char * cmdlinekeys[]
const char *const tracekey
key to select traces
aff::Series< double > Tseries