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 40 : Temperature::Temperature() : 32 40 : valueIS_(0.0) 33 : { 34 40 : } 35 : 36 14 : Temperature::Temperature(double temperature) : 37 14 : valueIS_(temperature) 38 : { 39 14 : } 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 3215 : Temperature::Temperature(double temperature, const Temperature::Units units) 58 : { 59 3215 : if(units == Temperature::UnitMilliKelvin) { 60 0 : valueIS_ = 1.0E-3 * temperature; 61 3215 : } else if(units == Temperature::UnitKelvin) { 62 3215 : 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 3215 : } 72 : 73 2614 : double Temperature::get(const string &units) const 74 : { 75 2614 : if(units == "mK") { 76 0 : return 1.0E3 * valueIS_; 77 2614 : } else if(units == "K") { 78 2614 : 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 306 : double Temperature::get(Temperature::Units units) const 90 : { 91 306 : if(units == Temperature::UnitMilliKelvin) { 92 0 : return 1.0E3 * valueIS_; 93 306 : } else if(units == Temperature::UnitKelvin) { 94 306 : 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