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

introduced compare utility

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: 1461
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 4fda7cc2
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id: Makefile,v 1.6 2003-12-30 17:18:52 tforb Exp $
# $Id: Makefile,v 1.7 2004-01-28 15:56:08 tforb Exp $
#
# Copyright (c) 2003 by Thomas Forbriger (BFO Schiltach)
#
......@@ -48,7 +48,7 @@ clean: ;
# library part
# ------------
LIBSRC=sffxx.cc
LIBSRC=sffxx.cc wid2compare.cc
INCSRC=sffxx.h
-include $(patsubst %.cc,%.d,$(LIBSRC))
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: sffxx.h,v 1.8 2004-01-11 17:54:04 tforb Exp $
* $Id: sffxx.h,v 1.9 2004-01-28 15:56:09 tforb Exp $
* \author Thomas Forbriger
* \date 21/12/2003
*
......@@ -29,7 +29,7 @@
#define TF_SFFXX_H_VERSION \
"TF_SFFXX_H V1.2 "
#define TF_SFFXX_H_CVSID \
"$Id: sffxx.h,v 1.8 2004-01-11 17:54:04 tforb Exp $"
"$Id: sffxx.h,v 1.9 2004-01-28 15:56:09 tforb Exp $"
#include<string>
#include<list>
......@@ -384,6 +384,47 @@ namespace sff {
Mvalid=true;
} // InputWaveform::read
/*======================================================================*/
// some utilities
// --------------
/*----------------------------------------------------------------------*/
// compare WID2 headers
// --------------------
enum Ewid2field {
Fdate =1<<0,
Fstation =1<<1,
Fchannel =1<<2,
Fauxid =1<<3,
Fnsamples=1<<4,
Fdt =1<<5,
Fcalib =1<<6,
Fcalper =1<<7,
Finstype =1<<8,
Fhang =1<<9,
Fvang =1<<10
}; // enum Ewid2field
class WID2compare {
public:
WID2compare(const int& flags=(Fstation | Fchannel | Fdt)):
Mflags(flags), Mdttolerance(0.) { }
void set(const int& flags) { Mflags=Mflags | flags; }
void clear(const int& flags) { Mflags=Mflags & (0xffffffff ^ flags); }
void setdttolerance(const double& tol) { Mdttolerance=tol; }
void setdatetolerance(const libtime::TRelativeTime& tol)
{ Mdatetolerance=tol; }
bool operator()(const WID2& hd1, const WID2& hd2) const;
int flags() const { return(Mflags); }
double dttolerance() const { return(Mdttolerance); }
libtime::TRelativeTime datetolerance() const { return(Mdatetolerance); }
private:
int Mflags;
double Mdttolerance;
libtime::TRelativeTime Mdatetolerance;
}; // class WID2compare
} // namespace sff
#endif // TF_SFFXX_H_VERSION (includeguard)
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: wid2compare.cc,v 1.1 2004-01-28 15:11:07 tforb Exp $
* $Id: wid2compare.cc,v 1.2 2004-01-28 15:56:09 tforb Exp $
* \author Thomas Forbriger
* \date 28/01/2004
*
......@@ -19,12 +19,38 @@
#define TF_WID2COMPARE_CC_VERSION \
"TF_WID2COMPARE_CC V1.0 "
#define TF_WID2COMPARE_CC_CVSID \
"$Id: wid2compare.cc,v 1.1 2004-01-28 15:11:07 tforb Exp $"
"$Id: wid2compare.cc,v 1.2 2004-01-28 15:56:09 tforb Exp $"
#include <wid2compare.h>
#include <cmath>
#include <sffxx.h>
#include <tfxx/error.h>
namespace tf {
namespace sff {
}
bool WID2compare::operator()(const WID2& hd1, const WID2& hd2) const
{
bool retval=true;
if (Mflags & Fdate) {
TFXX_abort("ERROR: date comparison not yet implemented!");
}
if (Mflags & Fstation) { retval=retval && (hd1.station==hd2.station); }
if (Mflags & Fchannel) { retval=retval && (hd1.channel==hd2.channel); }
if (Mflags & Fauxid) { retval=retval && (hd1.auxid==hd2.auxid); }
if (Mflags & Fnsamples) { retval=retval && (hd1.nsamples==hd2.nsamples); }
if (Mflags & Fdt)
{
double diff=hd1.dt-hd2.dt;
diff = diff >= 0. ? diff : -diff;
retval=retval && (diff <= (hd1.dt*Mdttolerance));
}
if (Mflags & Fcalib) { retval=retval && (hd1.calib==hd2.calib); }
if (Mflags & Fcalper) { retval=retval && (hd1.calper==hd2.calper); }
if (Mflags & Finstype) { retval=retval && (hd1.instype==hd2.instype); }
if (Mflags & Fhang) { retval=retval && (hd1.hang==hd2.hang); }
if (Mflags & Fvang) { retval=retval && (hd1.vang==hd2.vang); }
return(retval);
}; // WID2compare::operator()
} // namespace sff
/* ----- END OF wid2compare.cc ----- */
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