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

cut window by passing absolute time or rather relative time (in case a

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.
duration had been specified)


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 4715
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent ed5d13c2
......@@ -27,13 +27,14 @@
* Copyright (c) 2012 by Daniel Armbruster
*
* REVISIONS and CHANGES
* 02/03/2012 V0.1 Daniel Armbruster
* 02/03/2012 V0.1 Daniel Armbruster
* 24/05/2012 V0.2 cut time window by passing timestrings
*
* ============================================================================
*/
#define TIJERASXX_VERSION \
"TIJERASXX V0.1 simply cut off timeseries data"
"TIJERASXX V0.2 simply cut off timeseries data"
#define TIJERASXX_SVNID \
"$Id$"
......@@ -60,6 +61,9 @@ struct Options {
bool verbose, overwrite, debug, integer, single;
int firstsamples, lastsamples, durationsamples;
double firstseconds, lastseconds, durationseconds;
libtime::TAbsoluteTime firstdate, lastdate;
libtime::TRelativeTime durationdate;
bool firstdateSet, lastdateSet, durationdateSet;
std::string inputformat, outputformat;
}; // struct Options
......@@ -76,6 +80,7 @@ int main(int iargc, char* argv[])
" [--iformat T] [--oformat T]" "\n"
" [--samplesf N] [--samplesl N] [--samplesd N]" "\n"
" [--secondsf N] [--secondsl N] [--secondsd N]" "\n"
" [--datesf DAT] [--datesl DAT] [--datesd DUR]" "\n"
" OUTFILE INFILE [t:T] [f:F] [INFILE [t:T] [f:F] ... ]\n"
" or: tijerasxx --help|-h" "\n"
" or: tijerasxx --xhelp" "\n"
......@@ -100,12 +105,16 @@ 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' 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"
"--samplesd N cut off after N samples beginning from '--samplesf'," "\n"
" '--secondsf' or '--datesf'" "\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'," "\n"
" '--secondsf' or '--datesf'" "\n"
"--datesf DAT start timeseries at date DAT" "\n"
"--datesl DAT finish timeseries at date DAT" "\n"
"--datesd DUR cut off timeseries after duration DUR beginning from" "\n"
" '--samplesf', '--secondsf' or '--datesf'" "\n"
"----" "\n"
"Note that tijerasxx always will compute the smallest subset passed by\n"
"the arguments above." "\n"
......@@ -157,6 +166,12 @@ int main(int iargc, char* argv[])
{"secondsl",arg_yes,"0."},
// 14: cut off after N seconds
{"secondsd",arg_yes,"-1."},
// 15: start time of window
{"datesf", arg_yes, "-"},
// 16: end time of window
{"datesl", arg_yes, "-"},
// 17: time window duration set by time
{"datesd", arg_yes, "-"},
{NULL}
};
......@@ -212,6 +227,21 @@ int main(int iargc, char* argv[])
opt.firstseconds=cmdline.double_arg(12);
opt.lastseconds=cmdline.double_arg(13);
opt.durationseconds=cmdline.double_arg(14);
opt.firstdateSet=cmdline.optset(15);
opt.lastdateSet=cmdline.optset(16);
opt.durationdateSet=cmdline.optset(17);
if (opt.firstdateSet)
{
opt.firstdate=libtime::TAbsoluteTime(cmdline.string_arg(15));
}
if (opt.lastdateSet)
{
opt.lastdate=libtime::TAbsoluteTime(cmdline.string_arg(16));
}
if (opt.durationdateSet)
{
opt.durationdate=libtime::TRelativeTime(cmdline.string_arg(17));
}
// extract commandline arguments
TFXX_assert(cmdline.extra(), "missing output file");
......@@ -372,6 +402,7 @@ int main(int iargc, char* argv[])
// ---------------------
// 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,
......@@ -381,6 +412,14 @@ int main(int iargc, char* argv[])
TFXX_assert(0 < (nsamples-samples_seconds) && 0 <= samples_seconds,
"ERROR: Timeseries of zero length selected ('--secondsf').");
start[1] = samples_seconds;
if (opt.firstdateSet)
{
int samples_date = static_cast<int>(
libtime::time2double(opt.firstdate-wid2.date)/wid2.dt);
TFXX_assert(0 < (nsamples-samples_date) && 0 <= samples_date,
"ERROR: Timeseries of zero length selected ('--datesf').");
start.push_back(samples_date);
}
int start_sample = *(std::max_element(start.begin(),start.end()));
// set wid2 header appropriately
......@@ -427,6 +466,25 @@ int main(int iargc, char* argv[])
"ERROR: Timeseries of zero length ('--secondsl').");
end.push_back(wid2.nsamples-1-s);
}
// date handling
if (opt.durationdateSet)
{
int samples = static_cast<int>(
libtime::time2double(opt.durationdate)/wid2.dt);
TFXX_assert(0 < (nsamples-samples),
"ERROR: Timeseries of zero length ('--datesd').");
end.push_back(start_sample+samples-1);
}
if (opt.lastdateSet)
{
int s = static_cast<int>(
libtime::time2double(opt.lastdate-wid2.date)/wid2.dt);
TFXX_assert(0 < (nsamples-s),
"ERROR: Timeseries of zero length ('--datesl').");
end.push_back(start_sample+s-1);
}
if (end.size() > 0)
{
end_idx = *(std::min_element(end.begin(), end.end()));
......
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