TS++ library: time series library
tstest.cc
Go to the documentation of this file.
1 
40 #define TSTEST_VERSION \
41  "TSTEST V1.5 test time series modules"
42 
43 #include <tfxx/commandline.h>
44 #include <iostream>
45 #include <tsxx/tsxx.h>
46 #include <aff/dump.h>
47 #include <tsxx/convolve.h>
48 #include <tsxx/random.h>
49 #include <tsxx/dropcontainer.h>
50 #include <tsxx/tapers.h>
51 #include <tsxx/ovtaper.h>
52 #include <tsxx/seifeclass.h>
53 #include <tsxx/filter.h>
54 
55 using std::cout;
56 using std::cerr;
57 using std::endl;
58 
59 struct Options {
64  std::string ovtaperfile;
65 }; // struct Options
66 
67 int main(int iargc, char* argv[])
68 {
69 
70  // define usage information
71  char usage_text[]=
72  {
73  TSTEST_VERSION "\n"
74  "usage: tstest [-c1] [-c2] [-r] [-drop] [-tap] [-ovtap f]" "\n"
75  " or: tstest --help|-h" "\n"
76  };
77 
78  // define full help text
79  char help_text[]=
80  {
81  "-c1 convolution test 1" "\n"
82  "-c2 convolution test 2" "\n"
83  "-r random noise test" "\n"
84  "-drop drop container test" "\n"
85  "-tap test tapers" "\n"
86  "-ovtap f test OffsetVariableTaper by reading taper from file f" "\n"
87  "\n"
88  };
89 
90  // define commandline options
91  using namespace tfxx::cmdline;
92  static Declare options[]=
93  {
94  // 0: print help
95  {"help",arg_no,"-"},
96  // 1: verbose mode
97  {"v",arg_no,"-"},
98  // 2: convolution test 1
99  {"c1",arg_no,"-"},
100  // 3: convolution test 2
101  {"c2",arg_no,"-"},
102  // 4: random noise test
103  {"r",arg_no,"-"},
104  // 5: drop container test
105  {"drop",arg_no,"-"},
106  // 6: taper test
107  {"tap",arg_no,"-"},
108  // 7: OffsetVariableTaper test
109  {"ovtap",arg_yes,"-"},
110  {NULL}
111  };
112 
113  // no arguments? print usage...
114  if (iargc<2)
115  {
116  cerr << usage_text << endl;
117  exit(0);
118  }
119 
120  // collect options from commandline
121  Commandline cmdline(iargc, argv, options);
122 
123  // help requested? print full help text...
124  if (cmdline.optset(0))
125  {
126  cerr << usage_text << endl;
127  cerr << help_text << endl;
128  ts::fir::help(cerr);
129  cerr << endl;
131  cerr << endl;
132  ts::seife::print_help(cerr);
133  exit(0);
134  }
135 
136  Options opt;
137  opt.convtest1=cmdline.optset(2);
138  opt.convtest2=cmdline.optset(3);
139  opt.randomnoise=cmdline.optset(4);
140  opt.droptest=cmdline.optset(5);
141  opt.tapertest=cmdline.optset(6);
142  opt.ovtapertest=cmdline.optset(7);
143  opt.ovtaperfile=cmdline.string_arg(7);
144 
145  /*======================================================================*/
146 
147  if (opt.convtest1)
148  {
149  aff::Series<double> a(-2,2), b(-3,3), c, d;
150  cout << endl;
151  cout << "convolution test 1" << endl;
152  for (int i=a.f(); i<=a.l(); ++i) { a(i)=i; }
153  for (int i=b.f(); i<=b.l(); ++i) { b(i)=i; }
154  DUMP( a );
155  DUMP( b );
156  DUMP( ts::convolve(a,b) );
157  c=a;
158  c.shift(-c.f());
159  DUMP( c );
160  DUMP( ts::convolve(c,b) );
161  d=b;
162  d.shift(-d.f());
163  DUMP( d );
164  DUMP( ts::convolve(c,d) );
165  }
166 
167  /*======================================================================*/
168 
169  if (opt.convtest2)
170  {
171  aff::Series<double> a(-2,2), b(-3,3);
172  cout << endl;
173  cout << "convolution test 2" << endl;
174  for (int i=a.f(); i<=a.l(); ++i) { a(i)=1; }
175  for (int i=b.f(); i<=b.l(); ++i) { b(i)=1; }
176  DUMP( a );
177  DUMP( b );
178  DUMP( ts::convolve(a,b) );
179  }
180 
181  /*======================================================================*/
182 
183  if (opt.randomnoise)
184  {
185  cout << "test random noise generation" << endl;
187  DUMP( s );
188  s=ts::rnd::dugauss(10);
189  DUMP( s );
190  }
191 
192  /*======================================================================*/
193 
194  if (opt.droptest)
195  {
196  cout << "test drop containers" << endl;
197  aff::Series<int> a(1,108);
198  for (int i=a.f(); i<=a.l(); ++i) { a(i)=i; }
203  cout << "downsampling with factor " << d1.downsampling_factor() << endl;
204  cout << "downsampling with gain " << d1.gain() << endl;
205  d1.attach(d2)->attach(d3)->attach(pass)->attach(d1);
206  cout << "downsampling with factor " << d1.downsampling_factor() << endl;
207  cout << "downsampling with gain " << d1.gain() << endl;
208  d1.initialize(a.size());
209  cout << "downsampling with factor " << d1.downsampling_factor() << endl;
210  cout << "downsampling with gain " << d1.gain() << endl;
211  for (int i=a.f(); i<=a.l(); ++i) { d1.drop(a(i)); }
212  DUMP( a );
213  DUMP( d1.container() );
214 
215  cout << ts::fir::SeisCompMP << endl;
216  cout << ts::fir::SeisCompLP << endl;
217  cout << ts::fir::SeisCompVLP << endl;
218  aff::Series<double> b(1,1000);
219  for (int i=b.f(); i<=b.l(); ++i) { b(i)=i; }
222 // d4.attach(d5);
223  d4.initialize(b.size());
224  for (int i=b.f(); i<=b.l(); ++i) { d4.drop(b(i)); }
225  DUMP( d4.container() );
226  }
227 
228  /*======================================================================*/
229 
230  if (opt.tapertest)
231  {
232  cout << "test taper" << endl;
233  aff::Series<double> a(-5,5);
234  a=1.;
235  DUMP( a );
237  h.apply(a);
238  DUMP( a );
239 
240 
241  aff::Series<double> b(-50,50);
242  b=1;
243  h.apply(b);
244  for (int i=b.f(); i<=b.l(); ++i)
245  {
246  cout << i << " " << b(i) << endl;
247  }
248  }
249 
250  /*======================================================================*/
251 
252  if (opt.ovtapertest)
253  {
255  ovt.read(opt.ovtaperfile);
256  const int n=30;
257  const double xmax=90.;
258  const double dx=xmax/n;
259  ts::tapers::ovtaper::Picks picks=ovt.t3();
260  for (int i=0; i<n; ++i)
261  {
262  double x=dx*i-9.;
263  cout << "x=" << x << " t=" << picks.time(x) << "\n";
264  }
265 
266  ts::tapers::FourPoint taper=ovt.taper(30., 0., 1.);
267  aff::Series<double> b(-50,50);
268  b=1;
269  taper.apply(b);
270  for (int i=b.f(); i<=b.l(); ++i)
271  {
272  cout << i << " " << b(i) << endl;
273  }
274  }
275 
276 }
277 
278 /* ----- END OF tstest.cc ----- */
Tdseries dugauss(const int &n)
return gaussian uniform noise (standard dev=1, zero mean)
Definition: random.cc:72
double time(const double &offset) const
return time for interpolated pick at given offset
Definition: ovtaper.cc:123
void apply(C c) const
apply taper to series container c.
Definition: tapers.h:162
bool droptest
Definition: tstest.cc:62
int main(int iargc, char *argv[])
Definition: tstest.cc:67
ts::tapers::FourPoint taper(const double &offset, const double &T0, const double &T) const
Definition: ovtaper.cc:133
aff::Series< T > convolve(const aff::ConstSeries< T > &a, const aff::ConstSeries< T > &b)
Calculate convolution of two series.
Definition: convolve.h:103
some time series filter classes (prototypes)
virtual PDropContainer attach(const DropContainer &c)
std::string ovtaperfile
Definition: tstest.cc:64
bool tapertest
Definition: tstest.cc:62
bool convtest1
Definition: tstest.cc:60
a sequence of picks
Definition: ovtaper.h:74
virtual int downsampling_factor() const
const FIR SeisCompVLP
Definition: firfilters.cc:164
Offset variable taper (refract taper).
Definition: ovtaper.h:100
bool randomnoise
Definition: tstest.cc:61
void read(std::istream &is)
Definition: ovtaper.cc:159
bool ovtapertest
Definition: tstest.cc:63
a container to drop samples into it (prototypes)
const FIR SeisCompMP
Definition: firfilters.cc:55
offset variable taper (prototypes)
virtual const Tseries::Tcoc & container() const
virtual void drop(const Tvalue &v)
this function accepts samples
virtual Tvalue gain() const
void help(std::ostream &os)
Definition: firfilters.cc:203
ovtaper::Picks t3() const
Definition: ovtaper.h:134
const FIR SeisCompLP
Definition: firfilters.cc:97
void print_help(std::ostream &os)
print usage information
Definition: seifeclass.cc:214
virtual void initialize(const int &n)
initialize for n samples input
basic modules of time series library in C++ (prototypes)
aff::Series< double > Tdseries
Definition: random.h:50
#define TSTEST_VERSION
Definition: tstest.cc:40
create a random series (prototypes)
provide all needed to use BasicFilter with seife code (prototypes)
virtual void drop(const Tvalue &v)
this function accepts samples
void print_help(std::ostream &os)
print usage information
Definition: filter.cc:517
Provides a 4-point taper.
Definition: tapers.h:140
convolve to series (prototypes)
bool convtest2
Definition: tstest.cc:60
provide signal tapers (prototypes)
Provides a Hanning taper (no parameters):
Definition: tapers.h:111