LCOV - code coverage report
Current view: top level - atmosphere/ATM - ATMOpacity.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 4 8 50.0 %
Date: 2024-10-09 13:55:54 Functions: 4 8 50.0 %

          Line data    Source code
       1             : #ifndef _ATM_OPACITY_H
       2             : #define _ATM_OPACITY_H
       3             : /*******************************************************************************
       4             :  * ALMA - Atacama Large Millimiter Array
       5             :  * (c) Instituto de Estructura de la Materia, 2009
       6             :  *
       7             :  * This library is free software; you can redistribute it and/or
       8             :  * modify it under the terms of the GNU Lesser General Public
       9             :  * License as published by the Free Software Foundation; either
      10             :  * version 2.1 of the License, or (at your option) any later version.
      11             :  *
      12             :  * This library is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :  * Lesser General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU Lesser General Public
      18             :  * License along with this library; if not, write to the Free Software
      19             :  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
      20             :  *
      21             :  * "@(#) $Id: ATMOpacity.h Exp $"
      22             :  *
      23             :  * who       when      what
      24             :  * --------  --------  ----------------------------------------------
      25             :  * pardo     24/03/09  created
      26             :  */
      27             : 
      28             : #ifndef __cplusplus
      29             : #error "This is a C++ include file and cannot be used from plain C"
      30             : #endif
      31             : 
      32             : #include "ATMCommon.h"
      33             : #include <string>
      34             : 
      35             : 
      36             : 
      37             : ATM_NAMESPACE_BEGIN
      38             : 
      39             : /*! \brief Class for opacities [no dimensions]
      40             :  *
      41             :  *   This class is defined for opacities.
      42             :  *   Default units are np (Transmission=exp(-opacity)).
      43             :  */
      44             : class Opacity
      45             : {
      46             : public:
      47             :   enum Units {
      48             :     UnitDeciBel,
      49             :     UnitNeper,
      50             :     NumOpacityUnits
      51             :   };
      52             : 
      53             :   /** Default constructor: Opacity value set to 0 np */
      54             :   Opacity();
      55             :   /** A full constructor: value in default units (np) */
      56             :   Opacity(double opacity);
      57             :   /** A full constructor: value + units. Valid units are:  np [neper] [NP] [NEPER], db [DB]. */
      58             :   Opacity(double opacity, const std::string &units);
      59             :   Opacity(double opacity, Units units);
      60             :   /** Copy constructor */
      61             :   Opacity (const Opacity &opacity);
      62             : 
      63             :   /** Destructor */
      64             :   virtual ~Opacity();
      65             : 
      66             :   /** Accessor to get the numerical value of opacity (in np) */
      67          27 :   double get() const { return valueIS_; }
      68             :   /** Accessor to the opacity value in specified units. Implemented units are np [neper] [NP] [NEPER], db [DB].
      69             :    *  If none of these implemented units is given, the value in neper will be returned. */
      70          15 :   inline double get(const std::string &units) const { return sget(valueIS_, units); }
      71           0 :   inline double get(Units units) const { return sget(valueIS_, units); }
      72             : 
      73             :   /** Operator "equal to a Opacity" */
      74           0 :   inline Opacity& operator=(const Opacity &rhs) { if(&rhs != this) valueIS_ = rhs.valueIS_; return *this; }
      75             :   /** Operator "equal to a double converted to Opacity in m" */
      76             :   inline Opacity& operator=(const double &rhs) { valueIS_ = rhs; return *this; }
      77             :   /** Operator "addition of opacities" */
      78          16 :   inline Opacity operator+(const Opacity &rhs) { return Opacity(valueIS_ + rhs.get()); }
      79             :   /** Operator "substraction of opacities" */
      80           0 :   inline Opacity operator-(const Opacity &rhs) { return Opacity(valueIS_ - rhs.get()); }
      81             :   /** Operator "multiplication of an opacity by a double" */
      82           1 :   inline Opacity operator*(double scf) { return Opacity(valueIS_ * scf); }
      83             :   /** Operator "multiplication of an opacity by a float" */
      84             :   inline Opacity operator*(float scf) { return Opacity(valueIS_ * (double) scf); }
      85             :   /** Operator "multiplication of an opacity by an int" */
      86             :   inline Opacity operator*(int scf) { return Opacity(valueIS_ * (double) scf); }
      87             :   /** Operator "multiplication of an opacity by an unsigned int" */
      88             :   inline Opacity operator*(unsigned int scf) { return Opacity(valueIS_ * (double) scf); }
      89             :   /** Operator "division of a opacity by an int" */
      90             :   inline Opacity operator/(double scf) { return Opacity(valueIS_ / scf); }
      91             :   /** Operator "division of a opacity by a float" */
      92             :   inline Opacity operator/(float scf) { return Opacity(valueIS_ / (double) scf); }
      93             :   /** Operator "division of a opacity by an int" */
      94             :   inline Opacity operator/(int scf) { return Opacity(valueIS_ / (double) scf); }
      95             :   /** Operator "division of a opacity by an unsigned int" */
      96           0 :   inline Opacity operator/(unsigned int scf) { return Opacity(valueIS_ / (double) scf); }
      97             :   /** Operator "comparator < for two opacities" */
      98             :   inline bool operator<(const Opacity &rhs) const { return (valueIS_ < rhs.get()); }
      99             :   /** Operator "comparator > for two opacities" */
     100             :   inline bool operator>(const Opacity &rhs) const { return (valueIS_ > rhs.get()); }
     101             :   /** Operator "comparator <= for two opacities" */
     102             :   inline bool operator<=(const Opacity &rhs) const { return (valueIS_ <= rhs.get()); }
     103             :   /** Operator "comparator >= for two opacities" */
     104             :   inline bool operator>=(const Opacity &rhs) const { return (valueIS_ >= rhs.get()); }
     105             :   /** Operator "comparator == for two opacities" */
     106             :   inline bool operator==(const Opacity &rhs) const { return (valueIS_ == rhs.get()); }
     107             :   /** Operator "comparator != for two opacities" */
     108             :   inline bool operator!=(const Opacity &rhs) const { return (valueIS_ != rhs.get()); }
     109             : 
     110             : private:
     111             :   static double sget(double value, const std::string &units);
     112             :   static double sput(double value, const std::string &units);
     113             :   static double sget(double value, Units units);
     114             :   static double sput(double value, Units units);
     115             : 
     116             : private:
     117             :   double valueIS_;
     118             : }; // class Opacity
     119             : 
     120             : ATM_NAMESPACE_END
     121             : 
     122             : #endif /*!_ATM_OPACITY_H*/

Generated by: LCOV version 1.16