source: branches/casa-release-4_3-test/external-alma/components/SpectralComponents/SpectralElement2.cc@ 3026

Last change on this file since 3026 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.4 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: SpectralElement2.cc 21451 2014-06-10 07:48:08Z gervandiepen $
27
28#include <components/SpectralComponents/CompiledSpectralElement.h>
29#include <components/SpectralComponents/GaussianSpectralElement.h>
30#include <components/SpectralComponents/GaussianMultipletSpectralElement.h>
31#include <components/SpectralComponents/LorentzianSpectralElement.h>
32#include <components/SpectralComponents/PolynomialSpectralElement.h>
33#include <components/SpectralComponents/PowerLogPolynomialSpectralElement.h>
34
35#include <casa/iostream.h>
36
37namespace casa { //# NAMESPACE CASA - BEGIN
38
39ostream &operator<<(ostream &os, const SpectralElement &elem) {
40 switch (elem.getType()) {
41 case SpectralElement::GAUSSIAN:
42 os << *dynamic_cast<const GaussianSpectralElement*>(&elem);
43 break;
44 case SpectralElement::POLYNOMIAL:
45 os << *dynamic_cast<const PolynomialSpectralElement*>(&elem);
46 break;
47 case SpectralElement::COMPILED:
48 case SpectralElement::POWERLOGPOLY:
49 case SpectralElement::LOGTRANSPOLY:
50 os << *dynamic_cast<const CompiledSpectralElement*>(&elem);
51 break;
52 case SpectralElement::GMULTIPLET:
53 os << *dynamic_cast<const GaussianMultipletSpectralElement*>(&elem);
54 break;
55 case SpectralElement::LORENTZIAN:
56 os << *dynamic_cast<const LorentzianSpectralElement*>(&elem);
57 break;
58 default:
59 throw AipsError("SpectralElement2::<<((): Logic Error. Unhandled spectral element type");
60 }
61 return os;
62}
63
64Bool near(const SpectralElement& s1, const SpectralElement& s2, const Double tol) {
65 if (s1.getType() != s2.getType()) {
66 return False;
67 }
68 for (uInt j=0; j<s1.get().size(); j++) {
69 if (! near(s1.get()[j], s2.get()[j], tol)) {
70 return False;
71 }
72 if (! near(s1.getError()[j], s2.getError()[j], tol)) {
73 return False;
74 }
75 if (s1.fixed()[j] != s2.fixed()[j]) {
76 return False;
77 }
78 }
79 return True;
80}
81
82Bool nearAbs(const SpectralElement& s1, const SpectralElement& s2, const Double tol) {
83 if (s1.getType() != s2.getType()) {
84 return False;
85 }
86 for (uInt j=0; j<s1.get().size(); j++) {
87 if (! nearAbs(s1.get()[j], s2.get()[j], tol)) {
88 return False;
89 }
90 if (! nearAbs(s1.getError()[j], s2.getError()[j], tol)) {
91 return False;
92 }
93 if (s1.fixed()[j] != s2.fixed()[j]) {
94 return False;
95 }
96 }
97 return True;
98}
99
100
101
102} //# NAMESPACE CASA - END
103
104
Note: See TracBrowser for help on using the repository browser.