casacore
Public Member Functions | Static Public Member Functions | List of all members
casacore::UnitMap Class Reference

contains all simple known physical units More...

#include <UnitMap.h>

Public Member Functions

 UnitMap ()
 Default constructor of maps. More...
 
 ~UnitMap ()
 Destructor. More...
 

Static Public Member Functions

static void releaseUM ()
 Remove all maps (just to get no memory leaks at end of program) More...
 
static void putCache (const String &s, const UnitVal &val)
 Save a definition of a full unit name in the cache (the cache will be cleared if getting too large (200 entries) More...
 
static void removeUser (const String &name)
 Remove a user unit. More...
 
static void removeUser (const UnitName &name)
 
static void clearCache ()
 Clear out the cache. More...
 
static void addFITS ()
 Define FITS related unit names. More...
 
static void clearFITS ()
 Clear FITS related units from user list. More...
 
static Unit fromFITS (const Unit &un)
 Translate a FITS unit to the proper units. More...
 
static Unit toFITS (const Unit &un)
 Translate to a FITS unit. More...
 
static Bool getPref (const String &s, UnitName &name)
 Check if a unit name is known, and return its value if True. More...
 
static Bool getCache (const String &s, UnitVal &val)
 Get a cached definition. More...
 
static Bool getUnit (const String &s, UnitName &name)
 Get a standard unit definition (search order: User, Customary, SI) More...
 
static void putUser (const String &s, const UnitVal &val)
 Define a user defined standard unit. More...
 
static void putUser (const String &s, const UnitVal &val, const String &name)
 
static void putUser (const UnitName &name)
 
static map< String, UnitName > * mapPref
 Decimal prefix list. More...
 
static map< String, UnitName > * mapDef
 Defining SI unit list. More...
 
static map< String, UnitName > * mapSI
 SI unit list. More...
 
static map< String, UnitName > * mapCust
 Customary list. More...
 
static map< String, UnitName > * mapUser
 User defined unit list. More...
 
static map< String, UnitVal > * mapCache
 Cached list. More...
 
static Bool doneFITS
 FITS unit list inclusion. More...
 
static Mutex fitsMutex
 
static void list (ostream &os)
 List some part of the standard unit lists on cout or stream. More...
 
static void list ()
 
static void listCache (ostream &os)
 List all units in cache. More...
 
static void listCache ()
 
static void listPref (ostream &os)
 List all prefixes. More...
 
static void listPref ()
 
static void listDef (ostream &os)
 List all defining units. More...
 
static void listDef ()
 
static void listSI (ostream &os)
 List all SI units. More...
 
static void listSI ()
 
static void listCust (ostream &os)
 List all customary units. More...
 
static void listCust ()
 
static void listUser (ostream &os)
 List all user defined units. More...
 
static void listUser ()
 
static const map< String, UnitName > & givePref ()
 Return the different maps. More...
 
static const map< String, UnitName > & giveDef ()
 
static const map< String, UnitName > & giveSI ()
 
static const map< String, UnitName > & giveCust ()
 
static const map< String, UnitName > & giveUser ()
 
static const map< String, UnitVal > & giveCache ()
 
 UnitMap (const UnitMap &other)
 Copy constructor (not implemented) More...
 
UnitMapoperator= (const UnitMap &other)
 Copy assignment (not implemented) More...
 
static Bool getNameFITS (const UnitName *&name, uInt which)
 Get the name of a FITS unit. More...
 
static const StringgetStringFITS (uInt which)
 Get the belonging unit to a FITS unit. More...
 
static void initUM ()
 Initialise the static maps. More...
 
static void doInitUM (void *)
 
static void initUMPrefix ()
 Bits and pieces of initUM() to get compilation speed improved. More...
 
static void initUMSI1 ()
 
static void initUMSI2 ()
 
static void initUMCust1 ()
 
static void initUMCust2 ()
 
static void initUMCust3 ()
 

Detailed Description

contains all simple known physical units

Intended use:

Public interface

Review Status

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

Prerequisite

Etymology

Based on Units and the Casacore container classes called 'Map'

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 UnitMap class contains the known standard basic units, and any other basic unit defined by the user of the Unit related classes. The known units are divided into 5 different groups:

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

The full list of known units can be viewed by running the tUnit test program.
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";

Information about the contents of the unit maps can be obtained by the Bool functions (False if not present):

The standard units can be viewed by the following commands, which output to cout:

Units can be defined in the user list by:
Tip: The cache will be cleared if a user defined unit is overwritten, to make sure no old value will be used;

UnitMap::putUser("tag", UnitVal(factor,"unit"), "full name (optional)");
or:
UnitMap::putUser(UnitName);


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 special set of 'units' used in FITS datasets can be added by the command

This set can be cleared from the user table by:

Note that Unitmap keeps track of the inclusion of the FITS inclusion, making multiple calls inexpensive. The list of current FITS units can be viewed by running the tUnit program, or looking at the FITSunit table.

Once the UnitMap::addFITS() has been run, the FITS units can be used as any other unit. In addition, a FITS unit can be translated to standard SI units by a call to Unit UnitMap::fromFITS(const Unit). Any unit that is defined as a standard FITS unit will be translated. Unknown ones will not be translated, making the way clear for having standard units in a FITS units string. A comparable toFITS() translates in the same way in the reversed direction.

The cache can be cleared by:

Example

Check for legal prefix:

UnitName myUnit;
if (UnitMap::getPref("k", myUnit)) { cout << "k has value " << myUnit;}

Define a value for the unit 'beam':

UnitMap::putUser("beam",UnitVal(C::pi * 0.1, "\"_2"),"telescope beam");

List current cache:

Motivation

Standard list available to try to enhance use of SI and related units

To Do

Definition at line 189 of file UnitMap.h.

Constructor & Destructor Documentation

§ UnitMap() [1/2]

casacore::UnitMap::UnitMap ( )

Default constructor of maps.

§ ~UnitMap()

casacore::UnitMap::~UnitMap ( )

Destructor.

§ UnitMap() [2/2]

casacore::UnitMap::UnitMap ( const UnitMap other)
private

Copy constructor (not implemented)

Member Function Documentation

§ addFITS()

static void casacore::UnitMap::addFITS ( )
static

Define FITS related unit names.

§ clearCache()

static void casacore::UnitMap::clearCache ( )
static

Clear out the cache.

§ clearFITS()

static void casacore::UnitMap::clearFITS ( )
static

Clear FITS related units from user list.

§ doInitUM()

static void casacore::UnitMap::doInitUM ( void *  )
staticprivate

§ fromFITS()

static Unit casacore::UnitMap::fromFITS ( const Unit un)
static

Translate a FITS unit to the proper units.

Note that this is a translation of the string only, no conversion. Unknown FITS units are not translated. Hence any new definition of the FITS units will work ok

§ getCache()

static Bool casacore::UnitMap::getCache ( const String s,
UnitVal val 
)
static

Get a cached definition.

§ getNameFITS()

static Bool casacore::UnitMap::getNameFITS ( const UnitName *&  name,
uInt  which 
)
staticprivate

Get the name of a FITS unit.

§ getPref()

static Bool casacore::UnitMap::getPref ( const String s,
UnitName name 
)
static

Check if a unit name is known, and return its value if True.

Get a prefix definition from key

§ getStringFITS()

static const String& casacore::UnitMap::getStringFITS ( uInt  which)
staticprivate

Get the belonging unit to a FITS unit.

§ getUnit()

static Bool casacore::UnitMap::getUnit ( const String s,
UnitName name 
)
static

Get a standard unit definition (search order: User, Customary, SI)

§ giveCache()

static const map<String, UnitVal>& casacore::UnitMap::giveCache ( )
static

§ giveCust()

static const map<String, UnitName>& casacore::UnitMap::giveCust ( )
static

§ giveDef()

static const map<String, UnitName>& casacore::UnitMap::giveDef ( )
static

§ givePref()

static const map<String, UnitName>& casacore::UnitMap::givePref ( )
static

Return the different maps.

§ giveSI()

static const map<String, UnitName>& casacore::UnitMap::giveSI ( )
static

§ giveUser()

static const map<String, UnitName>& casacore::UnitMap::giveUser ( )
static

§ initUM()

static void casacore::UnitMap::initUM ( )
staticprivate

Initialise the static maps.

§ initUMCust1()

static void casacore::UnitMap::initUMCust1 ( )
staticprivate

§ initUMCust2()

static void casacore::UnitMap::initUMCust2 ( )
staticprivate

§ initUMCust3()

static void casacore::UnitMap::initUMCust3 ( )
staticprivate

§ initUMPrefix()

static void casacore::UnitMap::initUMPrefix ( )
staticprivate

Bits and pieces of initUM() to get compilation speed improved.

§ initUMSI1()

static void casacore::UnitMap::initUMSI1 ( )
staticprivate

§ initUMSI2()

static void casacore::UnitMap::initUMSI2 ( )
staticprivate

§ list() [1/2]

static void casacore::UnitMap::list ( ostream &  os)
static

List some part of the standard unit lists on cout or stream.

List all known unit symbols

§ list() [2/2]

static void casacore::UnitMap::list ( )
static

§ listCache() [1/2]

static void casacore::UnitMap::listCache ( ostream &  os)
static

List all units in cache.

§ listCache() [2/2]

static void casacore::UnitMap::listCache ( )
static

§ listCust() [1/2]

static void casacore::UnitMap::listCust ( ostream &  os)
static

List all customary units.

§ listCust() [2/2]

static void casacore::UnitMap::listCust ( )
static

§ listDef() [1/2]

static void casacore::UnitMap::listDef ( ostream &  os)
static

List all defining units.

§ listDef() [2/2]

static void casacore::UnitMap::listDef ( )
static

§ listPref() [1/2]

static void casacore::UnitMap::listPref ( ostream &  os)
static

List all prefixes.

§ listPref() [2/2]

static void casacore::UnitMap::listPref ( )
static

§ listSI() [1/2]

static void casacore::UnitMap::listSI ( ostream &  os)
static

List all SI units.

§ listSI() [2/2]

static void casacore::UnitMap::listSI ( )
static

§ listUser() [1/2]

static void casacore::UnitMap::listUser ( ostream &  os)
static

List all user defined units.

§ listUser() [2/2]

static void casacore::UnitMap::listUser ( )
static

§ operator=()

UnitMap& casacore::UnitMap::operator= ( const UnitMap other)
private

Copy assignment (not implemented)

§ putCache()

static void casacore::UnitMap::putCache ( const String s,
const UnitVal val 
)
static

Save a definition of a full unit name in the cache (the cache will be cleared if getting too large (200 entries)

§ putUser() [1/3]

static void casacore::UnitMap::putUser ( const String s,
const UnitVal val 
)
static

Define a user defined standard unit.

If the unit is being redefined, and it has already been used in a user's Unit variable, the value cached in that variable will not change.

§ putUser() [2/3]

static void casacore::UnitMap::putUser ( const String s,
const UnitVal val,
const String name 
)
static

§ putUser() [3/3]

static void casacore::UnitMap::putUser ( const UnitName name)
static

§ releaseUM()

static void casacore::UnitMap::releaseUM ( )
static

Remove all maps (just to get no memory leaks at end of program)

§ removeUser() [1/2]

static void casacore::UnitMap::removeUser ( const String name)
static

Remove a user unit.

§ removeUser() [2/2]

static void casacore::UnitMap::removeUser ( const UnitName name)
static

§ toFITS()

static Unit casacore::UnitMap::toFITS ( const Unit un)
static

Translate to a FITS unit.

Member Data Documentation

§ doneFITS

Bool casacore::UnitMap::doneFITS
staticprivate

FITS unit list inclusion.

Definition at line 333 of file UnitMap.h.

§ fitsMutex

Mutex casacore::UnitMap::fitsMutex
staticprivate

Definition at line 334 of file UnitMap.h.

§ mapCache

map<String, UnitVal>* casacore::UnitMap::mapCache
staticprivate

Cached list.

Definition at line 331 of file UnitMap.h.

§ mapCust

map<String, UnitName>* casacore::UnitMap::mapCust
staticprivate

Customary list.

Definition at line 325 of file UnitMap.h.

§ mapDef

map<String, UnitName>* casacore::UnitMap::mapDef
staticprivate

Defining SI unit list.

Definition at line 319 of file UnitMap.h.

§ mapPref

map<String, UnitName>* casacore::UnitMap::mapPref
staticprivate

Decimal prefix list.

Definition at line 316 of file UnitMap.h.

§ mapSI

map<String, UnitName>* casacore::UnitMap::mapSI
staticprivate

SI unit list.

Definition at line 322 of file UnitMap.h.

§ mapUser

map<String, UnitName>* casacore::UnitMap::mapUser
staticprivate

User defined unit list.

Definition at line 328 of file UnitMap.h.


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