1UNITS(1) General Commands Manual UNITS(1)
2
3
4
6 units - unit conversion program
7
9 The `units' program converts quantities expressed in various scales to
10 their equivalents in other scales. The `units' program can handle mul‐
11 tiplicative scale changes as well as nonlinear conversions such as
12 Fahrenheit to Celsius. Temperature conversions require a special syn‐
13 tax. See the examples below.
14
15 The units are defined in an external data file. You can use the exten‐
16 sive data file that comes with this program, or you can provide your
17 own data file to suit your needs.
18
19 You can use the program interactively with prompts, or you can use it
20 from the command line.
21
23 To invoke units for interactive use, type `units' at your shell prompt.
24 The program will print something like this:
25
26 2131 units, 53 prefixes, 24 nonlinear units
27
28 You have:
29
30 At the `You have:' prompt, type the quantity and units that you are
31 converting from. For example, if you want to convert ten meters to
32 feet, type `10 meters'. Next, `units' will print `You want:'. You
33 should type the type of units you want to convert to. To convert to
34 feet, you would type `feet'. Note that if the readline library was
35 compiled in then the tab key can be used to complete unit names. See
36 Readline support, for more information about readline.
37
38 The answer will be displayed in two ways. The first line of output,
39 which is marked with a `*' to indicate multiplication, gives the result
40 of the conversion you have asked for. The second line of output, which
41 is marked with a `/' to indicate division, gives the inverse of the
42 conversion factor. If you convert 10 meters to feet, `units' will
43 print
44
45 * 32.808399
46 / 0.03048
47
48 which tells you that 10 meters equals about 32.8 feet. The second num‐
49 ber gives the conversion in the opposite direction. In this case, it
50 tells you that 1 foot is equal to about 0.03 dekameters since the
51 dekameter is 10 meters. It also tells you that 1/32.8 is about .03.
52
53 The `units' program prints the inverse because sometimes it is a more
54 convenient number. In the example above, for example, the inverse
55 value is an exact conversion: a foot is exactly .03048 dekameters. But
56 the number given the other direction is inexact.
57
58 If you try to convert grains to pounds, you will see the following:
59
60 You have: grains
61 You want: pounds
62 * 0.00014285714
63 / 7000
64
65 From the second line of the output you can immediately see that a grain
66 is equal to a seven thousandth of a pound. This is not so obvious from
67 the first line of the output. If you find the output format confus‐
68 ing, try using the `--verbose' option:
69
70 You have: grain
71 You want: aeginamina
72 grain = 0.00010416667 aeginamina
73 grain = (1 / 9600) aeginamina
74
75 If you request a conversion between units which measure reciprocal
76 dimensions, then `units' will display the conversion results with an
77 extra note indicating that reciprocal conversion has been done:
78
79 You have: 6 ohms
80 You want: siemens
81 reciprocal conversion
82 * 0.16666667
83 / 6
84
85 Reciprocal conversion can be suppressed by using the `--strict' option.
86 As usual, use the `--verbose' option to get more comprehensible output:
87
88 You have: tex
89 You want: typp
90 reciprocal conversion
91 1 / tex = 496.05465 typp
92 1 / tex = (1 / 0.0020159069) typp
93
94 You have: 20 mph
95 You want: sec/mile
96 reciprocal conversion
97 1 / 20 mph = 180 sec/mile
98 1 / 20 mph = (1 / 0.0055555556) sec/mile
99
100 If you enter incompatible unit types, the `units' program will print a
101 message indicating that the units are not conformable and it will dis‐
102 play the reduced form for each unit:
103
104 You have: ergs/hour
105 You want: fathoms kg^2 / day
106 conformability error
107 2.7777778e-11 kg m^2 / sec^3
108 2.1166667e-05 kg^2 m / sec
109
110 If you only want to find the reduced form or definition of a unit, sim‐
111 ply press return at the `You want:' prompt. Here is an example:
112
113 You have: jansky
114 You want:
115 Definition: fluxunit = 1e-26 W/m^2 Hz = 1e-26 kg / s^2
116
117 The output from `units' indicates that the jansky is defined to be
118 equal to a fluxunit which in turn is defined to be a certain combina‐
119 tion of watts, meters, and hertz. The fully reduced (and in this case
120 somewhat more cryptic) form appears on the far right.
121
122 Some named units are treated as dimensionless in some situations.
123 These include the radian and steradian. These units will be treated as
124 equal to 1 in units conversions. Power is equal to torque times angu‐
125 lar velocity. This conversion can only be performed if the radian is
126 dimensionless.
127
128 You have: (14 ft lbf) (12 radians/sec)
129 You want: watts
130 * 227.77742
131 / 0.0043902509
132
133 Note that named dimensionaless units are not treated as dimensionless
134 in other contexts. They cannot be used as exponents so for example,
135 `meter^radian' is not allowed.
136
137 If you want a list of options you can type `?' at the `You want:'
138 prompt. The program will display a list of named units which are con‐
139 formable with the unit that you entered at the `You have:' prompt
140 above. Note that conformable unit combinations will not appear on this
141 list.
142
143 Typing `help' at either prompt displays a short help message. You can
144 also type `help' followed by a unit name. This will invoke a pager on
145 the units data base at the point where that unit is defined. You can
146 read the definition and comments that may give more details or histori‐
147 cal information about the unit.
148
150 The `units' program can perform units conversions non-interactively
151 from the command line. To do this, type the command, type the original
152 units expression, and type the new units you want. You will probably
153 need to protect the units expressions from interpretation by the shell
154 using single quote characters.
155
156 If you type
157
158 units '2 liters' 'quarts'
159
160 then `units' will print
161
162 * 2.1133764
163 / 0.47317647
164
165 and then exit. The output tells you that 2 liters is about 2.1 quarts,
166 or alternatively that a quart is about 0.47 times 2 liters.
167
168 If the conversion is successful, then `units' will return success (0)
169 to the calling environment. If `units' is given non-conformable units
170 to convert, it will print a message giving the reduced form of each
171 unit and it will return failure (nonzero) to the calling environment.
172
173 When `units' is invoked with only one argument, it will print out the
174 definition of the specified unit. It will return failure if the unit
175 is not defined and success if the unit is defined.
176
178 In order to enter more complicated units or fractions, you will need to
179 use operations such as powers, products and division. Powers of units
180 can be specified using the `^' character as shown in the following
181 example, or by simple concatenation: `cm3' is equivalent to `cm^3'. If
182 the exponent is more than one digit, the `^' is required. An exponent
183 like `2^3^2' is evaluated right to left. The `^' operator has the sec‐
184 ond highest precedence.
185
186 You have: cm^3
187 You want: gallons
188 * 0.00026417205
189 / 3785.4118
190
191 You have: arabicfoot * arabictradepound * force
192 You want: ft lbf
193 * 0.7296
194 / 1.370614
195
196 Multiplication of units can be specified by using spaces, or an aster‐
197 isk (`*'). If `units' is invoked with the `--product' option then the
198 hyphen (`-') also acts as a multiplication operator. Division of units
199 is indicated by the slash (`/') or by `per'.
200
201 You have: furlongs per fortnight
202 You want: m/s
203 * 0.00016630986
204 / 6012.8727
205
206 Multiplication has a higher precedence than division and is evaluated
207 left to right, so `m/s * s/day' is equivalent to `m / s s day' and has
208 dimensions of length per time cubed. Similarly, `1/2 meter' refers to
209 a unit of reciprocal length equivalent to .5/meter, which is probably
210 not what you would intend if you entered that expression. You can
211 indicate division of numbers with the vertical dash (`|'). This opera‐
212 tor has the highest precedence so the square root of two thirds could
213 be written `2|3^1|2'.
214
215 You have: 1|2 inch
216 You want: cm
217 * 1.27
218 / 0.78740157
219
220 Parentheses can be used for grouping as desired.
221
222 You have: (1/2) kg / (kg/meter)
223 You want: league
224 * 0.00010356166
225 / 9656.0833
226
227 Prefixes are defined separately from base units. In order to get cen‐
228 timeters, the units database defines `centi-' and `c-' as prefixes.
229 Prefixes can appear alone with no unit following them. An exponent
230 applies only to the immediately preceding unit and its prefix so that
231 `cm^3' or `centimeter^3' refer to cubic centimeters but `centi*meter^3'
232 refers to hundredths of cubic meters. Only one prefix is permitted per
233 unit, so `micromicrofarad' will fail, but `micro*microfarad' will work,
234 as will `micro microfarad'..
235
236 For `units', numbers are just another kind of unit. They can appear as
237 many times as you like and in any order in a unit expression. For
238 example, to find the volume of a box which is 2 ft by 3 ft by 12 ft in
239 steres, you could do the following:
240
241 You have: 2 ft 3 ft 12 ft
242 You want: stere
243 * 2.038813
244 / 0.49048148
245
246 You have: $ 5 / yard
247 You want: cents / inch
248 * 13.888889
249 / 0.072
250
251 And the second example shows how the dollar sign in the units conver‐
252 sion can precede the five. Be careful: `units' will interpret `$5'
253 with no space as equivalent to dollars^5.
254
255 Outside of the SI system, it is often desirable to add values of dif‐
256 ferent units together. You may also wish to use `units' as a calcula‐
257 tor that keeps track of units. Sums of conformable units are written
258 with the `+' character.
259
260 You have: 2 hours + 23 minutes + 32 seconds
261 You want: seconds
262 * 8612
263 / 0.00011611705
264
265 You have: 12 ft + 3 in
266 You want: cm
267 * 373.38
268 / 0.0026782366
269
270 You have: 2 btu + 450 ft lbf
271 You want: btu
272 * 2.5782804
273 / 0.38785542
274
275 The expressions which are added together must reduce to identical
276 expressions in primitive units, or an error message will be displayed:
277
278 You have: 12 printerspoint + 4 heredium
279 ^
280 Illegal sum of non-conformable units
281
282 Historically `-' has been used for products of units, which complicates
283 its iterpretation in `units'. Because `units' provides several other
284 ways to obtain unit products, and because `-' is a subtraction operator
285 in general algebraic expressions, `units' treats the binary `-' as a
286 subtraction operator by default. This behavior can be altered using
287 the `--product' option which causes `units' to treat the binary `-'
288 operator as a product operator. Note that when `-' is a multiplication
289 operator it has the same precedence as `*', but when `-' is a subtrac‐
290 tion operator it has the lower precedence as the addition operator.
291
292 When `-' is used as a unary operator it negates its operand. Regard‐
293 less of the `units' options, if `-' appears after `(' or after `+' then
294 it will act as a negation operator. So you can always compute 20
295 degrees minus 12 minutes by entering `20 degrees + -12 arcmin'. You
296 must use this construction when you define new units because you cannot
297 know what options will be in force when your definition is processed.
298
299 The `+' character sometimes appears in exponents like `3.43e+8'. This
300 leads to an ambiguity in an expression like `3e+2 yC'. The unit `e' is
301 a small unit of charge, so this can be regarded as equivalent to
302 `(3e+2) yC' or `(3 e)+(2 yC)'. This ambiguity is resolved by always
303 interpreting `+' as part of an exponent if possible.
304
305 Several built in functions are provided: `sin', `cos', `tan', `ln',
306 `log', `log2', `exp', `acos', `atan' and `asin'. The `sin', `cos', and
307 `tan' functions require either a dimensionless argument or an argument
308 with dimensions of angle.
309
310 You have: sin(30 degrees)
311 You want:
312 Definition: 0.5
313
314 You have: sin(pi/2)
315 You want:
316 Definition: 1
317
318 You have: sin(3 kg)
319 ^
320 Unit not dimensionless
321
322 The other functions on the list require dimensionless arguments. The
323 inverse trigonometric functions return arguments with dimensions of
324 angle.
325
326 If you wish to take roots of units, you may use the `sqrt' or `cube‐
327 root' functions. These functions require that the argument have the
328 appropriate root. Higher roots can be obtained by using fractional
329 exponents:
330
331 You have: sqrt(acre)
332 You want: feet
333 * 208.71074
334 / 0.0047913202
335
336 You have: (400 W/m^2 / stefanboltzmann)^(1/4)
337 You have:
338 Definition: 289.80882 K
339
340 You have: cuberoot(hectare)
341 ^
342 Unit not a root
343
344 Nonlinear units are represented using functional notation. They make
345 possible nonlinear unit conversions such temperature. This is differ‐
346 ent from the linear units that convert temperature differences. Note
347 the difference below. The absolute temperature conversions are handled
348 by units starting with `temp', and you must use functional notation.
349 The temperature differences are done using units starting with `deg'
350 and they do not require functional notation.
351
352 You have: tempF(45)
353 You want: tempC
354 7.2222222
355
356 You have: 45 degF
357 You want: degC
358 * 25
359 / 0.04
360
361 Think of `tempF(x)' not as a function but as a notation which indicates
362 that `x' should have units of `tempF' attached to it. See Nonlinear
363 units. The first conversion shows that if it's 45 degrees Fahrehneit
364 outside it's 7.2 degrees Celsius. The second conversions indicates
365 that a change of 45 degrees Fahrenheit corresponds to a change of 25
366 degrees Celsius.
367
368 Some other examples of nonlinears units are ring size and wire gauge.
369 There are numerous different gauges and ring sizes. See the units
370 database for more details. Note that wire gauges with multiple zeroes
371 are signified using negative numbers where two zeroes is -1. Alterna‐
372 tively, you can use the synonyms `g00', `g000', and so on that are
373 defined in the units database.
374
375 You have: wiregauge(11)
376 You want: inches
377 * 0.090742002
378 / 11.020255
379
380 You have: brwiregauge(g00)
381 You want: inches
382 * 0.348
383 / 2.8735632
384
385 You have: 1 mm
386 You want: wiregauge
387 18.201919
388
390 You invoke `units' like this:
391
392 units [OPTIONS] [FROM-UNIT [TO-UNIT]]
393
394 If the FROM-UNIT and TO-UNIT are omitted, then the program will use
395 interactive prompts to determine which conversions to perform. See
396 Interactive use. If both FROM-UNIT and TO-UNIT are given, `units' will
397 print the result of that single conversion and then exit. If only
398 FROM-UNIT appears on the command line, `units' will display the defini‐
399 tion of that unit and exit. Units specified on the command line will
400 need to be quoted to protect them from shell interpretation and to
401 group them into two arguments. See Command line use.
402
403 The following options allow you to read in an alternative units file,
404 check your units file, or change the output format:
405
406 -c, --check
407 Check that all units and prefixes defined in the units data file
408 reduce to primitive units. Print a list of all units that can‐
409 not be reduced. Also display some other diagnostics about sus‐
410 picious definitions in the units data file. Note that only def‐
411 initions active in the current locale are checked.
412
413 --check-verbose
414 Like the `-check' option, this option prints a list of units
415 that cannot be reduced. But to help find unit definitions that
416 cause endless loops, it lists the units as they are checked. If
417 `units' hangs, then the last unit to be printed has a bad defi‐
418 nition. Note that only definitions active in the current locale
419 are checked.
420
421 -o format, --output-format format
422 Use the specified format for numeric output. Format is the same
423 as that for the printf function in the ANSI C standard. For
424 example, if you want more precision you might use `-o %.15g'.
425
426 -f filename, --file filename
427 Instruct `units' to load the units file `filename'. If `file‐
428 name' is the empty string (`-f "') then the default units file
429 will be loaded. This enables you to load the default file plus
430 a personal units file. Up to 25 units files may be specified on
431 the command line. This option overrides the `UNITSFILE' envi‐
432 ronment variable.
433
434 -h, --help
435 Print out a summary of the options for `units'.
436
437 -m, --minus
438 Causes `-' to be interpreted as a subtraction operator. This is
439 usually the default behavior.
440
441 -p, --product
442 Causes `-' to be interpreted as a multiplication operator when
443 it has two operands. It will as a negation operator when it has
444 only one operand: `(-3)'. Note that by default `-' is treated
445 as a subtraction operator.
446
447 , --compact Give compact output featuring only the conversion factor.
448 This turns off the `--verbose' option.
449
450 -q, --quiet, --silent
451 Suppress prompting of the user for units and the display of sta‐
452 tistics about the number of units loaded.
453
454 -s, --strict
455 Suppress conversion of units to their reciprocal units. For
456 example, `units' will normally convert hertz to seconds because
457 these units are reciprocals of each other. The strict option
458 requires that units be strictly conformable to perform a conver‐
459 sion, and will give an error if you attempt to convert hertz to
460 seconds.
461
462 -1, --one-line
463 Give only one line of output (the forward conversion). Do not
464 print the reverse conversion. Note that if a reciprocal conver‐
465 sion is performed then `units' will print still print the
466 "reciprocal conversion" line.
467
468 -t, --terse
469 Give terse output when converting units. This option can be
470 used when calling `units' from another program so that the out‐
471 put is easy to parse. This option has the combined effect of
472 these options: `--strict' `--quiet' `--one-line' `--compact'.
473
474 -v, --verbose
475 Give slightly more verbose output when converting units. When
476 combined with the `-c' option this gives the same effect as
477 `--check-verbose'.
478
479 -V, --version
480 Print program version number, tell whether the readline library
481 has been included, and give the location of the default units
482 data file.
483
485 The conversion information is read from a units data file which is
486 called `units.dat' and is probably located in the `/usr/local/share'
487 directory. If you invoke `units' with the `-V' option, it will print
488 the location of this file. The default file includes definitions for
489 all familiar units, abbreviations and metric prefixes. It also
490 includes many obscure or archaic units.
491
492 Many constants of nature are defined, including these:
493
494 pi ratio of circumference to diameter
495 c speed of light
496 e charge on an electron
497 force acceleration of gravity
498 mole Avogadro's number
499 water pressure per unit height of water
500 Hg pressure per unit height of mercury
501 au astronomical unit
502 k Boltzman's constant
503 mu0 permeability of vacuum
504 epsilon0 permitivity of vacuum
505 G gravitational constant
506 mach speed of sound
507
508 The database includes atomic masses for all of the elements and numer‐
509 ous other constants. Also included are the densities of various ingre‐
510 dients used in baking so that `2 cups flour_sifted' can be converted to
511 `grams'. This is not an exhaustive list. Consult the units data file
512 to see the complete list, or to see the definitions that are used.
513
514 The unit `pound' is a unit of mass. To get force, multiply by the
515 force conversion unit `force' or use the shorthand `lbf'. (Note that
516 `g' is already taken as the standard abbreviation for the gram.) The
517 unit `ounce' is also a unit of mass. The fluid ounce is `fluidounce'
518 or `floz'. British capacity units that differ from their US counter‐
519 parts, such as the British Imperial gallon, are prefixed with `br'.
520 Currency is prefixed with its country name: `belgiumfranc', `britain‐
521 pound'.
522
523 The US Survey foot, yard, and mile can be obtained by using the `US'
524 prefix. These units differ slightly from the international length
525 units. They were in general use until 1959, and are still used for
526 geographic surveys. The acre is officially defined in terms of the US
527 Survey foot. If you want an acre defined according to the interna‐
528 tional foot, use `intacre'. The difference between these units is
529 about 4 parts per million. The British also used a slightly different
530 length measure before 1959. These can be obtained with the prefix
531 `UK'.
532
533 When searching for a unit, if the specified string does not appear
534 exactly as a unit name, then the `units' program will try to remove a
535 trailing `s' or a trailing `es'. If that fails, `units' will check for
536 a prefix. All of the standard metric prefixes are defined.
537
538 To find out what units and prefixes are available, read the standard
539 units data file.
540
542 All of the units and prefixes that `units' can convert are defined in
543 the units data file. If you want to add your own units, you can supply
544 your own file.
545
546 A unit is specified on a single line by giving its name and an equiva‐
547 lence. Comments start with a `#' character, which can appear anywhere
548 in a line. The backslash character (`´) acts as a continuation charac‐
549 ter if it appears as the last character on a line, making it possible
550 to spread definitions out over several lines if desired. A file can be
551 included by giving the command `!include' followed by the file's name.
552 The file will be sought in the same directory as the parent file unless
553 a full path is given.
554
555 Unit names must not contain any of the operator characters `+', `-',
556 `*', `/', `|', `^' or the parentheses. They cannot begin with a digit
557 or a decimal point (`.'), nor can they end with a digit (except for
558 zero). Be careful to define new units in terms of old ones so that a
559 reduction leads to the primitive units, which are marked with `!' char‐
560 acters. Dimensionless units are indicated by using the string `!dimen‐
561 sionless' for the unit definition.
562
563 When adding new units, be sure to use the `-c' option to check that the
564 new units reduce properly. If you create a loop in the units defini‐
565 tions, then `units' will hang when invoked with the `-c' options. You
566 will need to use the `--check-verbose' option which prints out each
567 unit as it checks them. The program will still hang, but the last unit
568 printed will be the unit which caused the infinite loop.
569
570 If you define any units which contain `+' characters, carefully check
571 them because the `-c' option will not catch non-conformable sums. Be
572 careful with the `-' operator as well. When used as a binary operator,
573 the `-' character can perform addition or multiplication depending on
574 the options used to invoke `units'. To ensure consistent behavior use
575 `-' only as a unary negation operator when writing units definitions.
576 To multiply two units leave a space or use the `*' operator. To com‐
577 pute the difference of `foo' and `bar' write `foo+(-bar)' or even
578 `foo+-bar'.
579
580 Here is an example of a short units file that defines some basic units:
581
582 m ! # The meter is a primitive unit
583 sec ! # The second is a primitive unit
584 rad !dimensionless# The second is a primitive unit
585 micro- 1e-6 # Define a prefix
586 minute 60 sec # A minute is 60 seconds
587 hour 60 min # An hour is 60 minutes
588 inch 0.0254 m # Inch defined in terms of meters
589 ft 12 inches # The foot defined in terms of inches
590 mile 5280 ft # And the mile
591
592
593 A unit which ends with a `-' character is a prefix. If a prefix defi‐
594 nition contains any `/' characters, be sure they are protected by
595 parentheses. If you define `half- 1/2' then `halfmeter' would be
596 equivalent to `1 / 2 meter'.
597
599 Some units conversions of interest are nonlinear; for example, tempera‐
600 ture conversions between the Fahrenheit and Celsius scales cannot be
601 done by simply multiplying by conversions factors.
602
603 When you give a linear unit definition such as `inch 2.54 cm' you are
604 providing information that `units' uses to convert values in inches
605 into primitive units of meters. For nonlinear units, you give a func‐
606 tional definition that provides the same information.
607
608 Nonlinear units are represented using a functional notation. It is
609 best to regard this notation not as a function call but as a way of
610 adding units to a number, much the same way that writing a linear unit
611 name after a number adds units to that number. Internally, nonlinear
612 units are defined by a pair of functions which convert to and from lin‐
613 ear units in the data file, so that an eventual conversion to primitive
614 units is possible.
615
616 Here is an example nonlinear unit definition:
617
618 tempF(x) [1;K] (x+(-32)) degF + stdtemp ; (tempF+(-stdtemp))/degF + 32
619
620 A nonlinear unit definition comprises a unit name, a dummy parameter
621 name, two functions, and two corresponding units. The functions tell
622 `units' how to convert to and from the new unit. In order to produce
623 valid results, the arguments of these functions need to have the cor‐
624 rect dimensions. To facilitate error checking, you may specify the
625 dimensions.
626
627 The definition begins with the unit name followed immediately (with no
628 spaces) by a `(' character. In parentheses is the name of the parame‐
629 ter. Next is an optional specification of the units required by the
630 functions in this definition. In the example above, the `tempF' func‐
631 tion requires an input argument conformable with `1'. For normal non‐
632 linear units definitions the forward function will always take a dimen‐
633 sionless argument. The inverse function requires an input argument
634 conformable with `K'. In general the inverse function will need units
635 that match the quantity measured by your nonlinear unit. The sole pur‐
636 pose of the expression in brackets to enable `units' to perform error
637 checking on function arguments.
638
639 Next the function definitions appear. In the example above, the
640 `tempF' function is defined by
641
642 tempF(x) = (x+(-32)) degF + stdtemp
643
644 This gives a rule for converting `x' in the units `tempF' to linear
645 units of absolute temperature, which makes it possible to convert from
646 tempF to other units.
647
648 In order to make conversions to Fahrenheit possible, you must give a
649 rule for the inverse conversions. The inverse will be `x(tempF)' and
650 its definition appears after a `;' character. In our example, the
651 inverse is
652
653 x(tempF) = (tempF+(-stdtemp))/degF + 32
654
655 This inverse definition takes an absolute temperature as its argument
656 and converts it to the Fahrenheit temperature. The inverse can be
657 omitted by leaving out the `;' character, but then conversions to the
658 unit will be impossible. If the inverse is omitted then the `--check'
659 option will display a warning. It is up to you to calculate and enter
660 the correct inverse function to obtain proper conversions. The
661 `--check' option tests the inverse at one point and print an error if
662 it is not valid there, but this is not a guarantee that your inverse is
663 correct.
664
665 If you wish to make synonyms for nonlinear units, you still need to
666 define both the forward and inverse functions. Inverse functions can
667 be obtained using the `~' operator. So to create a synonym for `tempF'
668 you could write
669
670 fahrenheit(x) [1;K] tempF(x); ~tempF(fahrenheit)
671
672 You may occasionally wish to define a function that operates on units.
673 This can be done using a nonlinear unit definition. For example, the
674 definition below provides conversion between radius and the area of a
675 circle. Note that this definition requires a length as input and pro‐
676 duces an area as output, as indicated by the specification in brackets.
677
678 circlearea(r) [m;m^2] pi r^2 ; sqrt(circlearea/pi)
679
680 Sometimes you may be interested in a piecewise linear unit such as many
681 wire gauges. Piecewise linear units can be defined by specifying con‐
682 versions to linear units on a list of points. Conversion at other
683 points will be done by linear interpolation. A partial definition of
684 zinc gauge is
685
686 zincgauge[in] 1 0.002, 10 0.02, 15 0.04, 19 0.06, 23 0.1
687
688 In this example, `zincgauge' is the name of the piecewise linear unit.
689 The definition of such a unit is indicated by the embedded `[' charac‐
690 ter. After the bracket, you should indicate the units to be attached
691 to the numbers in the table. No spaces can appear before the `]' char‐
692 acter, so a definition like `foo[kg meters]' is illegal; instead write
693 `foo[kg*meters]'. The definition of the unit consists of a list of
694 pairs optionally separated by commas. This list defines a function for
695 converting from the piecewise linear unit to linear units. The first
696 item in each pair is the function argument; the second item is the
697 value of the function at that argument (in the units specified in
698 brackets). In this example, we define `zincgauge' at five points. For
699 example, we set `zincgauge(1)' equal to `0.002 in'. Definitions like
700 this may be more readable if written using continuation characters
701 as
702
703 zincgauge[in] \
704 1 0.002 \
705 10 0.02 \
706 15 0.04 \
707 19 0.06 \
708 23 0.1
709
710 With the preceeding definition, the following conversion can be per‐
711 formed:
712
713 You have: zincgauge(10)
714 You want: in
715 * 0.02
716 / 50
717 You have: .01 inch
718 You want: zincgauge
719 5
720
721 If you define a piecewise linear unit that is not strictly monotonic,
722 then the inverse will not be well defined. If the inverse is requested
723 for such a unit, `units' will return the smallest inverse. The
724 `--check' option will print a warning if a non-monotonic piecewise lin‐
725 ear unit is encountered.
726
728 Some units have different values in different locations. The localiza‐
729 tion feature accomodates this by allowing the units database to specify
730 region dependent definitions. A locale region in the units database
731 begins with `!locale' followed by the name of the locale. The leading
732 `!' must appear in the first column of the units database. The locale
733 region is terminated by `!endlocale'. The following example shows how
734 to define a couple units in a locale.
735
736 !locale en_GB
737 ton brton
738 gallon brgallon
739 !endlocale
740
741 The current locale is specified by the `LOCALE' environment variable.
742 Note that the `-c' option only checks the definitions which are active
743 for the current locale.
744
746 The `units' programs uses the following environment variables.
747
748 LOCALE Specifies the locale. The default is `en_US'. Sections of the
749 units database are specific to certain locales.
750
751 PAGER Specifies the pager to use for help and for displaying the con‐
752 formable units. The help function browses the units database
753 and calls the pager using the `+nn' syntax for specifying a line
754 number. The default pager is `more', but `less', `emacs', or
755 `vi' are possible alternatives.
756
757 UNITSFILE
758 Specifies the units database file to use (instead of the
759 default). This will be overridden by the `-f' option. Note that
760 you can only specify a single units database using this environ‐
761 ment variable.
762
764 If the `readline' package has been compiled in, then when `units' is
765 used interactively, numerous command line editing features are avail‐
766 able. To check if your version of `units' includes the readline,
767 invoke the program with the `--version' option.
768
769 For complete information about readline, consult the documentation for
770 the readline package. Without any configuration, `units' will allow
771 editing in the style of emacs. Of particular use with `units' are the
772 completion commands.
773
774 If you type a few characters and then hit `ESC' followed by the `?' key
775 then `units' will display a list of all the units which start with the
776 characters typed. For example, if you type `metr' and then request
777 completion, you will see something like this:
778
779 You have: metr
780 metre metriccup metrichorsepower metrictenth
781 metretes metricfifth metricounce metricton
782 metriccarat metricgrain metricquart metricyarncount
783 You have: metr
784
785 If there is a unique way to complete a unitname, you can hit the tab
786 key and `units' will provide the rest of the unit name. If `units'
787 beeps, it means that there is no unique completion. Pressing the tab
788 key a second time will print the list of all completions.
789
791 /usr/share/units.dat - the standard units data file
792
794 Adrian Mariano (adrian@cam.cornell.edu)
795
796
797
798 12 Dec 2004 UNITS(1)