All of the units and prefixes that units
can convert are defined
in the units data file. If you want to add your own units, you can
supply
your own file.
A unit is specified on a single line by
giving its name and an equivalence.
Comments start with a `#' character, which can appear anywhere in a line.
Be careful to define
new units in terms of old ones so that a reduction leads to the
primitive units, which are marked with `!' characters.
When adding new units, be sure to use the `-c' option to check that
the new units reduce properly. If you define any units which contain
`+' characters, carefully check them because the `-c' option
will not catch non-conformable sums.
If you create a loop in the units definitions, then units
will
hang when invoked with the `-c' options. You will need to
use the `--check-verbose' option which prints out each unit as it
checks them. The program will still hang, but the last unit printed
will be the unit which caused the infinite loop.
Here is an example of a short units file that defines some basic units:
m ! # The meter is a primitive unit sec ! # The second is a primitive unit micro- 1e-6 # Define a prefix minute 60 sec # A minute is 60 seconds hour 60 min # An hour is 60 minutes inch 0.0254 m # Inch defined in terms of meters ft 12 inches # The foot defined in terms of inches mile 5280 ft # And the mile
A unit which ends with a `-' character is a prefix. If a prefix contains a `/' character, then when it is applied to a unit, that unit will be in the denominator. So the definition `half- 1/2' would give a `halfmeter' equal to `1 / 2 meter'. For this reason, the `/' character should be avoided in prefixes.
Go to the first, previous, next, last section, table of contents.