Loading...
Searching...
No Matches
casacore::Unit Class Reference
casa package (libcasa_casa) » Quanta_module

More...

`#include <Unit.h>`

## Public Member Functions

| Unit ()
| Default empty string constructor.
| Unit (const Unit &other)
| Copy constructor.
| Unit (const std::string &other)
| String based constructors.
| Unit (const Char *other)
| Unit (Char other)
| Unit (const Char *other, Int len)
| ~Unit ()
| Destructor.
Unit & | operator= (const Unit &other)
Bool | operator== (const Unit &other) const
| Comparisons.
Bool | operator!= (const Unit &other) const
Bool | empty () const
| Fast check for "" units.
const UnitVal & | getValue () const
| Get the unit value.
const String & | getName () const
| Get the unit name.
void | setValue (const UnitVal &in)
| Set the unit value.
void | setName (const String &in)
| Set the unit name.

## Private Member Functions

void | check ()
| Check format of unit string.

## Private Attributes

String | uName
UnitVal | uVal

## Detailed Description

defines physical units

### Intended use:

Public interface

### Review Status

Reviewed By:
  UNKNOWN
Date Reviewed:
  before2004/08/25
Test programs:
  tUnit

### Synopsis

Physical units are basically used as quantities (see the Quantum class), i.e. a value and a dimension. The Unit class, or one of its subsidaries, will in general not be called separately. The only reason to make use of these classes is to generate additional 'tagged' units, i.e. units with a special name, e.g. 'beam' for a telescope beam, or 'JY', a non-SI name for Jy.

### Units

A Unit is a String, and can be defined as either a Unit or a String everywhere where a Unit is required.
If defined as a Unit, the format of the string will be checked for a legal definition and its value will be stored. If defined as a String, the checking and determination of the value will be done each time the string is encountered when a Unit is expected.
Tip: The use of a separate Unit variable will give a tremendous speed increase, if compared to using the String representation in e;g; Quantity(5,"deg")
Caution: If using an explicit Unit variable (e;g; Unit a("5Bolton/beam")), the check on the legality of the given string, and the conversion to the cached canonical value in the variable 'a', is only done at creation time; This means that if the user changes the value of a unit involved by the putUser() method, the unit using it should be re-created ( a = Unit("5Bolton/beam"););
A unit is a string of one or more fields separated by 'space' or '.' or '*' (FITS option) (to indicate multiply) or '/' (to indicate divide). Multiple separators are acted upon (i.e. m//s == m.s). Separators are acted upon left-to-right (i.e. m/s/A == (m/s)/A; use () to indicate otherwise (e.g. m/(s/A))).

A field is a name, or a unit enclosed in (), optionally followed by an, optionally signed, decimal constant. The decimal constant may be proceeded by '**' or '^' (FITS option)

E.g. m.(m/s)-2 == m-1.s2)
Tip: A 'space' or ';' before an opening '(' can be omitted;
A name can consist of case-sensitive letters, '', ''', ':', '"' and '0' ('0' not as first character). Digits 1-9 are allowed if preceded with an ''.

Possible legal names are e.g. Jy, R0, R_1, "_2.
Tip:

- ' is used for arcmin
- '' or " for arcsec
- : :: and ::: are used for h, min, s respectively
- _ is used for an undimensioned value (like beam or pixel)

Caution: The standard naming conventions for SI units are that they are all in lowercase, unless derived from a person's name, when they start with a capital letter; Notable exceptions are some of the astronomical SI related units (e;g; AU);
A name can be preceded by a (standard) decimal prefix.

A name must be defined in a Unit map before it can be used.

All SI units and some customary units are part of the classes. User defined names can be added by the UnitMap::putUser() function (see the UnitMap class).

Example: km/s/(Mpc.s)2 is identical to km.s-1.Mpc-2.s-2

There are 5 name lists in the UnitMap, which are searched in reverse order:

1. Defining units: m, kg, s, A, K, cd, mol, rad, sr, _
2. SI units: including a.o. g, Jy, AU
3. Customary units: e.g. lb, hp, ly
4. User defined units: defined by user (e.g. beam, KPH, KM)
5. Cached units: for speed in operations

All known names can be viewed by running the tUnit test program, or using the MapUnit::list() routine. They are also (at least the 1999/09/15 values) available in the Quanta module documentation.
Caution: There is a difference between units without a dimension (non-dimensioned I will call them), and undimensioned units; Non-dimensioned examples are "", "%"; undimensioned examples: "beam", "pixel";

### Unit class

The Unit class is not directly based on the String class, but Strings and Units are interchangeable in all Unit and Quantum related calls. (But notice the earlier note on speed if using explicit Strings often.)

To calculate with Units (or Strings representing units), use the UnitVal class. To use dimensioned values, use the Quantum (cq Quantity) class.

Using Unit i.s.o. String will give an immediate check of the legality of the unit string. In addition the UnitVal class contains a check facility to determine the legality of a unit string:

Bool UnitVal::check("string");
casacore::UnitVal::check
static Bool check(const String &s)
Convert a unit string to a proper unit value and cache the result.
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40

### Example

#include <casacore/casa/Quanta.h>
// check if a string is a valid unit
if (!UnitVal::check("Km")) { cout << "Invalid unit string " << "Km" << endl; }
// define some units
String unit1="km/Mpc";
Unit unit2="uJy/Mpc";
// define your own unit name
UnitMap::putUser("my_univ", UnitVal(C::pi, unit2), "My universe param");
// use the units in model calculations
Quantity observed(8.97, "Mmy_univ/a");
Quantity theory (3.8e-9, "mmy_univ/s");
if ((observed / theory) < 1.) { cout << "Eureka" << endl; }
casacore::String
String: the storage and methods of handling collections of characters.
Definition String.h:223
casacore::UnitMap::putUser
static void putUser(const String &s, const UnitVal &val)
Define a user defined standard unit.
casacore::UnitVal
Definition UnitVal.h:165
casacore::Unit
Definition Unit.h:187
casacore::C::pi
constexpr double pi
Pi and functions thereof:
Definition Constants.h:363
casacore::Quantity
Quantum< Double > Quantity
Definition Quantum.h:39

### Motivation

Make basis for all dimensioned values the SI system of units

### To Do

- Some inlining (did not work first go)
- Look into possiblity of conversion routine from rad2 to sr

Definition at line 187 of file Unit.h.

## Constructor & Destructor Documentation

## Unit() [1/6]

casacore::Unit::Unit | ( |  | ) |

Default empty string constructor.

Referenced by operator!=(), operator=(), operator==(), and Unit().

## Unit() [2/6]

casacore::Unit::Unit | ( | const Unit & | other | ) |

Copy constructor.

References Unit().

## Unit() [3/6]

casacore::Unit::Unit | ( | const std::string & | other | ) |

String based constructors.

### Thrown Exceptions

- AipsError if illegal unit string

## Unit() [4/6]

casacore::Unit::Unit | ( | const Char * | other | ) |

## Unit() [5/6]

casacore::Unit::Unit | ( | Char | other | ) |

explicit

## Unit() [6/6]

casacore::Unit::Unit | ( | const Char * | other,
|  | Int | len )

## ~Unit()

casacore::Unit::~Unit | ( |  | ) |

Destructor.

## Member Function Documentation

## check()

void casacore::Unit::check | ( |  | ) |

private

Check format of unit string.

### Thrown Exceptions

- AipsError

## empty()

Bool casacore::Unit::empty | ( |  | ) | const

Fast check for "" units.

## getName()

const String & casacore::Unit::getName | ( |  | ) | const

Get the unit name.

## getValue()

const UnitVal & casacore::Unit::getValue | ( |  | ) | const

Get the unit value.

## operator!=()

Bool casacore::Unit::operator!= | ( | const Unit & | other | ) | const

References Unit().

## operator=()

Unit & casacore::Unit::operator= | ( | const Unit & | other | ) |

References Unit().

## operator==()

Bool casacore::Unit::operator== | ( | const Unit & | other | ) | const

Comparisons.

Comparisons are done on the basis of the inherent units. I.e. m/s are identical to AU/cy.

References Unit().

## setName()

void casacore::Unit::setName | ( | const String & | in | ) |

Set the unit name.

## setValue()

void casacore::Unit::setValue | ( | const UnitVal & | in | ) |

Set the unit value.

## Member Data Documentation

## uName

String casacore::Unit::uName

private

Definition at line 230 of file Unit.h.

## uVal

UnitVal casacore::Unit::uVal

private

Definition at line 231 of file Unit.h.

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

- casa/Quanta/Unit.h