croposp.cc 2.65 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*! \file croposp.cc
 * \brief Cross power spectral density
 * 
 * ----------------------------------------------------------------------------
 * 
 * \author Thomas Forbriger
 * \date 25/12/2018
 * 
 * Cross power spectral density
 * 
 * Copyright (c) 2018 by Thomas Forbriger (BFO Schiltach) 
 * 
 * REVISIONS and CHANGES 
 *  - 25/12/2018   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */
#define CROPOSP_VERSION \
  "CROPOSP   V1.0   Cross power spectral density"

#include <iostream>
#include <tfxx/commandline.h>
#include <tsioxx/cmdlinefiles.h>

using std::cout;
using std::cerr;
using std::endl;

29
30
31
32
33
struct Options {
  bool verbose;
  std::string inputformat;
}; // struct Options

34
35
36
37
38
39
40
41
42
43
44
45
46
47
int main(int iargc, char* argv[])
{

  // define usage information
  char usage_text[]=
  {
    CROPOSP_VERSION "\n"
    "usage: croposp" "\n"
    "   or: croposp --help|-h" "\n"
  };

  // define full help text
  char help_text[]=
  {
48
49
50
51
52
    "-verbose     verbose\n"
    "-itype f     input file format\n"
    "\n"
    "t:sel        trace selection\n"
    "f:format     file format\n"
53
54
55
56
57
58
59
60
61
  };

  // define commandline options
  using namespace tfxx::cmdline;
  static Declare options[]= 
  {
    // 0: print help
    {"help",arg_no,"-"},
    // 1: verbose mode
62
63
64
    {"verbose",arg_no,"-"},
    // 2: default input file format
    {"itype",arg_yes,"sff"},
65
66
67
68
69
    {NULL}
  };

  // define command line keys for input files
  static const char tracekey[]="t";
70
  static const char formatkey[]="f";
71
72

  // define commandline argument modifier keys
73
  static const char* cmdlinekeys[]={tracekey, formatkey, 0};
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

  // no arguments? print usage...
  if (iargc<2) 
  {
    cerr << usage_text << endl;
    exit(0);
  }

  // collect options from commandline
  Commandline cmdline(iargc, argv, options);

  // help requested? print full help text...
  if (cmdline.optset(0))
  {
    cerr << usage_text << endl;
    cerr << help_text << endl;
    exit(0);
  }
92
93
94
95

  Options opt;
  opt.verbose=cmdline.optset(1);
  opt.inputformat=cmdline.string_arg(2);
96
97
98
99
100
  
  // extract commandline arguments
  TFXX_assert(cmdline.extra(), "missing input file");
  tfxx::cmdline::Tparsed arguments=parse_cmdline(cmdline, cmdlinekeys);

101
102
103
104
105
106
107
108
109
110
111
112
113
114
  ts::sff::TDFileList input_file_list;
  tfxx::cmdline::Tparsed::const_iterator file=arguments.begin();
  while (file != arguments.end())
  {
    std::string format=opt.inputformat;
    if (file->haskey(formatkey))
    {
      format=file->value(formatkey);
    }
    input_file_list.push_back(ts::sff::readDSFF(*file, opt.verbose, 
                                                tracekey, format));
    ++file;
  }

115
116
117
} // main()

/* ----- END OF croposp.cc ----- */