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 14The following options are available: 15.Bl -tag -width indent 16.It Fl h No , Fl -help 17Show an overview of options 18.It Fl f Ar filename No , Fl -file Ar filename 19Specify the name of the units data file to load. 20.It Fl e , Fl -exponential 21Behave as if -o '%6e' was typed. 22.It Fl q No , Fl -quiet 23Suppress prompting of the user for units and the display of statistics 24about the number of units loaded. 25.It Fl U No , Fl -unitsfile 26If the default unit file exists prints its location. 27If not, print 28.Qo 29Units data file not found 30.Qc 31.It Fl t No , Fl -terse 32Only print the result. This is used when calling 33.Nm 34from other programs for easy to parse results. 35.It Fl v No , Fl -verbose 36Print the units in the conversion output. 37Be more verbose in general. 38.It Fl o Ar format No , Fl -output-format Ar format 39Select the output format string by which numbers are printed. 40.It Fl V No , Fl -version 41Print the version number, usage, and then exit. 42.It Ar from-unit to-unit 43Allow a single unit conversion to be done directly from the command 44line. 45The program will not print prompts. 46It will print out the 47result of the single specified conversion. 48.El 49.Sh DESCRIPTION 50The 51.Nm 52program converts quantities expressed in various scales to 53their equivalents in other scales. 54The 55.Nm 56program can only 57handle multiplicative or affine scale changes. 58It works interactively by prompting 59the 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 86Powers of units can be specified using the '^' character as shown in 87the example, or by simple concatenation: 'cm3' is equivalent to 'cm^3'. 88Multiplication of units can be specified by using spaces, a dash or 89an asterisk. 90Division of units is indicated by the slash ('/'). 91Note that multiplication has a higher precedence than division, 92so 'm/s/s' is the same as 'm/s^2' or 'm/s s'. 93Division of numbers 94must be indicated using the vertical bar ('|'). 95To convert half a 96meter, you would write '1|2 meter'. 97If you write '1/2 meter' then the 98units program would interpret that as equivalent to '0.5/meter'. 99If you enter incompatible unit types, the units program will 100print a message indicating that the units are not conformable and 101it 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 110The conversion information is read from a units data file. 111The default 112file includes definitions for most familiar units, abbreviations and 113metric prefixes. 114Some 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 128The unit 'pound' is a unit of mass. 129Compound names are run together 130so 'pound force' is a unit of force. 131The unit 'ounce' is also a unit 132of mass. 133The fluid ounce is 'floz'. 134British units that differ from 135their US counterparts are prefixed with 'br', and currency is prefixed 136with its country name: 'belgiumfranc', 'britainpound'. 137When searching 138for a unit, if the specified string does not appear exactly as a unit 139name, then 140.Nm 141will try to remove a trailing 's' or a 142trailing 'es' and check again for a match. 143.Pp 144To find out what units are available read the standard units file. 145If you want to add your own units you can supply your own file. 146A unit is specified on a single line by 147giving its name and an equivalence. 148Be careful to define 149new units in terms of old ones so that a reduction leads to the 150primitive units which are marked with '!' characters. 151The 152.Nm 153program will not detect infinite loops that could be caused 154by careless unit definitions. 155Comments in the unit definition file 156begin with a '#' or '/' character at the beginning of a line. 157.Pp 158Prefixes are defined in the same was as standard units, but with 159a trailing dash at the end of the prefix name. 160If a unit is not found 161even after removing trailing 's' or 'es', then it will be checked 162against the list of prefixes. 163Prefixes will be removed until a legal 164base unit is identified. 165.Pp 166Here is an example of a short units file that defines some basic 167units. 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 182the standard units library 183.El 184.Sh AUTHORS 185.An Adrian Mariano Aq Mt adrian@cam.cornell.edu 186.Sh BUGS 187The effect of including a '/' in a prefix is surprising. 188.Pp 189Exponents entered by the user can be only one digit. 190You can work around this by multiplying several terms. 191.Pp 192The user must use | to indicate division of numbers and / to 193indicate division of symbols. 194This distinction should not 195be necessary. 196.Pp 197The program contains various arbitrary limits on the length 198of the units converted and on the length of the data file. 199.Pp 200The program should use a hash table to store units so that 201it does not take so long to load the units list and check 202for duplication. 203