aboutsummaryrefslogtreecommitdiff
path: root/sys/gio/doc/gio.hlp
blob: f8749c230554d97fc52e8942c83880f3235e04c8 (plain) (blame)
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
.help gio Dec84 "Graphics I/O"
.ce
\fBGraphics I/O Design\fR
.ce
Doug Tody
.ce
December 1984
.ce
(revised October 1987)
.sp 3
.nh
Introduction

    The graphics i/o (GIO) interface is a library of SPP or Fortran callable
procedures for interactive vector graphics.  The interface is designed primarily
for scientific applications (graphing 1-dimensional data vectors).  Limited
support is also provided for displaying 2-dimensional image data.  GIO is fully
integrated into the IRAF system and is not intended for use in systems other
than IRAF.  The principal design objectives of GIO are outlined below.

.ls
.ls o
Simple and efficient interactive graphics.  For interactive data analysis
applications speed is typically much more important than the quality of
the plot.
.le
.ls o
Ease of use.  The interface must be easy to use for scientific data analysis
applications.  Ease of use for interactive graphics in scientific applications
is considered more important than the flexibility required to produce
publication quality graphics.
.le
.ls o
Compact size.  That portion of the graphics system required for interactive
graphics must be small enough to be linked into every process which performs
interactive graphics.
.le
.ls o
Device independence.  The interface must be device independent without
compromising compactness and speed.  True device independence means that
an applications program that normally uses interactive graphics can be run
noninteractively or from a nongraphics workstation.
.le
.le


IRAF needs its own graphics interface partly because no existing graphics
interface meets all of the above requirements, and partly because we do not
want our applications to be dependent upon any particular external graphics
package.  The existing large graphics interfaces such as GKS and CORE are
likely to make it easier to interface GIO to new graphics devices, but to
be completely and directly dependent on any one such interface is unwise since
implementations are sometimes hard to come by.  Furthermore, packages such
as GKS and CORE were designed to serve as the kernel of a graphics system
and are cumbersome to use directly in applications software.  GIO will serve
as a front end to the graphics kernel, providing a higher level interface
for applications software and isolating the IRAF applications from the kernel,
making it possible to switch to a different kernel without rewriting the
applications packages.

.nh
Conceptual Design

    GIO is intended to be used either as a self contained interface to a
graphics device, with GIO writing device instructions directly to the device,
or as an interface to a more general device independent graphics kernel.
For maximum speed in interactive applications GIO will use a special builtin
kernel capable of driving only the interactive graphics devices in use at
a particular site (e.g., tektronix compatible graphics terminals).
Other devices will be driven by a device independent graphics kernel resident
in a separate process.  GIO will select the data path to be used for a
particular device transparently to the calling program.  Thus, the overhead
of process initiation and IPC will be eliminated in common interactive
applications without sacrificing device independence.  The builtin kernel
will be table driven using a \fBtermcap\fR format graphics device database,
allowing maximum flexibility for adapting GIO to new graphics devices.

The device independent graphics kernel may be GKS, CORE, NSPP, or any other
reasonably capable kernel.  GIO will be designed to require only a few simple
graphics primitives at the bottom end, making it straightforward to interface
to different graphics kernels.  Any application which requires a more
sophisticated graphics interface than that provided by GIO may bypass GIO
and talk directly to the underlying graphics kernel, but doing so will
render the application usable only with that particular graphics kernel.

Placing the device independent graphics kernel in a separate process makes
it possible to use a large, sophisticated graphics kernel without linking
enormous libraries of subroutines into applications processes.  Bugs can be
fixed and new features and devices added without relinking applications
processes.  In principle it is even possible to interface simultaneously
to more than one graphics kernel, e.g., one might drive some devices with
an NSPP kernel and others with a GKS kernel.  On a different host CORE might
be the only thing available and GIO would have to be interfaced to CORE on
such a host.


.ks
.nf
	        __________
	       /          \
	       | graphics |
	       | terminal |
	       \__________/
		   |  ^
		   |  |(device codes)
		   v  |                           _________
		+--------+     +-----------+     /         \
		|   CL+  |<----| graphics  |<----|         |
		|  fast  |     |  kernel   |     | gdevice |
		| kernel |---->|   task    |---->|         |
		+--------+     +-----------+     \_________/
		   |  ^                 |
		   |  |(gki metacode)   |          (core metacode)
		   v  |                 +--------> (nspp metacode)
		+--------+                         (gks vdm)
		|  user  |
		|  task  |-----------------------> (gki metacode)
		+--------+


	          simple                   plotters
	  |---  interactive ---|------     metafile    ------|
		 graphics               special devices


.fi
.ce
Figure 1. Graphics Task Structure
.ke


The IRAF command language (CL) is the user interface to IRAF programs and
as such moderates all interaction with the user, including interaction via
graphics devices.  GIO is primarily a graphics \fIoutput\fR interface;
graphics input (other than pixel readback) is decoupled from graphics output
and is controlled by the CL.  Often the task requesting cursor input will
differ from that which produced the graphics.  The CL, under control of the
user, may set the default graphics input and output devices, redirect graphics
input and/or output to devices other than the default, and control whether
a graphics task is used interactively or in batch mode.

.nh
Specifications

    The GIO graphics output procedures draw various flavors of vectors and
fill or color two dimensional areas.  Cursor input is a way of interacting
with the user and is therefore handled by CLIO (the command language
interface).  We first define important terms and define the coordinate
systems used by GIO.  Next follows an overview of the input and output
procedures.  Finally, we describe in detail the individual procedures and
the interface to the graphics kernel.

.nh 2
Coordinate Systems

    The full plotting surface of a device defines the domain of definition
of the coordinate systems used by GIO.
GIO supports up to sixteen user defined \fBworld coordinate systems\fR
(WCS) per open device, numbered 1 through 16.
One additional coordinate system (WCS 0) with values ranging from 0 to 1 in
either axis is predefined for every device; this \fBnormalized device
coordinate system\fR (NDC) spans the full plotting surface of the device.  

The mapping of world coordinates to device coordinates is
defined by a \fBwindow\fR into world space and a corresponding \fBviewport\fR
into device space.  Each window-viewport pair defines one of the 16 world
coordinate systems.  At \fBgopen\fR time GIO is initialized to WCS 1,
which has both window and viewport set to NDC coordinates.  A subsequent
call to either \fBgswind\fR or \fBgscale\fR will set the window and a
subsequent call to \fBgsview\fR will set the viewport.  The WCS is not fixed
to the device until a plotting operation occurs which requires use of the WCS.
Hence, multiple calls to \fBgscale\fR to determine the range of data values
in X and Y for a family of curves are possible before fixing the WCS to the
device, e.g. in a call to \fBglabax\fR.

A \fBviewport\fR is any rectangular plotting area lying entirely within the
plotting area of the device.  The viewport defines the area in which data
can be plotted, i.e., the boundary at which \fBclipping\fR will occur if
enabled.  The viewport is the area framed by \fBglabax\fR; the tick and axis
labels will be plotted in the area just outside the viewport.
A square viewport need not have the same resolution in both X and Y.
Devices with variable resolution, e.g. pen plotters, have a default
resolution in either axis which can be overridden when the plot is drawn.
The aspect ratio of the device is the ratio of the physical size of a
device pixel in Y to that in X.  Most devices have an aspect ratio of
unity, but it is common for the resolution to be different in X and Y.
The aspect ratio of the device is available via a \fBgget\fR inquiry,
as is the device resolution in either axis.

A \fBwindow\fR is the range of world coordinates which GIO will map to the
corresponding viewport.  The world coordinates must be cartesian and
either linear or logarithmic (base 10) in either axis.
There are no restrictions on the range of world coordinates other than
those imposed by the single precision floating point hardware of the
host computer, provided that the WCS is not degenerate
(zero range in either axis).

Most applications will use only a single WCS, hence the WCS number is not
included explicitly in the argument lists of the GIO procedures.
A call to \fBgset\fR is required to change to a different WCS.
Thereafter all graphics output and cursor input will refer to the new WCS.
Multiple WCS are useful when plotting in several distinct (nonoverlapping)
viewports on a device, or when overplotting curves within the same viewport
but with different world coordinate windows.

.nh 2
Graphics Output Procedures

    The GIO output procedures range from \fBgplotv\fR and \fBgploto\fR,
which can draw an entire plot with autoscaling and axis labeling in one call,
to the polyline, polymarker, move, draw, and text drawing primitives at
the low end.


.ks
.nf
	       gplotv (v, npts, x1, x2, title)
	       gploto (gp, v, npts, x1, x2, title)
	    gpagefile (gp, fname, prompt)
		
	   gp = gopen (device, mode, fd)
	       gclose (gp)
	  gdeactivate (gp, flags)
	  greactivate (gp, flags)
	      gcancel (gp)
	       gflush (gp)
	       gclear (gp)
	       gframe (gp)
	       greset (gp, flags)
	     gmftitle (gp, metafile_title)

	        gscan (gp, text)
	    gset[irs] (gp, param, value)
     val = gstat[irs] (gp, param[, outstr, maxch])
     val = gget[birs] (gp, devcap[, outstr, maxch])
	    g[sg]view (gp, x1, x2, y1, y2)
	    g[sg]wind (gp, x1, x2, y1, y2)
	   g[ar]scale (gp, v, npts, axis)
	      ggscale (gp, x, y, dx, dy)
	       gctran (gp, x1, y1, x2, y2, wcs1, wcs2)
	      gcurpos (gp, x, y)
	      gescape (gp, fn, instruction, nwords)

	       glabax (gp, title, xlabel, ylabel)
	        gline (gp, x1, y1, x2, y2)
	       gpline (gp, x, y, npts)
	       gvline (gp, v, npts, x1, x2)
	        gmark (gp, x, y, marktype, xsize, ysize)
	       gpmark (gp, x, y, npts, marktype, xsize, ysize)
	       gvmark (gp, v, npts, x1, x2, marktype, xsize, ysize)
	       gumark (gp, x, y, npts, xcen, ycen, xsize, ysize, fill)
	    g[ar]move (gp, x, y)
	    g[ar]draw (gp, x, y)
		gtext (gp, x, y, text, format)
		gfill (gp, x, y, npts, style)
	    g[pg]cell (gp, m, nx, ny, x1, y1, x2, y2)

	        gscur (gp, x, y)
	 stat = ggcur (gp, x, y, key)
.fi
.ke


All coordinates are given in world coordinates (user coordinates)
except the viewport coordinates and the marker sizes, which are given in
device coordinates.  Low level graphics i/o requires that the graphics
device first be opened with \fBgopen\fR and later closed with \fBgclose\fR.
Several graphics devices may be open simultaneously.

When a graphics device is opened with \fBgopen\fR all internal parameters
are initialized to their default values, unless the device is opened in
APPEND mode.  The default values of these internal parameters may be changed
via explicit \fBgset\fR, \fBgswind\fR, \fBgscale\fR, or \fBgscan\fR calls.
Most powerful is \fBgscan\fR, which interprets graphics commands passed
either as an explicit string or in a text file.

Much of the flexibility of GIO derives from its parameter defaulting
mechanism.  The interface may be expanded indefinitely by adding new
internal parameters accessed via \fBgset\fR calls, without changing the
basic interface.

.nh 2
Graphics Input Procedures

    The most commonly used type of graphics input is cursor readback.
Two forms of cursor input are supported: cursor input via the CLIO procedure
\fBclgcur\fR, and cursor input via the GIO procedure \fBggcur\fR.
CLIO based cursor input should be used whenever possible, i.e., when writing
to \fBstdgraph\fR or \fBstdimage\fR.  The advantage of cursor input via the
CL is that input may come from a list file or the terminal as well as from
a physical cursor read, allowing programs to be used either interactively
or in batch mode.  Furthermore, WCS selection and conversion of NDC cursor
coordinates to WCS and cursor mode interaction are only available with
\fBclgcur\fR.  Programs which do not produce any graphics output may read
the cursor via CLIO without using any part of the GIO interface.
The lower level GIO cursor read procedure always reads the physical device
cursor in NDC coordinates and is device dependent (it is what is called by
\fBclgcur\fR).

Cursors are implemented as abstract datatypes within the CL.  A user task
accesses a cursor by reading the value of a CL parameter of type \fBgcur\fR
(stdgraph cursor) or \fBimcur\fR (stdimage cursor).  Multiple cursors may
be implemented using multiple cursor type parameters.  A cursor parameter
is assumed to have a \fIlist\fR of values; EOF is returned when the end of
the list is reached.  Reading the cursor automatically causes any graphics
output to be flushed.

        stat = clgcur (param, wx, wy, wcs, key, strval, maxch)

The CLIO function \fBclgcur\fR reads the next cursor value from the named
cursor parameter, returning as output arguments the cursor position in world
coordinates, the index of the referenced WCS, the keystroke value (character
typed) of the cursor event, and a string value if the key was ':', the
cursor mode set option escape character.
A cursor read sequence begins with a prompt, i.e., the cursor lights up
or starts blinking.  The user is then free to move the cursor about;
the cursor position is not read until a key is typed on the user terminal.
Using a keystroke on the user terminal to terminate both \fBstdgraph\fR
and \fBstdimage\fR cursor reads provides a rich and device independent set of
keystroke values for identifying the action to be performed (imaging devices
are typically very limited in this area).

GIO always returns the cursor position in world coordinates, along with
the index of the WCS selected.  Typically there will be exactly one world
coordinate system (excluding WCS 0) and the WCS value may be ignored.
If no world coordinate systems are defined for the device the cursor
position will be returned in NDC coordinates with WCS=0.

If multiple world coordinate systems are defined GIO will select the WCS
closest to the position of the cursor, i.e., the cursor may lie outside the
viewport and GIO will still return WCS coordinates.  If the cursor lies
within two or more overlapping viewports GIO will select the WCS with the
highest number.  The cursor read protocol will allow the user to force
the selection of a particular viewport by first placing the cursor on a
nonoverlapping portion of the viewport and typing a special code,
e.g., W (see next section), and then continuing with the normal cursor read.
If the application wishes to override the automatic WCS selection it may
do so by calling \fBgctran\fR to transform the cursor coordinates returned
by \fBclgcur\fR to a different world coordinate system.

.nh 3
Cursor Mode

    In cursor mode, i.e., after a call to \fBclgcur\fR or after typing "=gcur",
a number of special keystrokes shall be recognized for interactive display
control.  All graphics output to stdgraph and stdimage is routed through the
CL on the way to the graphics kernel.  The CL will optionally spool in an
internal buffer all graphics instructions output to an interactive device.
This internal buffer is emptied whenever the device screen is cleared.
In cursor mode, special keystrokes may be used to redraw all or any portion
of the spooled graphics, e.g., one may zoom in on a portion of the plot and
then roam about on the plot at high magnification.  Since the spooled graphics
vectors typically contain more information than can be displayed at normal
magnification, zooming in on a feature may bring out additional detail
(the maximum resolution is 32768 points in either axis).  Increasing the
magnification will increase the precision of the cursor by the same factor.

Cursor mode is implemented by performing coordinate transformation and
clipping on each GKI instruction in the frame buffer, passing the transformed
and clipped instructions on to the graphics kernel.
The cursor mode operations perform a simple geometric transformation on
the spooled graphics frame, mapping a rectangular window of the spooled
frame onto the device screen.  The graphics frame itself is not modified,
hence zoom out or reset and redraw will restore the original display.

If the graphics frame is a typical vector plot with drawn and labeled
axes, magnifying a portion of the plot may cause the axes to be lost.
If this is not what is desired a keystroke is provided to draw and label
the axes of the displayed window.  The axes will be overplotted on the
current display and will not be saved in the frame buffer, hence they
will be lost when the frame is redrawn.  In cursor mode the viewport is
the full display area of the output device, hence the tick mark labels
of the drawn axes will be drawn inside the viewport.  This form of axes
labeling is used because it is simple and because it is appropriate for
both vector graphics and image display output devices (and cursor mode
must serve both).


.ks
.nf
	A 			draw and label the axes of current viewport
	B			backup over last instruction in frame buffer
	C			print the cursor position as it moves
	D 			draw a line by marking the endpoints
	E			expand plot by setting window corners
	F			set fast cursor (for HJKL)
	H			step cursor left
	J			step cursor down
	K			step cursor up
	L			step cursor right
	M			move point under cursor to center of screen
	P			zoom out (restore previous expansion)
	R			redraw the screen
	T 			draw a text string
	U 			undo last frame buffer edit
	V			set slow cursor (for HJKL)
	W 			select WCS at current position of cursor
	X			zoom in, X only
	Y			zoom in, Y only
	Z			zoom in, both X and Y
	<			set lower limit of plot to the cursor y value
	>			set upper limit of plot to the cursor y value
	\ 			escape next character
	:			set cursor mode options
	:!			send a command to the host system
	=			shorthand for :.snap (make graphics hardcopy)
	0			reset and redraw
       1-9			roam
.fi
.ce
Figure 2. Cursor Mode Keystrokes
.ke


By default the cursor mode keystrokes are all upper case letters, reserving
lower case for applications programs.  The terminal shift lock key may be
used to simplify typing in lengthy interactive cursor mode sessions.
The cursor motions are decoupled from roam since zoom and roam are often used
merely to increase the precision of a cursor read.  Special keystrokes are
provided for stepwise cursor motions to increase the speed of cursor setting
on terminals that do not have fast cursor motions (e.g., the retro-graphics
enhanced VT100).  The recognized keystrokes are shown in Figure 2.

If the character : is typed while in cursor mode the alpha cursor will appear
at the bottom of the screen, allowing a command line to be entered.  Commands
which begin with a period, e.g., ":." are interpreted by the graphics system;
any other command will terminate the cursor read, returning the character ':'
as the key value, and the command string as the string value of the cursor
read.  The commands recognized by the graphics system are summarized in
figure 3.


.ks
.nf
	:.axes[+-]		draw axes of viewport whenever screen is redrawn
	:.case[+-]		enable case sensitivity for keystrokes
	:.clear			clear alpha memory (e.g, this text)
	:.cursor n		select cursor (0=normal,1=crosshair,2=lightpen)
	:.gflush		flush plotter output
	:.help			print help text for cursor mode
	:.init			initialize the graphics system
	:.markcur[+-]		mark cursor position after each cursor read
	:.off [keys]		disable selected cursor mode keys
	:.on [keys]		enable selected cursor mode keys
	:.page[+-]		enable screen clear before printing help text
	:.read file		fill frame buffer from a file
	:.show			print cursor mode and graphics kernel status
	:.snap [device]		make hardcopy of graphics display
	:.txqual qual		set character generator quality (normal,l,m,h)
	:.txset format		set text drawing parameters (size,up,hj,vj,etc)
	:.xres=value		set X resolution (stdgraph only)
	:.yres=value		set Y resolution (stdgraph only)
	:.viewport x1 x2 y1 y2	set workstation viewport in world coordinates
	:.write[!][+] file	save frame buffer in a spool file
	:.zero			reset viewport and redraw frame
.fi


.ce
Figure 3. Cursor Mode Commands
.ke


Minimum match abbreviations are permitted for cursor mode command names.
Multiple commands may be given on one line, delimited by semicolons.
If the CL environment variable \fBcminit\fR is defined when cursor mode is
first entered, the string value will be interpreted as a cursor mode command
and used for initialization.  For example, to disable the numeric keys and
set the graphics resolution to 200 points in X and 100 points in Y, one
could add the following \fBset\fR declaration to their "login.cl" file:

	set cminit = "xres=200; yres=150; off 0-9"

The numeric keypad of the terminal (if it has one) is used to roam about
when the zoom factor is greater than one.  If the magnification is normal
the numeric keys are not recognized as special keystrokes, i.e., typing
a numeric key will exit cursor mode, returning the character typed to the
applications program.  In roam mode a numeric key must be escaped to exit
cursor mode.  The directional significance of the numeric keys in roam
mode is obvious if the terminal has a keypad, and is illustrated below.


.ks
.nf
	7   8   9	135 090 045

	4   5   6	180 000 000

	1   2   3	225 -90 -45
.fi
.ke


There is a fixed upper limit on the size of the cursor mode frame buffer.
If the frame data overflows the frame buffer while plotting the plot will
still come out correctly, but only the final plotting instructions will be
retained in the buffer.  Redisplay of the frame in cursor mode will thus
result in only a portion of the full frame being drawn.  If this is a problem
the user can increase the upper limit on the size of the frame buffer by
setting the value of the environment variable \fBcmbuflen\fR, e.g.,

	gflush; set cmbuflen = 512000

would initialize the graphics system (freeing the old frame buffer) and set
the upper limit on the size of the frame buffer to 512K words or 1Mb.

.nh 2
Example

    At this point a brief example may help to illustrate the use of the GIO
procedures.  The following procedure will plot a data vector (pixel array)
and then repeatedly read the cursor, drawing a mark at successive positions
of the cursor.  The procedure exits if the user types either the character
'q' or EOF, e.g., <ctrl/z> or carriage return.


.ks
.nf
	include	<gset.h>

	# MARKPLOT -- Plot a data array and then enter a loop, drawing
	# circles at successive cursor positions.

	procedure markplot (data, npts, x1, x2)

	real	data[npts]		# data vector to be plotted
	int	npts			# length of array
	real	x1, x2			# world X-coords of vector

	pointer	gp
	int	wcs, key
	char	str[32]
	real	wx, wy
	pointer	gopen()
	int	clgcur()

	begin
		gp = gopen ("stdgraph", NEW_FILE, STDGRAPH)

		call gploto (gp, data, npts, x1, x2, "data")

		while (clgcur ("points", wx, wy, wcs, key, str, 32) != EOF)
		    if (key == 'q')
			break
		    else
			call gmark (gp, wx, wy, GM_CIRCLE, 1., 1.)

		call gclose (gp)
	end
.fi
.ke

.nh 2
Graphics Output Devices

    While the graphics output device may be specified explicitly by name,
more often graphics output devices will be specified by one of the logical
device names shown below.  Examples of the installation dependent device name
associated with each logical name are also shown.


.ks
.nf
	stdgraph	= "gterm"
	stdimage	= "deanza"
	stdplot		= "qms"
	stdvdm		= "uparm$vdm"
.fi
.ke


Interaction (via the CL) is supported only for \fBstdgraph\fR and
\fBstdimage\fR.  The standard batch plotter device is \fBstdplot\fR,
and the standard metafile (for spooling graphics output) is \fBstdvdm\fR.

The user should not normally set the value of \fBstdgraph\fR directly with
\fIset\fR, rather they should set the terminal type with \fIstty\fR and let
the latter specify the value of \fBstdgraph\fR.  If the terminal specified
is not a graphics terminal (no ":gd" capability in the termcap entry for the
device) the value of \fBstdgraph\fR will be set to "none", otherwise
\fBstdgraph\fR will be set to the name of the stdgraph device entry for the
graphics terminal.

The device name associated with a logical graphics output
device must have an associated entry in the \fBgraphcap\fR file,
a text file used to describe the characteristics of each device.
New graphcap entries may easily be added by the user to interface to
special graphics devices.
System privledge is not required to modify graphcap, since the name
of the graphcap file is taken from a CL environment variable of the
same name (which can be redefined by the user to point to a file in a
private directory).  The graphcap entries for the most commonly used
devices at a given site may be precompiled by the system manager to
eliminate the overhead of searching the graphcap file at \fBgopen\fR time.

The graphcap parameters (device \fIcapabilities\fR) are too involved to
be presented here and will be described in a later section.
Examples of device capabilities are the device resolution, whether a frame
advance is required before or after a plot, indication of device capabilities
such as the ability to generate text, and the name of the executable
graphics kernel file associated with the device.  Many additional parameters
are defined for interactive devices.  The graphcap device capabilities
may be inspected with the \fBgget[birs]\fR procedures, which resolve into
calls to the TTY interface, used to access both graphcap and termcap files.

The sequence of actions taken by GIO to access the graphcap entry for a
device is summarized below.


.ks
.nf
	if (standard graphics output device)
	    get device name from environment

	if (device name is actually a filename) {
	    load graphics device descriptor using the first device entry
		from the named graphcap format file
	} else {
	    get filename of graphcap file from environment
	    load graphics device descriptor by searching the graphcap file
		for the named device
	}
.fi
.ke

.nh 2
Graphics Input Devices

    The technique used to associate an input source with a graphics cursor
is similar to that used for output devices.  A CL environment variable is
associated with each cursor type.  The names and default values of the
environment variables are shown below.


.ks
.nf
	stdgcur		= "stdgraph"
	stdimcur	= "stdimage"
.fi
.ke


The default input source for a cursor is the graphics output device associated
with the graphics output stream.  If the cursor device is "stdgraph" or
"stdimage" the graphics kernel is called to read the physical device cursor
for \fIstdgraph\fR or \fIstdimage\fR.  If the cursor device is "text"
the cursor value is a line of text read from the user terminal.
In this mode the user enters at least two of the fields defining
a cursor value.  Missing fields are assigned the value zero (the user
presumably will know that the program does not use the extra fields).


.ks
.nf
	cl> set stdgcur = "text"
	cl> = gcur
	gcur: 345.33 23.22 1 c
	345.33 23.22 1 c
	cl>
.fi
.ke


An example of a cursor read request entered interactively by the user,
taking input from the terminal and sending output to the terminal,
is shown above (the CL typed the "gcur: " query and the user entered the
remainder of that line).  If the cursor device were "stdgraph" a real
cursor read would occur and the equivalent interaction might appear as
shown below.  The cursor position is returned in world coordinates,
where the world coordinate system was defined by the last plot output to
the device.  For an imaging device the world coordinates will typically
be the pixel coordinates of the image section being displayed.


.ks
.nf
	cl> = gcur
	345.33 23.22 1 c
	cl>
.fi
.ke


Redirecting cursor input to the terminal is useful when working from a
nongraphics workstation and when debugging programs.  ASCII cursor queries
are the only type supported when running an IRAF program outside the CL.
Cursor input may also be taken from a list file by assigning a filename
to a cursor parameter, i.e., by assigning a list file to a list structured
parameter and overriding query mode:


.ks
.nf
	cl> gcur = filename
	cl> = gcur
	345.33 23.22 1 c
	cl>
.fi
.ke


This last mechanism is a standard technique used with CL list structured
parameters and will not be discussed further here.

.NH 2
Mixed Terminal and Graphics I/O

    Interactive graphics programs are normally (but not necessarily) executed
on a graphics terminal or workstation supporting both ordinary terminal i/o
and vector graphics.  IRAF is designed to use a single terminal for both text
and graphics; text and graphics on separate devices is also supported but is
not the norm.  By text we refer here to ordinary line or screen oriented
terminal i/o (e.g., for \fIhelp\fR or \fIeparam\fR), not the use of text in
the graphics plane to annotate plots.

.NH 3
Text and Graphics Mode

    Most modern graphics terminals provide separate memory planes for text
and graphics.  Depending upon the device, these planes may be displayed
simultaneously, displayed alternately, or only a single memory plane may be
available for both terminal modes, in which case a mode switch is destructive.
The graphics device model implemented by GIO and the STDGRAPH kernel is
flexible enough to deal with all or nearly all such devices.

The normal mode for the terminal or workstation is text mode.  Activating the
workstation causes a switch to graphics mode; deactivating the workstation
restores the terminal to text mode.  Activation is implied whenever a device
is opened with \fBgopen\fR, unless the AW_DEFER mode bit is set to defer the
activate workstation until graphics i/o is actually done to the device.
Closing the workstation automatically deactivates the workstation.  The GIO
procedures \fBgreactivate\fR and \fBgdeactivate\fR are provided to simplify
mode switching while a device is open on a graphics stream.

Occasionally it is necessary to print out a large amount of text in response
to a user command entered in a cursor loop while in graphics mode.  If the
text is in a file this is done most easily by calling \fBgpagefile\fR to page
the file in text mode, restoring graphics mode when the operation is completed.
If the application generates the output text dynamically then the workstation
must be explicitly deactivated and later reactivated before resuming graphics
i/o, e.g.,

.ks
.nf
	while (clgcur (gp, ...) != EOF) {
	    switch (key) {
	    case XXX:
		call gdeactivate (gp, AW_CLEAR)
		    <write the text to STDOUT>
		call greactivate (gp, AW_PAUSE)
	    case YYY:
		...
	    }
	}
.fi
.ke

The sequence shown will switch to text mode, clear the screen, output the
text, and pause for the user to read the text before restoring graphics mode
and initiating another cursor read.

.NH 3
Status Line I/O

    The deactivate/reactivate workstation technique is fine for outputting
large amounts of text, but is not well suited for small amounts of text,
e.g., single line commands to interactively set internal parameters,
output of single lines of text to prompt the user, print the value of a
calculation or some variable, and so on.  The so-called "status line"
interface is provided for this purpose.  Status line i/o makes it possible
to interact directly with the user without interfering with the contents of
the graphics frame, and without leaving graphics mode.

What the status line actually is determined by the graphcap entry for the
device and the characteristics or limitations of the actual device.
On most devices, the status line is a single line at the bottom of the screen.
This only works, however, if the device can dynamically erase the status line;
if this is not possible the status "line" may actually be the entire screen,
with successive output lines being drawn on top of the graph.

To output text to the status line while in graphics mode one merely writes to
STDOUT or STDERR in the usual way, e.g., in a call to \fBprintf\fR.  When
newline is seen a flag is set which causes the status line to be cleared when
the next output character is received.  Output lines may be built up in
successive calls to output procedures, outputting a single newline to terminate
the line and start a new one.  After a newline delimited line of text has been
output, output of a single newline (blank line) will clear the status line.

It is also possible to read from the status line.  This is most commonly done
after writing a prompt string to the status line.  The prompt should be
terminated with a colon (e.g., "enter value: ") rather than a newline,
to signal to the user that input is expected, and to avoid having the
subsequent status line read clear the prompt string.  In many cases such
explicit prompting and decoding of the return string can be avoided by using
the standard CLIO parameter prompting mechanism for interactive input.
CL parameter prompts are also permitted in graphics mode, and will interact
with the user on the status line in the expected way, without interfering
with the graphics state of the device.

When mixing status line i/o and graphics i/o one must be careful to flush any
buffered graphics or textual output before switching modes.  In many cases the
system will do this for you automatically, but there are exceptions where
explicitly flushing of buffered output is necessary (e.g., STDOUT and STDERR
are low level facilities with no knowledge of GIO, and output to one of these
streams will not automatically cause any graphics output to be flushed).

.NH 2
User Interface Conventions

    While different interactive (cursor driven) graphics programs will differ
in many ways, there are certain operations which are common to all such
programs.  In order to present a more consistent interface to the user,
conventions have been defined for these common operations.

.NH 3
On Line Help

    All interactive graphics programs should respond to the key '?' with a
description of the keystrokes and colon commands recognized by the program
(or submenu, in the case of a menu structured interface).  This is normally
done by calling \fBgpagefile\fR to interactively page the ".key" keystrokes
help file for the program.  The keystroke files for system programs are
stored in the directory lib$scr; non-system programs keep their keys files
either in the package directory, or in a global package library.

.NH 3
Cursor and Device Names

    In general, applications programs should not read directly from \fBgcur\fR
or \fBimcur\fR (the global cursor parameters), nor should the open the
"stdgraph", "stdimage", or "stdplot" device directly by these explicit string
values.  This works, but is inflexible.  To make it easy for the user to
run an otherwise interactive program in batch mode, taking input from a cursor
list file, the task should include a cursor type parameter in its parameter
set.  Likewise, to make it easy for the user to temporarily redirect the
output of the program to a device other than the current stdgraph, stdplot,
etc., device, the device name should be parameterized as a string type CL
parameter.

For example, if task \fBplotit\fR  has cursor and device parameters named
"cursor" and "device", the command

	cl> plotit cursor=listfile device=qms

would run the task taking cursor input from the text file "listfile", with
stdgraph graphics output directed to the plotter device "qms".

.NH 3
Exiting an Interactive Cursor Loop

    The following standards have been defined for dealing with EOF/quit in
interactive cursor loops.
.ls
.ls EOF	
End of file is indicated for a cursor list either by an actual
end of file in the case of a true cursor list, or by typing the EOF character
(e.g., <ctrl/z>, <ctrl/d>, or the interrupt character) in an interactive
cursor read.  EOF on the cursor list should be taken seriously by the
applications program, and not treated as just another key, hence it should
not be something that the user is expected to type routinely to exit a cursor
loop.  If a program gets EOF back as the value of \fBclgcur\fR it should exit
immediately, without any verification queries etc, since it may well have
been run in batch mode with input redirected to a cursor list file.
.le
.ls q
The standard interactive cursor loop exit character is 'q'.  
All interactive graphics programs should recognize this character
and take some action to exit the cursor loop, e.g.:

.ks
.nf
	while (clgcur (...) != EOF)
	    switch (key) {
	    case 'q':
		break
	    case ...
.fi
.ke

The 'q' character is intended to be handled directly by the application
program, rather than mapped into EOF by the system (like Q was, and CR and
the gt_gcur 'q' before that in old versions of IRAF),
to distinguish this case from a hard-EOF and to provide maximum
flexibility in how the program treats a request from the user to exit.
If the user would suffer from an accidental program exit then the 'q' key
action should do something before exiting, e.g., ask that the user first
update the database, ask that CR be hit to verify the quit, and so on.
In general, if it would take the user more than a minute to recover after
an accidental program exit, one should consider coding some sort of
verification action to be executed before exiting when 'q' is typed (but not
when EOF is seen on the list).
.le
.le

The GIO procedure \fBgqverify\fR is provided for programming convenience in
cases where only simple verification is desired.  Note that lightweight tasks
or submenus which can easily be reentered should not bother even with this,
but should simply exit.  For example:

.ks
.nf
	case 'q':
	    if (gqverify() == YES)
		break
.fi
.ke

As a more complex example, suppose the program is used to edit or
create a database which could be lost or damaged in an accidental
exit, if not updated first.  We do not want to update the database
automatically because this would overwrite the former contents of
the database.  The program might be set up as follows.

.ks
.nf
	'q'		program prints error message on status line, e.g.,
			  "No write since last change (:quit! overrides)"
	:w[rite]	updates the database; q will execute silently
	:q[uit]!	force a quit w/o an update; discard changes
.fi
.ke

.nh 2
Detailed Procedure Specifications

    The graphics output procedures provided by GIO fall into four main
groups.  First are the high level "plot at a time" procedures,
used to plot entire data vectors.  Second are the control procedures,
used to open and close a device, to flush output and clear the screen,
and to cancel output in the event of an interrupt.
Third are the procedures used to set and stat (inquire) the GIO
internal parameters, e.g. to define a WCS, change pens, select axis labeling
options, or inquire the device resolution.  Fourth and last are the output
procedures, used to draw and label the axes of a viewport, set the cursor,
draw lines or marks, plot text, or fill areas.

.nh 3
High Level Procedures
.ls 4
.tp 8
.ls gplotv (v, npts, x1, x2, title)

.nf
real	v[npts]		# data vector
int	npts		# number of data points
real	x1, x2		# WC assigned v[1] and v[npts]
char	title[ARB]	# plot title
.fi

Open GIO, clear the screen, autoscale and plot the data vector, then close GIO.
A default viewport is used.  The axes are drawn, tick marks are selected,
marked, and labeled, and the plot title is printed.  The data is plotted
using solid line segments.  The X values of the data points are evenly
distributed from X1 to X2.
.le

.tp 8
.ls gploto (gp, v, npts, x1, x2, title)

.nf
pointer	gp		# graphics descriptor
real	v[npts]		# data vector
int	npts		# number of data points
real	x1, x2		# WC assigned v[1] and v[npts]
char	title[ARB]	# plot title
.fi

A more flexible version of \fBgplotv\fR.  The graphics device must already
have been opened with an explicit call to \fBgopen\fR.  The explicit open
call makes it possible to append to an existing plot or to change plotting
options with calls to \fBgset\fR before calling \fBgploto\fR to autoscale,
draw the axes, and plot the data vector.  Annotation of the plot via calls
to the low level output primitives is possible before a final call to
\fBgclose\fR to close the device and free the graphics descriptor.
.le

.tp 8
.ls gpagefile (gp, fname, prompt)

.nf
pointer	gp		# graphics descriptor
char	fname[ARB]	# file to be paged
char	prompt[ARB]	# end of page prompt string
.fi

Interactively page through a file on the terminal in text mode, e.g., to
display help text in response to the '?' standard help query key.
The workstation is deactivated, the screen is cleared and the file is paged,
with the usual file pager prompt being displayed at the bottom of each page
of text.  When the pager is exited the workstation is reactivated if it was
active when the pager was called.  If the prompt string is null the file
name is used.
.le
.le

.nh 3
Control Procedures
.ls
.tp 8
.ls gopen (device, mode, fd)

.nf
char	device[ARB]	# name of device to be opened
int	mode		# access mode
int	fd		# graphics stream to be written
.fi

The named graphics device is opened for graphics i/o.  A pointer to the GIO
graphics descriptor assigned to the device is returned as the function value.
The device name may be the name of one of the standard logical graphics
devices, i.e., \fBstdgraph\fR, \fBstdimage\fR, \fBstdplot\fR, or \fBstdvdm\fR,
or the actual name of a physical device.

The only meaningful device access modes at present are NEW_FILE and APPEND.
In NEW_FILE mode all WCS are initialized to NDC coordinates.
Opening the stdgraph device in NEW_FILE mode causes a screen clear on the next
call to \fIgflush\fR.  In APPEND mode the WCS are restored to the values they
had when the device was last accessed.
The GIO internal state variables are initialized to their default values
at \fBgopen\fR time regardless of the access mode for the device.

Opening the stdgraph device causes an implicit reactivate workstation unless
the AW_DEFER flag (<gset.h>) is set in the access mode, e.g.,

	gp = gopen (device, NEW_FILE+AW_DEFER, fd)

Defer mode allows the graphics descriptor to be opened once, e.g., during task
startup, before any graphics output is required.  This is sometimes useful in
applications which switch back and forth between text and graphics mode often,
by bracketing each graphics sequence with calls to \fIgreactivate\fR to enter
graphics mode, and \fIgdeactivate\fR to return to text mode.  Defer mode may
be combined with any normal access mode code.

Graphics output will be written to the stream \fIfd\fR, which may be one
of the standard streams STDGRAPH, STDIMAGE, or STDPLOT, or to a binary file
opened explicitly by the user before calling \fBgopen\fR.
.le

.tp 5
.ls gclose (gp)

The graphics device associated with graphics descriptor \fBgp\fR is closed,
freeing all resources allocated to the device.  Any buffered graphics output
is automatically flushed before closing the device.
.le

.tp 4
.ls gdeactivate (gp, flags)

.nf
pointer	gp		# graphics descriptor
int	flags		# AW_CLEAR, AW_PAUSE (see <gset.h>)
.fi

The graphics workstation is deactivated, i.e., restored to the normal terminal
(text drawing) mode, the state the terminal was in prior to \fIgopen\fR, and to
which it will be restored after a \fIgclose\fR.  This function is intended for
interactive graphics applications and may be may be ignored by some graphics
kernels.  If the AW_PAUSE flag bit is set the user will be asked to type a
key before the terminal is restored to text mode.  If the AW_CLEAR flag bit
is set the terminal (text) screen will be cleared after the workstation is
deactivated.

.le

.tp 4
.ls greactivate (gp, flags)

.nf
pointer	gp		# graphics descriptor
int	flags		# AW_CLEAR, AW_PAUSE (see <gset.h>)
.fi

The graphics workstation is reactivated, i.e., restored to graphics mode from
the normal terminal (text drawing) mode.  This function is intended for
interactive graphics applications and may be may be ignored by some graphics
kernels.  If the AW_PAUSE flag bit is set the user will be asked to type a
key before the terminal is restored to graphics mode.  If the AW_CLEAR flag
bit is set the graphics frame will be cleared.
.le

.tp 4
.ls gcancel (gp)

Any buffered graphics output is discarded and any output operation currently
in progress is aborted.  Used to recover from an interrupt.
.le

.tp 3
.ls gflush (gp)

Any buffered graphics output is flushed to the output device.
.le

.tp 4
.ls gclear (gp)

If the output device is a CRT the screen is erased (including all viewports).
If the output device is a plotter a formfeed is issued, advancing to the next
page of output (whether or not any graphics output has occurred).
All WCS are initialized to NDC coordinates and the internal state of GIO
is initialized, i.e., the state of each drawing instruction attribute packet
is set to UNSET to force retransmission to the graphics kernel as i/o occurs,
and the current settings of the \fIgset\fR options, e.g., line style and width,
\fIglabax\fR options, etc., are all initialized to their default (\fBgopen\fR)
values.
.le

.tp 4
.ls gframe (gp)

Issue a screen clear or frame advance.  This call is equivalent to \fBgclear\fR
except that the internal state of GIO is not initialized.  An application
might want to call \fBgframe\fR and \fBgreset\fR directly rather than using
\fBgclear\fR, if the full initialization implied by \fBgclear\fR is not what
is desired.
.le

.tp 4
.ls greset (gp, flags)

.nf
pointer	gp		# graphics descriptor
int	flags		# bitflags noting what to reset (0 is a no-op)
.fi

The \fBgreset\fR may be used to reset all or parts of the internal state of
GIO, without actually doing any i/o to the graphics device.  The \fIflags\fR
argument is used to specify what is to be reset.  The bitflags (defined in
<gset.h>) are enumerated below.

.nf
	GR_RESETALL		reset everything
	GR_RESETGIO		reset only GIO drawing parameters
	GR_RESETWCS		reset the WCS to wcs=1, all NDC
	GR_RESETGLABAX		reset the GLABAX parameters
.fi

A \fBgclear\fR is equivalent to a \fBgframe\fR followed by a
greset(gp,GR_RESETALL).
.le

.tp 8
.ls gmftitle (gp, mftitle)

.nf
pointer	gp		# graphics descriptor
char	mftitle[ARB]	# comment (metafile title string)
.fi

Place a comment describing the graphics being generated in the output
stream.  Useful primarily when the output is expected to be saved in a
metafile.  No graphics is generated.
.le
.le

.nh 3
Set and Stat Procedures
.ls
.tp 8
.ls gscan (gp, text)  [NOT YET IMPLEMENTED]

.nf
pointer	gp		# graphics descriptor
char	text[ARB]	# graphics commands
.fi

The string \fBtext\fR, consisting of an arbitrary length sequence of
printable ASCII graphics commands delimited by semicolons or newlines,
is interpreted and executed by GIO.  Each GIO procedure has a corresponding
command of the same syntax, minus the parenthesis, commas, and the argument
\fBgp\fR.  The syntax of a \fBgset\fR command is "param=value".
File inclusion is provided by the operator "@" followed by the filename
of the file to be included.
The include operator may appear anywhere a token is expected and includes
may be nested up to some maximum depth.
The sequence "@STDIN" is especially useful for entering commands or data
interactively.
.le

.tp 8
.ls gset[irs] (gp, param, value)

.nf
pointer	gp		# graphics descriptor
int	param		# parameter to be set
[irs]	value		# new value for parameter
.fi

Set the value of the indicated parameter.  A separate procedure is used for
integer, real, and string valued parameters, i.e., gseti, gsetr, gsets.
GIO parameters may be either internal state variables (e.g. the number of
ticks on an axis) or device parameters (e.g. the number of the pen to be
used to draw lines).
The GIO parameters are defined in the global include file \fB<gset.h>\fR.
.le

.tp 10
.sp
.nf
gstati (gp, param)
gstatr (gp, param)
gstats (gp, param, outstr, maxch)
.fi
.ls
.nf
pointer	gp		# graphics descriptor
int	param		# parameter to be set
char	outstr[maxch]	# output string
.fi

Inquire the value of the indicated GIO internal parameter.
The integer and real functions \fBgstati\fR and \fBgstatr\fR return
the parameter value as the function value, whereas \fBgstats\fR is
a procedure returning the string value of a parameter as an output argument.
The GIO parameters are defined in the global include file \fB<gset.h>\fR.
.le

.tp 11
.sp
.nf
ggetb (gp, cap)
ggeti (gp, cap)
ggetr (gp, cap)
ggets (gp, cap, outstr, maxch)
.fi
.ls
.nf
pointer	gp		# graphics descriptor
char	cap[2]		# device capability
char	outstr[maxch]	# output string
.fi

Inquire the value of the indicated graphics device capability.
The device capability \fIcap\fR is the two character name of the capability
as it appears in the \fIgraphcap\fR file.  Aside from the device capabilities
required by GIO, GIO itself knows nothing about the graphcap device
capabilities.  New capabilities may be added without modifying GIO.
The \fBgget\fR procedures call the corresponding procedures in the TTY
interface.  If more control over device capabilities is required than
that provided by GIO, the TTY interface may be used directly, following a
call to \fBgstati\fR to get the pointer to the TTY descriptor for the device.

The boolean function \fBggetb\fR tests whether the device has the named
capability.  The integer and real functions \fBggeti\fR and \fBggetr\fR return
the capability value as the function value, or zero if the capability is
not defined for the device.  String valued capabilities are returned by
\fBggets\fR as an output argument; the null string is returned if the
device does not have the indicated capability.
.le

.tp 8
.ls g[sg]view (gp, x1, x2, y1, y2)

.nf
pointer	gp		# graphics descriptor
real	x1, x2		# range of NDC coordinates in X
real	y1, y2		# range of NDC coordinates in Y
.fi

Set or get the NDC coordinates of the viewport associated with the current WCS.
The default viewport is the full display area of the device.
.le

.tp 8
.ls g[sg]wind (gp, x1, x2, y1, y2)

.nf
pointer	gp		# graphics descriptor
real	x1, x2		# range of world coordinates in X
real	y1, y2		# range of world coordinates in Y
.fi

Set or get the world coordinates of the window associated with the current WCS.
The default window ranges from 0 to 1 in both X and Y, i.e., the default
window associates a normalized coordinate system with the associated viewport.
Any window limits passed as INDEF will be ignored, i.e., those window
parameters will not be modified.
.le

.tp 9
.ls g[ar]scale (gp, v, npts, axis)

.nf
pointer	gp		# graphics descriptor
real	v[npts]		# data vector window is to be scaled to
int	npts		# length of data vector
int	axis		# axis to be scaled (1=X, 2=Y).
.fi

Set absolute (\fIgascale\fR) or rescale (\fBgrscale\fR) the minimum and
maximum world coordinates of the indicated axis of the current window,
i.e., scale the window to fit a data vector.
May be called repeatedly if overplotting several curves.  The current minimum
and maximum values for either axis may be obtained at any time by calling
\fBggwind\fR.  To scale the window to fit a family of curves,
call \fBgascale\fR for the first curve and \fBgrscale\fR for the remaining
curves, thereby computing the range in X and or Y of all curves.
.le

.tp 9
.ls ggscale (gp, x, y, dx, dy)

.nf
pointer	gp		# graphics descriptor
real	x, y		# point at which scale is desired (wc)
real	dx, dy		# scale, wcs units per ndc unit
.fi

Determine the scale in world coordinate units at the point (x,y).  Useful
for computing the size of an object in world coordinates given its size
in ndc coordinates, or vice versa.  An approximation is used to determine
the scale if log scaling is in use.  Note that the scale is a function of
position for the nonlinear coordinate systems.
.le

.tp 9
.ls gctran (gp, x1, y1, x2, y2, wcs1, wcs2)

.nf
pointer	gp		# graphics descriptor
real	x1, y1		# input point in WCS1 coords
real	x2, y2		# output point in WCS2 coords
int	wcs1, wcs2	# input, output world coordinate systems
.fi

Transform a point in world coordinate system \fIwcs1\fR to world coordinate
system \fIwcs2\fR.  If \fIwcs1\fR is zero the transformation is from NDC
coordinates to WCS coordinates.  If \fIwcs2\fR is zero the transformation is
from WCS coordinates to NDC coordinates.  Otherwise the transformation is
between two user defined world coordinate systems.  The point need not fall
within the viewports of the two world coordinate systems.  World coordinate
systems which were never set are equivalent to WCS=0.
.le

.tp 9
.ls gcurpos (gp, x, y)

.nf
pointer	gp		# graphics descriptor
real	x, y		# current pen position in world coordinates
.fi

Return the "current pen position" in the current world coordinate system.
The current pen position is the position set by the last move or draw
command.
.le

.tp 10
.ls gescape (gp, fn, instruction, nwords)

.nf
pointer	gp		# graphics descriptor
int	fn		# function code
short	instruction[nwords]	# instruction sequence to be passed
int	nwords		# length of instruction sequence
.fi

Send a device dependent instruction sequence to the graphics kernel.
Escape functions are ignored by GIO and by graphics kernels that do
not recognize the function code.
.le
.le

.nh 3
Output Procedures

    Data passed to the polyline or polymarker output procedures may contain
embedded INDEF (indefinite) values in the X, Y, or V arrays.  Indefinite valued
points appear as gaps in the plot and are ignored when autoscaling.
Indefinite valued pixels are not permitted in a cell array since GIO does
not look at the values of the pixels.

.ls
.tp 9
.ls glabax (gp, title, xlabel, ylabel)

.nf
pointer	gp		# graphics descriptor
char	title[ARB]	# plot title
char	xlabel[ARB]	# X axis label
char	ylabel[ARB]	# Y axis label
.fi

Draw and label the axes of the viewport.
If the WCS has not yet been fixed it will be fixed by this call.
If desired, \fBglabax\fR may modify the window slightly to place
simple values on the tick marks.  Numerous \fBgset\fR options are
available for controlling the number and sizes of the tick marks,
the format of tick labels, the axes on which tick labels appear,
and so on.  If the device viewport has not yet been set and axis labeling
is enabled, \fBglabax\fR will set a default size viewport which allows room
for the label text outside the viewport.
.le

.tp 8
.ls gline (gp, x1, y1, x2, y2)

.nf
pointer	gp		# graphics descriptor
real	x1, y1		# start of line
real	x2, y2		# end of line
.fi

Draw a line connecting the point (x1,y1) to the point (x2,y2) (WCS coordinates).
The linetype, linewidth, and color may be changed beforehand with a call
to \fBgset\fR.  The relevant parameters and their possible values are shown
below.  Linetype zero (clear) may be used to erase lines drawn with any of the
other linetypes (device permitting).

.ks
.nf
	G_PLTYPE	0=clear, 1=solid, 2=dashed, 3=dotted,
			    4=dotdash, >4=device dependent
	G_PLWIDTH	relative line width (default 1.0)
	G_PLCOLOR	color index
.fi
.ke
.le

.tp 8
.ls gpline (gp, x, y, npts)

.nf
pointer	gp		# graphics descriptor
real	x[npts]		# X coordinates of the line endpoints
real	y[npts]		# Y coordinates of the line endpoints
int	npts		# number of line endpoints
.fi

Polyline.  Draw a line connecting the points (WCS coordinates).
The linetype, linewidth, and color may be changed beforehand with a call
to \fBgset\fR.
.le

.tp 8
.ls gvline (gp, v, npts, x1, x2)

.nf
pointer	gp		# graphics descriptor
real	v[npts]		# vector to be plotted (Y values)
int	npts		# number of line endpoints
real	x1, x2		# range of vector in X 
.fi

Vector polyline.  Draw a polyline wherein the Y values of the polyline are
taken from V and the X values are evenly distributed along the X-axis,
ranging from X1 at point V[1] to X2 at point V[npts] (WCS coordinates).
.le

.tp 9
.ls gmark (gp, x, y, marktype, xsize, ysize)

.nf
pointer	gp		# graphics descriptor
real	x, y		# WCS coordinates of marker
int	marktype	# marker type
real	xsize, ysize	# marker sizes
.fi

Mark drawing primitive.  Draw a mark of type \fImarktype\fR and size
\fImarksize\fR at the given position in WCS coordinates.
The marker type codes recognized are shown below and are defined in <gset.h>.
Marktype codes may be summed to make composite marks, e.g.,

	call gmark (gp, x, y, GM_PLUS+GM_CROSS, 1.)

is an asterisk.  The pseudo-mark GM_FILL may be combined with GM_CIRCLE,
GM_BOX, or GM_DIAMOND to output the mark as a filled area, using the current
fill area attributes.  A positive \fImarksize\fR specifies the mark size in NDC
coordinates, whereas negative signifies WCS coordinates.
The positive marksizes 1., 2., 3., and 4. signify default size marks of
increasing size.

.ks
.nf
    typecode      name                symbol

	0 	GM_POINT	smallest plottable point
        1	GM_FILL		fill interior of mark
	2	GM_BOX		square box
        4	GM_PLUS		plus
	8	GM_CROSS	cross
       16	GM_DIAMOND	diamond
       32	GM_HLINE	horizontal line
       64	GM_VLINE	vertical line
      128	GM_HEBAR	horizontal error bar
      256	GM_VEBAR	vertical error bar
      512	GM_CIRCLE	circle
.fi
.ke

The linetype for a mark is set by the parameter G_PMLTYPE.  A mark may
be erased (device permitting) by setting the marker linetype to clear and
redrawing the mark.  The color index used for marks is controlled by the
\fBgset\fR parameter G_PMCOLOR.
.le

.tp 9
.ls gpmark (gp, x, y, npts, marktype, xsize, ysize)

.nf
pointer	gp		# graphics descriptor
real	x[npts]		# WCS X coordinates of markers
real	y[npts]		# WCS Y coordinates of markers
int	npts		# number of markers
int	marktype	# marker type
real	xsize, ysize	# marker sizes
.fi

Polymarker.  Plot a sequence of \fInpts\fR markers at the positions given
by successive WCS coordinate pairs (x[i],y[i]).  All markers will be of
the same type and size.  The significance of the marker type and size codes
is the same as for \fBgmark\fR.
.le

.tp 9
.ls gvmark (gp, v, npts, x1, x2, marktype, xsize, ysize)

.nf
pointer	gp		# graphics descriptor
real	v[npts]		# WCS Y coordinates of markers
int	npts		# number of markers
real	x1, x2		# range of WCS X coordinates
int	marktype	# marker type
real	xsize, ysize	# marker sizes
.fi

Vector polymarker.  Plot a sequence of \fInpts\fR markers at the positions given
by successive WCS coordinate pairs (x[i],y[i]), where the x[i] are evenly
distributed from X1 at V[1] to X2 at V[npts].  All markers will be of the same
type and size.  The significance of the marker type and size codes is the same
as for \fBgmark\fR.
.le

.tp 11
.ls gumark (gp, x, y, npts, xcen, ycen, xsize, ysize, fill)

.nf
pointer	gp		# graphics descriptor
real	x[npts],y[npts]	# normalized polyline defining marker
int	npts		# number of points in polyline
real	xcen, xcen	# world coordinates of center of marker
real	xsize, ysize	# marker size in X and Y
int	fill		# draw mark using area fill
.fi

Draw a user defined marker.  The marker is defined by the polyline (X[i],Y[i]),
normalized to the unit square.  The marker polyline is scaled to fit the
window defined by \fIxcen\fR, \fIycen\fR, \fIxsize\fR, and \fIysize\fR,
where the center is always defined in world coordinates but the marker sizes
may be defined in any of a number of ways (see \fBgmark\fR).  If \fIfill\fR
is YES the marker will be drawn using area fill rather than as a polyline.
.le

.tp 8
.ls g[ar]move (gp, x, y)

.nf
pointer	gp		# graphics descriptor
real	x, y		# WCS coordinates to move or shift
.fi

Move absolute (\fBgamove\fR) or move relative (\fBgrmove\fR),
with the "pen up".  A move relative should be preceded by a move absolute
to unambiguously define the "current pen position" in WCS coordinates.
Only the move, draw, and mark primitives leave the pen in a defined position.
Calls to \fBgset\fR may be intermixed with move and draw commands without
affecting the current pen position.
.le

.tp 8
.ls g[ar]draw (gp, x, y)

.nf
pointer	gp		# graphics descriptor
real	x, y		# WCS coordinates to move or shift
.fi

Move absolute (\fBgadraw\fR) or move relative (\fBgrdraw\fR),
with the "pen down".  Draws a line segment.
The type of line drawn (linetype or "pen number") defaults to solid but
may be changed beforehand with a call to \fBgset\fR.
Calls to \fBgset\fR may be intermixed with move and draw commands without
affecting the current pen position.
.le

.tp 9
.ls gtext (gp, x, y, text, format)

.nf
pointer	gp		# graphics descriptor
real	x, y		# WCS coordinates of text string
char	text[ARB]	# text to be plotted
char	format[ARB]	# text characteristics
.fi

Plot the string \fItext\fR at the position (x,y) in WCS coordinates.
The default size, orientation, and justification of the generated string 
may be set by a prior call to \fBgset\fR or overridden for the duration
of the current call by the \fIformat\fR string.  A null format string
is permtted.


.ks
.nf
          keyword               values                 default

        up	        degrees ccw, zero = +x          90
        size            character size scale factor	1.0
        path	        left,right,up,down              r
        hjustify        normal,center,left,right	l
        vjustify        normal,center,top,bottom        b
	font		roman,greek,italic,bold		r
	quality		normal,low,medium,high		n
	color		integers greater than one	1
.fi
.ke


The attributes controlling how text is generated are shown above.
The character up vector (attribute \fIup\fR) defines the horizontal and
vertical axes (the horizontal axis is perpendicular to the character up
vector).  Directions left and right, up and down are relative to these axes.
The attribute \fIpath\fR defines the direction in which characters are
to be plotted.  The attribute \fBquality\fR makes it possible to choose
between low or medium quality (fast) and high quality (expensive) character
generation techniques, e.g., hardware versus software character generation.
This attribute is normally best set to "normal" and then overridden at
metafile translation time.

The attributes are set in the format string by a semicolon delimited list of
keyword=value constructs.  Only the first character of keyword and value
strings is significant, i.e., keywords and values may be abbreviated to as
little as one character if desired.  For example, the format "p=d;v=c"
would plot characters downward in a vertical string centered at the position
given.

The default font is set by the font attribute at the beginning of each call.
Font changes may also be signaled by placing the sequence "\fF" in the text,
where F is one of the characters RGIB, denoting the fonts roman, greek,
italic, and bold.  In this manner the font may change from character
to character within a single line of text.  Additional escape sequences may
be added to represent special symbols.
.le

.tp 10
.ls gfill (gp, x, y, npts, style)

.nf
pointer	gp		# graphics descriptor
real	x[npts]		# X coordinates of polygon
real	y[npts]		# Y coordinates of polygon
int	npts		# number of vertices of polygon
int	style		# type of fill
.fi

Area fill.  The points (x[i],y[i]) define a closed area which will be filled
in the indicated \fIstyle\fR.  The recognized style codes, defined in <gset.h>,
are:

.ks
.nf
	0	GF_CLEAR	clear area
	1	GF_HOLLOW	draw only outline of area
	2	GF_SOLID	fill area with a color
       3-6	GF_HATCH[1234]	fill area with a pattern
       7-N			device dependent
.fi
.ke

If the device can support multiple colors the color index for area fill may
be set beforehand with a call to \fBgset\fR to set the parameter G_FILLCOLOR.
.le

.tp 10
.ls gpcell (gp, m, nx, ny, x1, y1, x2, y2)

.nf
pointer	gp		# graphics descriptor
short	m[nx,ny]	# greylevels or colors (pixels)
int	nx, ny		# number of pixels in X and Y
real	x1, y1		# lower left corner of output area
real	x2, y2		# upper right corner of output area
.fi

Output a cell array.
Map each pixel in the input array into the corresponding area
of the output device.  For maximum efficiency the resolution of M should
match that of the area of the output device defined by the window (x1,y1)
and (x2,y2), otherwise M is subsampled or replicated to best fill the output
area.  The aspect ratio of a pixel need not be preserved in the mapping.
The pixel values (greylevels or color indices) are passed on to the kernel
without modification.
.le

.tp 7
.ls gscur (gp, x, y)

.nf
pointer	gp		# graphics descriptor
real	x, y		# new cursor position
.fi

Move the device cursor to the indicated position (WCS coordinates).
.le
.le

.nh 3
Input Procedures

    Input procedures are available for cursor and pixel input.  Inquiry of GIO
parameters and device capabilities is handled by the \fBgstat\fR and \fBgget\fR
procedures and is not considered graphics input.

.ls
.tp 8
.ls clgcur (param, wx, wy, wcs, key, strval, maxch)

.nf
char	param[ARB]	# CL parameter to be input
real	wx, wy		# world coordinates of cursor event
int	wcs		# index of WCS selected
int	key		# keystroke value of cursor event
char	strval[maxch]	# string value if set option (key = ':')
int	maxch		# max chars to be returned in strval
.fi

The next value of the list structured CL cursor type parameter \fIparam\fR
is read and the cursor coordinates in WCS units are decoded and returned
as output arguments, along with the WCS number and the keystroke value,
i.e., the character typed by the user causing the cursor to be read.
The range of keystroke values is the full ASCII character set, minus a system
dependent subset of control codes (if a physical cursor is read, the read is
always terminated by the user typing a key on the user terminal).
No GIO device need be open to read the cursor.  EOF is returned as the
function value when the end of the cursor list is reached.
The number of output arguments successfully decoded is returned as the
function value for a normal read.  Values not converted are set to zero.
.le

.tp 8
.ls ggcur (gp, sx, sy, key)

.nf
pointer	gp		# graphics descriptor
real	sx, sy		# NDC coordinates of cursor event
int	key		# keystroke value of cursor event
.fi

The physical cursor of the graphics device associated with graphics
descriptor \fIgp\fR is read and the cursor coordinates in NDC units are
returned as output arguments, along with the keystroke value, i.e.,
the character typed or button pushed causing the cursor to be read.
On many devices the cursor read will be instantaneous (the cursor position
will be sampled), and the keystroke value will always be zero.  The range
of possible keystroke values is device dependent.  EOF is returned as the
function value when the end of the cursor list is reached.  An error action
is taken if the device is not readable.  The GIO device must have previously
been opened with \fBgopen\fR.

Use of this low level procedure is not recommended since it forces a program
to be used interactively, operation is device dependent, and cursor mode
interaction is not supported.  The main uses for \fBggcur\fR are cursor input
from special graphics devices, i.e., devices other than \fBstdgraph\fR or
\fBstdimage\fR, and continuous sampling of the cursor position on devices
which support it.  The characteristics of the device cursors are described
in the graphcap entry for the device.
.le

.tp 10
.ls ggcell (gp, m, nx, ny, x1, y1, x2, y2)

.nf
pointer	gp		# graphics descriptor
short	m[nx,ny]	# output pixel array
int	nx, ny		# number of pixels out in X and Y
real	x1, y1		# lower left corner of input area
real	x2, y2		# upper right corner of input area
.fi

Input a cell array.  The cell array defined by the rectangular window
from point (x1,y1) to (x2,y2) is read into the output array M of size
NX columns by NY lines.
For maximum efficiency the resolution of the output array should match
that of the device area defined by the input window.
If the resolution of the output array does not match that of the device
output lines will be subsampled or replicated to best fit the output array.
Unaddressable pixels are returned as negative values.  An error action is
taken if the device is not readable.
.le
.le

.nh 2
GIO Internal Parameters

    The GIO internal parameters may be set with either a \fBgset\fR or
\fBgscan\fR call, and inspected with a \fBgstat\fR function call.
Parameters are identified to \fBgset\fR and \fBgscan\fR by an integer
code.  Each integer code is assigned a symbolic name of the form G_PARAM
in the include file <gset.h>.  In input to \fBgscan\fR, parameters are
referred to by name in lower case, without the "g_" prefix.  The parameters
and their default values are shown below.


.tp 5
.nf
        \fBparameter     default            description\fR

	wcs		1	index of current WCS
	xtran		linear	linear, log, or nlog (WCS attribute)
	ytran		linear	linear, log, or nlog (WCS attribute)
	clip		yes	clip at viewport boundary (WCS attribute)
	cursor		1	current cursor number
	pltype		1	polyline linetype
	plwidth		1.0	polyline relative line width
	plcolor		1	polyline color index
	pmltype		1	polymarker linetype
	pmcolor		1	polymarker color index
	szmarker[1-4] (.5:2)*ch	standard marker sizes, NDC coordinates
	fastyle		1	fill area interior style
	facolor		1	fill area color index
	txsize		1.0	relative character size
	txup		90	character up vector
	txpath		right	direction in which characters are drawn
	txspacing	0.0	character spacing relative to height
	txhjustify	left	horizontal justification (n,c,l,r)
	txvjustify	bottom	vertical justification (n,c,t,b)
	txfont		roman	text font (roman,greek,italic,bold)
	txquality	normal	text generator precision (n,l,m,h)
	txcolor		1	text color index
.fi

.tp 9
.nf
	    (axis labeling parameters)

	drawtitle	yes	draw plot title if given
	titlesize	1.0	character size for plot title
	titlejust	center	horizontal justification of title
	ntitlelines	1	number of lines in title block
	aspect		0.0	aspect ratio of viewport (0=dontcare)	

	    (the following are duplicated for the Y axis)

	xdrawaxes	3	draw X axis 1, 2, both (3), none (0)
	xsetaxispos	no	set world coords of X axes
	xaxispos1	0.0	world coord of X axis 1 (default wx1)
	xaxispos2	0.0	world coord of X axis 2 (default wx2)
	xdrawgrid	yes	draw grid marks connecting X ticks
	xround		no	extend WCS to end at a tick mark
	xlabelaxis	yes	draw axis label string if given
	xaxislabelsize	1.0	character size for X axis label
	xdrawticks	yes	draw and label X ticks
	xlabelticks	yes	label X ticks
	xnmajor		6	number of major ticks in X
	xnminor		4	number of minor ticks in X
	xmajorlength	0.8ch	length of a major tick, X
	xminorlength	0.4ch	length of a minor tick, X
	xmajorwidth	1.0	linewidth of a major tick, X
	xminorwidth	1.0	linewidth of a minor tick, X
	xaxiswidth	1.0	linewidth of the axis
	xticklabelsize	1.0	character size for X tick labels
	xtickformat	""	override format for X tick labels
.fi

.tp 4
.nf
	    (read only variables)

	tty		-	pointer to TTY graphcap descriptor
	fd		-	file descriptor of output stream
	devname		-	device name as passed to gopen
.fi


The Y axis parameters have names equivalent to those shown with the
X prefix replaced by a Y.  If the prefix is omitted entirely then the
parameters for both axes will be set or queried.
The \fBglabax\fR code and parameters are built upon the GIO graphics
primitives and may be replaced by a more sophisticated user program
if desired.

Drawing and labeling of the X and Y axes is parameterized independently
in X and Y.  If drawing and labeling of an axis is disabled, tick drawing
and labeling is automatically disabled.  Drawing and labeling of an axis
may be disabled on only one side of the viewport (useful when a single viewport
is used simultaneously for two different world coordinate systems).
If tick drawing is disabled tick labeling is automatically disabled.
The tick marks, if drawn, may be connected by dotted lines within the
interior of the plot.

Given the approximate number of major ticks, GIO will compute the nearest
number of tick marks resulting in round numbers for the tick mark labels.
If rounding is enabled the window will be enlarged to the nearest tick
outward on either end of an axis, otherwise an axis will end at the window
boundary, which need not fall on a tick mark.
If linear scaling is indicated \fInminor\fR minor ticks will be drawn
between each pair of major ticks.  If log scaling is indicated the
\fInmajor\fR and \fInminor\fR parameters are ignored and
major ticks will be placed at powers of ten with eight minor ticks
(e.g., 2,3,4,5,6,7,8,9) between each pair of major ticks.
Tick lengths are given in NDC coordinates.  The default tick lengths
are parameterized in terms of the character height for the device.


.nh 2
Graphcap Parameters

    Each logical graphics device accessible to GIO must have an entry
in the \fBgraphcap\fR (graphics capabilities) file.  The name of the
device entry in the graphcap file must agree with that specified in the
\fBgopen\fR call when the device is opened.  Multiple logical device
entries may be given for a single physical device, each with slightly
different parameters.  The name of the graphcap file is parameterized
by the CL environment variable "graphcap", making it easy for the user
to customize or extend the graphcap file.  The graphcap entries for
common devices may be precompiled by the system manager to eliminate
the overhead of searching the graphcap file at run time.

The format of the graphcap file is identical to that of a UNIX \fBtermcap\fR
file, and indeed the same interface (TTY) is used to access both types of files.
The set of capabilities defined for a graphics device is however quite
different than that defined for a terminal.  Capabilities are typed 
parameters referred to by a two character internal name.  The restriction to
two characters is perhaps unfortunate but is desirable for efficiency reasons
(as well as for compatablity with the original termcap) and may be alleviated
at some point in the future by the use of macro defines.

Graphcap parameters fall into two classes, those parameters which are
common to all devices, and those parameters which are required only for
devices accessed with a particular graphics kernel.  GIO is capable
of supporting any number of quite different kernels, each of which may
support any number of devices.  These kernels are free to add parameters
to their graphcap entries provided they do not conflict with the standard
parameters.  An example is the "fast" or \fBstdgraph\fR kernel, discussed
in detail in a later section.  If a device is to be accessed by more than
one kernel each kernel must typically have its own graphcap entry for the
device, with selection of the graphcap entry (logical device name)
specifying the kernel to be used.

In the discussion which follows the reader is assumed to already be familiar
with the syntax and usage of \fBtermcap\fR format files.  This is documented,
for example, in section 5 of the UNIX manuals.  A sample termcap entry for
the devices "vt100-nam" and "vt100-am" is included below as an example of
a typical termcap entry.


.tp 5
.nf
d1|vt100|vt100-nam|vt100 w/no am:\
	:am@:xn@:tc=vt100-am:
d0|vt100|vt100-am|vt100|dec vt100:\
	:cr=^M:do=^J:nl=^J:bl=^G:co#80:li#24:cl=50\E[;H\E[2J:\
	:le=^H:bs:am:cm=5\E[%i%d;%dH:nd=2\E[C:up=2\E[A:\
	:ce=3\E[K:cd=50\E[J:so=2\E[7m:se=2\E[m:us=2\E[4m:ue=2\E[m:\
	:md=2\E[1m:mr=2\E[7m:mb=2\E[5m:me=2\E[m:is=\E[1;24r\E[24;1H:\
	:rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:\
	:if=/usr/lib/tabset/vt100:ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=^H:\
	:ho=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:ta=^I:pt:sr=5\EM:vt#3:xn:\
	:k5=\EOp:k6=\EOx:k7=\EOr:k8=\EOm:k9=\EOl:k0=\EOq:\
	:sc=\E7:rc=\E8:cs=\E[%i%d;%dr:ks=\E[?1h\E=:ke=\E[?1l\E>:
.fi


Note that each device may be known by several names.  The device capabilities
are delimited by colons, e.g., ":xx=...:yy=...:".  The special capability "tc"
allows an entry to include another entry recursively.  Escape is represented
as either "\E" or "^[", <ctrl/h> is "^H".  If a delay of so many milliseconds
is required after transmission of a string, the number of milliseconds
appears as the first few chars in an entry, e.g., "cl=50..." causes a
delay of 50 milliseconds following a screen clear.  Numeric capabilities are
prefaced by a sharp, e.g., ":co#80:" (screen has 80 columns).


.nh 3
Generic GRAPHCAP Parameters

    To make the distinction between the generic and kernel graphcap parameters
clear and to eliminate the possibility of redefinitions, the generic
parameters have lower case names and the kernel parameters have upper case
names.  Only the standard graphcap parameters should be accessed from within
applications programs.  The standard parameters are listed and defined below.
These parameters should be included in the graphcap entry for every device.

.ls 4
.ls 15 ar   real
Aspect ratio dY/dX, i.e., the ratio of the size of the device screen in Y to
that in X (equivalent to ys/xs).
.le
.ls ca   bool
Device implements cellarray plotting in hardware, i.e, the \fIzr\fR greylevels
are displayed by the hardware rather than emulated by software in the kernel.
.le
.ls ch   real
Height in NDC units of a character of size 1.0.
.le
.ls co   int
Number of columns of text displayable on the device screen at character
size 1.0.
.le
.ls cw   real
Width in NDC units of a character of size 1.0.
.le
.ls fa   bool
Device implements fill area in hardware.
.le
.ls fs   int
Number of fill area styles supported by the device.
.le
.ls in   bool
Device supports at least one input function, i.e., cursor readback or cell
array input.
.le
.ls k1   int
Minimum possible key value in a cursor read.
.le
.ls k2   int
Maximum possible key value in a cursor read.
.le
.ls kf   str
Filename of the executable graphics kernel file for the device.
If this is given as "cl", the kernel is assumed to be resident in the
CL process.  Should be a virtual filename, e.g., "dev$x_device.e".
See also parameter \fItn\fR.
.le
.ls li   int
Number of lines of text displayable on the device screen at character
size 1.0.
.le
.ls lt   int
Number of linetypes supported by the device.
.le
.ls lw   int
Number of linewidths supported by the device.
.le
.ls nc   int
Number of cursors supported by the device.
.le
.ls nk   int
Number of possible key values in a cursor read.
.le
.ls pl   bool
Device implements polyline drawing in hardware.
.le
.ls pm   bool
Device implements polymarker drawing in hardware.
.le
.ls ro   bool
Device supports roam at the hardware level (used in cursor mode).
.le
.ls se   bool
Device supports selective erase of portions of the screen.
.le
.ls tf   int
Number of text fonts supported by the device.
.le
.ls th   int
Number of text heights or sizes supported by the device.  If absent or zero
it is assumed that characters may be freely scaled in size.  If only a number
of discreet character sizes are available the sizes are given by the
parameters \fItN\fR.
.le
.ls tn   str
Taskname, i.e., name of the logical task within the kernel file \fIkf\fR
to be run to exercise a kernel.
.le
.ls tq   int
Number of text quality or precision levels supported by the device.
.le
.ls tN   real
Sizes of the \fIth\fR possible character sizes, relative to a character
of size 1.0 (expands to the set of parameters t1,t2,...,tN).
.le
.ls tx   bool
Device implements text generation in hardware.
.le
.ls wc   bool
Reading the cursor implies a wait, i.e., a cursor read is triggered by
the user.
.le
.ls xr   int
Device resolution in X.
.le
.ls xs   real
Device scale in X, i.e., the width of the display area in meters.
.le
.ls yr   int
Device resolution in Y.
.le
.ls ys   real
Device scale in Y, i.e., the height of the display area in meters.
.le
.ls zo   bool
Device supports zoom at the hardware level (used in cursor mode).
.le
.ls zr   int
Device resolution in Z, i.e., the number of greylevels or colors displayable
at each point using the cell array primitive.
.le
.le


The graphcap parameters are accessed by name via \fBgget\fR calls.
For example,

	xr = ggetr (gp, "xr")

would assign the value of the parameter "xr" into the local variable of
the same name.

.nh 3
STDGRAPH Graphcap Parameters

    The \fBstdgraph\fR kernel is the "fast" kernel, i.e., the graphics kernel
resident in the CL process.  This kernel is capable of driving almost any
modern graphics terminals given only a graphcap entry for the device,
providing the graphics terminal is data driven and provides both character
and vector generation in hardware.

.nh 4
Classes of Parameters

    The stdgraph parameters fall into a number of classes which we shall
describe separately.  An alphabetical summary of all parameters is given in
a later section.

The open and close workstation sequences are sent to the device whenever the
workstation is activated (OW) or deactivated (CW), e.g., when the STDGRAPH
kernel receives the open workstation or close workstation directive, or when
the open workstation is explicitly deactivated and later reactivated by the
applications program.

The primary function of the open and close workstation sequences is to
effect a mode switch from text mode to graphics mode and back again,
but the sequences may also contain instructions used only for initialization
or mode setting.  For example, OW might initialize user defined line types
or enable the graphics board.  The close string CW might disable the graphics
board and set the alpha cursor to a standard place on the screen.

The graphics enable and disable strings (GE,GD) are sent to the terminal
by the STDGRAPH kernel when status line i/o occurs.  The GD sequence should
clear the status line, leaving the terminal in status line mode, with the
text cursor positioned to the start of the status line.  The GE sequence
restores the terminal to graphics mode, and is often the same as the OW
sequence.  Note that GD should not cause the graphics frame to disappear,
as the status line is supposed to be visible at the same time as the plot.

The status line is normally the line at the bottom of the screen.  On terminals
with separate text and graphics memories which can both be displayed at the
same time, the status line is normally written into the text memory.  If the
terminal has both text and graphics memories but can only display one at a time
the graphics memory should be used, provided the status line can be erased in
the graphics memory.  If the graphics plane must be used but erase is not
possible, the best approach is probably to write successive lines of status
line text on top of the plot, starting at the upper left corner and advancing
downward for each line of output text (see the 4012 entry in dev$graphcap).

The parameters X1, X2, Y1, and Y2 define the range of device coordinates
to be output.  Normally these will span the full screen of the device,
but in general they may define any rectangular window on the device screen.
The fill area and font tables are array valued parameters mapping the GKI
fill area and font indices into device codes (if the device should happen
to support such niceties).


.ks
.nf
	OW		open (reactivate) workstation
	IF		initialization file, if OW string is large
	CW		close (deactivate) workstation
	GE		graphics enable (exit status line mode)
	GD		graphics disable (enter status line mode)
	CL		screen clear
	LR		load registers (see "binary encoding")

	X1,X2		range of device X coordinates
	Y1,Y2		range of device Y coordinates
.fi
.ke


The set attribute parameters are format strings used to encode set attribute
commands, each of which has a single integer argument.  The format string is
similar to a \fBprintf\fR format string with the addition of a notation for
binary encoding (described below).


.ks
.nf
	TH(i)		set text height
	TC(i)		set text color
	TF(i)		set text font
	LT(i)		set line type
	LC(i)		set line color
	LW(i)		set line width
	MC(i)		set marker color
	FT(i)		set fill area type
	FC(i)		set fill area color
.fi
.ke


Polyline generation, i.e., vector drawing, is more difficult to parameterize.
We assume that polylines, polymarkers, fill areas, etc. are all similar enough
to be described by the same coordinate encoding format, but we allow each
such instruction to have different head and tail strings.

.ks
.nf
	PL		polyline flag
	VS		move start
	VE		move end
	DS		draw start
	DE		draw end
	MS		marker start
	ME		marker end
	FS		fillarea start
	FE		fillarea end
	XY(i,j)		coord format
.fi
.ke


A polyline command consists of a number of subcommands, as outlined in the
drawing below.  The polyline is a move followed by one or more draws.
The polyline flag PL is set to indicate that multiple coordinate pairs
can be output between the DS and DE commands.  If PL is false (or omitted)
each coordinate pair in the GKI polyline will be output surrounded by DS
and DE commands.  The encoding of each coordinate pair is defined by the
parameter XY.


.ks
.nf
	set attributes if necessary
	move start
	    x, y
	move end
	draw start
	    x, y
		...
	    x, y
	draw end
.fi
.ke


The polymarker and fillarea parameters are optional.  The kernel will
emulate markers and fill area if not supported by the hardware.
Recall that GIO handles all mark drawing except GM_POINT (point mode),
hence sophisticated mark drawing facilities are not required.

Text generation is handled by the kernel a character at a time.
If character up is 90 degrees and the path is to the right, the kernel
will assume that it can output a number of characters between a TS
and a TE.  Otherwise each character will be output preceded by a TS
and followed by a TE.  The TS parameter is a format string with two
arguments, the device coordinates of the lower left corner of the
character to be drawn.  The encoding of these coordinates is defined
by the TS format string.  It is possible to perform a coordinate
transformation using the binary encoding facilities, if such is necessary.
If characters are not addressed at the lower left corner an offset
may be applied to the given coordinates using the binary encoding
facilities.


.ks
.nf
	TS(i,j)		text start
	TE		text end
.fi
.ke


Cursor output is controlled by the parameter WC.
Cursor input is initiated by output of the sequence defined by the format RC.
RC has one integer argument, the number of the cursor to be read.
The UC capability, if defined, will cause the cursor position to be updated
(with WC) to the position at the last cursor read.  This is desirable if the
device cannot maintain the cursor position, i.e., if unrelated graphics
output commands affect the cursor position as an unwanted side effect.


.ks
.nf
	UC		update cursor pos before read
	WC(x,y,i)	write cursor 
	RC(i)		read cursor start
	RE		read cursor end
	CN		cursor value length
	CD		cursor value delimiter
	SC		scan cursor (-> x,y,key)
.fi
.ke


Following transmission of the RC sequence the kernel will read the
response as defined by the parameters CN and CD.  At least one of CN or CD
must be given.  If CN is given but not CD exactly CN characters will be
read.  If CD is given then characters will be read until the delimiter string
is matched (and until at least CN characters have been read).  If possible
a delimiter string should be specified to permit recovery from bad cursor
reads, e.g., when the user types something before the cursor is displayed.
When a satisfactory cursor response string has been obtained the format SC
will be used to decode the string into the output values X, Y, and KEY.
The RE sequence is transmitted once the cursor read has successfully
completed.

.nh 4
Binary Encoding

    Graphics devices vary widely in the techniques used to encode numeric
data such as a line type or color index, or the coordinate pairs of a
polyline.  Our approach to the encoding problem is a generalization of the
\fBprintf\fR format string.  The encoder is driven by a format string
taken from the graphcap entry for the device.  A number of standard formats
are recognized with encoding provided internally for these standard formats
by the encoder.  To permit encoding of special formats the encoder provides
a very general yet efficient RPN virtual machine capable of computing bit
patterns according to a user supplied program embedded in the format string.

A format string is a sequence of ASCII characters.  Any ASCII character,
including all control characters, is permitted in the string.
The significance of a character depends on the context in which it appears.
Initially characters are simply copied to the output.  Three special
characters are recognized in \fBcopy mode\fR (excluding the characters
already counted as special by termcap):


.ks
.nf
	'	escape next character (literal)
	%	begin a formatted output string
	(	begin an executable expression
.fi
.ke


The encoder is a table driven interpreter which is programmed by the format
given in the graphcap file.  Programming the encoder is rather
like programming in assembler or microcode (its fun but easy to screw up).
The encoder provides a set of 12 integer registers, an integer stack with a
capacity of 50 values, and a dozen or so instructions.  It is fundamentally
assumed that the character set is ASCII (this is guaranteed by the IRAF
programming environment).

Upon entry one or more of the registers 1 through 3 are initialized to the
values of the input arguments, leaving the remaining registers, i.e., R4-R9
and R0 (R10) available for general use.  Registers R11 and R12 are reserved
for internal use.
The interpreter is activated when an unescaped ( is encountered in the input.
In \fBexecute mode\fR the following characters have special meanings
(excluding :, ^, and \, which are special characters to termcap/TTY):

.ks
.nf
	'	escape next character (recognized everywhere)
	%	conventional formatted output
	)	revert to copy mode
	#nnn	push signed decimal integer number nnn
	$ 	switch case construct
	.	pop number from stack and place in output string
	,	get next character from input string and push on stack
	&	modulus (similar to AND of low bits)
	+	add (similar to OR)
	-	subtract (similar to AND)
	*	multiply (shift left if pwr of 2)
	/	divide (shift right if pwr of 2)
	<	less than (0=false, 1=true)
	> 	greater than (0=false, 1=true)
	=	equals (0=false, 1=true)
	;	branch if: <bool> <offset> ;.  The ; is at offset=0.
       0-9	push contents of register 0 through 9
	!N	pop stack into register N
	!!	generate a N millisecond delay, where N is on the stack
.fi
.ke


Any other character encountered in execute mode is interpreted as an integer
number and pushed on the stack.  Hence, the character "@" is equivalent to
"#64", i.e., octal 100.  A blank is the integer constant 40B.

The output format directive % will format and output the number on the top
of the stack, popping the stack in the process.  The format specification
may be any legal \fBprintf\fR format.  The case construct is used to process
set attribute commands, e.g., set linetype 0, 1, 2, text size 1, 2, 3, etc,
and also provides a rudimentary conditional processing capability.  The branch
if operator ; provides a rudimentary branching and looping capability.
Beware that sequences like "^N" and "\E" compile as a single character in
the format string.

.nh 4
Examples

    As a simple example consider the encoding of the ANSI command to set
the cursor of a nongraphics terminal.  The required sequence is the
following:

	ESC [ line ; col H

Assuming that the column number is designated as X and the line number as
Y, in registers 1 and 2 respectively, the format would be as follows
(the quotes are not part of the format):

	"\E[(2)%d;(1)%dH"

Now assume that the output sequence is the same but the line and column
numbers are one-indexed while the terminal requires zero-indexed
coordinates:

	"\E[(2#1-)%d;(1#1-)%dH"

Thus far the examples have been pretty trivial and do not warrant the
complexity of the RPN interpreter proposed here.  For our next example
consider the encoding of a polyline coordinate pair for a Tektronix
compatible graphics terminal and for an AED512, two quite different
graphics terminals.  The Tektronix format for encoding an (X,Y) coordinate
pair is as follows:


.ks
.nf
	0 1 YA Y9 Y8 Y7 Y6
	1 1 Y5 Y4 Y3 Y2 Y1
	0 1 XA X9 X8 X7 X6
	1 0 X5 X4 X3 X2 X1
.fi
.ke


Since the Tektronix device is so common the special format %t is provided
for encoding register 1 and 2 (X and Y) in this format, and writing out
the result.  The format string

	"%t"

is all that is required.  The more general solution is provided by the
following format.

	"(2 / +.2 &`+.1 / +.1 &@+."

To understand this last example one must look up the octal values of
the characters " " (40B), "`" (140B), and "@" (100B).  The notation is
admittedly rather cryptic but it is also concise and efficient, and works
for a wide range of devices.

Now consider the AED512 in binary mode (this is courtesy of NCAR; I do not
have access to such a terminal).  The output encoding of a coordinate pair
is as follows:


.ks
.nf
	XA X9 X8 YB YA Y9 Y8
	X7 X6 X5 X4 X3 X2 X1
	Y7 Y6 Y5 Y4 Y3 Y2 Y1
.fi
.ke


The format required to generate this is shown below.  Note the use of
register 9 to store the constant 200B.  The "^N" signifies <ctrl/n>,
i.e., 16B, used to effect a left shift of four bits.

	"(#128!919/^N*29/+.19&.29&."

This format could be further optimized by preloading register 9 at
\fBopenws\fR time by moving the "(#128!9" to parameter LR.  The encoder
registers maintain their values indefinitely.  Using LR the two parameters
might appear in the graphcap entry as follows.

	":LR=(#128!9:XY=(19/^N*29/+.19&.29&.:"

The case construct makes it possible to generate output conditionally based
on the value of an integer switch.  The syntax of a case statement is as
follows:

	$1 ... $2-5 ... $6 ... $D ... $$

When the first $ is encountered the switch value is popped off the stack
and converted into a character by addition of the constant '0' (60B).
The interpreter will then scan forward until it finds the indicated case,
at which point it resumes execution in case mode.  If the indicated case
is not found scanning will stop at $D (the default case) or $$, whichever
comes first.  When the next $ is seen the interpreter skips forward until
it finds $$, which marks the end of the case.  Case constructs are not
nestable.

The case construct is used primarily for set attribute formats.
For example, the GKI linetype codes are integers greater than or equal to zero,
with case zero being the line clear and the other cases actual linetypes.
For the VT640 there are nine possible linetypes, i.e., line clear,
five builtin linetypes, and 3 user defined linetypes.  The strings to be
output for the cases 0 through 5 are the following:


.ks
.nf
	linetype		     string

	    0			ESC / 1 d ESC `
	    1			ESC / 0 d ESC `
	    2			ESC / 0 d ESC a
	    3			ESC / 0 d ESC b
	  (etc)			     (etc)
.fi
.ke


We could encode linetypes 0, 1 through 5, and everything else with the
following format (linetype code in register 1):

	"\E/(1$0)0d\E`($1-5)1d\E(1_+.$D)0d\E`($$"

Note that case searching is a simple string matching operation that ignores
operators such as ( and ).  Only $, ' (escape), and EOS are recognized when
searching for a case.

.nh 4
Efficiency

    The interpreter approach to solving the general encoding problem
presented here is not the only solution to the problem.  Before adopting
this approach several alternatives were considered.  One such alternative
was the bitfield packing and unpacking scheme used by NCAR to solve the
same problem.  The third alternative considered was to hand code a
subroutine for each encoding required for each device.  Benchmarks run
to compare the three alternatives yielded the following times in
cpu seconds required to plot a 1000 point array with Tektronix encoding:


.ks
.nf
	bitfields	approximately 30 seconds
	interpreter	0.82 - 2.0 seconds
	hand coded	0.78 seconds (mostly i/o)
.fi
.ke


The time required for character output is included in the figures shown.
The bitfields benchmark is an extrapolation from an actual timing of the
prototype NCAR software as ported to the UNIX VAX by Cliff Stoll.
The GBYTE and SBYTE primitives used to implement bitfields in the NCAR
software were written in portable C by Cliff and did not use the VAX bitfield
instructions, which would have helped significantly (but which would not
have yielded a fair test: all IRAF target machines may not have bitfield
instructions).  The two timings shown for the interpreter are for the "%t"
format and the general format.  The clock time required by the hardware
(VT100 with VT640 retrographics board) to draw the vectors was about 7 seconds.

We conclude that the execution time overhead of the interpreter for encoding
polyline points is acceptable and the use of hand coded, device dependent
procedures is neither warranted nor desirable.  The bitfields technique
is too inefficient to use in a production interface.

.nh 4
Decoding Cursor Input

    Decoding of the cursor value string returned by the device into
X, Y, and KEY (keystroke) values is carried out using the table driven
interpreter for decoding rather than for encoding.  In this mode characters
are input with "," and the decoded output values X, Y, and KEY are returned
in registers 1 through 3.  The % format encoding operator is not used.
If the cursor value is returned in ASCII X and Y must be converted to
binary the hard way (e.g., "ch1 '0' - 100 * ch2 '0' - 10 * +", etc.).

To verify that this scheme will work consider the cursor value returned
by a Tektronix compatible terminal.  The return value is 6 characters,
consisting of the character typed followed by the encoded X and Y in
the next four characters, and lastly a CR terminator:


.ks
.nf
	C7 C6 C5 C4 C3 C2 C1
	 0  1 XA X9 X8 X7 X6
	 0  1 X5 X4 X3 X2 X1
	 0  1 YA Y9 Y8 Y7 Y6
	 0  1 Y5 Y4 Y3 Y2 Y1
	 0  0  0  1  1  0  1
.fi
.ke


The required decoding format is shown below.

	",!3, & *, &+!1, & *, &+!2"

.nh 4
Summary of STDGRAPH Graphcap Parameters

    An alphabetical summary of the graphcap parameters used by the STDGRAPH
kernel is given below.


.tp 3
.nf
	CD		cursor value delimiter
	CL		screen clear
	CN		cursor response length
	CW		close (deactivate) workstation
	DE		draw end
	DS		draw start
	FC(i)		set fill area color
	FE		fillarea end
	FS		fillarea start
	FT(i)		set fill area type
	GD		graphics disable (exit status line mode)
	GE		graphics enable (enter status line mode)
	IF		initialization file, if OP string is large
	LC(i)		set line color
	LR		load registers
	LT(i)		set line type
	LW(i)		set line width
	MC(i)		set marker color
	ME		marker end
	MS		marker start
	OW		open (reactivate) workstation
	PL		polyline flag
	RC(i)		read cursor start
	RE		read cursor end
	SC		scan cursor (-> x,y,key)
	TC(i)		set text color
	TE		text end
	TF(i)		set text font
	TH(i)		set text height
	TS(i,j)		text start
	VE		move end
	VS		move start
	WC(x,y,i)	write cursor 
	X1		first device X coordinate
	X2		last device X coordinate
	XY(i,j)		coordinate format
	Y1		first device Y coordinate
	Y2		last device Y coordinate
.fi


As a final example, the actual graphcap entry for the vt640 terminal
(DEC VT100 with retrographics) is reproduced below.


.ks
.nf
vt640|vt640g|vt100 with Retrographics:\
    :RC=(1$2)^X\E[24;65H\E[7mLIGHT PEN READY\E[0m($$)^]\E"(1$2)5($D)4($$)g:\
    :WC=^]%t\E/f:OW=150^]^_:CW=^X\E[24;0H\E[K:GE=150^]^_:GD=^X\E[24;0H\E[K:\
    :lt#5:nc#2:se:CL=50^]\E^L:xr#640:yr#480:ar#.57:xs#.23:ys#.13:tc=4012:

4012|tek4012|tektronix 4012:\
    :ar#.70:ch#.0294:co#80:cw#.0125:in:k1#1:k2#127:kf=cl:li#35:\
    :lt#5:nc#1:nk#127:pl:pm:th#4:t1#1:t2#2:t3#3:t4#4:tx:\
    :wc:xr#1024:yr#780:xs#.20:ys#.14:\
    :CD=^M:CN#6:LT=^]\E/(1$0)1d\E`($1-5)0d\E(1_+.$D)0d\E`($$:\
    :MS=\034:PL:RC=\E^Z:SC=(,!3, & *, &+!1, & *, &+!2:\
    :TH=\E(1#47+.:TS=^]%t^_:VS=^]:X1#0:X2#1023:XY=%t:Y1#0:Y2#779:\
    :OW=^]^_:CW=(#682!2#0!1)^]%t^_:GE=^]^_:\
    :CL=1000(#32!9)\E^L:\
    :LR=(#32!9:GD=(9#1-!99$0#31!9$$9#22*!2#0!1)^]%t^_:
.fi
.ke

.NH 3
TERMCAP and GRAPHCAP

    Every graphics terminal entry in the graphcap file should have a
corresponding terminal capability entry in the termcap file.  When the user
sets the terminal type with the \fBstty\fR task in the CL, the termcap entry
tells whether or not the terminal supports vector graphics, and the value
of the \fBstdgraph\fR environment variable is set to "none" for a non-graphics
terminal, or to the graphcap name of the device for a graphics terminal.
For a terminal to be recognized by the system as a graphics terminal the
termcap entry must include the ":gd" capability.  If the graphcap name for
the device is different than the termcap name then the form ":gd=gcname:"
should be used.

For example, the minimal termcap entry for the vt640 graphics terminal would
be as follows.  Note that it makes no sense to set the terminal type to
"vt100", since a standard vt100 does not support vector graphics.

.ks
.nf
	vt640|Retrographics enhanced VT100:\
	:gd:tc=vt100:
.fi
.ke

The "gd" capability is not standard termcap, but will be ignored by non-IRAF
programs which do not recognize the capability.

.nh 2
Graphics Kernel Interface

    The graphics kernel interface (GKI) is the interface between GIO and the
underlying graphics kernel or kernels.  The GKI is a data driven interface,
i.e., GIO communicates with the graphics kernel via bidirectional streams
of control instructions and data.  The functionality assumed by the GKI is
simple enough to permit use of a variety of graphics kernels, e.g., the builtin
GIO kernel for interactive graphics terminals, GKS, CORE, NSPP, and so on.
To understand the level of functionality expected from the kernel we first
summarize the functions the kernel is \fInot\fR expected to perform, i.e.,
the functions performed by GIO before output to the kernel:

.ls 4
.ls o
All WCS coordinate transformations and clipping at the viewport boundary.
The kernel sees only NDC coordinates.
.le
.ls o
Axis drawing and labeling.  GIO processes a \fBglabax\fR call into a
sequence of polylines in NDC coordinates.
.le
.ls o
Mark drawing.  GIO processes all mark drawing commands into polyline
instructions.
.le
.ls o
Move and draw commands.  GIO processes all absolute and relative move and draw
commands into sequences of polyline instructions.
.le
.le


The main functions of the kernel are the control and attribute set functions,
set cursor, polyline, polymarker (GM_POINT only), text generation, fill area,
cell array, and cursor read.  A kernel need not implement all such functions,
but it must at least recognize and ignore the corresponding GKI instructions.
The GKI kernel instructions are easily implemented for modern intelligent
graphics terminals.  The fast kernel will let the terminal handle polyline
drawing, point mode polymarker drawing, dashed lines, and character generation.

The GKI format is a sequence of variable length binary control and
output instructions.  Each instruction consists of the beginning of instruction
sentinel (BOI), an integer binary opcode identifying the instruction,
an integer giving the length of the instruction in metacode words,
and an arbitrary number of parameter and data words.
The BOI word aids in the detection of and recovery from botched instructions,
e.g., if an interrupt occurs while writing an instruction.


.ks
.nf
	 \fBfield\fR                          \fBdescription\fR

	BOI		beginning of instruction (magic value = 100000B)
	opcode		unique instruction identification code (1-27)
	length		length of entire of instruction in metacode
			    words (includes all four fields)
	data		variable length part of instruction
.fi

.ce
Figure 3. GKI Instruction Format
.ke


The instruction format chosen for GKI is basically a direct mapping of the
required low level functions into binary opcodes.
Various standard formats were considered and rejected,
in particular the GKS VDM (virtual device metafile) format.
GKS VDM turned out to be far to complex to be worth using at this level
in the system.  The GKS VDI format might have been better suited,
but I could not find any information describing this format
(my understanding was that, although there are numerous implementations of VDI,
there is no formal standard as yet).

The GKI format may be extended at some point in the future to provide
a binary instruction for each procedure in the GKS Fortran binding.
This will make it possible for applications to use either GIO or GKS,
provided a GKS kernel is available.  This will make it easier to
import applications which are already written to use GKS (alternatively a
mini-GKS might be built upon GIO, since the primitive functions are almost
identical).  Since IRAF itself is transportable and it is desirable for IRAF
applications to have full access to the IRAF i/o facilities, new IRAF
applications are not being written with transport to another data reduction
system in mind.  New IRAF applications will use only GIO whenever the
facilities provided by GIO are adequate.  Applications which use only GIO
will continue to be usable with any graphics kernel.

.nh 3
GKI Instructions

    The GKI instruction stream transmitted between processes on the same or
compatible machines will be a sequence of SPP short integer metacode words.
The machine independent GKI metafile format will be the equivalent stream
encoded as 16 bit twos complement signed integer metacode words, blocked 
1440 words per block, with conversion between the internal and external
metacode formats being provided by the IRAF MII (machine independent integer)
interface (MII takes care of byte swapping, etc.).  GKI metafiles in MII
format will be easily read and written by different machines, offloading most
of the work to the graphics kernel on the reader machine.  The GKI instruction
format is designed for maximum efficiency on modern minicomputers, i.e.,
the internal format (SPP short integer) is an atomic datatype and no bit
operations are required to generate or interpret metacode.

NDC coordinates (0.0 to 1.0) will be represented in GKI as integers in the
range 0-32767.  Character data will be packed one 7 bit ASCII character per
metacode word.  Floating point is required only for certain output attributes,
e.g., the linewidth and character height (size) scale factors.
To avoid the problems of machine dependent floating point formats we shall
represent the low precision real numbers by converting them to integer
metacode words scaled according to the following relation:

	I = int (R * 1E2)

Specifications for the GKI metafile instructions follow.  The datatype and
size of each field of the instruction is given in parenthesis.
The datatype "p" denotes a coordinate pair (x,y) of type (m,m),
where "m" denotes an NDC coordinate.

The OPENWS instruction marks the start of an instruction stream or
\fBmetafile\fR for a particular device.
A subsequent CLOSEWS (or physical end of file) marks the end of a metafile.
An OPENWS in APPEND mode requires that GIO recall the WCS defined when the
device was last accessed.
A physical file may consist of any number of independent metafiles.
Although there is no explicit connection between OPENWS and screen clear
(CLEARWS), a screen clear is implied for some devices when opened in
new file mode.
The MFTITLE instruction is optional and is provided only for documenting
the contents of a metafile.


.ks
.nf
			GKI_EOF = BOI  0 L
		     GKI_OPENWS = BOI  1 L M N D
		    GKI_CLOSEWS = BOI  2 L N D
	       GKI_REACTIVATEWS = BOI  3 L
	       GKI_DEACTIVATEWS = BOI  4 L
		    GKI_MFTITLE = BOI  5 L N T
		    GKI_CLEARWS = BOI  6 L
		     GKI_CANCEL = BOI  7 L
		      GKI_FLUSH = BOI  8 L
		   GKI_POLYLINE = BOI  9 L N P
		 GKI_POLYMARKER = BOI 10 L N P
		       GKI_TEXT = BOI 11 L P N T
		   GKI_FILLAREA = BOI 12 L N P
	       GKI_PUTCELLARRAY = BOI 13 L LL UR NC NL P
		  GKI_SETCURSOR = BOI 14 L CN POS
		      GKI_PLSET = BOI 15 L LT LW CI
		      GKI_PMSET = BOI 16 L MT MW CI
		      GKI_TXSET = BOI 17 L UP SZ SP P HJ VJ F Q CI
		      GKI_FASET = BOI 18 L FS CI
		  GKI_GETCURSOR = BOI 19 L CN
		GKI_CURSORVALUE = BOI 19 L CN POS KEY
	       GKI_GETCELLARRAY = BOI 20 L LL UR NC NL
		  GKI_CELLARRAY = BOI 20 L NP P
		     GKI_ESCAPE = BOI 25 L FN N DC
		     GKI_SETWCS = BOI 26 L N WCS
		     GKI_GETWCS = BOI 27 L N
.fi

.ce
The GKI Instruction Set
.ke

.nh 4
Control Instructions

    The NULL instruction is unique in that it consists of a single metacode
word with value zero.  The BOI and length fields are omitted.  Any number
of null words may be inserted between regular metacode instructions, e.g.,
to pad a block of metacode to be written to an MII format metafile.
The EOF instruction is used internally by GIO to stop metacode translation
on a pseudofile stream, as if end of file had been encountered.

The open workstation instruction should start a new frame unless the access
mode is APPEND, in which case graphics is to be added to the last frame.
An OPENWS implies an REACTIVATEWS.  CLOSEWS does little more than deactivate
the workstation, since the last frame must in some sense remain open for
APPEND mode to be possible.  Normal termination of the kernel process
will or an open workstation in a mode other than append will cause the last
frame to be terminated.


.ls
.tp 4
GKI_EOF = BOI 0 L
.ls
.nf
L(i)		3
.fi
.le


.tp 6
GKI_OPENWS = BOI 1 L M N D
.ls
.nf
L(i)		5 + N
M(i)		access mode (APPEND=4, NEW_FILE=5, TEE=6)
N(i)		number of characters in field D
D(Nc)		device name as in \fBgraphcap\fR file
.fi
.le


.tp 5
GKI_CLOSEWS = BOI 2 L N D
.ls
.nf
L(i)		4 + N
N(i)		number of characters in field D
D(Nc)		device name as in \fBgraphcap\fR file
.fi
.le


.tp 5
GKI_REACTIVATEWS = BOI 3 L
.ls
.nf
L(i)		3
.fi
.le


.tp 5
GKI_DEACTIVATEWS = BOI 4 L
.ls
.nf
L(i)		3
.fi
.le


.tp 5
.rj (optional)
GKI_MFTITLE = BOI 5 L N T
.ls
.nf
L(i)		4 + N
N(i)		number of characters in field T
T(Nc)		title string identifying metafile
.fi
.le


.tp 3
GKI_CLEARWS = BOI 6 L
.ls
.nf
L(i)		set to the constant 3 (no data fields)
.fi
.le


.tp 3
GKI_CANCEL = BOI 7 L
.ls
.nf
L(i)		set to the constant 3 (no data fields)
.fi
.le


.tp 3
GKI_FLUSH = BOI 8 L
.ls
.nf
L(i)		set to the constant 3 (no data fields)
.fi
.le
.le

.nh 4
Output Instructions

    All data points in the GKI output instructions have been transformed into
NDC coordinates and clipped at the viewport boundary (if clipping is enabled).
In the process GIO will translate any INDEF valued points by breaking large
polylines into smaller polylines, hence the semantics of plotting polylines and
polymarkers is quite simple at the graphics kernel level.

CELLARRAY is processed into a series of one dimensional cell array instructions,
one for each line in the two dimensional array supplied by the user.  Fewer or
shorter lines will be output if clipping is necessary.  Arrays larger than 32767
pixels may be output since each line is passed as a separate instruction.
The maximum number of lines and columns in a cell array is 32767 and 32761,
respectively (more lines can be input but they will not be resolved).
The kernel is expected to scale cell arrays to fit the output device via some
combination of pixel replication or subsampling, if there is not a one to one
correspondence between cell array pixels and device pixels.

.ls
.tp 5
GKI_POLYLINE = BOI 9 L N P
.ls
.nf
L(i)		4 + N * 2
N(i)		number of points in the polyline
P(Np)		list of points (x,y pairs)
.fi
.le


.tp 5
GKI_POLYMARKER = BOI 10 L N P
.ls
.nf
L(i)		4 + N * 2
N(i)		number of points in the polymarker
P(Np)		list of points (x,y pairs)
.fi
.le


.tp 6
GKI_TEXT = BOI 11 L P N T
.ls
.nf
L(i)		6 + N
P(p)		starting point of character string
N(i)		number of characters in string T
T(Nc)		string of N ASCII characters
.fi
.le


.tp 5
GKI_FILLAREA = BOI 12 L N P
.ls
.nf
L(i)		4 + (N * 2)
N(i)		number of points defining the polygon to be filled
P(Np)		list of points (x,y pairs)
.fi
.le


.tp 8
GKI_PUTCELLARRAY = BOI 13 L LL UR NC NL P
.ls
.nf
L(i)		9 + (N * M)
LL(p)		coordinates of lower left corner of output area
UR(p)		coordinates of upper right corner of output area
NC(i)		number of columns in array
NL(i)		number of lines in array
P(NCNLi)	array of color indices (pixels) stored by row
.fi
.le


.tp 5
GKI_SETCURSOR = BOI 14 L CN POS
.ls
.nf
L(i)		6
CN(i)		cursor number
POS(p)		new cursor position
.fi
.le
.le

.nh 4
Set Attribute Instructions

    The set polyline, polymarker, text, and fillarea instructions change
the attributes used to generate graphics output.  These instructions need be
issued only when one of the attributes in an instruction packet changes, i.e.,
the kernel is assumed to remember the attributes while a device is open.

.ls
.tp 6
GKI_PLSET = BOI 15 L LT LW CI
.ls
.nf
L(i)		6
LT(i)		linetype number
LW(r)		linewidth scale factor
CI(i)		polyline color index
.fi
.le


.tp 6
GKI_PMSET = BOI 16 L MT MW CI
.ls
.nf
L(i)		6
MT(i)		marktype (not used at present)
MW(i)		marksize, NDC coords (not used at present)
CI(i)		marker color index
.fi
.le


.tp 9
GKI_TXSET = BOI 17 L UP SZ SP P HJ VJ F Q CI
.ls
.nf
L(i)		12
UP(i)		character up vector (degrees)
SZ(r)		character size scale factor
SP(r)		character spacing
P(i)		path (0,2=left,3=right,4=up,5=down)
HJ(i)		horizontal justification
		    (0=normal,1=center,2=left,3=right)
VJ(i)		vertical justification
		    (0=normal,1=center,6=top,7=bottom)
F(i)		font (8=roman,9=greek,10=italic,11=bold)
Q(i)		quality (0=normal,12=low,13=medium,14=high)
CI(i)		text color index
.fi
.le


.tp 5
GKI_FASET = BOI 18 L FS CI
.ls
.nf
L(i)		5
FS(i)		fill style (0=clear,1=hollow,2=solid,3-6=hatch)
CI(i)		fill area color index
.fi
.le
.le


The attributes for the output primitives are assumed to be set to their
default values when OPENWS is issued.

.nh 4
Input Instructions

    The primary input instruction is the cursor read instruction, used to read
the cursor position in NDC coordinates.  The device cursor read may be either
event driven or instantaneous.  If the cursor read is event driven a nonzero
keystroke value may be returned, the range of possible keystroke values being
device dependent.  The instantaneous type of cursor read is preferred at the
GKI level since it offers the maximum flexibility (\fBclgcur\fR may then be
used to provide an optional device independent keystroke driven cursor read).
Devices which support both forms of cursor read may provide both as separate
logical cursors.  The graphics kernel should return a null cursor value if
the output device does not have a cursor.

.ls
.tp 6
GKI_GETCURSOR = BOI 19 L CN
.ls
.nf
L(i)		4
CN(i)		cursor number
.fi

The kernel reads graphics cursor number CN and returns the keystroke value
(if any) and the cursor position in NDC coordinates.  The cursor attributes
are returned in the following format:

	GKI_CURSORVALUE = BOI 19 L CN POS KEY

where

.nf
	L(i)		7
	CN(i)		cursor number
	POS(r)		NDC coordinates of cursor
	KEY(i)		keystroke value (>= 0 or EOF)
.fi
.le


.tp 8
GKI_GETCELLARRAY = BOI 20 L LL UR NC NL
.ls
.nf
L(i)		9
LL(p)		coordinates of lower left corner of input area
UR(p)		coordinates of upper right corner of input area
NC(i)		number of columns in output array
NL(i)		number of lines in output array
.fi

The GETCELLARRAY instruction is the converse of the PUTCELLARRAY instruction.
The cell array is returned in the following format:

	GKI_CELLARRAY = BOI 20 L NP P

where

.nf
	L(i)		4 + NP
	NP(i)		number of pixels (0 if noread)
	P(NPi)		array of pixels
.fi
.le


(instruction codes 19-24 are reserved for future use)
.le

.nh 4
Escape Instruction

    The escape instruction is used to pass device dependent information or
commands to the graphics kernel via GKI.  The graphics kernel will ignore
unrecognized escape functions.  Function codes 1 through 100 are reserved
for use by GIO.

.ls
.tp 5
GKI_ESCAPE = BOI 25 L FN N DC
.ls
.nf
L(i)		5 + N
FN(i)		escape function code
N(i)		number of escape data words
DC(i)		escape data words
.fi
.le
.le

.nh 4
Pseudo-GKI Instructions

    Since the CL must be able to read the device cursor and convert NDC
coordinates to WCS coordinates, the WCS must be passed to the CL when they
are "fixed" to the device.  The most natural and efficient way to do this
is via the GKI instruction stream, hence several additional instructions
are used internally in GIO to communicate with the portion of GIO resident
in the CL process.  These instructions are filtered out and executed by the
CL process and their existence may therefore be ignored by the graphics kernels.

The SETWCS instruction is used to pass WCS information to the CL process.
The GETWCS instruction is used to recall the WCS for a device opened in APPEND
mode (the WCS are returned in SETWCS format).  Since these instructions
are passed only between two closely coupled processes on a single cpu,
floating point numbers are passed in machine dependent format.
The length of this instruction is machine dependent.
Only the fields L and WCS are truely part of the instruction; the remaining
fields are a binary copy of the GIO internal WCS structure.

.ls
.tp 6
GKI_SETWCS = BOI 26 L N WCS
.ls
.nf
L(i)		4 + 17 * sizeof (struct wcs)
N(i)		length of WCS structure, words
WCS		binary copy of the 17 WCS structures, transmitted
		    in a single call to WRITE
.fi
.le


.tp 5
GKI_GETWCS = BOI 27 L N
.ls
.nf
L(i)		4
N(i)		maximum number of words to read
.fi
.le
.le

.nh 3
Encoding GKI Instructions

    The GKI instruction opcodes and fields are defined in the global include
file lib$gki.h.  To avoid direct knowledge of the binary format of the GKI
instructions, GIO uses a subpackage called GKI to encode the GKI instructions.
The GKI procedures each encode and transmit a single GKI instruction on the
output stream.  Although the GIO and GKI procedures have similar names, they
should not be confused.  The GIO \fBgpline\fR, for example, performs conversion
from a WCS to GKI coordinates with clipping at the viewport boundary, checking
that the polyline attributes are up to date before transmitting the polyline
instruction.  In contrast the GKI \fBgki_polyline\fR merely encodes and
transmits the GKI_POLYLINE metacode instruction.

The GKI procedures are self contained with the exception of the set attribute
instructions, which reference attribute packet structures (argument \fIap\fR)
defined in the include file gio.h.
The GKI instruction encoding procedures are shown below.

.ks
.nf
	     gki_openws (fd, device, mode)
	    gki_closews (fd, device)
       gki_reactivatews (fd, flags)
       gki_deactivatews (fd, flags)
	    gki_mftitle (fd, title)
	    gki_clearws (fd)
	     gki_cancel (fd)
	      gki_flush (fd)
	   gki_polyline (fd, points, npts)
	 gki_polymarker (fd, points, npts)
	       gki_text (fd, x, y, text)
	   gki_fillarea (fd, points, npts)
       gki_getcellarray (fd, m, nx, ny, x1,y1, x2,y2)
       gki_putcellarray (fd, m, nx, ny, x1,y1, x2,y2)
              gki_plset (fd, ap)
              gki_pmset (fd, ap)
	      gki_txset (fd, ap)
              gki_faset (fd, ap)
	  gki_setcursor (fd, x, y, cursor)
	  gki_getcursor (fd, x, y, key, cursor)
	     gki_escape (fd, fn, instruction, nwords)
	     gki_setwcs (fd, wcsdata, len_wcsdata)
	     gki_getwcs (fd, wcsdata, len_wcsdata)

	     gki_fflush (fd)	# not GKI instruction; flushes GKI stream
.fi
.ke


.nh 3
Decoding GKI Instructions

    The following additional procedures are provided for decoding and executing
GKI metacode, e.g., in a graphics kernel.  In what follows, \fIinstruction\fR
is a short integer array containing the encoded GKI instruction, and \fIdd\fR
is the device driver table, i.e., array of \fBzlocpr\fR entry point addresses
of the standard kernel procedures.


.ks
.nf
	 stat = gki_fetch_next_instruction (fd, instruction_ptr)
		gki_execute (instruction, dd)
		gkp_install (dd, out_fd, verbose_output)
.fi
.ke


The \fBfetch\fR procedure extracts the next instruction from the input metacode
stream, returning a short integer pointer to the instruction as an output
argument.  EOF is returned as the function value when end of file is detected.
The \fBexecute\fR procedure decodes an instruction and calls a graphics device
driver procedure to execute the instruction.  If the entry point address
of the driver procedure is NULL \fBgki_execute\fR will ignore the corresponding
GKI instruction.  The fields of the metacode instruction are passed to the
driver procedure as distinct arguments, hence the device driver need not
understand the GKI format.

A standard kernel is provided for decoding GKI instructions, printing the
decoded instructions in text form on the output stream.  The driver for this
kernel is installed with \fBgkp_install\fR, setting the output file and
verbose output flag in the process.

.nh 3
Example

    To illustrate the use of GKI as well as the output of the GKI decoding
kernel, consider the simple \fBgplotv\fR style plot of the following function:

	y = x ** 2

over the range

	x = 1 to 5, y = 1 to 25

The decoded GKI metacode produced by GIO to graph this function is
shown below.  The "verbose" mode of output (shown) lists the values
of the data points in the polyline, etc. output functions.  If verbose
output is disabled only the statistics of the output polylines
(computed by the decoder) will be printed.  All coordinates are printed
in NDC units.  The redundant points appearing in the output metacode
are expected to be filtered out by the kernel, which should not plot
points separated by less than the device resolution in NDC units.


.tp 4
.nf
open_workstation 'vt640', mode=new_file
set_wcs nwords=352
	 1 1. 5. 1. 25.  0.19 0.81 0.33 0.96  0 0 1
set_polyline ltype=1, lwidth=2.00, color=1
polyline np=3, xmin=0.19,xmax=0.19,xavg=0.19, ymin=0.33,ymax=0.37,yavg=0.34
	0.188 0.334  0.188 0.334  0.188 0.367  
set_text up=90, path=right, hjustify=center, vjustify=top, font=roman,
	size=1.00, spacing=0.00, color=1, quality=normal
text 0.19, 0.31, '1'
polyline np=15, xmin=0.19,xmax=0.34,xavg=0.27, ymin=0.33,ymax=0.37,yavg=0.34
	0.188 0.334  0.219 0.334  0.219 0.350  0.219 0.334  0.250 0.334  
	0.250 0.350  0.250 0.334  0.281 0.334  0.281 0.350  0.281 0.334  
	0.313 0.334  0.313 0.350  0.313 0.334  0.344 0.334  0.344 0.367  
text 0.34, 0.31, '2'
polyline np=15, xmin=0.34,xmax=0.50,xavg=0.43, ymin=0.33,ymax=0.37,yavg=0.34
	0.344 0.334  0.375 0.334  0.375 0.350  0.375 0.334  0.406 0.334  
	0.406 0.350  0.406 0.334  0.437 0.334  0.437 0.350  0.437 0.334  
	0.469 0.334  0.469 0.350  0.469 0.334  0.500 0.334  0.500 0.367  
text 0.50, 0.31, '3'
polyline np=15, xmin=0.50,xmax=0.66,xavg=0.58, ymin=0.33,ymax=0.37,yavg=0.34
	0.500 0.334  0.531 0.334  0.531 0.350  0.531 0.334  0.562 0.334  
	0.562 0.350  0.562 0.334  0.593 0.334  0.593 0.350  0.593 0.334  
	0.625 0.334  0.625 0.350  0.625 0.334  0.656 0.334  0.656 0.367  
text 0.66, 0.31, '4'
polyline np=15, xmin=0.66,xmax=0.81,xavg=0.74, ymin=0.33,ymax=0.37,yavg=0.34
	0.656 0.334  0.687 0.334  0.687 0.350  0.687 0.334  0.718 0.334  
	0.718 0.350  0.718 0.334  0.750 0.334  0.750 0.350  0.750 0.334  
	0.781 0.334  0.781 0.350  0.781 0.334  0.812 0.334  0.812 0.367  
text 0.81, 0.31, '5'
polyline np=2, xmin=0.81,xmax=0.81,xavg=0.81, ymin=0.33,ymax=0.33,yavg=0.33
	0.812 0.334  0.812 0.334  
polyline np=77, xmin=0.78,xmax=0.81,xavg=0.81, ymin=0.33,ymax=0.96,yavg=0.65
	0.812 0.334  0.812 0.334  0.796 0.334  0.812 0.334  0.812 0.360  
	0.796 0.360  0.812 0.360  0.812 0.386  0.796 0.386  0.812 0.386  
	0.812 0.412  0.796 0.412  0.812 0.412  0.812 0.438  0.779 0.438  
	0.812 0.438  0.812 0.464  0.795 0.464  0.812 0.464  0.812 0.490  
	0.795 0.490  0.812 0.490  0.812 0.516  0.795 0.516  0.812 0.516  
	0.812 0.542  0.795 0.542  0.812 0.542  0.812 0.568  0.779 0.568  
	0.812 0.568  0.812 0.594  0.795 0.594  0.812 0.594  0.812 0.620  
	0.795 0.620  0.812 0.620  0.812 0.646  0.795 0.646  0.812 0.646  
	0.812 0.672  0.795 0.672  0.812 0.672  0.812 0.698  0.779 0.698  
	0.812 0.698  0.812 0.724  0.795 0.724  0.812 0.724  0.812 0.750  
	0.795 0.750  0.812 0.750  0.812 0.776  0.795 0.776  0.812 0.776  
	0.812 0.802  0.795 0.802  0.812 0.802  0.812 0.828  0.778 0.828  
	0.812 0.828  0.812 0.854  0.795 0.854  0.812 0.854  0.812 0.880  
	0.795 0.880  0.812 0.880  0.812 0.906  0.795 0.906  0.812 0.906  
	0.812 0.932  0.795 0.932  0.812 0.932  0.812 0.958  0.778 0.958  
	0.812 0.958  0.812 0.958  
polyline np=15, xmin=0.19,xmax=0.22,xavg=0.19, ymin=0.33,ymax=0.44,yavg=0.38
	0.188 0.334  0.188 0.334  0.204 0.334  0.188 0.334  0.188 0.360  
	0.204 0.360  0.188 0.360  0.188 0.386  0.204 0.386  0.188 0.386  
	0.188 0.412  0.204 0.412  0.188 0.412  0.188 0.438  0.221 0.438  
set_text up=90, path=right, hjustify=right, vjustify=center, font=roman,
	size=1.00, spacing=0.00, color=1, quality=normal
text 0.19, 0.44, '5'
polyline np=15, xmin=0.19,xmax=0.22,xavg=0.19, ymin=0.44,ymax=0.57,yavg=0.51
	0.188 0.438  0.188 0.464  0.204 0.464  0.188 0.464  0.188 0.490  
	0.204 0.490  0.188 0.490  0.188 0.516  0.204 0.516  0.188 0.516  
	0.188 0.542  0.204 0.542  0.188 0.542  0.188 0.568  0.221 0.568  
text 0.19, 0.57, '10'
polyline np=15, xmin=0.19,xmax=0.22,xavg=0.19, ymin=0.57,ymax=0.70,yavg=0.64
	0.188 0.568  0.188 0.594  0.204 0.594  0.188 0.594  0.188 0.620  
	0.204 0.620  0.188 0.620  0.188 0.646  0.204 0.646  0.188 0.646  
	0.188 0.672  0.204 0.672  0.188 0.672  0.188 0.698  0.221 0.698  
text 0.19, 0.70, '15'
polyline np=15, xmin=0.19,xmax=0.22,xavg=0.19, ymin=0.70,ymax=0.83,yavg=0.77
	0.188 0.698  0.188 0.724  0.204 0.724  0.188 0.724  0.188 0.750  
	0.204 0.750  0.188 0.750  0.188 0.776  0.204 0.776  0.188 0.776  
	0.188 0.802  0.204 0.802  0.188 0.802  0.188 0.828  0.221 0.828  
text 0.19, 0.83, '20'
polyline np=15, xmin=0.19,xmax=0.22,xavg=0.19, ymin=0.83,ymax=0.96,yavg=0.90
	0.188 0.828  0.188 0.854  0.204 0.854  0.188 0.854  0.188 0.880  
	0.204 0.880  0.188 0.880  0.188 0.906  0.204 0.906  0.188 0.906  
	0.188 0.932  0.204 0.932  0.188 0.932  0.188 0.958  0.221 0.958  
text 0.19, 0.96, '25'
polyline np=2, xmin=0.19,xmax=0.19,xavg=0.19, ymin=0.96,ymax=0.96,yavg=0.96
	0.188 0.958  0.188 0.958  
polyline np=65, xmin=0.19,xmax=0.81,xavg=0.50, ymin=0.92,ymax=0.96,yavg=0.95
	0.188 0.958  0.188 0.958  0.188 0.925  0.188 0.958  0.219 0.958  
	0.219 0.942  0.219 0.958  0.250 0.958  0.250 0.942  0.250 0.958  
	0.281 0.958  0.281 0.941  0.281 0.958  0.313 0.958  0.313 0.941  
	0.313 0.958  0.344 0.958  0.344 0.925  0.344 0.958  0.375 0.958  
	0.375 0.941  0.375 0.958  0.406 0.958  0.406 0.941  0.406 0.958  
	0.437 0.958  0.437 0.941  0.437 0.958  0.469 0.958  0.469 0.941  
	0.469 0.958  0.500 0.958  0.500 0.925  0.500 0.958  0.531 0.958  
	0.531 0.941  0.531 0.958  0.562 0.958  0.562 0.941  0.562 0.958  
	0.593 0.958  0.593 0.941  0.593 0.958  0.625 0.958  0.625 0.941  
	0.625 0.958  0.656 0.958  0.656 0.924  0.656 0.958  0.687 0.958  
	0.687 0.941  0.687 0.958  0.718 0.958  0.718 0.941  0.718 0.958  
	0.750 0.958  0.750 0.941  0.750 0.958  0.781 0.958  0.781 0.941  
	0.781 0.958  0.812 0.958  0.812 0.924  0.812 0.958  0.812 0.958  
set_text up=90, path=right, hjustify=center, vjustify=bottom, font=roman,
	size=1.00, spacing=0.00, color=1, quality=normal
text 0.50, 0.96, 'title'
set_polyline ltype=1, lwidth=1.00, color=1
polyline np=5, xmin=0.19,xmax=0.69,xavg=0.44, ymin=0.33,ymax=0.96,yavg=0.59
	0.188 0.334  0.313 0.412  0.438 0.542  0.562 0.724  0.687 0.958  
flush
close_workstation 'vt640'
.fi


.nh 2
Graphics Kernel Parameters

    The translation from GKI codes to device codes should ideally be
parameterized to permit variable device resolution, font substitution,
and so on at translation time.  In general this is best handled by
spooling the metacode and later processing it via an explicit call to
a metacode translator program, using CL parameters to control the translation.
Some control over translation may also be achieved by modifying the
\fBgraphcap\fR entry for a device, provided the graphics kernel uses
the graphics capability database.

One of the most useful translation time parameters is the device resolution.
On some devices, e.g. pen plotters, it is necessary to be able to change
the device resolution at translation time to permit plotting of large vectors
without loss of resolution.  Changing the device resolution is also a valuable
technique for speeding up graphics when working remotely via a modem.

.nh
GKS Emulation

    The basic graphics primitives provided by GIO (polyline, polymarker, etc.)
are functionally identical to those provided by GKS (the Graphics Kernel
System).  The basic drawing primitives of GKS are therefore easily emulated
using GIO.  A subset of the Fortran binding of GKS has already been emulated,
sufficient to run the NCAR utilities recently converted by NCAR for use with
GKS.  In principle it should be possible to expand the GKS emulation to a
full level 0b or 1b interface, although we have no plans to do so at present.