DATRW++ library: seismic data I/O with multiple formats
pdastest.cc
Go to the documentation of this file.
1 /*! \file pdastest.cc
2  * \brief test pdas reading functions
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 07/04/2004
8  *
9  * test pdas 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  * - 07/04/2004 V1.0 Thomas Forbriger
31  * - 19/10/2004 V1.1 support different data types
32  *
33  * ============================================================================
34  */
35 #define PDASTEST_VERSION \
36  "PDASTEST V1.0 test pdas reading functions"
37 
38 #include <fstream>
39 #include <iostream>
40 #include <tfxx/commandline.h>
41 #include <datrwxx/error.h>
42 #include <datrwxx/pdasread.h>
43 #include <datrwxx/pdas.h>
44 
45 using std::cout;
46 using std::cerr;
47 using std::endl;
48 
49 struct Options {
50  bool verbose;
51  bool count;
52  int nprint;
53  bool streams;
54 }; // struct Options
55 
56 int main(int iargc, char* argv[])
57 {
58 
59  // define usage information
60  char usage_text[]=
61  {
62  PDASTEST_VERSION "\n"
63  "usage: pdastest [-v] [-n=val] [-c] [-s] filename ..." "\n"
64  " or: pdastest --help|-h" "\n"
65  };
66 
67  // define full help text
68  char help_text[]=
69  {
70  "\n"
71  "filename file to read" "\n"
72  "\n"
73  "-v be verbose" "\n"
74  "-n=val display only vale samples at start end end of file" "\n"
75  "-c only count samples" "\n"
76  "-s use streams" "\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: count samples
88  {"c",arg_no,"-"},
89  // 3: number of samples
90  {"n",arg_yes,"10" },
91  // 4: use streams
92  {"s",arg_no,"-"},
93  {NULL}
94  };
95 
96  // no arguments? print usage...
97  if (iargc<2)
98  {
99  cerr << usage_text << endl;
100  exit(0);
101  }
102 
103  // collect options from commandline
104  Commandline cmdline(iargc, argv, options);
105 
106  // help requested? print full help text...
107  if (cmdline.optset(0))
108  {
109  cerr << usage_text << endl;
110  cerr << help_text << endl;
111  exit(0);
112  }
113 
114  Options opt;
115  opt.verbose=cmdline.optset(1);
116  opt.count=cmdline.optset(2);
117  opt.nprint=cmdline.int_arg(3);
118  opt.streams=cmdline.optset(4);
119 
120  /*
121  // dummy operation: print option settings
122  for (int iopt=0; iopt<2; iopt++)
123  {
124  cout << "option: '" << options[iopt].opt_string << "'" << endl;
125  if (cmdline.optset(iopt)) { cout << " option was set"; }
126  else { cout << "option was not set"; }
127  cout << endl;
128  cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
129  cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
130  cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
131  cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
132  cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
133  cout << " argument (bool): '";
134  if (cmdline.bool_arg(iopt))
135  { cout << "true"; } else { cout << "false"; }
136  cout << "'" << endl;
137  }
138  while (cmdline.extra()) { cout << cmdline.next() << endl; }
139 
140  // dummy operation: print rest of command line
141  */
142  while (cmdline.extra())
143  {
144  std::cout << std::endl;
145  std::string filename=cmdline.next();
146  std::cout << "file: " << filename << std::endl;
147 
148  std::ifstream ifs(filename.c_str());
149  if (opt.streams)
150  {
151  datrw::ipdasstream is(ifs);
152  if (opt.verbose) { is.free().write(std::cout); }
153  datrw::Tiseries iseries;
154  if (opt.count)
155  {
156  is.skipseries();
157  }
158  else
159  {
160  is >> iseries;
161  }
162  std::cout << is.wid2().line() << std::endl;
163  if (!opt.count)
164  {
165  int npr=
166  opt.nprint < int(iseries.size()/2) ?
167  opt.nprint : iseries.size()/2;
168  for (int i=0; i<npr; ++i)
169  { std::cout << i << " " << iseries(i) << std::endl; }
170  std::cout << " ... " << std::endl;
171  for (int i=iseries.size()-npr; i<int(iseries.size()); ++i)
172  { std::cout << i << " " << iseries(i) << std::endl; }
173  }
174  }
175  else
176  {
178  if (opt.count)
179  {
180  std::cout << "*** number of samples: " <<
181  datrw::pdas::countdata(ifs, header.type) << " ***" << std::endl;
182  }
183  else
184  {
185  datrw::pdas::Tdata indata;
186  datrw::pdas::readdata(ifs, indata, header.type);
187  std::cout << "*** number of samples: " <<
188  indata.size() << " ***" << std::endl;
189  int npr=
190  opt.nprint < int(indata.size()/2) ?
191  opt.nprint : indata.size()/2;
192  for (int i=0; i<npr; ++i)
193  { std::cout << i << " " << indata[i] << std::endl; }
194  std::cout << " ... " << std::endl;
195  for (int i=indata.size()-npr; i<int(indata.size()); ++i)
196  { std::cout << i << " " << indata[i] << std::endl; }
197  }
198  }
199  }
200 }
201 
202 /* ----- END OF pdastest.cc ----- */
bool streams
Definition: pdastest.cc:53
sff::WID2 wid2() const
Definition: datread.h:111
#define PDASTEST_VERSION
Definition: pdastest.cc:35
exception class declaration for libdatrwxx (prototypes)
int nprint
Definition: pdastest.cc:52
void readdata(std::istream &is, Tdata &data, const Etype &type)
Definition: pdasread.cc:150
read PDAS data (prototypes)
sff::FREE free() const
Definition: datread.cc:79
bool verbose
Definition: asciitest.cc:51
int main(int iargc, char *argv[])
Definition: pdastest.cc:56
aff::Series< int > Tiseries
Definition: types.h:47
struct to hold complete header
Definition: pdasread.h:68
virtual void skipseries()
Definition: ipdasstream.cc:106
Header readheader(std::istream &is, const bool &verbose)
function to read the file header
Definition: pdasread.cc:82
int countdata(std::istream &is, const Etype &type)
function to skip the file data but count the samples
Definition: pdasread.cc:166
bool count
Definition: pdastest.cc:51
class to read PDAS data
Definition: pdas.h:63
std::vector< Tvalue > Tdata
Definition: pdasread.h:76