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

◆ main()

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

Definition at line 107 of file binarytest.cc.

References BINARYTEST_VERSION, datrw::binary::Fdouble, datrw::binary::Finfo, datrw::binary::Fsrce, Options::iofile, Options::iotest, datrw::binary::magic, reportseries(), reportsff(), Options::skipsamples, values(), and Options::verbose.

108 {
109 
110  // define usage information
111  char usage_text[]=
112  {
113  BINARYTEST_VERSION "\n"
114  "usage: binarytest [-v] [-iotest file] [-skip]" "\n"
115  " or: binarytest --help|-h" "\n"
116  };
117 
118  // define full help text
119  char help_text[]=
120  {
121  "\n"
122  "-v be verbose\n"
123  "-iotest file execute fixed I/O test with file \"file\"\n"
124  "-skip skip samples of series, just count\n"
125  };
126 
127  // define commandline options
128  using namespace tfxx::cmdline;
129  static Declare options[]=
130  {
131  // 0: print help
132  {"help",arg_no,"-"},
133  // 1: verbose mode
134  {"v",arg_no,"-"},
135  // 2: skip samples
136  {"skip",arg_no,"-"},
137  // 3: verbose mode
138  {"iotest",arg_yes,"-"},
139  {NULL}
140  };
141 
142  // no arguments? print usage...
143  if (iargc<2)
144  {
145  cerr << usage_text << endl;
146  exit(0);
147  }
148 
149  // collect options from commandline
150  Commandline cmdline(iargc, argv, options);
151 
152  // help requested? print full help text...
153  if (cmdline.optset(0))
154  {
155  cerr << usage_text << endl;
156  cerr << help_text << endl;
157  exit(0);
158  }
159 
160  Options opt;
161  opt.verbose=cmdline.optset(1);
162  opt.skipsamples=cmdline.optset(2);
163  opt.iotest=cmdline.optset(3);
164  opt.iofile=cmdline.string_arg(3);
165 
166  /*
167  // dummy operation: print option settings
168  for (int iopt=0; iopt<2; iopt++)
169  {
170  cout << "option: '" << options[iopt].opt_string << "'" << endl;
171  if (cmdline.optset(iopt)) { cout << " option was set"; }
172  else { cout << "option was not set"; }
173  cout << endl;
174  cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
175  cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
176  cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
177  cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
178  cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
179  cout << " argument (bool): '";
180  if (cmdline.bool_arg(iopt))
181  { cout << "true"; } else { cout << "false"; }
182  cout << "'" << endl;
183  }
184  while (cmdline.extra()) { cout << cmdline.next() << endl; }
185 
186  // dummy operation: print rest of command line
187  while (cmdline.extra()) { cout << cmdline.next() << endl; }
188  */
189 
190  /*----------------------------------------------------------------------*/
191 
192  if (opt.iotest)
193  {
194  // prepare test data
195  datrw::Tiseries iseries(-10,10);
196  datrw::Tdseries dseries(15);
197  datrw::Tfseries fseries(20);
198  for (int i=iseries.f(); i<=iseries.l(); ++i)
199  { iseries(i)=2*i; }
200  for (int i=dseries.f(); i<=dseries.l(); ++i)
201  { dseries(i)=double(i)*i; }
202  for (int i=fseries.f(); i<=fseries.l(); ++i)
203  { fseries(i)=sin((i-fseries.f())*2.
204  *3.141592653589793115998/(fseries.size()-1)); }
205  ::sff::WID2 wid2;
206  ::sff::INFO info;
207  ::sff::SRCE srce;
208  ::sff::FREE free;
209 
210  wid2.nsamples=50;
211  wid2.dt=1.e-4;
212  wid2.date=libtime::TAbsoluteTime(2010,5,6,18,23,12,13,14);
213  wid2.station="STAT";
214  wid2.channel="CHA";
215  wid2.auxid="AUX";
216  wid2.instype="my seismometer type";
217 
218  info.cx=1.;
219  info.cy=2.;
220  info.cz=3.;
221  info.nstacks=49;
222 
223  srce.cx=-1.;
224  srce.cy=-2.;
225  srce.cz=-3.;
226  srce.type="my source type for this test";
227  srce.date=libtime::TAbsoluteTime(2006,1,1,9,15,12,345,678);
228 
229  free.append(BINARYTEST_VERSION);
230  free.append("my free comment line");
231 
232  char fflags=
235  char tflags=
237 
238  const char* const magic="B123";
239  // write data
240  {
241  std::ofstream ofs(opt.iofile.c_str(),
242  std::ios_base::out|std::ios_base::binary);
244 
245  os << wid2;
246  os << free;
247  os << fseries;
248  os << info;
249  os << dseries;
250  os << srce;
251  os << char(fflags);
252  os << char(tflags);
253  os << iseries;
254  }
255 
256  // reread file
257  {
258  std::ifstream ifs(opt.iofile.c_str(),
259  std::ios_base::in|std::ios_base::binary);
261 
262  ::sff::WID2 inwid2;
263  is >> inwid2;
264  reportsff(wid2, inwid2);
265 
266  ::sff::FREE infree;
267  is >> infree;
268  reportsff(free, infree);
269 
270  if (opt.skipsamples)
271  {
272  cout << "skipped " << is.skipfseries() << " samples" << endl;
273  }
274  else
275  {
276  datrw::Tfseries infseries;
277  is >> infseries;
278  reportseries(fseries, infseries);
279  }
280 
281  ::sff::INFO ininfo;
282  is >> ininfo;
283  reportsff(info, ininfo);
284 
285  if (opt.skipsamples)
286  {
287  cout << "skipped " << is.skipdseries() << " samples" << endl;
288  }
289  else
290  {
291  datrw::Tdseries indseries;
292  is >> indseries;
293  reportseries(dseries, indseries);
294  }
295 
296  ::sff::SRCE insrce;
297  is >> insrce;
298  reportsff(srce, insrce);
299 
300  char inflags;
301  is >> inflags;
302  values(char(fflags), inflags);
303  is >> inflags;
304  values(char(tflags), inflags);
305 
306  if (opt.skipsamples)
307  {
308  cout << "skipped " << is.skipiseries() << " samples" << endl;
309  }
310  else
311  {
312  datrw::Tiseries iniseries;
313  is >> iniseries;
314  reportseries(iseries, iniseries);
315  }
316  }
317 
318  }
319 }
std::string iofile
Definition: binarytest.cc:58
aff::Series< float > Tfseries
Definition: types.h:46
void values(const char &out, const char &in)
Definition: binarytest.cc:63
trace has INFO header
Definition: binary.h:81
bool skipsamples
Definition: binarytest.cc:57
const char *const magic
magic number to identify file type and bytesex
Definition: binary.cc:53
aff::Series< double > Tdseries
Definition: types.h:45
binary output for basic types and classes
Definition: obinstream.h:56
bool iotest
Definition: binarytest.cc:57
trace has SRCE header
Definition: binary.h:79
trace has double data
Definition: binary.h:82
bool verbose
Definition: asciitest.cc:51
aff::Series< int > Tiseries
Definition: types.h:47
stream like class for binary input of basic types and classes
Definition: ibinstream.h:56
#define BINARYTEST_VERSION
Definition: binarytest.cc:35
void reportseries(const C &out, const C &in)
Definition: binarytest.cc:95
void reportsff(const C &out, const C &in)
Definition: binarytest.cc:84
Here is the call graph for this function: