Public Member Functions |
| UnitVal () |
| Construct an non-dimensioned value of 1.
|
| UnitVal (const UnitVal &other) |
| Copy constructor.
|
| UnitVal (Double factor) |
| Construct an non-dimensioned value.
|
| UnitVal (Double factor, const String &s) |
| Construct a fully dimensioned value.
|
| UnitVal (Double factor, Int pos) |
| Construct a value with a single unit at position specified.
|
| ~UnitVal () |
| Destructor.
|
UnitVal & | operator= (const UnitVal &other) |
| Assignment (copy semantics)
|
UnitVal | pow (Int p) |
| Raise a unit to an integer power.
|
UnitVal | root (Int p) const |
| Take integer root.
|
UnitVal | sqrt () const |
|
UnitVal & | operator*= (const UnitVal &other) |
| Manipulate units.
|
UnitVal & | operator/= (const UnitVal &other) |
| Divide different units.
|
Bool | operator== (const UnitVal &other) const |
| Compare the dimensionality of different units.
|
Bool | operator!= (const UnitVal &other) const |
|
const UnitDim & | getDim () const |
| Get the data parts of the unit value definition.
|
Double | getFac () const |
| Get the factor of the unit (as compared to pure SI units)
|
Static Public Member Functions |
static Bool | check (const String &s) |
| Convert a unit string to a proper unit value and cache the result.
|
static Bool | check (const String &s, UnitVal &loc) |
| Convert a unit string to a proper unit value, cache the result and compare the dimension with the specified unit value.
|
Static Public Attributes |
|
static UnitVal | NODIM |
| Some constants to check type of units.
|
static UnitVal | UNDIM |
static UnitVal | LENGTH |
static UnitVal | MASS |
static UnitVal | TIME |
static UnitVal | CURRENT |
static UnitVal | TEMPERATURE |
static UnitVal | INTENSITY |
static UnitVal | MOLAR |
static UnitVal | ANGLE |
static UnitVal | SOLIDANGLE |
Protected Member Functions |
void | init (Double factor) |
| alternate initialization
|
void | init (Double factor, Int pos) |
Static Private Member Functions |
static Bool | create (const String &s, UnitVal &res) |
| Convert (and check) a unit string to an SI value representation.
|
static Bool | create (MUString &str, UnitVal &res) |
static Int | psign (MUString &str) |
| Determine sign of unit power (i.e.
|
static Int | power (MUString &str) |
| Determine exponent of unit symbol.
|
static Bool | field (MUString &str, UnitVal &res) |
| Determine symbol name in unit string.
|
Private Attributes |
Double | kindFactor |
| The factor necessary to express the specified unit in the defining SI units.
|
UnitDim | kindDim |
| The dimensions of the unit in the defining SI units.
|
Friends |
class | UnitVal_static_initializer |
| ensure that statics are initialized
|
UnitVal | operator* (const UnitVal &in, const UnitVal &other) |
| Multiply.
|
UnitVal | operator/ (const UnitVal &in, const UnitVal &other) |
| Divide.
|
ostream & | operator<< (ostream &os, const UnitVal &ku) |
| Output a unit as a value and a string of SI defining units.
|
describes any valid unit as a factor and a dimenion of SI units
Intended use:
Public interface
Review Status
- Reviewed By:
- UNKNOWN
- Date Reviewed:
- before2004/08/25
- Test programs:
- tUnit
Prerequisite
Etymology
The class name derives from Units and gives a Value for a unit string
Synopsis
Physical units are strings consisting of one or more names of known basic units, separated by '.' or ' ' (for multiplication) or '/' (for division). Each name can optionally be preceded by a standard decimal prefix, and/or followed by an (optionally signed) exponent. Example: km/s/(Mpc.s)2 is identical to km.s-1.Mpc-2.s-2
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.
Constructing UnitVal values
UnitVal has the following constructors:
-
UnitVal() creates an (non-dimensioned) value 1.
-
UnitVal(Double f) creates an (non-dimensioned) value f.
-
UnitVal(Double f, String s) creates value f with unit s
-
UnitVal(Double f, Int i) (private) creates value f with unit at position i in dimension vector
Manipulating unit values
The UnitVal can be manipulated by the following operators and functions:
-
*, / generates combined UnitVal (e.g. 1 yd * 1 m = 0.9 m2)
-
pow(Int) UnitVal(2,"km")->pow(2) = 4000000 m2
-
root(Int) UnitVal(4000000,"m2")->root(2) = 2 km
-
==, != compares dimensions only: 1 yd == 5 ly: True
-
getFac() will return the factor (Double)
-
getDim() will return the dimensions (as UnitDim)
-
<< will output formatted unit (factor and dimension)
To aid in checking the dimensionality of units, the following constants are available:
Tip: 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
Checking for valid unit strings
The validity of a unit string can be checked by:
Example
An observation contains values in Janskys and in Westerbork Units. The data can be combined by the following code:
if ( !UnitVal::check( "JY")) {
UnitMap::putUser("JY", UnitVal(1.,"Jy"), "FITS way to write Jy");
}
if (UnitVal(1.,"JY") != UnitVal(1.,"WU")) {
cerr << "Wrong dimension for either JY ( " <<
UnitVal(1.,"JY")->getDim() <<
") or WU ( " <<
UnitVal(1.,"WU")->getDim() << ")" << endl;
}
cout << "1 WU = " << ( UnitVal(1.,"WU")/UnitVal(1.,"Jy") )->getVal() <<
" JY with 1 WU = " << UnitVal(1.,"WU") << endl;
Motivation
To separate the actual manipulation of unit values from the related quantity
To Do
-
Some inlining (did not work first go)
Definition at line 166 of file UnitVal.h.