Hints, Tips and Solutions

Q. How do I convert a value from one set of units into another?

A. Use the DBINTERNAL CONVERT.UNITS command.

1) Introduction

The command CONVERT.UNITS was introduced in DBINTERNAL version 2.5.2.C. This allows the conversion of a value in one set of units into a value in another set of units that have the same dimension.

For example it can convert values from one set of units into another:

convert.units 0.1 in/s into um/min
0.1 in / s == 152400 um / min

Alternatively it can check that two different representations of a unit are the same thing (such as the viscosity coefficients in ATHENA and VICTORY Process)

convert.units 1 g/(cm.s) into (dyn.s)/cm2
1 g / cm.s == 1 dyn.s / cm2

2) Units and SI prefixes.

Units are usually indicated by their standard unit symbol: “m” for meter, “s” for second, “dyn” for dyne, etc. This symbol is case sensitive. The symbol for a liter is a lower case “l” (an upper case “L” is the symbol for the lambert). The symbol for an electron volt is “eV” (none of “ev”, “Ev”, or “EV” would be recognized as an electron volt).

Several standard symbols cannot be represented in the Latin alphabet and so have equivalent names: “Ang” for Å, “Ohm” for Ω, “degC” for °C, and “degF” for °F.

If the same unit means different things then the specific meaning of a unit must be indicated. For example “atu” is the standard symbol for atomic unit, but there are many atomic units. The specific atomic unit required must be specified by adding the type, in brackets, after the unit name.

convert 1 atu (time) into s
1 atu (time) == 2.41888e-17 s
convert 1 atu (energy) into eV
1 atu (energy) == 27.2114 eV

This also occurs with several units that are shared between the US and the Imperial measurement systems, see section 5.

Any of the SI prefixes can be used with any unit. There must be no space between the SI prefix and the unit it is associated with. The letter “u” is used instead of µ to indicate 10-6. Tom Duff of Bell Labs observed that a nanocentury is about seconds.

convert.units 1 ncentury into s
1 ncentury == 3.1557 s

If there is a clash between a prefixed unit and a bare unit then the parser will recognize the bare unit. The symbol for inch is “in”, therefore “min” could be “milli-inch”, but the unit “min” will be parsed as “minute”.

Any number that comes immediately after a unit is assumed to be a power that the unit is raised to. This number can be a positive or negative integer, fraction, or decimal. Any space between the unit and the number is ignored. The numbers may, but don’t have to be, enclosed in brackets. The “^” symbol can be used to make the expression more readable if desired. The following units all have the dimension of a volume (“b” is “barn”, an SI unit of area); “m^3”, “m 3”, “m3”, “b^3/2”, “b(3/2)”, “b 3/2”, “b1.5”.

Any two adjacent units are assumed to be multiplied. Units are adjacent if they are separated by spaces, by the “.” sign, or by an exponent. Dynamic viscosity is “Pa.s” or “Pa s”. Energy is “m2kg s-2” (where the exponent of “m” separates “m2” and “kg”).

The solidus “/” (when not being used in an exponent fraction) switches from the numerator to the denominator (or back again) where any subsequent units are added. The energy units could have been written “m2 kg / s2”. Spaces around the solidus are not needed but can be used to make the units easier to read.

A repeated solidus is allowed, but it probably doesn’t do what is expected. An old style of writing the acceleration was “ft/s/s”. In this parser the “ft” is added to the numerator, the first solidus indicates subsequent units should be added to the denominator, therefore the first “s” is added to the denominator, the second solidus indicates subsequent units should be added to the numerator, therefore the second “s” is added to the numerator. The two “s” will cancel leaving a length rather than an acceleration.

convert.units 1 ft/s/s into m
1 ft == 0.3048 m

The units of acceleration should be defined as “ft/s2”, or “ft.s-2”, or “(ft/s)/s”.

3) The “D” prefix

Most of the units are “ratio scale” units which means that the origin is an absolute zero and a single unit has the same magnitude everywhere on the scale.

However the common temperature units, degrees Celsius and degrees Fahrenheit, are “interval scale” units, which means that a single unit has the same magnitude everywhere on the scale but the origin is not an absolute zero.

There is a potential for confusion when converting values between “interval scale” units and “ratio scale” units. For example, suppose a beaker of water was at 41 °F and it was warmed up by 45 °F to 86 °F. If these temperatures were converted into Kelvin then

convert.units 41 degF into K
41 degF == 278.15 K
convert.units 45 degF into K
45 degF == 280.372 K
convert.units 86 degF into K
86 degF == 303.15 K

Obviously 278.15 K + 280.372 K is not equal to 303.15 K.

The problem is that the difference (45 °F) should be measured on a “ratio scale” rather than the normal Fahrenheit “interval scale”. The unit needs to be prefixed with a “D” to indicate this (there must be no space between the D and its associated unit).

convert.units 45 DdegF into K
45 degF == 25 K

And 278.15 K + 25 K = 303.15 K.

If the “D” is used with an SI prefix on the unit then the “D” must come before the SI prefix.

convert.units 9 DmdegF into uK
9 mdegF == 5000 uK

To convert into a difference unit the “D” prefix must occur on the first unit

convert.units 5 K into DdegF
5 K == -450.67 degF
convert.units 5 DK into degF
5 K == 9 degF

A “degF” or “degC” in a compound unit is treated as a “ratio scale” unit, rather than an “interval scale” unit.

convert.units 5 J/degF into J/K
5 J / degF == 9 J / K
convert.units 9 degF/W into K/W
9 degF / W == 5 K / W

4) Incompatible units.

If an attempt is made to convert one unit into an incompatible set of units then the conversion fails and a warning is issued.

convert.units 1 W into J
The conversion failed
The dimensions of “W”
[LENGTH^2.MASS.TIME^-3]
Are incompatible with “J”
[LENGTH^2.MASS.TIME^-2]
[LENGTH^2.MASS.TIME^-3] ==
[LENGTH^2.MASS.TIME^-2] * [TIME^1]

The term at the far right of the last line, after the “*”, indicates what dimensions need to be added to the required units to make them dimensionally compatible with the initial units.

convert.units 1 W into J.s-1
1 W == 1 J / s

This can be used to check the dimensions of a set of units: by attempting to convert one unit into a dimensionless unit (indicated by a unit of “1”).

convert.units 1 W into 1
The conversion failed
The dimensions of “W”
[LENGTH^2.MASS.TIME^-3]
Are incompatible with “1” []
[LENGTH^2.MASS.TIME^-3] ==
[] * [LENGTH2.MASS.TIME^-3
]

Hence the dimensions of “W” are “L2.M.T-3”.

5) US and Imperial units.

Many of the traditional volume units, and various other units, have different magnitudes in the US and Imperial systems. For example:

convert.units 1 gal (us) into gal (imp)
1 gal (us) == 0.832674 gal (imp)

Initially all such unit names must be qualified by “(us)” or “(imp)”. If it is known that one type of system is predominant then the CONVERT.UNITS.OPTIONS command can be used to indicate which system an unqualified unit should belong to.

convert.units.options us
convert.units 1 gal into gal (imp)
1 gal (us) == 0.832674 gal (imp)

convert.units.options imp
convert.units 1 gal into gal (us)
1 gal (imp) == 1.20095 gal (us)