Waveform filter programs

◆ main()

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

Definition at line 364 of file geophone.cc.

References Tparameters::C, Toptions::debug, Toptions::dt, Tparameters::fn, func_heff(), func_R1(), func_R2(), func_Rd(), func_RdV(), func_Rs(), func_V(), GEOPHON_VERSION, Tparameters::heff, Tparameters::hoc, Toptions::outfile, Toptions::R1, Toptions::R1mode, Toptions::R2mode, Tparameters::Rc, Toptions::Rd, Toptions::Rd1mode, Toptions::resfile, response(), Tparameters::Ri, Toptions::saveresponse, Toptions::T, Tparameters::type, Toptions::V, Toptions::verbose, writeparameters(), and Toptions::writeresfile.

365 {
366 
367  // define usage information
368  char usage_text[]=
369  {
370  GEOPHON_VERSION "\n"
371  "usage: geophone [-hoc hoc] [-heff heff] [-Ri Ri] [-Rc Rc]" "\n"
372  " [-C C] [-fn fn] [-type type] [-o file]" "\n"
373  " [-T T] [-dt dt] [-Rd1 Rd,R1]" "\n"
374  " or: geophone --help|-h" "\n"
375  };
376 
377  // define full help text
378  char help_text[]=
379  {
380  "-v be verbose" "\n"
381  "-DEBUG debug mode" "\n"
382  "\n"
383  "geophone parameters:\n"
384  "-hoc hoc open circuit damping" "\n"
385  "-Rc Rc coil resistance" "\n"
386  "-C C geophone constant" "\n"
387  " C=Rt*Bc*fn=(K**2)/(4*pi*m)" "\n"
388  "-fn fn natural frequency" "\n"
389  "-type type geophone type" "\n"
390  "\n"
391  "recorder parameters:\n"
392  "-Ri Ri recorder input resistance" "\n"
393  "\n"
394  "desired damping:\n"
395  "-heff heff desired effective damping" "\n"
396  "\n"
397  "output parameters:\n"
398  "-o file name of file to save impulse response" "\n"
399  " parameters T and dt specify the sampling for\n"
400  " the impulse response time series\n"
401  "-T T length of time series" "\n"
402  " as a fraction of the natural period" "\n"
403  "-dt dt sampling interval" "\n"
404  " as a fraction of the natural period" "\n"
405  "\n"
406  "-resfile file Write an appropriate seife deconvolution" "\n"
407  " filter to \"file\". The filter is designed" "\n"
408  " to deconvolve the output of the damped geophone" "\n"
409  " to the repsonse of the standard application (i.e." "\n"
410  " geophone connected directly to recorder)." "\n"
411  "\n"
412  "alternative modes of operation:\n"
413  "-R2 V return R2 for voltage division factor V" "\n"
414  " specified relative to the voltage obtained" "\n"
415  " by standard operation (Ri being the only" "\n"
416  " resistance external to the geophone)." "\n"
417  " heff is ignored in this case." "\n"
418  "-R1 V return R1 and R2 for voltage division factor V" "\n"
419  " maintaining a damping of heff." "\n"
420  " V is specified like with option -R2." "\n"
421  "-Rd1 Rd,R1 The values R1 and Rd specify the additional" "\n"
422  " resistance in series with the geophone (R1) and" "\n"
423  " parallel to the recorder (Rd). The program" "\n"
424  " returns the resulting response." "\n"
425  "\n"
426  "All damping values are given as a fraction of critical damping." "\n"
427  "\n"
428  "Usually you specify hoc, Ri, Rc, C, fn, and heff. Then the program" "\n"
429  "will tell you which shunt resistance to use parallel to the recorder" "\n"
430  "input terminals." "\n"
431  "\n"
432  "In case you specify V by option -R2, the program will ignore the" "\n"
433  "desired effective damping heff and will tell you, which shunt" "\n"
434  "resistance to use to obtain the desired voltage division factor V." "\n"
435  "\n"
436  "In case you specify V by option -R1, the program will tell you," "\n"
437  "which shunt and series resistance to use to obtain the desired" "\n"
438  "voltage division factor V and damping heff." "\n"
439  "\n"
440  "In case you specify the series resistance R1 and the shunt resistantce\n"
441  "Rd in parallel to the recorder by option -Rd1, the program returns" "\n"
442  "the resulting response." "\n"
443  "\n"
444  "Circuit diagram:\n"
445  "\n"
446  " +--------+ +-----+ +--------+\n"
447  " | +----|-----| R1 |-----+-----|---+ |\n"
448  " | | | +-----+ | | | |\n"
449  " | +---+ | +---+ | +---+ |\n"
450  " | | | | | | | | | |\n"
451  " | |Rc | | |Rd | | |Ri | |\n"
452  " | | | | | | | | | |\n"
453  " | +---+ | +---+ | +---+ |\n"
454  " | | | | | | |\n"
455  " | +----|-----------------+-----|---+ |\n"
456  " | | | |\n"
457  " |geophone| |recorder|\n"
458  " +--------+ +--------+\n"
459  " ||||\n"
460  " |||| usually R1=0 and Rd=infinity\n"
461  " ||\n"
462  " || use finite Rd for larger \n"
463  " || effective damping\n"
464  " ||\n"
465  " || use R1 to set up a voltage divider\n"
466  " \\/ and small effective damping\n"
467  "\n"
468  "Background:\n"
469  "Usually geophones are directly connected to the recording system.\n"
470  "This is equivalent to R1=0 and Rd=infinity. With Ri >> Rc the\n"
471  "effective damping of the geophone is only slightly larger than\n"
472  "the open circuit damping of the geophone.\n"
473  "\n"
474  "If a damping of the geophone larger than the open circuit damping\n"
475  "is desired, a finite Rd can be connected in parallel to the input\n"
476  "of the recording system. This program provides the appropriate value\n"
477  "if the desired effective damping is passed in the parameter to\n"
478  "option -heff. Alternatively the effective damping heff is\n"
479  "provided as output, if values for R1 and Rd are passed as\n"
480  "parameters to option -Rd1.\n"
481  "\n"
482  "In some cases near offset geophones are saturated in the recording\n"
483  "system by ground motion close to the seismic source. In this case a\n"
484  "small resistance Rd can be used to set up a voltage divider with\n"
485  "the coil resistance Rc thus makeing the voltage to be recorded\n"
486  "smaller accordingly. At the same time this will strongly damp the\n"
487  "geophone itself thus preventing mechanical saturation and clipping.\n"
488  "If this is desired, the parallel resistance required for a given\n"
489  "amplitude factor V is provided by the program, if V is passed as\n"
490  "a parameter to option -R1.\n"
491  "\n"
492  "If strong overdamping of the geophone has to be avoided, for\n"
493  "example to maintain the same effective damping for all geophones\n"
494  "in a profile, a series resistance R1 together with a parallel\n"
495  "resistance Rd can be used to adjust a voltage divider with\n"
496  "factor V and a desired effective damping heff at the same time.\n"
497  "In this case pass V as a parameter to option -R2 and heff as a\n"
498  "parameter to option -heff.\n"
499  "\n"
500  "If R1 and Rd are known from the configuration of the seismic\n"
501  "experiment, you can use both values as parameters to option\n"
502  "-Rd1 in order to obtain the effective response characteristic\n"
503  "of the geophone.\n"
504  "\n"
505  "Geophone response are provided in three ways:\n"
506  "1. Effective geophone parameters are printed to standard output.\n"
507  "2. A filename passed as a parameter to option -resfile will\n"
508  " cause the program to create a filter control file with this\n"
509  " name. This filter control file can be used together with\n"
510  " stufi or tidofi in order to restore the response of a\n"
511  " geophone as used with R1=0 and Rd=infinity in terms of\n"
512  " effective damping as well as singal amplitude.\n"
513  "3. A filename passed as a parameter to option -o will cause\n"
514  " the program to produce an SFF data file containing the\n"
515  " the impulse response of the geophone. The first trace contains\n"
516  " the response of the geophone as if recorded with R1=0 and\n"
517  " Rd=infinity. The second trace contains the impulse response\n"
518  " of a geophone if operated with a finite R1 and Rd as\n"
519  " specified by the command line arguments. The effective\n"
520  " geophone parameters are given in the first line of the\n"
521  " trace FREE block.\n"
522  };
523 
524  // define commandline options
525  using namespace tfxx::cmdline;
526  static Declare options[]=
527  {
528  // 0: print help
529  {"help",arg_no,"-"},
530  // 1: verbose mode
531  {"v",arg_no,"-"},
532  // 2: open circuit damping
533  {"hoc",arg_yes,"0.315"},
534  // 3: desired effective damping
535  {"heff",arg_yes,"0.707"},
536  // 4: recorder input resistance
537  {"Ri",arg_yes,"20000."},
538  // 5: coil resistance
539  {"Rc",arg_yes,"375."},
540  // 6: geophone constant
541  {"C",arg_yes,"6000."},
542  // 7: natural frequency
543  {"fn",arg_yes,"8."},
544  // 8: geophone type
545  {"type",arg_yes,"SM-4"},
546  // 9: geophone type
547  {"o",arg_yes,"response.sff"},
548  // 10: length of time series
549  {"T",arg_yes,"10."},
550  // 11: sampling interval
551  {"dt",arg_yes,"1.e-2"},
552  // 12: series resistance
553  {"R1",arg_yes,"0."},
554  // 13: series resistance
555  {"R2",arg_yes,"1.e12"},
556  // 14: Rd and R1
557  {"Rd1", arg_yes, "-"},
558  // 15: deconvolution filter
559  {"resfile", arg_yes, "res.fil"},
560  // 16: deconvolution filter
561  {"DEBUG", arg_no, "-"},
562  {NULL}
563  };
564 
565  // no arguments? print usage...
566  if (iargc<1)
567  {
568  cerr << usage_text << endl;
569  exit(0);
570  }
571 
572  // collect options from commandline
573  Commandline cmdline(iargc, argv, options);
574 
575  // help requested? print full help text...
576  if (cmdline.optset(0))
577  {
578  cerr << usage_text << endl;
579  cerr << help_text << endl;
580  exit(0);
581  }
582 
583  /*
584  // dummy operation: print option settings
585  for (int iopt=0; iopt<2; iopt++)
586  {
587  cout << "option: '" << options[iopt].opt_string << "'" << endl;
588  if (cmdline.optset(iopt)) { cout << " option was set"; }
589  else { cout << "option was not set"; }
590  cout << endl;
591  cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
592  cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
593  cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
594  cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
595  cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
596  cout << " argument (bool): '";
597  if (cmdline.bool_arg(iopt))
598  { cout << "true"; } else { cout << "false"; }
599  cout << "'" << endl;
600  }
601  while (cmdline.extra()) { cout << cmdline.next() << endl; }
602 
603  // dummy operation: print rest of command line
604  while (cmdline.extra()) { cout << cmdline.next() << endl; }
605  */
606 
607  Tparameters para;
608  para.hoc=cmdline.double_arg(2);
609  para.heff=cmdline.double_arg(3);
610  para.Ri=cmdline.double_arg(4);
611  para.Rc=cmdline.double_arg(5);
612  para.C=cmdline.double_arg(6);
613  para.fn=cmdline.double_arg(7);
614  para.type=cmdline.string_arg(8);
615 
616  Toptions opt;
617  opt.verbose=cmdline.optset(1);
618  opt.saveresponse=cmdline.optset(9);
619  opt.outfile=cmdline.string_arg(9);
620  opt.T=cmdline.double_arg(10);
621  opt.dt=cmdline.double_arg(11);
622  opt.R1mode=cmdline.optset(12);
623  opt.V=cmdline.double_arg(12);
624  opt.R2mode=cmdline.optset(13);
625  if (!opt.R1mode) { opt.V=cmdline.double_arg(13); }
626  opt.Rd1mode=cmdline.optset(14);
627  if (opt.Rd1mode)
628  {
629  std::string args=cmdline.string_arg(14);
630  args.replace(args.find(","),1," ");
631  std::istringstream is(args);
632  is >> opt.Rd >> opt.R1;
633  }
634  opt.writeresfile=cmdline.optset(15);
635  opt.resfile=cmdline.string_arg(15);
636  opt.debug=cmdline.optset(16);
637 
638  /*----------------------------------------------------------------------*/
639 
640 /*
641  double Rd=1./(1./((para.C/((para.heff-para.hoc)*para.fn))-para.Rc)
642  -(1./para.Ri));
643  double hnd=para.hoc+para.C/(para.fn*(para.Ri+para.Rc));
644  double Rs=1./((1./Rd)+(1./para.Ri));
645  double Afac=100.*para.Ri/(para.Ri+para.Rc);
646  double Afacs=100.*Rs/(Rs+para.Rc);
647 */
648 
649  // calculate reference parameters
650  double hnd=func_heff(para.fn, para.hoc, para.C, para.Rc, para.Ri);
651  double Afac=func_V(para.Ri, para.Rc);
652 
653  double Rd, R1=0., heff, Afaceff, Rs;
654  // case Rd1
655  if (opt.Rd1mode)
656  {
657  Rd=opt.Rd;
658  R1=opt.R1;
659  Rs=func_Rs(para.Ri, Rd, R1);
660  heff=func_heff(para.fn, para.hoc, para.C, para.Rc, Rs);
661  Afaceff=func_V(para.Ri, para.Rc, R1, Rd);
662  }
663  // case R1
664  else if (opt.R1mode)
665  {
666  Afaceff=opt.V*Afac;
667  heff=para.heff;
668  Rs=func_Rs(para.fn, para.hoc, para.C, para.Rc, para.heff);
669  Rd=func_R2(para.Ri, para.Rc, Rs, Afaceff);
670  R1=func_R1(para.Ri, para.Rc, Rs, Afaceff);
671  }
672  // case R2
673  else if (opt.R2mode)
674  {
675  R1=0.;
676  Afaceff=opt.V*Afac;
677  Rd=func_RdV(para.Ri, para.Rc, Afaceff);
678  Rs=func_Rs(para.Ri, Rd, 0.);
679  heff=func_heff(para.fn, para.hoc, para.C, para.Rc, Rs);
680  }
681  // default case
682  else
683  {
684  R1=0.;
685  heff=para.heff;
686  Rs=func_Rs(para.fn, para.hoc, para.C, para.Rc, para.heff);
687  Rd=func_Rd(Rs, para.Ri);
688  // effective input resistance
689  Afaceff=func_V(para.Ri, para.Rc, R1, Rd);
690  }
691 
692  /*----------------------------------------------------------------------*/
693  // report
694  writeparameters(cout, "", para, hnd, heff, Rs, R1, Rd, Afac, Afaceff);
695 
696  if (opt.saveresponse) {
697  if (opt.verbose) {
698  cout << endl;
699  cout << "write impulse response to " << opt.outfile << endl;
700  }
701 
702  double dt=opt.dt/para.fn;
703  int n=int(opt.T/opt.dt);
704  Tseries srnd=response(para.fn,hnd,dt,n);
705  srnd *= Afac;
706  Tseries sreff=response(para.fn,heff,dt,n);
707  sreff *= Afaceff;
708 
709  sff::WID2 wid2;
710  wid2.dt=dt;
711 
712  std::ostringstream oss;
713  sff::FREE ndfree, efffree;
714  oss.str("");
715  oss << para.type << " geophone impulse response ("
716  << "fn=" << para.fn << "Hz, " << "h=" << hnd << ")";
717  ndfree.append(oss.str());
718  oss.str("");
719  oss << para.type << " geophone impulse response ("
720  << "fn=" << para.fn << "Hz, " << "h=" << heff << ")";
721  efffree.append(oss.str());
722 
723  TFXX_debug(opt.debug, "geophon (main):",
724  "para.heff = " << heff << "\n"
725  "oss.str(): " << oss.str());
726 
727  std::ofstream ofs(opt.outfile.c_str());
728  sff::SFFostream<Tseries> os(ofs);
729  os << srnd;
730  os << wid2;
731  os << ndfree;
732  os << sreff;
733  os << wid2;
734  os << efffree;
735 
736  } // if (opt.saveresponse)
737 
738  if (opt.writeresfile)
739  {
740  if (opt.verbose) {
741  cout << endl;
742  cout << "write deconvolution filter to " << opt.resfile << endl;
743  }
744 
745  std::ofstream os(opt.resfile.c_str());
746  os << "rem deconvolution filter calculated by" << endl;
747  writeparameters(os, "rem ", para, hnd, heff, Rs, R1, Rd, Afac, Afaceff);
748  os << "fac " << (Afac/Afaceff) << endl;
749  os << "he2 " << 1./para.fn << ","
750  << heff << ","
751  << 1./para.fn << ","
752  << hnd << endl;
753  os << "end " << endl;
754  } // if (opt.writeresfile)
755 }
double T
Definition: geophone.cc:96
bool saveresponse
Definition: geophone.cc:93
#define GEOPHON_VERSION
Definition: geophone.cc:49
bool verbose
Definition: geophone.cc:93
double func_V(const double &Ri, const double &Rc)
Definition: geophone.cc:209
double Rc
Definition: geophone.cc:80
bool debug
Definition: geophone.cc:94
std::string resfile
Definition: geophone.cc:95
double fn
Definition: geophone.cc:80
double func_heff(const double &fn, const double &hoc, const double &C, const double &Rc, const double &Rs)
Definition: geophone.cc:150
double Rd
Definition: geophone.cc:96
double C
Definition: geophone.cc:80
bool writeresfile
Definition: geophone.cc:93
bool R1mode
Definition: geophone.cc:93
std::string outfile
Definition: geophone.cc:95
double func_R2(const double &Ri, const double &Rc, const double &Rs, const double &V)
Definition: geophone.cc:279
double func_RdV(const double &Ri, const double &Rc, const double &V)
Definition: geophone.cc:241
void writeparameters(std::ostream &os, const std::string &prefix, const Tparameters &para, const double &hnd, const double &heff, const double &Rs, const double &R1, const double &Rd, const double &Afac, const double &Afaceff)
Definition: geophone.cc:292
std::string type
Definition: geophone.cc:89
double func_R1(const double &Ri, const double &Rc, const double &Rs, const double &V)
Definition: geophone.cc:260
double R1
Definition: geophone.cc:96
bool R2mode
Definition: geophone.cc:93
double hoc
Definition: geophone.cc:80
double Ri
Definition: geophone.cc:80
double V
Definition: geophone.cc:96
double func_Rd(const double &Rs, const double &Ri)
Definition: geophone.cc:196
double dt
Definition: geophone.cc:96
double heff
Definition: geophone.cc:80
double func_Rs(const double &fn, const double &hoc, const double &C, const double &Rc, const double &heff)
Definition: geophone.cc:167
aff::Series< double > Tseries
Definition: cross.cc:69
bool Rd1mode
Definition: geophone.cc:93
Tseries response(const double &fn, const double &h, const double &dt, const int &n)
Definition: geophone.cc:114
Here is the call graph for this function: