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

◆ main()

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

Definition at line 65 of file sutest.cc.

References datrw::su::ScalCoo::adjustscale(), datrw::su::options::SpatialSampling::bestrict, CODE, datrw::su::ScalCoo::coo, Options::coordinate, datrw::su::SUheader::dateoffirstsample(), datrw::su::SUheader::dateofshot(), DATRW_Xassert, Options::debug, datrw::su::SUheader::delay(), datrw::su::TraceHeaderStruct::delrt, Options::docootest, Options::doscaletest, Options::dowritetest, datrw::su::Coordinates::equalizescaling(), Options::filename, datrw::su::Coordinates::gelev, datrw::su::Coordinates::gy, Options::imodifier, datrw::su::SUheader::info(), datrw::su::inputmodifiers(), datrw::su::SUheader::Mheader, datrw::su::TraceHeaderStruct::ns, Options::ofilename, Options::omodifier, datrw::isustream::openmode, datrw::osustream::openmode, datrw::su::outputmodifiers(), datrw::su::ScalCoo::power(), datrw::su::SUheader::read(), datrw::su::options::SpatialSampling::scalco, datrw::su::TraceHeaderStruct::scalco, Options::scale, datrw::su::ScalCoo::scale, datrw::su::TraceHeaderStruct::scalel, Options::scanfile, datrw::su::Coordinates::sdepth, datrw::su::SUheader::set(), datrw::su::ScalCoo::set(), Options::sfilename, datrw::su::options::SUHeaderControl::spatialsampling, datrw::su::SUheader::srce(), Options::streamfile, SUTEST_VERSION, datrw::su::Coordinates::sx, datrw::su::Coordinates::sy, datrw::su::TraceHeaderStruct::trid, VALUE, datrw::su::ScalCoo::value(), Options::verbose, and datrw::su::SUheader::wid2().

66 {
67 
68  // define usage information
69  char usage_text[]=
70  {
71  SUTEST_VERSION "\n"
72  "usage: sutest [-v] [-D] [-file filename] [-stream filename]" "\n"
73  " [-scale s] [-coordinate v] [-write filename]" "\n"
74  " [-imodifier m] [-omodifier m]" "\n"
75  " or: sutest --help|-h" "\n"
76  };
77 
78  // define full help text
79  char help_text[]=
80  {
81  SUTEST_VERSION "\n"
82  "\n"
83  "-v be verbose\n"
84  "-D switch on DEBUG mode\n"
85  "-file filename scan file, using elementary SU structs and\n"
86  " report contents\n"
87  " input modifiers are effective\n"
88  "-stream filename use isustream to read an SU data file and\n"
89  " report contents\n"
90  " input modifiers are effective\n"
91  "-write filename write a synthetic SU data file containing\n"
92  " sine signals\n"
93  " output modifiers are effective\n"
94  "-scale s test the ScalCoo struct, which is used to\n"
95  " hold scalco and scalel header values\n"
96  " input and output modifiers are effective\n"
97  "-coordinate v test modules ScalCoo, Coordinates, and\n"
98  " SUheader\n"
99  " input and output modifiers are effective\n"
100  "-imodifier m set input stream modifiers\n"
101  "-omodifier m set output stream modifiers\n"
102  "\n"
103  "If no option is selected, the program reports the size of the\n"
104  "TraceHeaderStruct and terminates.\n"
105  };
106 
107  // define commandline options
108  using namespace tfxx::cmdline;
109  static Declare options[]=
110  {
111  // 0: print help
112  {"help",arg_no,"-"},
113  // 1: verbose mode
114  {"v",arg_no,"-"},
115  // 2: debug mode
116  {"D",arg_no,"-"},
117  // 3: file to scan
118  {"file",arg_yes,"-"},
119  // 4: file to scan with stream
120  {"stream",arg_yes,"-"},
121  // 5: test coordinate scaling for scale value
122  {"scale",arg_yes,"-"},
123  // 6: test coordinate scaling for coordinate value
124  {"coordinate",arg_yes,"-"},
125  // 7: write a test file
126  {"write",arg_yes,"-"},
127  // 8: use modifier string for input
128  {"imodifier",arg_yes,""},
129  // 9: use modifier string for output
130  {"omodifier",arg_yes,""},
131  {NULL}
132  };
133 
134  // no arguments? print usage...
135  if (iargc<2)
136  {
137  cerr << usage_text << endl;
138  exit(0);
139  }
140 
141  // collect options from commandline
142  Commandline cmdline(iargc, argv, options);
143 
144  // help requested? print full help text...
145  if (cmdline.optset(0))
146  {
147  cerr << usage_text << endl;
148  cerr << help_text << endl;
149  exit(0);
150  }
151 
152  Options opt;
153  opt.verbose=cmdline.optset(1);
154  opt.debug=cmdline.optset(2);
155  opt.scanfile=cmdline.optset(3);
156  opt.filename=cmdline.string_arg(3);
157  opt.streamfile=cmdline.optset(4);
158  opt.sfilename=cmdline.string_arg(4);
159  opt.doscaletest=cmdline.optset(5);
160  opt.scale=cmdline.int_arg(5);
161  opt.docootest=cmdline.optset(6);
162  opt.coordinate=cmdline.double_arg(6);
163  opt.dowritetest=cmdline.optset(7);
164  opt.ofilename=cmdline.string_arg(7);
165  opt.imodifier=cmdline.string_arg(8);
166  opt.omodifier=cmdline.string_arg(9);
167 
168  cout << "size of TraceHeaderStruct " <<
169  sizeof(datrw::su::TraceHeaderStruct) << endl;
170 
171  /*----------------------------------------------------------------------*/
172 
173  if (opt.dowritetest)
174  {
175  cout << "Write test file\n"
176  << "---------------" << endl;
177  if (opt.verbose)
178  {
179  cout << "write to file " << opt.ofilename << endl;
180  }
181  std::ofstream ofs(opt.ofilename.c_str(),
183  datrw::osustream os(ofs, opt.omodifier, opt.debug);
184  ::sff::WID2 wid2;
185  wid2.dt=1.e-4;
186  wid2.station="stat";
187  wid2.channel="chan";
188  wid2.auxid="auxid";
189  wid2.instype="inst";
190  ::sff::SRCE srce;
191  ::sff::INFO info;
192  ::sff::verbose(cout, srce);
193  os << srce;
194  const int mtrace=3;
195  const int msamp=100;
196  ::datrw::Tfseries series(0,msamp-1);
197  for (int itrace=0; itrace<mtrace; ++itrace)
198  {
199  cout << endl << "trace #" << itrace << endl;
200  wid2.date=srce.date+libtime::double2time(wid2.dt*msamp*itrace);
201  os << wid2;
202  info.cx=1.*(itrace+1);
203  os << info;
204  ::sff::verbose(cout, wid2);
205  ::sff::verbose(cout, info);
206 
207  for (int isamp=0; isamp<msamp; ++isamp)
208  {
209  series(isamp)=std::sin(6*3.14159265358*
210  ((static_cast<double>(isamp)/msamp)
211  +(static_cast<double>(itrace)/mtrace)));
212  }
213  os << series;
214  }
215  }
216 
217  /*----------------------------------------------------------------------*/
218 
219  if (opt.scanfile)
220  {
221  std::ifstream ifs(opt.filename.c_str(),
225  datrw::su::SUheader header(hc, opt.debug);
226  bool hot=true;
227  while (hot)
228  {
229  try {
230  header.read(ifs);
231  cout << "trid: " << header.Mheader.trid << endl;
232  cout << "ns: " << header.Mheader.ns << endl;
233  cout << "delrt: " << header.Mheader.delrt << endl;
234  cout << "scalco: " << header.Mheader.scalco << endl;
235  cout << "scalel: " << header.Mheader.scalel << endl;
236  datrw::Tfseries series(header.Mheader.ns);
237  char *ipointer=reinterpret_cast<char *>(series.pointer());
238  DATRW_Xassert(ifs.read(ipointer, series.size()*sizeof(float)),
239  "ERROR: reading SU samples",
241  cout << "read " << series.size() << " samples"
242  << " which are " << series.size()*sizeof(float)
243  << " characters" << endl;
244  cout << header.wid2().line() << endl;
245  cout << "srce date: " << header.dateofshot().timestring() << endl;
246  cout << "delay: " << header.delay().timestring() << endl;
247  cout << "time of data: " << header.dateoffirstsample().timestring() << endl;
248  cout << header.info().line() << endl;
249  cout << header.srce().line() << endl;
250  }
251  catch (...)
252  {
253  hot=false;
254  cout << "CAUGHT EXCEPTION" << endl;
255  }
256  }
257  }
258 
259  /*----------------------------------------------------------------------*/
260 
261  if (opt.streamfile)
262  {
263  std::ifstream ifs(opt.sfilename.c_str(),
265  datrw::isustream is(ifs, opt.imodifier, opt.debug);
266  ::datrw::Tfseries series;
267  ::sff::WID2 wid2;
268  ::sff::SRCE srce;
269  ::sff::INFO info;
270  int itrace=0;
271  is >> srce;
272  ::sff::verbose(cout, srce);
273  while (is.good())
274  {
275  ++itrace;
276  cout << endl << "trace #" << itrace << endl;
277  is >> series;
278  is >> wid2;
279  is >> info;
280  ::sff::verbose(cout, wid2);
281  ::sff::verbose(cout, info);
282  int l=3;
283  l=series.l()>l ? l:series.l();
284  for (int i=series.f(); i<=l; ++i)
285  {
286  cout << "s("<<i<<")="<<series(i)<<" ";
287  }
288  cout << endl;
289  l=series.l()-2;
290  l=series.f()>l ? series.f():l;
291  for (int i=l; i<=series.l(); ++i)
292  {
293  cout << "s("<<i<<")="<<series(i)<<" ";
294  }
295  cout << endl;
296  }
297  }
298 
299  /*----------------------------------------------------------------------*/
300 
301  if (opt.doscaletest)
302  {
308  cout << "scale value: " << opt.scale << endl;
310  co.set(opt.scale, 34500);
311  cout << "scale in ScalCoo: " << co.scale << endl;
312  cout << "coordinate in ScalCoo: " << co.coo << endl;
313  cout << "value from ScalCoo: " << co.value() << endl;
314  cout << "power from ScalCoo: " << co.power() << endl;
315  co.adjustscale();
316  cout << "scale in ScalCoo after adjust: " << co.scale << endl;
317  cout << "coordinate in ScalCoo: " << co.coo << endl;
318  cout << "value from ScalCoo: " << co.value() << endl;
319  }
320 
321  /*----------------------------------------------------------------------*/
322 
323  if (opt.docootest)
324  {
325  cout << "Test su coordinate manager\n"
326  << "==========================\n\n";
332  cout << "Test module ::datrw::su::ScalCoo\n"
333  << "--------------------------------\n" << endl;
334  cout << "check det function\n";
335  CODE( ::datrw::su::ScalCoo co(hc.spatialsampling, opt.debug); )
336  for (int i=-4; i<5; ++i)
337  {
338  if (i<0)
339  {
340  CODE( co.set(-std::pow(10, -i), 1); )
341  }
342  else
343  {
344  CODE( co.set(std::pow(10, i), 1); )
345  }
346  cout << "i: " << i << "; co.scale " << co.scale
347  << "; co.coo " << co.coo
348  << "; co.power() " << co.power()
349  << "; co.value() " << co.value()
350  << endl;
351  }
352  cout << "\n";
353 
354  CODE( co.set(opt.coordinate); )
355  VALUE( opt.coordinate );
356  VALUE( co.scale );
357  VALUE( co.coo );
358  VALUE( co.power() );
359  VALUE( co.value() );
360  cout << endl;
361 
362  CODE( co.scaletopower(-3); )
363  VALUE( opt.coordinate );
364  VALUE( co.scale );
365  VALUE( co.coo );
366  VALUE( co.power() );
367  VALUE( co.value() );
368  cout << endl;
369 
370  CODE( co.scaletopower(1); )
371  VALUE( opt.coordinate );
372  VALUE( co.scale );
373  VALUE( co.coo );
374  VALUE( co.power() );
375  VALUE( co.value() );
376  cout << endl;
377 
378  CODE( co.scaletopower(3); )
379  VALUE( opt.coordinate );
380  VALUE( co.scale );
381  VALUE( co.coo );
382  VALUE( co.power() );
383  VALUE( co.value() );
384  cout << endl;
385 
386  VALUE( co.smallestpower(hc.spatialsampling.scalco) );
387  CODE( co.scaletopower(co.smallestpower(hc.spatialsampling.scalco)); )
388  VALUE( opt.coordinate );
389  VALUE( co.scale );
390  VALUE( co.coo );
391  VALUE( co.power() );
392  VALUE( co.value() );
393  cout << endl;
394 
395  CODE( co.set(opt.coordinate); )
396  VALUE( opt.coordinate );
397  VALUE( co.scale );
398  VALUE( co.coo );
399  VALUE( co.power() );
400  VALUE( co.value() );
401  cout << endl;
402 
403  CODE( co.adjustscale(); )
404  VALUE( opt.coordinate );
405  VALUE( co.scale );
406  VALUE( co.coo );
407  VALUE( co.power() );
408  VALUE( co.value() );
409  cout << endl;
410 
411  VALUE( co.smallestpower(hc.spatialsampling.scalco) );
412  CODE( co.scaletopower(co.smallestpower(hc.spatialsampling.scalco)); )
413  VALUE( opt.coordinate );
414  VALUE( co.scale );
415  VALUE( co.coo );
416  VALUE( co.power() );
417  VALUE( co.value() );
418  cout << endl;
419 
420  cout << "\n"
421  << "Test module ::datrw::su::Coordinates\n"
422  << "------------------------------------\n" << endl;
424  coo.sx.set(opt.coordinate);
425  coo.gy.set(opt.coordinate);
426  cout << "values:"
427  << " sx: " << coo.sx.value()
428  << " sy: " << coo.sy.value()
429  << " sdepth: " << coo.sdepth.value()
430  << " gx: " << coo.gy.value()
431  << " gy: " << coo.gy.value()
432  << " gelev: " << coo.gelev.value()
433  << endl;
434  cout << "call equalizescaling()" << endl;
435  coo.equalizescaling();
436  cout << "values:"
437  << " sx: " << coo.sx.value()
438  << " sy: " << coo.sy.value()
439  << " sdepth: " << coo.sdepth.value()
440  << " gx: " << coo.gy.value()
441  << " gy: " << coo.gy.value()
442  << " gelev: " << coo.gelev.value()
443  << endl;
444 
445  cout << "\n\n"
446  << "Test module ::datrw::su::SUheader\n"
447  << "---------------------------------\n" << endl;
448  ::datrw::su::SUheader suh(hc, opt.debug);
449  ::sff::SRCE srce;
450  srce.cy=opt.coordinate;
451  cout << "SRCE data passed to su header:" << endl;
452  ::sff::verbose(cout, srce);
453  suh.set(srce);
454  ::sff::INFO info;
455  info.cx=opt.coordinate;
456  cout << "INFO data passed to su header:" << endl;
457  ::sff::verbose(cout, info);
458  suh.set(info);
459  cout << "INFO data returned from su header:" << endl;
460  ::sff::verbose(cout, suh.info());
461  }
462 }
short scale
Definition: sutest.cc:59
bool streamfile
Definition: sutest.cc:56
full set of coordinates.This struct holds a full set of coordinates for a SEG-Y trace header...
Definition: sucomanager.h:195
aff::Series< float > Tfseries
Definition: types.h:46
scaled coordinate.This struct holds one coordinate together with a scale value. It provides functions...
Definition: sucomanager.h:124
SEG-Y and SU trace header as taken from segy.h coming with SeismicUnixsegy - trace identification hea...
C++ class to handle Seismic Un*x header struct.
Definition: suheader.h:123
bool bestrict
if true: strictly use header definition by SeismicUnix source
Definition: suformat.h:133
static const std::ios_base::openmode openmode
Definition: su.h:108
short scalco
preferred scalco value
Definition: suformat.h:131
options::SUHeaderControl inputmodifiers(const std::string &modifier, const bool &debug)
evaluate input stream format modifiers
Definition: suformat.cc:94
#define DATRW_Xassert(C, M, E)
Check an assertion and report by throwing an exception.
Definition: error.h:76
std::string ofilename
Definition: sutest.cc:58
bool doscaletest
Definition: sutest.cc:56
#define VALUE(V)
Definition: sutest.cc:53
std::string omodifier
Definition: sutest.cc:58
std::string sfilename
Definition: sutest.cc:58
bool debug
Definition: asciitest.cc:52
std::string imodifier
Definition: sutest.cc:58
#define CODE(C)
Definition: sutest.cc:52
bool dowritetest
Definition: sutest.cc:57
bool verbose
Definition: asciitest.cc:51
static const std::ios_base::openmode openmode
Definition: su.h:87
double coordinate
Definition: sutest.cc:60
#define SUTEST_VERSION
Definition: sutest.cc:38
std::string filename
Definition: sutest.cc:58
class to read SeismicUnix data
Definition: su.h:76
class to write SU data
Definition: su.h:100
bool scanfile
Definition: sutest.cc:56
options to control the way header variables are handeled.
Definition: suformat.h:168
options::SUHeaderControl outputmodifiers(const std::string &modifier, const bool &debug)
evaluate output stream format modifiers
Definition: suformat.cc:122
bool docootest
Definition: sutest.cc:57
Here is the call graph for this function: