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: ATMTemperature.cpp Exp $" 20 : * 21 : * who when what 22 : * -------- -------- ---------------------------------------------- 23 : * pardo 24/03/09 created 24 : */ 25 : 26 : #include "ATMTemperature.h" 27 : #include "ATMCommon.h" 28 : 29 : ATM_NAMESPACE_BEGIN 30 : 31 13818 : Temperature::Temperature() : 32 13818 : valueIS_(0.0) 33 : { 34 13818 : } 35 : 36 15770246 : Temperature::Temperature(double temperature) : 37 15770246 : valueIS_(temperature) 38 : { 39 15770246 : } 40 : 41 10 : Temperature::Temperature(double temperature, const string &units) 42 : { 43 10 : if(units == "mK" || units == "mk") { 44 0 : valueIS_ = 1.0E-3 * temperature; 45 10 : } else if(units == "K" || units == "k") { 46 10 : valueIS_ = temperature; 47 0 : } else if(units == "C" || units == "c") { 48 0 : valueIS_ = temperature + 273.16; 49 0 : } else if(units == "F" || units == "f") { 50 0 : valueIS_ = (temperature-32.0)*(5./9.)+273.16; 51 : } else { 52 : // Exception: Unknown temperature unit. S.I. used (Kelvin) 53 0 : valueIS_ = temperature; 54 : } 55 10 : } 56 : 57 458969944 : Temperature::Temperature(double temperature, const Temperature::Units units) 58 : { 59 458969944 : if(units == Temperature::UnitMilliKelvin) { 60 0 : valueIS_ = 1.0E-3 * temperature; 61 458969944 : } else if(units == Temperature::UnitKelvin) { 62 458969944 : valueIS_ = temperature; 63 0 : } else if(units == Temperature::UnitCelsius) { 64 0 : valueIS_ = temperature + 273.16; 65 0 : } else if(units == Temperature::UnitFahrenheit) { 66 0 : valueIS_ = (temperature-32.0)*(5./9.)+273.16; 67 : } else { 68 : // Exception: Unknown temperature unit. S.I. used (Kelvin) 69 0 : valueIS_ = temperature; 70 : } 71 458969944 : } 72 : 73 134590 : double Temperature::get(const string &units) const 74 : { 75 134590 : if(units == "mK") { 76 0 : return 1.0E3 * valueIS_; 77 134590 : } else if(units == "K") { 78 134590 : return valueIS_; 79 0 : } else if(units == "C" || units == "c") { 80 0 : return valueIS_ - 273.16; 81 0 : } else if(units == "F" || units == "f") { 82 0 : return (valueIS_ - 273.16)*(9./5.)+32.0; 83 : } else { 84 : // Exception: Unknown temperature unit. S.I. used (Kelvin) 85 0 : return valueIS_; 86 : } 87 : } 88 : 89 78666259 : double Temperature::get(Temperature::Units units) const 90 : { 91 78666259 : if(units == Temperature::UnitMilliKelvin) { 92 0 : return 1.0E3 * valueIS_; 93 78666259 : } else if(units == Temperature::UnitKelvin) { 94 78666259 : return valueIS_; 95 0 : } else if(units == Temperature::UnitCelsius) { 96 0 : return valueIS_ - 273.16; 97 0 : } else if(units == Temperature::UnitFahrenheit) { 98 0 : return (valueIS_ - 273.16)*(9./5.)+32.0; 99 : } else { 100 : // Exception: Unknown temperature unit. S.I. used (Kelvin) 101 0 : return valueIS_; 102 : } 103 : } 104 : 105 : ATM_NAMESPACE_END