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

◆ main()

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

Definition at line 54 of file tfasciitest.cc.

References DATRW_assert, Options::dseries, Options::fseries, Options::iseries, Options::micsecs, Options::skip, TFASCIITEST_VERSION, and Options::verbose.

55 {
56  // define usage information
57  char usage_text[]=
58  {
60  "usage: tfasciitest [-v] [-dseries] [-fseries] [-iseries] [-skip]" "\n"
61  " [-micsecs] filename" "\n"
62  " or: tfasciitest --help" "\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  "-dseries test reading a double series" "\n"
71  "-fseries test reading a float series" "\n"
72  "-iseries test reading a integer series" "\n"
73  "-skip test to skip a series and read only the header data" "\n"
74  "-micsecs test the output of the microseconds in the date values" "\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: read double series
86  {"dseries",arg_no,"-"},
87  // 3: read float series
88  {"fseries",arg_no,"-"},
89  // 4: read integer series
90  {"iseries",arg_no,"-"},
91  // 5: skip trace and read only header
92  {"skip",arg_no,"-"},
93  // 6: print date values including microseconds
94  {"micsecs",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  Options opt;
117  opt.verbose=cmdline.optset(1);
118  opt.dseries=cmdline.optset(2);
119  opt.fseries=cmdline.optset(3);
120  opt.iseries=cmdline.optset(4);
121  opt.skip=cmdline.optset(5);
122  opt.micsecs=cmdline.optset(6);
123 
124  DATRW_assert(cmdline.extra(), "missing filename!");
125 
126 
127 /*----------------------------------------------------------------------*/
128 
129  while (cmdline.extra())
130  {
131  std::string infile=cmdline.next();
132  std::ifstream ifs(infile.c_str());
133  DATRW_assert(ifs.good(), "invalid file!");
134  datrw::itfasciistream is(ifs, opt.verbose);
135  if (opt.verbose)
136  {
137  cout << "Reading file " << infile << endl;
138  if (opt.dseries)
139  {
140  cout << endl << "TEST: double reading" << endl;
141  } else
142  if (opt.fseries)
143  {
144  cout << endl << "TEST: float reading" << endl;
145  } else
146  if (opt.iseries)
147  {
148  cout << endl << "TEST: integer reading" << endl;
149  }
150  cout << "=====================" << endl;
151  if (is.hassrce())
152  {
153  cout << is.srce().line();
154  if (opt.micsecs)
155  {
156  cout << "Test micsecs in SRCE date: "
157  << is.srce().date.timestring() << endl;
158  }
159  }
160  if (is.hasfree()) { is.free().write(cout); }
161  }
162  datrw::Tdseries dseries;
163  datrw::Tfseries fseries;
164  datrw::Tiseries iseries;
165  if (opt.skip) { is.skipseries(); } else
166  if (opt.dseries) { is >> dseries; } else
167  if (opt.fseries) { is >> fseries; } else
168  if (opt.iseries) { is >> iseries; }
169  if (opt.verbose)
170  {
171  cout << endl;
172  // print traceheader
173  cout << is.wid2().line();
174  if (opt.micsecs)
175  {
176  cout << "Test micsecs in WID2 date: "
177  << is.wid2().date.timestring() << endl;
178  }
179  if (is.hasinfo()) { cout << is.info().line(); }
180  if (is.hasfree()) { is.free().write(cout); }
181  cout << endl;
182 
183  // print series
184  if (opt.dseries && !opt.skip)
185  {
186  cout << "data:" << endl;
187  for (int isample=dseries.first(); isample<=dseries.last();
188  ++isample)
189  {
190  cout << std::setprecision(7) << std::scientific << std::showpos
191  << dseries(isample) << endl;
192  }
193  } else
194  if (opt.fseries && !opt.skip)
195  {
196  cout << "data:" << endl;
197  for (int isample=fseries.first(); isample<=fseries.last();
198  ++isample)
199  {
200  cout << std::setprecision(7) << std::scientific << std::showpos
201  << fseries(isample) << endl;
202  }
203  } else
204  if (opt.iseries && !opt.skip)
205  {
206  cout << "data:" << endl;
207  for (int isample=iseries.first(); isample<=iseries.last();
208  ++isample)
209  {
210  cout << iseries(isample) << endl;
211  }
212  }
213  }
214  }
215 }
bool micsecs
Definition: tfasciitest.cc:51
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:92
input stream to read seismic data provided by T. Forbriger&#39;s any2ascii
Definition: tfascii.h:64
aff::Series< float > Tfseries
Definition: types.h:46
aff::Series< double > Tdseries
Definition: types.h:45
bool dseries
Definition: tfasciitest.cc:51
bool iseries
Definition: tfasciitest.cc:51
bool skip
Definition: tfasciitest.cc:51
#define TFASCIITEST_VERSION
Definition: tfasciitest.cc:35
bool verbose
Definition: asciitest.cc:51
aff::Series< int > Tiseries
Definition: types.h:47
bool fseries
Definition: tfasciitest.cc:51