[2980] | 1 | //# SpectralElement.cc: Describes (a set of related) spectral lines |
---|
| 2 | //# Copyright (C) 2001,2004 |
---|
| 3 | //# Associated Universities, Inc. Washington DC, USA. |
---|
| 4 | //# |
---|
| 5 | //# This library is free software; you can redistribute it and/or modify it |
---|
| 6 | //# under the terms of the GNU Library General Public License as published by |
---|
| 7 | //# the Free Software Foundation; either version 2 of the License, or (at your |
---|
| 8 | //# option) any later version. |
---|
| 9 | //# |
---|
| 10 | //# This library is distributed in the hope that it will be useful, but WITHOUT |
---|
| 11 | //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 12 | //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
---|
| 13 | //# License for more details. |
---|
| 14 | //# |
---|
| 15 | //# You should have received a copy of the GNU Library General Public License |
---|
| 16 | //# along with this library; if not, write to the Free Software Foundation, |
---|
| 17 | //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. |
---|
| 18 | //# |
---|
| 19 | //# Correspondence concerning AIPS++ should be addressed as follows: |
---|
| 20 | //# Internet email: aips2-request@nrao.edu. |
---|
| 21 | //# Postal address: AIPS++ Project Office |
---|
| 22 | //# National Radio Astronomy Observatory |
---|
| 23 | //# 520 Edgemont Road |
---|
| 24 | //# Charlottesville, VA 22903-2475 USA |
---|
| 25 | //# |
---|
| 26 | //# $Id: SpectralElement.cc 21024 2011-03-01 11:46:18Z gervandiepen $ |
---|
| 27 | |
---|
| 28 | #include <components/SpectralComponents/PowerLogPolynomialSpectralElement.h> |
---|
| 29 | |
---|
| 30 | #include <scimath/Functionals/PowerLogarithmicPolynomial.h> |
---|
| 31 | |
---|
| 32 | #include <casa/iostream.h> |
---|
| 33 | |
---|
| 34 | #define _ORIGIN String("PowerLogPolynomialSpectralElement::") + __FUNCTION__ + ":" + String::toString(__LINE__) + ": " |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | namespace casa { //# NAMESPACE CASA - BEGIN |
---|
| 38 | |
---|
| 39 | /* |
---|
| 40 | PowerLogPolynomialSpectralElement::PowerLogPolynomialSpectralElement( |
---|
| 41 | uInt n |
---|
| 42 | ) : SpectralElement(SpectralElement::POWERLOGPOLY, n) { |
---|
| 43 | if (n == 0) { |
---|
| 44 | throw AipsError(_ORIGIN + "n must be greater than zero."); |
---|
| 45 | } |
---|
| 46 | //_makeFunction(); |
---|
| 47 | _setFunction( |
---|
| 48 | std::tr1::shared_ptr<PowerLogarithmicPolynomial<Double> >( |
---|
| 49 | new PowerLogarithmicPolynomial(n) |
---|
| 50 | ) |
---|
| 51 | ); |
---|
| 52 | } |
---|
| 53 | */ |
---|
| 54 | PowerLogPolynomialSpectralElement::PowerLogPolynomialSpectralElement( |
---|
| 55 | const Vector<Double>& param |
---|
| 56 | ) : SpectralElement(SpectralElement::POWERLOGPOLY, param) { |
---|
| 57 | //_makeFunction(); |
---|
| 58 | _setFunction( |
---|
| 59 | std::tr1::shared_ptr<PowerLogarithmicPolynomial<Double> >( |
---|
| 60 | new PowerLogarithmicPolynomial<Double>(param.tovector()) |
---|
| 61 | ) |
---|
| 62 | ); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /* |
---|
| 66 | void PowerLogPolynomialSpectralElement::_makeFunction() { |
---|
| 67 | ostringstream function; |
---|
| 68 | function << "p0"; |
---|
| 69 | uInt n = get().size(); |
---|
| 70 | for (uInt i=1; i<n; i++) { |
---|
| 71 | if (i == 1) { |
---|
| 72 | function << "*(x)^(p1"; |
---|
| 73 | } |
---|
| 74 | else { |
---|
| 75 | function << " + p" << i << "*ln(x)"; |
---|
| 76 | if (i > 2) { |
---|
| 77 | function << "^" << (i-1); |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | if (i == n-1) { |
---|
| 81 | function << ")"; |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | _setFunction(function.str()); |
---|
| 85 | } |
---|
| 86 | */ |
---|
| 87 | |
---|
| 88 | PowerLogPolynomialSpectralElement::PowerLogPolynomialSpectralElement( |
---|
| 89 | const PowerLogPolynomialSpectralElement &other |
---|
| 90 | ) : SpectralElement(other) {} |
---|
| 91 | |
---|
| 92 | PowerLogPolynomialSpectralElement::~PowerLogPolynomialSpectralElement() {} |
---|
| 93 | |
---|
| 94 | PowerLogPolynomialSpectralElement& PowerLogPolynomialSpectralElement::operator=( |
---|
| 95 | const PowerLogPolynomialSpectralElement& other |
---|
| 96 | ) { |
---|
| 97 | if (this != &other) { |
---|
| 98 | SpectralElement::operator=(other); |
---|
| 99 | } |
---|
| 100 | return *this; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | SpectralElement* PowerLogPolynomialSpectralElement::clone() const { |
---|
| 104 | return new PowerLogPolynomialSpectralElement(*this); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | ostream &operator<<(ostream& os, const PowerLogPolynomialSpectralElement& elem) { |
---|
| 108 | os << SpectralElement::fromType((elem.getType())) << " element: " << endl; |
---|
| 109 | ostringstream function; |
---|
| 110 | function << "p0"; |
---|
| 111 | uInt n = elem.get().size(); |
---|
| 112 | for (uInt i=1; i<n; i++) { |
---|
| 113 | if (i == 1) { |
---|
| 114 | function << "*(x)^(p1"; |
---|
| 115 | } |
---|
| 116 | else { |
---|
| 117 | function << " + p" << i << "*ln(x)"; |
---|
| 118 | if (i > 2) { |
---|
| 119 | function << "^" << (i-1); |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | if (i == n-1) { |
---|
| 123 | function << ")"; |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | os << " Function: " << function.str() << endl; |
---|
| 127 | const Vector<Double> p = elem.get(); |
---|
| 128 | for (uInt i=0; i<p.size(); i++) { |
---|
| 129 | os << "p" << i << ": " << p[i] << endl; |
---|
| 130 | } |
---|
| 131 | return os; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | } //# NAMESPACE CASA - END |
---|
| 136 | |
---|