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

◆ main()

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

Definition at line 55 of file sfftest.cc.

References Options::count, Options::debug, datrw::idatstream::free(), Options::nprint, SFFTEST_VERSION, datrw::isffstream::skipseries(), Options::streams, Options::verbose, and datrw::idatstream::wid2().

56 {
57 
58  // define usage information
59  char usage_text[]=
60  {
61  SFFTEST_VERSION "\n"
62  "usage: sfftest [-D] [-v] [-s] filename ..." "\n"
63  " or: sfftest --help|-h" "\n"
64  };
65 
66  // define full help text
67  char help_text[]=
68  {
69  "\n"
70  "filename ... SFF data files for reading" "\n"
71  "\n"
72  "-D DEBUG mode" "\n"
73  "-v verbose mode" "\n"
74  "-s use streams" "\n"
75  "-n=val display only vale samples at start end end of file" "\n"
76  "-c only count samples" "\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: DEBUG mode
88  {"D",arg_no,"-"},
89  // 3: stream mode
90  {"s",arg_no,"-"},
91  // 4: count samples
92  {"c",arg_no,"-"},
93  // 5: number of samples
94  {"n",arg_yes,"10" },
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.debug=cmdline.optset(2);
119  opt.streams=cmdline.optset(3);
120  opt.count=cmdline.optset(4);
121  opt.nprint=cmdline.int_arg(5);
122 
123  while (cmdline.extra())
124  {
125  std::string filename=cmdline.next();
126  if (opt.verbose)
127  {
128  std::cout << std::endl;
129  std::cout << "file: " << filename << std::endl;
130  }
131 
132  std::ifstream ifs(filename.c_str());
133  if (opt.streams)
134  {
135  datrw::isffstream is(ifs);
136  if (opt.verbose) { is.free().write(std::cout); }
137  datrw::Tiseries iseries;
138  if (opt.count)
139  {
140  is.skipseries();
141  }
142  else
143  {
144  is >> iseries;
145  }
146  if (opt.verbose)
147  {
148  std::cout << is.wid2().line() << std::endl;
149  }
150  if ((!opt.count) && (opt.verbose))
151  {
152  int npr=
153  opt.nprint < int(iseries.size()/2) ?
154  opt.nprint : iseries.size()/2;
155  for (int i=0; i<npr; ++i)
156  { std::cout << i << " " << iseries(i) << std::endl; }
157  std::cout << " ... " << std::endl;
158  for (int i=iseries.size()-npr; i<int(iseries.size()); ++i)
159  { std::cout << i << " " << iseries(i) << std::endl; }
160  }
161  }
162  else
163  {
164  sff::FileHeader fileheader(ifs, opt.debug);
165  if (opt.verbose)
166  {
167  cout << "read file header:" << endl;
168  fileheader.write(cout);
169  cout << "-----------------" << endl << endl;
170  }
171  bool last=false;
172  while (!last)
173  {
174  sff::InputWaveform<Tseries> inputwaveform(ifs, opt.debug);
175  if (opt.verbose)
176  {
177  cout << "read trace header:" << endl;
178  inputwaveform.header().writeheader(cout);
179  inputwaveform.header().writetrailer(cout);
180  cout << "------------------" << endl << endl;
181  }
182  last=inputwaveform.last();
183  }
184  }
185  }
186 }
bool streams
Definition: pdastest.cc:53
class to read SFF data
Definition: sff.h:76
int nprint
Definition: pdastest.cc:52
bool debug
Definition: asciitest.cc:52
bool verbose
Definition: asciitest.cc:51
#define SFFTEST_VERSION
Definition: sfftest.cc:34
aff::Series< int > Tiseries
Definition: types.h:47
bool count
Definition: pdastest.cc:51
Here is the call graph for this function: