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 21851 : Length::Length() : 35 21851 : valueIS_(0.0) 36 : { 37 21851 : } 38 : 39 32064404 : Length::Length(double length) : 40 32064404 : valueIS_(length) 41 : { 42 32064404 : } 43 : 44 874 : Length::Length(double length, const std::string &units) 45 : { 46 874 : valueIS_ = sput(length, units); 47 874 : } 48 : 49 540077569 : Length::Length(double length, Length::Units units) 50 : { 51 540077569 : valueIS_ = sput(length, units); 52 540077569 : } 53 : 54 32096929 : Length::Length(const Length &length) : 55 32096929 : valueIS_(length.valueIS_) 56 : { 57 32096929 : } 58 : 59 604261627 : Length::~Length() 60 : { 61 604261627 : } 62 : 63 573 : double Length::sget(double value, const std::string &units) 64 : { 65 573 : if(units == "km" || units == "KM") { 66 10 : return 1.0E-3 * value; 67 563 : } else if(units == "m" || units == "M") { 68 426 : return value; 69 137 : } else if(units == "mm" || units == "MM") { 70 137 : 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 874 : double Length::sput(double value, const std::string &units) 83 : { 84 874 : if(units == "km" || units == "KM") { 85 61 : return 1.0E+3 * value; 86 813 : } else if(units == "m" || units == "M") { 87 6 : return value; 88 807 : } else if(units == "mm" || units == "MM") { 89 807 : 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 93858 : double Length::sget(double value, Length::Units units) 100 : { 101 93858 : if(units == Length::UnitKiloMeter) { 102 39844 : return 1.0E-3 * value; 103 54014 : } else if(units == Length::UnitMeter) { 104 1009 : return value; 105 53005 : } else if(units == Length::UnitMilliMeter) { 106 53005 : 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 540077569 : double Length::sput(double value, Length::Units units) 117 : { 118 540077569 : if(units == Length::UnitKiloMeter) { 119 36025 : return 1.0E+3 * value; 120 540041544 : } else if(units == Length::UnitMeter) { 121 540014424 : return value; 122 27120 : } else if(units == Length::UnitMilliMeter) { 123 27120 : 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