Waveform filter programs

◆ main()

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

Definition at line 64 of file autocorr.cc.

References AUTOCORR_VERSION, Options::debug, Options::overwrite, and Options::verbose.

65 {
66 
67  // define usage information
68  char usage_text[]=
69  {
70  AUTOCORR_VERSION "\n"
71  "usage: autocorr -v -o -D file [file [...]] outfile" "\n"
72  " or: autocorr --help|-h" "\n"
73  };
74 
75  // define full help text
76  char help_text[]=
77  {
78  "-v be verbose" "\n"
79  "-D debug mode" "\n"
80  "-o overwrite existing output file" "\n"
81  "file ... input file(s)" "\n"
82  "outfile output file" "\n"
83  };
84 
85  // define commandline options
86  using namespace tfxx::cmdline;
87  static Declare options[]=
88  {
89  // 0: print help
90  {"help",arg_no,"-"},
91  // 1: verbose mode
92  {"v",arg_no,"-"},
93  // 2: overwrite mode
94  {"o",arg_no,"-"},
95  // 3: debug mode
96  {"D",arg_no,"-"},
97  {NULL}
98  };
99 
100  // no arguments? print usage...
101  if (iargc<2)
102  {
103  cerr << usage_text << endl;
104  exit(0);
105  }
106 
107  // collect options from commandline
108  Commandline cmdline(iargc, argv, options);
109 
110  // help requested? print full help text...
111  if (cmdline.optset(0))
112  {
113  cerr << usage_text << endl;
114  cerr << help_text << endl;
115  exit(0);
116  }
117 
118  /*
119  // dummy operation: print option settings
120  for (int iopt=0; iopt<2; iopt++)
121  {
122  cout << "option: '" << options[iopt].opt_string << "'" << endl;
123  if (cmdline.optset(iopt)) { cout << " option was set"; }
124  else { cout << "option was not set"; }
125  cout << endl;
126  cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
127  cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
128  cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
129  cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
130  cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
131  cout << " argument (bool): '";
132  if (cmdline.bool_arg(iopt))
133  { cout << "true"; } else { cout << "false"; }
134  cout << "'" << endl;
135  }
136  while (cmdline.extra()) { cout << cmdline.next() << endl; }
137 
138  // dummy operation: print rest of command line
139  while (cmdline.extra()) { cout << cmdline.next() << endl; }
140  */
141 
142  Options opt;
143  opt.verbose=cmdline.optset(1);
144  opt.overwrite=cmdline.optset(2);
145  opt.debug=cmdline.optset(3);
146 
147  TFXX_assert(cmdline.extra(), "missing input file!");
148  std::string outfile=cmdline.next();
149  TFXX_assert(cmdline.extra(), "missing output file!");
150  Tnames infiles;
151  while (cmdline.extra())
152  {
153  infiles.push_back(outfile);
154  outfile=cmdline.next();
155  }
156 
157  if (opt.verbose) { cout << "open output file " << outfile << endl; }
158  std::ofstream ofs(outfile.c_str());
159  datrw::osffstream os(ofs);
160 
161  sff::SRCE srce=sff::srce_reference();
162  os << srce;
163 
164  Tnames::const_iterator I=infiles.begin();
165  while (I!=infiles.end())
166  {
167  if (opt.verbose) { cout << "open " << std::string(*I) << endl; }
168  std::ifstream ifs(I->c_str());
169  datrw::isffstream is(ifs, opt.debug);
170  while (is.good())
171  {
172  if (opt.verbose) { cout << "read trace" << endl; }
173  Tts data;
174  Tts::Tseries samples;
175  is >> samples >> data.header;
176  data=samples;
177  sff::INFO info;
178  is >> info;
179  if (opt.verbose) { cout << data.header.line() << endl; }
180  Tts result;
181  result=ts::correlate(data,data);
182  result /= Tts::Tvalue(data.size());
183  result.header=data.header;
184  result.header.auxid="corr";
185  result.header.date=srce.date
186  +(result.first()*libtime::double2time(result.header.dt));
187  if (is.hasinfo()) { os << info; }
188  os << result;
189  }
190  ++I;
191  }
192 }
double Tvalue
Definition: fidasexx.cc:136
bool overwrite
Definition: autocorr.cc:61
ts::TDsfftimeseries Tts
Definition: autocorr.cc:58
bool debug
Definition: autocorr.cc:61
bool verbose
Definition: autocorr.cc:61
std::list< std::string > Tnames
Definition: autocorr.cc:57
#define AUTOCORR_VERSION
Definition: autocorr.cc:36
aff::Series< double > Tseries
Definition: cross.cc:69