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: ATMFrequency.cpp Exp $" 20 : * 21 : * who when what 22 : * -------- -------- ---------------------------------------------- 23 : * pardo 24/03/09 created 24 : */ 25 : 26 : #include <stdio.h> 27 : 28 : #include "ATMFrequency.h" 29 : 30 : 31 : 32 : ATM_NAMESPACE_BEGIN 33 : 34 10 : Frequency::Frequency() : 35 10 : valueIS_(0.0) 36 : { 37 10 : } 38 : 39 18 : Frequency::Frequency(double frequency) : 40 18 : valueIS_(frequency) 41 : { 42 18 : } 43 : 44 27 : Frequency::Frequency(double frequency, const std::string &units) 45 : { 46 27 : valueIS_ = sput(frequency, units); 47 27 : } 48 : 49 11931 : Frequency::Frequency(double frequency, Frequency::Units units) 50 : { 51 11931 : valueIS_ = sput(frequency, units); 52 11931 : } 53 : 54 0 : Frequency::Frequency(const Frequency &frequency) : 55 0 : valueIS_(frequency.valueIS_) 56 : { 57 0 : } 58 : 59 11986 : Frequency::~Frequency() 60 : { 61 11986 : } 62 : 63 588 : double Frequency::sget(double value, const std::string &units) 64 : { 65 588 : if(units == "THz" || units == "THZ") { 66 0 : return 1.0E-12 * value; 67 588 : } else if(units == "GHz" || units == "GHz" || units == "ghz") { 68 567 : return 1.0E-9 * value; 69 21 : } else if(units == "MHz" || units == "MHZ" || units == "mhz") { 70 4 : return 1.0E-6 * value; 71 17 : } else if(units == "kHz" || units == "KHZ" || units == "khz") { 72 3 : return 1.0E-3 * value; 73 14 : } else if(units == "Hz" || units == "HZ" || units == "hz") { 74 14 : return value; 75 : } else { 76 0 : return value; 77 : } 78 : } 79 27 : double Frequency::sput(double freq, const std::string &units) 80 : { 81 27 : if(units == "THz" || units == "THZ") { 82 0 : return 1.0E12 * freq; 83 27 : } else if(units == "GHz" || units == "GHZ" || units == "ghz") { 84 20 : return 1.0E9 * freq; 85 7 : } else if(units == "MHz" || units == "MHZ" || units == "mhz") { 86 5 : return 1.0E6 * freq; 87 2 : } else if(units == "kHz" || units == "KHZ" || units == "khz") { 88 0 : return 1.0E3 * freq; 89 2 : } else if(units == "Hz" || units == "HZ" || units == "hz") { 90 2 : return freq; 91 : } else { 92 0 : return freq; 93 : } 94 : } 95 : 96 11324 : double Frequency::sget(double value, Frequency::Units units) 97 : { 98 11324 : if(units == Frequency::UnitTeraHertz) { 99 0 : return 1.0E-12 * value; 100 11324 : } else if(units == Frequency::UnitGigaHertz) { 101 11272 : return 1.0E-9 * value; 102 52 : } else if(units == Frequency::UnitMegaHertz) { 103 0 : return 1.0E-6 * value; 104 52 : } else if(units == Frequency::UnitKiloHertz) { 105 0 : return 1.0E-3 * value; 106 52 : } else if(units == Frequency::UnitHertz) { 107 52 : return value; 108 : } else { 109 0 : return value; 110 : } 111 : } 112 11931 : double Frequency::sput(double freq, Frequency::Units units) 113 : { 114 11931 : if(units == Frequency::UnitTeraHertz) { 115 0 : return 1.0E12 * freq; 116 11931 : } else if(units == Frequency::UnitGigaHertz) { 117 0 : return 1.0E9 * freq; 118 11931 : } else if(units == Frequency::UnitMegaHertz) { 119 0 : return 1.0E6 * freq; 120 11931 : } else if(units == Frequency::UnitKiloHertz) { 121 0 : return 1.0E3 * freq; 122 11931 : } else if(units == Frequency::UnitHertz) { 123 11931 : return freq; 124 : } else { 125 0 : return freq; 126 : } 127 : } 128 : 129 : ATM_NAMESPACE_END