123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- <manpage cat="package" id="units" title="units" package="units" version="1.0">
- <!--
- units package documentation
- Robert W. Techentin
- October 31, 2000
- Copyright 2000-2004 Mayo Foundation. All Rights Reserved.
- $Id: units.xml,v 1.2 2004/02/05 22:24:22 techenti Exp $
-
- This documentation accompanies the units converter package
- written by the author. It is intended to be processed by
- the TMML package by Joe English, which requires the SAXON
- SSL processor.
- % saxon units.xml tmml-html.xsl > units.html
- -->
- <namesection>
- <name>units</name>
- <desc>Convert and manipulate quantities with units</desc>
- </namesection>
- <synopsis>
- <syntax>
- package require units ?1.0?
- units::convert <m>value</m> <m>targetUnits</m>
- units::reduce <m>unitString</m>
- units::new <m>name</m> <m>baseUnits</m>
- </syntax>
- </synopsis>
- <section>
- <title>DESCRIPTION</title>
- <p>
- This library provides a conversion facility from a variety of
- scientific and engineering shorthand notations into floating point
- numbers. This allows application developers to easily convert
- values with different units into uniformly scaled numbers.
- </p>
- <p>
- The units conversion facility is also able to convert between
- compatible units. If, for example, a application is expecting a value
- in <samp>ohms</samp> (Resistance), and the user specifies units of
- <samp>milliwebers/femtocoulomb</samp>, the conversion routine will
- handle it appropriately. An error will be generated if an incorrect
- conversion is attempted.
- </p>
- <p>
- Values are scaled from one set of units to another by dimensional
- analysis. Both the value units and the target units are reduced into
- primitive units and a scale factor. Units are checked for
- compatibility, and the scale factors are applied by multiplication and
- division. This technique is extremely flexible and quite robust.
- </p>
- <p>
- New units and new unit abbreviations can be defined in terms of
- existing units and abbreviations. It is also possible to define a new
- primitive unit, although that will probably be unnecessary. New units
- will most commonly be defined to accommodate non-SI measurement
- systems, such as defining the unit <samp>inch</samp> as <samp>"2.54
- cm"</samp>.
- </p>
- </section>
- <section>
- <title>COMMANDS</title>
- <commandlist>
- <commanddef>
- <command>units::convert <m>value</m> <m>targetUnits</m> </command>
- <desc>
- Converts the value string into a floating point number, scaled to the
- specified <m>targetUnits</m>. The <m>value</m> string may contain a
- number and units. If units are specified, then they must be
- compatible with the <m>targetUnits</m>. If units are not specified
- for the <m>value</m>, then it will be scaled to the target units. For
- example, scaling <samp>"1.0"</samp> to <samp>"millimeter"</samp> would
- result in <samp>"1000.0"</samp>.
- </desc>
- </commanddef>
- <commanddef>
- <command>units::reduce <m>unitString</m> </command>
- <desc>
- Returns a unit string consisting of a scale factor followed by a space
- separated list of sorted and reduced primitive units. The reduced
- unit string may include a forward-slash (separated from the
- surrounding primitive subunits by spaces) indicating that the
- remaining subunits are in the denominator. Generates an error if the
- <m>unitString</m> is invalid.
- </desc>
- </commanddef>
- <commanddef>
- <command>units::new <m>name</m> <m>baseUnits</m> </command>
- <desc>
- Creates a new unit conversion with the specified name. The new unit
- <m>name</m> must be only alphabetic (upper or lower case) letters.
- The <m>baseUnits</m> string can consist of any valid units conversion
- string, including constant factors, numerator and denominator parts,
- units with prefixes, and exponents. The baseUnits may contain any
- number of subunits, but it must reduce to primitive units. BaseUnits
- could also be the string <samp>"-primitive"</samp> to represent a new
- kind of quantity which cannot be derived from other units. But you
- probably would not do that unless you have discovered some kind of new
- univeral property.
- </desc>
- </commanddef>
- </commandlist>
- </section>
- <section>
- <title>Unit String Format</title>
- <p>
- Value and unit string format is quite flexible. It is possible to
- define virtually any combination of units, prefixes, and powers.
- Valid unit strings must conform to these rules.
- </p>
- <ul>
- <li>
- A unit string consists of an optional scale factor followed by zero or
- more subunits. The scale factor must be a valid floating point
- number, and may or may not be separated from the subunits. The scale
- factor could be negative.
- </li>
- <li>
- Subunits are separated form each other by one or more separator
- characters, which are space (" "), hyphen ("-"), asterisk ("*"), and
- forward-slash ("/"). Sure, go ahead and complain about using a minus
- sign ("-") to represent multiplication. It just isn't sound
- mathematics, and, by rights, we should require everyone to use the
- asterisk ("*") to separate all units. But the bottom line is that
- complex unit strings like <samp>"m-kg/s^2"</samp> are pleasantly
- readable.
- </li>
- <li>
- The forward-slash seperator ("/") indicates that following subunits are
- in the denominator. There can be at most one forward-slash separator.
- </li>
- <li>
- Subunits can be floating point scale factors, but with the exception
- of the leading scale factor, they must be surrounded by valid
- separators. Subunit scale factors cannot be negative. (Remember that
- the hyphen is a unit separator.)
- </li>
- <li>
- Subunits can be valid units or abbreviations. They may include a
- prefix. They may include a plural suffix "s" or "es". They may also
- include a power string denoted by a circumflex ("^"), followed by a
- integer, after the unit name (or plural suffix, if there is one).
- Negative exponents are not allowed. (Remember that the hyphen is a
- unit separator.)
- </li>
- </ul>
- <subsection>
- <title> Example valid unit strings </title>
- <example>
- Unit String Reduced Unit String
- ------------------------------------------------------------
- meter 1.0 meter
- kilometer 1000.0 meter
- km 1000.0 meter
- km/s 1000.0 meter / second
- /microsecond 1000000.0 / second
- /us 1000000.0 / second
- kg-m/s^2 1000.0 gram meter / second second
- 30second 30.0 second
- 30 second 30.0 second
- 30 seconds 30.0 second
- 200*meter/20.5*second 9.75609756098 meter / second
- </example>
- </subsection>
- </section>
- <section>
- <title>SI UNITS</title>
- <p>
- The standard SI units are predefined according to <emph>NIST Special
- Publication 330</emph>. Standard units for both SI Base Units (Table
- 1) and SI Derived Units with Special Names (Tables 3a and 3b) are
- included here for reference. Each standard unit name and abbreviation
- are included in this package.
- </p>
- <subsection>
- <title>SI Base Units</title>
- <example>
- Quantity Unit Name Abbr.
- ---------------------------------------------
- Length meter m
- Mass kilogram kg
- Time second s
- Current ampere A
- Temperature kelvin K
- Amount mole mol
- Luminous Intensity candela cd
- </example>
- </subsection>
- <subsection>
- <title>SI Derived Units with Special Names</title>
- <example>
- Quantity Unit Name Abbr. Units Base Units
- --------------------------------------------------------------------
- plane angle radian rad m/m m/m
- solid angle steradian sr m^2/m^2 m^2/m^2
- frequency hertz Hz /s
- force newton N m-kg/s^2
- pressure pascal Pa N/m^2 kg/m-s^2
- energy, work joule J N-m m^2-kg/s^2
- power, radiant flux watt W J/s m^2-kg/s^3
- electric charge coulomb C s-A
- electric potential volt V W/A m^2-kg/s^3-A
- capacitance farad F C/V s^4-A^2/m^2-kg
- electric resistance ohm V/A m^2-kg/s^3-A^2
- electric conductance siemens S A/V s^3-A^2/m^2-kg
- magnetic flux weber Wb V-s m^2-kg/s^2-A
- magnetic flux density tesla T Wb/m^2 kg/s^2-A
- inductance henry H Wb/A m^2-kg/s^2-A^2
- luminous flux lumen lm cd-sr
- illuminance lux lx lm/m^2 cd-sr/m^2
- activity (of a
- radionuclide) bacquerel Bq /s
- absorbed dose gray Gy J/kg m^2/s^2
- dose equivalent sievert Sv J/kg m^2/s^2
- </example>
- <p>
- Note that the SI unit kilograms is actually implemented as grams
- because 1e-6 kilogram = 1 milligram, not 1 microkilogram. The
- abbreviation for Electric Resistance (ohms), which is the omega
- character, is not supported. Also note that there is no support for
- Celsius temperature. The units conversion routines can only scale
- values with multiplication and division, and the abbreviation "C"
- (which is the closest one could get to "degrees C" using the degrees
- symbol) is already used by Electric Potential.
- </p>
- </subsection>
- <p>
- SI Units can have a multiple or sub-multiple prefix. The prefix or its
- abbreviation should appear before the unit, without spaces. Compound
- prefixes are not allowed, and a prefix should never be used alone.
- These prefixes are defined in Table 5 of <emph>Special Publication
- 330</emph>.
- </p>
- <subsection>
- <title>SI Prefixes</title>
- <example>
- Prefix Name Abbr. Factor
- ---------------------------------------
- yotta Y 1e24
- zetta Z 1e21
- exa E 1e18
- peta P 1e15
- tera T 1e12
- giga G 1e9
- mega M 1e6
- kilo k 1e3
- hecto h 1e2
- deka da 1e1
- deca 1e1
- deci d 1e-1
- centi c 1e-2
- milli m 1e-3
- micro u 1e-6
- nano n 1e-9
- pico p 1e-12
- femto f 1e-15
- atto a 1e-18
- zepto z 1e-21
- yocto y 1e-24
- </example>
- </subsection>
- <p>
- Note that we define the same prefix with both the USA ("deka") and
- non-USA ("deca") spellings. Also note that we take the liberty of
- allowing "micro" to be typed as a "u" instead of the Greek character
- mu.
- </p>
- <p>
- Many non-SI units are commonly used in applications. Appendix B.8 of
- <emph>NIST Special Publication 811</emph> lists many non-SI conversion
- factors. It is not possible to include all possible unit definitions
- in this package. In some cases, many different conversion factors
- exist for a given unit, depending on the context. (The appendix lists
- over 40 conversions for British thermal units!) Application specific
- conversions can always be added using the <command>new</command>
- command, but some well known and often used conversions are included
- in this package.
- </p>
- <subsection>
- <title>Non-SI Units</title>
- <example>
- Unit Name Abbr. Base Units
- --------------------------------------------------
- angstrom 1.0E-10 m
- astronomicalUnit AU 1.495979E11 m
- atmosphere 1.01325E5 Pa
- bar 1.0E5 Pa
- calorie 4.1868 J
- curie 3.7E10 Bq
- day 8.64E4 s
- degree 1.745329E-2 rad
- erg 1.0E-7 J
- faraday 9.648531 C
- fermi 1.0E-15 m
- foot ft 3.048E-1 m
- gauss 1.0E-4 T
- gilbert 7.957747E-1 A
- grain gr 6.479891E-5 kg
- hectare ha 1.0E4 m^2
- hour h 3.6E3 s
- inch in 2.54E-2 m
- lightYear 9.46073E15 m
- liter L 1.0E-3 m^3
- maxwell Mx 1.0E-8 Wb
- mho 1.0 S
- micron 1.0E-6 m
- mil 2.54E-5 m
- mile mi 1.609344E3 m
- minute min 6.0E1 s
- parsec pc 3.085E16 m
- pica 4.233333E-3 m
- pound lb 4.535924E-1 kg
- revolution 6.283185 rad
- revolutionPerMinute rpm 1.047198E-1 rad/s
- yard 9.144E-1 m
- year yd 3.1536E7 s
- </example>
- </subsection>
- <subsection>
- <title>Quantities and Derived Units with Special Names</title>
- <p>
- This units conversion package is limited specifically to unit
- reduction, comparison, and scaling. This package does not consider
- any of the quantity names for either base or derived units. A similar
- implementation or an extension in a typed or object-oriented language
- might introduce user defined types for the quantities. Quantity type
- checking could be used, for example, to ensure that all
- <samp>"length"</samp> values properly reduced to <samp>"meters"</samp>, or
- that all <samp>"velocity"</samp> values properly reduced to
- <samp>"meters/second"</samp>.
- </p>
- <p>
- A C implementation of this package has been created to work in
- conjunction with the Simplified Wrapper Interface Generator
- (http://www.swig.org). That package (units.i) exploits SWIG's typemap
- system to automatically convert script quantity strings into floating
- point quantities. Function arguments are specified as quantity types
- (e.g., <samp>typedef float Length</samp>), and target units (expected
- by the C application code) are specified in an associative array.
- Default units are also defined for each quantity type, and are applied
- to any unit-less quantity strings.
- </p>
- <p>
- A units system enhanced with quantity type checking might benefit from
- inclusion of other derived types which are expressed in terms of
- special units, as illustrated in Table 2 of <emph>NIST Publication
- 330</emph>. The quantity <samp>"area"</samp>, for example, could be
- defined as units properly reducing to <samp>"meter^2"</samp>, although
- the utility of defining a unit named <samp>"square meter"</samp> is
- arguable.
- </p>
- </subsection>
- </section>
- <section>
- <title>REFERENCES</title>
- <p>
- The unit names, abbreviations, and conversion values are derived from
- those published by the United States Department of Commerce Technology
- Administration, National Institute of Standards and Technology (NIST)
- in <emph>NIST Special Publication 330: The International System of
- Units (SI)</emph> and <emph>NIST Special Publication 811: Guide for
- the Use of the International System of Units (SI)</emph>. Both of
- these publications are available (as of December 2000) from
- http://physics.nist.gov/cuu/Reference/contents.html
- </p>
- <p>
- The ideas behind implementation of this package is based in part on
- code written in 1993 by Adrian Mariano which performed dimensional
- analysis of unit strings using fixed size tables of C structs.
- </p>
- </section>
- <keywords>
- <keyword>unit</keyword>
- <keyword>convert</keyword>
- </keywords>
- </manpage>
|