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: ATMLength.cpp Exp $" 20 : * 21 : * who when what 22 : * -------- -------- ---------------------------------------------- 23 : * pardo 24/03/09 created 24 : */ 25 : 26 : 27 : #include "ATMLength.h" 28 : #include <stdio.h> 29 : 30 : 31 : 32 : ATM_NAMESPACE_BEGIN 33 : 34 16202 : Length::Length() : 35 16202 : valueIS_(0.0) 36 : { 37 16202 : } 38 : 39 31067294 : Length::Length(double length) : 40 31067294 : valueIS_(length) 41 : { 42 31067294 : } 43 : 44 804 : Length::Length(double length, const std::string &units) 45 : { 46 804 : valueIS_ = sput(length, units); 47 804 : } 48 : 49 412300759 : Length::Length(double length, Length::Units units) 50 : { 51 412300759 : valueIS_ = sput(length, units); 52 412300759 : } 53 : 54 31046665 : Length::Length(const Length &length) : 55 31046665 : valueIS_(length.valueIS_) 56 : { 57 31046665 : } 58 : 59 474431724 : Length::~Length() 60 : { 61 474431724 : } 62 : 63 205 : double Length::sget(double value, const std::string &units) 64 : { 65 205 : if(units == "km" || units == "KM") { 66 0 : return 1.0E-3 * value; 67 205 : } else if(units == "m" || units == "M") { 68 200 : return value; 69 5 : } else if(units == "mm" || units == "MM") { 70 5 : return 1.0E+3 * value; 71 0 : } else if(units == "micron" || units == "MICRON") { 72 0 : return 1.0E+6 * value; 73 0 : } else if(units == "microns" || units == "MICRONS") { 74 0 : return 1.0E+6 * value; 75 0 : } else if(units == "nm" || units == "NM") { 76 0 : return 1.0E+9 * value; 77 : } else { 78 0 : return value; 79 : } 80 : } 81 : 82 804 : double Length::sput(double value, const std::string &units) 83 : { 84 804 : if(units == "km" || units == "KM") { 85 0 : return 1.0E+3 * value; 86 804 : } else if(units == "m" || units == "M") { 87 0 : return value; 88 804 : } else if(units == "mm" || units == "MM") { 89 804 : return 1.0E-3 * value; 90 0 : } else if(units == "micron" || units == "MICRON") { 91 0 : return 1.0E-6 * value; 92 0 : } else if(units == "nm" || units == "NM") { 93 0 : return 1.0E-9 * value; 94 : } else { 95 0 : return value; 96 : } 97 : } 98 : 99 22355 : double Length::sget(double value, Length::Units units) 100 : { 101 22355 : if(units == Length::UnitKiloMeter) { 102 21183 : return 1.0E-3 * value; 103 1172 : } else if(units == Length::UnitMeter) { 104 971 : return value; 105 201 : } else if(units == Length::UnitMilliMeter) { 106 201 : return 1.0E+3 * value; 107 : } else if(units == Length::UnitMicron || Length::UnitMicrons) { 108 0 : return 1.0E+6 * value; 109 : } else if(units == Length::UnitNanoMeter) { 110 : return 1.0E+9 * value; 111 : } else { 112 : return value; 113 : } 114 : } 115 : 116 412300759 : double Length::sput(double value, Length::Units units) 117 : { 118 412300759 : if(units == Length::UnitKiloMeter) { 119 17794 : return 1.0E+3 * value; 120 412282965 : } else if(units == Length::UnitMeter) { 121 412258693 : return value; 122 24272 : } else if(units == Length::UnitMilliMeter) { 123 24272 : return 1.0E-3 * value; 124 0 : } else if(units == Length::UnitMicron || units == Length::UnitMicrons) { 125 0 : return 1.0E-6 * value; 126 0 : } else if(units == Length::UnitNanoMeter) { 127 0 : return 1.0E-9 * value; 128 : } else { 129 0 : return value; 130 : } 131 : } 132 : 133 : 134 : /* 135 : std::string Length::get(const std::string &form, const std::string &units) const 136 : { 137 : char myString[18]; 138 : 139 : sprintf(myString, "%f %s", get(units), units.c_str()); 140 : 141 : 142 : return std::string(myString); 143 : } 144 : */ 145 : 146 : ATM_NAMESPACE_END