DATRW++ library: seismic data I/O with multiple formats
hpmotest.cc
Go to the documentation of this file.
1 /*! \file hpmotest.cc
2  * \brief test hpmo reading functions
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 21/12/2004
8  *
9  * test hpmo reading functions
10  *
11  * ----
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25  * ----
26  *
27  * Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
28  *
29  * REVISIONS and CHANGES
30  * - 21/12/2004 V1.0 Thomas Forbriger
31  *
32  * ============================================================================
33  */
34 #define HPMOTEST_VERSION \
35  "HPMOTEST V1.0 test hpmo reading functions"
36 
37 #include <fstream>
38 #include <iostream>
39 #include <tfxx/commandline.h>
40 #include <datrwxx/error.h>
41 #include <datrwxx/readhpmo.h>
42 #include <datrwxx/hpmo.h>
43 #include <datrwxx/readany.h>
44 #include <aff/dump.h>
45 
46 using std::cout;
47 using std::cerr;
48 using std::endl;
49 
50 struct Options {
52 }; // struct Options
53 
54 int main(int iargc, char* argv[])
55 {
56 
57  // define usage information
58  char usage_text[]=
59  {
60  HPMOTEST_VERSION "\n"
61  "usage: hpmotest [-v] [-s1] [-s2] [-s3] [-x] filename" "\n"
62  " or: hpmotest --help|-h" "\n"
63  };
64 
65  // define full help text
66  char help_text[]=
67  {
68  "filename file to read" "\n"
69  "-v be verbose" "\n"
70  "-s1 test reading functions of stage 1" "\n"
71  "-s2 test reading functions of stage 2" "\n"
72  "-s3 test reading functions of stage 3" "\n"
73  "-s4 test reading functions of stage 4" "\n"
74  "-x extract samples in stage 3 and 4" "\n"
75  };
76 
77  // define commandline options
78  using namespace tfxx::cmdline;
79  static Declare options[]=
80  {
81  // 0: print help
82  {"help",arg_no,"-"},
83  // 1: verbose mode
84  {"v",arg_no,"-"},
85  // 2: test stage 1
86  {"s1",arg_no,"-"},
87  // 3: test stage 2
88  {"s2",arg_no,"-"},
89  // 4: test stage 3
90  {"s3",arg_no,"-"},
91  // 5: extract samples
92  {"x",arg_no,"-"},
93  // 6: test stage 4
94  {"s4",arg_no,"-"},
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  /* dummy operation: print option settings
117  for (int iopt=0; iopt<2; iopt++)
118  {
119  cout << "option: '" << options[iopt].opt_string << "'" << endl;
120  if (cmdline.optset(iopt)) { cout << " option was set"; }
121  else { cout << "option was not set"; }
122  cout << endl;
123  cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
124  cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
125  cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
126  cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
127  cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
128  cout << " argument (bool): '";
129  if (cmdline.bool_arg(iopt))
130  { cout << "true"; } else { cout << "false"; }
131  cout << "'" << endl;
132  }
133  while (cmdline.extra()) { cout << cmdline.next() << endl; }
134 
135  // dummy operation: print rest of command line
136  while (cmdline.extra()) { cout << cmdline.next() << endl; }
137  */
138 
139  Options opt;
140  opt.verbose=cmdline.optset(1);
141  opt.stage1=cmdline.optset(2);
142  opt.stage2=cmdline.optset(3);
143  opt.stage3=cmdline.optset(4);
144  opt.extractsamples=cmdline.optset(5);
145  opt.stage4=cmdline.optset(6);
146 
147  DATRW_assert(cmdline.extra(), "missing filename!");
148  std::string infile=cmdline.next();
149 
150  if (opt.verbose) { cout << "reading file " << infile << endl; }
151 
152 /*----------------------------------------------------------------------*/
153 
154  if (opt.stage1)
155  {
156  if (opt.verbose)
157  {
158  cout << endl << "TEST: stage 1" << endl
159  << "=============" << endl;
160  }
161  std::ifstream ifs(infile.c_str());
162  DATRW_assert(ifs.good(), "invalid file!");
163  datrw::hpmo::Header header;
164  datrw::hpmo::SampleBlock samples;
165  bool hot=true;
166  while (ifs.good() && hot)
167  {
168  try {
169  ifs >> header;
171  {
172  cout << "End of file!" << endl;
173  hot=false;
174  }
175  if (hot)
176  {
177  if (opt.verbose) { cout << header; }
178  if (ifs.good())
179  {
180  ifs >> samples;
181  if (opt.verbose) { cout << samples; }
182  }
183  }
184  }
185  }
186 
187 /*----------------------------------------------------------------------*/
188 
189  if (opt.stage2)
190  {
191  if (opt.verbose)
192  {
193  cout << endl << "TEST: stage 2" << endl
194  << "=============" << endl;
195  }
196  std::ifstream ifs(infile.c_str());
197  DATRW_assert(ifs.good(), "invalid file!");
198  if (opt.verbose)
199  {
200  cout << endl << "read whole file" << endl;
201  }
203  =datrw::hpmo::readfile(ifs, opt.verbose);
204  if (opt.verbose)
205  {
206  cout << endl << "read " << blocks.size() << " blocks" << endl;
207  }
208  datrw::hpmo::Tvecofblocks::const_iterator I(blocks.begin());
209  while (I!=blocks.end())
210  {
211  cout << *I;
212  ++I;
213  }
214  }
215 
216 /*----------------------------------------------------------------------*/
217 
218  if (opt.stage3)
219  {
220  if (opt.verbose)
221  {
222  cout << endl << "TEST: stage 3" << endl
223  << "=============" << endl;
224  }
225  std::ifstream ifs(infile.c_str());
226  DATRW_assert(ifs.good(), "invalid file!");
227  datrw::ihpmostream is(ifs, opt.verbose);
228  sff::FREE filefree;
229  is >> filefree;
230  cout << filefree;
231  while (is.good())
232  {
234  if (opt.extractsamples)
235  {
236  is >> data;
237  }
238  else
239  {
240  is.skipseries();
241  }
242  sff::WID2 wid2line;
243  cout << std::endl << "next trace: " << std::endl;
244  is >> wid2line;
245  cout << wid2line;
246  sff::FREE tracefree;
247  is >> tracefree;
248  cout << tracefree;
249  if (opt.extractsamples) { DUMP( data ); }
250  }
251  }
252 
253 /*----------------------------------------------------------------------*/
254 
255  if (opt.stage4)
256  {
257  if (opt.verbose)
258  {
259  cout << endl << "TEST: stage 4" << endl
260  << "=============" << endl;
261  }
262  std::ifstream ifs(infile.c_str());
263  DATRW_assert(ifs.good(), "invalid file!");
265  sff::FREE filefree;
266  is >> filefree;
267  cout << filefree;
268  while (is.good())
269  {
271  if (opt.extractsamples)
272  {
273  is >> data;
274  }
275  else
276  {
277  is.skipseries();
278  }
279  sff::WID2 wid2line;
280  cout << std::endl << "next trace: " << std::endl;
281  is >> wid2line;
282  cout << wid2line;
283  sff::FREE tracefree;
284  is >> tracefree;
285  cout << tracefree;
286  if (opt.extractsamples) { DUMP( data ); }
287  }
288  }
289 }
290 
291 /* ----- END OF hpmotest.cc ----- */
int main(int iargc, char *argv[])
Definition: hpmotest.cc:54
provides all specific data reading classes (prototypes)
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
class to read HPMO data
Definition: hpmo.h:61
aff::Series< float > Tfseries
Definition: types.h:46
std::vector< MinuteBlock > Tvecofblocks
within the inner reading functions, we use vector to hold minute blocks
Definition: readhpmo.h:67
#define HPMOTEST_VERSION
Definition: hpmotest.cc:34
bool stage3
Definition: hpmotest.cc:51
exception class declaration for libdatrwxx (prototypes)
Read, hold and handle one minute block header line.
Definition: readhpmo.h:88
const char *const data
keywords for consistency checks
Class to read any type of data file.
Definition: readany.h:82
this excpetion will be thrown by the Header reading function, in case it does not find something that...
Definition: readhpmo.h:77
bool stage1
Definition: hpmotest.cc:51
hold samples of one minute-block
Definition: hpmodata.h:58
bool verbose
Definition: asciitest.cc:51
bool extractsamples
Definition: hpmotest.cc:51
bool stage2
Definition: hpmotest.cc:51
Tvecofblocks readfile(std::istream &is, const bool &verbose)
read a full data file
Definition: readhpmo.cc:216
provide data from HP Mo (BFO data acquisition system) (prototypes)
bool stage4
Definition: hpmotest.cc:51