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 312 : Length::Length() : 35 312 : valueIS_(0.0) 36 : { 37 312 : } 38 : 39 33963 : Length::Length(double length) : 40 33963 : valueIS_(length) 41 : { 42 33963 : } 43 : 44 28 : Length::Length(double length, const std::string &units) 45 : { 46 28 : valueIS_ = sput(length, units); 47 28 : } 48 : 49 296206 : Length::Length(double length, Length::Units units) 50 : { 51 296206 : valueIS_ = sput(length, units); 52 296206 : } 53 : 54 55115 : Length::Length(const Length &length) : 55 55115 : valueIS_(length.valueIS_) 56 : { 57 55115 : } 58 : 59 385624 : Length::~Length() 60 : { 61 385624 : } 62 : 63 444 : double Length::sget(double value, const std::string &units) 64 : { 65 444 : if(units == "km" || units == "KM") { 66 10 : return 1.0E-3 * value; 67 434 : } else if(units == "m" || units == "M") { 68 292 : return value; 69 142 : } else if(units == "mm" || units == "MM") { 70 142 : 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 28 : double Length::sput(double value, const std::string &units) 83 : { 84 28 : if(units == "km" || units == "KM") { 85 11 : return 1.0E+3 * value; 86 17 : } else if(units == "m" || units == "M") { 87 6 : return value; 88 11 : } else if(units == "mm" || units == "MM") { 89 11 : 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 46500 : double Length::sget(double value, Length::Units units) 100 : { 101 46500 : if(units == Length::UnitKiloMeter) { 102 3260 : return 1.0E-3 * value; 103 43240 : } else if(units == Length::UnitMeter) { 104 25 : return value; 105 43215 : } else if(units == Length::UnitMilliMeter) { 106 43215 : 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 296206 : double Length::sput(double value, Length::Units units) 117 : { 118 296206 : if(units == Length::UnitKiloMeter) { 119 2865 : return 1.0E+3 * value; 120 293341 : } else if(units == Length::UnitMeter) { 121 268689 : return value; 122 24652 : } else if(units == Length::UnitMilliMeter) { 123 24652 : 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