Waveform filter programs

◆ main()

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

Definition at line 811 of file sigscale.cc.

References cmdlinekeys, DDAS3::conversion_code(), DDAS3::convert_to_display_units(), Options::debrep, Options::debug, formatkey, Options::inputformat, Options::outputformat, Options::overwrite, DDAS3::report_sidiode_table(), SIGSCALE_VERSION, tracekey, TRANGE_100K, TRANGE_12K, TRANGE_24K, TRANGE_475K, and Options::verbose.

812 {
813 
814  // define usage information
815  char usage_text[]=
816  {
817  SIGSCALE_VERSION "\n"
818  "usage: sigscale [-v] [-o] [-itype type] [-otype type]" "\n"
819  " outfile infile [t:T] [f:F] [infile [t:T] [f:F] ... ]" "\n"
820  " or: sigscale --help|-h" "\n"
821  " or: sigscale --xhelp" "\n"
822  };
823 
824  // define full help text
825  char help_text[]=
826  {
827  "outfile name of output file" "\n"
828  "infile name of input file" "\n"
829  " t:T select traces T, where T may be any range" "\n"
830  " specification like \'3-4\' or \'5,6,7-12,20\'" "\n"
831  " f:F specifies an input file format differing from" "\n"
832  " the format selected by \"-type\"" "\n"
833  "\n"
834  "-xhelp print detailed information regarding file formats" "\n"
835  "-v be verbose" "\n"
836  "-DEBUG produce debug output" "\n"
837  "-DEBREP report internal scaling values for debugging" "\n"
838  "-o overwrite output" "\n"
839  "-itype type choose input file format (default: sff)" "\n"
840  "-otype type choose output file format (default: sff)" "\n"
841  "\n"
842  "This program is designed for auxilliary data from superconduction\n"
843  "gravimeter SG056 at BFO. It uses scling relations provided by GWR\n"
844  "to convert sample values to meaningful physical units."
845  };
846 
847  // define commandline options
848  using namespace tfxx::cmdline;
849  static Declare options[]=
850  {
851  // 0: print help
852  {"help",arg_no,"-"},
853  // 1: verbose mode
854  {"v",arg_no,"-"},
855  // 2: overwrite mode
856  {"o",arg_no,"-"},
857  // 3: input file format
858  {"itype",arg_yes,"sff"},
859  // 4: output file format
860  {"otype",arg_yes,"sff"},
861  // 5: generate debug output
862  {"DEBUG",arg_no,"-"},
863  // 6: output file format
864  {"xhelp",arg_no,"-"},
865  // 7: generate debug output
866  {"DEBREP",arg_no,"-"},
867  {NULL}
868  };
869 
870  // file specific keys
871  static const char tracekey[]="t";
872  static const char formatkey[]="f";
873 
874  // define commandline argument modifier keys
875  static const char* cmdlinekeys[]
876  ={tracekey, formatkey, 0};
877 
878  // no arguments? print usage...
879  if (iargc<2)
880  {
881  cerr << usage_text << endl;
882  cerr << tfxx::seitosh::repository_reference << endl;
883  exit(0);
884  }
885 
886  // collect options from commandline
887  Commandline cmdline(iargc, argv, options);
888 
889  // help requested? print full help text...
890  if (cmdline.optset(0))
891  {
892  cerr << usage_text << endl;
893  cerr << help_text << endl;
894  datrw::supported_data_types(cerr);
895  cerr << endl << tfxx::seitosh::repository_reference << endl;
896  exit(0);
897  }
898 
899  // help on file format details requested?
900  if (cmdline.optset(6))
901  {
902  cerr << usage_text << endl;
903  cerr << endl;
904  datrw::online_help(cerr);
905  cerr << endl << tfxx::seitosh::repository_reference << endl;
906  exit(0);
907  }
908  // extract commandline options
909  Options opt;
910  opt.verbose=cmdline.optset(1);
911  opt.overwrite=cmdline.optset(2);
912  opt.inputformat=cmdline.string_arg(3);
913  opt.outputformat=cmdline.string_arg(4);
914  opt.debug=cmdline.optset(5);
915  // 6 is --xhelp
916  opt.debrep=cmdline.optset(7);
917 
918  /*======================================================================*/
919 
920  if (opt.debrep) {
921  cout << SIGSCALE_VERSION << endl;
922 
927  exit(2);
928  }
929 
930  /*======================================================================*/
931 
932  if (opt.verbose)
933  { cout << SIGSCALE_VERSION << endl; }
934 
935  // extract commandline arguments
936  TFXX_assert(cmdline.extra(), "missing output file");
937  std::string outfile=cmdline.next();
938  TFXX_assert(cmdline.extra(), "missing input file");
939  tfxx::cmdline::Tparsed arguments=parse_cmdline(cmdline, cmdlinekeys);
940  if ((arguments.size()>1) && opt.verbose)
941  {
942  cout << "NOTICE: file specific information (SRCE line and file FREE)" <<
943  endl
944  << " will be taken from first file only!" << endl;
945  }
946 
947  /*======================================================================*/
948  // start processing
949 
950  // open output file
951  // ----------------
952  if (opt.verbose) { cout << "open output file " << outfile << endl; }
953  // check if output file exists and open
954  if (!opt.overwrite)
955  {
956  std::ifstream file(outfile.c_str(),std::ios_base::in);
957  TFXX_assert((!file.good()),"ERROR: output file exists!");
958  }
959  std::ios_base::openmode oopenmode
960  =datrw::oanystream::openmode(opt.outputformat);
961  std::ofstream ofs(outfile.c_str(), oopenmode);
962  datrw::oanystream os(ofs, opt.outputformat, opt.debug);
963 
964  // set flag to process header of first input file
965  bool firstfile=true;
966  // cycle through all input files
967  // -----------------------------
968  tfxx::cmdline::Tparsed::const_iterator infile=arguments.begin();
969  while (infile != arguments.end())
970  {
971  // open input file
972  if (opt.verbose) { cout << "open input file " << infile->name << endl; }
973  std::string inputformat=opt.inputformat;
974  if (infile->haskey(formatkey))
975  {
976  inputformat=infile->value(formatkey);
977  }
978  std::ios_base::openmode iopenmode
979  =datrw::ianystream::openmode(inputformat);
980  std::ifstream ifs(infile->name.c_str(), iopenmode);
981  datrw::ianystream is(ifs, inputformat);
982 
983  // handle file header
984  // ------------------
985  sff::FREE filefree;
986  if (firstfile)
987  {
988  if (is.hasfree())
989  {
990  sff::FREE infilefree;
991  is >> infilefree;
992  filefree.append("block read from first input file:");
993  filefree.append(infilefree);
994  }
995  if (os.handlesfilefree()) { os << filefree; }
996  if (is.hassrce())
997  {
998  sff::SRCE insrceline;
999  is >> insrceline;
1000  if (os.handlessrce()) { os << insrceline; }
1001  }
1002  }
1003 
1004  // cycle through traces of input file
1005  // ----------------------------------
1006  // setup trace selection
1007  typedef tfxx::RangeList<int> Trangelist;
1008  bool doselect=infile->haskey(tracekey);
1009  Trangelist traceranges=
1010  tfxx::string::rangelist<Trangelist::Tvalue>(infile->value(tracekey));
1011  int itrace=0;
1012  while (is.good())
1013  {
1014  ++itrace;
1015  if ((!doselect) || traceranges.contains(itrace))
1016  {
1017  TFXX_debug(opt.debug, "main", "process trace #" << itrace );
1018  if (opt.verbose)
1019  { std::cout << " process trace #" << itrace << ":"; }
1020  Tseries series;
1021  is >> series;
1022 
1023  sff::WID2 wid2;
1024  is >> wid2;
1025  TFXX_debug(opt.debug, "main",
1026  " series and WID2 are read");
1027  sff::INFO info;
1028  if (is.hasinfo())
1029  {
1030  is >> info;
1031  }
1032 
1033  /*----------------------------------------------------------------------*/
1034  // apply scaling
1035  ChannelDescription CD;
1036  SFFchannelid sid;
1037  sid.station=wid2.station;
1038  sid.channel=wid2.channel;
1039  sid.instrument=wid2.instype;
1040  sid.auxid=wid2.auxid;
1041  CD=channel(sid);
1042 
1043  std::string CCstring=DDAS3::conversion_code(CD.cc);
1044 
1045  aff::Iterator<Tseries> I(series);
1046  while (I.valid())
1047  {
1048  Tseries::Tvalue v= *I;
1049  *I = DDAS3::convert_to_display_units(CD.cc, v);
1050  ++I;
1051  }
1052 
1053  /*----------------------------------------------------------------------*/
1054 
1055  os << wid2;
1056  TFXX_debug(opt.debug, "main",
1057  " series and WID are written");
1058  if (is.hasinfo())
1059  {
1060  if (os.handlesinfo()) { os << info; }
1061  }
1062  if (is.hasfree() || true)
1063  {
1064  sff::FREE tracefree;
1065  is >> tracefree;
1066  tracefree.append(SIGSCALE_VERSION);
1067  tracefree.append("read from file " + infile->name);
1068  tracefree.append("applied scaling for conversion code \""
1069  + CCstring +"\"");
1070  if (os.handlestracefree()) { os << tracefree; }
1071  }
1072  TFXX_debug(opt.debug, "main",
1073  "trace #" << itrace << " successfully processed");
1074  os << series;
1075  }
1076  else
1077  {
1078  TFXX_debug(opt.debug, "main", "skip trace #" << itrace );
1079  if (opt.verbose)
1080  { std::cout << " skip trace #" << itrace << std::endl; }
1081  is.skipseries();
1082  }
1083  }
1084 
1085  // go to next file
1086  firstfile=false;
1087  ++infile;
1088  }
1089 }
#define SIGSCALE_VERSION
Definition: sigscale.cc:35
std::string inputformat
Definition: cross.cc:75
static const char * cmdlinekeys[]
Definition: fidasexx.cc:131
double Tvalue
Definition: fidasexx.cc:136
#define TRANGE_24K
Definition: sigscale.cc:97
static const char formatkey[]
Definition: fidasexx.cc:128
bool overwrite
Definition: autocorr.cc:61
std::string outputformat
Definition: cross.cc:75
bool debug
Definition: autocorr.cc:61
double convert_to_display_units(const Econversion &ConvCode, const double &chanval)
Definition: sigscale.cc:601
bool verbose
Definition: autocorr.cc:61
std::string conversion_code(const Econversion &ConvCode)
Definition: sigscale.cc:732
void report_sidiode_table(int range)
Definition: sigscale.cc:101
#define TRANGE_475K
Definition: sigscale.cc:99
const char *const tracekey
key to select traces
Definition: deconv.cc:68
bool debrep
Definition: sigscale.cc:67
#define TRANGE_100K
Definition: sigscale.cc:98
#define TRANGE_12K
Definition: sigscale.cc:96
aff::Series< double > Tseries
Definition: cross.cc:69
Here is the call graph for this function: