testpsdxx.cc 3.33 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
  bool verbose, logfrequency, logindex;
35
36
}; // Options

37
38
39
40
/* ====================================================================== */

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

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

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

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

  // define full help text
  char help_text[]=
  {
65
    "-lf    test function log_frequency"
66
67
68
69
70
71
72
73
74
75
  };

  // define commandline options
  using namespace tfxx::cmdline;
  static Declare options[]= 
  {
    // 0: print help
    {"help",arg_no,"-"},
    // 1: verbose mode
    {"v",arg_no,"-"},
76
    // 2: log frequency
77
    {"lf",arg_no,"-"},
78
79
    // 3: log index
    {"li",arg_no,"-"},
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
    {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);
  }

101
102
103
  Options opt;
  opt.verbose=cmdline.optset(1);
  opt.logfrequency=cmdline.optset(2);
104
  opt.logindex=cmdline.optset(3);
105

106
107
108
109
110
111
112
113
114
115
116
  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 );
117
118
119
120
121
122
123
124
125
126
127
128
129
130
    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;
    }
131
  } // if (opt.logfrequency)
132
133
134
135
136
137
138
139
140

  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)
141
142
143
}

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