6 .Nd conversion calculator
16 program converts quantities expressed in various scales to
17 their equivalents in other scales.
19 handle multiplicative or affine scale changes.
22 can work interactively by prompting
25 or non-interactively, providing a conversion for given arguments
30 The following options are available:
31 .Bl -tag -width "from to"
32 .It Fl e , Fl -exponential
36 (see the description of the
39 .It Fl f Ar unitsfile , Fl -file Ar unitsfile
40 Specify the name of the units data file to load.
41 This option may be specified multiple times.
42 .It Fl H Ar historyfile , Fl -history Ar historyfile
43 Ignored, for compatibility with GNU units.
45 Show an overview of options.
46 .It Fl o Ar format , Fl -output-format Ar format
47 Select the output format string by which numbers are printed.
51 Suppress prompting of the user for units and the display of statistics
52 about the number of units loaded.
54 Only print the result.
55 This is used when calling
57 from other programs for easy to parse results.
58 .It Fl U , Fl -unitsfile
59 Print the location of the default unit file if it exists.
61 .Dq Units data file not found .
62 .It Fl V , Fl -version
63 Print the version number
64 .Pq which is fixed at Dq Fx units ,
65 the path to the units data file and exit.
66 .It Fl v , Fl -verbose
67 Print the units in the conversion output.
68 Be more verbose in general.
70 Allow a single unit conversion to be done directly from the command
72 The program will not print prompts.
73 It will print out the result of the single specified conversion.
82 or a quantity with a unit
85 .Ss Mathematical operators
88 Powers of units can be specified using the
90 character as shown in the example, or by simple concatenation:
98 for details on the limitations of exponent values.
100 Multiplication of units can be specified by using spaces
107 Division of units is indicated by the slash
111 must be indicated using the vertical bar
115 Note that multiplication has a higher precedence than division,
123 The conversion information is read from a units data file.
125 file includes definitions for most familiar units, abbreviations and
127 Some constants of nature included are:
129 .Bl -column -offset indent -compact "mercury"
130 .It "pi ratio of circumference to diameter"
131 .It "c speed of light"
132 .It "e charge on an electron"
133 .It "g acceleration of gravity"
134 .It "force same as g"
135 .It "mole Avogadro's number"
136 .It "water pressure per unit height of water"
137 .It "mercury pressure per unit height of mercury"
138 .It "au astronomical unit"
144 Compound names are run together
150 is also a unit of mass.
153 British units that differ from
154 their US counterparts are prefixed with
156 and currency is prefixed with its country name:
157 .Dq Ic belgiumfranc ,
158 .Dq Ic britainpound .
160 for a unit, if the specified string does not appear exactly as a unit
163 will try to remove a trailing
167 and check again for a match.
168 .Ss Units file format
169 To find out what units are available read the standard units file.
170 If you want to add your own units you can supply your own file.
171 A unit is specified on a single line by
172 giving its name and an equivalence.
174 new units in terms of old ones so that a reduction leads to the
175 primitive units which are marked with
180 program will not detect infinite loops that could be caused
181 by careless unit definitions.
182 Comments in the unit definition file
187 character at the beginning of a line.
189 Prefixes are defined in the same way as standard units, but with
192 at the end of the prefix name.
193 If a unit is not found
194 even after removing trailing
198 then it will be checked against the list of prefixes.
199 Prefixes will be removed until a legal
200 base unit is identified.
204 The colon-separated list of root directories at which
207 .Pa /usr/share/misc/definitions.units .
212 .Dq Li /tmp:/:/usr/local ,
215 flags are provided, and
216 .Pa /usr/share/misc/definitions.units
219 tries to open the following files as the default units file:
220 .Pa /tmp/usr/share/misc/definitions.units ,
221 .Pa /usr/share/misc/definitions.units ,
223 .Pa /usr/local/usr/share/misc/definitions.units .
226 .Bl -tag -width /usr/share/misc/definitions.units -compact
227 .It Pa /usr/share/misc/definitions.units
228 The standard units file.
234 .It Sy Example 1 : No Simple conversion of units
236 This example shows how to do simple conversions, for example from gigabytes
238 .Bd -literal -offset 2n
239 .Li $ Ic units -o %0.f -t '4 gigabytes' bytes
245 part of the command is required to print the result in a non-scientific
246 notation (e.g, 4294967296 instead of 4.29497e+09).
247 .It Sy Example 2 : No Interactive usage
249 Here is an example of an interactive session where the user is prompted for
251 .Bd -literal -offset 2n
252 .Li You have : Ic meters
253 .Li You want : Ic feet
257 .Li You have : Ic cm^3
258 .Li You want : Ic gallons
262 .Li You have : Ic meters/s
263 .Li You want : Ic furlongs/fortnight
267 .Li You have : Ic 1|2 inch
272 .Li You have : Ic 85 degF
273 .Li You want : Ic degC
276 .It Sy Example 3 : No Difference between Do Ic \&| Dc No and Do Ic / Dc No division
278 The following command shows how to convert half a meter to centimeters.
279 .Bd -literal -offset 2n
280 .Li $ Ic units '1|2 meter' cm
286 prints the expected result because the division operator for numbers
290 Using the division operator for units
292 would result in an error:
293 .Bd -literal -offset 2n
294 .Li $ Ic units '1/2 meter' cm
306 which is not conformable to
308 .It Sy Example 4 : No Simple units file
309 Here is an example of a short units file that defines some basic
312 .Bl -column -offset 2n -compact "minute"
322 .It Sy Example 5 : No Viewing units and conversions of the default units file
323 The following shell one-liner allows the user to view the contents of the
325 .Bd -literal -offset 2n
326 .Li $ Ic less \&"$(units -U)"
331 .It can't find units file '%s'
332 The default units file is not in its default location
334 and it is not present in any file tree starting with their roots at directories from
336 .Pq see Sx ENVIRONMENT .
337 .It cap_rights_limit\&() failed
340 .It conformability error
341 It is not possible to reduce the given units to one common unit:
342 they are not conformable.
343 Instead of a conversion,
345 will display the reduced form for each provided unit:
346 .Bd -literal -offset 2n
347 .Li You have : Ic ergs/hour
348 .Li You want : Ic fathoms kg^2 / day
350 2.7777778e-11 kg m^2 / sec^3
351 2.1166667e-05 kg^2 m / sec
353 .It Could not initialize history
359 .It memory for prefixes exceeded in line %d
360 Over 100 prefixes were defined.
361 .It memory for units exceeded in line %d
362 Over 1000 prefixes were defined.
363 .It memory overflow in unit reduction
364 The requested conversion involves too many units
366 .It redefinition of prefix '%s' on line %d ignored
368 .It redefinition of unit '%s' on line %d ignored
370 .It unexpected end of prefix on line %d
372 .It unexpected end of unit on line %d
374 .It Units data file not found
375 The default units file is missing.
376 .It unable to enter capability mode
379 .It unable to open units file '%s'
380 One of the user-specified units files cannot be opened.
381 .It unit reduces to zero
383 .It unknown unit '%s'
384 The provided unit cannot be found in the units file.
385 .It WARNING: conversion of non-proportional quantities.
391 because the units are not proportional.
392 The warning is printed when a quantity is a part of the
395 It can be illustrated on an example of conversion from Fahrenheit to Celsius:
396 .Bd -literal -offset 2n
397 .Li $ Ic units \&"degF" \&"degC"
398 (-> x*0.55555556g -17.777778g)
400 .Li $ Ic units \&"degF" \&"1 degC"
401 WARNING: conversion of non-proportional quantities.
402 (-> x*0.55555556g -17.777778g)
404 .Li $ Ic units \&"1 degF" \&"1 degC"
405 WARNING: conversion of non-proportional quantities.
419 The manual page was significantly rewritten in
422 .An Mateusz Piotrowski Aq Mt 0mp@FreeBSD.org .
424 .An Adrian Mariano Aq Mt adrian@cam.cornell.edu
426 The effect of including a
428 in a prefix is surprising.
430 Exponents entered by the user can be only one digit.
431 You can work around this by multiplying several terms.
435 to indicate division of numbers and
437 to indicate division of symbols.
438 This distinction should not
441 The program contains various arbitrary limits on the length
442 of the units converted and on the length of the data file.
444 The program should use a hash table to store units so that
445 it does not take so long to load the units list and check
448 It is not possible to convert a negative value.
453 does not handle reductions of long lists of units very well:
454 .Bd -literal -offset 2n
455 .Li $ Ic units \&"$(yes m | head -n 154)" \&"$(yes cm | head -n 154)"
458 .Li $ Ic units \&"$(yes m | head -n 333)" \&"$(yes cm | head -n 333)"
461 .Li $ Ic units \&"$(yes m | head -n 500)" \&"$(yes cm | head -n 500)"
462 units: memory overflow in unit reduction
466 .Li $ Ic units \&"$(yes m | head -n 501)" \&"$(yes cm | head -n 501)"
467 units: memory overflow in unit reduction
468 units: memory overflow in unit reduction
469 units: memory overflow in unit reduction