xref: /freebsd/usr.bin/units/units.1 (revision 1669d8afc64812c8d2d1d147ae1fd42ff441e1b1)
1.\" $FreeBSD$
2.Dd July 14, 1993
3.Dt UNITS 1
4.Os
5.Sh NAME
6.Nm units
7.Nd conversion program
8.Sh SYNOPSIS
9.Nm
10.Op Fl f Ar filename
11.Op Fl qv
12.Op Ar from-unit to-unit
13.Sh OPTIONS
14The following options are available:
15.Bl -tag -width indent
16.It Fl f Ar filename
17Specify the name of the units data file to load.
18.It Fl q
19Suppress prompting of the user for units and the display of statistics
20about the number of units loaded.
21.It Fl v
22Print the version number.
23.It Ar from-unit to-unit
24Allow a single unit conversion to be done directly from the command
25line.
26The program will not print prompts.
27It will print out the
28result of the single specified conversion.
29.El
30.Sh DESCRIPTION
31The
32.Nm
33program converts quantities expressed in various scales to
34their equivalents in other scales.
35The
36.Nm
37program can only
38handle multiplicative scale changes.
39It cannot convert Celsius
40to Fahrenheit, for example.
41It works interactively by prompting
42the user for input:
43.Bd -literal
44    You have: meters
45    You want: feet
46            * 3.2808399
47            / 0.3048
48
49    You have: cm^3
50    You want: gallons
51            * 0.00026417205
52            / 3785.4118
53
54    You have: meters/s
55    You want: furlongs/fortnight
56            * 6012.8848
57            / 0.00016630952
58
59    You have: 1|2 inch
60    You want: cm
61            * 1.27
62            / 0.78740157
63.Ed
64.Pp
65Powers of units can be specified using the '^' character as shown in
66the example, or by simple concatenation: 'cm3' is equivalent to 'cm^3'.
67Multiplication of units can be specified by using spaces, a dash or
68an asterisk.
69Division of units is indicated by the slash ('/').
70Note that multiplication has a higher precedence than division,
71so 'm/s/s' is the same as 'm/s^2' or 'm/s s'.
72Division of numbers
73must be indicated using the vertical bar ('|').
74To convert half a
75meter, you would write '1|2 meter'.
76If you write '1/2 meter' then the
77units program would interpret that as equivalent to '0.5/meter'.
78If you enter incompatible unit types, the units program will
79print a message indicating that the units are not conformable and
80it will display the reduced form for each unit:
81.Bd -literal
82    You have: ergs/hour
83    You want: fathoms kg^2 / day
84    conformability error
85            2.7777778e-11 kg m^2 / sec^3
86            2.1166667e-05 kg^2 m / sec
87.Ed
88.Pp
89The conversion information is read from a units data file.
90The default
91file includes definitions for most familiar units, abbreviations and
92metric prefixes.
93Some constants of nature included are:
94.Pp
95.Bl -column -offset indent -compact "mercury"
96.It "pi	ratio of circumference to diameter
97.It "c	speed of light
98.It "e	charge on an electron
99.It "g	acceleration of gravity
100.It "force	same as g
101.It "mole	Avogadro's number
102.It "water	pressure per unit height of water
103.It "mercury	pressure per unit height of mercury
104.It "au	astronomical unit
105.El
106.Pp
107The unit 'pound' is a unit of mass.
108Compound names are run together
109so 'pound force' is a unit of force.
110The unit 'ounce' is also a unit
111of mass.
112The fluid ounce is 'floz'.
113British units that differ from
114their US counterparts are prefixed with 'br', and currency is prefixed
115with its country name: 'belgiumfranc', 'britainpound'.
116When searching
117for a unit, if the specified string does not appear exactly as a unit
118name, then
119.Nm
120will try to remove a trailing 's' or a
121trailing 'es' and check again for a match.
122.Pp
123To find out what units are available read the standard units file.
124If you want to add your own units you can supply your own file.
125A unit is specified on a single line by
126giving its name and an equivalence.
127Be careful to define
128new units in terms of old ones so that a reduction leads to the
129primitive units which are marked with '!' characters.
130The
131.Nm
132program will not detect infinite loops that could be caused
133by careless unit definitions.
134Comments in the unit definition file
135begin with a '/' character at the beginning of a line.
136.Pp
137Prefixes are defined in the same was as standard units, but with
138a trailing dash at the end of the prefix name.
139If a unit is not found
140even after removing trailing 's' or 'es', then it will be checked
141against the list of prefixes.
142Prefixes will be removed until a legal
143base unit is identified.
144.Pp
145Here is an example of a short units file that defines some basic
146units.
147.Pp
148.Bl -column -offset indent -compact "minute"
149.It "m	!a!
150.It "sec	!b!
151.It "micro-	1e-6
152.It "minute	60 sec
153.It "hour	60 min
154.It "inch	0.0254 m
155.It "ft	12 inches
156.It "mile	5280 ft
157.El
158.Sh FILES
159.Bl -tag -width /usr/share/misc/units.lib -compact
160.It Pa /usr/share/misc/units.lib
161the standard units library
162.El
163.Sh AUTHORS
164.An Adrian Mariano Aq adrian@cam.cornell.edu
165.Sh BUGS
166The effect of including a '/' in a prefix is surprising.
167.Pp
168Exponents entered by the user can be only one digit.
169You can work around this by multiplying several terms.
170.Pp
171The user must use | to indicate division of numbers and / to
172indicate division of symbols.
173This distinction should not
174be necessary.
175.Pp
176The program contains various arbitrary limits on the length
177of the units converted and on the length of the data file.
178.Pp
179The program should use a hash table to store units so that
180it does not take so long to load the units list and check
181for duplication.
182