1UNITS(1) General Commands Manual UNITS(1)
2
3
4
6 units — unit conversion and calculation program
7
9 [options] [from-unit [to-unit]]
10
12 The units program converts quantities expressed in various systems of
13 measurement to their equivalents in other systems of measurement. Like
14 many similar programs, it can handle multiplicative scale changes. It
15 can also handle nonlinear conversions such as Fahrenheit to Celsius;
16 see Temperature Conversions. The program can also perform conversions
17 from and to sums of units, such as converting between meters and feet
18 plus inches.
19
20 Basic operation is simple: you enter the units that you want to convert
21 from and the units that you want to convert to. You can use the pro‐
22 gram interactively with prompts, or you can use it from the command
23 line.
24
25 Beyond simple unit conversions, units can be used as a general-purpose
26 scientific calculator that keeps track of units in its calculations.
27 You can form arbitrary complex mathematical expressions of dimensions
28 including sums, products, quotients, powers, and even roots of dimen‐
29 sions. Thus you can ensure accuracy and dimensional consistency when
30 working with long expressions that involve many different units that
31 may combine in complex ways; for an illustration, see Complicated Unit
32 Expressions.
33
34 The units are defined in an external data file. You can use the exten‐
35 sive data file that comes with this program, or you can provide your
36 own data file to suit your needs. You can also use your own data file
37 to supplement the standard data file.
38
39 You can change the default behavior of units with various options given
40 on the command line. See Invoking Units for a description of the avail‐
41 able options.
42
44 To invoke units for interactive use, type units at your shell prompt.
45 The program will print something like this:
46
47 Currency exchange rates from www.timegenie.com on 2014-03-05
48 2860 units, 109 prefixes, 85 nonlinear units
49
50 You have:
51
52 At the ‘You have:’ prompt, type the quantity and units that you are
53 converting from. For example, if you want to convert ten meters to
54 feet, type 10 meters. Next, units will print ‘You want:’. You should
55 type the units you want to convert to. To convert to feet, you would
56 type feet. If the readline library was compiled in, then tab will com‐
57 plete unit names. See Readline Support for more information about
58 readline. To quit the program type quit or exit at either prompt.
59
60 The result will be displayed in two ways. The first line of output,
61 which is marked with a ‘*’ to indicate multiplication, gives the result
62 of the conversion you have asked for. The second line of output, which
63 is marked with a ‘/’ to indicate division, gives the inverse of the
64 conversion factor. If you convert 10 meters to feet, units will print
65
66 * 32.808399
67 / 0.03048
68
69 which tells you that 10 meters equals about 32.8 feet. The second num‐
70 ber gives the conversion in the opposite direction. In this case, it
71 tells you that 1 foot is equal to about 0.03 dekameters since the
72 dekameter is 10 meters. It also tells you that 1/32.8 is about 0.03.
73
74 The units program prints the inverse because sometimes it is a more
75 convenient number. In the example above, for example, the inverse
76 value is an exact conversion: a foot is exactly 0.03048 dekameters.
77 But the number given the other direction is inexact.
78
79 If you convert grains to pounds, you will see the following:
80
81 You have: grains
82 You want: pounds
83 * 0.00014285714
84 / 7000
85
86 From the second line of the output you can immediately see that a
87 grain is equal to a seven thousandth of a pound. This is not so obvi‐
88 ous from the first line of the output. If you find the output format
89 confusing, try using the ‘--verbose’ option:
90
91 You have: grain
92 You want: aeginamina
93 grain = 0.00010416667 aeginamina
94 grain = (1 / 9600) aeginamina
95
96 If you request a conversion between units that measure reciprocal
97 dimensions, then units will display the conversion results with an
98 extra note indicating that reciprocal conversion has been done:
99
100 You have: 6 ohms
101 You want: siemens
102 reciprocal conversion
103 * 0.16666667
104 / 6
105
106 Reciprocal conversion can be suppressed by using the ‘--strict’ option.
107 As usual, use the ‘--verbose’ option to get more comprehensible output:
108
109 You have: tex
110 You want: typp
111 reciprocal conversion
112 1 / tex = 496.05465 typp
113 1 / tex = (1 / 0.0020159069) typp
114
115 You have: 20 mph
116 You want: sec/mile
117 reciprocal conversion
118 1 / 20 mph = 180 sec/mile
119 1 / 20 mph = (1 / 0.0055555556) sec/mile
120
121 If you enter incompatible unit types, the units program will print a
122 message indicating that the units are not conformable and it will dis‐
123 play the reduced form for each unit:
124
125 You have: ergs/hour
126 You want: fathoms kg^2 / day
127 conformability error
128 2.7777778e-11 kg m^2 / sec^3
129 2.1166667e-05 kg^2 m / sec
130
131 If you only want to find the reduced form or definition of a unit, sim‐
132 ply press Enter at the ‘You want:’ prompt. Here is an example:
133
134 You have: jansky
135 You want:
136 Definition: fluxunit = 1e-26 W/m^2 Hz = 1e-26 kg / s^2
137
138 The output from units indicates that the jansky is defined to be equal
139 to a fluxunit which in turn is defined to be a certain combination of
140 watts, meters, and hertz. The fully reduced (and in this case somewhat
141 more cryptic) form appears on the far right.
142
143 Some named units are treated as dimensionless in some situations.
144 These units include the radian and steradian. These units will be
145 treated as equal to 1 in units conversions. Power is equal to torque
146 times angular velocity. This conversion can only be performed if the
147 radian is dimensionless.
148
149 You have: (14 ft lbf) (12 radians/sec)
150 You want: watts
151 * 227.77742
152 / 0.0043902509
153
154 It is also possible to compute roots and other non-integer powers of
155 dimensionless units; this allows computations such as the altitude of
156 geosynchronous orbit:
157
158 You have: cuberoot(G earthmass / (circle/siderealday)^2) - earthradius
159 You want: miles
160 * 22243.267
161 / 4.4957425e-05
162
163 Named dimensionless units are not treated as dimensionless in other
164 contexts. They cannot be used as exponents so for example,
165 ‘meter^radian’ is forbidden.
166
167 If you want a list of options you can type ? at the ‘You want:’ prompt.
168 The program will display a list of named units that are conformable
169 with the unit that you entered at the ‘You have:’ prompt above. Con‐
170 formable unit combinations will not appear on this list.
171
172 Typing help at either prompt displays a short help message. You can
173 also type help followed by a unit name. This will invoke a pager on
174 the units data base at the point where that unit is defined. You can
175 read the definition and comments that may give more details or histori‐
176 cal information about the unit. (You can generally quit out of the
177 page by pressing ‘q’.)
178
179 Typing search text will display a list of all of the units whose names
180 contain text as a substring along with their definitions. This may
181 help in the case where you aren't sure of the right unit name.
182
184 The units program can perform units conversions non-interactively from
185 the command line. To do this, type the command, type the original unit
186 expression, and type the new units you want. If a units expression
187 contains non-alphanumeric characters, you may need to protect it from
188 interpretation by the shell using single or double quote characters.
189
190 If you type
191
192 units "2 liters" quarts
193
194 then units will print
195
196 * 2.1133764
197 / 0.47317647
198
199 and then exit. The output tells you that 2 liters is about 2.1 quarts,
200 or alternatively that a quart is about 0.47 times 2 liters.
201
202 units does not require a space between a numerical value and the unit,
203 so the previous example can be given as
204
205 units 2liters quarts
206
207 to avoid having to quote the first argument.
208
209 If the conversion is successful, units will return success (zero) to
210 the calling environment. If you enter non-conformable units, then
211 units will print a message giving the reduced form of each unit and it
212 will return failure (nonzero) to the calling environment.
213
214 If the ‘--conformable’ option is given, only one unit expression is
215 allowed, and units will print all units conformable with that expres‐
216 sion; it is equivalent to giving ? at the ‘You want:’ prompt. For
217 example,
218
219 units --conformable gauss
220 B_FIELD tesla
221 Gs gauss
222 T tesla
223 gauss abvolt sec / cm^2
224 stT stattesla
225 statT stattesla
226 stattesla statWb/cm^2
227 tesla Wb/m^2
228
229 If you give more than one unit expression with the ‘--conformable’
230 option, the program will exit with an error message and return failure.
231 This option has no effect in interactive mode.
232
233 If the ‘--terse’ (‘-t’) option is given with the ‘--conformable’
234 option, conformable units are shown without definitions; with the pre‐
235 vious example, this would give
236
237 units --terse --conformable gauss
238 B_FIELD
239 Gs
240 T
241 gauss
242 stT
243 statT
244 stattesla
245 tesla
246
247 When the ‘--conformable’ option is not given and you invoke units with
248 only one argument, units will print the definition of the specified
249 unit. It will return failure if the unit is not defined and success if
250 the unit is defined.
251
253 The conversion information is read from a units data file that is
254 called ‘definitions.units’ and is usually located in the
255 ‘/usr/share/units’ directory. If you invoke units with the ‘-V’
256 option, it will print the location of this file. The default file
257 includes definitions for all familiar units, abbreviations and metric
258 prefixes. It also includes many obscure or archaic units. Many common
259 spelled-out numbers (e.g., ‘seventeen’) are recognized.
260
261 Many constants of nature are defined, including these:
262
263 pi ratio of circumference to diameter
264 c speed of light
265 e charge on an electron
266 force acceleration of gravity
267 mole Avogadro's number
268 water pressure per unit height of water
269 Hg pressure per unit height of mercury
270 au astronomical unit
271 k Boltzman's constant
272 mu0 permeability of vacuum
273 epsilon0 permittivity of vacuum
274 G Gravitational constant
275 mach speed of sound
276
277 The standard data file includes atomic masses for all of the elements
278 and numerous other constants. Also included are the densities of vari‐
279 ous ingredients used in baking so that ‘2 cups flour_sifted’ can be
280 converted to ‘grams’. This is not an exhaustive list. Consult the
281 units data file to see the complete list, or to see the definitions
282 that are used.
283
284 The ‘pound’ is a unit of mass. To get force, multiply by the force
285 conversion unit ‘force’ or use the shorthand ‘lbf’. (Note that ‘g’ is
286 already taken as the standard abbreviation for the gram.) The unit
287 ‘ounce’ is also a unit of mass. The fluid ounce is ‘fluidounce’ or
288 ‘floz’. When British capacity units differ from their US counterparts,
289 such as the British Imperial gallon, the unit is defined both ways with
290 ‘br’ and ‘us’ prefixes. Your locale settings will determine the value
291 of the unprefixed unit. Currency is prefixed with its country name:
292 ‘belgiumfranc’, ‘britainpound’.
293
294 When searching for a unit, if the specified string does not appear
295 exactly as a unit name, then the units program will try to remove a
296 trailing ‘s’, ‘es’. Next units will replace a trailing ‘ies’ with ‘y’.
297 If that fails, units will check for a prefix. The database includes
298 all of the standard metric prefixes. Only one prefix is permitted per
299 unit, so ‘micromicrofarad’ will fail. However, prefixes can appear
300 alone with no unit following them, so ‘micro*microfarad’ will work, as
301 will ‘micro microfarad’.
302
303 To find out which units and prefixes are available, read the standard
304 units data file, which is extensively annotated.
305
306 English Customary Units
307 English customary units differ in various ways in different regions.
308 In Britain a complex system of volume measurements featured different
309 gallons for different materials such as a wine gallon and ale gallon
310 that different by twenty percent. This complexity was swept away in
311 1824 by a reform that created an entirely new gallon, the British Impe‐
312 rial gallon defined as the volume occupied by ten pounds of water.
313 Meanwhile in the USA the gallon is derived from the 1707 Winchester
314 wine gallon, which is 231 cubic inches. These gallons differ by about
315 twenty percent. By default if units runs in the ‘en_GB’ locale you
316 will get the British volume measures. If it runs in the ‘en_US’ locale
317 you will get the US volume measures. In other locales the default val‐
318 ues are the US definitions. If you wish to force different defini‐
319 tions, then set the environment variable UNITS_ENGLISH to either ‘US’
320 or ‘GB’ to set the desired definitions independent of the locale.
321
322 Before 1959, the value of a yard (and other units of measure defined in
323 terms of it) differed slightly among English-speaking countries. In
324 1959, Australia, Canada, New Zealand, the United Kingdom, the United
325 States, and South Africa adopted the Canadian value of 1 yard =
326 0.9144 m (exactly), which was approximately halfway between the values
327 used by the UK and the US; it had the additional advantage of making
328 1 inch = 2.54 cm (exactly). This new standard was termed the Interna‐
329 tional Yard. Australia, Canada, and the UK then defined all customary
330 lengths in terms of the International Yard (Australia did not define
331 the furlong or rod); because many US land surveys were in terms of the
332 pre-1959 units, the US continued to define customary surveyors' units
333 (furlong, chain, rod, and link) in terms of the previous value for the
334 foot, which was termed the US survey foot. The US defined a US survey
335 mile as 5280 US survey feet, and defined a statute mile as a US survey
336 mile. The US values for these units differ from the international val‐
337 ues by about 2 ppm.
338
339 The units program uses the international values for these units; the US
340 values can be obtained by using either the ‘US’ or the ‘survey’ prefix.
341 In either case, the simple familiar relationships among the units are
342 maintained, e.g., 1 ‘furlong’ = 660 ‘ft’, and 1 ‘USfurlong’ = 660
343 ‘USft’, though the metric equivalents differ slightly between the two
344 cases. The ‘US’ prefix or the ‘survey’ prefix can also be used to
345 obtain the US survey mile and the value of the US yard prior to 1959,
346 e.g., ‘USmile’ or ‘surveymile’ (but not ‘USsurveymile’). To get the US
347 value of the statute mile, use either ‘USstatutemile’ or ‘USmile’.
348
349 Except for distances that extend over hundreds of miles (such as in the
350 US State Plane Coordinate System), the differences in the miles are
351 usually insignificant:
352
353 You have: 100 surveymile - 100 mile
354 You want: inch
355 * 12.672025
356 / 0.078913984
357
358 The pre-1959 UK values for these units can be obtained with the prefix
359 ‘UK’.
360
361 In the US, the acre is officially defined in terms of the US survey
362 foot, but units uses a definition based on the international foot. If
363 you want the official US acre use ‘USacre’ and similarly use
364 ‘USacrefoot’ for the official US version of that unit. The difference
365 between these units is about 4 parts per million.
366
368 Operators
369 You can enter more complicated units by combining units with operations
370 such as multiplication, division, powers, addition, subtraction, and
371 parentheses for grouping. You can use the customary symbols for these
372 operators when units is invoked with its default options. Addition‐
373 ally, units supports some extensions, including high priority multipli‐
374 cation using a space, and a high priority numerical division operator
375 (‘|’) that can simplify some expressions.
376
377 You multiply units using a space or an asterisk (‘*’). The next exam‐
378 ple shows both forms:
379
380 You have: arabicfoot * arabictradepound * force
381 You want: ft lbf
382 * 0.7296
383 / 1.370614
384
385 You can divide units using the slash (‘/’) or with ‘per’:
386
387 You have: furlongs per fortnight
388 You want: m/s
389 * 0.00016630986
390 / 6012.8727
391
392 You can use parentheses for grouping:
393
394 You have: (1/2) kg / (kg/meter)
395 You want: league
396 * 0.00010356166
397 / 9656.0833
398
399 White space surrounding operators is optional, so the previous example
400 could have used ‘(1/2)kg/(kg/meter)’. As a consequence, however,
401 hyphenated spelled-out numbers (e.g., ‘forty-two’) cannot be used;
402 ‘forty-two’ is interpreted as ‘40 - 2’.
403
404 Multiplication using a space has a higher precedence than division
405 using a slash and is evaluated left to right; in effect, the first ‘/’
406 character marks the beginning of the denominator of a unit expression.
407 This makes it simple to enter a quotient with several terms in the
408 denominator: ‘J / mol K’. The ‘*’ and ‘/’ operators have the same
409 precedence, and are evaluated left to right; if you multiply with ‘*’,
410 you must group the terms in the denominator with parentheses:
411 ‘J / (mol * K)’.
412
413 The higher precedence of the space operator may not always be advanta‐
414 geous. For example, ‘m/s s/day’ is equivalent to ‘m / s s day’ and has
415 dimensions of length per time cubed. Similarly, ‘1/2 meter’ refers to
416 a unit of reciprocal length equivalent to 0.5/meter, perhaps not what
417 you would intend if you entered that expression. The get a half meter
418 you would need to use parentheses: ‘(1/2) meter’. The ‘*’ operator is
419 convenient for multiplying a sequence of quotients. For example,
420 ‘m/s * s/day’ is equivalent to ‘m/day’. Similarly, you could write
421 ‘1/2 * meter’ to get half a meter.
422
423 The units program supports another option for numerical fractions: you
424 can indicate division of numbers with the vertical bar (‘|’), so if you
425 wanted half a meter you could write ‘1|2 meter’. You cannot use the
426 vertical bar to indicate division of non-numerical units (e.g., ‘m|s’
427 results in an error message).
428
429 Powers of units can be specified using the ‘^’ character, as shown in
430 the following example, or by simple concatenation of a unit and its
431 exponent: ‘cm3’ is equivalent to ‘cm^3’; if the exponent is more than
432 one digit, the ‘^’ is required. You can also use ‘**’ as an exponent
433 operator.
434
435 You have: cm^3
436 You want: gallons
437 * 0.00026417205
438 / 3785.4118
439
440 Concatenation only works with a single unit name: if you write
441 ‘(m/s)2’, units will treat it as multiplication by 2. When a unit
442 includes a prefix, exponent operators apply to the combination, so
443 ‘centimeter3’ gives cubic centimeters. If you separate the prefix from
444 the unit with any multiplication operator (e.g., ‘centi meter^3’), the
445 prefix is treated as a separate unit, so the exponent applies only to
446 the unit without the prefix. The second example is equivalent to
447 ‘centi * (meter^3)’, and gives a hundredth of a cubic meter, not a
448 cubic centimeter. The units program is limited internally to products
449 of 99 units; accordingly, expressions like ‘meter^100’ or ‘joule^34’
450 (represented internally as ‘kg^34 m^68 / s^68’) will fail.
451
452 The ‘|’ operator has the highest precedence, so you can write the
453 square root of two thirds as ‘2|3^1|2’. The ‘^’ operator has the sec‐
454 ond highest precedence, and is evaluated right to left, as usual:
455
456 You have: 5 * 2^3^2
457 You want:
458 Definition: 2560
459
460 With a dimensionless base unit, any dimensionless exponent is meaning‐
461 ful (e.g., ‘pi^exp(2.371)’). Even though angle is sometimes treated as
462 dimensionless, exponents cannot have dimensions of angle:
463
464 You have: 2^radian
465 ^
466 Exponent not dimensionless
467
468 If the base unit is not dimensionless, the exponent must be a rational
469 number p/q, and the dimension of the unit must be a power of q, so
470 ‘gallon^2|3’ works but ‘acre^2|3’ fails. An exponent using the slash
471 (‘/’) operator (e.g., ‘gallon^(2/3)’) is also acceptable; the parenthe‐
472 ses are needed because the precedence of ‘^’ is higher than that of
473 ‘/’. Since units cannot represent dimensions with exponents greater
474 than 99, a fully reduced exponent must have q < 100. When raising a
475 non-dimensionless unit to a power, units attempts to convert a decimal
476 exponent to a rational number with q < 100. If this is not possible
477 units displays an error message:
478
479 You have: ft^1.234
480 Base unit not dimensionless; rational exponent required
481
482 A decimal exponent must match its rational representation to machine
483 precision, so ‘acre^1.5’ works but ‘gallon^0.666’ does not.
484
485 Sums and Differences of Units
486 You may sometimes want to add values of different units that are out‐
487 side the SI. You may also wish to use units as a calculator that keeps
488 track of units. Sums of conformable units are written with the ‘+’
489 character, and differences with the ‘-’ character.
490
491 You have: 2 hours + 23 minutes + 32 seconds
492 You want: seconds
493 * 8612
494 / 0.00011611705
495
496 You have: 12 ft + 3 in
497 You want: cm
498 * 373.38
499 / 0.0026782366
500
501 You have: 2 btu + 450 ft lbf
502 You want: btu
503 * 2.5782804
504 / 0.38785542
505
506 The expressions that are added or subtracted must reduce to identical
507 expressions in primitive units, or an error message will be displayed:
508
509 You have: 12 printerspoint - 4 heredium
510 ^
511 Illegal sum of non-conformable units
512
513 If you add two values of vastly different scale you may exceed the
514 available precision of floating point (about 15 digits). The effect is
515 that the addition of the smaller value makes no change to the larger
516 value; in other words, the smaller value is treated as if it were zero.
517
518 You have: lightyear + cm
519
520 No warning is given, however. As usual, the precedence for ‘+’ and ‘-’
521 is lower than that of the other operators. A fractional quantity such
522 as 2 1/2 cups can be given as ‘(2+1|2) cups’; the parentheses are nec‐
523 essary because multiplication has higher precedence than addition. If
524 you omit the parentheses, units attempts to add ‘2’ and ‘1|2 cups’, and
525 you get an error message:
526
527 You have: 2+1|2 cups
528 ^
529 Illegal sum or difference of non-conformable units
530
531 The expression could also be correctly written as ‘(2+1/2) cups’. If
532 you write ‘2 1|2 cups’ the space is interpreted as multiplication so
533 the result is the same as ‘1 cup’.
534
535 The ‘+’ and ‘-’ characters sometimes appears in exponents like
536 ‘3.43e+8’. This leads to an ambiguity in an expression like ‘3e+2 yC’.
537 The unit ‘e’ is a small unit of charge, so this can be regarded as
538 equivalent to ‘(3e+2) yC’ or ‘(3 e)+(2 yC)’. This ambiguity is
539 resolved by always interpreting ‘+’ and ‘-’ as part of an exponent if
540 possible.
541
542 Numbers as Units
543 For units, numbers are just another kind of unit. They can appear as
544 many times as you like and in any order in a unit expression. For
545 example, to find the volume of a box that is 2 ft by 3 ft by 12 ft in
546 steres, you could do the following:
547
548 You have: 2 ft 3 ft 12 ft
549 You want: stere
550 * 2.038813
551 / 0.49048148
552
553 You have: $ 5 / yard
554 You want: cents / inch
555 * 13.888889
556 / 0.072
557
558 And the second example shows how the dollar sign in the units conver‐
559 sion can precede the five. Be careful: units will interpret ‘$5’ with
560 no space as equivalent to ‘dollar^5’.
561
562 Built-in Functions
563 Several built-in functions are provided: ‘sin’, ‘cos’, ‘tan’, ‘asin’,
564 ‘acos’, ‘atan’, ‘sinh’, ‘cosh’, ‘tanh’, ‘asinh’, ‘acosh’, ‘atanh’,
565 ‘exp’, ‘ln’, ‘log’, ‘abs’, ‘round’, ‘floor’, ‘ceil’, ‘factorial’,
566 ‘Gamma’, ‘lnGamma’, ‘erf’, and ‘erfc’; the function ‘lnGamma’ is the
567 natural logarithm of the ‘Gamma’ function.
568
569 The ‘sin’, ‘cos’, and ‘tan’ functions require either a dimensionless
570 argument or an argument with dimensions of angle.
571
572 You have: sin(30 degrees)
573 You want:
574 Definition: 0.5
575
576 You have: sin(pi/2)
577 You want:
578 Definition: 1
579
580 You have: sin(3 kg)
581 ^
582 Unit not dimensionless
583
584 The other functions on the list require dimensionless arguments. The
585 inverse trigonometric functions return arguments with dimensions of
586 angle.
587
588 The ‘ln’ and ‘log’ functions give natural log and log base 10 respec‐
589 tively. To obtain logs for any integer base, enter the desired base
590 immediately after ‘log’. For example, to get log base 2 you would
591 write ‘log2’ and to get log base 47 you could write ‘log47’.
592
593 You have: log2(32)
594 You want:
595 Definition: 5
596 You have: log3(32)
597 You want:
598 Definition: 3.1546488
599 You have: log4(32)
600 You want:
601 Definition: 2.5
602 You have: log32(32)
603 You want:
604 Definition: 1
605 You have: log(32)
606 You want:
607 Definition: 1.50515
608 You have: log10(32)
609 You want:
610 Definition: 1.50515
611
612 If you wish to take roots of units, you may use the ‘sqrt’ or
613 ‘cuberoot’ functions. These functions require that the argument have
614 the appropriate root. You can obtain higher roots by using fractional
615 exponents:
616
617 You have: sqrt(acre)
618 You want: feet
619 * 208.71074
620 / 0.0047913202
621
622 You have: (400 W/m^2 / stefanboltzmann)^(1/4)
623 You have:
624 Definition: 289.80882 K
625
626 You have: cuberoot(hectare)
627 ^
628 Unit not a root
629
630 Previous Result
631 You can insert the result of the previous conversion using the under‐
632 score (‘_’). It is useful when you want to convert the same input to
633 several different units, for example
634
635 You have: 2.3 tonrefrigeration
636 You want: btu/hr
637 * 27600
638 / 3.6231884e-005
639 You have: _
640 You want: kW
641 * 8.0887615
642 / 0.12362832
643
644 Suppose you want to do some deep frying that requires an oil depth of
645 2 inches. You have 1/2 gallon of oil, and want to know the largest-
646 diameter pan that will maintain the required depth. The nonlinear unit
647 ‘circlearea’ gives the radius of the circle (see Other Nonlinear Units,
648 for a more detailed description) in SI units; you want the diameter in
649 inches:
650
651 You have: 1|2 gallon / 2 in
652 You want: circlearea
653 0.10890173 m
654 You have: 2 _
655 You want: in
656 * 8.5749393
657 / 0.1166189
658
659 In most cases, surrounding white space is optional, so the previous
660 example could have used ‘2_’. If ‘_’ follows a non-numerical unit sym‐
661 bol, however, the space is required:
662
663 You have: m_
664 ^
665 Parse error
666
667 When ‘_’ is followed by a digit, the operation is multiplication rather
668 than exponentiation, so that ‘_2’, is equivalent to ‘_ * 2’ rather than
669 ‘_^2’.
670
671 You can use the ‘_’ symbol any number of times; for example,
672
673 You have: m
674 You want:
675 Definition: 1 m
676 You have: _ _
677 You want:
678 Definition: 1 m^2
679
680 Using ‘_’ before a conversion has been performed (e.g., immediately
681 after invocation) generates an error:
682
683 You have: _
684 ^
685 No previous result; '_' not set
686
687 Accordingly, ‘_’ serves no purpose when units is invoked non-interac‐
688 tively.
689
690 If units is invoked with the ‘--verbose’ option (see Invoking Units),
691 the value of ‘_’ is not expanded:
692
693 You have: mile
694 You want: ft
695 mile = 5280 ft
696 mile = (1 / 0.00018939394) ft
697 You have: _
698 You want: m
699 _ = 1609.344 m
700 _ = (1 / 0.00062137119) m
701
702 You can give ‘_’ at the ‘You want:’ prompt, but it usually is not very
703 useful.
704
705 Complicated Unit Expressions
706 The units program is especially helpful in ensuring accuracy and dimen‐
707 sional consistency when converting lengthy unit expressions. For exam‐
708 ple, one form of the Darcy-Weisbach fluid-flow equation is
709
710 Delta P = (8 / pi)^2 (rho fLQ^2) / d^5,
711
712 where Delta P is the pressure drop, rho is the mass density, f is the
713 (dimensionless) friction factor, L is the length of the pipe, Q is the
714 volumetric flow rate, and d is the pipe diameter. It might be desired
715 to have the equation in the form
716
717 Delta P = A1 rho fLQ^2 / d^5
718
719 that accepted the user’s normal units; for typical units used in the
720 US, the required conversion could be something like
721
722 You have: (8/pi^2)(lbm/ft^3)ft(ft^3/s)^2(1/in^5)
723 You want: psi
724 * 43.533969
725 / 0.022970568
726
727 The parentheses allow individual terms in the expression to be entered
728 naturally, as they might be read from the formula. Alternatively, the
729 multiplication could be done with the ‘*’ rather than a space; then
730 parentheses are needed only around ‘ft^3/s’ because of its exponent:
731
732 You have: 8/pi^2 * lbm/ft^3 * ft * (ft^3/s)^2 /in^5
733 You want: psi
734 * 43.533969
735 / 0.022970568
736
737 Without parentheses, and using spaces for multiplication, the previous
738 conversion would need to be entered as
739
740 You have: 8 lb ft ft^3 ft^3 / pi^2 ft^3 s^2 in^5
741 You want: psi
742 * 43.533969
743 / 0.022970568
744
745 Backwards Compatibility: ‘*’ and ‘-’
746 The original units assigned multiplication a higher precedence than
747 division using the slash. This differs from the usual precedence
748 rules, which give multiplication and division equal precedence, and can
749 be confusing for people who think of units as a calculator.
750
751 The star operator (‘*’) included in this units program has, by default,
752 the same precedence as division, and hence follows the usual precedence
753 rules. For backwards compatibility you can invoke units with the
754 ‘--oldstar’ option. Then ‘*’ has a higher precedence than division,
755 and the same precedence as multiplication using the space.
756
757 Historically, the hyphen (‘-’) has been used in technical publications
758 to indicate products of units, and the original units program treated
759 it as a multiplication operator. Because units provides several other
760 ways to obtain unit products, and because ‘-’ is a subtraction operator
761 in general algebraic expressions, units treats the binary ‘-’ as a sub‐
762 traction operator by default. For backwards compatibility use the
763 ‘--product’ option, which causes units to treat the binary ‘-’ operator
764 as a product operator. When ‘-’ is a multiplication operator it has
765 the same precedence as multiplication with a space, giving it a higher
766 precedence than division.
767
768 When ‘-’ is used as a unary operator it negates its operand. Regard‐
769 less of the units options, if ‘-’ appears after ‘(’ or after ‘+’, then
770 it will act as a negation operator. So you can always compute 20
771 degrees minus 12 minutes by entering ‘20 degrees + -12 arcmin’. You
772 must use this construction when you define new units because you cannot
773 know what options will be in force when your definition is processed.
774
776 Nonlinear units are represented using functional notation. They make
777 possible nonlinear unit conversions such as temperature.
778
779 Temperature Conversions
780 Conversions between temperatures are different from linear conversions
781 between temperature increments—see the example below. The absolute
782 temperature conversions are handled by units starting with ‘temp’, and
783 you must use functional notation. The temperature-increment conver‐
784 sions are done using units starting with ‘deg’ and they do not require
785 functional notation.
786
787 You have: tempF(45)
788 You want: tempC
789 7.2222222
790
791 You have: 45 degF
792 You want: degC
793 * 25
794 / 0.04
795
796 Think of ‘tempF(x)’ not as a function but as a notation that indicates
797 that x should have units of ‘tempF’ attached to it. See Defining Non‐
798 linear Units. The first conversion shows that if it’s 45 degrees
799 Fahrenheit outside, it’s 7.2 degrees Celsius. The second conversion
800 indicates that a change of 45 degrees Fahrenheit corresponds to a
801 change of 25 degrees Celsius. The conversion from ‘tempF(x)’ is to
802 absolute temperature, so that
803
804 You have: tempF(45)
805 You want: degR
806 * 504.67
807 / 0.0019814929
808
809 gives the same result as
810
811 You have: tempF(45)
812 You want: tempR
813 * 504.67
814 / 0.0019814929
815
816 But if you convert ‘tempF(x)’ to ‘degC’, the output is probably not
817 what you expect:
818
819 You have: tempF(45)
820 You want: degC
821 * 280.37222
822 / 0.0035666871
823
824 The result is the temperature in K, because ‘degC’ is defined as ‘K’,
825 the Kelvin. For consistent results, use the ‘tempX’ units when convert‐
826 ing to a temperature rather than converting a temperature increment.
827
828 The ‘tempC()’ and ‘tempF()’ definitions are limited to positive abso‐
829 lute temperatures, and giving a value that would result in a negative
830 absolute temperature generates an error message:
831
832 You have: tempC(-275)
833 ^
834 Argument of function outside domain
835
836 Other Nonlinear Units
837 Some other examples of nonlinear units are numerous different ring
838 sizes and wire gauges, the grit sizes used for abrasives, the decibel
839 scale, shoe size, scales for the density of sugar (e.g., baume). The
840 standard data file also supplies units for computing the area of a cir‐
841 cle and the volume of a sphere. See the standard units data file for
842 more details. Wire gauges with multiple zeroes are signified using
843 negative numbers where two zeroes is ‘-1’. Alternatively, you can use
844 the synonyms ‘g00’, ‘g000’, and so on that are defined in the standard
845 units data file.
846
847 You have: wiregauge(11)
848 You want: inches
849 * 0.090742002
850 / 11.020255
851
852 You have: brwiregauge(g00)
853 You want: inches
854 * 0.348
855 / 2.8735632
856
857 You have: 1 mm
858 You want: wiregauge
859 18.201919
860
861 You have: grit_P(600)
862 You want: grit_ansicoated
863 342.76923
864
865 The last example shows the conversion from P graded sand paper, which
866 is the European standard and may be marked “P600” on the back, to the
867 USA standard.
868
869 You can compute the area of a circle using the nonlinear unit,
870 ‘circlearea’. You can also do this using the circularinch or cir‐
871 cleinch. The next example shows two ways to compute the area of a cir‐
872 cle with a five inch radius and one way to compute the volume of a
873 sphere with a radius of one meter.
874
875 You have: circlearea(5 in)
876 You want: in2
877 * 78.539816
878 / 0.012732395
879
880 You have: 10^2 circleinch
881 You want: in2
882 * 78.539816
883 / 0.012732395
884
885 You have: spherevol(meter)
886 You want: ft3
887 * 147.92573
888 / 0.0067601492
889
890 The inverse of a nonlinear conversion is indicated by prefixing a tilde
891 (‘~’) to the nonlinear unit name:
892
893 You have: ~wiregauge(0.090742002 inches)
894 You want:
895 Definition: 11
896
897 You can give a nonlinear unit definition without an argument or paren‐
898 theses, and press Enter at the ‘You want:’ prompt to get the definition
899 of a nonlinear unit; if the definition is not valid for all real num‐
900 bers, the range of validity is also given. If the definition requires
901 specific units this information is also displayed:
902
903 You have: tempC
904 Definition: tempC(x) = x K + stdtemp
905 defined for x >= -273.15
906 You have: ~tempC
907 Definition: ~tempC(tempC) = (tempC +(-stdtemp))/K
908 defined for tempC >= 0 K
909 You have: circlearea
910 Definition: circlearea(r) = pi r^2
911 r has units m
912
913 To see the definition of the inverse use the ‘~’ notation. In this
914 case the parameter in the functional definition will usually be the
915 name of the unit. Note that the inverse for ‘tempC’ shows that it
916 requires units of ‘K’ in the specification of the allowed range of val‐
917 ues. Nonlinear unit conversions are described in more detail in Defin‐
918 ing Nonlinear Units.
919
921 Outside of the SI, it is sometimes desirable to convert a single unit
922 to a sum of units—for example, feet to feet plus inches. The conver‐
923 sion from sums of units was described in Sums and Differences of Units,
924 and is a simple matter of adding the units with the ‘+’ sign:
925
926 You have: 12 ft + 3 in + 3|8 in
927 You want: ft
928 * 12.28125
929 / 0.081424936
930
931 Although you can similarly write a sum of units to convert to, the
932 result will not be the conversion to the units in the sum, but rather
933 the conversion to the particular sum that you have entered:
934
935 You have: 12.28125 ft
936 You want: ft + in + 1|8 in
937 * 11.228571
938 / 0.089058524
939
940 The unit expression given at the ‘You want:’ prompt is equivalent to
941 asking for conversion to multiples of ‘1 ft + 1 in + 1|8 in’, which is
942 1.09375 ft, so the conversion in the previous example is equivalent to
943
944 You have: 12.28125 ft
945 You want: 1.09375 ft
946 * 11.228571
947 / 0.089058524
948
949 In converting to a sum of units like miles, feet and inches, you typi‐
950 cally want the largest integral value for the first unit, followed by
951 the largest integral value for the next, and the remainder converted to
952 the last unit. You can do this conversion easily with units using a
953 special syntax for lists of units. You must list the desired units in
954 order from largest to smallest, separated by the semicolon (‘;’) char‐
955 acter:
956
957 You have: 12.28125 ft
958 You want: ft;in;1|8 in
959 12 ft + 3 in + 3|8 in
960
961 The conversion always gives integer coefficients on the units in the
962 list, except possibly the last unit when the conversion is not exact:
963
964 You have: 12.28126 ft
965 You want: ft;in;1|8 in
966 12 ft + 3 in + 3.00096 * 1|8 in
967
968 The order in which you list the units is important:
969
970 You have: 3 kg
971 You want: oz;lb
972 105 oz + 0.051367866 lb
973
974 You have: 3 kg
975 You want: lb;oz
976 6 lb + 9.8218858 oz
977
978 Listing ounces before pounds produces a technically correct result, but
979 not a very useful one. You must list the units in descending order of
980 size in order to get the most useful result.
981
982 Ending a unit list with the separator ‘;’ has the same effect as
983 repeating the last unit on the list, so ‘ft;in;1|8 in;’ is equivalent
984 to ‘ft;in;1|8 in;1|8 in’. With the example above, this gives
985
986 You have: 12.28126 ft
987 You want: ft;in;1|8 in;
988 12 ft + 3 in + 3|8 in + 0.00096 * 1|8 in
989
990 in effect separating the integer and fractional parts of the coeffi‐
991 cient for the last unit. If you instead prefer to round the last coef‐
992 ficient to an integer you can do this with the ‘--round’ (‘-r’) option.
993 With the previous example, the result is
994
995 You have: 12.28126 ft
996 You want: ft;in;1|8 in
997 12 ft + 3 in + 3|8 in (rounded down to nearest 1|8 in)
998
999 When you use the ‘-r’ option, repeating the last unit on the list has
1000 no effect (e.g., ‘ft;in;1|8 in;1|8 in’ is equivalent to ‘ft;in;1|8
1001 in’), and hence neither does ending a list with a ‘;’. With a single
1002 unit and the ‘-r’ option, a terminal ‘;’ does have an effect: it causes
1003 units to treat the single unit as a list and produce a rounded value
1004 for the single unit. Without the extra ‘;’, the ‘-r’ option has no
1005 effect on single unit conversions. This example shows the output using
1006 the ‘-r’ option:
1007
1008 You have: 12.28126 ft
1009 You want: in
1010 * 147.37512
1011 / 0.0067854058
1012
1013 You have: 12.28126 ft
1014 You want: in;
1015 147 in (rounded down to nearest in)
1016
1017 Each unit that appears in the list must be conformable with the first
1018 unit on the list, and of course the listed units must also be conform‐
1019 able with the unit that you enter at the ‘You have:’ prompt.
1020
1021 You have: meter
1022 You want: ft;kg
1023 ^
1024 conformability error
1025 ft = 0.3048 m
1026 kg = 1 kg
1027
1028 You have: meter
1029 You want: lb;oz
1030 conformability error
1031 1 m
1032 0.45359237 kg
1033
1034 In the first case, units reports the disagreement between units appear‐
1035 ing on the list. In the second case, units reports disagreement
1036 between the unit you entered and the desired conversion. This con‐
1037 formability error is based on the first unit on the unit list.
1038
1039 Other common candidates for conversion to sums of units are angles and
1040 time:
1041
1042 You have: 23.437754 deg
1043 You want; deg;arcmin;arcsec
1044 23 deg + 26 arcmin + 15.9144 arcsec
1045
1046 You have: 7.2319 hr
1047 You want: hr;min;sec
1048 7 hr + 13 min + 54.84 sec
1049
1050 Some applications for unit lists may be less obvious. Suppose that you
1051 have a postal scale and wish to ensure that it’s accurate at 1 oz, but
1052 have only metric calibration weights. You might try
1053
1054 You have: 1 oz
1055 You want: 100 g;50 g; 20 g;10 g;5 g;2 g;1 g;
1056 20 g + 5 g + 2 g + 1 g + 0.34952312 * 1 g
1057
1058 You might then place one each of the 20 g, 5 g, 2 g, and 1 g weights on
1059 the scale and hope that it indicates close to
1060
1061 You have: 20 g + 5 g + 2 g + 1 g
1062 You want: oz;
1063 0.98767093 oz
1064
1065 Appending ‘;’ to ‘oz’ forces a one-line display that includes the unit;
1066 here the integer part of the result is zero, so it is not displayed.
1067
1068 If a non-empty list item differs vastly in scale from the quantity from
1069 which the list is to be converted, you may exceed the available preci‐
1070 sion of floating point (about 15 digits), in which case you will get a
1071 warning, e.g.,
1072
1073 You have: lightyear
1074 You want: mile;100 inch;10 inch;mm;micron
1075 5.8786254e+12 mile + 390 * 100 inch (at 15-digit precision limit)
1076
1077 Cooking Measure
1078 In North America, recipes for cooking typically measure ingredients by
1079 volume, and use units that are not always convenient multiples of each
1080 other. Suppose that you have a recipe for 6 and you wish to make a
1081 portion for 1. If the recipe calls for 2 1/2 cups of an ingredient,
1082 you might wish to know the measurements in terms of measuring devices
1083 you have available, you could use units and enter
1084
1085 You have: (2+1|2) cup / 6
1086 You want: cup;1|2 cup;1|3 cup;1|4 cup;tbsp;tsp;1|2 tsp;1|4 tsp
1087 1|3 cup + 1 tbsp + 1 tsp
1088
1089 By default, if a unit in a list begins with fraction of the form 1|x
1090 and its multiplier is an integer, the fraction is given as the product
1091 of the multiplier and the numerator; for example,
1092
1093 You have: 12.28125 ft
1094 You want: ft;in;1|8 in;
1095 12 ft + 3 in + 3|8 in
1096
1097 In many cases, such as the example above, this is what is wanted, but
1098 sometimes it is not. For example, a cooking recipe for 6 might call
1099 for 5 1/4 cup of an ingredient, but you want a portion for 2, and your
1100 1-cup measure is not available; you might try
1101
1102 You have: (5+1|4) cup / 3
1103 You want: 1|2 cup;1|3 cup;1|4 cup
1104 3|2 cup + 1|4 cup
1105
1106 This result might be fine for a baker who has a 1 1/2-cup measure (and
1107 recognizes the equivalence), but it may not be as useful to someone
1108 with more limited set of measures, who does want to do additional cal‐
1109 culations, and only wants to know “How many 1/2-cup measures to I need
1110 to add?” After all, that’s what was actually asked. With the
1111 ‘--show-factor’ option, the factor will not be combined with a unity
1112 numerator, so that you get
1113
1114 You have: (5+1|4) cup / 3
1115 You want: 1|2 cup;1|3 cup;1|4 cup
1116 3 * 1|2 cup + 1|4 cup
1117
1118 A user-specified fractional unit with a numerator other than 1 is never
1119 overridden, however—if a unit list specifies ‘3|4 cup;1|2 cup’, a
1120 result equivalent to 1 1/2 cups will always be shown as ‘2 * 3|4 cup’
1121 whether or not the ‘--show-factor’ option is given.
1122
1123 Unit List Aliases
1124 A unit list such as
1125
1126 cup;1|2 cup;1|3 cup;1|4 cup;tbsp;tsp;1|2 tsp;1|4 tsp
1127
1128 can be tedious to enter. The units program provides shorthand names
1129 for some common combinations:
1130
1131 hms hours, minutes, seconds
1132 dms angle: degrees, minutes, seconds
1133 time years, days, hours, minutes and seconds
1134 usvol US cooking volume: cups and smaller
1135 ftin feet, inches and 1/8 inches
1136 inchfine inches subdivided to 1/64 inch
1137
1138 Using these shorthands, or unit list aliases, you can do the following
1139 conversions:
1140
1141 You have: anomalisticyear
1142 You want: time
1143 1 year + 25 min + 3.4653216 sec
1144 You have: 1|6 cup
1145 You want: usvol
1146 2 tbsp + 2 tsp
1147
1148 You can define your own unit list aliases; see Defining Unit List
1149 Aliases.
1150
1151 You cannot combine a unit list alias with other units: it must appear
1152 alone at the ‘You want:’ prompt.
1153
1154 You can display the definition of a unit list alias by entering it at
1155 the ‘You have:’ prompt:
1156
1157 You have: dms
1158 Definition: unit list, deg;arcmin;arcsec
1159
1160 When you specify compact output with ‘--compact’, ‘--terse’ or ‘-t’ and
1161 perform conversion to a unit list, units lists the conversion factors
1162 for each unit in the list, separated by semicolons.
1163
1164 You have: year
1165 You want: day;min;sec
1166 365;348;45.974678
1167
1168 Unlike the case of regular output, zeros are included in this output
1169 list:
1170
1171 You have: liter
1172 You want: cup;1|2 cup;1|4 cup;tbsp
1173 4;0;0;3.6280454
1174
1176 CGS Units
1177 The SI—an extension of the MKS (meter–kilogram–second) system—has
1178 largely supplanted the older CGS (centimeter–gram–second) system, but
1179 CGS units are still used in a few specialized fields, especially in
1180 physics where they lead to a more elegant formulation of Maxwell’s
1181 equations. Conversions between SI and CGS involving mechanical units
1182 are straightforward, involving powers of 10 (e.g., 1 m = 100 cm). Con‐
1183 versions involving electromagnetic units are more complicated, and
1184 units supports four different systems of CGS units: electrostatic units
1185 (ESU), electromagnetic units (EMU), the Gaussian system and the Heavi‐
1186 side–Lorentz system. The differences between these systems arise from
1187 different choices made for proportionality constants in electromagnetic
1188 equations. Coulomb’s law gives electrostatic force between two charges
1189 separated by a distance delim $$ r:
1190
1191 F = k_C q_1 q_2 / r^2.
1192
1193 Ampere’s law gives the electromagnetic force per unit length between
1194 two current-carrying conductors separated by a distance r:
1195
1196 F/l = 2 k_A I_1 I_2 / r.
1197
1198 The two constants, k_C and k_A, are related by the square of the speed
1199 of light: k_A = k_C / c^2.
1200
1201 In the SI, the constants have dimensions, and an additional base unit,
1202 the ampere, measures electric current. The CGS systems do not define
1203 new base units, but express charge and current as derived units in
1204 terms of mass, length, and time. In the ESU system, the constant for
1205 Coulomb’s law is chosen to be unity and dimensionless, which defines
1206 the unit of charge. In the EMU system, the constant for Ampere’s law
1207 is chosen to be unity and dimensionless, which defines a unit of cur‐
1208 rent. The Gaussian system usually uses the ESU units for charge and
1209 current; it chooses another constant so that the units for the electric
1210 and magnetic fields are the same. The Heaviside–Lorentz system is
1211 “rationalized” so that factors of 4{pi} do not appear in Maxwell’s
1212 equations. The SI system is similarly rationalized, but the other CGS
1213 systems are not. In the Heaviside–Lorentz (HLU) system the factor of
1214 4{pi} appears in Coulomb’s law instead; this system differs from the
1215 Gaussian system by factors of the square root of 4{pi}
1216
1217 The dimensions of electrical quantities in the various CGS systems are
1218 different from the SI dimensions for the same units; strictly, conver‐
1219 sions between these systems and SI are not possible. But units in dif‐
1220 ferent systems relate to the same physical quantities, so there is a
1221 correspondence between these units. The units program defines the
1222 units so that you can convert between corresponding units in the vari‐
1223 ous systems.
1224
1225 The CGS definitions involve cm^(1/2) and g^(1/2), which is problematic
1226 because units does not normally support fractional roots of base units.
1227 The ‘--units’ (‘-u’) option allows selection of a CGS unit system and
1228 works around this restriction by introducing base units for the square
1229 roots of length and mass: ‘sqrt_cm’ and ‘sqrt_g’. The centimeter then
1230 becomes ‘sqrt_cm^2’ and the gram, ‘sqrt_g^2’. This allows working from
1231 equations using the units in the CGS system, and enforcing dimensional
1232 conformity within that system. Recognized CGS arguments to the
1233 ‘--units’ option are ‘gauss[ian]’, ‘esu’, ‘emu’, ‘lhu’; the argument is
1234 case insensitive. You can also give ‘si’ which just enforces the
1235 default SI mode and displays ‘(SI)’ at the ‘You have:’ prompt to empha‐
1236 size the units mode. Some other types of units are also supported as
1237 described below. Giving an unrecognized system generates a warning,
1238 and units uses SI units.
1239
1240 The changes resulting from the ‘--units’ option are actually controlled
1241 by the UNITS_SYSTEM environment variable. If you frequently work with
1242 one of the supported CGS units systems, you may set this environment
1243 variable rather than giving the ‘--units’ option at each invocation.
1244 As usual, an option given on the command line overrides the setting of
1245 the environment variable. For example, if you would normally work with
1246 Gaussian units but might occasionally work with SI, you could set
1247 UNITS_SYSTEM to ‘gaussian’ and specify SI with the ‘--units’ option.
1248 Unlike the argument to the ‘--units’ option, the value of UNITS_SYSTEM
1249 is case sensitive, so setting a value of ‘EMU’ will have no effect
1250 other than to give an error message and set SI units.
1251
1252 The CGS definitions appear as conditional settings in the standard
1253 units data file, which you can consult for more information on how
1254 these units are defined, or on how to define an alternate units system.
1255
1256 The ESU system derives the electromagnetic units from its unit of
1257 charge, the statcoulomb, which is defined from Coulomb’s law. The
1258 statcoulomb equals dyne^(1/2) cm, or cm^(3/2) g^(1/2) s^(−1). The unit
1259 of current, the statampere, is statcoulomb sec, analogous to the rela‐
1260 tionship in SI. Other electrical units are then derived in a manner
1261 similar to that for SI units; the units use the SI names prefixed by
1262 ‘stat-’, e.g., ‘statvolt’ or ‘statV’. The prefix ‘st-’ is also recog‐
1263 nized (e.g., ‘stV’).
1264
1265 The EMU system derives the electromagnetic units from its unit of cur‐
1266 rent, the abampere, which is defined in terms of Ampere’s law. The
1267 abampere is equal to dyne^(1/2), or cm^(1/2) g^(1/2) s^(−1). delim off
1268 The unit of charge, the abcoulomb, is abampere sec, again analogous to
1269 the SI relationship. Other electrical units are then derived in a man‐
1270 ner similar to that for SI units; the units use the SI names prefixed
1271 by ‘ab-’, e.g., ‘abvolt’ or ‘abV’. The magnetic field units include
1272 the gauss, the oersted and the maxwell.
1273
1274 The Gaussian units system, which was also known as the Symmetric Sys‐
1275 tem, uses the same charge and current units as the ESU system (e.g.,
1276 ‘statC’, ‘statA’); it differs by defining the magnetic field so that it
1277 has the same units as the electric field. The resulting magnetic field
1278 units are the same ones used in the EMU system: the gauss, the oersted
1279 and the maxwell.
1280
1281 The Heaviside–Lorentz system appears to lack named units. We define
1282 five basic units, ‘hlu_charge’, ‘hlu_current’, ‘hlu_volt’, ‘hlu_efield’
1283 and ‘hlu_bfield’ for conversions with this system. It is important to
1284 remember that with all of the CGS systems, the units may look the same
1285 but mean something different. The HLU system and Gaussian systems both
1286 measure magnetic field using the same CGS dimensions, but the amount of
1287 magnetic field with the same units is different in the two systems.
1288
1289 The CGS systems define units that measure the same thing but may have
1290 conflicting dimensions. Furthermore, the dimensions of the electromag‐
1291 netic CGS units are never compatible with SI. But if you measure
1292 charge in two different systems you have measured the same physical
1293 thing, so there is a correspondence between the units in the different
1294 systems, and units supports conversions between corresponding units.
1295 When running with SI, units defines all of the CGS units in terms of
1296 SI. When you select a CGS system, units defines the SI units and the
1297 other CGS system units in terms of the system you have selected.
1298
1299 (Gaussian) You have: statA
1300 You want: abA
1301 * 3.335641e-11
1302 / 2.9979246e+10
1303 (Gaussian) You have: abA
1304 You want: sqrt(dyne)
1305 conformability error
1306 2.9979246e+10 sqrt_cm^3 sqrt_g / s^2
1307 1 sqrt_cm sqrt_g / s
1308
1309 In the above example, units converts between the current units statA
1310 and abA even though the abA, from the EMU system, has incompatible
1311 dimensions. This works because in Gaussian mode, the abA is defined in
1312 terms of the statA, so it does not have the correct definition for EMU;
1313 consequently, you cannot convert the abA to its EMU definition.
1314
1315 One challenge of conversion is that because the CGS system has fewer
1316 base units, quantities that have different dimensions in SI may have
1317 the same dimension in a CGS system. And yet, they may not have the
1318 same conversion factor. For example, the unit for the E field and B
1319 fields are the same in the Gaussian system, but the conversion factors
1320 to SI are quite different. This means that correct conversion is only
1321 possible if you keep track of what quantity is being measured. You
1322 cannot convert statV/cm to SI without indicating which type of field
1323 the unit measures. To aid in dimensional analysis, units defines vari‐
1324 ous dimension units such as LENGTH, TIME, and CHARGE to be the appro‐
1325 priate dimension in SI. The electromagnetic dimensions such as B_FIELD
1326 or E_FIELD may be useful aids both for conversion and dimensional anal‐
1327 ysis in CGS. You can convert them to or from CGS in order to perform
1328 SI conversions that in some cases will not work directly due to dimen‐
1329 sional incompatibilities. This example shows how the Gaussian system
1330 uses the same units for all of the fields, but they all have different
1331 conversion factors with SI.
1332
1333 (Gaussian) You have: statV/cm
1334 You want: E_FIELD
1335 * 29979.246
1336 / 3.335641e-05
1337 (Gaussian) You have: statV/cm
1338 You want: B_FIELD
1339 * 0.0001
1340 / 10000
1341 (Gaussian) You have: statV/cm
1342 You want: H_FIELD
1343 * 79.577472
1344 / 0.012566371
1345 (Gaussian) You have: statV/cm
1346 You want: D_FIELD
1347 * 2.6544187e-07
1348 / 3767303.1
1349
1350 The next example shows that the oersted cannot be converted directly to
1351 the SI unit of magnetic field, A/m, because the dimensions conflict.
1352 We cannot redefine the ampere to make this work because then it would
1353 not convert with the statampere. But you can still do this conversion
1354 as shown below.
1355
1356 (Gaussian) You have: oersted
1357 You want: A/m
1358 conformability error
1359 1 sqrt_g / s sqrt_cm
1360 29979246 sqrt_cm sqrt_g / s^2
1361 (Gaussian) You have: oersted
1362 You want: H_FIELD
1363 * 79.577472
1364 / 0.012566371
1365
1366 Natural Units
1367 Like the CGS units, “natural” units are an alternative to the SI system
1368 used primarily physicists in different fields, with different systems
1369 tailored to different fields of study. These systems are “natural”
1370 because the base measurements are defined using physical constants
1371 instead of arbitrary values such as the meter or second. In different
1372 branches of physics, different physical constants are more fundamental,
1373 which has given rise to a variety of incompatible natural unit systems.
1374
1375 The supported systems are the “natural” units (which seem to have no
1376 better name) used in high energy physics and cosmology, the Planck
1377 units, often used my scientists working with gravity, and the Hartree
1378 atomic units are favored by those working in physical chemistry and
1379 condensed matter physics.
1380
1381 You can select the various natural units using the ‘--units’ option in
1382 the same way that you select the CGS units. The “natural” units come
1383 in two types, a rationalized system derived from the Heaviside–Lorentz
1384 units and an unrationalized system derived from the Gaussian system.
1385 You can select these using ‘natural’ and ‘natural-gauss’ respectively.
1386 For conversions in SI mode, several unit names starting with ‘natural’
1387 are available. This “natural” system is defined by setting {hbar}, c
1388 and the Boltzman constant to 1. Only a single base unit remains: the
1389 electron volt.
1390
1391 The Planck units exist in a variety of forms, and units supports two.
1392 Both supported forms are rationalized, in that factors of 4{pi} do not
1393 appear in Maxwell’s equations. However, Planck units can also differ
1394 based on how the gravitational constant is treated. This system is
1395 similar to the natural units in that c, {hbar}, and Boltzman’s constant
1396 are set to 1, but in this system, Newton’s gravitational constant, G is
1397 also fixed. In the “reduced” Planck system, delim $$ 8{pi}G = 1
1398 whereas in the unreduced system G = 1. The reduced system eliminates
1399 factors of 8{pi} delim off from the Einstein field equations for gravi‐
1400 tation, so this is similar to the process of forming rationalized units
1401 to simplify Maxwell’s equations. To obtain the unreduced system use
1402 the name ‘planck’ and for the reduced Planck units, ‘planck-red’.
1403 Units such as ‘planckenergy’ and ‘planckenergy_red’ enable you to con‐
1404 vert the unreduced and reduced Planck energy unit in SI mode between
1405 the various systems. In Planck units, all measurements are dimension‐
1406 less.
1407
1408 The final natural unit system is the Hartree atomic units. Like the
1409 Planck units, all measurements in the Hartree units are dimensionless,
1410 but this system is defined by defined from completely different physi‐
1411 cal constants: the electron mass, Planck’s constant, the electron
1412 charge, and the Coulomb constant are the defining physical quantities,
1413 which are all set to unity. To invoke this system with the ‘--units’
1414 option use the name ‘hartree’.
1415
1416 Prompt Prefix
1417 If a unit system is specified with the ‘--units’ option, the selected
1418 system’s name is prepended to the ‘You have:’ prompt as a reminder,
1419 e.g.,
1420
1421 (Gaussian) You have: stC
1422 You want:
1423 Definition: statcoulomb = sqrt(dyne) cm = 1 sqrt_cm^3 sqrt_g / s
1424
1425 You can suppressed the prefix by including a line
1426
1427 !prompt
1428
1429 with no argument in a site or personal units data file. The prompt can
1430 be conditionally suppressed by including such a line within ‘!var’ ...
1431 ‘!endvar’ constructs, e.g.,
1432
1433 !var UNITS_SYSTEM gaussian gauss
1434 !prompt
1435 !endvar
1436
1437 This might be appropriate if you normally use Gaussian units and find
1438 the prefix distracting but want to be reminded when you have selected a
1439 different CGS system.
1440
1442 The ‘--log’ option allows you to save the results of calculations in a
1443 file; this can be useful if you need a permanent record of your work.
1444 For example, the fluid-flow conversion in Complicated Unit Expressions,
1445 is lengthy, and if you were to use it in designing a piping system, you
1446 might want a record of it for the project file. If the interactive
1447 session
1448
1449 # Conversion factor A1 for pressure drop
1450 # dP = A1 rho f L Q^2/d^5
1451 You have: (8/pi^2) (lbm/ft^3)ft(ft^3/s)^2(1/in^5) # Input units
1452 You want: psi
1453 * 43.533969
1454 / 0.022970568
1455
1456 were logged, the log file would contain
1457
1458 ### Log started Fri Oct 02 15:55:35 2015
1459
1460 # Conversion factor A1 for pressure drop
1461 # dP = A1 rho f L Q^2/d^5
1462 From: (8/pi^2) (lbm/ft^3)ft(ft^3/s)^2(1/in^5) # Input units
1463 To: psi
1464 * 43.533969
1465 / 0.022970568
1466
1467 The time is written to the log file when the file is opened.
1468
1469 The use of comments can help clarify the meaning of calculations for
1470 the log. The log includes conformability errors between the units at
1471 the ‘You have:’ and ‘You want:’ prompts, but not other errors, includ‐
1472 ing lack of conformability of items in sums or differences or among
1473 items in a unit list. For example, a conversion between zenith angle
1474 and elevation angle could involve
1475
1476 You have: 90 deg - (5 deg + 22 min + 9 sec)
1477 ^
1478 Illegal sum or difference of non-conformable units
1479 You have: 90 deg - (5 deg + 22 arcmin + 9 arcsec)
1480 You want: dms
1481 84 deg + 37 arcmin + 51 arcsec
1482 You have: _
1483 You want: deg
1484 * 84.630833
1485 / 0.011816024
1486 You have:
1487
1488 The log file would contain
1489
1490 From: 90 deg - (5 deg + 22 arcmin + 9 arcsec)
1491 To: deg;arcmin;arcsec
1492 84 deg + 37 arcmin + 51 arcsec
1493 From: _
1494 To: deg
1495 * 84.630833
1496 / 0.011816024
1497
1498 The initial entry error (forgetting that minutes have dimension of
1499 time, and that arcminutes must be used for dimensions of angle) does
1500 not appear in the output. When converting to a unit list alias, units
1501 expands the alias in the log file.
1502
1503 The ‘From:’ and ‘To:’ tags are written to the log file even if the
1504 ‘--quiet’ option is given. If the log file exists when units is
1505 invoked, the new results are appended to the log file. The time is
1506 written to the log file each time the file is opened. The ‘--log’
1507 option is ignored when units is used non-interactively.
1508
1510 You invoke units like this:
1511
1512 units [options] [from-unit [to-unit]]
1513
1514 If the from-unit and to-unit are omitted, the program will use interac‐
1515 tive prompts to determine which conversions to perform. See Interac‐
1516 tive Use. If both from-unit and to-unit are given, units will print
1517 the result of that single conversion and then exit. If only from-unit
1518 appears on the command line, units will display the definition of that
1519 unit and exit. Units specified on the command line may need to be
1520 quoted to protect them from shell interpretation and to group them into
1521 two arguments. Note also that the ‘--quiet’ option is enabled by
1522 default if you specify from-unit on the command line. See Command Line
1523 Use.
1524
1525 The default behavior of units can be changed by various options given
1526 on the command line. In most cases, the options may be given in either
1527 short form (a single ‘-’ followed by a single character) or long form
1528 (‘--’ followed by a word or hyphen-separated words). Short-form
1529 options are cryptic but require less typing; long-form options require
1530 more typing but are more explanatory and may be more mnemonic. With
1531 long-form options you need only enter sufficient characters to uniquely
1532 identify the option to the program. For example, ‘--out %f’ works, but
1533 ‘--o %f’ fails because units has other long options beginning with ‘o’.
1534 However, ‘--q’ works because ‘--quiet’ is the only long option begin‐
1535 ning with ‘q’.
1536
1537 Some options require arguments to specify a value (e.g., ‘-d 12’ or
1538 ‘--digits 12’). Short-form options that do not take arguments may be
1539 concatenated (e.g., ‘-erS’ is equivalent to ‘-e -r -S’); the last
1540 option in such a list may be one that takes an argument (e.g.,
1541 ‘-ed 12’). With short-form options, the space between an option and
1542 its argument is optional (e.g., ‘-d12’ is equivalent to ‘-d 12’).
1543 Long-form options may not be concatenated, and the space between a
1544 long-form option and its argument is required. Short-form and long-
1545 form options may be intermixed on the command line. Options may be
1546 given in any order, but when incompatible options (e.g.,
1547 ‘--output-format’ and ‘--exponential’) are given in combination, behav‐
1548 ior is controlled by the last option given. For example, ‘-o%.12f -e’
1549 gives exponential format with the default eight significant digits).
1550
1551 The following options are available:
1552
1553 -c, --check
1554 Check that all units and prefixes defined in the units data file
1555 reduce to primitive units. Print a list of all units that can‐
1556 not be reduced. Also display some other diagnostics about sus‐
1557 picious definitions in the units data file. Only definitions
1558 active in the current locale are checked. You should always run
1559 units with this option after modifying a units data file.
1560
1561 --check-verbose, --verbose-check
1562 Like the ‘--check’ option, this option prints a list of units
1563 that cannot be reduced. But to help find unit definitions that
1564 cause endless loops, it lists the units as they are checked. If
1565 units hangs, then the last unit to be printed has a bad defini‐
1566 tion. Only definitions active in the current locale are
1567 checked.
1568
1569 -d ndigits, --digits ndigits
1570 Set the number of significant digits in the output to the value
1571 specified (which must be greater than zero). For example,
1572 ‘-d 12’ sets the number of significant digits to 12. With expo‐
1573 nential output units displays one digit to the left of the deci‐
1574 mal point and eleven digits to the right of the decimal point.
1575 On most systems, the maximum number of internally meaningful
1576 digits is 15; if you specify a greater number than your system’s
1577 maximum, units will print a warning and set the number to the
1578 largest meaningful value. To directly set the maximum value,
1579 give an argument of max (e.g., ‘-d max’). Be aware, of course,
1580 that “significant” here refers only to the display of numbers;
1581 if results depend on physical constants not known to this preci‐
1582 sion, the physically meaningful precision may be less than that
1583 shown. The ‘--digits’ option conflicts with the
1584 ‘--output-format’ option.
1585
1586 -e, --exponential
1587 Set the numeric output format to exponential (i.e., scientific
1588 notation), like that used in the Unix units program. The
1589 default precision is eight significant digits (seven digits to
1590 the right of the decimal point); this can be changed with the
1591 ‘--digits’ option. The ‘--exponential’ option conflicts with
1592 the ‘--output-format’ option.
1593
1594 -o format, --output-format format
1595 This option affords complete control over the numeric output
1596 format using the specified format. The format is a single float‐
1597 ing point numeric format for the printf() function in the C pro‐
1598 gramming language. All compilers support the format types ‘g’
1599 and ‘G’ to specify significant digits, ‘e’ and ‘E’ for scien‐
1600 tific notation, and ‘f’ for fixed-point decimal. The ISO C99
1601 standard introduced the ‘F’ type for fixed-point decimal and the
1602 ‘a’ and ‘A’ types for hexadecimal floating point; these types
1603 are allowed with compilers that support them. The default for‐
1604 mat is ‘%.8g’; for greater precision, you could specify
1605 ‘-o %.15g’. See Numeric Output Format and the documentation for
1606 printf() for more detailed descriptions of the format specifica‐
1607 tion. The ‘--output-format’ option affords the greatest control
1608 of the output appearance, but requires at least rudimentary
1609 knowledge of the printf() format syntax. If you don’t want to
1610 bother with the printf() syntax, you can specify greater preci‐
1611 sion more simply with the ‘--digits’ option or select exponen‐
1612 tial format with ‘--exponential’. The ‘--output-format’ option
1613 is incompatible with the ‘--exponential’ and ‘--digits’ options.
1614
1615 -f filename, --file filename
1616 Instruct units to load the units file filename. You can specify
1617 up to 25 units files on the command line. When you use this
1618 option, units will load only the files you list on the command
1619 line; it will not load the standard file or your personal units
1620 file unless you explicitly list them. If filename is the empty
1621 string (‘-f ""’), the default units file (or that specified by
1622 UNITSFILE) will be loaded in addition to any others specified
1623 with ‘-f’.
1624
1625 -L logfile, --log logfile
1626 Save the results of calculations in the file logfile; this can
1627 be useful if it is important to have a record of unit conver‐
1628 sions or other calculations that are to be used extensively or
1629 in a critical activity such as a program or design project. If
1630 logfile exits, the new results are appended to the file. This
1631 option is ignored when units is used non-interactively. See
1632 Logging Calculations for a more detailed description and some
1633 examples.
1634
1635 -H filename, --history filename
1636 Instruct units to save history to filename, so that a record of
1637 your commands is available for retrieval across different units
1638 invocations. To prevent the history from being saved set file‐
1639 name to the empty string (‘-H ""’). This option has no effect
1640 if readline is not available.
1641
1642 -h, --help
1643 Print out a summary of the options for units.
1644
1645 -m, --minus
1646 Causes ‘-’ to be interpreted as a subtraction operator. This is
1647 the default behavior.
1648
1649 -p, --product
1650 Causes ‘-’ to be interpreted as a multiplication operator when
1651 it has two operands. It will act as a negation operator when it
1652 has only one operand: ‘(-3)’. By default ‘-’ is treated as a
1653 subtraction operator.
1654
1655 --oldstar
1656 Causes ‘*’ to have the old-style precedence, higher than the
1657 precedence of division so that ‘1/2*3’ will equal ‘1/6’.
1658
1659 --newstar
1660 Forces ‘*’ to have the new (default) precedence that follows the
1661 usual rules of algebra: the precedence of ‘*’ is the same as the
1662 precedence of ‘/’, so that ‘1/2*3’ will equal ‘3/2’.
1663
1664 -r, --round
1665 When converting to a combination of units given by a unit list,
1666 round the value of the last unit in the list to the nearest
1667 integer.
1668
1669 -S, --show-factor
1670 When converting to a combination of units specified in a list,
1671 always show a non-unity factor before a unit that begins with a
1672 fraction with a unity denominator. By default, if the unit in a
1673 list begins with fraction of the form 1|x and its multiplier is
1674 an integer other than 1, the fraction is given as the product of
1675 the multiplier and the numerator (e.g., ‘3|8 in’ rather than ‘3
1676 * 1|8 in’). In some cases, this is not what is wanted; for
1677 example, the results for a cooking recipe might show ‘3 *
1678 1|2 cup’ as ‘3|2 cup’. With the ‘--show-factor’ option, a
1679 result equivalent to 1.5 cups will display as ‘3 * 1|2 cup’
1680 rather than ‘3|2 cup’. A user-specified fractional unit with a
1681 numerator other than 1 is never overridden, however—if a unit
1682 list specifies ‘3|4 cup;1|2 cup’, a result equivalent to 1 1/2
1683 cups will always be shown as ‘2 * 3|4 cup’ whether or not the
1684 ‘--show-factor’ option is given.
1685
1686 --conformable
1687 In non-interactive mode, show all units conformable with the
1688 original unit expression. Only one unit expression is allowed;
1689 if you give more than one, units will exit with an error message
1690 and return failure.
1691
1692 -v, --verbose
1693 Give slightly more verbose output when converting units. When
1694 combined with the ‘-c’ option this gives the same effect as
1695 ‘--check-verbose’. When combined with ‘--version’ produces a
1696 more detailed output, equivalent to the ‘--info’ option.
1697
1698 -V, --version
1699 Print the program version number, tell whether the readline
1700 library has been included, tell whether UTF-8 support has been
1701 included; give the locale, the location of the default units
1702 data file, and the location of the personal units data file;
1703 indicate if the personal units data file does not exist.
1704
1705 When given in combination with the ‘--terse’ option, the program
1706 prints only the version number and exits.
1707
1708 When given in combination with the ‘--verbose’ option, the pro‐
1709 gram, the ‘--version’ option has the same effect as the ‘--info’
1710 option below.
1711
1712 -I, --info
1713 Print the information given with the ‘--version’ option, show
1714 the pathname of the units program, show the status of the
1715 UNITSFILE and MYUNITSFILE environment variables, and additional
1716 information about how units locates the related files. On sys‐
1717 tems running Microsoft Windows, the status of the UNITSLOCALE
1718 environment variable and information about the related locale
1719 map are also given. This option is usually of interest only to
1720 developers and administrators, but it can sometimes be useful
1721 for troubleshooting.
1722
1723 Combining the ‘--version’ and ‘--verbose’ options has the same
1724 effect as giving ‘--info’.
1725
1726 -U, --unitsfile
1727 Print the location of the default units data file and exit; if
1728 the file cannot be found, print “Units data file not found”.
1729
1730 -u (gauss[ian]|esu|emu), --units (gauss[ian]|esu|emu)
1731 Specify a CGS units system: Gaussian, ESU, or EMU.
1732
1733 -l locale, --locale locale
1734 Force a specified locale such as ‘en_GB’ to get British defini‐
1735 tions by default. This overrides the locale determined from
1736 system settings or environment variables. See Locale for a
1737 description of locale format.
1738
1739 -n, --nolists
1740 Disable conversion to unit lists.
1741
1742 -s, --strict
1743 Suppress conversion of units to their reciprocal units. For
1744 example, units will normally convert hertz to seconds because
1745 these units are reciprocals of each other. The strict option
1746 requires that units be strictly conformable to perform a conver‐
1747 sion, and will give an error if you attempt to convert hertz to
1748 seconds.
1749
1750 -1, --one-line
1751 Give only one line of output (the forward conversion); do not
1752 print the reverse conversion. If a reciprocal conversion is
1753 performed, then units will still print the “reciprocal conver‐
1754 sion” line.
1755
1756 -t, --terse
1757 Print only a single conversion factor. This option can be used
1758 when calling units from another program so that the output is
1759 easy to parse. This option has the combined effect of these
1760 options: ‘--strict’ ‘--quiet’ ‘--one-line’ ‘--compact’. When
1761 combined with ‘--version’ it produces a display showing only the
1762 program name and version number.
1763
1764 --compact
1765 Give compact output featuring only the conversion factor; the
1766 multiplication and division signs are not shown, and there is no
1767 leading whitespace. If you convert to a unit list, then the
1768 output is a semicolon separated list of factors. This turns off
1769 the ‘--verbose’ option.
1770
1771 -q, --quiet, --silent
1772 Suppress the display of statistics about the number of units
1773 loaded, any messages printed by the units database, and the
1774 prompting of the user for units. This option does not affect
1775 how units displays the results. This option is turned on by
1776 default if you invoke units with a unit expression on the com‐
1777 mand line.
1778
1780 Despite its numerous options, units cannot cover every conceivable
1781 unit-conversion task. For example, suppose we have found some mysteri‐
1782 ous scale, but cannot figure out the units in which it is reporting.
1783 We reach into our pocket, place a 3.75-gram coin on the scale, and
1784 observe the scale reading ‘0.120’. How do we quickly determine the
1785 units? Or we might wonder if a unit has any “synonyms,” i.e., other
1786 units with the same value.
1787
1788 The capabilities of units are easily extended with simple scripting.
1789 Both questions above involve conformable units; on a system with Unix-
1790 like utilities, conversions to conformable units could be shown accom‐
1791 plished with the following script:
1792
1793 #!/bin/sh
1794
1795 progname=`basename $0 .sh`
1796 umsg="Usage: $progname [<number>] unit"
1797
1798 if [ $# -lt 1 ]
1799 then
1800 echo "$progname: missing quantity to convert"
1801 echo "$umsg"
1802 exit 1
1803 fi
1804
1805 for unit in `units --conformable "$*" | cut -f 1 -d ' '`
1806 do
1807 echo "$*" # have -- quantity to convert
1808 echo $unit # want -- conformable unit
1809 done | units --terse --verbose
1810
1811 When units is invoked with no non-option arguments, it reads have/want
1812 pairs, on alternating lines, from its standard input, so the task can
1813 be accomplished with only two invocations of units. This avoids the
1814 computational overhead of needlessly reprocessing the units database
1815 for each conformable unit, as well as the inherent system overhead of
1816 process invocation.
1817
1818 By itself, the script is not very useful. But it could be used in com‐
1819 bination with other commands to address specific tasks. For example,
1820 running the script through a simple output filter could help solve the
1821 scale problem above. If the script is named conformable, running
1822
1823 $ conformable 3.75g | grep 0.120
1824
1825 gives
1826 3.75g = 0.1205653 apounce
1827 3.75g = 0.1205653 fineounce
1828 3.75g = 0.1205653 ozt
1829 3.75g = 0.1205653 tradewukiyeh
1830 3.75g = 0.1205653 troyounce
1831
1832 So we might conclude that the scale is calibrated in troy ounces.
1833
1834 We might run
1835 $ units --verbose are
1836 Definition: 100 m^2 = 100 m^2
1837
1838 and wonder if ‘are’ has any synonyms, value. To find out, we could run
1839
1840 $ conformable are | grep "= 1 "
1841 are = 1 a
1842 are = 1 are
1843
1845 The output can be tweaked in various ways using command line options.
1846 With no options, the output looks like this
1847
1848 $ units
1849 Currency exchange rates from FloatRates (USD base) on 2019-02-20
1850 3070 units, 109 prefixes, 109 nonlinear units
1851
1852 You have: 23ft
1853 You want: m
1854 * 7.0104
1855 / 0.14264521
1856 You have: m
1857 You want: ft;in
1858 3 ft + 3.3700787 in
1859
1860 This is arguably a bit cryptic; the ‘--verbose’ option makes clear what
1861 the output means:
1862
1863 $ units --verbose
1864 Currency exchange rates from FloatRates (USD base) on 2019-02-20
1865 3070 units, 109 prefixes, 109 nonlinear units
1866
1867 You have: 23 ft
1868 You want: m
1869 23 ft = 7.0104 m
1870 23 ft = (1 / 0.14264521) m
1871 You have: meter
1872 You want: ft;in
1873 meter = 3 ft + 3.3700787 in
1874
1875 The ‘--quiet’ option suppresses the clutter displayed when units
1876 starts, as well as the prompts to the user. This option is enabled by
1877 default when you give units on the command line.
1878
1879 $ units --quiet
1880 23 ft
1881 m
1882 * 7.0104
1883 / 0.14264521
1884
1885 $ units 23ft m
1886 * 7.0104
1887 / 0.14264521
1888
1889 The remaining style options allow you to display only numerical values
1890 without the tab or the multiplication and division signs, or to display
1891 just a single line showing the forward conversion:
1892
1893 $ units --compact 23ft m
1894 7.0104
1895 0.14264521
1896
1897 $ units --compact m 'ft;in'
1898 3;3.3700787
1899
1900 $ units --one-line 23ft m
1901 * 7.0104
1902
1903 $ units --one-line 23ft 1/m
1904 reciprocal conversion
1905 * 0.14264521
1906
1907 $ units --one-line 23ft kg
1908 conformability error
1909 7.0104 m
1910 1 kg
1911
1912 Note that when converting to a unit list, the ‘--compact’ option dis‐
1913 plays a semicolon separated list of results. Also be aware that the
1914 ‘one-line’ option doesn't live up to its name if you execute a recipro‐
1915 cal conversion or if you get a conformability error. The former case
1916 can be prevented using the ‘--strict’ option, which suppresses recipro‐
1917 cal conversions. Similarly you can suppress unit list conversion using
1918 ‘--nolists’. It is impossible to prevent the three line error output.
1919
1920 $ units --compact --nolists m 'ft;in'
1921 Error in 'ft;in': Parse error
1922
1923 $ units --one-line --strict 23ft 1/m
1924
1925 The various style options can be combined appropriately. The ultimate
1926 combination is the ‘--terse’ option, which combines ‘--strict’,
1927 ‘--quiet’, ‘--one-line’, and ‘--compact’ to produce the minimal output,
1928 just a single number for regular conversions and a semicolon separated
1929 list for conversion to unit lists. This will likely be the best choice
1930 for programs that want to call units and then process its result.
1931
1932 $ units --terse 23ft m
1933 7.0104
1934
1935 $ units --terse m 'ft;in'
1936 3;3.3700787
1937
1938 $ units --terse 23ft 1/m
1939 conformability error
1940 7.0104 m
1941 1 / m
1942
1944 Units Data Files
1945 The units and prefixes that units can convert are defined in the units
1946 data file, typically ‘/usr/share/units/definitions.units’. If you
1947 can’t find this file, run units --version to get information on the
1948 file locations for your installation. Although you can extend or mod‐
1949 ify this data file if you have appropriate user privileges, it’s usu‐
1950 ally better to put extensions in separate files so that the definitions
1951 will be preserved if you update units.
1952
1953 You can include additional data files in the units database using the
1954 ‘!include’ command in the standard units data file. For example
1955
1956 !include /usr/local/share/units/local.units
1957
1958 might be appropriate for a site-wide supplemental data file. The loca‐
1959 tion of the ‘!include’ statement in the standard units data file is
1960 important; later definitions replace earlier ones, so any definitions
1961 in an included file will override definitions before the ‘!include’
1962 statement in the standard units data file. With normal invocation, no
1963 warning is given about redefinitions; to ensure that you don’t have an
1964 unintended redefinition, run units -c after making changes to any units
1965 data file.
1966
1967 If you want to add your own units in addition to or in place of stan‐
1968 dard or site-wide supplemental units data files, you can include them
1969 in the ‘.units’ file in your home directory. If this file exists it is
1970 read after the standard units data file, so that any definitions in
1971 this file will replace definitions of the same units in the standard
1972 data file or in files included from the standard data file. This file
1973 will not be read if any units files are specified on the command line.
1974 (Under Windows the personal units file is named ‘unitdef.units’.) Run‐
1975 ning units -V will display the location and name of your personal units
1976 file.
1977
1978 The units program first tries to determine your home directory from the
1979 HOME environment variable. On systems running Microsoft Windows, if
1980 HOME does not exist, units attempts to find your home directory from
1981 HOMEDRIVE, HOMEPATH and USERPROFILE. You can specify an arbitrary file
1982 as your personal units data file with the MYUNITSFILE environment vari‐
1983 able; if this variable exists, its value is used without searching your
1984 home directory. The default units data files are described in more
1985 detail in Data Files.
1986
1987 Defining New Units and Prefixes
1988 A unit is specified on a single line by giving its name and an equiva‐
1989 lence. Comments start with a ‘#’ character, which can appear anywhere
1990 in a line. The backslash character (‘\’) acts as a continuation char‐
1991 acter if it appears as the last character on a line, making it possible
1992 to spread definitions out over several lines if desired. A file can be
1993 included by giving the command ‘!include’ followed by the file’s name.
1994 The ‘!’ must be the first character on the line. The file will be
1995 sought in the same directory as the parent file unless you give a full
1996 path. The name of the file to be included cannot contain spaces or the
1997 comment character ‘#’.
1998
1999 Unit names must not contain any of the operator characters ‘+’, ‘-’,
2000 ‘*’, ‘/’, ‘|’, ‘^’, ‘;’, ‘~’, the comment character ‘#’, or parenthe‐
2001 ses. They cannot begin or end with an underscore (‘_’), a comma (‘,’)
2002 or a decimal point (‘.’). The figure dash (U+2012), typographical
2003 minus ('-’; U+2212), and en dash ('--’; U+2013) are converted to the
2004 operator ‘-’, so none of these characters can appear in unit names.
2005 Names cannot begin with a digit, and if a name ends in a digit other
2006 than zero or one, the digit must be preceded by a string beginning with
2007 an underscore, and afterwards consisting only of digits, decimal
2008 points, or commas. For example, ‘foo_2’, ‘foo_2,1’, or ‘foo_3.14’ are
2009 valid names but ‘foo2’ or ‘foo_a2’ are invalid. The underscore is nec‐
2010 essary because without it, units cannot determine whether ‘foo2’ is a
2011 unit name or represents ‘foo^2’. Zero and one are exceptions because
2012 units never interprets them as exponents.
2013
2014 You could define nitrous oxide as
2015
2016 N2O nitrogen 2 + oxygen
2017
2018 but would need to define nitrogen dioxide as
2019
2020 NO_2 nitrogen + oxygen 2
2021
2022 Be careful to define new units in terms of old ones so that a reduction
2023 leads to the primitive units, which are marked with ‘!’ characters.
2024 Dimensionless units are indicated by using the string ‘!dimensionless’
2025 for the unit definition.
2026
2027 When adding new units, be sure to use the ‘-c’ option to check that the
2028 new units reduce properly. If you create a loop in the units defini‐
2029 tions, then units will hang when invoked with the ‘-c’ option. You
2030 will need to use the ‘--check-verbose’ option, which prints out each
2031 unit as it is checked. The program will still hang, but the last unit
2032 printed will be the unit that caused the infinite loop.
2033
2034 If you define any units that contain ‘+’ characters in their defini‐
2035 tions, carefully check them because the ‘-c’ option will not catch non-
2036 conformable sums. Be careful with the ‘-’ operator as well. When used
2037 as a binary operator, the ‘-’ character can perform addition or multi‐
2038 plication depending on the options used to invoke units. To ensure
2039 consistent behavior use ‘-’ only as a unary negation operator when
2040 writing units definitions. To multiply two units leave a space or use
2041 the ‘*’ operator with care, recalling that it has two possible prece‐
2042 dence values and may require parentheses to ensure consistent behavior.
2043 To compute the difference of ‘foo’ and ‘bar’ write ‘foo+(-bar)’ or even
2044 ‘foo+-bar’.
2045
2046 You may wish to intentionally redefine a unit. When you do this, and
2047 use the ‘-c’ option, units displays a warning message about the redefi‐
2048 nition. You can suppress these warnings by redefining a unit using a
2049 ‘+’ at the beginning of the unit name. Do not include any white space
2050 between the ‘+’ and the redefined unit name.
2051
2052 Here is an example of a short data file that defines some basic units:
2053
2054 m ! # The meter is a primitive unit
2055 sec ! # The second is a primitive unit
2056 rad !dimensionless # A dimensionless primitive unit
2057 micro- 1e-6 # Define a prefix
2058 minute 60 sec # A minute is 60 seconds
2059 hour 60 min # An hour is 60 minutes
2060 inch 72 m # Inch defined incorrectly terms of meters
2061 ft 12 inches # The foot defined in terms of inches
2062 mile 5280 ft # And the mile
2063 +inch 0.0254 m # Correct redefinition, warning suppressed
2064
2065 A unit that ends with a ‘-’ character is a prefix. If a prefix defini‐
2066 tion contains any ‘/’ characters, be sure they are protected by paren‐
2067 theses. If you define ‘half- 1/2’, then ‘halfmeter’ would be equiva‐
2068 lent to ‘1 / (2 meter)’.
2069
2070 Defining Nonlinear Units
2071 Some unit conversions of interest are nonlinear; for example, tempera‐
2072 ture conversions between the Fahrenheit and Celsius scales cannot be
2073 done by simply multiplying by conversion factors.
2074
2075 When you give a linear unit definition such as ‘inch 2.54 cm’ you are
2076 providing information that units uses to convert values in inches into
2077 primitive units of meters. For nonlinear units, you give a functional
2078 definition that provides the same information.
2079
2080 Nonlinear units are represented using a functional notation. It is
2081 best to regard this notation not as a function call but as a way of
2082 adding units to a number, much the same way that writing a linear unit
2083 name after a number adds units to that number. Internally, nonlinear
2084 units are defined by a pair of functions that convert to and from lin‐
2085 ear units in the database, so that an eventual conversion to primitive
2086 units is possible.
2087
2088 Here is an example nonlinear unit definition:
2089
2090 tempF(x) units=[1;K] domain=[-459.67,) range=[0,) \
2091 (x+(-32)) degF + stdtemp ; (tempF+(-stdtemp))/degF + 32
2092
2093 A nonlinear unit definition comprises a unit name, a formal parameter
2094 name, two functions, and optional specifications for units, the domain,
2095 and the range (the domain of the inverse function). The functions tell
2096 units how to convert to and from the new unit. To produce valid
2097 results, the arguments of these functions need to have the correct
2098 dimensions and be within the domains for which the functions are
2099 defined.
2100
2101 The definition begins with the unit name followed immediately (with no
2102 spaces) by a ‘(’ character. In the parentheses is the name of the for‐
2103 mal parameter. Next is an optional specification of the units required
2104 by the functions in the definition. In the example above, the
2105 ‘units=[1;K]’ specification indicates that the ‘tempF’ function
2106 requires an input argument conformable with ‘1’ (i.e., the argument is
2107 dimensionless), and that the inverse function requires an input argu‐
2108 ment conformable with ‘K’. For normal nonlinear units definition, the
2109 forward function will always take a dimensionless argument; in general,
2110 the inverse function will need units that match the quantity measured
2111 by your nonlinear unit. Specifying the units enables units to perform
2112 error checking on function arguments, and also to assign units to
2113 domain and range specifications, which are described later.
2114
2115 Next the function definitions appear. In the example above, the
2116 ‘tempF’ function is defined by
2117
2118 tempF(x) = (x+(-32)) degF + stdtemp
2119
2120 This gives a rule for converting ‘x’ in the units ‘tempF’ to linear
2121 units of absolute temperature, which makes it possible to convert from
2122 tempF to other units.
2123
2124 To enable conversions to Fahrenheit, you must give a rule for the
2125 inverse conversions. The inverse will be ‘x(tempF)’ and its definition
2126 appears after a ‘;’ character. In our example, the inverse is
2127
2128 x(tempF) = (tempF+(-stdtemp))/degF + 32
2129
2130 This inverse definition takes an absolute temperature as its argument
2131 and converts it to the Fahrenheit temperature. The inverse can be
2132 omitted by leaving out the ‘;’ character and the inverse definition,
2133 but then conversions to the unit will not be possible. If the inverse
2134 definition is omitted, the ‘--check’ option will display a warning. It
2135 is up to you to calculate and enter the correct inverse function to
2136 obtain proper conversions; the ‘--check’ option tests the inverse at
2137 one point and prints an error if it is not valid there, but this is not
2138 a guarantee that your inverse is correct.
2139
2140 With some definitions, the units may vary. For example, the definition
2141
2142 square(x) x^2
2143
2144 can have any arbitrary units, and can also take dimensionless argu‐
2145 ments. In such a case, you should not specify units. If a definition
2146 takes a root of its arguments, the definition is valid only for units
2147 that yield such a root. For example,
2148
2149 squirt(x) sqrt(x)
2150
2151 is valid for a dimensionless argument, and for arguments with even pow‐
2152 ers of units.
2153
2154 Some definitions may not be valid for all real numbers. In such cases,
2155 units can handle errors better if you specify an appropriate domain and
2156 range. You specify the domain and range as shown below:
2157
2158 baume(d) units=[1;g/cm^3] domain=[0,130.5] range=[1,10] \
2159 (145/(145-d)) g/cm^3 ; (baume+-g/cm^3) 145 / baume
2160
2161 In this example the domain is specified after ‘domain=’ with the end‐
2162 points given in brackets. In accord with mathematical convention,
2163 square brackets indicate a closed interval (one that includes its end‐
2164 points), and parentheses indicate an open interval (one that does not
2165 include its endpoints). An interval can be open or closed on one or
2166 both ends; an interval that is unbounded on either end is indicated by
2167 omitting the limit on that end. For example, a quantity to which deci‐
2168 bel (dB) is applied may have any value greater than zero, so the range
2169 is indicated by ‘(0,)’:
2170
2171 decibel(x) units=[1;1] range=(0,) 10^(x/10); 10 log(decibel)
2172
2173 If the domain or range is given, the second endpoint must be greater
2174 than the first.
2175
2176 The domain and range specifications can appear independently and in any
2177 order along with the units specification. The values for the domain
2178 and range endpoints are attached to the units given in the units speci‐
2179 fication, and if necessary, the parameter value is adjusted for compar‐
2180 ison with the endpoints. For example, if a definition includes
2181 ‘units=[1;ft]’ and ‘range=[3,)’, the range will be taken as 3 ft to
2182 infinity. If the function is passed a parameter of ‘900 mm’, that
2183 value will be adjusted to 2.9527559 ft, which is outside the specified
2184 range. If you omit the units specification from the previous example,
2185 units can not tell whether you intend the lower endpoint to be 3 ft or
2186 3 microfurlongs, and can not adjust the parameter value of 900 mm for
2187 comparison. Without units, numerical values other than zero or plus or
2188 minus infinity for domain or range endpoints are meaningless, and
2189 accordingly they are not allowed. If you give other values without
2190 units, then the definition will be ignored and you will get an error
2191 message.
2192
2193 Although the units, domain, and range specifications are optional, it’s
2194 best to give them when they are applicable; doing so allows units to
2195 perform better error checking and give more helpful error messages.
2196 Giving the domain and range also enables the ‘--check’ option to find a
2197 point in the domain to use for its point check of your inverse defini‐
2198 tion.
2199
2200 You can make synonyms for nonlinear units by providing both the forward
2201 and inverse functions; inverse functions can be obtained using the ‘~’
2202 operator. So to create a synonym for ‘tempF’ you could write
2203
2204 fahrenheit(x) units=[1;K] tempF(x); ~tempF(fahrenheit)
2205
2206 This is useful for creating a nonlinear unit definition that differs
2207 slightly from an existing definition without having to repeat the orig‐
2208 inal functions. For example,
2209
2210 dBW(x) units=[1;W] range=[0,) dB(x) W ; ~dB(dBW/W)
2211
2212 If you wish a synonym to refer to an existing nonlinear unit without
2213 modification, you can do so more simply by adding the synonym with
2214 appended parentheses as a new unit, with the existing nonlinear unit—
2215 without parentheses—as the definition. So to create a synonym for
2216 ‘tempF’ you could write
2217
2218 fahrenheit() tempF
2219
2220 The definition must be a nonlinear unit; for example, the synonym
2221
2222 fahrenheit() meter
2223
2224 will result in an error message when units starts.
2225
2226 You may occasionally wish to define a function that operates on units.
2227 This can be done using a nonlinear unit definition. For example, the
2228 definition below provides conversion between radius and the area of a
2229 circle. This definition requires a length as input and produces an
2230 area as output, as indicated by the ‘units=’ specification. Specifying
2231 the range as the nonnegative numbers can prevent cryptic error mes‐
2232 sages.
2233
2234 circlearea(r) units=[m;m^2] range=[0,) pi r^2 ; sqrt(circlearea/pi)
2235
2236 Defining Piecewise Linear Units
2237 Sometimes you may be interested in a piecewise linear unit such as many
2238 wire gauges. Piecewise linear units can be defined by specifying con‐
2239 versions to linear units on a list of points. Conversion at other
2240 points will be done by linear interpolation. A partial definition of
2241 zinc gauge is
2242
2243 zincgauge[in] 1 0.002, 10 0.02, 15 0.04, 19 0.06, 23 0.1
2244
2245 In this example, ‘zincgauge’ is the name of the piecewise linear unit.
2246 The definition of such a unit is indicated by the embedded ‘[’ charac‐
2247 ter. After the bracket, you should indicate the units to be attached
2248 to the numbers in the table. No spaces can appear before the ‘]’ char‐
2249 acter, so a definition like ‘foo[kg meters]’ is invalid; instead write
2250 ‘foo[kg*meters]’. The definition of the unit consists of a list of
2251 pairs optionally separated by commas. This list defines a function for
2252 converting from the piecewise linear unit to linear units. The first
2253 item in each pair is the function argument; the second item is the
2254 value of the function at that argument (in the units specified in
2255 brackets). In this example, we define ‘zincgauge’ at five points. For
2256 example, we set ‘zincgauge(1)’ equal to ‘0.002 in’. Definitions like
2257 this may be more readable if written using continuation characters
2258 as
2259
2260 zincgauge[in] \
2261 1 0.002 \
2262 10 0.02 \
2263 15 0.04 \
2264 19 0.06 \
2265 23 0.1
2266
2267 With the preceding definition, the following conversion can be per‐
2268 formed:
2269
2270 You have: zincgauge(10)
2271 You want: in
2272 * 0.02
2273 / 50
2274 You have: .01 inch
2275 You want: zincgauge
2276 5
2277
2278 If you define a piecewise linear unit that is not strictly monotonic,
2279 then the inverse will not be well defined. If the inverse is requested
2280 for such a unit, units will return the smallest inverse.
2281
2282 After adding nonlinear units definitions, you should normally run
2283 units --check to check for errors. If the ‘units’ keyword is not
2284 given, the ‘--check’ option checks a nonlinear unit definition using a
2285 dimensionless argument, and then checks using an arbitrary combination
2286 of units, as well as the square and cube of that combination; a warning
2287 is given if any of these tests fail. For example,
2288
2289 Warning: function 'squirt(x)' defined as 'sqrt(x)'
2290 failed for some test inputs:
2291 squirt(7(kg K)^1): Unit not a root
2292 squirt(7(kg K)^3): Unit not a root
2293
2294 Running units --check will print a warning if a non-monotonic piecewise
2295 linear unit is encountered. For example, the relationship between ANSI
2296 coated abrasive designation and mean particle size is non-monotonic in
2297 the vicinity of 800 grit:
2298
2299 ansicoated[micron] \
2300 . . .
2301 600 10.55 \
2302 800 11.5 \
2303 1000 9.5 \
2304
2305 Running units --check would give the error message
2306
2307 Table 'ansicoated' lacks unique inverse around entry 800
2308
2309 Although the inverse is not well defined in this region, it’s not
2310 really an error. Viewing such error messages can be tedious, and if
2311 there are enough of them, they can distract from true errors. Error
2312 checking for nonlinear unit definitions can be suppressed by giving the
2313 ‘noerror’ keyword; for the examples above, this could be done as
2314
2315 squirt(x) noerror domain=[0,) range=[0,) sqrt(x); squirt^2
2316 ansicoated[micron] noerror \
2317 . . .
2318
2319 Use the ‘noerror’ keyword with caution. The safest approach after
2320 adding a nonlinear unit definition is to run units --check and confirm
2321 that there are no actual errors before adding the ‘noerror’ keyword.
2322
2323 Defining Unit List Aliases
2324 Unit list aliases are treated differently from unit definitions,
2325 because they are a data entry shorthand rather than a true definition
2326 for a new unit. A unit list alias definition begins with ‘!unitlist’
2327 and includes the alias and the definition; for example, the aliases
2328 included in the standard units data file are
2329
2330 !unitlist hms hr;min;sec
2331 !unitlist time year;day;hr;min;sec
2332 !unitlist dms deg;arcmin;arcsec
2333 !unitlist ftin ft;in;1|8 in
2334 !unitlist usvol cup;3|4 cup;2|3 cup;1|2 cup;1|3 cup;1|4 cup;\
2335 tbsp;tsp;1|2 tsp;1|4 tsp;1|8 tsp
2336
2337 Unit list aliases are only for unit lists, so the definition must
2338 include a ‘;’. Unit list aliases can never be combined with units or
2339 other unit list aliases, so the definition of ‘time’ shown above could
2340 not have been shortened to ‘year;day;hms’.
2341
2342 As usual, be sure to run units --check to ensure that the units listed
2343 in unit list aliases are conformable.
2344
2346 By default, units shows results to eight significant digits. You can
2347 change this with the ‘--exponential’, ‘--digits’, and ‘--output-format’
2348 options. The first sets an exponential format (i.e., scientific nota‐
2349 tion) like that used in the original Unix units program, the second
2350 allows you to specify a different number of significant digits, and the
2351 last allows you to control the output appearance using the format for
2352 the printf() function in the C programming language. If you only want
2353 to change the number of significant digits or specify exponential for‐
2354 mat type, use the ‘--digits’ and ‘--exponential’ options. The
2355 ‘--output-format’ option affords the greatest control of the output
2356 appearance, but requires at least rudimentary knowledge of the printf()
2357 format syntax. See Invoking Units for descriptions of these options.
2358
2359 Format Specification
2360 The format specification recognized with the ‘--output-format’ option
2361 is a subset of that for printf(). The format specification has the
2362 form %[flags][width][.precision]type; it must begin with ‘%’, and must
2363 end with a floating-point type specifier: ‘g’ or ‘G’ to specify the
2364 number of significant digits, ‘e’ or ‘E’ for scientific notation, and
2365 ‘f’ for fixed-point decimal. The ISO C99 standard added the ‘F’ type
2366 for fixed-point decimal and the ‘a’ and ‘A’ types for hexadecimal
2367 floating point; these types are allowed with compilers that support
2368 them. Type length modifiers (e.g., ‘L’ to indicate a long double) are
2369 inapplicable and are not allowed.
2370
2371 The default format for units is ‘%.8g’; for greater precision, you
2372 could specify ‘-o %.15g’. The ‘g’ and ‘G’ format types use exponential
2373 format whenever the exponent would be less than -4, so the value
2374 0.000013 displays as ‘1.3e-005’. These types also use exponential
2375 notation when the exponent is greater than or equal to the precision,
2376 so with the default format, the value 5e7 displays as ‘50000000’ and
2377 the value 5e8 displays as ‘5e+008’. If you prefer fixed-point display,
2378 you might specify ‘-o %.8f’; however, small numbers will display very
2379 few significant digits, and values less than 0.5e-8 will show nothing
2380 but zeros.
2381
2382 The format specification may include one or more optional flags: ‘+’,
2383 ‘ ’ (space), ‘#’, ‘-’, or ‘0’ (the digit zero). The digit-grouping
2384 flag ‘'’ is allowed with compilers that support it. Flags are followed
2385 by an optional value for the minimum field width, and an optional pre‐
2386 cision specification that begins with a period (e.g., ‘.6’). The field
2387 width includes the digits, decimal point, the exponent, thousands sepa‐
2388 rators (with the digit-grouping flag), and the sign if any of these are
2389 shown.
2390
2391 Flags
2392 The ‘+’ flag causes the output to have a sign (‘+’ or ‘-’). The space
2393 flag ‘ ’ is similar to the ‘+’ flag, except that when the value is pos‐
2394 itive, it is prefixed with a space rather than a plus sign; this flag
2395 is ignored if the ‘+’ flag is also given. The ‘+’ or ‘ ’ flag could be
2396 useful if conversions might include positive and negative results, and
2397 you wanted to align the decimal points in exponential notation. The
2398 ‘#’ flag causes the output value to contain a decimal point in all
2399 cases; by default, the output contains a decimal point only if there
2400 are digits (which can be trailing zeros) to the right of the point.
2401 With the ‘g’ or ‘G’ types, the ‘#’ flag also prevents the suppression
2402 of trailing zeros. The digit-grouping flag ‘'’ shows a thousands sepa‐
2403 rator in digits to the left of the decimal point. This can be useful
2404 when displaying large numbers in fixed-point decimal; for example, with
2405 the format ‘%f’,
2406
2407 You have: mile
2408 You want: microfurlong
2409 * 8000000.000000
2410 / 0.000000
2411
2412 the magnitude of the first result may not be immediately obvious with‐
2413 out counting the digits to the left of the decimal point. If the thou‐
2414 sands separator is the comma (‘,’), the output with the format ‘%'f’
2415 might be
2416
2417 You have: mile
2418 You want: microfurlong
2419 * 8,000,000.000000
2420 / 0.000000
2421
2422 making the magnitude readily apparent. Unfortunately, few compilers
2423 support the digit-grouping flag.
2424
2425 With the ‘-’ flag, the output value is left aligned within the speci‐
2426 fied field width. If a field width greater than needed to show the
2427 output value is specified, the ‘0’ (zero) flag causes the output value
2428 to be left padded with zeros until the specified field width is
2429 reached; for example, with the format ‘%011.6f’,
2430
2431 You have: troypound
2432 You want: grain
2433 * 5760.000000
2434 / 0000.000174
2435
2436 The ‘0’ flag has no effect if the ‘-’ (left align) flag is given.
2437
2438 Field Width
2439 By default, the output value is left aligned and shown with the minimum
2440 width necessary for the specified (or default) precision. If a field
2441 width greater than this is specified, the value shown is right aligned,
2442 and padded on the left with enough spaces to provide the specified
2443 field width. A width specification is typically used with fixed-point
2444 decimal to have columns of numbers align at the decimal point; this
2445 arguably is less useful with units than with long columnar output, but
2446 it may nonetheless assist in quickly assessing the relative magnitudes
2447 of results. For example, with the format ‘%12.6f’,
2448
2449 You have: km
2450 You want: in
2451 * 39370.078740
2452 / 0.000025
2453 You have: km
2454 You want: rod
2455 * 198.838782
2456 / 0.005029
2457 You have: km
2458 You want: furlong
2459 * 4.970970
2460 / 0.201168
2461
2462 Precision
2463 The meaning of “precision” depends on the format type. With ‘g’ or
2464 ‘G’, it specifies the number of significant digits (like the ‘--digits’
2465 option); with ‘e’, ‘E’, ‘f’, or ‘F’, it specifies the maximum number of
2466 digits to be shown after the decimal point.
2467
2468 With the ‘g’ and ‘G’ format types, trailing zeros are suppressed, so
2469 the results may sometimes have fewer digits than the specified preci‐
2470 sion (as indicated above, the ‘#’ flag causes trailing zeros to be dis‐
2471 played).
2472
2473 The default precision is 6, so ‘%g’ is equivalent to ‘%.6g’, and would
2474 show the output to six significant digits. Similarly, ‘%e’ or ‘%f’
2475 would show the output with six digits after the decimal point.
2476
2477 The C printf() function allows a precision of arbitrary size, whether
2478 or not all of the digits are meaningful. With most compilers, the max‐
2479 imum internal precision with units is 15 decimal digits (or 13 hexadec‐
2480 imal digits). With the ‘--digits’ option, you are limited to the maxi‐
2481 mum internal precision; with the ‘--output-format’ option, you may
2482 specify a precision greater than this, but it may not be meaningful.
2483 In some cases, specifying excess precision can result in rounding arti‐
2484 facts. For example, a pound is exactly 7000 grains, but with the for‐
2485 mat ‘%.18g’, the output might be
2486
2487 You have: pound
2488 You want: grain
2489 * 6999.9999999999991
2490 / 0.00014285714285714287
2491
2492 With the format ‘%.25g’ you might get the following:
2493
2494 You have: 1/3
2495 You want:
2496 Definition: 0.333333333333333314829616256247
2497
2498 In this case the displayed value includes a series of digits that rep‐
2499 resent the underlying binary floating-point approximation to 1/3 but
2500 are not meaningful for the desired computation. In general, the result
2501 with excess precision is system dependent. The precision affects only
2502 the display of numbers; if a result relies on physical constants that
2503 are not known to the specified precision, the number of physically
2504 meaningful digits may be less than the number of digits shown.
2505
2506 See the documentation for printf() for more detailed descriptions of
2507 the format specification.
2508
2509 The ‘--output-format’ option is incompatible with the ‘--exponential’
2510 or ‘--digits’ options; if the former is given in combination with
2511 either of the latter, the format is controlled by the last option
2512 given.
2513
2515 Some units have different values in different locations. The localiza‐
2516 tion feature accommodates this by allowing a units data file to specify
2517 definitions that depend on the user’s locale.
2518
2519 Locale
2520 A locale is a subset of a user’s environment that indicates the user’s
2521 language and country, and some attendant preferences, such as the for‐
2522 matting of dates. The units program attempts to determine the locale
2523 from the POSIX setlocale function; if this cannot be done, units exam‐
2524 ines the environment variables LC_CTYPE and LANG. On POSIX systems, a
2525 locale is of the form language_country, where language is the two-char‐
2526 acter code from ISO 639-1 and country is the two-character code from
2527 ISO 3166-1; language is lower case and country is upper case. For exam‐
2528 ple, the POSIX locale for the United Kingdom is en_GB.
2529
2530 On systems running Microsoft Windows, the value returned by setlocale()
2531 is different from that on POSIX systems; units attempts to map the Win‐
2532 dows value to a POSIX value by means of a table in the file
2533 ‘locale_map.txt’ in the same directory as the other data files. The
2534 file includes entries for many combinations of language and country,
2535 and can be extended to include other combinations. The
2536 ‘locale_map.txt’ file comprises two tab-separated columns; each entry
2537 is of the form
2538
2539 Windows-locale POSIX-locale
2540
2541 where POSIX-locale is as described above, and Windows-locale typically
2542 spells out both the language and country. For example, the entry for
2543 the United States is
2544
2545 English_United States en_US
2546
2547 You can force units to run in a desired locale by using the ‘-l’
2548 option.
2549
2550 In order to create unit definitions for a particular locale you begin a
2551 block of definitions in a unit datafile with ‘!locale’ followed by a
2552 locale name. The ‘!’ must be the first character on the line. The
2553 units program reads the following definitions only if the current
2554 locale matches. You end the block of localized units with
2555 ‘!endlocale’. Here is an example, which defines the British gallon.
2556
2557 !locale en_GB
2558 gallon 4.54609 liter
2559 !endlocale
2560
2561 Additional Localization
2562 Sometimes the locale isn’t sufficient to determine unit preferences.
2563 There could be regional preferences, or a company could have specific
2564 preferences. Though probably uncommon, such differences could arise
2565 with the choice of English customary units outside of English-speaking
2566 countries. To address this, units allows specifying definitions that
2567 depend on environment variable settings. The environment variables can
2568 be controled based on the current locale, or the user can set them to
2569 force a particular group of definitions.
2570
2571 A conditional block of definitions in a units data file begins with
2572 either ‘!var’ or ‘!varnot’ following by an environment variable name
2573 and then a space separated list of values. The leading ‘!’ must appear
2574 in the first column of a units data file, and the conditional block is
2575 terminated by ‘!endvar’. Definitions in blocks beginning with ‘!var’
2576 are executed only if the environment variable is exactly equal to one
2577 of the listed values. Definitions in blocks beginning with ‘!varnot’
2578 are executed only if the environment variable does not equal any of the
2579 list values.
2580
2581 The inch has long been a customary measure of length in many places.
2582 The word comes from the Latin uncia meaning “one twelfth,” referring to
2583 its relationship with the foot. By the 20th century, the inch was
2584 officially defined in English-speaking countries relative to the yard,
2585 but until 1959, the yard differed slightly among those countries. In
2586 France the customary inch, which was displaced in 1799 by the meter,
2587 had a different length based on a french foot. These customary defini‐
2588 tions could be accommodated as follows:
2589
2590 !var INCH_UNIT usa
2591 yard 3600|3937 m
2592 !endvar
2593 !var INCH_UNIT canada
2594 yard 0.9144 meter
2595 !endvar
2596 !var INCH_UNIT uk
2597 yard 0.91439841 meter
2598 !endvar
2599 !var INCH_UNIT canada uk usa
2600 foot 1|3 yard
2601 inch 1|12 foot
2602 !endvar
2603 !var INCH_UNIT france
2604 foot 144|443.296 m
2605 inch 1|12 foot
2606 line 1|12 inch
2607 !endvar
2608 !varnot INCH_UNIT usa uk france canada
2609 !message Unknown value for INCH_UNIT
2610 !endvar
2611
2612 When units reads the above definitions it will check the environment
2613 variable INCH_UNIT and load only the definitions for the appropriate
2614 section. If INCH_UNIT is unset or is not set to one of the four values
2615 listed, then units will run the last block. In this case that block
2616 uses the ‘!message’ command to display a warning message. Alterna‐
2617 tively that block could set default values.
2618
2619 In order to create default values that are overridden by user settings
2620 the data file can use the ‘!set’ command, which sets an environment
2621 variable only if it is not already set; these settings are only for
2622 the current units invocation and do not persist. So if the example
2623 above were preceded by ‘!set INCH_UNIT france’, then this would make
2624 ‘france’ the default value for INCH_UNIT. If the user had set the
2625 variable in the environment before invoking units, then units would use
2626 the user’s value.
2627
2628 To link these settings to the user’s locale you combine the ‘!set’ com‐
2629 mand with the ‘!locale’ command. If you wanted to combine the above
2630 example with suitable locales you could do by preceding the above defi‐
2631 nition with the following:
2632
2633 !locale en_US
2634 !set INCH_UNIT usa
2635 !endlocale
2636 !locale en_GB
2637 !set INCH_UNIT uk
2638 !endlocale
2639 !locale en_CA
2640 !set INCH_UNIT canada
2641 !endlocale
2642 !locale fr_FR
2643 !set INCH_UNIT france
2644 !endlocale
2645 !set INCH_UNIT france
2646
2647 These definitions set the overall default for INCH_UNIT to ‘france’ and
2648 set default values for four locales appropriately. The overall default
2649 setting comes last so that it only applies when INCH_UNIT was not set
2650 by one of the other commands or by the user.
2651
2652 If the variable given after ‘!var’ or ‘!varnot’ is undefined, then
2653 units prints an error message and ignores the definitions that follow.
2654 Use ‘!set’ to create defaults to prevent this situation from arising.
2655 The ‘-c’ option only checks the definitions that are active for the
2656 current environment and locale, so when adding new definitions take
2657 care to check that all cases give rise to a well defined set of defini‐
2658 tions.
2659
2661 The units program uses the following environment variables:
2662
2663 HOME Specifies the location of your home directory; it is used by
2664 units to find a personal units data file ‘.units’. On systems
2665 running Microsoft Windows, the file is ‘unitdef.units’, and if
2666 HOME does not exist, units tries to determine your home direc‐
2667 tory from the HOMEDRIVE and HOMEPATH environment variables; if
2668 these variables do not exist, units finally tries
2669 USERPROFILE—typically ‘C:\Users\username’ (Windows Vista and
2670 Windows 7) or ‘C:\Documents and Settings\username’ (Windows XP).
2671
2672 LC_CTYPE, LANG
2673 Checked to determine the locale if units cannot obtain it from
2674 the operating system. Sections of the standard units data file
2675 are specific to certain locales.
2676
2677 MYUNITSFILE
2678 Specifies your personal units data file. If this variable
2679 exists, units uses its value rather than searching your home
2680 directory for ‘.units’. The personal units file will not be
2681 loaded if any data files are given using the ‘-f’ option.
2682
2683 PAGER Specifies the pager to use for help and for displaying the con‐
2684 formable units. The help function browses the units database
2685 and calls the pager using the ‘+n’n syntax for specifying a line
2686 number. The default pager is more; PAGER can be used to specify
2687 alternatives such as less, pg, emacs, or vi.
2688
2689 UNITS_ENGLISH
2690 Set to either ‘US’ or ‘GB’ to choose United States or British
2691 volume definitions, overriding the default from your locale.
2692
2693 UNITSFILE
2694 Specifies the units data file to use (instead of the default).
2695 You can only specify a single units data file using this envi‐
2696 ronment variable. If units data files are given using the ‘-f’
2697 option, the file specified by UNITSFILE will be not be loaded
2698 unless the ‘-f’ option is given with the empty string (‐
2699 ‘units -f ""’).
2700
2701 UNITSLOCALEMAP
2702 Windows only; this variable has no effect on Unix-like systems.
2703 Specifies the units locale map file to use (instead of the
2704 default). This variable seldom needs to be set, but you can use
2705 it to ensure that the locale map file will be found if you spec‐
2706 ify a location for the units data file using either the ‘-f’
2707 option or the UNITSFILE environment variable, and that location
2708 does not also contain the locale map file.
2709
2710 UNITS_SYSTEM
2711 This environment variable is used in the standard data file to
2712 select CGS measurement systems. Currently supported systems are
2713 ‘esu’, ‘emu’, ‘gauss[ian]’, and ‘si’. The default is ‘si’.
2714
2716 The units program uses two default data files: ‘definitions.units’ and
2717 ‘currency.units’. The program can also use an optional personal units
2718 data file ‘.units’ (‘unitdef.units’ under Windows) located in the
2719 user’s home directory. The personal units data file is described in
2720 more detail in Units Data Files.
2721
2722 On Unix-like systems, the data files are typically located in
2723 ‘/usr/share/units’ if units is provided with the operating system, or
2724 in ‘/usr/local/share/units’ if units is compiled from the source dis‐
2725 tribution. Note that the currency file ‘currency.units’ is a symbolic
2726 link to another location.
2727
2728 On systems running Microsoft Windows, the files may be in the same
2729 locations if Unix-like commands are available, a Unix-like file struc‐
2730 ture is present (e.g., ‘C:/usr/local’), and units is compiled from the
2731 source distribution. If Unix-like commands are not available, a more
2732 common location is ‘C:\Program Files (x86)\GNU\units’ (for 64-bit Win‐
2733 dows installations) or ‘C:\Program Files\GNU\units’ (for 32-bit instal‐
2734 lations).
2735
2736 If units is obtained from the GNU Win32 Project
2737 (http://gnuwin32.sourceforge.net/), the files are commonly in
2738 ‘C:\Program Files\GnuWin32\share\units’.
2739
2740 If the default units data file is not an absolute pathname, units will
2741 look for the file in the directory that contains the units program; if
2742 the file is not found there, units will look in a directory
2743 ../share/units relative to the directory with the units program.
2744
2745 You can determine the location of the files by running units --version.
2746 Running units --info will give you additional information about the
2747 files, how units will attempt to find them, and the status of the
2748 related environment variables.
2749
2751 The standard units data file is in Unicode, using UTF-8 encoding. Most
2752 definitions use only ASCII characters (i.e., code points U+0000 through
2753 U+007F); definitions using non-ASCII characters appear in blocks begin‐
2754 ning with ‘!utf8’ and ending with ‘!endutf8’.
2755
2756 The non-ASCII definitions are loaded only if the platform and the
2757 locale support UTF-8. Platform support is determined when units is
2758 compiled; the locale is checked at every invocation of units. To see
2759 if your version of units includes Unicode support, invoke the program
2760 with the ‘--version’ option.
2761
2762 When Unicode support is available, units checks every line within UTF-8
2763 blocks in all of the units data files for invalid or non-printing UTF-8
2764 sequences; if such sequences occur, units ignores the entire line. In
2765 addition to checking validity, units determines the display width of
2766 non-ASCII characters to ensure proper positioning of the pointer in
2767 some error messages and to align columns for the ‘search’ and ‘?’ com‐
2768 mands.
2769
2770 As of early 2019, Microsoft Windows provides limited support for UTF-8
2771 in console applications, and accordingly, units does not support Uni‐
2772 code on Windows. The UTF-16 and UTF-32 encodings are not supported on
2773 any platforms.
2774
2775 If Unicode support is available and definitions that contain non-ASCII
2776 UTF-8 characters are added to a units data file, those definitions
2777 should be enclosed within ‘!utf8’ ... ‘!endutf8’ to ensure that they
2778 are only loaded when Unicode support is available. As usual, the ‘!’
2779 must appear as the first character on the line. As discussed in Units
2780 Data Files, it’s usually best to put such definitions in supplemental
2781 data files linked by an ‘!include’ command or in a personal units data
2782 file.
2783
2784 When Unicode support is not available, units makes no assumptions about
2785 character encoding, except that characters in the range 00–7F hexadeci‐
2786 mal correspond to ASCII encoding. Non-ASCII characters are simply
2787 sequences of bytes, and have no special meanings; for definitions in
2788 supplementary units data files, you can use any encoding consistent
2789 with this assumption. For example, if you wish to use non-ASCII char‐
2790 acters in definitions when running units under Windows, you can use a
2791 character set such as Windows “ANSI” (code page 1252 in the US and
2792 Western Europe); if this is done, the console code page must be set to
2793 the same encoding for the characters to display properly. You can even
2794 use UTF-8, though some messages may be improperly aligned, and units
2795 will not detect invalid UTF-8 sequences. If you use UTF-8 encoding
2796 when Unicode support is not available, you should place any definitions
2797 with non-ASCII characters outside ‘!utf8’
2798
2799 Typeset material other than code examples usually uses the Unicode
2800 minus (U+2212) rather than the ASCII hyphen-minus operator (U+002D)
2801 used in units; the figure dash (U+2012) and en dash (U+2013) are also
2802 occasionally used. To allow such material to be copied and pasted for
2803 interactive use or in units data files, units converts these characters
2804 to U+002D before further processing. Because of this, none of these
2805 characters can appear in unit names.
2806
2808 If the readline package has been compiled in, then when units is used
2809 interactively, numerous command line editing features are available.
2810 To check if your version of units includes readline, invoke the program
2811 with the ‘--version’ option.
2812
2813 For complete information about readline, consult the documentation for
2814 the readline package. Without any configuration, units will allow
2815 editing in the style of emacs. Of particular use with units are the
2816 completion commands.
2817
2818 If you type a few characters and then hit ESC followed by ?, then units
2819 will display a list of all the units that start with the characters
2820 typed. For example, if you type metr and then request completion, you
2821 will see something like this:
2822
2823 You have: metr
2824 metre metriccup metrichorsepower metrictenth
2825 metretes metricfifth metricounce metricton
2826 metriccarat metricgrain metricquart metricyarncount
2827 You have: metr
2828
2829 If there is a unique way to complete a unit name, you can hit the TAB
2830 key and units will provide the rest of the unit name. If units beeps,
2831 it means that there is no unique completion. Pressing the TAB key a
2832 second time will print the list of all completions.
2833
2834 The readline library also keeps a history of the values you enter. You
2835 can move through this history using the up and down arrows. The his‐
2836 tory is saved to the file ‘.units_history’ in your home directory so
2837 that it will persist across multiple units invocations. If you wish to
2838 keep work for a certain project separate you can change the history
2839 filename using the ‘--history’ option. You could, for example, make an
2840 alias for units to units --history .units_history so that units would
2841 save separate history in the current directory. The length of each
2842 history file is limited to 5000 lines. Note also that if you run sev‐
2843 eral concurrent copies of units each one will save its new history to
2844 the history file upon exit.
2845
2847 The units program database includes currency exchange rates and prices
2848 for some precious metals. Of course, these values change over time,
2849 sometimes very rapidly, and units cannot provide real-time values. To
2850 update the exchange rates, run units_cur, which rewrites the file con‐
2851 taining the currency rates, typically ‘/var/lib/units/currency.units’
2852 or ‘/usr/local/com/units/currency.units’ on a Unix-like system or
2853 ‘C:Program Files (x86)\:GNU\:units\:definitions.units’ on a Windows
2854 system.
2855
2856 This program requires Python (https://www.python.org); either version 2
2857 or 3 will work. The program must be run with suitable permissions to
2858 write the file. To keep the rates updated automatically, run it using
2859 a cron job on a Unix-like system, or a similar scheduling program on a
2860 different system.
2861
2862 Reliable free sources of currency exchange rates have been annoyingly
2863 ephemeral. The program currently supports several sources:
2864
2865 • FloatRates (https://www/floatrates.com). The US dollar (‘USD’) is
2866 the default base currency. You can change the base currency with
2867 the ‘-b’ option described below. Allowable base currencies are
2868 listed on the FloatRates website. Exchange rates update daily.
2869
2870 • The European Central Bank (https://www.ecb.europa.eu). The base
2871 currency is always the euro (‘EUR’). Exchange rates update daily.
2872 This source offers a more limited list of currencies than the oth‐
2873 ers.
2874
2875 • Fixer (https://fixer.io). Registration for a free API key is
2876 required. With a free API key, base currency is the euro; exchange
2877 rates are updated hourly, the service has a limit of 1,000 API
2878 calls per month, and SSL encryption (https protocol) is not avail‐
2879 able. Most of these restrictions are eliminated or reduced with
2880 paid plans.
2881
2882 • open exchange rates (https://openexchangerates.org). Registration
2883 for a free API key is required. With a free API key, the base cur‐
2884 rency is the US dollar; exchange rates are updated hourly, and
2885 there is a limit of 1,000 API calls per month. Most of these
2886 restrictions are eliminated or reduced with paid plans.
2887
2888 The default source is FloatRates; you can select a different one using
2889 ‘-s’ option described below.
2890
2891 Precious metals pricing is obtained from Packetizer (www.packe‐
2892 tizer.com). This site updates once per day.
2893
2894 You invoke units_cur like this:
2895
2896 units_cur [options] [outfile]
2897
2898 By default, the output is written to the default currency file
2899 described above; this is usually what you want, because this is where
2900 units looks for the file. If you wish, you can specify a different
2901 filename on the command line and units_cur will write the data to that
2902 file. If you give ‘-’ for the file it will write to standard output.
2903
2904 The following options are available:
2905
2906 -h, --help
2907 Print a summary of the options for units_cur.
2908
2909 -V, --version
2910 Print the units_cur version number.
2911
2912 -v, --verbose
2913 Give slightly more verbose output when attempting to update cur‐
2914 rency exchange rates.
2915
2916 -s source, --source source
2917 Specify the source for currency exchange rates; currently sup‐
2918 ported values are ‘floatrates’ (for FloatRates), ‘eubank’ (for
2919 the European Central Bank), ‘fixer’ (for Fixer), and
2920 ‘openexchangerates’ (for open exchange rates); the last two
2921 require an API key to be given with the ‘-k’ option.
2922
2923 -b base, --base base
2924 Set the base currency (when allowed by the site providing the
2925 data). base should be a 3-letter ISO currency code, e.g.,
2926 ‘USD’. The specified currency will be the primitive currency
2927 unit used by units. You may find it convenient to specify your
2928 local currency. Conversions may be more accurate and you will
2929 be able to convert to your currency by simply hitting Enter at
2930 the ‘You want:’ prompt. This option is ignored if the source
2931 does not allow specifying the base currency. (Currently only
2932 floatrates supports this option.)
2933
2934 -k key, --key key
2935 Set the API key to key for sources that require it.
2936
2938 unit definition
2939 Define a regular unit.
2940
2941 prefix- definition
2942 Define a prefix.
2943
2944 funcname(var) noerror units=[in-units,out-units] domain=[x1,x2]
2945 range=[y1,y2] definition(var) ; inverse(funcname)
2946 Define a nonlinear unit or unit function. The four optional
2947 keywords noerror, units=, range= and domain= can appear in any
2948 order. The definition of the inverse is optional.
2949
2950 tabname[out-units] noerror pair-list
2951 Define a piecewise linear unit. The pair list gives the points
2952 on the table listed in ascending order. The noerror keyword is
2953 optional.
2954
2955 !endlocale
2956 End a block of definitions beginning with ‘!locale’
2957
2958 !endutf8
2959 End a block of definitions begun with ‘!utf8’
2960
2961 !endvar
2962 End a block of definitions begun with ‘!var’ or ‘!varnot’
2963
2964 !include file
2965 Include the specified file.
2966
2967 !locale value
2968 Load the following definitions only of the locale is set to
2969 value.
2970
2971 !message text
2972 Display text when the database is read unless the quiet option
2973 (‘-q’) is enabled. If you omit text, then units will display a
2974 blank line. Messages will also appear in the log file.
2975
2976 !prompt text
2977 Prefix the ‘You have:’ prompt with the specified text. If you
2978 omit text, then any existing prefix is canceled.
2979
2980 !set variable value
2981 Sets the environment variable, variable, to the specified value
2982 only if it is not already set.
2983
2984 !unitlist alias definition
2985 Define a unit list alias.
2986
2987 !utf8 Load the following definitions only if units is running with
2988 UTF-8 enabled.
2989
2990 !var envar value-list
2991 Load the block of definitions that follows only if the environ‐
2992 ment variable envar is set to one of the values listed in the
2993 space-separated value list. If envar is not set, units prints
2994 an error message and ignores the block of definitions.
2995
2996 !varnot envar value-list
2997 Load the block of definitions that follows only if the environ‐
2998 ment variable envar is set to value that is not listed in the
2999 space-separated value list. If envar is not set, units prints
3000 an error message and ignores the block of definitions.
3001
3003 /usr/share/units/definitions.units — the standard units data file
3004
3006 units was written by Adrian Mariano
3007
3008
3009
3010 22 September 2020 UNITS(1)