DATRW++ library: seismic data I/O with multiple formats
sfftest.cc
Go to the documentation of this file.
1 /*! \file sfftest.cc
2  * \brief test SFF reading
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 19/06/2007
8  *
9  * test SFF reading
10  *
11  * Copyright (c) 2007 by Thomas Forbriger (BFO Schiltach)
12  *
13  * ----
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27  * ----
28  *
29  * REVISIONS and CHANGES
30  * - 19/06/2007 V1.0 Thomas Forbriger
31  *
32  * ============================================================================
33  */
34 #define SFFTEST_VERSION \
35  "SFFTEST V1.0 test SFF reading"
36 
37 #include <iostream>
38 #include <fstream>
39 #include <tfxx/commandline.h>
40 #include <datrwxx/error.h>
41 #include <datrwxx/sff.h>
42 
43 using std::cout;
44 using std::cerr;
45 using std::endl;
46 
47 typedef aff::Series<double> Tseries;
48 
49 struct Options {
50  bool debug, verbose, streams;
51  bool count;
52  int nprint;
53 }; // struct Options
54 
55 int main(int iargc, char* argv[])
56 {
57 
58  // define usage information
59  char usage_text[]=
60  {
61  SFFTEST_VERSION "\n"
62  "usage: sfftest [-D] [-v] [-s] filename ..." "\n"
63  " or: sfftest --help|-h" "\n"
64  };
65 
66  // define full help text
67  char help_text[]=
68  {
69  "\n"
70  "filename ... SFF data files for reading" "\n"
71  "\n"
72  "-D DEBUG mode" "\n"
73  "-v verbose mode" "\n"
74  "-s use streams" "\n"
75  "-n=val display only vale samples at start end end of file" "\n"
76  "-c only count samples" "\n"
77  };
78 
79  // define commandline options
80  using namespace tfxx::cmdline;
81  static Declare options[]=
82  {
83  // 0: print help
84  {"help",arg_no,"-"},
85  // 1: verbose mode
86  {"v",arg_no,"-"},
87  // 2: DEBUG mode
88  {"D",arg_no,"-"},
89  // 3: stream mode
90  {"s",arg_no,"-"},
91  // 4: count samples
92  {"c",arg_no,"-"},
93  // 5: number of samples
94  {"n",arg_yes,"10" },
95  {NULL}
96  };
97 
98  // no arguments? print usage...
99  if (iargc<2)
100  {
101  cerr << usage_text << endl;
102  exit(0);
103  }
104 
105  // collect options from commandline
106  Commandline cmdline(iargc, argv, options);
107 
108  // help requested? print full help text...
109  if (cmdline.optset(0))
110  {
111  cerr << usage_text << endl;
112  cerr << help_text << endl;
113  exit(0);
114  }
115 
116  Options opt;
117  opt.verbose=cmdline.optset(1);
118  opt.debug=cmdline.optset(2);
119  opt.streams=cmdline.optset(3);
120  opt.count=cmdline.optset(4);
121  opt.nprint=cmdline.int_arg(5);
122 
123  while (cmdline.extra())
124  {
125  std::string filename=cmdline.next();
126  if (opt.verbose)
127  {
128  std::cout << std::endl;
129  std::cout << "file: " << filename << std::endl;
130  }
131 
132  std::ifstream ifs(filename.c_str());
133  if (opt.streams)
134  {
135  datrw::isffstream is(ifs);
136  if (opt.verbose) { is.free().write(std::cout); }
137  datrw::Tiseries iseries;
138  if (opt.count)
139  {
140  is.skipseries();
141  }
142  else
143  {
144  is >> iseries;
145  }
146  if (opt.verbose)
147  {
148  std::cout << is.wid2().line() << std::endl;
149  }
150  if ((!opt.count) && (opt.verbose))
151  {
152  int npr=
153  opt.nprint < int(iseries.size()/2) ?
154  opt.nprint : iseries.size()/2;
155  for (int i=0; i<npr; ++i)
156  { std::cout << i << " " << iseries(i) << std::endl; }
157  std::cout << " ... " << std::endl;
158  for (int i=iseries.size()-npr; i<int(iseries.size()); ++i)
159  { std::cout << i << " " << iseries(i) << std::endl; }
160  }
161  }
162  else
163  {
164  sff::FileHeader fileheader(ifs, opt.debug);
165  if (opt.verbose)
166  {
167  cout << "read file header:" << endl;
168  fileheader.write(cout);
169  cout << "-----------------" << endl << endl;
170  }
171  bool last=false;
172  while (!last)
173  {
174  sff::InputWaveform<Tseries> inputwaveform(ifs, opt.debug);
175  if (opt.verbose)
176  {
177  cout << "read trace header:" << endl;
178  inputwaveform.header().writeheader(cout);
179  inputwaveform.header().writetrailer(cout);
180  cout << "------------------" << endl << endl;
181  }
182  last=inputwaveform.last();
183  }
184  }
185  }
186 }
187 
188 /* ----- END OF sfftest.cc ----- */
aff::Series< double > Tseries
Definition: sfftest.cc:47
bool streams
Definition: pdastest.cc:53
sff::WID2 wid2() const
Definition: datread.h:111
read sff data (prototypes)
class to read SFF data
Definition: sff.h:76
int main(int iargc, char *argv[])
Definition: sfftest.cc:55
exception class declaration for libdatrwxx (prototypes)
int nprint
Definition: pdastest.cc:52
bool debug
Definition: asciitest.cc:52
sff::FREE free() const
Definition: datread.cc:79
bool verbose
Definition: asciitest.cc:51
#define SFFTEST_VERSION
Definition: sfftest.cc:34
aff::Series< int > Tiseries
Definition: types.h:47
bool count
Definition: pdastest.cc:51
virtual void skipseries()
Definition: isffstream.cc:128