From b6c75a70d398bea95e60c7fb7fadc4defe143d71 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 29 Sep 2017 16:02:36 -0700 Subject: [PATCH] Math: sync convertcore unit data with ConvertAll 0.7.2 Also add in a special case for handling the new unitless unit ("!!") --- plugins/Math/local/convertcore.py | 452 +++++++++++++++++------------- 1 file changed, 257 insertions(+), 195 deletions(-) diff --git a/plugins/Math/local/convertcore.py b/plugins/Math/local/convertcore.py index 3357123b5..42948c791 100644 --- a/plugins/Math/local/convertcore.py +++ b/plugins/Math/local/convertcore.py @@ -16,38 +16,40 @@ import copy 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 -# 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 # 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 -# combination. A python expression may be used for the quantity, but is -# resticted to using only the following operators: *, /, +, -, **, (, ). -# Beware of integer division truncation: be sure to use a float for at -# least one of the values. +# combination. A Python expression may be used for the quantity, but is +# restricted to using only the following operators: *, /, +, -. +# Beware of integer division truncation: be sure to use a float for at least +# one of the values. # -# The unit type must be placed in square brackets before a set of units. -# The first comment after the equivalent unit will be put in parenthesis after -# the unit name (usually used to give the full name of an abbreviated unit). -# The next comment will be used in the program list's comment column; -# later comments and full line comments are ignored. +# The unit type must be placed in square brackets before a set of units. The +# first comment after the equivalent unit will be put in parenthesis after the +# unit name (usually used to give the full name of an abbreviated unit). The +# next comment will be used in the program list's comment column; later +# comments and full line comments are ignored. # # Non-linear units are indicated with an equivalent unit in square brackets, -# followed by either equations or equivalency lists for the definition. -# For equations, two are given, separated by a ';'. Both are functions of -# "x", the first going from the unit to the equivalent unit and the second -# one in reverse. Any valid Python expression returning a float (including -# the functions in the math module) should work. The equivalency list is a -# python list of tuples giving points for linear interpolation. +# followed by either equations or equivalency lists for the definition. For +# equations, two are given, separated by a ';'. Both are functions of "x", the +# first going from the unit to the equivalent unit and the second one in +# reverse. Any valid Python expression returning a float (including the +# functions in the math module) should work. The equivalency list is a Python +# list of tuples giving points for linear interpolation. # -# All units must reduce to primitive units, which are indicated by an '!' -# as the equivalent unit. Circular refernces must also be avoided. +# All units must reduce to primitive units, which are indicated by an +# 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 # @@ -57,127 +59,152 @@ unitData = \ # mass units # [mass] -kg = ! # kilogram -kilogram = kg -key = kg # # drug slang -hectogram = 100 gram -dekagram = 10 gram -gram = 0.001 kg -g = gram # gram -decigram = 0.1 gram -centigram = 0.01 gram -milligram = 0.001 gram -mg = milligram # milligram -microgram = 0.001 mg -tonne = 1000 kg # # metric -metric ton = tonne -megagram = tonne -kilotonne = 1000 tonne # # metric -gigagram = 1e9 gram -teragram = 1e12 gram -carat = 0.2 gram -ct = carat # carat -amu = 1.66053873e-27 kg # atomic mass -atomic mass unit = amu -pound = 0.45359237 kg -lb = pound # pound -lbm = pound # pound -ounce = 1/16.0 pound -oz = ounce # ounce -lid = ounce # # drug slang -pound troy = 5760 grain -lb troy = pound troy # pound troy -ounce troy = 1/12.0 lb troy -oz troy = ounce troy # ounce troy -ton = 2000 lb # # non-metric -kiloton = 1000 ton # # non-metric -slug = lbf*s^2/ft -stone = 14 lb -grain = 1/7000.0 lb +kg = ! # kilogram +kilogram = kg +key = kg # # drug slang +hectogram = 100 gram +dekagram = 10 gram +gram = 0.001 kg +g = gram # gram +decigram = 0.1 gram +centigram = 0.01 gram +milligram = 0.001 gram +mg = milligram # milligram +microgram = 0.001 mg +tonne = 1000 kg # # metric +metric ton = tonne +megagram = tonne +kilotonne = 1000 tonne # # metric +gigagram = 1e9 gram +teragram = 1e12 gram +carat = 0.2 gram +ct = carat # carat +amu = 1.66053873e-27 kg # atomic mass +atomic mass unit = amu +pound = 0.45359237 kg # # avoirdupois +lb = pound # pound # avoirdupois +lbm = pound # pound # avoirdupois +ounce = 1/16.0 pound # # avoirdupois +oz = ounce # ounce # avoirdupois +lid = ounce # # drug slang +dram = 1/16.0 ounce # # avoirdupois +pound troy = 5760 grain +lb troy = pound troy # pound troy +ounce troy = 1/12.0 lb troy +oz troy = ounce troy # ounce troy +ton = 2000 lb # # non-metric +kiloton = 1000 ton # # non-metric +long ton = 2240 lb # # Imperial +ton imperial = long ton +slug = lbf*s^2/ft +stone = 14 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 # # length / distance units # [length] -m = ! # meter -meter = m -metre = m -decimeter = 0.1 m -cm = 0.01 m # centimeter -centimeter = cm -mm = 0.001 m # millimeter -millimeter = mm -micrometer = 1e-6 m -micron = micrometer -nanometer = 1e-9 m -nm = nanometer # nanometer -dekameter = 10 m -hectometer = 100 m -km = 1000 m # kilometer -kilometer = km -megameter = 1000 km -angstrom = 1e-10 m -fermi = 1e-15 m # # nuclear sizes -inch = 2.54 cm -in = inch # inch -inches = inch -mil = 0.001 inch -microinch = 1e-6 inch -microinches = microinch -foot = 12 inch -ft = foot # foot -feet = foot -yard = 3 ft -yd = yard # yard -mile = 5280 ft -mi = mile # mile -nautical mile = 1852 m -nmi = nautical mile # nautical mile -league = 3 mile -chain = 66 ft -fathom = 6 ft -rod = 5.5 yard -furlong = 40 rod -hand = 4 inch -cubit = 21.8 inch # # biblical unit -point = 1/72.27 inch -pica = 12 point -caliber = 0.01 inch # # bullet sizes -football field = 100 yd -marathon = 46145 yd -mil Swedish = 10 km -au = 1.49597870691e11 m # astronomical unit -astronomical unit = au -light year = 365.25 light speed * day -light minute = light speed * min -light second = light speed * s -parsec = 3.0856775813e16 m -kiloparsec = 1000 parsec -megaparsec = 1000 kiloparsec -screw size = [in] 0.013*x + 0.06 ; (x - 0.06) / 0.013 \ - # # Unified diameters, non-linear -AWG = [in] 92.0**((36-x)/39.0)/200.0 ; \ - 36 - 39.0*log(200.0*x)/log(92.0) \ - # American Wire Gauge \ - # use -1, -2 for 00, 000; non-linear -American Wire Gauge = [in] 92.0**((36-x)/39.0)/200.0 ; \ - 36 - 39.0*log(200.0*x)/log(92.0) \ - # # use -1, -2 for 00, 000; non-linear -standard gauge = [in] [(-5, .448350), (1, .269010), (14, .0747250), \ - (16, .0597800), (17, .0538020), (20, .0358680), \ - (26, .0179340), (31, .0104615), (36, .00672525), \ - (38, .00597800)] # steel \ - # Manufacturers Std. Gauge, non-linear -zinc gauge = [in] [(1, .002), (10, .02), (15, .04), (19, .06), \ - (23, .1), (24, .125), (27, .5), (28, 1)] \ - # # sheet metal thickness, non-linear -ring size = [in] 0.1018*x + 1.4216 ; (x - 1.4216) / 0.1018 \ - # # US size, circum., non-linear -shoe size mens = [in] x/3.0 + 7 + 1/3.0 ; (x - 7 - 1/3.0) * 3 \ - # # US sizes, non-linear -shoe size womens = [in] x/3.0 + 6 + 5/6.0 ; (x - 6 - 5/6.0) * 3 \ - # # US sizes, non-linear +m = ! # meter +meter = m +metre = m +dm = 0.1 m # decimeter +decimeter = dm +cm = 0.01 m # centimeter +centimeter = cm +mm = 0.001 m # millimeter +millimeter = mm +micrometer = 1e-6 m +micron = micrometer +nanometer = 1e-9 m +nm = nanometer # nanometer +dekameter = 10 m +hectometer = 100 m +km = 1000 m # kilometer +kilometer = km +megameter = 1000 km +angstrom = 1e-10 m +fermi = 1e-15 m # # nuclear sizes +inch = 2.54 cm +in = inch # inch +inches = inch +mil = 0.001 inch +microinch = 1e-6 inch +microinches = microinch +foot = 12 inch +ft = foot # foot +feet = foot +foot US survey = 1200/3937.0 m +Cape foot = 1.033 foot +yard = 3 ft +yd = yard # yard +mile = 5280 ft # # statute mile +mi = mile # mile # statute mile +nautical mile = 1852 m +nmi = nautical mile # nautical mile +mile US survey = 5280 foot US survey +league = 3 mile +chain = 66 ft +chain US survey = 66 foot US survey +link = 0.01 chain +fathom = 6 ft +cable = 0.1 nautical mile +rod = 5.5 yard +furlong = 40 rod +hand = 4 inch +cubit = 21.8 inch # # biblical unit +point = 1/72.0 inch # # desktop publishing point +pica = 12 point +caliber = 1.0 inch # # bullet sizes +rack unit = 1.75 in # # computing +smoot = 67 inch +football field = 100 yd +marathon = 46145 yd +mil Swedish = 10 km +versta = 3500 ft # # Russian unit +au = 1.49597870691e11 m # astronomical unit +astronomical unit = au +LD = 384400 km # lunar distance # astronomical +lunar distance = LD # # astronomical distance +light year = 365.25 light speed * day +light minute = light speed * min +light second = light speed * s +parsec = 3.0856775813e16 m +kiloparsec = 1000 parsec +megaparsec = 1000 kiloparsec +screw size = [in] 0.013*x + 0.06 ; (x - 0.06) / 0.013 \ + # # Unified diameters, non-linear +AWG Dia = [in] pow(92.0,(36-x)/39.0)/200.0 ; \ + 36 - 39.0*log(200.0*x)/log(92.0) \ + # American Wire Gauge \ + # use -1, -2 for 00, 000; non-linear +American Wire Gauge Dia = [in] pow(92.0,(36-x)/39.0)/200.0 ; \ + 36 - 39.0*log(200.0*x)/log(92.0) \ + # # 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), \ + (16, .0597800), (17, .0538020), (20, .0358680), \ + (26, .0179340), (31, .0104615), (36, .00672525), \ + (38, .00597800)] # steel \ + # Manufacturers Std. Gauge, non-linear +zinc gauge = [in] [(1, .002), (10, .02), (15, .04), (19, .06), \ + (23, .1), (24, .125), (27, .5), (28, 1)] \ + # # sheet metal thickness, non-linear +ring size = [in] 0.1018*x + 1.4216 ; (x - 1.4216) / 0.1018 \ + # # US size, circum., non-linear +shoe size mens = [in] x/3.0 + 7 + 1/3.0 ; (x - 7 - 1/3.0) * 3 \ + # # US sizes, non-linear +shoe size womens = [in] x/3.0 + 6 + 5/6.0 ; (x - 6 - 5/6.0) * 3 \ + # # US sizes, non-linear # @@ -289,6 +316,7 @@ picofarad = 1e-12 farad [magn. flux] weber = V*s Wb = weber # weber +maxwell = 1e-8 Wb [inductance] henry = Wb/A H = henry # henry @@ -298,6 +326,7 @@ microhenry = 0.001 mH [flux density] tesla = Wb/m^2 T = tesla # tesla +gauss = maxwell/cm^2 # @@ -312,7 +341,7 @@ kmol = kilomole # kilomole pound mole = mol*lbm/gram lbmol = pound mole # pound mole [size of a mol] -avogadro = gram/amu*mol +avogadro = gram/(amu*mol) # @@ -332,9 +361,9 @@ footcandle = lumen/ft^2 metercandle = lumen/m^2 [luminance] -lambert = cd/pi*cm^2 +lambert = cd/(pi*cm^2) 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 # [quantity] -unit = ! +unit = !! 1 = unit # unit pi = 3.14159265358979323846 unit pair = 2 unit @@ -458,41 +487,56 @@ carat gold = karat # # gold purity # [force] newton = kg*m/s^2 -N = newton # newton +N = newton # newton dekanewton = 10 newton kilonewton = 1000 N -kN = kilonewton # kilonewton +kN = kilonewton # kilonewton meganewton = 1000 kN millinewton = 0.001 N dyne = cm*g/s^2 -kg force = kg * gravity # kilogram f -kgf = kg force # kilogram force +kg force = kg * gravity # kilogram f +kgf = kg force # kilogram force kilogram force = kg force +kp = kg force # kilopond +kilopond = kg force gram force = g * gravity -pound force = lbm * gravity -lbf = pound force # pound force +pound force = lbm * gravity # # avoirdupois +lbf = pound force # pound force # avoirdupois ton force = ton * 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 # # area units # [area] -barn = 1e-28 m^2 # # particle physics -are = 100 m^2 -decare = 10 are -dekare = 10 are -hectare = 100 are -acre = 10 chain^2 -section = mile^2 -township = 36 section -homestead = 160 acre -rai = 1600 m^2 # # Thai -ngaan = 400 m^2 # # Thai -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 +barn = 1e-28 m^2 # # particle physics +are = 100 m^2 +decare = 10 are +dekare = 10 are +hectare = 100 are +stremma = 1000 m^2 +acre = 10 chain^2 +section = mile^2 +township = 36 section +homestead = 160 acre +square perch = 30.25 yd^2 +rood = 0.25 acre +rai = 1600 m^2 # # Thai +ngaan = 400 m^2 # # Thai +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 +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 milliliter = cc ml = milliliter # milliliter +microliter = 1e-6 liter dekaliter = 10 liter hectoliter = 100 liter kiloliter = 1000 liter @@ -522,6 +567,8 @@ pt = pint # pint # US liquid fluid ounce = 1/16.0 pint # # US fl oz = fluid ounce # 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 imp gal = imperial gallon # imperial gallon gallon imperial = imperial gallon @@ -533,6 +580,8 @@ imp pt = imperial pint # imperial pint pint imperial = imperial pint imperial fluid ounce = 1/160.0 imp gal 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 tablespoon = 1/16.0 cup tbsp = tablespoon # tablespoon @@ -613,19 +662,20 @@ megabar = 1000 kilobar mm Hg = mm*density Hg*gravity millimeter of Hg = mm Hg torr = mm Hg +micron of Hg = micron*density Hg*gravity in Hg = in*density Hg*gravity # inch of Hg inch of Hg = in Hg -m water = m*density water*gravity # meter of H2O -m H2O = m water # meter of H2O -meter of water = m water -in water = in*density water*gravity # inch of H2O -in H2O = in water # inch of H2O -inch of water = in water -ft water = ft*density water*gravity # feet of H2O -ft H2O = ft water # feet of H20 -feet of water = ft water -foot of head = ft water -ft hd = ft water # foot of head +m water = m*density water*gravity # meter of H2O # fresh water +m H2O = m water # meter of H2O # fresh water +meter of water = m water # # fresh water +in water = in*density water*gravity # inch of H2O # fresh water +in H2O = in water # inch of H2O # fresh water +inch of water = in water # # fresh water +ft water = ft*density water*gravity # feet of H2O # fresh water +ft H2O = ft water # feet of H20 # fresh water +feet of water = ft water # # fresh water +foot of head = ft water # # fresh water +ft hd = ft water # foot of head # fresh water psi = lbf/in^2 # pound / sq inch pound per sq inch = psi ksi = 1000 psi # 1000 lb / sq inch @@ -657,27 +707,31 @@ density polycarbonate = 0.045 lb/in^3 # energy units # [energy] -joule = N*m -J = joule # joule -kilojoule = 1000 joule -kJ = kilojoule # kilojoule -megajoule = 1000 kilojoule -gigajoule = 1000 megajoule -millijoule = 0.001 joule -mJ = millijoule # millijoule -calorie = 4.1868 J -cal = calorie # calorie -kilocalorie = 1000 cal -kcal = kilocalorie # kilocalorie -calorie food = kilocalorie -Btu = cal*lb*R/g*K # British thermal unit -British thermal unit = Btu -erg = cm*dyne -electronvolt = 1.602176462e-19 J -eV = electronvolt # electronvolt -kWh = kW*hour # kilowatt-hour -kilowatt hour = kWh -ton TNT = 4.184e9 J +joule = N*m +J = joule # joule +kilojoule = 1000 joule +kJ = kilojoule # kilojoule +megajoule = 1000 kilojoule +gigajoule = 1000 megajoule +millijoule = 0.001 joule +mJ = millijoule # millijoule +calorie = 4.1868 J +cal = calorie # calorie +kilocalorie = 1000 cal +kcal = kilocalorie # kilocalorie +calorie food = kilocalorie +thermie = 1000 kcal +Btu = cal*lb*R/(g*K) # British thermal unit +British thermal unit = Btu +therm = 100000 Btu +erg = cm*dyne +electronvolt = 1.602176462e-19 J +eV = electronvolt # electronvolt +kWh = kW*hour # kilowatt-hour +kilowatt hour = kWh +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 hp = horsepower # horsepower 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] gray = J/kg 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 millisievert = 0.001 sievert # # equiv. dose Sv = sievert # sievert # equiv. dose @@ -737,7 +794,7 @@ millirem = 0.001 rem # # roentgen equiv mammal # viscosity # [dyn viscosity] -poise = g/cm*s +poise = g/(cm*s) P = poise # poise centipoise = 0.01 poise cP = centipoise # centipoise @@ -754,13 +811,18 @@ cSt = centistokes # centistokes # [acceleration] gravity = 9.80665 m/s^2 +galileo = cm/s^2 [constant] 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.] mpg = mi/gal # miles/gallon +mpg imp = mi/gallon imperial # miles/gallon imp liter per 100 km = [mpg] 3.785411784 / (x * 0.01609344) ; \ 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: raise UnitDataError('Circular unit definition') unit = tmpList.pop(0) - if unit.equiv == '!': + if unit.equiv in ('!', '!!'): self.reducedList.append(copy.copy(unit)) elif not unit.equiv: raise UnitDataError('Invalid conversion for "%s"' % unit.name)