1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930
|
\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename units.info
@settitle Units: A Unit Conversion Program and Scientific Calculator
@finalout
@setchapternewpage off
@firstparagraphindent none
@set EDITION 2.23
@set VERSION 2.24
@c %**end of header
@c for AUTHOR section
@c man program units
@c ifman .\"
@copying
This manual is for GNU Units (version @value{VERSION}),
which performs units conversions and units calculations.
Copyright @copyright{} 1996, 1997, 1999, 2000, 2001, 2002, 2004, 2005, 2007,
2011--2024 Free Software Foundation, Inc.
@quotation
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts.
@c end ifman
@c noman
A copy of the license is included in the section entitled
``GNU Free Documentation License''.
@end quotation
@end copying
@c end noman
@defcodeindex op
@syncodeindex op cp
@c noman
@dircategory Science
@direntry
* Units: (units). Units conversion and scientific calculation.
@end direntry
@c end noman
@c man .TH UNITS 1 "20 November 2024"
@c man .\" ====================================================================
@c man .SH NAME
@c man .\" ====================================================================
@c man .PP
@c man units \(em unit conversion and calculation program
@c man .\" hack to prevent very thick fraction bars with gropdf
@c man .\" '-1' makes thickness proportional to type size
@c man .if \n(.g .if t \Z@\D't -1'@
@titlepage
@title Units Conversion
@subtitle Edition @value{EDITION} for @command{units} Version @value{VERSION}
@author Adrian Mariano
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@contents
@iftex
@headings off
@everyheading Units Conversion @| @| @thispage
@end iftex
@ifnottex
@node Top
@top Units Conversion
@c noman
This manual describes the @command{units} command for units conversion
and how you can use it as a powerful scientific calculator that keeps
track of units. This is Edition @value{EDITION} of @cite{The Units
Conversion Manual} for @command{units} Version @value{VERSION}.
@c end noman
@end ifnottex
@menu
* Overview:: What does @command{units} do?
* Interactive Use:: How to use @command{units}.
* Command Line Use:: How to use @command{units} non-interactively.
* Unit Definitions:: What units are defined?
* Unit Expressions:: Forming compound units.
* Nonlinear Conversions:: Nonlinear unit conversions (e.g., temperature).
* Unit Lists:: Conversion to sums of units (e.g., feet and inches).
* Alternative Unit Systems:: CGS units and natural units
* Logging Calculations:: Logging conversions and calculations in a file.
* Invoking Units:: Command line options.
* Setting Options Interactively:: Setting options interactively
* Scripting with Units:: Using units in scripts
* Output Styles:: Different ways units can print the output.
* Defining Your Own Units:: Adding your own unit definitions
* Numeric Output Format:: How to change the output format
* Localization:: How to define and use regional unit names.
* Environment Vars:: Environment variables used by @command{units}.
* Data Files:: Descriptions and locations of units data files.
* Unicode Support:: Support for Unicode (UTF-8).
* Readline Support:: Unit name completion and editing.
* Currency:: Updating currency exchange rates and CPI.
* Database Syntax:: Summary of database command syntax.
* GNU Free Documentation License:: License.
* Index:: General index.
@end menu
@c noman
@node Overview
@c =====================================================================
@chapter Overview of @command{units}
@c =====================================================================
@c end noman
@c ifman
@ignore
.\" ====================================================================
.SH SYNOPSIS
.\" ====================================================================
.SY units
.RI \:[ from-unit
.RI \:[ to-unit ]]
.YS
.SY units
.OP \-hcemnSpqsv1trUVI
.OP \-d digits
.OP \-f "units\ file"
.OP \-L logfile
.OP \-l locale
.OP \-o format
.OP \-u "unit\ system"
.br
.RI \:[ from-unit
.RI \:[ to-unit ]]
.YS
.SY units
.OP \-\^\-help
.OP \-\^\-check
.OP \-\^\-check-verbose
.OP \-\^\-verbose-check
.OP \-\^\-digits digits
.OP \-\^\-exponential
.OP \-\^\-file "units\ file"
.OP \-\^\-log logfile
.OP \-\^\-locale locale
.OP \-\^\-minus
.OP \-\^\-oldstar
.OP \-\^\-newstar
.OP \-\^\-nolists
.OP \-\^\-show-factor
.OP \-\^\-conformable
.OP \-\^\-output-format format
.OP \-\^\-product
.OP \-\^\-quiet
.OP \-\^\-silent
.OP \-\^\-strict
.OP \-\^\-verbose
.OP \-\^\-compact
.OP \-\^\-one-line
.OP \-\-terse
.OP \-\^\-round
.OP \-\^\-unitsfile
.OP \-\^\-units "units\ system"
.OP \-\^\-version
.OP \-\^\-info
.br
.RI \:[ from-unit
.RI \:[ to-unit ]]
.YS
.\" ====================================================================
.SH DESCRIPTION
.\" ====================================================================
@end ignore
@c end ifman
The @command{units} program converts quantities expressed in various
systems of measurement to their equivalents in other systems of
measurement.
Like many similar programs, it can handle multiplicative scale changes.
It can also handle nonlinear conversions such as Fahrenheit to
@c man Celsius;
@c noman
Celsius;@footnote{But Fahrenheit to
Celsius is linear, you insist. Not so. A transformation @math{T} is linear if
@math{T(x+y)=T(x)+T(y)} and this fails for @math{T(x)=ax+b}. This transformation is
affine, but not linear---see @url{https://en.wikipedia.org/wiki/Linear_map}. }
@pxref{Temperature Conversions}.
@c end noman
@c man see \fITemperature Conversions\fP.
The program can also perform conversions from and to sums of
units, such as converting between meters and feet plus inches.
@c ifman
@ignore
.if n .ig ++
.EQ
delim $$
.EN
.++
But Fahrenheit to
Celsius is linear, you insist. Not so. A transformation \fIT\fP is linear if
.if t $T(x + y) = T(x) + T(y)$
.if n \fIT\fP(\fIx\fP\ +\ \fIy\fP)\ =\ \fPT\fP(\fPx\fP)\ +\ \fIT\fP(\fPy\fP)
and this fails for
.if t $T(x) = ax + b$.
.if n \fIT\fP(\fIx\fP)\ =\ \fIax\fP\ +\ \fIb\fP.
This transformation is affine, but not linear\(emsee \f(CWhttps://en.wikipedia.org/wiki/Linear_map\fP.
.if n .ig ++
.EQ
delim off
.EN
.++
.PP
@end ignore
@c end ifman
Basic operation is simple: you enter the units that you want to convert
@emph{from} and the units that you want to convert @emph{to}.
You can use the program interactively with prompts, or you can use it
from the command line.
Beyond simple unit conversions, @command{units} can be used as a
general-purpose scientific calculator that keeps track of units in its
calculations. You can form arbitrary complex mathematical expressions
of dimensions including sums, products, quotients, powers, and even
roots of dimensions. Thus you can ensure accuracy and dimensional
consistency when working with long expressions that involve many
different units that may combine in complex ways; for an illustration,
@c man see \fIComplicated Unit Expressions\fP.
@c noman
@pxref{Complicated Unit Expressions}.
@c end noman
The units are defined in several external data files. You can use the
extensive data files that come with the program, or you can provide
your own data file to suit your needs. You can also use your own data
file to supplement the standard data files.
You can change the default behavior of @command{units} with various
options given on the command line. @xref{Invoking Units}, for a
description of the available options.
@c
@ignore
@c ifman
.\" =====================================================================
.SH "ADDITIONAL DOCUMENTATION"
.\" =====================================================================
.PP
This manual is also available in PDF and HTML:
.PP
.RS 3n
.nf
.UR https://www.gnu.org/software/units/manual/units.pdf
.UE
.UR https://www.gnu.org/software/units/manual/units.html
.UE
.fi
.RE
@c end ifman
@end ignore
@c
@node Interactive Use
@c =====================================================================
@chapter Interacting with @command{units}
@c =====================================================================
@cindex interactive use
To invoke @command{units} for interactive use, type @kbd{units} at your
shell prompt. The program will print something like this:
@example
@group
Currency exchange rates from FloatRates (USD base) on 2023-07-08
3612 units, 109 prefixes, 122 nonlinear units
You have:
@end group
@end example
@noindent
At the @w{@samp{You have:}} prompt, type the quantity and units that you
are converting @emph{from}. For example, if you want to convert ten
meters to feet, type @kbd{10 meters}. Next, @command{units} will print
@w{@samp{You want:}}. You should type the units you want to convert
@emph{to}. To convert to feet, you would type @kbd{feet}. If the
@command{readline} library was compiled in, then @key{tab} will complete
unit names. @xref{Readline Support}, for more information about
@command{readline}. To quit the program type @kbd{quit} or @kbd{exit}
at either prompt.
The result will be displayed in two ways. The first line of output,
which is marked with a @samp{*} to indicate multiplication, gives the
result of the conversion you have asked for. The second line of output,
which is marked with a @samp{/} to indicate division, gives the inverse
of the conversion factor. If you convert 10 meters to feet,
@command{units} will print
@example
@group
* 32.808399
/ 0.03048
@end group
@end example
@noindent
which tells you that 10 meters equals about 32.8 feet.
The second number gives the conversion in the opposite direction.
In this case, it tells you that 1 foot is equal to about
0.03 dekameters since the dekameter is 10 meters.
It also tells you that 1/32.8 is about 0.03.
The @command{units} program prints the inverse because sometimes it is a
more convenient number. In the example above, for example, the inverse
value is an exact conversion: a foot is exactly 0.03048 dekameters.
But the number given the other direction is inexact.
If you convert grains to pounds, you will see the following:
@example
@group
You have: grains
You want: pounds
* 0.00014285714
/ 7000
@end group
@end example
@noindent
@w{From} the second line of the output, you can immediately see that a grain
is equal to a seven thousandth of a pound. This is not so obvious from
the first line of the output. If you find the output format confusing,
try using the @option{--verbose} option:
@cindex verbose output
@example
@group
You have: grain
You want: aeginamina
grain = 0.00010416667 aeginamina
grain = (1 / 9600) aeginamina
@end group
@end example
@noindent
If you request a conversion between units that measure reciprocal
dimensions, then @command{units} will display the conversion results with an extra
note indicating that reciprocal conversion has been done:
@cindex reciprocal conversion
@example
@group
You have: 6 ohms
You want: siemens
reciprocal conversion
* 0.16666667
/ 6
@end group
@end example
@noindent
Reciprocal conversion can be suppressed by using the @option{--strict} option.
As usual, use
the @option{--verbose} option to get more comprehensible output:
@cindex verbose output
@cindex strict conversion
@example
@group
You have: tex
You want: typp
reciprocal conversion
1 / tex = 496.05465 typp
1 / tex = (1 / 0.0020159069) typp
You have: 20 mph
You want: sec/mile
reciprocal conversion
1 / 20 mph = 180 sec/mile
1 / 20 mph = (1 / 0.0055555556) sec/mile
@end group
@end example
@noindent
If you enter incompatible unit types, the @command{units} program will
print a message indicating that the units are not conformable and
it will display the reduced form for each unit:
@cindex incompatible units
@cindex non-conformable units
@example
@group
You have: ergs/hour
You want: fathoms kg^2 / day
conformability error
2.7777778e-11 kg m^2 / sec^3
2.1166667e-05 kg^2 m / sec
@end group
@end example
@noindent
If you only want to find the reduced form or definition of a unit,
simply press @key{Enter} at the @w{@samp{You want:}} prompt. Here is an
example:
@example
@group
You have: jansky
You want:
Definition: fluxunit = 1e-26 W/m^2 Hz = 1e-26 kg / s^2
@end group
@end example
@noindent
The output from @command{units} indicates that the jansky is defined to
be equal to a fluxunit which in turn is defined to be a certain
combination of watts, meters, and hertz. The fully reduced (and in this
case somewhat more cryptic) form appears on the far right. If the
ultimate definition and the fully reduced form are identical, the latter
is not shown:
@example
@group
You have: B
You want:
Definition: byte = 8 bit
@end group
@end example
@noindent
The fully reduced form @emph{is} shown if it and the ultimate definition
are equivalent but not identical:
@example
@group
You have: N
You want:
Definition: newton = kg m / s^2 = 1 kg m / s^2
@end group
@end example
@noindent
Some named units are treated as dimensionless in some situations.
These units include the radian and steradian. These units will be
treated as equal to 1 in units conversions. Power is equal to torque
times angular velocity. This conversion can only be performed if the
radian is dimensionless.
@example
@group
You have: (14 ft lbf) (12 radians/sec)
You want: watts
* 227.77742
/ 0.0043902509
@end group
@end example
@noindent
It is also possible to compute roots and other non-integer powers of
dimensionless units; this allows computations such as the altitude of
geosynchronous orbit:
@example
@group
You have: cuberoot(G earthmass / (circle/siderealday)^2) - earthradius
You want: miles
* 22243.267
/ 4.4957425e-05
@end group
@end example
@noindent
Named dimensionless units are not treated as dimensionless
in other contexts. They cannot be used as exponents
so for example, @samp{meter^radian} is forbidden.
@cindex dimensionless units
@cindex @samp{?} to show conformable units
@cindex conformable units, @samp{?} to show
If you want a list of options you can type @kbd{?} at the
@w{@samp{You want:}} prompt. The program will display a list of named
units that are conformable with the unit that you entered at the
@w{@samp{You have:}} prompt above. Conformable unit @emph{combinations}
will not appear on this list.
@cindex help
Typing @kbd{help} at either prompt displays a short help message. You
can also type @kbd{help} followed by a unit name. This will invoke a
pager on the units data base at the point where that unit is defined.
You can read the definition and comments that may give more details or
historical information about the unit. If your pager allows, you may
want to scroll backwards, e.g. with @samp{b}, because sometimes a longer
comment about a unit or group of units will appear before the
definition. You can generally quit out of the pager by pressing
@samp{q}.
@cindex search
Typing @w{@kbd{search} @var{text}} will display a list of all of the units
whose names contain @var{text} as a substring along with their definitions.
This may help in the case where you aren't sure of the right unit name.
Many command-line options can be set by typing
@w{@kbd{set} @var{option}@kbd{=}@var{value}}; typing
@w{@kbd{set} @var{option}} will show the value for that option. Typing
@kbd{set} will show a list of options that can be set; options set to
other than default values will have a prepended @samp{*}.
@xref{Setting Options Interactively} for more information.
@node Command Line Use
@c =====================================================================
@chapter Using @command{units} Non-Interactively
@c =====================================================================
@cindex command-line unit conversion
@cindex non-interactive unit conversion
The @command{units} program can perform units conversions non-interactively
from the command line. To do this, type the command, type the original
unit expression, and type the new units you want. If a units expression
contains non-alphanumeric characters, you may need to protect it from
interpretation by the shell using single or double quote characters.
If you type
@example
units "2 liters" quarts
@end example
@noindent
then @command{units} will print
@example
@group
* 2.1133764
/ 0.47317647
@end group
@end example
@noindent
and then exit.
The output tells you that 2 liters is about 2.1 quarts, or alternatively that
a quart is about 0.47 times 2 liters.
@command{units} does not require a space between a numerical value and
the unit, so the previous example can be given as
@example
units 2liters quarts
@end example
@noindent
to avoid having to quote the first argument.
If the conversion is successful, @command{units} will return success (zero)
to the calling environment. If you enter non-conformable units, then
@command{units} will print a message giving the reduced form of each
unit and it will return failure (nonzero) to the calling environment.
If the @option{--conformable} option is given, only one unit expression
is allowed, and @command{units} will print all units conformable with
that expression; it is equivalent to giving @kbd{?} at the
@w{@samp{You want:}} prompt. For example,
@example
@group
units --conformable gauss
B_FIELD tesla
Gs gauss
T tesla
gauss abvolt sec / cm^2
stT stattesla
statT stattesla
stattesla statWb/cm^2
tesla Wb/m^2
@end group
@end example
@noindent
If you give more than one unit expression with the
@option{--conformable} option, the program will exit with an error
message and return failure. This option has no effect in interactive
mode.
If the @option{--terse} (@option{-t}) option is given with the
@option{--conformable} option, conformable units are shown without
definitions; with the previous example, this would give
@example
@group
units --terse --conformable gauss
B_FIELD
Gs
T
gauss
stT
statT
stattesla
tesla
@end group
@end example
@noindent
When the @option{--conformable} option is not given and you invoke
@command{units} with only one argument, @command{units} will print the
definition of the specified unit. It will return failure if the unit is
not defined and success if the unit is defined.
@node Unit Definitions
@c =====================================================================
@chapter Unit Definitions
@c =====================================================================
@cindex unit definitions
The conversion information is read from several units data files:
@file{definitions.units}, @file{elements.units}, @file{currency.units},
and @file{cpi.units},
which are usually located in
the @file{/usr/share/units} directory.
If you invoke @command{units} with the @option{-V} option, it will print
the location of these files.
The default main
file includes definitions for all familiar units, abbreviations and
metric prefixes. It also includes many obscure or archaic units.
Many common spelled-out numbers (e.g., @samp{seventeen}) are recognized.
@c ---------------------------------------------------------------------
@section Physical Constants
@c ---------------------------------------------------------------------
Many constants of nature are defined, including these:
@example
pi @r{ratio of circumference of a circle to its diameter}
c @r{speed of light}
e @r{charge on an electron}
force @r{acceleration of gravity}
mole @r{Avogadro's number}
water @r{pressure per unit height of water}
Hg @r{pressure per unit height of mercury}
au @r{astronomical unit}
k @r{Boltzman's constant}
mu0 @r{permeability of vacuum}
epsilon0 @r{permittivity of vacuum}
G @r{Gravitational constant}
mach @r{speed of sound}
@end example
@noindent
The standard data file includes numerous other constants. Also included
are the densities of various ingredients used in baking so that
@samp{2@tie{}cups flour_sifted} can be converted to @samp{grams}. This
is not an exhaustive list. Consult the units data file to see the
complete list, or to see the definitions that are used.
@c ---------------------------------------------------------------------
@section Atomic Masses of the Elements
@c ---------------------------------------------------------------------
The data file @file{elements.units} includes atomic masses for most
elements and most known isotopes. If the mole fractions of constituent
isotopes are known, an elemental mass is calculated from the sum of the
products of the mole fractions and the masses of the constituent
isotopes. If the mole fractions are not known, the mass of the most
stable isotope---if known---is given as the elemental mass.
For radioactive elements with atomic numbers 95 or greater, the mass
number of the most stable isotope is not specified, because the list of
studied isotopes is still incomplete. If no stable isotope is known, no
elemental mass is given, and you will need to choose the most
appropriate isotope.
The data are obtained from the US National Institute for Standards and
Technology (NIST):
@uref{https://physics.nist.gov/cgi-bin/Compositions/stand_alone.pl?ele=&all=all&ascii=ascii2&isotype=all}.
The @file{elements.units} file can be generated from these data using
the @command{elemcvt} command included with the distribution.
@c ---------------------------------------------------------------------
@section Currency Exchange Rates and Consumer Price Index
@c ---------------------------------------------------------------------
The data file @file{currency.units} includes currency conversion rates;
the file @file{cpi.units} includes the US Consumer Price Index (CPI),
published by the US Bureau of Labor Statistics. The data are updated
monthly by the BLS;
@c man see \fIUpdating Currency Exchange Rates and CPI\fP
@c noman
@pxref{Currency, ,Updating Currency Exchange Rates and CPI}
@c end noman
for information on updating @file{currency.units} and @file{cpi.units}.
@c ---------------------------------------------------------------------
@section English Customary Units
@c ---------------------------------------------------------------------
@cindex volume measure, English customary
English customary units differ in various ways among different
regions. In Britain a complex system of volume measurements featured
different gallons for different materials such as a wine gallon and
ale gallon that different by twenty percent. This complexity was
swept away in 1824 by a reform that created an entirely new gallon,
the British Imperial gallon defined as the volume occupied by ten
pounds of water. Meanwhile in the USA the gallon is derived from the
1707 Winchester wine gallon, which is 231 cubic inches. These gallons
differ by about twenty percent. By default if @command{units} runs in
the @samp{en_GB} locale you will get the British volume measures. If
it runs in the @samp{en_US} locale you will get the US volume
measures. In other locales the default values are the US
definitions. If you wish to force different definitions, then set the
environment variable @env{UNITS_ENGLISH} to either @samp{US} or
@samp{GB} to set the desired definitions independent of the locale.
@cindex units, English customary
@cindex units, US customary
@cindex length measure, English customary
@cindex length measure, UK
@cindex survey measure, US
@cindex US survey measure
@cindex survey mile, US
@cindex US survey foot
@cindex State Plane Coordinate System, US
@cindex US State Plane Coordinate System
@cindex survey foot, US
@cindex US survey mile
@cindex mile, international
@cindex international mile
@cindex yard, international
@cindex international yard
Before 1959, the value of a yard (and other units of measure defined in
terms of it) differed slightly among English-speaking countries. In
1959, Australia, Canada, New Zealand, the United Kingdom, the United
States, and South Africa adopted the Canadian value of 1@tie{}yard =
0.9144@tie{}m (exactly), which was approximately halfway between the
values used by the UK and the US; it had the additional advantage of
making 1@tie{}inch = 2.54@tie{}cm (exactly). This new standard was
termed the @dfn{International Yard}. Australia, Canada, and the UK then
defined all customary lengths in terms of the International Yard
(Australia did not define the furlong or rod); because many US land
surveys were in terms of the pre-1959 units, the US continued to define
customary surveyors' units (furlong, chain, rod, pole, perch, and link)
in terms of the previous value for the foot, which was termed the
@dfn{US survey foot}. The US defined a @dfn{US survey mile} as 5280 US
survey feet, and defined a @dfn{statute mile} as a US survey mile. The
US values for these units differed from the international values by about
2@tie{}ppm.
The 1959 redefinition of the foot was legally binding in the US but
allowed continued use of the previous definition of the foot for
geodetic surveying. It was assumed that this use would be temporary,
but use persisted, leading to confusion and errors, and it was at
odds with the intent of uniform standards. Since January 1, 2023, the
US survey foot has been officially deprecated
@c noman
(@url{https://www.govinfo.gov/app/details/FR-2020-10-05/2020-21902,,85 FR
62698}),
@c end noman
@c man (85 FR 62698),
with its use limited to historical and legacy applications.
The @command{units} program has always used the international values for these
units; the legacy US values can be obtained by using either the @samp{US} or
the @samp{survey} prefix. In either case, the simple familiar
relationships among the units are maintained, e.g., 1 @samp{furlong} =
660 @samp{ft}, and 1 @samp{USfurlong} = 660 @samp{USft}, though the
metric equivalents differ slightly between the two cases.
The @samp{US} prefix or the @samp{survey} prefix can also be used to
obtain the US survey mile and the value of the US yard prior to 1959,
e.g., @samp{USmile} or @samp{surveymile} (but @emph{not}
@samp{USsurveymile}). To get the US value of the statute mile, use
either @samp{USstatutemile} or @samp{USmile}.
The pre-1959 UK values for these units can be obtained with the prefix
@samp{UK}.
Except for distances that extend over hundreds of miles (such as in the
US State Plane Coordinate System), the differences in the miles are
usually insignificant:
@example
@group
You have: 100 surveymile - 100 mile
You want: inch
* 12.672025
/ 0.078913984
@end group
@end example
The US acre was officially defined in terms of the US survey
foot, but @command{units} has used a definition based on the
international foot; the @command{units} definition is now the same as
the official US value. If you want the previous US acre, use
@samp{USacre} and similarly use @samp{USacrefoot} for the previous US
version of that unit. The difference between these units is about 4
parts per million.
@c ---------------------------------------------------------------------
@section Miscellaneous Notes on Unit Definitions
@c ---------------------------------------------------------------------
@cindex measure, Imperial
@cindex Imperial measure
@cindex British Imperial measure
The @samp{pound} is a unit of mass. To get force, multiply by the
force conversion unit @samp{force} or use the shorthand @samp{lbf}.
(Note that @samp{g} is already taken as the standard abbreviation for
the gram.) The unit @samp{ounce} is also a unit of mass. The fluid
ounce is @samp{fluidounce} or @samp{floz}. When British capacity
units differ from their US counterparts, such as the British Imperial
gallon, the unit is defined both ways with @samp{br} and @samp{us}
prefixes. Your locale settings will determine the value of the
unprefixed unit. Currency is prefixed with its country
name: @samp{belgiumfranc}, @samp{britainpound}.
@cindex units, lookup method
When searching for a unit, if the specified string does not appear
exactly as a unit name, then the @command{units} program will try to
remove a trailing @samp{s}, @samp{es}. Next units will replace a
trailing @samp{ies} with @samp{y}. If that fails,
@command{units} will check for a prefix. The database includes all
of the standard metric prefixes. Only one prefix is permitted per
unit, so @samp{micromicrofarad} will fail. However, prefixes can
appear alone with no unit following them, so
@samp{micro*microfarad} will work, as will @samp{micro microfarad}.
@cindex prefixes
To find out which units and prefixes are available, read the default
units data files; the main data file is extensively annotated.
@node Unit Expressions
@c =====================================================================
@chapter Unit Expressions
@c =====================================================================
@cindex unit expressions
@menu
* Operators:: The usual arithmetic operators, with a few extras
* Sums and Differences of Units:: Adding and subtracting units
* Numbers as Units:: A number is a dimensionless unit
* Built-in Functions:: Trigonometric functions, logarithms, roots
* Previous Result:: Inserting the result of the previous conversion
* Complicated Unit Expressions:: A complicated example
* Variables Assigned at Run Time:: Saving intermediate results in variables
* Backwards Compatibility:: Alternate behavior for @samp{*} and @samp{-}
@end menu
@node Operators
@c ---------------------------------------------------------------------
@section Operators
@c ---------------------------------------------------------------------
@cindex operators
You can enter more complicated units by combining units with operations
such as multiplication, division, powers, addition, subtraction, and
parentheses for grouping. You can use the customary symbols for these
operators when @command{units} is invoked with its default options.
Additionally, @command{units} supports some extensions, including high
priority multiplication using a space, and a high priority numerical
division operator (@samp{|}) that can simplify some expressions.
@cindex products of units
@cindex quotients of units
@cindex units quotients
@cindex multiplication of units
@cindex division of units
@cindex operator, @samp{per}
@cindex @samp{per} operator
@cindex operator, space
@cindex operator, star (@samp{*})
@cindex star (@samp{*}) operator
@cindex @samp{*} operator
@cindex operator, slash (@samp{/})
@cindex slash (@samp{/}) operator
@cindex operator, solidus (@samp{/})
@cindex solidus (@samp{/}) operator
You multiply units using a space or an asterisk (@samp{*}).
The next example shows both forms:
@example
@group
You have: arabicfoot * arabictradepound * force
You want: ft lbf
* 0.7296
/ 1.370614
@end group
@end example
@noindent
You can divide units using the slash (@samp{/}) or with @samp{per}:
@example
@group
You have: furlongs per fortnight
You want: m/s
* 0.00016630986
/ 6012.8727
@end group
@end example
@cindex parentheses
@noindent
You can use parentheses for grouping:
@example
@group
You have: (1/2) kg / (kg/meter)
You want: league
* 0.00010356166
/ 9656.0833
@end group
@end example
@cindex operator precedence
@cindex parentheses
@cindex white space
@noindent
White space surrounding operators is optional, so the previous example
could have used @samp{(1/2)kg/(kg/meter)}. As a consequence, however,
hyphenated spelled-out numbers (e.g., @samp{forty-two}) cannot be used;
@samp{forty-two} is interpreted as @samp{40 - 2}.
Multiplication using a space has a higher precedence
than division using a slash and is evaluated left to right;
in effect, the first @samp{/} character marks the beginning of the
denominator of a unit expression.
This makes it simple to enter a quotient with several terms in the
denominator: @w{@samp{J / mol K}}.
The @samp{*} and @samp{/} operators have the same precedence, and are
evaluated left to right; if you multiply with @samp{*}, you must group
the terms in the denominator with parentheses: @w{@samp{J / (mol * K)}}.
@cindex fractions, numerical
@cindex numerical fractions
@cindex division of numbers
@cindex operator, vertical bar (@samp{|})
@cindex vertical bar (@samp{|}) operator
@cindex @samp{|} operator
The higher precedence of the space operator may not always be advantageous.
For example, @w{@samp{m/s s/day}} is equivalent to
@w{@samp{m / s s day}} and has dimensions of length per time cubed.
Similarly, @w{@samp{1/2 meter}} refers to a unit of reciprocal length
equivalent to 0.5/meter, perhaps not what you would intend if
you entered that expression. The get a half meter you would need to
use parentheses: @w{@samp{(1/2) meter}}.
The @samp{*} operator is convenient for multiplying a sequence of
quotients. For example, @w{@samp{m/s * s/day}} is equivalent to
@samp{m/day}. Similarly, you could write @w{@samp{1/2 * meter}} to get
half a meter.
The @command{units} program supports another option for numerical fractions:
you can indicate division of @emph{numbers} with the vertical bar
(@samp{|}), so if you wanted half a meter you could write
@w{@samp{1|2 meter}}.
You cannot use the vertical bar to indicate division of non-numerical
units (e.g., @samp{m|s} results in an error message).
@cindex powers
@cindex exponent operator
@cindex operator, caret (@samp{^})
@cindex operator, (@samp{**})
@cindex @samp{**} operator
@cindex parentheses
Powers of units can be specified using the @samp{^} character, as shown in
the following example, or by simple concatenation of a unit and its
exponent: @samp{cm3} is equivalent to @samp{cm^3};
if the exponent is more than one digit, the @samp{^} is required.
You can also use @samp{**} as an exponent operator.
@example
@group
You have: cm^3
You want: gallons
* 0.00026417205
/ 3785.4118
@end group
@end example
@noindent
Concatenation only works with a single unit name: if you write @samp{(m/s)2},
@command{units} will treat it as multiplication by 2.
@cindex prefixes and exponents
When a unit includes a prefix, exponent operators apply to the
combination, so @samp{centimeter3} gives cubic centimeters. If you
separate the prefix from the unit with any multiplication operator (e.g.,
@samp{centi meter^3}), the prefix is treated as a separate unit, so
the exponent applies only to the unit without the prefix. The second
example is equivalent to @samp{centi * (meter^3)}, and gives a hundredth
of a cubic meter, not a cubic centimeter. The @command{units} program
is limited internally to products of 99 units; accordingly, expressions
like @samp{meter^100} or @samp{joule^34} (represented internally as
@w{@samp{kg^34 m^68 / s^68}}) will fail.
The @samp{|}
operator has the highest precedence, so you can write the square root of
two thirds as @samp{2|3^1|2}.
The @samp{^} operator has the second highest precedence, and is
evaluated right to left, as usual:
@example
@group
You have: 5 * 2^3^2
You want:
Definition: 2560
@end group
@end example
@noindent
With a dimensionless base unit, any dimensionless exponent is meaningful
(e.g., @samp{pi^exp(2.371)}). Even though angle is sometimes treated as
dimensionless, exponents cannot have dimensions of angle:
@example
@group
You have: 2^radian
^
Exponent not dimensionless
@end group
@end example
@noindent
If the base unit is not dimensionless, the
exponent must be a rational number @w{@var{p}/@var{q}}, and the
dimension of the unit must be a power of @var{q}, so @samp{gallon^2|3}
works but @samp{acre^2|3} fails. An exponent using the slash (@samp{/})
operator (e.g., @samp{gallon^(2/3)}) is also acceptable; the parentheses
are needed because the precedence of @samp{^} is higher than that of
@samp{/}. Since @command{units} cannot represent dimensions with
exponents greater than 99, a fully reduced exponent must have
@w{@var{q} < 100}. When raising a non-dimensionless unit to a power,
@command{units} attempts to convert a decimal exponent to a rational
number with @w{@var{q} < 100}. If this is not possible
@command{units} displays an error message:
@example
@group
You have: ft^1.234
Base unit not dimensionless; rational exponent required
@end group
@end example
@noindent
A decimal exponent must match its rational representation to machine
precision, so @samp{acre^1.5} works but @samp{gallon^0.666} does not.
@node Sums and Differences of Units
@c ---------------------------------------------------------------------
@section Sums and Differences of Units
@c ---------------------------------------------------------------------
@cindex sums and differences of units
@cindex units, sums and differences
@cindex operator, plus (@samp{+})
@cindex plus (@samp{+}) operator
@cindex @samp{+} operator
@cindex operator, minus (@samp{-})
@cindex minus (@samp{-}) operator, subtraction
@cindex operator, hyphen (@samp{-}) as subtraction
@cindex @samp{-} as subtraction operator
@noindent
You may sometimes want to add values of
different units that are outside the SI.
You may also wish to use @command{units} as a
calculator that keeps track of units. Sums of conformable units are written with
the @samp{+} character, and differences with the @samp{-} character.
@cindex sums of units
@cindex addition of units
@cindex subtraction of units
@cindex differences of units
@example
@group
You have: 2 hours + 23 minutes + 32 seconds
You want: seconds
* 8612
/ 0.00011611705
@end group
@end example
@example
@group
You have: 12 ft + 3 in
You want: cm
* 373.38
/ 0.0026782366
@end group
@end example
@example
@group
You have: 2 btu + 450 ft lbf
You want: btu
* 2.5782804
/ 0.38785542
@end group
@end example
@noindent
The expressions that are added or subtracted must reduce to identical
expressions in primitive units, or an error message will be displayed:
@example
@group
You have: 12 printerspoint - 4 heredium
^
Invalid sum of non-conformable units
@end group
@end example
@cindex parentheses
@noindent
If you add two values of vastly different scale you may exceed the
available precision of floating point (about 15 digits). The effect is
that the addition of the smaller value makes no change to the larger
value; in other words, the smaller value is treated as if it were zero.
@example
@group
You have: lightyear + cm
@end group
@end example
@noindent
No warning is given, however.
As usual, the precedence for @samp{+} and @samp{-} is lower than that of
the other operators.
A fractional quantity such as 2@tie{}1/2 cups can be given as
@samp{(2+1|2) cups}; the parentheses are necessary because
multiplication has higher precedence than addition. If you omit the
parentheses, @command{units} attempts to add @samp{2} and
@samp{1|2 cups}, and you get an error message:
@example
@group
You have: 2+1|2 cups
^
Invalid sum or difference of non-conformable units
@end group
@end example
@noindent
The expression could also be correctly written as @samp{(2+1/2) cups}.
If you write @samp{2@tie{}1|2 cups} the space is interpreted as
@emph{multiplication} so the result is the same as @samp{1 cup}.
The @samp{+} and @samp{-} characters sometimes appears in exponents like
@samp{3.43e+8}. This leads to an ambiguity in an expression like
@samp{3e+2 yC}. The unit @samp{e} is a small unit of charge, so this
can be regarded as equivalent to @samp{(3e+2) yC} or @samp{(3 e)+(2 yC)}.
This ambiguity is resolved by always interpreting @samp{+} and @samp{-} as part
of an exponent if possible.
@node Numbers as Units
@c ---------------------------------------------------------------------
@section Numbers as Units
@c ---------------------------------------------------------------------
@cindex numbers as units
For @command{units}, numbers are just another kind of unit. They can
appear as many times as you like and in any order in a unit expression.
For example, to find the volume of a box that is 2 ft by 3 ft by 12 ft
in steres, you could do the following:
@example
@group
You have: 2 ft 3 ft 12 ft
You want: stere
* 2.038813
/ 0.49048148
You have: $ 5 / yard
You want: cents / inch
* 13.888889
/ 0.072
@end group
@end example
@noindent
And the second example shows how the dollar sign in the units conversion
can precede the five. Be careful: @command{units} will interpret
@samp{$5} with no space as equivalent to @samp{dollar^5}.
@node Built-in Functions
@c ---------------------------------------------------------------------
@section Built-in Functions
@c ---------------------------------------------------------------------
@cindex functions, built in
@cindex built-in functions
Several built-in functions are provided: @samp{sin}, @samp{cos}, @samp{tan},
@samp{asin}, @samp{acos}, @samp{atan},
@samp{sinh}, @samp{cosh}, @samp{tanh},
@samp{asinh}, @samp{acosh}, @samp{atanh},
@samp{exp}, @samp{ln}, @samp{log},
@samp{abs}, @samp{round}, @samp{floor}, @samp{ceil}, @samp{factorial},
@samp{Gamma}, @samp{lnGamma}, @samp{erf}, and @samp{erfc};
the function @samp{lnGamma} is the natural logarithm of the @samp{Gamma}
function.
The @samp{sin}, @samp{cos}, and @samp{tan}
functions require either a dimensionless argument or an argument with
dimensions of angle.
@example
@group
You have: sin(30 degrees)
You want:
Definition: 0.5
You have: sin(pi/2)
You want:
Definition: 1
You have: sin(3 kg)
^
Unit not dimensionless
@end group
@end example
@noindent
The other functions on the list require dimensionless arguments. The
inverse trigonometric functions return arguments with dimensions of
angle.
@cindex logs
The @samp{ln} and @samp{log} functions give natural log and log base
10 respectively. To obtain logs for any integer base, enter the
desired base immediately after @samp{log}. For example, to get log
base 2 you would write @samp{log2} and to get log base 47 you could
write @samp{log47}.
@example
@group
You have: log2(32)
You want:
Definition: 5
You have: log3(32)
You want:
Definition: 3.1546488
You have: log4(32)
You want:
Definition: 2.5
You have: log32(32)
You want:
Definition: 1
You have: log(32)
You want:
Definition: 1.50515
You have: log10(32)
You want:
Definition: 1.50515
@end group
@end example
@cindex roots
@cindex square roots
If you wish to take roots of units, you may use the @samp{sqrt} or
@samp{cuberoot} functions. These functions require that the argument
have the appropriate root. You can obtain higher roots by using
fractional exponents:
@example
@group
You have: sqrt(acre)
You want: feet
* 208.71074
/ 0.0047913202
You have: (400 W/m^2 / stefanboltzmann)^(1/4)
You have:
Definition: 289.80882 K
You have: cuberoot(hectare)
^
Unit not a root
@end group
@end example
@node Previous Result
@c ---------------------------------------------------------------------
@section Previous Result
@c ---------------------------------------------------------------------
@cindex previous result
@cindex @samp{_} to use result of previous conversion
@noindent
You can insert the result of the previous conversion using the
underscore (@samp{_}). It is useful when you want to
convert the same input to several different units, for example
@example
@group
You have: 2.3 tonrefrigeration
You want: btu/hr
* 27600
/ 3.6231884e-005
You have: _
You want: kW
* 8.0887615
/ 0.12362832
@end group
@end example
@noindent
Suppose you want to do some deep frying that requires an oil depth of
2@tie{}inches. You have 1/2 gallon of oil, and want to know the
largest-diameter pan that will maintain the required depth. The
nonlinear unit @samp{circlearea} gives the @emph{radius} of the circle
(@pxref{Other Nonlinear Units}, for a more detailed description) in SI
units; you want the @emph{diameter} in @emph{inches}:
@example
@group
You have: 1|2 gallon / 2 in
You want: circlearea
0.10890173 m
You have: 2 _
You want: in
* 8.5749393
/ 0.1166189
@end group
@end example
@cindex white space
@noindent
In most cases, surrounding white space is optional, so the previous
example could have used @samp{2_}. If @samp{_} follows a non-numerical
unit symbol, however, the space is required:
@example
@group
You have: m_
^
Parse error
@end group
@end example
@noindent
You can use the @samp{_} symbol any number of times; for example,
@example
@group
You have: m
You want:
Definition: 1 m
You have: _ _
You want:
Definition: 1 m^2
@end group
@end example
@noindent
Using @samp{_} before a conversion has been performed (e.g.,
immediately after invocation) generates an error:
@set codequoteundirected
@example
@group
You have: _
^
No previous result; '_' not set
@end group
@end example
@clear codequoteundirected
@noindent
Accordingly, @samp{_} serves no purpose when @command{units} is invoked
non-interactively.
If @command{units} is invoked with the @option{--verbose} option
(@pxref{Invoking Units}), the value of @samp{_} is not expanded:
@example
@group
You have: mile
You want: ft
mile = 5280 ft
mile = (1 / 0.00018939394) ft
You have: _
You want: m
_ = 1609.344 m
_ = (1 / 0.00062137119) m
@end group
@end example
@noindent
You can give @samp{_} at the @w{@samp{You want:}} prompt, but it
usually is not very useful.
@node Complicated Unit Expressions
@c ---------------------------------------------------------------------
@section Complicated Unit Expressions
@c ---------------------------------------------------------------------
@cindex unit expressions, complicated
@noindent
The @command{units} program is especially helpful in ensuring accuracy
and dimensional consistency when converting lengthy unit expressions.
@c noman
@cindex Darcy--Weisbach equation
For example, one form of the Darcy--Weisbach fluid-flow equation is
@c
@c ==================== Math for pressure drop example
@c ================
@ifnotinfo
@displaymath
\Delta P = {8 \over \pi^2} \rho fL { Q^2 \over d^5}
@end displaymath
@end ifnotinfo
@ifinfo
@example
Delta P = (8/pi^2) rho f L (Q^2 / d^5)
@end example
@end ifinfo
@noindent
@ifinfo
where @w{Delta P} is the pressure drop, rho
@end ifinfo
@ifnotinfo
where @math{ \Delta P} is the pressure drop, @math{\rho}
@end ifnotinfo
is the mass density,
@math{f} is the (dimensionless) friction factor, @math{L} is the length
of the pipe, @math{Q} is the volumetric flow rate, and @math{d}
is the pipe diameter.
You might want to have the equation in the form
@ifnotinfo
@displaymath
\Delta P = A_1 \rho fL {Q^2 \over d^5}
@end displaymath
@end ifnotinfo
@ifinfo
@example
Delta P = A1 rho f L (Q^2 / d^5)
@end example
@end ifinfo
@c end noman
@c -----------------------------------
@c nroff--assume neqn is not available
@c -----------------------------------
@c man .if t .ig ++
@c man For example, one form of the Darcy-Weisbach fluid-flow equation is
@c man .RS 5n
@c man .PP
@c man Delta \fIP\fP = (8 / pi)^2 (\fIrho\fP \fIfLQ\fP^2) / \fId\fP^5,
@c man .RE
@c man .PP
@c man where Delta \fIP\fP is the pressure drop, \fIrho\fP is the mass density,
@c man \fIf\fP is the (dimensionless) friction factor, \fIL\fP is the length
@c man of the pipe, \fIQ\fP is the volumetric flow rate, and \fId\fP
@c man is the pipe diameter.
@c man You might want to have the equation in the form
@c man .RS 5n
@c man .PP
@c man Delta \fIP\fP = A1 \fIrho\fP \fIfLQ\fP^2 / \fId\fP^5
@c man .RE
@c man .PP
@c man .++
@c -----
@c troff
@c -----
@c man .if n .ig ++
@c man .EQ
@c man delim $$
@c man .EN
@c don't assume en dash is available
@c man For example, one form of the Darcy\-Weisbach fluid-flow equation is
@c man .RS 5n
@c man .PP
@c man .EQ
@c man DELTA P = 8 over pi sup 2 rho fL Q sup 2 over d sup 5 ,
@c man .EN
@c man .RE
@c man .PP
@c man where $DELTA P$ is the pressure drop, $rho$ is the mass density,
@c man $f$ is the (dimensionless) friction factor, $L$ is the length
@c man of the pipe, $Q$ is the volumetric flow rate, and $d$
@c man is the pipe diameter.
@c man You might want to have the equation in the form
@c man .RS 5n
@c man .PP
@c man .EQ
@c man DELTA P = A sub 1 rho fL Q sup 2 over d sup 5
@c man .EN
@c man .RE
@c man .PP
@c man .EQ
@c man delim off
@c man .EN
@c man .++
@c ================ End Math for pressure drop example ================
@c
@noindent
that accepted the user's normal units; for typical units used in the US,
the required conversion could be something like
@example
@group
You have: (8/pi^2)(lbm/ft^3)ft(ft^3/s)^2(1/in^5)
You want: psi
* 43.533969
/ 0.022970568
@end group
@end example
@cindex parentheses
@noindent
The parentheses allow individual terms in the expression to be entered naturally,
as they might be read from the formula. Alternatively, the
multiplication could be done with the @samp{*} rather than a space;
then parentheses are needed only around @samp{ft^3/s} because of its
exponent:
@example
@group
You have: 8/pi^2 * lbm/ft^3 * ft * (ft^3/s)^2 /in^5
You want: psi
* 43.533969
/ 0.022970568
@end group
@end example
@noindent
Without parentheses, and using spaces for multiplication, the previous
conversion would need to be entered as
@example
@group
You have: 8 lb ft ft^3 ft^3 / pi^2 ft^3 s^2 in^5
You want: psi
* 43.533969
/ 0.022970568
@end group
@end example
@node Variables Assigned at Run Time
@c ---------------------------------------------------------------------
@section Variables Assigned at Run Time
@c ---------------------------------------------------------------------
@cindex variables assigned at run time
@cindex runtime variables
@cindex @samp{=} operator
@cindex operator, @samp{=}
Unit definitions are fixed once @command{units} has finished reading the
units data file(s), but at run time you can assign unit expressions to
variables whose names begin with an underscore, using the syntax
@example
_@var{name} = @var{<unit expression>}
@end example
@noindent
This can help manage a long calculation by saving intermediate
quantities as variables that you can use later. For example, to
determine the shot-noise-limited signal-to-noise ratio (SNR) of an
imaging system using a helium--neon laser, you could do
@example
You have: _lambda = 632.8 nm # laser wavelength
You have: _nu = c / _lambda # optical frequency
You have: _photon_energy = h * _nu
You have: _power = 550 uW
You have: _photon_count = _power * 500 ns / _photon_energy
You have: _snr = sqrt(_photon_count)
You have: _snr
You want:
Definition: sqrt(_photon_count) = 29597.922
@end example
@noindent
Except for beginning with an underscore, runtime variables follow the
same naming rules as units. Because names beginning with @samp{_} are
reserved for these variables and unit names cannot begin with @samp{_},
runtime variables can never hide unit definitions. Runtime variables
are undefined until you make an assignment to them, so if you give a
name beginning with an underscore and no assignment has been made, you
get an error message.
When you assign a unit expression to a runtime variable, @command{units}
checks the expression to determine whether it is valid, but the
resulting definition is stored as a text string that is not reduced to
primitive units. The text will be processed anew each time you use the
variable in a conversion or calculation; this means that if your
definition depends on other runtime variables (or the special variable
@samp{_}), the result of calculating with your variable will change if
any of those variables change. A dependence need not be direct.
Continuing the example of the laser above, suppose you have done the
calculation as shown. You now wonder what happens if you switch to an
argon laser:
@example
@group
You have: _lambda = 454.6 nm
You have: _snr
You want:
Definition: sqrt(_photon_count) = 25086.651
@end group
@end example
@noindent
If you then change the power:
@example
@group
You have: _power = 1 mW
You have: _snr
You want:
Definition: sqrt(_photon_count) = 33826.834
@end group
@end example
@noindent
Instead of having to reenter or edit a lengthy expression when you
perform another calculation, you need only enter values that change; in
this respect, runtime variables are similar to a spreadsheet.
The more times a variable appears in an expression that depends on it,
the greater the benefit of having a calculation using that expression
reflect changes to that variable. For example, the length of
daylight---the time the Sun is above the horizon---at a given latitude
and declination of the Sun is given by
@c ================ Math for day length example ==========================
@c noman
@ifnotinfo
@displaymath
L = 2 \cos^{-1} \left (
{ \sin h - \sin \phi \sin \delta }
\over
{ \cos \phi \cos \delta }
\right )
@end displaymath
@end ifnotinfo
@ifinfo
L = 2 acos((sin(h) - cos(phi) cos (delta)) / (cos(phi) cos(delta)))
@end ifinfo
@noindent
where @math{L} is the day length, @math{h} is the Sun's altitude
(elevation angle), @math{\phi} is the location's latitude, and
@math{\delta} is the Sun's declination (angle with the equatorial plane).
@c end noman
@c -----------------------------------
@c nroff--assume neqn is not available
@c -----------------------------------
@c man .if t .ig ++
@c man .RS 5n
@c man .PP
@c man \fIL\fP = acos((sin \fIh\fP - sin \fI\(*f\fP sin \fI\(*d\fP) /
@c man (cos \fI\(*f\fP cos \fI\(*d\fP))
@c man .RE
@c man .PP
@c man where \fIL\fP is the day length, \fIh\fP is the altitude,
@c man \fI\(*f\fP is the latitude, and \fI\(*d\fP is the Sun's declination.
@c man .++
@c -----
@c troff
@c -----
@c man .if n .ig ++
@c man .EQ
@c man delim $$
@c man .EN
@c man .RS 5n
@c man .PP
@c man .EQ
@c man L = 2 cos sup {-1} left (
@c man {sin h - sin phi sin delta}
@c man over
@c man {cos phi cos delta}
@c man right )
@c man .EN
@c man .RE
@c man .PP
@c man where $L$ is the day length, $phi$ is the latitude, and $delta$
@c man is the Sun's declination.
@c man .EQ
@c man delim off
@c man .EN
@c man .++
@c
@c ============= End Math for day length example =======================
@c
The result above is in sidereal time; the length in solar time is
obtained by multiplying by
@example
siderealday / day
@end example
@noindent
By convention, the Sun's altitude at rise or set is
@c noman
@ifnotinfo
@math{-50^\prime}
@end ifnotinfo
@ifinfo
-50'
@end ifinfo
@c end noman
@ignore
@c ifman
\&\-50\(fm
@c end ifman
@end ignore
to allow for atmospheric refraction and the semidiameter of its disk.
At the summer solstice in the northern hemisphere, the Sun's declination
is approximately
@ifinfo
23.44@textdegree{};
@end ifinfo
@ifnotinfo
@math{23.44^\circ};
@end ifnotinfo
to find the length of the longest day of the year
for a latitude of
@ifnotinfo
@math{55^\circ},
@end ifnotinfo
@ifinfo
55@textdegree{};
@end ifinfo
you could do
@example
@group
You have: _alt = -50 arcmin
You have: _lat = 55 deg
You have: _decl = 23.44 deg
You have: _num = sin(_alt) - sin(_lat) sin(_decl)
You have: _denom = cos(_lat) cos(_decl)
You have: _sday = 2 (acos(_num / _denom) / circle) 24 hr
You have: _day = _sday siderealday / day
You have: _day
You want: hms
17 hr + 19 min + 34.895151 sec
@end group
@end example
@noindent
At the winter solstice, the Sun's declination is approximately
@ifnotinfo
@math{-23.44^\circ},
@end ifnotinfo
@ifinfo
-23.44@textdegree{};
@end ifinfo
so you could calculate
the length of the shortest day of
the year using:
@example
@group
You have: _decl = -23.44 deg
You have: _day
You want: hms
7 hr + 8 min + 40.981084 sec
@end group
@end example
@noindent
Latitude and declination each appear twice in the expression for
@code{_day}; the result in the examples above is updated by changing
only the value of the declination.
It may seem easier---and less subject to error---to simply specify the
new value of @code{_decl} as the negative of the current value (e.g.,
@w{@samp{_decl = -_decl}}). This doesn't work; when you make an
assignment with the @samp{=} operator, the definition is stored as
entered, including possible dependencies on variables. But if you
attempt an assignment that is ultimately self-referential, the current
definition is retained, and you get an error message. For example,
@cindex @samp{=} operator
@cindex operator, @samp{=}
@example
@group
You have: _decl = 23.44 deg
You have: _decl = -_decl
Circular unit definition
@end group
@end example
@noindent
You can overcome this by using the @samp{:=} operator, which reduces the
right hand side to primitive units before making the assignment,
eliminating any dependencies on variables. Returning to the example
above,
@cindex @samp{:=} operator
@cindex operator, @samp{:=}
@example
@group
You have: _decl = 23.44 deg
You have: _decl = -_decl
Circular unit definition
You have: _decl := -_decl
You have: _decl
You want: deg
* -23.44
/ -0.042662116
@end group
@end example
@noindent
This works to much the same effect as if the assignment had been
entered literally, e.g.,
@example
You have: _decl = -23.44 deg
@end example
@noindent
but the actual definition is in primitive units---in this case,
radians:
@example
@group
You have: _decl = 23.44 deg
You have: _decl := -_decl
You have: _decl
You want:
Definition: -0.40910517666747087 radian = -0.40910518 radian
@end group
@end example
@noindent
Definitions are text strings, and a redefinition using @samp{:=} is given
with enough digits maintain the full precision of the current definition
when converted back to a number; because it is a string, all digits are
displayed when showing the definition, regardless of the numerical
display precision, so you may see more digits than expected.
A runtime variable must be assigned before it can be used in an
assignment; in the first of the three examples above, giving the general
equation before the values for @code{_alt}, @code{_lat}, and @code{_decl}
had been assigned would result in an error message.
@node Backwards Compatibility
@c ---------------------------------------------------------------------
@section Backwards Compatibility: @samp{*} and @samp{-}
@c ---------------------------------------------------------------------
@cindex backwards compatibility
@cindex compatibility
@cindex compatibility with earlier versions
The original @command{units} assigned multiplication a higher
precedence than division using the slash. This differs from the
usual precedence rules, which give multiplication and division equal
precedence, and can be confusing for people who think
of units as a calculator.
The star operator (@samp{*}) included in this @command{units} program
has, by default, the same precedence as division,
and hence follows the usual precedence rules. For backwards
compatibility you can invoke @command{units}
with the @option{--oldstar}
option. Then @samp{*} has a higher precedence than
division, and the same precedence as multiplication using the space.
@cindex @samp{-} as multiplication operator
@cindex operator, hyphen (@samp{-}) as multiplication
@cindex multiplication, hyphen
@cindex hyphen as multiplication operator
Historically, the hyphen (@samp{-}) has been used in technical
publications to indicate products of units, and the original
@command{units} program treated it as a multiplication operator.
Because @command{units} provides
several other ways to obtain unit products, and because @samp{-} is a
subtraction operator in general algebraic expressions, @command{units}
treats the binary @samp{-} as a subtraction operator by default.
For backwards compatibility use the @option{--product} option, which
causes @command{units} to treat the binary @samp{-} operator as a
product operator. When @samp{-} is a multiplication operator
it has the same precedence as multiplication with a space, giving it a
higher precedence than division.
When @samp{-} is used as a unary operator it negates its operand.
Regardless of the @command{units} options, if
@samp{-} appears after @samp{(} or after
@samp{+}, then it will act as a negation operator. So you can always compute 20
degrees minus 12 minutes by entering @samp{20@tie{}degrees + -12@tie{}arcmin}.
You must use this construction when you define new units because you
cannot know what options will be in force when your definition is
processed.
@cindex defining units with `-'
@node Nonlinear Conversions
@c =====================================================================
@chapter Nonlinear Unit Conversions
@c =====================================================================
@cindex nonlinear unit conversions
Nonlinear units are represented using functional notation. They make
possible nonlinear unit conversions such as temperature.
@menu
* Temperature Conversions:: Conversion between temperature scales
* US Consumer Price Index:: US Consumer Price Index
* Other Nonlinear Units:: Ring size, wire gauge, abrasive grit size
@end menu
@node Temperature Conversions
@c ---------------------------------------------------------------------
@section Temperature Conversions
@c ---------------------------------------------------------------------
@cindex temperature conversions
Conversions between temperatures are different from linear conversions
between temperature @emph{increments}---see the example below. The
absolute temperature conversions are handled by units starting with
@samp{temp}, and you must use functional notation.
The temperature-increment conversions are done using units starting
with @samp{deg} and they do not require functional notation.
@example
@group
You have: tempF(45)
You want: tempC
7.2222222
You have: 45 degF
You want: degC
* 25
/ 0.04
@end group
@end example
@noindent
Think of @samp{tempF(@var{x})} not as a function but as a notation that
indicates that @var{x} should have units of @samp{tempF} attached to
it. @xref{Defining Nonlinear Units}. The first conversion shows that if it's 45
degrees Fahrenheit outside, it's 7.2 degrees Celsius. The second
conversion indicates that a change of 45 degrees Fahrenheit corresponds
to a change of 25 degrees Celsius. The conversion from
@samp{tempF(@var{x})} is to absolute temperature, so that
@example
@group
You have: tempF(45)
You want: degR
* 504.67
/ 0.0019814929
@end group
@end example
@noindent
gives the same result as
@example
@group
You have: tempF(45)
You want: tempR
* 504.67
/ 0.0019814929
@end group
@end example
@noindent
But if you convert @samp{tempF(@var{x})} to @samp{degC}, the output is
probably not what you expect:
@example
@group
You have: tempF(45)
You want: degC
* 280.37222
/ 0.0035666871
@end group
@end example
@noindent
The result is the temperature in K, because @samp{degC} is defined as
@samp{K}, the kelvin. For consistent results, use the @samp{temp@var{X}} units
when converting to a temperature rather than converting a temperature
increment.
The @samp{tempC()} and @samp{tempF()} definitions are limited to
positive absolute temperatures, and giving a value that would result in
a negative absolute temperature generates an error message:
@example
@group
You have: tempC(-275)
^
Argument of function outside domain
@end group
@end example
@node US Consumer Price Index
@c ---------------------------------------------------------------------
@section US Consumer Price Index
@c ---------------------------------------------------------------------
@cindex US Consumer Price Index
@cindex Consumer Price Index
@cindex CPI
@command{units} includes the US Consumer Price Index published by the US
Bureau of Labor Statistics. Several functions that use this value are
provided:
@samp{cpi},
@samp{cpi_now},
@samp{inflation_since},
and
@samp{dollars_in}.
The @samp{cpi} function gives the CPI for a specified decimal year. A
@dfn{decimal year} is given as the year plus the fractional part of the
year; because of leap years and the different lengths of months,
calculating an exact value for the fractional part can be tedious, but
for the purposes of CPI, an approximate value is usually
adequate. For example, @w{1 January} 2000 is 2000.0, @w{1 April} 2000 is 2000.25,
@w{1 July} 2000 is 2000.4986, and @w{1 October} 2000 is 2000.75.
Note also that the CPI data update monthly; values in between months
are linearly interpolated.
In the middle of 1975, the CPI was
@example
@group
You have: cpi(1975.5)
You want:
Definition: 53.6
@end group
@end example
@noindent
The value of the CPI for a month is usually published sometime around
the 20th day of the following month; the latest value of the CPI is available with
@samp{cpi_now}. On @w{7 January} 2024, the value was
@example
@group
You have: cpi_now
You want:
Definition: UScpi_now = 307.051
@end group
@end example
@noindent
This means that the CPI was 307.015 on @w{1 December} 2023. The
@samp{cpi_now} variable can only present the most recent data available,
so it can lag the current CPI by several weeks.
The decimal year of the last update is available with @samp{cpi_lastdate}.
The @samp{inflation_since} function provides a convenient way to
determine the inflation factor from a specified decimal year to the
latest value in the CPI table. For example, on @w{7 January} 2024:
@example
@group
You have: inflation_since(1970)
You want:
Definition: 8.1445889
@end group
@end example
@noindent
In other words, goods that cost 1 US$ in 1970 would cost 8.14 US$ on
@w{1 December} 2023.
The @samp{inflation_since} function can be used to determine an annual
rate of inflation. The earliest US CPI data are from about 1913.1; the
approximate time between then and @w{7 January} 2024 is 110.9 years. The
approximate annual inflation rate for that period is then
@example
@group
You have: inflation_since(1913.1)^1|110.9 - 1
You want: %
* 3.1548115
/ 0.31697614
@end group
@end example
@noindent
The inflation rate for any time period can be found from the ratio of
the CPI at the end of the period to that of the beginning:
@example
@group
You have: (cpi(1982)/cpi(1972))^1|10 - 1
You want: %
* 8.6247033
/ 0.11594602
@end group
@end example
@noindent
The period 1972--1982 was indeed one of high inflation.
The @samp{dollars_in} function is similar to @samp{inflation_since} but
its output is in US$ rather than dimensionless:
@example
@group
You have: dollars_in(1970)
You want:
Definition: 8.1445889 US$
@end group
@end example
@noindent
A typical use might be
@example
@group
You have: 250 dollars_in(1970)
You want: $
* 2036.1472
/ 0.00049112362
@end group
@end example
@noindent
Because @samp{dollars_in} includes the units, you should not
include them at the @w{@samp{You have:}} prompt. You can also
use @samp{dollars_in} to convert between two specified years:
@example
@group
You have: 250 dollars_in(1970)
You want: dollars_in(1950)
* 156.49867
/ 0.0063898305
@end group
@end example
@noindent
which shows that 250 US$ in 1970 would have equivalent purchasing
power to 156 US$ in 1950.
@node Other Nonlinear Units
@c ---------------------------------------------------------------------
@section Other Nonlinear Units
@c ---------------------------------------------------------------------
@cindex nonlinear units, other
Some other examples of nonlinear units are numerous different ring sizes
and wire gauges, screw gauges, pipe and tubing sizes, the grit sizes
used for abrasives, the decibel scale, shoe size, scales for the density
of sugar (e.g., baume). The standard data file also supplies units for
computing the area of a circle and the volume of a sphere. See the
standard units data file for more details.
@cindex wire gauge
@cindex wire size
@cindex American Wire Gauge (AWG)
Diameters of American wire sizes can be found using the
@samp{wiregauge()} function or its alias @samp{awg()}:
@example
@group
You have: wiregauge(11)
You want: inches
* 0.090742002
/ 11.020255
You have: 1 mm
You want: wiregauge
18.201919
@end group
@end example
@noindent
Wire and screw gauges with multiple zeroes are signified using negative
numbers, where two zeroes (``00''; ``2/0'') is @samp{-1}, three zeros
(``000''; ``3/0'') is @samp{-2}, and so on. Alternatively, you can use
the synonyms @samp{g00}, @samp{g000}, or @samp{g2_0}, @samp{g3_0}, and
so on that are defined in the standard units data file.
@example
@group
You have: brwiregauge(g00)
You want: inches
* 0.348
/ 2.8735632
@end group
@end example
@noindent
In North America, wire sizes larger than 0000 (``4/0'') are usually
given in terms of area, either in kcmil or the older initialism MCM
(thousand circular mils). Outside of North America, all wire sizes are
usually given in terms of area in
@c noman
@ifinfo
mm^2.
@end ifinfo
@c
@ifnotinfo
mm@sup{2}.
@end ifnotinfo
@c end noman
@c man .if n mm^2.
@c man .if t mm\v'-.4m'\s-32\s0\v'.4m'.
@c mm@sup{2}.
Wire area can be
obtained using @samp{wiregaugeA()} or its alias @samp{awgA()}:
@example
@group
You have: awgA(g6_0)
You want: kcmil
* 336.45718
/ 0.0029721464
You have: awgA(12)
You want: mm^2
* 3.3087729
/ 0.30222685
@end group
@end example
@noindent
The closest standard metric sizes are
2.5@tie{}mm@sup{2} and 4@tie{}mm@sup{2}; in general, there isn't an
exact correlation between American and metric wire sizes.
@cindex iron pipe size (IPS)
@cindex nominal pipe size (NPS)
@cindex pipe size
Though based on the long-established iron pipe size (IPS) given in
inches, nominal pipe size (NPS) is a dimensionless quantity that
corresponds to the inch size. Pipe size can be equivalently specified
using metric diam@U{00E8}tre nominal (DN), which roughly corresponds to
the diameter in mm. For a given pipe size, outside diameter is constant
while inside diameter varies with schedule. For example, for NPS
2@U{00BD} pipe,
@example
@group
You have: npsOD(2+1|2)
You want: in
* 2.875
/ 0.34782609
You have: nps40(2+1|2)
You want: in
* 2.469
/ 0.40502228
You have: nps80(2+1|2)
You want: in
* 2.323
/ 0.43047783
@end group
@end example
@noindent
Pipe size can be given equivalently in terms of the metric DN by using
the @samp{DN()} function, which converts nominal metric size to nominal
inch size:
@example
@group
You have: npsOD(DN(65))
You want: mm
* 73.025
/ 0.01369394
You have: _
You want: in
* 2.875
/ 0.34782609
@end group
@end example
@noindent
Unlike with wire sizes, actual NPS and metric DN pipe dimensions are the
same.
@example
@group
You have: grit_P(600)
You want: grit_ansicoated
342.76923
@end group
@end example
@noindent
The last example shows the conversion from P graded sand paper,
which is the European standard and may be marked ``P600'' on the back,
to the USA standard.
@cindex abrasive grit size
You can compute the area of a circle using the nonlinear unit,
@samp{circlearea}. You can also do this using the circularinch or
circleinch. The next example shows two ways to compute the area of a
circle with a five inch radius and one way to compute the volume of a
sphere with a radius of one meter.
@cindex circle, area of
@cindex sphere, volume of
@example
@group
You have: circlearea(5 in)
You want: in2
* 78.539816
/ 0.012732395
You have: 10^2 circleinch
You want: in2
* 78.539816
/ 0.012732395
You have: spherevol(meter)
You want: ft3
* 147.92573
/ 0.0067601492
@end group
@end example
@noindent
The inverse of a nonlinear conversion is indicated by prefixing a tilde
(@samp{~}) to the nonlinear unit name:
@example
@group
You have: ~wiregauge(0.090742002 inches)
You want:
Definition: 11
@end group
@end example
@noindent
You can give a nonlinear unit definition without an argument or
parentheses, and press @key{Enter} at the @w{@samp{You want:}} prompt to
get the definition of a nonlinear unit; if the definition is not valid
for all real numbers, the range of validity is also given. If the
definition requires specific units this information is also
displayed:
@example
@group
You have: tempC
Definition: tempC(x) = x K + stdtemp
defined for x >= -273.15
You have: ~tempC
Definition: ~tempC(tempC) = (tempC +(-stdtemp))/K
defined for tempC >= 0 K
You have: circlearea
Definition: circlearea(r) = pi r^2
r has units m
@end group
@end example
@noindent
To see the definition of the inverse use the @samp{~} notation. In
this case the parameter in the functional definition will
usually be the name of the unit. Note that the inverse for
@samp{tempC} shows that it requires units of @samp{K} in the
specification of the allowed range of values.
Nonlinear unit conversions are described in more detail in
@ref{Defining Nonlinear Units}.
@node Unit Lists
@c =====================================================================
@chapter Unit Lists: Conversion to Sums of Units
@c =====================================================================
@cindex sums of units
@cindex unit lists
@cindex units, sums of
@menu
* Cooking Measure
* Unit List Aliases
@end menu
Outside of the SI, it is sometimes desirable to convert a single
unit to a sum of units---for example, feet to feet plus inches.
The conversion @emph{from} sums of units was described in
@ref{Sums and Differences of Units}, and is a simple matter of adding
the units with the @samp{+} sign:
@example
@group
You have: 12 ft + 3 in + 3|8 in
You want: ft
* 12.28125
/ 0.081424936
@end group
@end example
@noindent
Although you can similarly write a sum of units to convert @emph{to},
the result will not be the conversion to the units in the sum, but
rather the conversion to the particular sum that you have entered:
@example
@group
You have: 12.28125 ft
You want: ft + in + 1|8 in
* 11.228571
/ 0.089058524
@end group
@end example
@noindent
The unit expression given at the @w{@samp{You want:}} prompt is
equivalent to asking for conversion to multiples of
@samp{1@tie{}ft + 1@tie{}in + 1|8@tie{}in}, which is 1.09375 ft, so the
conversion in the previous example is equivalent to
@example
@group
You have: 12.28125 ft
You want: 1.09375 ft
* 11.228571
/ 0.089058524
@end group
@end example
@noindent
In converting to a sum of units like miles, feet and inches, you
typically want the largest integral value for the first unit, followed
by the largest integral value for the next, and the remainder converted
to the last unit.
You can do this conversion easily with @command{units} using a special
syntax for lists of units. You must list the desired units in order
from largest to smallest, separated by the semicolon (@samp{;})
character:
@example
@group
You have: 12.28125 ft
You want: ft;in;1|8 in
12 ft + 3 in + 3|8 in
@end group
@end example
@noindent
The conversion always gives integer coefficients on the units in the
list, except possibly the last unit when the conversion is not exact:
@example
@group
You have: 12.28126 ft
You want: ft;in;1|8 in
12 ft + 3 in + 3.00096 * 1|8 in
@end group
@end example
@noindent
The order in which you list the units is important:
@example
@group
You have: 3 kg
You want: oz;lb
105 oz + 0.051367866 lb
You have: 3 kg
You want: lb;oz
6 lb + 9.8218858 oz
@end group
@end example
@noindent
Listing ounces before pounds produces a technically correct result,
but not a very useful one. You must list the units in descending
order of size in order to get the most useful result.
Ending a unit list with the separator @samp{;}
has the same effect as repeating the last
unit on the list, so @samp{ft;in;1|8 in;} is equivalent to
@samp{ft;in;1|8 in;1|8 in}. With the example above, this gives
@example
@group
You have: 12.28126 ft
You want: ft;in;1|8 in;
12 ft + 3 in + 3|8 in + 0.00096 * 1|8 in
@end group
@end example
@noindent
in effect separating the integer and fractional parts of the
coefficient for the last unit. If you instead
prefer to round the last coefficient to an integer
you can do this with the @option{--round} (@option{-r}) option.
With the previous example, the result is
@example
@group
You have: 12.28126 ft
You want: ft;in;1|8 in
12 ft + 3 in + 3|8 in (rounded down to nearest 1|8 in)
@end group
@end example
@noindent
When you use the @option{-r} option, repeating the last unit on the
list has no effect (e.g., @samp{ft;in;1|8 in;1|8 in} is equivalent to
@samp{ft;in;1|8 in}), and hence neither does ending a list with a
@samp{;}. With a single unit and the @option{-r} option, a terminal @samp{;}
@emph{does} have an effect: it causes @command{units} to treat the
single unit as a list and produce a rounded value for the single unit.
Without the extra @samp{;}, the @option{-r} option has no effect on
single unit conversions. This example shows the output using the
@option{-r} option:
@example
@group
You have: 12.28126 ft
You want: in
* 147.37512
/ 0.0067854058
You have: 12.28126 ft
You want: in;
147 in (rounded down to nearest in)
@end group
@end example
@noindent
Each unit that appears in the list must be conformable with the first
unit on the list, and of course the listed units must also be
conformable with the unit that you enter at the @w{@samp{You have:}}
prompt.
@example
@group
You have: meter
You want: ft;kg
^
conformability error
ft = 0.3048 m
kg = 1 kg
You have: meter
You want: lb;oz
conformability error
1 m
0.45359237 kg
@end group
@end example
@noindent
In the first case, @command{units} reports the disagreement between
units appearing on the list. In the second case, @command{units}
reports disagreement between the unit you entered and the desired
conversion. This conformability error is based on the first
unit on the unit list.
Other common candidates for conversion to sums of units are
angles and time:
@example
@group
You have: 23.437754 deg
You want: deg;arcmin;arcsec
23 deg + 26 arcmin + 15.9144 arcsec
You have: 7.2319 hr
You want: hr;min;sec
7 hr + 13 min + 54.84 sec
@end group
@end example
@noindent
Some applications for unit lists may be less obvious. Suppose that you
have a postal scale and wish to ensure that it's accurate at 1@tie{}oz,
but have only metric calibration weights. You might try
@example
@group
You have: 1 oz
You want: 100 g;50 g; 20 g;10 g;5 g;2 g;1 g;
20 g + 5 g + 2 g + 1 g + 0.34952312 * 1 g
@end group
@end example
@noindent
You might then place one each of the 20@tie{}g, 5@tie{}g, 2@tie{}g, and
1@tie{}g weights on the scale and hope that it indicates close to
@example
@group
You have: 20 g + 5 g + 2 g + 1 g
You want: oz;
0.98767093 oz
@end group
@end example
@noindent
Appending @samp{;} to @samp{oz} forces a one-line display that includes
the unit; here the integer part of the result is zero, so it is not
displayed.
If a non-empty list item differs vastly in scale from the quantity from
which the list is to be converted, you may exceed the available
precision of floating point (about 15 digits), in which case you will
get a warning, e.g.,
@example
@group
You have: lightyear
You want: mile;100 inch;10 inch;mm;micron
5.8786254e+12 mile + 390 * 100 inch (at 15-digit precision limit)
@end group
@end example
@c ---------------------------------------------------------------------
@section Cooking Measure
@c ---------------------------------------------------------------------
@noindent
In North America, recipes for cooking typically measure ingredients by
volume, and use units that are not always convenient multiples of each
other. Suppose that you have a recipe for 6 and you wish to make a
portion for 1. If the recipe calls for 2@tie{}1/2 cups of an
ingredient, you might wish to know the measurements in terms of
measuring devices you have available, you could use @command{units} and
enter
@example
@group
You have: (2+1|2) cup / 6
You want: cup;1|2 cup;1|3 cup;1|4 cup;tbsp;tsp;1|2 tsp;1|4 tsp
1|3 cup + 1 tbsp + 1 tsp
@end group
@end example
@noindent
By default, if a unit in a list begins with fraction of the form
1|@var{x} and its multiplier is an integer, the fraction is given as
the product of the multiplier and the numerator; for example,
@example
@group
You have: 12.28125 ft
You want: ft;in;1|8 in;
12 ft + 3 in + 3|8 in
@end group
@end example
@noindent
In many cases, such as the example above, this is what is wanted, but
sometimes it is not. For example, a cooking recipe for 6 might call
for 5@tie{}1/4 cup of an ingredient, but you want a portion for 2, and
your 1-cup measure is not available; you might try
@example
@group
You have: (5+1|4) cup / 3
You want: 1|2 cup;1|3 cup;1|4 cup
3|2 cup + 1|4 cup
@end group
@end example
@noindent
This result might be fine for a baker who has a 1@tie{}1/2-cup measure
(and recognizes the equivalence), but it may not be as useful to
someone with more limited set of measures, who does want to do
additional calculations, and only wants to know ``How many 1/2-cup
measures to I need to add?'' After all, that's what was actually
asked. With the @option{--show-factor} option, the factor will not be
combined with a unity numerator, so that you get
@example
@group
You have: (5+1|4) cup / 3
You want: 1|2 cup;1|3 cup;1|4 cup
3 * 1|2 cup + 1|4 cup
@end group
@end example
@noindent
A user-specified fractional unit with a numerator other than 1 is never
overridden, however---if a unit list specifies @samp{3|4 cup;1|2 cup},
a result equivalent to 1@tie{}1/2 cups will always be shown as
@samp{2 * 3|4@tie{}cup} whether or not the @option{--show-factor} option
is given.
@c ---------------------------------------------------------------------
@section Unit List Aliases
@c ---------------------------------------------------------------------
@cindex unit list aliases
@noindent
A unit list such as
@example
cup;1|2@tie{}cup;1|3@tie{}cup;1|4@tie{}cup;tbsp;tsp;1|2@tie{}tsp;1|4@tie{}tsp
@end example
@noindent
can be tedious to enter. The @command{units} program provides shorthand names
for some common combinations:
@example
hms @r{time: hours, minutes, seconds}
dms @r{angle: degrees, minutes, seconds}
time @r{time: years, days, hours, minutes and seconds}
usvol @r{US cooking volume: cups and smaller}
uswt @r{US weight: pounds and ounces}
ftin @r{length: feet, inches and 1/8 inches}
ftin2 @r{length: feet, inches and 1/2 inches}
ftin4 @r{length: feet, inches and 1/4 inches}
ftin8 @r{length: feet, inches and 1/8 inches}
ftin16 @r{length: feet, inches and 1/16 inches}
ftin32 @r{length: feet, inches and 1/32 inches}
ftin64 @r{length: feet, inches and 1/64 inches}
inchfine @r{length: inches subdivided to 1/64 inch}
@end example
@noindent
Using these shorthands, or @dfn{unit list aliases},
you can do the following conversions:
@example
@group
You have: anomalisticyear
You want: time
1 year + 25 min + 3.4653216 sec
You have: 1|6 cup
You want: usvol
2 tbsp + 2 tsp
@end group
@end example
@noindent
Suppose you want to drill a clearance hole for a #10 screw and have
about 1/64 inch clearance; you could try
@example
@group
You have: screwgauge(10) + 1|64 in
You want: ftin64
13.16 * 1|64 in
You have: _
You want: ftin32
6.58 * 1|32 in
@end group
@end example
@noindent
If a slightly tight fit is acceptable, a 13/64-inch drill would do the
job; if not, a 7/32-inch drill would work with a slightly looser fit.
You can define your own unit list aliases;
@pxref{Defining Unit List Aliases}.
You cannot combine a unit list alias with other units: it must appear
alone at the @w{@samp{You want:}} prompt.
You can display the definition of a unit list alias by entering it at
the @w{@samp{You have:}} prompt:
@example
@group
You have: dms
Definition: unit list, deg;arcmin;arcsec
@end group
@end example
@noindent
When you specify compact output with @option{--compact},
@option{--terse} or @option{-t} and perform conversion to a unit list,
@command{units} lists the conversion factors for each unit in the
list, separated by semicolons.
@example
@group
You have: year
You want: day;min;sec
365;348;45.974678
@end group
@end example
@noindent
Unlike the case of regular
output, zeros @emph{are} included in this output list:
@example
@group
You have: liter
You want: cup;1|2 cup;1|4 cup;tbsp
4;0;0;3.6280454
@end group
@end example
@node Alternative Unit Systems
@c =====================================================================
@chapter Alternative Unit Systems
@c =====================================================================
@menu
* CGS Units::
* Natural Units::
* Prompt Prefix:: The prompt prefix shows specified CGS units
@end menu
@node CGS Units
@c ---------------------------------------------------------------------
@section CGS Units
@c ---------------------------------------------------------------------
@cindex CGS units, using
@menu
* Specifying CGS Units:: How to specify the desired CGS units
* CGS Units Systems:: The various CGS units systems
* Conversions Between Systems:: Conversions between units in different systems
@end menu
The SI---an extension of the MKS (meter--kilogram--second) system---has
largely supplanted the older CGS (centimeter--gram--second) system, but
CGS units are still used in a few specialized fields, especially in
physics where they lead to a more elegant formulation of Maxwell's equations.
Conversions between SI and CGS involving mechanical units are
straightforward, involving powers of 10 (e.g., @w{1 m = 100 cm}).
Conversions involving electromagnetic units are more complicated, and
@command{units} supports four different systems of CGS units:
electrostatic units (ESU), electromagnetic units (EMU), the
Gaussian system and the Heaviside--Lorentz system.
The differences between these systems
arise from different choices made for proportionality
constants in electromagnetic equations.
Coulomb's law gives electrostatic force between two
charges separated by a distance
@c noman
@math{r}:
@ifinfo
@display
F = k_C q_1 q_2 / r^2.
@end display
@end ifinfo
@ifnotinfo
@displaymath
F = k_{\rm C} { {q_1 q_2} \over {r^2} }.
@end displaymath
@end ifnotinfo
@c end noman
@c
@c man .EQ
@c man delim $$
@c man .EN
@c man .if n \fIr\fP:
@c man .if t $r$:
@c man .RS 5n
@c man .PP
@c man .if n \fIF\fP = \fIk\fP_C \fIq\fP_1\ \fIq\fP_2\ /\ \fIr\fP^2.
@c man .if t \{\
@c man .EQ
@c man F = k sub roman C { q sub 1 q sub 2} over r sup 2.
@c man .EN
@c man .\}
@c man .RE
@noindent
Ampere's law gives the electromagnetic force per unit length
between two current-carrying conductors separated by a distance
@c noman
@math{r}:
@ifinfo
@display
F/l = 2 k_A I_1 I_2 / r.
@end display
@end ifinfo
@ifnotinfo
@displaymath
{ F \over \ell } = 2 k_{\rm A} { {I_1 I_2} \over {r} } .
@end displaymath
@end ifnotinfo
@c end noman
@c
@c man .if n \fIr\fP:
@c man .if t $r$:
@c man .RS 5n
@c man .PP
@c man .if n \fIF\fP/\fIl\fP = 2 \fIk\fP_A \fII\fP_1\ \fII\fP_2\ /\ \fIr\fP.
@c man .if t \{\
@c man .EQ
@c man F over l = 2 k sub roman A { I sub 1 I sub 2 } over r .
@c man .EN
@c man .\}
@c man .RE
@noindent
The two constants,
@c noman
@ifnotinfo
@math{k_{\rm C}} and @math{k_{\rm A}},
@end ifnotinfo
@ifinfo
k_C and k_A,
@end ifinfo
are related by the square of the speed of light:
@ifinfo
k_A = k_C / c^2.
@end ifinfo
@ifnotinfo
@displaymath
k_{\rm A} = k_{\rm C} / c^{2}.
@end displaymath
@end ifnotinfo
@c end noman
@c
@c man .if n \fIk\fP_C and \fIk\fP_A,
@c man .if t $k sub roman C$ and $k sub roman A$,
@c man are related by the square of the speed of light:
@c man .if n \fIk\fP_A\ =\ \fIk\fP_C\ /\ \fIc\fP^2.
@c man .if t $k sub roman A = k sub roman C / c sup 2$.
In the SI, the constants have dimensions, and an additional base unit,
the ampere, measures electric current. The CGS systems do not define
new base units, but express charge and current as derived units in
terms of mass, length, and time. In the ESU system, the constant for
Coulomb's law is chosen to be unity and dimensionless, which defines
the unit of charge. In the EMU system, the constant for Ampere's law
is chosen to be unity and dimensionless, which defines a unit of
current. The Gaussian system usually uses the ESU units for charge
and current; it chooses another constant so that the units for the
electric and magnetic fields are the same. The Heaviside--Lorentz
system is ``rationalized'' so that factors of
@c noman
@math{4\pi}
@c end noman
@c
@c man .if n 4{pi}
@c man .if t 4\(*p
do not appear in
Maxwell's equations. The SI system is similarly rationalized, but the
other CGS systems are not. In the Heaviside--Lorentz (HLU) system the
factor of
@c noman
@math{4\pi}
@c end noman
@c
@c man .if n 4{pi}
@c man .if t 4\(*p
appears in Coulomb's law instead; this system differs
from the Gaussian system by factors of
@c noman
@math{\sqrt{4\pi}}.
@c end noman
@c
@c man .if n the square root of 4{pi}
@c man .if t \(sr\o'\[sqrtex]4'\o'\[sqrtex]\(*p'\^.
The dimensions of electrical quantities in the various CGS systems are
different from the SI dimensions for the same units;
strictly, conversions between these systems and SI are not possible.
But units in different systems relate to the same physical quantities,
so there is a @emph{correspondence} between these units.
The @command{units} program defines the units so that you can convert
between corresponding units in the various systems.
@node Specifying CGS Units
@subsection Specifying CGS Units
@cindex CGS units, specifying
The CGS definitions involve
@c noman
@ifinfo
cm^(1/2) and g^(1/2)
@end ifinfo
@ifnotinfo
@math {{\rm cm}^{1/2}} and @math{{\rm g}^{1/2}},
@end ifnotinfo
@c end noman
@c
@c man .if n cm^(1/2) and g^(1/2),
@c man .if t cm$"" sup {1/2}$ and g$"" sup {1/2}$,
@c man
@c
which is problematic because @command{units} does not normally support
fractional roots of base units. The @option{--units} (@option{-u})
option allows selection of a CGS unit system and works around this
restriction by introducing base units for the square roots of length
and mass: @samp{sqrt_cm} and @samp{sqrt_g}. The centimeter then
becomes @samp{sqrt_cm^2} and the gram, @samp{sqrt_g^2}. This allows
working from equations using the units in the CGS system, and
enforcing dimensional conformity within that system. Recognized CGS
arguments to the @option{--units} option are @samp{gauss[ian]},
@samp{esu}, @samp{emu}, @samp{lhu}; the argument is case insensitive.
You can also give @samp{si} which just enforces the default SI mode
and displays @samp{(SI)} at the @w{@samp{You have:}} prompt to
emphasize the units mode. Some other types of units are also
supported as described below. Giving an unrecognized system generates
a warning, and @command{units} uses SI units.
The changes resulting from the @option{--units} option are actually
controlled by the @env{UNITS_SYSTEM} environment variable. If you
frequently work with one of the supported CGS units systems, you may set
this environment variable rather than giving the @option{--units} option
at each invocation. As usual, an option given on the command line
overrides the setting of the environment variable. For example, if you would
normally work with Gaussian units but might occasionally work with
SI, you could set @env{UNITS_SYSTEM} to @samp{gaussian} and specify
SI with the @option{--units} option.
Unlike the argument to the @option{--units} option, the value of
@env{UNITS_SYSTEM} @emph{is} case sensitive, so setting a value of
@samp{EMU} will have no effect other than to give an error message and
set SI units.
The CGS definitions appear as conditional settings in the standard
units data file, which you can consult for more information on how
these units are defined, or on how to define an alternate units system.
@node CGS Units Systems
@subsection CGS Units Systems
@cindex CGS Units Systems
@cindex units systems, CGS
The ESU system derives the electromagnetic units from its unit of
charge, the statcoulomb,
which is defined from
Coulomb's law. The statcoulomb equals
@c noman
@ifinfo
@w{dyne^(1/2) cm} or @w{cm^(3/2) g^(1/2) s^(-1)}.
@end ifinfo
@c
@ifnotinfo
@math{{\rm dyne}^{1/2}\,{\rm cm}} or @math{{\rm cm}^{3/2}\,{\rm g}^{1/2}\,{\rm s}^{-1}}.
@end ifnotinfo
@c end noman
@c
@c man .if n dyne^(1/2)\ cm, or cm^(3/2)\ g^(1/2)\ s^(\(mi1).
@c man .if t $roman dyne sup {1/2} ^ roman cm$,
@c man .if t or $roman cm sup {3/2} ^ roman g sup {1/2} ^ roman s sup {-1}$.
The unit of current, the statampere, is @w{statcoulomb sec}, analogous to
the relationship in SI. Other electrical units are then derived in a
manner similar to that for SI units; the units use the SI names prefixed
by @samp{stat-}, e.g., @samp{statvolt} or @samp{statV}. The prefix
@samp{st-} is also recognized (e.g., @samp{stV}).
The EMU system derives the electromagnetic units from its unit of current,
the abampere, which is defined in terms of Ampere's law. The abampere
is equal to
@c noman
@ifinfo
dyne^(1/2) or @w{cm^(1/2) g^(1/2) s^(-1)}.
@end ifinfo
@ifnotinfo
@math{{\rm dyne}^{1/2}} or
@math{{\rm cm}^{1/2}{\rm g}^{1/2}{\rm s}^{-1}}.
@end ifnotinfo
@c
@c end noman
@c
@c man .if n dyne^(1/2), or cm^(1/2)\ g^(1/2)\ s^(\(mi1).
@c man .if t $roman dyne sup {1/2}$,
@c man .if t or $roman cm sup {1/2} ^ roman g sup {1/2} ^ roman s sup{-1}$.
@c man .EQ
@c man delim off
@c man .EN
The unit of charge, the abcoulomb, is
@w{abampere sec}, again analogous to the SI relationship.
Other electrical units are then derived in a
manner similar to that for SI units; the units use the SI names prefixed
by @samp{ab-}, e.g., @samp{abvolt} or @samp{abV}. The magnetic field
units include the gauss, the oersted and the maxwell.
The Gaussian units system, which was also known as the Symmetric
System,
uses the same charge and current units as the ESU system (e.g.,
@samp{statC}, @samp{statA}); it differs by defining the magnetic field
so that it has the same units as the electric field. The resulting
magnetic field units are the same ones used in the EMU system: the
gauss, the oersted and the maxwell.
The Heaviside--Lorentz system appears to lack named units. We define
five basic units, @samp{hlu_charge}, @samp{hlu_current}, @samp{hlu_volt}, @samp{hlu_efield} and
@samp{hlu_bfield} for conversions with this system. It is important to
remember that with all of the CGS systems, the units may look the same
but mean something different. The HLU system and Gaussian systems
both measure magnetic field using the same CGS dimensions, but the
amount of magnetic field with the same units is different in the two
systems.
@node Conversions Between Systems
@subsection Conversions Between Different Systems
The CGS systems define units that measure the same thing but may have
conflicting dimensions. Furthermore, the dimensions of the
electromagnetic CGS units are never compatible with SI.
But if you measure charge in two different systems you have measured the
same physical thing, so there is a @emph{correspondence} between the
units in the different systems, and @command{units} supports conversions
between corresponding units. When running with SI, @command{units}
defines all of the CGS units in terms of SI. When you select a CGS
system, @command{units} defines the SI units and the other CGS system
units in terms of the system you have selected.
@example
@group
(Gaussian) You have: statA
You want: abA
* 3.335641e-11
/ 2.9979246e+10
(Gaussian) You have: abA
You want: sqrt(dyne)
conformability error
2.9979246e+10 sqrt_cm^3 sqrt_g / s^2
1 sqrt_cm sqrt_g / s
@end group
@end example
@noindent
In the above example, @command{units} converts between the current
units statA and abA even though the abA, from the EMU system, has
incompatible dimensions. This works because in Gaussian mode, the abA
is defined in terms of the statA, so it does not have the correct
definition for EMU; consequently, you cannot convert the abA to its EMU
definition.
One challenge of conversion is that because
the CGS system has fewer base units, quantities that have different
dimensions in SI may have the same dimension in a CGS system. And
yet, they may not have the same conversion factor. For example, the
unit for the @math{E} field and @math{B} fields are the same in the
Gaussian system, but the conversion factors to SI are quite
different. This means that correct conversion is only possible if you
keep track of what quantity is being measured. You cannot convert
statV/cm to SI without indicating which type of field the unit
measures. To aid in dimensional analysis, @command{units} defines
various dimension units such as @samp{LENGTH}, @samp{TIME}, and @samp{CHARGE} to be the
appropriate dimension in SI. The
electromagnetic dimensions such as @samp{B_FIELD} or @samp{E_FIELD} may be useful
aids both for conversion and dimensional analysis in CGS. You
can convert them to or from CGS in order to perform SI conversions
that in some cases will not work directly due to dimensional incompatibilities.
This example shows how the Gaussian system uses the same units for all
of the fields, but they all have different conversion factors with
SI.
@example
@group
(Gaussian) You have: statV/cm
You want: E_FIELD
* 29979.246
/ 3.335641e-05
@end group
@group
(Gaussian) You have: statV/cm
You want: B_FIELD
* 0.0001
/ 10000
@end group
@group
(Gaussian) You have: statV/cm
You want: H_FIELD
* 79.577472
/ 0.012566371
@end group
@group
(Gaussian) You have: statV/cm
You want: D_FIELD
* 2.6544187e-07
/ 3767303.1
@end group
@end example
@noindent
The next example shows that the oersted cannot be converted directly
to the SI unit of magnetic field, A/m, because the dimensions
conflict. We cannot redefine the ampere to make this work because
then it would not convert with the statampere. But you can still do
this conversion as shown below.
@example
@group
(Gaussian) You have: oersted
You want: A/m
conformability error
1 sqrt_g / s sqrt_cm
29979246 sqrt_cm sqrt_g / s^2
(Gaussian) You have: oersted
You want: H_FIELD
* 79.577472
/ 0.012566371
@end group
@end example
@node Natural Units
@c ---------------------------------------------------------------------
@section Natural Units
@c ---------------------------------------------------------------------
@cindex Natural units, using
Like the CGS units, ``natural'' units are an alternative to the SI
system used primarily physicists in different fields, with different
systems tailored to different fields of study. These
systems are ``natural'' because the base measurements are defined
using physical constants instead of arbitrary values such as the meter
or second. In different branches of physics, different physical constants
are more fundamental, which has given rise to a variety of incompatible natural
unit systems.
The supported systems are the ``natural'' units (which seem to have no
better name) used in high energy physics and cosmology, the Planck
units, often used by scientists working with gravity, and the Hartree
atomic units are favored by those working in physical chemistry and
condensed matter physics.
You can select the various natural units using the @option{--units}
option in the same way that you select the CGS units. The ``natural''
units come in two types, a rationalized system derived from the
Heaviside--Lorentz units and an unrationalized system derived from the
Gaussian system. You can select these using @samp{natural} and
@samp{natural-gauss} respectively. For conversions in SI mode,
several unit names starting with @samp{natural} are available.
This ``natural'' system is defined by setting
@c noman
@math{\hbar},
@c end noman
@c
@c man .if n {hbar},
@c man .if t \[hbar],
@math{c} and the Boltzman
constant to 1. Only a single base unit remains: the electron volt.
The Planck units exist in a variety of forms, and @command{units}
supports two. Both supported forms are rationalized, in that factors
of
@c noman
@math{4\pi}
@c end noman
@c
@c man .if n 4{pi}
@c man .if t 4\(*p
do not appear in Maxwell's equations. However, Planck units
can also differ based on how the gravitational constant is treated.
This system is similar to the natural units in that @math{c},
@c noman
@math{\hbar},
@c end noman
@c
@c man .if n {hbar},
@c man .if t \[hbar],
and
Boltzman's constant are set to 1, but in this system, Newton's
gravitational constant,
@c noman
@math{G},
@c end noman
@c
@c man \fIG\fP
is also fixed. In the ``reduced'' Planck
system,
@c noman
@math{8 \pi G=1}
@c end noman
@c
@c man .EQ
@c man delim $$
@c man .EN
@c man .if n 8{pi}\fIG\fP\ =\ 1
@c man .if t $8 pi G = 1$
whereas in the unreduced system
@c noman
@math{G = 1}.
@c end noman
@c
@c man .if n \fIG\fP\ =\ 1.
@c man .if t $G = 1$.
The reduced system eliminates factors of
@c noman
@math{8 \pi}
@c end noman
@c
@c man .if n 8{pi}
@c man .if t 8\(*p
@c man .EQ
@c man delim off
@c man .EN
from the Einstein field equations for gravitation, so this is similar to
the process of forming rationalized units to simplify Maxwell's equations.
To obtain the unreduced system use the name @samp{planck} and for the
reduced Planck units, @samp{planck-red}. Units such as
@samp{planckenergy} and @samp{planckenergy_red} enable you to convert
the unreduced and reduced Planck energy unit in SI mode between the
various systems. In Planck units, all measurements are
dimensionless.
The final natural unit system is the Hartree atomic units. Like the
Planck units, all measurements in the Hartree units are dimensionless,
but this system is defined by defined from completely different
physical constants: the electron mass, Planck's constant, the electron
charge, and the Coulomb constant are the defining physical
quantities, which are all set to unity. To invoke this system with
the @option{--units} option use the name @samp{hartree}.
@node Prompt Prefix
@c ---------------------------------------------------------------------
@section Prompt Prefix
@c ---------------------------------------------------------------------
@cindex prompt prefix with CGS units
@cindex CGS units, prompt prefix
If a unit system is specified with the @option{--units} option, the
selected system's name is prepended to the @w{@samp{You have:}} prompt
as a reminder, e.g.,
@example
@group
(Gaussian) You have: stC
You want:
Definition: statcoulomb = sqrt(dyne) cm = 1 sqrt_cm^3 sqrt_g / s
@end group
@end example
@noindent
You can suppressed the prefix by including a line
@example
!prompt
@end example
@noindent
with no argument in a site or personal units data file. The prompt can
be conditionally suppressed by including such a line within
@samp{!var} ... @samp{!endvar} constructs, e.g.,
@example
@group
!var UNITS_SYSTEM gaussian gauss
!prompt
!endvar
@end group
@end example
@noindent
This might be appropriate if you normally use Gaussian units and find
the prefix distracting but want to be reminded when you have selected a
different CGS system.
@node Logging Calculations
@c =====================================================================
@chapter Logging Calculations
@c =====================================================================
@cindex logging calculations
@cindex log file
The @option{--log} option allows you to save the results of calculations
in a file; this can be useful if you need a permanent record of your
work. For example, the fluid-flow conversion in
@ref{Complicated Unit Expressions}, is lengthy, and if you were to use
it in designing a piping system, you might want a record of it for the
project file. If the interactive session
@example
@group
# Conversion factor A1 for pressure drop
# dP = A1 rho f L Q^2/d^5
You have: (8/pi^2) (lbm/ft^3)ft(ft^3/s)^2(1/in^5) # Input units
You want: psi
* 43.533969
/ 0.022970568
@end group
@end example
@noindent
were logged, the log file would contain
@example
@group
### Log started Fri Oct 02 15:55:35 2015
# Conversion factor A1 for pressure drop
# dP = A1 rho f L Q^2/d^5
From: (8/pi^2) (lbm/ft^3)ft(ft^3/s)^2(1/in^5) # Input units
To: psi
* 43.533969
/ 0.022970568
@end group
@end example
@noindent
The time is written to the log file when the file is opened.
The use of comments can help clarify the meaning of calculations for
the log.
The log includes conformability errors between the units at the
@w{@samp{You have:}} and @w{@samp{You want:}} prompts, but not other
errors, including lack of conformability of items in sums or differences
or among items in a unit list. For example, a conversion between zenith
angle and elevation angle could involve
@example
@group
You have: 90 deg - (5 deg + 22 min + 9 sec)
^
Invalid sum or difference of non-conformable units
You have: 90 deg - (5 deg + 22 arcmin + 9 arcsec)
You want: dms
84 deg + 37 arcmin + 51 arcsec
You have: _
You want: deg
* 84.630833
/ 0.011816024
You have:
@end group
@end example
@noindent
The log file would contain
@example
@group
From: 90 deg - (5 deg + 22 arcmin + 9 arcsec)
To: deg;arcmin;arcsec
84 deg + 37 arcmin + 51 arcsec
From: _
To: deg
* 84.630833
/ 0.011816024
@end group
@end example
@noindent
The initial entry error (forgetting that minutes have dimension of time,
and that arcminutes must be used for dimensions of angle) does not
appear in the output. When converting to a unit list alias,
@command{units} expands the alias in the log file.
The @samp{From:} and @samp{To:} tags are written to the log file even if
the @option{--quiet} option is given. If the log file exists when
@command{units} is invoked, the new results are appended to the log file.
The time is written to the log file each time the file is opened.
The @option{--log} option is ignored when @command{units} is used
non-interactively.
@node Invoking Units
@c =====================================================================
@chapter Invoking @command{units}
@c =====================================================================
@cindex invoking units
@cindex command-line options
You invoke @command{units} like this:
@example
units [@var{options}] [@var{from-unit} [@var{to-unit}]]
@end example
@noindent
If the @var{from-unit} and @var{to-unit} are omitted, the program
will use interactive prompts to determine which conversions to perform.
@xref{Interactive Use}.
If both @var{from-unit} and @var{to-unit} are given, @command{units} will
print the result of that single conversion and then exit.
If only @var{from-unit} appears on the command line, @command{units} will
display the definition of that unit and exit.
Units specified on the command line may need
to be quoted to protect them from shell interpretation and to group
them into two arguments. Note also that the @option{--quiet} option
is enabled by default if you specify @var{from-unit} on the command line.
@xref{Command Line Use}.
The default behavior of @command{units} can be changed by various
options given on the command line. In most cases, the options may be
given in either short form (a single @samp{-} followed by a single
character)
or long form (@option{--} followed by a word or hyphen-separated words).
Short-form options are cryptic but require
less typing; long-form options require more typing but are more
explanatory and may be more mnemonic. With long-form options you need
only enter sufficient characters to uniquely identify the option to
the program. For example, @option{--out@tie{}%f} works, but
@option{--o@tie{}%f} fails because @command{units} has other long options
beginning with @samp{o}. However, @option{--q} works because
@option{--quiet} is the only long option beginning with @samp{q}.
Some options require
arguments to specify a value (e.g., @option{-d@tie{}12} or
@option{--digits@tie{}12}). Short-form options that do not take
arguments may be concatenated (e.g., @option{-erS} is equivalent to
@option{-e@tie{}-r@tie{}-S}); the last option in such a list may be one
that takes an argument (e.g., @option{-ed@tie{}12}). With short-form
options, the space between an option and its argument is optional (e.g.,
@option{-d12} is equivalent to @option{-d@tie{}12}). Long-form options may
not be concatenated, and the space between a long-form option and its
argument is required. Short-form and long-form options may be
intermixed on the command line. Options may be given in any order, but
when incompatible options (e.g., @option{--output-format} and
@option{--exponential}) are given in combination, behavior is controlled
by the last option given. For example, @option{-o%.12f@tie{}-e} gives
exponential format with the default eight significant digits).
Many options can be set interactively; this can be especially helpful
for Windows users who start @command{units} from a shortcut.
@xref{Setting Options Interactively} for more information.
The following options are available:
@table @env
@item -c
@itemx --check
@opindex -c @r{(option for} @command{units}@r{)}
@opindex --check @r{(option for} @command{units}@r{)}
Check that all units and prefixes defined in units data files reduce to
primitive units. Display a list of all units that cannot be reduced and
a list of units with circular definitions. Also display some other
diagnostics about suspicious definitions in the units data file. Only
definitions active in the current locale are checked. You should always
run @command{units} with this option after modifying a units data file.
Some errors may hide other errors, so you should run @command{units}
with this option again after correcting any errors, and keep doing so
until there are no errors.
@item --check-verbose
@itemx --verbose-check
@opindex --check-verbose @r{(option for} @command{units}@r{)}
@opindex --verbose-check @r{(option for} @command{units}@r{)}
Like the @option{--check} option, this option displays a list of units that
cannot be reduced. But it also lists the units as they are checked.
Because the @option{--check} option now catches circular unit
definitions that previously caused @command{units} to hang, this option
is no longer necessary. It is retained only for compatibility with
previous versions.
@item -d @var{ndigits}
@itemx --digits @var{ndigits}
@opindex -d @r{(option for} @command{units}@r{)}
@opindex --digits @r{(option for} @command{units}@r{)}
Set the number of significant digits in the output to the value
specified (which must be greater than zero). For example,
@option{-d@tie{}12} sets the number of significant digits to 12.
With exponential output, @command{units} displays one digit to the left
of the decimal point and eleven digits to the right of the decimal point.
On most systems, the maximum number of internally meaningful digits is
15; if you specify a greater number than your system's maximum, @command{units}
will print a warning and set the number to the largest meaningful
value. To directly set the maximum value, give an argument
of @code{max} (e.g., @option{-d@tie{}max}). Be aware, of course, that
``significant'' here refers only to the @emph{display} of numbers; if
results depend on physical constants not known to this precision, the
physically meaningful precision may be less than that shown. The
@option{--digits} option is incompatible with the @option{--output-format}
option; if you give them both, the format is controlled by the last
option given.
@item -e
@itemx --exponential
@opindex -e @r{(option for} @command{units}@r{)}
@opindex --exponential @r{(option for} @command{units}@r{)}
Set the numeric output format to exponential (i.e., scientific
notation), like that used in the Unix @command{units} program.
The default precision is eight significant digits (seven digits to the
right of the decimal point); this can be changed with the
@option{--digits} option. The @option{--exponential}
option is incompatible with the @option{--output-format} option; if you
give them both, the format is controlled by the last option given.
@item -o @var{format}
@itemx --output-format @var{format}
@opindex -o @r{(option for} @command{units}@r{)}
@opindex --output-format @r{(option for} @command{units}@r{)}
This option affords complete control over the numeric output format
using the specified @var{format}. The format is a single floating
point numeric format for the @code{printf} function in the
C programming language. All compilers support the format types @samp{g}
and @samp{G} to specify significant digits, @samp{e} and @samp{E} for
scientific notation, and @samp{f} for fixed-point decimal.
The ISO C99 standard introduced the @samp{F} type for fixed-point
decimal and the @samp{a} and @samp{A} types for hexadecimal
floating point; these types are allowed with compilers that support
them. The default format is @samp{%.8g}; for greater precision, you
could specify @option{-o@tie{}%.15g}. Unlike with the @option{--digits}
option, you can specify any desired precision, though not all digits may
be meaningful. @xref{Numeric Output Format}, and the documentation for
@code{printf} for more detailed descriptions of the format
specification. The @option{--output-format} option affords the greatest
control of the output appearance, but requires at least rudimentary
knowledge of the @code{printf} format syntax. If you don't want to
bother with the @code{printf} syntax, you can specify greater precision
more simply with the @option{--digits} option or select exponential
format with @option{--exponential}. The @option{--output-format} option
is incompatible with the @option{--exponential} and @option{--digits}
options; if you give either in combination with @option{--output-format},
the format is controlled by the last option given.
@item -f @var{filename}
@itemx --file @var{filename}
@opindex -f @r{(option for} @command{units}@r{)}
@opindex --file @r{(option for} @command{units}@r{)}
Instruct @command{units} to load the units file @var{filename}. You
can specify up to 25 units files on the command line. When you use
this option, @command{units} will load @emph{only} the files you list
on the command line; it will not load the standard file or your
personal units file unless you explicitly list them. If @var{filename}
is the empty string (@w{@option{-f ""}}), the default main units file (or
that specified by @env{UNITSFILE}) will be loaded in addition to any
others specified with @option{-f}.
@item -L @var{logfile}
@itemx --log @var{logfile}
@opindex -L @r{(option for} @command{units}@r{)}
@opindex --log @r{(option for} @command{units}@r{)}
Save the results of calculations in the file @var{logfile}; this can be
useful if it is important to have a record of unit conversions or other
calculations that are to be used extensively or in a critical activity
such as a program or design project. If @var{logfile} exits, the new
results are appended to the file.
This option is ignored when @command{units} is used non-interactively.
@xref{Logging Calculations}, for a more detailed description and some
examples.
@item -H @var{filename}
@itemx --history @var{filename}
@opindex -H @r{(option for} @command{units}@r{)}
@opindex --history @r{(option for} @command{units}@r{)}
Instruct @command{units} to save history to @var{filename}, so that a
record of your commands is available for retrieval across different
@command{units} invocations. To prevent the history from being saved
set @var{filename} to the empty string (@w{@option{-H ""}}). This
option has no effect if readline is not available.
@item -h
@itemx --help
@opindex -h @r{(option for} @command{units}@r{)}
@opindex --help @r{(option for} @command{units}@r{)}
Print out a summary of the options for @command{units}.
@item -m
@itemx --minus
@opindex -m @r{(option for} @command{units}@r{)}
@opindex --minus @r{(option for} @command{units}@r{)}
Causes @samp{-} to be interpreted as a subtraction operator. This is
the default behavior.
@item -p
@itemx --product
@opindex -p @r{(option for} @command{units}@r{)}
@opindex --product @r{(option for} @command{units}@r{)}
Causes @samp{-} to be interpreted as a multiplication operator when it
has two operands. It will act as a negation operator when it has only one
operand: @samp{(-3)}. By default @samp{-} is treated as a
subtraction operator.
@item --oldstar
@opindex --oldstar @r{(option for} @command{units}@r{)}
Causes @samp{*} to have the old-style precedence, higher than the
precedence of division so that @samp{1/2*3} will equal @samp{1/6}.
@item --newstar
@opindex --newstar @r{(option for} @command{units}@r{)}
Forces @samp{*} to have the new (default) precedence that follows
the usual rules of algebra: the precedence of @samp{*} is the same as
the precedence of @samp{/}, so that @samp{1/2*3} will equal @samp{3/2}.
@item -r
@itemx --round
When converting to a combination of units given by a unit list, round
the value of the last unit in the list to the nearest integer.
@item -S
@itemx --show-factor
When converting to a combination of units specified in a list,
always show a non-unity factor before a unit that
begins with a fraction with a unity denominator. By default, if the
unit in a list begins with fraction of the form 1|@var{x} and
its multiplier is an integer other than 1, the fraction is given as the
product of the multiplier and the numerator (e.g., @samp{3|8@tie{}in}
rather than @samp{3 * 1|8@tie{}in}). In some cases, this is not what is
wanted; for example, the results for a cooking recipe might show
@samp{3 * 1|2@tie{}cup} as @samp{3|2@tie{}cup}.
With the @option{--show-factor} option, a
result equivalent to 1.5 cups will display as @samp{3 * 1|2@tie{}cup}
rather than @samp{3|2@tie{}cup}. A user-specified fractional unit with
a numerator other than 1 is never overridden, however---if a unit list
specifies @samp{3|4 cup;1|2 cup}, a result equivalent to 1@tie{}1/2 cups
will always be shown as @samp{2 * 3|4@tie{}cup} whether or not the
@option{--show-factor} option is given.
@item --conformable
@opindex --conformable @r{(option for} @command{units}@r{)}
In non-interactive mode, show all units conformable with the original
unit expression. Only one unit expression is allowed; if you give more
than one, @command{units} will exit with an error message and return
failure.
@item -v
@itemx --verbose
@opindex -v @r{(option for} @command{units}@r{)}
@opindex --verbose @r{(option for} @command{units}@r{)}
Give slightly more verbose output when converting units. When combined
with the @option{-c} option this gives the same effect as
@option{--check-verbose}. When combined with @option{--version}
produces a more detailed output, equivalent to the @option{--info}
option.
@item -V
@itemx --version
@opindex -V @r{(option for} @command{units}@r{)}
@opindex --version @r{(option for} @command{units}@r{)}
Print the program version number, tell whether the @command{readline}
library has been included, tell whether UTF-8 support has been included;
give the locale, the location of the default main units data file, and
the location of the personal units data file; indicate if the personal
units data file does not exist.
When given in combination with the @option{--terse} option, the program
prints only the version number and exits.
When given in combination with the @option{--verbose} option, the
program, the @option{--version} option has the same effect as the
@option{--info} option below.
@item -I
@itemx --info
@opindex -I @r{(option for} @command{units}@r{)}
@opindex --info @r{(option for} @command{units}@r{)}
Print the information given with the @option{--version} option, show the
pathname of the units program, show the status of the @env{UNITSFILE}
and @env{MYUNITSFILE} environment variables, and additional information
about how @command{units} locates the related files. On systems running
Microsoft Windows, the status of the @env{UNITSLOCALE} environment
variable and information about the related locale map are also given.
This option is usually of interest only to developers and
administrators, but it can sometimes be useful for troubleshooting.
Combining the @option{--version} and @option{--verbose} options has the
same effect as giving @option{--info}.
@item -U
@itemx --unitsfile
@opindex -U @r{(option for} @command{units}@r{)}
@opindex --unitsfile @r{(option for} @command{units}@r{)}
Print the location of the default main units data file and exit; if the
file cannot be found, print ``Units data file not found''.
@item -u @var{units-system}
@itemx --units @var{units-system}
@opindex -u @r{(option for} @command{units}@r{)}
@opindex --units @r{(option for} @command{units}@r{)}
Specify a CGS units system or natural units system. The supported units
systems are: gauss[ian], esu, emu, hlu, natural, natural-gauss,
hartree, planck, planck-red, and si. @xref{Alternative Unit Systems},
for further information about these unit systems.
@item -l @var{locale}
@itemx --locale @var{locale}
@opindex --locale @r{(option for} @command{units}@r{)}
@opindex -l @r{(option for} @command{units}@r{)}
Force a specified locale such as @samp{en_GB} to get British definitions
by default.
This overrides the locale determined from system settings or environment
variables. @xref{Locale}, for a description of locale format.
@item -n
@itemx --nolists
Disable conversion to unit lists.
@item -s
@itemx --strict
@opindex -s @r{(option for} @command{units}@r{)}
@opindex --strict @r{(option for} @command{units}@r{)}
Suppress conversion of units to their reciprocal units. For
example, @command{units} will normally convert hertz to seconds
because these units are reciprocals of each other. The strict option
requires that units be strictly conformable to perform a conversion, and
will give an error if you attempt to convert hertz to seconds.
@item -1
@itemx --one-line
@opindex -1 @r{(option for} @command{units}@r{)}
@opindex --one-line @r{(option for} @command{units}@r{)}
Give only one line of output (the forward conversion); do not print
the reverse conversion. If a reciprocal conversion is
performed, then @command{units} will still print the ``reciprocal
conversion'' line.
@item -t
@itemx --terse
@opindex -t @r{(option for} @command{units}@r{)}
@opindex --terse @r{(option for} @command{units}@r{)}
Print only a single conversion factor without any clutter, or if you
request a definition, prints just the definition (including its units).
This option can be used when calling @command{units} from another
program so that the output is easy to parse.
The command @code{units --terse mile m} produces the output @samp{1690.344}.
This option has the combined
effect of these options: @option{--strict} @option{--quiet} @option{--one-line}
@option{--compact}. When combined with @option{--version} it produces
a display showing only the program name and version number.
@item --compact
@opindex --compact @r{(option for} @command{units}@r{)}
Give compact output featuring only the conversion factor; the
multiplication and division signs are not shown, and there is no leading
whitespace. If you convert to a unit list, then the output is a
semicolon separated list of factors.
This turns off the @option{--verbose} option.
@item -q
@itemx --quiet
@itemx --silent
@opindex -q @r{(option for} @command{units}@r{)}
@opindex --quiet @r{(option for} @command{units}@r{)}
@opindex --silent @r{(option for} @command{units}@r{)}
Suppress the display of statistics about the number of units loaded,
any messages printed by the units database,
and the prompting of the user for units. This option does not
affect how @command{units} displays the results. This option is
turned on by default if you invoke @command{units} with a unit
expression on the command line.
@end table
@node Setting Options Interactively
@c =====================================================================
@chapter Setting Options Interactively
@c =====================================================================
@cindex set
@cindex setting options interactively
@cindex options, setting interactively
Many command-line options can also be set interactively,
obviating the need to quit and restart @command{units} to change
the values. This can be especially helpful for Windows users who
start @command{units} from a shortcut.
Typing @w{@kbd{set}} will display a list of all options that
can be set interactively, as well as the current and possible
values; options set to other than default values have an asterisk
(@samp{*}) prepended. For example,
@example
You have: set
q[uiet] = no (y|n) do/don't suppress prompting
o[neline] = no (y|n) do/don't suppress the second line of output
st[rict] = no (y|n) do/don't suppress reciprocal unit conversion
(e.g. Hz<->s)
t[erse] = no (y|n) do/don't give very terse output
c[ompact] = no (y|n) do/don't suppress printing tab, SETFLAG, and '/'
characters in results
v[erbose] = 1 (0|1|2) amount of information shown
*d[igits] = 9 number of significant digits in output
e[ponential] = no (y|n) do/don't use exponential ("scientific") notation
*f[ormat] = %.9g printf(3) format specification
u[nitlists] = yes (y|n) do/don't allow conversion to unit lists
r[ound] = no (y|n) do/don't round last element of unit list output
to an integer
sh[owfactor] = no (y|n) do/don't show non-unity factor before 1|x
in multi-unit output
@end example
@noindent
Characters within the square brackets are optional, so settings
can be changed by entering only one or two characters.
The syntax for setting options is @w{@kbd{set} @var{option}@kbd{ = }@var{value}};
the spaces around the @samp{=} sign are optional.
Some settings are Boolean, enabled by entering @kbd{yes} (or just
@kbd{y}) and disabled by entering @kbd{no} (or just @kbd{n}). For
example,
@example
@group
You have: set quiet = y
quiet = yes
@end group
@end example
@noindent
Other settings take an integer value; for example,
@example
@group
You have: set d=11
digits = 11
format = %.11g
@end group
@end example
@noindent
The @code{format} setting takes a string, the format specification for
the @code{printf} function in the C programming language; for example,
@example
@group
You have: set format = %.9g
format = %.9g
@end group
@end example
@noindent
Typing @w{@kbd{set} @var{option}} will display the current value
of @var{option}, for example
@example
@group
You have: set u
unitlists = yes
You have: set d
digits = 8
format = %.8g
@end group
@end example
@noindent
For the @code{digits} and @code{exponential} options, the value
of @code{format} is also shown.
@node Scripting with Units
@c =====================================================================
@chapter Scripting with @command{units}
@c =====================================================================
@cindex scripting with @command{units}
Despite its numerous options, @command{units} cannot cover every
conceivable unit-conversion task.
For example, suppose we have found some mysterious scale, but cannot
figure out the units in which it is reporting. We reach into our
pocket, place a 3.75-gram coin on the scale, and observe the scale
reading @samp{0.120}. How do we quickly determine the units? Or we
might wonder if a unit has any ``synonyms,'' i.e., other units with the
same value.
The capabilities of @command{units} are easily extended with simple
scripting. Both questions above involve conformable units; on a system
with Unix-like utilities, conversions to conformable units could be
shown accomplished with the following script:
@set codequoteundirected
@set codequotebacktick
@example
@group
#!/bin/sh
progname=`basename $0 .sh`
umsg="Usage: $progname [<number>] unit"
if [ $# -lt 1 ]
then
echo "$progname: missing quantity to convert"
echo "$umsg"
exit 1
fi
for unit in `units --conformable "$*" | cut -f 1 -d ' '`
do
echo "$*" # have -- quantity to convert
echo $unit # want -- conformable unit
done | units --terse --verbose
@end group
@end example
@clear codequotebacktick
@clear codequoteundirected
@noindent
When @command{units} is invoked with no non-option arguments, it reads
@var{have}/@var{want} pairs, on alternating lines, from its standard
input, so the task can be accomplished with only two invocations of
@command{units}. This avoids the computational overhead of needlessly
reprocessing the units database for each conformable unit, as well as
the inherent system overhead of process invocation.
By itself, the script is not very useful. But it could be used in
combination with other commands to address specific tasks. For example,
running the script through a simple output filter could help solve the
scale problem above. If the script is named @command{conformable},
running
@example
$ conformable 3.75g | grep 0.120
@end example
@noindent
gives
@example
@group
3.75g = 0.1205653 apounce
3.75g = 0.1205653 fineounce
3.75g = 0.1205653 ozt
3.75g = 0.1205653 tradewukiyeh
3.75g = 0.1205653 troyounce
@end group
@end example
@noindent
So we might conclude that the scale is calibrated in troy ounces.
We might run
@example
@group
$ units --verbose are
Definition: 100 m^2 = 100 m^2
@end group
@end example
@noindent
and wonder if @samp{are} has any synonyms, value. To find out, we could
run
@example
@group
$ conformable are | grep "= 1 "
are = 1 a
are = 1 are
@end group
@end example
@node Output Styles
@c =====================================================================
@chapter Output Styles
@c =====================================================================
The output can be tweaked in various ways using command line options.
With no options, the output looks like this
@example
@group
$ units
Currency exchange rates from FloatRates (USD base) on 2023-07-08
3612 units, 109 prefixes, 122 nonlinear units
You have: 23ft
You want: m
* 7.0104
/ 0.14264521
You have: m
You want: ft;in
3 ft + 3.3700787 in
@end group
@end example
@noindent
This is arguably a bit cryptic; the @option{--verbose}
option makes clear what the output means:
@example
@group
$ units --verbose
Currency exchange rates from FloatRates (USD base) on 2023-07-08
3612 units, 109 prefixes, 122 nonlinear units
You have: 23 ft
You want: m
23 ft = 7.0104 m
23 ft = (1 / 0.14264521) m
You have: meter
You want: ft;in
meter = 3 ft + 3.3700787 in
@end group
@end example
@noindent
The @option{--quiet} option suppresses the clutter displayed when
@command{units} starts, as well as the prompts to the user.
This option is enabled by default when you
give units on the command line.
@example
@group
$ units --quiet
23 ft
m
* 7.0104
/ 0.14264521
$ units 23ft m
* 7.0104
/ 0.14264521
@end group
@end example
@noindent
The remaining style options allow you to display only numerical values
without the tab or the multiplication and division signs, or to display just a
single line showing the forward conversion:
@set codequoteundirected
@example
@group
$ units --compact 23ft m
7.0104
0.14264521
$ units --compact m 'ft;in'
3;3.3700787
$ units --one-line 23ft m
* 7.0104
$ units --one-line 23ft 1/m
reciprocal conversion
* 0.14264521
$ units --one-line 23ft kg
conformability error
7.0104 m
1 kg
@end group
@end example
@noindent
Note that when converting to a unit list, the @option{--compact}
option displays a semicolon separated list of results. Also be aware
that the
@option{one-line} option doesn't live up to its name if you
execute a reciprocal conversion or if you get a conformability error.
The former case can be prevented using the @option{--strict} option,
which suppresses reciprocal conversions.
Similarly you can suppress unit list conversion using
@option{--nolists}.
It is impossible to prevent
the three line error output.
@example
@group
$ units --compact --nolists m 'ft;in'
Error in 'ft;in': Parse error
$ units --one-line --strict 23ft 1/m
@end group
@end example
@noindent
The various style options can be combined appropriately. The ultimate
combination is the @option{--terse} option, which combines
@option{--strict}, @option{--quiet}, @option{--one-line},
and @option{--compact} to produce the minimal output,
just a single number for regular conversions and a semicolon
separated list for conversion to unit lists. This will likely be the
best choice for programs that want to call @command{units} and then
process its result.
@example
@group
$ units --terse 23ft m
7.0104
$ units --terse m 'ft;in'
3;3.3700787
$ units --terse 23ft 1/m
conformability error
7.0104 m
1 / m
$ units --terse '1 mile'
1609.344 m
$ units --terse mile
5280 ft = 1609.344 m
@end group
@end example
@clear codequoteundirected
@node Defining Your Own Units
@c =====================================================================
@chapter Adding Your Own Definitions
@c =====================================================================
@menu
* Units Data Files:: Where are units defined?
* Defining New Units:: Writing your own unit and prefix definitions
* Defining Nonlinear Units:: Writing your own nonlinear unit definitions
* Piecewise Linear Units:: Writing your own piecewise linear definitions
* Defining Unit List Aliases:: Writing your own unit list aliases
@end menu
@node Units Data Files
@c ---------------------------------------------------------------------
@section Units Data Files
@c ---------------------------------------------------------------------
@cindex additional units data files
@cindex data files, additional
@cindex units data files, additional
@cindex @samp{!include}
@cindex command, @samp{!include}
@cindex including additional units data files
The units and prefixes that @command{units} can convert are defined in
the units data file, typically @file{/usr/share/units/definitions.units}.
If you can't find this file, run @w{@code{units --version}} to get
information on the file locations for your installation.
Although you can extend or modify this data file if you have appropriate
user privileges, it's usually better to put extensions in separate files
so that the definitions will be preserved if you update @command{units}.
You can include additional data files in the units database using
the @samp{!include} command in the standard units data file. For
example
@example
!include /usr/local/share/units/local.units
@end example
@noindent
might be appropriate for a site-wide supplemental data file.
The location of the @samp{!include} statement in the standard units
data file is important; later definitions replace earlier ones,
so any definitions in an included file will override definitions before
the @samp{!include} statement in the standard units data file.
With normal invocation, no warning is given about redefinitions; to
ensure that you don't have an unintended redefinition, run
@w{@code{units -c}} after making changes to any units data file.
@cindex personal units data file
@cindex units data file, personal
If you want to add your own units in addition to or in place of
standard or site-wide supplemental units data files, you can include
them in the @file{.units} file in your home directory. If this
file exists it is read after the standard units data file, so that any
definitions in this file will replace definitions of the same units in
the standard data file or in files included from the standard data
file. This file will not be read if any units files are specified on
the command line. (Under Windows the personal units file is
named @file{unitdef.units}.) Running @w{@code{units -V}} will
display the location and name of your personal units file.
The @command{units} program first tries to determine your home
directory from the @env{HOME} environment variable. On systems running
Microsoft Windows, if @env{HOME} does not exist, @command{units}
attempts to find your home directory from @env{HOMEDRIVE},
@env{HOMEPATH} and @env{USERPROFILE}.
@cindex MYUNITSFILE environment variable
@cindex environment variable, MYUNITSFILE
You can specify an arbitrary file as your personal units data file with
the @env{MYUNITSFILE} environment variable; if this variable exists, its
value is used without searching your home directory.
The default units data files are described in more detail in
@ref{Data Files}.
@node Defining New Units
@c ---------------------------------------------------------------------
@section Defining New Units and Prefixes
@c ---------------------------------------------------------------------
@cindex defining units
@cindex units, definition of
@cindex units definitions, adding
@cindex units definitions, changing
@cindex prefixes, definition of
@cindex defining prefixes
@cindex primitive units
@cindex units, primitive
@cindex @samp{!} to indicate primitive units
@cindex command, @samp{!} to indicate primitive units
A unit is specified on a single line by giving its name and an
equivalence. Comments start with a @samp{#} character, which can appear
anywhere in a line. The backslash character (@samp{\})
acts as a continuation
character if it appears as the last character on a line, making it
possible to spread definitions out over several lines if desired.
A file can be included by giving the command @samp{!include} followed by
the file's name. The @samp{!} must be the first character on the
line. The file will be sought in the same directory as the
parent file unless you give a full path. The name of the file to be
included cannot contain spaces or the comment character @samp{#}.
@cindex include files
Unit names cannot begin or
end with an underscore (@samp{_}), a comma (@samp{,}) or a decimal point
(@samp{.}).
Names must not contain any of the operator characters @samp{+},
@samp{-}, @samp{*}, @samp{/}, @samp{|}, @samp{^}, @samp{;}, @samp{~},
the comment character @samp{#}, or parentheses.
To facilitate copying and pasting from documents, several typographical
characters are converted to operators:
the figure
dash (U+2012), minus (@samp{@minus{}}; U+2212), and en
dash (`--'; U+2013) are converted to the operator @samp{-};
the multiplication sign (@samp{@U{00D7}}; U+00D7),
N-ary times operator (U+2A09),
dot operator (@samp{@U{22C5}}; U+22C5),
and middle dot (@samp{@U{00B7}}; U+00B7)
are converted to the operator @samp{*};
the division sign (@samp{@U{00F7}}; U+00F7)
is converted to the operator @samp{/};
and the fraction slash (U+2044) is converted to the operator @samp{|};
accordingly, none of these characters can appear in unit names.
Names cannot begin with a digit, and if a name ends in a digit other
than zero or one, the digit must be preceded by a string beginning with
an underscore, and afterwards consisting only of digits, decimal points,
or commas. For example, @samp{foo_2}, @samp{foo_2,1}, or
@samp{foo_3.14} are valid names but @samp{foo2} or @samp{foo_a2} are
invalid. The underscore is necessary because without it,
@command{units} cannot determine whether @samp{foo2} is a unit name or
represents @samp{foo^2}. Zero and one are exceptions because
@command{units} never interprets them as exponents.
You could define nitrous oxide as
@example
N2O nitrogen 2 + oxygen
@end example
@noindent
but would need to define nitrogen dioxide as
@example
NO_2 nitrogen + oxygen 2
@end example
@noindent
Be careful to define new units in terms of old ones so that a
reduction leads to the primitive units, which are marked with @samp{!}
characters. Dimensionless units are indicated by using the string
@samp{!dimensionless} for the unit definition.
@cindex dimensionless units, defining
When adding new units, be sure to use the @option{-c} option to check
that the new units reduce properly and that there are no circular
definitions that lead to endless loops. Because some errors may hide
other errors, you should run @command{units} with the @option{-c} option
again after correcting any errors, and keep doing so until no errors are
displayed.
@cindex parentheses
If you define any units that contain
@samp{+} characters in their definitions,
carefully check them because the @option{-c} option
will not catch non-conformable sums. Be careful with the @samp{-}
operator as well. When used as a binary operator, the @samp{-}
character can perform addition or multiplication
depending on the options used to invoke @command{units}.
To ensure consistent behavior use @samp{-} only as a unary negation
operator when writing units definitions. To multiply two units leave a
space or use the @samp{*} operator with care, recalling that it has
two possible precedence values and may require parentheses to ensure
consistent behavior. To compute the difference
of @samp{foo} and @samp{bar} write @samp{foo+(-bar)} or even @samp{foo+-bar}.
You may wish to intentionally redefine a unit. When you do this, and
use the @option{-c} option, @command{units} displays a warning message
about the redefinition. You can suppress these warnings by redefining
a unit using a @samp{+} at the beginning of the unit name. Do not
include any white space between the @samp{+} and the redefined unit
name.
Here is an example of a short data file that defines some basic
units:
@example
@group
m ! # The meter is a primitive unit
sec ! # The second is a primitive unit
rad !dimensionless # A dimensionless primitive unit
micro- 1e-6 # Define a prefix
minute 60 sec # A minute is 60 seconds
hour 60 min # An hour is 60 minutes
inch 72 m # Inch defined incorrectly terms of meters
ft 12 inches # The foot defined in terms of inches
mile 5280 ft # And the mile
+inch 0.0254 m # Correct redefinition, warning suppressed
@end group
@end example
@cindex parentheses
@noindent
A unit that ends with a @samp{-} character is a prefix. If a prefix
definition contains any @samp{/} characters, be sure they are protected
by parentheses. If you define @samp{half- 1/2}, then @samp{halfmeter}
would be equivalent to @samp{1 / (2@tie{}meter)}.
@node Defining Nonlinear Units
@c ---------------------------------------------------------------------
@section Defining Nonlinear Units
@c ---------------------------------------------------------------------
@cindex defining nonlinear units
@cindex nonlinear units, defining
@cindex nonlinear unit conversions
Some unit conversions of interest are nonlinear; for
example, temperature conversions between the Fahrenheit and Celsius
scales cannot be done by simply multiplying by conversion factors.
When you give a linear unit definition such as @samp{inch 2.54@tie{}cm}
you are providing information that @command{units} uses to convert
values in inches into primitive units of meters. For nonlinear units,
you give a functional definition that provides the same information.
Nonlinear units are represented using a functional notation.
It is best to regard this notation not as a function call but
as a way of adding units to a number, much the same way that
writing a linear unit name after a number adds units to that number.
Internally, nonlinear units are defined by a pair of functions
that convert to and from linear units in the database, so that
an eventual conversion to primitive units is possible.
Here is an example nonlinear unit definition:
@example
@group
tempF(x) units=[1;K] domain=[-459.67,) range=[0,) \
(x+(-32)) degF + stdtemp ; (tempF+(-stdtemp))/degF + 32
@end group
@end example
@noindent
A nonlinear unit definition comprises a unit name, a formal parameter
name, two functions, and optional specifications for units, the domain,
and the range (the domain of the inverse function). The functions tell
@command{units} how to convert to and from the new unit. To produce
valid results, the arguments of these functions need to have the correct
dimensions and be within the domains for which the functions are
defined.
@cindex parentheses
The definition begins with the unit name followed immediately (with no
spaces) by a @samp{(} character. In the parentheses is the name of the
formal parameter. Next is an optional specification of the units
required by the functions in the definition. In the example above,
the @samp{units=[1;K]} specification indicates that the
@samp{tempF} function requires an input argument conformable with
@samp{1} (i.e., the argument is dimensionless), and that the inverse
function requires an input argument conformable with @samp{K}. For
normal nonlinear units definition, the forward function will always take
a dimensionless argument; in general, the inverse function will need
units that match the quantity measured by your nonlinear unit.
Specifying the units enables @command{units} to perform error checking
on function arguments, and also to assign units to domain and range
specifications, which are described later.
Next the function definitions appear. In the example above, the
@samp{tempF} function is defined by
@example
@group
tempF(x) = (x+(-32)) degF + stdtemp
@end group
@end example
@noindent
This gives a rule for converting @samp{x} in the units @samp{tempF}
to linear units of absolute temperature, which makes it possible to
convert from tempF to other units.
To enable conversions to Fahrenheit, you must give a rule for the
inverse conversions. The inverse will be @samp{x(tempF)} and its
definition appears after a @samp{;} character. In our example, the
inverse is
@example
@group
x(tempF) = (tempF+(-stdtemp))/degF + 32
@end group
@end example
@noindent
This inverse definition takes an absolute temperature as its argument
and converts it to the Fahrenheit temperature. The inverse can be
omitted by leaving out the @samp{;} character and the inverse
definition, but then conversions @emph{to} the unit will not be
possible. If the inverse definition is omitted, the @option{--check}
option will display a warning. It is up to you to calculate and enter
the correct inverse function to obtain proper conversions; the
@option{--check} option tests the inverse at one point and prints an
error if it is not valid there, but this is not a guarantee that your
inverse is correct.
With some definitions, the units may vary. For example, the definition
@example
@group
square(x) x^2
@end group
@end example
@noindent
can have any arbitrary units, and can also take dimensionless arguments.
In such a case, you should @emph{not} specify units.
If a definition takes a root of its arguments, the definition is valid
only for units that yield such a root. For example,
@example
@group
squirt(x) sqrt(x)
@end group
@end example
@noindent
is valid for a dimensionless argument, and for arguments with even
powers of units.
@cindex domain, nonlinear unit definitions
@cindex range, nonlinear unit definitions
Some definitions may not be valid for all real numbers. In such cases,
@command{units} can handle errors better if you specify an appropriate
domain and range. You specify the domain and range as shown below:
@example
@group
baume(d) units=[1;g/cm^3] domain=[0,130.5] range=[1,10] \
(145/(145-d)) g/cm^3 ; (baume+-g/cm^3) 145 / baume
@end group
@end example
@noindent
In this example the domain is specified after @samp{domain=} with
the endpoints given in brackets. In accord with mathematical
convention, square brackets indicate a closed interval (one that
includes its endpoints), and parentheses indicate an open interval (one
that does not include its endpoints). An interval can be open or closed
on one or both ends; an interval that is unbounded on either end is
indicated by omitting the limit on that end. For example, a quantity to
which decibel (dB) is applied may have any value greater than zero, so
the range is indicated by @samp{(0,)}:
@example
@group
decibel(x) units=[1;1] range=(0,) 10^(x/10); 10 log(decibel)
@end group
@end example
@noindent
If the domain or range is given, the second endpoint must be greater
than the first.
The domain and range specifications can appear independently and in any
order along with the units specification.
The values for the domain and range endpoints are attached to the units
given in the units specification, and if necessary, the parameter value
is adjusted for comparison with the endpoints. For example, if a
definition includes @samp{units=[1;ft]} and @samp{range=[3,)}, the range
will be taken as @w{3 ft} to infinity. If the function is passed a
parameter of @w{@samp{900 mm}}, that value will be adjusted to
@w{2.9527559 ft}, which is outside the specified range.
If you omit the units specification from the previous example,
@command{units} can not tell whether you intend the lower endpoint
to be @w{3 ft} or @w{3 microfurlongs}, and can not adjust the
parameter value of @w{900 mm} for comparison. Without units,
numerical values other than zero or plus or minus infinity for domain or
range endpoints are meaningless, and accordingly they are not allowed. If
you give other values without units, then the definition will be ignored
and you will get an error message.
Although the units, domain, and range specifications are optional, it's
best to give them when they are applicable; doing so allows
@command{units} to perform better error checking and give more helpful
error messages. Giving the domain and range also enables the
@option{--check} option to find a point in the domain to use for its
point check of your inverse definition.
You can make synonyms for nonlinear units by providing both the
forward and inverse functions; inverse functions can be obtained using
the @samp{~} operator. So to create a synonym for @samp{tempF} you
could write
@example
@group
fahrenheit(x) units=[1;K] tempF(x); ~tempF(fahrenheit)
@end group
@end example
@noindent
This is useful for creating a nonlinear unit
definition that differs slightly from an existing definition without
having to repeat the original functions. For example,
@example
dBW(x) units=[1;W] range=[0,) dB(x) W ; ~dB(dBW/W)
@end example
@noindent
If you wish a synonym to refer to an existing nonlinear unit without
modification, you can do so more simply by adding the synonym with
appended parentheses as a new unit, with the existing nonlinear
unit---without parentheses---as the definition. So to create a synonym
for @samp{tempF} you could write
@example
fahrenheit() tempF
@end example
@noindent
The definition must be a nonlinear unit; for example, the synonym
@example
fahrenheit() meter
@end example
@noindent
will result in an error message when @command{units} starts.
@cindex units functions
@cindex functions of units
You may occasionally wish to define a function that operates on units.
This can be done using a nonlinear unit definition. For example, the
definition below provides conversion between radius and the area of a
circle. This definition requires a length as input and
produces an area as output, as indicated by the @samp{units=} specification.
Specifying the range as the nonnegative numbers can prevent cryptic
error messages.
@example
@group
circlearea(r) units=[m;m^2] range=[0,) pi r^2 ; sqrt(circlearea/pi)
@end group
@end example
@node Piecewise Linear Units
@c ---------------------------------------------------------------------
@section Defining Piecewise Linear Units
@c ---------------------------------------------------------------------
@cindex defining piecewise linear units
@cindex linear interpolation
@cindex units, piecewise linear
@cindex piecewise linear units
Sometimes you may be interested in a piecewise linear unit such as
many wire gauges. Piecewise linear units can be defined by specifying
conversions to linear units on a list of points.
Conversion at other points will be done by linear interpolation.
A partial definition of zinc gauge is
@example
@group
zincgauge[in] 1 0.002, 10 0.02, 15 0.04, 19 0.06, 23 0.1
@end group
@end example
@noindent
In this example, @samp{zincgauge} is the name of the piecewise linear
unit. The definition of such a unit is indicated by the
embedded @samp{[} character. After the bracket, you should indicate the
units to be attached to the numbers in the table.
No spaces can appear before the
@samp{]} character, so a definition like @samp{foo[kg meters]} is
invalid; instead write @samp{foo[kg*meters]}. The definition of the
unit consists of a list of pairs optionally separated by commas.
This list defines a function for converting from the piecewise linear
unit to linear units. The
first item in each pair is the function argument; the second item is the
value of the function at that argument (in the units specified in brackets).
In this example,
we define @samp{zincgauge} at five points. For example, we set
@samp{zincgauge(1)} equal to @w{@samp{0.002 in}}. Definitions like this
may be more readable if written using continuation characters as
@example
@group
zincgauge[in] \
1 0.002 \
10 0.02 \
15 0.04 \
19 0.06 \
23 0.1
@end group
@end example
@noindent
With the preceding definition, the following conversion can be
performed:
@example
@group
You have: zincgauge(10)
You want: in
* 0.02
/ 50
You have: .01 inch
You want: zincgauge
5
@end group
@end example
@noindent
If you define a piecewise linear unit that is not strictly monotonic,
then the inverse will not be well defined. If the inverse is requested
for such a unit, @command{units} will return the smallest inverse.
After adding nonlinear units definitions, you should normally run
@w{@samp{units --check}} to check for errors. If the @samp{units}
keyword is not given, the @option{--check} option checks a nonlinear unit
definition using a dimensionless argument, and then checks using an
arbitrary combination of units, as well as the square and cube of that
combination; a warning is given if any of these tests fail. For
example,
@set codequoteundirected
@example
@group
Warning: function 'squirt(x)' defined as 'sqrt(x)'
failed for some test inputs:
squirt(7(kg K)^1): Unit not a root
squirt(7(kg K)^3): Unit not a root
@end group
@end example
@clear codequoteundirected
@noindent
Running @w{@samp{units --check}} will print a warning if a
non-monotonic piecewise linear unit is encountered. For example, the
relationship between ANSI coated abrasive designation and mean particle
size is non-monotonic in the vicinity of 800 grit:
@example
@group
ansicoated[micron] \
. . .
600 10.55 \
800 11.5 \
1000 9.5 \
@end group
@end example
@noindent
Running @w{@samp{units --check}} would give the error message
@set codequoteundirected
@example
@group
Table 'ansicoated' lacks unique inverse around entry 800
@end group
@end example
@clear codequoteundirected
@noindent
Although the inverse is not well defined in this region, it's not really
an error. Viewing such error messages can be tedious, and if there are
enough of them, they can distract from true errors. Error checking for
nonlinear unit definitions can be suppressed by giving the
@samp{noerror} keyword; for the examples above, this could be done as
@example
@group
squirt(x) noerror domain=[0,) range=[0,) sqrt(x); squirt^2
ansicoated[micron] noerror \
. . .
@end group
@end example
@noindent
Use the @samp{noerror} keyword with caution. The safest approach after
adding a nonlinear unit definition is to run @w{@samp{units --check}}
and confirm that there are no actual errors before adding the
@samp{noerror} keyword.
@node Defining Unit List Aliases
@c ---------------------------------------------------------------------
@section Defining Unit List Aliases
@c ---------------------------------------------------------------------
@cindex defining unit list aliases
@cindex unit list aliases, defining
@cindex @samp{!unitlist}
@cindex command, @samp{!unitlist}
Unit list aliases are treated differently from unit definitions,
because they are a data entry shorthand rather than a true definition
for a new unit.
A unit list alias definition begins with @samp{!unitlist} and includes the
alias and the definition; for example, the aliases included in the
standard units data file are
@example
@group
!unitlist hms hr;min;sec
!unitlist time year;day;hr;min;sec
!unitlist dms deg;arcmin;arcsec
!unitlist ftin ft;in;1|8 in
!unitlist usvol cup;3|4 cup;2|3 cup;1|2 cup;1|3 cup;1|4 cup;\
tbsp;tsp;1|2 tsp;1|4 tsp;1|8 tsp
@end group
@end example
@noindent
Unit list aliases are only for unit lists, so the definition must
include a @samp{;}. Unit list aliases can never be combined with
units or other unit list aliases, so the definition of @samp{time}
shown above could @emph{not} have been shortened to
@samp{year;day;hms}.
As usual, be sure to run @w{@samp{units --check}} to ensure that the
units listed in unit list aliases are conformable.
@node Numeric Output Format
@c =====================================================================
@chapter Numeric Output Format
@c =====================================================================
@cindex numeric output format
@cindex output format
@menu
* Format Specification:: The output format specification
* Flags:: Optional format flags
* Field Width:: Specifying output field width
* Precision:: Specifying output precision
@end menu
By default, @code{units} shows results to eight significant digits in
general number format. You can change this with the
@option{--exponential}, @option{--digits}, and @option{--output-format}
options. The first sets an exponential format (i.e., scientific
notation) like that used in the original Unix @command{units} program,
the second allows you to specify a different number of significant
digits, and the last allows you to control the output appearance using
the format for the @code{printf} function in the C programming language.
If you only want to change the number of significant digits or specify
exponential format type, use the @option{--digits} and
@option{--exponential} options. The @option{--output-format} option
affords the greatest control of the output appearance, but requires at
least rudimentary knowledge of the @code{printf} format syntax.
@xref{Invoking Units}, for descriptions of these options.
@node Format Specification
@c ---------------------------------------------------------------------
@section Format Specification
@c ---------------------------------------------------------------------
@cindex output format specification
@cindex format specification, output
The format specification recognized with the @option{--output-format}
option is a subset of that for @code{printf}. The format specification has
the form
@c noman
@code{%}[@i{flags}][@i{width}][@code{.}@i{precision}]@i{type};
@c end noman
@c ifman
@ignore
.\".CW "%\fR[\fP\fIflags\fP\fR][\fP\fIwidth\fP\fR][\fP.\fIprecision\fP\fR]\fP\fItype\fP" ;
@code{%}[@i{flags}][@i{width}][\c
@code{.}@i{precision}]@i{type};
@end ignore
@c end ifman
it must begin with @samp{%}, and must end with a floating-point type
specifier:
@samp{g} or @samp{G} to specify the number of significant digits,
@samp{e} or @samp{E} for scientific notation, and @samp{f} for
fixed-point decimal. The ISO C99 standard added the @samp{F} type for
fixed-point decimal and the @samp{a} and @samp{A} types for hexadecimal
floating point; these types are allowed with compilers that support
them. Type length modifiers (e.g., @samp{L} to indicate a long double)
are inapplicable and are not allowed.
The default format for @command{units} is @samp{%.8g};
for greater precision, you could specify @option{-o@tie{}%.15g}.
The @samp{g} and @samp{G} format types use exponential format whenever
the exponent would be less than @math{-4}, so the value 0.000013
displays as @samp{1.3e-005}. These types also use exponential notation
when the exponent is greater than or equal to the precision, so with the
default format, the value
@c
@c noman
@ifnotinfo
@math{5\times 10^7}
@end ifnotinfo
@ifinfo
5e7
@end ifinfo
@c end noman
@c man .if t .ig ++
@c man 5 \(mu 10^7
@c man .++
@c man .if n .ig ++
@c man .EQ
@c man 5 times 10 sup 7
@c man .EN
@c man .++
displays as @samp{50000000} and the value
@c
@c noman
@ifnotinfo
@math{5\times 10^8}
@end ifnotinfo
@ifinfo
5e8
@end ifinfo
@c end noman
@c man .if t .ig ++
@c man 5 \(mu 10^8
@c man .++
@c man .if n .ig ++
@c man .EQ
@c man 5 times 10 sup 8
@c man .EN
@c man .++
@c
displays as @samp{5e+008}. If you prefer fixed-point display, you might
specify @option{-o@tie{}%.8f}; however, small numbers will display very
few significant digits, and values less than
@c
@c noman
@ifnotinfo
@math{5\times 10^{-8}}
@end ifnotinfo
@ifinfo
5e8
@end ifinfo
@c end noman
@c man .if t .ig ++
@c man 5 \(mu 10^\-8
@c man .++
@c man .if n .ig ++
@c man .EQ
@c man 5 times 10 sup -8
@c man .EN
@c man .++
@c
will show nothing but zeros.
The format specification may include one or more optional flags:
@samp{+}, @samp{@tie{}} (space), @samp{#}, @samp{-}, or @samp{0} (the
digit zero). The digit-grouping flag
@c noman
@set codequoteundirected
@samp{'} (apostrophe)
@clear codequoteundirected
@c end noman
@c if the troff formatter is groff, ensure an ASCII single quote
@c man .ie \n(.g \(oq\(aq'
@c man .el \&'
is allowed with compilers that support it. Flags are followed by an
optional value for the minimum field width, and an optional precision
specification that begins with a period (e.g., @samp{.6}). The field
width includes the digits, decimal point, the exponent, thousands
separators (with the digit-grouping flag), and the sign if any of these
are shown.
@node Flags
@c ---------------------------------------------------------------------
@section Flags
@c ---------------------------------------------------------------------
@cindex output format flags
@cindex flags, output format
The @samp{+} flag causes the output to have a sign (@samp{+} or @samp{-}).
The space flag @samp{@tie{}} is similar to the @samp{+} flag, except
that when the value is positive, it is prefixed with a space rather than
a plus sign; this flag is ignored if the @samp{+} flag is also given.
The @samp{+} or @samp{@tie{}} flag could be useful if conversions might
include positive and negative results, and you wanted to align
the decimal points in exponential notation.
@c
The @samp{#} flag causes the output value to contain a decimal point in
all cases; by default, the output contains a decimal point only if there
are digits (which can be trailing zeros) to the right of the point.
With the @samp{g} or @samp{G} types, the @samp{#} flag also prevents the
suppression of trailing zeros.
@c
The digit-grouping flag
@c noman
@set codequoteundirected
@samp{'}
@clear codequoteundirected
@c end noman
@c if the troff formatter is groff, ensure an ASCII single quote
@c man .ie \n(.g \(oq\(aq'
@c man .el \&`''
shows a thousands separator in digits to the left of the decimal point.
@c (e.g., @samp{1,234.56}).
This can be useful when displaying large numbers in fixed-point decimal;
for example, with the format @samp{%f},
@example
You have: mile
You want: microfurlong
* 8000000.000000
/ 0.000000
@end example
@noindent
the magnitude of the first result may not be immediately obvious without
counting the digits to the left of the decimal point. If the thousands
separator is the comma (@samp{,}), the output with the format
@c noman
@set codequoteundirected
@samp{%'f}
@clear codequoteundirected
@c end noman
@c if the troff formatter is groff, ensure an ASCII single quote
@c man .ie \n(.g \(oq%\(aqf'
@c man .el `%'f'
might be
@example
You have: mile
You want: microfurlong
* 8,000,000.000000
/ 0.000000
@end example
@noindent
making the magnitude readily apparent. Unfortunately, few compilers
support the digit-grouping flag.
@c
With the @samp{-} flag, the output value is left aligned within the
specified field width. If a field width greater than needed to show the
output value is specified, the @samp{0} (zero) flag causes the output
value to be left padded with zeros until the specified field width is
reached; for example, with the format @samp{%011.6f},
@example
You have: troypound
You want: grain
* 5760.000000
/ 0000.000174
@end example
@noindent
The @samp{0} flag has no effect if the @samp{-} (left align) flag is
given.
@node Field Width
@c ---------------------------------------------------------------------
@section Field Width
@c ---------------------------------------------------------------------
@cindex output field width
By default, the output value is left aligned and shown with the minimum
width necessary for the specified (or default) precision. If a field
width greater than this is specified, the value shown is right aligned,
and padded on the left with enough spaces to provide the specified field
width. A width specification is typically used with fixed-point decimal
to have columns of numbers align at the decimal point; this arguably is
less useful with @command{units} than with long columnar output, but it
may nonetheless assist in quickly assessing the relative magnitudes of
results. For example, with the format @samp{%12.6f},
@example
@group
You have: km
You want: in
* 39370.078740
/ 0.000025
@end group
@group
You have: km
You want: rod
* 198.838782
/ 0.005029
@end group
@group
You have: km
You want: furlong
* 4.970970
/ 0.201168
@end group
@end example
@node Precision
@c ---------------------------------------------------------------------
@section Precision
@c ---------------------------------------------------------------------
@cindex output precision
@cindex precision, output
The meaning of ``precision'' depends on the format type. With @samp{g}
or @samp{G}, it specifies the number of significant digits (like the
@option{--digits} option); with @samp{e}, @samp{E}, @samp{f}, or
@samp{F}, it specifies the maximum number of digits to be shown after
the decimal point.
@c
With the @samp{g} and @samp{G} format types, trailing zeros are
suppressed, so the results may sometimes have fewer digits than the
specified precision (as indicated above, the @samp{#} flag causes
trailing zeros to be displayed).
The default precision is 6, so @samp{%g} is equivalent to @samp{%.6g},
and would show the output to six significant digits. Similarly,
@samp{%e} or @samp{%f} would show the output with six digits after the
decimal point.
The C @code{printf} function allows a precision of arbitrary size, whether or
not all of the digits are meaningful. With most compilers, the maximum
internal precision with @command{units} is 15 decimal digits (or 13
hexadecimal digits).
With the @option{--digits} option, you are limited
to the maximum internal precision; with the @option{--output-format}
option, you may specify a precision greater than this, but it may not be
meaningful. In some cases, specifying excess precision can result in
rounding artifacts. For example, a pound is exactly 7000 grains, but
with the format @samp{%.18g}, the output might be
@example
You have: pound
You want: grain
* 6999.9999999999991
/ 0.00014285714285714287
@end example
@noindent
With the format @samp{%.25g} you might get the following:
@example
You have: 1/3
You want:
Definition: 0.333333333333333314829616256247
@end example
@noindent
In this case the displayed value includes a series of digits that represent the
underlying binary floating-point approximation to 1/3 but are not
meaningful for the desired computation.
In general, the result with excess precision is system dependent.
@c
The precision affects only the @emph{display} of numbers; if a result
relies on physical constants that are not known to the specified
precision, the number of physically meaningful digits may be less than
the number of digits shown.
See the documentation for @code{printf} for more detailed descriptions of the
format specification.
The @option{--output-format} option is incompatible with the
@option{--exponential} or @option{--digits} options; if the former is
given in combination with either of the latter, the format is controlled
by the last option given.
@node Localization
@c =====================================================================
@chapter Localization
@c =====================================================================
@cindex environment dependent definitions
@cindex localization
@cindex @samp{!locale}
@cindex command, @samp{!locale}
@cindex @samp{!endlocale}
@cindex command, @samp{!endlocale}
@cindex command, @samp{!endvar}
@cindex command, @samp{!var}
@cindex command, @samp{!varnot}
@cindex command, @samp{!set}
@cindex command, @samp{!message}
@menu
* Locale:: What is a locale?
* Additional Localization:: When the locale isn't enough
@end menu
Some units have different values in different locations. The
localization feature accommodates this by allowing a units data file to
specify definitions that depend on the user's locale.
@node Locale
@c ---------------------------------------------------------------------
@section Locale
@c ---------------------------------------------------------------------
@cindex locale
A locale is a subset of a user's environment that indicates the user's
language and country, and some attendant preferences, such as the
formatting of dates. The @command{units} program attempts to determine
the locale from the POSIX @code{setlocale} function; if this cannot be done,
@command{units} examines the environment
variables @env{LC_CTYPE} and @env{LANG}.
On POSIX systems, a locale is of the form
@var{language}@code{_}@var{country}, where @var{language} is the
two-character code from ISO 639-1 and @var{country} is the two-character
code from ISO 3166-1; @var{language} is lower case and @var{country} is
upper case. For example, the POSIX locale for the United Kingdom is @code{en_GB}.
@cindex @file{locale_map.txt}
@cindex setlocale function
On systems running Microsoft Windows, the value returned by @code{setlocale}
is different from that on POSIX systems; @command{units} attempts to map
the Windows value to a POSIX value by means of a table in the file
@file{locale_map.txt} in the same directory as the other data files. The
file includes entries for many combinations of language and country, and
can be extended to include other combinations. The @file{locale_map.txt}
file comprises two tab-separated columns; each entry is of the form
@display
@var{Windows-locale}@ @ @ @var{POSIX-locale}
@end display
@noindent
where @var{POSIX-locale} is as described above, and @var{Windows-locale}
typically spells out both the language and country. For example, the
entry for the United States is
@example
English_United States en_US
@end example
@noindent
You can force @command{units} to run in a desired locale by using the
@option{-l} option.
In order to create unit definitions for a particular locale you begin
a block of definitions in a unit datafile with @samp{!locale} followed
by a locale name. The @samp{!} must be the first character on the
line. The @command{units} program reads the following
definitions only if the current locale matches. You end the block of
localized units with @samp{!endlocale}. Here is an example, which
defines the British gallon.
@example
@group
!locale en_GB
gallon 4.54609 liter
!endlocale
@end group
@end example
@node Additional Localization
@c ---------------------------------------------------------------------
@section Additional Localization
@c ---------------------------------------------------------------------
Sometimes the locale isn't sufficient to determine unit preferences.
There could be regional preferences, or a company could have specific
preferences. Though probably uncommon, such differences could arise
with the choice of English customary units outside of English-speaking
countries. To address this, @command{units} allows specifying
definitions that depend on environment variable settings.
The environment variables can be controlled based on the current locale,
or the user can set them to force a particular group of definitions.
A conditional block of definitions in a units data file begins with
either @samp{!var} or @samp{!varnot} following by an environment
variable name and then a space separated
list of values. The leading @samp{!} must appear in the first column of a units
data file, and the conditional block is terminated by @samp{!endvar}.
Definitions in blocks beginning with @samp{!var} are executed only if the
environment variable is exactly equal to one of the listed values.
Definitions in blocks beginning with @samp{!varnot} are executed only if the
environment variable does @emph{not} equal any of the list values.
The inch has long been a customary measure of length in many places.
The word comes from the Latin @emph{uncia} meaning ``one twelfth,''
referring to its relationship with the foot. By the 20th century, the
inch was officially defined in English-speaking countries relative to
the yard, but until 1959, the yard differed slightly among those
countries. In France the customary inch, which was displaced in 1799
by the meter, had a different length based on a french foot. These
customary definitions could be accommodated as follows:
@example
@group
!var INCH_UNIT usa
yard 3600|3937 m
!endvar
@end group
@group
!var INCH_UNIT canada
yard 0.9144 meter
!endvar
@end group
@group
!var INCH_UNIT uk
yard 0.91439841 meter
!endvar
@end group
@group
!var INCH_UNIT canada uk usa
foot 1|3 yard
inch 1|12 foot
!endvar
@end group
@group
!var INCH_UNIT france
foot 144|443.296 m
inch 1|12 foot
line 1|12 inch
!endvar
@end group
@group
!varnot INCH_UNIT usa uk france canada
!message Unknown value for INCH_UNIT
!endvar
@end group
@end example
@noindent
When @command{units} reads the above definitions it will check the
environment variable @env{INCH_UNIT} and load only the definitions for
the appropriate section. If @env{INCH_UNIT} is unset or is not set to
one of the four values listed, then @command{units} will run the last
block. In this case that block uses the
@samp{!message} command to display a warning message. Alternatively
that block could set default values.
In order to create default values that are overridden by user settings
the data file can use the @samp{!set} command, which sets an
environment variable @emph{only if it is not already set}; these
settings are only for the current @command{units} invocation and do
not persist. So if the example above were preceded by
@samp{!set INCH_UNIT france}, then this would make @samp{france} the
default value for @env{INCH_UNIT}. If the user had set the variable
in the environment before invoking @command{units}, then
@command{units} would use the user's value.
To link these settings to the user's locale you combine the @samp{!set}
command with the @samp{!locale} command.
If you wanted to combine the above example with suitable locales you
could do by @emph{preceding} the above definition with the following:
@example
@group
!locale en_US
!set INCH_UNIT usa
!endlocale
!locale en_GB
!set INCH_UNIT uk
!endlocale
!locale en_CA
!set INCH_UNIT canada
!endlocale
!locale fr_FR
!set INCH_UNIT france
!endlocale
!set INCH_UNIT france
@end group
@end example
@noindent
These definitions set the overall default for @env{INCH_UNIT} to
@samp{france} and set default values for four locales appropriately.
The overall default setting comes last so that it only applies when
@env{INCH_UNIT} was not set by one of the other commands or by the
user.
If the variable given after @samp{!var} or @samp{!varnot} is undefined,
then @command{units} prints an error message and ignores the
definitions that follow. Use @samp{!set} to create defaults to
prevent this situation from arising. The @option{-c}
option only checks the definitions that are active for the current
environment and locale, so when adding new definitions take care to
check that all cases give rise to a well defined set of definitions.
@node Environment Vars
@c =====================================================================
@chapter Environment Variables
@c =====================================================================
@cindex environment variables
The @command{units} program uses the following environment variables:
@table @env
@item HOME
@cindex HOME environment variable
@cindex environment variable, HOME
Specifies the location of your home directory; it is used by
@command{units} to find a personal units data file @samp{.units}. On
systems running Microsoft Windows, the file is @samp{unitdef.units}, and
if @env{HOME} does not exist, @command{units} tries to determine your
home directory from the @env{HOMEDRIVE} and @env{HOMEPATH} environment
variables; if these variables do not exist, units finally tries
@env{USERPROFILE}---typically @file{C:\Users\@var{username}} (Windows
Vista and Windows@tie{}7) or
@w{@file{C:\Documents and Settings\@var{username}}} (Windows@tie{}XP).
@item LC_CTYPE, LANG
@cindex LANG environment variable
@cindex LC_CTYPE environment variable
@cindex environment variable, LANG
@cindex environment variable, LC_CTYPE
Checked to determine the locale if @command{units} cannot obtain it
from the operating system. Sections of the default main units data file
are specific to certain locales.
@item MYUNITSFILE
@cindex MYUNITSFILE environment variable
@cindex environment variable, MYUNITSFILE
Specifies your personal units data file. If this variable exists,
@command{units} uses its value rather than searching your home
directory for @samp{.units}. The personal units file will not be
loaded if any data files are given using the @option{-f} option.
@item PAGER
@cindex PAGER environment variable
@cindex environment variable, PAGER
@cindex help
Specifies the pager to use for help and for displaying the conformable
units. The help function browses the units database and calls
the pager using the @samp{+n}@var{n} syntax for specifying a line
number. The default pager is @command{more}; @env{PAGER} can be used
to specify alternatives such as @command{less}, @command{pg},
@command{emacs}, or @command{vi}.
@item UNITS_ENGLISH
@cindex UNITS_ENGLISH environment variable
@cindex environment variable, UNITS_ENGLISH
Set to either @samp{US} or
@samp{GB} to choose United States or British volume definitions,
overriding the default from your locale.
@item UNITSFILE
@cindex UNITSFILE environment variable
@cindex environment variable, UNITSFILE
Specifies the units data file to use (instead of the default).
You can only specify a single units data file using this environment
variable. If units data files are given using the @option{-f} option,
the file specified by @env{UNITSFILE} will be not be loaded unless the
@option{-f} option is given with the empty string
(@w{@samp{units -f ""}}).
@item UNITSLOCALEMAP
@cindex UNITSLOCALEMAP environment variable
@cindex environment variable, UNITSLOCALEMAP
Windows only; this variable has no effect on Unix-like systems.
Specifies the units locale map file to use (instead of the default).
This variable seldom needs to be set, but you can use it to ensure that
the locale map file will be found if you specify a location for the
units data file using either the @option{-f} option or the
@env{UNITSFILE} environment variable, and that location does not also
contain the locale map file.
@item UNITS_SYSTEM
@cindex UNITS_SYSTEM environment variable
@cindex environment variable, UNITS_SYSTEM
This environment variable is used in the default main data file to select
CGS measurement systems. Currently supported systems are @samp{esu},
@samp{emu}, @samp{gauss[ian]}, @samp{hlu}, @samp{natural},
@samp{natural-gauss}, @samp{planck}, @samp{planck-red}, @samp{hartree}
and @samp{si}. The default is @samp{si}.
@end table
@node Data Files
@c =====================================================================
@chapter Data Files
@c =====================================================================
@cindex files, data
@cindex data files
The @command{units} program uses four default data files: the main data
file, @file{definitions.units}; the atomic masses of the elements,
@file{elements.units}; currency exchange rates, @file{currency.units},
and the US Consumer Price Index, @file{cpi.units}. The last three files
are loaded by means of @samp{!include} directives in the main file
@c man (see \fIDatabase Command Syntax\fP).
@c noman
(@pxref{Database Syntax, ,Database Command Syntax}).
@c end noman
The program can
also use an optional personal units data file @file{.units}
(@file{unitdef.units} under Windows) located in the user's home
directory. The personal units data file is described in more detail in
@ref{Units Data Files}.
On Unix-like systems, the data files are typically located in
@file{/usr/share/units} if @command{units} is provided with the
operating system, or in @file{/usr/local/share/units} if @command{units}
is compiled from the source distribution. Note that the currency file
@file{currency.units} is a symbolic link to another location.
On systems running Microsoft Windows, the files may be in the same
locations if Unix-like commands are available, a Unix-like file
structure is present (e.g., @file{C:/usr/local}), and @command{units} is
compiled from the source distribution. If Unix-like commands are not
available, a more common location is
@w{@file{C:\Program Files (x86)\GNU\units}} (for 64-bit Windows
installations) or @w{@file{C:\Program Files\GNU\units}} (for 32-bit
installations).
If @command{units} is obtained from the GNU Win32 Project
(@uref{http://gnuwin32.sourceforge.net/}), the files are commonly in
@w{@file{C:\Program Files\GnuWin32\share\units}}.
If the default main units data file is not an absolute pathname,
@command{units} will look for the file in the directory that contains
the @command{units} program; if the file is not found there,
@command{units} will look in a directory @code{../share/units} relative
to the directory with the @command{units} program.
You can determine the location of the files by running
@w{@samp{units --version}}. Running @w{@samp{units --info}}
will give you additional information about the files, how
@command{units} will attempt to find them, and the status of the
related environment variables.
@node Unicode Support
@c =====================================================================
@chapter Unicode Support
@c =====================================================================
@cindex Unicode support
@cindex UTF-8
@cindex @samp{!utf8}
@cindex command, @samp{!utf8}
@cindex @samp{!endutf8}
@cindex command, @samp{!endutf8}
@menu
* Unicode Support on Windows:: Unicode support on Windows
@end menu
The standard units data file is in Unicode, using UTF-8 encoding. Most
definitions use only ASCII characters (i.e., code points U+0000 through
U+007F); definitions using non-ASCII characters appear in blocks
beginning with @samp{!utf8} and ending with @samp{!endutf8}.
The non-ASCII definitions are loaded only if the platform and the locale
support @w{UTF-8}. Platform support is determined when @command{units}
is compiled; the locale is checked at every invocation of
@command{units}. To see if your version of @command{units} includes
Unicode support, invoke the program with the @option{--version} option.
When Unicode support is available, @command{units} checks every line
within UTF-8 blocks in all of the units data files for invalid or
non-printing UTF-8 sequences; if such sequences occur, @command{units}
ignores the entire line. In addition to checking validity,
@command{units} determines the display width of non-ASCII characters to
ensure proper positioning of the pointer in some error messages and to
align columns for the @samp{search} and @samp{?} commands.
Microsoft Windows supports UTF-8 in console applications running
in Windows Terminal; UTF-8 is not supported in applications
running in the older Windows Console Host---@pxref{Unicode Support on Windows}.
The UTF-16 and UTF-32 encodings are not supported on any
platforms.
If Unicode support is available and definitions that contain non-ASCII
UTF-8 characters are added to a units data file, those definitions
should be enclosed within @samp{!utf8} @dots{} @samp{!endutf8} to ensure
that they are only loaded when Unicode support is available. As usual,
the @samp{!} must appear as the first character on the line. As
discussed in @ref{Units Data Files}, it's usually best to put such
definitions in supplemental data files linked by an @samp{!include}
command or in a personal units data file.
When Unicode support is not available, @command{units} makes no assumptions
about character encoding, except that characters in the range 00--7F
hexadecimal correspond to ASCII encoding. Non-ASCII characters are
simply sequences of bytes, and have no special meanings; for definitions
in supplementary units data files, you can use any encoding consistent
with this assumption. For example, if you wish to use non-ASCII
characters in definitions when running @command{units} under Windows,
you can use a character set such as Windows ``ANSI'' (code page 1252 in
the US and Western Europe); if this is done, the console code page must
be set to the same encoding for the characters to display properly.
You can even use UTF-8, though some messages may be improperly aligned,
and @command{units} will not detect invalid UTF-8 sequences. If you use
UTF-8 encoding when Unicode support is not available, you should place any
definitions with non-ASCII characters @emph{outside} @samp{!utf8}
@dots{} @samp{!endutf8} blocks---otherwise, they will be ignored.
Except for code examples, typeset material usually uses the Unicode
symbols for mathematical operators.
To facilitate copying and pasting from such sources, several
typographical characters are converted to the ASCII operators
used in @command{units}:
the figure dash (U+2012),
minus (@samp{@minus{}}; U+2212),
and en dash (`--'; U+2013) are converted to the operator @samp{-};
the multiplication sign (@samp{@U{00D7}}; U+00D7),
N-ary times operator (U+2A09),
dot operator (@samp{@U{22C5}}; U+22C5),
and middle dot (@samp{@U{00B7}}; U+00B7)
are converted to the operator @samp{*};
the division sign (@samp{@U{00F7}}; U+00F7)
is converted to the operator @samp{/};
and the fraction slash (U+2044) is converted to the operator@tie{}@samp{|}.
@node Unicode Support on Windows
@c ---------------------------------------------------------------------
@section Unicode Support on Windows
@c ---------------------------------------------------------------------
Microsoft Windows supports UTF-8 in console applications running
in Windows Terminal but not in applications running in the older
Windows Console Host. In Windows Terminal, the code page must be
set to 65001 for UTF-8 to be enabled.
With the UTF-8 code page, running @w{@code{units -V}} might show
@example
@group
GNU Units version 2.24
Without readline, with UTF-8, locale English_United States (en_US)
@end group
@end example
@noindent
Two values are shown for the locale: the first is the one
returned by the system; the second is the POSIX value to which
the system value is mapped.
With a different code page, the result might be
@example
@group
GNU Units version 2.24
Without readline, with UTF-8 (disabled), locale English_United States (en_US)
To enable UTF-8: set code page to 65001
@end group
@end example
@noindent
If @command{units} is running in Windows Console Host, regardless
of the code page, the result might be
@example
@group
GNU Units version 2.24
Without readline, with UTF-8 (disabled), locale English_United States (en_US)
To enable UTF-8: run in Windows Terminal and set code page to 65001
@end group
@end example
@noindent
The UTF-8 code page can be set by running @w{@code{chcp 65001}}.
As of late 2024, the Windows build of @command{units} does not
identify characters---typically East Asian---that occupy more than
one column, and error messages involving those characters may not
be properly aligned.
@node Readline Support
@c =====================================================================
@chapter Readline Support
@c =====================================================================
@cindex @command{readline}, use with @command{units}
If the @command{readline} package has been compiled in, then when
@command{units} is used interactively, numerous command line editing
features are available. To check if your version of @command{units}
includes @command{readline}, invoke the program with the
@option{--version} option.
For complete information about @command{readline}, consult the
documentation for the @command{readline} package. Without any
configuration, @command{units} will allow editing in the style of
emacs. Of particular use with @command{units} are the completion
commands.
@cindex @samp{?} for unit completion with @command{readline}
@cindex unit completion using @samp{?} (@command{readline} only)
@cindex completion, unit, using @samp{?} (@command{readline} only)
If you type a few characters and then hit @key{ESC} followed by
@kbd{?}, then @command{units} will display a list of all the units that
start with the characters typed. For example, if you type @kbd{metr} and
then request completion, you will see something like this:
@cindex unit name completion
@example
@group
You have: metr
metre metriccup metrichorsepower metrictenth
metretes metricfifth metricounce metricton
metriccarat metricgrain metricquart metricyarncount
You have: metr
@end group
@end example
@noindent
If there is a unique way to complete a unit name, you can hit the @key{TAB} key
and @command{units} will provide the rest of the unit name. If @command{units}
beeps, it means that there is no unique completion. Pressing the @key{TAB}
key a second time will print the list of all completions.
The readline library also keeps a history of the values you enter.
You can move through this history using the up and down arrows. The
history is saved to the file @file{.units_history} in your home
directory so that it will persist across multiple @command{units}
invocations. If you wish to keep work for a certain project separate
you can change the history filename using the @option{--history}
option. You could, for example, make an alias for @command{units} to
@code{units --history .units_history} so that @command{units} would
save separate history in the current directory.
The length of each history file is limited to 5000 lines. Note also that if
you run several concurrent copies of @command{units} each one will save
its new history to the history file upon exit.
@node Currency
@c =====================================================================
@chapter Updating Currency Exchange Rates and CPI
@c =====================================================================
@cindex currency, updating
@cindex CPI, updating
@cindex exchange rates, updating
@c ---------------------------------------------------------------------
@section Currency Exchange Rates
@c ---------------------------------------------------------------------
@c man .na
The units program database includes currency exchange rates and prices
for some precious metals. Of course, these values change over time,
sometimes very rapidly, and @command{units} cannot provide real-time
values. To update the exchange rates, run @command{units_cur}, which
rewrites the file containing the currency rates, typically
@file{/var/lib/@/units/@/currency.units} or
@file{/usr/local/@/com/@/units/@/currency.units}
on a Unix-like system or
@file{@w{C:\Program Files (x86)}\@/GNU\@/units\@/definitions.units} on a Windows
system.
@c man .ad b
This program requires Python 3 (@uref{https://www.python.org}).
The program must be run with suitable
permissions to write the file. To keep the rates updated automatically,
run it using a cron job on a Unix-like system, or a similar scheduling
program on a different system.
Reliable free sources of currency exchange rates have been annoyingly
ephemeral. The program currently supports several sources:
@itemize @bullet
@item
ExchangeRate-API.com (@uref{https://www.exchangerate-api.com}). @*
The default currency server. Allows open access without an API key,
with unlimited API requests. Rates update once a day, the US dollar
(@samp{USD}) is the default base currency, and you can choose your
base currency with the @option{-b} option described below. You can
optionally sign up for an API key to access paid benefits such as
faster data update rates.
@item
FloatRates (@uref{https://www/floatrates.com}). @*
The US dollar (@samp{USD}) is the default base currency. You can
change the base currency with the
@option{-b} option described below. Allowable base currencies are listed on
the FloatRates website. Exchange rates update daily.
@item
The European Central Bank (@uref{https://www.ecb.europa.eu}). @*
The base currency is always the euro (@samp{EUR}). Exchange rates
update daily. This source offers a more limited list of currencies
than the others.
@item
Fixer (@uref{https://fixer.io}). @*
Registration for a free API key is required. With a free API key, base
currency is the euro; exchange rates are updated hourly, the
service has a limit of 1,000 API calls per month, and SSL encryption
(https protocol) is not available. Most of these restrictions are
eliminated or reduced with paid plans.
@item
open exchange rates (@uref{https://openexchangerates.org}). @*
Registration for a free API key is required. With a free API key, the
base currency is the US dollar; exchange rates are updated hourly, and
there is a limit of 1,000 API calls per month. Most of these
restrictions are eliminated or reduced with paid plans.
@end itemize
@noindent
The default source is FloatRates; you can select a different one using
@option{-s} option described below.
Precious metals pricing is obtained from Packetizer
(@uref{www.packetizer.com}). This site updates once per day.
@c ---------------------------------------------------------------------
@section US Consumer Price Index
@c ---------------------------------------------------------------------
The @command{units} program includes the US Consumer Price Index (CPI)
published by the US Bureau of Labor Statistics: specifically, the
Consumer Price Index for All Urban Consumers (CPI-U), not seasonally
adjusted---Series CUUR0000SA0. The @command{units_cur} command updates
the CPI and saves the result in @file{cpi.units} in the same location as
@file{currency.units}. The data are obtained via the BLS Public Data
API (@uref{https://www.bls.gov/developers/}). These data update once a
month. When @command{units_cur} runs it will only attempt to update the
CPI data if the current CPI data file is from a previous month, or if
the current date is after the 18th of the month.
@c ---------------------------------------------------------------------
@section Invoking @command{units_cur}
@c ---------------------------------------------------------------------
You invoke @command{units_cur} like this:
@example
units_cur [@var{options}] [@var{currency_file}] [@var{cpi_file}]
@end example
@noindent
By default, the output is written to the default currency and CPI files
described above; this is usually what you want, because this is where
@command{units} looks for the files. If you wish, you can specify
different filenames on the command line and @command{units_cur} will
write the data to those files. If you give @samp{-} for a file it will
write to standard output.
@noindent
The following options are available:
@table @env
@item -h
@itemx --help
Print a summary of the options for @command{units_cur}.
@item -V
@itemx --version
Print the @command{units_cur} version number.
@item -v
@itemx --verbose
Give slightly more verbose output when attempting to update currency
exchange rates.
@item -s @var{source}
@itemx --source @var{source}
Specify the source for currency exchange rates; currently supported
values are @samp{floatrates} (for FloatRates), @samp{eubank} (for the
European Central Bank), @samp{fixer} (for Fixer), and
@samp{openexchangerates} (for open exchange rates); the last two require
an API key to be given with the @option{-k} option.
@item -b @var{base}
@itemx --base @var{base}
Set the base currency (when allowed by the site providing the data).
@var{base} should be a 3-letter ISO currency code, e.g., @samp{USD}.
The specified currency will be the primitive currency unit used by
@command{units}. You may find it convenient to specify your local
currency. Conversions may be more accurate and you will be able to
convert to your currency by simply hitting @key{Enter} at the
@w{@samp{You want:}} prompt. This option is ignored if the source
does not allow specifying the base currency. (Currently only
floatrates supports this option.)
@item -k @var{key}
@itemx --key @var{key}
Set the API key to @var{key} for currency sources that require it.
@item --blskey @var{BLSkey}
Set the US Bureau of Labor Statistics (BLS) key for fetching CPI data.
Without a BLS key you should be able to fetch the CPI data exactly one
time per day. If you want to use a key you must request a personal
key from BLS.
@end table
@node Database Syntax
@c =====================================================================
@chapter Database Command Syntax
@c =====================================================================
@cindex database syntax summary
@cindex syntax of units database
@cindex commands in units database
@table @t
@item @var{unit} @var{definition}
Define a regular unit.
@item @var{prefix}- @var{definition}
Define a prefix.
@item @var{funcname}(@var{var}) noerror units=[@var{in-units},@var{out-units}] domain=[@var{x1},@var{x2}] range=[@var{y1},@var{y2}] @var{definition(var)} ; @var{inverse(funcname)}
Define a nonlinear unit or unit function. The four optional keywords @command{noerror},
@samp{units=}, @samp{range=} and @samp{domain=} can appear in
any order. The definition of the inverse is optional.
@item @var{tabname}[@var{out-units}] noerror @var{pair-list}
Define a piecewise linear unit. The pair list gives the points on the
table listed in ascending order. The @command{noerror} keyword is
optional.
@item !endlocale
End a block of definitions beginning with @samp{!locale}
@item !endutf8
End a block of definitions begun with @samp{!utf8}
@item !endvar
End a block of definitions begun with @samp{!var} or @samp{!varnot}
@item !include @var{file}
Include the specified file.
@item !locale @var{value}
Load the following definitions only of the locale is set to
@var{value}.
@item !message @var{text}
Display @var{text} when the database is read unless the quiet
option (@option{-q}) is enabled. If you omit @var{text}, then units
will display a blank line. Messages will also appear in the log
file.
@item !prompt @var{text}
Prefix the @w{@samp{You have:}} prompt with the specified text. If
you omit @var{text}, then any existing prefix is canceled.
@item !set @var{variable} @var{value}
Sets the environment variable, @var{variable}, to the specified
value @emph{only if} it is not already set.
@item !unitlist @var{alias} @var{definition}
Define a unit list alias.
@item !utf8
Load the following definitions only if @command{units} is running with
UTF-8 enabled.
@item !var @var{envar} @var{value-list}
Load the block of definitions that follows only if the environment
variable @var{envar} is set to one of the values listed in the
space-separated value list. If @var{envar} is not set,
@command{units} prints an error message and ignores the block of
definitions.
@item !varnot @var{envar} @var{value-list}
Load the block of definitions that follows only if the environment
variable @var{envar} is set to value that is @emph{not} listed in the
space-separated value list. If @var{envar} is not set, @command{units}
prints an error message and ignores the block of definitions.
@end table
@node GNU Free Documentation License
@c =====================================================================
@chapter GNU Free Documentation License
@c =====================================================================
@include fdl-1.3.texi
@node Index
@unnumbered Index
@printindex cp
@bye
@c man .\" ====================================================================
@c man .SH FILES
@c man .\" ====================================================================
@c man @DATAFILE@ \(em the standard units data file
@c man .\" ====================================================================
@c man .SH AUTHOR
@c man .\" ====================================================================
|