This is a modification of document Unit Conversion, edition 1.89, by Adrian Mariano. It describes a Java imitation of GNU program units, version 1.87. Changes to the document reflect differences between the original program and its Java imitation. The original program was written in C by Adrian Mariano. The Java imitation was written by Roman R Redziejowski, who is also reponsible for changes to the document.
Copyright © 1996, 1997, 1999, 2001, 2002, 2004, 2005, 2006, 2007, 2009 by Free Software Foundation, Inc. The author gives unlimited permission to copy, translate and/or distribute this document, with or without modifications, as long as this notice is preserved.
The program documented here is free software; you can redistribute and/or modify
it under the terms of the
GNU Library General Public License
as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This document describes a Java imitation of GNU program units. The 'units' below always means that imitation.
The units program converts quantities expressed in various scales to their equivalents in other scales. It can handle multiplicative scale changes as well as nonlinear conversions such as Fahrenheit to Celsius1. Temperature conversions require a special syntax.
The units are defined in an external data file. You can use the extensive data file that comes with this program, or you can provide your own data file to suit your needs.
You can use the program interactively from command prompt, from graphic interface, or as an applet. You can also invoke it non-interactively from command line.
Unless you want to use the program as an applet, you need to download the Java archive (JAR) file that contains the program and the data file. You can save the JAR in any directory of your choice, and give it any name compatible with your file system. The following assumes that you saved the JAR file under the name jarfile. It also assumes that you have a Java Runtime Environment (JRE) version 1.5.0 or later that is invoked by typing java at your shell prompt.
1But Fahrenheit to Celsius is linear, you insist. Not so. A transformation T is linear if T(x+y)=T(x)+T(y) and this fails for T(x)=ax+b. This transformation is affine, but not linear.
To invoke units for interactive use, type
java -jar jarfile -iat your shell prompt. The program will print something like this:
2192 units, 71 prefixes, 32 nonlinear units You have:
At 'You have:' prompt, type the quantity and units that you are converting from. For example, if you want to convert ten meters to feet, type 10 meters. Next, units will print 'You want:'. You should enter the type of units you want to convert to. To convert to feet, you would type feet.
The answer will be displayed in two ways. The first line of output, which is marked with a '*' to indicate multiplication, gives the result of the conversion you have asked for. The second line of output, which is marked with a '/' to indicate division, gives the inverse of the conversion factor. If you convert 10 meters to feet, units will print
* 32.8084
/ 0.03048
which tells you that 10 meters equals about 32.8 feet. The second number gives the conversion in the opposite direction. In this case, it tells you that 1 foot is equal to about 0.03 dekameters since the dekameter is 10 meters. It also tells you that 1/32.8 is about .03.
The units program prints the inverse because sometimes it is a more convenient number. In the example above, for example, the inverse value is an exact conversion: a foot is exactly .03048 dekameters. But the number given the other direction is inexact.
If you try to convert grains to pounds, you will see the following:
You have: grains
You want: pounds
* 1.428571E-4
/ 7000.0
From the second line of the output you can immediately see that a grain is equal to a seven thousandth of a pound. This is not so obvious from the first line of the output. If you find the output format confusing, try using the -v ('verbose') option:
You have: grain
You want: aeginamina
grain = 1.0416667E-4 aeginamina
grain = (1 / 9600) aeginamina
If you request a conversion between units which measure reciprocal dimensions, then units will display the conversion results with an extra note indicating that reciprocal conversion has been done:
You have: 6 ohms
You want: siemens
reciprocal conversion
* 0.16666667
/ 6
Reciprocal conversion can be suppressed by using the -s ('strict') option. As usual, use the -v option to get more comprehensible output:
You have: tex
You want: typp
reciprocal conversion
1 / tex = 496.05465 typp
1 / tex = (1 / 0.0020159069) typp
You have: 20 mph
You want: sec/mile
reciprocal conversion
1 / 20 mph = 180 sec/mile
1 / 20 mph = (1 / 0.0055555557) sec/mile
If you enter incompatible unit types, the units program will print a message indicating that the units are not conformable and it will display the reduced form for each unit:
You have: ergs/hour
You want: fathoms kg^2 / day
conformability error
2.7777778E-11 kg m^2 / s^3
2.1166667E-05 kg^2 m / s
If you only want to find the reduced form or definition of a unit, simply press return at the 'You want:' prompt. Here is an example:
You have: jansky
You want:
Definition: fluxunit = 1e-26 W/m^2 Hz = 1e-26 kg / s^2
The output from units indicates that the jansky is defined to be equal to a fluxunit which in turn is defined to be a certain combination of watts, meters, and hertz. The fully reduced (and in this case somewhat more cryptic) form appears on the far right.
Some named units are treated as dimensionless in some situations. These include the radian and steradian. These units will be treated as equal to 1 in units conversions. Power is equal to torque times angular velocity. This conversion can only be performed if the radian is dimensionless.
You have: (14 ft lbf) (12 radians/sec)
You want: watts
* 227.77742
/ 0.004390251
Note that named dimensionaless units are not treated as dimensionless in other contexts. They cannot be used as exponents so for example, 'meter^radian' is not allowed.
If you want a list of options you can type ? at the 'You want:' prompt. The program will display a list of named units which are conformable with the unit that you entered at the 'You have:' prompt above. Note that conformable unit combinations will not appear on this list.
Typing help at either prompt displays a short help message. You can also type help followed by a unit name. This will open a window on the units file at the point where that unit is defined. You can read the definition and comments that may give more details or historical information about the unit.
Typing search text at either prompt displays a list of all units whose names contain text as a substring, along with their definitions. This may help in the case where you aren't sure of the right unit name.
To end the session, you type quit at either prompt, or press return at the 'You have:' prompt.
To open the graphic interface of units , type
java -jar jarfile
at your shell prompt. If you stored the JAR file with extension .jar and your system has an association of .jar files with javaw command (which is usually set up when you install JRE), you can instead double-click on the JAR icon. In each case, the program should open a window like this:
Type the quantity and units that you are converting from in the 'You have:' field, in the form explained by examples in Section 2.1. Next, enter the type of units you want to convert to in the 'You want:' field. Then hit the Enter (Return) key or press the 'Convert' button. The result should appear in the large field below, in the 'verbose' format described in Section 2.1.
Press the 'Reduce' button to see the reduced form of the measure you entered in the 'You have:' field.
Press the 'Conformable units' button to see a list of named units which are conformable with that measure. Note that conformable unit combinations will not appear on this list.
Enter a unit name in the 'You have:' field and press the 'Source' button to see the units file at the point where that unit is defined. You can read the definition and comments that may give more details or historical information about the unit.
Enter any text in the 'You have:' field and press the 'Search' button to see the list of all units whose names contain that text as a substring, along with their definitions. This may help in the case where you aren't sure of the right unit name.
Explore by yourself the three buttons at the bottom.
To use units as an applet, you do not need to download the JAR. You only need a browser that supports Java 1.5.22 or later. You use that browser to open a Web page with embedded units applet, for example, by clicking here. The page will contain a window looking exactly like that shown in Section 2.2. You use it in the same way as described there.
The units program can perform units conversions non-interactively from the command line. To do this, type the command, type the original units expression, and type the new units you want. You will probably need to protect the units expressions from interpretation by the shell using quote characters.
If you type
java -jar jarfile "2 liters" "quarts"then units will print
* 2.1133764
/ 0.47317648
and then exit.
The output tells you that 2 liters is about 2.1 quarts, or alternatively that
a quart is about 0.47 times 2 liters.
If the conversion is successful, then units will return success (0) to the calling environment. If units is given non-conformable units to convert, it will print a message giving the reduced form of each unit and it will return failure (nonzero) to the calling environment.
When units is invoked with only one argument, it will print out the definition of the specified unit. It will return failure if the unit is not defined and success if the unit is defined.
In order to enter more complicated units or fractions, in GUI or in the line command version, you will need to use operations such as powers, products and division. Powers of units can be specified using the '^' character as shown in the following example, or by simple concatenation: 'cm3' is equivalent to 'cm^3'. If the exponent is more than one digit, the '^' is required. An exponent like '2^3^2' is evaluated right to left. The '^' operator has the second highest precedence. The '**' operator is provided as an alternative exponent operator.
You have: cm^3
You want: gallons
* 2.6417206E-4
/ 3785.4119
You have: arabicfoot arabictradepound force
You want: ft lbf
* 0.7296
/ 1.370614
Multiplication of units can be specified by using spaces, or an asterisk ('*'). Division of units is indicated by the slash ('/') or by 'per'.
You have: furlongs per fortnight
You want: m/s
* 1.6630985E-4
/ 6012.8726
In the previous versions of units, multiplication was assigned a higher precedence than division. This disagrees with the usual precedence rules which give multiplication and division equal precedence, and it has been a source of confusion for people who think of units as a calculator.
In this version, multiplication using the star (*) has the same precedence as division and hence follows the usual precedence rules. (The corresponding version, 1.87, of the original units has an option for treating '*' in the old way. The Java version doesn't.)
Multiplication using a space has higher precedence than division and is evaluated left to right. So 'm/s s/day' is equivalent to 'm / s s day' and has dimensions of length per time cubed. Similarly, '1/2 meter' refers to a unit of reciprocal length equivalent to .5/meter, which is probably not what you would intend if you entered that expression. You can indicate division of numbers with the vertical dash ('|'). This operator has the highest precedence so the square root of two thirds could be written '2|3^1|2'.
You have: 1|2 inch
You want: cm
* 1.27
/ 0.78740156
Parentheses can be used for grouping as desired.
You have: (1/2) kg / (kg/meter)
You want: league
* 1.0356166E-4
/ 9656.083
Prefixes are defined separately from base units. In order to get centimeters, the units database defines 'centi-' and 'c-' as prefixes. Prefixes can appear alone with no unit following them. An exponent applies only to the immediately preceding unit and its prefix so that 'cm^3' or 'centimeter^3' refer to cubic centimeters but 'centi meter^3' refers to hundredths of cubic meters. Only one prefix is permitted per unit, so 'micromicrofarad' will fail, but 'micro microfarad' will work.
For units , numbers are just another kind of unit. They can appear as many times as you like and in any order in a unit expression. For example, to find the volume of a box which is 2 ft by 3 ft by 12 ft in steres, you could do the following:
You have: 2 ft 3 ft 12 ft
You want: stere
* 2.03881129
/ 0.4904815
You have: $ 5 / yard
You want: cents / inch
* 13.888889
/ 0.072
And the second example shows how the dollar sign in the units conversion can precede the five. Be careful: units will interpret '$5' with no space as equivalent to dollars^5.
Outside of the SI system, it is often desirable to add values of different units together. You may also wish to use units as a calculator that keeps track of units. Sums of conformable units are written with the '+' and '-' characters.
You have: 2 hours + 23 minutes + 32 seconds
You want: seconds
* 8612
/ 1.16117044E-4
You have: 12 ft + 3 in
You want: cm
* 373.38
/ 0.0026782367
You have: 2 btu + 450 ft lbf
You want: btu
* 2.5782804
/ 0.3878554
The expressions which are added together must reduce to identical expressions in primitive units, or an error message will be displayed:
You have: 12 printerspoint + 4 heredium
Sum of non-conformable values:
0.0042175176 m
20186.727 m^2
In previous versions of units , '-' has been used for products of units. This Java version always treats the binary operator '-' as a subtraction operator. (The corresponding version, 1.87, of the original units has an option for treating '-' as product operator. The Java version doesn't.)
When '-' is used as a unary operator it negates its operand.
The '+' or '-' character sometimes appears in exponents like '3.43e+8'. This leads to an ambiguity in an expression like '3e+2 yC'. The unit 'e' is a small unit of charge, so this can be regarded as equivalent to '(3e+2) yC' or '(3 e)+(2 yC)'. This ambiguity is resolved by always interpreting '+' or '-' as part of an exponent if possible.
Several built in functions are provided: 'sin', 'cos', 'tan', 'ln', 'log', 'log2', 'exp', 'acos', 'atan' and 'asin'. The 'sin', 'cos', and 'tan' functions require either a dimensionless argument or an argument with dimensions of angle.
You have: sin(30 degrees)
You want:
Definition: 0.5
You have: sin(pi/2)
You want:
Definition: 1
You have: sin(3 kg)
Argument 3 kg of sin is not a number or an angle.
The other functions on the list require dimensionless arguments. The inverse trigonometric functions return arguments with dimensions of angle.
If you wish to take roots of units, you may use the 'sqrt' or 'cuberoot' functions. These functions require that the argument have the appropriate root. Higher roots can be obtained by using fractional exponents:
You have: sqrt(acre)
You want: feet
* 208.71074
/ 0.0047913203
You have: (400 W/m^2 / stefanboltzmann)^(1/4)
You have:
Definition: 289.8088 K
You have: cuberoot(hectare)
10000 m^2 is not a cube root.
Nonlinear units are represented using functional notation. They make possible nonlinear unit conversions such as temperature. This is different from the linear units that convert temperature differences. Note the difference below. The absolute temperature conversions are handled by units starting with 'temp', and you must use functional notation. The temperature differences are done using units starting with 'deg' and they do not require functional notation.
You have: tempF(45)
You want: tempC
7.2222223
You have: 45 degF
You want: degC
* 25
/ 0.04
Think of 'tempF(x)' not as a function but as a notation which indicates that 'x' should have units of 'tempF' attached to it. The first conversion shows that if it's 45 degrees Fahrehneit outside it's 7.2 degrees Celsius. The second conversion indicates that a change of 45 degrees Fahrenheit corresponds to a change of 25 degrees Celsius.
Some other examples of nonlinears units are ring size and wire gauge. There are numerous different gauges and ring sizes. See the units database for more details. Note that wire gauges with multiple zeroes are signified using negative numbers where two zeroes is -1. Alternatively, you can use the synonyms 'g00', 'g000', and so on that are defined in the units database.
You have: wiregauge(11)
You want: inches
* 0.090742
/ 11.020255
You have: brwiregauge(g00)
You want: inches
* 0.348
/ 2.8735633
You have: 1 mm
You want: wiregauge
18.20192
The syntax of unit expressions is defined as follows. Phrases and symbols in quotes represent themselves, | means 'or', [] means optional occurrence, and []... zero or more occurrences of phrase between brackets.
expr = term [('+' | '-') term ]...
| ('/' | 'per') product
term = product [('*' | '/' | 'per') product ]...
product = factor [ factor ]...
factor = unary [('^' | '**') unary ]...
unary = [('+' | '-')] primary
primary = unitname
| numexpr
| bfunc '(' expr ')'
| ['~'] dfunc '(' expr ')'
| '(' expr ')'
numexpr = number ['|' number ]...
number = mantissa [ exponent ]
mantissa = '.' digits
| digits ['.' [ digits ]]
exponent = 'e' [sign] digits
bfunc = built-in function name: sqrt, cuberoot, sin, cos, etc.
dfunc = defined function name
Names of syntactic elements shown above in italics may appear in error messages that you receive if you happen to enter an incorrect expression. For example:
You have: 1|m After '1|': Expected number. You have: cm^per $ After 'cm^': Expected unary. You have: 3m+*lbf After '3m+': Expected term.
Assuming the JAR file saved under the name jarfile and Java Runtime Environment invoked by typing java, you invoke units like this:
java -jar jarfile [options] [from-unit [to-unit]]
If all of options, from-unit and to-unit are omitted, this opens a graphic interface as described in Section 2.2. The same is achieved by double-clicking on the JAR icon, provided the right association is set up. (This association is normally set up automatically as a part of installing Java Runtime Environment.)
If the from-unit and to-unit are omitted, then the program will use interactive prompts to determine which conversions to perform, as described in Section 2.1.
If both from-unit and to-unit are given, units will print the result of that single conversion and then exit. If only from-unit appears on the command line, units will display the definition of that unit and exit. Note that from-unit and to-unit will need to be quoted to protect them from shell interpretation and to group them into two arguments.
The following options allow you to use alternative units file(s), check your units file, or change the output format:
Note that you cannot specify any of these options if you use graphic interface. In that case, you can specify alternative units file(s) and locale by means of Properties, as described in Section 10. The results are always shown 'verbose' in that interface.
You embed a units applet in a Web page by means of this tag:
<APPLET CODE="units.applet.class" ARCHIVE="http://units-in-java.sourceforge.net/Java-units.jar" WIDTH=550 HEIGHT=450> <PARAM NAME="LOCALE" VALUE="locale"> </APPLET>
where locale is the locale you want to use.
You may omit the PARAM tag if you want to use the default locale, 'en_US'.
Notice that, because an applet cannot access any files on your system, you can use only the default units file packaged with the applet. The results are always shown 'verbose' in the applet.
Click here and view source for an example of Web page with embedded units applet.
The conversion information is read from a units data file. A default data file, called 'units.dat', is packaged in the JAR file together with the program. (You can extract it from there using the jar tool of Java.) The default file includes definitions for all familiar units, abbreviations and metric prefixes. It also includes many obscure or archaic units.
Many constants of nature are defined, including these:
pi ratio of circumference to diameter c speed of light e charge on an electron force acceleration of gravity mole Avogadro's number water pressure per unit height of water Hg pressure per unit height of mercury au astronomical unit k Boltzman's constant mu0 permeability of vacuum epsilon0 permitivity of vacuum G Gravitational constant mach speed of sound
The file includes atomic masses for all of the elements and numerous other constants. Also included are the densities of various ingredients used in baking so that '2 cups flour_sifted' can be converted to 'grams'. This is not an exhaustive list. Consult the units data file to see the complete list, or to see the definitions that are used.
The unit 'pound' is a unit of mass. To get force, multiply by the force conversion unit 'force' or use the shorthand 'lbf'. (Note that 'g' is already taken as the standard abbreviation for the gram.) The unit 'ounce' is also a unit of mass. The fluid ounce is 'fluidounce' or 'floz'. British capacity units that differ from their US counterparts, such as the British Imperial gallon, are prefixed with 'br'. Currency is prefixed with its country name: 'britainpound'.
The US Survey foot, yard, and mile can be obtained by using the 'US' prefix. These units differ slightly from the international length units. They were in general use until 1959, and are still used for geographic surveys. The acre is officially defined in terms of the US Survey foot. If you want an acre defined according to the international foot, use 'intacre'. The difference between these units is about 4 parts per million. The British also used a slightly different length measure before 1959. These can be obtained with the prefix 'UK'.
When searching for a unit, if the specified string does not appear exactly as a unit name, then the units program will try to remove a trailing 's' or a trailing 'es'. It will also try to remove a trailing 'ies' and replace it by 'y'. If that fails, units will check for a prefix. All of the standard metric prefixes are defined.
To find out what units and prefixes are available, read the standard units data file.
All of the units and prefixes that units can convert are defined in the units data file. If you want to add your own units, you can supply your own file. You can also add your own units definitions in the 'units.dat' file in your home directory. If this file exists it is read before the units data file. It will not be read if any units files are specified on the command line or by means of Properties.
A unit is specified on a single line by giving its name and an equivalence. Comments start with a '#' character, which can appear anywhere in a line. The backslash character ('\') acts as a continuation character if it appears as the last character on a line, making it possible to spread definitions out over several lines if desired. A file can be included by giving the command '!include' followed by full path to the file.
Unit names must not contain any of the operator characters '+', '-', '*', '/', '|', '^' or the parentheses. They cannot begin with a digit or a decimal point ('.'), or tilde ('~'), nor can they end with a digit (except for zero). Be careful to define new units in terms of old ones so that a reduction leads to the primitive units, which are marked with '!' characters. Dimensionless units are indicated by using the string '!dimensionless' for the unit definition.
When adding new units, be sure to use the '-C' option to check that the new units reduce properly. If you create a loop in the units definitions, then units will hang when invoked with the '-C' option. You will need to use the cobined '-Cv' option which prints out each unit as it checks them. The program will still hang, but the last unit printed will be the unit which caused the infinite loop.
Here is an example of a short units file that defines some basic units:
m ! # The meter is a primitive unit sec ! # The second is a primitive unit rad !dimensionless # A dimensionless primitive unit micro- 1e-6 # Define a prefix minute 60 sec # A minute is 60 seconds hour 60 min # An hour is 60 minutes inch 0.0254 m # Inch defined in terms of meters ft 12 inches # The foot defined in terms of inches mile 5280 ft # And the mile
A unit which ends with a '-' character is a prefix. If a prefix definition contains any '/' characters, be sure they are protected by parentheses. If you define 'half- 1/2' then 'halfmeter' would be equivalent to '1 / 2 meter'.
Some units conversions of interest are nonlinear; for example, temperature conversions between the Fahrenheit and Celsius scales cannot be done by simply multiplying by conversions factors.
When you give a linear unit definition such as 'inch 2.54 cm' you are providing information that units uses to convert values in inches into primitive units of meters. For nonlinear units, you give a functional definition that provides the same information.
Nonlinear units are represented using a functional notation. It is best to regard this notation not as a function call but as a way of adding units to a number, much the same way that writing a linear unit name after a number adds units to that number. Internally, nonlinear units are defined by a pair of functions which convert to and from linear units in the data file, so that an eventual conversion to primitive units is possible.
Here is an example nonlinear unit definition:
tempF(x) [1;K] (x+(-32)) degF + stdtemp ; (tempF+(-stdtemp))/degF + 32
A nonlinear unit definition comprises a unit name, a dummy parameter name, two functions, and two corresponding units. The functions tell units how to convert to and from the new unit. In order to produce valid results, the arguments of these functions need to have the correct dimensions. To facilitate error checking, you may specify the dimensions.
The definition begins with the unit name followed immediately (with no spaces) by a '(' character. In parentheses is the name of the parameter. Next is an optional specification of the units required by the functions in this definition. In the example above, the 'tempF' function requires an input argument conformable with '1'. For normal nonlinear units definitions the forward function will always take a dimensionless argument. The inverse function requires an input argument conformable with K. In general the inverse function will need units that match the quantity measured by your nonlinear unit. The sole purpose of the expression in brackets to enable units to perform error checking on function arguments.
Next the function definitions appear. In the example above, the 'tempF' function is defined by
tempF(x) = (x+(-32)) degF + stdtemp
This gives a rule for converting 'x' in the units 'tempF' to linear units of absolute temperature, which makes it possible to convert from tempF to other units.
In order to make conversions to Fahrenheit possible, you must give a rule for the inverse conversions. The inverse will be 'x(tempF)' and its definition appears after a ';' character. In our example, the inverse is
x(tempF) = (tempF+(-stdtemp))/degF + 32
This inverse definition takes an absolute temperature as its argument and converts it to the Fahrenheit temperature. The inverse can be omitted by leaving out the ; character, but then conversions to the unit will be impossible. If the inverse is omitted then the '-c' option will display a warning. It is up to you to calculate and enter the correct inverse function to obtain proper conversions. The '-c' option tests the inverse at one point and print an error if it is not valid there, but this is not a guarantee that your inverse is correct.
If you wish to make synonyms for nonlinear units, you still need to define both the forward and inverse functions. Inverse functions can be obtained using the '~' operator. So to create a synonym for 'tempF' you could write
fahrenheit(x) [1;K] tempF(x); ~tempF(fahrenheit)
You may occasionally wish to define a function that operates on units. This can be done using a nonlinear unit definition. For example, the definition below provides conversion between radius and the area of a circle. Note that this definition requires a length as input and produces an area as output, as indicated by the specification in brackets.
circlearea(r) [m;m^2] pi r^2 ; sqrt(circlearea/pi)
Sometimes you may be interested in a piecewise linear unit such as many wire gauges. Piecewise linear units can be defined by specifying conversions to linear units on a list of points. Conversion at other points will be done by linear interpolation. A partial definition of zinc gauge is
zincgauge[in] 1 0.002, 10 0.02, 15 0.04, 19 0.06, 23 0.1
In this example, 'zincgauge' is the name of the piecewise linear unit. The definition of such a unit is indicated by the embedded '[' character. After the bracket, you should indicate the units to be attached to the numbers in the table. No spaces can appear before the ']' character, so a definition like 'foo[kg meters]' is illegal; instead write 'foo[kg*meters]'. The definition of the unit consists of a list of pairs optionally separated by commas. This list defines a function for converting from the piecewise linear unit to linear units. The first item in each pair is the function argument; the second item is the value of the function at that argument (in the units specified in brackets). In this example, we define zincgauge at five points. For example, we set 'zincgauge(1)' equal to '0.002 in'. Definitions like this may be more readable if written using continuation characters as
zincgauge[in] \
1 0.002 \
10 0.02 \
15 0.04 \
19 0.06 \
23 0.1
With the preceeding definition, the following conversion can be performed:
You have: zincgauge(10)
You want: in
* 0.02
/ 50
You have: .01 inch
You want: zincgauge
5
If you define a piecewise linear unit that is not strictly monotonic, then the inverse will not be well defined. If the inverse is requested for such a unit, units will return the smallest inverse. The '-c' option will print a warning if a non-monotonic piecewise linear unit is encountered.
Some units have different values in different locations. The localization feature accomodates this by allowing the units database to specify region dependent definitions. A locale region in the units database begins with '!locale' followed by the name of the locale. The leading '!' must appear in the first column of the units database. The locale region is terminated by '!endlocale'. The following example shows how to define a couple of units in a locale.
!locale en_GB ton brton gallon brgallon !endlocale
Note that the '-c' option only checks the definitions which are active for the current locale.
If you systematically use units file(s) and/or locale different from the deafult ones, you may avoid writing '-f' and/or '-l' option every time you invoke units . You can do it by setting up a Property list. This is also the only way of communicating the alternative files and/or locale if you use the graphic interface.
Property list is a file named 'units.opt', placed in the same directory as the JAR file. It may look like this:
LOCALE = en_GB UNITSFILE = ; c:\\Java\\gnu\\units\\my.dat
The first line specifies 'en_GB' as the locale to be used. The second line tells that you want to use the default units file plus your own file 'c:\Java\gnu\units\my.dat'. Following 'UNITSFILE =' is a list of file names separated by semicolons. An empty name indicates the default file (whitespace characters are ignored).
Notice that each file must be specified by full path. Notice also that each backslash character ('\') is escaped by another backslash. In general, the file must have the format specified as follows by Java documentation:
Every property occupies one line of the input stream.
Each line is terminated by a line terminator (\n or \r or \r\n).
Lines from the input stream are processed until end of file is reached on the input stream.
A line that contains only whitespace or whose first non-whitespace character
is an ASCII # or ! is ignored (thus, # or ! indicate comment lines).
Every line other than a blank line or a comment line describes one property
to be added to the table (except that if a line ends with \,
then the following line, if it exists, is treated as a continuation line,
as described below).
The key consists of all the characters in the line starting with the first
non-whitespace character and up to, but not including, the first ASCII =, :,
or whitespace character. All of the key termination characters may be included
in the key by preceding them with a \. Any whitespace after the key is skipped;
if the first non-whitespace character after the key is = or :,
then it is ignored and any whitespace characters after it are also skipped.
All remaining characters on the line become part of the associated element string.
Within the element string, the ASCII escape sequences
\t, \n, \r, \\, \", \', \ (a backslash and a space),
and \uxxxx are recognized and converted to single characters.
Moreover, if the last character on the line is \, then the next line
is treated as a continuation of the current line; the \ and line terminator
are simply discarded, and any leading whitespace characters on the continuation
line are also discarded and are not part of the element string.
(Quoted verbatim from description of method 'load' in class 'Properties'.)
The '-f' and '-l' options specified on the command line override settings from the Property list.
The Java imitation is not an exact port of the original GNU units. The following is a (most likely incomplete) list of differences.
Latest change 2009-11-20