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")
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 '.' (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.
E.g. m.(m/s)-2 == m-1.s2)
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.
- ' 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)
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:
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".
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");
#include <aips/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;
* Operators Copy assignment
Check format of unit string