units.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <manpage cat="package" id="units" title="units" package="units" version="1.0">
  2. <!--
  3. units package documentation
  4. Robert W. Techentin
  5. October 31, 2000
  6. Copyright 2000-2004 Mayo Foundation. All Rights Reserved.
  7. $Id: units.xml,v 1.2 2004/02/05 22:24:22 techenti Exp $
  8. This documentation accompanies the units converter package
  9. written by the author. It is intended to be processed by
  10. the TMML package by Joe English, which requires the SAXON
  11. SSL processor.
  12. % saxon units.xml tmml-html.xsl > units.html
  13. -->
  14. <namesection>
  15. <name>units</name>
  16. <desc>Convert and manipulate quantities with units</desc>
  17. </namesection>
  18. <synopsis>
  19. <syntax>
  20. package require units ?1.0?
  21. units::convert <m>value</m> <m>targetUnits</m>
  22. units::reduce <m>unitString</m>
  23. units::new <m>name</m> <m>baseUnits</m>
  24. </syntax>
  25. </synopsis>
  26. <section>
  27. <title>DESCRIPTION</title>
  28. <p>
  29. This library provides a conversion facility from a variety of
  30. scientific and engineering shorthand notations into floating point
  31. numbers. This allows application developers to easily convert
  32. values with different units into uniformly scaled numbers.
  33. </p>
  34. <p>
  35. The units conversion facility is also able to convert between
  36. compatible units. If, for example, a application is expecting a value
  37. in <samp>ohms</samp> (Resistance), and the user specifies units of
  38. <samp>milliwebers/femtocoulomb</samp>, the conversion routine will
  39. handle it appropriately. An error will be generated if an incorrect
  40. conversion is attempted.
  41. </p>
  42. <p>
  43. Values are scaled from one set of units to another by dimensional
  44. analysis. Both the value units and the target units are reduced into
  45. primitive units and a scale factor. Units are checked for
  46. compatibility, and the scale factors are applied by multiplication and
  47. division. This technique is extremely flexible and quite robust.
  48. </p>
  49. <p>
  50. New units and new unit abbreviations can be defined in terms of
  51. existing units and abbreviations. It is also possible to define a new
  52. primitive unit, although that will probably be unnecessary. New units
  53. will most commonly be defined to accommodate non-SI measurement
  54. systems, such as defining the unit <samp>inch</samp> as <samp>"2.54
  55. cm"</samp>.
  56. </p>
  57. </section>
  58. <section>
  59. <title>COMMANDS</title>
  60. <commandlist>
  61. <commanddef>
  62. <command>units::convert <m>value</m> <m>targetUnits</m> </command>
  63. <desc>
  64. Converts the value string into a floating point number, scaled to the
  65. specified <m>targetUnits</m>. The <m>value</m> string may contain a
  66. number and units. If units are specified, then they must be
  67. compatible with the <m>targetUnits</m>. If units are not specified
  68. for the <m>value</m>, then it will be scaled to the target units. For
  69. example, scaling <samp>"1.0"</samp> to <samp>"millimeter"</samp> would
  70. result in <samp>"1000.0"</samp>.
  71. </desc>
  72. </commanddef>
  73. <commanddef>
  74. <command>units::reduce <m>unitString</m> </command>
  75. <desc>
  76. Returns a unit string consisting of a scale factor followed by a space
  77. separated list of sorted and reduced primitive units. The reduced
  78. unit string may include a forward-slash (separated from the
  79. surrounding primitive subunits by spaces) indicating that the
  80. remaining subunits are in the denominator. Generates an error if the
  81. <m>unitString</m> is invalid.
  82. </desc>
  83. </commanddef>
  84. <commanddef>
  85. <command>units::new <m>name</m> <m>baseUnits</m> </command>
  86. <desc>
  87. Creates a new unit conversion with the specified name. The new unit
  88. <m>name</m> must be only alphabetic (upper or lower case) letters.
  89. The <m>baseUnits</m> string can consist of any valid units conversion
  90. string, including constant factors, numerator and denominator parts,
  91. units with prefixes, and exponents. The baseUnits may contain any
  92. number of subunits, but it must reduce to primitive units. BaseUnits
  93. could also be the string <samp>"-primitive"</samp> to represent a new
  94. kind of quantity which cannot be derived from other units. But you
  95. probably would not do that unless you have discovered some kind of new
  96. univeral property.
  97. </desc>
  98. </commanddef>
  99. </commandlist>
  100. </section>
  101. <section>
  102. <title>Unit String Format</title>
  103. <p>
  104. Value and unit string format is quite flexible. It is possible to
  105. define virtually any combination of units, prefixes, and powers.
  106. Valid unit strings must conform to these rules.
  107. </p>
  108. <ul>
  109. <li>
  110. A unit string consists of an optional scale factor followed by zero or
  111. more subunits. The scale factor must be a valid floating point
  112. number, and may or may not be separated from the subunits. The scale
  113. factor could be negative.
  114. </li>
  115. <li>
  116. Subunits are separated form each other by one or more separator
  117. characters, which are space (" "), hyphen ("-"), asterisk ("*"), and
  118. forward-slash ("/"). Sure, go ahead and complain about using a minus
  119. sign ("-") to represent multiplication. It just isn't sound
  120. mathematics, and, by rights, we should require everyone to use the
  121. asterisk ("*") to separate all units. But the bottom line is that
  122. complex unit strings like <samp>"m-kg/s^2"</samp> are pleasantly
  123. readable.
  124. </li>
  125. <li>
  126. The forward-slash seperator ("/") indicates that following subunits are
  127. in the denominator. There can be at most one forward-slash separator.
  128. </li>
  129. <li>
  130. Subunits can be floating point scale factors, but with the exception
  131. of the leading scale factor, they must be surrounded by valid
  132. separators. Subunit scale factors cannot be negative. (Remember that
  133. the hyphen is a unit separator.)
  134. </li>
  135. <li>
  136. Subunits can be valid units or abbreviations. They may include a
  137. prefix. They may include a plural suffix "s" or "es". They may also
  138. include a power string denoted by a circumflex ("^"), followed by a
  139. integer, after the unit name (or plural suffix, if there is one).
  140. Negative exponents are not allowed. (Remember that the hyphen is a
  141. unit separator.)
  142. </li>
  143. </ul>
  144. <subsection>
  145. <title> Example valid unit strings </title>
  146. <example>
  147. Unit String Reduced Unit String
  148. ------------------------------------------------------------
  149. meter 1.0 meter
  150. kilometer 1000.0 meter
  151. km 1000.0 meter
  152. km/s 1000.0 meter / second
  153. /microsecond 1000000.0 / second
  154. /us 1000000.0 / second
  155. kg-m/s^2 1000.0 gram meter / second second
  156. 30second 30.0 second
  157. 30 second 30.0 second
  158. 30 seconds 30.0 second
  159. 200*meter/20.5*second 9.75609756098 meter / second
  160. </example>
  161. </subsection>
  162. </section>
  163. <section>
  164. <title>SI UNITS</title>
  165. <p>
  166. The standard SI units are predefined according to <emph>NIST Special
  167. Publication 330</emph>. Standard units for both SI Base Units (Table
  168. 1) and SI Derived Units with Special Names (Tables 3a and 3b) are
  169. included here for reference. Each standard unit name and abbreviation
  170. are included in this package.
  171. </p>
  172. <subsection>
  173. <title>SI Base Units</title>
  174. <example>
  175. Quantity Unit Name Abbr.
  176. ---------------------------------------------
  177. Length meter m
  178. Mass kilogram kg
  179. Time second s
  180. Current ampere A
  181. Temperature kelvin K
  182. Amount mole mol
  183. Luminous Intensity candela cd
  184. </example>
  185. </subsection>
  186. <subsection>
  187. <title>SI Derived Units with Special Names</title>
  188. <example>
  189. Quantity Unit Name Abbr. Units Base Units
  190. --------------------------------------------------------------------
  191. plane angle radian rad m/m m/m
  192. solid angle steradian sr m^2/m^2 m^2/m^2
  193. frequency hertz Hz /s
  194. force newton N m-kg/s^2
  195. pressure pascal Pa N/m^2 kg/m-s^2
  196. energy, work joule J N-m m^2-kg/s^2
  197. power, radiant flux watt W J/s m^2-kg/s^3
  198. electric charge coulomb C s-A
  199. electric potential volt V W/A m^2-kg/s^3-A
  200. capacitance farad F C/V s^4-A^2/m^2-kg
  201. electric resistance ohm V/A m^2-kg/s^3-A^2
  202. electric conductance siemens S A/V s^3-A^2/m^2-kg
  203. magnetic flux weber Wb V-s m^2-kg/s^2-A
  204. magnetic flux density tesla T Wb/m^2 kg/s^2-A
  205. inductance henry H Wb/A m^2-kg/s^2-A^2
  206. luminous flux lumen lm cd-sr
  207. illuminance lux lx lm/m^2 cd-sr/m^2
  208. activity (of a
  209. radionuclide) bacquerel Bq /s
  210. absorbed dose gray Gy J/kg m^2/s^2
  211. dose equivalent sievert Sv J/kg m^2/s^2
  212. </example>
  213. <p>
  214. Note that the SI unit kilograms is actually implemented as grams
  215. because 1e-6 kilogram = 1 milligram, not 1 microkilogram. The
  216. abbreviation for Electric Resistance (ohms), which is the omega
  217. character, is not supported. Also note that there is no support for
  218. Celsius temperature. The units conversion routines can only scale
  219. values with multiplication and division, and the abbreviation "C"
  220. (which is the closest one could get to "degrees C" using the degrees
  221. symbol) is already used by Electric Potential.
  222. </p>
  223. </subsection>
  224. <p>
  225. SI Units can have a multiple or sub-multiple prefix. The prefix or its
  226. abbreviation should appear before the unit, without spaces. Compound
  227. prefixes are not allowed, and a prefix should never be used alone.
  228. These prefixes are defined in Table 5 of <emph>Special Publication
  229. 330</emph>.
  230. </p>
  231. <subsection>
  232. <title>SI Prefixes</title>
  233. <example>
  234. Prefix Name Abbr. Factor
  235. ---------------------------------------
  236. yotta Y 1e24
  237. zetta Z 1e21
  238. exa E 1e18
  239. peta P 1e15
  240. tera T 1e12
  241. giga G 1e9
  242. mega M 1e6
  243. kilo k 1e3
  244. hecto h 1e2
  245. deka da 1e1
  246. deca 1e1
  247. deci d 1e-1
  248. centi c 1e-2
  249. milli m 1e-3
  250. micro u 1e-6
  251. nano n 1e-9
  252. pico p 1e-12
  253. femto f 1e-15
  254. atto a 1e-18
  255. zepto z 1e-21
  256. yocto y 1e-24
  257. </example>
  258. </subsection>
  259. <p>
  260. Note that we define the same prefix with both the USA ("deka") and
  261. non-USA ("deca") spellings. Also note that we take the liberty of
  262. allowing "micro" to be typed as a "u" instead of the Greek character
  263. mu.
  264. </p>
  265. <p>
  266. Many non-SI units are commonly used in applications. Appendix B.8 of
  267. <emph>NIST Special Publication 811</emph> lists many non-SI conversion
  268. factors. It is not possible to include all possible unit definitions
  269. in this package. In some cases, many different conversion factors
  270. exist for a given unit, depending on the context. (The appendix lists
  271. over 40 conversions for British thermal units!) Application specific
  272. conversions can always be added using the <command>new</command>
  273. command, but some well known and often used conversions are included
  274. in this package.
  275. </p>
  276. <subsection>
  277. <title>Non-SI Units</title>
  278. <example>
  279. Unit Name Abbr. Base Units
  280. --------------------------------------------------
  281. angstrom 1.0E-10 m
  282. astronomicalUnit AU 1.495979E11 m
  283. atmosphere 1.01325E5 Pa
  284. bar 1.0E5 Pa
  285. calorie 4.1868 J
  286. curie 3.7E10 Bq
  287. day 8.64E4 s
  288. degree 1.745329E-2 rad
  289. erg 1.0E-7 J
  290. faraday 9.648531 C
  291. fermi 1.0E-15 m
  292. foot ft 3.048E-1 m
  293. gauss 1.0E-4 T
  294. gilbert 7.957747E-1 A
  295. grain gr 6.479891E-5 kg
  296. hectare ha 1.0E4 m^2
  297. hour h 3.6E3 s
  298. inch in 2.54E-2 m
  299. lightYear 9.46073E15 m
  300. liter L 1.0E-3 m^3
  301. maxwell Mx 1.0E-8 Wb
  302. mho 1.0 S
  303. micron 1.0E-6 m
  304. mil 2.54E-5 m
  305. mile mi 1.609344E3 m
  306. minute min 6.0E1 s
  307. parsec pc 3.085E16 m
  308. pica 4.233333E-3 m
  309. pound lb 4.535924E-1 kg
  310. revolution 6.283185 rad
  311. revolutionPerMinute rpm 1.047198E-1 rad/s
  312. yard 9.144E-1 m
  313. year yd 3.1536E7 s
  314. </example>
  315. </subsection>
  316. <subsection>
  317. <title>Quantities and Derived Units with Special Names</title>
  318. <p>
  319. This units conversion package is limited specifically to unit
  320. reduction, comparison, and scaling. This package does not consider
  321. any of the quantity names for either base or derived units. A similar
  322. implementation or an extension in a typed or object-oriented language
  323. might introduce user defined types for the quantities. Quantity type
  324. checking could be used, for example, to ensure that all
  325. <samp>"length"</samp> values properly reduced to <samp>"meters"</samp>, or
  326. that all <samp>"velocity"</samp> values properly reduced to
  327. <samp>"meters/second"</samp>.
  328. </p>
  329. <p>
  330. A C implementation of this package has been created to work in
  331. conjunction with the Simplified Wrapper Interface Generator
  332. (http://www.swig.org). That package (units.i) exploits SWIG's typemap
  333. system to automatically convert script quantity strings into floating
  334. point quantities. Function arguments are specified as quantity types
  335. (e.g., <samp>typedef float Length</samp>), and target units (expected
  336. by the C application code) are specified in an associative array.
  337. Default units are also defined for each quantity type, and are applied
  338. to any unit-less quantity strings.
  339. </p>
  340. <p>
  341. A units system enhanced with quantity type checking might benefit from
  342. inclusion of other derived types which are expressed in terms of
  343. special units, as illustrated in Table 2 of <emph>NIST Publication
  344. 330</emph>. The quantity <samp>"area"</samp>, for example, could be
  345. defined as units properly reducing to <samp>"meter^2"</samp>, although
  346. the utility of defining a unit named <samp>"square meter"</samp> is
  347. arguable.
  348. </p>
  349. </subsection>
  350. </section>
  351. <section>
  352. <title>REFERENCES</title>
  353. <p>
  354. The unit names, abbreviations, and conversion values are derived from
  355. those published by the United States Department of Commerce Technology
  356. Administration, National Institute of Standards and Technology (NIST)
  357. in <emph>NIST Special Publication 330: The International System of
  358. Units (SI)</emph> and <emph>NIST Special Publication 811: Guide for
  359. the Use of the International System of Units (SI)</emph>. Both of
  360. these publications are available (as of December 2000) from
  361. http://physics.nist.gov/cuu/Reference/contents.html
  362. </p>
  363. <p>
  364. The ideas behind implementation of this package is based in part on
  365. code written in 1993 by Adrian Mariano which performed dimensional
  366. analysis of unit strings using fixed size tables of C structs.
  367. </p>
  368. </section>
  369. <keywords>
  370. <keyword>unit</keyword>
  371. <keyword>convert</keyword>
  372. </keywords>
  373. </manpage>