Author: | Fred Gylys-Colwell |
Home Page: | |
Version: | $Name: $, $Revision: 1.19 $ |
Release Tag: | $ |
Release Date: | 2002/02/09 05:38:47 |
JVM Required: | 1.2 @gjtmain Converter |
License: | Public Domain |
Categories: | utility, scientific |
Requirements: | |
Dependencies: | org.gjt.fredgc.misc, org.gjt.fredgc.function |
Externals: | None |
unit
package allows one to convert from one set of units to another. For example from feet to meters. Most of the conversion factors are taken from the U.S. National Institute of Standards and Technology, NIST. An example of the {@linkorg.gjt.fredgc.unit.Converter} applet is on my Homepage The main classes are the {@linkorg.gjt.fredgc.unit.Unit}, which represents a particular unit of measure; the {@linkorg.gjt.fredgc.unit.Quantity}, which represents a number or quantity, together with the unit is is measured in; and the subclasses of {@linkorg.gjt.fredgc.unit.UnitSystem}, which, when given a unit, can find the corresponding unit in a given system of units.
The default units are given as: m
(meters), s
(seconds), kg
(kilograms), K
(Kelvin), mol
(Moles), A
(Amperes), and cd
(candelas).
Use {@linkorg.gjt.fredgc.unit.Unit#newUnit(String)}, {@linkorg.gjt.fredgc.unit.Unit#newUnit(String, double, String)}, {@linkorg.gjt.fredgc.unit.Unit#newUnit(String, double, String, double)}, or {@linkorg.gjt.fredgc.unit.Unit#newUnit(String, double, Unit, double)} to create a new unit. You may use a combination of any of the standard units, including standard prefixes. Strings are case sensitive mm
is milimeter, Mm
is megameter, and MM
will generate an error. Each unit is made up of a fraction of other units. Everything to the left of the slash is in the numerator and everything to the right is in the denominator -- parenthesis are not used (it's a bug, not a feature...). For example the unit kW/m^2
is the same as 1715 times the unit Btu/h ft^2
.
Prefix used in code | Prefix for written unit | Multiplier |
---|---|---|
da- | deka- | 10 |
h- | hecto- | 100 |
k- | kilo- | 1000 |
M- | mega- | 1e6 |
G- | giga- | 1e9 |
T- | tera- | 1e12 |
P- | peta- | 1e15 |
E- | exa- | 1e18 |
Z- | zeta- | 1e21 |
Y- | yotta- | 1e24 |
d- | deci- | 1e-1 |
c- | centi- | 1e-2 |
m- | milli- | 1e-3 |
mu- | micro- | 1e-6 |
n- | nano- | 1e-9 |
p- | pico- | 1e-12 |
f- | femto- | 1e-15 |
a- | atto- | 1e-18 |
z- | zepto- | 1e-21 |
y- | yocto- | 1e-24 |
Unit | Symbol | Definition | Comments |
---|---|---|---|
Time | |||
second | sec | 1 s | |
minute | min | 60 s | |
hour | hr | 60 min | |
hour | hour | 1 hr | alternate symbol |
hour | h | 1 hr | alternate symbol |
day | day | 24 hr | |
shake | shake | 10 ns | |
Hertz | Hz | 1 s^-1 | |
Length or Distance | |||
international foot | ft | 0.3048 m | |
inch | in | 1.0/12.0 ft | |
international mile | mile | 5280.0 ft | |
international mile | mi | 1 mile | alternate symbol |
milli-inch | mil | 0.001 in | |
micron | micron | 1e-6 m | |
Parsec | pc | 3.085678e16 m | |
League | league | 3 mile | |
Astronomical Unit | ua | 1.49598e11 m | |
Astronomical Unit | AU | 1.49598e11 m | alternate symbol |
yard | yd | 3 ft | |
Angstrom | Ang | 1e-10 m | (I call it Ang, because I can't spell Å in java) |
Angstrom | \\AA | 1 Ang | alternate symbol |
furlong | furlong | 220 yd | |
fathom | fathom | 6 ft | (my dad is sea foam) |
Rod | rd | 16.5 ft | |
U.S. survey foot | sft | (1200./3937.) m | |
U.S. survey mile | smi | 5280 sft | also called statue mile |
point | pt | 1./72. in | Typeface Point |
pica | pica | 1./6. in | Typeface Pica |
Temperature | |||
Celsius | C | 1 K -273.15 | |
Rankine | R | 5.0/9.0 K | |
Fahrenheit | F | 1 R -459.67 | |
Mass | |||
gram | g | 0.001 kg | This is case sensitive. |
gram | gm | g | (alternate symbol) |
pound mass | lbm | 0.45359237 kg | (avoirdupois) |
Troy pound | lbt | 0.3732417 kg | (apothecary) |
carat (metric) | carat | 0.2 g | |
slug | slug | 1 lb sec^2/ft | |
snail | snail | 1 lb sec^2/in | |
Short Ton | ton | 2000 lbm | |
Long Ton | ton_l | 2240 lbm | |
Ounce | oz | 28.34952 g | (avoirdupois) |
Grain | gr | 64.79891 mg | |
Pennyweight | dwt | 1.55174 g | |
Force or Weight | |||
Newton | N | 1 kg m/s^2 | |
Dyne | dyn | 1e-5 N | |
pound force | lb | lbm G | |
pound force | lbf | lbm G | |
poundal | poundal | 1 lbm ft/sec^2 | |
kilopound | kip | 1000 lbf | |
kilogram force | kgf | kg G | |
Energy | |||
Joule | J | 1 N m | |
British Therm. Unit | BTU | 1055.056 J | (International Table) |
British Therm. Unit | Btu | 1 BTU | alternate symbol |
British Therm. Unit | BTU_th | 1054.350 J | (Thermochemical) |
calorie | cal | 4.1868 J | (International Table) |
calorie | cal_th | 4.184 J | (Thermochemical) |
Calorie | Cal | 4.1868 kJ | (nutritionists) |
electron volt | eV | 1.602177e-19 J | |
erg | erg | 1e-7 J | |
Ton of TNT | TNT | 4.184e9 J | |
Power | |||
Watt | W | 1 J/s | |
Horse Power | hp | 550 ft lb/s | |
Pressure | |||
bar | bar | 1e5 N/m^2 | |
Pascal | Pa | 1 N/m^2 | |
Pounds per sq. inch | psi | 1 lb/in^2 | |
Pounds per sq. ft. | psf | 1 lb/ft^2 | |
kilo psi | ksi | 1000.0 psi | |
atmospheres | atm | 1.01325e5 N/m^2 | |
inches of Mercury | inHg | 3.387 kPa | |
millimeters Mercury | mmHg | 0.1333 kPa | |
Torr | torr | 1.333224 Pa | |
Volume or Area | |||
Liter | L | 1/1000.0 m^3 | |
gallon | gal | 3.785412 L | |
Pint (U.S. liquid) | pint | 1/8. gal | |
Quart (U.S. liquid) | qt | 2 pint | |
Pint (U.S. dry) | dpint | 0.5506105 L | |
Quart (U.S. dry) | dqt | 2 dpint | |
Acre | acre | 1/640.0 smi^2 | |
Hectare | ha | 10000 m^2 | |
Barrel (petroleum) | barrel | 158.9873 L | |
Fluid Ounce | oz_fl | 29.57353 mL | |
Gill (U.S.) | gi | 0.1182941 L | |
Peck (U.S.) | pk | 8.809768 L | |
Tablespoon | tbl | 1/32. pint | |
Teaspoon | tsp | 1/3. tbl | |
Cup | cup | 16. tbl | |
Electromagnetism | |||
Coulomb | Co | 1 A s | Electric Charge |
Volt | V | 1 W/A | Electric Potential |
Ohm | ohm | 1 V/A | Electric Resistance |
Ohm | \\Omega | 1 V/A | alternate symbol |
Faraday | faraday | 96485.31 Co | Electric Charge |
Farad | farad | Co/V | Capacitance |
Stokes | stokes | 1e-4 m^2/s | |
Oersted | Oe | 79.57747 A/m | |
Webber | Wb | V s | Magnetic flux |
Tesla | Tesla | Wb/m^2 | Magnetic flux density |
Henry | H | Wb/A | Inductance |
Siemens | S | A/V | Electrical Conductance |
Light and Radiation | |||
Lux | lux | cd/m^2 | Iluminance |
Lux | lx | cd/m^2 | |
Lumen | lm | cd | Luminous Flux |
Stilb | sb | 10000 cd/m^2 | |
Phot | ph | 10000 lx | |
Becquerel | Bq | s^-1 | activity |
Gray | Gy | J/kg | Absorbed Dose, kerma |
Sievert | Sv | J/kg | Dose equivalent |
Other Quantities | |||
pound mole | lbmole | 1 mol lbm/g | quantity |
poise | poise | 1 g /sec cm | viscocity |
Gravity's accel. | G | 9.80665 m/sec^2 | Gravity on Earth |
Degree | deg | Pi/180 | Can be used to convert from degrees to radians for trig functions. |
radian | rad | 1 | Actually, radian is a pure number. |
steradian | st | 1 | The unit surface area of a sphere. It is really a pure number. |
Percent | % | 0.01 | |
Knot | knot | 1852 m/hr | velocity |
Miles per Hour | mph | 1 mi/hr | velocity |
Gallon/minute | gpm | 1. gal/min | flow rate |
Revolution/minute | rpm | 360 deg/min | |
Obscure | |||
ch'ih | chih | 32 cm | Chinese |
feddan | feddan | 4.193 m^2 | Egyptian |
vara | vera | 0.84 m | Nicaraguan |
verst | verst | 1.067 km | Russan |
Humor | |||
1 million microphones | 1 megaphone | (it's a joke! Get it?) | |
1 million bicycles | 2 megacycles | ||
2000 mockingbirds | 2 kilomockingbirds | ||
10 cards | 1 decacards | (or is it 52 cards = 1 deck-a-cards?) | |
1/2 lavatory | 1 demijohn | ||
1 millionth of a fish | 1 microfiche | ||
453.6 graham crackers | 1 pound cake | ||
10 rations | 1 decoration | ||
1 ship | 1 millihelen | ||
10 millipedes | 1 centipede | ||
3-1/3 tridents | 1 decadent | ||
10 monologs | 5 dialogues | ||
2 monograms | 1 diagram | ||
8 nickles | 2 paradigms |
If you would prefer to use lb
for pound mass, you can have the code Unit.newUnit("lb", 1, "lbm")
before you use it. This will create a new unit with the same name as the old one, but with a new definition. This new Unit
is then stored in the internal table of units under the name "lb". Now, any more calls to newUnit
will use this new definition of "lb".
According to the National Institute of Standards and Technology (NIST), the Btu and calorie were redefined at the Fifth International Conference on the Properties of Steam (London, July 1956). These are marked as International Table above. An alternate definition is listed as "Thermochemical".
Note to would-be package maintainers: to add a new unit, you should edit the file UnitList.java
, which will create package.html
and UnitInit.java
. The parser in this package was created with JavaCC