croposp.h 5.07 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
29
/*! \file croposp.h
 * \brief declaration of classes, types and functions used in croposp 
 * 
 * ----------------------------------------------------------------------------
 * 
 * \author Thomas Forbriger
 * \date 06/02/2019
 * 
 * declaration of classes, types and functions used in croposp (prototypes)
 * 
 * Copyright (c) 2019 by Thomas Forbriger (BFO Schiltach) 
 * 
 * ----
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. 
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * ----
 *
 * REVISIONS and CHANGES 
 *  - 06/02/2019   V1.0   Thomas Forbriger
30
 *  - 14/02/2019   V1.1   set program version 1.1
31
32
33
34
 * 
 * ============================================================================
 */
#define CROPOSP_VERSION \
35
  "CROPOSP   V1.1   Cross power spectral density"
36
37
38
39
40

// include guard
#ifndef CROPOSP_H_VERSION

#define CROPOSP_H_VERSION \
41
  "CROPOSP_H   V1.1"
42
43
44
45
46
47
48
49
50
51
52

#include <string>
#include <vector>
#include <tfxx/commandline.h>
#include <tfxx/xcmdline.h>
#include <tsxx/wid2timeseries.h>
#include <tsxx/tscollection.h>
#include <psdxx/psd.h>

namespace croposp {

53
54
55
56
57
  // a structure to hold all commanline parameters
  struct Options {
    bool verbose, trim, debug, overwrite;
    std::string inputformat, labelpattern;
    double datetolerance;
58
    bool logscale, avg_on_output;
59
60
61
62
63
64
65
66
67
68
69
    unsigned int n_per_decade;
    unsigned int nsegments, divisor, padfactor;
    double overlap;
    bool compute_psd, compute_npsd, compute_coherency, compute_transfer;
    bool compute_phase;
    std::string outfile_psd, outfile_npsd, outfile_coherency, outfile_transfer;
    std::string outfile_phase;
    std::string prefix_psd, prefix_npsd, prefix_transfer;
    std::string prefix_phase, prefix_coherency;
  }; // struct Options

70
71
72
73
74
75
76
77
78
79
80
81
82
83
  // a struct to hold meta data
  struct Meta {
    tfxx::cmdline::Filename filearguments;
    std::string label;
  }; // struct Meta

  // type of time series collection to hold input data
  typedef ts::TimeSeriesCollection<double> TCollection;
  // a vector to gold meta data for each time series
  typedef std::vector<Meta> TMetaVector;

  // a struct to hold computation results for exactly one series
  struct NamedSeries {
    std::string label;
84
    psd::TDseries::Tcoc series;
85
86
  }; // struct NamedSeries

87
88
89
  // a struct to hold computation results cross PSD
  struct NamedCPSD {
    std::string label;
90
    psd::TDCseries::Tcoc series;
91
92
  }; // struct NamedCPSD

93
94
95
  // a vector type to hold results
  typedef std::vector<NamedSeries> TNamedSeriesVector;

96
97
98
  // a vector type to hold results
  typedef std::vector<NamedCPSD> TNamedCPSDVector;

99
100
101
102
103
104
105
106
107
108
109
110
  /* ====================================================================== */
  /* classes
   * -------
   */

  /*! provide index values to pairs 
   *
   * cycle through a complete set
   */
  class Pairs {
    public:
      Pairs(const unsigned int& n);
111
112
113
114
115
116
117
118
      unsigned int operator()(const unsigned int& k,
                              const unsigned int& l) const;
      bool swap(const unsigned int& k,
                const unsigned int& l) const;
      unsigned int size() const;
      unsigned int pairs() const;
    private:
      unsigned int Mn;
119
120
  }; // class Pairs

121
122
123
124
125
126
127
128
129
  /* ---------------------------------------------------------------------- */

  /*! provide index values to triples 
   *
   * cycle through a complete set
   */
  class Triples {
    public:
      Triples(const Pairs& p, const bool& pairs_first=false);
130
131
      unsigned int operator()(const unsigned int& i,
                              const unsigned int& k,
132
133
134
135
136
137
138
139
140
141
142
                              const unsigned int& l) const;
      bool swap(const unsigned int& k,
                const unsigned int& l) const;
      unsigned int size() const;
      unsigned int pairs() const;
      unsigned int triples() const;
    private:
      Pairs Mpairs;
      bool Mpairs_first;
  }; // class Triples

143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
  /* ====================================================================== */
  /* functions
   * ---------
   */

  std::string patsubst(const std::string& templatestring,
                       const std::string& pattern,
                       const std::string& content);

  void report_collection(const TCollection& collection,
                         const TMetaVector& metadata,
                         const bool& debug=false);

  void write_named_series(const std::string& filename,
                          const std::string& comment,
                          psd::TDseries f,
                          const TNamedSeriesVector& nsv,
160
                          const Options& opt);
161
162
163
164
165
166

} // namespace croposp

#endif // TF_CROPOSP_H_VERSION (includeguard)

/* ----- END OF croposp.h ----- */