Commit f395b064 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

proceeding with parameter evaluation

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 3926
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 6ea90fb4
...@@ -110,6 +110,9 @@ $Id$ ...@@ -110,6 +110,9 @@ $Id$
Online help is made available through stfinv::STFEngine::help() and Online help is made available through stfinv::STFEngine::help() and
stfinv::help(). stfinv::help().
See the stfinv::STFBaseEngine, where we explain
how the initialization takes place.
\todo \todo
Engines I consider to implement: Engines I consider to implement:
- blind deconvolution in the Fourier domain: - blind deconvolution in the Fourier domain:
...@@ -182,4 +185,41 @@ time series samples as passed to ::initstfinvengine() become invalid. ...@@ -182,4 +185,41 @@ time series samples as passed to ::initstfinvengine() become invalid.
\date 05.05.2011 \date 05.05.2011
*/ */
/*======================================================================*/
/*! \page page_design Design considerations
\section sec_page_design_initialization Initialization of classes
It would have been nice to implement the classes in a way that default
parameters are collected automatically and that the constructors care about
parameter key values not matching a default parameter.
Without tests for matching key values typos by the user may remain
unnoticed.
Default values either must be provided in a static data structure or must be
collected in a top down manner beginning at the child class proceeding to
the parents.
Collection of default parameters must be finished before passing the actual
parameters to the parameter map stfinv::STFBaseEngine::Mparamap.
The sequence in which the constructors are called is the other way round.
Constructor processing naturally starts at the base class and proceeds in
direction of the children.
At the same time a base class constructor is not able to call a virtual
function of the child, since the child not actually is constructed at this
time.
Implementing a check for default parameter matches cannot easily be
implemented within the constructors.
A second sequence of initializing member function would be necessary.
The constructor of the derived class would have to initiate this process
thus ultimately terminating the chain of inheritance.
Since all other initialization takes place in the order starting at the base
class, I do not check the key values and prefer the simple and straight
forward way of implementation.
\date 10.05.2011
*/
// ----- END OF README ----- // ----- END OF README -----
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#define STFINV_PARAMETERHANDLER_CC_CVSID \ #define STFINV_PARAMETERHANDLER_CC_CVSID \
"$Id$" "$Id$"
#include <algorithm>
#include <stfinv/parameterhandler.h> #include <stfinv/parameterhandler.h>
std::string stfinv::tools::clipstring(std::string& s, const std::string& delim) std::string stfinv::tools::clipstring(std::string& s, const std::string& delim)
...@@ -71,4 +72,35 @@ stfinv::tools::Tparamap stfinv::tools::makeparamap(const std::string& p, ...@@ -71,4 +72,35 @@ stfinv::tools::Tparamap stfinv::tools::makeparamap(const std::string& p,
return retval; return retval;
} // stfinv::tools::Tparamap stfinv::tools::makeparamap() } // stfinv::tools::Tparamap stfinv::tools::makeparamap()
/*----------------------------------------------------------------------*/
std::string stfinv::tools::commatospace(std::string s)
{
std::replace(s.begin(), s.end(), ',', ' ');
return(s);
} // std::string stfinv::tools::commatospace(const std::string& s)
/*----------------------------------------------------------------------*/
// \brief remove leading and trailing whitespace
std::string stfinv::tools::trimws(std::string s)
{
if (s.length()>0)
{
std::string::size_type ib=s.find_first_not_of(" ", 0);
if (ib==std::string::npos)
{
s="";
}
else
{
std::string::size_type il=s.find_last_not_of(" \r", s.length());
std::string::size_type n=il>=ib ? il-ib+1 : 0;
if (n==0) { ib = 0; }
if ((ib!=0) || (n!=s.length())) { s=s.substr(ib,n); }
}
}
return(s);
} // std::string trimws(std::string s)
/* ----- END OF parameterhandler.cc ----- */ /* ----- END OF parameterhandler.cc ----- */
...@@ -94,7 +94,18 @@ namespace stfinv { ...@@ -94,7 +94,18 @@ namespace stfinv {
* \param s input string * \param s input string
* \return input string with all commas replaced by whitespace * \return input string with all commas replaced by whitespace
*/ */
std::string commatospace(const std::string& s); std::string commatospace(std::string s);
/*----------------------------------------------------------------------*/
/*! \brief remove leading and trailing whitespace
* \ingroup tools
*
* \param s any string
* \return value a input string with any leading and trailing whitespace
* removed
*/
std::string trimws(std::string s);
} // namespace tools } // namespace tools
......
...@@ -45,6 +45,9 @@ namespace stfinv { ...@@ -45,6 +45,9 @@ namespace stfinv {
void STFBaseEngine::checkconsistency() const void STFBaseEngine::checkconsistency() const
{ {
STFINV_abort("consistency check not yet implemented"); STFINV_abort("consistency check not yet implemented");
const int& n=Mstf.sampling.n;
const double& dt=Mstf.sampling.dt;
const double tolerance=1.e-4;
} }
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
...@@ -54,6 +57,41 @@ namespace stfinv { ...@@ -54,6 +57,41 @@ namespace stfinv {
os << "online help is not implemented for this engine" << std::endl; os << "online help is not implemented for this engine" << std::endl;
} }
/*----------------------------------------------------------------------*/
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)
/*----------------------------------------------------------------------*/
//! \brief return the value of a parameters
std::string STFBaseEngine::parameter(const std::string& key,
const std::string& defvalue="false") const
{
} // std::string STFBaseEngine::parameter()
/*----------------------------------------------------------------------*/
const char* STFBaseEngine::name() const
{
return("STFBaseEngine");
} // const char const* STFBaseEngine::name() const
} // namespace stfinv } // namespace stfinv
/* ----- END OF stfinvbase.cc ----- */ /* ----- END OF stfinvbase.cc ----- */
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
"$Id$" "$Id$"
#include<stfinv/waveformheader.h> #include<stfinv/waveformheader.h>
#include<stfinv/parameterhandler.h>
#include<stfinv/error.h> #include<stfinv/error.h>
#include<aff/series.h> #include<aff/series.h>
#include<iostream> #include<iostream>
...@@ -111,6 +112,9 @@ namespace stfinv { ...@@ -111,6 +112,9 @@ namespace stfinv {
/*! \brief Abstract base class for engines to derive source time functions /*! \brief Abstract base class for engines to derive source time functions
* \ingroup cxxinterface * \ingroup cxxinterface
*
* \sa
* \ref sec_page_design_initialization
*/ */
class STFBaseEngine { class STFBaseEngine {
protected: protected:
...@@ -119,9 +123,10 @@ namespace stfinv { ...@@ -119,9 +123,10 @@ namespace stfinv {
STFBaseEngine(const stfinv::Tvectoroftriples& triples, STFBaseEngine(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf, const stfinv::Waveform& stf,
const std::string& parameters) const std::string& parameters)
: Mtriples(triples), Mstf(stf), Mparameters(parameters) : Mtriples(triples), Mstf(stf)
{ {
this->checkconsistency(); this->checkconsistency();
this->parseparameters(parameters);
} }
public: public:
//! \brief abstract base requires virtual destructor //! \brief abstract base requires virtual destructor
...@@ -130,7 +135,15 @@ namespace stfinv { ...@@ -130,7 +135,15 @@ namespace stfinv {
virtual stfinv::Waveform run() { STFINV_baseillegal; } virtual stfinv::Waveform run() { STFINV_baseillegal; }
//! \brief print online help //! \brief print online help
virtual void help(std::ostream& os=std::cout) const; virtual void help(std::ostream& os=std::cout) const;
//! \brief return name of engine
virtual const char* name() const;
protected:
//! \brief return the value of a parameters
std::string parameter(const std::string& key,
const std::string& defvalue="false") const;
private: private:
//! \brief parse parameters in Mparameters
void parseparameters(std::string parameters);
//! \brief Check consistency of data members. //! \brief Check consistency of data members.
void checkconsistency() const; void checkconsistency() const;
...@@ -140,8 +153,9 @@ namespace stfinv { ...@@ -140,8 +153,9 @@ namespace stfinv {
stfinv::Tvectoroftriples Mtriples; stfinv::Tvectoroftriples Mtriples;
//! \brief Source time function. //! \brief Source time function.
stfinv::Waveform Mstf; stfinv::Waveform Mstf;
//! \brief Control parameters encoded in a string. private:
std::string Mparameters; //! \brief Parameter map
stfinv::tools::Tparamap Mparamap;
}; // class STFBaseEngine }; // class STFBaseEngine
} // namespace stfinv } // namespace stfinv
......
...@@ -73,6 +73,13 @@ namespace stfinv { ...@@ -73,6 +73,13 @@ namespace stfinv {
os << "Online help is not yet provided." << std::endl; os << "Online help is not yet provided." << std::endl;
} // void STFEngineBlindDeconvolution::classhelp(std::ostream& os) } // void STFEngineBlindDeconvolution::classhelp(std::ostream& os)
/*----------------------------------------------------------------------*/
const char* STFEngineBlindDeconvolution::name() const
{
return("STFEngineBlindDeconvolution");
} // const char const* STFEngineBlindDeconvolution::name() const
} // namespace stfinv } // namespace stfinv
/* ----- END OF stfinvblinddeconv.cc ----- */ /* ----- END OF stfinvblinddeconv.cc ----- */
...@@ -71,6 +71,13 @@ namespace stfinv { ...@@ -71,6 +71,13 @@ namespace stfinv {
virtual void help(std::ostream& os=std::cout) const; virtual void help(std::ostream& os=std::cout) const;
//! \brief print online help //! \brief print online help
static void classhelp(std::ostream& os=std::cout); static void classhelp(std::ostream& os=std::cout);
//! \brief return name of engine
virtual const char* name() const;
protected:
//! \brief set default values in Mparamap
virtual void setdefaults() { }
//! \brief initialize work space
virtual void initialize() { }
}; // class STFEngineBlindDeconvolution }; // class STFEngineBlindDeconvolution
} // namespace stfinv } // namespace stfinv
......
...@@ -71,6 +71,13 @@ namespace stfinv { ...@@ -71,6 +71,13 @@ namespace stfinv {
os << "Online help is not yet provided." << std::endl; os << "Online help is not yet provided." << std::endl;
} // void STFEngineFixedWavelet::classhelp(std::ostream& os) } // void STFEngineFixedWavelet::classhelp(std::ostream& os)
/*----------------------------------------------------------------------*/
const char* STFEngineFixedWavelet::name() const
{
return("STFEngineFixedWavelet");
} // const char const* STFEngineFixedWavelet::name() const
} // namespace stfinv } // namespace stfinv
/* ----- END OF stfinvfixedstf.cc ----- */ /* ----- END OF stfinvfixedstf.cc ----- */
...@@ -71,6 +71,13 @@ namespace stfinv { ...@@ -71,6 +71,13 @@ namespace stfinv {
virtual void help(std::ostream& os=std::cout) const; virtual void help(std::ostream& os=std::cout) const;
//! \brief print online help //! \brief print online help
static void classhelp(std::ostream& os=std::cout); static void classhelp(std::ostream& os=std::cout);
//! \brief return name of engine
virtual const char* name() const;
protected:
//! \brief set default values in Mparamap
virtual void setdefaults() { }
//! \brief initialize work space
virtual void initialize() { }
}; // class STFEngineFixedWavelet }; // class STFEngineFixedWavelet
} // namespace stfinv } // namespace stfinv
......
...@@ -64,6 +64,13 @@ namespace stfinv { ...@@ -64,6 +64,13 @@ namespace stfinv {
os << "Online help is not yet provided." << std::endl; os << "Online help is not yet provided." << std::endl;
} // void STFFourierDomainEngine::classhelp(std::ostream& os) } // void STFFourierDomainEngine::classhelp(std::ostream& os)
/*----------------------------------------------------------------------*/
const char* STFFourierDomainEngine::name() const
{
return("STFFourierDomainEngine");
} // const char const* STFFourierDomainEngine::name() const
} // namespace stfinv } // namespace stfinv
/* ----- END OF stfinvfourier.cc ----- */ /* ----- END OF stfinvfourier.cc ----- */
...@@ -72,6 +72,13 @@ namespace stfinv { ...@@ -72,6 +72,13 @@ namespace stfinv {
virtual void help(std::ostream& os=std::cout) const; virtual void help(std::ostream& os=std::cout) const;
//! \brief print online help //! \brief print online help
static void classhelp(std::ostream& os=std::cout); static void classhelp(std::ostream& os=std::cout);
//! \brief return name of engine
virtual const char* name() const;
protected:
//! \brief set default values in Mparamap
virtual void setdefaults() { }
//! \brief initialize work space
virtual void initialize() { }
}; // class STFFourierDomainEngine }; // class STFFourierDomainEngine
} }
......
...@@ -71,6 +71,13 @@ namespace stfinv { ...@@ -71,6 +71,13 @@ namespace stfinv {
os << "Online help is not yet provided." << std::endl; os << "Online help is not yet provided." << std::endl;
} // void STFEngineIdentity::classhelp(std::ostream& os) } // void STFEngineIdentity::classhelp(std::ostream& os)
/*----------------------------------------------------------------------*/
const char* STFEngineIdentity::name() const
{
return("STFEngineIdentity");
} // const char const* STFEngineIdentity::name() const
} // namespace stfinv } // namespace stfinv
/* ----- END OF stfinvidentity.cc ----- */ /* ----- END OF stfinvidentity.cc ----- */
...@@ -71,6 +71,13 @@ namespace stfinv { ...@@ -71,6 +71,13 @@ namespace stfinv {
virtual void help(std::ostream& os=std::cout) const; virtual void help(std::ostream& os=std::cout) const;
//! \brief print online help //! \brief print online help
static void classhelp(std::ostream& os=std::cout); static void classhelp(std::ostream& os=std::cout);
//! \brief return name of engine
virtual const char* name() const;
protected:
//! \brief set default values in Mparamap
virtual void setdefaults() { }
//! \brief initialize work space
virtual void initialize() { }
}; // class STFEngineIdentity }; // class STFEngineIdentity
} // namespace stfinv } // namespace stfinv
......
...@@ -65,6 +65,13 @@ namespace stfinv { ...@@ -65,6 +65,13 @@ namespace stfinv {
os << "Online help is not yet provided." << std::endl; os << "Online help is not yet provided." << std::endl;
} // void STFEngineNormalize::classhelp(std::ostream& os) } // void STFEngineNormalize::classhelp(std::ostream& os)
/*----------------------------------------------------------------------*/
const char* STFEngineNormalize::name() const
{
return("STFEngineNormalize");
} // const char const* STFEngineNormalize::name() const
} // namespace stfinv } // namespace stfinv
/* ----- END OF stfinvnormalize.cc ----- */ /* ----- END OF stfinvnormalize.cc ----- */
...@@ -71,6 +71,13 @@ namespace stfinv { ...@@ -71,6 +71,13 @@ namespace stfinv {
virtual void help(std::ostream& os=std::cout) const; virtual void help(std::ostream& os=std::cout) const;
//! \brief print online help //! \brief print online help
static void classhelp(std::ostream& os=std::cout); static void classhelp(std::ostream& os=std::cout);
//! \brief return name of engine
virtual const char* name() const;
protected:
//! \brief set default values in Mparamap
virtual void setdefaults() { }
//! \brief initialize work space
virtual void initialize() { }
}; // class STFEngineNormalize }; // class STFEngineNormalize
} // namespace stfinv } // namespace stfinv
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment