testpsdxx.cc 4.3 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
/*! \file testpsdxx.cc
 * \brief test library functions
 * 
 * ----------------------------------------------------------------------------
 * 
 * \author Thomas Forbriger
 * \date 10/01/2019
 * 
 * test library functions
 * 
 * Copyright (c) 2019 by Thomas Forbriger (BFO Schiltach) 
 * 
 * REVISIONS and CHANGES 
 *  - 10/01/2019   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */
#define TESTPSDXX_VERSION \
  "TESTPSDXX   V1.0   test library functions"

#include <iostream>
#include <tfxx/commandline.h>
23
#include <psdxx/psd.h>
24
#include <psdxx/debug.h>
25
#include <psdxx/helper.h>
26
#include <aff/dump.h>
27
28
29
30
31

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

32
33
struct Options
{
34
35
  bool verbose, logfrequency, logindex, logtaper;
  int taperindex;
36
37
}; // Options

38
39
40
41
/* ====================================================================== */

void testlogindex(const psd::TDseries::Tcoc& f, const int& i)
{
42
43
  CODE( psd::helper::LogIndex index(f(i), f(i+1), f(i+2)) );
  cout << "with " << PSDXX_value(i) << endl;
44
45
  for (int i=f.f(); i<=f.l(); ++i)
  {
46
    cout << PSDXX_value(i) << " " << PSDXX_value(index(f(i))) << endl;
47
48
49
50
51
  }
}

/* ====================================================================== */

52
53
54
55
56
57
58
int main(int iargc, char* argv[])
{

  // define usage information
  char usage_text[]=
  {
    TESTPSDXX_VERSION "\n"
59
    "usage: testpsdxx [-lf] [-li] [-lt [i]]" "\n"
60
61
62
63
64
65
    "   or: testpsdxx --help|-h" "\n"
  };

  // define full help text
  char help_text[]=
  {
66
67
68
69
    "-lf     test function log_frequency\n"
    "-li     test function class LogIndex\n"
    "-lt [i] test function class LogTaper, center taper on\n"
    "        frequency with index i on logarithmic scale\n"
70
71
72
73
74
75
76
77
78
79
  };

  // define commandline options
  using namespace tfxx::cmdline;
  static Declare options[]= 
  {
    // 0: print help
    {"help",arg_no,"-"},
    // 1: verbose mode
    {"v",arg_no,"-"},
80
    // 2: log frequency
81
    {"lf",arg_no,"-"},
82
83
    // 3: log index
    {"li",arg_no,"-"},
84
85
    // 4: log taper
    {"lt",arg_opt,"5"},
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
    {NULL}
  };

  // 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);
  }

107
108
109
  Options opt;
  opt.verbose=cmdline.optset(1);
  opt.logfrequency=cmdline.optset(2);
110
  opt.logindex=cmdline.optset(3);
111
112
  opt.logtaper=cmdline.optset(4);
  opt.taperindex=cmdline.int_arg(4);
113

114
115
116
117
118
119
120
121
122
123
124
  if (opt.logfrequency)
  {
    cout << "test function log_frequency" << endl;
    CODE( psd::TDseries ls1=psd::log_frequency(0.1,100,6) );
    DUMP( ls1 );
    CODE( ls1=psd::log_frequency(0.1,10000,6) );
    DUMP( ls1 );
    CODE( ls1=psd::log_frequency(0.1,1000,20) );
    DUMP( ls1 );
    CODE( ls1=psd::log_frequency(0.1,10000,2) );
    DUMP( ls1 );
125
126
127
128
129
130
131
132
133
134
135
136
137
138
    CODE( ls1=psd::log_frequency(0.1,10000,6) );
    for (int i=ls1.f(); i<=ls1.l(); ++i)
    {
      cout << "i=" << i << " f=" << ls1(i) << " nu= " <<
        std::log(ls1(i)/ls1(ls1.f()))/std::log(10.) << endl;
    }
    int iref=2;
    double fref=ls1(iref-1);
    double fref1=ls1(iref);
    for (int i=iref+1; i<=ls1.l(); ++i)
    {
      cout << "i=" << i << " f=" << ls1(i) << " nu= " <<
        std::log((ls1(i)-fref)/(fref1-fref))/std::log(10.) << endl;
    }
139
  } // if (opt.logfrequency)
140

141
142
  /* ---------------------------------------------------------------------- */

143
144
145
146
147
148
149
150
  if (opt.logindex)
  {
    cout << "test class LogIndex" << endl;
    CODE( psd::TDseries ls1=psd::log_frequency(0.1,1000,6) );
    DUMP( ls1 );
    testlogindex(ls1, 0);
    testlogindex(ls1, 3);
  } // if (opt.logindex)
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

  /* ---------------------------------------------------------------------- */

  if (opt.logtaper)
  {
    cout << "test class LogTaper" << endl;
    CODE( psd::TDseries linf=psd::lin_frequency(0.1,100) );
    CODE( psd::TDseries logf=psd::log_frequency(0.1,100,6) );
    CODE( psd::helper::LogTaper logt(logf, opt.taperindex) ); 
    cout << PSDXX_value( logf(opt.taperindex) ) << endl;
    for (int i=linf.f(); i<= linf.l(); ++i)
    {
      cout << i << " " << linf(i) << " " << logt(linf(i)) << endl;
    }
    cout << PSDXX_value( logt.sum() ) << endl;
  } // if (opt.logtaper)
167
168
169
}

/* ----- END OF testpsdxx.cc ----- */