Commit b1e94bfa authored by thomas.forbriger's avatar thomas.forbriger
Browse files

ts/wf/cross [WP]: set proper time values

parent 355a947b
......@@ -242,6 +242,9 @@ int main(int iargc, char* argv[])
Tts reference;
bool referenceread=false;
// file header information for reference trace
ts::sff::FileHeader referencefileheader;
// cycle through list of file names found on command line
tfxx::cmdline::Tparsed::const_iterator infile=arguments.begin();
while (infile!=arguments.end())
......@@ -261,7 +264,6 @@ int main(int iargc, char* argv[])
// ------------------
ts::sff::FileHeader fileheader;
is >> fileheader;
if (!referenceread) { os << fileheader; }
// cycle through traces of input file
// ----------------------------------
......@@ -286,11 +288,35 @@ int main(int iargc, char* argv[])
if (opt.verbose) { std::cout << "process trace #" << iftrace << ": "; }
if (!referenceread)
{
// handle file header of reference
// -------------------------------
// set a SRCE definition if not present in input and mode is
// cross-correlation
sff::FREE freeblock(fileheader.free());
freeblock.append(CROSS_VERSION);
// SRCE date is a reference time for cross-correlograms
if (!opt.convolve)
{
if (!fileheader.hassrce())
{
sff::SRCE srce;
srce.date=libtime::TAbsoluteTime(2000);
fileheader.srce(srce);
freeblock.append("added SRCE definition to file header");
}
}
fileheader.free(freeblock);
os << fileheader;
referencefileheader=fileheader;
// read actual reference time series
// ---------------------------------
if (opt.verbose)
{ std::cout << "read reference trace" << std::endl; }
is >> reference;
referenceread=true;
if (opt.verbose) { cout << reference.header.wid2().line() << endl; }
// remember
}
else
{
......@@ -305,10 +331,62 @@ int main(int iargc, char* argv[])
if (opt.convolve)
{
result=ts::convolve(reference,data);
wid2line.auxid="corr";
wid2line.auxid="conv";
// set time of first sample
// ------------------------
if (referencefileheader.hasfree())
{
// offset of impulse response
libtime::TRelativeTime t0(reference.header.wid2().date
-referencefileheader.srce().date);
if (reference.header.wid2().date
<referencefileheader.srce().date)
{
wid2line.date -= t0;
}
else
{
wid2line.date += t0;
}
}
} else {
result=ts::correlate(reference,data);
wid2line.auxid="conv";
wid2line.auxid="corr";
/*
* Time delay of current signal with respect to first sample of
* reference signal to be understood as a signed value:
*
* tor = signal.date-ref.date
*
* Duration of reference signal: Tr
* Duration of current signal: Ts
*
* Duration of cross-correlogram: Tr+Ts
*
* lag time of first sample:
*
* tl1=tor-(Tr+Ts)/2
*/
libtime::TRelativeTime
Tr(libtime::double2time(reference.header.wid2().dt
*(reference.header.wid2().nsamples-1)));
libtime::TRelativeTime
Ts(libtime::double2time(data.header.wid2().dt
*(data.header.wid2().nsamples-1)));
libtime::TRelativeTime tor(data.header.wid2().date
-reference.header.wid2().date);
libtime::TAbsoluteTime
torigin=referencefileheader.srce().date-((Tr+Ts)/2);
if (data.header.wid2().date
>=reference.header.wid2().date)
{
torigin += tor;
}
else
{
torigin -= tor;
}
wid2line.date=torigin;
}
result *= wid2line.dt;
result.header.wid2(wid2line);
......
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