stfinvany.cc 6.91 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
/*! \file stfinvany.cc
 * \brief a wrapper to any STF engine in the library (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
 * \author Thomas Forbriger
 * \date 06/05/2011
 * 
 * a wrapper to any STF engine in the library (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
 *  - 30/09/2011   V1.1   implemented handling of additional time series pairs
 *  - 04/10/2011   V1.2   renamed Fourier domain least squares engine
34
 *  - 14/10/2015   V1.3   new end-user usage functions
35 36 37 38
 * 
 * ============================================================================
 */
#define STFINV_STFINVANY_CC_VERSION \
39
  "STFINV_STFINVANY_CC   V1.3"
40 41 42 43 44 45

#include <stfinv/stfinvany.h>
#include <stfinv/stfinvfdleastsquares.h>
#include <stfinv/stfinvfixedstf.h>
#include <stfinv/stfinvidentity.h>
#include <stfinv/parameterhandler.h>
46 47 48 49
#include <stfinv/stfinvany_summary_usage.h>
#include <stfinv/stfinvany_description_usage.h>
#include <stfinv/stfinv_summary_usage.h>
#include <stfinv/stfinv_description_usage.h>
50
#include <stfinv/error.h>
51
#include <stfinv/tools.h>
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

namespace stfinv {
  
  //! \brief Constructor.
  STFEngine::STFEngine(const stfinv::Tvectoroftriples& triples,
                       const stfinv::Waveform& stf,
                       const std::string& parameters)
  {
    stfinv::Tvectorofpairs pairs;
    pairs.clear();
    this->initialize(triples, stf, pairs, parameters);
  }

  /*----------------------------------------------------------------------*/
  //! \brief Constructor.
  STFEngine::STFEngine(const stfinv::Tvectoroftriples& triples,
                       const stfinv::Waveform& stf,
                       const stfinv::Tvectorofpairs& pairs,
                       const std::string& parameters)
  {
    this->initialize(triples, stf, pairs, parameters);
  }

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

  void STFEngine::initialize(const stfinv::Tvectoroftriples& triples,
                             const stfinv::Waveform& stf,
                             const stfinv::Tvectorofpairs& pairs,
                             const std::string& parameters)
  {
    std::string para=parameters;
    std::string id=stfinv::tools::clipstring(para, ":");
    if (id == std::string(stfinv::STFEngineIdentity::ID))
    {
      Mengine=new stfinv::STFEngineIdentity(triples, stf, para);
    }
88
    /*
89 90 91 92 93 94
    else if (id == std::string(stfinv::STFEngineFixedWavelet::ID))
    {
      STFINV_assert(pairs.size()==0,
              "ERROR: engine does not support additional time series pairs");
      Mengine=new stfinv::STFEngineFixedWavelet(triples, stf, para);
    }
95
    */
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    else if ((id == std::string(stfinv::STFEngineFDLeastSquares::ID))
             || (id == std::string("fbd")))
    {
      STFINV_report_assert((id == std::string(stfinv::STFEngineFDLeastSquares::ID)),
                           "The ID \"fbd\" for this engine is deprecated",
                           "The correct ID of the Fourier domain least "
                           "squares engine is \"" <<
                           stfinv::STFEngineFDLeastSquares::ID <<
                           "\".\n"
                           "The former ID \"fbd\" may vanish in the future "
                           "and should no longer be used.");
      if (pairs.size()>0)
      {
        Mengine=new stfinv::STFEngineFDLeastSquares(triples, stf, 
                                                        pairs, para);
      }
      else
      {
        Mengine=new stfinv::STFEngineFDLeastSquares(triples, stf, para);
      }
    }
    else
    {
      std::cerr << "ERROR: engine ID " << id << " is unkown!" << std::endl;
      STFINV_abort("aborting since engine ID is not recognized");
    }
    STFINV_assert(Mengine!=0, "engine was not created correctly");
  }

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

  STFEngine::~STFEngine() 
  {
    delete Mengine;
  } // STFEngine::~STFEngine()

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

134
  void STFEngine::engines(std::ostream& os)
135
  {
136 137 138 139 140
    os << "Available procedures:" << std::endl;
    os << "---------------------" << std::endl;
    tools::report_engine<STFEngineIdentity>(os);
    // tools::report_engine<STFEngineFixedWavelet>(os);
    tools::report_engine<STFEngineFDLeastSquares>(os);
141 142
  } // void STFEngine::help(std::ostream& os=std::cout)

143
  /*----------------------------------------------------------------------*/
144

145
  void STFEngine::help(std::ostream& os)
146
  {
147
    os << stfinv_summary_usage;
148
    os << std::endl;
149
    STFEngine::engines(os);
150
    os << std::endl;
151
    STFEngineIdentity::classhelp(os);
152 153
    os << std::endl;
    STFEngineFDLeastSquares::classhelp(os);
154 155 156 157 158 159 160
    os << std::endl;
    STFFourierDomainEngine::classhelp(os);
    os << std::endl;
    STFBaseEngine::classhelp(os);
    os << std::endl;
    os << stfinvany_summary_usage;
  } // void STFEngine::help(std::ostream& os=std::cout)
161

162
  /*----------------------------------------------------------------------*/
163

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
  void STFEngine::usage(const std::string& id, std::ostream& os)
  {
    os << stfinv_description_usage;
    os << std::endl;
    if (id == std::string(stfinv::STFEngineIdentity::ID))
    {
      stfinv::STFEngineIdentity::classusage(os);
    }
    else if ((id == std::string(stfinv::STFEngineFDLeastSquares::ID)))
    {
      stfinv::STFEngineFDLeastSquares::classusage(os);
    }
    else
    {
      std::cerr << "ERROR: engine ID " << id << " is unkown!" << std::endl;
      STFINV_abort("aborting since engine ID is not recognized");
    }
181
    os << std::endl;
182 183 184 185 186 187 188 189 190
    os << stfinvany_description_usage;
  } // void STFEngine::help(std::ostream& os=std::cout)

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

  void engines(std::ostream& os)
  {
    STFEngine::engines(os);
  } // void engines(std::ostream& os)
191

192 193
  void help(std::ostream& os)
  {
194 195 196
    STFEngine::help(os);
  } // void help(std::ostream& os=std::cout)

197 198 199 200 201
  void usage(const std::string& id, std::ostream& os)
  {
    STFEngine::usage(id, os);
  } // void usage(const std::string& id, std::ostream& os)

202 203 204
} // namespace stfinv

/* ----- END OF stfinvany.cc ----- */