Commit 9efcca5d authored by Daniel Armbruster's avatar Daniel Armbruster Committed by thomas.forbriger
Browse files

Ready.

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.

Improved the algorithm to calculate the smallest subset, so that adding new
'cut off' commandline arguments should be straightforward. Up to now cutting off
an abitrary number of samples and/or an arbitrary number of seconds is supported.

Heavily tested - hopefully enough ;-)


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 4658
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent a0b5b2f9
......@@ -39,6 +39,8 @@
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <tfxx/commandline.h>
#include <tfxx/xcmdline.h>
#include <tfxx/error.h>
......@@ -56,8 +58,8 @@ using std::endl;
struct Options {
bool verbose, overwrite, debug, integer, single;
unsigned int firstsamples, lastsamples;
int durationsamples;
int firstsamples, lastsamples, durationsamples;
double firstseconds, lastseconds, durationseconds;
std::string inputformat, outputformat;
}; // struct Options
......@@ -73,8 +75,8 @@ int main(int iargc, char* argv[])
"usage: tijerasxx [--verbose] [--overwrite] [--integer] [--single]" "\n"
" [--iformat T] [--oformat T]" "\n"
" [--samplesf N] [--samplesl N] [--samplesd N]" "\n"
" OUTFILE INFILE [t:T] [f:F]" "\n"
" [INFILE [t:T] [f:F] ... ]" "\n"
" [--secondsf N] [--secondsl N] [--secondsd N]" "\n"
" OUTFILE INFILE [t:T] [f:F] [INFILE [t:T] [f:F] ... ]\n"
" or: tijerasxx --help|-h" "\n"
" or: tijerasxx --xhelp" "\n"
};
......@@ -98,8 +100,14 @@ int main(int iargc, char* argv[])
"Data selection:" "\n"
"--samplesf N cut off N samples from the beginning of the timeseries\n"
"--samplesl N cut off N samples from the end of the timeseries\n"
"--samplesd N cut off after N samples beginning from '--samplesf'\n"
"Note that tijerasxx always will select the smallest subset passed by" "\n"
"--samplesd N cut off after N samples beginning from '--samplesf' or\n"
" '--secondsf'" "\n"
"--secondsf N cut off N seconds from the beginning of the timeseries\n"
"--secondsl N cut off N seconds from the end of the timeseries\n"
"--secondsd N cut off after N seconds beginning from '--samplesf' or\n"
" '--secondsf'" "\n"
"----" "\n"
"Note that tijerasxx always will compute the smallest subset passed by\n"
"the arguments above." "\n"
"\n"
"OUTFILE output data file name" "\n"
......@@ -141,8 +149,14 @@ int main(int iargc, char* argv[])
{"samplesf",arg_yes,"0"},
// 10: cut off N samples from the end
{"samplesl",arg_yes,"0"},
// 11: cut off after N samples beginning from samplesf
// 11: cut off after N samples
{"samplesd",arg_yes,"-1"},
// 12: cut off N seconds from the beginning
{"secondsf",arg_yes,"0."},
// 13: cut off N seconds from the end
{"secondsl",arg_yes,"0."},
// 14: cut off after N seconds
{"secondsd",arg_yes,"-1."},
{NULL}
};
......@@ -174,11 +188,11 @@ int main(int iargc, char* argv[])
{
cout << usage_text << endl;
cout << help_text << endl;
datrw::supported_data_types(cerr);
datrw::supported_data_types(cout);
if (cmdline.optset(1))
{
cout << endl;
datrw::online_help(cerr);
datrw::online_help(cout);
}
exit(0);
}
......@@ -195,6 +209,9 @@ int main(int iargc, char* argv[])
opt.firstsamples=cmdline.int_arg(9);
opt.lastsamples=cmdline.int_arg(10);
opt.durationsamples=cmdline.int_arg(11);
opt.firstseconds=cmdline.double_arg(12);
opt.lastseconds=cmdline.double_arg(13);
opt.durationseconds=cmdline.double_arg(14);
// extract commandline arguments
TFXX_assert(cmdline.extra(), "missing output file");
......@@ -351,29 +368,86 @@ int main(int iargc, char* argv[])
sff::WID2 wid2;
is >> wid2;
// compute smallest subset to cut off the series
unsigned int nsamples = wid2.nsamples;
if (0 < opt.firstsamples)
// calculate smallest subset to cut off the series
// ---------------------
// compute start sample
int nsamples = wid2.nsamples;
std::vector<int> start(2);
std::vector<int> end;
TFXX_assert(0 < (nsamples-opt.firstsamples) && 0 <= opt.firstsamples,
"ERROR: Timeseries of zero length selected ('--samplesf').");
start[0] = opt.firstsamples;
int samples_seconds = static_cast<int>(opt.firstseconds/wid2.dt);
TFXX_assert(0 < (nsamples-samples_seconds) && 0 <= samples_seconds,
"ERROR: Timeseries of zero length selected ('--secondsf').");
start[1] = samples_seconds;
int start_sample = *(std::max_element(start.begin(),start.end()));
// set wid2 header appropriately
if (0 < start_sample)
{
TFXX_assert(0 < (nsamples-opt.firstsamples),
"ERROR: Timeseries of zero length selected.")
nsamples -= opt.firstsamples;
double seconds = wid2.dt*opt.firstsamples;
nsamples -= start_sample;
double seconds = wid2.dt*start_sample;
int sec = static_cast<int>(seconds);
int milsec = static_cast<int>(seconds-sec);
libtime::TRelativeTime t(0,0,0,0,sec,milsec);
int milsec = static_cast<int>((seconds-sec)*1000);
int micsec = static_cast<int>((seconds-sec-milsec)*1000000);
libtime::TRelativeTime t(0,0,0,sec,milsec,micsec);
wid2.date += t;
}
if (0 < opt.durationsamples &&
opt.durationsamples < (nsamples-opt.lastsamples))
// ---------------------
// compute end index in aff series
int end_idx = wid2.nsamples-1;
// add max possible index
end.push_back(end_idx);
// sample handling
if (0 <= opt.durationsamples)
{
wid2.nsamples = opt.durationsamples;
} else
TFXX_assert(0 < opt.durationsamples,
"ERROR: Timeseries of zero length ('--samplesd').");
cout << "nsamples: " << nsamples << endl;
if (opt.durationsamples >= wid2.nsamples ||
opt.durationsamples > nsamples)
{
opt.durationsamples = wid2.nsamples;
}
end.push_back(start_sample+opt.durationsamples-1);
}
if (0 <= opt.lastsamples)
{
TFXX_assert(0 < (nsamples-opt.lastsamples),
"ERROR: Negative range or timeseries of zero length.")
wid2.nsamples = nsamples-opt.lastsamples;
"ERROR: Timeseries of zero length ('--samplesl').");
end.push_back(wid2.nsamples-1-opt.lastsamples);
}
// seconds handling
if (0 < opt.durationseconds)
{
int s = static_cast<int>(opt.durationseconds/wid2.dt);
if (s >= wid2.nsamples || s > nsamples)
{
s = wid2.nsamples;
}
end.push_back(start_sample+s-1);
}
if (0 < opt.lastseconds)
{
int s = static_cast<int>(opt.lastseconds/wid2.dt);
TFXX_assert(0 < (nsamples-s),
"ERROR: Timeseries of zero length ('--secondsl').");
end.push_back(wid2.nsamples-1-s);
}
if (end.size() > 0)
{
end_idx = *(std::min_element(end.begin(), end.end()));
}
// complete wid2 header information
if (end_idx >= 0)
{ wid2.nsamples = nsamples - (wid2.nsamples-1 - end_idx); }
else
{ wid2.nsamples = nsamples; }
if (opt.verbose) { cout << wid2; }
os << wid2;
......@@ -452,21 +526,18 @@ int main(int iargc, char* argv[])
// write output
if (opt.integer)
{
datrw::Tiseries result_series(iseries(opt.firstsamples),
iseries(opt.firstsamples+wid2.nsamples));
os << result_series;
iseries.setindexrange(start_sample, end_idx);
os << iseries;
}
else if (opt.single)
{
datrw::Tfseries result_series(fseries(opt.firstsamples),
fseries(opt.firstsamples+wid2.nsamples));
os << result_series;
fseries.setindexrange(start_sample, end_idx);
os << fseries;
}
else
{
datrw::Tdseries result_series(dseries(opt.firstsamples),
dseries(opt.firstsamples+wid2.nsamples));
os << result_series;
dseries.setindexrange(start_sample, end_idx);
os << dseries;
}
} // if ((!doselect) || traceranges.contains(itrace))
else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment