#include <Quantum.h>
Inheritance diagram for casa::Quantum< Qtype >:


dimensioned values)
Part of API
A Quantity is defined as a single Double value with attached units. From this definition the templated Quantum class arose, to have non-Double, non-scalar quantities.
Quantities are values with a unit. Their basic specification can be one of two forms:
Quantity( Double value, String unit); // or: Unit unit Quantum<Type> ( Type value, String unit) // or: Unit unit
A unit is a string of known unit fields separated by 'space' or '.' (to indicate multiply) or '/' (to indicate divide). See the Unit class for details.
Example: km/s/(Mpc.s)2 is identical to km.s-1.Mpc-2.s-2
The following list of constructors is available. Tip: In the following 'String' can be replaced by 'Unit' everywhere. The only difference being a check for a legitimate unit string being executed if Unit specified (with exception if error) Tip: 'Quantum<Type>' can, if Type equals Double, be replaced with 'Quantity'
'Type' can be any simple or non-simple arithmetic type.
E.g. <Double>, <Complex>, <Vector<Double> >
Quantum<Type>() value 0 generated Quantum<Type>( Quantum<Type>) copy constructor Quantum<Type>( Type factor) value factor generated Quantum<Type>( Type factor, Unit unit) specified quantity Quantum<Type>( Type factor, Quantum<any> quant) specified factor, the unit from the quant
Mathematical operators and functions and logical operations (comparisons) are defined on Quantums. They are, of course, only available if the template Type supports them.
= assignment of identical <type> * *= multiple two Quantums of same <type>, or Quantum and type / /= divide two Quantums of same <type>, or Quantum and type note: In multiplication and division, and if <type> is scalar, the left or right-hand side can be of type <type> (e.g 2.*Quantity is allowed) + += add two Quantums of same <type> or Quantum and type and same unit dimensions (else exception) == != compare unit dimensions and value of same <type>. They will be unequal if the units do not match or the values (possibly converted to common base units). All comparisons work also on a Quantum<type> and <type> < > compare unit dimensions. Exception if no match, else compare the values <= >= ibid
Quantities can be converted to other units by the following set of member functions:
convert(Quantum<Type> quant) will convert the quantum to the units of the specified quant with the same conversion rules as the previous one Quanta can be checked for having the correct unit dimensions (e.g. before addition or comparing) by the following two member functions, which will return a Bool value:
isConform(Quantum<Type> quant) The quantum can be retrieved with a change in units by:
get(Quantum<Type> quant) will return the quantum converted to the units of the specified quant with the same conversion rules as the previous one The value and units of a quantum can be set or retrieved separately by the following member functions:
setUnit(Quantum<Type> quant) ibid
The output operator (<<) will produce the value of the quantum and its units. Given Quantity myval(5.,"mJy"), << myval will produce: 5.0 mJy; while << myval.get("yW/m2") will produce: .00005 yW/m2.s.
The input operator (>>, or the static read functions) will convert a String to a Quantum (quantity only for now). The analysis will do the following:
An experiment has measured the energy of a photon in keV. The following will output the wavelength and frequency of this photon (see the QC class for quantity constants):
#include <casa/Quanta.h> Double myval; // keV photon energy Quantity quant(myval,"keV"); // make quantity cout << "A photon with energy " << quant << endl << " has a frequency of " << (quant/QC::h)->get("GHz") << endl // h=Planck << " and a wavelength of " << (QC::c/quant/QC::h)->get("nm") // c=light velocity << " or " << QC::c/quant/QC::h << endl;
Major use is foreseen in all calculations with observed data.
< <= == != >= >
Definition at line 273 of file Quantum.h.
| void | scale (const Qtype &factor) |
| Scale ( i.e. | |
| void | setValue (const Qtype &val) |
| Set the value without changing units. | |
| static Bool | read (Quantity &res, const String &in) |
| Set the value and unit deduced from input string Caution: At the moment the implementation can only convert scalars to the appropiate Quantum. | |
| static Bool | read (Quantity &res, MUString &in) |
| virtual uInt | type () const |
| Get the type (== Register()) of derived Quantum (faster than Strings). | |
| static uInt | myType () |
Public Member Functions | |
| Quantum () | |
| Default constructor, generates '0'. | |
| Quantum (const Quantum< Qtype > &other) | |
| Copy constructor (deep copy). | |
| Quantum (const Qtype &factor) | |
| Construct undimensioned quantum (i.e. | |
| Quantum (const Qtype &factor, const QBase &other) | |
| Construct quantum with unit copied from existing quantum. | |
| ~Quantum () | |
| Destructor. | |
| Quantum< Qtype > & | operator= (const Quantum< Qtype > &other) |
| Assignment (deep copy). | |
| Qtype | getBaseValue () const |
| Get value in canonical base units. | |
| Qtype | getValue (const Unit &other) const |
| Get value in specified units. | |
| virtual const Unit & | getFullUnit () const |
| Get the unit (as Unit) that is attached to the Quantum. | |
| Bool | check (const UnitVal &uv) const |
| Check if of specified type. | |
| void | assure (const UnitVal &uv) const |
| Assert correct kind. | |
| virtual QBase * | clone () const |
| Get a copy of Quantum. | |
| virtual void | print (ostream &os) const |
| Print a Quantum. | |
| Quantum (const Qtype &factor, const Unit &s) | |
| Construct dimensioned quantum (e.g. | |
| const Quantum< Qtype > & | operator+ () const |
| Unary operations. | |
| Quantum< Qtype > | operator- () const |
| Quantum< Qtype > & | operator+= (const Quantum< Qtype > &other) |
| In place arithmetic functions: left hand side changed in place. | |
| Quantum< Qtype > & | operator+= (const Qtype &other) |
| Quantum< Qtype > & | operator-= (const Quantum< Qtype > &other) |
| Quantum< Qtype > & | operator-= (const Qtype &other) |
| Quantum< Qtype > & | operator *= (const Quantum< Qtype > &other) |
| Quantum< Qtype > & | operator *= (const Qtype &other) |
| Quantum< Qtype > & | operator/= (const Quantum< Qtype > &other) |
| Quantum< Qtype > & | operator/= (const Qtype &other) |
| Quantum< Qtype > | operator+ (const Quantum< Qtype > &other) const |
| Arithmetic operators: return Quantum<T>. | |
| Quantum< Qtype > | operator- (const Quantum< Qtype > &other) const |
| Quantum< Qtype > | operator * (const Quantum< Qtype > &other) const |
| Quantum< Qtype > | operator/ (const Quantum< Qtype > &other) const |
| const Qtype & | getValue () const |
| Get value of quantum in current units (i.e. | |
| Qtype & | getValue () |
| Quantum< Qtype > | get () const |
| Convert to canonical units. | |
| Quantum< Qtype > | get (const Unit &s) const |
| Convert to specified units; any remainder will be expressed in canonical units. | |
| Quantum< Qtype > | get (const Quantum< Qtype > &other) const |
| Convert a Quantum to units from specified quantum (ibid example). | |
| void | convert () |
| Convert to canonical units. | |
| void | convert (const Unit &s) |
| Convert to specified units; any remainder will be expressed in canonical units. | |
| void | convert (const Quantum< Qtype > &other) |
| Convert a Quantum to units from specified quantum (ibid example). | |
Private Attributes | |
| Qtype | qVal |
| Actual quantum value. | |
Friends | |
| istream & | operator>> (istream &is, Quantity &ku) |
| Input, only quantity is supported now. | |
| casa::Quantum< Qtype >::Quantum | ( | ) |
Default constructor, generates '0'.
| casa::Quantum< Qtype >::Quantum | ( | const Quantum< Qtype > & | other | ) |
Copy constructor (deep copy).
| casa::Quantum< Qtype >::Quantum | ( | const Qtype & | factor | ) |
Construct undimensioned quantum (i.e.
unit="")
| casa::Quantum< Qtype >::Quantum | ( | const Qtype & | factor, | |
| const Unit & | s | |||
| ) |
Construct dimensioned quantum (e.g.
'1.23 km/Mpc')
| casa::Quantum< Qtype >::Quantum | ( | const Qtype & | factor, | |
| const QBase & | other | |||
| ) |
Construct quantum with unit copied from existing quantum.
| casa::Quantum< Qtype >::~Quantum | ( | ) |
Destructor.
| Quantum<Qtype>& casa::Quantum< Qtype >::operator= | ( | const Quantum< Qtype > & | other | ) |
Assignment (deep copy).
| const Quantum<Qtype>& casa::Quantum< Qtype >::operator+ | ( | ) | const |
Unary operations.
| Quantum<Qtype> casa::Quantum< Qtype >::operator- | ( | ) | const |
| Quantum<Qtype>& casa::Quantum< Qtype >::operator+= | ( | const Quantum< Qtype > & | other | ) |
| Quantum<Qtype>& casa::Quantum< Qtype >::operator+= | ( | const Qtype & | other | ) |
| Quantum<Qtype>& casa::Quantum< Qtype >::operator-= | ( | const Quantum< Qtype > & | other | ) |
| Quantum<Qtype>& casa::Quantum< Qtype >::operator-= | ( | const Qtype & | other | ) |
| Quantum<Qtype>& casa::Quantum< Qtype >::operator *= | ( | const Quantum< Qtype > & | other | ) |
| Quantum<Qtype>& casa::Quantum< Qtype >::operator *= | ( | const Qtype & | other | ) |
| Quantum<Qtype>& casa::Quantum< Qtype >::operator/= | ( | const Quantum< Qtype > & | other | ) |
| Quantum<Qtype>& casa::Quantum< Qtype >::operator/= | ( | const Qtype & | other | ) |
| Quantum<Qtype> casa::Quantum< Qtype >::operator+ | ( | const Quantum< Qtype > & | other | ) | const |
| Quantum<Qtype> casa::Quantum< Qtype >::operator- | ( | const Quantum< Qtype > & | other | ) | const |
| Quantum<Qtype> casa::Quantum< Qtype >::operator * | ( | const Quantum< Qtype > & | other | ) | const |
| Quantum<Qtype> casa::Quantum< Qtype >::operator/ | ( | const Quantum< Qtype > & | other | ) | const |
| const Qtype& casa::Quantum< Qtype >::getValue | ( | ) | const |
Get value of quantum in current units (i.e.
in units specified in quantum)
Referenced by casa::SimObservations::addField(), casa::SimSpWin::chanFreq(), casa::SimSpWin::chanWidth(), casa::SimScan::gapTimeSec(), casa::SimScan::intTimeSec(), casa::SimSource::setDistance(), casa::SimSource::setInterval(), casa::SimScan::slewTimeSec(), casa::SimSource::timeSec(), and casa::SimSpWin::totalBandwidth().
| Qtype& casa::Quantum< Qtype >::getValue | ( | ) |
| Qtype casa::Quantum< Qtype >::getBaseValue | ( | ) | const |
Get value in canonical base units.
| Qtype casa::Quantum< Qtype >::getValue | ( | const Unit & | other | ) | const |
Get value in specified units.
| virtual const Unit& casa::Quantum< Qtype >::getFullUnit | ( | ) | const [virtual] |
Get the unit (as Unit) that is attached to the Quantum.
(use getUnit() if interested in the String part only, e.g. for output)
Implements casa::QBase.
| void casa::Quantum< Qtype >::scale | ( | const Qtype & | factor | ) |
Scale ( i.e.
multiply) the value of the Quantum without changing units
| void casa::Quantum< Qtype >::setValue | ( | const Qtype & | val | ) |
Set the value without changing units.
| static Bool casa::Quantum< Qtype >::read | ( | Quantity & | res, | |
| const String & | in | |||
| ) | [static] |
| static Bool casa::Quantum< Qtype >::read | ( | Quantity & | res, | |
| MUString & | in | |||
| ) | [static] |
| Bool casa::Quantum< Qtype >::check | ( | const UnitVal & | uv | ) | const |
Check if of specified type.
| void casa::Quantum< Qtype >::assure | ( | const UnitVal & | uv | ) | const |
| Quantum<Qtype> casa::Quantum< Qtype >::get | ( | ) | const |
Convert to canonical units.
| Quantum<Qtype> casa::Quantum< Qtype >::get | ( | const Unit & | s | ) | const |
Convert to specified units; any remainder will be expressed in canonical units.
E.g. conversion of Jy/pc into W/ly2 will result in W/ly2.m-1.s .
| Quantum<Qtype> casa::Quantum< Qtype >::get | ( | const Quantum< Qtype > & | other | ) | const |
Convert a Quantum to units from specified quantum (ibid example).
| void casa::Quantum< Qtype >::convert | ( | ) |
Convert to canonical units.
| void casa::Quantum< Qtype >::convert | ( | const Unit & | s | ) |
Convert to specified units; any remainder will be expressed in canonical units.
E.g. conversion of Jy/pc into W/ly2 will result in W/ly2.m-1.s .
| void casa::Quantum< Qtype >::convert | ( | const Quantum< Qtype > & | other | ) |
Convert a Quantum to units from specified quantum (ibid example).
| virtual QBase* casa::Quantum< Qtype >::clone | ( | ) | const [virtual] |
| virtual void casa::Quantum< Qtype >::print | ( | ostream & | os | ) | const [virtual] |
| virtual uInt casa::Quantum< Qtype >::type | ( | ) | const [virtual] |
| static uInt casa::Quantum< Qtype >::myType | ( | ) | [static] |
| istream& operator>> | ( | istream & | is, | |
| Quantity & | ku | |||
| ) | [friend] |
Input, only quantity is supported now.
Qtype casa::Quantum< Qtype >::qVal [private] |
1.5.1