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