casacore
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
casacore::UnitVal Class Reference

More...

#include <UnitVal.h>

Public Member Functions

 UnitVal ()
 Construct an non-dimensioned value of 1. More...
 
 UnitVal (const UnitVal &other)
 Copy constructor. More...
 
 UnitVal (Double factor)
 Construct an non-dimensioned value. More...
 
 UnitVal (Double factor, const String &s, UMaps *=0)
 Construct a fully dimensioned value. More...
 
 UnitVal (Double factor, Int pos)
 Construct a value with a single unit at position specified. More...
 
 ~UnitVal ()
 Destructor. More...
 
UnitValoperator= (const UnitVal &other)
 Assignment (copy semantics) More...
 
UnitValoperator*= (const UnitVal &other)
 Manipulate units
More...
 
UnitValoperator/= (const UnitVal &other)
 Divide different units. More...
 
Bool operator== (const UnitVal &other) const
 Compare the dimensionality of different units. More...
 
Bool operator!= (const UnitVal &other) const
 
UnitVal pow (Int p)
 Raise a unit to an integer power. More...
 
UnitVal root (Int p) const
 Take integer root. More...
 
UnitVal sqrt () const
 
const UnitDimgetDim () const
 Get the data parts of the unit value definition
More...
 
Double getFac () const
 Get the factor of the unit (as compared to pure SI units) More...
 

Static Public Member Functions

static Bool check (const String &s)
 Convert a unit string to a proper unit value and cache the result. More...
 
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. More...
 

Static Public Attributes

static UnitVal NODIM
 Some constants to check type of units
More...
 
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 More...
 
void init (Double factor, Int pos)
 

Static Private Member Functions

static Bool create (const String &s, UnitVal &res, UMaps *=0)
 Convert (and check) a unit string to an SI value representation. More...
 
static Bool create (MUString &str, UnitVal &res, UMaps *=0)
 
static Int psign (MUString &str)
 Determine sign of unit power (i.e. More...
 
static Int power (MUString &str)
 Determine exponent of unit symbol. More...
 
static Bool field (MUString &str, UnitVal &res, UMaps *)
 Determine symbol name in unit string. More...
 

Private Attributes

Double kindFactor
 The factor necessary to express the specified unit in the defining SI units. More...
 
UnitDim kindDim
 The dimensions of the unit in the defining SI units. More...
 

Friends

class UnitVal_static_initializer
 ensure that statics are initialized More...
 
UnitVal operator* (const UnitVal &in, const UnitVal &other)
 Multiply. More...
 
UnitVal operator/ (const UnitVal &in, const UnitVal &other)
 Divide. More...
 
ostream & operator<< (ostream &os, const UnitVal &ku)
 Output a unit as a value and a string of SI defining units. More...
 

Detailed Description

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:

Manipulating unit values

The UnitVal can be manipulated by the following operators and functions:

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:

// 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")) {...}
static Bool check(const String &s)
Convert a unit string to a proper unit value and cache the result.

Example

An observation contains values in Janskys and in Westerbork Units. The data can be combined by the following code:

// 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;
static void putUser(const String &s, const UnitVal &val)
Define a user defined standard unit.
UnitVal()
Construct an non-dimensioned value of 1.

Motivation

To separate the actual manipulation of unit values from the related quantity

To Do

Definition at line 167 of file UnitVal.h.

Constructor & Destructor Documentation

◆ UnitVal() [1/5]

casacore::UnitVal::UnitVal ( )

Construct an non-dimensioned value of 1.

◆ UnitVal() [2/5]

casacore::UnitVal::UnitVal ( const UnitVal other)

Copy constructor.

◆ UnitVal() [3/5]

casacore::UnitVal::UnitVal ( Double  factor)
inline

Construct an non-dimensioned value.

Definition at line 186 of file UnitVal.h.

References init().

◆ UnitVal() [4/5]

casacore::UnitVal::UnitVal ( Double  factor,
const String s,
UMaps = 0 
)

Construct a fully dimensioned value.

Thrown Exceptions

◆ UnitVal() [5/5]

casacore::UnitVal::UnitVal ( Double  factor,
Int  pos 
)
inline

Construct a value with a single unit at position specified.

Definition at line 195 of file UnitVal.h.

References init().

◆ ~UnitVal()

casacore::UnitVal::~UnitVal ( )

Destructor.

Member Function Documentation

◆ check() [1/2]

static Bool casacore::UnitVal::check ( const String s)
static

Convert a unit string to a proper unit value and cache the result.

The function will return False if invalid string specified

◆ check() [2/2]

static Bool casacore::UnitVal::check ( const String s,
UnitVal loc 
)
static

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

◆ create() [1/2]

static Bool casacore::UnitVal::create ( const String s,
UnitVal res,
UMaps = 0 
)
staticprivate

Convert (and check) a unit string to an SI value representation.

◆ create() [2/2]

static Bool casacore::UnitVal::create ( MUString str,
UnitVal res,
UMaps = 0 
)
staticprivate

◆ field()

static Bool casacore::UnitVal::field ( MUString str,
UnitVal res,
UMaps  
)
staticprivate

Determine symbol name in unit string.

◆ getDim()

const UnitDim& casacore::UnitVal::getDim ( ) const

Get the data parts of the unit value definition

Get the dimensions in the defining SI units

◆ getFac()

Double casacore::UnitVal::getFac ( ) const

Get the factor of the unit (as compared to pure SI units)

◆ init() [1/2]

void casacore::UnitVal::init ( Double  factor)
protected

◆ init() [2/2]

void casacore::UnitVal::init ( Double  factor,
Int  pos 
)
protected

◆ operator!=()

Bool casacore::UnitVal::operator!= ( const UnitVal other) const

◆ operator*=()

UnitVal& casacore::UnitVal::operator*= ( const UnitVal other)

Manipulate units

Multiply different units

◆ operator/=()

UnitVal& casacore::UnitVal::operator/= ( const UnitVal other)

Divide different units.

◆ operator=()

UnitVal& casacore::UnitVal::operator= ( const UnitVal other)

Assignment (copy semantics)

◆ operator==()

Bool casacore::UnitVal::operator== ( const UnitVal other) const

Compare the dimensionality of different units.

◆ pow()

UnitVal casacore::UnitVal::pow ( Int  p)

Raise a unit to an integer power.

◆ power()

static Int casacore::UnitVal::power ( MUString str)
staticprivate

Determine exponent of unit symbol.

◆ psign()

static Int casacore::UnitVal::psign ( MUString str)
staticprivate

Determine sign of unit power (i.e.

if '.' or '/')

◆ root()

UnitVal casacore::UnitVal::root ( Int  p) const

Take integer root.

Thrown Exceptions

◆ sqrt()

UnitVal casacore::UnitVal::sqrt ( ) const

Friends And Related Function Documentation

◆ operator*

UnitVal operator* ( const UnitVal in,
const UnitVal other 
)
friend

Multiply.

◆ operator/

UnitVal operator/ ( const UnitVal in,
const UnitVal other 
)
friend

Divide.

◆ operator<<

ostream& operator<< ( ostream &  os,
const UnitVal ku 
)
friend

Output a unit as a value and a string of SI defining units.

◆ UnitVal_static_initializer

friend class UnitVal_static_initializer
friend

ensure that statics are initialized

Definition at line 176 of file UnitVal.h.

Member Data Documentation

◆ ANGLE

UnitVal casacore::UnitVal::ANGLE
static

◆ CURRENT

UnitVal casacore::UnitVal::CURRENT
static

◆ INTENSITY

UnitVal casacore::UnitVal::INTENSITY
static

◆ kindDim

UnitDim casacore::UnitVal::kindDim
private

The dimensions of the unit in the defining SI units.

Definition at line 278 of file UnitVal.h.

◆ kindFactor

Double casacore::UnitVal::kindFactor
private

The factor necessary to express the specified unit in the defining SI units.

Definition at line 275 of file UnitVal.h.

◆ LENGTH

UnitVal casacore::UnitVal::LENGTH
static

◆ MASS

UnitVal casacore::UnitVal::MASS
static

◆ MOLAR

UnitVal casacore::UnitVal::MOLAR
static

◆ NODIM

UnitVal casacore::UnitVal::NODIM
static

Some constants to check type of units

Definition at line 255 of file UnitVal.h.

Referenced by casacore::UnitVal_static_initializer::UnitVal_static_initializer().

◆ SOLIDANGLE

UnitVal casacore::UnitVal::SOLIDANGLE
static

◆ TEMPERATURE

UnitVal casacore::UnitVal::TEMPERATURE
static

◆ TIME

UnitVal casacore::UnitVal::TIME
static

◆ UNDIM

UnitVal casacore::UnitVal::UNDIM
static

The documentation for this class was generated from the following file: