Line data Source code
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 : //# Includes 29 : #include <components/SpectralComponents/PolynomialSpectralElement.h> 30 : 31 : #include <casacore/scimath/Functionals/Polynomial.h> 32 : 33 : #include <iostream> 34 : 35 : using namespace casacore; 36 : namespace casa { //# NAMESPACE CASA - BEGIN 37 : 38 0 : PolynomialSpectralElement::PolynomialSpectralElement() 39 0 : : SpectralElement(SpectralElement::POLYNOMIAL, Vector<Double>(0)) { 40 0 : _setFunction( 41 0 : std::shared_ptr<Polynomial<Double> >( 42 0 : new Polynomial<Double>() 43 : ) 44 : ); 45 0 : } 46 : 47 0 : PolynomialSpectralElement::PolynomialSpectralElement(const uInt n) 48 0 : : SpectralElement(SpectralElement::POLYNOMIAL, Vector<Double>(n+1)) { 49 0 : _setFunction( 50 0 : std::shared_ptr<Polynomial<Double> >( 51 0 : new Polynomial<Double>(n) 52 : ) 53 : ); 54 0 : } 55 : 56 0 : PolynomialSpectralElement::PolynomialSpectralElement(const Vector<Double>& param) 57 0 : : SpectralElement(SpectralElement::POLYNOMIAL, param) { 58 0 : _setFunction( 59 0 : std::shared_ptr<Polynomial<Double> >( 60 0 : new Polynomial<Double>(param.size()) 61 : ) 62 : ); 63 0 : _set(param); 64 0 : fix(Vector<Bool>(param.size(), false)); 65 0 : } 66 : 67 0 : PolynomialSpectralElement::PolynomialSpectralElement( 68 : const PolynomialSpectralElement &other 69 0 : ) : SpectralElement(other) {} 70 : 71 0 : PolynomialSpectralElement::~PolynomialSpectralElement() {} 72 : 73 0 : SpectralElement* PolynomialSpectralElement::clone() const { 74 0 : return new PolynomialSpectralElement(*this); 75 : } 76 : 77 : /* 78 : Double PolynomialSpectralElement::operator()(const Double x) const { 79 : Double s = 0; 80 : Vector<Double> p = get(); 81 : for (uInt i=0; i<p.size(); i++) { 82 : Double prod = 1; 83 : for (uInt j=0; j<i; j++) { 84 : prod *= x; 85 : } 86 : s += p[i]*prod; 87 : } 88 : return s; 89 : } 90 : */ 91 : 92 0 : uInt PolynomialSpectralElement::getDegree() const { 93 0 : return get().size() - 1; 94 : } 95 : 96 0 : ostream &operator<<(ostream &os, const PolynomialSpectralElement &elem) { 97 0 : os << SpectralElement::fromType((elem.getType())) << " element: " << endl; 98 0 : uInt degree = elem.getDegree(); 99 0 : os << " Degree: " << degree << endl; 100 0 : os << " Function: c0 "; 101 0 : ostringstream ss; 102 0 : Vector<Double> c = elem.get(); 103 0 : ss << "c0: " << c[0] << endl; 104 0 : for (uInt i=1; i<=degree; i++) { 105 0 : os << " + c" << i << "*x"; 106 0 : if (i > 1) { 107 0 : os << "**" << i; 108 : } 109 0 : ss << "c" << i << ": " << c[i] << endl; 110 : } 111 0 : os << endl; 112 0 : os << ss.str(); 113 : 114 : 115 0 : return os; 116 : } 117 : 118 : } //# NAMESPACE CASA - END 119 :