Line data Source code
1 : /******************************************************************************* 2 : * ALMA - Atacama Large Millimiter Array 3 : * (c) Instituto de Estructura de la Materia, 2009 4 : * 5 : * This library is free software; you can redistribute it and/or 6 : * modify it under the terms of the GNU Lesser General Public 7 : * License as published by the Free Software Foundation; either 8 : * version 2.1 of the License, or (at your option) any later version. 9 : * 10 : * This library is distributed in the hope that it will be useful, 11 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 : * Lesser General Public License for more details. 14 : * 15 : * You should have received a copy of the GNU Lesser General Public 16 : * License along with this library; if not, write to the Free Software 17 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 : * 19 : * "@(#) $Id: ATMMassDensity.cpp Exp $" 20 : * 21 : * who when what 22 : * -------- -------- ---------------------------------------------- 23 : * pardo 24/03/09 created 24 : */ 25 : 26 : #include "ATMMassDensity.h" 27 : 28 : ATM_NAMESPACE_BEGIN 29 : 30 0 : MassDensity::MassDensity() : 31 0 : valueIS_(0.0) 32 : { 33 0 : } 34 : 35 0 : MassDensity::MassDensity(double massdensity) : 36 0 : valueIS_(massdensity) 37 : { 38 0 : } 39 : 40 0 : MassDensity::MassDensity(double massdensity, const std::string &units) 41 : { 42 0 : if(units == "gcm**-3" || units == "g cm**-3" || units == "GCM**-3" || 43 0 : units == "G CM**-3" || units == "g/cm^3") { 44 0 : valueIS_ = 1.0E+3 * massdensity; 45 0 : } else if(units == "gm**-3" || units == "g m**-3" || units == "GM**-3" || 46 0 : units == "G M**-3" || units == "g/m^3") { 47 0 : valueIS_ = 1.0E-3 * massdensity; 48 0 : } else if(units == "kgm**-3" || units == "kg m**-3" || units == "KGM**-3" || 49 0 : units == "KG M**-3" || units == "kg/m^3") { 50 0 : valueIS_ = massdensity; 51 : } else { 52 : // Exception: unknown number density unit. S.I. unit (kg m**-3) used by default. 53 0 : valueIS_ = massdensity; 54 : } 55 0 : } 56 : 57 215 : MassDensity::MassDensity(double massdensity, MassDensity::Units units) 58 : { 59 215 : if(units == MassDensity::UnitGramPerCubicCentiMeter) { 60 0 : valueIS_ = 1.0E+3 * massdensity; 61 215 : } else if(units == MassDensity::UnitGramPerCubicMeter) { 62 125 : valueIS_ = 1.0E-3 * massdensity; 63 90 : } else if(units == MassDensity::UnitKiloGramPerCubicMeter) { 64 90 : valueIS_ = massdensity; 65 : } else { 66 : // Exception: unknown number density unit. S.I. unit (kg m**-3) used by default. 67 0 : valueIS_ = massdensity; 68 : } 69 215 : } 70 : 71 215 : MassDensity::~MassDensity() { }; 72 : 73 : 74 90 : double MassDensity::get(const std::string &units) const 75 : { 76 270 : if(units == "gcm**-3" || units == "g cm**-3" || units == "GCM**-3" || 77 270 : units == "G CM**-3" || units == "g/cm^3") { 78 0 : return 1.0E-3 * valueIS_; 79 270 : } else if(units == "gm**-3" || units == "g m**-3" || units == "GM**-3" || 80 270 : units == "G M**-3" || units == "g/m^3") { 81 0 : return 1.0E+3 * valueIS_; 82 90 : } else if(units == "kgm**-3" || units == "kg m**-3" || units == "KGM**-3" || 83 90 : units == "KG M**-3" || units == "kg/m^3") { 84 90 : return valueIS_; 85 : } else { 86 : // Exception: unknown number density unit. S.I. unit (kg m**-3) used by default. 87 0 : return valueIS_; 88 : } 89 : } 90 : 91 125 : double MassDensity::get(MassDensity::Units units) const 92 : { 93 125 : if(units == MassDensity::UnitGramPerCubicCentiMeter) { 94 0 : return 1.0E-3 * valueIS_; 95 125 : } else if(units == MassDensity::UnitGramPerCubicMeter) { 96 125 : return 1.0E+3 * valueIS_; 97 0 : } else if(units == MassDensity::UnitKiloGramPerCubicMeter) { 98 0 : return valueIS_; 99 : } else { 100 : // Exception: unknown number density unit. S.I. unit (kg m**-3) used by default. 101 0 : return valueIS_; 102 : } 103 : } 104 : 105 : ATM_NAMESPACE_END