Commit b39412b0 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

merged feature branch; new tijerasxx version

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.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 4881
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent a477363a
......@@ -90,7 +90,9 @@ $(LOCBINDIR)/%: %
#----------------------------------------------------------------------
flist: Makefile $(wildcard *.f *.cc)
TESTCASEMAKE=$(filter-out %.bak,$(wildcard testcases/Makefile*))
flist: Makefile $(wildcard *.f *.cc) $(TESTCASEMAKE)
echo $^ | tr ' ' '\n' | sort > $@
.PHONY: edit
......
This is a legacy version of the repository. It may be incomplete as well as
inconsistent. See README.history for details. For the old stock of the
repository copyright and licence conditions apply as specified for versions
commited after 2015-03-01. Use recent versions as a base for new development.
The legacy version is only stored to keep a record of history.
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id$
#
# Copyright (c) 2012 by Thomas Forbriger (BFO Schiltach)
#
# test cases for header modifiers
#
# REVISIONS and CHANGES
# 13/12/2012 V1.0 Thomas Forbriger
#
# ============================================================================
#
all:
TESTCASEMAKE=$(filter-out %.bak,$(wildcard Makefile*))
flist: $(TESTCASEMAKE) $(wildcard *.par) $(wildcard *.tpl)
echo $^ | tr ' ' '\n' | sort > $@
.PHONY: edit
edit: flist; vim $<
.PHONY: clean
clean: ;
-find . -name \*.bak | xargs --no-run-if-empty /bin/rm -v
-/bin/rm -vf flist *.xxx *.xxx.* *.sff *.TZ *.TR *.grn *.su
-/bin/rm -vf *.ps *.pdf *.asc *.bin
#----------------------------------------------------------------------
# test cases for soutifu
tijerasxx.ps: Makefile.tijerasxx ; $(MAKE) -f $< $@
#----------------------------------------------------------------------
%.psp: %.ps; gv -infoSilent $<; /bin/rm -fv $<
%.pdf: %.ps; ps2pdf $<
%.rw.ps: %.ps; gs -sDEVICE=pswrite -dNOPAUSE -dBATCH -sOutputFile=$@ $<
%.fix.ps: %.ps; fixps $< > $@
%.2up.ps: %.ps; psnup -r -l -2 -Pa4 -pa4 $< > $@
%.rs.ps: %.ps; psresize -Pa4 -pa5 $< > $@
%.pngp: %.png; xv $<; /bin/rm -fv $<
# ----- END OF Makefile -----
# this is <Makefile.tijerasxx>
# ----------------------------------------------------------------------------
# $Id: $
#
# Copyright (c) 2012 by Thomas Forbriger (BFO Schiltach)
#
# test cases for tijerasxx
#
# REVISIONS and CHANGES
# 13/12/2012 V1.0 Thomas Forbriger
#
# ============================================================================
#
all: tijerasxx.ps
BN=tijerasxx
BND=2012/12/12
BNDT=0.05
$(BN).asc:
siggenx 1 $@ -ot ascii -o -T 2. -d $(BNDT) -f 0.5
$(BN).m.asc: $(BN).asc
egrep -v 'date:' $< > $@
$(BN).1.asc: $(BN).m.asc
any2any -verb -over -itype ascii:date=$(BND) -otype ascii $@ $^
$(BN).2.asc: $(BN).m.asc
any2any -verb -over -itype ascii:date=$(BND)/0/0/3 -otype ascii $@ $^
$(BN).3.asc: $(BN).m.asc
any2any -verb -over -itype ascii:date=$(BND)/0/0/6 -otype ascii $@ $^
$(BN).bin: $(BN).1.asc $(BN).2.asc $(BN).3.asc
any2any -verb -over -itype ascii -otype bin $@ $^
BNOP=--verb --over -iformat bin -oformat bin -DEB
$(BN)t1.bin: $(BN).bin
tijerasxx $(BNOP) --samplesf=20 -samplesl=10 $@ $<
$(BN)t2.bin: $(BN).bin
tijerasxx $(BNOP) --secondsf=0.4 -secondsd=0.2 $@ $<
$(BN)t3.bin: $(BN).bin
tijerasxx $(BNOP) --datesf=2012/12/12/0/0/3.50\
--datesl=2012/12/12/0/0/6.00 --datesd=0/0/0/0.2 $@ $<
BNPOPS=n:"%F %T" sf:1.1
$(BN).ps: $(BN).bin $(BN)t1.bin $(BN)t2.bin $(BN)t3.bin
stuploxx -dev $@/ps \
-title="tijerasxx test; dt=$(BNDT)s" -tstitle=0.6 \
-labr -labe -labh 0.13 \
$(word 1,$^) p:1 f:bin $(BNPOPS) \
$(word 2,$^) p:2 f:bin $(BNPOPS) \
$(word 3,$^) p:3 f:bin $(BNPOPS) \
$(word 4,$^) p:4 f:bin $(BNPOPS)
# ----- END OF Makefile.tijerasxx -----
......@@ -31,12 +31,15 @@
* 24/05/2012 V0.2 cut time window by passing timestrings
* 15/09/2012 V0.3 fixed bug in microsecond computation setting date of
* first sample in WID2 header line
* 13/12/2012 V1.0 thof:
* reworked evaluation of new time window
* empty time ranges are allowed
*
* ============================================================================
*/
#define TIJERASXX_VERSION \
"TIJERASXX V0.2 simply cut off timeseries data"
"TIJERASXX V1.0 simply cut off timeseries data"
#define TIJERASXX_SVNID \
"$Id$"
......@@ -400,195 +403,257 @@ int main(int iargc, char* argv[])
sff::WID2 wid2;
is >> wid2;
/*------------------------------------------------------------*/
// 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;
if (opt.firstdateSet)
// a flag indicating an empty time range - just in case
bool ResultIsEmpty=false;
long int newFirstSample=0;
long int newLastSample=0;
{
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
if (0 < start_sample)
{
nsamples -= start_sample;
double seconds = wid2.dt*start_sample;
int sec = static_cast<int>(seconds);
int milsec = static_cast<int>((seconds-sec)*1000);
int micsec = static_cast<int>((seconds-sec-milsec*0.001)*1000000);
libtime::TRelativeTime t(0,0,0,sec,milsec,micsec);
wid2.date += t;
}
// ---------------------
// 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)
{
TFXX_assert(0 < opt.durationsamples,
"ERROR: Timeseries of zero length ('--samplesd').");
end.push_back(start_sample+opt.durationsamples-1);
}
if (0 <= opt.lastsamples)
{
TFXX_assert(0 < (nsamples-opt.lastsamples),
"ERROR: Timeseries of zero length ('--samplesl').");
end.push_back(wid2.nsamples-1-opt.lastsamples);
}
// extract coordinates of input data
libtime::TRelativeTime dt=libtime::double2time(wid2.dt);
libtime::TAbsoluteTime TimeOfFirst=wid2.date;
libtime::TAbsoluteTime TimeOfLast=sff::wid2lastsample(wid2);
TFXX_debug(opt.debug, "tijerasxx (main)",
TFXX_value(TimeOfFirst.timestring())
<< "\n " <<
TFXX_value(TimeOfLast.timestring()));
// set values as defined on command line
// -------------------------------------
/*
* first find the lastest time of the first sample as specified by
* any of the options
*/
// samples options
libtime::TAbsoluteTime
SamplesTimeOfFirst=TimeOfFirst+opt.firstsamples*dt;
// seconds options
libtime::TAbsoluteTime
SecondsTimeOfFirst
=TimeOfFirst+libtime::double2time(opt.firstseconds);
// date options
libtime::TAbsoluteTime DateTimeOfFirst=TimeOfFirst;
TFXX_debug(opt.debug, "tijerasxx (main)",
TFXX_value(SamplesTimeOfFirst.timestring())
<< "\n " <<
TFXX_value(SecondsTimeOfFirst.timestring())
<< "\n " <<
TFXX_value(DateTimeOfFirst.timestring()));
if (opt.firstdateSet)
{
DateTimeOfFirst=opt.firstdate;
}
// new first
libtime::TAbsoluteTime NewTimeOfFirst=TimeOfFirst;
if (NewTimeOfFirst<SamplesTimeOfFirst)
{ NewTimeOfFirst=SamplesTimeOfFirst; }
if (NewTimeOfFirst<SecondsTimeOfFirst)
{ NewTimeOfFirst=SecondsTimeOfFirst; }
if (NewTimeOfFirst<DateTimeOfFirst)
{ NewTimeOfFirst=DateTimeOfFirst; }
TFXX_debug(opt.debug, "tijerasxx (main)",
TFXX_value(NewTimeOfFirst.timestring()));
/*
* the find the earliest time of the last sample as specified by any
* of the options
* duration options have precendence over last options
* duration options refer to new first time as evaluated above
*/
// samples options
libtime::TAbsoluteTime
SamplesTimeOfLast=TimeOfLast-opt.lastsamples*dt;
if (opt.durationsamples>0)
{
SamplesTimeOfLast=NewTimeOfFirst+opt.durationsamples*dt;
}
// seconds options
libtime::TAbsoluteTime
SecondsTimeOfLast
=TimeOfLast-libtime::double2time(opt.lastseconds);
if (opt.durationseconds>0)
{
SecondsTimeOfLast
=NewTimeOfFirst+libtime::double2time(opt.durationseconds);
}
// date options
libtime::TAbsoluteTime DateTimeOfLast=TimeOfLast;
if (opt.lastdateSet)
{
DateTimeOfLast=opt.lastdate;
}
if (opt.durationdateSet)
{
DateTimeOfLast=NewTimeOfFirst+opt.durationdate;
}
// seconds handling
if (0 < opt.durationseconds)
{
int s = static_cast<int>(opt.durationseconds/wid2.dt);
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);
TFXX_debug(opt.debug, "tijerasxx (main)",
TFXX_value(SamplesTimeOfLast.timestring())
<< "\n " <<
TFXX_value(SecondsTimeOfLast.timestring())
<< "\n " <<
TFXX_value(DateTimeOfLast.timestring()));
// new last
libtime::TAbsoluteTime NewTimeOfLast=TimeOfLast;
if (NewTimeOfLast>SamplesTimeOfLast)
{ NewTimeOfLast=SamplesTimeOfLast; }
if (NewTimeOfLast>SecondsTimeOfLast)
{ NewTimeOfLast=SecondsTimeOfLast; }
if (NewTimeOfLast>DateTimeOfLast)
{ NewTimeOfLast=DateTimeOfLast; }
TFXX_debug(opt.debug, "tijerasxx (main)",
TFXX_value(NewTimeOfLast.timestring()));
// check if result is empty
// ------------------------
if ((NewTimeOfLast<NewTimeOfFirst)
|| (NewTimeOfLast<TimeOfFirst)
|| (NewTimeOfFirst>TimeOfLast))
{
ResultIsEmpty=true;
if (opt.verbose)
{
std::cout
<< "time range of input series: "
<< TimeOfFirst.timestring()
<< " - "
<< TimeOfLast.timestring()
<< std::endl;
std::cout
<< "new time range as specified: "
<< NewTimeOfFirst.timestring()
<< " - "
<< NewTimeOfLast.timestring()
<< std::endl;
std::cout
<< "notice: the intersection is empty!\n"
<< "the series will be skipped"
<< std::endl;
}
}
else // not empty
{
newFirstSample=sff::wid2isample(wid2, NewTimeOfFirst);
newLastSample=sff::wid2isample(wid2, NewTimeOfLast);
// values should be fine; just for safety:
if (newFirstSample<0) { newFirstSample=0; }
if (newFirstSample>=wid2.nsamples)
{ newFirstSample=wid2.nsamples-1; }
if (newLastSample<newFirstSample)
{ newLastSample=newFirstSample; }
if (newLastSample>=wid2.nsamples)
{ newLastSample=wid2.nsamples-1; }
}
}
// 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)
// output data only if not empty
if (!ResultIsEmpty)
{
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; }
// adjust wid2
sff::WID2 newwid2(wid2);
newwid2.date=sff::wid2isample(wid2, newFirstSample);
newwid2.nsamples=newLastSample-newFirstSample+1;
if (opt.verbose) { cout << wid2; }
if (opt.verbose) { cout << newwid2; }
os << wid2;
os << newwid2;
TFXX_debug(opt.debug, "tijerasxx: trace header data availability",
" is.hasinfo(): " << is.hasinfo() <<
" is.hasfree(): " << is.hasfree());
TFXX_debug(opt.debug, "tijerasxx: trace header data availability",
" is.hasinfo(): " << is.hasinfo() <<
" is.hasfree(): " << is.hasfree());
// pass INFO
if (is.hasinfo())
{
if (os.handlesinfo())
// pass INFO
if (is.hasinfo())
{
sff::INFO infoline;
is >> infoline;
os << infoline;
TFXX_debug(opt.debug, "tijerasxx: INFO data",
infoline.line());
if (os.handlesinfo())
{
sff::INFO infoline;
is >> infoline;
os << infoline;
TFXX_debug(opt.debug, "tijerasxx: INFO data",
infoline.line());
}
else
{
if (opt.verbose)
{
cout << " INFO line is discarded." << endl;
}
}
}
else
// pass trace FREE
if (is.hasfree())
{
if (opt.verbose)
if (os.handlestracefree())
{
sff::FREE freeblock;
is >> freeblock;
freeblock.append("Edited with: ");
freeblock.append(TIJERASXX_VERSION);
freeblock.append(TIJERASXX_SVNID);
os << freeblock;
}
else
{
cout << " INFO line is discarded." << endl;
if (opt.verbose)
{
cout << " trace FREE block is discarded." << endl;
}
}
}
}
// pass trace FREE
if (is.hasfree())
{
if (os.handlestracefree())
// check output data format
switch (os.seriestype()) {
case datrw::Fint:
if (!opt.integer)
{
cout << " WARNING: converting floating point data to integer!"
<< endl;
}
break;
case datrw::Ffloat:
if (!(opt.single || opt.integer))
{
cout << " WARNING: "
"converting double precision to single precision data!"
<< endl;
}
break;
case datrw::Fdouble:
// that's just fine
break;
case datrw::Fall:
// that's just fine
break;
default:
TFXX_abort("output stream uses unknown variable type!");
} // switch (os.seriestype())
// write output
if (opt.integer)
{
iseries.setindexrange(newFirstSample, newLastSample);
os << iseries;
}
else if (opt.single)
{
sff::FREE freeblock;
is >> freeblock;
freeblock.append("Edited with: ");
freeblock.append(TIJERASXX_VERSION);
freeblock.append(TIJERASXX_SVNID);
os << freeblock;
fseries.setindexrange(newFirstSample, newLastSample);
os << fseries;
}
else
{
if (opt.verbose)
{
cout << " trace FREE block is discarded." << endl;
}
dseries.setindexrange(newFirstSample, newLastSample);
os << dseries;
}
}
// check output data format
switch (os.seriestype()) {
case datrw::Fint:
if (!opt.integer)
{
cout << " WARNING: converting floating point data to integer!"
<< endl;
}
break;
case datrw::Ffloat:
if (!(opt.single || opt.integer))
{
cout << " WARNING: "
"converting double precision to single precision data!"
<< endl;
}
break;
case datrw::Fdouble:
// that's just fine
break;
case datrw::Fall:
// that's just fine
break;
default:
TFXX_abort("output stream uses unknown variable type!");
} // switch (os.seriestype())
// write output
if (opt.integer)
{
iseries.setindexrange(start_sample, end_idx);
os << iseries;
}
else if (opt.single)
{
fseries.setindexrange(start_sample, end_idx);
os << fseries;
}
else
{
dseries.setindexrange(start_sample, end_idx);
os << dseries;
}
} // if (!ResultIsEmpty)
} // 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