Note that the man page is not the primary manual, but a hacked output for people that really like a man page. So we adjusted the hack and I believe the empty sections are fixed. See attached.
On Sun, Apr 07, 2019 at 02:44:24AM +0800, 積丹尼 Dan Jacobson wrote: > X-Debbugs-Cc: adri...@gnu.org > Package: units > Version: 2.18-1 > Severity: minor > File: /usr/share/man/man1/units.1.gz > > We see AUTHOR and then it is blank, on man page.
.\"Do not edit this file. It was created from units.texinfo .\"using texi2man version 1.01w on Tue Apr 2 21:26:50 EDT 2019 .\"This manual is for GNU Units (version 2.18), .\"which performs units conversions and units calculations. .\" .\"Copyright \(co 1996, 1997, 1999, 2000, 2001, 2002, 2004, 2005, 2007, .\"2011\-2019 Free Software Foundation, Inc. .\" .\"Permission is granted to copy, distribute and/or modify this document .\"under the terms of the GNU Free Documentation License, Version 1.3 or .\"any later version published by the Free Software Foundation; with no .\"Invariant Sections, with no Front-Cover Texts, and with no Back-Cover .\"Texts. .TH UNITS 1 "19 March 2019" .\" .if \n(.g \{\ . \" ensure that ASCII circumflex U+005E (^) is not remapped . tr ^\(ha . \" override translation in troffrc . ie '\*[.T]'utf8' .tr `\(oq'\(cq . \" override mapping of ` to 60h with Tascii; assume . \" we don't need a backquote for an example . el .if n .tr `' .\} .\" ellipsis: space periods with troff but not with nroff .if n .ds El \&... .if t .ds El \&.\ .\ . .if n \{\ . tr \(bu* . \" override translation to MIDDLE DOT . if \n(.g .if '\*(.T'utf8' .tr \(bu\(bu . if \n(.g .if '\*(.T'cp1252' .tr \(bu\(bu . if \n(.g .if '\*(.T'ansi' .tr \(bu\(bu .\} .\" .\" Extensions to man macros .\" .\" set handling of single quotes: 0=>straight, >0=>left and right .nr tQ 0 .\" groff only .if '\*(.T'utf8' .nr tQ 1 .\" non-standard devices: Windows code page 1252 .if '\*(.T'cp1252' .nr tQ 1 .if '\*(.T'ansi' .nr tQ 1 .\" Constant-width font .de CW .hy 0 .\" nroff can't show CW font, so enclose in single quotes .if n \{\ . ie \\n(.g \{\ . \" use proper opening and closing single quotes . ie \\n(tQ>0 \{\ . ie \\n(.$>2 \&\\$1\(oq\\$2\(cq\\$3 . el \&\(oq\\$1\(cq\\$2 . \} . \" ensure neutral single quotes with Tascii . el \{\ . ie \\n(.$>2 \&\\$1\(aq\\$2\(aq\\$3 . el \&\(aq\\$1\(aq\\$2 . \} . \} . \" legacy nroff doesn't have 'aq', so use ' and hope for the best . el \{\ . ie \\n(.$>2 \&\\$1'\\$2'\\$3 . el \&'\\$1'\\$2 . \} .\} .\" troff can change fonts, so no need for quotes .if t \{\ . ie \\n(.$>2 \&\\$1\f(CW\\$2\fR\\$3 . el \&\f(CW\\$1\fR\\$2 .\} .hy 14 .. .\" Constant-width oblique font .de CI .hy 0 .\" nroff can't show CW font, so enclose in single quotes .if n \{\ . ie \\n(.g \{\ . \" use proper opening and closing single quotes . ie \\n(tQ \{\ . ie \\n(.$>2 \&\\$1\(oq\fI\\$2\fR\(cq\\$3 . el \&\(oq\fI\\$1\fR\(cq\\$2 . \} . \" ensure neutral single quotes with Tascii . el \{\ . ie \\n(.$>2 \&\\$1\(aq\fI\\$2\fR\(aq\\$3 . el \&\(aq\fI\\$1\fR\(aq\\$2 . \} . \} . \" legacy nroff doesn't have 'aq', so use ' and hope for the best . el \{ . ie \\n(.$>2 \&\\$1'\fI\\$2\fR'\\$3 . el \&'\fI\\$1\fR'\\$2 . \} .\} .\" troff can change fonts, so no need for quotes .if t \{\ . ie \\n(.$>2 \&\\$1\f(CI\\$2\fR\\$3 . el \&\f(CI\\$1\fR\\$2 .\} .hy 14 .. .\" Constant-width font with quotes with nroff and troff .de CQ .hy 0 .if n \{\ . ie \\n(.g \{\ . \" use proper opening and closing single quotes . ie \\n(tQ \{\ . ie \\n(.$>2 \&\\$1\(oq\\$2\(cq\\$3 . el \&\(oq\\$1\(cq\\$2 . \} . \" ensure neutral single quotes with Tascii . el \{\ . ie \\n(.$>2 \&\\$1\(aq\\$2\(aq\\$3 . el \&\(aq\\$1\(aq\\$2 . \} . \} . \" legacy nroff doesn't have 'aq', so use ' and hope for the best . el \{\ . ie \\n(.$>2 \&\\$1'\\$2'\\$3 . el \&'\\$1'\\$2 . \} .\} .if t \{\ . ie \\n(.g \{\ . ie \\n(.$>2 \&\\$1\(oq\f(CW\\$2\fR\(cq\\$3 . el \&\(oq\f(CW\\$1\fR\(cq\\$2 . \} . \" legacy troff doesn't have 'oq' or 'cq' . el \{\ . ie \\n(.$>2 \&\\$1`\f(CW\\$2\fR'\\$3 . el \&`\f(CW\\$1\fR'\\$2 . \} .\} .hy 14 .. .\" equivalent of @set codequoteundirected .de aQ .if \\n(.g .tr '\(aq .. .\" equivalent of @clear codequoteundirected .de aE .if \\n(.g \{ .ie \\n(tQ>0 .tr '\(cq .el .tr '' \} .. .\" opening and closing double quotes .\" groff: true opening and closing quotes .ie \n(.g \{\ . ds lQ \(lq . ds rQ \(rq .\} .el \{\ .\" legacy nroff: ASCII neutral double quotes . ie n \{\ . ds lQ "" . ds rQ "" . \} .\" legacy troff: adjacent opening and closing single quotes . el \{\ . ds lQ `` . ds rQ '' . \} .\} .\" Display start .de DS .hy 0 .if t .in +4n .if n .in +3n .nf .. .\" Display end .de DE .fi .in .hy 14 .. .\" Example start .de ES .DS .if t \{\ .if '\\$1'S' \{\ .nr Ex 1 .ps -1 .\} .el .nr Ex 0 .nr mE \\n(.f .ft CW .\} .. .\" Example end .de EE .if t \{\ .ft \\n(mE .if \\n(Ex=1 .ps .\} .DE .. .SH NAME units \(em unit conversion and calculation program .\" hack to prevent very thick fraction bars with gropdf .\" '-1' makes thickness proportional to type size .if \n(.g .if t \Z@\D't -1'@ .PP .SH SYNOPSIS .PP .CW units .RI [ options ] .RI [ from-unit .RI [ to-unit ]] .PP .SH DESCRIPTION The .CW "units" program converts quantities expressed in various systems of measurement to their equivalents in other systems of measurement. Like many similar programs, it can handle multiplicative scale changes. It can also handle nonlinear conversions such as Fahrenheit to Celsius; see \fITemperature Conversions\fP. The program can also perform conversions from and to sums of units, such as converting between meters and feet plus inches. .PP Basic operation is simple: you enter the units that you want to convert \fIfrom\fP and the units that you want to convert \fIto\fP. You can use the program interactively with prompts, or you can use it from the command line. .PP Beyond simple unit conversions, .CW "units" can be used as a general-purpose scientific calculator that keeps track of units in its calculations. You can form arbitrary complex mathematical expressions of dimensions including sums, products, quotients, powers, and even roots of dimensions. Thus you can ensure accuracy and dimensional consistency when working with long expressions that involve many different units that may combine in complex ways; for an illustration, see \fIComplicated Unit Expressions\fP. .PP The units are defined in an external data file. You can use the extensive data file that comes with this program, or you can provide your own data file to suit your needs. You can also use your own data file to supplement the standard data file. .PP You can change the default behavior of .CW "units" with various options given on the command line. See \fIInvoking Units\fP for a description of the available options. .PP .SH INTERACTING WITH \f(BIUNITS\fP To invoke .CW "units" for interactive use, type .CI "units" at your shell prompt. The program will print something like this: .PP .ES Currency exchange rates from www.timegenie.com on 2014-03-05 2860 units, 109 prefixes, 85 nonlinear units You have: .EE .PP At the .CQ "You\ have:" prompt, type the quantity and units that you are converting \fIfrom\fP. For example, if you want to convert ten meters to feet, type .CI "10 meters" . Next, .CW "units" will print .CQ "You\ want:" . You should type the units you want to convert \fIto\fP. To convert to feet, you would type .CI "feet" . If the .CW "readline" library was compiled in, then \fItab\fP will complete unit names. See \fIReadline Support\fP for more information about .CW "readline" . To quit the program type .CI "quit" or .CI "exit" at either prompt. .PP The result will be displayed in two ways. The first line of output, which is marked with a .CQ "*" to indicate multiplication, gives the result of the conversion you have asked for. The second line of output, which is marked with a .CQ "/" to indicate division, gives the inverse of the conversion factor. If you convert 10 meters to feet, .CW "units" will print .PP .ES * 32.808399 / 0.03048 .EE .PP which tells you that 10 meters equals about 32.8 feet. The second number gives the conversion in the opposite direction. In this case, it tells you that 1 foot is equal to about 0.03 dekameters since the dekameter is 10 meters. It also tells you that 1/32.8 is about 0.03. .PP The .CW "units" program prints the inverse because sometimes it is a more convenient number. In the example above, for example, the inverse value is an exact conversion: a foot is exactly 0.03048 dekameters. But the number given the other direction is inexact. .PP If you convert grains to pounds, you will see the following: .PP .ES You have: grains You want: pounds * 0.00014285714 / 7000 .EE .PP From the second line of the output you can immediately see that a grain is equal to a seven thousandth of a pound. This is not so obvious from the first line of the output. If you find the output format confusing, try using the .CQ "--verbose" option: .PP .ES You have: grain You want: aeginamina grain = 0.00010416667 aeginamina grain = (1 / 9600) aeginamina .EE .PP If you request a conversion between units that measure reciprocal dimensions, then .CW "units" will display the conversion results with an extra note indicating that reciprocal conversion has been done: .PP .ES You have: 6 ohms You want: siemens reciprocal conversion * 0.16666667 / 6 .EE .PP Reciprocal conversion can be suppressed by using the .CQ "--strict" option. As usual, use the .CQ "--verbose" option to get more comprehensible output: .PP .ES You have: tex You want: typp reciprocal conversion 1 / tex = 496.05465 typp 1 / tex = (1 / 0.0020159069) typp You have: 20 mph You want: sec/mile reciprocal conversion 1 / 20 mph = 180 sec/mile 1 / 20 mph = (1 / 0.0055555556) sec/mile .EE .PP If you enter incompatible unit types, the .CW "units" program will print a message indicating that the units are not conformable and it will display the reduced form for each unit: .PP .ES You have: ergs/hour You want: fathoms kg^2 / day conformability error 2.7777778e-11 kg m^2 / sec^3 2.1166667e-05 kg^2 m / sec .EE .PP If you only want to find the reduced form or definition of a unit, simply press \fIEnter\fP at the .CQ "You\ want:" prompt. Here is an example: .PP .ES You have: jansky You want: Definition: fluxunit = 1e-26 W/m^2 Hz = 1e-26 kg / s^2 .EE .PP The output from .CW "units" indicates that the jansky is defined to be equal to a fluxunit which in turn is defined to be a certain combination of watts, meters, and hertz. The fully reduced (and in this case somewhat more cryptic) form appears on the far right. .PP Some named units are treated as dimensionless in some situations. These units include the radian and steradian. These units will be treated as equal to 1 in units conversions. Power is equal to torque times angular velocity. This conversion can only be performed if the radian is dimensionless. .PP .ES You have: (14 ft lbf) (12 radians/sec) You want: watts * 227.77742 / 0.0043902509 .EE .PP It is also possible to compute roots and other non-integer powers of dimensionless units; this allows computations such as the altitude of geosynchronous orbit: .PP .ES You have: cuberoot(G earthmass / (circle/siderealday)^2) - earthradius You want: miles * 22243.267 / 4.4957425e-05 .EE .PP Named dimensionless units are not treated as dimensionless in other contexts. They cannot be used as exponents so for example, .CQ "meter^radian" is forbidden. .PP If you want a list of options you can type .CI "?" at the .CQ "You\ want:" prompt. The program will display a list of named units that are conformable with the unit that you entered at the .CQ "You\ have:" prompt above. Conformable unit \fIcombinations\fP will not appear on this list. .PP Typing .CI "help" at either prompt displays a short help message. You can also type .CI "help" followed by a unit name. This will invoke a pager on the units data base at the point where that unit is defined. You can read the definition and comments that may give more details or historical information about the unit. (You can generally quit out of the page by pressing .CQ "q" .) .PP Typing .CI "search" \fItext\fP will display a list of all of the units whose names contain \fItext\fP as a substring along with their definitions. This may help in the case where you aren't sure of the right unit name. .PP .SH USING \f(BIUNITS\fP NON-INTERACTIVELY The .CW "units" program can perform units conversions non-interactively from the command line. To do this, type the command, type the original unit expression, and type the new units you want. If a units expression contains non-alphanumeric characters, you may need to protect it from interpretation by the shell using single or double quote characters. .PP If you type .PP .ES units "2 liters" quarts .EE .PP then .CW "units" will print .PP .ES * 2.1133764 / 0.47317647 .EE .PP and then exit. The output tells you that 2 liters is about 2.1 quarts, or alternatively that a quart is about 0.47 times 2 liters. .PP .CW "units" does not require a space between a numerical value and the unit, so the previous example can be given as .PP .ES units 2liters quarts .EE .PP to avoid having to quote the first argument. .PP If the conversion is successful, then .CW "units" will return success (zero) to the calling environment. If you enter non-conformable units, then .CW "units" will print a message giving the reduced form of each unit and it will return failure (nonzero) to the calling environment. .PP When you invoke .CW "units" with only one argument, it will print the definition of the specified unit. It will return failure if the unit is not defined and success if the unit is defined. .PP .SH UNIT DEFINITIONS The conversion information is read from a units data file that is called .CQ "definitions.units" and is usually located in the .CQ "/usr/share/units" directory. If you invoke .CW "units" with the .CQ "-V" option, it will print the location of this file. The default file includes definitions for all familiar units, abbreviations and metric prefixes. It also includes many obscure or archaic units. Many common spelled-out numbers (e.g., .CQ "seventeen" ) are recognized. .PP Many constants of nature are defined, including these: .PP .ES pi \fRratio of circumference to diameter\fP c \fRspeed of light\fP e \fRcharge on an electron\fP force \fRacceleration of gravity\fP mole \fRAvogadro's number\fP water \fRpressure per unit height of water\fP Hg \fRpressure per unit height of mercury\fP au \fRastronomical unit\fP k \fRBoltzman's constant\fP mu0 \fRpermeability of vacuum\fP epsilon0 \fRpermittivity of vacuum\fP G \fRGravitational constant\fP mach \fRspeed of sound\fP .EE .PP The standard data file includes atomic masses for all of the elements and numerous other constants. Also included are the densities of various ingredients used in baking so that .CQ "2\ cups flour_sifted" can be converted to .CQ "grams" . This is not an exhaustive list. Consult the units data file to see the complete list, or to see the definitions that are used. .PP The .CQ "pound" is a unit of mass. To get force, multiply by the force conversion unit .CQ "force" or use the shorthand .CQ "lbf" . (Note that .CQ "g" is already taken as the standard abbreviation for the gram.) The unit .CQ "ounce" is also a unit of mass. The fluid ounce is .CQ "fluidounce" or .CQ "floz" . When British capacity units differ from their US counterparts, such as the British Imperial gallon, the unit is defined both ways with .CQ "br" and .CQ "us" prefixes. Your locale settings will determine the value of the unprefixed unit. Currency is prefixed with its country name: .CQ "belgiumfranc" , .CQ "britainpound" . .PP When searching for a unit, if the specified string does not appear exactly as a unit name, then the .CW "units" program will try to remove a trailing .CQ "s" , .CQ "es" . Next units will replace a trailing .CQ "ies" with .CQ "y" . If that fails, .CW "units" will check for a prefix. The database includes all of the standard metric prefixes. Only one prefix is permitted per unit, so .CQ "micromicrofarad" will fail. However, prefixes can appear alone with no unit following them, so .CQ "micro*microfarad" will work, as will .CQ "micro microfarad" . .PP To find out which units and prefixes are available, read the standard units data file, which is extensively annotated. .PP .SS English Customary Units English customary units differ in various ways in different regions. In Britain a complex system of volume measurements featured different gallons for different materials such as a wine gallon and ale gallon that different by twenty percent. This complexity was swept away in 1824 by a reform that created an entirely new gallon, the British Imperial gallon defined as the volume occupied by ten pounds of water. Meanwhile in the USA the gallon is derived from the 1707 Winchester wine gallon, which is 231 cubic inches. These gallons differ by about twenty percent. By default if .CW "units" runs in the .CQ "en_GB" locale you will get the British volume measures. If it runs in the .CQ "en_US" locale you will get the US volume measures. In other locales the default values are the US definitions. If you wish to force different definitions, then set the environment variable .CW "UNITS_ENGLISH" to either .CQ "US" or .CQ "GB" to set the desired definitions independent of the locale. .PP Before 1959, the value of a yard (and other units of measure defined in terms of it) differed slightly among English-speaking countries. In 1959, Australia, Canada, New Zealand, the United Kingdom, the United States, and South Africa adopted the Canadian value of 1\ yard = 0.9144\ m (exactly), which was approximately halfway between the values used by the UK and the US; it had the additional advantage of making 1\ inch = 2.54\ cm (exactly). This new standard was termed the \fIInternational Yard\fP. Australia, Canada, and the UK then defined all customary lengths in terms of the International Yard (Australia did not define the furlong or rod); because many US land surveys were in terms of the pre-1959 units, the US continued to define customary surveyors' units (furlong, chain, rod, and link) in terms of the previous value for the foot, which was termed the \fIUS survey foot\fP. The US defined a \fIUS survey mile\fP as 5280 US survey feet, and defined a \fIstatute mile\fP as a US survey mile. The US values for these units differ from the international values by about 2\ ppm. .PP The .CW "units" program uses the international values for these units; the US values can be obtained by using either the .CQ "US" or the .CQ "survey" prefix. In either case, the simple familiar relationships among the units are maintained, e.g., 1 .CQ "furlong" = 660 .CQ "ft" , and 1 .CQ "USfurlong" = 660 .CQ "USft" , though the metric equivalents differ slightly between the two cases. The .CQ "US" prefix or the .CQ "survey" prefix can also be used to obtain the US survey mile and the value of the US yard prior to 1959, e.g., .CQ "USmile" or .CQ "surveymile" (but \fInot\fP .CQ "USsurveymile" ). To get the US value of the statute mile, use either .CQ "USstatutemile" or .CQ "USmile" . .PP Except for distances that extend over hundreds of miles (such as in the US State Plane Coordinate System), the differences in the miles are usually insignificant: .PP .ES You have: 100 surveymile - 100 mile You want: inch * 12.672025 / 0.078913984 .EE .PP The pre-1959 UK values for these units can be obtained with the prefix .CQ "UK" . .PP In the US, the acre is officially defined in terms of the US survey foot, but .CW "units" uses a definition based on the international foot. If you want the official US acre use .CQ "USacre" and similarly use .CQ "USacrefoot" for the official US version of that unit. The difference between these units is about 4 parts per million. .PP .SH UNIT EXPRESSIONS .SS Operators You can enter more complicated units by combining units with operations such as multiplication, division, powers, addition, subtraction, and parentheses for grouping. You can use the customary symbols for these operators when .CW "units" is invoked with its default options. Additionally, .CW "units" supports some extensions, including high priority multiplication using a space, and a high priority numerical division operator .CQ ( "|" ) that can simplify some expressions. .PP You multiply units using a space or an asterisk .CQ ( "*" ). The next example shows both forms: .PP .ES You have: arabicfoot * arabictradepound * force You want: ft lbf * 0.7296 / 1.370614 .EE .PP You can divide units using the slash .CQ ( "/" ) or with .CQ "per" : .PP .ES You have: furlongs per fortnight You want: m/s * 0.00016630986 / 6012.8727 .EE .PP You can use parentheses for grouping: .PP .ES You have: (1/2) kg / (kg/meter) You want: league * 0.00010356166 / 9656.0833 .EE .PP White space surrounding operators is optional, so the previous example could have used .CQ "(1/2)kg/(kg/meter)" . As a consequence, however, hyphenated spelled-out numbers (e.g., .CQ "forty-two" ) cannot be used; .CQ "forty-two" is interpreted as .CQ "40 - 2" . .PP Multiplication using a space has a higher precedence than division using a slash and is evaluated left to right; in effect, the first .CQ "/" character marks the beginning of the denominator of a unit expression. This makes it simple to enter a quotient with several terms in the denominator: .CQ "J\ /\ mol\ K" . The .CQ "*" and .CQ "/" operators have the same precedence, and are evaluated left to right; if you multiply with .CQ "*" , you must group the terms in the denominator with parentheses: .CQ "J\ /\ (mol\ *\ K)" . .PP The higher precedence of the space operator may not always be advantageous. For example, .CQ "m/s\ s/day" is equivalent to .CQ "m\ /\ s\ s\ day" and has dimensions of length per time cubed. Similarly, .CQ "1/2\ meter" refers to a unit of reciprocal length equivalent to 0.5/meter, perhaps not what you would intend if you entered that expression. The get a half meter you would need to use parentheses: .CQ "(1/2)\ meter" . The .CQ "*" operator is convenient for multiplying a sequence of quotients. For example, .CQ "m/s\ *\ s/day" is equivalent to .CQ "m/day" . Similarly, you could write .CQ "1/2\ *\ meter" to get half a meter. .PP The .CW "units" program supports another option for numerical fractions: you can indicate division of \fInumbers\fP with the vertical bar .CQ ( "|" ), so if you wanted half a meter you could write .CQ "1|2\ meter" . You cannot use the vertical bar to indicate division of non-numerical units (e.g., .CQ "m|s" results in an error message). .PP Powers of units can be specified using the .CQ "^" character, as shown in the following example, or by simple concatenation of a unit and its exponent: .CQ "cm3" is equivalent to .CQ "cm^3" ; if the exponent is more than one digit, the .CQ "^" is required. You can also use .CQ "**" as an exponent operator. .PP .ES You have: cm^3 You want: gallons * 0.00026417205 / 3785.4118 .EE .PP Concatenation only works with a single unit name: if you write .CQ "(m/s)2" , .CW "units" will treat it as multiplication by 2. When a unit includes a prefix, exponent operators apply to the combination, so .CQ "centimeter3" gives cubic centimeters. If you separate the prefix from the unit with any multiplication operator (e.g., .CQ "centi meter^3" ), the prefix is treated as a separate unit, so the exponent applies only to the unit without the prefix. The second example is equivalent to .CQ "centi * (meter^3)" , and gives a hundredth of a cubic meter, not a cubic centimeter. The .CW "units" program is limited internally to products of 99 units; accordingly, expressions like .CQ "meter^100" or .CQ "joule^34" (represented internally as .CQ "kg^34\ m^68\ /\ s^68" ) will fail. .PP The .CQ "|" operator has the highest precedence, so you can write the square root of two thirds as .CQ "2|3^1|2" . The .CQ "^" operator has the second highest precedence, and is evaluated right to left, as usual: .PP .ES You have: 5 * 2^3^2 You want: Definition: 2560 .EE .PP With a dimensionless base unit, any dimensionless exponent is meaningful (e.g., .CQ "pi^exp(2.371)" ). Even though angle is sometimes treated as dimensionless, exponents cannot have dimensions of angle: .PP .ES You have: 2^radian ^ Exponent not dimensionless .EE .PP If the base unit is not dimensionless, the exponent must be a rational number \fIp\fP/\fIq\fP, and the dimension of the unit must be a power of \fIq\fP, so .CQ "gallon^2|3" works but .CQ "acre^2|3" fails. An exponent using the slash .CQ ( "/" ) operator (e.g., .CQ "gallon^(2/3)" ) is also acceptable; the parentheses are needed because the precedence of .CQ "^" is higher than that of .CQ "/" . Since .CW "units" cannot represent dimensions with exponents greater than 99, a fully reduced exponent must have \fIq\fP\ <\ 100. When raising a non-dimensionless unit to a power, .CW "units" attempts to convert a decimal exponent to a rational number with \fIq\fP\ <\ 100. If this is not possible .CW "units" displays an error message: .PP .ES You have: ft^1.234 Base unit not dimensionless; rational exponent required .EE .PP A decimal exponent must match its rational representation to machine precision, so .CQ "acre^1.5" works but .CQ "gallon^0.666" does not. .PP .SS Sums and Differences of Units You may sometimes want to add values of different units that are outside the SI. You may also wish to use .CW "units" as a calculator that keeps track of units. Sums of conformable units are written with the .CQ "+" character, and differences with the .CQ "-" character. .PP .ES You have: 2 hours + 23 minutes + 32 seconds You want: seconds * 8612 / 0.00011611705 .EE .PP .ES You have: 12 ft + 3 in You want: cm * 373.38 / 0.0026782366 .EE .PP .ES You have: 2 btu + 450 ft lbf You want: btu * 2.5782804 / 0.38785542 .EE .PP The expressions that are added or subtracted must reduce to identical expressions in primitive units, or an error message will be displayed: .PP .ES You have: 12 printerspoint - 4 heredium ^ Illegal sum of non-conformable units .EE .PP As usual, the precedence for .CQ "+" and .CQ "-" is lower than that of the other operators. A fractional quantity such as 2\ 1/2 cups can be given as .CQ "(2+1|2) cups" ; the parentheses are necessary because multiplication has higher precedence than addition. If you omit the parentheses, .CW "units" attempts to add .CQ "2" and .CQ "1|2 cups" , and you get an error message: .PP .ES You have: 2+1|2 cups ^ Illegal sum or difference of non-conformable units .EE .PP The expression could also be correctly written as .CQ "(2+1/2) cups" . If you write .CQ "2\ 1|2 cups" the space is interpreted as \fImultiplication\fP so the result is the same as .CQ "1 cup" . .PP The .CQ "+" and .CQ "-" characters sometimes appears in exponents like .CQ "3.43e+8" . This leads to an ambiguity in an expression like .CQ "3e+2 yC" . The unit .CQ "e" is a small unit of charge, so this can be regarded as equivalent to .CQ "(3e+2) yC" or .CQ "(3 e)+(2 yC)" . This ambiguity is resolved by always interpreting .CQ "+" and .CQ "-" as part of an exponent if possible. .PP .SS Numbers as Units For .CW "units" , numbers are just another kind of unit. They can appear as many times as you like and in any order in a unit expression. For example, to find the volume of a box that is 2 ft by 3 ft by 12 ft in steres, you could do the following: .PP .ES You have: 2 ft 3 ft 12 ft You want: stere * 2.038813 / 0.49048148 You have: $ 5 / yard You want: cents / inch * 13.888889 / 0.072 .EE .PP And the second example shows how the dollar sign in the units conversion can precede the five. Be careful: .CW "units" will interpret .CQ "$5" with no space as equivalent to .CQ "dollar^5" . .PP .SS Built-in Functions Several built-in functions are provided: .CQ "sin" , .CQ "cos" , .CQ "tan" , .CQ "ln" , .CQ "log" , .CQ "exp" , .CQ "acos" , .CQ "atan" , .CQ "asin" , .CQ "cosh" , .CQ "sinh" , .CQ "tanh" , .CQ "acosh" , .CQ "asinh" , and .CQ "atanh" . The .CQ "sin" , .CQ "cos" , and .CQ "tan" functions require either a dimensionless argument or an argument with dimensions of angle. .PP .ES You have: sin(30 degrees) You want: Definition: 0.5 You have: sin(pi/2) You want: Definition: 1 You have: sin(3 kg) ^ Unit not dimensionless .EE .PP The other functions on the list require dimensionless arguments. The inverse trigonometric functions return arguments with dimensions of angle. .PP The .CQ "ln" and .CQ "log" functions give natural log and log base 10 respectively. To obtain logs for any integer base, enter the desired base immediately after .CQ "log" . For example, to get log base 2 you would write .CQ "log2" and to get log base 47 you could write .CQ "log47" . .PP .ES You have: log2(32) You want: Definition: 5 You have: log3(32) You want: Definition: 3.1546488 You have: log4(32) You want: Definition: 2.5 You have: log32(32) You want: Definition: 1 You have: log(32) You want: Definition: 1.50515 You have: log10(32) You want: Definition: 1.50515 .EE .PP If you wish to take roots of units, you may use the .CQ "sqrt" or .CQ "cuberoot" functions. These functions require that the argument have the appropriate root. You can obtain higher roots by using fractional exponents: .PP .ES You have: sqrt(acre) You want: feet * 208.71074 / 0.0047913202 You have: (400 W/m^2 / stefanboltzmann)^(1/4) You have: Definition: 289.80882 K You have: cuberoot(hectare) ^ Unit not a root .EE .PP .SS Previous Result You can insert the result of the previous conversion using the underscore .CQ ( "_" ). It is useful when you want to convert the same input to several different units, for example .PP .ES You have: 2.3 tonrefrigeration You want: btu/hr * 27600 / 3.6231884e-005 You have: _ You want: kW * 8.0887615 / 0.12362832 .EE .PP Suppose you want to do some deep frying that requires an oil depth of 2\ inches. You have 1/2 gallon of oil, and want to know the largest-diameter pan that will maintain the required depth. The nonlinear unit .CQ "circlearea" gives the \fIradius\fP of the circle (see \fIOther Nonlinear Units\fP, for a more detailed description) in SI units; you want the \fIdiameter\fP in \fIinches\fP: .PP .ES You have: 1|2 gallon / 2 in You want: circlearea 0.10890173 m You have: 2 _ You want: in * 8.5749393 / 0.1166189 .EE .PP In most cases, surrounding white space is optional, so the previous example could have used .CQ "2_" . If .CQ "_" follows a non-numerical unit symbol, however, the space is required: .PP .ES You have: m_ ^ Parse error .EE .PP When .CQ "_" is followed by a digit, the operation is multiplication rather than exponentiation, so that .CQ "_2" , is equivalent to .CQ "_\ *\ 2" rather than .CQ "_^2" . .PP You can use the .CQ "_" symbol any number of times; for example, .PP .ES You have: m You want: Definition: 1 m You have: _ _ You want: Definition: 1 m^2 .EE .PP Using .CQ "_" before a conversion has been performed (e.g., immediately after invocation) generates an error: .aQ .PP .ES You have: _ ^ No previous result; '_' not set .EE .aE .PP Accordingly, .CQ "_" serves no purpose when .CW "units" is invoked non-interactively. .PP If .CW "units" is invoked with the .CQ "--verbose" option (see \fIInvoking Units\fP), the value of .CQ "_" is not expanded: .PP .ES You have: mile You want: ft mile = 5280 ft mile = (1 / 0.00018939394) ft You have: _ You want: m _ = 1609.344 m _ = (1 / 0.00062137119) m .EE .PP You can give .CQ "_" at the .CQ "You\ want:" prompt, but it usually is not very useful. .PP .SS Complicated Unit Expressions The .CW "units" program is especially helpful in ensuring accuracy and dimensional consistency when converting lengthy unit expressions. .if t .ig ++ For example, one form of the Darcy-Weisbach fluid-flow equation is .RS 5n .PP Delta \fIP\fP = (8 / pi)^2 (\fIrho\fP \fIfLQ\fP^2) / \fId\fP^5, .RE .PP where Delta \fIP\fP is the pressure drop, \fIrho\fP is the mass density, \fIf\fP is the (dimensionless) friction factor, \fIL\fP is the length of the pipe, \fIQ\fP is the volumetric flow rate, and \fId\fP is the pipe diameter. It might be desired to have the equation in the form .RS 5n .PP Delta \fIP\fP = A1 \fIrho\fP \fIfLQ\fP^2 / \fId\fP^5 .RE .PP .++ .if n .ig ++ .EQ delim $$ .EN For example, one form of the Darcy\-Weisbach fluid-flow equation is .RS 5n .PP .EQ DELTA P = 8 over pi sup 2 rho fL Q sup 2 over d sup 5 , .EN .RE .PP where $DELTA P$ is the pressure drop, $rho$ is the mass density, $f$ is the (dimensionless) friction factor, $L$ is the length of the pipe, $Q$ is the volumetric flow rate, and $d$ is the pipe diameter. It might be desired to have the equation in the form .RS 5n .PP .EQ DELTA P = A sub 1 rho fL Q sup 2 over d sup 5 .EN .RE .PP .EQ delim off .EN .++ .PP that accepted the user's normal units; for typical units used in the US, the required conversion could be something like .PP .ES You have: (8/pi^2)(lbm/ft^3)ft(ft^3/s)^2(1/in^5) You want: psi * 43.533969 / 0.022970568 .EE .PP The parentheses allow individual terms in the expression to be entered naturally, as they might be read from the formula. Alternatively, the multiplication could be done with the .CQ "*" rather than a space; then parentheses are needed only around .CQ "ft^3/s" because of its exponent: .PP .ES You have: 8/pi^2 * lbm/ft^3 * ft * (ft^3/s)^2 /in^5 You want: psi * 43.533969 / 0.022970568 .EE .PP Without parentheses, and using spaces for multiplication, the previous conversion would need to be entered as .PP .ES You have: 8 lb ft ft^3 ft^3 / pi^2 ft^3 s^2 in^5 You want: psi * 43.533969 / 0.022970568 .EE .PP .SS Backwards Compatibility: .CQ "*" and .CQ "-" The original .CW "units" assigned multiplication a higher precedence than division using the slash. This differs from the usual precedence rules, which give multiplication and division equal precedence, and can be confusing for people who think of units as a calculator. .PP The star operator .CQ ( "*" ) included in this .CW "units" program has, by default, the same precedence as division, and hence follows the usual precedence rules. For backwards compatibility you can invoke .CW "units" with the .CQ "--oldstar" option. Then .CQ "*" has a higher precedence than division, and the same precedence as multiplication using the space. .PP Historically, the hyphen .CQ ( "-" ) has been used in technical publications to indicate products of units, and the original .CW "units" program treated it as a multiplication operator. Because .CW "units" provides several other ways to obtain unit products, and because .CQ "-" is a subtraction operator in general algebraic expressions, .CW "units" treats the binary .CQ "-" as a subtraction operator by default. For backwards compatibility use the .CQ "--product" option, which causes .CW "units" to treat the binary .CQ "-" operator as a product operator. When .CQ "-" is a multiplication operator it has the same precedence as multiplication with a space, giving it a higher precedence than division. .PP When .CQ "-" is used as a unary operator it negates its operand. Regardless of the .CW "units" options, if .CQ "-" appears after .CQ "(" or after .CQ "+" , then it will act as a negation operator. So you can always compute 20 degrees minus 12 minutes by entering .CQ "20\ degrees + -12\ arcmin" . You must use this construction when you define new units because you cannot know what options will be in force when your definition is processed. .PP .SH NONLINEAR UNIT CONVERSIONS Nonlinear units are represented using functional notation. They make possible nonlinear unit conversions such as temperature. .PP .SS Temperature Conversions Conversions between temperatures are different from linear conversions between temperature \fIincrements\fP\(emsee the example below. The absolute temperature conversions are handled by units starting with .CQ "temp" , and you must use functional notation. The temperature-increment conversions are done using units starting with .CQ "deg" and they do not require functional notation. .PP .ES You have: tempF(45) You want: tempC 7.2222222 You have: 45 degF You want: degC * 25 / 0.04 .EE .PP Think of .CQ "tempF(\fIx\fP)" not as a function but as a notation that indicates that \fIx\fP should have units of .CQ "tempF" attached to it. See \fIDefining Nonlinear Units\fP. The first conversion shows that if it's 45 degrees Fahrenheit outside, it's 7.2 degrees Celsius. The second conversion indicates that a change of 45 degrees Fahrenheit corresponds to a change of 25 degrees Celsius. The conversion from .CQ "tempF(\fIx\fP)" is to absolute temperature, so that .PP .ES You have: tempF(45) You want: degR * 504.67 / 0.0019814929 .EE .PP gives the same result as .PP .ES You have: tempF(45) You want: tempR * 504.67 / 0.0019814929 .EE .PP But if you convert .CQ "tempF(\fIx\fP)" to .CQ "degC" , the output is probably not what you expect: .PP .ES You have: tempF(45) You want: degC * 280.37222 / 0.0035666871 .EE .PP The result is the temperature in K, because .CQ "degC" is defined as .CQ "K" , the Kelvin. For consistent results, use the .CQ "temp\fIX\fP" units when converting to a temperature rather than converting a temperature increment. .PP The .CQ "tempC()" and .CQ "tempF()" definitions are limited to positive absolute temperatures, and giving a value that would result in a negative absolute temperature generates an error message: .PP .ES You have: tempC(-275) ^ Argument of function outside domain ^ .EE .PP .SS Other Nonlinear Units Some other examples of nonlinear units are numerous different ring sizes and wire gauges, the grit sizes used for abrasives, the decibel scale, shoe size, scales for the density of sugar (e.g., baume). The standard data file also supplies units for computing the area of a circle and the volume of a sphere. See the standard units data file for more details. Wire gauges with multiple zeroes are signified using negative numbers where two zeroes is .CQ "-1" . Alternatively, you can use the synonyms .CQ "g00" , .CQ "g000" , and so on that are defined in the standard units data file. .PP .ES You have: wiregauge(11) You want: inches * 0.090742002 / 11.020255 You have: brwiregauge(g00) You want: inches * 0.348 / 2.8735632 You have: 1 mm You want: wiregauge 18.201919 You have: grit_P(600) You want: grit_ansicoated 342.76923 .EE .PP The last example shows the conversion from P graded sand paper, which is the European standard and may be marked \*(lQP600\*(rQ on the back, to the USA standard. .PP You can compute the area of a circle using the nonlinear unit, .CQ "circlearea" . You can also do this using the circularinch or circleinch. The next example shows two ways to compute the area of a circle with a five inch radius and one way to compute the volume of a sphere with a radius of one meter. .PP .ES You have: circlearea(5 in) You want: in2 * 78.539816 / 0.012732395 You have: 10^2 circleinch You want: in2 * 78.539816 / 0.012732395 You have: spherevol(meter) You want: ft3 * 147.92573 / 0.0067601492 .EE .PP The inverse of a nonlinear conversion is indicated by prefixing a tilde .CQ ( "~" ) to the nonlinear unit name: .PP .ES You have: ~wiregauge(0.090742002 inches) You want: Definition: 11 .EE .PP You can give a nonlinear unit definition without an argument or parentheses, and press \fIEnter\fP at the .CQ "You\ want:" prompt to get the definition of a nonlinear unit; if the definition is not valid for all real numbers, the range of validity is also given. If the definition requires specific units this information is also displayed: .PP .ES You have: tempC Definition: tempC(x) = x K + stdtemp defined for x >= -273.15 You have: ~tempC Definition: ~tempC(tempC) = (tempC +(-stdtemp))/K defined for tempC >= 0 K You have: circlearea Definition: circlearea(r) = pi r^2 r has units m .EE .PP To see the definition of the inverse use the .CQ "~" notation. In this case the parameter in the functional definition will usually be the name of the unit. Note that the inverse for .CQ "tempC" shows that it requires units of .CQ "K" in the specification of the allowed range of values. Nonlinear unit conversions are described in more detail in \fIDefining Nonlinear Units\fP. .PP .SH UNIT LISTS: CONVERSION TO SUMS OF UNITS Outside of the SI, it is sometimes desirable to convert a single unit to a sum of units\(emfor example, feet to feet plus inches. The conversion \fIfrom\fP sums of units was described in \fISums and Differences of Units\fP, and is a simple matter of adding the units with the .CQ "+" sign: .PP .ES You have: 12 ft + 3 in + 3|8 in You want: ft * 12.28125 / 0.081424936 .EE .PP Although you can similarly write a sum of units to convert \fIto\fP, the result will not be the conversion to the units in the sum, but rather the conversion to the particular sum that you have entered: .PP .ES You have: 12.28125 ft You want: ft + in + 1|8 in * 11.228571 / 0.089058524 .EE .PP The unit expression given at the .CQ "You\ want:" prompt is equivalent to asking for conversion to multiples of .CQ "1\ ft + 1\ in + 1|8\ in" , which is 1.09375 ft, so the conversion in the previous example is equivalent to .PP .ES You have: 12.28125 ft You want: 1.09375 ft * 11.228571 / 0.089058524 .EE .PP In converting to a sum of units like miles, feet and inches, you typically want the largest integral value for the first unit, followed by the largest integral value for the next, and the remainder converted to the last unit. You can do this conversion easily with .CW "units" using a special syntax for lists of units. You must list the desired units in order from largest to smallest, separated by the semicolon .CQ ( ";" ) character: .PP .ES You have: 12.28125 ft You want: ft;in;1|8 in 12 ft + 3 in + 3|8 in .EE .PP The conversion always gives integer coefficients on the units in the list, except possibly the last unit when the conversion is not exact: .PP .ES You have: 12.28126 ft You want: ft;in;1|8 in 12 ft + 3 in + 3.00096 * 1|8 in .EE .PP The order in which you list the units is important: .PP .ES You have: 3 kg You want: oz;lb 105 oz + 0.051367866 lb You have: 3 kg You want: lb;oz 6 lb + 9.8218858 oz .EE .PP Listing ounces before pounds produces a technically correct result, but not a very useful one. You must list the units in descending order of size in order to get the most useful result. .PP Ending a unit list with the separator .CQ ";" has the same effect as repeating the last unit on the list, so .CQ "ft;in;1|8 in;" is equivalent to .CQ "ft;in;1|8 in;1|8 in" . With the example above, this gives .PP .ES You have: 12.28126 ft You want: ft;in;1|8 in; 12 ft + 3 in + 3|8 in + 0.00096 * 1|8 in .EE .PP in effect separating the integer and fractional parts of the coefficient for the last unit. If you instead prefer to round the last coefficient to an integer you can do this with the .CQ "--round" .CQ ( "-r" ) option. With the previous example, the result is .PP .ES You have: 12.28126 ft You want: ft;in;1|8 in 12 ft + 3 in + 3|8 in (rounded down to nearest 1|8 in) .EE .PP When you use the .CQ "-r" option, repeating the last unit on the list has no effect (e.g., .CQ "ft;in;1|8 in;1|8 in" is equivalent to .CQ "ft;in;1|8 in" ), and hence neither does ending a list with a .CQ ";" . With a single unit and the .CQ "-r" option, a terminal .CQ ";" \fIdoes\fP have an effect: it causes .CW "units" to treat the single unit as a list and produce a rounded value for the single unit. Without the extra .CQ ";" , the .CQ "-r" option has no effect on single unit conversions. This example shows the output using the .CQ "-r" option: .PP .ES You have: 12.28126 ft You want: in * 147.37512 / 0.0067854058 You have: 12.28126 ft You want: in; 147 in (rounded down to nearest in) .EE .PP Each unit that appears in the list must be conformable with the first unit on the list, and of course the listed units must also be conformable with the unit that you enter at the .CQ "You\ have:" prompt. .PP .ES You have: meter You want: ft;kg ^ conformability error ft = 0.3048 m kg = 1 kg You have: meter You want: lb;oz conformability error 1 m 0.45359237 kg .EE .PP In the first case, .CW "units" reports the disagreement between units appearing on the list. In the second case, .CW "units" reports disagreement between the unit you entered and the desired conversion. This conformability error is based on the first unit on the unit list. .PP Other common candidates for conversion to sums of units are angles and time: .PP .ES You have: 23.437754 deg You want; deg;arcmin;arcsec 23 deg + 26 arcmin + 15.9144 arcsec You have: 7.2319 hr You want: hr;min;sec 7 hr + 13 min + 54.84 sec .EE .PP In North America, recipes for cooking typically measure ingredients by volume, and use units that are not always convenient multiples of each other. Suppose that you have a recipe for 6 and you wish to make a portion for 1. If the recipe calls for 2\ 1/2 cups of an ingredient, you might wish to know the measurements in terms of measuring devices you have available, you could use .CW "units" and enter .PP .ES You have: (2+1|2) cup / 6 You want: cup;1|2 cup;1|3 cup;1|4 cup;tbsp;tsp;1|2 tsp;1|4 tsp 1|3 cup + 1 tbsp + 1 tsp .EE .PP By default, if a unit in a list begins with fraction of the form 1|\fIx\fP and its multiplier is an integer, the fraction is given as the product of the multiplier and the numerator; for example, .PP .ES You have: 12.28125 ft You want: ft;in;1|8 in; 12 ft + 3 in + 3|8 in .EE .PP In many cases, such as the example above, this is what is wanted, but sometimes it is not. For example, a cooking recipe for 6 might call for 5\ 1/4 cup of an ingredient, but you want a portion for 2, and your 1-cup measure is not available; you might try .PP .ES You have: (5+1|4) cup / 3 You want: 1|2 cup;1|3 cup;1|4 cup 3|2 cup + 1|4 cup .EE .PP This result might be fine for a baker who has a 1\ 1/2-cup measure (and recognizes the equivalence), but it may not be as useful to someone with more limited set of measures, who does want to do additional calculations, and only wants to know \*(lQHow many 1/2-cup measures to I need to add?\*(rQ After all, that's what was actually asked. With the .CQ "--show-factor" option, the factor will not be combined with a unity numerator, so that you get .PP .ES You have: (5+1|4) cup / 3 You want: 1|2 cup;1|3 cup;1|4 cup 3 * 1|2 cup + 1|4 cup .EE .PP A user-specified fractional unit with a numerator other than 1 is never overridden, however\(emif a unit list specifies .CQ "3|4 cup;1|2 cup" , a result equivalent to 1\ 1/2 cups will always be shown as .CQ "2 * 3|4\ cup" whether or not the .CQ "--show-factor" option is given. .PP Some applications for unit lists may be less obvious. Suppose that you have a postal scale and wish to ensure that it's accurate at 1\ oz, but have only metric calibration weights. You might try .PP .ES You have: 1 oz You want: 100 g;50 g; 20 g;10 g;5 g;2 g;1 g; 20 g + 5 g + 2 g + 1 g + 0.34952312 * 1 g .EE .PP You might then place one each of the 20\ g, 5\ g, 2\ g, and 1\ g weights on the scale and hope that it indicates close to .PP .ES You have: 20 g + 5 g + 2 g + 1 g You want: oz; 0.98767093 oz .EE .PP Appending .CQ ";" to .CQ "oz" forces a one-line display that includes the unit; here the integer part of the result is zero, so it is not displayed. .PP A unit list such as .PP .ES cup;1|2\ cup;1|3\ cup;1|4\ cup;tbsp;tsp;1|2\ tsp;1|4\ tsp .EE .PP can be tedious to enter. The .CW "units" program provides shorthand names for some common combinations: .PP .ES hms \fRhours, minutes, seconds\fP dms \fRangle: degrees, minutes, seconds\fP time \fRyears, days, hours, minutes and seconds\fP usvol \fRUS cooking volume: cups and smaller\fP .EE .PP Using these shorthands, or \fIunit list aliases\fP, you can do the following conversions: .PP .ES You have: anomalisticyear You want: time 1 year + 25 min + 3.4653216 sec You have: 1|6 cup You want: usvol 2 tbsp + 2 tsp .EE .PP You cannot combine a unit list alias with other units: it must appear alone at the .CQ "You\ want:" prompt. .PP You can display the definition of a unit list alias by entering it at the .CQ "You\ have:" prompt: .PP .ES You have: dms Definition: unit list, deg;arcmin;arcsec .EE .PP When you specify compact output with .CQ "--compact" , .CQ "--terse" or .CQ "-t" and perform conversion to a unit list, .CW "units" lists the conversion factors for each unit in the list, separated by semicolons. .PP .ES You have: year You want: day;min;sec 365;348;45.974678 .EE .PP Unlike the case of regular output, zeros \fIare\fP included in this output list: .PP .ES You have: liter You want: cup;1|2 cup;1|4 cup;tbsp 4;0;0;3.6280454 .EE .PP .SH USING CGS UNITS The SI\(eman extension of the MKS (meter\-kilogram\-second) system\(emhas largely supplanted the older CGS (centimeter\-gram\-second) system, but CGS units are still used in a few specialized fields, especially in physics where they lead to a more elegant formulation of Maxwell's equations. Conversions between SI and CGS involving mechanical units are straightforward, involving powers of 10 (e.g., 1\ m\ =\ 100\ cm). Conversions involving electromagnetic units are more complicated, and .CW "units" supports three different systems of CGS units: electrostatic units (ESU), electromagnetic units (EMU), and the Gaussian system. The differences between these systems arise from different choices made for proportionality constants in electromagnetic equations. Coulomb's law gives electrostatic force between two charges separated by a distance .EQ delim $$ .EN .if n \fIr\fP: .if t $r$: .RS 5n .PP .if n \fIF\fP = \fIk\fP_C \fIq\fP_1\ \fIq\fP_2\ /\ \fIr\fP^2. .if t \{ .EQ F = k sub roman C { q sub 1 q sub 2} over r sup 2. .EN .\} .RE .PP .PP Ampere's law gives the electromagnetic force per unit length between two current-carrying conductors separated by a distance .if n \fIr\fP: .if t $r$: .RS 5n .PP .if n \fIF\fP/\fIl\fP = 2 \fIk\fP_A \fII\fP_1\ \fII\fP_2\ /\ \fIr\fP. .if t \{ .EQ F over l = 2 k sub roman A { I sub 1 I sub 2 } over r . .EN .\} .RE .PP .PP The two constants, .if n \fIk\fP_C and \fIk\fP_A, .if t $k sub roman C$ and $k sub roman A$, are related by the square of the speed of light: .if n \fIk\fP_A\ =\ \fIk\fP_C\ /\ \fIc\fP^2. .if t $k sub roman A = k sub roman C / c sup 2$. .PP In the SI, the constants have dimensions, and an additional base unit, the ampere, measures electric current. The CGS systems do not define new base units, but express charge and current as derived units in terms of mass, length, and time. In the ESU system, the constant for Coulomb's law is chosen to be unity and dimensionless, which defines the unit of charge. In the EMU system, the constant for Ampere's law is chosen to be unity and dimensionless, which defines a unit of current. The Gaussian system usually uses the ESU units for charge and current; it chooses another constant so that the units for the electric and magnetic fields are the same. .PP The dimensions of electrical quantities in the various CGS systems are different from the SI dimensions for the same units; strictly, conversions between these systems and SI are not possible. But units in different systems relate to the same physical quantities, so there is a \fIcorrespondence\fP between these units. The .CW "units" program defines the units so that you can convert between corresponding units in the various systems. .PP .SS Specifying CGS Units The CGS definitions involve .if n cm^(1/2) and g^(1/2), .if t cm$"" sup {1/2}$ and g$"" sup {1/2}$, which is problematic because .CW "units" does not normally support fractional roots of base units. The .CQ "--units" .CQ ( "-u" ) option allows selection of a CGS unit system and works around this restriction by introducing base units for the square roots of length and mass: .CQ "sqrt_cm" and .CQ "sqrt_g" . The centimeter then becomes .CQ "sqrt_cm^2" and the gram, .CQ "sqrt_g^2" . This allows working from equations using the units in the CGS system, and enforcing dimensional conformity within that system. Recognized arguments to the .CQ "--units" option are .CQ "gauss[ian]" , .CQ "esu" , .CQ "emu" , and .CQ "si" ; the argument is case insensitive. The default mode for .CW "units" is SI units; the only effect of giving .CQ "si" with the .CQ "--units" option is to prepend .CQ "(SI)" to the .CQ "You\ have:" prompt. Giving an unrecognized system generates a warning, and .CW "units" uses SI units. .PP The changes resulting from the .CQ "--units" option are actually controlled by the .CW "UNITS_SYSTEM" environment variable. If you frequently work with one of the supported CGS units systems, you may set this environment variable rather than giving the .CQ "--units" option at each invocation. As usual, an option given on the command line overrides the setting of the environment variable. For example, if you would normally work with Gaussian units but might occasionally work with SI, you could set .CW "UNITS_SYSTEM" to .CQ "gaussian" and specify SI with the .CQ "--units" option. Unlike the argument to the .CQ "--units" option, the value of .CW "UNITS_SYSTEM" \fIis\fP case sensitive, so setting a value of .CQ "EMU" will have no effect other than to give an error message and set SI units. .PP The CGS definitions appear as conditional settings in the standard units data file, which you can consult for more information on how these units are defined, or on how to define an alternate units system. .PP .SS CGS Units Systems The ESU system derives the electromagnetic units from its unit of charge, the statcoulomb, which is defined from Coulomb's law. The statcoulomb equals .if n dyne^(1/2)\ cm, or cm^(3/2)\ g^(1/2)\ s^(\(mi1). .if t $roman dyne sup {1/2} ^ roman cm$, .if t or $roman cm sup {3/2} ^ roman g sup {1/2} ^ roman s sup {-1}$. The unit of current, the statampere, is statcoulomb\ sec, analogous to the relationship in SI. Other electrical units are then derived in a manner similar to that for SI units; the units use the SI names prefixed by .CQ "stat-" , e.g., .CQ "statvolt" or .CQ "statV" . The prefix .CQ "st-" is also recognized (e.g., .CQ "stV" ). .PP The EMU system derives the electromagnetic units from its unit of current, the abampere, which is defined in terms of Ampere's law. The abampere is equal to .if n dyne^(1/2), or cm^(1/2)\ g^(1/2)\ s^(\(mi1). .if t $roman dyne sup {1/2}$, .if t or $roman cm sup {1/2} ^ roman g sup {1/2} ^ roman s sup{-1}$. .EQ delim off .EN The unit of charge, the abcoulomb, is abampere\ sec, again analogous to the SI relationship. Other electrical units are then derived in a manner similar to that for SI units; the units use the SI names prefixed by .CQ "ab-" , e.g., .CQ "abvolt" or .CQ "abV" . The magnetic field units include the gauss, the oersted and the maxwell. .PP The Gaussian units system, which was also known as the Symmetric System, uses the same charge and current units as the ESU system (e.g., .CQ "statC" , .CQ "statA" ); it differs by defining the magnetic field so that it has the same units as the electric field. The resulting magnetic field units are the same ones used in the EMU system: the gauss, the oersted and the maxwell. .PP .SS Conversions Between Different Systems The CGS systems define units that measure the same thing but may have conflicting dimensions. Furthermore, the dimensions of the electromagnetic CGS units are never compatible with SI. But if you measure charge in two different systems you have measured the same physical thing, so there is a \fIcorrespondence\fP between the units in the different systems, and .CW "units" supports conversions between corresponding units. When running with SI, .CW "units" defines all of the CGS units in terms of SI. When you select a CGS system, .CW "units" defines the SI units and the other CGS system units in terms of the system you have selected. .PP .ES (Gaussian) You have: statA You want: abA * 3.335641e-11 / 2.9979246e+10 (Gaussian) You have: abA You want: sqrt(dyne) conformability error 2.9979246e+10 sqrt_cm^3 sqrt_g / s^2 1 sqrt_cm sqrt_g / s .EE .PP In the above example, .CW "units" converts between the current units statA and abA even though the abA, from the EMU system, has incompatible dimensions. This works because in Gaussian mode, the abA is defined in terms of the statA, so it does not have the correct definition for EMU; consequently, you cannot convert the abA to its EMU definition. .PP One challenge of conversion is that because the CGS system has fewer base units, quantities that have different dimensions in SI may have the same dimension in a CGS system. And yet, they may not have the same conversion factor. For example, the unit for the E field and B fields are the same in the Gaussian system, but the conversion factors to SI are quite different. This means that correct conversion is only possible if you keep track of what quantity is being measured. You cannot convert statV/cm to SI without indicating which type of field the unit measures. To aid in dimensional analysis, .CW "units" defines various dimension units such as LENGTH, TIME, and CHARGE to be the appropriate dimension in SI. The electromagnetic dimensions such as B_FIELD or E_FIELD may be useful aids both for conversion and dimensional analysis in CGS. You can convert them to or from CGS in order to perform SI conversions that in some cases will not work directly due to dimensional incompatibilities. This example shows how the Gaussian system uses the same units for all of the fields, but they all have different conversion factors with SI. .PP .ES (Gaussian) You have: statV/cm You want: E_FIELD * 29979.246 / 3.335641e-05 (Gaussian) You have: statV/cm You want: B_FIELD * 0.0001 / 10000 (Gaussian) You have: statV/cm You want: H_FIELD * 79.577472 / 0.012566371 (Gaussian) You have: statV/cm You want: D_FIELD * 2.6544187e-07 / 3767303.1 .EE .PP The next example shows that the oersted cannot be converted directly to the SI unit of magnetic field, A/m, because the dimensions conflict. We cannot redefine the ampere to make this work because then it would not convert with the statampere. But you can still do this conversion as shown below. .PP .ES (Gaussian) You have: oersted You want: A/m conformability error 1 sqrt_g / s sqrt_cm 29979246 sqrt_cm sqrt_g / s^2 (Gaussian) You have: oersted You want: H_FIELD * 79.577472 / 0.012566371 .EE .PP .SS Prompt Prefix If a unit system is specified with the .CQ "--units" option, the selected system's name is prepended to the .CQ "You\ have:" prompt as a reminder, e.g., .PP .ES (Gaussian) You have: stC You want: Definition: statcoulomb = sqrt(dyne) cm = 1 sqrt_cm^3 sqrt_g / s .EE .PP You can suppressed the prefix by including a line .PP .ES !prompt .EE .PP with no argument in a site or personal units data file. The prompt can be conditionally suppressed by including such a line within .CQ "!var" ... .CQ "!endvar" constructs, e.g., .PP .ES !var UNITS_SYSTEM gaussian gauss !prompt !endvar .EE .PP This might be appropriate if you normally use Gaussian units and find the prefix distracting but want to be reminded when you have selected a different CGS system. .PP .SH LOGGING CALCULATIONS The .CQ "--log" option allows you to save the results of calculations in a file; this can be useful if you need a permanent record of your work. For example, the fluid-flow conversion in \fIComplicated Unit Expressions\fP, is lengthy, and if you were to use it in designing a piping system, you might want a record of it for the project file. If the interactive session .PP .ES # Conversion factor A1 for pressure drop # dP = A1 rho f L Q^2/d^5 You have: (8/pi^2) (lbm/ft^3)ft(ft^3/s)^2(1/in^5) # Input units You want: psi * 43.533969 / 0.022970568 .EE .PP were logged, the log file would contain .PP .ES ### Log started Fri Oct 02 15:55:35 2015 # Conversion factor A1 for pressure drop # dP = A1 rho f L Q^2/d^5 From: (8/pi^2) (lbm/ft^3)ft(ft^3/s)^2(1/in^5) # Input units To: psi * 43.533969 / 0.022970568 .EE .PP The time is written to the log file when the file is opened. .PP The use of comments can help clarify the meaning of calculations for the log. The log includes conformability errors between the units at the .CQ "You\ have:" and .CQ "You\ want:" prompts, but not other errors, including lack of conformability of items in sums or differences or among items in a unit list. For example, a conversion between zenith angle and elevation angle could involve .PP .ES You have: 90 deg - (5 deg + 22 min + 9 sec) ^ Illegal sum or difference of non-conformable units You have: 90 deg - (5 deg + 22 arcmin + 9 arcsec) You want: dms 84 deg + 37 arcmin + 51 arcsec You have: _ You want: deg * 84.630833 / 0.011816024 You have: .EE .PP The log file would contain .PP .ES From: 90 deg - (5 deg + 22 arcmin + 9 arcsec) To: deg;arcmin;arcsec 84 deg + 37 arcmin + 51 arcsec From: _ To: deg * 84.630833 / 0.011816024 .EE .PP The initial entry error (forgetting that minutes have dimension of time, and that arcminutes must be used for dimensions of angle) does not appear in the output. When converting to a unit list alias, .CW "units" expands the alias in the log file. .PP The .CQ "From:" and .CQ "To:" tags are written to the log file even if the .CQ "--quiet" option is given. If the log file exists when .CW "units" is invoked, the new results are appended to the log file. The time is written to the log file each time the file is opened. The .CQ "--log" option is ignored when .CW "units" is used non-interactively. .PP .SH INVOKING \f(BIUNITS\fP You invoke .CW "units" like this: .PP .ES units [\fIoptions\fP] [\fIfrom-unit\fP [\fIto-unit\fP]] .EE .PP If the \fIfrom-unit\fP and \fIto-unit\fP are omitted, the program will use interactive prompts to determine which conversions to perform. See \fIInteractive Use\fP. If both \fIfrom-unit\fP and \fIto-unit\fP are given, .CW "units" will print the result of that single conversion and then exit. If only \fIfrom-unit\fP appears on the command line, .CW "units" will display the definition of that unit and exit. Units specified on the command line may need to be quoted to protect them from shell interpretation and to group them into two arguments. Note also that the .CQ "--quiet" option is enabled by default if you specify \fIfrom-unit\fP on the command line. See \fICommand Line Use\fP. .PP The default behavior of .CW "units" can be changed by various options given on the command line. In most cases, the options may be given in either short form (a single .CQ "-" followed by a single character) or long form .CQ ( "--" "" followed by a word or hyphen-separated words). Short-form options are cryptic but require less typing; long-form options require more typing but are more explanatory and may be more mnemonic. With long-form options you need only enter sufficient characters to uniquely identify the option to the program. For example, .CQ "--out\ %f" works, but .CQ "--o\ %f" fails because .CW "units" has other long options beginning with .CQ "o" . However, .CQ "--q" works because .CQ "--quiet" is the only long option beginning with .CQ "q" . .PP Some options require arguments to specify a value (e.g., .CQ "-d\ 12" or .CQ "--digits\ 12" ). Short-form options that do not take arguments may be concatenated (e.g., .CQ "-erS" is equivalent to .CQ "-e\ -r\ -S" ); the last option in such a list may be one that takes an argument (e.g., .CQ "-ed\ 12" ). With short-form options, the space between an option and its argument is optional (e.g., .CQ "-d12" is equivalent to .CQ "-d\ 12" ). Long-form options may not be concatenated, and the space between a long-form option and its argument is required. Short-form and long-form options may be intermixed on the command line. Options may be given in any order, but when incompatible options (e.g., .CQ "--output-format" and .CQ "--exponential" ) are given in combination, behavior is controlled by the last option given. For example, .CQ "-o%.12f\ -e" gives exponential format with the default eight significant digits). .PP The following options are available: .TP .BR "-\^c" ", " "-\^-\^check" Check that all units and prefixes defined in the units data file reduce to primitive units. Print a list of all units that cannot be reduced. Also display some other diagnostics about suspicious definitions in the units data file. Only definitions active in the current locale are checked. You should always run .CW "units" with this option after modifying a units data file. .TP .BR "-\^-\^check-verbose" ", " "-\^-\^verbose-check" Like the .CQ "--check" option, this option prints a list of units that cannot be reduced. But to help find unit definitions that cause endless loops, it lists the units as they are checked. If .CW "units" hangs, then the last unit to be printed has a bad definition. Only definitions active in the current locale are checked. .TP .BR "-\^d \fIndigits\fP" ", " "-\^-\^digits \fIndigits\fP" Set the number of significant digits in the output to the value specified (which must be greater than zero). For example, .CQ "-d\ 12" sets the number of significant digits to 12. With exponential output .CW "units" displays one digit to the left of the decimal point and eleven digits to the right of the decimal point. On most systems, the maximum number of internally meaningful digits is 15; if you specify a greater number than your system's maximum, .CW "units" will print a warning and set the number to the largest meaningful value. To directly set the maximum value, give an argument of .CW "max" (e.g., .CQ "-d\ max" ). Be aware, of course, that \*(lQsignificant\*(rQ here refers only to the \fIdisplay\fP of numbers; if results depend on physical constants not known to this precision, the physically meaningful precision may be less than that shown. The .CQ "--digits" option conflicts with the .CQ "--output-format" option. .TP .BR "-\^e" ", " "-\^-\^exponential" Set the numeric output format to exponential (i.e., scientific notation), like that used in the Unix .CW "units" program. The default precision is eight significant digits (seven digits to the right of the decimal point); this can be changed with the .CQ "--digits" option. The .CQ "--exponential" option conflicts with the .CQ "--output-format" option. .TP .BR "-\^o \fIformat\fP" ", " "-\^-\^output-format \fIformat\fP" This option affords complete control over the numeric output format using the specified \fIformat\fP. The format is a single floating point numeric format for the .CW "printf()" function in the C programming language. All compilers support the format types .CQ "g" and .CQ "G" to specify significant digits, .CQ "e" and .CQ "E" for scientific notation, and .CQ "f" for fixed-point decimal. The ISO C99 standard introduced the .CQ "F" type for fixed-point decimal and the .CQ "a" and .CQ "A" types for hexadecimal floating point; these types are allowed with compilers that support them. The default format is .CQ "%.8g" ; for greater precision, you could specify .CQ "-o\ %.15g" . See \fINumeric Output Format\fP and the documentation for .CW "printf()" for more detailed descriptions of the format specification. The .CQ "--output-format" option affords the greatest control of the output appearance, but requires at least rudimentary knowledge of the .CW "printf()" format syntax. If you don't want to bother with the .CW "printf()" syntax, you can specify greater precision more simply with the .CQ "--digits" option or select exponential format with .CQ "--exponential" . The .CQ "--output-format" option is incompatible with the .CQ "--exponential" and .CQ "--digits" options. .TP .BR "-\^f \fIfilename\fP" ", " "-\^-\^file \fIfilename\fP" Instruct .CW "units" to load the units file \fIfilename\fP. You can specify up to 25 units files on the command line. When you use this option, .CW "units" will load \fIonly\fP the files you list on the command line; it will not load the standard file or your personal units file unless you explicitly list them. If \fIfilename\fP is the empty string .CQ ( "-f\ """"" ), the default units file (or that specified by .CW "UNITSFILE" ) will be loaded in addition to any others specified with .CQ "-f" . .TP .BR "-\^L \fIlogfile\fP" ", " "-\^-\^log \fIlogfile\fP" Save the results of calculations in the file \fIlogfile\fP; this can be useful if it is important to have a record of unit conversions or other calculations that are to be used extensively or in a critical activity such as a program or design project. If \fIlogfile\fP exits, the new results are appended to the file. This option is ignored when .CW "units" is used non-interactively. See \fILogging Calculations\fP for a more detailed description and some examples. .TP .BR "-\^H \fIfilename\fP" ", " "-\^-\^history \fIfilename\fP" Instruct .CW "units" to save history to \fIfilename\fP, so that a record of your commands is available for retrieval across different .CW "units" invocations. To prevent the history from being saved set \fIfilename\fP to the empty string .CQ ( "-H\ """"" ). This option has no effect if readline is not available. .TP .BR "-\^h" ", " "-\^-\^help" Print out a summary of the options for .CW "units" . .TP .BR "-\^m" ", " "-\^-\^minus" Causes .CQ "-" to be interpreted as a subtraction operator. This is the default behavior. .TP .BR "-\^p" ", " "-\^-\^product" Causes .CQ "-" to be interpreted as a multiplication operator when it has two operands. It will act as a negation operator when it has only one operand: .CQ "(-3)" . By default .CQ "-" is treated as a subtraction operator. .TP .BR "-\^-\^oldstar" Causes .CQ "*" to have the old-style precedence, higher than the precedence of division so that .CQ "1/2*3" will equal .CQ "1/6" . .TP .BR "-\^-\^newstar" Forces .CQ "*" to have the new (default) precedence that follows the usual rules of algebra: the precedence of .CQ "*" is the same as the precedence of .CQ "/" , so that .CQ "1/2*3" will equal .CQ "3/2" . .TP .BR "-\^r" ", " "-\^-\^round" When converting to a combination of units given by a unit list, round the value of the last unit in the list to the nearest integer. .TP .BR "-\^S" ", " "-\^-\^show-factor" When converting to a combination of units specified in a list, always show a non-unity factor before a unit that begins with a fraction with a unity denominator. By default, if the unit in a list begins with fraction of the form 1|\fIx\fP and its multiplier is an integer other than 1, the fraction is given as the product of the multiplier and the numerator (e.g., .CQ "3|8\ in" rather than .CQ "3 * 1|8\ in" ). In some cases, this is not what is wanted; for example, the results for a cooking recipe might show .CQ "3 * 1|2\ cup" as .CQ "3|2\ cup" . With the .CQ "--show-factor" option, a result equivalent to 1.5 cups will display as .CQ "3 * 1|2\ cup" rather than .CQ "3|2\ cup" . A user-specified fractional unit with a numerator other than 1 is never overridden, however\(emif a unit list specifies .CQ "3|4 cup;1|2 cup" , a result equivalent to 1\ 1/2 cups will always be shown as .CQ "2 * 3|4\ cup" whether or not the .CQ "--show-factor" option is given. .IP .TP .BR "-\^v" ", " "-\^-\^verbose" Give slightly more verbose output when converting units. When combined with the .CQ "-c" option this gives the same effect as .CQ "--check-verbose" . When combined with .CQ "--version" produces a more detailed output, equivalent to the .CQ "--info" option. .TP .BR "-\^V" ", " "-\^-\^version" Print the program version number, tell whether the .CW "readline" library has been included, tell whether UTF-8 support has been included; give the locale, the location of the default units data file, and the location of the personal units data file; indicate if the personal units data file does not exist. .IP When given in combination with the .CQ "--terse" option, the program prints only the version number and exits. .IP When given in combination with the .CQ "--verbose" option, the program, the .CQ "--version" option has the same effect as the .CQ "--info" option below. .TP .BR "-\^I" ", " "-\^-\^info" Print the information given with the .CQ "--version" option, show the pathname of the units program, show the status of the .CW "UNITSFILE" and .CW "MYUNITSFILE" environment variables, and additional information about how .CW "units" locates the related files. On systems running Microsoft Windows, the status of the .CW "UNITSLOCALE" environment variable and information about the related locale map are also given. This option is usually of interest only to developers and administrators, but it can sometimes be useful for troubleshooting. .IP Combining the .CQ "--version" and .CQ "--verbose" options has the same effect as giving .CQ "--info" . .TP .BR "-\^U" ", " "-\^-\^unitsfile" Print the location of the default units data file and exit; if the file cannot be found, print \*(lQUnits data file not found\*(rQ. .TP .BR "-\^u (gauss[ian]|esu|emu)" ", " "-\^-\^units (gauss[ian]|esu|emu)" Specify a CGS units system: Gaussian, ESU, or EMU. .TP .BR "-\^l \fIlocale\fP" ", " "-\^-\^locale \fIlocale\fP" Force a specified locale such as .CQ "en_GB" to get British definitions by default. This overrides the locale determined from system settings or environment variables. See \fILocale\fP for a description of locale format. .TP .BR "-\^n" ", " "-\^-\^nolists" Disable conversion to unit lists. .TP .BR "-\^s" ", " "-\^-\^strict" Suppress conversion of units to their reciprocal units. For example, .CW "units" will normally convert hertz to seconds because these units are reciprocals of each other. The strict option requires that units be strictly conformable to perform a conversion, and will give an error if you attempt to convert hertz to seconds. .TP .BR "-\^1" ", " "-\^-\^one-line" Give only one line of output (the forward conversion); do not print the reverse conversion. If a reciprocal conversion is performed, then .CW "units" will still print the \*(lQreciprocal conversion\*(rQ line. .TP .BR "-\^t" ", " "-\^-\^terse" Print only a single conversion factor. This option can be used when calling .CW "units" from another program so that the output is easy to parse. This option has the combined effect of these options: .CQ "--strict" .CQ "--quiet" .CQ "--one-line" .CQ "--compact" . When combined with .CQ "--version" it produces a display showing only the program name and version number. .TP .BR "-\^-\^compact" Give compact output featuring only the conversion factor; the multiplication and division signs are not shown, and there is no leading whitespace. If you convert to a unit list, then the output is a semicolon separated list of factors. This turns off the .CQ "--verbose" option. .TP .BR "-\^q" ", " "-\^-\^quiet" ", " "-\^-\^silent" Suppress the display of statistics about the number of units loaded, any messages printed by the units database, and the prompting of the user for units. This option does not affect how .CW "units" displays the results. This option is turned on by default if you invoke .CW "units" with a unit expression on the command line. .IP .SH OUTPUT STYLES The output can be tweaked in various ways using command line options. With no options, the output looks like this .PP .ES $ units Currency exchange rates from FloatRates (USD base) on 2019-02-20 3070 units, 109 prefixes, 109 nonlinear units You have: 23ft You want: m * 7.0104 / 0.14264521 You have: m You want: ft;in 3 ft + 3.3700787 in .EE .PP This is arguably a bit cryptic; the .CQ "--verbose" option makes clear what the output means: .PP .ES $ units --verbose Currency exchange rates from FloatRates (USD base) on 2019-02-20 3070 units, 109 prefixes, 109 nonlinear units You have: 23 ft You want: m 23 ft = 7.0104 m 23 ft = (1 / 0.14264521) m You have: meter You want: ft;in meter = 3 ft + 3.3700787 in .EE .PP The .CQ "--quiet" option suppresses the clutter displayed when .CW "units" starts, as well as the prompts to the user. This option is enabled by default when you give units on the command line. .PP .ES $ units --quiet 23 ft m * 7.0104 / 0.14264521 $ units 23ft m * 7.0104 / 0.14264521 .EE .PP The remaining style options allow you to display only numerical values without the tab or the multiplication and division signs, or to display just a single line showing the forward conversion: .aQ .PP .ES $ units --compact 23ft m 7.0104 0.14264521 $ units --compact m 'ft;in' 3;3.3700787 $ units --one-line 23ft m * 7.0104 $ units --one-line 23ft 1/m reciprocal conversion * 0.14264521 $ units --one-line 23ft kg conformability error 7.0104 m 1 kg .EE .PP Note that when converting to a unit list, the .CQ "--compact" option displays a semicolon separated list of results. Also be aware that the .CQ "one-line" option doesn't live up to its name if you execute a reciprocal conversion or if you get a conformability error. The former case can be prevented using the .CQ "--strict" option, which suppresses reciprocal conversions. Similarly you can suppress unit list conversion using .CQ "--nolists" . It is impossible to prevent the three line error output. .PP .ES $ units --compact --nolists m 'ft;in' Error in 'ft;in': Parse error $ units --one-line --strict 23ft 1/m .EE .PP The various style options can be combined appropriately. The ultimate combination is the .CQ "--terse" option, which combines .CQ "--strict" , .CQ "--quiet" , .CQ "--one-line" , and .CQ "--compact" to produce the minimal output, just a single number for regular conversions and a semicolon separated list for conversion to unit lists. This will likely be the best choice for programs that want to call .CW "units" and then process its result. .PP .ES $ units --terse 23ft m 7.0104 $ units --terse m 'ft;in' 3;3.3700787 $ units --terse 23ft 1/m conformability error 7.0104 m 1 / m .EE .aE .PP .SH ADDING YOUR OWN DEFINITIONS .SS Units Data Files The units and prefixes that .CW "units" can convert are defined in the units data file, typically .CQ "/usr/share/units/definitions.units" . If you can't find this file, run .CW "units\ --version" to get information on the file locations for your installation. Although you can extend or modify this data file if you have appropriate user privileges, it's usually better to put extensions in separate files so that the definitions will be preserved if you update .CW "units" . .PP You can include additional data files in the units database using the .CQ "!include" command in the standard units data file. For example .PP .ES !include /usr/local/share/units/local.units .EE .PP might be appropriate for a site-wide supplemental data file. The location of the .CQ "!include" statement in the standard units data file is important; later definitions replace earlier ones, so any definitions in an included file will override definitions before the .CQ "!include" statement in the standard units data file. With normal invocation, no warning is given about redefinitions; to ensure that you don't have an unintended redefinition, run .CW "units\ -c" after making changes to any units data file. .PP If you want to add your own units in addition to or in place of standard or site-wide supplemental units data files, you can include them in the .CQ ".units" file in your home directory. If this file exists it is read after the standard units data file, so that any definitions in this file will replace definitions of the same units in the standard data file or in files included from the standard data file. This file will not be read if any units files are specified on the command line. (Under Windows the personal units file is named .CQ "unitdef.units" .) Running .CW "units\ -V" will display the location and name of your personal units file. .PP The .CW "units" program first tries to determine your home directory from the .CW "HOME" environment variable. On systems running Microsoft Windows, if .CW "HOME" does not exist, .CW "units" attempts to find your home directory from .CW "HOMEDRIVE" , .CW "HOMEPATH" and .CW "USERPROFILE" . You can specify an arbitrary file as your personal units data file with the .CW "MYUNITSFILE" environment variable; if this variable exists, its value is used without searching your home directory. The default units data files are described in more detail in \fIData Files\fP. .PP .SS Defining New Units and Prefixes A unit is specified on a single line by giving its name and an equivalence. Comments start with a .CQ "#" character, which can appear anywhere in a line. The backslash character .CQ ( "\e" ) acts as a continuation character if it appears as the last character on a line, making it possible to spread definitions out over several lines if desired. A file can be included by giving the command .CQ "!include" followed by the file's name. The .CQ "!" must be the first character on the line. The file will be sought in the same directory as the parent file unless you give a full path. The name of the file to be included cannot contain spaces or the comment character .CQ "#" . .PP Unit names must not contain any of the operator characters .CQ "+" , .CQ "-" , .CQ "*" , .CQ "/" , .CQ "|" , .CQ "^" , .CQ ";" , .CQ "~" , the comment character .CQ "#" , or parentheses. They cannot begin or end with an underscore .CQ ( "_" ), a comma .CQ ( "," ) or a decimal point .CQ ( "." ). The figure dash (U+2012), typographical minus (`\-'; U+2212), and en dash (`\-'; U+2013) are converted to the operator .CQ "-" , so none of these characters can appear in unit names. Names cannot begin with a digit, and if a name ends in a digit other than zero, the digit must be preceded by a string beginning with an underscore, and afterwards consisting only of digits, decimal points, or commas. For example, .CQ "foo_2" , .CQ "foo_2,1" , or .CQ "foo_3.14" are valid names but .CQ "foo2" or .CQ "foo_a2" are invalid. You could define nitrous oxide as .PP .ES N2O nitrogen 2 + oxygen .EE .PP but would need to define nitrogen dioxide as .PP .ES NO_2 nitrogen + oxygen 2 .EE .PP Be careful to define new units in terms of old ones so that a reduction leads to the primitive units, which are marked with .CQ "!" characters. Dimensionless units are indicated by using the string .CQ "!dimensionless" for the unit definition. .PP When adding new units, be sure to use the .CQ "-c" option to check that the new units reduce properly. If you create a loop in the units definitions, then .CW "units" will hang when invoked with the .CQ "-c" option. You will need to use the .CQ "--check-verbose" option, which prints out each unit as it is checked. The program will still hang, but the last unit printed will be the unit that caused the infinite loop. .PP If you define any units that contain .CQ "+" characters in their definitions, carefully check them because the .CQ "-c" option will not catch non-conformable sums. Be careful with the .CQ "-" operator as well. When used as a binary operator, the .CQ "-" character can perform addition or multiplication depending on the options used to invoke .CW "units" . To ensure consistent behavior use .CQ "-" only as a unary negation operator when writing units definitions. To multiply two units leave a space or use the .CQ "*" operator with care, recalling that it has two possible precedence values and may require parentheses to ensure consistent behavior. To compute the difference of .CQ "foo" and .CQ "bar" write .CQ "foo+(-bar)" or even .CQ "foo+-bar" . .PP You may wish to intentionally redefine a unit. When you do this, and use the .CQ "-c" option, .CW "units" displays a warning message about the redefinition. You can suppress these warnings by redefining a unit using a .CQ "+" at the beginning of the unit name. Do not include any white space between the .CQ "+" and the redefined unit name. .PP Here is an example of a short data file that defines some basic units: .PP .ES m ! # The meter is a primitive unit sec ! # The second is a primitive unit rad !dimensionless # A dimensionless primitive unit micro- 1e-6 # Define a prefix minute 60 sec # A minute is 60 seconds hour 60 min # An hour is 60 minutes inch 72 m # Inch defined incorrectly terms of meters ft 12 inches # The foot defined in terms of inches mile 5280 ft # And the mile +inch 0.0254 m # Correct redefinition, warning suppressed .EE .PP A unit that ends with a .CQ "-" character is a prefix. If a prefix definition contains any .CQ "/" characters, be sure they are protected by parentheses. If you define .CQ "half- 1/2" , then .CQ "halfmeter" would be equivalent to .CQ "1 / (2\ meter)" . .PP .SS Defining Nonlinear Units Some unit conversions of interest are nonlinear; for example, temperature conversions between the Fahrenheit and Celsius scales cannot be done by simply multiplying by conversion factors. .PP When you give a linear unit definition such as .CQ "inch 2.54\ cm" you are providing information that .CW "units" uses to convert values in inches into primitive units of meters. For nonlinear units, you give a functional definition that provides the same information. .PP Nonlinear units are represented using a functional notation. It is best to regard this notation not as a function call but as a way of adding units to a number, much the same way that writing a linear unit name after a number adds units to that number. Internally, nonlinear units are defined by a pair of functions that convert to and from linear units in the database, so that an eventual conversion to primitive units is possible. .PP Here is an example nonlinear unit definition: .PP .ES tempF(x) units=[1;K] domain=[-459.67,) range=[0,) \e (x+(-32)) degF + stdtemp ; (tempF+(-stdtemp))/degF + 32 .EE .PP A nonlinear unit definition comprises a unit name, a formal parameter name, two functions, and optional specifications for units, the domain, and the range (the domain of the inverse function). The functions tell .CW "units" how to convert to and from the new unit. To produce valid results, the arguments of these functions need to have the correct dimensions and be within the domains for which the functions are defined. .PP The definition begins with the unit name followed immediately (with no spaces) by a .CQ "(" character. In the parentheses is the name of the formal parameter. Next is an optional specification of the units required by the functions in the definition. In the example above, the .CQ "units=[1;K]" specification indicates that the .CQ "tempF" function requires an input argument conformable with .CQ "1" (i.e., the argument is dimensionless), and that the inverse function requires an input argument conformable with .CQ "K" . For normal nonlinear units definition, the forward function will always take a dimensionless argument; in general, the inverse function will need units that match the quantity measured by your nonlinear unit. Specifying the units enables .CW "units" to perform error checking on function arguments, and also to assign units to domain and range specifications, which are described later. .PP Next the function definitions appear. In the example above, the .CQ "tempF" function is defined by .PP .ES tempF(x) = (x+(-32)) degF + stdtemp .EE .PP This gives a rule for converting .CQ "x" in the units .CQ "tempF" to linear units of absolute temperature, which makes it possible to convert from tempF to other units. .PP To enable conversions to Fahrenheit, you must give a rule for the inverse conversions. The inverse will be .CQ "x(tempF)" and its definition appears after a .CQ ";" character. In our example, the inverse is .PP .ES x(tempF) = (tempF+(-stdtemp))/degF + 32 .EE .PP This inverse definition takes an absolute temperature as its argument and converts it to the Fahrenheit temperature. The inverse can be omitted by leaving out the .CQ ";" character and the inverse definition, but then conversions \fIto\fP the unit will not be possible. If the inverse definition is omitted, the .CQ "--check" option will display a warning. It is up to you to calculate and enter the correct inverse function to obtain proper conversions; the .CQ "--check" option tests the inverse at one point and prints an error if it is not valid there, but this is not a guarantee that your inverse is correct. .PP With some definitions, the units may vary. For example, the definition .PP .ES square(x) x^2 .EE .PP can have any arbitrary units, and can also take dimensionless arguments. In such a case, you should \fInot\fP specify units. If a definition takes a root of its arguments, the definition is valid only for units that yield such a root. For example, .PP .ES squirt(x) sqrt(x) .EE .PP is valid for a dimensionless argument, and for arguments with even powers of units. .PP Some definitions may not be valid for all real numbers. In such cases, .CW "units" can handle errors better if you specify an appropriate domain and range. You specify the domain and range as shown below: .PP .ES baume(d) units=[1;g/cm^3] domain=[0,130.5] range=[1,10] \e (145/(145-d)) g/cm^3 ; (baume+-g/cm^3) 145 / baume .EE .PP In this example the domain is specified after .CQ "domain=" with the endpoints given in brackets. In accord with mathematical convention, square brackets indicate a closed interval (one that includes its endpoints), and parentheses indicate an open interval (one that does not include its endpoints). An interval can be open or closed on one or both ends; an interval that is unbounded on either end is indicated by omitting the limit on that end. For example, a quantity to which decibel (dB) is applied may have any value greater than zero, so the range is indicated by .CQ "(0,)" : .PP .ES decibel(x) units=[1;1] range=(0,) 10^(x/10); 10 log(decibel) .EE .PP If the domain or range is given, the second endpoint must be greater than the first. .PP The domain and range specifications can appear independently and in any order along with the units specification. The values for the domain and range endpoints are attached to the units given in the units specification, and if necessary, the parameter value is adjusted for comparison with the endpoints. For example, if a definition includes .CQ "units=[1;ft]" and .CQ "range=[3,)" , the range will be taken as 3\ ft to infinity. If the function is passed a parameter of .CQ "900\ mm" , that value will be adjusted to 2.9527559\ ft, which is outside the specified range. If you omit the units specification from the previous example, .CW "units" can not tell whether you intend the lower endpoint to be 3\ ft or 3\ microfurlongs, and can not adjust the parameter value of 900\ mm for comparison. Without units, numerical values other than zero or plus or minus infinity for domain or range endpoints are meaningless, and accordingly they are not allowed. If you give other values without units, then the definition will be ignored and you will get an error message. .PP Although the units, domain, and range specifications are optional, it's best to give them when they are applicable; doing so allows .CW "units" to perform better error checking and give more helpful error messages. Giving the domain and range also enables the .CQ "--check" option to find a point in the domain to use for its point check of your inverse definition. .PP You can make synonyms for nonlinear units by providing both the forward and inverse functions; inverse functions can be obtained using the .CQ "~" operator. So to create a synonym for .CQ "tempF" you could write .PP .ES fahrenheit(x) units=[1;K] tempF(x); ~tempF(fahrenheit) .EE .PP This is useful for creating a nonlinear unit definition that differs slightly from an existing definition without having to repeat the original functions. For example, .PP .ES dBW(x) units=[1;W] range=[0,) dB(x) W ; ~dB(dBW/W) .EE .PP If you wish a synonym to refer to an existing nonlinear unit without modification, you can do so more simply by adding the synonym with appended parentheses as a new unit, with the existing nonlinear unit\(emwithout parentheses\(emas the definition. So to create a synonym for .CQ "tempF" you could write .PP .ES fahrenheit() tempF .EE .PP The definition must be a nonlinear unit; for example, the synonym .PP .ES fahrenheit() meter .EE .PP will result in an error message when .CW "units" starts. .PP You may occasionally wish to define a function that operates on units. This can be done using a nonlinear unit definition. For example, the definition below provides conversion between radius and the area of a circle. This definition requires a length as input and produces an area as output, as indicated by the .CQ "units=" specification. Specifying the range as the nonnegative numbers can prevent cryptic error messages. .PP .ES circlearea(r) units=[m;m^2] range=[0,) pi r^2 ; sqrt(circlearea/pi) .EE .PP .SS Defining Piecewise Linear Units Sometimes you may be interested in a piecewise linear unit such as many wire gauges. Piecewise linear units can be defined by specifying conversions to linear units on a list of points. Conversion at other points will be done by linear interpolation. A partial definition of zinc gauge is .PP .ES zincgauge[in] 1 0.002, 10 0.02, 15 0.04, 19 0.06, 23 0.1 .EE .PP In this example, .CQ "zincgauge" is the name of the piecewise linear unit. The definition of such a unit is indicated by the embedded .CQ "[" character. After the bracket, you should indicate the units to be attached to the numbers in the table. No spaces can appear before the .CQ "]" character, so a definition like .CQ "foo[kg meters]" is invalid; instead write .CQ "foo[kg*meters]" . The definition of the unit consists of a list of pairs optionally separated by commas. This list defines a function for converting from the piecewise linear unit to linear units. The first item in each pair is the function argument; the second item is the value of the function at that argument (in the units specified in brackets). In this example, we define .CQ "zincgauge" at five points. For example, we set .CQ "zincgauge(1)" equal to .CQ "0.002\ in" . Definitions like this may be more readable if written using continuation characters as .PP .ES zincgauge[in] \e 1 0.002 \e 10 0.02 \e 15 0.04 \e 19 0.06 \e 23 0.1 .EE .PP With the preceding definition, the following conversion can be performed: .PP .ES You have: zincgauge(10) You want: in * 0.02 / 50 You have: .01 inch You want: zincgauge 5 .EE .PP If you define a piecewise linear unit that is not strictly monotonic, then the inverse will not be well defined. If the inverse is requested for such a unit, .CW "units" will return the smallest inverse. .PP After adding nonlinear units definitions, you should normally run .CW "units\ --check" to check for errors. If the .CQ "units" keyword is not given, the .CQ "--check" option checks a nonlinear unit definition using a dimensionless argument, and then checks using an arbitrary combination of units, as well as the square and cube of that combination; a warning is given if any of these tests fail. For example, .aQ .PP .ES Warning: function 'squirt(x)' defined as 'sqrt(x)' failed for some test inputs: squirt(7(kg K)^1): Unit not a root squirt(7(kg K)^3): Unit not a root .EE .aE .PP Running .CW "units\ --check" will print a warning if a non-monotonic piecewise linear unit is encountered. For example, the relationship between ANSI coated abrasive designation and mean particle size is non-monotonic in the vicinity of 800 grit: .PP .ES ansicoated[micron] \e . . . 600 10.55 \e 800 11.5 \e 1000 9.5 \e .EE .PP Running .CW "units\ --check" would give the error message .aQ .PP .ES Table 'ansicoated' lacks unique inverse around entry 800 .EE .aE .PP Although the inverse is not well defined in this region, it's not really an error. Viewing such error messages can be tedious, and if there are enough of them, they can distract from true errors. Error checking for nonlinear unit definitions can be suppressed by giving the .CQ "noerror" keyword; for the examples above, this could be done as .PP .ES squirt(x) noerror domain=[0,) range=[0,) sqrt(x); squirt^2 ansicoated[micron] noerror \e . . . .EE .PP Use the .CQ "noerror" keyword with caution. The safest approach after adding a nonlinear unit definition is to run .CW "units\ --check" and confirm that there are no actual errors before adding the .CQ "noerror" keyword. .PP .SS Defining Unit List Aliases Unit list aliases are treated differently from unit definitions, because they are a data entry shorthand rather than a true definition for a new unit. A unit list alias definition begins with .CQ "!unitlist" and includes the alias and the definition; for example, the aliases included in the standard units data file are .PP .ES !unitlist hms hr;min;sec !unitlist time year;day;hr;min;sec !unitlist dms deg;arcmin;arcsec !unitlist ftin ft;in;1|8 in !unitlist usvol cup;3|4 cup;2|3 cup;1|2 cup;1|3 cup;1|4 cup;\e tbsp;tsp;1|2 tsp;1|4 tsp;1|8 tsp .EE .PP Unit list aliases are only for unit lists, so the definition must include a .CQ ";" . Unit list aliases can never be combined with units or other unit list aliases, so the definition of .CQ "time" shown above could \fInot\fP have been shortened to .CQ "year;day;hms" . .PP As usual, be sure to run .CW "units\ --check" to ensure that the units listed in unit list aliases are conformable. .PP .SH NUMERIC OUTPUT FORMAT By default, .CW "units" shows results to eight significant digits. You can change this with the .CQ "--exponential" , .CQ "--digits" , and .CQ "--output-format" options. The first sets an exponential format (i.e., scientific notation) like that used in the original Unix .CW "units" program, the second allows you to specify a different number of significant digits, and the last allows you to control the output appearance using the format for the .CW "printf()" function in the C programming language. If you only want to change the number of significant digits or specify exponential format type, use the .CQ "--digits" and .CQ "--exponential" options. The .CQ "--output-format" option affords the greatest control of the output appearance, but requires at least rudimentary knowledge of the .CW "printf()" format syntax. See \fIInvoking Units\fP for descriptions of these options. .PP .SS Format Specification The format specification recognized with the .CQ "--output-format" option is a subset of that for .CW "printf()" . The format specification has the form .\".CW "%\fR[\fP\fIflags\fP\fR][\fP\fIwidth\fP\fR][\fP.\fIprecision\fP\fR]\fP\fItype\fP" ; .CW "%" [\fIflags\fP][\fIwidth\fP][\c .CW "." \fIprecision\fP]\fItype\fP; it must begin with .CQ "%" , and must end with a floating-point type specifier: .CQ "g" or .CQ "G" to specify the number of significant digits, .CQ "e" or .CQ "E" for scientific notation, and .CQ "f" for fixed-point decimal. The ISO C99 standard added the .CQ "F" type for fixed-point decimal and the .CQ "a" and .CQ "A" types for hexadecimal floating point; these types are allowed with compilers that support them. Type length modifiers (e.g., .CQ "L" to indicate a long double) are inapplicable and are not allowed. .PP The default format for .CW "units" is .CQ "%.8g" ; for greater precision, you could specify .CQ "-o\ %.15g" . The .CQ "g" and .CQ "G" format types use exponential format whenever the exponent would be less than \-4, so the value 0.000013 displays as .CQ "1.3e-005" . These types also use exponential notation when the exponent is greater than or equal to the precision, so with the default format, the value .if t .ig ++ 5e7 .++ .if n .ig ++ .EQ 5 times 10 sup 7 .EN .++ displays as .CQ "50000000" and the value .if t .ig ++ 5e8 .++ .if n .ig ++ .EQ 5 times 10 sup 8 .EN .++ displays as .CQ "5e+008" . If you prefer fixed-point display, you might specify .CQ "-o\ %.8f" ; however, small numbers will display very few significant digits, and values less than .if t .ig ++ 0.5e\-8 .++ .if n .ig ++ .EQ 0.5 times 10 sup -8 .EN .++ will show nothing but zeros. .PP The format specification may include one or more optional flags: .CQ "+" , .CQ "\ " (space), .CQ "#" , .CQ "-" , or .CQ "0" (the digit zero). The digit-grouping flag .ie \n(.g .CQ "\(aq" .el .CQ "'" is allowed with compilers that support it. Flags are followed by an optional value for the minimum field width, and an optional precision specification that begins with a period (e.g., .CQ ".6" ). The field width includes the digits, decimal point, the exponent, thousands separators (with the digit-grouping flag), and the sign if any of these are shown. .PP .SS Flags The .CQ "+" flag causes the output to have a sign .CQ ( "+" "" or .CQ "-" ). The space flag .CQ "\ " is similar to the .CQ "+" flag, except that when the value is positive, it is prefixed with a space rather than a plus sign; this flag is ignored if the .CQ "+" flag is also given. The .CQ "+" or .CQ "\ " flag could be useful if conversions might include positive and negative results, and you wanted to align the decimal points in exponential notation. The .CQ "#" flag causes the output value to contain a decimal point in all cases; by default, the output contains a decimal point only if there are digits (which can be trailing zeros) to the right of the point. With the .CQ "g" or .CQ "G" types, the .CQ "#" flag also prevents the suppression of trailing zeros. The digit-grouping flag .ie \n(.g .CQ "\(aq" .el .CQ "'" shows a thousands separator in digits to the left of the decimal point. This can be useful when displaying large numbers in fixed-point decimal; for example, with the format .CQ "%f" , .PP .ES You have: mile You want: microfurlong * 8000000.000000 / 0.000000 .EE .PP the magnitude of the first result may not be immediately obvious without counting the digits to the left of the decimal point. If the thousands separator is the comma .CQ ( "," ), the output with the format .ie \n(.g .CQ "%\(aqf" .el .CQ "%'f" might be .PP .ES You have: mile You want: microfurlong * 8,000,000.000000 / 0.000000 .EE .PP making the magnitude readily apparent. Unfortunately, few compilers support the digit-grouping flag. .PP With the .CQ "-" flag, the output value is left aligned within the specified field width. If a field width greater than needed to show the output value is specified, the .CQ "0" (zero) flag causes the output value to be left padded with zeros until the specified field width is reached; for example, with the format .CQ "%011.6f" , .PP .ES You have: troypound You want: grain * 5760.000000 / 0000.000174 .EE .PP The .CQ "0" flag has no effect if the .CQ "-" (left align) flag is given. .PP .SS Field Width By default, the output value is left aligned and shown with the minimum width necessary for the specified (or default) precision. If a field width greater than this is specified, the value shown is right aligned, and padded on the left with enough spaces to provide the specified field width. A width specification is typically used with fixed-point decimal to have columns of numbers align at the decimal point; this arguably is less useful with .CW "units" than with long columnar output, but it may nonetheless assist in quickly assessing the relative magnitudes of results. For example, with the format .CQ "%12.6f" , .PP .ES You have: km You want: in * 39370.078740 / 0.000025 You have: km You want: rod * 198.838782 / 0.005029 You have: km You want: furlong * 4.970970 / 0.201168 .EE .PP .SS Precision The meaning of \*(lQprecision\*(rQ depends on the format type. With .CQ "g" or .CQ "G" , it specifies the number of significant digits (like the .CQ "--digits" option); with .CQ "e" , .CQ "E" , .CQ "f" , or .CQ "F" , it specifies the maximum number of digits to be shown after the decimal point. .PP With the .CQ "g" and .CQ "G" format types, trailing zeros are suppressed, so the results may sometimes have fewer digits than the specified precision (as indicated above, the .CQ "#" flag causes trailing zeros to be displayed). .PP The default precision is 6, so .CQ "%g" is equivalent to .CQ "%.6g" , and would show the output to six significant digits. Similarly, .CQ "%e" or .CQ "%f" would show the output with six digits after the decimal point. .PP The C .CW "printf()" function allows a precision of arbitrary size, whether or not all of the digits are meaningful. With most compilers, the maximum internal precision with .CW "units" is 15 decimal digits (or 13 hexadecimal digits). With the .CQ "--digits" option, you are limited to the maximum internal precision; with the .CQ "--output-format" option, you may specify a precision greater than this, but it may not be meaningful. In some cases, specifying excess precision can result in rounding artifacts. For example, a pound is exactly 7000 grains, but with the format .CQ "%.18g" , the output might be .PP .ES You have: pound You want: grain * 6999.9999999999991 / 0.00014285714285714287 .EE .PP With the format .CQ "%.25g" you might get the following: .PP .ES You have: 1/3 You want: Definition: 0.333333333333333314829616256247 .EE .PP In this case the displayed value includes a series of digits that represent the underlying binary floating-point approximation to 1/3 but are not meaningful for the desired computation. In general, the result with excess precision is system dependent. The precision affects only the \fIdisplay\fP of numbers; if a result relies on physical constants that are not known to the specified precision, the number of physically meaningful digits may be less than the number of digits shown. .PP See the documentation for .CW "printf()" for more detailed descriptions of the format specification. .PP The .CQ "--output-format" option is incompatible with the .CQ "--exponential" or .CQ "--digits" options; if the former is given in combination with either of the latter, the format is controlled by the last option given. .PP .SH LOCALIZATION Some units have different values in different locations. The localization feature accommodates this by allowing a units data file to specify definitions that depend on the user's locale. .PP .SS Locale A locale is a subset of a user's environment that indicates the user's language and country, and some attendant preferences, such as the formatting of dates. The .CW "units" program attempts to determine the locale from the POSIX setlocale function; if this cannot be done, .CW "units" examines the environment variables .CW "LC_CTYPE" and .CW "LANG" . On POSIX systems, a locale is of the form .CW \fIlanguage\fP "_" \fIcountry\fP, where \fIlanguage\fP is the two-character code from ISO 639-1 and \fIcountry\fP is the two-character code from ISO 3166-1; \fIlanguage\fP is lower case and \fIcountry\fP is upper case. For example, the POSIX locale for the United Kingdom is .CW "en_GB" . .PP On systems running Microsoft Windows, the value returned by setlocale() is different from that on POSIX systems; .CW "units" attempts to map the Windows value to a POSIX value by means of a table in the file .CQ "locale_map.txt" in the same directory as the other data files. The file includes entries for many combinations of language and country, and can be extended to include other combinations. The .CQ "locale_map.txt" file comprises two tab-separated columns; each entry is of the form .PP .DS \fIWindows-locale\fP \fIPOSIX-locale\fP .DE .PP where \fIPOSIX-locale\fP is as described above, and \fIWindows-locale\fP typically spells out both the language and country. For example, the entry for the United States is .PP .ES English_United States en_US .EE .PP You can force .CW "units" to run in a desired locale by using the .CQ "-l" option. .PP In order to create unit definitions for a particular locale you begin a block of definitions in a unit datafile with .CQ "!locale" followed by a locale name. The .CQ "!" must be the first character on the line. The .CW "units" program reads the following definitions only if the current locale matches. You end the block of localized units with .CQ "!endlocale" . Here is an example, which defines the British gallon. .PP .ES !locale en_GB gallon 4.54609 liter !endlocale .EE .PP .SS Additional Localization Sometimes the locale isn't sufficient to determine unit preferences. There could be regional preferences, or a company could have specific preferences. Though probably uncommon, such differences could arise with the choice of English customary units outside of English-speaking countries. To address this, .CW "units" allows specifying definitions that depend on environment variable settings. The environment variables can be controled based on the current locale, or the user can set them to force a particular group of definitions. .PP A conditional block of definitions in a units data file begins with either .CQ "!var" or .CQ "!varnot" following by an environment variable name and then a space separated list of values. The leading .CQ "!" must appear in the first column of a units data file, and the conditional block is terminated by .CQ "!endvar" . Definitions in blocks beginning with .CQ "!var" are executed only if the environment variable is exactly equal to one of the listed values. Definitions in blocks beginning with .CQ "!varnot" are executed only if the environment variable does \fInot\fP equal any of the list values. .PP The inch has long been a customary measure of length in many places. The word comes from the Latin \fIuncia\fP meaning \*(lQone twelfth,\*(rQ referring to its relationship with the foot. By the 20th century, the inch was officially defined in English-speaking countries relative to the yard, but until 1959, the yard differed slightly among those countries. In France the customary inch, which was displaced in 1799 by the meter, had a different length based on a french foot. These customary definitions could be accommodated as follows: .PP .ES !var INCH_UNIT usa yard 3600|3937 m !endvar !var INCH_UNIT canada yard 0.9144 meter !endvar !var INCH_UNIT uk yard 0.91439841 meter !endvar !var INCH_UNIT canada uk usa foot 1|3 yard inch 1|12 foot !endvar !var INCH_UNIT france foot 144|443.296 m inch 1|12 foot line 1|12 inch !endvar !varnot INCH_UNIT usa uk france canada !message Unknown value for INCH_UNIT !endvar .EE .PP When .CW "units" reads the above definitions it will check the environment variable .CW "INCH_UNIT" and load only the definitions for the appropriate section. If .CW "INCH_UNIT" is unset or is not set to one of the four values listed, then .CW "units" will run the last block. In this case that block uses the .CQ "!message" command to display a warning message. Alternatively that block could set default values. .PP In order to create default values that are overridden by user settings the data file can use the .CQ "!set" command, which sets an environment variable \fIonly if it is not already set\fP; these settings are only for the current .CW "units" invocation and do not persist. So if the example above were preceded by .CQ "!set INCH_UNIT france" , then this would make .CQ "france" the default value for .CW "INCH_UNIT" . If the user had set the variable in the environment before invoking .CW "units" , then .CW "units" would use the user's value. .PP To link these settings to the user's locale you combine the .CQ "!set" command with the .CQ "!locale" command. If you wanted to combine the above example with suitable locales you could do by \fIpreceding\fP the above definition with the following: .PP .ES !locale en_US !set INCH_UNIT usa !endlocale !locale en_GB !set INCH_UNIT uk !endlocale !locale en_CA !set INCH_UNIT canada !endlocale !locale fr_FR !set INCH_UNIT france !endlocale !set INCH_UNIT france .EE .PP These definitions set the overall default for .CW "INCH_UNIT" to .CQ "france" and set default values for four locales appropriately. The overall default setting comes last so that it only applies when .CW "INCH_UNIT" was not set by one of the other commands or by the user. .PP If the variable given after .CQ "!var" or .CQ "!varnot" is undefined, then .CW "units" prints an error message and ignores the definitions that follow. Use .CQ "!set" to create defaults to prevent this situation from arising. The .CQ "-c" option only checks the definitions that are active for the current environment and locale, so when adding new definitions take care to check that all cases give rise to a well defined set of definitions. .PP .SH ENVIRONMENT VARIABLES The .CW "units" program uses the following environment variables: .TP .BR "HOME" Specifies the location of your home directory; it is used by .CW "units" to find a personal units data file .CQ ".units" . On systems running Microsoft Windows, the file is .CQ "unitdef.units" , and if .CW "HOME" does not exist, .CW "units" tries to determine your home directory from the .CW "HOMEDRIVE" and .CW "HOMEPATH" environment variables; if these variables do not exist, units finally tries .CW "USERPROFILE" \(emtypically .CQ "C:\eUsers\e\fIusername\fP" (Windows Vista and Windows\ 7) or .CQ "C:\eDocuments\ and\ Settings\e\fIusername\fP" (Windows\ XP). .TP .BR "LC_CTYPE, LANG" Checked to determine the locale if .CW "units" cannot obtain it from the operating system. Sections of the standard units data file are specific to certain locales. .TP .BR "MYUNITSFILE" Specifies your personal units data file. If this variable exists, .CW "units" uses its value rather than searching your home directory for .CQ ".units" . The personal units file will not be loaded if any data files are given using the .CQ "-f" option. .TP .BR "PAGER" Specifies the pager to use for help and for displaying the conformable units. The help function browses the units database and calls the pager using the .CQ "+n" \fIn\fP syntax for specifying a line number. The default pager is .CW "more" ; .CW "PAGER" can be used to specify alternatives such as .CW "less" , .CW "pg" , .CW "emacs" , or .CW "vi" . .TP .BR "UNITS_ENGLISH" Set to either .CQ "US" or .CQ "GB" to choose United States or British volume definitions, overriding the default from your locale. .TP .BR "UNITSFILE" Specifies the units data file to use (instead of the default). You can only specify a single units data file using this environment variable. If units data files are given using the .CQ "-f" option, the file specified by .CW "UNITSFILE" will be not be loaded unless the .CQ "-f" option is given with the empty string .CQ ( "units\ -f\ """"" ). .TP .BR "UNITSLOCALEMAP" Windows only; this variable has no effect on Unix-like systems. Specifies the units locale map file to use (instead of the default). This variable seldom needs to be set, but you can use it to ensure that the locale map file will be found if you specify a location for the units data file using either the .CQ "-f" option or the .CW "UNITSFILE" environment variable, and that location does not also contain the locale map file. .TP .BR "UNITS_SYSTEM" This environment variable is used in the standard data file to select CGS measurement systems. Currently supported systems are .CQ "esu" , .CQ "emu" , .CQ "gauss[ian]" , and .CQ "si" . The default is .CQ "si" . .IP .SH DATA FILES The .CW "units" program uses two default data files: .CQ "definitions.units" and .CQ "currency.units" . The program can also use an optional personal units data file .CQ ".units" .CQ ( "unitdef.units" "" under Windows) located in the user's home directory. The personal units data file is described in more detail in \fIUnits Data Files\fP. .PP On Unix-like systems, the data files are typically located in .CQ "/usr/share/units" if .CW "units" is provided with the operating system, or in .CQ "/usr/local/share/units" if .CW "units" is compiled from the source distribution. Note that the currency file .CQ "currency.units" is a symbolic link to another location. .PP On systems running Microsoft Windows, the files may be in the same locations if Unix-like commands are available, a Unix-like file structure is present (e.g., .CQ "C:/usr/local" ), and .CW "units" is compiled from the source distribution. If Unix-like commands are not available, a more common location is .CQ "C:\eProgram\ Files\ (x86)\eGNU\eunits" (for 64-bit Windows installations) or .CQ "C:\eProgram\ Files\eGNU\eunits" (for 32-bit installations). .PP If .CW "units" is obtained from the GNU Win32 Project (\fRhttp://gnuwin32.sourceforge.net/\fP), the files are commonly in .CQ "C:\eProgram\ Files\eGnuWin32\eshare\eunits" . .PP If the default units data file is not an absolute pathname, .CW "units" will look for the file in the directory that contains the .CW "units" program; if the file is not found there, .CW "units" will look in a directory .CW "../share/units" relative to the directory with the .CW "units" program. .PP You can determine the location of the files by running .CW "units\ --version" . Running .CW "units\ --info" will give you additional information about the files, how .CW "units" will attempt to find them, and the status of the related environment variables. .PP .SH UNICODE SUPPORT The standard units data file is in Unicode, using UTF-8 encoding. Most definitions use only ASCII characters (i.e., code points U+0000 through U+007F); definitions using non-ASCII characters appear in blocks beginning with .CQ "!utf8" and ending with .CQ "!endutf8" . .PP The non-ASCII definitions are loaded only if the platform and the locale support UTF-8. Platform support is determined when .CW "units" is compiled; the locale is checked at every invocation of .CW "units" . To see if your version of .CW "units" includes Unicode support, invoke the program with the .CQ "--version" option. .PP When Unicode support is available, .CW "units" checks every line within UTF-8 blocks in all of the units data files for invalid or non-printing UTF-8 sequences; if such sequences occur, .CW "units" ignores the entire line. In addition to checking validity, .CW "units" determines the display width of non-ASCII characters to ensure proper positioning of the pointer in some error messages and to align columns for the .CQ "search" and .CQ "?" commands. .PP As of early 2019, Microsoft Windows provides limited support for UTF-8 in console applications, and accordingly, .CW "units" does not support Unicode on Windows. The UTF-16 and UTF-32 encodings are not supported on any platforms. .PP If Unicode support is available and definitions that contain non-ASCII UTF-8 characters are added to a units data file, those definitions should be enclosed within .CQ "!utf8" \*(El .CQ "!endutf8" to ensure that they are only loaded when Unicode support is available. As usual, the .CQ "!" must appear as the first character on the line. As discussed in \fIUnits Data Files\fP, it's usually best to put such definitions in supplemental data files linked by an .CQ "!include" command or in a personal units data file. .PP When Unicode support is not available, .CW "units" makes no assumptions about character encoding, except that characters in the range 00\-7F hexadecimal correspond to ASCII encoding. Non-ASCII characters are simply sequences of bytes, and have no special meanings; for definitions in supplementary units data files, you can use any encoding consistent with this assumption. For example, if you wish to use non-ASCII characters in definitions when running .CW "units" under Windows, you can use a character set such as Windows \*(lQANSI\*(rQ (code page 1252 in the US and Western Europe); if this is done, the console code page must be set to the same encoding for the characters to display properly. You can even use UTF-8, though some messages may be improperly aligned, and .CW "units" will not detect invalid UTF-8 sequences. If you use UTF-8 encoding when Unicode support is not available, you should place any definitions with non-ASCII characters \fIoutside\fP .CQ "!utf8" \*(El .CQ "!endutf8" blocks\(emotherwise, they will be ignored. .PP Typeset material other than code examples usually uses the Unicode minus (U+2212) rather than the ASCII hyphen-minus operator (U+002D) used in .CW "units" ; the figure dash (U+2012) and en dash (U+2013) are also occasionally used. To allow such material to be copied and pasted for interactive use or in units data files, .CW "units" converts these characters to U+002D before further processing. Because of this, none of these characters can appear in unit names. .PP .SH READLINE SUPPORT If the .CW "readline" package has been compiled in, then when .CW "units" is used interactively, numerous command line editing features are available. To check if your version of .CW "units" includes .CW "readline" , invoke the program with the .CQ "--version" option. .PP For complete information about .CW "readline" , consult the documentation for the .CW "readline" package. Without any configuration, .CW "units" will allow editing in the style of emacs. Of particular use with .CW "units" are the completion commands. .PP If you type a few characters and then hit \fIESC\fP followed by .CI "?" , then .CW "units" will display a list of all the units that start with the characters typed. For example, if you type .CI "metr" and then request completion, you will see something like this: .PP .ES You have: metr metre metriccup metrichorsepower metrictenth metretes metricfifth metricounce metricton metriccarat metricgrain metricquart metricyarncount You have: metr .EE .PP If there is a unique way to complete a unit name, you can hit the \fITAB\fP key and .CW "units" will provide the rest of the unit name. If .CW "units" beeps, it means that there is no unique completion. Pressing the \fITAB\fP key a second time will print the list of all completions. .PP The readline library also keeps a history of the values you enter. You can move through this history using the up and down arrows. The history is saved to the file .CQ ".units_history" in your home directory so that it will persist across multiple .CW "units" invocations. If you wish to keep work for a certain project separate you can change the history filename using the .CQ "--history" option. You could, for example, make an alias for .CW "units" to .CW "units --history .units_history" so that .CW "units" would save separate history in the current directory. The length of each history file is limited to 5000 lines. Note also that if you run several concurrent copies of .CW "units" each one will save its new history to the history file upon exit. .PP .SH UPDATING CURRENCY EXCHANGE RATES .na The units program database includes currency exchange rates and prices for some precious metals. Of course, these values change over time, sometimes very rapidly, and .CW "units" cannot provide real-time values. To update the exchange rates, run .CW "units_cur" , which rewrites the file containing the currency rates, typically .CQ "/var/lib/\:units/\:currency.units" or .CQ "/usr/local/\:com/\:units/\:currency.units" on a Unix-like system or .CQ "C:\eProgram\ Files\ (x86)\e\:GNU\e\:units\e\:definitions.units" on a Windows system. .ad b .PP This program requires Python (\fRhttps://www.python.org\fP); either version 2 or 3 will work. The program must be run with suitable permissions to write the file. To keep the rates updated automatically, run it using a cron job on a Unix-like system, or a similar scheduling program on a different system. .PP Reliable free sources of currency exchange rates have been annoyingly ephemeral. The program currently supports several sources: .PP .IP \h'1n'\(bu 4n FloatRates (\fRhttps://www/floatrates.com\fP). The US dollar .CQ ( "USD" ) is the default base currency. You can change the base currency with the .CQ "-b" option described below. Allowable base currencies are listed on the FloatRates website. Exchange rates update daily. .PP .IP \h'1n'\(bu 4n The European Central Bank (\fRhttps://www.ecb.europa.eu\fP). The base currency is always the euro .CQ ( "EUR" ). Exchange rates update daily. This source offers a more limited list of currencies than the others. .PP .IP \h'1n'\(bu 4n Fixer (\fRhttps://fixer.io\fP). Registration for a free API key is required. With a free API key, base currency is the euro; exchange rates are updated hourly, the service has a limit of 1,000 API calls per month, and SSL encryption (https protocol) is not available. Most of these restrictions are eliminated or reduced with paid plans. .PP .IP \h'1n'\(bu 4n open exchange rates (\fRhttps://openexchangerates.org\fP). Registration for a free API key is required. With a free API key, the base currency is the US dollar; exchange rates are updated hourly, and there is a limit of 1,000 API calls per month. Most of these restrictions are eliminated or reduced with paid plans. .PP The default source is FloatRates; you can select a different one using .CQ "-s" option described below. .PP Precious metals pricing is obtained from Packetizer (\fRwww.packetizer.com\fP). This site updates once per day. .PP You invoke .CW "units_cur" like this: .PP .ES units_cur [\fIoptions\fP] [\fIoutfile\fP] .EE .PP By default, the output is written to the default currency file described above; this is usually what you want, because this is where .CW "units" looks for the file. If you wish, you can specify a different filename on the command line and .CW "units_cur" will write the data to that file. If you give .CQ "-" for the file it will write to standard output. .PP The following options are available: .TP .BR "-\^h" ", " "-\^-\^help" Print a summary of the options for .CW "units_cur" . .TP .BR "-\^V" ", " "-\^-\^version" Print the .CW "units_cur" version number. .TP .BR "-\^v" ", " "-\^-\^verbose" Give slightly more verbose output when attempting to update currency exchange rates. .TP .BR "-\^s \fIsource\fP" ", " "-\^-\^source \fIsource\fP" Specify the source for currency exchange rates; currently supported values are .CQ "floatrates" (for FloatRates), .CQ "eubank" (for the European Central Bank), .CQ "fixer" (for Fixer), and .CQ "openexchangerates" (for open exchange rates); the last two require an API key to be given with the .CQ "-k" option. .TP .BR "-\^b \fIbase\fP" ", " "-\^-\^base \fIbase\fP" Set the base currency (when allowed by the site providing the data). \fIbase\fP should be a 3-letter ISO currency code, e.g., .CQ "USD" . The specified currency will be the primitive currency unit used by .CW "units" . You may find it convenient to specify your local currency. Conversions may be more accurate and you will be able to convert to your currency by simply hitting \fIEnter\fP at the .CQ "You\ want:" prompt. This option is ignored if the source does not allow specifying the base currency. (Currently only floatrates supports this option.) .TP .BR "-\^k \fIkey\fP" ", " "-\^-\^key \fIkey\fP" Set the API key to \fIkey\fP for sources that require it. .IP .SH DATABASE COMMAND SYNTAX .TP .BR "\fIunit\fP \fIdefinition\fP" Define a regular unit. .TP .BR "\fIprefix\fP- \fIdefinition\fP" Define a prefix. .TP .BR "\fIfuncname\fP(\fIvar\fP) noerror units=[\fIin-\^units\fP,\fIout-units\fP] domain=[\fIx1\fP,\fIx2\fP] range=[\fIy1\fP,\fIy2\fP] \fIdefinition(var)\fP ; \fIinverse(funcname)\fP" Define a nonlinear unit or unit function. The four optional keywords .CW "noerror" , .CW "units=" , .CW "range=" and .CW "domain=" can appear in any order. The definition of the inverse is optional. .TP .BR "\fItabname\fP[\fIout-\^units\fP] noerror \fIpair-list\fP" Define a piecewise linear unit. The pair list gives the points on the table listed in ascending order. The .CW "noerror" keyword is optional. .TP .BR "!endlocale" End a block of definitions beginning with .CQ "!locale" .TP .BR "!endutf8" End a block of definitions begun with .CQ "!utf8" .TP .BR "!endvar" End a block of definitions begun with .CQ "!var" or .CQ "!varnot" .TP .BR "!include \fIfile\fP" Include the specified file. .TP .BR "!locale \fIvalue\fP" Load the following definitions only of the locale is set to \fIvalue\fP. .TP .BR "!message \fItext\fP" Display \fItext\fP when the database is read unless the quiet option .CQ ( "-q" ) is enabled. If you omit \fItext\fP, then units will display a blank line. Messages will also appear in the log file. .TP .BR "!prompt \fItext\fP" Prefix the .CQ "You\ have:" prompt with the specified text. If you omit \fItext\fP, then any existing prefix is canceled. .TP .BR "!set \fIvariable\fP \fIvalue\fP" Sets the environment variable, \fIvariable\fP, to the specified value \fIonly if\fP it is not already set. .TP .BR "!unitlist \fIalias\fP \fIdefinition\fP" Define a unit list alias. .TP .BR "!utf8" Load the following definitions only if .CW "units" is running with UTF-8 enabled. .TP .BR "!var \fIenvar\fP \fIvalue-\^list\fP" Load the block of definitions that follows only if the environment variable \fIenvar\fP is set to one of the values listed in the space-separated value list. If \fIenvar\fP is not set, .CW "units" prints an error message and ignores the block of definitions. .TP .BR "!varnot \fIenvar\fP \fIvalue-\^list\fP" Load the block of definitions that follows only if the environment variable \fIenvar\fP is set to value that is \fInot\fP listed in the space-separated value list. If \fIenvar\fP is not set, .CW "units" prints an error message and ignores the block of definitions. .IP .SH FILES /usr/local/share/units/definitions.units \(em the standard units data file .SH AUTHOR .I units was written by Adrian Mariano