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