croposp.cc 3.81 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
/*! \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>
24
#include <tsxx/tscollection.h>
25
26
27
28
29

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

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

35
36
37
38
39
40
41
42
43
44
45
46
47
48
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[]=
  {
49
50
51
52
53
    "-verbose     verbose\n"
    "-itype f     input file format\n"
    "\n"
    "t:sel        trace selection\n"
    "f:format     file format\n"
54
55
56
57
58
59
60
61
62
  };

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

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

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

  // 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);
  }
93
94
95
96

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

102
103
104
105
106
  // read data files
  if (opt.verbose) 
  {
    cout << "Read time series data" << endl;
  }
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  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;
  }

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
  // collect traces
  typedef ts::TimeSeriesCollection<double> TCollection;
  TCollection list_of_series;
  typedef ts::sff::DFile::Tfile Tfile;
  typedef Tfile::Ttracevector Ttracevector;
  ts::sff::TDFileList::const_iterator i_file=input_file_list.begin();
  while (i_file != input_file_list.end())
  {
    Ttracevector::const_iterator i_trace=i_file->data.begin();
    while (i_trace != i_file->data.end())
    {
      list_of_series.push_back(*i_trace);
      ++i_trace;
    }
    ++i_file;
  }

  // report traces
  if (opt.verbose)
  {
    cout << "Time series to be analyzed:" << endl;
    TCollection::const_iterator i_series=list_of_series.begin();
    while (i_series != list_of_series.end())
    {
      cout << "  "
        << i_series->header.station << " "
        << i_series->header.channel << " "
        << i_series->header.auxid << " "
        << "dt=" << i_series->header.dt << "s "
        << "begin: " << i_series->header.date.timestring() << " "
        << "n: " << i_series->header.nsamples 
        << endl;
      ++i_series;
    }
  }

157
158
159
} // main()

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