DATRW++ library: seismic data I/O with multiple formats

◆ main()

int main ( int  iargc,
char *  argv[] 
)

Definition at line 92 of file thiesdl1test.cc.

References Options::countonly, DATRW_assert, datrw::hpmo::dump(), Options::integer, Options::modifiers, Options::nprint, datrw::ithiesdl1stream::openmode, Options::readfile, Options::readheader, datrw::thiesdl1::readheader(), reportfilled(), reportheader(), Options::streamread, THIESDL1TEST_VERSION, Options::tolerateredundant, datrw::thiesdl1::File::tolerateredundant(), Options::toleratewrongtime, and Options::verbose.

93 {
94 
95  // define usage information
96  char usage_text[]=
97  {
99  "usage: thiesdl1test [-v] [-h] [-f] [-trs] [-twt] [-stream] [-count]\n"
100  " [-int] [-np n] [-modifiers m]\n"
101  " file [file ...]" "\n"
102  " or: thiesdl1test --help|-h" "\n"
103  };
104 
105  // define full help text
106  char help_text[]=
107  {
108  "\n"
109  "-v be verbose\n"
110  "-h read file header and report entries\n"
111  "-f read complete file and report entries\n"
112  "-trs tolerate redundant samples\n"
113  "-twt tolerate wrong time\n"
114  "-stream use stream interface\n"
115  "-count only count samples in stream mode\n"
116  "-int use integer reading in stream mode\n"
117  "-np n display n samples in stream mode\n"
118  "-modifiers m use modifiers m in stream mode\n"
119  };
120 
121  // define commandline options
122  using namespace tfxx::cmdline;
123  static Declare options[]=
124  {
125  // 0: print help
126  {"help",arg_no,"-"},
127  // 1: verbose mode
128  {"v",arg_no,"-"},
129  // 2: read file header
130  {"h",arg_no,"-"},
131  // 3: read complete file
132  {"f",arg_no,"-"},
133  // 4: tolerate redundant samples
134  {"trs",arg_no,"-"},
135  // 5: tolerate wrong time
136  {"twt",arg_no,"-"},
137  // 6: use stream reading
138  {"stream",arg_no,"-"},
139  // 7: count samples
140  {"count",arg_no,"-"},
141  // 8: use integer input
142  {"int",arg_no,"-"},
143  // 9: use integer input
144  {"np",arg_yes,"10"},
145  // 10: use integer input
146  {"modifiers",arg_yes,""},
147  {NULL}
148  };
149 
150  // no arguments? print usage...
151  if (iargc<2)
152  {
153  cerr << usage_text << endl;
154  exit(0);
155  }
156 
157  // collect options from commandline
158  Commandline cmdline(iargc, argv, options);
159 
160  // help requested? print full help text...
161  if (cmdline.optset(0))
162  {
163  cerr << usage_text << endl;
164  cerr << help_text << endl;
165  exit(0);
166  }
167 
168  Options opt;
169  opt.verbose=cmdline.optset(1);
170  opt.readheader=cmdline.optset(2);
171  opt.readfile=cmdline.optset(3);
172  opt.tolerateredundant=cmdline.optset(4);
173  opt.toleratewrongtime=cmdline.optset(5);
174  opt.streamread=cmdline.optset(6);
175  opt.countonly=cmdline.optset(7);
176  opt.integer=cmdline.optset(8);
177  opt.nprint=cmdline.int_arg(9);
178  opt.modifiers=cmdline.string_arg(10);
179 
180  /*
181  // dummy operation: print option settings
182  for (int iopt=0; iopt<2; iopt++)
183  {
184  cout << "option: '" << options[iopt].opt_string << "'" << endl;
185  if (cmdline.optset(iopt)) { cout << " option was set"; }
186  else { cout << "option was not set"; }
187  cout << endl;
188  cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
189  cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
190  cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
191  cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
192  cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
193  cout << " argument (bool): '";
194  if (cmdline.bool_arg(iopt))
195  { cout << "true"; } else { cout << "false"; }
196  cout << "'" << endl;
197  }
198  while (cmdline.extra()) { cout << cmdline.next() << endl; }
199  */
200 
201  // cycle through all file names
202  while (cmdline.extra())
203  {
204  std::string filename=cmdline.next();
205  cout << "process file " << filename << endl;
206 
207  /*----------------------------------------------------------------------*/
208 
209  if (opt.readheader)
210  {
211  cout << " read header\n"
212  << " -----------" << endl;
213  std::ifstream ifs(filename.c_str(), datrw::ithiesdl1stream::openmode);
216  reportheader(header);
217  } // if (opt.readheader)
218 
219  /*----------------------------------------------------------------------*/
220 
221  if (opt.readfile)
222  {
223  cout << " read file\n"
224  << " ---------" << endl;
225  std::ifstream ifs(filename.c_str(), datrw::ithiesdl1stream::openmode);
228  file.toleratewrongtime(opt.toleratewrongtime);
229  reportfilled(file);
230  file.readwithheader(ifs);
231  reportfilled(file);
232  reportheader(file.header());
233  datrw::Tdseries series=file.dseries();
234  aff::dump(series);
235  } // if (opt.readheader)
236 
237  /*----------------------------------------------------------------------*/
238 
239  if (opt.streamread)
240  {
241 
242  std::ifstream ifs(filename.c_str());
243  datrw::ithiesdl1stream is(ifs, opt.modifiers);
244  if (is.hasfree())
245  {
246  if (opt.verbose)
247  {
248  cout << "file FREE block:" << endl;
249  is.free().write(std::cout);
250  }
251  else
252  {
253  cout << "file has FREE block" << endl;
254  }
255  }
256  else
257  {
258  cout << "file has no FREE block" << endl;
259  }
260  if (is.hassrce())
261  {
262  if (opt.verbose)
263  {
264  cout << "file SRCE line:" << endl;
265  cout << is.srce().line() << endl;;
266  }
267  else
268  {
269  cout << "file has SRCE line" << endl;
270  }
271  }
272  else
273  {
274  cout << "file has no SRCE line" << endl;
275  }
276  datrw::Tfseries fseries;
277  datrw::Tiseries iseries;
278 
279  if (opt.countonly)
280  {
281  is.skipseries();
282  }
283  else
284  {
285  if (opt.integer)
286  {
287  is >> iseries;
288  }
289  else
290  {
291  is >> fseries;
292  }
293  }
294  if (is.hasfree())
295  {
296  if (opt.verbose)
297  {
298  cout << "trace FREE block:" << endl;
299  is.free().write(std::cout);
300  }
301  else
302  {
303  cout << "trace has FREE block" << endl;
304  }
305  }
306  else
307  {
308  cout << "trace has no FREE block" << endl;
309  }
310  if (is.hasinfo())
311  {
312  if (opt.verbose)
313  {
314  cout << "trace INFO line:" << endl;
315  cout << is.info().line() << endl;;
316  }
317  else
318  {
319  cout << "trace has INFO line" << endl;
320  }
321  }
322  else
323  {
324  cout << "trace has no INFO line" << endl;
325  }
326  std::cout << is.wid2().line() << std::endl;
327  if ((!opt.countonly) && (opt.verbose))
328  {
329  if (opt.integer)
330  {
331  int npr=
332  opt.nprint < int(iseries.size()/2) ?
333  opt.nprint : iseries.size()/2;
334  for (int i=0; i<npr; ++i)
335  { std::cout << i << " " << iseries(i) << std::endl; }
336  std::cout << " ... " << std::endl;
337  for (int i=iseries.size()-npr; i<int(iseries.size()); ++i)
338  { std::cout << i << " " << iseries(i) << std::endl; }
339  }
340  else
341  {
342  int npr=
343  opt.nprint < int(fseries.size()/2) ?
344  opt.nprint : fseries.size()/2;
345  for (int i=0; i<npr; ++i)
346  { std::cout << i << " " << fseries(i) << std::endl; }
347  std::cout << " ... " << std::endl;
348  for (int i=fseries.size()-npr; i<int(fseries.size()); ++i)
349  { std::cout << i << " " << fseries(i) << std::endl; }
350  }
351  }
352  DATRW_assert(is.last(), "last flag was not set");
353  } // if (opt.streamread)
354 
355  } // while (cmdline.extra())
356 }
void reportheader(const datrw::thiesdl1::FileHeader &header)
Definition: thiesdl1test.cc:59
bool countonly
Definition: seifetest.cc:55
bool tolerateredundant
Definition: thiesdl1test.cc:83
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
FileHeader readheader(std::istream &is)
Read and parse a file header.
aff::Series< float > Tfseries
Definition: types.h:46
bool streamread
Definition: seifetest.cc:54
class to read Thies DL1 data
Definition: thiesdl1.h:64
void tolerateredundant(const bool flag=true)
set tolerance for redundant samples
Definition: thiesdl1file.h:167
aff::Series< double > Tdseries
Definition: types.h:45
Store a full data file.
Definition: thiesdl1file.h:125
int nprint
Definition: pdastest.cc:52
void reportfilled(const datrw::thiesdl1::File &f)
Definition: thiesdl1test.cc:50
#define THIESDL1TEST_VERSION
Definition: thiesdl1test.cc:34
bool toleratewrongtime
Definition: thiesdl1test.cc:83
bool integer
Definition: thiesdl1test.cc:85
Store the header of a data file.
Definition: thiesdl1file.h:87
bool readfile
Definition: thiesdl1test.cc:82
bool verbose
Definition: asciitest.cc:51
aff::Series< int > Tiseries
Definition: types.h:47
void dump(std::ostream &os, const SampleBlock &block)
dump one block of samples
Definition: readhpmo.cc:161
bool readheader
Definition: thiesdl1test.cc:82
std::string modifiers
Definition: seifetest.cc:59
static const std::ios_base::openmode openmode
Definition: thiesdl1.h:76
Here is the call graph for this function: