Math: sync convertcore unit data with ConvertAll 0.7.2

Also add in a special case for handling the new unitless unit ("!!")
This commit is contained in:
James Lu 2017-09-29 16:02:36 -07:00
parent b5f53fb22f
commit b6c75a70d3
1 changed files with 257 additions and 195 deletions

View File

@ -16,38 +16,40 @@ import copy
unitData = \ unitData = \
""" """
#***************************************************************************** #*****************************************************************************
# units.dat, the units data file, version 0.3.1 #units.dat, the units data file, version 0.6.2
# #
# ConvertAll, a units conversion program # ConvertAll, a units conversion program
# Copyright (C) 2005, Douglas W. Bell # Copyright (C) 2016, Douglas W. Bell
# #
# This is free software; you can redistribute it and/or modify it under the # This is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License, Version 2. This program is # terms of the GNU General Public License, Version 2. This program is
# distributed in the hope that it will be useful, but WITTHOUT ANY WARRANTY. # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
#***************************************************************************** #*****************************************************************************
# #
# Units are defined by an optional quantity and an equivalent unit or unit # Units are defined by an optional quantity and an equivalent unit or unit
# combination. A python expression may be used for the quantity, but is # combination. A Python expression may be used for the quantity, but is
# resticted to using only the following operators: *, /, +, -, **, (, ). # restricted to using only the following operators: *, /, +, -.
# Beware of integer division truncation: be sure to use a float for at # Beware of integer division truncation: be sure to use a float for at least
# least one of the values. # one of the values.
# #
# The unit type must be placed in square brackets before a set of units. # The unit type must be placed in square brackets before a set of units. The
# The first comment after the equivalent unit will be put in parenthesis after # first comment after the equivalent unit will be put in parenthesis after the
# the unit name (usually used to give the full name of an abbreviated unit). # unit name (usually used to give the full name of an abbreviated unit). The
# The next comment will be used in the program list's comment column; # next comment will be used in the program list's comment column; later
# later comments and full line comments are ignored. # comments and full line comments are ignored.
# #
# Non-linear units are indicated with an equivalent unit in square brackets, # Non-linear units are indicated with an equivalent unit in square brackets,
# followed by either equations or equivalency lists for the definition. # followed by either equations or equivalency lists for the definition. For
# For equations, two are given, separated by a ';'. Both are functions of # equations, two are given, separated by a ';'. Both are functions of "x", the
# "x", the first going from the unit to the equivalent unit and the second # first going from the unit to the equivalent unit and the second one in
# one in reverse. Any valid Python expression returning a float (including # reverse. Any valid Python expression returning a float (including the
# the functions in the math module) should work. The equivalency list is a # functions in the math module) should work. The equivalency list is a Python
# python list of tuples giving points for linear interpolation. # list of tuples giving points for linear interpolation.
# #
# All units must reduce to primitive units, which are indicated by an '!' # All units must reduce to primitive units, which are indicated by an
# as the equivalent unit. Circular refernces must also be avoided. # equivalent unit starting with '!'. A special "unitless" primitve unit
# (usualty called "unit") has '!!' for an equivalent unit. Circular references
# must also be avoided.
# #
# Primitive units: kg, m, s, K, A, mol, cd, rad, sr, bit, unit # Primitive units: kg, m, s, K, A, mol, cd, rad, sr, bit, unit
# #
@ -79,21 +81,28 @@ carat = 0.2 gram
ct = carat # carat ct = carat # carat
amu = 1.66053873e-27 kg # atomic mass amu = 1.66053873e-27 kg # atomic mass
atomic mass unit = amu atomic mass unit = amu
pound = 0.45359237 kg pound = 0.45359237 kg # # avoirdupois
lb = pound # pound lb = pound # pound # avoirdupois
lbm = pound # pound lbm = pound # pound # avoirdupois
ounce = 1/16.0 pound ounce = 1/16.0 pound # # avoirdupois
oz = ounce # ounce oz = ounce # ounce # avoirdupois
lid = ounce # # drug slang lid = ounce # # drug slang
dram = 1/16.0 ounce # # avoirdupois
pound troy = 5760 grain pound troy = 5760 grain
lb troy = pound troy # pound troy lb troy = pound troy # pound troy
ounce troy = 1/12.0 lb troy ounce troy = 1/12.0 lb troy
oz troy = ounce troy # ounce troy oz troy = ounce troy # ounce troy
ton = 2000 lb # # non-metric ton = 2000 lb # # non-metric
kiloton = 1000 ton # # non-metric kiloton = 1000 ton # # non-metric
long ton = 2240 lb # # Imperial
ton imperial = long ton
slug = lbf*s^2/ft slug = lbf*s^2/ft
stone = 14 lb stone = 14 lb
grain = 1/7000.0 lb grain = 1/7000.0 lb
pennyweight = 24 grain
hundredweight long = 112 lb # # Imperial
hundredweight short = 100 lb # # US & Canada
solar mass = 1.9891e30 kg
# #
@ -103,7 +112,8 @@ grain = 1/7000.0 lb
m = ! # meter m = ! # meter
meter = m meter = m
metre = m metre = m
decimeter = 0.1 m dm = 0.1 m # decimeter
decimeter = dm
cm = 0.01 m # centimeter cm = 0.01 m # centimeter
centimeter = cm centimeter = cm
mm = 0.001 m # millimeter mm = 0.001 m # millimeter
@ -128,27 +138,38 @@ microinches = microinch
foot = 12 inch foot = 12 inch
ft = foot # foot ft = foot # foot
feet = foot feet = foot
foot US survey = 1200/3937.0 m
Cape foot = 1.033 foot
yard = 3 ft yard = 3 ft
yd = yard # yard yd = yard # yard
mile = 5280 ft mile = 5280 ft # # statute mile
mi = mile # mile mi = mile # mile # statute mile
nautical mile = 1852 m nautical mile = 1852 m
nmi = nautical mile # nautical mile nmi = nautical mile # nautical mile
mile US survey = 5280 foot US survey
league = 3 mile league = 3 mile
chain = 66 ft chain = 66 ft
chain US survey = 66 foot US survey
link = 0.01 chain
fathom = 6 ft fathom = 6 ft
cable = 0.1 nautical mile
rod = 5.5 yard rod = 5.5 yard
furlong = 40 rod furlong = 40 rod
hand = 4 inch hand = 4 inch
cubit = 21.8 inch # # biblical unit cubit = 21.8 inch # # biblical unit
point = 1/72.27 inch point = 1/72.0 inch # # desktop publishing point
pica = 12 point pica = 12 point
caliber = 0.01 inch # # bullet sizes caliber = 1.0 inch # # bullet sizes
rack unit = 1.75 in # # computing
smoot = 67 inch
football field = 100 yd football field = 100 yd
marathon = 46145 yd marathon = 46145 yd
mil Swedish = 10 km mil Swedish = 10 km
versta = 3500 ft # # Russian unit
au = 1.49597870691e11 m # astronomical unit au = 1.49597870691e11 m # astronomical unit
astronomical unit = au astronomical unit = au
LD = 384400 km # lunar distance # astronomical
lunar distance = LD # # astronomical distance
light year = 365.25 light speed * day light year = 365.25 light speed * day
light minute = light speed * min light minute = light speed * min
light second = light speed * s light second = light speed * s
@ -157,13 +178,19 @@ kiloparsec = 1000 parsec
megaparsec = 1000 kiloparsec megaparsec = 1000 kiloparsec
screw size = [in] 0.013*x + 0.06 ; (x - 0.06) / 0.013 \ screw size = [in] 0.013*x + 0.06 ; (x - 0.06) / 0.013 \
# # Unified diameters, non-linear # # Unified diameters, non-linear
AWG = [in] 92.0**((36-x)/39.0)/200.0 ; \ AWG Dia = [in] pow(92.0,(36-x)/39.0)/200.0 ; \
36 - 39.0*log(200.0*x)/log(92.0) \ 36 - 39.0*log(200.0*x)/log(92.0) \
# American Wire Gauge \ # American Wire Gauge \
# use -1, -2 for 00, 000; non-linear # use -1, -2 for 00, 000; non-linear
American Wire Gauge = [in] 92.0**((36-x)/39.0)/200.0 ; \ American Wire Gauge Dia = [in] pow(92.0,(36-x)/39.0)/200.0 ; \
36 - 39.0*log(200.0*x)/log(92.0) \ 36 - 39.0*log(200.0*x)/log(92.0) \
# # use -1, -2 for 00, 000; non-linear # # use -1, -2 for 00, 000; non-linear
British Std Wire Gauge = [in] [(-6, .500), (-5, .464), (-3, .400), \
(-2, .372), (3, .252), (6, .192), (10, .128), \
(14, .080), (19, .040), (23, .024), (26, .018), \
(28, .0148), (30, .0124), (39, .0052), \
(49, .0012), (50, .001)] \
# # use -1, -2 for 2/0, 3/0; non-linear
standard gauge = [in] [(-5, .448350), (1, .269010), (14, .0747250), \ standard gauge = [in] [(-5, .448350), (1, .269010), (14, .0747250), \
(16, .0597800), (17, .0538020), (20, .0358680), \ (16, .0597800), (17, .0538020), (20, .0358680), \
(26, .0179340), (31, .0104615), (36, .00672525), \ (26, .0179340), (31, .0104615), (36, .00672525), \
@ -289,6 +316,7 @@ picofarad = 1e-12 farad
[magn. flux] [magn. flux]
weber = V*s weber = V*s
Wb = weber # weber Wb = weber # weber
maxwell = 1e-8 Wb
[inductance] [inductance]
henry = Wb/A henry = Wb/A
H = henry # henry H = henry # henry
@ -298,6 +326,7 @@ microhenry = 0.001 mH
[flux density] [flux density]
tesla = Wb/m^2 tesla = Wb/m^2
T = tesla # tesla T = tesla # tesla
gauss = maxwell/cm^2
# #
@ -312,7 +341,7 @@ kmol = kilomole # kilomole
pound mole = mol*lbm/gram pound mole = mol*lbm/gram
lbmol = pound mole # pound mole lbmol = pound mole # pound mole
[size of a mol] [size of a mol]
avogadro = gram/amu*mol avogadro = gram/(amu*mol)
# #
@ -332,9 +361,9 @@ footcandle = lumen/ft^2
metercandle = lumen/m^2 metercandle = lumen/m^2
[luminance] [luminance]
lambert = cd/pi*cm^2 lambert = cd/(pi*cm^2)
millilambert = 0.001 lambert millilambert = 0.001 lambert
footlambert = cd/pi*ft^2 footlambert = cd/(pi*ft^2)
# #
@ -423,7 +452,7 @@ kbps = 1000 bps # kilobits / sec. # based on power of 10
# Unitless numbers # Unitless numbers
# #
[quantity] [quantity]
unit = ! unit = !!
1 = unit # unit 1 = unit # unit
pi = 3.14159265358979323846 unit pi = 3.14159265358979323846 unit
pair = 2 unit pair = 2 unit
@ -468,12 +497,17 @@ dyne = cm*g/s^2
kg force = kg * gravity # kilogram f kg force = kg * gravity # kilogram f
kgf = kg force # kilogram force kgf = kg force # kilogram force
kilogram force = kg force kilogram force = kg force
kp = kg force # kilopond
kilopond = kg force
gram force = g * gravity gram force = g * gravity
pound force = lbm * gravity pound force = lbm * gravity # # avoirdupois
lbf = pound force # pound force lbf = pound force # pound force # avoirdupois
ton force = ton * gravity ton force = ton * gravity
ounce force = ounce * gravity ounce force = ounce * gravity
ozf = ounce force # ounce force ozf = ounce force # ounce force
tonne force = tonne * gravity # # metric
pdl = lbm * ft / sec^2 # poundal # Imperial force
poundal = pdl # # Imperial force
# #
@ -485,14 +519,24 @@ are = 100 m^2
decare = 10 are decare = 10 are
dekare = 10 are dekare = 10 are
hectare = 100 are hectare = 100 are
stremma = 1000 m^2
acre = 10 chain^2 acre = 10 chain^2
section = mile^2 section = mile^2
township = 36 section township = 36 section
homestead = 160 acre homestead = 160 acre
square perch = 30.25 yd^2
rood = 0.25 acre
rai = 1600 m^2 # # Thai rai = 1600 m^2 # # Thai
ngaan = 400 m^2 # # Thai ngaan = 400 m^2 # # Thai
circular inch = 1/4.0 pi*in^2 # # area of 1 inch circle circular inch = 1/4.0 pi*in^2 # # area of 1 inch circle
circular mil = 1/4.0 pi*mil^2 # # area of 1 mil circle circular mil = 1/4.0 pi*mil^2 # # area of 1 mil circle
AWG Area = [in^2] pi/4*pow(pow(92.0,(36-x)/39.0)/200.0,2) ; \
36 - 39.0*log(200.0*sqrt(x*4.0/pi))/log(92.0) \
# American Wire Gauge \
# use -1, -2 for 00, 000; non-linear
American Wire Gauge Area = [in^2] pi/4*pow(pow(92.0,(36-x)/39.0)/200.0,2) ; \
36 - 39.0*log(200.0*sqrt(x*4.0/pi))/log(92.0) \
# # use -1, -2 for 00, 000; non-linear
# #
@ -508,6 +552,7 @@ deciliter = 0.1 liter
centiliter = 0.01 liter centiliter = 0.01 liter
milliliter = cc milliliter = cc
ml = milliliter # milliliter ml = milliliter # milliliter
microliter = 1e-6 liter
dekaliter = 10 liter dekaliter = 10 liter
hectoliter = 100 liter hectoliter = 100 liter
kiloliter = 1000 liter kiloliter = 1000 liter
@ -522,6 +567,8 @@ pt = pint # pint # US liquid
fluid ounce = 1/16.0 pint # # US fluid ounce = 1/16.0 pint # # US
fl oz = fluid ounce # fluid ounce # US fl oz = fluid ounce # fluid ounce # US
ounce fluid = fluid ounce # # US ounce fluid = fluid ounce # # US
fluid dram = 1/8.0 fluid ounce # # US
minim = 1/480.0 fluid ounce # # US
imperial gallon = 4.54609 liter imperial gallon = 4.54609 liter
imp gal = imperial gallon # imperial gallon imp gal = imperial gallon # imperial gallon
gallon imperial = imperial gallon gallon imperial = imperial gallon
@ -533,6 +580,8 @@ imp pt = imperial pint # imperial pint
pint imperial = imperial pint pint imperial = imperial pint
imperial fluid ounce = 1/160.0 imp gal imperial fluid ounce = 1/160.0 imp gal
imp fl oz = imperial fluid ounce # imperial fluid ounce imp fl oz = imperial fluid ounce # imperial fluid ounce
imperial fluid dram = 1/8.0 imp fl oz
imperial minim = 1/480.0 imp fl oz
cup = 8 fl oz cup = 8 fl oz
tablespoon = 1/16.0 cup tablespoon = 1/16.0 cup
tbsp = tablespoon # tablespoon tbsp = tablespoon # tablespoon
@ -613,19 +662,20 @@ megabar = 1000 kilobar
mm Hg = mm*density Hg*gravity mm Hg = mm*density Hg*gravity
millimeter of Hg = mm Hg millimeter of Hg = mm Hg
torr = mm Hg torr = mm Hg
micron of Hg = micron*density Hg*gravity
in Hg = in*density Hg*gravity # inch of Hg in Hg = in*density Hg*gravity # inch of Hg
inch of Hg = in Hg inch of Hg = in Hg
m water = m*density water*gravity # meter of H2O m water = m*density water*gravity # meter of H2O # fresh water
m H2O = m water # meter of H2O m H2O = m water # meter of H2O # fresh water
meter of water = m water meter of water = m water # # fresh water
in water = in*density water*gravity # inch of H2O in water = in*density water*gravity # inch of H2O # fresh water
in H2O = in water # inch of H2O in H2O = in water # inch of H2O # fresh water
inch of water = in water inch of water = in water # # fresh water
ft water = ft*density water*gravity # feet of H2O ft water = ft*density water*gravity # feet of H2O # fresh water
ft H2O = ft water # feet of H20 ft H2O = ft water # feet of H20 # fresh water
feet of water = ft water feet of water = ft water # # fresh water
foot of head = ft water foot of head = ft water # # fresh water
ft hd = ft water # foot of head ft hd = ft water # foot of head # fresh water
psi = lbf/in^2 # pound / sq inch psi = lbf/in^2 # pound / sq inch
pound per sq inch = psi pound per sq inch = psi
ksi = 1000 psi # 1000 lb / sq inch ksi = 1000 psi # 1000 lb / sq inch
@ -670,14 +720,18 @@ cal = calorie # calorie
kilocalorie = 1000 cal kilocalorie = 1000 cal
kcal = kilocalorie # kilocalorie kcal = kilocalorie # kilocalorie
calorie food = kilocalorie calorie food = kilocalorie
Btu = cal*lb*R/g*K # British thermal unit thermie = 1000 kcal
Btu = cal*lb*R/(g*K) # British thermal unit
British thermal unit = Btu British thermal unit = Btu
therm = 100000 Btu
erg = cm*dyne erg = cm*dyne
electronvolt = 1.602176462e-19 J electronvolt = 1.602176462e-19 J
eV = electronvolt # electronvolt eV = electronvolt # electronvolt
kWh = kW*hour # kilowatt-hour kWh = kW*hour # kilowatt-hour
kilowatt hour = kWh kilowatt hour = kWh
ton TNT = 4.184e9 J ton TNT = 4.184e9 J
tonne oil equivalent = 41.868 gigajoule
tonne coal equivalent = 7000000 kcal
# #
@ -696,6 +750,8 @@ milliwatt = 0.001 W
horsepower = 550 ft*lbf/sec horsepower = 550 ft*lbf/sec
hp = horsepower # horsepower hp = horsepower # horsepower
metric horsepower = 75 kgf*m/s metric horsepower = 75 kgf*m/s
ton refrigeration = 12000 Btu/hr
MBH = 1000 Btu/hr # 1000 Btu/hr
# #
@ -725,7 +781,8 @@ roentgen = 2.58e-4 coulomb/kg
[radiation dose] [radiation dose]
gray = J/kg gray = J/kg
Gy = gray # gray Gy = gray # gray
rad. abs. dose = 0.001 Gy # # commonly rad centigray = 0.01 Gy
rad. abs. dose = 0.01 Gy # # commonly rad
sievert = J/kg # # equiv. dose sievert = J/kg # # equiv. dose
millisievert = 0.001 sievert # # equiv. dose millisievert = 0.001 sievert # # equiv. dose
Sv = sievert # sievert # equiv. dose Sv = sievert # sievert # equiv. dose
@ -737,7 +794,7 @@ millirem = 0.001 rem # # roentgen equiv mammal
# viscosity # viscosity
# #
[dyn viscosity] [dyn viscosity]
poise = g/cm*s poise = g/(cm*s)
P = poise # poise P = poise # poise
centipoise = 0.01 poise centipoise = 0.01 poise
cP = centipoise # centipoise cP = centipoise # centipoise
@ -754,13 +811,18 @@ cSt = centistokes # centistokes
# #
[acceleration] [acceleration]
gravity = 9.80665 m/s^2 gravity = 9.80665 m/s^2
galileo = cm/s^2
[constant] [constant]
gravity constant = 6.673e-11 N*m^2/kg^2 gravity constant = 6.673e-11 N*m^2/kg^2
gas constant = 8.314472 J/mol*K # R gas constant = 8.314472 J/(mol*K) # R
[fuel consumpt.] [fuel consumpt.]
mpg = mi/gal # miles/gallon mpg = mi/gal # miles/gallon
mpg imp = mi/gallon imperial # miles/gallon imp
liter per 100 km = [mpg] 3.785411784 / (x * 0.01609344) ; \ liter per 100 km = [mpg] 3.785411784 / (x * 0.01609344) ; \
3.785411784 / (x * 0.01609344) # # non-linear 3.785411784 / (x * 0.01609344) # # non-linear
[permeability]
darcy = 1 cm^2*centipoise/atm/s
millidarcy = 0.001 darcy
""" """
@ -937,7 +999,7 @@ class UnitGroup:
if count > 5000: if count > 5000:
raise UnitDataError('Circular unit definition') raise UnitDataError('Circular unit definition')
unit = tmpList.pop(0) unit = tmpList.pop(0)
if unit.equiv == '!': if unit.equiv in ('!', '!!'):
self.reducedList.append(copy.copy(unit)) self.reducedList.append(copy.copy(unit))
elif not unit.equiv: elif not unit.equiv:
raise UnitDataError('Invalid conversion for "%s"' % unit.name) raise UnitDataError('Invalid conversion for "%s"' % unit.name)