LCOV - code coverage report
Current view: top level - components/SpectralComponents - PowerLogPolynomialSpectralElement.cc (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 11 33 33.3 %
Date: 2023-11-06 10:06:49 Functions: 5 7 71.4 %

          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             : #include <components/SpectralComponents/PowerLogPolynomialSpectralElement.h>
      29             : 
      30             : #include <casacore/scimath/Functionals/PowerLogarithmicPolynomial.h>
      31             : 
      32             : #include <iostream>
      33             : 
      34             : #define _ORIGIN  String("PowerLogPolynomialSpectralElement::") + __FUNCTION__ + ":" + String::toString(__LINE__) + ": "
      35             : 
      36             : 
      37             : using namespace casacore;
      38             : namespace casa { //# NAMESPACE CASA - BEGIN
      39             : 
      40             : /*
      41             : PowerLogPolynomialSpectralElement::PowerLogPolynomialSpectralElement(
      42             :         uInt n
      43             : ) : SpectralElement(SpectralElement::POWERLOGPOLY, n) {
      44             :         if (n == 0) {
      45             :                 throw AipsError(_ORIGIN + "n must be greater than zero.");
      46             :         }
      47             :         //_makeFunction();
      48             :         _setFunction(
      49             :                 std::shared_ptr<PowerLogarithmicPolynomial<Double> >(
      50             :                         new PowerLogarithmicPolynomial(n)
      51             :                 )
      52             :         );
      53             : }
      54             : */
      55          11 : PowerLogPolynomialSpectralElement::PowerLogPolynomialSpectralElement(
      56             :         const Vector<Double>& param
      57          11 : ) : SpectralElement(SpectralElement::POWERLOGPOLY, param) {
      58             :         //_makeFunction();
      59          11 :         _setFunction(
      60          22 :                 std::shared_ptr<PowerLogarithmicPolynomial<Double> >(
      61          22 :                         new PowerLogarithmicPolynomial<Double>(param.tovector())
      62             :                 )
      63             :         );
      64          11 : }
      65             : 
      66             : /*
      67             : void PowerLogPolynomialSpectralElement::_makeFunction() {
      68             :         ostringstream function;
      69             :         function << "p0";
      70             :         uInt n = get().size();
      71             :         for (uInt i=1; i<n; i++) {
      72             :                 if (i == 1) {
      73             :                         function << "*(x)^(p1";
      74             :                 }
      75             :                 else {
      76             :                         function << " + p" << i << "*ln(x)";
      77             :                         if (i > 2) {
      78             :                                 function << "^" << (i-1);
      79             :                         }
      80             :                 }
      81             :                 if (i == n-1) {
      82             :                         function << ")";
      83             :                 }
      84             :         }
      85             :         _setFunction(function.str());
      86             : }
      87             : */
      88             : 
      89        3032 : PowerLogPolynomialSpectralElement::PowerLogPolynomialSpectralElement(
      90             :         const PowerLogPolynomialSpectralElement &other
      91        3032 : ) : SpectralElement(other) {}
      92             : 
      93        6075 : PowerLogPolynomialSpectralElement::~PowerLogPolynomialSpectralElement() {}
      94             : 
      95           0 : PowerLogPolynomialSpectralElement& PowerLogPolynomialSpectralElement::operator=(
      96             :         const PowerLogPolynomialSpectralElement& other
      97             : ) {
      98           0 :         if (this != &other) {
      99           0 :                 SpectralElement::operator=(other);
     100             :         }
     101           0 :         return *this;
     102             : }
     103             : 
     104        3032 : SpectralElement* PowerLogPolynomialSpectralElement::clone() const {
     105        3032 :         return new PowerLogPolynomialSpectralElement(*this);
     106             : }
     107             : 
     108           0 : ostream &operator<<(ostream& os, const PowerLogPolynomialSpectralElement& elem) {
     109           0 :         os << SpectralElement::fromType((elem.getType())) << " element: " << endl;
     110           0 :         ostringstream function;
     111           0 :         function << "p0";
     112           0 :         uInt n = elem.get().size();
     113           0 :         for (uInt i=1; i<n; i++) {
     114           0 :                 if (i == 1) {
     115           0 :                         function << "*(x)^(p1";
     116             :                 }
     117             :                 else {
     118           0 :                         function << " + p" << i << "*ln(x)";
     119           0 :                         if (i > 2) {
     120           0 :                                 function << "^" << (i-1);
     121             :                         }
     122             :                 }
     123           0 :                 if (i == n-1) {
     124           0 :                         function << ")";
     125             :                 }
     126             :         }
     127           0 :         os << "  Function:    " << function.str() << endl;
     128           0 :         const Vector<Double> p = elem.get();
     129           0 :         for (uInt i=0; i<p.size(); i++) {
     130           0 :                 os << "p" << i << ": " << p[i] << endl;
     131             :         }
     132           0 :         return os;
     133             : }
     134             : 
     135             : 
     136             : } //# NAMESPACE CASA - END
     137             : 

Generated by: LCOV version 1.16