[Debian-astro-commits] [gyoto] 130/221: Convert Spectrommeter::Generic and ::Uniform to Object/Property; rename Spectrometer::Generic::kind_ to kindid_; remove kind_ from Spectrum::Generic
Thibaut Jean-Claude Paumard
thibaut at moszumanska.debian.org
Fri May 22 20:52:40 UTC 2015
This is an automated email from the git hooks/post-receive script.
thibaut pushed a commit to branch master
in repository gyoto.
commit 4876907c001532a7a6a2685800fc47de8d94f42e
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date: Fri Dec 5 17:01:34 2014 +0100
Convert Spectrommeter::Generic and ::Uniform to Object/Property; rename Spectrometer::Generic::kind_ to kindid_; remove kind_ from Spectrum::Generic
---
include/GyotoDefs.h | 1 +
include/GyotoProperty.h | 27 +++++-
include/GyotoSpectrometer.h | 111 +++++------------------
include/GyotoSpectrum.h | 3 +-
include/GyotoUniformSpectrometer.h | 33 ++++---
lib/Object.C | 25 +++++-
lib/Property.C | 14 +++
lib/Spectrometer.C | 51 +++++------
lib/Spectrum.C | 5 +-
lib/UniformSpectrometer.C | 177 ++++++++++++++++++++++++-------------
yorick/gyoto_SpectroComplex.C | 2 +-
yorick/gyoto_SpectroUniform.C | 6 +-
yorick/gyoto_Spectrometer.C | 4 +-
yorick/gyoto_utils.C | 7 +-
14 files changed, 250 insertions(+), 216 deletions(-)
diff --git a/include/GyotoDefs.h b/include/GyotoDefs.h
index 98c7fc3..9bb259d 100644
--- a/include/GyotoDefs.h
+++ b/include/GyotoDefs.h
@@ -608,6 +608,7 @@ namespace Gyoto {
# define getThickness thickness;
# define setDir dir;
# define getDir dir;
+# define setBand band;
//\}
#endif
diff --git a/include/GyotoProperty.h b/include/GyotoProperty.h
index ee12d7d..c2b7f57 100644
--- a/include/GyotoProperty.h
+++ b/include/GyotoProperty.h
@@ -114,6 +114,15 @@ namespace Gyoto {
(Gyoto::Property::set_vector_double_t)&class::fname, \
(Gyoto::Property::get_vector_double_t)&class::fname),
+/// Define a Property of type vector<double> with unit support
+#define GYOTO_PROPERTY_VECTOR_DOUBLE_UNIT(class, name, fname) \
+ Gyoto::Property \
+ (#name, \
+ (Gyoto::Property::set_vector_double_t)&class::fname, \
+ (Gyoto::Property::get_vector_double_t)&class::fname, \
+ (Gyoto::Property::set_vector_double_unit_t)&class::fname, \
+ (Gyoto::Property::get_vector_double_unit_t)&class::fname),
+
/// Define a Property of type Gyoto::Metric::Generic
#define GYOTO_PROPERTY_METRIC(class, name, fname) \
Gyoto::Property \
@@ -166,6 +175,8 @@ class Gyoto::Property
typedef std::string (Object::* get_fname_t)() const;
typedef void (Object::* set_vector_double_t)(std::vector<double> const&);
typedef std::vector<double> (Object::* get_vector_double_t)() const;
+ typedef void (Object::* set_vector_double_unit_t)(std::vector<double> const&, std::string const &);
+ typedef std::vector<double> (Object::* get_vector_double_unit_t)(std::string const &) const;
typedef void (Object::* set_metric_t)
(Gyoto::SmartPointer<Gyoto::Metric::Generic>);
@@ -197,8 +208,14 @@ class Gyoto::Property
get_metric_t get_metric;
get_spectrum_t get_spectrum;
};
- union setter_unit_t {set_double_unit_t set_double;};
- union getter_unit_t {get_double_unit_t get_double;};
+ union setter_unit_t {
+ set_double_unit_t set_double;
+ set_vector_double_unit_t set_vdouble;
+ };
+ union getter_unit_t {
+ get_double_unit_t get_double;
+ get_vector_double_unit_t get_vdouble;
+ };
setter_t setter;
getter_t getter;
setter_unit_t setter_unit;
@@ -243,6 +260,12 @@ class Gyoto::Property
get_vector_double_t get_vdouble);
Property(std::string name,
+ set_vector_double_t set_vdouble,
+ get_vector_double_t get_vdouble,
+ set_vector_double_unit_t set_vdouble_unit,
+ get_vector_double_unit_t get_vdouble_unit);
+
+ Property(std::string name,
set_metric_t set_metric,
get_metric_t get_metric);
diff --git a/include/GyotoSpectrometer.h b/include/GyotoSpectrometer.h
index 69635be..b7d468b 100644
--- a/include/GyotoSpectrometer.h
+++ b/include/GyotoSpectrometer.h
@@ -73,7 +73,7 @@ namespace Gyoto{
/**
* \brief Type for Spectrometer kind
*
- * Spectrometer kind is a unique numerical identifier for that kind,
+ * Spectrometer kindid is a unique numerical identifier for that kind,
* produced as the address to a static C string variable holding the
* kind's name. Most of the time, the address is the only
* significant part as this is more reliable and allows for direct
@@ -153,7 +153,7 @@ namespace Gyoto{
*
* \param name The kind name which identifies this object type in
* an XML file, as in <Spectrometer kind="name">. For
- * clarity, this should be the same as the value of kind_ for this
+ * clarity, this should be the same as the value of kindid_ for this
* object, but it is not mandatory.
*
* \param scp A pointer to the subcontractor, which will
@@ -177,14 +177,14 @@ class Gyoto::Spectrometer::Generic
friend class Gyoto::SmartPointer<Gyoto::Spectrometer::Generic>;
protected:
/**
- * \brief Spectrometer kind name
+ * \brief Spectrometer kind ID
*
- * The content is not copied. kind_ should be set (as a parameter to
- * the Generic() constructor or using kind()) to the adress of a
+ * The content is not copied. kindid_ should be set (as a parameter to
+ * the Generic() constructor or using kindid()) to the adress of a
* static variable holding the name. This allows checking the kind
* using pointer comparison rather than string comparison.
*/
- kind_t kind_;
+ kind_t kindid_;
public:
size_t nsamples_; ///< Number of spectral elements
size_t nboundaries_; ///< Size of the boundaries_ array
@@ -228,6 +228,8 @@ class Gyoto::Spectrometer::Generic
double* widths_;
public:
+ GYOTO_OBJECT;
+
/**
* \brief Default constructor
*
@@ -236,26 +238,26 @@ class Gyoto::Spectrometer::Generic
Generic();
/**
- * \brief Constructor setting kind
+ * \brief Constructor setting kindid
*
* Sets the other members to 0. This is usually the right
* constructor to use:
* \code
- * Complex::Complex : Generic(Complex::Kind) {}
+ * Complex::Complex : Generic(Complex::Kindid) {}
* \endcode
*
- * Always set kind to the adress of a static variable, not to a temporary.
+ * Always set kindid to the adress of a static variable, not to a temporary.
* Usually your class should have a static member for that purpose:
* \code
* class MyKind : public Spectrometer::Generic
* {
- * static kind_t Kind;
+ * static kind_t Kindid;
* };
- * kind_t MyKind::Kind = "MyKind";
+ * kind_t MyKind::Kindid = "MyKind";
* \endcode
*
*/
- Generic(kind_t kind);
+ Generic(kind_t kindid);
/**
* \brief Copy constructor
@@ -287,25 +289,25 @@ class Gyoto::Spectrometer::Generic
virtual ~Generic();
/**
- * \brief Get kind_
+ * \brief Get kindid_
*
* You can check whether the Spectrometer sp is of a given kind
* MyKind with something like:
*
* \code
- * if (sp->kind()) == MyKind::Kind;
+ * if (sp->kind()) == MyKind::Kindid;
* \endcode
*
* See Uniform::WaveKind, Uniform::WaveLogKind, Uniform::FreqKind,
* Uniform::FreqLogKind and Complex::Kind.
*
*/
- virtual kind_t kind() const ;
+ virtual kind_t kindid() const ;
/**
- * \brief Set Generic::kind_
+ * \brief Set Generic::kindid_
*
- * This should rarely be used as the Generic::kind_ attribute usually is set
+ * This should rarely be used as the Generic::kindid_ attribute usually is set
* in the constructor and doesn't change after that.
*
* Always set to the adress of a static variable, not to a temporary.
@@ -313,16 +315,16 @@ class Gyoto::Spectrometer::Generic
* \code
* class MyKind : public Spectrometer::Generic
* {
- * static kind_t Kind;
+ * static kind_t Kindid;
* };
* kind_t MyKind::Kind = "MyKind";
* ...
* SmartPointer<MyKind> sp();
- * sp->kind(MyKind::Kind)
+ * sp->kindid(MyKind::Kindid)
* \endcode
*
*/
- virtual void kind(kind_t) ;
+ virtual void kindid(kind_t) ;
virtual size_t nSamples() const ; ///< Get Generic::nsamples_.
virtual size_t getNBoundaries() const ; ///< Get Generic::nboundaries_
@@ -354,75 +356,6 @@ class Gyoto::Spectrometer::Generic
*/
virtual void getWidths( double data[], std::string unit);
- /**
- * \brief Set parameter by name
- *
- * Assume MyKind is a subclass of Spectrometer::Generic which has
- * two members (a string StringMember and a double DoubleMember):
- *
- * \code
- * int MyKind::setParameter(std::string name, std::string content, std::string unit)
- * {
- * if (name=="StringMember") setStringMember(content);
- * else if (name=="DoubleMember") setDoubleMemeber(atof(content.c_str()), unit);
- * else return Generic::setParameter(name, content, unit);
- * return 0;
- * }
- * \endcode
- *
- * If MyKind is not a direct subclass of Generic, it should call the
- * corresponding setParameter() implementation instead of
- * Generic::setParameter().
- *
- * \param name XML name of the parameter
- * \param content string representation of the value
- * \param unit string representation of the unit
- * \return 0 if this parameter is known, 1 if it is not.
- */
- virtual int setParameter(std::string name,
- std::string content,
- std::string unit);
-#ifdef GYOTO_USE_XERCES
-
-
- /**
- * \brief Main loop in Subcontractor_t function
- *
- * The Subcontractor_t function for each Spectrometer kind should look
- * somewhat like this (templated as
- * Gyoto::Spectrometer::Subcontractor<MyKind>):
- *
- * \code
- * SmartPointer<Spectrometer::Generic>
- * Gyoto::Spectrometer::MyKind::Subcontractor(FactoryMessenger* fmp)
- * {
- * SmartPointer<MyKind> gg = new MyKind();
- * gg -> setParameters(fmp);
- * return gg;
- * }
- * \endcode
- *
- * Each spectrometer kind should implement setParameter(string name,
- * string content, string unit) to interpret the individual XML
- * elements. setParameters() can be overloaded in case the specific
- * Spectrometer class needs low level access to the FactoryMessenger. See
- * Gyoto::Astrobj::UniformSphere::setParameters().
- */
- virtual void setParameters(Gyoto::FactoryMessenger *fmp) ;
-
- /**
- * \brief Write out parameters to XML entities
- *
- * Spectrometers implementations should impement fillElement to save their
- * parameters to XML and call the Spectrometer::fillElement(fmp) for the
- * shared properties.
- *
- * This is mainly used by the Yorick plug-in to print out any sort
- * of GYOTO objects and to save them to XML files.
- */
- virtual void fillElement(FactoryMessenger *fmp) const ;
-
-#endif
};
diff --git a/include/GyotoSpectrum.h b/include/GyotoSpectrum.h
index d72d9fb..02f5bcb 100644
--- a/include/GyotoSpectrum.h
+++ b/include/GyotoSpectrum.h
@@ -129,13 +129,12 @@ class Gyoto::Spectrum::Generic
{
friend class Gyoto::SmartPointer<Gyoto::Spectrum::Generic>;
protected:
- std::string kind_; ///< e.g. constants, blackbody...
public:
GYOTO_OBJECT;
Generic(const std::string kind); ///< Set kind in constructor
- // Spectrum::Generic(const Spectrum::Generic &); ///< Copy constructor. Default is fine.
+ Generic(const Spectrum::Generic &);
virtual Generic * clone() const; ///< Cloner
virtual ~Generic() ; ///< Destructor: does nothing.
diff --git a/include/GyotoUniformSpectrometer.h b/include/GyotoUniformSpectrometer.h
index 84e0292..8d9caf9 100644
--- a/include/GyotoUniformSpectrometer.h
+++ b/include/GyotoUniformSpectrometer.h
@@ -78,6 +78,7 @@ class Gyoto::Spectrometer::Uniform : public Gyoto::Spectrometer::Generic {
void reset_(); ///< Computes boundaries_, midpoints_ and widths_
public:
+ GYOTO_OBJECT;
Uniform() ; ///< Default constructor
Uniform(size_t nsamples, double band_min, double band_max,
kind_t kind); ///< Constructor setting everything
@@ -85,8 +86,8 @@ class Gyoto::Spectrometer::Uniform : public Gyoto::Spectrometer::Generic {
Generic * clone() const; ///< Cloner
virtual ~Uniform() ; ///< Destructor
- using Generic::kind;
- void kind(kind_t);
+ using Generic::kindid;
+ void kindid(kind_t);
/**
* \brief Set Generic::kind_ from a std::string
@@ -97,7 +98,8 @@ class Gyoto::Spectrometer::Uniform : public Gyoto::Spectrometer::Generic {
* \param name std::string, one of "wave", "wavelog", "freq" or
* "freqlog"
*/
- void kind(std::string name);
+ void kind(std::string const &name);
+ std::string kind() const;
using Generic::nSamples;
/**
@@ -105,13 +107,18 @@ class Gyoto::Spectrometer::Uniform : public Gyoto::Spectrometer::Generic {
*/
void nSamples(size_t n);
+ void band(std::vector<double> const &nu);
+ void band(std::vector<double> const &nu, std::string const &unit);
+ std::vector<double>band() const;
+ std::vector<double>band(std::string const &unit) const;
+
/**
* \brief Set Uniform::band_
*
* \param nu 2-element vector, in Hz, m, log10(Hz) or log10(m)
* depending on Generic::kind_
*/
- void setBand(double nu[2]);
+ void band(double nu[2]);
/**
* \brief Set the spectral band boundaries in specified unit
@@ -125,27 +132,17 @@ class Gyoto::Spectrometer::Uniform : public Gyoto::Spectrometer::Generic {
* - kind==wavelog: 10^nu in meters
*
*/
- void setBand(double nu[2], std::string unit, std::string kind="");
+ void band(double nu[2], std::string const &unit, std::string const &kind);
+ void band(double nu[], std::string const &unit);
double const * getBand() const ; ///< Get Uniform::band_
-#ifdef GYOTO_USE_XERCES
public:
- void fillElement(FactoryMessenger *fmp) const ;
-
- /**
- * \brief Main loop in the (templated) subcontractor
- *
- * In the case of Spectrometer::Complex, the setParameter() API is
- * not sufficient: setParameters() needs acces to the
- * FactoryMessenger to instanciate childs for the SubSpectrometers.
- */
+ void fillProperty(Gyoto::FactoryMessenger *fmp, Property const &p) const;
+#ifdef GYOTO_USE_XERCES
virtual void setParameters(FactoryMessenger *fmp);
#endif
- virtual int setParameter(std::string name,
- std::string content,
- std::string unit);
/**
* \brief "wave"
*
diff --git a/lib/Object.C b/lib/Object.C
index c27a312..4127478 100644
--- a/lib/Object.C
+++ b/lib/Object.C
@@ -48,8 +48,21 @@ void Object::set(Property const &p,
}
}
return;
+ case Property::vector_double_t:
+ {
+ Property::set_vector_double_unit_t setu = p.setter_unit.set_vdouble;
+ if (setu) {
+ GYOTO_DEBUG << "vector<double> Property which supports unit" << endl;
+ (this->*setu)(val, unit);
+ } else {
+ GYOTO_DEBUG << "vector<double> Property which does not support unit" << endl;
+ if (unit != "") throwError("Can't set this property with unit");
+ set(p, val);
+ }
+ }
+ return;
default:
- GYOTO_DEBUG<< "Not a double_t or empty_t Property" << endl;
+ GYOTO_DEBUG<< "Not a double_t, vector_double_t or empty_t Property" << endl;
if (unit != "")
throwError("Can't set this property with unit (not a double)");
set(p, val);
@@ -104,6 +117,13 @@ Value Object::get(Property const &p,
return get(p);
}
+ if (p.type == Property::vector_double_t) {
+ Property::get_vector_double_unit_t getu = p.getter_unit.get_vdouble;
+ if (getu) return (this->*getu)(unit);
+ if (unit != "") throwError("Can't get this property with unit");
+ return get(p);
+ }
+
if (unit != "")
throwError("Can't set this property with unit (not a double)");
@@ -271,7 +291,8 @@ void Object::setParameter(Property const &p, string const &name,
break;
case Property::vector_double_t:
val = FactoryMessenger::parseArray(content);
- break;
+ set(p, val, unit);
+ return;
case Property::metric_t:
throwError("Metric can't be set using setParameter()");
default:
diff --git a/lib/Property.C b/lib/Property.C
index eed42c2..d005008 100644
--- a/lib/Property.C
+++ b/lib/Property.C
@@ -55,6 +55,20 @@ Property::Property(string n,
: name(n), type(vector_double_t), parent(NULL) {
setter.set_vdouble=set;
getter.get_vdouble=get;
+ setter_unit.set_vdouble=NULL;
+ getter_unit.get_vdouble=NULL;
+}
+
+Property::Property(string n,
+ set_vector_double_t set,
+ get_vector_double_t get,
+ set_vector_double_unit_t setu,
+ get_vector_double_unit_t getu)
+ : name(n), type(vector_double_t), parent(NULL) {
+ setter.set_vdouble=set;
+ getter.get_vdouble=get;
+ setter_unit.set_vdouble=setu;
+ getter_unit.get_vdouble=getu;
}
Property::Property(string n,
diff --git a/lib/Spectrometer.C b/lib/Spectrometer.C
index 819f945..74ae305 100644
--- a/lib/Spectrometer.C
+++ b/lib/Spectrometer.C
@@ -36,6 +36,18 @@ using namespace Gyoto;
using namespace Gyoto::Spectrometer;
using namespace std;
+/// Properties
+
+// There is no generic properties for spectrometers. Nevertheless, we
+// define this to derived classes can point to
+// Spectrometer::Generic::properties rather than Object::properties
+
+#include "GyotoProperty.h"
+GYOTO_PROPERTY_START(Spectrometer::Generic)
+GYOTO_PROPERTY_END(Spectrometer::Generic, Object::properties)
+
+///
+
Register::Entry* Gyoto::Spectrometer::Register_ = NULL;
void Spectrometer::initRegister() {
if (Gyoto::Spectrometer::Register_) delete Gyoto::Spectrometer::Register_;
@@ -61,21 +73,11 @@ Spectrometer::getSubcontractor(std::string name, int errmode) {
-> getSubcontractor(name, errmode);
}
-#if defined GYOTO_USE_XERCES
-void Spectrometer::Generic::setParameters(Gyoto::FactoryMessenger *fmp) {
- string name="", content="", unit="";
- if (fmp)
- while (fmp->getNextParameter(&name, &content, &unit))
- setParameter(name, content, unit);
-}
-#endif
-
-
-
Generic::Generic() :
SmartPointee(),
Teller(),
- kind_(NULL),
+ Object(),
+ kindid_(NULL),
nsamples_(0),
nboundaries_(0),
boundaries_(NULL),
@@ -87,7 +89,8 @@ Generic::Generic() :
Generic::Generic(kind_t kin) :
SmartPointee(),
Teller(),
- kind_(kin),
+ Object(kin),
+ kindid_(kin),
nsamples_(0),
nboundaries_(0),
boundaries_(NULL),
@@ -99,7 +102,8 @@ Generic::Generic(kind_t kin) :
Generic::Generic(const Generic& o) :
SmartPointee(o),
Teller(o),
- kind_(o.kind_),
+ Object(o),
+ kindid_(o.kindid_),
nsamples_(o.nsamples_),
nboundaries_(o.nboundaries_),
boundaries_(NULL),
@@ -123,8 +127,8 @@ Generic::~Generic() {
if (chanind_) delete [] chanind_;
}
-char const * Generic::kind() const {return kind_;}
-void Generic::kind(char const * k) {kind_=k; tellListeners();}
+char const * Generic::kindid() const {return kindid_;}
+void Generic::kindid(char const * k) {kindid_=k; kind_=k; tellListeners();}
size_t Generic::nSamples() const { return nsamples_; }
size_t Generic::getNBoundaries() const { return nboundaries_; }
@@ -148,18 +152,3 @@ void Generic::getWidths( double data[], std::string unit) {
data[i]=fabs(cbound[chanind_[2*i+1]]-cbound[chanind_[2*i]]);
delete [] cbound;
}
-
-int Spectrometer::Generic::setParameter(string /* name */,
- string /* content */,
- string /* unit */)
-{
- // nothing to do... yet
- return 1;
-}
-
-#ifdef GYOTO_USE_XERCES
-
-void Generic::fillElement(FactoryMessenger *fmp) const {
- fmp -> setSelfAttribute( "kind", kind() );
-}
-#endif
diff --git a/lib/Spectrum.C b/lib/Spectrum.C
index b0205e3..7841575 100644
--- a/lib/Spectrum.C
+++ b/lib/Spectrum.C
@@ -39,7 +39,10 @@ GYOTO_PROPERTY_END(Spectrum::Generic, Object::properties)
///
-Spectrum::Generic::Generic(const string kin) : kind_(kin) {}
+Spectrum::Generic::Generic(const string kin)
+: SmartPointee(), Object(kin) {}
+Spectrum::Generic::Generic(const Generic& o)
+: SmartPointee(o), Object(o) {}
Spectrum::Generic * Spectrum::Generic::clone() const
{
string msg = "Spectrum::clone() called: "
diff --git a/lib/UniformSpectrometer.C b/lib/UniformSpectrometer.C
index f876385..861832d 100644
--- a/lib/UniformSpectrometer.C
+++ b/lib/UniformSpectrometer.C
@@ -34,6 +34,48 @@ using namespace Gyoto;
using namespace Gyoto::Spectrometer;
using namespace std;
+/// Properties
+
+#include "GyotoProperty.h"
+GYOTO_PROPERTY_START(Uniform)
+GYOTO_PROPERTY_VECTOR_DOUBLE_UNIT(Uniform, Band, band)
+GYOTO_PROPERTY_STRING(Uniform, Kind, kind)
+GYOTO_PROPERTY_SIZE_T(Uniform, NSamples, nSamples)
+GYOTO_PROPERTY_END(Uniform, Generic::properties)
+
+void Uniform::fillProperty(Gyoto::FactoryMessenger *fmp,
+ Property const &p) const {
+ if (p.type == Property::unsigned_long_t && p.name == "NSamples")
+ fmp -> setSelfAttribute("nsamples", nsamples_);
+ else if (p.type == Property::string_t && p.name == "Kind")
+ ; // do nothing
+ else if (p.type == Property::vector_double_t && p.name == "Band") {
+ ostringstream ss;
+ ss << setprecision(GYOTO_PREC) << setw(GYOTO_WIDTH) << band_[0] << " "
+ << setprecision(GYOTO_PREC) << setw(GYOTO_WIDTH) << band_[1];
+ fmp -> setFullContent(ss.str());
+ } else throwError("Unsupported Property in Spectrometer::Uniform");
+}
+
+#ifdef GYOTO_USE_XERCES
+
+void Gyoto::Spectrometer::Uniform::setParameters(FactoryMessenger* fmp) {
+ string skind = fmp -> getSelfAttribute( "kind" );
+ size_t nsamples = atol( fmp -> getSelfAttribute( "nsamples" ) . c_str () );
+ string unit = fmp -> getSelfAttribute( "unit" );
+
+ string content = fmp -> getFullContent();
+ double band[2];
+ if (FactoryMessenger::parseArray(content, band, 2) != 2)
+ throwError("Spectromecter::Uniform requires exactly 2 tokens");
+
+ Uniform::band(band, unit, skind);
+ nSamples(nsamples);
+}
+#endif
+
+///
+
Uniform::Uniform() :
Generic(WaveKind)
{
@@ -72,7 +114,7 @@ void Uniform::reset_() {
midpoints_ = NULL;
widths_ = NULL;
GYOTO_DEBUG << endl;
- if (!nsamples_ || !kind_) return;
+ if (!nsamples_ || !kindid_) return;
boundaries_ = new double[nsamples_+1];
chanind_ = new size_t[nsamples_*2];
@@ -84,7 +126,7 @@ void Uniform::reset_() {
GYOTO_IF_DEBUG;
GYOTO_DEBUG_EXPR(band_);
if (band_) GYOTO_DEBUG_ARRAY(band_, 2);
- GYOTO_DEBUG_EXPR(kind_);
+ GYOTO_DEBUG_EXPR(kindid_);
GYOTO_ENDIF_DEBUG
# endif
for (i=0; i<=nsamples_; ++i){
@@ -92,11 +134,11 @@ void Uniform::reset_() {
GYOTO_DEBUG << "boundaries_[" <<i<<"]=";
# endif
boundaries_[i]=band_[0]+double(i)*(band_[1]-band_[0])/double(nsamples_);
- if (kind_==FreqLogKind ||
- kind_==WaveLogKind)
+ if (kindid_==FreqLogKind ||
+ kindid_==WaveLogKind)
boundaries_[i]=pow(10.,boundaries_[i]);
- if (kind_==WaveKind ||
- kind_==WaveLogKind)
+ if (kindid_==WaveKind ||
+ kindid_==WaveLogKind)
boundaries_[i]=boundaries_[i]?GYOTO_C/boundaries_[i]:DBL_MAX;
# if GYOTO_DEBUG_ENABLED
if (debug()) cerr << boundaries_[i]<< endl;
@@ -131,12 +173,14 @@ void Uniform::reset_() {
tellListeners();
}
-void Uniform::kind(kind_t k) {
- kind_ = k;
+void Uniform::kindid(kind_t k) {
+ kind_=k;
+ kindid_ = k;
reset_();
}
-void Uniform::kind(std::string str) {
+void Uniform::kind(std::string const &str) {
+ kind_ = str;
kind_t s;
if (str == "freq" ) s = FreqKind;
@@ -147,94 +191,103 @@ void Uniform::kind(std::string str) {
throwError("unknown Spectrometer::Uniform kind"); s=NULL;
}
- kind_ = s;
+ kindid_ = s;
reset_();
}
+std::string Uniform::kind() const {return Object::kind_;}
+
void Uniform::nSamples(size_t n) {
nsamples_ = n;
nboundaries_=nsamples_+1;
reset_();
}
-void Uniform::setBand(double nu[2]) {
+
+void Uniform::band(std::vector<double>const &vnu) {
+ if (vnu.size() != 2) throwError("Band needs exactly two elements");
+ double nu[] = {vnu[0], vnu[1]};
+ band(nu);
+}
+
+void Uniform::band(std::vector<double>const &vnu, std::string const &u) {
+ if (vnu.size() != 2) throwError("Band needs exactly two elements");
+ double nu[] = {vnu[0], vnu[1]};
+ band(nu, u);
+}
+
+std::vector<double> Uniform::band() const {
+ std::vector<double> vnu(2, band_[0]);
+ vnu[1]=band_[1];
+ return vnu;
+}
+
+std::vector<double> Uniform::band(std::string const &unit) const {
+ std::vector<double> vnu = band();
+
+ if (kindid_== FreqKind) {
+ if (unit != "" && unit != "Hz")
+ for (size_t i=0; i<=1; ++i)
+ vnu[i] = Units::FromHerz(vnu[i], unit);
+ } else if (kindid_== FreqLogKind) {
+ if (unit != "" && unit != "Hz")
+ for (size_t i=0; i<=1; ++i)
+ vnu[i] = pow(10., Units::FromHerz(log10(vnu[i]), unit));
+ } else if (kindid_== WaveKind) {
+ if (unit != "" && unit != "m")
+ for (size_t i=0; i<=1; ++i)
+ vnu[i] = Units::FromMeters(vnu[i], unit);
+ } else if (kindid_ == WaveLogKind) {
+ if (unit != "" && unit != "m")
+ for (size_t i=0; i<=1; ++i)
+ vnu[i] = pow(10., Units::FromMeters(log10(vnu[i]), unit));
+ } else {
+ throwError("Uniform::band(string const &unit) at loss: "
+ "please specify Spectrometer kind");
+ }
+
+ return vnu;
+}
+
+void Uniform::band(double nu[2]) {
band_[0] = nu[0];
band_[1] = nu[1];
reset_();
}
-void Uniform::setBand(double nu[2], string unit, string skind) {
+void Uniform::band(double nu[2], string const &unit, string const &skind) {
if (skind != "") kind(skind);
+ band(nu, unit);
+}
+
+void Uniform::band(double nu[2], string const &unit) {
double band[2] = {nu[0], nu[1]};
- if (kind_== FreqKind) {
+ if (kindid_== FreqKind) {
if (unit != "" && unit != "Hz")
for (size_t i=0; i<=1; ++i)
band[i] = Units::ToHerz(nu[i], unit);
- } else if (kind_== FreqLogKind) {
+ } else if (kindid_== FreqLogKind) {
if (unit != "" && unit != "Hz")
for (size_t i=0; i<=1; ++i)
band[i] = log10(Units::ToHerz(pow(10., nu[i]), unit));
- } else if (kind_== WaveKind) {
+ } else if (kindid_== WaveKind) {
if (unit != "" && unit != "m")
for (size_t i=0; i<=1; ++i)
band[i] = Units::ToMeters(nu[i], unit);
- } else if (kind_ == WaveLogKind) {
+ } else if (kindid_ == WaveLogKind) {
if (unit != "" && unit != "m")
for (size_t i=0; i<=1; ++i)
band[i] = log10(Units::ToMeters(pow(10., nu[i]), unit));
} else {
- throwError("Uniform::setBand(double, string, string) at loss: "
+ throwError("Uniform::band(double, string) at loss: "
"please specify Spectrometer kind");
}
- setBand(band);
-}
-
-double const * Uniform::getBand() const { return band_; }
-
-#ifdef GYOTO_USE_XERCES
-
-void Uniform::fillElement(FactoryMessenger *fmp) const {
- fmp -> setSelfAttribute( "nsamples", nsamples_ );
- ostringstream ss;
- ss << setprecision(GYOTO_PREC) << setw(GYOTO_WIDTH) << band_[0] << " "
- << setprecision(GYOTO_PREC) << setw(GYOTO_WIDTH) << band_[1];
- fmp -> setFullContent(ss.str());
- Generic::fillElement(fmp);
+ Uniform::band(band);
}
-void Gyoto::Spectrometer::Uniform::setParameters(FactoryMessenger* fmp) {
- string skind = fmp -> getSelfAttribute( "kind" );
- size_t nsamples = atol( fmp -> getSelfAttribute( "nsamples" ) . c_str () );
- string unit = fmp -> getSelfAttribute( "unit" );
-
- string content = fmp -> getFullContent();
- double band[2];
- if (FactoryMessenger::parseArray(content, band, 2) != 2)
- throwError("Spectromecter::Uniform requires exactly 2 tokens");
- setBand(band, unit, skind);
- nSamples(nsamples);
-}
-#endif
-
-int Spectrometer::Uniform::setParameter(string name,
- string content,
- string unit)
-{
- double band[2];
- char* tc = const_cast<char*>(content.c_str());
- if (name=="Band") {
- if (FactoryMessenger::parseArray(content, band, 2) != 2)
- throwError("Spectromecter::Uniform \"Band\" requires exactly 2 tokens");
- setBand(band, unit);
- } else if (name=="Kind") {
- kind(content);
- } else if (name=="NSamples") {
- nSamples(atoi(tc));
- } else return Generic::setParameter(name, content, unit);
- return 0;
-}
+double const * Uniform::getBand() const { return band_; }
char const * const Uniform::WaveKind = "wave";
char const * const Uniform::WaveLogKind = "wavelog";
diff --git a/yorick/gyoto_SpectroComplex.C b/yorick/gyoto_SpectroComplex.C
index cf59ba5..06faf89 100644
--- a/yorick/gyoto_SpectroComplex.C
+++ b/yorick/gyoto_SpectroComplex.C
@@ -87,7 +87,7 @@ extern "C" {
{
YGYOTO_CONSTRUCTOR_INIT2(Spectrometer, Spectrometer::Generic,
Complex, spectrometer);
- if ((*OBJ)->kind() != Complex::Kind)
+ if ((*OBJ)->kindid() != Complex::Kind)
y_error("Expecting Spectrometer of kind Complex");
YGyoto::SpCplxEval(OBJ, argc);
}
diff --git a/yorick/gyoto_SpectroUniform.C b/yorick/gyoto_SpectroUniform.C
index 1b32725..a14e559 100644
--- a/yorick/gyoto_SpectroUniform.C
+++ b/yorick/gyoto_SpectroUniform.C
@@ -59,7 +59,7 @@ YGyoto::SpectroUniformYEval(Gyoto::SmartPointer<Spectrometer::Generic>*sp_,
iarg+=*rvset;
if (yarg_nil(iarg)) { // get spectro kind
if ((*rvset)++) y_error(rmsg);
- *ypush_q(0) = p_strcpy((*sp) -> kind() );
+ *ypush_q(0) = p_strcpy((*sp) -> kindid() );
} else { // set spectro kind
(*sp) -> kind(std::string(ygets_q(iarg)));
}
@@ -82,7 +82,7 @@ YGyoto::SpectroUniformYEval(Gyoto::SmartPointer<Spectrometer::Generic>*sp_,
boundaries = ygeta_d(iarg, &ntot, NULL);
if (ntot != 2)
y_error("BAND must have 2 elements");
- (*sp) -> setBand(boundaries, unit?unit:"");
+ (*sp) -> band(boundaries, unit?unit:"");
}
}
@@ -160,7 +160,7 @@ extern "C" {
{
YGYOTO_CONSTRUCTOR_INIT2(Spectrometer, Spectrometer::Generic,
Uniform, spectrometer);
- kind_t kind=(*sp)->kind();
+ kind_t kind=(*sp)->kindid();
if (kind != Uniform::WaveKind &&
kind != Uniform::WaveLogKind &&
kind != Uniform::FreqKind &&
diff --git a/yorick/gyoto_Spectrometer.C b/yorick/gyoto_Spectrometer.C
index 9e53f7e..9404308 100644
--- a/yorick/gyoto_Spectrometer.C
+++ b/yorick/gyoto_Spectrometer.C
@@ -50,7 +50,7 @@ extern "C" {
// Try calling kind-specific worker
int n=0;
- char const * const kind = (*OBJ_)->kind();
+ char const * const kind = (*OBJ_)->kindid();
while (n<ygyoto_Spectrometer_count &&
kind != ygyoto_Spectrometer_names[n]) ++n;
@@ -105,7 +105,7 @@ void ygyoto_Spectrometer_generic_eval(SmartPointer<Spectrometer::Generic>*OBJ,
if ((*rvset)++) y_error(rmsg);
if (!yarg_nil(iarg)) y_error("KIND is readonly");
char ** kind = ypush_q(0);
- *kind = p_strcpy((*OBJ)->kind());
+ *kind = p_strcpy((*OBJ)->kindid());
}
// Process SET keywords
diff --git a/yorick/gyoto_utils.C b/yorick/gyoto_utils.C
index a6674de..14813d5 100644
--- a/yorick/gyoto_utils.C
+++ b/yorick/gyoto_utils.C
@@ -376,7 +376,8 @@ void ypush_property(Gyoto::SmartPointer<Gyoto::SmartPointee> ptr,
if (!object)
Gyoto::throwError("dynamic_cast from SmartPointee* to Object* failed");
- if (p.type == Gyoto::Property::double_t)
+ if (p.type == Gyoto::Property::double_t ||
+ p.type == Gyoto::Property::vector_double_t)
val = object -> get(p, unit);
else
val = object -> get(p);
@@ -462,9 +463,9 @@ void yget_property(Gyoto::SmartPointer<Gyoto::SmartPointee> ptr,
double *buf = ygeta_d(iarg, &n, NULL);
std::vector<double> vval(n, 0.);
for (size_t i=0; i<n; ++i) vval[i]=buf[i];
- val = vval;
+ object->set(p, vval, unit);
}
- break;
+ return;
case Gyoto::Property::metric_t:
val = *yget_Metric(iarg);
break;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-astro/packages/gyoto.git
More information about the Debian-astro-commits
mailing list