Waveform filter programs

◆ main()

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

Definition at line 69 of file gatherdiff.cc.

References Options::debug, GATHERDIFF_VERSION, Options::ignorecoo, Options::inputformat, Options::normalize, Options::outputformat, Options::overwrite, Options::srtol, and Options::verbose.

70 {
71 
72  // define usage information
73  char usage_text[]=
74  {
76  "usage: gatherdiff infile1 infile2 outfile [-v] [-n]" "\n"
77  " [--overwrite] [--type f] [--Type f]" "\n"
78  " [--srtol r] [--ignorecoo]" "\n"
79  " or: gatherdiff --help|-h" "\n"
80  " or: gatherdiff --xhelp" "\n"
81  };
82 
83  // define full help text
84  char help_text[]=
85  {
86  "This program takes two data files as input. It assumes" "\n"
87  "that both contain full record gathers with identical recording" "\n"
88  "parameters. Typically these will be two sets of synthetic" "\n"
89  "seismograms that were calculated for different subsurface" "\n"
90  "models. The residual of these two sets is calculated and written" "\n"
91  "to the output, together with shot an receiver coordinates of" "\n"
92  "the first input set." "\n"
93  "\n"
94  "infile1 name of first SFF input file" "\n"
95  "infile2 name of second SFF input file" "\n"
96  "outfile name of output file (outfile=infile1-infile2)" "\n"
97  "\n"
98  "-v be verbose" "\n"
99  "-n normalize input time series to their absolute maximum" "\n"
100  "--overwrite overwrite out put file (in case it already exists)" "\n"
101  "--type f input files have data file format \"f\"" "\n"
102  "--Type f output file will be written in data file format \"f\"" "\n"
103  "--srtol r set sampling rate tolerance for comaprison of" "\n"
104  " input data" "\n"
105  "--ignorecoo ignore coordinates when checking trace consistency\n"
106  };
107 
108  // define commandline options
109  using namespace tfxx::cmdline;
110  static Declare options[]=
111  {
112  // 0: print help
113  {"help",arg_no,"-"},
114  // 1: verbose mode
115  {"v",arg_no,"-"},
116  // 2: debug mode
117  {"DEBUG",arg_no,"-"},
118  // 3: normalize
119  {"n",arg_no,"-"},
120  // 4: overwrite output
121  {"overwrite",arg_no,"-"},
122  // 5: input data format
123  {"type",arg_yes,"sff"},
124  // 6: output data format
125  {"Type",arg_yes,"sff"},
126  // 7: output data format
127  {"srtol",arg_yes,"0.001"},
128  // 8: ignore coordinates
129  {"ignorecoo",arg_no,"-"},
130  {NULL}
131  };
132 
133  // collect options from commandline
134  Commandline cmdline(iargc, argv, options);
135 
136  // help requested? print full help text...
137  if (cmdline.optset(0))
138  {
139  cerr << usage_text << endl;
140  cerr << help_text << endl;
141  exit(0);
142  }
143 
144  // no arguments? print usage...
145  if (iargc<4)
146  {
147  cerr << usage_text << endl;
148  exit(0);
149  }
150 
151  Options opt;
152  opt.verbose=cmdline.optset(1);
153  opt.debug=cmdline.optset(2);
154  opt.normalize=cmdline.optset(3);
155  opt.overwrite=cmdline.optset(4);
156  opt.inputformat=cmdline.string_arg(5);
157  opt.outputformat=cmdline.string_arg(6);
158  opt.srtol=cmdline.double_arg(7);
159  opt.ignorecoo=cmdline.optset(8);
160 
161  TFXX_assert(cmdline.extra(), "ERROR: missing parameter: infile1!");
162  std::string infile1=cmdline.next();
163  TFXX_assert(cmdline.extra(), "ERROR: missing parameter: infile2!");
164  std::string infile2=cmdline.next();
165  TFXX_assert(cmdline.extra(), "ERROR: missing parameter: outfile!");
166  std::string outfile=cmdline.next();
167 
168  if (opt.verbose)
169  {
170  cout << "tolerance when comparing sampling interval: " << opt.srtol <<
171  "\n";
172  cout << "input format: " << cmdline.string_arg(5) << "\n";
173  cout << "output format: " << cmdline.string_arg(6) << "\n";
174  }
175 
176  if (opt.verbose) { cout << "open input file (#1) " << infile1 << endl; }
177  std::ios_base::openmode iopenmode
178  =datrw::ianystream::openmode(opt.inputformat);
179  std::ifstream ifs1(infile1.c_str(), iopenmode);
180  datrw::ianystream is1(ifs1, opt.inputformat, opt.debug);
181  sff::FREE filefree1;
182  sff::SRCE source1;
183  is1 >> filefree1;
184  is1 >> source1;
185 
186  if (opt.verbose) { cout << "open input file (#2) " << infile2 << endl; }
187  std::ifstream ifs2(infile2.c_str(), iopenmode);
188  datrw::ianystream is2(ifs2, opt.inputformat, opt.debug);
189  sff::FREE filefree2;
190  sff::SRCE source2;
191  is2 >> filefree2;
192  is2 >> source2;
193 
194  if (!opt.ignorecoo)
195  {
196  TFXX_assert((source1.cs == source2.cs) &&
197  (source1.cx == source2.cx) &&
198  (source1.cy == source2.cy) &&
199  (source1.cz == source2.cz),
200  "ERROR: coordinates do not match!");
201  }
202 
203  if (opt.verbose) { cout << "open output file " << outfile << endl; }
204  std::ios_base::openmode oopenmode
205  =datrw::oanystream::openmode(opt.outputformat);
206  std::ofstream ofs(outfile.c_str(), oopenmode);
207  datrw::oanystream os(ofs, opt.outputformat, opt.debug);
208  sff::FREE outfilefree;
209  outfilefree.append(GATHERDIFF_VERSION);
210  outfilefree.append("input file #1: "+infile1);
211  outfilefree.append("input file #2: "+infile2);
212  outfilefree.append("input FREE #1:");
213  outfilefree.append(filefree1);
214  outfilefree.append("input FREE #2:");
215  outfilefree.append(filefree2);
216  if (os.handlessrce()) { os << source1; }
217  if (os.handlesfilefree()) { os << outfilefree; }
218 
219  int itrace=0;
220  while (is1.good() && is2.good())
221  {
222  if (opt.verbose) { cout << "process trace #" << ++itrace << endl; }
223 
224  sff::WID2 wid2in1, wid2in2, wid2out;
225  sff::INFO infoin1, infoin2;
226  sff::FREE tracefreein1, tracefreein2, outtracefree;
227  Tseries series1, series2;
228  is1 >> series1;
229  is1 >> wid2in1;
230  is1 >> infoin1;
231  is1 >> tracefreein1;
232  is2 >> series2;
233  is2 >> wid2in2;
234  is2 >> infoin2;
235  is2 >> tracefreein2;
236  outtracefree.append("input FREE #1:");
237  outtracefree.append(tracefreein1);
238  outtracefree.append("input FREE #2:");
239  outtracefree.append(tracefreein2);
240  TFXX_assert((wid2in1.date-source1.date) == (wid2in2.date-source2.date),
241  "ERROR: times do not match!");
242  double dtreldev=1-(wid2in1.dt/wid2in2.dt);
243  if (dtreldev<0) { dtreldev *= -1.; }
244  TFXX_debug(opt.debug, "gatherdiff",
245  "dt infile 1: "<< wid2in1.dt
246  << " dt infile 2: "<< wid2in2.dt
247  << " relative deviation: "<< dtreldev);
248  TFXX_assert(dtreldev <= opt.srtol,
249  "ERROR: sampling interval does not match!");
250  TFXX_assert(wid2in1.nsamples == wid2in2.nsamples,
251  "ERROR: numer of samples does not match!");
252  if (!opt.ignorecoo)
253  {
254  TFXX_assert((infoin1.cs == infoin2.cs) &&
255  (infoin1.cx == infoin2.cx) &&
256  (infoin1.cy == infoin2.cy) &&
257  (infoin1.cz == infoin2.cz),
258  "ERROR: coordinates do not match!");
259  }
260  wid2out=wid2in1;
261  wid2out.channel="dif";
262  if (opt.normalize)
263  {
264  outtracefree.append("input series are normalized to their absolute maximum of 1");
265  double max1=aff::func::absmax(series1);
266  double max2=aff::func::absmax(series2);
267  if (opt.verbose)
268  {
269  cout << "normalize input time series to absolute maximum of 1" <<
270  endl;
271  cout << "absolute maximum of first input series: " << max1 << endl;
272  cout << "absolute maximum of second input series: " << max2 << endl;
273  }
274  series1 /= max1;
275  series2 /= max2;
276  }
277  Tseries outseries=series1-series2;
278  os << wid2out;
279  if (os.handlesinfo()) { os << infoin1; }
280  if (os.handlesfilefree()) { os << outtracefree; }
281  os << outseries;
282  }
283 }
double srtol
Definition: gatherdiff.cc:62
bool ignorecoo
Definition: gatherdiff.cc:60
std::string inputformat
Definition: cross.cc:75
#define GATHERDIFF_VERSION
Definition: gatherdiff.cc:38
bool overwrite
Definition: autocorr.cc:61
std::string outputformat
Definition: cross.cc:75
bool normalize
Definition: gatherdiff.cc:60
bool debug
Definition: autocorr.cc:61
bool verbose
Definition: autocorr.cc:61
aff::Series< double > Tseries
Definition: cross.cc:69