//# UnitVal.cc: defines the class describing a unit as a value and a dimension //# Copyright (C) 1994-2001,2008 //# Associated Universities, Inc. Washington DC, USA. //# //# This library is free software; you can redistribute it and/or modify it //# under the terms of the GNU Library General Public License as published by //# the Free Software Foundation; either version 2 of the License, or (at your //# option) any later version. //# //# This library is distributed in the hope that it will be useful, but WITHOUT //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public //# License for more details. //# //# You should have received a copy of the GNU Library General Public License //# along with this library; if not, write to the Free Software Foundation, //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. //# //# Correspondence concerning AIPS++ should be addressed as follows: //# Internet email: aips2-request@nrao.edu. //# Postal address: AIPS++ Project Office //# National Radio Astronomy Observatory //# 520 Edgemont Road //# Charlottesville, VA 22903-2475 USA //# //# $Id$ //# Includes #include #include #include #include #include #include #include namespace casacore { //# NAMESPACE CASACORE - BEGIN int UnitVal_static_initializer::initialized = 0; //# Constants UnitVal UnitVal::NODIM( 1.); UnitVal UnitVal::UNDIM( 1., UnitDim::Dnon); UnitVal UnitVal::LENGTH( 1., UnitDim::Dm); UnitVal UnitVal::MASS( 1., UnitDim::Dkg); UnitVal UnitVal::TIME( 1., UnitDim::Ds); UnitVal UnitVal::CURRENT( 1., UnitDim::DA); UnitVal UnitVal::TEMPERATURE( 1., UnitDim::DK); UnitVal UnitVal::INTENSITY( 1., UnitDim::Dcd); UnitVal UnitVal::MOLAR( 1., UnitDim::Dmol); UnitVal UnitVal::ANGLE( 1., UnitDim::Drad); UnitVal UnitVal::SOLIDANGLE( 1., UnitDim::Dsr); void UnitVal::init(Double factor) { kindFactor = factor; kindDim.init(); } void UnitVal::init(Double factor, Int pos) { kindFactor = factor; kindDim.init(pos); } UnitVal::UnitVal() : kindFactor(1.0), kindDim() {} UnitVal::UnitVal(const UnitVal &other) : kindFactor(other.kindFactor), kindDim(other.kindDim) {} UnitVal::UnitVal(Double factor, const String& s, UMaps* maps) : kindFactor(1.), kindDim() { if (UnitMap::getCache(s,*this)) { kindFactor *= factor; } else if (UnitVal::create(s, *this, maps)) { UnitMap::putCache(s,*this); kindFactor *= factor; } else { throw (AipsError("UnitVal::UnitVal Illegal unit string '" + s + "'")); } } UnitVal::~UnitVal() {} UnitVal &UnitVal::operator=(const UnitVal &other) { if (this != &other) { kindFactor = other.kindFactor; kindDim = other.kindDim; } return *this; } UnitVal &UnitVal::operator*=(const UnitVal &other) { kindFactor *= other.kindFactor; kindDim *= other.kindDim; return *this; } UnitVal operator*(const UnitVal &in, const UnitVal &other) { UnitVal result = in; result *= other; return result; } UnitVal &UnitVal::operator/=(const UnitVal &other) { kindFactor /= other.kindFactor; kindDim /= other.kindDim; return *this; } UnitVal operator/(const UnitVal &in, const UnitVal &other) { UnitVal result = in; result /= other; return result; } Bool UnitVal::operator==(const UnitVal &other) const { return kindDim == other.kindDim; } Bool UnitVal::operator!=(const UnitVal &other) const { return kindDim != other.kindDim; } ostream& operator<< (ostream &os, const UnitVal &ku) { os << ku.kindFactor << ku.kindDim; return os; } UnitVal UnitVal::pow(Int p) { UnitVal loc; loc.kindFactor = ::pow(kindFactor,Double(p)); loc.kindDim = kindDim.pow(p); return(loc); } UnitVal UnitVal::root(Int p) const { if (p==0) throw (AipsError("UnitVal::UnitVal Illegal root zero taken")); UnitVal loc; loc.kindDim = kindDim; for (Int i=0; i 1 && UnitMap::getPref(key(0,1), loc, maps)) { UnitName loc1 = UnitName(); if (UnitMap::getUnit(key.from(1), loc1, maps)) { res = (loc.getVal() * loc1.getVal()); return True; } else if ( key.length() > 2 && UnitMap::getPref(key(0,2),loc)) { if (UnitMap::getUnit(key.from(2), loc1, maps)) { res = (loc.getVal() * loc1.getVal()); return True; } } } return False; } } //# NAMESPACE CASACORE - END