stfinvbase.cc 4.63 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
30
31
32
33
34
35
36
37
38
39
40
/*! \file stfinvbase.cc
 * \brief C++ interface and abstract base class (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
 * $Id$
 * \author Thomas Forbriger
 * \date 06/05/2011
 * 
 * C++ interface and abstract base class (implementation)
 * 
 * Copyright (c) 2011 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, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * ----
 *
 * 
 * REVISIONS and CHANGES 
 *  - 06/05/2011   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */
#define STFINV_STFINVBASE_CC_VERSION \
  "STFINV_STFINVBASE_CC   V1.0   "
#define STFINV_STFINVBASE_CC_CVSID \
  "$Id$"

thomas.forbriger's avatar
thomas.forbriger committed
41
42
#include <sstream>
#include <cmath>
43
44
45
46
#include <stfinv/stfinvbase.h>

namespace stfinv {

thomas.forbriger's avatar
thomas.forbriger committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  STFBaseEngine::STFBaseEngine(const stfinv::Tvectoroftriples& triples,
                               const stfinv::Waveform& stf,
                               const std::string& parameters)
    : Mtriples(triples), Mstf(stf)
  {
    this->checkconsistency();
    this->parseparameters(parameters);
    std::istringstream is(this->parameter("DEBUG","0"));
    is >> Mdebug;
    Mverbose=(this->parameter("verbose","false")=="true");
  } // STFBaseEngine::STFBaseEngine(const stfinv::Tvectoroftriples& triples,

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

61
62
  void STFBaseEngine::checkconsistency() const
  {
63
    const unsigned int& n=Mstf.sampling.n;
64
65
    const double& dt=Mstf.sampling.dt;
    const double tolerance=1.e-4;
thomas.forbriger's avatar
thomas.forbriger committed
66
67
68
69
70
71
72
73
74
    stfinv::Tvectoroftriples::const_iterator I=Mtriples.begin();
    while (I!=Mtriples.end())
    {
      CTripleHeader header=I->header;
      STFINV_assert(header.sampling.n==n,
                    "inconsistent number of samples");
      STFINV_assert(std::abs(1.-header.sampling.dt/dt)<tolerance,
                    "inconsistent values of sampling interval");
    } // while (I!=Mtriples.end())
75
76
77
78
79
80
81
82
83
  }

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

  void STFBaseEngine::help(std::ostream& os) const
  {
    os << "online help is not implemented for this engine" << std::endl;
  }

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  /*----------------------------------------------------------------------*/

  void STFBaseEngine::parseparameters(std::string parameters) 
  {
    while (parameters.length()>0)
    {
      std::string value=stfinv::tools::clipstring(parameters,":");
      std::string key
        =stfinv::tools::trimws(stfinv::tools::clipstring(value,"="));
      if (value.length()==0)
      {
        this->Mparamap[key]="true";
      }
      else
      {
        this->Mparamap[key]=value;
      }
    } // while (parameters.length()>0)
  } // void STFBaseEngine::parseparameters(std::string parameters)

  /*----------------------------------------------------------------------*/
  
thomas.forbriger's avatar
thomas.forbriger committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  /*! \brief check is parameter was set
   *
   * \param key parameter key
   * \return true, if parameter was set by user
   */
  bool STFBaseEngine::parameterisset(const std::string& key) const
  {
    return (Mparamap.count(key)>0);
  } // bool STFBaseEngine::parameter(const std::string& key) const

  /*----------------------------------------------------------------------*/
  
  /*! \brief return the value of a parameters
   *
   * \param key parameter key
   * \param defvalue default value to be used is not set externally
   * \return parameter value or default value if key is not present.
   */
124
  std::string STFBaseEngine::parameter(const std::string& key,
thomas.forbriger's avatar
thomas.forbriger committed
125
                                       const std::string& defvalue) const
126
  {
thomas.forbriger's avatar
thomas.forbriger committed
127
128
129
130
131
132
133
134
135
136
    std::string retval;
    if (this->parameterisset(key))
    {
      retval=Mparamap[key];
    }
    else
    {
      retval=defvalue;
    }
    return retval;
137
138
139
140
141
142
143
144
145
  } // std::string STFBaseEngine::parameter()

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

  const char* STFBaseEngine::name() const
  {
    return("STFBaseEngine");
  } //  const char const* STFBaseEngine::name() const

146
147
148
} // namespace stfinv

/* ----- END OF stfinvbase.cc ----- */