TS++ library: time series library
ovtaper.cc
Go to the documentation of this file.
1 
37 #define TSXX_OVTAPER_CC_VERSION \
38  "TSXX_OVTAPER_CC V1.2"
39 
40 #include <fstream>
41 #include <sstream>
42 #include <tsxx/tsxx.h>
43 #include <tsxx/debug.h>
44 #include <tsxx/ovtaper.h>
45 #include <tsxx/error.h>
46 
47 namespace ts {
48 
49  namespace tapers {
50 
51  namespace ovtaper {
52 
54  void Picks::read(std::istream& is)
55  {
56  Mpicks.clear();
57  std::string line;
58  do {
59  TSXX_assert(getline(is, line),
60  "Picks::read: error while reading taper definition");
61  } while (line.substr(0,9)!="taper set");
62 
63  TSXX_debug(Mdebug, "Picks::read",
64  "found data line:\n" << line);
65 
66  std::istringstream iss(line.substr(17,4));
67  int n;
68  iss >> n;
69  TSXX_debug(Mdebug, "Picks::read",
70  "read " << n << " picks");
71 
72  // skip one line
73  TSXX_assert(getline(is, line),
74  "Picks::read: error while reading taper definition");
75  for (int i=0; i<n; ++i)
76  {
77  Pick p;
78  TSXX_assert(is >> p.x >> p.t,
79  "Picks::read: error while reading taper definition");
80  Mpicks.push_back(p);
81  TSXX_debug(Mdebug, "Picks::read",
82  "#" << i << " x=" << p.x << ", t=" << p.t);
83  }
84 
85  Mpicks.sort();
86  } // void Picks::read(std::istream& is)
87 
88  /*----------------------------------------------------------------------*/
89 
90  Pick Picks::pick(const double& offset) const
91  {
92  Pick p(offset);
93  if (!Mpicks.empty())
94  {
95  Tlistofpick::const_iterator P=Mpicks.begin();
96  if ((*P) > p)
97  {
98  p.t=P->t;
99  }
100  else
101  {
102  Tlistofpick::const_iterator Pp=P;
103  while ((P!=Mpicks.end()) && (*P<p)) { Pp=P; P++; }
104  if (P==Pp)
105  {
106  p.t=P->t;
107  }
108  else if (P==Mpicks.end())
109  {
110  p.t=Pp->t;
111  }
112  else
113  {
114  p.t=Pp->t+(P->t-Pp->t)*(p.x-Pp->x)/(P->x-Pp->x);
115  }
116  }
117  }
118  return p;
119  } // Pick Picks::pick(const double& offset) const
120 
121  /*----------------------------------------------------------------------*/
122 
123  double Picks::time(const double& offset) const
124  {
125  Pick p=this->pick(offset);
126  return(p.t);
127  } // double Picks::time(const double& offset) const
128 
129  } // namespace ovtaper
130 
131  /*======================================================================*/
132 
134  const double& T0,
135  const double& T) const
136  {
138  "OffsetVariableTaper::taper: "
139  "taper is undefined");
140  // calculate times in units of the duration of the time series
141  double t1=(Mt1.time(offset)-T0)/T;
142  double t2=(Mt2.time(offset)-T0)/T;
143  double t3=(Mt3.time(offset)-T0)/T;
144  double t4=(Mt4.time(offset)-T0)/T;
145  // keep values in bounds of time series
146  t1 = t1 >= 0. ? t1 : 0.;
147  t2 = t2 >= 1.e-6 ? t2 : 1.e-6;
148  t3 = t3 <= .99999 ? t3 : .99999;
149  t4 = t4 <= 1. ? t4 : 1.;
150  // initialize taper
151  ts::tapers::FourPoint fpt(t1, t2, t3, t4);
152  return(fpt);
153  } // ts::tapers::FourPoint OffsetVariableTaper::taper(...)
154 
155  /*----------------------------------------------------------------------*/
156 
159  void OffsetVariableTaper::read(std::istream& is)
160  {
161  Mt1.read(is);
162  Mt2.read(is);
163  Mt3.read(is);
164  Mt4.read(is);
165  Mvalid=true;
166  } // void OffsetVariableTaper::read(std::istream& is)
167 
168  /*----------------------------------------------------------------------*/
169 
172  void OffsetVariableTaper::read(const std::string& filename)
173  {
174  std::ifstream is(filename.c_str());
175  TSXX_assert(is.good(),
176  "OffsetVariableTaper::read(): "
177  "error when opening taper file");
178  this->read(is);
179  } // void OffsetVariableTaper::read(const std::string& filename)
180 
181  } // namespace tapers
182 
183 } // namespace ts
184 
185 /* ----- END OF ovtaper.cc ----- */
double time(const double &offset) const
return time for interpolated pick at given offset
Definition: ovtaper.cc:123
ts::tapers::FourPoint taper(const double &offset, const double &T0, const double &T) const
Definition: ovtaper.cc:133
debug macro (prototypes)
bool Mdebug
produce debug output if true
Definition: ovtaper.h:86
ovtaper::Picks t1() const
Definition: ovtaper.h:132
Tlistofpick Mpicks
picks
Definition: ovtaper.h:88
void read(std::istream &is)
Definition: ovtaper.cc:159
error handling for libtsxx (prototypes)
Pick pick(const double &offset) const
return interpolated pick for given offset
Definition: ovtaper.cc:90
#define TSXX_debug(C, N, M)
produce debug output
Definition: debug.h:51
offset variable taper (prototypes)
a single pick
Definition: ovtaper.h:57
ovtaper::Picks Mt1
taper picks
Definition: ovtaper.h:142
All stuff in this library will be placed within namespace ts.
Definition: anyfilter.cc:43
double x
offset
Definition: ovtaper.h:61
ovtaper::Picks t3() const
Definition: ovtaper.h:134
#define TSXX_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:127
basic modules of time series library in C++ (prototypes)
ovtaper::Picks t4() const
Definition: ovtaper.h:135
ovtaper::Picks t2() const
Definition: ovtaper.h:133
Provides a 4-point taper.
Definition: tapers.h:140
bool Mvalid
true if taper definition is present
Definition: ovtaper.h:140
void read(std::istream &is)
read from file in refract taper file format
Definition: ovtaper.cc:54