Testing, one, two

GNU units conversion program - short introduction

Introduction

A re-occcuring problem in science and engineering is the correct conversion of one unit (say metre) into another (say yard). Usually, it is just a matter of working out the conversation factor but - if things go wrong - it can been the cause for incorrect results, errors, and dramatic accidents.

An open source program is available (with the name units) that can be of great assistence in these situations. In this post, I introduce the very fundamental way of using it but note for completeness that it is a framework that can be extended by providing new definitions of units etc.

Some examples

Suppose we need to know how many centimeters there are in one inch. After starting the unit program, it displays:

```You have:
```

and we complete this by typing inch:

```You have: inch
```

The unit program then displays the next line:

```You want:
```

and we enter cm:

```You want: cm
```

After pressing return, the unit program prints the following answer:

```* 2.54
/ 0.39370079
```

which tells us that there are 2.54cm in one inch. The second number (0.39370079) can be used for the inverse conversion: there are 0.39370079 inch within one centimetre.

We summarise this dialog for the following examples like this (and it will look like this on the screen):

```You have: inch
You want: cm
* 2.54
/ 0.39370079
```

The unit program knows many units and constants, and these can be queried. For example, if we need to know what an erg is, we could type erg, and just press return when unit asks You want::

```You have: erg
You want:
Definition: cm dyne = 1e-07 kg m^2 / s^2
```

This may raise the question what a dyne is:

```You have: dyne
You want:
Definition: cm gram / s^2 = 1e-05 kg m / s^2
```

Alternatively, if we are interested in how this erg energy relates to Joule, we can do this:

```You have: erg
You want: joule
* 1e-07
/ 10000000
```

to find that 10 million erg are equivalent to one Joule.

We can further provide a number in addition to the units for the conversion process. Here is an example to see what 32 psi are in bar:

```You have: 32 psi
You want: bar
* 2.2063223
/ 0.45324293
```

More complicated calculations can be carried out (see some examples at http://www.gnu.org/software/units/#examples).

Finally, we can also provide products and quotients of known units. For example, to convert 70 miles per hour into metre per second:

```You have: 70 miles/hour
You want: m/s
* 31.2928
/ 0.031956233
```

Putting all this together, and exploiting one of the many known constants of the unit program, we computer what fraction of the velocity of light (abbreviated c within the units program) the velocity of 70 miles represents:

```You have: 70 miles / hour
You want: c
* 1.0438155e-07
/ 9580237.6
```

70 miles per hour are - as expected - a somewhat small fraction of the velocity of light.

It is worth noting that the units program will complain if units are inconsistent. For example, magnetic fields and magnetic induction are oft used interchangably in some areas of research (and an implicit multiplication or division with the vacuum permeability is required for the conversion of one into the other). If we try to convert 1 milli Tesla into A/m we get the following message:

```You have: 1mT
You want: A/m
conformability error
0.001 kg / A s^2
1 A / m
```

Dividing the milli Tesla by mu0, makes the units equivalent:

```You have: 1mT/mu0
You want: A/m
* 795.77472
/ 0.0012566371
```

where:

```You have: mu0
You want:
Definition: 4 pi 1e-7 H/m = 1.2566371e-06 kg m / A^2 s^2
```

Further information

There is much more to say about this useful tool, and further information can be found on the webpage http://www.gnu.org/software/units/, and the documentation is available at http://www.gnu.org/software/units/manual/ .

Installation

The programme is available in all major Linux distributions as a standard package (usually with the name units), via MacPorts (gunits) for Mac OS X, Cygwin for MS Windows, or can be compiled from source.