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 10090 : Temperature::Temperature() : 32 10090 : valueIS_(0.0) 33 : { 34 10090 : } 35 : 36 15278584 : Temperature::Temperature(double temperature) : 37 15278584 : valueIS_(temperature) 38 : { 39 15278584 : } 40 : 41 5 : Temperature::Temperature(double temperature, const string &units) 42 : { 43 5 : if(units == "mK" || units == "mk") { 44 0 : valueIS_ = 1.0E-3 * temperature; 45 5 : } else if(units == "K" || units == "k") { 46 5 : 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 5 : } 56 : 57 442783162 : Temperature::Temperature(double temperature, const Temperature::Units units) 58 : { 59 442783162 : if(units == Temperature::UnitMilliKelvin) { 60 0 : valueIS_ = 1.0E-3 * temperature; 61 442783162 : } else if(units == Temperature::UnitKelvin) { 62 442783162 : 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 442783162 : } 72 : 73 131848 : double Temperature::get(const string &units) const 74 : { 75 131848 : if(units == "mK") { 76 0 : return 1.0E3 * valueIS_; 77 131848 : } else if(units == "K") { 78 131848 : 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 76207832 : double Temperature::get(Temperature::Units units) const 90 : { 91 76207832 : if(units == Temperature::UnitMilliKelvin) { 92 0 : return 1.0E3 * valueIS_; 93 76207832 : } else if(units == Temperature::UnitKelvin) { 94 76207832 : 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