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$
Online help is made available through stfinv::STFEngine::help() and
stfinv::help().
See the stfinv::STFBaseEngine, where we explain
how the initialization takes place.
\todo
Engines I consider to implement:
- blind deconvolution in the Fourier domain:
......@@ -182,4 +185,41 @@ time series samples as passed to ::initstfinvengine() become invalid.
\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 -----
......@@ -38,6 +38,7 @@
#define STFINV_PARAMETERHANDLER_CC_CVSID \
"$Id$"
#include <algorithm>
#include <stfinv/parameterhandler.h>
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,
return retval;
} // 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 ----- */
......@@ -94,7 +94,18 @@ namespace stfinv {
* \param s input string
* \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
......
......@@ -45,6 +45,9 @@ namespace stfinv {
void STFBaseEngine::checkconsistency() const
{
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 {
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
/* ----- END OF stfinvbase.cc ----- */
......@@ -43,6 +43,7 @@
"$Id$"
#include<stfinv/waveformheader.h>
#include<stfinv/parameterhandler.h>
#include<stfinv/error.h>
#include<aff/series.h>
#include<iostream>
......@@ -111,6 +112,9 @@ namespace stfinv {
/*! \brief Abstract base class for engines to derive source time functions
* \ingroup cxxinterface
*
* \sa
* \ref sec_page_design_initialization
*/
class STFBaseEngine {
protected:
......@@ -119,9 +123,10 @@ namespace stfinv {
STFBaseEngine(const stfinv::Tvectoroftriples& triples,
const stfinv::Waveform& stf,
const std::string& parameters)
: Mtriples(triples), Mstf(stf), Mparameters(parameters)
: Mtriples(triples), Mstf(stf)
{
this->checkconsistency();
this->parseparameters(parameters);
}
public:
//! \brief abstract base requires virtual destructor
......@@ -130,7 +135,15 @@ namespace stfinv {
virtual stfinv::Waveform run() { STFINV_baseillegal; }
//! \brief print online help
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:
//! \brief parse parameters in Mparameters
void parseparameters(std::string parameters);
//! \brief Check consistency of data members.
void checkconsistency() const;
......@@ -140,8 +153,9 @@ namespace stfinv {
stfinv::Tvectoroftriples Mtriples;
//! \brief Source time function.
stfinv::Waveform Mstf;
//! \brief Control parameters encoded in a string.
std::string Mparameters;
private:
//! \brief Parameter map
stfinv::tools::Tparamap Mparamap;
}; // class STFBaseEngine
} // namespace stfinv
......
......@@ -73,6 +73,13 @@ namespace stfinv {
os << "Online help is not yet provided." << std::endl;
} // void STFEngineBlindDeconvolution::classhelp(std::ostream& os)
/*----------------------------------------------------------------------*/
const char* STFEngineBlindDeconvolution::name() const
{
return("STFEngineBlindDeconvolution");
} // const char const* STFEngineBlindDeconvolution::name() const
} // namespace stfinv
/* ----- END OF stfinvblinddeconv.cc ----- */
......@@ -71,6 +71,13 @@ namespace stfinv {
virtual void help(std::ostream& os=std::cout) const;
//! \brief print online help
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
} // namespace stfinv
......
......@@ -71,6 +71,13 @@ namespace stfinv {
os << "Online help is not yet provided." << std::endl;
} // void STFEngineFixedWavelet::classhelp(std::ostream& os)
/*----------------------------------------------------------------------*/
const char* STFEngineFixedWavelet::name() const
{
return("STFEngineFixedWavelet");
} // const char const* STFEngineFixedWavelet::name() const
} // namespace stfinv
/* ----- END OF stfinvfixedstf.cc ----- */
......@@ -71,6 +71,13 @@ namespace stfinv {
virtual void help(std::ostream& os=std::cout) const;
//! \brief print online help
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
} // namespace stfinv
......
......@@ -64,6 +64,13 @@ namespace stfinv {
os << "Online help is not yet provided." << std::endl;
} // void STFFourierDomainEngine::classhelp(std::ostream& os)
/*----------------------------------------------------------------------*/
const char* STFFourierDomainEngine::name() const
{
return("STFFourierDomainEngine");
} // const char const* STFFourierDomainEngine::name() const
} // namespace stfinv
/* ----- END OF stfinvfourier.cc ----- */
......@@ -72,6 +72,13 @@ namespace stfinv {
virtual void help(std::ostream& os=std::cout) const;
//! \brief print online help
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
}
......
......@@ -71,6 +71,13 @@ namespace stfinv {
os << "Online help is not yet provided." << std::endl;
} // void STFEngineIdentity::classhelp(std::ostream& os)
/*----------------------------------------------------------------------*/
const char* STFEngineIdentity::name() const
{
return("STFEngineIdentity");
} // const char const* STFEngineIdentity::name() const
} // namespace stfinv
/* ----- END OF stfinvidentity.cc ----- */
......@@ -71,6 +71,13 @@ namespace stfinv {
virtual void help(std::ostream& os=std::cout) const;
//! \brief print online help
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
} // namespace stfinv
......
......@@ -65,6 +65,13 @@ namespace stfinv {
os << "Online help is not yet provided." << std::endl;
} // void STFEngineNormalize::classhelp(std::ostream& os)
/*----------------------------------------------------------------------*/
const char* STFEngineNormalize::name() const
{
return("STFEngineNormalize");
} // const char const* STFEngineNormalize::name() const
} // namespace stfinv
/* ----- END OF stfinvnormalize.cc ----- */
......@@ -71,6 +71,13 @@ namespace stfinv {
virtual void help(std::ostream& os=std::cout) const;
//! \brief print online help
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
} // 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