See the Unit class for more details.
The UnitVal class maps a Unit string to a factor and a dimension of SI defining units. E.g 'km/s' will be 1000 m.s-1 . This class is only of interest if the manipulation of units is of direct interest. Normally units will be used as Quantities and Quantums (see the Quantum class) only, i.e. as a physical quantity having a value and unit. The class can also be used to check the validity of a unit string.
UnitVal has the following constructors:
The UnitVal can be manipulated by the following operators and functions:
Any other dimension can be checked by a combination. To check e.g. if a unit is an acceleration, use: UnitVal::LENGTH/UnitVal::TIME/UnitVal::TIME
The validity of a unit string can be checked by:
// Check if the given String is a valid unit representation. The String // will be cached in the unit maps for later reference if True if ( UnitVal::check( "km/s/Mpc") ) {...}
// The Fits tape gave JY, we check if defined, else we define them if ( !UnitVal::check( "JY")) { UnitMap::putUser("JY", UnitVal(1.,"Jy"), "FITS way to write Jy"); } // The Fits tape gave WU (which are defined): // We check if JY and WU are of the same dimension: if (UnitVal(1.,"JY") != UnitVal(1.,"WU")) { cerr << "Wrong dimension for either JY ( " << UnitVal(1.,"JY")->getDim() << ") or WU ( " << UnitVal(1.,"WU")->getDim() << ")" << endl; } // And output the relation between WU and JY, and the WU value: cout << "1 WU = " << ( UnitVal(1.,"WU")/UnitVal(1.,"Jy") )->getVal() << " JY with 1 WU = " << UnitVal(1.,"WU") << endl;
Construct an non-dimensioned value
Construct a fully dimensioned value
Construct a value with a single unit at position specified
Destructor
Assignment (copy semantics)
Manipulate units
Multiply different units
Manipulate units
Divide different units
Manipulate units
Compare the dimensionality of different units
Manipulate units
Raise a unit to an integer power
Take integer root
Get the data parts of the unit value definition
Get the factor of the unit (as compared to pure SI units)
Get the data parts of the unit value definition
Convert a unit string to a proper unit value and cache the result. The
function will return False if invalid string specified
Convert a unit string to a proper unit value, cache the result and compare
the dimension with the specified unit value. False if any of the steps fails
Convert (and check) a unit string to an SI value representation
Determine sign of unit power (i.e. if '.' or '/')
Determine exponent of unit symbol
Determine symbol name in unit string
UnitVal &operator*=(const UnitVal &other)
UnitVal &operator/=(const UnitVal &other)
Bool operator==(const UnitVal &other) const
Bool operator!=(const UnitVal &other) const
UnitVal pow(Int p)
UnitVal root(Int p) const
UnitVal sqrt() const
Thrown Exceptions
Double getFac() const
const UnitDim &getDim() const
static Bool check(const String &s)
static Bool check(const String &s, UnitVal &loc)
void init(Double factor)
alternate initialization
void init(Double factor, Int pos)
static Bool create(const String &s, UnitVal &res)
static Bool create(MUString &str, UnitVal &res)
static Int psign(MUString &str)
static Int power(MUString &str)
static Bool field(MUString &str, UnitVal &res)
Global output function (source)
Interface
Description
Member Description
ostream& operator<<(ostream &os, const UnitVal &ku)
Output
static class UnitVal_static_initializer
Interface
Description
Member Description
UnitVal_static_initializer( )