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