source: branches/casa-release-4_3-test02/external-alma/components/SpectralComponents/PolynomialSpectralElement.cc@ 3060

Last change on this file since 3060 was 2980, checked in by Malte Marquarding, 10 years ago

Add a copy of casacore/components/SpectralComponents to external-alma directory to prepare for its removal from casacore-trunk. DOn;t activate in SConscript yet.

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