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
|
# gri - scientific graphic program (version 2.8.7)
# GPL Copyright 1991-2001 Dan E. Kelley.
#
# NOTE: The linkages to `extern "C"' routines makes use a list of C
# functions defined in the file tags.hh.
`assert .condition. ["message"]'
The condition may be a variable, a synonym, or an RPN expression. If
this condition is true (i.e. evaluates to a non-zero number), do
nothing. If the condition is false, the program will terminate with
an error condition (in unix, it will terminate with a non-zero exit
code).
Before termination, a message will be printed, the form of which
depends on the optional `"msg"' string.
If no `"msg"' string is given, the the printed message will
indicate the name of the command-file and the line at which the assert
command was encountered.
If a `"msg"' string is given, and if it ends in a newline
(`"\\n"'), then this string is printed.
If a `"msg"' string is given, and if it does not end in `"\\n"',
then the string is printed along with an indication of the location in
the command-file.
(Perl users will recognize this as being patterned on the `"die"'
command.)
{
extern "C" bool assertCmd(void);
}
`cd [\pathname]'
If a pathname specified, change to that directory. Normal unix
filenames are used, according to the C-shell convention; thus
`cd ~/src' and `cd $HOME/src' are equivalent. You may specify relative
pathnames as in `cd ../sister_directory'.
If no \pathname directory path specified, go to the home directory,
exactly as `cd ~' and `cd $HOME' do.
{
extern "C" bool cdCmd(void);
}
`close [\filename]'
If no filename is specified, close the most recently opened data-file;
otherwise close indicated file.
{
extern "C" bool closeCmd(void);
}
`convert columns to grid [neighbor | {objective|boxcar .xr. .yr. [.n. .e.]} | {barnes [.xr. .yr. .gamma. .iter.]}]'
Various forms exist:
`convert columns to grid'
`convert columns to grid neighbor'
`convert columns to grid boxcar [.xr. .yr. [.n. .e.]]'
`convert columns to grid objective [.xr. .yr. [.n. .e.]]'
`convert columns to grid barnes [.xr. .yr. .gamma. .iter.]'
All these commands ``grid'' columnar (x,y,z) data. That is, they fill
up a grid based on some form of interpolation of the possibly randomly
spaced columnar data. There are many methods in existence for doing
this, and Gri implements several of them as alternatives.
The grid will have been defined by commands such as `set x grid',
`set y grid', `read grid x' and `read grid y'. As of version 2.1.9,
Gri does not require a grid to have been pre-defined; it will create a
regular 20 by 20 grid, spanning the range of x and y data, as a
default. This is a good starting point in many cases.
*`neighbor' method*
Very fast but very limited.
*`boxcar' method*
Slower but a lot better. Still, this can produce noisy contours
if the data are not densely and uniformly ditributed through
domain.
*`objective' method*
Somewhat slower than `boxcar', but produces better fields since the
averaging function is smooth.
*`barnes' method*
Somewhat slower than `objective', but only by a constant factor
(that is, independent of number of data). This produces by far
the best results, since the smoothing function has variable
spatial scale. This is the default method if no method is
supplied.
All except the `neighbor' method may take optional arguments to
define the x and y scales of the smoothing function (called `.xr.' and
`.yr.'). (The barnes method has two other optional arguments - see
below.) If you do not supply these arguments, Gri will make a
reasonable choice and inform you of its decision. Many users find that
it's best to `convert columns to grid' with no additional parameters as
a first step, to get advice on values to use for the optional
parameters.
The default `.xr.' and `.yr.' are calculated by determining the span
in x and in y directions, and dividing each by the square root of the
number of data points. These numbers are then multiplied by the square
root of 2. The method is as proposed by S. E. Koch and M. DesJardins
and P. J. Kocin, 1983. "An interactive Barnes objective map anlaysis
scheme for use with satellite and conventional data,", J. Climate Appl.
Met., vol 22, p. 1487-1503.
If `.xr.' and `.yr.' were supplied but negative, then Gri interprets
this as an instruction to modify the default values, described in last
paragraph, by multiplying by the absolute values of the negative
numbers given, instead of muliplying by square root of 2.
If the `chatty' option is turned on, then Gri will print out
the values of (dx,dy) that it has calculated; this gives you
some guidance for supplying your own values of `(.xr.,.yr.)' if
you choose to supply them yourself. It is also a good idea to let
these parameters be a guide for your grid spacing; for example,
Koch et al., 1983, suggest using grid spacing of 0.3 to 0.5
times (dx,dy).
And now, the details ...
* *"Neighbor" method* The `convert columns to grid neighbor' method
is useful for (x,y,z) data which are already gridded (i.e., for
which x and y take only values which lie on the grid), or nearly
gridded. The (x,y,z) data are scanned from start to finish. For
each data point, the nearest grid point is found. Nearness is
measured as Cartesian distance, with scale factor given by the
distance between the first and second grid points. In other
words, distance is given by D=sqrt(dx*dx+dy*dy) where dx is ratio
of distance from data point to nearest grid point, in x-units,
divided by the difference between the first two elements of the
x-grid, and dy is similarly defined. Once the grid point nearest
the data point is determined, Gri adds the z-value to a list of
possible values to store in the grid. Once the entire data set
has been scanned, Gri then goes back to each grid point, and
chooses the z-value of the data point that was nearest to the grid
point - that is, it stores the z value of the (x,y,z) data triplet
which has minimal D value. Note that this scheme is independent
of the order of the data within the columns.
The `neighbor' method is useful when the data are already
pre-gridded, meaning that the (x,y,z) triplets have x and y values
which are already aligned with the grid. *Computational cost:* For
`P' data points, `X' x-grid points, and `Y' y-grid points, the
method calculation cost is proportional to `P*[log2(X)+log2(Y)]'
where `log2' is logarithm base 2. As discussed below, this is
often several orders of magnitude lower than the other methods of
gridding.
* *"Objective" method* In the `objective' method, a smoothing
technique known as objective mapping is applied. It is
essentially a variable-size smoothing filter of approximately
Gaussian shape (it is method "two" of Levy and Brown [1986 J.
Geophysical Res. vol 91, p 5153-5158]) The parameters `.xr.' and
`.yr.' give the width of the filter.
With the optional additional parameters `.n.' and `.e.' are
specified, then grid values will be assigned the missing value if
there are fewer than `.n.' (x,y,f) data in the neighborhood of the
gridpoint, even after enlarging the neighborhood by widening and
heightening by root(2) up to `.e.' times. (The enlargement is only
done if fewer than `.n.' points are found.) If these parameters
are not specified in the command, then values `.n.'=5 and `.e.'=1
are assumed. The special case where `.e.' is negative tells Gri
to *always* fill in each grid point, by extending the neighborhood
to enclose the entire dataset if necessary.
*Computational cost:* For `P' data points, `X' x-grid points, and
`Y' y-grid points, the method calculation cost is proportional to
`P*X*Y'. Given that `X' and `Y' are determined by the requirement
for smoothness of contours and the size of the graph, they are
more or less fixed for all applications. They are often in the
range of 20 or so - on 10 cm wide graph, this yields a contour
footprint of 1/2 cm, which is often small enough to yield smooth
contours. Therefore, the computational cost scales linearly with
the number of data points. Compared to the "neighborhood" method,
this is more costly by a factor of `X*Y/log_2(X)/log_2(Y)' which is
normally in the range from 20 to 50.
* *"Boxcar" method* In the `boxcar' method, the grid points are
derived from simple averages calculated in rectangles `.xr.' wide
and `.yr.' tall, centred on the gridpoints. The `.n.' and `.e.'
parameters have similar meanings as in the "objective" method.
*Computational cost:* Roughly same as `objective' method described
above.
* *"Barnes" method* This is the default scheme.
The Barnes algorithm is applied. If no parameters are specified,
`.xr.' and `.yr.' are determined as above, with `.gamma.' set to
0.5, and `.iter.' set to 2 so that two iterations are done. On
successive iterations, the smoothing lengthscales `.xr' and `.yr'
are each reduced by multiplying by the square root of `.gamma.'.
Smaller `.gamma.' values yield better resolution of small-scale
features on successive iterations. Koch et al., 1983, recommend
using a `.gamma.' value in the range 0.2 to 1, with two iterations.
Provided that all the grid points are close enough to at least some
column data, the entire grid is filled. But if `.xr.' and `.yr.'
are too small, the weighting function can fall to zero, since it
is exponential in the sum of the squares of the x-distance/`.xr.'
and the y-distance/`.yr.'; in that case missing values result at
those grid points. On a 32 bit computer, the weighting function
will fall to zero when x-distance/`.xr.' and y-distance/`.yr.'
are less than about 15 to 20.
If weights have been read in, then these values are applied
in addition to the distance-based weighting. (The normalization
means that weights for two data points of e.g. 1 and 2 will
yield the same result as if the weights had been given as
10 and 20.)
The computational cost is proportional to `P*P+P*X*Y)'. For large
datasets, the first term (which results from the necessity to
interpolate not only to the grid points but also to the data
points) overwhelms the second term. For example, `X' and `Y' are
normally less than approximately 20. This value is common because
on a graph with a 10 cm axis, this yields a contour footprint of
1/2 cm, which is normally fine enough to get smooth contours.
Therefore, if there are more than 400 data points, the `P*P' term
exceeds the `P*X*Y' term. A data set may well have thousands of
data points, and in this case the computational cost is
approximately `P*P'. This is, therefore, a "order n-squared"
algorithm, and it is therefore, by it's very nature, slow. The
other methods, "neighbor", "objective" and "boxcar" are "order n"
algorithms, so that "barnes" is much more costly for large data
sets. As an example, for a dataset with a `P' of 1000, and with
`X' and `Y' of 20, "barnes' is slower than "neighbor" by a factor
of about 100. (The ratio increases to 300 for 5000 points.)
Compared to "objective" and "boxcar," however, "barnes" is slower
by a factor of 13 for 5000 data points and 26 for 10000 data
points. For most practical purposes, therefore, the many
advantages of "barnes" over "objective" and "boxcar" far outweigh
the additional computational cost. On the other hand, the very
swift "neighbor" method,is only suitable for very particular types
of data sets.
References: (1) Section 3.6 in Roger Daley, 1991, "Atmospheric data
analysis," Cambridge Press, New York. (2) S. E. Koch and M.
DesJardins and P. J. Kocin, 1983. "An interactive Barnes
objective map anlaysis scheme for use with satellite and
conventional data,", J. Climate Appl. Met., vol 22, p. 1487-1503.
The Barnes algorithm is as follows:
The gridded field is estimated iteratively. Successive iterations
retain largescale features from previous iterations, while adding
details at smaller scales.
The first estimate of the gridded field, here denoted `G_(ij)^0'
(the superscript indicating the order of the iteration) is given by a
weighted sum of the input data, with `z_k' denoting the k-th `z' value.
sum_1^n W_(ijk)^0 z_k
G_(ij)^(0) = ----------------------
sum_1^n W_(ijk)0
where the notation `sum_1^n' means to sum the elements for the `k'
index ranging from 1 to `n'.
The weights `W_(ijk)^0' are defined in terms of a Guassian function
decaying with distance from observation point to grid point:
( (x_k - X_i)^2 (y_k - Y_j)^2 )
W_(ijk)^0 = exp ( - --------------- - --------------- )
( L_x^2 L_y^2 )
Here `L_x' and `L_y' are lengths which define the smallest `(x,y)'
scales over which the gridded field will have significant variations
(for details of the spectral response see Koch et al. 1983).
Note: if the user has supplied weights, then these are applied in addition
to the distance-based weights. That is, `w_i W_(ijk)' is used instead
of `W_(ijk)'.
The second iteration derives a grid `G_(ij)^1' in terms of the first
grid `G_(ij)^0' and "analysis values" `f_k^0' calculated at the
`(x_k,y_k)' using a formula analogous to that above. (Interpolation
based on the first estimate of the grid `G_(ij)^0' can also be used to
calculate `f_k^0', with equivalent results for a grid of sufficiently
fine mesh.) In this iteration, however, the weighted average is based
on the difference between the data and the gridded field, so that no
further adjustment of the gridded field is done in regions where it is
already close to through the observed values. The second estimate of
the gridded field is given by
sum_1^n W_(ijk)^1 (f_k - f_k^0)
G_(ij)^1 = G_(ij)^0 + -------------------------------
sum_1^n W_(ijk)^1
where the weights `w_(ik,1)' are defined by analogy with `W_(ik)^0'
except that `L_x' and `L_y' are replaced by `gamma^(1/2)L_x' and
`gamma^(1/2)L_y'. The nondimensional parameter `gamma' (`0<gamma<1')
controls the degree to which the focus is improved on the second
iteration. Just as the weighting function forced the gridded field to
be smooth over scales smaller than `L_x' and `L_y' on the first
iteration, so it forces the second estimate of the gridded field to be
smooth over the smaller scales `gamma^(1/2)L_x' and `gamma^(1/2)L_y'.
The first iteration yields a gridded field which represents the
observations over scales larger than `(L_x,L_y)', while successive
iterations fill in details at smaller scales, without greatly modifying
the larger scale field.
In principle, the iterative process may be continued an arbitrary
number of times, each time reducing the scale of variation in the
gridded field by the factor `gamma^(1/2)'. Koch et al. 1983 suggest
that there is little utility in performing more than two iterations,
providing an appropriate choice of the focussing parameter `gamma' has
been made. Thus the gridding procedure defines a gridded field based
on three tunable parameters: `(L_x,L_y,gamma)'.
{
extern "C" bool convert_columns_to_gridCmd(void);
}
`convert columns to spline [.gamma.] [.xmin. .xmax. .xinc.]'
Fit a normal or taut interpolating spline, y=y(x), through the (x,y)
data. Then subsample this spline to get a new set of (x,y) data. If
the spline x-values, `.xmin.', etc, are not specified, the spline
ranges from the smallest x-value with legitimate data to the largest
one, with 200 steps in between.
The parameter `.gamma.' determines the type of spline used. If
`.gamma.' is not specified, or is given as zero, a standard
interpolating spline is used. A knot appears at each x location, with
cubic polynomials spanning the space between the knots. If `.gamma.'
lies between 0 and 6, a taut spline is used; this tends to have fewer
wiggles than a normal spline. If `.gamma.' lies in the range 0 to 3,
a taut spline is used, with the possible insertion of knots between
interior x pairs. The value 2.5 is used commonly. If `.gamma.' lies
in the range 3 to 6, extra knots are permitted in the x pairs at the
ends of the domain. A value of 5.5 is used commonly.
*Reference* Chapter 16 of Carl de Boar, 1987. "A Practical Guide to
Splines" Springer-Verlag.
{
extern "C" bool convert_columns_to_splineCmd(void);
}
`convert grid to columns'
Create column data from grid data. Each non-missing gridpoint is
translated into a single (x,y,f) triplet. If column data already exist,
then they are first erased. This command is useful in changing the grid
configuration, perhaps from a non-uniform grid to a uniform grid. In
the following example, a new grid with x=(0, 0.05, 0.1, ..., 0.1) and
y=(10, 11, ..., 20) is created. The default gridding method (`convert
columns to grid') is used here, but of course one is free to adjust the
method as usual.
# ... read/create grid
convert grid to columns
delete grid
set x grid 0 1 0.05
set y grid 10 20 1
convert columns to grid
{
extern "C" bool convert_grid_to_columnsCmd(void);
}
`convert grid to image [size .width. .height.] [box .ll_x. .ll_y. .ur_x. .ur_y.]'
With no options specified, convert grid to a 128x128 image, using an
image range as previously set by `set image range'. The image will
only be defined for those patches of the region which are spanned by
four neighboring non-missing grid data. For example, isolated
non-missing grid values will not translate into non-missing pixels. The
reason for this is that individual pixel values for the image are
determined by interpolating using the four corners of the grid nearest
the pixel. The interpolation formula is f(x,y)=a+bx+cy+dxy.
With the `size' options `.width.' and `.height.' specified, they set
the number of rectanglular patches in the image.
With the `box' options specified, they set the bounding box for the
image. Otherwise, by default, the image spans the same bounding box as
the grid as set by `set x grid' and `set y grid'.
Normally, missing values in the grid are translated to white in the
image. You may control the color of missing values with the `set image
missing value color to'... command.
{
extern "C" bool convert_grid_to_imageCmd(void);
}
`convert image to grid'
Convert image to grid, using current graylevel/colorlevel mapping. If
the image is in color, the grid values will represent the result of
mapping the colors to grayscale in the standard way (Foley and VanDam,
1984). [BUG: as of 1.063, the colorscale is ignored completely, and I'm
not sure what happens.] The image data are interpolated onto the grid
using a nearest-neighbor substitution. This command insists that the
image x/y grids have already been defined.
{
extern "C" bool convert_image_to_gridCmd(void);
}
`create columns from function'
Plot a function of x which is defined in synonym \function.
ENVIRONMENT
\function = function to plot.
\xmin = minimum x value
\xmax = minimum x value
\xinc = increment in x values
EXAMPLE
\function = "cos(x)"
\xmin = "0"
\xmax = "2 * 3.14"
\xinc = "0.1"
create columns from function
draw curve
quit
NOTE: This only works on machines which have the `awk' command
available at the commandline. This means most unix machines and some
vax machines, but probably no Macintoshes.
{
if {rpn "\\xmin" defined}
.must_clean_up_xmin. = 0
else
\xmin = "0"
.must_clean_up_xmin. = 1
end if
if {rpn "\\xmax" defined}
.must_clean_up_xmax. = 0
else
\xmax = "1"
.must_clean_up_xmax. = 1
end if
if {rpn "\\xinc" defined}
.must_clean_up_xinc. = 0
else
\xinc = "0.1"
.must_clean_up_xinc. = 1
end if
if {"\.system." == "unix"}
system awk \
'BEGIN {for(x = \xmin; x <= \xmax; x += \xinc) {print (x, \function)} \
} ' \
> tmp
else if {"\.system." == "vax"}
system awk/COMMANDS =\
"BEGIN { for (x = \xmin; x <= \xmax; x += \xinc) {print (x, \function)} \
} " \
/OUTPUT=TMP NL:
end if
open tmp
read columns x y
close tmp
if {"\.system." == "unix"}
system rm tmp
else if {"\.system." == "vax"}
system DELETE TMP.*;*
end if
if .must_clean_up_xmin.
delete \xmin
end if
if .must_clean_up_xmax.
delete \xmax
end if
if .must_clean_up_xinc.
delete \xinc
end if
delete .must_clean_up_xmin.
delete .must_clean_up_xmax.
delete .must_clean_up_xinc.
}
`create image grayscale banded .band.'
Make a banded grayscale with in units of .band. pixel values each.
Thus, pixel values 0 to (.band. - 1) on the image will map to 0, while
values from .band. to (2 * .band. - 1) will map to .band., etc. For
example, .band. = 2 gives grayscale = (0 0 2 2 4 4 6 6 ... 252 252 254
254).
{
if {rpn \.words. 5 ==}
\band = "\.word4"
else
show "ERROR: Require 4 words, but got \.words. words."
show traceback
quit
end if
system awk 'BEGIN \
{ \
for (i = 0; i < 256; i++) \
{ \
printf ("%d ", \band * int (i / \band)) \
} \
printf ("\n") \
}' \
> GRAYSCALE.TMP
open GRAYSCALE.TMP
read image grayscale
close
system rm GRAYSCALE.TMP
delete \band
}
`create image greyscale banded .band.'
Alternate spelling of grayscale.
{
if {rpn \.words. 5 ==}
\band = "\.word4"
else
show "ERROR: Require 4 words, but got \.words. words."
show traceback
quit
end if
system awk 'BEGIN \
{ \
for (i = 0; i < 256; i++) \
{ \
printf ("%d ", \band * int (i / \band)) \
} \
printf ("\n") \
}' \
> GRAYSCALE.TMP
open GRAYSCALE.TMP
read image grayscale
close
system rm GRAYSCALE.TMP
delete \band
}
`debug [.n.] | [clipped values in draw commands] | off'
With no optional parameters, sets the value of `..debug..' to 1.
(Normally, `..debug..' is 0.) You may use `..debug..' in if
statements, etc. Note that `..debug..' is also set to 1 when gri is
invoked with the commandline switch `-d'.
With `.n.' specified, `..debug..' is set to `.n.'; a value of zero
for `.n.' turns debugging off, while 1 turns it on. Higher values may
be used for deeper debugging, if you choose:
if \{rpn ..debug.. 2 <}
# Code to do if ..debug.. is greater than 2.
end if
Note that you can assign to `..debug..' as you can to any other
variable; `debug .n.' is equivalent to `..debug.. = .n.'.
With the `clipped' option, Gri prints any clipped data encountered
during any `draw ...' commands, EXCEPT in the case of `postscript'
clipping, where no check is possible. (Note that `..debug..' is not
affected.)
All these forms of debugging are cancelled by `debug off'.
{
extern "C" bool debugCmd(void);
}
`delete {.variable. | \synonym [...]} | columns [{randomly .fraction.}|{where missing}] | grid | {[x|y] scale}'
Delete some item or characteristic.
`delete .variable.'
Delete definition of variable `.variable.', making it undefined.
`delete \synonym'
Delete definition of synonym `\synonym', making it undefined.
`delete columns'
Delete column data.
`delete columns randomly .fraction.' Randomly select fraction
`.fraction.' of the non-missing column data, and designate them
as being missing.
`delete grid'
Delete grid data.
`delete scale'
Delete scales for both x and y, so next `read columns' will set
it.
`delete x scale'
Delete scales for x, so next `read columns' will set it.
`delete y scale'
Delete scales for y, so next `read columns' will set it.
{
extern "C" bool deleteCmd(void);
}
`differentiate {x|y wrt index|y|x} | {grid wrt x|y}'
Differentiate column data or grid data. Only the `x' and `y' columns
may be differentiated. They may be differentiated either with respect
to ("wrt") the index (forming a first difference) or with respect to
the other column. The derivative is done with the backwards-difference
algorithm. Grid data may differentiated with respect to `x' direction
or `y' direction. Grid differentiation is done with a centred
difference, with endpoints being assigned the derivative of the
neighboring interior point (so that the second derivative is zero at
the edges of the grid).
{
extern "C" bool differentiateCmd(void);
}
`draw arrow from .x0. .y0. to .x1. .y1. [cm]'
With no optional parameters, draw an arrow from (`.x0.', `.y0.') to
(`.x1.', `.y1.'), where coordinates are in user units. The arrow head
will be at (`.x1.', `.y1.'), and its size is as set by most recent
call to `set arrow size'. With the `cm' keyword present, the
coordinates are in centimetres on the page. NOTE: This will not cause
auto-drawing of axes.
{
extern "C" bool draw_arrow_from_toCmd(void);
}
`draw arrows'
Draw a vector field consisting of arrows emanating from the coordinates
stored in the (x, y) columns. The lengths and orientations of the
arrows are stored in the (u, v) columns, and the scale for the (u,v)
columns is set by `set u scale' and `set v scale'. SEE ALSO: (1) To
set arrow size, use `set arrow size'. (2) To get a single arrow, for
labelling plots, etc, use the `draw arrow from .x0. .y0. to .x1. .y1.
[cm]' command.
{
extern "C" bool draw_arrowsCmd(void);
}
`draw axes if needed'
Draw axes frame if required. Used within gri commands that auto-draw
axes. NOTE: this should only be done by developers.
{
extern "C" bool draw_axes_if_needed(void);
}
`draw axes [.style.|frame|none]'
With no style (`.style.') specified, draw x-y axes frame labelled at
left and bottom. The value of `.style.' determines the style of axes:
`.style. = 0'
Draw x-y axes frame labelled at left and bottom
`.style. = 1'
Draw axes without tics at top and right
`.style. = 2'
Draw axes frame with no tics or labels
With the keyword `frame' specified, draw axes frame with no tics or
labels (just like `.style.' = 2).
With the keyword `none' specified, prevent Gri from automatically
drawing axes when drawing curves.
{
extern "C" bool draw_axesCmd(void);
}
`draw border box [.ll_x. .ll_y. .ur_x. .ur_y. .width_cm. .brightness.]'
Draw gray box, as decoration or alignment key for pastup. The box, with
outer lower left corner at (`.ll_x.', `.ll_y.') and outer upper right
corner at (`.ur_x'., `.ur_y.') - both coordinates being in centimetres
on the page - is drawn with thickness `.width_cm.' and with graylevel
`.brightness.' (0 for black; 1 for white). The gray line is drawn
inside the box. After drawing the gray line, a thin black line is
drawn along the outside edge.
If the geometry is not specified with `.ll_x.' and the other
parameters, then a reasonable margin is used around the present axes
area, and the defaults (`.border.' = 0.2, `.brightness.' = 0.75) are
used.
NOTE: This command does not cause auto-drawing of axes.
{
if {rpn \.words. 3 ==}
.ll_x. = {rpn ..xmargin.. "M" width 5 * -}
.ll_y. = {rpn ..ymargin.. "M" ascent 6 * -}
.ur_x. = {rpn ..xmargin.. ..xsize.. + "M" width 2.0 * +}
.ur_y. = {rpn ..ymargin.. ..ysize.. + "M" width 2.0 * +}
.width_cm. = 0.2
.brightness. = 0.75
else if {rpn \.words. 9 ==}
.ll_x. = \.word3.
.ll_y. = \.word4.
.ur_x. = \.word5.
.ur_y. = \.word6.
.width_cm. = \.word7.
.brightness. = \.word8.
else
show "ERROR: Require 3 or 9 words, but got \.words. words."
show traceback
quit
end if
#
# Save old values of things that will be changed.
.old_graylevel. = ..graylevel..
.old_linewidth. = ..linewidth..
set graylevel .brightness.
set line width {rpn .width_cm. cmtopt}
.tmp. = {rpn .ll_y. ..linewidth.. 2 / pttocm +}
draw line from .ll_x. .tmp. to .ur_x. .tmp. cm # lower edge
.tmp. = {rpn .ll_x. ..linewidth.. 2 / pttocm +}
draw line from .tmp. .ll_y. to .tmp. .ur_y. cm # left edge
.tmp. = {rpn .ur_y. ..linewidth.. 2 / pttocm -}
draw line from .ll_x. .tmp. to .ur_x. .tmp. cm # upper edge
.tmp. = {rpn .ur_x. ..linewidth.. 2 / pttocm -}
draw line from .tmp. .ll_y. to .tmp. .ur_y. cm # right edge
#
# Draw thin black border.
set line width 0.25
set graylevel black
draw box .ll_x. .ll_y. .ur_x. .ur_y. cm
#
# Return to old values.
set line width .old_linewidth.
set graylevel .old_graylevel.
#
# Clean up local storage.
delete .tmp.
delete .old_graylevel.
delete .old_linewidth.
delete .brightness.
delete .width_cm.
delete .ll_x.
delete .ll_y.
delete .ur_x.
delete .ur_y.
}
`draw box filled .ll_x. .ll_y. .ur_x. .ur_y. [cm]'
Draw filled box spanning indicated range, with lower-left corner at
(`.ll_x.', `.ll_y.') and upper-right corner at (`.ur_x.', `.ur_y.').
The corners are specified in user coordinates, unless the optional
`cm' keyword is present, in which case they are in centimetres on the
page. An error will result if you specify user coordinates but they
aren't defined yet.
No checking is done on the rectangle; for example, there is no
requirement that `.ll_x.' be to the left of `.ur_x.' in your
coordinate system.
NOTE: if the box is specified in user units, this command will cause
auto-drawing of axes, but not if the box is specified in cm units.
{
extern "C" bool draw_box_filledCmd(void);
}
`draw box .ll_x. .ll_y. .ur_x. .ur_y. [cm]'
Draw box spanning indicated range, with lower-left corner at
(`.ll_x.', `.ll_y.)' and upper-right corner at (`.ur_x.', `.ur_y.').
The corners are specified in user coordinates, unless the optional
`cm' keyword is present, in which case they are in centimetres on the
page. An error will result if you specify user coordinates but they
aren't defined yet.
No checking is done on the rectangle; for example, there is no
requirement that `.ll_x.' be to the left of `.ur_x.' in your
coordinate system.
{
extern "C" bool draw_boxCmd(void);
}
`draw circle with radius .r_cm. at .x_cm. .y_cm.'
Draw circle of specified radius (in cm) at the specified location (in
cm on the page).
{
extern "C" bool draw_circleCmd(void);
}
`draw contour [{.value. [unlabelled|{labelled "\label"}]} | {.min. .max. .inc. [.inc_unlabelled.] [unlabelled]}]'
This command draws contours based on the "grid" data previously read in
by a `read grid data' command or created by gridding column data
with a `create grid from columns' command. If the grid data don't
exist, or if the x and y locations of the grid points do not exist (see
`set x grid', `set y grid', `read grid x' and `read grid y'), Gri will
complain.
With no optional parameters, draw labelled contours at an interval
that is picked automatically based on the range of the data.
With a single numerical value (`.value.'), draw the indicated
contour. With the addition of `labelled "\label"', put the indicated
label instead of a numeric label. This can be useful, say, for using
scientific notation instead of computer notation for exponents. For
example, you might do something like `draw contour 1e-5 labelled
"10$^\{-5}$"' or maybe `draw contour 1e-5 labelled "critical value"'.
With (`.min.', `.max.' and `.inc.') given, draw contours for z(x,y)
= `.min.', z(x,y) = `.min. + .inc.', z(x,y) = `.min. + 2*.inc.', ...,
z(x,y) = `.max.'
With the additional value `.inc_unlabelled.' specified, extra
unlabelled contours are drawn at this finer interval.
With the optional parameter `unlabelled' at the end of any form of
this command (except the `labelled "\label"' variation, of course),
Gri will not label the contour(s).
*Hint:* It can be effective to draw contours at a certain interval
with labels, and a thicker pen, e.g.
set line width rapidograph 3x0
draw contour -2 5 1 0.25
set line width rapidograph 1
draw contour -2 5 1
{
extern "C" bool draw_contourCmd(void);
}
`draw curve overlying'
Like `draw curve', except that before drawing, the area underneath the
curve (+/- one linewidth) is whited out. This clarifies graphs where
curves overly other curves or the axes. SEE ALSO: `draw curve'.
{
state save
set dash off
set color white
set line width {rpn ..linewidth.. 3 *}
draw curve # clean space underneath
state restore
draw curve # draw actual curve
}
`draw curve filled [to {.y. y} | {.x. x}]'
The form `draw curve filled ...' draws filled curves. If `to .value.'
is not specified, fill the region defined by the x-y points using the
current paint colour (see `set graylevel'). To complete the shape, an
extra line is drawn from the first and last point.
The form `draw curve filled to .y. y' fills the region between y(x)
and y = `.y.'; do not connect the first and last points as in the case
where `to .yvalue.' is not specified.
The form `draw curve filled to .x. x' fills the region between x(y)
and x = `.x.'
{
extern "C" bool draw_curveCmd(void);
}
`draw curve'
Draws a curve connecting the points (x,y), which have been read in by a
command like `read columns x y'. Line segments are drawn between all
(x,y) points, except: (1) no line segments are drawn to any missing
data (see `set missing value'), and (2) if clipping is turned on
(see `set clip on'), no line segments are drawn outside the clipping
region. SEE ALSO: `draw curve overlying'
{
extern "C" bool draw_curveCmd(void);
}
`draw essay "text"|reset'
Draw indicated text on the page. Succeeding calls draw text further
and further down the page, starting at the top.
The current font size is used; to alter this, do `set font size'
before calling `draw essay'.
When `reset' is present instead of text, the drawing position is
reset to the top of the page. Use this after a `new page' command to
ensure that the next text lines will appear at the top of the page as
expected. EXAMPLE:
set font size 2 cm
draw essay "Line 1, at top of page"
draw essay "Line 2, below top line"
{
# Check for proper format, and give error message if not.
if {rpn \.words. 3 ==}
# Check to see if this is the first call; if so, initialize location.
if {"\.word2." == "reset"}
# Reset .top_of_page. and return.
if ..landscape..
.top_of_page. = {rpn 8.5 2.54 * 1 -}
else
.top_of_page. = {rpn 11. 2.54 * 1 -}
end if
return
end if
# Last word is not `reset', so draw it.
if {rpn ".top_of_page." defined !}
#
if ..landscape..
.top_of_page. = {rpn 8.5 2.54 * 1 -}
else
.top_of_page. = {rpn 11. 2.54 * 1 -}
end if
end if
.top_of_page. -= {rpn ..fontsize.. pttocm 1.5 *}
draw label "\.word2." at 1 .top_of_page. cm
else
show "ERROR: Require 3 words, but got \.words. words."
show traceback
quit
end if
}
`draw gri logo .x_cm. .y_cm. .height_cm. .style. \fgcolor \bgcolor'
.style. style
======= ===================
0 stroke curve
1 fill with color \fgcolor, no background
2 fill with color \fgcolor it in tight box of color \bgcolor
3 as 2 but in square box
4 draw in \fgcolor on top of shifted copy in \bgcolor
{
extern "C" bool draw_gri_logoCmd(void);
}
`draw grid'
Draw plus-signs at locations where grid data are non-missing.
{
extern "C" bool draw_gridCmd(void);
}
`draw image palette [axisleft|axisright|axistop|axisbottom] [left .left. right .right. [increment .inc.]] [box .ll_x_cm. .ll_y_cm. .ur_x_cm. .ur_y_cm.]'
With no optional parameters, draw palette for image, placed above the
current top showing values ranging from `.min_value.' to `.max_value.'
as given in `set image range'.
Optional keywords (`axisleft', etc) control the orientation of the
palette, the default being `axisbottom'.
The optional parameters `.left.' and `.right.' may be used to specify
the range to be drawn in the palette. If the additional optional
parameter `.inc.' is present, it specifies the interval between tics
on the scale; if not present, the tics are at increments of 2 *
(`.right.' - `.left'.). (If `.inc.' has the wrong sign, it will be
corrected without warning.)
When the optional `box' parameters are present, they prescribe the
bounding box to contain the palette. The units are centimetres on the
page. If these parameters are not present, the box will be drawn above
the image plot.
HINT: It is a good idea to make the palette range `.left.' to
`.right.' extend a little beyond the range of full white and full
black, since otherwise neither pure white nor pure black will appear in
the colorbar. For example:
set image grayscale black 0 white 1 increment 0.1
draw image palette left -0.1 right 1.1 increment 0.1
{
extern "C" bool draw_image_paletteCmd(void);
}
`draw image grayscale [left .left. right .right. [increment .inc.]] [box .ll_x_cm. .ll_y_cm. .ur_x_cm. .ur_y_cm.]'
Old name for `draw image palette'
{
extern "C" bool draw_image_paletteCmd(void);
}
`draw image histogram [box .ll_x_cm. .ll_y_cm. .ur_x_cm. .ur_y_cm.]'
With no optional parameters, draw histogram of all unmasked parts of
the image, placing it above the current top of the plot.
When the `box' options are present, they specify the box (in
centimetre coordinates on the page) in which the histogram plot is to
be done.
{
extern "C" bool draw_image_histogramCmd(void);
}
`draw image'
Draw black/white image made by `convert grid to image' or by `read
image'.
{
extern "C" bool draw_imageCmd(void);
}
#* @param .P_sigma. = reference pressure for density @default 0dbar
#* @param .P_theta. = reference pressure for temperature @default 0dbar
`draw isopycnal [unlabelled] .density. [.P_sigma. [.P_theta.]]'
Draw isopycnal curve for a temperature-salinity diagram. This curve
is the locus of temperature and salinity values which yield seawater of
the indicated density, at the indicated pressure. The UNESCO equation
of state is used.
For the results to make sense, the x-axis should be salinity and the
y-axis should be either in-situ temperature or potential temperature.
The `.density.' unit is kg/m^3. If the supplied value exceeds 100
it will be taken to indicate the actual density; otherwise it will be
taken to indicate density minus 1000 kg/m^3. (Thus, 1020 and 20 each
correspond to an actual density of 1020 kg/m^3.)
The reference pressure for density, `.P_sigma.', is in decibars
(roughly corresponding to meters of water depth). If no value is
supplied, a pressure of 0 dbar (i.e. atmospheric pressure) is used.
The reference pressure for theta, `.P_theta.', is in decibars, and
defaults to zero (i.e. atmospheric pressure) if not supplied. This
option is used if the y-axis is potential temperature referenced to a
pressure other than the surface. Normally the potential temperature is,
however, referenced to the surface, so that specifying a value for
`.P_theta.' is uncommon.
By default, labels will be drawn on the isopycnal curve; this may be
prevented by supplying the keyword `unlabelled'. If labels are drawn,
they will be of order 1000, or of order 10 to 30, according to the
value of `.density.' supplied (see above). The label format defaults
to "%g" in the C-language format notation, and may be controlled by
`set contour format'. The label position may be controlled by `set
contour label position' command (bug: only non-centered style works).
Setting label position is useful if labels collide with data points.
Labels are drawn in the whiteunder mode, so they can white-out data
below. For this reason it is common to draw data points after drawing
isopycnals.
If the y-axis is in-situ temperature, the command should be called
without specifying `.P_sigma.', or, equivalently, with `.P_sigma.' = 0.
That is, the resultant curve will correspond to the (S,T) solution to
the equation
.density. = RHO(S, T, 0)
where `RHO=RHO(S,T,p' is the UNESCO equation of state for seawater.
This is a curve of constant sigma_T.
If the y-axis is potential temperature referenced to the surface,
`.P_theta.' should not be specified, or should be specified to be zero.
The resultant curve corresponds to a constant value of potential
density referenced to pressure `.P_sigma.', i.e. the (S,theta) solution
to the equation
.density. = RHO(S, theta, .P_sigma.)
For example, with `.P_sigma.=0' (the default), the result is a curve
of constant sigma_theta.
If the y-axis is potential temperature referenced to some pressure
other than that at the surface, `.P_theta.' should be supplied. The
resultant curve will be the (S,theta) solution to the equation
.density. = RHO(S, T', .P_sigma.)
where
T'=THETA(S, theta, .P_theta., .P_sigma.)
where `THETA=THETA(S,T,P,Pref)' is the UNESCO formula for potential
temperature of a water-parcel moved to a reference pressure of `Pref'.
Note that `theta', potential temperature referenced to
pressure `.P_theta.', is the variable assumed to exist on
the y-axis.
{
extern "C" bool draw_isopycnalCmd(void);
}
`draw isospice .spice. [unlabelled]'
Draw an iso-spice line for a "TS" diagram, using (S, T) data stored in
files in a subdirectory named `iso-spice0' in a directory named by the
environment variable `GRI_EOS_DIR'. You must set this environment
variable yourself, in the normal unix way. If `GRI_EOS_DIR' is not
defined, Gri looks in the directory `/data/po/ocean/EOS/iso0';
of course, this will work only for people on the same machine as the
author.
Only certain iso-spice lines are stored in these files, so only
certain values of `.spice.' are allowed. They are 21.75, 22.00, 22.25,
..., 30.75. You must supply `.density.' in exactly this format (with 2
decimal places), or else Gri will not find the appropriate TS file, and
will give a "can't open file" error. NB: isopycnals ranging from about
23.00 to 26.00 cross a TS diagram spanning 34<S<36 and 0<T<10.
The line is labelled at the right with the density value, unless
the `unlabelled' option is given.
Clipping should be on when drawing iso-spice lines. A warning will
be given if the isospice line does not intersect the clipping region.
EXAMPLE
set clip on
draw isospice line 27.00
draw isospice line 27.50 unlabelled
{
if {rpn \.words. 3 > \.words. 4 < |}
show "ERROR: Require 3 or 4 words, but got \.words. words."
show traceback
quit
end if # don't have 3 or 4 words
get env \gri_eos_dir GRI_EOS_DIR
if {rpn "\gri_eos_dir" "" ==}
\eos_file = "/data/po/ocean/EOS/iso-spice0/spice0_\.word2."
else
\eos_file = "\gri_eos_dir/iso-spice0/spice0_\.word2."
end if
if ..trace..
show "Plotting iso-spice lines in \eos_file"
end if # ..trace..
open \eos_file
read columns x y
close
if ..num_col_data..
draw curve
if {rpn \.words. 4 ==}
if {"\.word3." == "unlabelled"}
# no label
else # improper final word
show "ERROR: Bad 4th word \"\.word3.\"; expecting \"labelled\""
show traceback
quit
end if # improper final word
else # not 4 words
if {rpn ..xlast.. ..xright.. - ..ylast.. ..ytop.. - >}
# Put label above.
draw label "\.word2." at \
{rpn ..xlast.. xusertocm "\.word2." width 0.35 * -} \
{rpn ..ytop.. yusertocm ..fontsize.. pttocm 0.7 * +} cm
else # label at right
# Put label to right.
draw label "\.word2." at \
{rpn ..xright.. xusertocm ..fontsize.. pttocm 0.7 * +} \
{rpn ..ylast.. yusertocm ..fontsize.. pttocm 0.4 * -} cm
end if # label at right
end if
else # iso-spice not in region
show "WARNING from `draw isospice ...': iso-spice \.word2. not in clip region."
end if # iso-spice not in region
delete \gri_eos_dir \eos_file
}
`draw label boxed "\string" at .ll_x. .ll_y. [cm]'
Draw boxed label for plot, located with lower-left corner at indicated
(x,y) position (specified in user units or in cm on the page). The
current font size and pen color are used. The geometry derives from
the current font size, with the label being centered within the box.
{
if {rpn "\.word4." "at" !=}
show "ERROR: Fifth word must be \"at\", not \"\.word4.\""
show traceback
quit
end if
new .x. .y.
new .draw_boxed_labelR.
new .draw_boxed_labelG.
new .draw_boxed_labelB.
.draw_boxed_labelR. = ..red..
.draw_boxed_labelG. = ..green..
.draw_boxed_labelB. = ..blue..
if {rpn \.words. 7 ==}
.x. = {rpn \.word5. xusertocm}
.y. = {rpn \.word6. yusertocm}
else if {rpn \.words. 8 ==}
if {rpn "\.word7." "cm" !=}
show "ERROR: Require 7th word to be `cm'"
show traceback
quit
end if
.x. = \.word5.
.y. = \.word6.
else
show "ERROR: Require 7 or 8 words, but got \.words. words."
show traceback
quit
end if
# Coordinates now in cm
.draw_boxed_label_offset. = {rpn ..linewidth.. pttocm 4 *}
draw box filled \
{rpn .x. .draw_boxed_label_offset. +} \
{rpn .y. .draw_boxed_label_offset. -} \
{rpn .x. "MM\.word3." width + .draw_boxed_label_offset. +} \
{rpn .y. "M" ascent 2 * + .draw_boxed_label_offset. -} cm
set color white
draw box filled \
.x. \
.y. \
{rpn .x. "MM\.word3." width +} \
{rpn .y. "M" ascent 2 * +} cm
set color rgb .draw_boxed_labelR. .draw_boxed_labelG. .draw_boxed_labelB.
draw box \
.x. \
.y. \
{rpn .x. "MM\.word3." width +} \
{rpn .y. "M" ascent 2 * +} cm
draw label "\.word3." at \
{rpn .x. "M" width +} \
{rpn .y. "M" ascent 0.5 * +} cm
delete .x. .y.
delete .draw_boxed_labelR.
delete .draw_boxed_labelG.
delete .draw_boxed_labelB.
}
`draw label whiteunder "\string" at .ll_x. .ll_y. [cm]'
Draw label for plot, located with lower-left corner at indicated
(x,y) position (specified in user units or in cm on the page).
Whiteout is used to clean up the area under the label. BUGS:
Cannot handle angled text; doesn't check for super/subscripts.
{
if {rpn "\.word4." "at" !=}
show "ERROR: Fifth word must be \"at\", not \"\.word4.\""
show traceback
quit
end if
new .x. .y. .space. .oldR. .oldG. .oldB.
.oldR. = ..red..
.oldG. = ..green..
.oldB. = ..blue..
if {rpn \.words. 7 ==}
.x. = {rpn \.word5. xusertocm}
.y. = {rpn \.word6. yusertocm}
else if {rpn \.words. 8 ==}
if {rpn "\.word7." "cm" !=}
show "ERROR: Require 7th word to be `cm'"
show traceback
quit
end if
.x. = \.word5.
.y. = \.word6.
else
show "ERROR: Require 7 or 8 words, but got \.words. words."
show traceback
quit
end if
# Coordinates now in cm. Next, white out a box under the
# text (and .space. centimetres beyond text), then draw label.
.space. = 0.1 # cm
set color white
draw box filled \
{rpn .x. .space. -} \
{rpn .y. .space. -} \
{rpn .x. "\.word3." width + .space. +} \
{rpn .y. "M" ascent + .space. + } cm
set color rgb .oldR. .oldG. .oldB.
draw label "\.word3." at .x. .y. cm
delete .x. .y. .space. .oldR. .oldG. .oldB.
}
`draw label for last curve "label"'
Draw a label for the last curve drawn, using the `..xlast..' and
`..ylast..' built-in variables.
{
if {rpn \.words. 6 ==}
draw label "\.word5." at\
{rpn ..xlast.. xusertocm "M" width 0.5 * +} \
{rpn ..ylast.. yusertocm "M" ascent 0.5 * -} cm
else
show "ERROR: Require 6 words, but got \.words. words."
show traceback
quit
end if
}
`draw label "\string" [centered|rightjustified] at .x. .y. [cm] [rotated .deg.]'
With no optional parameters, draw string at given location in USER
units.
With the `cm' keyword present, the location is in centimetres on
the page.
With the `rotated' keyword present, the angle in degrees from the
horizontal, measured positive in the counterclockwise direction, is
given.
With the keyword `centered' present, the text is centered at the
given location; similarly the keyword `rightjustified' makes the text
end at the given location.
{
extern "C" bool draw_labelCmd(void);
}
`draw line from .x0. .y0. to .x1. .y1. [cm]'
With no optional parameters, draw a line from (`.x0.', `.y0.') to
(`.x1.', `.y1'.), where coordinates are in user units. With the `cm'
keyword present, the coordinates are in centimetres on the page.
NOTE: This will not cause auto-drawing of axes.
{
extern "C" bool draw_line_from_toCmd(void);
}
`draw line legend "label" at .x. .y. [cm] [length .cm.]'
Draw a legend identifying the current line type with the given label.
A short horizontal line is drawn starting at the location (`.x.',
`.y.'), which may be specified in centimetres or, the default, in user
coordinates. The line length is normally 1 cm, but this length can be
set by the last option. The indicated label string is drawn 0.25 cm
to the right of the line.
SEE ALSO `draw symbol legend ...'.
EXAMPLE (of keeping track of the desired location for the legend)
.offset. = 1 # cm to offset legends
# ... get salinity data
set line width 0.25
draw curve
draw line legend "Salinity" at .x. .y.
# ... get temperature data
set line width 1.0
set dash 0.45 0.05
draw curve
.y. += .offset.
draw line legend "Temperature" at .x. .y.
{
# Check for too few or too many words.
if {rpn \.words. 7 >}
show "ERROR: Require 7 or more words, but got \.words. words."
show traceback
quit
end if
if {rpn \.words. 10 <}
show "ERROR: Require 10 or fewer words, but got \.words. words."
show traceback
quit
end if
.tmp_len. = 1 # cm
if {rpn \.words. 9 ==}
.tmp_len. = \.word8.
else if {rpn \.words. 10 ==}
.tmp_len. = \.word9.
end if
if {"\.word7." == "cm"}
# Position given in centimetres.
draw line from \
\.word5. \
\.word6. \
to \
{rpn \.word5. .tmp_len. +} \
\.word6. \
cm
draw label "\.word3." at\
{rpn \.word5. .tmp_len. + 0.25 +} \
{rpn \.word6. ..fontsize.. pttocm 0.4 * -} \
cm
else
# Position given in user units.
draw line from \
\.word5. \
\.word6. \
to \
{rpn \.word5. xusertocm .tmp_len. + xcmtouser} \
\.word6.
draw label "\.word3." at\
{rpn \.word5. xusertocm .tmp_len. + 0.25 + xcmtouser} \
{rpn \.word6. yusertocm ..fontsize.. pttocm 0.4 * - ycmtouser}
end if
}
`draw lines {vertically .left. .right. .inc.} | {horizontally .bottom. .top. .inc.}'
Draw several lines, either vertically or horizontally. This can be
useful in drawing gridlines for axes, etc. The following example shows
how to draw thin gray lines extending from the labelled tics on the x
axis (ie, at 0, 0.1, 0.2, ... 1):
set x axis 0 1 0.1 0.05
set y axis 10 20 10
draw axes
set graylevel 0.75
set line width 0.5
draw lines vertically 0 1 0.1
set graylevel black
{
extern "C" bool draw_linesCmd(void);
}
`draw patches .width. .height. [cm]'
With the optional `cm' keyword not present, draw column data z(x,y) as
gray patches according to the grayscale as set by most recent `set
image grayscale'. The patches are aligned along the horizontal, and
have the indicated size in user units.
With the optional keyword `cm' is present, the patch size is
specified in centimetres.
{
extern "C" bool draw_patchesCmd(void);
}
`draw polygon [filled] .x0. .y0. .x1. .y1. .x2. .y2. [...]'
Draw a polygon connecting the indicated points, specified in user
units. The last point is joined to the first by a line segment. At
least two points must be specified. If the `filled' keyword is
present, the polygon is filled with the current pen color.
{
extern "C" bool draw_polygonCmd(void);
}
`draw regression line [clipped]'
Fit a regression line to column data, of the form
`y = ..coeff0.. + ..coeff1.. * x'
(exporting `..coeff0..' and `..coeff1..' as global variables) and draw this line on the plot, for the range `..xleft.. <=
x <= ..xright..' on the x-axis.
Fit and draw a regression line to column data, of the form
`y = ..coeff0.. + ..coeff1.. * x'
(exporting `..coeff0..', `..coeff0_sig..', `..coeff1..' and
`..coeff1_sig..' as global variables; see `regress').
Normally, the line is not clipped to the axes frame, but it will be if the
keyword 'clipped' is given.
HINT: to label the plot you might do the following:
sprintf \label "y = %f + %f * x. R$^2$=%f" ..coeff0.. ..coeff1.. ..R2..
draw title "The linear fit is \label"
SEE ALSO: `regress'
{
regress y vs x
new .clipped. .xl. .xr. .yl. .yr.
if {rpn \.words. 4 ==}
if {rpn "\.word3." "clipped" ==}
.clipped. = 1
else
show "ERROR: 4-th word must be 'clipped', not '\.word3.'"
show traceback
quit
end if
else
.clipped. = 0
end if
.xl. = ..xleft..
.xr. = ..xright..
.yl. = {rpn .xl. ..coeff1.. * ..coeff0.. +}
.yr. = {rpn .xr. ..coeff1.. * ..coeff0.. +}
if .clipped.
if {rpn .yl. ..ybottom.. > }
.yl. = ..ybottom..
.xl. = {rpn .yl. ..coeff0.. - ..coeff1.. /}
end if
if {rpn .yl. ..ytop.. < }
.yl. = ..ytop..
.xl. = {rpn .yl. ..coeff0.. - ..coeff1.. /}
end if
if {rpn .yr. ..ytop.. < }
.yr. = ..ytop..
.xr. = {rpn .yr. ..coeff0.. - ..coeff1.. /}
end if
if {rpn .yr. ..ybottom.. > }
.yr. = ..ybottom..
.xr. = {rpn .yr. ..coeff0.. - ..coeff1.. /}
end if
end if
draw line from .xl. .yl. to .xr. .yr.
draw axes if needed
delete .clipped. .xl. .xr. .yl. .yr.
}
`draw symbol legend \symbol_name "label" at .x. .y. [cm]'
Draw indicated symbol at indicated location, with the indicated label
beside it. The label is drawn one M-space to the right of the symbol,
vertically centered on the indicated `.y.' location.
{
# Note kludge in y position, because ascent is inaccurate as
# of version 1.17 anyway
if {rpn \.words. 8 ==}
draw symbol \.word3. at \.word6. \.word7.
draw label "\.word4." at\
{rpn \.word6. xusertocm "M" width +} \
{rpn \.word7. yusertocm "M" ascent 0.7 * 2 / -} cm
else if {rpn \.words. 9 ==}
if {rpn "\.word8." "cm" ==}
draw symbol \.word3. at \.word6. \.word7. cm
draw label "\.word4." at \
{rpn \.word6. "M" width +} \
{rpn \.word7. "M" ascent 0.7 * 2 / -} cm
else
show "ERROR: Can't understand [\.word8.]; expecting [cm]"
show traceback
quit
end if
else
show "ERROR: Require 8 or 9 words, not \.words. as given."
show traceback
quit
end if
}
`draw symbol [.code.|\name [at .x. .y. [cm]] [graylevel z]|[color [hue z|.h.] [brightness z|.b.] [saturation z|.s.]]]'
The "at" form `draw symbol .code.|\name at .x. .y. [cm]' draws a
single symbol at the named location.
The non-"at" form draws symbols at the (x,y) data. If a z-column has
been read with `read columns', then it's value codes the symbol to
draw, according to the table below. (The value of z is first rounded
to the nearest integer.) If no z-column has been read, the symbol X
is drawn at each datum.
With the optional numerical/name code specified, then the symbol of
that number or name is drawn at each (x,y) datum, whether or not a
z-column exists. The numerical/name codes are:
# name description
-- ---- -----------
0 plus +
1 times x
2 box box
3 circ circle
4 diamond diamond
5 triangleup triangle with base at bottom
6 triangleright triangle with base at left
7 triangledown triangle with base at top
8 triangleleft triangle with base at right
9 asterisk *
10 star star of David
11 filledbox filled box
12 bullet filled circle
13 filleddiamond filled diamond
14 filledtriangleup filled triangleup
15 filledtriangleright filled triangleright
16 filledtriangledown filled triangledown
17 filledtriangleleft filled triangleleft
With the optional `graylevel z' fields specified, the graylevel is
given by the `z` column (0=black, 1=white).
With the optional `color' field specified, the color is specified,
either directly in the command (the `hue .h.' form) or in the z
column. For more information on color, refer to the `set color hsb
...' command.
Examples: both `draw symbol bullet color' and `draw symbol bullet
color hue z' draw bullets whose hue is given by the value in the z
column. The hue (or the color, in other words) blends smoothly across
the spectrum as the numerical value ranges from 0 to 1. The value
0yields red, 1/3 yields green, 2/3 yields blue, etc. If the
`brightness' and the `saturation' are not specified, they both default
to the value 1, which yields pure, bright colors.
Example: `draw symbol bullet color hue 0.333 brightness 1
saturation 1' draws green dots.
{
extern "C" bool draw_symbolCmd(void);
}
`draw time stamp [fontsize .points. [at .x_cm. .y_cm. cm [with angle .deg.]]]'
Draw the command-file name, PostScript file name, and time, at the top
of graph. Normally, the timestamp is drawn at the top of the page, in
a fontsize of 10 points. But the user can specify the fontsize, and
additionally the location (in cm) and additionally the angle measured
in degrees anticlockwise from the horizontal.
NOTE: If you want to have the plot in landscape mode on the page,
make sure that you do `set page landscape' before `draw time stamp.'
{
new .old_fontsize.
.old_fontsize. = ..fontsize..
if {rpn \.words. 3 ==}
# Just `draw time stamp'
set font size 10
if ..landscape..
draw label "Gri-\.version. \.wd./\.command_file. (\.time.)" at \
1.5 20.6 cm
else
draw label "Gri-\.version. \.wd./\.command_file. (\.time.)" at \
1.5 27.0 cm
end if
else if {rpn \.words. 5 ==}
# `draw time stamp fontsize .points.'
# 0 1 2 3 4
set font size \.word4.
if ..landscape..
draw label "Gri-\.version. \.wd./\.command_file. (\.time.)" at \
1.5 20.6 cm
else
draw label "Gri-\.version. \.wd./\.command_file. (\.time.)" at \
1.5 27.0 cm
end if
else if {rpn \.words. 9 ==}
# `draw time stamp fontsize .points. at .x_cm. .y_cm. cm'
# 0 1 2 3 4 5 6 7 8
set font size \.word4.
draw label "Gri-\.version. \.wd./\.command_file. (\.time.)" at \
\.word6. \.word7. cm
else if {rpn \.words. 12 ==}
# `draw time stamp fontsize .points. at .x_cm. .y_cm. cm with angle .deg.'
# 0 1 2 3 4 5 6 7 8 9 10 11
set font size \.word4.
draw label "Gri-\.version. \.wd./\.command_file. (\.time.)" at \
\.word6. \.word7. cm rotated \.word11.
else
show "ERROR: Require 3, 5, 9 or 12 words, but got \.words. words."
show traceback
quit
end if
set font size .old_fontsize.
delete .old_fontsize.
}
`draw title "\string"'
Draw the indicated string above the plot.
{
extern "C" bool draw_titleCmd(void);
}
`draw values [.dx. .dy.] [\format] [separation .xcm. .ycm.]'
Draw values of `z' column, at corresponding (`x', `y') locations. If
the `separation' keyword is present, the distance between successive
points is checked, and points are skipped unless the x and y
separations exceed than the indicated distances.
`draw values'
Draw the values of `z(x,y)', positioned 1/2 M-space to the right
of `(x,y)' and vertically centred on `y'. The values are written
in a good general format known as `%g', in C terminology.
`draw values %.2f'
Draw values of `z(x,y)' positioned as described above, but using
the indicated format string. This format string specifies that 2
numbers be used after the decimal place, and that floating point
should be used. See any C manual for format codes.
`draw values .dx. .dy.'
Print values of `z(x,y)' at indicated offset vector
(`.dx.',`.dy.'), measured in centimeters, from the values of
`(x,y)' at which the data are defined.
`draw values .dx. .dy. %.3f'
Print values of `z(x,y)' at indicated distance from `(x,y)',
indicated format.
{
extern "C" bool draw_valuesCmd(void);
}
`draw x axis [at bottom|top|{.y. [cm]} [lower|upper]]'
Draw an x axis, optionally at a specified location and of a specified
style.
`draw x axis'
Draw a lower x axis (ie, one with the numbers below the line) at
the bottom of the box defined by `set y axis'.
`draw x axis at bottom'
Draw a lower x axis (ie, one with the numbers below the line) at
the bottom of the box defined by `set y axis'.
`draw x axis at top'
Draw an upper x axis (ie, one with the numbers above the line) at
the top of the box defined by `set y axis' (or above any existing
stacked x axes there)
`draw x axis at .y.'
Draw a lower x axis at indicated value of `.y.'.
`draw x axis at .y. upper'
Draw an upper x axis at indicated value of .y.
{
extern "C" bool draw_x_axisCmd(void);
}
`draw x box plot at .y. [size .cm.]'
Draw Tukey box plots (which give a summary of histogram properties).
Box plots were invented by Tukey for eda (exploratory data analysis).
The centre of the box is the median. The box edges show the first
quartile (q1) and the third quartile (q3). The distance from q3 to q1
is called the inter-quartile range. The whiskers (i.e., the lines with
crosses at the end) extend from q1 and q3 to the furthest data points
which are still within a distance of 1.5 inter-quartile ranges from q1
and q3. Beyond the whiskers, all outliers are shown: open circles are
used for data within a distance of 3 inter-quartile ranges beyond q1 and
q3, and in closed circles beyond that.
`draw x box plot at .y.'
Draw Tukey's box plot, spreading in the x direction, centered at
y=`.y.' and of default width 0.5 cm.
`draw x box plot at .y. size .cm.'
Draw Tukey's box plot, spreading in the x direction, centered at
y=`.y.' and of width `.cm.' centimetres.
{
extern "C" bool draw_x_box_plotCmd(void);
}
`draw y axis [at left|right|{.x. cm} [left|right]]'
Draw a y axis, optionally at a specified location and of a specified
style.
`draw y axis'
Draw a left-hand-side y axis (ie, one with the numbers to the
left of the line) at left of box defined by `set x axis'
`draw y axis at left'
Draw a left-hand-side y axis (ie, one with the numbers to the
left of the line) at left of box defined by `set x axis'.
`draw y axis at right'
Draw a right-hand-side y axis (ie, one with the numbers to the
right of the line) at right of box defined by `set x axis'.
`draw y axis at .x.'
Draw a left-hand-side y axis (ie, one with the numbers to the
left of the line) at indicated value of `.x.'
`draw y axis at .x. right'
Draw a right-hand-side y axis (ie, one with the numbers to the
right of the line) at indicated value of `.x.'
{
extern "C" bool draw_y_axisCmd(void);
}
`draw y box plot at .x. [size .cm]'
Draw Tukey box plots (which give summary of histogram properties).
`draw y box plot at .x.'
Draw Tukey's box plot, spreading in the y direction, centered at
x=`.x.' and of default width 0.5 cm.
`draw y box plot at .x. size .cm.'
Draw Tukey's box plot, spreading in the y direction, centered at
x=`.x.' and of width `.cm.' centimetres.
{
extern "C" bool draw_y_box_plotCmd(void);
}
`draw zero line [horizontally|vertically]'
Draw lines corresponding to x=0 or y=0.
`draw zero line'
Draw line y=0 if it's within axes.
`draw zero line horizontally'
Draw line y=0 if it's within axes.
`draw zero line vertically'
Draw line x=0 if it's within axes.
{
extern "C" bool draw_zero_lineCmd(void);
}
`expecting version .n.'
Show a list of incompatibilites since the named version. This protects
you from being clobbered by changes made to Gri, since you will be
assured of being warned of these changes. For example, if you are doing
a lot of work with version 2.1.0, but want to move up to a higher
version, you would include the line `expecting version 2.0100' in all
your commandfiles. Once you are sure that your commandfile will not be
affected by the newer version, you should change the version that is
expected.
Note: As of October 1996, Gri version numbers have been in the form
`a.b.c'. Numerical version numbers are created by the formula
`a + b/100 + c/10000'. For example, version `2.1.0' has a numerical
value of `2.0100'.
{
extern "C" bool expectingCmd(void);
}
`filter column x|y|z|u|v recursively .a0. .a1. ... .b0. .b1. ...'
Filter indicated column, using a two-pass recursive filter. The
first pass runs from the start to the end, while the second pass
runs from the end to the start; in this way, the phase shift
inherent in this type of filter is removed entirely. The
coefficients are used in the following formula (demonstrated on
the `x' column):
x_new[i] = b[0] * x[i] + b[1] * x[i-1] + b[2] * x[i-2] + ...
- a[1] * x_new[i-1] - a[2] * x_new[i-2] - ...
Thus, for example, setting `a[i]' = 0 results in a simple
backwards-looking moving-average filter applied in two passes.
The real power of this type of filter, however, comes when
non-zero `a[i]' coefficients are given, thus adding recursion
(i.e., `x_new[i]' depends on `x_new[i-...]'). See any standard
reference on digital filters for an explanation. You might find
that the Matlab command `butter' an easy way to design filter
coefficients. Here are some examples:
# Filter x column with simple 2-point moving average.
filter column x recursively 0 0 0.5 0.5
# Use filter designed with the Matlab command butter(2,0.1),
# which creates a 2nd order lowpass butterworth filter, with a cutoff
# frequency of 0.1 (in units which have a frequency of 1 corresponding
# to one-half the sampling rate).
filter column x recursively 1 -1.561 0.6414 0.0201 0.0402 0.0201
{
extern "C" bool filter_columnCmd(void);
}
`filter grid rows|columns recursively .a0. .a1. ... .b0. .b1. ...'
Apply recursive filter (see `filter column ... recursively' for
meaning of this filter) to the individual rows or columns of the grid
data. For example, `filter grid columns recursively 0 0 .5 .5'
applies a 2-point moving average filter across the columns, smoothing
the grid in the x-direction.
{
extern "C" bool filter_gridCmd(void);
}
`filter image highpass|lowpass'
`filter image highpass'
Remove low-wavenumber components from image (ie, sharpen edges).
Do this by subtracting a Laplacian smoothed version of the image.
`filter image lowpass'
Remove high-wavenumber components from image (ie, smooth shapes).
Do this by Laplacian smoothing.
{
extern "C" bool filter_imageCmd(void);
}
`flip grid|image x|y'
Flip image by relecting it about a horizontal or vertical centerline.
`flip grid x'
Flip grid so right-hand side becomes left-hand side.
`flip grid y'
Flip grid so bottom side becomes top side.
`flip image x'
Flip image so right-hand side becomes left-hand side.
`flip image y'
Flip image so bottom side becomes top side.
{
extern "C" bool flipCmd(void);
}
`get env \result \environment_variable'
Get the value of an "environment variable" from the operating system,
and store the result in the indicated synonym. This makes most sense on
unix systems (hence the name, patterned after the unix command
`getenv'). This command can be useful in making gri programs resistant
to changes in data-file locations. Suppose, for example, there is a
file called `data', normally in a local directory called `Bravo'. The
line `open Bravo/data' will fail if the Bravo directory is moved. But
if the name of the datafile is stored in an environment variable,
`DIR_BRAVO' say, then the gri program will work no matter where the
Bravo data are moved, so long as an appropriate environment variable is
modified when the data are moved. Example:
get env \dir DIR_BRAVO
if \{rpn "\dir" "" ==}
show "Cannot determine location of the Bravo data, which should"
show "be stored in the environment-variable DIR_BRAVO. You should"
show "do something like"
show " export DIR_BRAVO='/users/dek/kelley/data/Bravo/'"
show "in your ~/.environment file"
quit
end if
open \dir/data
...
{
extern "C" bool get_envCmd(void);
}
`heal columns|{grid along x|y}'
The `heal' command heals over gaps in either columnar or gridded
data. This is done by linear interpolation across the missing-value
gaps.
* `heal columns'
Fill in missing values in x, y, z, ... columns, by linear
interpolation to neighboring valid data. All gaps in the data
will get replaced by a linear function of index which matches the
data at the indices just before and just after the gap. For
example, if the y data were like
111
3
-9
-9
-9
7
333
where `-9' is the missing-value code, then they would get replace
by
111
3
4
5
6
7
333
Notes: (1) This is done *independently* for all existing columns.
(2) Gaps at the start and end of the columns are not filled in.
* `heal grid along x'
Scan in the x direction, filling in missing values by linearly
interpolation. Since this uses the the x-grid, you must first
have done `read grid x' or `set x grid'.
* `heal grid along y'
Scan in the y direction, filling in missing values by linearly
interpolation. Since this uses the the y-grid, you must first
have done `read grid y' or `set y grid'.
{
extern "C" bool healCmd(void);
}
`help [*|command_name|{- topic}]'
Give help on a command or topic.
`help'
Print a general help message.
`help *'
Prints complete help info.
`help command_name'
Prints help on the command whose name begins with the string
`command_name'. The string may be several words long; e.g.
`help set' or `help set x axis'.
`help - topic_name'
The minus sign tells Gri that the string to follow it is a topic,
not a command. Topics Gri knows about are listed by the one-word
`help' request.
{
extern "C" bool helpCmd(void);
}
`if {[!] .flag.}|\flag|{{"string1" == "string2"}}'
Control program flow. The `if' block is ended with a line containing
`end if'. Optional `else' and `else if' blocks are allowed. Note
that RPN expressions are allowed, and a special form of string
comparison is allowed, as in the examples below.
if .flag.
# List of Gri commands to be done if .flag. is 1.
# This list may extend across any number of lines.
end if
If the variable `.flag.' is not equal to 0, do the code between the
`if' line and the `end if' line.
if .flag.
# Commands done if .flag. is 1
else
# Commands done if .flag. is 0
end if
If the variable `.flag.' is not equal to 0, do the code between the
`if' line and the `else' line. If `.flag.' is equal to 0, do the code
between the `else' line and the `end if' line.
if ! .flag.
# Commands done if .flag. is 0
end if
If the variable `.flag.' is equal to 0, do the code between the `if'
line and the `end if' line.
if \{rpn .flag. 10 <}
# Commands done if 10 is less than .flag.
end if
If the variable `.flag.' is less than 10, do the code between the `if'
line and the `end if' line.
if \smooth
# Commands done if \smooth is 1
else
# Commands done if \smooth is 0
end if
If the number stored in the synonym `\smooth' is not equal to 0, do
the code between the `if' line and the `else' line. If the synonym
stores a representation of a number not equal to zero, do the `else'
part. If the synonym contains text that does not decode to a number,
generate error message.
if \{"\item" == "Temperature"}
# Commands done if the synonym \item is equal to the
# indicated text string.
end if
If the synonym `\item' has the value `Temperature' stored in it, do
the indicated code.
if \{rpn "\item" "Temperature" ==}
# Commands done if the synonym \item is equal to the
# indicated text string.
end if
As above, but using the `rpn' calculator.
{
extern "C" bool null;
}
`ignore last .n.'
Ignores last `.n.' lines read by `read columns'.
{
extern "C" bool ignoreCmd(void);
}
`input \ps_filename [.xcm. .ycm. [.xmag. .ymag. [.rot_deg.]]]'
Input the named PostScript file directly into the Gri output PostScript
file. (If the filename has punctuation, insert it in double quotes,
e.g. `input "../thefile"'.) If no options are specified, the file is
input at normal scale, with normal margins. (Aside to PostScript
programmers: the named file is sandwiched between `gsave' and
`grestore' commands.) If `.xcm.' and `.ycm.' are specified, then the
origin is moved to the named location first. If, in addition, `.xmag.'
and `.ymag.' are specified, then these are used as scale factors after
translation. Finally, if `.rot_deg.' is specified in addition, then
the indicated counterclockwise rotation is applied after translation
and scaling. Hint: if the results look wrong, the first thing to do is
to think carefully about the order of the (translation, scaling,
rotation) operations.
{
extern "C" bool inputCmd(void);
}
`insert \filename'
Insert instructions in named file into current file. This is useful as
a way of sharing global information between several Gri programs. On
unix systems, if a full filename is specified (i.e., a filename
beginning with slash or period), then that particular file will be used.
For filenames beginning with a letter or number, though, Gri will search
for the file in the list of directories stored in your `GRIINPUTS'
environment variable, or in the list (`.', `/usr/local/lib/gri') if
that environment variable is not set.
{
extern "C" bool insertCmd(void);
}
`interpolate x|y grid to ...'
The forms are
interpolate x grid to .left. .right. .inc.|\{/.cols.}
interpolate y grid to .bottom. .top. .inc.|\{/.rows.}
Transform grid by interpolating between existing grid data, according to
a new x or y grid specified in the manner of `set x grid' and `set y
grid'. Note that the new grid is neccessarily regular, while the first
grid needn't have been. The data of the new grid are constructed by
interpolation, using the same interpolation algorithm as the `convert
grid to image' command.
{
extern "C" bool interpolateCmd(void);
}
`list \command-syntax'
List the source of a gri command. Often this is just the name of a C
function internal to gri (try `list list' for an example), but when
the command is written in the gri programming language the source will
be more understandable (try `list set panel').
{
extern "C" bool listCmd(void);
}
`ls [\file_specification]'
List files in current directory. (The current directory can be printed
by the gri command `pwd' and can be set by the gri command `cd'.) `ls
\file_specification' lists files in current directory which match the
file specification. Normal unix file specification options are
understood.
{
extern "C" bool lsCmd(void);
}
`mask image [to {uservalue .u.}|{imagevalue .i.}]'
Examine both the image and the mask pixel by pixel. For any pixels
which have a mask value of 1 (which indicates an invalid region of the
image), change the image value. If no `to' phrase is present, change
the image value to 0 in pixel units. If the `to uservalue .u.' phrase
is present, change the pixel to hold the imagevalue that corresponds to
this uservalue (see `set image range' command for a discussion of this
correspondance). If the `to imagevalue .i.', change the pixel to hold
that imagevalue (in range 0 to 255 inclusive for 8-bit images).
{
extern "C" bool maskCmd(void);
}
`new page'
Finish the present page, and start a new page. All settings (of
linewidth, axes, landscape/portrait, etc.) and data are retained
on the new page.
{
extern "C" bool new_pageCmd(void);
}
`new postscript file \name'
Finish the present Postscript file, and start a new page with
the given name. All settings (of linewidth, axes, landscape/portrait,
etc.) and data are retained on the new file.
{
extern "C" bool new_postscript_fileCmd(void);
}
`new .variable_name.|\synonym_name [.variable_name.|\synonym_name [...]]'
Set aside storage for new version of the named variable(s) and/or
synonym(s). Any number of variables and synonyms may be specified. If
a given variable/synonym already exists, this will create a new version
of it, and future assignments will be stored in this new version
*without* affecting the pre-existing version. If the variable/synonym
is `delete'ed, the new version is deleted, making the old, unaltered,
version accessible again.
This command is used mostly for temporary use, to prevent clashing
with existing values. Suppose you want to change the font size inside
a new command or an if block. Then you might do the following, where
the variable `.tmp.' is used to store the old font size. Note that the
use of the `new/delete' statements prevents the assignment to the
local version of the variable `.tmp.' from affecting the value known
outside the `if' block, if in fact `.tmp.' happened to exist outside
the block.
set font size 10
draw label "This is in fontsize 10, before modification" at 10 2 cm
if .want_title.
new .tmp. # Get storage
.tmp. = ..fontsize.. # Save old size
set font size 22 # Set new size
draw label "This is in fontsize 22" at 10 5 cm
set font size .tmp. # Restore old size
delete .tmp. # Clean up
end if
draw label "This is in fontsize 10, after modification" at 10 8 cm
{
extern "C" bool newCmd(void);
}
`open {\filename}|{"system command|"} {[binary [uchar|int|float|double|16bit]]}|{netCDF}'
Possibilities are:
`open \filename'
`open \filename binary [uchar|int|float|double]'
`open \filename netCDF'
`open "SYSTEM-COMMAND |" [binary [uchar|int|float|double]]'
The first three forms work on data files. Use double-quotes around
filenames with punctuation in them (e.g. `open "../data"'). Files may
be ascii (the default), binary or - on systems with the `netCDF'
libraries installed - in the `netCDF' format. The `SYSTEM-COMMAND'
form is used to work on a temporary file created by a system command.
Several binary file types are allowed. The keywords `uchar', etc,
can be used to specify the type of data in the file. If no keyword is
given, Gri assumes that images use `unsigned char' (8 bits), columns
use `float' (32 bits), and that grids use `float' (32 bits).
In the `SYSTEM-COMMAND' form, the indicated system command is
performed, with the output being inserted into a temporary file. Future
`read', `close', etc, commands apply to to this temporary file. (The
temporary file is automaticaly deleted by Gri, but if Gri fails for
some reason you should scan `/usr/tmp/' for files that you own.) For
example
open "cat a.dat | awk '\{$1, $2 * 22}' |"
read columns x y
gets awk to multiply the y column by 22. The ability to
use system commands in `open' statements lets you use familiar system
tools like `head', `sed', `awk', `perl', etc, to work on your data.
For example, if you store your data in compressed form, and do not wish
to have temporary files sitting around, you might wish to do something
like
open "zcat myfile.dat.Z | "
Files may be opened across the WWW (world-wide web). Here is a
replacement for example1.gri:
open "lynx -dump http://www.phys.ocean.dal.ca/~kelley/gri/examples/example1.dat | tail +2 |"
read columns x y
draw curve
draw title "Example 1"
Note: the `tail +2' removes the initial blank line that lynx
generates.
For complicated data manipulation, a system tool like `awk' or
`perl' is ideal. For example, suppose x and y data are stored in
Hour.minutesecond format, e.g. 12.2133 means hour 12, minute 21, second
33. Gri doesn't read HMS format, but gawk can be told to:
open "cat datafile.HMS | \
awk '\{ \
split($1, hms, \".\"); \
h = hms[1]; \
m = int(hms[2] / 100); \
s = hms[2] - 100 * m; \
x = h + m / 60 + s / 3600; \
split($2, hms, \".\"); \
h = hms[1]; \
m = int(hms[2] / 100); \
s = hms[2] - 100 * m; \
y = h + m / 60 + s / 3600; \
print(x,y) \
}' | "
read columns x y
{
extern "C" bool openCmd(void);
}
`postscript \string'
Write the indicated string to the PostScript output file, after
substitution of synonyms if there are any. Example:
\angle = "45"
\page_width = "8.5"
postscript gsave \page_width 72 mul 0 translate \angle rotate
# ... other code to do stuff
postscript grestore
Here is how to draw an image palette vertically instead of
horizontally:
\originX = "3" # cm
\originY = "10" # cm
\angle = "90" # degrees counterclockwise
postscript gsave \originX 28.35 mul \originY 28.35 mul translate \angle rotate
draw image palette box 0 0 10 1 # this is at user's origin
postscript grestore
NOTE: the `postscript' command is *very* dangerous, and should
normally only be used by developers. Most of the code concerning this
is in the file `doline.cc'; look for the string `postscriptCmd' to find
the relevant code.
{
extern "C" bool postscriptCmd(void);
}
`pwd'
Print current directory (which can be set by `cd').
{
extern "C" bool pwdCmd(void);
}
`query \synonym|.variable ["\prompt" [("\default"|.default)]]'
Ask the user for the value of a variable (number) or synonym (text
string). Gri recognizes the type of the item being asked for, either a
variable or synonym, by the presence of a dot or backslash in the second
word of the command line. If a prompt string is given (in quotes), then
this string is shown to the user. If a default is given (in
parentheses), then it will be displayed also, and if the user types
carriage-return, then that item will be assigned to the variable or
synonym. If the default has more than one item, then Gri considers this
a restrictive list of possibilities, and will demand that the answer be
in that list, going into an infinite query loop until an item from the
list (or carriage-return, meaning take first item) is found. The items
in the list are to be separated by spaces, not commas or any other
non-whitespace characters.
NOTE: The `-y' command-line option bypasses all query commands,
fooling Gri into thinking that the user typed a carriage-return to all
questions. Thus the defaults, if they exist, are selected.
{
extern "C" bool queryCmd(void);
}
`quit [.exit_status.]'
Exits the gri program. If an exit status (`.exit_status') is
specified, then Gri returns this value, rounded to the nearest integer,
as the "exit status" (a concept meaningful mostly in the unix
environment).
{
extern "C" bool quitCmd(void);
}
`read colornames from RGB \filename'
Read colornames from named file, which is in the X11 format. This
format has 4 or more columns, the first three giving the red, green
and blue values in the range 0 to 255, and the last columns giving the
colorname (which may have more than one word). You can create colors
yourself or read an X11 color file. In many cases you will want to
`read colornames from RGB "/usr/lib/X11/rgb.txt"'. Full filenames
must be used; the '~' syntax is not permitted. Once you have read in
a colorname table, the named colors may be used as builtin colors (see
also `set color'). To view the colors available on your particular
system, use the Unix command `xcolors' or `excolors'; to see the RGB
values for all colors on your system, use the `showrgb' Unix command.
To view the names and RGB values of the colors Gri knows, including
builtin ones and ones from `read colornames', use `show colornames'.
{
extern "C" bool read_colornamesCmd(void);
}
`read columns ...'
Read numbers into columns. These columns have predefined meanings and
names. For example, `read columns x y' instructs Gri to read data
into columns called `x' and `y'; it is these data that Gri will use if
you tell it to `draw curve'. Other columns are: `z', used for
contouring a function `z=z(x,y)'; `weight', used for weighting data
points; `u' and `v', used for arrow (vector) plots.
If the keyword `appending' is given as the last word on the `read
columns' line, then the new data will be appended to any existing
columnar data; otherwise they will overwrite any existing data.
* `read columns x y' Read `x' in column 1, `y' in column 2 until
blank-line found. Only the first tow numbers on each line will be
read; any extra numbers (or words) on the line will be ignored.
* `read columns * y * * x' Read `x' in column 5, `y' in column 2.
The `*' character is a spacer. It instructs Gri to skip the
first, third, and fourth words on the data line. These words need
not be numbers. This example illustrates a general mechanism of
using the `*' character to skip over unwanted items in the data
file. Note that there is no need to supply `*' characters for
trailing extraneous words; Gri will skip them anywary. Finally,
note that any order of `x' and `y' (and the other columns; see
below) is allowed.
* `read columns y=2 x=5' or `read columns x=5 y=2' As above; read
`x' in column 5 and `y' in column 2. The column number may be
specified in this manner for all the named column variables. No
spaces are allowed before or after the `=' sign. The first column
is called column 1. Whether this format is used or the `*' format
is a matter of choice, except that numbered format also permits
using a given number to fill several variables (e.g. `read columns
x=1 y=2 u=1 v=2').
* `read columns x="netCDF name" ...' If the file is a `netCDF' file,
opened by e.g. `open myfile.nc netCDF', then the `netCDF'
variables for the columns, e.g.
open latlon.nc netCDF
read columns x="longitude" y="latitude"
Note: the data *must* be stored as the `netCDF' "float" type.
* `read columns y' Read `y' in column 1. Since `x' is not read from
the file, it will be assigned the default values `x' = (0,1,2,
`..num_col_data..'); that is, it will have the same number of
elements as `y'.
* `read columns * y z * x' Read `x' in column 5, `y' in column 2,
and `z' in column 3. The `z' column is used for contouring.
* `read columns x y u v' Read `x' and `y' in first two columns, and
the "arrow" data `u' and `v' as third and fourth columns.
* `read columns .rows. x y' Read `.rows.' rows of column data.
NOTE FOR BINARY FILES: For ascii files, Gri will proceed to a new
line after it has read the items requested; it skips any words
appearing on the data line after the last object of interest. Thus
`read columns x y' will read the first two columns and ignore any other
columns that might be present. But for binary files, Gri has no way of
knowing how to "skip" to the next line (see `skip' command), so you
will have to flesh out the `read columns' command with as many spacers
as are present in your data. For example, if you have four numbers in
each data record and want to interpret the first two as `x' and `y',
you would use `read columns x y * *' to read the data.
RETURN VALUE: Sets `\.return_value'
to `N rows N non-missing N inside-clip-region'
{
extern "C" bool read_columnsCmd(void);
}
`read grid {x [.rows.|{="name"}]}|{y [.cols.]{="name"}}|{data {[spacers] [.rows. .cols.] [spacers] [bycolumns]}|{="name"}}'
"Read grid" commands read grid characteristics. (The "grid" is the
object that is contoured.)
For normal ascii or binary files, the commands to read the grid's
x-locations, y-locations and data are:
`read grid x [.rows.]'
`read grid y [.rows.]'
`read grid data [spacers] [.rows. .cols.] [spacers] [bycolumns]'
For `netCDF' files, the commands are as follows (note that it is not
possible to specify the number of data to read, nor to read the grid by
columns).
`read grid x = "variable name"'
`read grid y = "variable name"'
`read grid data = "variable name"'
The data *must* be stored as the `netCDF' "float" type. The ordering
of the y-grid data is the same as if they were read from a normal file:
the first number is considered to be at the top of the plot.
Details of the non-netCDF commands:
* `read grid x [.cols.]' Read the `x' locations of the grid points,
one number per line. If `.cols.' is supplied, then that many
values will be read; otherwise, reading will stop at end-of-file
or blank-line.
* `read grid y [.rows.]' As above, but for y grid; `.rows.' is the
number of rows. The first number to be read corresponds to the
location of the *top* edge of the grid. Thus, if you were to view
the column of numbers with a text editor, they would be oriented
the same way as the corresponding elements will appear on the page.
* `read grid data [.rows. .cols.]' Read data for a grid having
`.rows.' and `.cols.' columns. (If `.rows.' and `.cols.' are not
supplied, but the grid already exists, then those pre-existing
values are used. If they are specified here, then they are
checked for consistency with the pre-existing values if they
exist.) Gri will read `.rows.' lines, each containing `.cols.'
numbers. (Extra information in the file can be skipped; see
discussion of the `*' keyword below.) Gri will interpret the
first line it reads as the grid data corresponding to a value of y
equal to `y[.rows.]'. Thus, file should be arranged like this:
f(x[1], y[.rows.]) f(x[2], y[.rows.]) ... f(x[.cols.], y[.rows.])
.
.
.
f(x[1], y[3]) f(x[2], y[3]) ... f(x[.cols], y[3])
f(x[1], y[2]) f(x[2], y[2]) ... f(x[.cols], y[2])
f(x[1], y[1]) f(x[2], y[1]) ... f(x[.cols], y[1])
* `read grid data [.rows. .cols.] bycolumns' As above, but the
`bycolumns' keyword tells Gri to read the data one column at a
time, instead of one row at a time. Each line is expected to
contain `.rows.' numbers (as opposed to `.cols.' numbers, as in
the format where the `bycolumns' keyword is not present). (Extra
information in the file can be skipped; see discussion of the `*'
keyword below). The first line of the data file contains the
first column of the gridded data, corresponding to x equal to
`x[1]'). The file should look like this:
f(x[1], y[1]) f(x[1], y[2]) ... f(x[1], y[.cols.])
f(x[2], y[1]) f(x[2], y[2]) ... f(x[2], y[.cols.])
f(x[3], y[1]) f(x[3], y[2]) ... f(x[3], y[.cols.])
.
.
.
f(x[.rows.],y[1]) f(x[.rows], y[2]) ... f(x[.rows.], y[.cols.])
* `read grid data * * [.rows. .cols.]' As `read grid data .rows.
.cols.' except that the first two words on each line are skipped.
As usual, trailing extraneous numbers are also skipped.
The following example illustrates how to use these together.
read grid x 3 --- results in the grid locations
1
4 1 2 3 4 5
5 0 *-------------------------*--------*
10 | | |
read grid y 3 20 *-------------------------*--------*
0 30 | | |
20 40 *-------------------------*--------*
40
read grid data 3 3 --- fills in the grid as follows
9 1 2
3 4 5 1 2 3 4 5
6 7 8 0 9-------------------------1--------2
10 | | |
20 3-------------------------4--------5
30 | | |
40 6-------------------------7--------8
SEE ALSO:
`set x grid', `set y grid'
RETURN CODES:
`read grid x' sets `\.return_value to `N cols'
`read grid y' sets `\.return_value' to `N rows'
`read grid data' sets `\.return_value to `N rows N cols'
{
extern "C" bool read_gridCmd(void);
}
`read image colorscale [rgb|hsb]'
Read colorscale for image, from 256 lines each containing values for
Red, Green, and Blue (or Hue, Saturation and Brightness), separated by
whitespace. The values are expected to be in the range 0 to 1, and are
clipped to these limits if not.
For hints on how to create such an input file, see `read image
grayscale'. If the example given there has the following code instead,
open "awk 'BEGIN \{ \
for(i=0;i<256;i++) \{ \
print((i - 50)/50, 1, 1) \
} \
}' |"
read image colorscale hsb
then a full-color spectrum running from red at 10C to magenta at 15C is
achieved.
{
extern "C" bool read_image_colorscaleCmd(void);
}
`read image grayscale'
Read grayscale for image for image, from 256 lines each containing a
single value. The values are expected to be in the range 0 to 1, and
are clipped to these limits if not. For 8-bit images, Gri multiplies
these values by 255, and uses this list for the grayscale mapping. Such
a list is created by `write image grayscale'.
As an example, the code fragment
set image range 5 30.5
set image grayscale black 10 white 15
is equivalent to
set image range 5 30.5
open "awk 'BEGIN\{for(i=0;i<256;i++) print(1-(i-50)/50)}' |"
read image grayscale
close
because the image formula is
Temperature = 5C + 0.1C * pixelvalue
where the pixelvalue ranges from 0 to 255. Therefore, a temperature of
10C is a pixelvalue of 50, and 15C is 100. To get a grayscale ranging
between these values, therefore, we create a linear function which maps
the 50th pixelvalue into grayvalue 1, and the 100th pixelvalue into
grayvalue 0. That is what the awk line does; to see the actual numbers,
you could insert the line `write image grayscale to TMP' and look at the
file `TMP' (bear in mind that Gri will clip the values to the range 0
to 1).
Sometimes you will have a file, say named `map.dat', with RGB
numbers in the range 0-255, rather than 0-1 as Gri requires. To read
them, use the operating system to convert the numbers for you:
open "cat map.dat | awk '\{print(($1+$2+$3)/3/255)}' |"
read image grayscale
close
{
extern "C" bool read_image_grayscaleCmd(void);
}
`read image greyscale'
Alternate spelling of grayscale
{
extern "C" bool read_image_grayscaleCmd(void);
}
`read image mask rasterfile'
Read image mask. The mask is associated with the image read in by
the `read image' command in the following way. When computing image
histograms, Gri ignores any pixels in the image for which the
corresponding pixel in the mask is set to `1'. The image size is
specified in the rasterfile file itself, so it is not specified.
{
extern "C" bool read_image_mask_rasterfileCmd(void);
}
`read image mask .rows. .cols.'
Read image mask. The mask is associated with the image read in by the
` read image' command in the following way. When computing image
histograms, Gri ignores any pixels in the image for which the
corresponding pixel in the mask is set to `1'. The file must
contain `.rows.*.cols.' binary data. Pixel order is the same as
for images.
{
extern "C" bool read_image_maskCmd(void);
}
`read image pgm [box .ll_x. .ll_y. .ur_x. .ur_y.]'
Read image in pgm (portable graymap) format. The image range must have
previously have been set by `set image range'. The image width and
height are specified in the image file itself. Both ascii and binary
PGM formats are supported (that is, files with magic characters of P2
and P5).
When the `box' option is specified, the geometry of the image, in
user coordinates, is specified in terms of the cartesian coordinates of
the lower-left corner (`.ll_x.', `.ll_y.') and upper-right corner
(`.ur_x.', `.ur_y.'). If the `box' option is not specified, this
geometry can be specified with either `read grid x' or `set x grid',
plus either `read grid y' or `set y grid'.
{
extern "C" bool read_image_pgmCmd(void);
}
`read image rasterfile [box .ll_x. .ll_y. .ur_x. .ur_y.]'
Read image in Sun rasterfile format. The image range must have
previously have been set by `set image range'. The image width and
height are specified in the rasterfile file itself.
When the `box' option is specified, the geometry of the image, in
user coordinates, is specified in terms of the cartesian coordinates of
the lower-left corner (`.ll_x.', `.ll_y.') and upper-right corner
(`.ur_x.', `.ur_y.'). If the `box' option is not specified, this
geometry can be specified with either `read grid x' or `set x grid',
plus either `read grid y' or `set y grid'.
{
extern "C" bool read_image_rasterfileCmd(void);
}
`read image .rows. .cols. [box .ll_x. .ll_y. .ur_x. .ur_y.] [bycolumns]'
With no options specified (`read image .rows. .cols.'), read binary
data defining an `image'. The image range must have previously have
been set by `set image range'. The data are as written as "unsigned
char" format in C.
When the `box' option is specified, the geometry of the image, in
user coordinates, is specified in terms of the cartesian coordinates of
the lower-left corner (`.ll_x.', `.ll_y.') and upper-right corner
(`.ur_x.', `.ur_y.'). If the `box' option is not specified, this
geometry can be specified with either `read x grid' or `set x grid',
plus either `read y grid' or `set y grid'.
With the `bycolumns' keyword present, the image is read sweeping
from top-to-bottom, then left-to-right, instead of the user order.
{
extern "C" bool read_imageCmd(void);
}
`read from \filename'
Cause future `read' commands to read from the indicated file. If that
file is not open, an error message will result. Use `read from
\filename' to shuffle reading between several open files.
{
extern "C" bool read_from_filenameCmd(void);
}
`read line [raw] \synonym'
Read the next line of the datafile (or commandfile) and then store the
next line of datafile into the named synonym. Normally, comments are
removed from the line first, but if the keyword "raw" is present, then
comments are retained.
{
extern "C" bool read_lineCmd(void);
}
`read [raw] [* [*...]] \synonym|{.variable. [.variable. ...]}'
As the same command without the "raw" keyword, except that
in this instance comments are not removed from the line before
reading.
If the optional `raw' keyword is not present, comments are first
trimmed from the data line. If `raw' is present, however, any
comments are retained on the line.
{
extern "C" bool read_synonym_or_variableCmd(void);
}
`read [* [*...]] \synonym|{.variable. [.variable. ...]}'
Read whitespace-separated words from datafile, assigning to any number
of synonyms or variables as indicated. The token `*' indicates that
the word in the datafile should be skipped. As usual, the datafile may
be embedded in the commandfile.
If the input file is in the netCDF format, the indicated item will be
read. For example, `read \time:_MissingValue' reads the missing value
for the variable called `time' (you might follow this by a line like
`.missing. = \time:_MissingValue'). Similarly, `read \location' stores
the value of the global attribute called `location' into the variable
named `\location'.
{
extern "C" bool read_synonym_or_variableCmd(void);
}
`regress {y vs x [linear]}|{x vs y [linear]}'
Perform linear regression of `y' as a function of `x' or `x' as a
function of `y'.
* `regress y vs x' Linear regression of y vs x. Several quantities
are reported and also saved into builtin variables. The intercept
is defined as `..coeff0..', it's 95 percent confidence limit is
defined as `..coeff0_sig..'. Thus the confidence range is
`..coeff0..-..coeff0_sig..' to `..coeff0..+..coeff0_sig..'.
Similarly the slope and confidence limit are stored in
`..coeff1..' and `..coeff1_sig..'
The squared correlation coefficient is stored in `..R2..'.
Historical note' prior to version 2.1.15, a different meaning was
attached to `..coeff0_sig..' and `..coeff1_sig..'; they used
be defined as standard error, without having been multiplied by
the appropriate student-t coefficient.
* `regress x vs y' Linear regression of x vs y; for notation see
above.
* `regress y vs x linear' Linear regression of y vs x; for notation
see above.
* `regress x vs y linear' Linear regression of x vs y; for notation
see above.
SEE ALSO `draw regression line'
{
extern "C" bool regressCmd(void);
}
`reorder columns randomly|{ascending in x|y|z}|{descending in x|y|z}'
Reorder the columns in various ways.
In the `randomly' style, the column data are shuffled randomly by
index, retaining the correspondance between a given x and y. This is
useful with `draw symbol' using colored dots -- it prevents the
overpainting of one dot on another from biasing the color field to
values that happened to occur near the end of the column data. If you
prefer the overpainting to be done in random order, use this command to
reorder the columns randomly. The random number is selected using the
system `rand' call, with the seed being provided by the PID
(process ID) of the job.
The `ascending' and `descending' styles do what you'd expect.
{
extern "C" bool reorder_columnsCmd(void);
}
`rpnfunction \name "action"'
Create a new keyword for use in RPN expressions. Inside any RPN
expression which follows this line, the word `name' will be substituted
with the indicated replacement words.
For example, the following shows the definition and use of a
function which computes the sine of twice an angle, by multiplying
whatever is on the stack by `2', and then taking the sine of the result.
rpnfunction sin2 2 * sin
show "expect the number 1 to follow: " \{rpn 45 sin2}
NOTE: The replacement words will have any synonyms in them
translated first, unless they start with an underscore followed by a
double backslash. Similarly, variables are substituted unless they
start with an underscore. These exceptions are to allow the use of
the `defined' operator.
{
extern "C" bool rpnfunctionCmd(void);
}
`rescale'
Re-determine the scales for the x and y axes. Typically used after a
column math operation, when you want the new data to be auto-scaled.
(Note: this is not the default action after column mathematics, since
Gri lets users add offsets, etc, without altering the axes scales.)
{
extern "C" bool rescaleCmd(void);
}
`resize x for maps'
Resize the axes frame region in such a way that geographical objects
appear in correct proportions. This assumes that y is degrees latitude
and x is degrees latitude.
`resize x for maps'
Resize the plot width for maps, assuming that x represents
longitude and y represents latitude. Before using this, you must
have defined scales for both x and y, and a size for y (ie, you
must have done `set x axis ...', `set y axis ...' and `set y
size'); this command sets the x size, thus eliminating `set x
size.' The result is that, at the central latitude (y), a
centimetre on the page will correspond to an equal distance on
the earth, in both the north-south and east-west directions.
{
set x size {rpn ..ysize.. ..xright.. ..xleft.. - * \
..ybottom.. ..ytop.. - /\
..ybottom.. ..ytop.. + 2 / cos * abs}
}
`resize y for maps'
Resize the axes frame region in such a way that geographical objects
appear in correct proportions. This assumes that y is degrees latitude
and x is degrees latitude.
`resize y for maps'
Resize the plot height for maps, assuming that x represents
longitude and y represents latitude. Before using this, you must
have defined scales for both x and y, and a size for x (ie, you
must have done `set x axis ...', `set y axis ...' and `set x
size'); this command sets the y size, thus eliminating `set y
size.' The result is that, at the central latitude (y), a
centimetre on the page will correspond to an equal distance on
the earth, in both the north-south and east-west directions. SEE
ALSO `resize x for maps' command.
{
set y size {rpn ..xsize.. ..ybottom.. ..ytop.. - * \
..xright.. ..xleft.. - /\
..ybottom.. ..ytop.. + 2 / cos / abs}
}
`return'
Return early from a user-defined function or an `insert' file. Or, in
the main gri program, do the same thing as `quit'.
{
show "ERROR in `return' -- should not get here in gri.cmd"
show traceback
quit
}
`rewind [filename]'
Rewind a data-file to the beginning. If no filename is given, this
is done for the currently active file; otherwise the named
file is rewound.
{
extern "C" bool rewindCmd(void);
}
#* @param .style. = style of axes @default 0
`set axes style .style. | {offset [.dist_cm.]} | rectangular | none | default'
Tell Gri how you want axes to look.
`set axes style 0'
Set axes to be rectangular, with an x-y axes frame labelled at
the left and bottom.
`set axes style 1'
Set axes to be rectangular, with an x-y frame will be without
tics at the top right.
`set axes style 2'
Set axes to be rectangular, with an x-y frame without tics or
numbers on any side.
`set axes style offset [.dist_cm.]'
Set axes so that the actual x and y axes will be drawn with a
space separating them from the data area. The space, if not set
by the `.distance_cm.' option, will be equal to the current tic
size (see `set tic size'). This command can be used together
with any other `set axes style' command. It applies to both the
`draw axes' command and with any `draw x|y axis' command in which
the axis location is not explicitly given.
`set axes style rectangular'
Set axes to be rectangular, with an x-y axes frame labelled at
the left and bottom.
`set axes style none'
Tell gri not to bother drawing axes before drawing curves, etc.
`set axes style default'
Same as `set axes style 0', and with `offset' turned off.
{
extern "C" bool set_axes_styleCmd(void);
}
#* @param .size. arrowhead half-width @unit cm @default 0.2
`set arrow size .size.|{as .num. percent of length}|default'
Set the arrowsize (which is stored in the builtin variable
`..arrowsize..').
`set arrow size .size.'
Set the arrow size (ie, half-width of the arrowhead) to `.size.'
centimetres.
`set arrow size as .num. percent of length'
Set the arrow size to be the indicated percentage of arrow
length, as in "HWP" in the singles ads. (As a flag to this,
`..arrowsize..' is set to the negative of the fractional size
measured in percent.)
`set arrow size default'
Set the arrow size to the default of 0.2 cm.
{
extern "C" bool set_arrow_sizeCmd(void);
}
#* @param .type. 0 for 3-strokes, 1 for outline, 2 for filled swept-back @default 0
`set arrow type .which.'
Set type of arrow. `.which.'=0 yields the default arrows, drawn with
three line strokes, `.which.'=1 yields outline arrows, and `.which.'=2
yields swept-back filled arrows.
{
extern "C" bool set_arrow_typeCmd(void);
}
`set beep on|off'
The command `set beep on' makes gri beep on errors and `query'. `set
beep off' turns this beeping off.
{
extern "C" bool set_beepCmd(void);
}
`set bounding box .ll_x. .ll_y. .ur_x. .ur_y. [cm|pt]'
Set the PostScript bounding box for graph to indicated value. The
bounding box is used by some programs to determine the region of the
page on which marks have been made. For example, LaTeX uses the
bounding box to decide how to position figures in documents.
Normally, the bounding box is computed automatically (unless the
`-no_bounding_box' commandline option has been specified). But
if `set bounding box' is done, the automatically computed value
is ignored and the given box is used instead. Use this if Gri
makes mistakes in its automatic selection of bounding box.
The coordinates of the bounding box may be specified in (1) user
coordinates, as defined *at the moment* the command is executed, or (2)
in points on the page, measured from an origin at the lower-left (72
point per inch), or (3) in centimeters on the page. Which coordinate
system is used depends on the last keyword - use `pt' for points, `cm'
for centimeters, and nothing at all for user-units.
The most common use is in points, since that is how many other
application packages, e.g. LaTeX and dvips, specify the bounding box.
If the box is specified in the user units, the user units in effect
*at the moment* of executing the `set bounding box' command are used.
This must be born in mind if the coordinate system is changing during
the execution of the program, e.g. if margins are changing or the x
and y axes are changing. For this reason it often makes sense to put
this command at the end of the commandfile.
{
extern "C" bool set_bounding_boxCmd(void);
}
`set clip [postscript] {on [.xleft. .xright. .ybottom. .ytop.]}|off'
Control clipping of following drawing commands.
`set clip on'
Don't plot data outside axes.
`set clip on .xleft. .xright. .ybottom. .ytop.'
Don't plot data outside indicated box.
`set clip off'
Plot all data, whether in axes or not.
`set clip postscript on .xleft. .xright. .ybottom. .ytop.'
Turn PostScript clipping on. This will prevent *any* drawing
outside the named box. Note that it will also prevent axis
drawing, so the recommended procedure is something like
draw axes
set clip postscript on 10 20 0 1
draw curve
set clip postscript off
`set clip postscript off'
Turn PostScript clipping off. SEE ALSO: `set input data window'
command.
{
extern "C" bool set_clipCmd(void);
}
`set color \name|{rgb .red. .green. .blue.}|{hsb .hue. .saturation. .brightness.}'
Set the color of the "pen" used for drawing lines and text. Normally
lines and text are drawn in the same color, but the text color can be
specified independently if desired (see `set font color') this might
be useful to get contour lines of one color and labels of another.
In the `set colour \name' style, set the drawing color to the
indicated name, either from the builtin list (`white', `LightGray',
`darkslategray', `black', `red', `brown', `tan', `orange', `yellow',
`green', `ForestGreen', `cyan', `blue', `skyblue', `magenta'), or from
a list created by `read colornames'. In the latter case, if the
colorname has more than one word in it, use quotes, e.g. `set color
"ghost white"'.
In the `set colour rgb ...' style, set the individual color
components as indicated. The numbers `.red.', `.green.' and `.blue.'
range from 0 (for no contribution of that color component to the final
color) to 1 (for maximal contribution). Values less than 0 are
clipped to 0; values greater than 1 are clipped to 1. EXAMPLES:
set color rgb 0 0 0 # black
set color rgb 1 1 1 # white
set color rgb 1 0 0 # bright red
set color rgb 0.5 0 0 # dark red (only 50 percent)
set color rgb 0 1 0 # pure green
set color rgb 1 1 0 # yellow: red + green
In the `set colour hsb ...' style, set the individual color
components as indicated. The numbers `.hue.', `.saturation.' and
`.brightness.' range from 0 to 1. The color, represented by .hue.,
ranges from 0 for pure red, through 1/3 for pure green, and 2/3 for
pure blue, and back to 1 again for pure red. The purity of the color,
represented by .saturation., ranges from 0 (none of the hue is
visible) to 1 (the maximal amount is present). The brightness of the
color, represented by `.brightness.', ranges from 0 (black) to 1
(maximal brigntness). Values less than 0 are clipped to 0; values
greater than 1 are clipped to 1. EXAMPLES:
set color hsb 0 1 1 # pure, bright red
set color hsb 0 1 0.5 # half black, half red
set color hsb .333 1 1 # pure, bright green
{
extern "C" bool set_colorCmd(void);
}
`set colour \name|{rgb .red. .green. .blue.}|{hsb .hue. .saturation. .brightness.}'
Alternate spelling of 'color'.
{
extern "C" bool set_colorCmd(void);
}
`set colorname \\name {rgb .red. .green. .blue.}|{hsb .hue. .saturation. .brightness.}'
Create a colorname with the indicated color. The color components
range from 0 to 1, and will be clipped to these values if they are
outside this range. EXAMPLE (borrowing a color from /usr/lib/X11/rgb.txt):
set colorname peachpuff rgb 1 \{rpn 218 255 /} \{rpn 185 255 /}
draw box filled 2 2 3 3 cm
{
extern "C" bool set_colornameCmd(void);
}
#* @param \style for contour format @default %g
`set contour format \style|default'
Normally, Gri draws the numeric labels of contour using a format code
called `%g' in the "C" language. You may specify any other "long"
format using this command. For example, `set contour format %.1f'
tells Gri to use one decimal place in the numbers, and also to prefer
the "float" notation to the exponential notation. `set contour format
default' resets to the default `%f' format. You may use quotes around
the format if you need to, to make the item be a single word
(e.g. `set contour format "%.1f m/s"').
{
extern "C" bool set_contour_formatCmd(void);
}
`set contour label for lines exceeding .x. cm'
Make it so contour lines shorter than `.x.' centimeters will not be
labelled.
{
extern "C" bool set_contour_labelCmd(void);
}
`set contour label position {.start_cm. .between_cm.}|centered|default'
By default, contour labels are drawn at the location where contours
start (e.g., the boundary), and then at a uniform distance along the
contour. By default, this uniform distance is the average dimension of
the plotting area inside the axes. If `.start_cm.' and `.between_cm.'
are specified, the first label is drawn at a distance `.start_cm.'
from the start of the contour, and thereafter at a separation of
`.between_cm.'.
If the `centered' option is used, then the contour labels are
centered along the length of the line.
{
extern "C" bool set_contour_labelCmd(void);
}
`set contour labels rotated|horizontal|whiteunder|nowhiteunder'
The first two options control whether contour labels are rotated to line
up with the contour lines, or whether they are horizontal (the default).
The second two options control whether the region under contour
labels is whited out before drawing the label. The default is
`whiteunder', which has the visual effect of the label having been
drawn on a piece of paper and then pasted on. This can look jarring
when the material under the contour is an image. When `nowhiteunder'
is specified, the contour line is broken to make space for the text,
but no whiting out is done.
{
extern "C" bool set_contour_labelsCmd(void);
}
#* @param .type. style of dash to use (range 0 to 15) @default 2 -> 0.4 cm dashes and 0.1 cm blanks
`set dash [.type.|{.dash_cm. .blank_cm. ...}|off]'
Control dash-style for following `draw curve' and `draw line' commands.
* `set dash' Set to dashed line (0.4cm dashes, 0.1cm blanks).
* `set dash .type.' Set to indicated pre-defined dashed line, according
to table:
.n. dash/cm blank/cm
0 - - ... (Solid line)
1 0.2 0.1
2 0.4 0.1
3 0.6 0.1
4 0.8 0.1
5 1.0 0.1
10 w w
11 w 2w
12 w 3w
13 w 4w
14 w 5w
15 w 6w
Where `w' is written, it indicates the current linewidth. Thus,
types 10 through 15 give square-dotted lines.
* `set dash .dash_cm. .blank_cm. .dash_cm. .blank_cm. ...' Set to
indicated dashed line. The series of lengths `.dash_cm.' and
`.blank_cm.' give the lengths of dash and blank portions (measured
in centimeters). Any number of dash/blank lengths may be given.
For example, `set dash 0.5 0.1 0.1 0.1' looks good.
* `set dash off' Turn dashing off, setting to a solid line.
{
extern "C" bool set_dashCmd(void);
}
`set environment'
Set environment (graylevel, axis length, etc) so that following
plotting commands will make use of anything set by either a `set'
command or by direct manipulation of builtin variables like
`..xsize..', etc. NOTE: this should *only* be done by developers.
{
extern "C" bool set_environmentCmd(void);
}
`set error action to core dump'
Make Gri dump core when any error is found, to facilitate debugging.
{
extern "C" bool set_error_actionCmd(void);
}
`set flag \name [off]'
Set the indicated flag to YES. The name of the flag is contained in a
single word, e.g. `set flag dan_28sep_test'. The action of the flags
may change with time and is undocumented. This command is provided to
enable selected users (e.g., the developer himself) to use test
features of Gri before they are frozen into a fixed syntax and action.
The keyword `off' turns the indicated flag off. NOTE: this should
*only* be done by developers.
FLAG DATE ACTION
jinyu1 29sep94 'convert columns to grid' outputs (x,y,z,z_predicted)
emulate_gre 9jun97 'E' format on axes yields scientific notation
kelley1 17jun97 for kelley only - quit contour trace if hit nonlegit
kelley2 17jun97 for kelley only - print out tons of info as trace contour
{
extern "C" bool set_flagCmd(void);
}
`set font color \name|{rgb .red. .green. .blue.}|{hsb .hue. .saturation. .brightness.}'
The syntax is the same as `set color', except that this applies to
text only. By default, text is drawn in the same color as lines, so
text color is changed as line color is changed (e.g. by using the `set
color' or `set graylevel' commands)). However, once `set font color'
is used in a Gri program, the font thereafter maintains a separate
color from the lines.
{
extern "C" bool set_font_colorCmd(void);
}
`set font colour \name|{rgb .red. .green. .blue.}|{hsb .hue. .saturation. .brightness.}'
Alternate spelling of 'color'.
{
extern "C" bool set_font_colorCmd(void);
}
`set font encoding PostscriptStandard | isolatin1'
Permits one to control the so-called ``font encoding'' used in text.
The default font encoding is ISO-Latin-1, which is best for English and
other European languages.
If the so-called `Postscript Standard'' font encoding is required, this command
permits changing the encoding.
Note: few users will ever need this command. If you don't even know
what ``font encoding'' is about, ignore this command!
{
extern "C" bool set_font_encodingCmd(void);
}
#* @param .size. of font @unit point @default 12 @variable ..fontsize..
`set font size {.size. [cm]}|default'
Set the size of the font for drawing of text.
`set font size .size.'
Set font size to `.size.' points. (A point is 1/72 of an inch, or
1/28 of a centimetre.)
`set font size .size. cm'
Set font size to `.size.' centimetres.
`set font size default'
Set font size to default = 12 pts.
{
extern "C" bool set_font_sizeCmd(void);
}
#* @param \fontname of font @default Helvetica
`set font to \fontname'
Set font to named style. Note that the backslash is *not* to be
written, but here merely means that this word has several alternatives.
For example, one might say `set font to Courier'. The allowed
fontnames are: `Courier', a typewriter font; `Helvetica', a sans-serif
font commonly used in drafting scientific graphs; `HelveticaBold', a
bold version of Helvetica; `Times' (also called `TimesRoman'), a font
used in most newspapers; `Palatino' (also called `PalatinoRoman'),
similar to Times, but somewhat more elegant; `ZapfChancery', a font
akin to the TeX caligraphic font; `Symbol', included for completeness,
is a mathematical font in which "a" becomes $\alpha$ of the math mode,
etc. For reference on these fonts see any book on PostScript. The
default font is `Helvetica'.
{
extern "C" bool set_font_toCmd(void);
}
#* @param .brightness. of ink with 0 for black and 1 for white @default 0=black
`set graylevel .brightness.|white|black'
Set graylevel for lines to indicated numerical value between 0=black and
1=white, or to the named color.
Note: if your diagram is to be reproduced by a journal, it is
unlikely that the reproduction will be able to distinguish between any
two graylevels which differ by less than 0.2. Also, graylevels less
than 0.2 may appear as pure black, while those of 0.8 or more may
appear as pure white. These guidelines are as specified by American
Geophysical Union (publishers of J. Geophysical Res.), as of 1997.
{
extern "C" bool set_graylevelCmd(void);
}
`set greylevel .brightness.|white|black'
Alternate spelling of graylevel.
{
extern "C" bool set_graylevelCmd(void);
}
`set grid missing {above|below .intercept. .slope.}|{inside curve}'
The style
`set grid missing above|below .intercept. .slope'
sets grid to missing value for all points above/below the line defined
by
y = .intercept. + .slope. * x
The style
`set grid missing inside curve'
sets the grid to the missing value throughout an area described by the
curve last read in with `read columns'. This is useful for e.g.
excluding land areas while contouring ocean properties. The curve may
contain several "islands," each tracing (clockwise) a region inside of
which the grid is to considered missing. If the first point in an
island doesn't match the last, then an imaginary line is assumed which
connects them. Multiple islands may be separated by missing-value
codes.
{
extern "C" bool set_grid_missingCmd(void);
}
`set ignore initial newline [off]'
Make Gri ignore a newline if it occurs as the first character of the
next data file. This is used for files made by FORTRAN programs on
VAX/VMS computers.
{
extern "C" bool set_ignore_initial_newlineCmd(void);
}
`set ignore error eof'
Stop Gri from considering that to encounter an end of file in future
`read' commands consitutes an error; Gri will simply warn about future
EOFs.
{
extern "C" bool set_ignoreCmd(void);
}
`set image colorscale ...'
set image colorscale hsb .h. .s. .b. .im_value. hsb .h. .s. .b. .im_value. [increment .im_value.]
set image colorscale rgb .r. .g. .b. .im_value. rgb .r. .g. .b. .im_value. [increment .im_value.]
set image colorscale \name .im_value. \name .im_value. [increment .im_value.]
Set colorscale mapping for image, using HSB (hue, saturation,
brightness) specification, RGB (red, green, blue) color specification,
or named colors. The image range must have previously have been set by
`set image range', so that the `.im_value.' values will have meaning.
Two pairs of (color, image-value) are given, and possibly an increment.
Normally the colors are smoothly blended between the endpoints, but if
an increment is supplied, the colors are quantized. The HSB method
allows creation of spectral palettes, while the other two methods
create simple blending between the two endpoints.
EG: To get a spectrum ranging between pure red (H=0) for image value
of -10.0, and pure blue (H=2/3) for image value of 10.0, do this:
set image colorscale hsb 0 1 1 -10.0 hsb .66666 1 1 10.0
EG: To get a scale running from pure red (at image-value 10.0) into
pure blue (at image-value 25.1), but with the colors blending
intuitively in between (i.e., blending as paint might), use `rgb' color
specification, as follows:
set image colorscale rgb 1 0 0 10.0 rgb 0 0 1 25.1
EG: To get a quantized blend between the X11 colors `skyblue' at
image value of 0 and `tan' at image value of 20, and with steps at
image values incrementing by 5, do this:
set image colorscale skyblue 0 tan 20 increment 5
Note that the traversal is through RGB space, so it is intuitive,
not spectral. See `set color' for a list of X11 colors known to Gri.
{
extern "C" bool set_image_colorscaleCmd(void);
}
`set image colourscale ...'
Alternate spelling of colorscale.
{
extern "C" bool set_image_colorscaleCmd(void);
}
`set image grayscale using histogram [black .bl. white .wh.]'
Create a grayscale mapping using linearized cumulative histogram
enhancement. The image range must have previously have been set by
`set image range'.
This creates maximal contrast in each range of graylevels, and is
useful for tracing subtle features between different images (for
example, it makes it easier to trace fronts between successive satellite
images). The entire histogram is expanded, from the smallest value in
the image to the largest.
With no options specified, the histogram is done from 0 in the image
to 255 in the image. If the black/white options are specified, the
histogram is done between these values.
{
extern "C" bool set_image_grayscale_using_histogram(void);
}
`set image greyscale using histogram [black .bl. white .wh.]'
Alternate spelling of grayscale
{
extern "C" bool set_image_grayscale_using_histogramCmd(void);
}
`set image grayscale [black .bl. white .wh. [increment .inc.]]'
With no optional parameters, create a grayscale mapping for the current
image, scaling it from black for the mininum value in the image to white
for the maximum value. The image range must have previously have been
set by `set image range'.
The optional parameters `.wh.' and `.bl.' specify the values to be
drawn in white and black in the image, with smooth linear blending in
between.
Normally the blending from white to black is smooth (linear), but if
the additional optional parameter `.inc.' is specified, the blending is
quantized, jumping to darker values at (`.wh.' + `.inc.'), (`.wh.' + 2*
`.inc.'), etc. (The sign of `.inc.' will be altered, if necessary, to
ensure that (`.wh.' + `.inc.') is between `.wh.' and `.inc.'.) The
colour switches to pure white at the value `.wh.', and remains pure
white everywhere on the "white" side of this value. Similarly, the
transition to pure black occurs at the value `.bl.'. In other words,
neither pure white nor pure black is present inside the interval from
`.wh.' to `.bl.'. Therefore, when drawing grayscales with the `draw
image palette' command, you might want to extend the range by one
increment so as to get an example of both pure white and pure black.
.w. = 0
.b. = 1
.i. = 0.2
set image grayscale white .w. black .b. increment .i.
draw image palette left \{rpn .w. .i. -} right \{rpn .b. .i. +} increment .i.
{
extern "C" bool set_image_grayscaleCmd(void);
}
`set image greyscale [black .bl. white .wh. [increment .inc.]]'
Alternate spelling of grayscale.
{
extern "C" bool set_image_grayscaleCmd(void);
}
`set image missing value color to white|black|{graylevel .brightness.}{rgb .red. .green. .blue.}'
Set the color of "missing" pixels (white by default). The image range
must have previously have been set by `set image range'. Pixels with
missing values can result from creating images from grids which have
missing values; see the `convert grid to image' command. The
`.brightness.' parameter in the `graylevel' style ranges from 0 for
black to 1 for white. The `rgb' parameter allows specification in colour.
{
extern "C" bool set_image_missingCmd(void);
}
`set image missing value colour to white|black|{graylevel .brightness.}'
Alternate spelling of color.
{
extern "C" bool set_image_missingCmd(void);
}
`set image range .min_value. .max_value.'
Specify maximum possible range of values that images can hold, in
user units. Gri needs to know this because it stores images in a
limited format capable of holding only 256 distinct values. Unlike
some other programs, Gri encourages (forces) the user to specify things
in terms of user-units, not image-units. This has the advantage of
working regardless of the number of bits per pixel. Thus, for example,
`set image grayscale', `set image colorscale', `draw image grayscale',
etc, all use *user* units.
When an image is created by `convert grid to image', values outside
the range spanned by `.0value.' and `.255value.' are clipped. (There
is no need, however, for `.0value.' to be less than `.255value.'.)
This clipping discards information, so make sure the range you give is
larger than the range of data in the grid.
EXAMPLE: consider a satellite image in which an internal value of 0
is meant to correspond to 0 degrees Celsius, and an internal value of
255 corresponds to 25.5 degrees. (This is a common scale.) Then Gri
command `set image range 0 25.5' would establish the required range.
If this range were combined with a linear grayscale mapping (see `set
image grayscale'), the resultant granularity in the internal
representation of the user values would be (25.5-0)/255 or 0.1 degrees
Celsius; temperature variations from pixel to pixel which were less than
0.1 degrees would be lost.
All other image commands *require* that the range has been set.
Thus, all these commands fail unless `set image range' has been done:
`draw image', `draw image palette', `read image', `convert grid to
image', `set image grayscale', and `set image colorscale'.
NOTE: If a range already exists when `set image range' is used, then
the settings are altered. Thoughtless usage can therefore lead to
confusing results. (The situation is like setting an axis scale,
plotting a curve with no axes, then altering the scale and plotting the
new axes. It's legal but not necessarily smart.)
{
extern "C" bool set_image_rangeCmd(void);
}
`set input data window x|y {.min. .max.}|off'
Create a data window for following `read' statements.
`set input data window x .min. .max.'
For future reading commands, ignore all data with x < `.min.' or
x > `.max.' The data not in the interval will not be read in at all.
This will hold until `set data window x off' is done, in which
case all data will be read in.
`set input data window x off'
Return to normal conditions, in which all data are read in.
`set input data window y .min. .max.'
Analogous to command for x.
`set input data window y off'
Analagous to command for x.
EXAMPLE: To set the input data window as the current x axis plus a
border of 5 centimetres to left and right, do the following:
set input data window x \{rpn ..xleft.. xusertocm 5 - xcmtouser} \
\{rpn ..xright.. xusertocm 5 + xcmtouser}
SEE ALSO `set clip' command.
{
extern "C" bool set_input_data_windowCmd(void);
}
`set input data separator TAB|default'
Set the separator between data items. The `default' method is to
assume that data items are separated by one or more spaces or tabs,
and also to ignore any spaces or tabs at the start of a data line.
In the TAB method the data are assumed to be separated by a SINGLE tab
character. (Multiple tabs will result in null values being assigned
to items -- almost certainly not what you want!) Also, initial spaces
and tabs on lines are NOT skipped.
Use the TAB method only after thinking carefully about the above,
since the assignment of null values is problematic.
{
extern "C" bool set_input_data_separatorCmd(void);
}
`set line cap .type.'
Set the type of ends (caps) of lines. Use `.type.' of value 0 for
square ends, cut off precisely at the end of line, or 1 for round ends
which overhang half the line width, or 2 for square ends which overhang
half the line width. The selected style is used for the ends of line
segments, as well as at corners. In PostScript parlance, therefore,
this command sets both the linecap and the linejoin parameters.
This command only applies to lines drawn with `draw curve', `draw
line' and `draw polygon'. Axes are always drawn with a line cap of 0.
{
extern "C" bool set_line_capCmd(void);
}
`set line join .type.'
Set the type of intersection of lines. Use `.type.' of value 0 for
mitered joins (pointy ends that may extend beyond the data points), a
value of 1 for rounded ends (the default), or a value of 2 for
bevelled (squared-off) ends. See the `setlinejoin' command in any
text on the PostScript language for more information.
This command only applies to lines drawn with `draw curve', `draw
line' and `draw polygon'. Axes are always drawn with a line join of 0.
{
extern "C" bool set_line_joinCmd(void);
}
#* @param .width_pt. @unit point @default 0.709 @variable ..linewidth..
`set line width [axis|symbol|all] .width_pt.|{rapidograph \name}|default'
Set the width of lines used to draw curves (default), axes, symbols, or
all of the above. The width may be set to a value specified in points
(conversion: 72 pt = 1 inch), to a named rapidograph width, or to the
default value. The initial default values are: 0.709pt (or rapidograph
3x0) for curves; 0.369pt (or rapidograph 6x0) for axes; 0.369pt (or
rapidograph 6x0) for symbols.
The rapidograph settings match the standard set of widths used in
technical fountain pens. The table below gives width names along with
the width in points and centimetres, as given in the specifications
supplied with Rapidograph technical fountain pens. Names marked by the
symbol `*' are in sequence increasing by the factor root(2). Texts on
technical drawing often suggest using linewidths in the ratio of 2 or
root(2). On many printers, the variation in width from root(2) increase
is too subtle to see, so the factor-of-2 rule may be preferable. To get
sizes in a sequence doubling in width, pick from the list (`6x0',
`3x0', `1', `3.5' `7'). To get a sequence increasing in width by
root(2), pick from the list (`6x0', `4x0', `3x0', `0', `1', `2.5',
`3.5', `6', `7'). The eye can distinguish curves with linewidths
differing by a factor of root(2) if the image is of high quality, but a
factor of 2 is usually better. Similarly, for overhead projections and
projected slides, one would do well to use linewidths differing by a
factor of 4.
This is the list of `rapidograph' linewidths:
Name pt cm
==== ===== =====
* 6x0 0.369 0.013
* 4x0 0.510 0.018
* 3x0 0.709 0.025
00 0.850 0.03
* 0 0.992 0.035
* 1 1.417 0.05
2 1.701 0.06
* 2.5 1.984 0.07
3 2.268 0.08
* 3.5 2.835 0.1
4 3.402 0.12
* 6 3.969 0.14
* 7 5.669 0.2
{
extern "C" bool set_line_widthCmd(void);
}
#* @param .value. to be considered missing @default 1.0e22 @variable ..missingvalue..
`set missing value .value.'
Set missing-value code (stored in the builtin variable
`..missingvalue..' and builtin synonym `\.missingvalue..') to
`.value.', which mean that data within 0.1 percent of this value are
ignored. The initial default is 1.0e22.
{
extern "C" bool set_missing_valueCmd(void);
}
`set postscript filename "\string"'
Set name of PostScript file, over-riding the present name.
{
extern "C" bool set_postscript_filenameCmd(void);
}
`set page size letter|legal|folio|tabloid|A0|A1|A2|A3|A4|A5'
Prevent bounding box from extending outside the indicated page domain.
{
extern "C" bool set_page_sizeCmd(void);
}
`set page portrait|landscape|{factor .mag.}|{translate .xcm. .ycm.}'
Control orientation or scaling of what is drawn on the paper.
* `set page portrait' Print graph normally (default).
* `set page landscape' Print graph sideways.
* `set page factor .mag.' Scale everything to be drawn on the paper
by the indicated magnification factor. This *must* be called
before any drawing commands.
* `set page translate .xcm. .ycm.' Translate everything to be drawn
on the paper by the indicated x/y distances. This *must* be
called before any drawing commands.
*Note*: The order of the factor/translate commands matters, so you
may need to experiment. For example,
set page translate 2 1
set page factor 0.5
moves anything that would have been drawn at the lower-left corner of
the paper onto the point 2cm from the left side and 1cm from the bottom
side of the paper, and then applies the multiplication factor.
Reversing the order gives quite different results. PostScript gurus
should note that the following two commands are inserted into the
PostScript file:
56.900000 28.450000 translate
0.500000 0.500000 scale
{
extern "C" bool set_pageCmd(void);
}
`set panel .row. .col.'
Establish geometry for the panel in the indicated row and column. The
bottom row has .row. = 1, and the leftmost column has .col. = 1. This
must be used only after using `set panels .row. .col. .dx_cm. .dy_cm.'
{
if {rpn \.words. 4 !=}
show "ERROR: `\.proper_usage.' needs 3 words"
quit 1
end if
new .row. .col.
.row. = \.word2.
.col. = \.word3.
set x margin {rpn .col. 1 - .panel_xsize. .panel_dx. + * .panel_xmargin. +}
set y margin {rpn .row. 1 - .panel_ysize. .panel_dy. + * .panel_ymargin. +}
set x size .panel_xsize.
set y size .panel_ysize.
delete .row. .col.
}
`set panels .rows. .cols. [.dx_cm. .dy_cm.]'
Set up for multipanel plots, with spacing .dx_cm. between the columns
and .dy_cm. between the rows. If the spacings are not supplied, 2cm
is used. The panels fill the rectangle which would otherwise contain
the single axis frame, as set by `set x size' and `set x margin', etc.
The global variables .panel_dx., .panel_dy., .panel_xmargin.,
.panel_ymargin., .panel_xsize., and .panel_ysize are created, to be used
by later calls to `set panel'.
EXAMPLE
# Draw 2 panels across, 3 up the page.
# The Panel interiors will be in region cornered
# by (2,2), (12,22) cm
set x margin 2
set y margin 2
set x size 10
set y size 20
set panels 2 3
# Create dummy scale
set x axis 0 1
set y axis 0 1
# Draw blank axes
set panel 1 1
draw axes
set panel 1 2
draw axes
set panel 1 3
draw axes
set panel 2 1
draw axes
set panel 2 2
draw axes
set panel 2 3
draw axes
SEE ALSO `set panel .row. .col.'
{
# creates globals
# .panel_dx. .panel_dy.
# .panel_xmargin. .panel_ymargin.
# .panel_xsize. .panel_ysize.
if {rpn \.words. 4 ==}
.panel_dx. = 2
.panel_dy. = 2
else if {rpn \.words. 6 ==}
.panel_dx. = \.word4.
.panel_dy. = \.word5.
else
show "ERROR: `\.proper_usage.' needs 5 words"
quit 1
end if
new .rows. .cols. # local storage
.rows. = \.word2.
.cols. = \.word3.
if {rpn .panel_dx. 0 >}
show "ERROR: `\.proper_usage.' needs .dx. to be non-negative"
quit 1
end if
if {rpn .panel_dy. 0 >}
show "ERROR: `\.proper_usage.' needs .dy. to be non-negative"
quit 1
end if
.panel_xmargin. = ..xmargin..
.panel_ymargin. = ..ymargin..
.panel_xsize. = {rpn ..xsize.. .panel_dx. .cols. 1 - * - .cols. /}
.panel_ysize. = {rpn ..ysize.. .panel_dy. .rows. 1 - * - .rows. /}
delete .rows. .cols.
}
#* @param \path for data or command files @default "."
`set path to "\path"|default for data|commands'
Set directory path for finding data files or command files.
The default is ".", the current directory.
{
extern "C" bool set_pathCmd(void);
}
#* @param .diameter_cm. diameter size of symbols @unit cm @default 0.1
`set symbol size .diameter_cm.|default'
Control the size (diameter) of symbols drawn by `draw symbol' command.
`set symbol size .diameter_cm.'
Make symbol size (diameter) be `.diameter_cm.' centimeters.
`set symbol size default'
Set to default diameter of 0.1 cm.
{
extern "C" bool set_symbol_sizeCmd(void);
}
#* @param $.size. of axes tics @unit cm @default 0.2
`set tic size .size.|default'
Control size of tics on axes.
`set tic size .size.'
Set tic size to `.size.' centimetres.
`set tic size default'
Set tic size to default of 0.2 cm
{
extern "C" bool set_tic_sizeCmd(void);
}
`set tics in|out'
Make axis tics point inward or outward. The default is outward.
{
extern "C" bool set_ticsCmd(void);
}
`set trace [on|off]'
Control printing of command lines as they are processed.
`set trace'
Make Gri print command lines as they are processed.
`set trace on'
Same as `set trace'.
`set trace off'
Prevent printing command lines (default).
{
extern "C" bool set_traceCmd(void);
}
`set u scale .cm_per_unit.|{as x}'
Set scale for x-component of arrows.
`set u scale .cm_per_unit.'
Set scale for `u' component of arrows.
`set u scale as x'
Set scale for u component of arrows to be the same as the x-scale.
Equivalent to `set u scale as \{rpn ..xsize.. ..xright.. ..xleft..
- /}'.
NOTE: this only works if the x-scale is LINEAR (see `set x type').
{
extern "C" bool set_u_scaleCmd(void);
}
`set v scale .cm_per_unit.|{as y}'
Set scale for y-component of arrows.
`set v scale .cm_per_unit.'
Set scale for `v' component of arrows.
`set v scale as y'
Set scale for v component of arrows to be the same as the y-scale.
Equivalent to `set v scale as \{rpn ..ysize.. ..ytop.. ..ybottom..
- /}'.
NOTE: this only works if the y-scale is LINEAR (see `set y type').
{
extern "C" bool set_v_scaleCmd(void);
}
`set x axis top|bottom|increasing|decreasing|{.left. .right. [.incBig. [.incSml.]]}|unknown'
Control various things about the x axis.
`set x axis top'
Make next x-axis to be drawn have labels above the axis.
`set x axis bottom'
Make next x-axis to be drawn have labels below the axis.
`set x axis increasing'
Make next x-axis to be drawn have numeric labels increasing to the
right. This applies only if autoscaling is done; otherwise, the
supplied values (`.left. .right. [.incBig. [.incSml.]]') are
used.
`set x axis decreasing'
ke next x-axis to be drawn have numeric labels decreasing to the
right. This applies only if autoscaling is done; otherwise, the
supplied values (`.left. .right. [.incBig. [.incSml.]]') are
used.
`set x axis unknown' Make Gri forget any existing scale for the x
axis, whether set by another `set x axis' command or
automatically, during reading of data. This is essentially a
synonym for `delete x scale'.
`set x axis .left. .right.'
Make x-axis range from `.left.' to `.right.'
`set x axis .left. .right. .incBig.'
Make x-axis range from `.left.' to `.right.', with labelled
increments at `.incBig.' Note: In the case of log axes, and
provided that `set x type log' has been called previously, the
`.incBig.' parameter has a different meaning: it is the interval,
in decades, between numbered labels; the default is 1.
`set x axis .left .right. .incBig. .incSml.'
Make x-axis range from `.left.' to `.right.', with labelled increments
at `.incBig.', and small tics at `.incSml.' NOTE: if the axis is
logarithmic, the value of `.incSml.' takes on a special meaning: if it
is positive then small tics are put at values 2, 3, 4, etc. between
the decades, but if `.incSml.' is negative then no such small tics are
used.
{
extern "C" bool set_x_axisCmd(void);
}
#* @param \format for axis numbers in C notation @default %g
`set x format \format|default|off'
Set format for numbers on x axis. The format is specified in the manner
of the "C" programming language. The "C" formats (i.e., `%f',
`%e' and `%g') are permitted. For example, `set x format %.1f'
tells Gri to use 1 decimal place, and to prefer the "float" notation to
the exponential notation. The form `set x format off' tells Gri not to
write numbers on the axis. To get spaces in your format, enclose the
format string in double-quotes, e.g., you might use `set x format
"%.0f$\circ$ W"' for a map, or `set x format "%f "' to make the
numbers appear to the left of their normal location.
The default format is `%lg'.
{
extern "C" bool set_x_formatCmd(void);
}
`set x grid .left. .right. .inc.|{/.cols.}'
Create x-grid for contour or image.
`set x grid .left. .right. .inc.'
Create x-grid ranging from the value `.left.' at the left to
`.right.' at the right, stepping by an increment of `.inc.'.
`set x grid .left. .right. /.cols.'
Create x-grid with `.cols.' points, ranging from the value `.left.'
at the left to `.right.' at the right.
{
extern "C" bool set_x_gridCmd(void);
}
#* @param .size. of x margin @unit cm @default 6 @variable ..xmargin..
`set x margin {[bigger|smaller] .size.} | default'
Control x margin, that is, the space between the left-hand side of the
page and the left-hand side of the plotting area. (Note that axis
labels are drawn inside the margin; the margin extends to the axis
line, not to the labels.)
`set x margin .size.'
Set left margin to `.size.' cm. It is permissible to have
negative margins, with the expected effect.
`set x margin bigger .size.'
Increases left margin by `.size.' cm.
`set x margin smaller .size.'
Decreases left margin by `.size.' cm.
`set x margin default'
Set left margin to default = 6 cm.
{
extern "C" bool set_x_marginCmd(void);
}
#* @param \name of x axis @default ""
`set x name "\name"|default'
Set name of x-axis to the indicated string. An empty string
(`set x name ""') causes the x axis to be unlabelled.
The `default' is `"x"'.
{
extern "C" bool set_x_nameCmd(void);
}
#* @param .width_cm. of axis @unit cm @default 10 @variable ..xsize..
`set x size .width_cm.|default'
Set the width of the plotting area. This does not include axis labels,
only the interior part of the plot.
`set x size .width_cm.'
Set width of x-axis in centimeters.
`set x size default'
Set width of x-axis to default = 10 cm.
{
extern "C" bool set_x_sizeCmd(void);
}
`set x type linear|log|{map E|W|N|S}'
Control transformation function mapping user units to centimetres on the
page.
* `set x type linear' Set to linear axis.
* `set x type log' Set to log axis. To avoid clashes in the linear
to log transform, this command should precede the creation of an
axis scale, either explicitly through the `set x axis .left.
.right. ...' command or implicitly through the `read columns'
command.
* `set x type map E|W|N|S' Set to be a map. This means that whole
numbers on the axis will have a degree sign written after them
(and then the letter `E', etc) and that numbers which are
multiples of 1/60 will be written in degree-minute format, and
that similarly numbers which are divisible by 1/3600 will be in
degree-minute-second format. If none of these things apply, the
axis labels will be written in decimal degrees. Note that this
command overrides any format set by `set x format'.
BUG: this only has an effect if the axis is not already of type
`log'.
SEE ALSO: `set map projection', to set to non-rectangular axes for
various map projections.
{
extern "C" bool set_x_typeCmd(void);
}
`set y axis label horizontal|vertical'
`set y axis label horizontal'
Make y label be horizontal.
`set y axis label vertical'
Make y label be vertical (default).
{
extern "C" bool set_y_axis_labelCmd(void);
}
`set y axis left|right|increasing|decreasing|{.bottom. .top. [.incBig. [.incSml.]]}|unknown'
Control various things about the y axis.
`set y axis left'
Make next y-axis to be drawn have labels to the left of the axis.
`set y axis right'
Make next y-axis to be drawn have labels to the right of the axis.
`set y axis increasing'
Make next y-axis to be drawn have numeric labels increasing up
the page. This applies only if autoscaling is done; otherwise,
the supplied values (`.left. .right. [.incBig. [.incSml.]]') are
used.
`set y axis decreasing'
Make next y-axis to be drawn have numeric labels decreasing up
the page. This applies only if autoscaling is done; otherwise,
the supplied values (`.left. .right. [.incBig. [.incSml.]]') are
used.
`set y axis unknown' Make Gri forget any existing scale for the y
axis, whether set by another `set y axis' command or
automatically, during reading of data. This is essentially a
synonym for `delete y scale'.
`set y axis .bottom. .top.'
Make y-axis range from `.bottom.' to `.top.'
`set y axis .bottom. .top. .incBig.'
Make y-axis range from `.bottom.' to `.top.', with labelled
increments at `.incBig.'
`set y axis .bottom. .top. .incBig. .incSml.'
Make y-axis range from `.bottom.' to `.top.', with labelled
increments at `.incBig.', and small tics at `.incSml.' NOTE: if the
axis is logarithmic, the value of `.incSml.' takes on a special
meaning: if it is positive then small tics are put at values 2, 3, 4,
etc. between the decades, but if `.incSml.' is negative then no such
small tics are used.
{
extern "C" bool set_y_axisCmd(void);
}
#* @param \format for axis numbers in C notation @default %g
`set y format \format|default|off'
Set format for numbers on y axis. The format is specified in the manner
of the "C" programming language. The "C" formats (i.e., `%f',
`%e' and `%g') are permitted. For example, `set y format %.1f'
tells Gri to use 1 decimal place, and to prefer the "float" notation to
the exponential notation. The form `set y format off' tells Gri not to
write numbers on the axis. To get spaces in your format, enclose the
format string in double-quotes, e.g., you might use `set y format
"%.0f$\circ$ N"' for a map, or `set y format " %f"' to make the
numbers appear to the right of their normal location.
The default format is `%lg'.
{
extern "C" bool set_y_formatCmd(void);
}
`set y grid .bottom. .top. .inc.|{/.rows.}'
Create y-grid for contour or image.
`set y grid .bottom. .top. .inc.'
Create y-grid ranging from the value `.bottom.' at the bottom to
`.top.' at the top, stepping by an increment of `.inc.'.
`set y grid .bottom. .top. /.rows.'
Create y-grid with `.rows.' points, ranging from the value
`.bottom.' at the bottom to `.top.' at the top.
{
extern "C" bool set_y_gridCmd(void);
}
#* @param .size. of y margin @unit cm @default 6 @variable ..ymargin..
`set y margin {[bigger|smaller] .size.} | default'
Control y margin, that is, the space between the bottom side of the
page and the bottom of the plotting area. (Note that axis labels are
drawn inside the margin; the margin extends to the axis line, not to
the labels.)
`set y margin .size.'
Set bottom margin to `.size.' centimeters. It is permissible to
have negative margins, with the expected effect.
`set y margin bigger .size.'
Increases bottom margin by `.size.' centimeters.
`set y margin smaller .size.'
Decreases bottom margin by `.size.' centimeters.
`set y margin default'
Set bottom margin to default = 6 cm.
{
extern "C" bool set_y_marginCmd(void);
}
#* @param \name of y axis @default "y"
`set y name "\name"|default'
Set name of y-axis to the indicated string. An empty string
(`set y name ""') causes the y axis to be unlabelled.
The `default' is `"y"'.
{
extern "C" bool set_y_nameCmd(void);
}
#* @param .height_cm. of y axis @unit cm @default 10 @variable ..ysize..
`set y size .height_cm.|default'
Set the width of the plotting area. This does not include axis labels,
only the interior part of the plot.
`set y size .height_cm.'
Set height of y-axis in centimeters.
`set y size default'
Set width of y-axis to default = 10 cm.
{
extern "C" bool set_y_sizeCmd(void);
}
`set y type linear|log|{map N|S|E|W}'
Control transformation function mapping user units to centimetres on the
page.
* `set y type linear' Set to linear axis.
* `set y type log' Set to log axis. To avoid clashes in the linear
to log transform, this command should precede the creation of an
axis scale, either explicitly through the `set y axis .left.
.right. ...' command or implicitly through the `read columns'
command.
* `set y type map N|S|E|W' Set to be a map. This means that whole
numbers on the axis will have a degree sign written after them
(and then the letter `N', etc), and that numbers which are
multiples of 1/60 will be written in degree-minute format, and
that similarly numbers which are divisible by 1/3600 will be in
degree-minute-second format. If none of these things apply, the
axis labels will be written in decimal degrees. Note that this
command overrides any format set by `set y format'.
BUG: this only has an effect if the axis is not already of type
`log'.
SEE ALSO: `set map projection', to set to non-rectangular axes for
various map projections.
{
extern "C" bool set_y_typeCmd(void);
}
`set z missing above|below .intercept. .slope.'
Set `z' column to be missing whenever the associated `y' and `x'
columns are above/below the line defined by
y = .intercept. + .slope. * x
{
extern "C" bool set_z_missingCmd(void);
}
`set "..."'
{
extern "C" bool setCmd(void);
}
`show all'
Show lots of information about plot.
{
extern "C" bool show_allCmd(void);
}
`show axes'
Show information about axes.
{
extern "C" bool show_axesCmd(void);
}
`show color'
Show the current pen color used for lines and text. This is not to be
confused with image color, which is independent.
{
extern "C" bool show_colorCmd(void);
}
`show colornames'
Show all colors known by name, as defined by `read colornames' command and
also the builtin colors defined automatically (e.g. `white', `black',
`red', etc).
{
extern "C" bool show_colornamesCmd(void);
}
`show columns [statistics]'
`show columns'
Show x, y, z, u, v column data.
`show columns statistics'
Show means, std devs, etc for columns.
{
extern "C" bool show_columnsCmd(void);
}
`show flags'
Show values of all flags. (Developers only.)
{
extern "C" bool show_flagsCmd(void);
}
`show grid [mask]'
Show grid data (used for contouring), or show the grid mask (1 if data
are acceptable for contouring, or 0 if contours will not extend into
this region).
{
extern "C" bool show_gridCmd(void);
}
`show hint of the day'
Show a Gri hint for today, randomly selected from a list of hints
maintained on the Gri WWW site. Hints are cached, so that today's
your hint will only be dowloaded once, and stored in your
~/.gri-hint-cache file.
{
extern "C" bool show_hintCmd(void);
}
`show image'
Show information about image, such as a histogram of values, and,
if the image is small enough, the actual data.
{
extern "C" bool show_imageCmd(void);
}
`show license'
Show license, allowing copying of Gri
{
extern "C" bool show_licenseCmd(void);
}
`show misc'
Show miscellaneous information about the plot, the data, etc.
{
extern "C" bool show_miscCmd(void);
}
`show next line'
Show next line of data-file.
{
extern "C" bool show_next_lineCmd(void);
}
`show traceback'
Show traceback (i.e., the tree of commands being done at this
instant).
{
extern "C" bool show_tracebackCmd(void);
}
`show stopwatch'
Show elapsed time since first call to this command in the given Gri program.
{
extern "C" bool show_stopwatchCmd(void);
}
`show synonyms'
Show values of all synonyms, whether built-in or user-defined.
{
extern "C" bool show_synonymsCmd(void);
}
`show time'
Show the current time.
{
extern "C" bool show_timeCmd(void);
}
`show variables'
Show values of all variables, whether built-in or user-defined.
{
extern "C" bool show_variablesCmd(void);
}
`show .value. | {rpn ...} | "\text" [.value.|{rpn ...}|text [...]]'
`show .value.'
Show value of indicated variable.
`show \{rpn ...}'
Show result of computing indicated expression.
`show "some text"'
Print the indicated string.
`show "time=" .time. "; depth=" .depth.'
Print strings and values as indicated. If the last item is
ellipses (three dots with no spaces between them), then no
newline is printed; this makes the next `show' statement print on
the same line.
{
extern "C" bool show_expression_or_stringCmd(void);
}
`skip [forward|backward] [.n.]'
`skip'
For ascii files, skip forward 1 line in the data file. For binary
files, skip forward 1 byte.
`skip backward'
For ascii files, skip backward 1 line in the data file. For
binary files, skip backward 1 byte.
`skip .n.'
`skip forward .n.'
For ascii files, skip forward `.n.' lines in the data file. For
binary files, skip forward `.n.' bytes.
`skip backward .n.'
For ascii files, skip backward `.n.' lines in the data file. For
binary files, skip backward `.n.' bytes.
{
extern "C" bool skipCmd(void);
}
`sleep .sec.'
Cause Gri to sleep for the indicated number of seconds, which should
be a positive integer. This command is ignored if `.sec.' is zero or
negative, and the value of `.sec.' is first rounded to the nearest
integer.
Normally, this command is used only be the developer, as a way to
slow down Gri execution, to allow easier monitoring for debugging
purposes. Beware: it is tricky to kill a sleeping job!
{
extern "C" bool sleepCmd(void);
}
`smooth {x [.n.]} | {y [.n.]} | {grid data [.f.|{along x|y}]}'
All these smoothing commands ignore the *location* of the data. For
equispaced data these algorithms have the standard interpretation in
terms of digital filters. For non-equispaced data, the interpretation
is up to the user.
The `smooth x' command does smoothing by the following formula
x[i-1] x[i] x[i+1]
------ + ---- + ------
4 2 4
The `smooth x .n.' command does boxcar smoothing using centred
boxcars `.n.' points wide.
The `smooth y' command does the same as `smooth x', but on the `y'
column.
There are several methods of smoothing grid data. Note that isolated
missing values are filled in by each method. (Let the author know if
you'd like that `feature' to be an option.)
The `smooth grid data' command smooths gridded data, by weighted
average in a plus-shaped window about each gridpoint. The smoothing
algorithm replaces each interior gridpoint value `z[i][j]' by
z[i][j] z[i-1][j] + z[i+1][j] + z[i][j-1] + z[i][j+1]
------- + ---------------------------------------------
2 8
Points along the edges are smoothed by the same formula, after
inventing image points outside the domain by planar extrapolation.
The `smooth grid data .f.' command performs partial smoothing. A
temporary fully-smoothed grid `zSMOOTH[i][h]' is constructed as above,
and a linear combination of this grid and the original grid is used as
the replacement grid:
z[i][j] = (1-f) * z[i][j] + f * zSMOOTH[i][j]
where `f' is the value indicated on the command line. Thus, `smooth
grid data 0' performs no smoothing at all, while `smooth grid data 1'
is equivalent to `smooth grid data'.
The `smooth grid data along x' command smooths the grid data along
`x' (i.e., horizontally), by replacing each value `z[i][j]' with the
value
z[i][j] z[i-1][j] + z[i+1][j]
------- + ---------------------
2 4
Points along the edges are smoothed by the same formula, after
inventing image points outside the domain by linear extrapolation.
The `smooth grid data along y' command does the same thing as
`smooth grid data along x', but the smoothing is along `y'.
SEE ALSO: `filter', a generalization of `smooth x|y' which allows
for more sophisticated filters.
{
extern "C" bool smoothCmd(void);
}
`source \filename'
Insert instructions in named file into current file. This is useful as
a way of sharing global information between several Gri programs. On
unix systems, if a full filename is specified (i.e., a filename
beginning with slash or period), then that particular file will be used.
{
extern "C" bool sourceCmd(void);
}
`sprintf \synonym "format" .variable. [.variable. [...]]'
Write numbers into a synonym (text string). This is useful for
labelling plots.
`sprintf \out "a = %f b = %.2f" .a. .b.' - Create a synonym called
`\out', and print the values of the variables `.a.' and `.b.' into it.
If `.a.' = 1 and `.b.' = 0.112, then `\out' will be `"a = 1 b = 0.11"'
Formatting codes are as in the C programming language, eg:
%.2f -- Use floating point notation with 2 decimal places.
%9.2f -- As above, but specify the number to occupy 9 characters.
%e -- Use exponential notation.
WARNING: Variables are stored in the "double" storage type of the
"C" programming language, so "long" formats must be used in `sprintf'.
{
extern "C" bool sprintfCmd(void);
}
`state save|restore|display'
The `save' operation pushes a record of the graphics state (pen and
font characteristics, margins, axis lengths, min/max/inc values on axes,
etc) onto a stack. The `restore' operation replaces the present state with
whatever is on top of the stack, and then pops the stack. Use
the `display' operation to see some of the state properties.
The `state' command is useful for temporary changes of axis
properties, etc.
BUG: only line characteristics (width, color) and font characteristics
(font, size, color) are saved so far. In fact, the full list of what
should be saved has not yet been finalized by the author.
{
extern "C" bool stateCmd(void);
}
`superuser'
Allow extra debugging information and commands. Normally, this command
and the corresponding commandline flag -superuser are only used by
programmers altering the Gri source.
These are the flags and their meanings:
1 Print cmdline before/after substituting synonyms
2 Print cmdline before/after substituting rpn expressions
4 Print all new commands as they are being defined
8 Print system commands and `open "...|"' commands before they
are passed to the system
Note that all flags are equal to 2 raised to an integer power. Since
the flag values are detected by a bitwise OR, you can combine glags by
adding; thus specifying a flag of 5 yields flags 1 and 4 together.
{
extern "C" bool superuserCmd(void);
}
`system \system-command'
Tell the operating system to perform the indicated action. Whatever
string follows the word `system' is passed directly to the operating
system, *after* substitution of synonyms if any exist. Note that `rpn'
expressions are not evaluated, and variable values are not substituted
before passing the string to the operating system. The exit status is
stored in the builtin variable `..exit_status..'.
There are two ways to use the system:
* *Assign output to synonym*: The form `\synonym = system ...' does
the system command and then inserts the output from that command
into the indicated synonym.)
* *Just run a command*: The command `system ls' will list the files
in the current directory.
For long commands, there are two approaches, the second preferred:
* *Use continuation lines*: String a lot of information onto one
effective system line, using the `\' line-continuation character
at the ends of lines. The problem is that it's very easy to lose
one of these backslashes. The next method is better.
* *Here-is syntax* The here-is syntax of many unix shells is also
provided. If the system command contains the characters `<<'
followed by a word (with no space between!) then Gri will issue a
system command which includes not only this line but also all
succeeding lines, until a line is found which matches the
indicated word precisely (with no leading space allowed). The `<<
"WORD"' syntax is also supported, meaning that the operating
system is being told not to mess with the dollar-signs - needed in
perl.
*Note:* Be carefull using this inside a new-command. Gri
Recognizes the end of the body of a new-command by a line with `}'
in the *first column*, and no non-white characters thereafter. If
you system command happens to use a line with a curly brace (as in
a loop in perl, for example), you must put whitespace before the
brace. This won't affect the system command, but it will let Gri
correctly realize that this is *not* the end of the new-command.
For more information on new-commands.
*Caution:* Before sending the string to the system, Gri first
translates any synonyms present. Be careful with this, since
system commands calling awk, etc, very often use backslashes for
the newline character `\n' within strings. If you have a synonym
whose name starts with `\n', you can get a conflict. For example,
the awk command `print "foo\nbar";' should print a line with `foo'
on it, followed by a line with `bar' on it, but it will instead
print a single line with `fooMISTAKE', if you had previously
defined a synonym as `\nbar = "MISTAKE"'. One way to avoid this
mistake is to make sure any `\n' characters appear at the end of
strings, and then simply avoid having a synonym named `\n'.
Here is a Perl example.
\message = "Foo bar"
system perl <<"EOF"
$a = 100;
print "foo bar is \message, and a is $a\nQ: was a 100?\n";
print "BETTER: foo bar is \message, and a is $a\n";
print "Q: was a 100?\n";
EOF
which, written more safely (partially avoiding the string `\n'), is
\message = "Foo bar"
system perl <<"EOF"
$a = 100;
print "foo bar is \message, and a is $a\n";
print "Q: was a 100?\n";
EOF
Here is an Awk example. Note that the commandline flags `-f -' are
required to force awk to take commands from standard input. Note
also the absence of a final newline in the string; Awk does not
require one, while Perl does. (Finally, as usual, note that the
synonym `awk' is being used instead of `awk', to ensure
portability.)
\message = "Foo bar"
system awk -f - <<"EOF"
BEGIN \{
a = 100;
print "foobar is \message, and a is ", a, "\nQ: was a 100?";
}
EOF
which, written more safely (avoiding the string `\n'), is
\message = "Foo bar"
system awk -f - <<"EOF"
BEGIN\{
a = 100;
print "foobar is \message, and a is ", a;
print "Q: was a 100?";
}
EOF
*Some more examples*:
* To get the first 10 lines of a file called `foo.dat' inserted into
another file called `bar.dat', you might do the following. Only
the first method works; the second will fail because `.n.' will not
be translated before passing to the operating system.
\num = "-10"
system head \num foo.dat > bar.dat
# Following fails since .num. will not be translated
.num. = -10
system head .num. foo.dat > bar.dat
* Issue a unix command to get a listing of files in the current
working directory, and pipe them into the `more' system command.
system ls -l *c | more
* Store the date and time into a synonym, and use it in a title:
\time = system date
...
draw title "Plotted at time \time"
* Use `awk' to prepare a two-column table of x, ranging from 0 to 1
in steps of 0.1, and sin(x). The table is stored in a file whose
suffix is the process ID of the Gri job. This file is then
opened, and the data plotted. Finally, a system command is issued
to remove the temporary file.
system awk 'BEGIN \{ \
for (x=0; x<1; x+=0.1) \{ \
printf("%f %f\n", x, sin(x)) \
} \
}' > tmp.\.pid.
open tmp.\.pid.
read columns x y
close
system rm tmp.\.pid.
draw curve
quit
NOTE Under unix, this command calls the Bourne shell, not the
C-shell that is often used interactively. For many simple uses,
the only difference from normal interactive use will be that `~'
is not expanded to the home directory. For example, you'd do
system awk -f $HOME/foo/bar/cmd.gawk
instead of the
system awk -f ~/foo/bar/cmd.gawk
that you might expect from interactive C-shell usage.
RETURN VALUE: Sets `\.return_value' to system status, `N status'
{
extern "C" bool systemCmd(void);
}
`while .test.|{rpn ...}'
Perform statements in loop while the value of `.test.' or the RPN
expression is nonzero. The end of the loop designated by a line
containing the words `end while'. The value `.test.' may be an RPN
expression. To leave the loop prematurely, use a `break' statement.
Upon encountering a `break' statement, Gri jumps to the line
immediately following the loop. If the `-chatty' option is nonzero, a
notification is printed every 1000 passes through the loop, as a
debugging measure to catch unintended infinite loops.
*Examples*:
* Loop forever, printing a message over and over.
while 1
show "DANGER: This loop goes on forever. You need a break statement!"
end while
* Repeatedly read two numbers, and plot a bullet at the indicated
location. If (or, hopefully, "when") the end of the file is
encountered, break out of the loop; otherwise continue plotting
forever.
while 1
read .x. .y.
if ..eof..
break
end if
draw symbol bullet at .x. .y.
end while
* Loop 10 times, printing the values of `.i.' as they range 0, 1,
..., 9. After exiting from the loop, `.i.' will equal 10. Be
*careful* to use the correct RPN greater-than test to avoid an
infinite loop.
.i. = 0
while \{rpn .i. 10 >}
show .i.
.i. += 1
end while
{
extern "C" bool whileCmd(void);
}
`write columns to \filename'
Append data columns to the end of the indicated file.
{
extern "C" bool writeCmd(void);
}
`write contour .value. to \filename'
As corresponding `draw contour' command, but don't actually draw the
contours; instead, write to the indicated file, starting at the EOF of
the file if it is nonempty (thus, appending to the end of the file.)
The first line of output is a header line, containing two numbers: the
contour value and the missing value. Then the xy pairs are written a
line at a time, with missing values being used to indicate ends of
segments. A blank line is written after the last data pair. For
example, if the contour contained two closed regions, Gri would output
a pair of missing values as one of the xy pairs, to denote the
separation of the two curves. You could read and plot the output as
in this example
write contour 10 to contour.out
write contour 20 to contour.out
open contour.out
read .contour_value. .missing.
set missing value .missing.
read columns x y
draw curve
{
extern "C" bool writeCmd(void);
}
`write grid to \filename [bycolumns]'
Append grid to the end of the named file. Storage is in `%f' format,
and is in normal image order. If the keyword `bycolumns' is present,
then the grid is transposed first, in such a way that `read grid data
bycolumns' performed on that file will read back the original grid
data.
{
extern "C" bool writeCmd(void);
}
`write image colorscale to \filename'
Append image colorscale transform to the end of the named file.
Storage is a series of 256 lines, each containing 3 numbers (for Red,
Green and Blue) in the range 0 to 1. The file is suitable for reading
with the `read image colorscale' command.
*/
{
extern "C" bool writeCmd(void);
}
`write image grayscale to \filename'
Append image grayscale transform to the end of the named file.
Storage is a series of 256 lines, each containing a number in the
range 0 to 1. The file is suitable for reading with the `read image
grayscale' command.
*/
{
extern "C" bool writeCmd(void);
}
`write image greyscale to \filename'
Alternate spelling of grayscale
{
extern "C" bool writeCmd(void);
}
`write image mask [pgm|rasterfile] to \filename'
`write image mask to mask.dat'
Append image mask to the end of the named file. Storage is by
unsigned-char, and is in normal image order. There is no header.
`write image mask rasterfile to mask.dat'
Append image mask to the end of the named file, in Sun Rasterfile
format.
`write image mask pgm to mask.dat'
Append image mask to the end of the named file, in PGM 'rawbits'
format.
{
extern "C" bool writeCmd(void);
}
`write image [pgm|rasterfile] to \filename'
`write image to image.dat'
Append image to the end of the named file. Storage is by
unsigned-char, and is in normal image order. There is no
header.
`write image rasterfile to image.dat'
Append image to the end of the named file, in Sun Rasterfile
format.
`write image pgm to image.dat'
Append image to the end of the named file, in PGM 'rawbits'
format.
{
extern "C" bool writeCmd(void);
}
`unlink \filename'
Delete a filename and possibly the file to which it refers. On
non-unix machines, this simply means to delete the file. On unix
machines, the action is more subtle. The unix OS permits several
processes to use a given file at once. Therefore, `unlink' doesn't
immediately remove the file, but instead waits until other processes
are done with it. Most users will never realize the difference,
however, and it is safe to think of `unlink' as simply removing the
file. To learn more, type `man unlink' in a unix shell.
A common use of `unlink' is to remove files that were created with
the `tmpname' facility, e.g.
\tmp = tmpname
# do some system commands to put data into this file
open \tmp
read columns x y
draw curve
unlink \tmp
{
extern "C" bool unlinkCmd(void);
}
`?draw axes exploded'
Fragment to draw the xy axes at left and bottom, offset 0.2 cm from a
simple axis frame.
{
draw axes frame # Draw frame
draw x axis at {rpn ..ymargin.. 0.2 -} cm lower # X axis below frame
draw y axis at {rpn ..xmargin.. 0.2 -} cm left # Y axis left of frame
}
`?contour xyz data'
Fragment to read xyz data (from a file called "file.dat"), then
interpolate these xyz data onto a uniform grid (of size 30x30, chosen to
span the data), and then draw contours (at levels selected by autoscaling
the data). For reference, dots are also drawn at the data locations.
Adjustments: filename, grid characteristics, method/details of converting
columns to grid.
{
open input.dat # You'll want to change the filename
read columns x y z # Can read in any order, e.g '... y x z'
close # Close this file
set x grid ..xleft.. ..xright.. / 30 # Spans data, 30 wide
set y grid ..ybottom.. ..ytop.. / 30 # Spans data, 30 high
convert columns to grid # Uses default "objective" method
draw contour # Levels selected automatically
draw symbol bullet # Put dots at data locations
}
`?set axes'
{
set x margin 2 # 2cm at left of axis frame
set x margin 2 # 2cm at left of axis frame
set x size 12 # Axis frame 12cm wide
set y size 12 # Axis frame 12cm high
set x name "x" # Name of x axis
set y name "y" # Name of y axis
}
`?draw image BW raster'
Fragment to read/draw a Sun rasterfile image in BW, blown up to full size
on (portrait orientation) 8.5x11 paper. No axes are drawn. A palette is
drawn, assuming that the limits of the image value are 0 and 1.
Main adjustable parameters marked with '*' in comment.
{
\file = "A.rs" # * filename
.min. = 0 # * lowest possible value
.max. = 1 # * largest possible value
set image range .min. .max.
open \file binary
read image rasterfile
# ALTERNATIVE:
# read image pgm
close
.margin. = 1 # * margin space in cm
set x margin .margin.
set y margin .margin.
set x axis 0 ..image_width.. ..image_width..
set y axis 0 ..image_height.. ..image_height..
set font size 10 # * font size
set x size {rpn 8.5 2.54 * .margin. 2 * -}
set y size {rpn ..xsize.. ..image_width.. / ..image_height.. *}
# Want 2cm for palette
.left_over. = {rpn 11 2.54 * ..ysize.. - .margin. 2 * -}
if {rpn .left_over. 2 >}
set y size {rpn 11 2.54 * .margin. 2 * - 2 -}
set x size {rpn ..ysize.. ..image_height.. / ..image_width.. *}
end if
draw axes none
draw image
draw image palette left .min. right .max. box \
{rpn ..xmargin..} \
{rpn ..ymargin.. ..ysize.. + 1.0 +} \
{rpn ..xmargin.. ..xsize.. +} \
{rpn ..ymargin.. ..ysize.. + 2.0 +}
}
rpnfunction e 2.7182818284590452354
rpnfunction pi 3.14159265358979323846
# The following assume stack containing four numbers, 'x0 y0 x1 y',
# and return the slope and intercept of the line joining the points.
rpnfunction linear_slope exch roll_right - roll_right exch - /
rpnfunction linear_intercept exch dup roll_left roll_left roll_left dup roll_right - roll_right exch - / roll_left * -
# /----------------------------------------------------------------\
# |The following material is for the benefit of the Emacs gri mode |
# \----------------------------------------------------------------/
#
# @variable ..R2.. squared correlation coefficient (defined if regression has been done)
# @variable ..coeff0.. intercept in linear regression (defined if regression has been done)
# @variable ..coeff0_sig.. 95% C.I. on intercept in linear regression (defined if regression has been done)
# @variable ..coeff1.. slope in linear regression (defined if regression has been done)
# @variable ..coeff1_sig.. 95% C.I. on slope in linear regression (defined if regression has been done)
# @variable ..num_col_data.. number of column data
# @variable ..num_col_data_missing.. number of missing column data
# @variable ..arrowsize.. size of arrow heads @unit cm @default 0.2
# @variable ..batch.. is Gri in batch mode? @default 0
# @variable ..debug.. debugging flag @default 0
# @variable ..fontsize.. size of font @unit point @default 12
# @variable ..graylevel.. graylevel of pen (0 means black) @default 0
# @variable ..linewidth.. width of curves @unit point @default 0.709
# @variable ..linewidthaxis.. width of axis lines @unit point @default 0.369
# @variable ..linewidthsymbol.. width of symbol lines @unit point @default 0.369
# @variable ..missingvalue.. missing value @default 1e+22
# @variable ..symbolsize.. size of symbols @unit point @default 0.1
# @variable ..superuser.. superuser flag @default 0
# @variable ..trace.. are executed commands printed? @default 0
# @variable ..tic_direction.. direction of tics (0 means out and 1 means in) @default 0
# @variable ..tic_size.. size of tic marks @unit cm @default 0.2
# @variable ..xmargin.. margin to left of axis area @unit cm @default 6
# @variable ..xsize.. width of axis area @unit cm @default 10
# @variable ..ymargin.. margin below axis area @unit cm @default 6
# @variable ..ysize.. height of axis area @unit cm @default 10
# @variable ..red.. red-ness of pen (0 to 1) @default 0
# @variable ..blue.. blue-ness of pen (0 to 1) @default 0
# @variable ..green.. green-ness of pen (0 to 1) @default 0
# @variable ..exit_status.. exit status used for OS @default 0
# @variable ..xleft.. x-value at left of axis area @default 0
# @variable ..xright.. x-value at right of axis area @default 10
# @variable ..ybottom.. y-value at bottom of axis area @default 0
# @variable ..ytop.. y-value at top of axis area @default 10
# @variable ..use_default_for_query.. use default for query statements? (0 or 1) @default 0
# @variable ..words_in_dataline.. number of words in data line @default 0
# @variable ..eof.. at end of data file yet? (0 or 1) @default 0
# @variable ..landscape.. is the graph in landscape mode? (0 or 1) @default 0
# @variable ..publication.. use publication quality? (0 or 1) @default 0
# @variable ..xlast.. last value of x column @default 0
# @variable ..ylast.. last value of y column @default 0
# @variable ..image_width.. pixel width of image @default 0
# @variable ..image_height.. pixel height of image @default 0
# @variable \.missingvalue. missing value code @default "1e22"
# @variable \.return_value. return value from last command
# @variable \.version. version of gri being used
# @variable \.pid. process id of this job
# @variable \.wd. present working directory
# @variable \.time. day, date and time
# @variable \.user. name of user who started this job
# @variable \.host. name of computer on which job is running
# @variable \.system. name of operating system
# @variable \.home. name of this users home directory
# @variable \.lib_dir. directory that holds gri library files
# @variable \.command_file. name of command file for this job
# @variable \.readfrom_file. name of file being read for data
# @variable \.ps_file. name of PostScript file being created
# @variable \.path_data. directory path for finding data @default "."
# @variable \.path_commands. directory path for finding commands @default "."
|