### The Table of Units

#### Description

The table of units defines new units in terms of previously defined units. A term of units is expressed according to the ISO standard 2955 using the following operators:

`.'
multiplication
`/'
division

The exponentiation is expressed by writing an (integer) number directly behind the units symbol, e.g. a cubic meter is expressed as `m2'. Negative exponents are allowed by writing a `-' in front of the number. The use of parentheses to overcome left to right association is not allowed. Thus, the Newton is defined as `kg/m/s2'. Note that because there are no parentheses and operators strictly associate left to right, `kg/m.s2' is not a correct representation for the Newton. Using negative exponents `kg.m-1.s-2' is again the Newton. Parentheses in units are a part of the unit symbol itself. Thus, `m(H2O)' is an allowed unit symbol that can be defined distinct from `m(Hg)' and the base unit of length `m'.

The following basic units are predefined:

```
SYMBOL    BASE UNIT VECTOR       M  E
-------- ---------------------- -- --
m        [ 1, 0, 0, 0, 0, 0, 0]  1  0
s        [ 0, 1, 0, 0, 0, 0, 0]  1  0
g        [ 0, 0, 1, 0, 0, 0, 0]  1  0
c        [ 0, 0, 0, 1, 0, 0, 0]  1  0
k        [ 0, 0, 0, 0, 1, 0, 0]  1  0
cd       [ 0, 0, 0, 0, 0, 1, 0]  1  0
circ     [ 0, 0, 0, 0, 0, 0, 1]  1  0
1        [ 0, 0, 0, 0, 0, 0, 0]  1  0
10*      [ 0, 0, 0, 0, 0, 0, 0]  1  1

```

In the above table the attribute `M' is the mantissa and `E' is the exponent of logarithmical representation of the coefficient to the base 10. A unit symbol may be prepended by a prefix symbol. However, it is important that the combination of prefix and unit does not interfere with another combination of a prefix and a unit. The symbols are interpreted case insensitive according to ISO 2955. This is the reason, why the symbols for prefices as well as for the units slightly differ from the normal SI symbols. The following prefices may be used:

`ex'
exa 10^18
`pe'
peta 10^15
`t'
tera 10^12
`g'
giga 10^9
`ma'
mega 10^6
`k'
kilo 10^3
`h'
hecto 10^2
`da'
deka 2, 1
`d'
deci 10^-1
`c'
centi 10^-2
`m'
milli 10^-3
`u'
micro 10^-6
`n'
nano 10^-9
`p'
pico 10^-12
`f'
femto 10^-15
`a'
atto 10^-18

Beside the proportional conversions, i.e. those where conversion is performed simply by multiplication with a conversion coefficient, a limited set of non-proportional conversions is supported. This is used for logarithmic units like pH or db as well as for conversions of temperature scales of Celsius, Kelvin and Fahrenheit.

Proportional conversions are defined as

```
new_unit = number known_unit
```

while non-proportional conversions are defined as

```
new_unit = function_name(number known_unit)
```

where function_name must be a name known at compile time. Working with functions is a bit tricky and limits the applicability of the unit in conversions. Therefore the general rule is to avoid functions where possible. If not avoidable define new functions as follows:

1. define a pair of functions in the C++ source `cnv_func_tab.cc' and recompile/relink
2. edit the table of units
3. run through `unitmgr` to remake the database

Functions are applied as follows: If the table states:

```
foo = foo_f(12.3 bar)

```

a given foo (F) is converted to bar (B) as:

```
B = foo_from(F) * ( 12.3 bar )

```

and if a bar (B) is given, we get the foo (F) by:

```
F = foo_to(B / ( 12.3 bar ))

```

Comment lines starting with a number sign (`#') are allowed as well as blank lines.

#### Examples

The following is the current contents of the file `units.tab'.

```
# Pseudo Units, i.e. those whose dimension is 1

%       = 1 10*-2                               # percent

# Angle

sr      = 4.0528473456935108578 10*-1.circ+2    # steradian
deg     = 2.7777777777777777778 10*-3.circ      # degree (angular)
mnt     = 1.6666666666666666667 10*-2.deg       # angular minute

# Space

l       = 1 dm3                                 # liter

# Time

hr      = 3.6    10*3.s                         # hour
min     = 6      10*1.s                         # minute
d       = 8.64   10*4.s                         # day
ann     = 3.1536 10*7.s                         # year
hz      = 1 /s                                  # Herz

# Mechanics

n       = 1 kg.m/s2                             # Newton
p       = 9.80665 g.m/s2                        # pond
j       = 1 n.m                                 # Joule
cal     = 4.1868 j                              # calorie
w       = 1 j/s                                 # Watt
pal     = 1 n/m2                                # Pascal
bar     = 1 10*5.pal                            # bar
m(h2o)  = 9.806650 kpal                         # meter of water column
m(hg)   = 133.3220 kpal                         # meter of mercury column

# Temperature

cel     = cel_f(1 k)                            # degree Celsius
degf    = degf_f(0.5555555555555555556 k)       # degree Fahrenheit

# Electromagnetism

a       = 1 c/s                                 # Ampere
v       = 1 j/c                                 # Volt
ohm     = 1 v/a                                 # Ohm
sie     = 1 a/v                                 # Siemens
f       = 1 c/v                                 # Farad
wb      = 1 v.s                                 # Weber (magnetic flux)
t       = 1 wb/m2                               # Tesla (magnetic inductance)
hy      = 1 wb/a                                # Henry (inductance)

# Nuclear/Atomic/Molecular/Chemical

mol     = 6.022137 10*23                        # mole -- Avogadro's number
val     = 6.022137 10*23                        # val  -- equivalents
eq      = 6.022137 10*23                        # equivalents
ph      = ph_f(1 mol/l)                         # pH
e       = 1.6021892 10*-19.c                    # elementary charge
ev      = 1.602177 10*-19.j                     # electronvolt
u       = 1.6605655 10*-24.g                    # atomic mass unit
bq      = 1 1/s                                 # Bequerel (activity)
gy      = 1 j/s                                 # Gray (energy dose)

# Biological/Biochemical/Medical Units

sv(a)   = 0.04 gy                               # Sievert (alpha rays)
sv(b)   = 1 gy                                  # Sievert (beta rays)
sv(g)   = 1 gy                                  # Sievert (gamma rays)
sv(x)   = 1 gy                                  # Sievert (X-rays)
sv(n)   = 0.2 gy                                # Sievert (neutrons)
sv(p)   = 0.1 gy                                # Sievert (protons)

tot     = 1 1                                   # particles total count
cfu     = 1 1                                   # colony forming units
ppm     = 1 10*-6                               # parts per million
ppb     = 1 10*-9                               # parts per billion
iu      = 1 1                                   # international units
kat     = 1 mol/s                               # katal

# Photometric Units

lm      = 1 cd/sr                               # lumen (luminous flux)
lx      = 1 lm/m2                               # lux

# Levels

bel     = f_ln(1 1)                             # bel
db(spl) = f_20_lg(2 10*-5.pal)                  # decibel sound pressure
db(v)   = f_20_lg(1 v)                          # decibel volts
db(mv)  = f_20_lg(1 mv)                         # decibel millivolts
db(uv)  = f_20_lg(1 uv)                         # decibel mycrovolts
db(w)   = f_10_lg(1 w)                          # decibel watts
db(kw)  = f_10_lg(1 kw)                         # decibel kilowatts

```

#### Files

`/usr/hl7/etc/units.tab'
the source text of the units database
`/usr/hl7/lib/codes/units.db'
the compiled, hashed file of the units database