aboutsummaryrefslogtreecommitdiff
path: root/vendor/x11iraf/ximtool/ximtool.gui
blob: d978081136d9679e0af4ccd89864950be837cea3 (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
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
#!/usr/local/bin/obmsh
#
# XIMTOOL-ALT.GUI -- Default GUI for the Ximtool-alt image display server.
#
# Version 2.0 -- BETA VERSION

set Version     "NOAO/IRAF XImtool Version 2.0BETA"

reset-server

set Objects(ximtool) { \
	toplevel	Layout		display\
\
	display		Group		menuGroup\
	menuGroup	Layout		menubar\
	menubar		MenuButton	fileButton\
	menubar		MenuButton	viewButton\
	menubar		MenuButton	optionsButton\
	menubar		Label		imageTitle\
	menubar		Toggle		mXflipButton\
	menubar		Toggle		mYflipButton\
	menubar		Command		mPrevButton\
	menubar		MenuButton	mFrameButton\
	menubar		Command		mNextButton\
	menubar		Toggle		toolButton\
	menubar		Toggle		panelButton\
\
	display		Layout		toolbar\
	toolbar		Command		tbZoomIn\
	toolbar		Command		tbZoom0\
	toolbar		Command		tbZoomOut\
	toolbar		Command		tbInvert\
	toolbar		Command		tbNormalize\
	toolbar		Command		tbMatchLUT\
	toolbar		Toggle		tbAutoReg\
	toolbar		Command		tbRegister\
	toolbar		Command		tbCenter\
	toolbar		Command		tbBlinkDec\
	toolbar		Toggle		tbBlink\
	toolbar		Command		tbBlinkInc\
	toolbar		Toggle		xflipButton\
	toolbar		Toggle		yflipButton\
	toolbar		Toggle		tbTile\
	toolbar		Toggle		tbCompass\
	toolbar		Command		prevButton\
	toolbar		MenuButton	frameButton\
	toolbar		Command		nextButton\
\
	display		Frame		imageFrame\
	imageFrame	Gterm		imagewin\
	display		Frame		cbarFrame\
	cbarFrame	Gterm		colorbar\
	display		Toggle		hcut\
	display		Toggle		vcut\
	display		Frame		hcutFrame\
	hcutFrame	Gterm		hcutPlot\
	display		Frame		vcutFrame\
	vcutFrame	Gterm		vcutPlot\
	display		Slider2d	focusSlider\
\
	display		Group		plotOpts\
	plotOpts	Layout		poptsLayout\
	poptsLayout	TextToggle	plotSpeed\
	poptsLayout	TextToggle	plotAccurate\
	poptsLayout	TextToggle	plotImgPix\
	poptsLayout	Frame		optLine\
	poptsLayout	TextToggle	curJump\
	poptsLayout	TextToggle	curSmooth\
	poptsLayout	TextToggle	curTrack\
\
	display		Layout		panelbar\
	panelbar	Toggle		pbDisplayP\
	panelbar	Toggle		pbLoadP\
	panelbar	Toggle		pbSaveP\
	panelbar	Toggle		pbPrintP\
	panelbar	Toggle		pbInfoP\
	panelbar	Toggle		pbTileP\
	panelbar	Toggle		pbCoordP\
	panelbar	Toggle		pbPanM\
	panelbar	Toggle		pbMagM\
	panelbar	Toggle		pbWcsM\
	panelbar	Toggle		pbIsm\
	panelbar	Toggle		helpButton\
	panelbar	Command		pbQuit\
}


set Objects(panelShell) { \
	toplevel	TopLevelShell	panelShell\
	panelShell	Layout		panel\
\
	panel		Frame		panelMenuFrame\
	panelMenuFrame	Layout		panelMenuBar\
	panelMenuBar	Command		panelHelp\
	panelMenuBar	Command		panelClose\
\
	panel		Frame		tabFrame\
	tabFrame	Tabs		panelTabs\
	panelTabs	Frame		display_panel\
	panelTabs	Frame		print_panel\
	panelTabs	Frame		load_panel\
	panelTabs	Frame		save_panel\
	panelTabs	Frame		info_panel\
	panelTabs	Frame		tile_panel\
	panelTabs	Frame		wcs_panel\
\
\
	display_panel	Layout		controlPanel\
	controlPanel	Group		viewBox\
	controlPanel	Group		enhancementBox\
	controlPanel	Group		blinkBox\
	controlPanel	Group		optionsBox\
	controlPanel	Frame		controlBox\
\
	viewBox		Layout		view\
	view		Group		frameSelect\
	frameSelect	Layout		frameBox\
	frameBox	Box		frlistBox\
	frlistBox	Viewport	framePort\
	framePort	Layout		frameList\
	frameList	TextToggle	frame1\
	frameList	TextToggle	frame2\
	frameList	TextToggle	frame3\
	frameList	TextToggle	frame4\
	frameList	TextToggle	frame5\
	frameList	TextToggle	frame6\
	frameList	TextToggle	frame7\
	frameList	TextToggle	frame8\
	frameList	TextToggle	frame9\
	frameList	TextToggle	frame10\
	frameList	TextToggle	frame11\
	frameList	TextToggle	frame12\
	frameList	TextToggle	frame13\
	frameList	TextToggle	frame14\
	frameList	TextToggle	frame15\
	frameList	TextToggle	frame16\
	frameBox	Command		prevFrame\
	frameBox	Command		nextFrame\
	view		Frame		frameDataBox\
	frameDataBox	TextBox		frameData\
	view		Group		zoomBox\
	zoomBox		Layout		zoom\
	zoom		TextButton	toggleZoom\
	zoom		TextButton	zoomIn\
	zoom		Command		x1\
	zoom		Command		z2\
	zoom		Command		z3\
	zoom		Command		z4\
	zoom		Command		z5\
	zoom		Command		z8\
	zoom		TextButton	zoomOut\
	zoom		TextButton	centerFrame\
	zoom		Command		d2\
	zoom		Command		d3\
	zoom		Command		d4\
	zoom		Command		d5\
	zoom		Command		d8\
	view		Layout		viewButtons\
	viewButtons	Command		aspect\
	viewButtons	Command		flipX\
	viewButtons	Command		flipY\
	viewButtons	Command		flipXY\
	viewButtons	Command		clearFrame\
	viewButtons	Command		fitFrame\
\
	enhancementBox	Layout		enhance\
	enhance		Frame		colorlistFrame\
	colorlistFrame	Viewport	colorlistView\
	colorlistView	MultiList	colorlist\
	enhance		Frame		colordataFrame\
	colordataFrame	TextBox		colordata\
	enhance		Label		contrastLabel\
	enhance		Slider2d	contrastSlider\
	enhance		Label		brightnessLabel\
	enhance		Slider2d	brightnessSlider\
	enhance		Command		invertButton\
	enhance		Command		optimizeButton\
\
	blinkBox	Layout		blink\
	blink		Label		blinkFramesLabel\
	blink		Command		blinkFrame1\
	blink		Command		blinkFrame2\
	blink		Command		blinkFrame3\
	blink		Command		blinkFrame4\
	blink		Toggle		blinkPanel\
	blink		Command		blinkReset\
	blink		Label		blinkRateLabel\
	blink		Frame		BRframe\
	BRframe		Layout		BRlayout\
	BRlayout	Arrow		BRdecrease\
	BRlayout	TextBox		BRtext\
	BRlayout	Arrow		BRincrease\
	blink		Command		registerButton\
	blink		Command		matchButton\
	blink		TextToggle	blinkButton\
	blink		TextToggle	autoregButton\
\
	optionsBox	TextToggle	pannerButton\
	optionsBox	TextToggle	magnifierButton\
	optionsBox	TextToggle	coordsBoxButton\
	optionsBox	TextToggle	autoscaleButton\
	optionsBox	TextToggle	antialiasButton\
	optionsBox	TextToggle	tileFramesButton\
	optionsBox	TextToggle	warningsButton\
	optionsBox	TextToggle	peakupButton\
\
	controlBox	Layout		control\
	control		Command		initializeButton\
	control		Command		normalizeButton\
\
\
	print_panel	Layout		printLayout\
\
	printLayout	Group		printCmdGroup\
	printLayout	Group		optGroup\
	printLayout	Group		cmdGroup\
\
	printCmdGroup	Layout		printCmdLayout\
	printCmdLayout	Layout		labelLayout\
	labelLayout	Label		toLabel\
	labelLayout	Label		printerLabel\
	printCmdLayout	Layout		inputLayout\
	inputLayout	TextToggle	toPrinter\
	inputLayout	TextToggle	toFile\
	inputLayout	Frame		printcmdFrame\
	printcmdFrame	AsciiText	printcmd\
\
	optGroup	Layout		optLayout\
	optLayout	Group		epsPageGroup\
	optLayout	Group		optionsGroup\
	optLayout	Group		printColorGroup\
	optLayout	Group		printerGroup\
	optLayout	Group		annOptsGroup\
\
	epsPageGroup	Layout		epsPage\
	epsPage		Label		epsOrientLabel\
	epsPage		TextToggle	epsPortButton\
	epsPage		TextToggle	epsLandButton\
	epsPage		TextToggle	epsSquareButton\
	epsPage		Label		epsSizeLabel\
	epsPage		TextToggle	epsLetterButton\
	epsPage		TextToggle	epsLegalButton\
	epsPage		TextToggle	epsA4Button\
	epsPage		TextToggle	epsB5Button\
	epsPage		Label		epsScaleLabel\
	epsPage		Frame		ScaleFrame\
	ScaleFrame	Layout		ScaleLayout\
	ScaleLayout	Arrow		SCdecrease\
	ScaleLayout	TextBox		SCtext\
	ScaleLayout	Arrow		SCincrease\
\
	optionsGroup	Layout		options\
	options		TextToggle	epsscaleButton\
	options		TextToggle	autorotateButton\
	options		TextToggle	aspectButton\
	options		TextToggle	compressButton\
\
	annOptsGroup	Layout		annOpts\
	annOpts		TextToggle	annotateButton\
	annOpts		TextToggle	colorbarButton\
	annOpts		TextToggle	titleButton\
	annOpts		TextToggle	bordersButton\
	annOpts		Label		titleLabel\
	annOpts		Frame		titleFrame\
	titleFrame	AsciiText	titleString\
\
	printColorGroup	Layout		printColor\
	printColor	TextToggle	prGrayButton\
	printColor	TextToggle	prPseudoButton\
	printColor	TextToggle	prRGBButton\
\
	printerGroup	Layout		printers\
	printers	Frame		printlistFrame\
	printlistFrame	Viewport	printlistView\
	printlistView	MultiList	printlist\
\
	cmdGroup	Layout		cmdLayout\
	cmdLayout	Command		okayPrint\
	cmdLayout	Label		printStatus\
\
\
	load_panel	Layout		filesLayout\
	filesLayout	Group		imlistGroup\
	imlistGroup	Layout		imlistLayout\
	imlistLayout	Command		rootButton\
	imlistLayout	Command		homeButton\
	imlistLayout	Command		upButton\
	imlistLayout	Command		rescanButton\
	imlistLayout	Label		dirLabel\
	imlistLayout	Label		fnameLabel\
	imlistLayout	Frame		filnamFrame\
	filnamFrame	AsciiText	fnameText\
	imlistLayout	Label		imtemplateLabel\
	imlistLayout	Frame		imtemplateFrame\
	imtemplateFrame	AsciiText	imtemplateText\
	imlistLayout	Label		imlistLabel\
	imlistLayout	Frame		imlistFrame\
	imlistFrame	Viewport	imlistView\
	imlistView	MultiList	imageList\
\
	filesLayout	Group		imoptsGroup\
	imoptsGroup	Layout		imoptsLayout\
	imoptsLayout	TextToggle	grayscale\
	imoptsLayout	TextToggle	autoload\
	imoptsLayout	TextToggle	browseHdrs\
	imoptsLayout	TextToggle	zscale\
	imoptsLayout	TextToggle	zrange\
	imoptsLayout	Label		z1Label\
	imoptsLayout	Frame		z1Frame\
	z1Frame		AsciiText	z1Value\
	imoptsLayout	Label		z2Label\
	imoptsLayout	Frame		z2Frame\
	z2Frame		AsciiText	z2Value\
	imoptsLayout	Label		nsampLabel\
	imoptsLayout	Frame		nsampFrame\
	nsampFrame	AsciiText	nsampValue\
	imoptsLayout	Label		frameLabel\
	imoptsLayout	MenuButton	frameFrame\
\
	filesLayout	Group		loadCmdGroup\
	loadCmdGroup	Layout		loadCmdLayout\
	loadCmdLayout	Command		filesLoadButton\
	loadCmdLayout	Label		filesStatus\
\
\
	save_panel	Layout		saveLayout\
	saveLayout	Group		saveNameGroup\
	saveNameGroup	Layout		saveNameLayout\
	saveNameLayout	Label		saveLabel\
	saveNameLayout	Frame		fnameFrame\
	fnameFrame	AsciiText	saveFile\
\
	saveLayout	Group		saveOptGroup\
	saveOptGroup	Layout		saveOptLayout\
	saveOptLayout	Group		fmtGroup\
	saveOptLayout	Group		saveColorGroup\
	saveOptLayout	Frame		saveDataBox\
	saveDataBox	TextBox		saveData\
\
	fmtGroup	Layout		formats\
	formats		TextToggle	rasButton\
	formats		TextToggle	gifButton\
	formats		TextToggle	jpegButton\
	formats		TextToggle	tiffButton\
	formats		TextToggle	fitsButton\
	formats		TextToggle	epsButton\
	formats		TextToggle	x11Button\
	formats		TextToggle	rawButton\
\
	saveColorGroup	Layout		saveColor\
	saveColor	TextToggle	svGrayButton\
	saveColor	TextToggle	svPseudoButton\
	saveColor	TextToggle	svRGBButton\
\
	saveLayout	Group		saveCmdGroup\
	saveCmdGroup	Layout		saveCmdLayout\
	saveCmdLayout	Command		okaySave\
	saveCmdLayout	Label		saveStatus\
\
\
	info_panel	Layout		infoLayout\
	infoLayout	Group		infoBox\
	infoBox		Layout		infoBoxL\
	infoBoxL	Frame		infoFrame\
	infoFrame	AsciiText	infoText\
	infoBoxL	TextToggle	infoOptFr\
	infoBoxL	TextToggle	infoOptWCS\
	infoBoxL	TextToggle	infoOptSvr\
	infoBoxL	TextToggle	infoOptClients\
	infoBoxL	TextToggle	infoOptIsm\
	infoBoxL	TextToggle	infoOptFB\
\
\
	wcs_panel	Layout		wcsLayout\
	wcsLayout	Group		wcsGroup\
	wcsGroup	Layout		wcsBox\
\
	wcsBox		Frame		wcsFrame\
	wcsFrame	Layout		wcsText\
	wcsText		AsciiText	wtName\
	wcsText		AsciiText	wtTitle\
	wcsText		AsciiText	wtFBCfg\
	wcsText		AsciiText	wtIPixval\
	wcsText		AsciiText	wtSPixval\
	wcsText		AsciiText	wtBPixval\
	wcsText		AsciiText	wtWcs1\
	wcsText		AsciiText	wtWcs2\
	wcsText		AsciiText	wtWcs3\
	wcsText		AsciiText	wtWcs4\
\
	wcsBox		TextToggle	ismToggle\
	wcsBox		TextToggle	pixelTable\
	wcsBox		TextToggle	imageHeader\
	wcsBox		TextToggle	compass\
	wcsBox		TextToggle	wcsOptions\
\
\
        wcsLayout       Group           wcsOptGroup\
        wcsOptGroup     Layout          wcsOptLayout\
\
	wcsOptLayout	Group		wcsCoords\
	wcsCoords	Layout		wcLayout\
	wcLayout	Label		wcTitle\
	wcLayout	Frame		wcLine\
	wcLayout	Label		wlWcs1\
	wcLayout	Label		wlWcs2\
	wcLayout	Label		wlWcs3\
	wcLayout	Label		wlWcs4\
	wcLayout	MenuButton	sysWcs1\
	wcLayout	MenuButton	sysWcs2\
	wcLayout	MenuButton	sysWcs3\
	wcLayout	MenuButton	sysWcs4\
	wcLayout	MenuButton	fmtWcs1\
	wcLayout	MenuButton	fmtWcs2\
	wcLayout	MenuButton	fmtWcs3\
	wcLayout	MenuButton	fmtWcs4\
	wcLayout	TextToggle	wpWcs1\
	wcLayout	TextToggle	wpWcs2\
	wcLayout	TextToggle	wpWcs3\
	wcLayout	TextToggle	wpWcs4\
	wcLayout	TextToggle	wiWcs1\
	wcLayout	TextToggle	wiWcs2\
	wcLayout	TextToggle	wiWcs3\
	wcLayout	TextToggle	wiWcs4\
\
	wcsOptLayout	Group		wcsOpts\
	wcsOpts		Layout		woLayout\
	woLayout	TextToggle	woptLabels\
	woLayout	TextToggle	woptTitles\
	woLayout	TextToggle	woptFBinfo\
	woLayout	TextToggle	woptBPM\
\
	wcsOptLayout	Group		wcsIsmGroup\
	wcsIsmGroup	Layout		wcsIsmLayout\
	wcsIsmLayout	Label		wcsIsmLabel\
	wcsIsmLayout	Frame		wcsIsmFrame\
	wcsIsmFrame	AsciiText	wcsIsmCmd\
	wcsIsmLayout	Command		wcsIsmInit\
\
\
	tile_panel 	Frame	 	tileOpts\
	tileOpts	Layout	 	toptLayout\
	toptLayout 	Group	 	tFramesG\
	toptLayout 	Group	 	tileMode\
	tileMode	TextToggle	tileDisabled\
	tileMode	TextToggle	tileManual\
	tileMode	TextToggle	tileBest\
	tileMode	TextToggle	tileSquare\
	tileMode	TextToggle	tileHorizontal\
	tileMode	TextToggle	tileVertical\
	tileMode	TextToggle	tileRow\
	tileMode	TextToggle	tileCol\
	toptLayout 	Group	 	userOrientG\
	toptLayout	Group		fillStyle\
	fillStyle	TextToggle	byCols\
	fillStyle	TextToggle	bottomUp\
	toptLayout	Group		tileLabel\
	tileLabel	TextToggle	labelImname\
	tileLabel	TextToggle	labelTitles\
	tileLabel	TextToggle	labelFrames\
	toptLayout	Frame		geomFrame\
	geomFrame	Label		tileGeometry\
\
	userOrientG	Layout		userOrientL\
	userOrientL  	Label	 	nrowLab\
	userOrientL  	Frame	 	nrFrame\
	nrFrame	 	Layout	 	nrLayout\
	nrLayout	Arrow	 	nrdecrease\
	nrLayout	Label	 	nrtext\
	nrLayout	Arrow	 	nrincrease\
	userOrientL  	Label	 	ncolLab\
	userOrientL  	Frame	 	ncFrame\
	ncFrame	 	Layout	 	ncLayout\
	ncLayout	Arrow	 	ncdecrease\
	ncLayout	Label	 	nctext\
	ncLayout	Arrow	 	ncincrease\
\
	tFramesG  	Layout	 	tFrames\
	tFrames  	Command  	tAll\
	tFrames  	Command  	tNone\
	tFrames  	Toggle  	tFrame1\
	tFrames  	Toggle  	tFrame2\
	tFrames  	Toggle  	tFrame3\
	tFrames  	Toggle  	tFrame4\
	tFrames  	Toggle  	tFrame5\
	tFrames  	Toggle  	tFrame6\
	tFrames  	Toggle  	tFrame7\
	tFrames  	Toggle  	tFrame8\
	tFrames  	Toggle  	tFrame9\
	tFrames  	Toggle  	tFrame10\
	tFrames  	Toggle  	tFrame11\
	tFrames  	Toggle  	tFrame12\
	tFrames  	Toggle  	tFrame13\
	tFrames  	Toggle  	tFrame14\
	tFrames  	Toggle  	tFrame15\
	tFrames  	Toggle  	tFrame16\
}


set Objects(parameters) { \
	toplevel	Parameter	ximtool\
	ximtool		Parameter	alert\
	ximtool		Parameter	initialize\
	ximtool		Parameter	resize\
	ximtool		Parameter	frame\
	ximtool		Parameter	nframes\
	ximtool		Parameter	frameSize\
	ximtool		Parameter	frameRegion\
	ximtool		Parameter	frameView\
	ximtool		Parameter	frameTitle\
	ximtool		Parameter	frameFit\
	ximtool		Parameter	enhancement\
	ximtool		Parameter	colortables\
	ximtool		Parameter	cmfocus\
	ximtool		Parameter	autoscale\
	ximtool		Parameter	antialias\
	ximtool		Parameter	tileFrames\
	ximtool		Parameter	cursorMode\
	ximtool		Parameter	xflip\
	ximtool		Parameter	yflip\
	ximtool		Parameter	printerList\
	ximtool		Parameter	printOptions\
	ximtool		Parameter	loadOptions\
	ximtool		Parameter	saveOptions\
	ximtool		Parameter	tileOptions\
	ximtool		Parameter	filelist\
	ximtool		Parameter	help\
	ximtool		Parameter	info\
	ximtool		Parameter	ism_msg\
}


set Objects(help_panel) { \
	toplevel	TopLevelShell 	help_panel\
	help_panel  	Layout	 	helpLayout\
	helpLayout  	Group	 	helpMenuGroup\
	helpMenuGroup  	Layout	 	helpMenubar\
	helpLayout  	Layout	 	helpInfoLayout\
\
	helpMenubar	Command	 	helpClose\
\
	helpLayout	Command	 	helpBack\
	helpLayout	Command	 	helpForward\
	helpLayout	Command	 	helpHome\
        helpLayout      Frame           hfFrame\
        hfFrame         AsciiText       hfEntry\
        helpLayout      Command         hfFind\
        helpLayout      Command         hfClear\
	helpLayout  	Frame	 	helpTextFrame\
	helpTextFrame 	HTML	 	helpText\
\
	helpInfoLayout	Label	 	helpIRAFLogo\
	helpInfoLayout	Label	 	helpInfo1\
	helpInfoLayout	Label	 	helpInfo2\
	helpInfoLayout	Label	 	helpInfo3\
	helpInfoLayout	Label	 	helpNOAOLogo\
}


set Objects(blink_panel) { \
	toplevel	TopLevelShell 	blink_panel\
	blink_panel  	Layout	 	bpLayout\
\
	bpLayout  	Frame	 	brMenuFrame\
	brMenuFrame  	Layout	 	brMenuBar\
	brMenuBar  	Command	 	brClose\
\
	bpLayout	Frame		brFrame\
	brFrame		Layout		brLayout\
\
	brLayout	Group	 	brFramesG\
	brFramesG  	Layout	 	brFrames\
	brFrames	MenuButton  	brFrame1\
	brFrames	MenuButton  	brFrame2\
	brFrames	MenuButton  	brFrame3\
	brFrames	MenuButton  	brFrame4\
	brFrames	MenuButton  	brFrame5\
	brFrames	MenuButton  	brFrame6\
	brFrames	MenuButton  	brFrame7\
	brFrames	MenuButton  	brFrame8\
	brFrames	MenuButton  	brFrame9\
	brFrames	MenuButton  	brFrame10\
	brFrames	MenuButton  	brFrame11\
	brFrames	MenuButton  	brFrame12\
	brFrames	MenuButton  	brFrame13\
	brFrames	MenuButton  	brFrame14\
	brFrames	MenuButton  	brFrame15\
	brFrames	MenuButton  	brFrame16\
\
	brLayout	Group	 	brCmdG\
	brCmdG	 	Layout	 	brCmd\
	brCmd	 	Command	 	brReset\
	brCmd	 	Label	 	brRateLabel\
	brCmd	 	Frame	 	brBRframe\
	brBRframe  	Layout	 	brBRlayout\
	brBRlayout  	Arrow	 	brBRdecrease\
	brBRlayout  	TextBox	 	brBRtext\
	brBRlayout  	Arrow	 	brBRincrease\
	brCmd	 	Command	 	brRegButton\
	brCmd	 	Command	 	brMatchButton\
	brCmd	 	TextToggle  	brBlinkButton\
	brCmd	 	TextToggle  	brAregButton\
}


set Objects(hdr_panel) { \
	toplevel	TopLevelShell 	hdr_panel\
	hdr_panel	Layout		hdrLayout\
\
	hdrLayout	Frame		hdrMenuFrame\
	hdrMenuFrame	Layout		hdrMenuBar\
	hdrMenuBar	Command		hdrClose\
\
	hdrLayout  	Group	 	hdrObjGroup\
	hdrObjGroup  	Layout	 	hdrObjLayout\
	hdrObjLayout 	Label	 	hdrObjLabel\
	hdrObjLayout	MenuButton  	hdrObjMenu\
\
	hdrLayout  	Frame	 	hdrTabFrame\
	hdrTabFrame  	Tabs	 	hdrTabs\
	hdrTabs	 	Group	 	hdrHdrGroup\
	hdrTabs	 	Group	 	hdrWcsGroup\
\
	hdrHdrGroup  	Layout	 	hdrHdrLayout\
        hdrHdrLayout    Frame           hFindFrame\
        hFindFrame      AsciiText       hFindEntry\
        hdrHdrLayout    Command         hdrFilter\
        hdrHdrLayout    Command         hdrFind\
        hdrHdrLayout    Command         hdrClear\
	hdrHdrLayout 	HTML  		hdrText\
\
	hdrWcsGroup	Layout		hdrWcsLayout\
	hdrWcsLayout	Group		hdrInfoGroup\
	hdrInfoGroup	Frame		hdrIGFrame\
	hdrIGFrame	AsciiText	hdrIGText\
	hdrWcsLayout	Group		hdrKeywGroup\
	hdrKeywGroup	Frame		hdrKGFrame\
	hdrKGFrame	AsciiText	hdrKGText\
}


set Objects(pixel_table) { \
	toplevel	TopLevelShell	pixel_panel\
\
	pixel_panel	Layout		pixel_table\
	pixel_table	Frame		pixtabMenuFrame\
	pixtabMenuFrame	Layout		pixtabMenuBar\
	pixtabMenuBar	MenuButton	pixtabSize\
	pixtabMenuBar	Command		pixtabHelp\
	pixtabMenuBar	Command		pixtabClose\
\
	pixel_table	Frame		pixtabFrame\
	pixtabFrame  	Porthole	ptPort\
	ptPort	 	Layout	 	ptLayout\
	ptLayout	Frame	 	ptColFrame\
	ptColFrame  	MultiList  	ptColLabs\
	ptLayout  	Frame	 	ptRowFrame\
	ptRowFrame  	MultiList  	ptRowLabs\
	ptLayout	Frame		ptFrame\
	ptFrame		MultiList	pixtab\
\
	ptLayout	Label		meanLabel\
	ptLayout	Frame		meanFrame\
	meanFrame	Label		meanValue\
\
	ptLayout	Label		sigLabel\
	ptLayout	Frame		sigFrame\
	sigFrame	Label		sigValue\
}


set Objects(tcl_panel) { \
	toplevel	TopLevelShell tcl_panel\
	tcl_panel  	Layout		tclLayout\
	tclLayout  	Group		tclCmdGroup\
	tclCmdGroup  	Layout	 	tclCmd\
	tclCmd	 	Command	 	tclClear\
	tclCmd	 	Command	 	tclExecute\
	tclCmd	 	Command	 	tclDismiss\
	tclLayout  	Frame	 	tclFrame\
	tclFrame	AsciiText  	tclEntry\
}


set Objects(warning) { \
	toplevel	TransientShell	warning\
	warning		Layout		warn\
	warn		Frame		warnFrame\
	warnFrame	Layout		WFlayout\
	WFlayout	Icon		warnIcon\
	WFlayout	TextBox		warnText\
	warn		Command		warnOk\
	warn		Command		warnCancel\
}


set Resources(global) {	\

    !---------------------------------------------------------
    ! Define some global widget resources for the main panels.
    !---------------------------------------------------------
    *shadowWidth:			1
    *background:			#c4c4c4
!   *foreground:			black
    *Arrow.width:			16
    *Arrow.height:			25
    *Text*height:			21
    *Command.height:			21
    *Command.highlightThickness:	1
    *MenuButton.height:			21
    *MenuButton.highlightThickness:	1
    *Label.borderWidth:			0
    *Label.shadowWidth:			0
    *TextButton.shadowWidth:		0
    *TextButton.highlightThickness:	1
    *TextToggle*borderWidth:		0
    *TextToggle.highlightThickness:	0
    *Toggle.highlightThickness:		1
    *Group.shrinkToFit:			True

    *Arrow.foreground:			gray
    *Arrow.background:			#adadad
    *Text*background:			#adadad
    *AsciiText*background:		#adadad
    *TextBox.background:		#adadad
    *MultiList*background:		#adadad
    *Slider2d.thumbColor:		#c4c4c4


    !-------------------------------------------------------------
    ! Define resources to take advantage of the	3D scrollbar look.
    !-------------------------------------------------------------
    *Scrollbar*background:		#c4c4c4
    *Scrollbar*shadowWidth:		1
    *Scrollbar*width:			15
    *Scrollbar*height:			15
    *Scrollbar*cursorName:		top_left_arrow
    *Scrollbar*pushThumb:		true

    *HTML.Scrollbar.shadowWidth:	1
    *HTML*Scrollbar*width:		15
    *HTML*Scrollbar*height:		15


    !----------------------------------------
    ! Menu resources giving a shadow effect.
    !----------------------------------------
    *SmeBSB.leftMargin:			10
    *SmeBSB.rightMargin:		5
    *SmeBSB.shadowWidth:		2
    *SmeBSB.foreground:			#e5e5e5
    *SmeBSB.background:			SteelBlue
    *SimpleMenu.background:		#c4c4c4
    *SimpleMenu.borderWidth:		2
    *SimpleMenu.borderColor:		black
    *SimpleMenu.line1.foreground:	#9c9c9c
    *SimpleMenu.line2.foreground:	#e8e8e8
    *SimpleMenu.line3.foreground:	#9c9c9c
    *SimpleMenu.line4.foreground:	#e8e8e8
    *SimpleMenu.line5.foreground:	#9c9c9c
    *SimpleMenu.line6.foreground:	#e8e8e8
    *SimpleMenu.line7.foreground:	#9c9c9c
    *SimpleMenu.line8.foreground:	#e8e8e8
    *SimpleMenu.line9.foreground:	#9c9c9c
    *SimpleMenu.line10.foreground:	#e8e8e8
    *SimpleMenu.line11.foreground:	#9c9c9c
    *SimpleMenu.line12.foreground:	#e8e8e8
    *SimpleMenu.line13.foreground:	#9c9c9c
    *SimpleMenu.line14.foreground:	#e8e8e8
    *SimpleMenu.line15.foreground:	#9c9c9c
    *SimpleMenu.line16.foreground:	#e8e8e8
    *SimpleMenu.line17.foreground:	#9c9c9c
    *SimpleMenu.line18.foreground:	#e8e8e8
    *SimpleMenu.line19.foreground:	#9c9c9c
    *SimpleMenu.line20.foreground:	#e8e8e8
    *SimpleMenu.line21.foreground:	#9c9c9c
    *SimpleMenu.line22.foreground:	#e8e8e8
    *SimpleMenu.line23.foreground:	#9c9c9c
    *SimpleMenu.line24.foreground:	#e8e8e8
    *SimpleMenu.line25.foreground:	#9c9c9c
    *SimpleMenu.line26.foreground:	#e8e8e8
    *SimpleMenu.line27.foreground:	#9c9c9c
    *SimpleMenu.line28.foreground:	#e8e8e8
    *SimpleMenu.line29.foreground:	#9c9c9c
    *SimpleMenu.line30.foreground:	#e8e8e8
    *SimpleMenu.line31.foreground:	#9c9c9c
    *SimpleMenu.line32.foreground:	#e8e8e8
    *SimpleMenu.line33.foreground:	#9c9c9c
    *SimpleMenu.line34.foreground:	#e8e8e8
    *SimpleMenu.line35.foreground:	#9c9c9c
    *SimpleMenu.line36.foreground:	#e8e8e8
    *SimpleMenu.line37.foreground:	#9c9c9c
    *SimpleMenu.line38.foreground:	#e8e8e8
    *SimpleMenu.line39.foreground:	#9c9c9c
    *SimpleMenu.line40.foreground:	#e8e8e8


    !---------------------------------------------
    !  Fixups for 24-bit displays
    !---------------------------------------------
    *hFindEntry.background:		#adadad
    *hdrIGText.background:		#adadad
    *hdrKGText.background:		#adadad
    *hfEntry.background:		#adadad
    *printcmd.background:		#adadad
    *titleString.background:		#adadad
    *fnameText.background:		#adadad
    *imtemplateText.background:		#adadad
    *z1Value.background:		#adadad
    *z2Value.background:		#adadad
    *nsampValue.background:		#adadad
    *saveFile.background:		#adadad
    *infoText.background:		#adadad
    *wtName.background:			#adadad
    *wtTitle.background:		#adadad
    *wtFBCfg.background:		#adadad
    *wtIPixval.background:		#adadad
    *wtSPixval.background:		#adadad
    *wtBPixval.background:		#adadad
    *wtWcs1.background:			#adadad
    *wtWcs2.background:			#adadad
    *wtWcs3.background:			#adadad
    *wtWcs4.background:			#adadad
    *wcsIsmCmd.background:		#adadad
    *tclEntry.background:		#adadad

    *hFindEntry.foreground:		#000000
    *hdrIGText.foreground:		#000000
    *hdrKGText.foreground:		#000000
    *hfEntry.foreground:		#000000
    *printcmd.foreground:		#000000
    *titleString.foreground:		#000000
    *fnameText.foreground:		#000000
    *imtemplateText.foreground:		#000000
    *z1Value.foreground:		#000000
    *z2Value.foreground:		#000000
    *nsampValue.foreground:		#000000
    *saveFile.foreground:		#000000
    *infoText.foreground:		#000000
    *wtName.foreground:			#000000
    *wtTitle.foreground:		#000000
    *wtFBCfg.foreground:		#000000
    *wtIPixval.foreground:		#000000
    *wtSPixval.foreground:		#000000
    *wtBPixval.foreground:		#000000
    *wtWcs1.foreground:			#000000
    *wtWcs2.foreground:			#000000
    *wtWcs3.foreground:			#000000
    *wtWcs4.foreground:			#000000
    *wcsIsmCmd.foreground:		#000000
    *tclEntry.foreground:		#000000
}
    
    
    
    

set Resources(ximtool) { \

    ! Main image window	resources.
    ! -------------------------------
    *allowShellResize:				True
    *beNiceToColormap:				False
    *menuLabel.foreground:			Gold
    *markerMenu.foreground:			White
    *rulerMenu.foreground:			White
    *display.imagewin.markerMenu.foreground:	White
    *display.imagewin.rulerMenu.foreground:	White
    *markerMenu.background:			SteelBlue
    *markerMenu*SimpleMenu.foreground:		White
    *markerMenu*SimpleMenu.background:		SteelBlue
    *rulerMenu.background:			SteelBlue
    *rulerMenu*SimpleMenu.foreground:		White
    *rulerMenu*SimpleMenu.background:		SteelBlue
    *rulerColor.SmeBSB.leftMargin:		16
    *magzoomMenu.foreground:			White
    *magzoomMenu.background:			SteelBlue
    *magzoomMenu*SimpleMenu.foreground:		White
    *magzoomMenu*SimpleMenu.background:		SteelBlue
    *markerColor.SmeBSB.leftMargin:		64
    *markerColor.SmeBSB.rightMargin:		0
    *markerColor.menuLabel.leftMargin:		5
    *markerColor.menuLabel.rightMargin:		5
    *rulerColor.SmeBSB.leftMargin:		64
    *rulerColor.SmeBSB.rightMargin:		0
    *rulerColor.menuLabel.leftMargin:		5
    *rulerColor.menuLabel.rightMargin:		5

    *ximtool.title:				XIMTOOL_VERSION

    *display.borderWidth:			2
    *display.layout: horizontal	{ \
	-0 \
	vertical { \
	    menuGroup  < +inf -inf * > \
	    horizontal { 1 toolbar < +inf -inf * > 1 } \
	    1 < -1 > \
	    horizontal { 1 panelbar < +inf -inf * > 1 } \
	    1 < -1 > \
	    vertical { \
	        horizontal { \
	            imageFrame < +inf -inf * +inf -inf > \
		    -2 \
	            vcutFrame  < * +inf -inf > \
	        } \
		-3 \
	        horizontal { \
	            hcutFrame  < +inf -inf * > 1 \
		    vertical { 4 horizontal { -4 plotOpts}  -4 } \
	        } \
		-3 \
	        horizontal { \
	            cbarFrame  < +inf -inf * > \
	            focusSlider 2 hcut 2 vcut 15 \
	        } \
	    } \
	} \
	-0 \
    }
    *hcut.label:				H
    *hcut.font:					*lucida-bold-r*10*
    *vcut.label:				V
    *vcut.font:					*lucida-bold-r*10*
    *focusSlider.location:			0 0 100 15

    *hcutFrame.frameType:                       sunken
    *hcutFrame.frameWidth:                      1
    *hcutFrame.innerOffset:             	1
    *hcutFrame.outerOffset:             	1
    //*hcutPlot.color0:                           #c4c4c4
    //*hcutPlot.color1:                           #000000
    *hcutPlot.color0:                           #000000
    *hcutPlot.color1:                           #ffffff
    *hcutPlot.crosshairCursorColor:		red
    *hcutPlot.width:                            512
    *hcutPlot.height:                           6
    *hcutPlot.borderWidth:			0
    *hcutPlot.alphaFont1:			6x10
    *hcutPlot.alphaFont2:			6x10
    *hcutPlot.alphaFont3:			6x10
    *hcutPlot.alphaFont4:			6x10
    *hcutPlot.alphaFont5:			6x10
    *hcutPlot.alphaFont6:			6x10
    *hcutPlot.alphaFont7:			6x10
    *hcutPlot.alphaFont8:			6x10
    *hcutPlot.translations:	\
	 !Ctrl	<Key>1:	call(cpZoom,1,1,fixed) 		\n\
	 !Ctrl	<Key>2:	call(cpZoom,2,2,fixed) 		\n\
	 !Ctrl	<Key>3:	call(cpZoom,3,3,fixed) 		\n\
	 !Ctrl	<Key>4:	call(cpZoom,4,4,fixed) 		\n\
	 !Ctrl	<Key>5:	call(cpZoom,5,5,fixed) 		\n\
	 !Ctrl	<Key>6:	call(cpZoom,6,6,fixed) 		\n\
	 !Ctrl	<Key>7:	call(cpZoom,7,7,fixed) 		\n\
	 !Ctrl	<Key>8:	call(cpZoom,8,8,fixed) 		\n\
	 !Ctrl	<Key>9:	call(cpZoom,9,9,fixed) 		\n\
	 !Ctrl	<Key>b:	call(prevFrame,$name)		\n\
	 !Ctrl	<Key>f:	call(nextFrame,$name)		\n\
	 !Ctrl	<Key>i:	call(cpInvert)		       	\n\
	 !Ctrl	<Key>m:	call(toggleMagnifier)		\n\
	 !Ctrl	<Key>n:	call(normalize)			\n\
	 !Ctrl	<Key>p:	call(togglePanner)		\n\
      !Ctrl Alt <Key>q: call(Quit)			\n\
	 !Ctrl	<Key>r:	call(cpRegisterFrames)		\n\
	 !Ctrl	<Key>s:	call(cpMatchFrames)		\n\
	 !Ctrl	<Key>u:	call(cpZoom,1,1,fixed) 		\n\
	  Ctrl	<Key>+:	call(cpZoom,2.0,2.0,relative)	\n\
	  Ctrl	<Key>-:	call(cpZoom,0.5,0.5,relative)	\n\
	  Ctrl <Key>\<:	call(cpSetBlinkRate,BRdecrease)	\n\
	  Ctrl <Key>\>:	call(cpSetBlinkRate,BRincrease)	\n\
	  !Alt	<Key>b:	call(toggleBlink)	     	\n\
	  !Alt	<Key>c:	call(displayPanel)		\n\
	  !Alt	<Key>h:	call(Help)		 	\n\
	  !Alt	<Key>i:	call(infoPanel)		      	\n\
      !Ctrl Alt <Key>f: call(fitFrame)		 	\n\
	  !Alt	<Key>l:	call(loadPanel)		      	\n\
	  !Alt	<Key>p:	call(printPanel)	       	\n\
	  !Alt	<Key>s:	call(savePanel)		      	\n\
	  !Alt	<Key>t:	call(tclPanel)		     	\n\
	   !<Btn1Down>:	call(makeMarker,$name,$x,$y) m_create()	\n\
	 <EnterWindow>:	enter-window()			\n\
	 <LeaveWindow>:	leave-window()			\n\
	    <KeyPress>:	graphics-input()		\n\
         !Alt <Motion>:	call(curtrack_msg,$x,$y)	\n\
	      <Motion>:	track-cursor() call(hcutWCSUpdate,$x,$y)


    *vcutFrame.frameType:                       sunken
    *vcutFrame.frameWidth:                      1
    *vcutFrame.innerOffset:             	0
    *vcutFrame.outerOffset:             	0
    //*vcutPlot.color0:                           #c4c4c4
    //*vcutPlot.color1:                           black
    *vcutPlot.color0:                           #000000
    *vcutPlot.color1:                           #ffffff
    *vcutPlot.crosshairCursorColor:		red
    *vcutPlot.width:                            6
    *vcutPlot.height:                           512
    *vcutPlot.borderWidth:			0
    *vcutPlot.alphaFont1:			6x10
    *vcutPlot.alphaFont2:			6x10
    *vcutPlot.alphaFont3:			6x10
    *vcutPlot.alphaFont4:			6x10
    *vcutPlot.alphaFont5:			6x10
    *vcutPlot.alphaFont6:			6x10
    *vcutPlot.alphaFont7:			6x10
    *vcutPlot.alphaFont8:			6x10
    *vcutPlot.translations:	\
	 !Ctrl	<Key>1:	call(cpZoom,1,1,fixed) 		\n\
	 !Ctrl	<Key>2:	call(cpZoom,2,2,fixed) 		\n\
	 !Ctrl	<Key>3:	call(cpZoom,3,3,fixed) 		\n\
	 !Ctrl	<Key>4:	call(cpZoom,4,4,fixed) 		\n\
	 !Ctrl	<Key>5:	call(cpZoom,5,5,fixed) 		\n\
	 !Ctrl	<Key>6:	call(cpZoom,6,6,fixed) 		\n\
	 !Ctrl	<Key>7:	call(cpZoom,7,7,fixed) 		\n\
	 !Ctrl	<Key>8:	call(cpZoom,8,8,fixed) 		\n\
	 !Ctrl	<Key>9:	call(cpZoom,9,9,fixed) 		\n\
	 !Ctrl	<Key>b:	call(prevFrame,$name)		\n\
	 !Ctrl	<Key>f:	call(nextFrame,$name)		\n\
	 !Ctrl	<Key>i:	call(cpInvert)		       	\n\
	 !Ctrl	<Key>m:	call(toggleMagnifier)		\n\
	 !Ctrl	<Key>n:	call(normalize)			\n\
	 !Ctrl	<Key>p:	call(togglePanner)		\n\
      !Ctrl Alt <Key>q: call(Quit)			\n\
	 !Ctrl	<Key>r:	call(cpRegisterFrames)		\n\
	 !Ctrl	<Key>s:	call(cpMatchFrames)		\n\
	 !Ctrl	<Key>u:	call(cpZoom,1,1,fixed) 		\n\
	  Ctrl	<Key>+:	call(cpZoom,2.0,2.0,relative)	\n\
	  Ctrl	<Key>-:	call(cpZoom,0.5,0.5,relative)	\n\
	  Ctrl <Key>\<:	call(cpSetBlinkRate,BRdecrease)	\n\
	  Ctrl <Key>\>:	call(cpSetBlinkRate,BRincrease)	\n\
	  !Alt	<Key>b:	call(toggleBlink)	     	\n\
	  !Alt	<Key>c:	call(displayPanel)		\n\
	  !Alt	<Key>h:	call(Help)		 	\n\
	  !Alt	<Key>i:	call(infoPanel)		      	\n\
      !Ctrl Alt <Key>f: call(fitFrame)		 	\n\
	  !Alt	<Key>l:	call(loadPanel)		      	\n\
	  !Alt	<Key>p:	call(printPanel)	       	\n\
	  !Alt	<Key>s:	call(savePanel)		      	\n\
	  !Alt	<Key>t:	call(tclPanel)		     	\n\
	   !<Btn1Down>:	call(makeMarker,$name,$x,$y) m_create()	\n\
	 <EnterWindow>:	enter-window()			\n\
	 <LeaveWindow>:	leave-window()			\n\
	    <KeyPress>:	graphics-input()		\n\
         !Alt <Motion>:	call(curtrack_msg,$x,$y)	\n\
	      <Motion>:	track-cursor() call(vcutWCSUpdate,$x,$y)


    *plotOpts.label:                            Options
    !*plotOpts*location:                         0 0 105 18
    *plotOpts*location:                         0 0 1 18
    *plotOpts.shrinkToFit:                      True
    *plotOpts.outerOffset:                      5
    *plotOpts.innerOffset:                      3
    *plotOpts.frameWidth:                       2
    *plotOpts*TextToggle.offIcon:               square0s
    *plotOpts*TextToggle.onIcon:                square1s
    *plotOpts*TextToggle.highlightColor:        yellow
    *plotOpts*TextToggle.outerOffset:           0
    *plotOpts*TextToggle.frameWidth:            0
    *plotOpts*TextToggle.selectionStyle:	multi
    *plotOpts*TextToggle.leftMargin:		3
    *plotOpts*TextToggle.alignment:		left

    *poptsLayout.borderWidth:			0
    *poptsLayout.layout: vertical { \
	-1 \
        plotSpeed plotAccurate plotImgPix \
	2 < -2 > \
        horizontal { -4 optLine < +inf -inf * > -4 } \
	2 < -2 > \
        curJump curSmooth curTrack \
	-1 \
     }
    *plotSpeed.label:				Better Speed
    *plotSpeed.on:			 	True
    *plotAccurate.label:			Better Accuracy
    *plotAccurate.on:				False
    *plotImgPix.label:				Image Pixels
    *plotImgPix.on:				False
    *plotImgPix.sensitive:			False
    *optLine.height:                            2
    *optLine.width:				120
    *optLine.outerOffset:			0
    *optLine.innerOffset:			0
    *optLine.frameWidth:                        2
    *optLine.frameType:                         chiseled
    *curJump.label:				Jump Cursor
    *curJump.on:				True
    *curSmooth.label:				Smooth Cursor
    *curSmooth.on:				False
    *curTrack.label:				Graphics Cursors
    *curTrack.on:				True


    *menuGroup.label:				
    *menuGroup.height:				38
    *menuGroup.width:				512
    *menuGroup.frameType:			raised
    *menuGroup.frameWidth:			2
    *menubar.layout: horizontal	{ \
	2 < -2 > \
	fileButton 1 < -1 > viewButton	1 < -1 > optionsButton \
	1 < -1	> \
	imageTitle < +inff -inff * > \
	1 < -1	> \
	mXflipButton 1	< -1 > mYflipButton \
	1 < -1	> \
	mPrevButton 1 < -1 > mFrameButton 1 < -1 > mNextButton	\
	1 < -1	> \
	toolButton 1 <	-1 > panelButton \
	2 < -2 > \
    }

    *menubar*SimpleMenu.foreground:		Black
    *menubar*SimpleMenu.borderWidth:		1
    *menubar*SimpleMenu.foreground:		White
    *menubar*SimpleMenu.background:		SteelBlue
    *SmeBSB.vertSpace:				10

    *menubar.width:				512
    *menubar*borderWidth:			0
    *menubar*Command.internalWidth:		0
    *menubar*Command.borderWidth:		0
    *menubar*Toggle.label:			x
    *menubar*Toggle.internalWidth:		0
    *menubar*Toggle.borderWidth:		0

    *toolbar.layout: horizontal	{ \
	tbZoomIn    < +inf -inf * > 1 < -1 > \
	tbZoom0     < +inf -inf * > 1 < -1 > \
	tbZoomOut   < +inf -inf * > 1 < -1 > \
	tbInvert    < +inf -inf * > 1 < -1 > \
	tbNormalize < +inf -inf * > 1 < -1 > \
	tbMatchLUT  < +inf -inf * > 1 < -1 > \
	tbAutoReg   < +inf -inf * > 1 < -1 > \
	tbRegister  < +inf -inf * > 1 < -1 > \
	tbCenter    < +inf -inf * > 1 < -1 > \
	tbBlinkDec  < +inf -inf * > 1 < -1 > \
	tbBlink	    < +inf -inf * > 1 < -1 > \
	tbBlinkInc  < +inf -inf * > 1 < -1 > \
	xflipButton < +inf -inf * > 1 < -1 > \
	yflipButton < +inf -inf * > 1 < -1 > \
	tbCompass   < +inf -inf * > 1 < -1 > \
	tbTile      < +inf -inf * > 1 < -1 > \
	prevButton  < +inf -inf * > 1 < -1 > \
	frameButton < +inf -inf * > 1 < -1 > \
	nextButton  < +inf -inf * > 1 < -1 > \
    }
    *toolbar.width:				512
    *toolbar.height:				25
    *toolbar*borderWidth:			0
    *toolbar*Command.internalWidth:		3
    *toolbar*Command.borderWidth:		0
    *toolbar*Toggle.internalWidth:		2
    *toolbar*Toggle.borderWidth:		0

    *panelbar.layout: horizontal { \
        pbDisplayP < +inf -inf * > 1 < -1 > \
	pbPrintP   < +inf -inf * > 1 < -1 > \
	pbLoadP    < +inf -inf * > 1 < -1 > \
	pbSaveP    < +inf -inf * > 1 < -1 > \
	pbInfoP    < +inf -inf * > 1 < -1 > \
	pbTileP    < +inf -inf * > 1 < -1 > \
	pbCoordP   < +inf -inf * > 1 < -1 > \
        pbPanM	   < +inf -inf * > 1 < -1 > \
	pbMagM     < +inf -inf * > 1 < -1 > \
	pbWcsM     < +inf -inf * > 1 < -1 > \
	pbIsm      < +inf -inf * > 1 < -1 > \
        helpButton < +inf -inf * > 1 < -1 > \
	pbQuit     < +inf -inf * > 1 < -1 > \
    }
    *panelbar*SimpleMenu.borderColor:		 Black
    *panelbar*SimpleMenu.borderWidth:		 1
    *SmeBSB.vertSpace:				 10

    *panelbar.width:				 12
    *panelbar.height:				 25
    *panelbar*borderWidth:			 0
    *panelbar*Label.internalWidth:		 4
    *panelbar*Label.borderWidth:		 0
    *panelbar*Command.internalWidth:		 4
    *panelbar*Command.borderWidth:		 0
    *panelbar*Toggle.internalWidth:		 3
    *panelbar*Toggle.borderWidth:		 0

    *pbLoadP.label:				Load
    *pbDisplayP.label:				Display
    *pbSaveP.label:				Save
    *pbPrintP.label:				Print
    *pbInfoP.label:				Info
    *pbTileP.label:				Tile
    *pbCoordP.label:				Coords
    *pbPanM.label:				Pan
    *pbPanM.state:				1
    *pbMagM.label:				Mag
    *pbMagM.state:				0
    *pbWcsM.label:				WCS
    *pbWcsM.state:				1
    *pbIsm.label:				ISM
    *pbIsm.state:				0
    *helpButton.label:				

    *fileButton.label:				File
    *fileButton.menuName:			fileMenu
    *viewButton.label:				View
    *viewButton.menuName:			viewMenu
    *optionsButton.label:			Options
    *optionsButton.menuName:			optionsMenu
    *toolButton.label:			
    *toolButton.state:				0
    *panelButton.label:			
    *panelButton.state:				0
    *imageTitle*font:				*times-bold-r*12*
    *imageTitle.width:				40
    *imageTitle.height:				20
    *frameButton.menuName:			frameMenu
    *frameButton.label:				1
    *frameButton.width:				20
    *mFrameButton.menuName:			mFrameMenu
    *mFrameButton.label:			1
    *mFrameButton.width:			20
    *pbQuit.label:				Quit
    *tbZoom0.label:				Mag
    *tbBlink.label:				Blink
    *tbBlink.internalWidth:			3
    *tbCenter.label:				Cntr
    *tbAutoReg.label:				AReg
    *tbRegister.label:				Reg
    *tbInvert.label:				Inv
    *tbNormalize.label:				Norm
    *tbMatchLUT.label:				Match

    *SimpleMenu*font:     -adobe-times-bold-r-normal-*-12-*-*-*-*-*-iso8859-1
    *fileButton.font:     -adobe-times-bold-i-normal-*-12-*-*-*-*-*-iso8859-1
    *optionsButton.font:  -adobe-times-bold-i-normal-*-12-*-*-*-*-*-iso8859-1
    *viewButton.font:     -adobe-times-bold-i-normal-*-12-*-*-*-*-*-iso8859-1
    *panelbar*font:	  -adobe-times-bold-i-normal-*-12-*-*-*-*-*-iso8859-1
    *toolbar*font:	  -adobe-times-bold-i-normal-*-12-*-*-*-*-*-iso8859-1

    *Gterm.cmapName:				image
    *Gterm.basePixel:				64
    *imageFrame.frameType:			sunken
    *imageFrame.frameWidth:			1
    *imageFrame.outerOffset:			0
    *imageFrame.innerOffset:			0
    *imageFrame.width:                          512
    *imageFrame.height:                         512
    *cbarFrame.frameType:			sunken
    *cbarFrame.frameWidth:			1
    *cbarFrame.outerOffset:			0
    *cbarFrame.innerOffset:			0
    *cbarFrame.width:                           512
    *imagewin.warpCursor:			true
    *imagewin.raiseWindow:			true
    *imagewin.deiconifyWindow:			true
    *imagewin.idleCursor:			crosshair
    *imagewin.ginmodeCursor:			circle
    *imagewin.ginmodeBlinkInterval:		500
    *imagewin.resizable:			true
    *imagewin.copyOnResize:			false
    *imagewin.width:				512
    *imagewin.height:				512
    *imagewin.maxMappings:			64
    *imagewin.borderWidth:			0

    *imagewin.translations:	\
	 None<Key>Left:	call(move_cursor,-1,0)		\n\
	 None<Key>Down:	call(move_cursor,0,1)		\n\
	   None<Key>Up:	call(move_cursor,0,-1)		\n\
        None<Key>Right: call(move_cursor,1,0)		\n\
      !Shift <Key>Left: call(move_cursor,-10,0)		\n\
      !Shift <Key>Down: call(move_cursor,0,10)		\n\
        !Shift <Key>Up: call(move_cursor,0,-10)		\n\
     !Shift <Key>Right: call(move_cursor,10,0)		\n\
	 !Ctrl	<Key>h:	call(move_cursor,-1,0)		\n\
	 !Ctrl	<Key>j:	call(move_cursor,0,1)		\n\
	 !Ctrl	<Key>k:	call(move_cursor,0,-1)		\n\
	 !Ctrl	<Key>l:	call(move_cursor,1,0)		\n\
    !Ctrl Shift <Key>h: call(move_cursor,-10,0)		\n\
    !Ctrl Shift <Key>j: call(move_cursor,0,10)		\n\
    !Ctrl Shift <Key>k: call(move_cursor,0,-10)		\n\
    !Ctrl Shift <Key>l: call(move_cursor,10,0)		\n\
       !Ctrl <Key>Left: call(moveFrame,-1,0)		\n\
       !Ctrl <Key>Down: call(moveFrame,0,1)		\n\
	 !Ctrl <Key>Up:	call(moveFrame,0,-1)		\n\
      !Ctrl <Key>Right: call(moveFrame,1,0)		\n\
   !Ctrl Alt <Key>Left: call(moveFrame,-0.5,0)		\n\
   !Ctrl Alt <Key>Down: call(moveFrame,0,0.5)		\n\
     !Ctrl Alt <Key>Up: call(moveFrame,0,-0.5)		\n\
  !Ctrl Alt <Key>Right: call(moveFrame,0.5,0)		\n\
	  !Alt	<Key>1:	call(cpSetFrame,frame1)		\n\
	  !Alt	<Key>2:	call(cpSetFrame,frame2)		\n\
	  !Alt	<Key>3:	call(cpSetFrame,frame3)		\n\
	  !Alt	<Key>4:	call(cpSetFrame,frame4)		\n\
	 !Ctrl	<Key>1:	call(cpZoom,1,1,fixed) 		\n\
	 !Ctrl	<Key>2:	call(cpZoom,2,2,fixed) 		\n\
	 !Ctrl	<Key>3:	call(cpZoom,3,3,fixed) 		\n\
	 !Ctrl	<Key>4:	call(cpZoom,4,4,fixed) 		\n\
	 !Ctrl	<Key>5:	call(cpZoom,5,5,fixed) 		\n\
	 !Ctrl	<Key>6:	call(cpZoom,6,6,fixed) 		\n\
	 !Ctrl	<Key>7:	call(cpZoom,7,7,fixed) 		\n\
	 !Ctrl	<Key>8:	call(cpZoom,8,8,fixed) 		\n\
	 !Ctrl	<Key>9:	call(cpZoom,9,9,fixed) 		\n\
	 !Ctrl	<Key>a:	call(tbToggleAutoReg)		\n\
	 !Ctrl	<Key>b:	call(prevFrame,$name)		\n\
	 !Ctrl	<Key>c:	call(cpZoomAction,centerFrame)	\n\
	 !Ctrl	<Key>f:	call(nextFrame,$name)		\n\
	 !Ctrl	<Key>i:	call(cpInvert)		       	\n\
	 !Ctrl	<Key>m:	call(toggleMagnifier)		\n\
	 !Ctrl	<Key>n:	call(normalize)			\n\
	 !Ctrl	<Key>o:	call(offset,$x,$y)		\n\
	 !Ctrl	<Key>p:	call(togglePanner)		\n\
      !Ctrl Alt <Key>q: call(Quit)			\n\
	 !Ctrl	<Key>r:	call(cpRegisterFrames)		\n\
	 !Ctrl	<Key>s:	call(cpMatchFrames)		\n\
	 !Ctrl	<Key>t:	call(tbTileFramesToggle)	\n\
	 !Ctrl	<Key>u:	call(cpZoom,1,1,fixed) 		\n\
	 !Ctrl	<Key>x:	call(cpFrameAction,flipX)	\n\
	 !Ctrl	<Key>y:	call(cpFrameAction,flipY)	\n\
	  Ctrl	<Key>+:	call(cpZoom,2.0,2.0,relative)	\n\
	  Ctrl	<Key>-:	call(cpZoom,0.5,0.5,relative)	\n\
      !Ctrl Alt <Key>=: call(Print)			\n\
	  Ctrl <Key>\<:	call(cpSetBlinkRate,BRdecrease)	\n\
	  Ctrl <Key>\>:	call(cpSetBlinkRate,BRincrease)	\n\
	  Ctrl <Key>\[:	call(setCtrBoxSize,$x,$y,-1)	\n\
	  Ctrl <Key>\]:	call(setCtrBoxSize,$x,$y,1)	\n\
	 !Ctrl	<Key>0:	call(centroid,$x,$y,peak) 	\n\
      !Ctrl Alt <Key>0:	call(centroid,$x,$y,min) 	\n\
	  !Alt	<Key>b:	call(toggleBlink)	     	\n\
	  !Alt	<Key>c:	call(displayPanel)		\n\
    !Ctrl Shift <Key>c:	call(displayPanel)		\n\
      !Ctrl Alt <Key>f: call(fitFrame)		 	\n\
	  !Alt	<Key>h:	call(Help)		 	\n\
	  !Alt	<Key>i:	call(infoPanel)		      	\n\
	  !Alt	<Key>l:	call(loadPanel)		      	\n\
	  !Alt	<Key>p:	call(printPanel)	       	\n\
	  !Alt	<Key>s:	call(savePanel)		      	\n\
	  !Alt	<Key>t:	call(tclPanel)		     	\n\
    !Ctrl Shift <Key>t:	call(tclPanel)		     	\n\
      !Shift<Btn1Down>: call(setDynamicMagnifier,1)	\n\
        !Shift<Btn1Up>: call(setDynamicMagnifier,0)	\n\
	   !<Btn1Down>:	call(makeMarker,$name,$x,$y) m_create()	\n\
     !Shift <Btn2Down>: crosshair(on)			\n\
   !Shift <Btn2Motion>: crosshair(on)			\n\
       !Shift <Btn2Up>: crosshair(off)			\n\
 	     !<Btn2Up>:	crosshair(off)			\n\
	   !<Btn2Down>:	call(zoom,$x,$y)		\n\
	   !<Btn3Down>:	call(windowColormap,$x,$y)	\n\
	     !<Btn3Up>:	call(updateColormap,$x,$y)	\n\
	 !<Btn3Motion>:	call(windowColormap,$x,$y)	\n\
      !Ctrl <Btn1Down>:	call(makeRuler,$name,$x,$y) 	\n\
    !Ctrl <Btn1Motion>:	track-cursor() call(wcsUpdate,$x,$y) call(magnifierMapImage,$x,$y) call(resizeRuler,$x,$y,0) 	\n\
        !Ctrl <Btn1Up>:	call(deleteRuler,$x,$y) 	\n\
	 <EnterWindow>:	enter-window()			\n\
	 <LeaveWindow>:	leave-window()			\n\
	    <KeyPress>:	graphics-input()		\n\
         !Alt <Motion>:	call(curtrack_msg,$x,$y)	\n\
	      <Motion>:	track-cursor() call(wcsUpdate,$x,$y) call(magnifierMapImage,$x,$y)

! The following	translations can be used to enable windowing of	the
! individual RGB components of the colormap.  It's not very useful but
! included here	for those that may wish	to use it.
!--------------------------------------------------------------------------
!     !Ctrl <Btn1Down>:	call(windowRGB,1,$x,$y,0)	\n\
!   !Ctrl <Btn1Motion>:	call(windowRGB,1,$x,$y,0)	\n\
!	!Ctrl <Btn1Up>:	call(windowRGB,1,$x,$y,1)	\n\
!     !Ctrl <Btn2Down>:	call(windowRGB,2,$x,$y,0)	\n\
!   !Ctrl <Btn2Motion>:	call(windowRGB,2,$x,$y,0)	\n\
!	!Ctrl <Btn2Up>:	call(windowRGB,2,$x,$y,1)	\n\
!     !Ctrl <Btn3Down>:	call(windowRGB,3,$x,$y,0)	\n\
!   !Ctrl <Btn3Motion>:	call(windowRGB,3,$x,$y,0)	\n\
!	!Ctrl <Btn3Up>:	call(windowRGB,3,$x,$y,1)	\n\


    *colorbar.maxRasters:			1
    *colorbar.maxMappings:			1
    *colorbar.height:				17
    *colorbar.width:				50
    *colorbar.borderWidth:			0
}


set Resources(panelShell) { \

    !================================
    !  Main Integrated Control Panel
    !================================
    *panelShell.title:				XImtool Control Panel
    *panelShell.geometry:			480x630
    *panelShell.maxWidth:			480
    *panelShell.minWidth:			480
    *panelTabs.internalHeight:			3
    *panelTabs.internalWidth:			10

    *Text*font:	 	 -*-helvetica-medium-r-normal-*-12-*-iso8859-1
    *TextBox*font:	 -*-helvetica-medium-r-normal-*-12-*-iso8859-1
    *List.font:	 	 -*-helvetica-medium-r-normal-*-12-*-iso8859-1
    *MultiList.font:	 -*-helvetica-medium-r-normal-*-12-*-iso8859-1
    *TextButton.font: 	 -*-helvetica-medium-r-normal-*-12-*-iso8859-1
    *TextToggle.font: 	 -*-helvetica-medium-r-normal-*-12-*-iso8859-1

    *display_panel.tabLabel:			Display
    *display_panel.innerOffset:			5
    *print_panel.tabLabel:			Print
    *print_panel.innerOffset:			5
    *load_panel.tabLabel:			Load
    *load_panel.innerOffset:			5
    *save_panel.tabLabel:			Save
    *save_panel.innerOffset:			5
    *info_panel.tabLabel:			Info
    *info_panel.innerOffset:			5
    *tile_panel.tabLabel:			Tile
    *tile_panel.innerOffset:			5
    *wcs_panel.tabLabel:			Coords
    *wcs_panel.innerOffset:			5

    *panelMenuBar*borderWidth:			0
    *panelMenuBar*Command.internalHeight:	4
    *panelMenuBar*Command.internalWidth:	15
    *panelMenuBar.layout: vertical { \
	5 < -5	> \
	horizontal { \
	    10	< +inf -10> \
	    panelHelp \
	    3 < -3 > \
	    panelClose	\
	    7 < -7 > \
	} \
	5 < -5	> \
    }

    *panelHelp.label:				Help
    *panelClose.label:				Dismiss


    *tabFrame.outerOffset:			3
    *tabFrame.innerOffset:			0
    *tabFrame.frameWidth:			0
    *tabFrame.frameType:			chiseled
    *panelMenuFrame.outerOffset:		0
    *panelMenuFrame.innerOffset:		1
    *panelMenuFrame.frameType:			raised
    *panelMenuFrame.frameWidth:			2
    *panel.layout: vertical { \
	panelMenuFrame	 < +inf	-inf * > \
	3 \
	horizontal { tabFrame < +inf -inf * +inf -inf>	} \
    }
} 


set Resources(display_panel) { \

    !================================
    ! Main Display Control Panel.
    !================================
    *controlPanel*internalWidth:		0
    *controlPanel*borderWidth:			0

    *TextBox.font:	7x13bold
    *TextToggle.font:	-adobe-times-medium-r-normal-*-12-*-*-*-*-*-iso8859-1
    *Command.font:	-adobe-times-bold-i-normal-*-12-*-*-*-*-*-iso8859-1
    *Toggle.font:	-adobe-times-medium-r-normal-*-12-*-*-*-*-*-iso8859-1
    *Label.font:	-*-helvetica-medium-r-normal-*-12-*-iso8859-1
    *MultiList.font:	-adobe-times-medium-r-normal-*-12-*-*-*-*-*-iso8859-1
    *toggleZoom.font:	-*-helvetica-medium-r-normal-*-12-*-iso8859-1
    *centerFrame.font:	-*-helvetica-medium-r-normal-*-12-*-iso8859-1
    *zoom*Command.font:	7x13bold

    *blinkFrame1.font:		-adobe-times-medium-r-normal-*-12-*-iso8859-1
    *blinkFrame2.font:		-adobe-times-medium-r-normal-*-12-*-iso8859-1
    *blinkFrame3.font:		-adobe-times-medium-r-normal-*-12-*-iso8859-1
    *blinkFrame4.font:		-adobe-times-medium-r-normal-*-12-*-iso8859-1
    *matchButton.font:		-adobe-times-medium-r-normal-*-12-*-iso8859-1
    *registerButton.font:	-adobe-times-medium-r-normal-*-12-*-iso8859-1
    *blinkButton.font:		-adobe-times-medium-r-normal-*-12-*-iso8859-1
    *autoregButton.font: 	-adobe-times-medium-r-normal-*-12-*-iso8859-1

    *controlPanel.layout: vertical { \
	5 < -5	> \
	horizontal { \
	    -1	\
	    viewBox < +inf -inf * > \
	    -1	\
	} \
	5 < -5	> \
	horizontal { \
	    -1	\
	    enhancementBox < +inf -inf	* +inf -inf > \
	    -5	\
	    vertical {	\
		-1 \
		blinkBox < * +inf - inf > \
		 1 \
		optionsBox < * +inff -inff > \
		-1 \
	    } \
	    -1	\
	} \
	-5 \
	controlBox < +inf * > \
	-5 \
    }

    ! VIEW
    ! ------------------
    *viewBox.label:				View
    *viewBox.location:				0 0 410 0
    *viewBox.shrinkToFit:			True
    *viewBox.outerOffset:			7

    *view.layout: vertical { \
	5 < +inf -5 > \
	horizontal { \
	    -1	\
	    frameSelect \
	    vertical {	\
		3 < -3 > \
		frameDataBox < +inff -100% * +inff -100% > \
		3 < -3 > \
	    } \
	    zoomBox \
	    -1	\
	} \
	1 < +inf > \
	viewButtons < +inf -inf * +inf	-inf > \
	5 < +inf -5 > \
    }

    *frameDataBox.frameType:			sunken
    *frameDataBox.frameWidth:			1
    *frameData.width:				150
    *frameData.height:				50

    *frameSelect.location:			0 0 72 0
    *frameSelect.shrinkToFit:			True
    *frameSelect.outerOffset:			7
    *frameSelect.innerOffset:			2
    *frameSelect.frameWidth:			2
    *frameSelect*offIcon:			diamond0s
    *frameSelect*onIcon:			diamond1s
    *frameSelect*highlightColor:		blue
    *frameSelect.label:				Frame

    *frameBox.layout: vertical { \
	3 \
	horizontal { -2	frlistBox < * +inff -inff > } \
	3 < +inf -3 > \
	horizontal { prevFrame < +inf -inf * > 4 nextFrame < +inf -inf * > } \
    }
    *framePort.allowVert:			True
    *framePort.allowHoriz:			False
    *framePort.useRight:			True
    *framePort.height:				80

    *frameBox*alignment:			left
    *frameBox*frameWidth:			0
    *frameBox*frame1.label:			1\ \ 
    *frameBox*frame2.label:			2\ \ 
    *frameBox*frame3.label:			3\ \ 
    *frameBox*frame4.label:			4\ \ 

    *frameBox*frame5.label:			5\ \ 
    *frameBox*frame6.label:			6\ \ 
    *frameBox*frame7.label:			7\ \ 
    *frameBox*frame8.label:			8\ \ 
    *frameBox*frame9.label:			9\ \ 
    *frameBox*frame10.label:			10\ 
    *frameBox*frame11.label:			11\ 
    *frameBox*frame12.label:			12\ 
    *frameBox*frame13.label:			13\ 
    *frameBox*frame14.label:			14\ 
    *frameBox*frame15.label:			15\ 
    *frameBox*frame16.label:			16\ 
    *frameBox*Command.width:			24
    *frameBox*prevFrame.label:			xxx
    *frameBox*nextFrame.label:			xxx

    *frameList*location:			0 0 50 20
    *frameList.layout: vertical	{ \
	frame1	< +inf * >\
	frame2	< +inf * >\
	frame3	< +inf * >\
	frame4	< +inf * >\
	frame5	< +inf * >\
	frame6	< +inf * >\
	frame7	< +inf * >\
	frame8	< +inf * >\
	frame9	< +inf * >\
	frame10 < +inf * >\
	frame11 < +inf * >\
	frame12 < +inf * >\
	frame13 < +inf * >\
	frame14 < +inf * >\
	frame15 < +inf * >\
	frame16 < +inf * >\
    }


    *zoomBox.label:				Zoom:
    *zoomBox.location:				0 0 160 127
    *zoomBox.outerOffset:			7
    *zoomBox.shrinkToFit:			True
    *zoomBox*TextButton.frameWidth:		1
    *zoomBox*TextButton.outerOffset:		0

    *controlPanel*zoom*internalWidth:		4
    *zoom.layout: vertical { \
	space = ((50% of width	zoom) -	(50% of	width z5)) \
	1 < +inf > \
	horizontal { \
	    vertical { toggleZoom < +inf * +inf > 1 } \
	    1 \
	    vertical { 1 < +inf > z5 1 < +inf > z3 0 < +inf > } \
	    1 \
	    vertical { zoomIn < +inf	* +inf > 1 } \
	} \
	1 \
	horizontal { \
	    1 < +inf >	\
	    d8	1 d4 1 d2 1 x1 1 z2 1 z4 1 z8 \
	    1 < +inf >	\
	} \
	1 \
	horizontal { \
	    vertical { 1 zoomOut < +inf * +inf	> } \
	    1 \
	    vertical { 0 < +inf > d3 1 < +inf > d5 1 < +inf > } \
	    1 \
	    vertical { 1 centerFrame <	+inf * +inf > } \
	} \
	1 < +inf > \
    }

    *toggleZoom.label:				Toggle\nZoom
    *toggleZoom.outerOffset:			2
    *toggleZoom.width:				30
    *toggleZoom.height:				25

    *zoomIn.label:				Zoom\nIn
    *zoomIn.outerOffset:			2
    *zoomIn.width:				30
    *zoomIn.height:				25

    *x1.label:					1
    *z2.label:					2
    *z3.label:					3
    *z4.label:					4
    *z5.label:					5
    *z8.label:					8

    *controlPanel*zoomIn.foreground:		royalBlue3
    *controlPanel*z4.foreground:		royalBlue3
    *controlPanel*z5.foreground:		royalBlue3
    *controlPanel*z8.foreground:		royalBlue3
    *controlPanel*z2.foreground:		royalBlue3
    *controlPanel*z3.foreground:		royalBlue3

    *zoomOut.label:				Zoom\nOut
    *zoomOut.outerOffset:			2
    *zoomOut.width:				30
    *zoomOut.height:				25

    *centerFrame.label:				Center
    *centerFrame.outerOffset:			2
    *centerFrame.width:				30
    *centerFrame.height:			25

    *d2.label:					2
    *d3.label:					3
    *d4.label:					4
    *d5.label:					5
    *d8.label:					8

    *controlPanel*zoomOut.foreground:		mediumVioletRed
    *controlPanel*d2.foreground:		mediumVioletRed
    *controlPanel*d3.foreground:		mediumVioletRed
    *controlPanel*d4.foreground:		mediumVioletRed
    *controlPanel*d5.foreground:		mediumVioletRed
    *controlPanel*d8.foreground:		mediumVioletRed

    *viewButtons.location:			0 0 100 80
    *viewButtons.layout: horizontal { \
	2 < -2 > \
	aspect     < +inf * > 2 \
	flipX      < +inf * > 2 \
	flipY      < +inf * > 2 \
	flipXY     < +inf * > 2 \
	clearFrame < +inf * > 2 \
	fitFrame   < +inf * >   \
	2 < -2 > \
    }
    *nextFrame.label:				Next Frame
    *prevFrame.label:				Previous Frame
    *fitFrame.label:				Fit Frame
    *aspect.label:				Aspect
    *clearFrame.label:				Clear Frame
    *flipX.label:				Flip X
    *flipY.label:				Flip Y
    *flipXY.label:				Flip XY


    ! ENHANCEMENT
    ! ------------------
    *enhancementBox.label:			Enhancement
    *enhancementBox.location:			0 0 110	0
    *enhancementBox.shrinkToFit:		True
    *enhancementBox.outerOffset:		7

    *enhance*Viewport.allowVert:		True
    *enhance*Viewport.allowHoriz:		False
    *enhance*Viewport.useRight:			False
    *enhance*Viewport.resizeable:		True
    *enhance*Scrollbar.width:			17
    *enhance*Scrollbar.minimumThumb:		10
    *enhance.layout: vertical {	\
	3 < -3	> \
	horizontal { \
	    2 < -2 > \
	    colorlistFrame < +inf -inf	* +inff	-inff >	\
	    2 < -2 > \
	} \
	2 \
	horizontal { \
	    2 < -2 > \
	    colordataFrame < +inf -inf	* +inf -inf > \
	    2 < -2 > \
	} \
	5 < -5	> \
	horizontal { \
	    2 < -2 > \
	    vertical { -1 contrastLabel 3 < -3 > brightnessLabel -1 } \
	    3 < -3 > \
	    vertical {	\
		-1 \
		contrastSlider < +inf -inf * > \
		3 < -3 > \
		brightnessSlider < +inf -inf * > \
		-1 \
	    } \
	    2 < -2 > \
	} \
	5 < -5	> \
	horizontal { \
	    3 < -3 > \
	    invertButton < +inf -inf *	> \
	    5 < -5 > \
	    optimizeButton < +inf -inf	* > \
	    3 < -3 > \
	} \
	3 < -3	> \
    }

    *enhance*frameType:				sunken
    *enhance*frameWidth:			1
    *enhance*BorderWidth:			0
    *enhance*Label.ShadowWidth:			0

    *colorlist.width:				100
    *colorlist.height:				98
    *colordata.width:				100
    *colordata.height:				45
    *enhance*colordata.frameWidth:		0
    *contrastLabel.label:			x
    *contrastSlider.location:			0 0 100	17
    *brightnessLabel.label:			x
    *brightnessSlider.location:			0 0 100 17
    *invertButton.label:			Invert
    *optimizeButton.label:			Optimize


    ! ---------------------
    ! BLINK/REGISTER
    ! ---------------------
    *blinkBox.label:				Blink/Register
    *blinkBox.location:				0 0 235 0
    *blinkBox.shrinkToFit:			True
    *blinkBox.outerOffset:			7
    *blinkBox*TextToggle.frameWidth:		1

    *blink.layout: vertical { \
	space = (width	blinkFramesLabel - width blinkRateLabel) \
	3 < -3	> \
	horizontal { \
	    0 \
	    blinkFramesLabel \
	    3 < +inf >	\
	    blinkFrame1 < -50%	* > \
	    blinkFrame2 < -50%	* > \
	    blinkFrame3 < -50%	* > \
	    blinkFrame4 < -50%	* > \
	    4 < +inf >	\
	    blinkPanel	 < -50%	* > \
	    blinkReset	\
	    2 \
	} \
	5 < -5	> \
	horizontal { \
	    $space \
	    blinkRateLabel \
	    2	\
	    BRframe < +inf * >	\
	} \
	5 < +inf -100%	> \
	horizontal { \
	    vertical {	\
		2 matchButton	< +inf * > 4 < -4 > registerButton < +inf * > \
	    } \
	    5 < -5 > \
	    vertical {	\
		1 blinkButton	< +inf * > 4 < -4 > autoregButton < +inf * > \
	    } \
	} \
    }

    *BRlayout.layout: horizontal { \
	BRdecrease \
	BRtext	< +inf -100% * > \
	BRincrease \
    }

    *blink.Label.borderWidth:			0
    *blink.Label.shadowWidth:			0
    *controlPanel*blink*internalWidth:		4
    *blink.TextToggle.location:			0 0 102 23
    *blink.TextToggle.frameWidth:		1
    *blink*TextToggle.highlightColor:		yellow
    *blink*TextToggle.offIcon:			square0s
    *blink*TextToggle.onIcon:			square1s
    *blink*TextToggle.outerOffset:		1
    *blink*Command.height:			27
    *blink*Arrow.width:				16
    *blink*Arrow.height:			25


    *blinkFramesLabel.label:			Frames List:
    *blinkFrame1.label:				1
    *blinkFrame2.label:				2
    *blinkFrame3.label:				3
    *blinkFrame4.label:				4
    *blinkPanel.label:				x
    *blinkPanel.width:				20
    *blinkReset.label:				Reset

    *blinkRateLabel.label:			Blink Rate:
    *BRframe.frameType:				sunken
    *BRframe.frameWidth:			1
    *BRtext.width:				40
    *BRtext.height:				23
    *BRdecrease.direction:			left
    *BRincrease.direction:			right
    *registerButton.label:			Register
    *matchButton.label:				Match LUTs
    *blinkButton.label:				Blink
    *autoregButton.label:			Auto-Register

    ! OPTIONS
    ! ---------------------
    *optionsBox.label:				Options
    *optionsBox.location:			0 0 220 0
    *optionsBox.shrinkToFit:			False
    *optionsBox.outerOffset:			7
    *optionsBox*offIcon:			square0s
    *optionsBox*onIcon:				square1s
    *optionsBox*selectionStyle:			multi
    *optionsBox*highlightColor:			yellow
    *optionsBox.TextToggle.location:		0 0 102 20
    *optionsBox.TextToggle.frameWidth:		0
    *optionsBox.TextToggle.highlightThickness:	0
    *optionsBox*alignment:			left

    *pannerButton.label:			Panner
    *coordsBoxButton.label:			Coords Box
    *autoscaleButton.label:			Autoscale
    *antialiasButton.label:			Antialias
    *tileFramesButton.label:			Tile Frames
    *magnifierButton.label:			Magnifier
    *warningsButton.label:			Warnings
    *peakupButton.label:			Centroid Peaks
    *peakupButton.on:				True

    ! CONTROL
    ! ----------------------
    *controlBox.frameType:			chiseled
    *controlBox.frameWidth:			2
    *controlBox.outerOffset:			7
    *controlBox.innerOffset:			5
    *controlBox.height:				30

    *control.layout: horizontal	{ \
	1 \
	initializeButton < +inf * > \
	5 < -5	> \
	normalizeButton < +inf	* > \
	80 < +inf -100% > \
    }

    *initializeButton.label:			Initialize
    *normalizeButton.label:			Normalize
}


set Resources(print_panel) { \

    !=====================================
    !  Print Setup Panel resources.	!
    !=====================================
    *print_panel*TextToggle.alignment:		left
    *print_panel*Arrow.width:			16
    *print_panel*Arrow.height:			20
    *print_panel*TextToggle.frameWidth:		0
    *print_panel*TextToggle.height:		20
    *print_panel*Label.borderWidth:		0
    *print_panel*Label.shadowWidth:		0
    *print_panel*TextButton.width:		40
    *print_panel*TextButton.height:		25

    *printLayout.borderWidth:			0
    *printLayout.layout: vertical { \
	-1 \
	printCmdGroup < +inf *	> \
	-1 \
	optGroup < +inf -inf *	+inf -inf > \
	-3 \
	cmdGroup < +inf * > \
	-1\
    }


    ! Print Group resources.
    !----------------------------------
    *printCmdGroup.borderWidth:			0
    *printCmdGroup.outerOffset:			5
    *printCmdGroup.label:			
    *printCmdGroup.location:			0 0 400 80
    *printCmdGroup*offIcon:			diamond0s
    *printCmdGroup*onIcon:			diamond1s
    *printCmdGroup*highlightColor:		cyan
    *printCmdGroup*Frame.frameType:		sunken
    *printCmdGroup*Frame.frameWidth:		1
    *printCmdGroup*Frame.width:			300
    *printCmdGroup*Label.justify:		right
    *printCmdGroup*Text*editType:		edit
    *printCmdGroup*Text*height:			22
    *printCmdGroup*TextToggle.width:		70
    *printCmdGroup*shadowWidth:			0
    *printCmdGroup*borderWidth:			0
    *printCmdLayout.borderWidth:		0
    *printCmdLayout.layout: horizontal { \
	labelLayout 5 inputLayout < +inf -inf * > \
    }
    *labelLayout.borderWidth:			0
    *labelLayout.layout: vertical { 5 toLabel 7 printerLabel }
    *printerLabel.label:			Print Command:
    *toLabel.label:				Print To:
    *toPrinter.label:				Printer
    *toPrinter.on:				True
    *toFile.label:				File

    *inputLayout.borderWidth:			0
    *inputLayout.layout: horizontal { \
	3 \
	vertical { \
	    5 \
	    horizontal { 5 toPrinter 5 toFile 5 < +inf -inf > } \
	    5 \
	    printcmdFrame < +inf -inf * > \
	    5 \
	} \
	3 \
    }
    *printcmd*string:				lpr
    *printcmd*height:				22
    *printcmd*Text*editType:			edit


    !  Main options groups layout resources.
    !---------------------------------------
    *optGroup.frameWidth:			2
    *optGroup.frameType:			chiseled
    *optGroup.label:			
    *optGroup.location:				0 0 400 330
    *optGroup.outerOffset:			5
    *optGroup.innerOffset:			2
    *optLayout*borderWidth:			0
    *optLayout.layout: vertical	{ \
	-1 \
	horizontal { \
	    vertical {	\
		5 \
		epsPageGroup < +inf -inf * >	\
		optionsGroup < +inf -inf * +inf -inf > \
		-1 \
	    } \
	    vertical {	\
		5 \
		printColorGroup  < +inf -inf * > \
		printerGroup	< +inf -inf * >	\
		-1 \
	    } \
	    -1	\
	} \
	5 \
	horizontal { annOptsGroup < +inf * +inf	> -1 } \
	-1 \
    }


    ! Postscript Options group resources.
    ! -----------------------------------
    *epsPageGroup.label:			Postscript Options
    *epsPageGroup.outerOffset:			7
    *epsPageGroup.innerOffset:			5
    *epsPageGroup.location:			0 0 250 150
    *epsPageGroup*offIcon:			diamond0s
    *epsPageGroup*onIcon:			diamond1s
    *epsPageGroup*highlightColor:		cyan
    *epsPage*Label.justify:			left
    *epsPage.layout: vertical {	\
	-1 \
	epsOrientLabel	4 < -4 > \
	horizontal { 25 epsPortButton epsLandButton epsSquareButton -1 } \
	4 \
	epsSizeLabel -1 \
	horizontal { \
	    25 epsLetterButton epsLegalButton epsA4Button epsB5Button -1 \
	} \
	10 \
	horizontal { 5 epsScaleLabel 4 ScaleFrame < +inf -inf * > } \
	-1 \
    }


    ! Page Layout resources.
    ! -------------------------------
    *epsOrientLabel.label:			Orientation:
    *epsPortButton.label:			Portrait
    *epsPortButton.width:			65
    *epsLandButton.label:			Landscape
    *epsLandButton.width:			85
    *epsSquareButton.label:			Square
    *epsSquareButton.width:			70
    *epsSquareButton.sensitive:			False

    *epsSizeLabel.label:			Paper Size:
    *epsLetterButton.label:			Letter
    *epsLetterButton.width:			60
    *epsLegalButton.label:			Legal
    *epsLegalButton.width:			60
    *epsA4Button.label:				A4
    *epsA4Button.width:				50
    *epsB5Button.label:				B5
    *epsB5Button.width:				50

    ! Image scale box resources.
    ! -------------------------------
    *epsScaleLabel.label:			Output  Image  Scale:
    *epsScaleLabel.justify:			right
    *ScaleFrame.frameType:			sunken
    *ScaleFrame.frameWidth:			1
    *ScaleFrame*shadowWidth:			0
    *ScaleLayout.location:			0 0 100 35
    *ScaleLayout.label:			 
    *ScaleLayout.layout: horizontal { \
	SCdecrease SCtext < +inf -100% * > SCincrease \
    }
    *SCdecrease.direction:			left
    *SCtext.width:				75
    *SCtext.height:				22
    *SCtext.label:				100 %
    *SCincrease.direction:			right


    ! Miscellaneous print options box resources.
    ! ------------------------------------
    *optionsGroup.outerOffset:			7
    *optionsGroup.innerOffset:			5
    *optionsGroup*onIcon:			square1s
    *optionsGroup*offIcon:			square0s
    *optionsGroup.label:			Processing Options
    *optionsGroup*TextToggle.width:		125
    *optionsGroup*TextToggle.highlightColor:	yellow
    *options.location:				0 0 250 60
    *options.frameWidth:			2
    *options.layout: horizontal	{ \
	5 \
	vertical { -1 epsscaleButton 2	autorotateButton -1 } \
	3 \
	vertical { -1 aspectButton   2	compressButton	 -1 } \
	-1 \
    }
    *epsscaleButton.label:			Auto Scale
    *autorotateButton.label:			Auto Rotate
    *aspectButton.label:			Max Aspect
    *compressButton.label:			RLE Compress
    *compressButton.sensitive:			False


    ! Annotation options box resources.
    ! ------------------------------------
    *annOptsGroup.outerOffset:			7
    *annOptsGroup.innerOffset:			5
    *annOptsGroup*onIcon:			square1s
    *annOptsGroup*offIcon:			square0s
    *annOptsGroup.label:			Annotation Options
    *annOptsGroup*TextToggle.width:		90
    *annOptsGroup*TextToggle.highlightColor:	yellow
    *annOptsGroup*Frame.frameType:		sunken
    *annOptsGroup*Frame.frameWidth:		1
    *annOptsGroup*Frame.width:			300
    *annOptsGroup*Text*editType:		edit
    *annOpts.frameWidth:			2
    *annOpts.location:				0 0 400 70
    *annOpts.layout: vertical {	\
	2 \
	horizontal { \
	    5 annotateButton 2 titleButton 2 bordersButton 2 colorbarButton 5 \
	} \
	3 \
	horizontal { -1 titleLabel 2 titleFrame < +inf -inf * > -1 } \
	-1 \
    }
    *annotateButton.label:			\ Annotate
    *titleButton.label:				\ Title
    *bordersButton.label:			\ Borders
    *colorbarButton.label:			\ Colorbar
    *titleLabel.label:				Title String
    *titleString*string:			imtitle
    *titleString*height:			23
    *titleString*Text*editType:			edit


    ! Output color box resources.
    ! ------------------------------
    *printColorGroup.location:			0 0 150 90
    *printColorGroup.outerOffset:		7
    *printColorGroup.frameWidth:		2
    *printColorGroup*offIcon:			diamond0s
    *printColorGroup*onIcon:			diamond1s
    *printColorGroup*highlightColor:		cyan
    *printColorGroup.innerOffset:		5
    *printColorGroup.label:			Output Color
    *printColorGroup*TextToggle.width:		110
    *printColor.frameWidth:			2
    *printColor.location:			0 0 250 75
    *printColor.layout:	horizontal { \
	1 \
	vertical { -1 prGrayButton 2 prPseudoButton 2 prRGBButton -1 }	\
	-1 \
    }
    *prGrayButton.label:			Grayscale
    *prPseudoButton.label:			PseudoColor
    *prRGBButton.label:				RGB

    ! Printer Selection.
    ! --------------------------
    *printerGroup.label:			Printers
    *printerGroup.location:			0 0 110 130
    *printerGroup.shrinkToFit:			True
    *printerGroup.outerOffset:			7

    *printers*Viewport.allowVert:		True
    *printers*Viewport.allowHoriz:		False
    *printers*Viewport.useRight:		True
    *printers*Viewport.resizeable:		True
    *printers*Scrollbar.width:			17
    *printers*Scrollbar.minimumThumb:		10
    *printers.layout: vertical { \
	3 < -3	> \
	horizontal { \
	    2 < -2 > \
	    printlistFrame < +inf -inf	* +inff	-inff >	\
	    2 < -2 > \
	} \
	3 < -3	> \
    }

    *printers*frameType:			sunken
    *printers*frameWidth:			1
    *printers*BorderWidth:			0
    *printers*Label.ShadowWidth:		0

    *printlist.width:				100
    *printlist.height:				78


    ! Panel command resources.
    ! ------------------------------
    *cmdGroup.frameType:			chiseled
    *cmdGroup.frameWidth:			2
    *cmdGroup.outerOffset:			5
    *cmdGroup.innerOffset:			5
    *cmdGroup.label:
    *cmdGroup.location:				0 0 150 50
    *cmdLayout.borderWidth:			0
    *cmdLayout*Command.internalWidth:       	12
    *cmdLayout.layout: horizontal { \
	2 \
	okayPrint 1 < +inf > printStatus < +inf -inf *	+inf -inf > \
	2 \
    }
    *cmdGroup*TextButton*location:		0 0 80 0
    *okayPrint.label:				Print
}


set Resources(info_panel) { \

    !--------------------
    ! Information Panel
    !--------------------
    *infoLayout*borderWidth:			0
    *infoLayout*Frame.frameType:		sunken
    *infoLayout*Frame.frameWidth:		1
    *infoLayout*Command.internalWidth:		12
    *infoLayout*Text*editType:			read
    *infoLayout*Text*scrollVertical:		whenNeeded
    *infoLayout*Text*scrollHorizontal:		whenNeeded
    *infoLayout*Text*displayCaret:		False
    *infoLayout*Scrollbar.background:		#c4c4c4
    *infoLayout*Scrollbar.width:		17
    *infoLayout*Scrollbar.height:		17

    *infoText.height:				240
    *infoText*font:      			6x13
    *infoLayout.layout:	vertical { \
	infoBox  < +inf -inf * > \
    }

    *infoBox.label:
    *infoBox.outerOffset:			0
    *infoBox.innerOffset:			3
    *infoBoxL*TextToggle.frameType:		raised
    *infoBoxL*TextToggle.frameWidth:		1
    *infoBoxL*TextToggle*outerOffset:		0
    *infoBoxL*TextToggle*innerOffset:		1
    *infoBoxL*TextToggle.location:		0 0 100 25
    *infoBoxL*TextToggle*onIcon:		square1s
    *infoBoxL*TextToggle*offIcon:		square0s
    *infoBoxL*TextToggle*highlightColor:	cyan
    *infoBoxL.layout: vertical { \
	infoFrame < +inf -inf * +inf -inf > 1 \
	4 \
	horizontal { \
	    infoOptFr	< +inf -inf * > 1 \
	    infoOptSvr  < +inf -inf * > 1 \
	    infoOptClients  < +inf -inf * > 1 \
	    infoOptWCS  < +inf -inf * > 1 \
	    infoOptIsm  < +inf -inf * > 1 \
	    infoOptFB	< +inf -inf * >   \
	}\
 	2 \
    }
    *infoOptFr.label:				Frame
    *infoOptFr.on:				True
    *infoOptSvr.label:				Server
    *infoOptWCS.label:				WCS
    *infoOptIsm.label:				ISM
    *infoOptClients.label:			Clients
    *infoOptFB.label:				Imtoolrc
}



set Resources(load_panel) { \

    !-------------------------------
    ! File Load	Control	Panel.
    !-------------------------------
    *filesLayout*borderWidth:			0
    *filesLayout*Group.shrinkToFit:		True
    *filesLayout*Group.frameType:		chiseled
    *filesLayout*Frame*frameType:		sunken
    *filesLayout*Frame*frameWidth:		1
    *filesLayout*TextToggle.frameWidth:		0
    *filesLayout*TextToggle.height:		28
    *filesLayout*TextToggle.alignment:		left
    *filesLayout*TextToggle.ledtMargin:		3
    *filesLayout*SimpleMenu.borderWidth:        1
    *filesLayout*SimpleMenu.borderColor:        black
    *filesLayout*SimpleMenu.foreground:         White
    *filesLayout*SimpleMenu.background:         SteelBlue
    *filesLayout*Label.borderWidth:		0
    *filesLayout*Label.shadowWidth:		0
    *filesLayout.layout: vertical { \
	imlistGroup   < +inf -inf * > \
	3 \
	horizontal { -5 imoptsGroup < +inf -inf * > -5 } \
	-1 \
	loadCmdGroup < +inf -inf * > \
    }

    *imlistGroup.label:
    *imlistGroup.frameWidth:			2
    *imlistGroup.outerOffset:			2
    *imlistLayout*Label.shadowWidth:		0
    *imlistLayout*Label.justify:		left
    *imlistLayout*Command.width:		90
    *imlistLayout*Command.height:		23
    *imlistLayout*Command.shadowWidth:		1
    *imlistLayout*Viewport.allowVert:           True
    *imlistLayout*Viewport.allowHoriz           True
    *imlistLayout*Viewport.useRight:            True
    *imlistLayout*Viewport.useBottom:           True
    *imlistLayout*Viewport.resizeable:		True
    *imlistLayout*Scrollbar.height:		17
    *imlistLayout*Scrollbar.width:		17
    *imlistLayout.layout: vertical { \
	3 \
	horizontal { \
	    3 \
	    rootButton	 < +inf -inf * > 1 \
	    homeButton	 < +inf -inf * > 1 \
	    upButton     < +inf -inf * > 1 \
	    rescanButton < +inf -inf * >   \
	    3 \
	    imtemplateLabel 3 imtemplateFrame < +inf -inf  * > \
	    3 \
	} \
	5 \
	horizontal { 1 imlistLabel < +inf -inf * > 1 } \
	imlistFrame < +inf -inf * +inf -inf > \
	3 \
	dirLabel < +inf -inf * > \
	3 \
	horizontal { 5 fnameLabel 5 filnamFrame < +inf -inf * > } \
	3 \
    }
    *imtemplateLabel.label:			Filter:
    *imtemplateText*editType:			edit
    *imtemplateText*height:			23
    *imtemplateText*font:			7x13
    !*imageList.width:				100
    *imageList*height:				140
    *imageList.shadeSurplus:			False
    *imageList.defaultColumns:			3
    *imageList.font:				7x13
    *imlistView.resizeable:			True
    *imlistLabel.height:			0
    *imlistLabel.label:				xxx
    *imlistLabel.justify:			left
    *imlistLabel.font:				*lucida-bold-r*10*
    *upButton.label:				Up
    *rootButton.label:				Root
    *homeButton.label:				Home
    *rescanButton.label:			Rescan
    *dirLabel.label:				\ \ Directory:
    *dirLabel.alignment:			left
    *fnameLabel.label:				Load File:
    *fnameText*editType:			edit
    *fnameText.height:				22

    *imoptsGroup.label:				Options
    *imoptsGroup.frameWidth:			2
    *imoptsGroup.outerOffset:			7
    *imoptsGroup*offIcon:			square0s
    *imoptsGroup*onIcon:			square1s
    *imoptsGroup*highlightColor:		yellow
    *imoptsLayout*Label.shadowWidth:		0
    *imoptsLayout*Label.justify:		left
    *imoptsLayout.layout: vertical { \
	3 \
	horizontal { \
	    3 \
	    autoload 6 grayscale \
	    3 < +inf > \
	    browseHdrs \
	    3 < +inf > \
	    frameLabel 2 frameFrame \
	    3 \
	} \
	6 \
	horizontal { \
	    3 \
	    zscale 6 zrange \
	    3 \
	    z1Label z1Frame < +inf * >  2 \
	    z2Label z2Frame < +inf * >  2 \
	    nsampLabel nsampFrame < +inf * > \
	    3 \
	} \
	3 \
    }
    *grayscale.label:				Auto Grayscale
    *grayscale.location:			0 0 100 22
    *autoload.label:				Auto Load
    *autoload.location:				0 0 80 22
    *autoload.on:				True
    *browseHdrs.label:				List Image Headers
    *browseHdrs.location:			0 0 120 22
    *browseHdrs.on:				False
    *zscale.label:				Zscale
    *zscale.location:				0 0 60 22
    *zrange.label:				Zrange
    *zrange.location:				0 0 60 22
    *z1Label.label:				z1
    *z1Value*width:				60
    *z1Value*height:				22
    *z1Value*editType:				edit
    *z2Label.label:				z2
    *z2Value*width:				60
    *z2Value*height:				22
    *z2Value*editType:				edit
    *nsampLabel.label:				Nsample
    *nsampValue*width:				60
    *nsampValue*height:				22
    *nsampValue*editType:			edit
    *frameLabel.label:				Frame:\ 
    *frameFrame.width:				50
    *frameFrame.resize:				False
    *frameFrame.label:				Current
    *frameFrame.font:				6x13
    *frameFrame.menuName:			loadFrames


    *loadCmdGroup.label:
    *loadCmdGroup*frameWidth:			2
    *loadCmdGroup*outerOffset:			5
    *loadCmdGroup.outerOffset:			2
    *loadCmdGroup*innerOffset:			5
    *loadCmdGroup.frameType:			sunken
    *loadCmdGroup.label:
    *loadCmdGroup.location:                     0 0 400 45
    *loadCmdLayout*Command.internalWidth:	12
    *loadCmdLayout.layout: horizontal { \
	2 \
	filesLoadButton \
	1 < +inf > \
	filesStatus \
	2 \
    }
    *filesLoadButton.label:			Load
    *filesStatus.label:
}



set Resources(save_panel) { \

    !=====================================
    !  Save Setup Panel	resources.	!
    !=====================================
    *save_panel*TextToggle.alignment:		left
    *save_panel*TextToggle.frameWidth:		0
    *save_panel*TextToggle.height:		20
    *save_panel*Label.borderWidth:		0
    *save_panel*Label.shadowWidth:		0
    *save_panel*TextButton.width:		80

    *saveLayout.borderWidth:			0
    *saveLayout.layout:	vertical { \
	saveNameGroup < +inf *	> \
	saveOptGroup <	+inf -inf * > -3 \
	saveCmdGroup <	+inf * > \
    }

    ! Save Name	Group resources.
    !----------------------------------
    *saveNameGroup.borderWidth:			0
    *saveNameGroup.outerOffset:			5
    *saveNameGroup.label:
    *saveNameGroup.location:			0 0 400 50
    *saveNameGroup*offIcon:			diamond0s
    *saveNameGroup*onIcon:			diamond1s
    *saveNameGroup*highlightColor:		cyan
    *saveNameGroup*Frame.frameType:		sunken
    *saveNameGroup*Frame.frameWidth:		1
    *saveNameGroup*Label.justify:		right
    *saveNameGroup*Text*editType:		edit
    *saveNameGroup*shadowWidth:			0
    *saveNameGroup*borderWidth:			0
    *saveNameLayout.borderWidth:		0
    *saveNameLayout.layout: vertical { \
	2 \
	horizontal { 5 saveLabel 5 fnameFrame < +inf -inf * > 5 } \
	2 \
    }
    *saveLabel.label:				File Name:
    *saveFile.height:				22

    !  Main options groups layout resources.
    !---------------------------------------
    *saveOptGroup.frameWidth:			2
    *saveOptGroup.frameType:			chiseled
    *saveOptGroup.label:
    *saveOptGroup.location:			0 0 400 140
    *saveOptGroup.outerOffset:			5
    *saveOptGroup.innerOffset:			0
    *saveOptLayout*borderWidth:			0
    *saveOptLayout.layout: horizontal {	\
	-1 \
	vertical { 5 <	-5 > fmtGroup <	+inf * +inf > -1 } \
	-1 \
	vertical { \
	    10	< -10 >	\
	    saveDataBox < +inff -inff * +inff -inff > \
	    5 < -5 > \
	} \
	-1 \
	vertical { 5 <	-5 > saveColorGroup < +inf * +inf > -1 } \
	-1 \
    }

    ! Output color box resources.
    ! ------------------------------
    *saveColorGroup.location:			0 0 140	120
    *saveColorGroup.outerOffset:		7
    *saveColorGroup.frameWidth:			2
    *saveColorGroup*offIcon:			diamond0s
    *saveColorGroup*onIcon:			diamond1s
    *saveColorGroup*highlightColor:		cyan
    *saveColorGroup.innerOffset:		5
    *saveColorGroup.label:			Output Color
    *saveColorGroup*TextToggle.width:		110
    *saveColor.frameWidth:			2
    *saveColor.layout: horizontal { \
	3 \
	vertical { 5 svGrayButton 2 svPseudoButton 2 svRGBButton -1 } \
	-1 \
    }
    *svGrayButton.label:			Grayscale
    *svPseudoButton.label:			PseudoColor
    *svRGBButton.label:				RGB

    *saveDataBox.frameType:			sunken
    *saveDataBox.frameWidth:			1


    ! Output format box	resources.
    ! -----------------------------------
    *fmtGroup.location:				0 0 140 120
    *fmtGroup.outerOffset:			7
    *fmtGroup.frameWidth:			2
    *fmtGroup*offIcon:				diamond0s
    *fmtGroup*onIcon:				diamond1s
    *fmtGroup*TextToggle.width:			55
    *fmtGroup*highlightColor:			cyan
    *fmtGroup.label:				File Format
    *formats.layout: horizontal	{ \
	3 \
	vertical { 5 fitsButton 2 gifButton 2 tiffButton 2 rawButton  1 } \
	2 < -2	> \
	vertical { 5 epsButton	2 rasButton 2 x11Button  2 jpegButton 1 } \
	-1 \
    }
    *rasButton.label:				RAS
    *gifButton.label:				GIF
    *jpegButton.label:				JPEG
    *tiffButton.label:				TIFF
    *fitsButton.label:				FITS
    *x11Button.label:				X11
    *epsButton.label:				EPS
    *rawButton.label:				Raw

    ! Change the sensitivity once these	formats	are implemented. !
    !-------------------------------------------------------------
    *jpegButton.sensitive:			False
    *x11Button.sensitive:			False
    *rawButton.sensitive:			False


    ! Panel command resources.
    ! ------------------------------
    *saveCmdLayout.borderWidth:			0
    *saveCmdGroup.frameType:			chiseled
    *saveCmdGroup.frameWidth:			2
    *saveCmdGroup.outerOffset:			5
    *saveCmdGroup.innerOffset:			5
    *saveCmdGroup.label:
    *saveCmdGroup.location:			0 0 400 50
    *saveCmdLayout*Command.internalWidth:	12
    *saveCmdLayout.layout: horizontal {	\
	2 \
	okaySave 1 < +inf -1 >	saveStatus < +inf -inf * > \
	2 \
    }
    *okaySave.label:				Save
}


set Resources(tile_panel) { \

    *tileOpts.frameType:		    	chiseled
    *tileOpts.frameWidth:		    	2
    *tileOpts.outerOffset:			5
    *tileOpts.innerOffset:			7
    *tileOpts*shrinkToFit:			True
    *tileOpts*borderWidth:		      	0

    *toptLayout.layout:	vertical { \
	horizontal { -6 tFramesG < +inf -inf * > -6 } \
	horizontal { \
	    -1 \
	    horizontal { -6 tileMode < * +inf -inf > -6 } \
	    vertical { \
		horizontal { -3 userOrientG < +inf -inf * > -3 } \
		horizontal { -3 fillStyle   < +inf -inf * > -3 } \
		horizontal { -3 tileLabel   < +inf -inf * > -3 } \
		-7 \
		horizontal { -3 geomFrame   < +inf -inf * > -3 } \
	    } \
	    -1 \
	} \
	-4 \
    }
    *tileMode.label:				Tile Mode
    *tileMode.outerOffset:			7
    *tileMode.innerOffset:			5
    *tileMode*location:				0 0 150 20
    *tileMode*TextToggle.outerOffset:		2
    *tileMode*TextToggle.innerOffset:		1
    *tileMode*TextToggle.frameWidth:		0
    *tileMode*TextToggle.leftMargin:		10
    *tileMode*TextToggle.rightMargin:		20
    *tileMode*TextToggle.onIcon:		diamond1s
    *tileMode*TextToggle.offIcon:		diamond0s
    *tileMode*TextToggle.highlightColor:	yellow

    *tileDisabled.label:			Disabled
    *tileManual.label:				Manual
    *tileBest.label:				Best
    *tileSquare.label:				Square
    *tileHorizontal.label:			Horizontal
    *tileVertical.label:			Vertical
    *tileRow.label:				One Row
    *tileCol.label:				One Column

    *fillStyle.label:				Fill Style
    *fillStyle.location:			0 0 160 30
    *fillStyle.outerOffset:			7
    *fillStyle.innerOffset:			5
    *fillStyle.rows:				1
    *fillStyle*selectionStyle:			multi
    *fillStyle*outerOffset:			0
    *fillStyle*innerOffset:			1
    *fillStyle*leftMargin:			7
    *fillStyle*onIcon:				square1s
    *fillStyle*offIcon:				square0s
    *fillStyle*highlightColor:			yellow
    *fillStyle.TextToggle.frameWidth:		0
    *fillStyle.TextToggle.location:		0 0 85 23
    *byCols.label:				Fill by Columns
    *bottomUp.label:				Fill from Bottom

    *tileLabel.label:				Tile Labels
    *tileLabel.location:			0 0 175 30
    *tileLabel.outerOffset:			7
    *tileLabel.innerOffset:			5
    *tileLabel.rows:				1
    *tileLabel*selection:			-1
    *tileLabel*outerOffset:			0
    *tileLabel*innerOffset:			1
    *tileLabel*leftMargin:			7
    *tileLabel*onIcon:				square1s
    *tileLabel*offIcon:				square0s
    *tileLabel*highlightColor:			yellow
    *tileLabel.TextToggle.frameWidth:		0
    *tileLabel.TextToggle.location:		0 0 85 23
    *labelFrames.label:				Frameno
    *labelImname.label:				Img Name
    *labelTitles.label:				Img Title

    *geomFrame.frameWidth:			0
    *geomFrame.frameType:			sunken
    *geomFrame.outerOffset:			7
    *geomFrame.innerOffset:			4
    *tileGeometry.width:			220
    *tileGeometry.height;			37
    *tileGeometry.background:			#c4c4c4
    *tileGeometry.font:				7x13bold
    *tileGeometry.label:			Tile Geometry:  1 x 2

    *userOrientG.label:				Manual Configuration
    *userOrientG.height:			90
    *userOrientG.width:				220
    *userOrientG.outerOffset:			7
    *userOrientG.innerOffset:			5
    *userOrientG.shrinkToFit:			True
    *userOrientG*Frame.frameWidth:		1
    *userOrientG*Frame.frameType:		sunken
    *userOrientG*Text.height:			21
    *userOrientG*Text*editType:			edit
    *userOrientL.borderWidth:			0
    *userOrientL.layout: vertical { \
	1 \
	horizontal { 18 nrowLab < +50% -inf * >  nrFrame < +inf -inf * > 5 } \
	1 \
	horizontal { ncolLab < +50% -inf * > ncFrame < +inf -inf * > 5 } \
    }
    *nrowLab.justify:				right
    *ncolLab.justify:				right

    *nrLayout.layout: horizontal {nrdecrease nrtext < +inf -inf * > nrincrease}
    *nrdecrease.direction:			left
    *nrincrease.direction:			right
    *nrowLab.label:				Tile Rows:
    *nrtext.background:				#adadad
    *nrtext.justify:				center
    *nrtext.font:				7x13bold
    *nrtext.label:				1

    *ncLayout.layout: horizontal {ncdecrease nctext < +inf -inf * > ncincrease}
    *ncdecrease.direction:			left
    *ncincrease.direction:			right
    *ncolLab.label:				Tile Columns:
    *nctext.background:				#adadad
    *nctext.justify:				center
    *nctext.font:				7x13bold
    *nctext.label:				2

    *tFramesG.label:				Tile Frames
    *tFramesG.outerOffset:			7
    *tFramesG.innerOffset:			7
    *tFrames.borderWidth:			0
    *tFrames*Toggle.height:			17
    *tFrames.layout: horizontal	{ \
	tAll \
	2 \
	tFrame1  tFrame2  tFrame3  tFrame4  tFrame5  \
	tFrame6  tFrame7  tFrame8  tFrame9  tFrame10 \
	tFrame11 tFrame12 tFrame13 tFrame14 tFrame15 tFrame16 \
	2 \
	tNone \
    }
    *tAll.label:				All\ 
    *tNone.label:				None
}


set Resources(wcs_panel) { \

    !--------------------
    ! WCS Readout Panel
    !--------------------
    *wcsGroup*TextToggle.offIcon:               square0s
    *wcsGroup*TextToggle.onIcon:                square1s

    !*wcsLayout*TextToggle.location:             0 0 160 23
    *wcsLayout*TextToggle.height:		23
    *wcsLayout*TextToggle.outerOffset:          0
    *wcsLayout*Layout.borderWidth:		0
    *wcsLayout.borderWidth:			0
    *wcsLayout.layout: vertical { \
	0 < +0 -0 > \
	wcsGroup < +inf -inf * > \
	5 \
	horizontal { -1 wcsOptGroup < +inf -inf * > -1 } \
	-2 \
    }

    *wcsOptGroup.label:
    *wcsOptGroup.outerOffset:                   0
    *wcsOptGroup.innerOffset:                   5
    *wcsOptGroup.frameType:                     chiseled
    *wcsOptGroup.frameWidth:                    0
    *wcsOptLayout.layout: vertical { \
	horizontal { -9 wcsCoords   < +inf -inf * > -9 } \
	-3 \
	horizontal { -5 wcsOpts     < +inf -inf * > -5 } \
	horizontal { -5 wcsIsmGroup < +inf -inf * > -5 } \
	1 \
    }

    *wcsOpts.label:
    *wcsOpts.width:				265
    *wcsOpts.height:				40
    *wcsOpts.outerOffset:			3
    *wcsOpts.innerOffset:			3
    *woLayout*TextToggle.frameWidth:		0
    *woLayout*TextToggle.onIcon:		square1s
    *woLayout*TextToggle.offIcon:		square0s
    *woLayout*TextToggle.highlightColor:	cyan
    *woLayout*TextToggle.alignment:		left
    *woLayout*TextToggle.leftMargin:		5
    *woLayout.layout: horizontal { \
	3 \
	woptLabels < +inf -inf * > 2 \
	woptTitles < +inf -inf * > 2 \
	woptFBinfo < +inf -inf * > 2 \
	woptBPM    < +inf -inf * >   \
	3 \
    }
    *woptLabels.label:				WCS Labels
    *woptLabels.on:				True
    *woptTitles.label:				Image Titles
    *woptTitles.on:				True
    *woptFBinfo.label:				Frame Buffer Info
    *woptFBinfo.on:				True
    *woptBPM.label:				BPM Data
    *woptBPM.on:				False
    *woptLabels.location:			0 0 150 21
    *woptTitles.location:			0 0 150 21
    *woptFBinfo.location:			0 0 175 21
    *woptBPM.location:				0 0 120 21


    *wcsCoords.label:				Readout Values
    *wcsCoords.width:				265
    *wcsCoords.height:				135
    *wcsCoords.outerOffset:			7
    *wcsCoords.innerOffset:			3
    *wcLayout*TextToggle.offIcon:           	diamond0s
    *wcLayout*TextToggle.onIcon:            	diamond1s
    *wcLayout*TextToggle.highlightColor:    	yellow2
    *wcLayout*TextToggle.shrinkToFit:		True
    *wcLayout*TextToggle.frameWidth:		0
    *wcLayout*TextToggle.label:
    *wcLayout*TextToggle.on:			True
    *wcLayout*Label.justify:			right
    *wcLayout*Label.font:			7x13bold
    *wcLayout*SimpleMenu.borderColor:           black
    *wcLayout*SimpleMenu.borderWidth:           1
    *wcLayout*SimpleMenu.foreground:            White
    *wcLayout*SimpleMenu.background:            SteelBlue
    *wcLayout*MenuButton.shadowWidth:		1
    *wcLayout*MenuButton.resize:		False
    *wcLayout.layout: vertical {\
	1 \
	horizontal { 20 < -20 > wcTitle < +inf -inf * > 20 < -20 > }\
	1 \
	horizontal { 5 wcLine < +inf -inf * > 5 } \
	5 \
	horizontal { \
	    10 \
	    vertical { 2 wlWcs1  2 wlWcs2  2 wlWcs3  2 wlWcs4  2 }  5 \
	    vertical { 1 sysWcs1 1 sysWcs2 1 sysWcs3 1 sysWcs4 1 }  5 \
	    vertical { 1 fmtWcs1 1 fmtWcs2 1 fmtWcs3 1 fmtWcs4 1 } 20 \
	    vertical { 1 wpWcs1  3 wpWcs2  3 wpWcs3  3 wpWcs4  3 } 20 \
	    vertical { 1 wiWcs1  3 wiWcs2  3 wiWcs3  3 wiWcs4  3 } 15 \
	} \
	3 \
    }
    *wcTitle.label:    Type\ \ \ \ \ \ \ \ \ \ Format\ \ \ \ \ \ Panel\ ImgWin

    *wcLine.height:				2
    *wcLine.frameWidth:				2
    *wcLine.frameType:				ledged

    *wlWcs1.label:				First WCS
    *wlWcs2.label:				Second WCS
    *wlWcs3.label:				Third WCS
    *wlWcs4.label:				Fourth WCS
    *sysWcs1.label:				\ Image Display\ 
    *sysWcs1.menuName:				sysMenu1
    *sysWcs2.label:				None
    *sysWcs2.menuName:				sysMenu2
    *sysWcs3.label:				None
    *sysWcs3.menuName:				sysMenu3
    *sysWcs4.label:				None
    *sysWcs4.menuName:				sysMenu4
    *fmtWcs1.label:				\ Sexigesimal\ 
    *fmtWcs1.menuName:				fmtMenu1
    *fmtWcs2.label:				None
    *fmtWcs2.menuName:				fmtMenu2
    *fmtWcs3.label:				None
    *fmtWcs3.menuName:				fmtMenu3
    *fmtWcs4.label:				None
    *fmtWcs4.menuName:				fmtMenu4

    *editMenu fmtWcsMenu$i fmtWcs$i $items

    *wcsIsmGroup.label:
    *wcsIsmGroup.width:				395
    *wcsIsmGroup.height:			50
    *wcsIsmGroup.outerOffset:			3
    *wcsIsmGroup.innerOffset:			5
    *wcsIsmGroup*borderWidth:			0
    *wcsIsmLayout.layout: horizontal { \
	wcsIsmLabel 1 wcsIsmFrame < +inf -inf * > 3 wcsIsmInit 1 \
     }
    *wcsIsmLabel.label:				ISM Command
    *wcsIsmFrame.frameType:			sunken
    *wcsIsmFrame.frameWidth:			1
    *wcsIsmFrame.outerOffset:			1
    *wcsIsmFrame*height:			23
    *wcsIsmCmd*editType:			edit
    *wcsIsmCmd.displayCaret:			True
    *wcsIsmInit.label:				Initialize
    *wcsIsmInit.internalWidth:			7

    *wcsBox*borderWidth:			0
    *wcsBox*TextToggle.frameType:		raised
    *wcsBox*TextToggle.frameWidth:		1
    *wcsBox*TextToggle.leftMargin:		2
    *wcsBox*borderWidth:			0
    *wcsBox.layout: vertical { \
	wcsFrame < +inf -inf * > \
	2 \
	horizontal { \
	    2 \
	    ismToggle   < +inf -inf * > 2 \
	    pixelTable  < +inf -inf * > 2 \
	    imageHeader < +inf -inf * > 2 \
	    compass     < +inf -inf * > 2 \
	    wcsOptions  < +inf -inf * >   \
	    2 \
	} \
    }
    *ismToggle.label:				ISM Mod
    *ismToggle.label:				WCS/Pix
    *pixelTable.label:				Pix Table
    *imageHeader.label:				Header
    *imageHeader.sensitive:			False
    *compass.label:				Compass
    *wcsOptions.label:				Options

    *wcsGroup.label:
    *wcsGroup.outerOffset:                      0
    *wcsGroup.innerOffset:                      5
    *wcsGroup.frameType:                        chiseled
    *wcsGroup.frameWidth:                       2
    *wcsGroup*Text*width:			260
    *wcsGroup*Text*height:			17
    *wcsGroup*Text*font:			7x13
    *wcsGroup*Text*displayCaret:		False
    *wcsGroup*Text*editType:			read
    *wcsGroup*Text*background:			black
    *wcsGroup*Text*foreground:			yellow2
    *wcsGroup*TextToggle.highlightColor:        cyan
    *wcsFrame.frameType:			sunken
    *wcsFrame.frameWidth:			1
    *wcsText*background:			yellow4
    *wcsText.layout: vertical { \
	wtName    < +inf -inf * > -3 \
	wtTitle   < +inf -inf * > -3 \
	wtFBCfg   < +inf -inf * >    \
	1 < -1 > \
	wtWcs1  < +inf -inf * > -3 \
	wtWcs2  < +inf -inf * > -3 \
	wtWcs3  < +inf -inf * > -3 \
	wtWcs4  < +inf -inf * >    \
	1 < -1 > \
	horizontal { \
	    wtIPixval < +inf -inf * +inf > 1 \
	    wtSPixval < +inf -inf * +inf > 1 \
	    wtBPixval < +inf -inf * +inf > \
	} \
    }
}


set Resources(blink_panel) { \

    *blink_panel.geometry:			425x200
    *blink_panel.title:				Blink/Register Frames

    *brMenuBar*Command.internalHeight:	       	4
    *brMenuBar*Command.internalWidth:	       	12
    *brMenuBar*Command.height:			27
    *brMenuBar*borderWidth:			0

    *brMenuBar*Label.font:	  7x13bold
    *brLayout*Command.font:	  -*-helvetica-medium-r-normal-*-12-*-iso8859-1
    *brRegButton.font:		  -*-helvetica-medium-r-normal-*-12-*-iso8859-1
    *brReset.font:  		  -*-helvetica-medium-r-normal-*-12-*-iso8859-1
    *brMatchButton.font:  	  -*-helvetica-medium-r-normal-*-12-*-iso8859-1
    *brBlinkButton.font:  	  -*-helvetica-medium-r-normal-*-12-*-iso8859-1
    *brAregButton.font:		  -*-helvetica-medium-r-normal-*-12-*-iso8859-1


    *brMenuBar.layout: vertical	{ \
	5 < -5	> \
	horizontal { 10	< +inf -10> brClose 5 } \
	5 < -5	> \
    }
    *brClose.label:			       	Dismiss

    *brMenuFrame.frameType:		       	raised
    *brMenuFrame.frameWidth:		       	2
    *bpLayout.layout: vertical { \
	brMenuFrame  <	+inf -inf * > \
	1 < -1	> \
	brFrame < +inf	-inf * +inf -inf > \
    }

    *brFrame.frameType:			       	chiseled
    *brFrame.frameWidth:		       	2
    *brFrame.outerOffset:			4
    *brFrame.innerOffset:			4

    *brLayout.borderWidth:			0
    *brLayout.layout: vertical { \
	3 < -3	> \
	horizontal { -3 brFramesG < +inf -inf * > -3 } \
	-5  \
	horizontal { -3 brCmdG	< +inf -inf * +inf -inf	> -3 } \
	-5 \
    }

    *brCmdG.label:
    *brCmdG.outerOffset:			7
    *brCmdG.innerOffset:			7
    *brCmdG*borderWidth:			0
    *brCmd.layout: horizontal {	\
	2 \
	vertical { \
	    2 \
	    horizontal	{ \
		2 \
		brRateLabel \
		2 \
		brBRframe < +inf -inf	* >\
		4 \
		brReset \
		2 \
	    } \
	    8 < -8 > \
	    horizontal	{ \
		4 \
		brMatchButton	< +inf -inf * >	\
		5 < -5 > \
		brRegButton <	+inf -inf * > \
		2 \
	    } \
	    1 < +inf >	\
	} \
	10 \
	vertical { \
	    2 \
	    brBlinkButton < +inf * > \
	    10	< -10 >	\
	    brAregButton < +inf * > \
	    1 < +inf >	\
	} \
	2 \
    }

    *brFramesG.label:				Frames List
    *brFramesG.outerOffset:			7
    *brFramesG.innerOffset:			7
    *brFramesG*SimpleMenu.borderColor:		black
    *brFramesG*SimpleMenu.borderWidth:		1
    *brFramesG*SimpleMenu.foreground:           White
    *brFramesG*SimpleMenu.background:           SteelBlue

    *brFrames.borderWidth:			0
    *brFrames.layout: horizontal { \
	5 < +inf > \
	brFrame1  < +inf * > 1 \
	brFrame2  < +inf * > 1 \
	brFrame3  < +inf * > 1 \
	brFrame4  < +inf * > 1 \
	brFrame5  < +inf * > 1 \
	brFrame6  < +inf * > 1 \
	brFrame7  < +inf * > 1 \
	brFrame8  < +inf * > 1 \
	brFrame9  < +inf * > 1 \
	brFrame10 < +inf * > 1 \
	brFrame11 < +inf * > 1 \
	brFrame12 < +inf * > 1 \
	brFrame13 < +inf * > 1 \
	brFrame14 < +inf * > 1 \
	brFrame15 < +inf * > 1 \
	brFrame16 < +inf * >   \
	5 < +inf > \
    }

    *brBRlayout.layout:	horizontal { \
	brBRdecrease \
	brBRtext < +inf -100% * > \
	brBRincrease \
    }

    *blink_panel*TextToggle.location:		0 0 110	23
    *blink_panel*TextToggle.frameWidth:		1
    *blink_panel*TextToggle.highlightColor:	yellow
    *blink_panel*TextToggle.offIcon:		square0s
    *blink_panel*TextToggle.onIcon:		square1s
    *blink_panel*TextToggle.outerOffset:	0
    *blink_panel*TextToggle.innerOffset:	2
    *blink_panel*Command.height:		23
    *blink_panel*Arrow.width:			16
    *blink_panel*Arrow.height:			20


    *brFramesLabel.label:		     	Frames:
    *brFrame1.menuName:				frame1Menu
    *brFrame2.menuName:				frame2Menu
    *brFrame3.menuName:				frame3Menu
    *brFrame4.menuName:				frame4Menu
    *brFrame5.menuName:				frame5Menu
    *brFrame6.menuName:				frame6Menu
    *brFrame7.menuName:				frame7Menu
    *brFrame8.menuName:				frame8Menu
    *brFrame9.menuName:				frame9Menu
    *brFrame10.menuName:			frame10Menu
    *brFrame11.menuName:			frame11Menu
    *brFrame12.menuName:			frame12Menu
    *brFrame13.menuName:			frame13Menu
    *brFrame14.menuName:			frame14Menu
    *brFrame15.menuName:			frame15Menu
    *brFrame16.menuName:			frame16Menu
    *brReset.label:			     	Reset

    *brRateLabel.label:			     	Rate:
    *brBRframe.frameType:			sunken
    *brBRframe.frameWidth:			1
    *brBRtext.width:				40
    *brBRtext.height:				23
    *brBRdecrease.direction:			left
    *brBRincrease.direction:			right
    *brRegButton.label:			     	Register
    *brMatchButton.label:			Match LUTs
    *brBlinkButton.label:			Blink
    *brAregButton.label:		       	Auto-Register
}


set Resources(hdr_panel) { \

    *hdr_panel.geometry:			550x600
    *hdr_panel.title:				Image Header

    *hdr_panel*SimpleMenu.borderColor:          black
    *hdr_panel*SimpleMenu.borderWidth:          1
    *hdr_panel*SimpleMenu.foreground:           White
    *hdr_panel*SimpleMenu.background:           SteelBlue

    *hdrMenuFrame.frameType:			raised
    *hdrMenuFrame.frameWidth:			2
    *hdrLayout.layout: vertical	{ \
	hdrMenuFrame < +inf -inf * > \
	hdrObjGroup  < +inf -inf * > \
	hdrTabFrame  < +inf -inf * +inf	-inf> \
    }

    *hdrMenuBar*borderWidth:			0
    *hdrMenuBar*Command.internalHeight:		5
    *hdrMenuBar*Command.internalWidth:		12
    *hdrMenuBar.layout:	vertical { \
	5 < -5	> \
	horizontal { 10 < +inf -10> hdrClose 7 } \
	5 < -5	> \
    }
    *hdrClose.label:				Dismiss

    *hdrObjGroup.label:
    *hdrObjGroup.outerOffset:			7
    *hdrObjGroup.innerOffset:			4
    *hdrObjLayout.borderWidth:			0
    *hdrObjLayout.layout: vertical { \
	horizontal { hdrObjLabel 2 hdrObjMenu < +inf -inf * > 2 } \
    }
    *hdrObjLabel.label:				Image Name:
    *hdrObjMenu.label:
    *hdrObjMenu.justify:			left
    *hdrObjMenu.font:				7x13
    *hdrObjMenu.menuName:			objMenu
    *hdrObjMenu.internalWidth:			5
    *hdrObjMenu.internalHeight:			1
    *hdrObjMenu.shadowWidth:			1

    *hdrHdrGroup.tabLabel:			Image Header
    *hdrHdrGroup.label:
    *hdrHdrGroup.outerOffset:			7
    *hdrHdrGroup.innerOffset:			5
    *hdrHdrLayout.borderWidth:			0
    *hdrHdrLayout.layout: vertical { \
	horizontal { \
	    hdrFilter 2 hFindFrame < +inf -inf * > 2 hdrFind 1 hdrClear \
	} \
	5 \
	hdrText < +inf -inf * +inf -inf > \
    }
    *hFindEntry*editType:                       edit
    *hFindEntry*font:                           7x13
    *hFindEntry*displayCaret:                   True
    *hFindEntry*width:                          150
    *hFindFrame.frameWidth:                     1
    *hFindFrame*borderWidth:			0
    *hFindFrame.frameType:                      sunken
    *hFindFrame.width:                          150
    *hFindFrame.height:                         23
    *hdrFilter.label:                           Keyword Filter
    *hdrFind.label:                             Search
    *hdrClear.label:                            Clear

    ! Resources if the header text widget is AsciiText
!   *hdrText*scrollVertical:			Always
!   *hdrText*scrollHorizontal:			Always
!   *hdrText*editType:				edit
!   *hdrText*font:				7x13
!   *hdrText*background:			#c4c4c4
!   *hdrText*displayCaret:			False
!   *hdrText*bottomMargin:			10
!   *hdrText*Scrollbar.width:			15
!   *hdrText*Scrollbar.height:			15

    ! Resources if the header text widget is HTML
    *hdrText.width:                             600
    *hdrText.height:                            500
    *hdrText.anchorUnderlines:                  1
    *hdrText.visitedAnchorUnderlines:           1
    *hdrText.verticalScrollOnRight:             True
    *hdrText.plainFont:                         7x13
    *hdrText.marginWidth:			5
    *hdrText.marginHeight:			5


    *hdrWcsGroup.tabLabel:			Image WCS Info
    *hdrWcsGroup.label:
    *hdrWcsGroup.outerOffset:			5
    *hdrWcsGroup.innerOffset:			5
    *hdrWcsGroup*Text*scrollVertical:		whenNeeded
    *hdrWcsGroup*Text*scrollHorizontal:		whenNeeded
    *hdrWcsGroup*Text*editType:			edit
    *hdrWcsGroup*Text*displayCaret:		False
    *hdrWcsGroup*Text*borderWidth:		0
    *hdrWcsGroup*Text*editType:			edit
    *hdrWcsGroup*Text*font:			7x13
    *hdrWcsGroup*Text*Scrollbar.width:		15
    *hdrWcsGroup*Text*Scrollbar.height:		15
    *hdrWcsLayout.borderWidth:			0
    *hdrWcsLayout.layout: vertical { \
	2 < -2	> \
	hdrInfoGroup <	+inf -inf * > \
	2 < -2	> \
	hdrKeywGroup <	+inf -inf * +inf -inf >	\
	-4 \
    }
    *hdrInfoGroup.label:			Basic WCS Information
    *hdrInfoGroup.outerOffset:			7
    *hdrInfoGroup.innerOffset:			0
    *hdrIGFrame.frameType:			sunken
    *hdrIGFrame.frameWidth:			1
    *hdrIGText.height:				130
!   *hdrIGText*background:			black
!   *hdrIGText*foreground:			yellow2
    *hdrIGText*background:			#adadad
    *hdrIGText*foreground:			black
    *hdrWcsGroup*hdrIGText*scrollVertical:	never
    *hdrWcsGroup*hdrIGText*scrollHorizontal:	never
    *hdrWcsGroup*hdrIGText*font:  		7x13
    *hdrKeywGroup.label:			WCS Header Keywords
    *hdrKeywGroup.outerOffset:			7
    *hdrKeywGroup.innerOffset:			5
    *hdrKGFrame.frameType:			sunken
    *hdrKGFrame.frameWidth:			1
    *hdrKGText*background:			#c4c4c4
    *hdrKGText*bottomMargin:			10

    *hdrIGText*background:			#c4c4c4
    *hdrIGFrame.frameWidth:			0
}


set Resources(pixel_table) { \

    *pixel_panel.title:				Image Pixel Table
    *pixel_panel*SimpleMenu.borderWidth:	1
    *pixel_panel*SimpleMenu.borderColor:	black
    *pixel_panel*SimpleMenu.foreground:         White
    *pixel_panel*SimpleMenu.background:         SteelBlue

    *pixtabMenuBar*borderWidth:			0
    *pixtabMenuBar*Command.internalHeight:	4
    *pixtabMenuBar*Command.internalWidth:	12
    *pixtabMenuBar.layout: vertical { \
	5 \
	horizontal { \
	    5 \
	    pixtabSize 10 < +inf -10> pixtabHelp 5 pixtabClose \
	    7 \
	} \
	5 \
    }
    *pixtabSize.label:				Size
    *pixtabSize.menuName:			pixtabMenu
    *pixtabHelp.label:				Help
    *pixtabHelp.sensitive:			False
    *pixtabClose.label:				Dismiss

    *pixtabMenuFrame.frameType:			raised
    *pixtabMenuFrame.frameWidth:		2
    *pixel_table.layout: vertical { \
	1 \
	pixtabMenuFrame  < +inf -inf * > \
	1 \
	pixtabFrame < +inf -inf * +inf -inf > \
	1 \
    }
    

    *pixtabFrame.frameType:			raised
    *pixtabFrame.frameWidth:			0
    *pixtabFrame*borderWidth:			0
    *pixtabFrame*font:                          6x10
    *pixtabFrame*MultiList.font: 	-*-helvetica-medium-r-normal-*-10-*
    *pixtabFrame*Label.font: 		-*-helvetica-medium-r-normal-*-10-*
    *pixtabFrame*TextToggle.font: 	-*-helvetica-medium-r-normal-*-10-*

    *pixtabFrame*MultiList.forceColumns:	True
    *pixtabFrame*MultiList.defaultColumns:	5
    *pixtabFrame*MultiList.shadeSurplus:	False
    *pixtabFrame*MultiList.borderWidth:		0
    *pixtabFrame*MultiList.rowHeight:		25
    *pixtabFrame*MultiList.rowSpacing:		7
    *pixtabFrame*MultiList.internalWidth:	7
    *pixtabFrame*MultiList.internalHeight:	4
    *pixtabFrame*MultiList.width:		410
    *pixtabFrame*MultiList.height:		160
    *pixtabFrame*MultiList.columnWidth:		50
    *pixtabFrame*MultiList.columnSpacing:	2
    *pixtabFrame*MultiList.maxSelectable:	1
    *pixtabFrame*MultiList.highlightForeground:	red
    *pixtabFrame*MultiList.highlightBackground:	#c4c4c4
    *pixtabFrame*MultiList.background:		#c4c4c4
    *pixtabFrame*TextToggle.background:		#c4c4c4

    *pixtabFrame*Label.width:			00
    !*pixtabFrame*Label.resize:			False

    *meanFrame.frameWidth:			2
    *meanFrame.frameType:			chiseled
    *meanFrame.outerOffset:			0
    *meanFrame.width:				120
    *meanLabel.label:				Mean:
    *meanValue.label:
    *meanValue.resize:				False

    *sigFrame.frameWidth:			2
    *sigFrame.frameType:			chiseled
    *sigFrame.outerOffset:			0
    *sigFrame.width:				120
    *sigLabel.label:				Stdev:
    *sigValue.label:
    *sigValue.resize:				False

    *ptColFrame.frameWidth:			0
    *ptColFrame.outerOffset:			0
    *ptRowFrame.frameWidth:			0
    *ptRowFrame.outerOffset:			0

    *pixtabFrame*ptColLabs.width:		410
    *pixtabFrame*ptColLabs.height:		23
    *pixtabFrame*ptColLabs.defaultColumns:	5
    *pixtabFrame*ptColLabs.forceColumns:	True
    *pixtabFrame*ptColLabs.columnWidth:		50
    *pixtabFrame*ptColLabs.columnSpacing:	2
    *pixtabFrame*ptRowLabs.width:		60
    *pixtabFrame*ptRowLabs.height:		110
    *pixtabFrame*ptRowLabs.defaultColumns:	1
    *pixtabFrame*ptRowLabs.forceColumns:	True
    *pixtabFrame*ptRowLabs.verticalList:	True
    *pixtabFrame*ptRowLabs.columnWidth:		50
    *pixtabFrame*ptRowLabs.columnSpacing:	2
    *pixtabFrame*pixtab.verticalList:		True

    *ptFrame.outerOffset:           		0
    *ptFrame.innerOffset:           		0
    *ptFrame.borderWidth:			0
    *ptFrame.frameWidth:            		1
    *ptFrame.frameType:             		sunken
    *ptLayout.layout: vertical { \
        3 \
        horizontal { 65 ptColFrame < +inf -inf * > 5 } \
        1 \
        horizontal { \
          vertical { ptRowFrame< * +inf -inf > 5  } \
	  1 \
	  vertical { ptFrame } \
	  5 \
        } \
	1 \
        horizontal { \
	    2 < +inf > \
	    meanLabel meanFrame < +inf -inf * > 2 \
	    sigLabel  sigFrame  < +inf -inf * >   \
	    10 \
	} \
    }
}


set Resources(help_panel) { \

    !----------------------
    ! Help panel resources.
    !----------------------
    *help_panel.title:				XImtool	Help Summary
    *help_panel.width:				500
    *help_panel.height:				550
    *helpLayout*borderWidth:			0
    *helpLayout*Command.internalHeight:		4
    *helpLayout*Command.internalWidth:		12
    *helpLayout*HTML*shadowWidth:		1
    *helpLayout*helpText*Scrollbar.shadowWidth:		1

    *helpMenuGroup.label:               
    *helpMenuGroup.height:                      45
    *helpMenuGroup.outerOffset:                 0
    *helpMenuGroup.innerOffset:                 0
    *helpMenuGroup.frameType:			raised
    *helpMenubar.layout: vertical { \
	5 < -5 > \
	horizontal { 20 < +inf -20 > helpClose 7 } \
	5 < -5 > \
    }
    *helpBack.label:				Back
    *helpBack.sensitive:			False
    *helpForward.label:				Forward
    *helpForward.sensitive:			False
    *helpHome.label:				Home
    *helpClose.label:				Dismiss


    *hfEntry*editType:                          edit
    *hfEntry*font:                              7x13
    *hfEntry*displayCaret:                      True
    *hfFrame.frameWidth:			1
    *hfFrame.frameType:				sunken
    *hfFrame.width:				250
    *hfFind.label:                              Search
    *hfFind.shadowWidth:                        1
    *hfClear.label:                             Clear
    *hfClear.shadowWidth:                       1

    *helpLayout.layout:	vertical { \
	-1 \
	horizontal { helpMenuGroup < +inf -inf * > 	     } \
	5 \
        horizontal { \
            5 \
	    helpBack 2 helpForward 2 helpHome \
	    20 < +inf -20 > \
            hfFrame < +inf -inf * > 3 hfFind 1 hfClear \
            5 \
        } \
	5 \
	horizontal { helpTextFrame < +inf -inf * +inf -inf > } \
	horizontal { helpInfoLayout < +inf -inf	* > 	     } \
	-1 \
    }
    *helpTextFrame.frameWidth:			1
    *helpTextFrame.frameType:			sunken
    *helpText.width:				600
    *helpText.height:				500
    *helpText.anchorUnderlines:			1
    *helpText.visitedAnchorUnderlines:		1
    *helpText.verticalScrollOnRight:		true
    *helpText*Scrollbar.shadowWidth:		1
    *helpText.plainFont:       -adobe-courier-medium-r-normal-*-12-*-*-*-*-*-*-*
    *helpText.plainboldFont:   -adobe-courier-bold-r-normal-*-12-*-*-*-*-*-*-*
    *helpText.plainitalicFont: -adobe-courier-medium-o-normal-*-12-*-*-*-*-*-*-*
!   *helpText.boldFont:				6x12bold


    ! Contact info at the bottom of the panel.
    *helpInfoLayout*Label.justify:		center
    *helpInfoLayout*Label.internalHeight:	0
    *helpInfoLayout.layout: horizontal { \
	5 \
	vertical { 5 helpIRAFLogo 5 } \
	1 < +inf > \
	vertical { \
	    5 \
	    helpInfo1 < +inf -inf * +inf -inf > \
	    helpInfo2 < +inf -inf * +inf -inf > \
	    helpInfo3 < +inf -inf * +inf -inf > \
	    5 \
	} \
	1 < +inf > \
	vertical { 5 helpNOAOLogo 5 } \
	5 \
    }
    *helpInfo1.label:		XIMTOOL_VERSION
    *helpInfo2.label:		For help or questions:   http://iraf.net
    *helpInfo3.label: \
	NOAO is operated by AURA under cooperative agreement with the NSF

    *helpInfoLayout*helpInfo1.font: -*-helvetica-medium-r-normal-*-12-*-*-*
    *helpInfoLayout*helpInfo2.font: -*-helvetica-medium-r-normal-*-12-*-*-*
    *helpInfoLayout*helpInfo3.font: -*-helvetica-medium-r-normal-*-10-*-*-*

    *helpInfoLayout.helpIRAFLogo.internalWidth:		0
    *helpInfoLayout.helpIRAFLogo.internalHeight:	0
    *helpInfoLayout.helpIRAFLogo.foreground:		SteelBlue
    *helpInfoLayout.helpIRAFLogo.background:		white
    *helpInfoLayout.helpNOAOLogo.internalWidth:		0
    *helpInfoLayout.helpNOAOLogo.internalHeight:	0
    *helpInfoLayout.helpNOAOLogo.foreground:		SteelBlue
    *helpInfoLayout.helpNOAOLogo.background:		white
}

set Resources(tcl_panel) { \

    !--------------------------------
    ! Define a debug Tcl shell.
    !--------------------------------
    *tcl_panel.width:                           550
    *tcl_panel.height:                          180
    *tcl_panel.title:                           Debug TCL Command Entry
    *tclLayout*borderWidth:                     0
    *tclLayout*Frame.frameType:                 sunken
    *tclLayout*Frame.frameWidth:                2
    *tclLayout.layout:  vertical { \
        0 < +0 -0 > \
        tclCmdGroup   < +inf -inf * > \
        tclFrame < +inf -inf * +inf -inf> \
        0 < +0 -0 > \
    }
    *tclEntry*foreground:                       black
    *tclEntry*editType:                         edit
    *tclEntry*type:                             string
    *tclEntry*font:				7x13
    *tclEntry*scrollVertical:                   Always
    *tclEntry*scrollHorizontal:                 whenNeeded

    *tclCmdGroup.label:         
    *tclCmdGroup.outerOffset:                   0
    *tclCmdGroup.innerOffset:                   0
    *tclCmd.layout: vertical { \
        5 \
        horizontal { \
            5 \
            tclClear   3 \
            tclExecute   \
            10 < +inf -10>    \
            tclDismiss   \
            5 \
        } \
        5 \
    }
    *tclClear.label:                            Clear
    *tclExecute.label:                          Execute
    *tclDismiss.label:                          Dismiss
}


set Resources(warning) { \

    ! ---------------------
    ! WARNING dialog.
    ! ---------------------
    *warning.geometry:				+400+300
    *warning*borderWidth:			0
    *warning*TextBox.frameWidth:		0

    *warn.layout: vertical { \
	5 < -5	> \
	horizontal { 5 warnFrame < +inf * +inf > 5 } \
	5 < -5	> \
	horizontal { \
	    10 \
	    warnOk < +inf * > \
	    5 < +inf -5 > \
	    warnCancel < +inf * > \
	    10 \
	} \
	5 < -5	> \
    }
    *warnOk.label:				Okay
    *warnCancel.label:				Cancel

    *WFlayout.layout: horizontal { \
	5 < -5	> \
	vertical { 5 < +inf -5 > warnIcon 5 < +inf -5 > } \
	5 < -5	> \
	warnText < +inf -inf *	+inf -inf > \
	5 < -5	> \
    }

    *warnLabel.label:				Warning
    *warnLabel.width:				300
    *warnLabel.height:				20
    *warnFrame.frameType:			sunken
    *warnFrame.frameWidth:			2
    *warnIcon.location:				0 0 40 40
    *warnIcon.image:				WARNING
    *warnText.label:				generic warning text
    *warnText.width:				270
    *warnText.height:				60
    *warnText.background:			#c4c4c4
}




set Resources(gui) { \

    ! GUI resources.
    ! ------------------------------
    *autoscale:					True
    *zoomfactors:				1 2 4 8
    *displayCoords:				True
    *displayPanner:				True
    *displayMagnifier:				False
    *blinkRate:					1.0
    *pannerArea:				150*150
    *pannerGeom:				-5+5
    *magnifierArea:				100*100
    *magnifierGeom:				+5+5
    *wcsboxGeom:				-5-5
    *maxContrast:				5.0
    *showToolBar:				False
    *showPanelBar:				False
    *warnings:					True
    *centerBoxSize:				5
    *peakCentroid:				True
}





################################################################################
#  GUI Bootstrap Procedures
################################################################################

# Initialize the widget tree.
proc InitWidgetTree args \
{
    global Objects Resources Version


    # Add a new objects description for each of the panels found so we can
    # create them by name later rather that with the defaults.

    set guiResources ""
    foreach obj [array names Objects] {
	set guiResources \
		[ format "%s\n\n*%s_objects:%s\n" \
		    $guiResources $obj $Objects($obj) ]
    }

    # Now append all the Resource strings, changing any version strings as
    # needed.

    foreach res [array names Resources] {
	regsub -all XIMTOOL_VERSION $Resources($res) $Version ver
	set guiResources [ format "%s\n\n%s\n\n" $guiResources $ver ]
    }

    # Define all of the GUI objects and resources.
    appInitialize ximtool XImtool $guiResources
}


# Realize a window module, i.e. create it's objects.
proc Realize { module args } \
{
    global Objects

    # Create any widgets for the module.  We only do this once and set a
    # flag to indicate the objects have been created so we don't do it on
    # subsequent realizations.
    if { [info exists Objects($module)] } {
	createObjects [format "%s_objects" $module]
	reset-server
    }
}


# Bootstrap up the GUI.
InitWidgetTree
Realize ximtool
Realize parameters
Realize panelShell
Realize tcl_panel
Realize pixel_table
Realize hdr_panel
Realize blink_panel
Realize help_panel
Realize xpan_panel
Realize xmag_panel
Realize warning

reset-server

# Set the gterm widget focus.
send colorbar setGterm ; send colorbar activate
send imagewin setGterm ; send imagewin activate

# Crank it up.
activate




##############################################################################
#  Utility Procedures.
##############################################################################

# Utility procedure to test True/False strings in resources.
proc true {v} {expr {$v == "true" || $v == "True" || $v == "TRUE"}}

# Utility functions.
proc min {a b} { expr {($a < $b) ? $a : $b} }
proc max {a b} { expr {($a > $b) ? $a : $b} }

# Global variables.
set version	"NOAO/IRAF XImtool Version 2.0BETA"

set winWidth 	[send imagewin get width ]	;# display window width
set winHeight 	[send imagewin get height]	;# display window height
set appWidth 	[send display  get width ]	;# application window width
set appHeight 	[send display  get height]	;# application window height
set marker 		none			;# selected marker
set markno 		0			;# used to name new markers
set ruler 		none			;# selected ruler
set ruleno 		0			;# used to name new rulers
set blinkFrames 	"1 2"			;# list of blink frames
set auto_reg 		0

set panel_up 		0			;# control panel mapped
set help_up 		0			;# help panel mapped
set ism_enable		0			;# ISM is running
set ism_capable		1			;# Client is ISM capable
set frameCache(0)	""			;# ISM frame cache

set ctype		"equatorial"		;# default coord type
set eqtype		"fk5"			;# default equatorial type

# Global constants.
set MAX_FRAMES 		16			;# max frame buffers

# TCL constants
set tcl_precision 	8



# Window resize callbacks.
proc winResize {w width height} { 
    global winWidth winHeight

    if {$width <= 1 || $height <= 1} \
	return

    set winWidth  $width
    set winHeight $height 
} ; send imagewin addCallback winResize resize

proc appResize {w width height} \
{
    global doHcut doVcut cutXPos cutYPos
    global appWidth appHeight

    set appWidth $width
    set appHeight $height 

    catch {
        if {$doHcut} { 
	    send hcutPlot clearScreen
	    hcutInit
	    send hcutAxes1 redraw ; send hcutAxes2 redraw
	    cutPlots $cutXPos $cutYPos 
        }
        if {$doVcut} { 
	    send vcutPlot clearScreen
	    vcutInit
	    send vcutAxes1 redraw ; send vcutAxes2 redraw
	    cutPlots $cutXPos $cutYPos 
        }
    }
} ; #send imagewin addCallback appResize resize



# Additional global variables, taking default values from resources.
getResources {
    { zoomfactors }
    { displayCoords }
    { displayPanner }
    { displayMagnifier }
    { blinkRate }
    { pannerArea }
    { pannerGeom }
    { magnifierArea }
    { magnifierGeom }
    { wcsboxGeom }
    { maxContrast }
    { showToolBar }
    { showPanelBar }
    { warnings }
    { centerBoxSize }
    { peakCentroid }
    { highlight }
}

set warnings [true $warnings]
set defaultBlinkRate $blinkRate

# Client state variables (UI parameter objects).  Certain of these parameters
# we mirror in Tcl variables here, updating the values with a callback when
# the parameter value changes.  Others require special callbacks.

set frame       1		;# current display frame
set nframes     0		;# number of frame buffers
set frames {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16} ;# list of image frames
set frameWidth  0		;# frame buffer width, pixels
set frameHeight 0		;# frame buffer height, pixels
set frameDepth  8		;# frame buffer pixel size, bits
set cursorMode  0		;# true when cursor read pending

foreach i $frames {
    set frameZoomX($i) 0	;# X zoom factor
    set frameZoomY($i) 0	;# Y zoom factor
    set frameCenterX($i) 0	;# X center of field
    set frameCenterY($i) 0	;# Y center of field
    set frameScaleX($i) 0	;# X scale factor
    set frameScaleY($i) 0	;# Y scale factor
    set frameOffsetX($i) 0	;# X register offset
    set frameOffsetY($i) 0	;# Y register offset
    set enhancement($i) none	;# colortable enhancement
}


#trace variable frameOffsetX w debug_pvar	;# Debug stuff
#trace variable frameOffsetY w debug_pvar
#trace variable frameZoomX w debug_pvar
#trace variable frameZoomY w debug_pvar
#trace variable frameScaleX w debug_pvar
#trace variable frameScaleY w debug_pvar

proc debug_pvar { name element op } \
{
    if {$element != ""} {
	set name ${name}($element)
    }
    upvar $name x
    puts "Variable $name set to $x"
}




################################################################################
# Cut-plot handling routines.
################################################################################

set doHcut	0
set doVcut	0
set hstate	0
set vstate	0
set plotSpeed	1 ; send plotSpeed  set on True
set curJump	1 ; send curJump  set on True
set curTrack	1 ; send curTrack set on True

set cutXPos	[expr "$winWidth  / 2"]
set cutYPos	[expr "$winHeight / 2"]
set cutXScale 	1.0
set cutYScale 	1.0



# Change the cursor to the crosshair when in the plot
proc cutCursor { widget event args } \
{
    global doHcut doVcut curTrack

    if {! $curTrack} \
	return

    if { $event == "enterNotify" } {
	send $widget setCursorType ginMode

	# Disable the update of the graph we're in while in the plot window.
	if {$widget == "hcutPlot"} { set doHcut 0 } else { set doVcut 0 }
    } elseif { $event == "leaveNotify" } {
        send $widget setCursorType idle

	# Enable the update of the graph we're leaving.
	if {$widget == "hcutPlot"} { set doHcut 1 } else { set doVcut 1 }
    }
    cutPlotRefresh
}
foreach w {hcutPlot vcutPlot} {
    send $w addEventHandler cutCursor enterWindowMask
    send $w addEventHandler cutCursor leaveWindowMask
}

proc cutPlotRefresh args \
{
    global doHcut doVcut cutXPos cutYPos

    if {$doHcut} {
        send hcutPlot clearScreen
        hcutInit
        send hcutAxes1 redraw ; send hcutAxes2 redraw
        cutPlots $cutXPos $cutYPos
    }
    if {$doVcut} {
        send vcutPlot clearScreen
        vcutInit
        send vcutAxes1 redraw ; send vcutAxes2 redraw
        cutPlots $cutXPos $cutYPos
    }
} ; send imagewin addEventHandler cutPlotRefresh enterWindowMask

proc cutPlotRedraw args \
{
    global doHcut doVcut cutXPos cutYPos

    if {$doHcut} {
        send hcutAxes1 redraw ; send hcutAxes2 redraw
        cutPlots $cutXPos $cutYPos
    }
    if {$doVcut} {
        send vcutAxes1 redraw ; send vcutAxes2 redraw
        cutPlots $cutXPos $cutYPos
    }
}


# Disable the options when we first start up.
#send plotOpts "set height 1 ; set width 1 ; unmap"
foreach w {plotOpts hcutFrame vcutFrame} { send $w unmap }


# Cut-Plot options callback.
proc doPlotOpts { widget type state args } \
{
    global plotSpeed curJump curTrack doHcut doVcut
    global cutXPos cutYPos

    if {$state} { set not 0 } else { set not 1 }

    switch $widget {
    plotSpeed 	 { if {$state} {
    		       send plotAccurate set on 0 ; send plotImgPix set on 0
		   } else {
    		       send plotSpeed set on True ; 
		   }
		   set plotSpeed $not
		 }
    plotAccurate { if {$state} {
    		       send plotImgPix set on 0 ; send plotSpeed set on 0
		   } else {
    		       send plotSpeed set on True ; 
		   }
		   set plotSpeed $not
		 }
    plotImgPix   { if {$state} {
    		       send plotAccurate set on 0 ; send plotSpeed set on 0
		   } else {
    		       send plotSpeed set on True ; 
		   }
		   set plotSpeed $not
		 }
    curJump	 { send curSmooth set on $not    ; set curJump   $state }
    curSmooth	 { send curJump set on $not      ; set curJump   $not 	}
    curTrack	 { set curTrack $state 					}
    }

    # Redraw the plots right away.
    if {$widget == "plotSpeed" || $widget == "plotAccurate"} { 
	cutPlots $cutXPos $cutYPos
    }
}
foreach w { plotSpeed plotAccurate plotImgPix curJump curSmooth curTrack } {
    send $w addCallback doPlotOpts 
}


# Toggle the display of the horizontal or vertical cut plot windows.

proc cutPlotToggle { widget type state args } \
{
    global doHcut doVcut cutXPos cutYPos hstate vstate
    set    debug  0

    set hstate [send hcut get state]
    set vstate [send vcut get state]
    set w [send display get width]
    set h [send display get height]

    if {$debug} { print " " ; print [format "display: %d x %d\n" $w $h] }

    if {$widget == "hcut"} {
	set hfw [expr [send hcutFrame get width] - 4]
	set hpw [send hcutPlot  get width]
        if {$state} {
	    # Enable the plot and resize the main window
	    if {$vstate} { 
		send plotOpts set width 134 
	    }
	    send hcutFrame "set width $hpw ; set height 132; map"
	    send hcutPlot "set width $hfw ; set height 128"
	    send display "set height [ expr ($h + 132) ]; set width $w"
            drawHcutAxes  1
	    setHcutCursor 1
	    if {$vstate} { 
		send plotOpts "set height 134 ; map"
	        vcutInit
	    }
	    hcutInit 				;# Initialize the plot.
        } else {
	    # Disable the plot and resize the main window
	    setHcutCursor 0
            drawHcutAxes  0
	    send hcutPlot clearScreen
	    send plotOpts "unmap; set height 4"
	    send hcutFrame "unmap; set width $hfw; set height 4"
	    send plotOpts "set width 4"
	    send display "set height [ expr ($h - 128) ] ; set width $w"
	    if {$vstate} { 
	        vcutInit
	    }
        }
        set doHcut $state
    } else {
	set vfh  [expr [send vcutFrame get height] - 4]
	set vph  [send vcutPlot  get height]
        if {$state} {
	    # Enable the plot and resize the main window
	    if {$hstate} { 
		send plotOpts set height 134
	    }
	    send vcutFrame "set height $vph ; set width 132 ; map"
	    send vcutPlot "set height $vfh ; set width 128"
	    send display "set height $h; set width [ expr ($w + 132) ]"
            drawVcutAxes  1
	    setVcutCursor 1
	    if {$hstate} { 
		send plotOpts "set height 134 ; set width 134; map"
     	        hcutInit
	    }
     	    vcutInit 				;# Initialize the plot.
        } else {
	    # Disable the plot and resize the main window
	    setVcutCursor 0
            drawVcutAxes  0
	    send vcutPlot clearScreen
	    send plotOpts "unmap; set width 4"
	    send vcutFrame "unmap; set height $vfh; set width 4"
	    send plotOpts "set height 4"
	    send display "set width [ expr ($w - 128) ] ; set height $h"
	    if {$hstate} { 
	        hcutInit
	    }
        }
        set doVcut $state
    }
		
    if {$debug} {
	print [format " hFrame: %d x %d\n" \
		[send hcutFrame get width] [send hcutFrame get height] ]
	print [format "  hPlot: %d x %d\n" \
		[send hcutPlot get width] [send hcutPlot get height] ]
	print [format " vFrame: %d x %d\n" \
		[send vcutFrame get width] [send vcutFrame get height] ]
	print [format "  vPlot: %d x %d\n" \
		[send vcutPlot get width] [send vcutPlot get height] ]
	print [format "state: %d  %d\n" $hstate $vstate]
	print [format "display: %d x %d\n" $w $h]
    }

    cutPlots $cutXPos $cutYPos
} ; foreach w { hcut vcut } { send $w addCallback cutPlotToggle }


# Draw the cut plots.
proc cutPlots { xpos ypos args } \
{
    global doHcut doVcut cutXPos cutYPos hstate vstate

    catch {
        if {$doHcut} {
    	    drawHcutIndicator $xpos
	     if {$hstate} { plotHcut $xpos $ypos }
	}
        if {$doVcut} {
    	    drawVcutIndicator $xpos
            if {$vstate} { plotVcut $xpos $ypos }
	}
    }

    set cutXPos $xpos  ;  set cutYPos $ypos
}


################################################################################
# Horizontal Cut-Plot Routines
################################################################################

set hcutVec	{}

# Initiailize the horizontal cut-plot
proc hcutInit args \
{
    global logz cutXScale winWidth cutXPos cutYPos

    # Just get some dummy pixels, we only want the z1/z2 values so we can 
    # initialize the labels.
    set xp   [expr [send imagewin get width] / 2 ]
    set yp   [expr [send imagewin get height] / 2 ]
    set pix  [send client getPixels $xp $yp 2 2 ]
    set z1   [lindex $pix 0]
    set z2   [lindex $pix 1]

    send hcutPlot getPhysRes  xr  yr
    send hcutPlot setLogRes  $xr $yr

    set logx    [send imagewin get width]
    set logz    [expr ($z2 - $z1)]
    set cutXScale [expr ($xr * 1.0) / ($logx * 1.0)]

    # Initialize the labels.
    send vcutPlot "setColorIndex 6"
    drawHcutLabels $z1 $z2
}

# Draw the horizontal cut-plot.
proc plotHcut { xpos ypos } \
{
    global doHcut cutXScale
    global hcutVec cutXPos plotSpeed


    if { ($xpos == 0 && $ypos == 0) || ! $doHcut } \
	return

    # Do the horizontal cut plot.
    set width [send imagewin get width]
    if {$plotSpeed} {
        set pix  [send client getPixels 0 $ypos $width 1 2 5 $cutXScale]
    } else {
        set pix  [send client getPixels 0 $ypos $width 1 2 1 $cutXScale]
    }
    set z1   [lindex $pix 0]
    set z2   [lindex $pix 1]
    set vec  [lrange $pix 2 end]

    # Erase the last plot rather than clear the screen and redraw 
    # the new vector.
    send hcutPlot setColorIndex background
    send hcutPlot drawPolyline $hcutVec
    send hcutPlot setColorIndex foreground
    send hcutPlot drawPolyline $vec
    set  hcutVec $vec 			;# save for later erasure

    # Mark the cursor position.
    drawHcutIndicator $xpos

    # Minimize the screen refreshes to speed things up.
    if { [expr "$ypos % 3"] == 0} {
	catch {
            drawHcutLabels $z1 $z2	;# redraw the labels
	}
        send hcutAxes1 redraw		;# redraw the axes markers
        send hcutAxes2 redraw
    }
}


# Create markers to indicate axes on the horizontal cut-plot.
proc drawHcutAxes { state } \
{
    if {$state} {
        send hcutPlot createMarker hcutAxes1 \
            type            box \
            createMode      noninteractive \
            lineColor       gray60 \
            lineStyle       0 \
            x               1 \
            y               60 \
            height          30 \
	    width           4096 \
            activated       True \
            visible         True \
            sensitive       False
        send hcutPlot createMarker hcutAxes2 \
            type            box \
            createMode      noninteractive \
            lineColor       gray60 \
            lineStyle       0 \
            x               1 \
            y               1 \
            height          60 \
	    width           4096 \
            activated       True \
            visible         True \
            sensitive       False
    } else {
	send hcutAxes1 destroy ; send hcutAxes2 destroy
    }
}

# Create a marker to be used as the cursor indicator.
proc setHcutCursor { state } \
{
    if {$state} {
	set pts { {252 10} {260 10} {256 1} }

        send hcutPlot createMarker hcutCursor \
            type          polygon \
            createMode    noninteractive \
            lineColor     black \
            fill     	  True \
            fillColor     yellow \
            x             256 \
            y             12 \
            width         8 \
            height        10 \
            knotSize      0 \
            activated     True \
            visible       False \
            sensitive     False
        send hcutCursor setVertices $pts
        send hcutCursor set visible True

    } else {
	send hcutCursor destroy
    }
}

# Label the axes on the horizontal cut plot.
proc drawHcutLabels { z1 z2 } \
{
    set mid  [expr "($z2-$z1)/2.0+$z1"]
    set low [expr "($mid-$z1)/2.0+$z1"]
    set high  [expr "($z2-$mid)/2.0+$mid"]

    send hcutPlot "setColorIndex 6 ; \
	 drawAlphaText 2 10  [format "%.1f" $z2] ; \
         drawAlphaText 2 34  [format "%.1f" $high] ; \
         drawAlphaText 2 64  [format "%.1f" $mid] ; \
         drawAlphaText 2 94  [format "%.1f" $low] ; \
         drawAlphaText 2 120 [format "%.1f" $z1]"
}

# Draw the cursor position indicator on the horizontal cut plot.
proc drawHcutIndicator { xpos } \
{
    global cutXScale cutXPos

    send hcutCursor move [expr ($xpos * $cutXScale)] 12
    set cutXPos $xpos
}

# Track the cursor while in the cut-graph window.
proc hcutWCSUpdate { x y args } \
{
    global cutYPos curTrack
    if {$curTrack} { 
        wcsUpdate $x $cutYPos 
    }
    drawHcutIndicator $x
}




################################################################################
# Vertical Cut-Plot Routines
################################################################################

set vcutVec	{}

# Initiailize the vertical cut-plot
proc vcutInit args \
{
    global cutYScale winWidth cutXPos cutYPos

    # Just get some dummy pixels, we only want the z1/z2 values so we can 
    # initialize the labels.
    set xp   [expr [send imagewin get width] / 2 ]
    set yp   [expr [send imagewin get height] / 2 ]
    set pix  [send client getPixels $xp $yp 2 2 ]
    set z1   [lindex $pix 0]
    set z2   [lindex $pix 1]

    send vcutPlot getPhysRes  xr  yr
    send vcutPlot setLogRes  $xr $yr

    set logy    [send imagewin get height]
    set logz    [expr ($z2 - $z1)]
    set cutYScale [expr ($yr * 1.0) / ($logy * 1.0)]

    # Initialize the labels.
    send vcutPlot "setColorIndex 6; reset"
    drawVcutLabels $z1 $z2
}

# Draw the horizontal cut-plot.
proc plotVcut { xpos ypos } \
{
    global doVcut cutYScale
    global vcutVec cutXPos cutYPos plotSpeed


    if { ($xpos == 0 && $ypos == 0) || ! $doVcut } \
	return

    # Do the vertical cut plot.
    set height [send imagewin get height]
    if {$plotSpeed} {
        set pix  [send client getPixels $xpos 0 1 $height 3 5 $cutYScale]
    } else {
        set pix  [send client getPixels $xpos 0 1 $height 3 1 $cutYScale]
    }
    set z1   [lindex $pix 0]
    set z2   [lindex $pix 1]
    set vec  [lrange $pix 2 end]

    # Draw the vector.
    send vcutPlot setColorIndex background
    send vcutPlot drawPolyline $vcutVec
    send vcutPlot setColorIndex foreground
    send vcutPlot drawPolyline $vec
    set  vcutVec $vec 			;# save for later erasure

    # Mark the cursor position.
    drawVcutIndicator $ypos

    # Minimize the screen refreshes to speed things up.
    if { [expr "$xpos % 3"] == 0} {
	catch {
            drawVcutLabels $z1 $z2	;# redraw the labels
	}
        send vcutAxes1 redraw		;# redraw the axes markers
        send vcutAxes2 redraw
    }
}

# Erase the last plot rather than clear the screen and redraw it all. The
# erase is done by redrawing the last vector in the the background color.
proc eraseOldVcut args \
{
    global cutYPos vcutVec

    send vcutPlot setColorIndex background
    send vcutPlot drawPolyline $vcutVec
    send vcutPlot setColorIndex foreground
}

# Draw the horizontal cut-plot.
# Create markers to indicate axes on the vertical cut-plot.
proc drawVcutAxes { state } \
{
    if {$state} {
        send vcutPlot createMarker vcutAxes1 \
            type            box \
            createMode      noninteractive \
            lineColor       gray60 \
            lineStyle       0 \
            x               60 \
            y               1 \
            height          4096 \
            width           30 \
            activated       True \
            visible         True \
            sensitive       False
        send vcutPlot createMarker vcutAxes2 \
            type            box \
            createMode      noninteractive \
            lineColor       gray60 \
            lineStyle       0 \
            x               1 \
            y               1 \
            width           60 \
            height          4096 \
            activated       True \
            visible         True \
            sensitive       False
    } else {
	send vcutAxes1 destroy ; send vcutAxes2 destroy
    }
}

# Create a marker to be used as the cursor indicator.
proc setVcutCursor { state } \
{
    if {$state} {
	set pts { {10 252} {10 260} {1 256} }

        send vcutPlot createMarker vcutCursor \
            type          polygon \
            createMode    noninteractive \
            lineColor     black \
            fill     	  True \
            fillColor     yellow \
            x             12 \
            y             256 \
            width         10 \
            height        8 \
            knotSize      0 \
            activated     True \
            visible       False \
            sensitive     False
        send vcutCursor setVertices $pts
        send vcutCursor set visible True

    } else {
	send vcutCursor destroy
    }
}

# Label the axes on the vertical cut plot.
proc drawVcutLabels { z1 z2 } \
{
    set mid  [expr "($z2-$z1)/2.0+$z1"]
    set low  [expr "($mid-$z1)/2.0+$z1"]
    set high [expr "($z2-$mid)/2.0+$mid"]

    # Initialize the label strings and positions.
    set labels {}
    foreach i [list $z2 $high $mid $low $z1] {
	lappend labels  [ format "%.1f" $i ]
    }
    set xposns { 2 28 58 88 112 }

    send vcutPlot "setColorIndex 6"

    # Draw each label vertically down the position since we can't rotate
    # the text.
    set xp  0
    foreach lab $labels {
	set chars [split $lab {} ]
        set yp  12
	set xpos [lindex $xposns $xp]
        foreach ch $chars {
	    if {$ch == "."} { incr yp -4 }
    	    send vcutPlot drawAlphaText $xpos $yp $ch
	    incr yp 10
        }
	incr xp
    }
}


# Draw the cursor position indicator on the horizontal cut plot.
proc drawVcutIndicator { ypos } \
{
    global cutYScale cutYPos

    send vcutCursor move 12 [expr ($ypos * $cutYScale)]
    set cutYPos $ypos
}


# Track the cursor while in the cut-graph window.
proc vcutWCSUpdate { x y args } \
{
    global cutXPos curTrack
    if {$curTrack} { 
        wcsUpdate $cutXPos $y 
    }
    drawVcutIndicator $y
}



################################################################################
# UTILITY ROUTINES
################################################################################


# TICSTEP -- Utility routine to compute nice ticmark steps in plots.
# [ NOT CURRENTLY USED. ]

proc ticstep { range nsteps } \
{
    set t2 0.301029996
    set t5 0.698970004
    set df [ expr "$range / double($nsteps + 1)" ]
    if {$df > 0.0} {
        set p1 [ expr "log10(double($df))" ]
    } else {
        set p1 [ expr "log10(double(-$df))" ]
    }
    set p2 [ expr "int($p1)" ]
    set p3 [ expr "$p1 - $p2" ]

    if { $p3 < 0.0 } {
        set p3 [ expr "$p2 + 1.0" ]
        set p2 [ expr "$p2 - 1.0" ]
    }

    if { $p3 < 1.0e-10 } {
       set ticstep [ expr "pow(double(10.0),double($p2))" ]
    } elseif { $p3 > 0. &&  $p3 <=  $t2 } {
       set ticstep [ expr "pow(double(10.0),double($p2 + $t2))" ]
    } elseif { $p3 >  $t2 &&  $p3 <=  $t5 } {
       set ticstep [ expr "pow(double(10.0),double($p2 + $t5))" ]
    } elseif { $p3 >  $t5 &&  $p3 <= 1.0 } {
       set ticstep [ expr "pow(double(10.0),double($p2 + 1.))" ]
    } else {
       set ticstep $df
    }

    set logtic  [ expr "int(log10($ticstep)) - 1" ]
    set scale   [ expr "pow(double(10.0),double($logtic))" ]
    set ticstep [ expr "int( ($ticstep / $scale) * $scale)" ]

    if {$ticstep < 0.1} { set ticstep 0.10 }

    return $ticstep
}



# Cursor positioning routines
#----------------------------

proc move_cursor { xstep ystep args } \
{
    set raster 0
    send imagewin getCursorPos rx ry
    send imagewin setCursorPos [expr $rx + $xstep] [expr $ry + $ystep] $raster
}


# Called when the number of frames changes.
proc setNFrames {param old new} \
{
    global frameMenuDescription nframes frames

    set nframes $new
    if {$old != $new} {
	foreach i {prevButton nextButton} {
	    send $i set sensitive [expr "$nframes > 1"]
	}

	if {$nframes > 0} {

	    # Creates the Frames menu on the main image window.
	    set items { }
	    for {set i 1} {$i <= $nframes} {incr i} {
		set l [format "%2d" $i]
		lappend  items "$l f.exec \{send client setFrame $i\} sensitive \{[expr \"$nframes >= $i\"]\}"
	    }
	    editMenu frameMenu frameButton $items

	    # Create the menu for the blink frames list.
	    set items { }
	    for {set i 0} {$i <= $nframes} {incr i} {
		set j [expr ($i + 1)]
		if {$i == 0} {
	   	    set s "\"none\" f.exec \{send brFrameBTN set label \" \"\}"
		    lappend items $s
		} else {
		    set l [format "%2d" $i]
		    lappend items "$l f.exec \{send brFrameBTN set label $l\} sensitive \{[expr \"$nframes >= $i\"]\}"
		}
	    }
	    for {set i 1} {$i <= $nframes} {incr i} {
		send brFrame$i setSensitive True
		send tFrame$i  setSensitive True
	        regsub -all BTN $items $i nmenu
		editMenu frame${i}Menu brFrame$i $nmenu
	    }

	} else {
	    editMenu frameMenu frameButton $frameMenuDescription

	    for {set i 1} {$i <= $nframes} {incr i} {
		send brFrame$i setSensitive True
		send tFrame$i  setSensitive True
		editMenu frame${i}Menu brFrame$i $frameMenuDescription
	    }
	}
    }

    for {set i 1} {$i <= 16} {incr i} {
	if {$i <= $nframes} {
	    send frame$i map
	} else {
	    send frame$i unmap
	}
    }

    if {$nframes > 2} {
        setAllTileFrames
    }
}; send nframes addCallback setNFrames


# Set the default main window frame menu.
set frameMenuDescription {
    {" 1" f.exec "send client setFrame 1"  sensitive {[expr "$nframes >= 1"]} }
    {" 2" f.exec "send client setFrame 2"  sensitive {[expr "$nframes >= 2"]} }
    {" 3" f.exec "send client setFrame 3"  sensitive {[expr "$nframes >= 3"]} }
    {" 4" f.exec "send client setFrame 4"  sensitive {[expr "$nframes >= 4"]} }
}; createMenu frameMenu  frameButton  $frameMenuDescription




# Initialize the frame lists panels (blink panel and tile tab).
for {set i 1} {$i <= 16} {incr i} {
    send brFrame$i set label [format "%2d" $i]
    send tFrame$i  set label [format "%2d" $i]
    if {$i <= 4} {
	send brFrame$i setSensitive True
	send tFrame$i  "setSensitive True ; set state 1"
    } else {
	send brFrame$i setSensitive False
	send tFrame$i  "setSensitive False ; set state 0"
    }
    createMenu frame${i}Menu brFrame$i $frameMenuDescription
}


# Called when the frame being displayed changes.
proc frameChanged {param old new} \
{
    global frame

    set frame $new
    send frameButton set label [format "%2d" $frame]

    # The first time we request frame 5 or higher reset 
    # the extra frame buttons on the control panel to make
    # them visible.
    if {$new >= 5} {
	send frlistBox set width 49
    }
    wcsFmtFBConfig
    drawCompass
}; send frame addCallback frameChanged


# Called when the frame buffer configuration changes.
proc setFrameSize {param old new} \
{
    global frameWidth frameHeight frameDepth
    set frameWidth [lindex $new 0]
    set frameHeight [lindex $new 1]
    set frameDepth [lindex $new 2]

    wcsFmtFBConfig
}; send frameSize addCallback setFrameSize

# Called when the current frame is zoomed or panned.
proc setFrameView {param old new} \
{
    global frameZoomX frameZoomY frameCenterX frameCenterY
    global frameScaleX frameScaleY frameOffsetX frameOffsetY
    global frame auto_reg blinkFrames

    # Update the position.
    set frameZoomX($frame)   [lindex $new 0]
    set frameZoomY($frame)   [lindex $new 1]
    set frameCenterX($frame) [lindex $new 2]
    set frameCenterY($frame) [lindex $new 3]
    set frameScaleX($frame)  [lindex $new 4]
    set frameScaleY($frame)  [lindex $new 5]
    set frameOffsetX($frame) [lindex $new 6]
    set frameOffsetY($frame) [lindex $new 7]

    # If auto-registering is enabled, do it now, but only when we're updating
    # the current display frame, and only if that frame is in the framelist.

    if {$auto_reg == 1 && $frame == [send frameButton get label]} {
	if {[string first $frame $blinkFrames] != -1} {
	    send client offsetRegister \{$blinkFrames\}
	}

	foreach f $blinkFrames {
	    if {$f != $frame} {
    	        set frameZoomX($f)   $frameZoomX($frame)
    	        set frameZoomY($f)   $frameZoomY($frame)
    	        set frameCenterX($f) $frameCenterX($frame)
    	        set frameCenterY($f) $frameCenterY($frame)
    	        set frameScaleX($f)  $frameScaleX($frame)
    	        set frameScaleY($f)  $frameScaleY($frame)
	    }
	}
    }
    deleteAllRulers

}; send frameView addCallback setFrameView


# Called when the color enhancement for a frame changes.
proc setEnhancement {param old new} \
{
    global enhancement
    set enhancement([lindex $new 0]) [lrange $new 1 end]
}; send enhancement addCallback setEnhancement

# Called when the frame title changes (e.g. frame change or new frame loaded).
proc setTitle {param old new} \
{
    set lab  [string trimright $new]
    send imageTitle set label $lab

    set image [lindex [ split $lab '-'] 0 ]
    wcsFmtImname $image

    set title [lindex [ split $lab '-'] 1 ]
    wcsFmtImtitle $title
    deleteAllRulers
}; send frameTitle addCallback setTitle

# Called when the image is flipped in an axis.
proc setFlip {param old new} \
{
    if {$param == "xflip"} { 
	send xflipButton set state [true $new]
    } else {
	send yflipButton set state [true $new]
    }
    deleteAllRulers
}; foreach i {xflip yflip} { send $i addCallback setFlip }


# Various general callbacks.

proc Quit args \
{
    global ism_enable

    if {$ism_enable} {
        catch { send wcspix quit }
    }
    send client Quit 			  
}
proc nextFrame args	    { send client nextFrame 		  }
proc prevFrame args	    { send client prevFrame 		  }
proc setColormap { mapno }  { send client setColormap $mapno 	  }
proc xflip  args	    { send client flip x   ; flipRegister }
proc yflip  args	    { send client flip y   ; flipRegister }
proc xyflip args	    { send client flip x y ; flipRegister }
proc flipRegister args \
{
    global auto_reg frame blinkFrames

    if {$auto_reg == 1 && $frame == [send frameButton get label]} {
	if {[string first $frame $blinkFrames] != -1} {
	   send client offsetRegister \{$blinkFrames\}
	}
    }
}



# Initialize bitmaps.
createBitmap xflip 16 16 {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x08, 0x18, 0x18,
   0x1c, 0x38, 0xfe, 0x7f, 0xfe, 0x7f, 0x1c, 0x38, 0x18, 0x18, 0x10, 0x08,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}

createBitmap yflip 16 16 {
   0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, 0x80, 0x01,
   0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xf0, 0x0f,
   0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00}

createBitmap qmark 16 16 {
   0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x0f, 0x18, 0x0c, 0x18, 0x0c,
   0x18, 0x0e, 0x00, 0x07, 0x80, 0x03, 0x80, 0x01, 0x80, 0x01, 0x00, 0x00,
   0x80, 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00}

createBitmap larrow 16 16 {
   0x00, 0x00, 0x00, 0x03, 0x80, 0x03, 0xc0, 0x03, 0xe0, 0x1e, 0x70, 0x1e,
   0x38, 0x18, 0x1c, 0x18, 0x1c, 0x18, 0x38, 0x18, 0x70, 0x1e, 0xe0, 0x1e,
   0xc0, 0x03, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00}

createBitmap rarrow 16 16 {
   0x00, 0x00, 0xc0, 0x00, 0xc0, 0x01, 0xc0, 0x03, 0x78, 0x07, 0x78, 0x0e,
   0x18, 0x1c, 0x18, 0x38, 0x18, 0x38, 0x18, 0x1c, 0x78, 0x0e, 0x78, 0x07,
   0xc0, 0x03, 0xc0, 0x01, 0xc0, 0x00, 0x00, 0x00}

createBitmap panel 16 16 {
   0x00, 0x00, 0xf8, 0x1f, 0xf8, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
   0x98, 0x19, 0x98, 0x19, 0x98, 0x19, 0x98, 0x19, 0x98, 0x19, 0x18, 0x18,
   0x18, 0x18, 0x18, 0x18, 0xf8, 0x1f, 0xf8, 0x1f}

createBitmap brightness 15 15 {
   0x00, 0x00, 0x80, 0x00, 0x84, 0x10, 0xe8, 0x0b, 0x10, 0x04, 0x08, 0x08,
   0x08, 0x08, 0x0e, 0x38, 0x08, 0x08, 0x08, 0x08, 0x10, 0x04, 0xe8, 0x0b,
   0x84, 0x10, 0x80, 0x00, 0x00, 0x00}

createBitmap contrast 15 15 {
   0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x30, 0x07, 0x08, 0x0f, 0x08, 0x0f,
   0x04, 0x1f, 0x04, 0x1f, 0x04, 0x1f, 0x08, 0x0f, 0x08, 0x0f, 0x30, 0x07,
   0xc0, 0x01, 0x00, 0x00, 0x00, 0x00}

createBitmap bar 10 10 {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x42, 0x00, 0x7e, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}

createBitmap dot 16 16 {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01,
   0xe0, 0x03, 0xf0, 0x07, 0xf0, 0x07, 0xf0, 0x07, 0xe0, 0x03, 0xc0, 0x01,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}

createBitmap null 16 16 {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}

createBitmap solid 64 24 {
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}

catch { send controlButton "set bitmap panel; addCallback panel" }
catch { send helpButton    "set bitmap qmark; addCallback Help"  }
send xflipButton "set bitmap xflip;	 addCallback xflip"
send yflipButton "set bitmap yflip;	 addCallback yflip"
send prevButton  "set bitmap larrow; addCallback prevFrame"
send nextButton  "set bitmap rarrow; addCallback nextFrame"
send blinkPanel  "set bitmap panel"



# WINDOW the current frame.
set old_cm_x	0
set old_cm_y	0

proc windowColormap {x y} \
{
    global winWidth winHeight maxContrast old_cm_x old_cm_y

    # For efficiency we won't compute the sqrt of the distance but instead
    # just compare the square.  Use a threshold of 6 pixels so when we
    # narrow in on the ROI we refine the colormap more precisely.

    set diff  [expr (($old_cm_x - $x) * ($old_cm_x - $x)) + \
                   (($old_cm_y - $y) * ($old_cm_y - $y))]

    # Keep the old position.
    set old_cm_x $x
    set old_cm_y $y
    if {$diff > 36} {
       return
    }

    send client windowColormap \
	[expr "double($x) / $winWidth"] \
	[expr "(double($y) - $winHeight / 2.0) / $winHeight * \
	    $maxContrast * 2.0"]
}

proc updateColormap {x y} \
{
    global winWidth winHeight maxContrast old_cm_x old_cm_y

    set old_cm_x $x
    set old_cm_y $y
    send client updateColormap \
	[expr "double($x) / $winWidth"] \
	[expr "(double($y) - $winHeight / 2.0) / $winHeight * \
	    $maxContrast * 2.0"]
}



# WINDOW the current frame, but only one color at a time.
proc windowRGB {color x y save_flag} \
{
    global winWidth winHeight maxContrast

    send client windowRGB $color \
	[expr "double($x) / $winWidth"] \
	[expr "(double($y) - $winHeight / 2.0) / $winHeight * \
	    $maxContrast * 2.0"] $save_flag
}


# ZOOM and PAN.
set xcen 0
set ycen 0
foreach i $frames {set zoomindex($i) 0}
set nzoomfactors 0
foreach i $zoomfactors {
    set zoomfactor($nzoomfactors) $i
    incr nzoomfactors
}

# Zoom or pan image at given center.
proc zoom {x y} \
{
    global xcen ycen frame
    global zoomindex zoomfactor
    global nzoomfactors

    set rx $x;  set ry $y
    set raster 0

    # Convert raw screen coordinates to frame buffer raster coordinates.
    send imagewin unmapPixel $x $y raster rx ry

    # Select a pixel.
    set rx [expr "int ($rx)"]
    set ry [expr "int ($ry)"]

    # If the pointer did not move (much) zoom the image, otherwise
    # pan it.

    send imagewin setCursorType busy
    if {sqrt(pow($x-$xcen, 2) + pow($y-$ycen, 2)) < 4} {
	set zoomindex($frame) [expr [incr zoomindex($frame)] % $nzoomfactors]
	set mag $zoomfactor($zoomindex($frame))
	send client zoom $mag $mag $rx $ry
    } else {
	send client pan $rx $ry
	set xcen $x
	set ycen $y
    }

    # Move the pointer so that it tracks the object feature the user
    # selected.

    send imagewin setCursorPos $rx $ry $raster
    send imagewin getCursorPos xcen ycen
    send imagewin setCursorType idle
}


# Zoom using a marker to indicate the region to be displayed.
proc zoomMarker {marker aspect} \
{
    global xcen ycen frame
    global winWidth winHeight
    global zoomindex nzoomfactors
    global auto_reg frame frameOffsetX frameOffsetY

    # getRegion returns: "rectangle raster x y width height rotangle".
    set region [send $marker getRegion unmap]

    set raster [lindex $region 1]
    set xcen [expr "int([lindex $region 2]) + 0.5"]
    set ycen [expr "int([lindex $region 3]) + 0.5"]
    set snx  [expr "[lindex $region 4] * 2"]
    set sny  [expr "[lindex $region 5] * 2"]

    # Compute the magnification ratio.
    set xmag [expr "$winWidth / $snx"]
    set ymag [expr "$winHeight / $sny"]
    if {$aspect == "equal"} {
	set mag [expr "($xmag < $ymag) ? $xmag : $ymag"]
	set xmag $mag;  set ymag $mag
    }

    # Zoom the image.
    send client zoomAbs \
	$xmag $ymag $xcen $ycen \
	$frameOffsetX($frame) $frameOffsetY($frame)

    # The following causes a button2 to redisplay the full image.
    send imagewin setCursorPos $xcen $ycen $raster
    send imagewin getCursorPos xcen ycen
    set zoomindex($frame) [expr "$nzoomfactors - 1"]
}

# Pan the display frame one width/height in a given direction.
proc moveFrame { xs ys args } \
{
    global winWidth winHeight frame
    global frameWidth frameHeight
    global frameZoomX frameZoomY frameCenterX frameCenterY
    global frameOffsetX frameOffsetY

    # Get the step size for the new position.
    set xstep_size [ expr "$xs * $winWidth / $frameZoomX($frame)" ]
    set ystep_size [ expr "$ys * $winHeight / $frameZoomY($frame)" ]

    # Set the boundaries so we only move up to the edges.
    set xl [ expr "($winWidth / $frameZoomX($frame)) / 2 + 1" ]
    set yl [ expr "($winHeight / $frameZoomY($frame)) / 2 + 1" ]
    set xu [ expr "$frameWidth - $xl" ]
    set yu [ expr "$frameHeight - $yl" ]

    # Set the new center position.
    set nxc [ expr "$frameCenterX($frame) + $xstep_size" ]
    set nyc [ expr "$frameCenterY($frame) + $ystep_size" ]
    if {$nxc < $xl} { set nxc $xl }
    if {$nxc > $xu} { set nxc $xu }
    if {$nyc < $yl} { set nyc $yl }
    if {$nyc > $yu} { set nyc $yu }

    # Finally, send the command to move the frame.
    send client zoomAbs \
	$frameZoomX($frame) $frameZoomY($frame) $nxc $nyc \
	$frameOffsetX($frame) $frameOffsetY($frame)
}

proc resetView {param old new} {
    global zoomindex xcen ycen frames
    global frameWidth frameHeight

    if {$new == "done"} {
	foreach i $frames {
	    send client setFrame $i
	    set xcen [expr $frameWidth / 2]
	    set ycen [expr $frameHeight / 2]
	    send client zoom 1 1 $xcen $ycen
	    set zoomindex($i) 0
	    send client setColormap Grayscale
	    normalize
	}
	send client setFrame 1
    }
}; #send initialize addCallback resetView


# CURSOR READ stuff.
proc setCursorMode {param old new} \
{
    global cursorMode

    if {$new == "on"} {
	send imagewin "activate; setCursorType ginMode"
	set cursorMode 1
    } elseif {$new == "off"} {
	send imagewin "setCursorType idle; deactivate"
	set cursorMode 0
    }
}

proc keyInput {widget event sx sy data} \
{
    global cursorMode frame

    if {!$cursorMode || $event != "keyPress"} \
	return
    if {[lindex $data 0] == "??"} \
	return

    # Convert raw screen coordinates to raster pixel coordinates.
    send imagewin unmapPixel $sx $sy raster rx ry

    # Return the cursor value and exit cursor mode.
    send client retCursorVal $rx $ry $frame 1 [lindex $data 0]
}

proc resetCursorMode args {
    global cursorMode frame
    if {$cursorMode} {
	send imagewin getCursorPos x y
	send client retCursorVal $x $y $frame 1 ^D
    }
}; send initialize addCallback resetCursorMode

send cursorMode addCallback setCursorMode
send imagewin   addCallback keyInput input


# MARKER stuff.  The active marker is determined by the global variable
# "marker", which is the marker the pointer is in, or which the pointer
# was most recently in.

# Translations when pointer is inside marker.
set markerTranslations { \
!Shift <Btn1Motion>:	m_rotateResize()
      <Btn1Motion>:	m_moveResize()
 !Shift <Btn1Down>:	m_raise()  m_markpos()
	<Btn1Down>:	m_raise()  m_markposAdd()
	  <Btn1Up>:	m_redraw() m_destroyNull()
	<Btn2Down>:	m_lower()
	<Btn3Down>:	popup(markerMenu)
	  <Btn3Up>:	popdown(markerMenu)
      !Ctrl <Key>b:     call(prevFrame,$name)
      !Ctrl <Key>f:     call(nextFrame,$name)
      !Ctrl <Key>h:     call(move_cursor,-1,0)
      !Ctrl <Key>j:     call(move_cursor,0,1)
      !Ctrl <Key>k:     call(move_cursor,0,-1)
      !Ctrl <Key>l:     call(move_cursor,1,0)
      !Ctrl <Key>n:     call(normalize)
      !Ctrl <Key>c:     call(cpZoomAction,centerFrame)
      !Ctrl <Key>i:     call(cpInvert)
      !Ctrl <Key>m:     call(cpMatchFrames)
      !Ctrl <Key>r:     call(cpRegisterFrames)
      !Ctrl <Key>p:     call(togglePanner)
       !Alt <Key>1: 	call(cpSetFrame,frame1)
       !Alt <Key>2: 	call(cpSetFrame,frame2)
       !Alt <Key>3: 	call(cpSetFrame,frame3)
       !Alt <Key>4: 	call(cpSetFrame,frame4)
      !Ctrl <Key>1: 	call(cpZoom,1,1,fixed)
      !Ctrl <Key>2: 	call(cpZoom,2,2,fixed)
      !Ctrl <Key>3: 	call(cpZoom,3,3,fixed)
      !Ctrl <Key>4: 	call(cpZoom,4,4,fixed)
      !Ctrl <Key>5: 	call(cpZoom,5,5,fixed)
      !Ctrl <Key>6: 	call(cpZoom,6,6,fixed)
      !Ctrl <Key>7: 	call(cpZoom,7,7,fixed)
      !Ctrl <Key>8: 	call(cpZoom,8,8,fixed)
      !Ctrl <Key>9: 	call(cpZoom,9,9,fixed)
    <Key>BackSpace:	m_deleteDestroy()
       <Key>Delete:	m_deleteDestroy()
	<KeyPress>:	m_input()
	  <Motion>:	track-cursor() call(wcsUpdate,$x,$y) call(magnifierMapImage,$x,$y)
}

# Popup menu in effect when inside marker.
createMenu markerMenu imagewin {
    {	Marker		f.title			}
    {			f.dblline		}
    {	Zoom		f.exec {
			    zoomMarker $marker equal
			    send $marker destroy
			}			}
    {	Fill		f.exec {
			    zoomMarker $marker fill
			    send $marker destroy
			}			}
    {	Print		f.exec {
			    send $marker getRect interior x0 y0 nx ny
		            setPrintCorners $x0 [expr $y0 + $ny -1] \
		                [expr $x0 + $nx -1] $y0
			    send client print $x0 $y0 $nx $ny
			}			}
    {	Save		f.exec {
		            send imagewin setCursorType busy
			    send $marker getRect interior x0 y0 nx ny
			    send client save $x0 $y0 $nx $ny
		            send imagewin setCursorType idle
			}			}
    {	Info		f.exec {
			    send infoText append \
				[format "%s\n" [send $marker getRegion unmap]]
			}			}
    {	Unrotate	f.exec {
			    send $marker setAttribute rotangle 0
			}			}
    {			f.dblline		}
    {	Color		f.menu markerColor	}
    {	Type		f.menu markerType	}
    {			f.dblline		}
    {	Destroy		f.exec {
			    send $marker destroy
			}			}
}

createMenu markerType markerMenu {
    {	Type		f.title			}
    {			f.dblline		}
    {	Rectangle	f.exec "m_setType $marker rectangle"	}
    {	Box		f.exec "m_setType $marker box"		}
    {	Circle		f.exec "m_setType $marker circle"	}
    {	Ellipse		f.exec "m_setType $marker ellipse"	}
    {	Polygon		f.exec "m_setType $marker polygon"	}
}

createMenu markerColor markerMenu {
    {	Color		f.title			}
    {			f.dblline		}
    {	""		f.exec "m_setColor $marker black"
			    bitmap solid foreground black }
    {	""		f.exec "m_setColor $marker white" 
			    bitmap solid foreground white }
    {	""		f.exec "m_setColor $marker red" 
			    bitmap solid foreground red }
    {	""		f.exec "m_setColor $marker green" 
			    bitmap solid foreground green }
    {	""		f.exec "m_setColor $marker blue" 
			    bitmap solid foreground blue }
    {	""		f.exec "m_setColor $marker magenta" 
			    bitmap solid foreground magenta }
    {	""		f.exec "m_setColor $marker cyan" 
			    bitmap solid foreground cyan }
    {	""		f.exec "m_setColor $marker yellow" 
			    bitmap solid foreground yellow }
}

proc m_setType {marker type}  {
    send $marker "markpos; set type $type; redraw"
}
proc m_setColor {marker color}  {
    send $marker "markpos;
	set lineColor $color;  set highlightColor $color; redraw"
}

# Callback executed when a marker gets or loses the focus.
proc selectMarker {active_marker event event_data} \
{
    global marker
    switch $event {
	focusIn		{ set marker $active_marker }
	focusOut	{  }
    }
}

# Create marker action.  Makes a new marker.
proc makeMarker {parent x y} \
{
    global markerTranslations markno
    set marker marker$markno;  incr markno

    send $parent createMarker $marker \
	type		rectangle \
	createMode	interactive \
	translations	$markerTranslations \
	x		$x \
	y		$y

    send $marker addCallback selectMarker focusIn focusOut
}


     
# WCSBOX -- Real time coordinate display.

set track_enable 	0
set last_x		0
set last_y		0

proc wcsUpdate {x y} \
{
    global track_enable frame pixtab_up tabTop
    global frameWidth frameHeight redraw_compass
    global ism_enable wcsLabels last_x last_y
    global ct_warn plotSpeed doHcut doVcut


    # If the cursor was frozen release it now.
    if {$ct_warn} {
	curtrack_destroy
    }

    # Convert screen coords to raster pixel.
    send imagewin unmapPixel $x $y raster rx ry rz

    # Set the current frame to the frame the pointer is within.
    if {$frame && $raster} {
	set track_frame [send client getFrame $raster]
	if {$frame != $track_frame} {
	    send client setFrame $track_frame
	}
    }

    # Update coords box.
    if {$raster} {
        set text [send client encodewcs $rx $ry $rz]
        scan $text "%g %g %g" nx ny nz
    } else {
        set text [format " %7.2f %7.2f %9.1f " $rx $ry $rz]
        set nx $rx ; set ny $ry ; set nz $rz
    }
	
    # Update the coords panel and pixel table.
    wcsFmtSValue $nz
    if {$pixtab_up} {
        updatePixelTable $x $y $nx $ny
    }

    # If the ISM is running update the coords box with all the selected
    # options, otherwise just write the one-line frame wcs coords.
    if {$ism_enable} {
        updateCoordsBox

    } else {
	# Update the on-screen marker.
        if {$track_enable} {
	    send wcsbox "set text \{$text\}; redraw noerase"
	}

	# Update the control panel readout (always done).
	if {$wcsLabels} {
	    set ln [format "   X: %12s     Y: %12s  WCS: Display" $nx $ny]
	} else {
	    set ln [format "      %12s        %12s       Display" $nx $ny]
	}
	send wtWcs1 set string $ln

	if {$redraw_compass} \
	    drawCompass
    }


    # Update the cut-plots if enabled.  If we're set for speed the don't 
    # track the really large cursor motions, wait till the differences are
    # small indicating a finer motion. 
    if {$doHcut || $doVcut} {
	set dist [ expr "sqrt(pow(($last_x - $x),2) + pow(($last_y - $y),2))" ]
	if {($plotSpeed && $dist < 30) || ! $plotSpeed} {
	    cutPlots $x $y
	}
    }

    # Save the position so we can track differences with last position.
    set last_x 	$x
    set last_y 	$y
}


proc setTrack {state} \
{
    global ism_enable track_enable wcsboxGeom
    global winWidth winHeight up_todo

    if {$state} {
	if {$track_enable} \
	    return

	send imagewin createMarker wcsbox {
	    type		text
	    createMode		noninteractive
	    width		27ch
	    height		1ch
	    lineWidth		0
	    imageText		true
	    textBgColor		black
	    textColor		yellow
	    visible		false
	}

	set box_width [send wcsbox get width]
	set box_height [send wcsbox get height]
	set defGeom [format "%sx%s-5-5" $box_width $box_height]
	send imagewin parseGeometry $wcsboxGeom $defGeom x y width height

	send wcsbox setAttributes    \
	    x			$x   \
	    y			$y   \
	    activated		true \
	    visible		true \
	    sensitive		true

	send wcsbox {
	    addCallback wcsboxDestroyCallback destroy
	    addCallback wcsboxMoved moveResize
	}

	send imagewin addCallback wcsboxWindowResize resize
	set track_enable 1
	send imagewin getCursorPos x y
	wcsUpdate $x $y
	magnifierMapImage $x $y

	# Turn on the option toggles on the control panel.
	foreach n {1 2 3 4} { 
	    if {[send sysWcs$n get label] != "None"} {
	        send wiWcs$n set on True
	    }
	}
	if {$ism_enable} {
	    resizeCoordsBox $up_todo
	}

    } elseif {$track_enable} {
	set track_enable 0
	send wcsbox destroy

	# Turn off the option toggles on the control panel.
	foreach w {wiWcs1 wiWcs2 wiWcs3 wiWcs4} { send $w set on False }
	resizeCoordsBox 0
    }
    updateCoordsBox
}

proc wcsboxDestroyCallback args \
{
    global track_enable
    send imagewin deleteCallback wcsboxWindowResize
    set track_enable 0
}

# If the window is resized make the wcsbox track the corner.
proc wcsboxWindowResize args \
{
    global track_enable
    global wcsboxGeom

    if {$track_enable} {
	# Get new location.
	set box_width [send wcsbox get width]
	set box_height [send wcsbox get height]
	set defGeom [format "%sx%s-5-5" $box_width $box_height]
	send imagewin parseGeometry $wcsboxGeom $defGeom x y width height

	# Move the marker.
	send wcsbox "\
	    deleteCallback wcsboxMoved; \
	    markpos; setAttributes x $x y $y; redraw; \
	    addCallback wcsboxMoved moveResize"
        set wcsboxGeom [send imagewin getGeometry $x $y $width $height]
    }
}

proc wcsboxMoved {marker event position} \
{
    global wcsboxGeom
    send wcsbox getRect boundary x y width height
    set wcsboxGeom [send imagewin getGeometry $x $y $width $height]
}

proc resetWcsbox {param old new} \
{
    global track_enable wcsboxGeom displayCoords
    if {$new == "done"} {
	setTrack [true $displayCoords]
    } elseif {$track_enable} {
	setTrack 0
	if {$new == "restart"} {
	    set wcsboxGeom -5-5
	}
    }
}; send initialize addCallback resetWcsbox



#---------------------
# FRAME BLINK.
#---------------------
set blinkId 0
set blinkIndex 0

proc toggleBlink args \
{
    global blinkId blinkRate blinkIndex
    global optionsMenuDescription

    if {$blinkId} {
	deleteTimedCallback $blinkId
	set blinkId 0
    } else {
	set blinkId [postTimedCallback blink [expr int($blinkRate * 1000)]]
    }

    set blinkIndex 0
    editMenu optionsMenu viewButton $optionsMenuDescription
}

proc blink args \
{
    global blinkId blinkRate blinkFrames blinkIndex

    send client setFrame [lindex $blinkFrames $blinkIndex]
    incr blinkIndex
    if {$blinkIndex >= [llength $blinkFrames]} {
	set blinkIndex 0
    }

    set blinkId [postTimedCallback blink [expr int($blinkRate * 1000)]]
}

proc resetBlink args \
{
    global blinkId
    if {$blinkId} \
	toggleBlink
}; send initialize addCallback resetBlink



# Normalize -- Reset the view parameters for the current frame.
proc normalize args \
{
    global zoomindex zoomfactor
    global frameWidth frameHeight
    global xcen ycen frame

    #set zoomindex($frame) 0
    #set xcen [expr $frameWidth / 2]
    #set ycen [expr $frameHeight / 2]
    #send client zoom 1 1 $xcen $ycen
    send client updateColormap 0.5 1.0
}


# Popdown menus.
createMenu fileMenu fileButton {
    {	"Info"		f.exec { panelTabToggle info_panel 	} }
    {	"Load"		f.exec {
			    panelTabToggle load_panel
	    		    set panel_up 1
			}					  }
    {	"Save"		f.exec { Save 				} }
    {	"Save As..."	f.exec { panelTabToggle save_panel 	} }
    {	"Print"		f.exec { 
			    send imagewin setCursorType busy
			    Print
			    send imagewin setCursorType idle
			}					  }
    {	"Print Setup"	f.exec { panelTabToggle print_panel 	} }
    {			f.dblline				  }
    {	"Reset"		f.exec {
			    # Do a hard reset.
			    send client Reset
			    #resetView initialize done done
			}					  }
    {	"Debug Panel"	f.exec { tclPanel 1			} }
    {	"Quit"		f.exec { Quit				} }
}

createMenu viewMenu viewButton {
    {	"Next frame"	f.exec nextFrame		}
    {	"Prev frame"	f.exec prevFrame		}
    {			f.dblline			}
    {	"Colormap"	f.menu cmapMenu			}
    {	"Flip"		f.menu flipMenu			}
    {			f.dblline			}
    {	"Equal aspect"	f.exec {
			    set xmag $frameZoomX($frame)
			    set ymag $frameZoomY($frame)
			    set zoom [expr ($xmag + $ymag) / 2.0]
			    cpZoom $zoom $zoom fixed
			}				}
    {	"Integer zoom"	f.exec {
			    set xmag [expr round ($frameZoomX($frame))]
			    set ymag [expr round ($frameZoomY($frame))]
			    cpZoom $xmag $ymag fixed
			}				}
    {	"Toggle zoom"	f.exec toggleZoom		}
    {	"Unzoom"	f.exec {
			    set zoomindex($frame) 0
			    set mag $zoomfactor($zoomindex($frame))
			    send client zoom $mag $mag $xcen $ycen
			}				}
}

createMenu cmapMenu viewMenu {
    {	"Normalize"	f.exec normalize	}
    {	"Invert"	f.exec cpInvert		}
    {	"Optimize"	f.exec cpOptimize	sensitive false }
    {			f.dblline		}
    {	"Grayscale"	f.exec "send client setColormap Grayscale" }
    {	"Color"		f.exec "send client setColormap Color" }
    {	"Heat"		f.exec "send client setColormap Heat" }
    {	"HSV"		f.exec "send client setColormap HSV" }
    {	"AIPS0"		f.exec "send client setColormap AIPS0" }
    {	"Halley"	f.exec "send client setColormap Halley" }
    {	"Ramp"		f.exec "send client setColormap Ramp" }
    {	"Standard"	f.exec "send client setColormap Standard" }
    {	"Staircase"	f.exec "send client setColormap Staircase" }
    {	"Rainbow1"	f.exec "send client setColormap Rainbow1" }
    {	"Rainbow2"	f.exec "send client setColormap Rainbow2" }
    {	"Random8"	f.exec "send client setColormap Random8" }
}

createMenu flipMenu viewMenu {
    {	"Flip X"	f.exec xflip		}
    {	"Flip Y"	f.exec yflip		}
    {	"Flip XY"	f.exec xyflip		}
}

set optionsMenuDescription {
    {	"Autoscale"	f.exec {
			    set value [send autoscaleButton get on]
			    send autoscaleButton set on [expr !$value]
			    cpSetAutoscale
			}			}
    {	"Antialias"	f.exec {
			    set value [send antialiasButton get on]
			    send antialiasButton set on [expr !$value]
			    cpSetAntialias
			}			}
    {	"Panner"	f.exec { setPanner [expr !$panner_enable] }	}
    {	"Magnifier"	f.exec { setMagnifier [expr !$magnifier_enable] }}
    {	"Coords box"	f.exec { setTrack [expr !$track_enable] }	}
    {	"Tile frames"	f.exec {
			    set value [send tileFramesButton get on]
			    send tileFramesButton set on [expr !$value]
			    cpSetTileFrames
			}			}
    {	"Clear frame"	f.exec clearFrame	}
    {	"Fit frame"	f.exec fitFrame		}
    {	"Match LUTs"	f.exec cpMatchFrames	}
    {	"Auto-Register"	f.exec cpAutoRegister	}
    {	"Register"	f.exec cpRegisterFrames	}
    {	{$blinkId ? "Stop blink" : "Blink frames"}
			f.exec toggleBlink	}
    {			f.dblline		}
    {   "Control Panel"	f.exec  { panelTabToggle display_panel	} }
    {   "Print Panel"	f.exec  { panelTabToggle print_panel	} }
    {   "Load Panel"	f.exec  { panelTabToggle load_panel	} }
    {   "Save Panel"	f.exec  { panelTabToggle save_panel	} }
}; createMenu optionsMenu optionsButton $optionsMenuDescription



#-------------------------------
# Frozen Cursor Warning Message
#-------------------------------

set ct_warn	0

proc curtrack_msg { x y args } \
{
    global ct_warn last_x last_y winHeight winWidth


    if {! $ct_warn == 0} {
	return
    }
        
    send imagewin createMarker curtrack_warn {
        type                text
        createMode          noninteractive
        width               25ch
        height              21
        lineWidth           0
        imageText           true
        textBgColor         red
        textColor           yellow
        visible             true
        sensitive           true
        activated           true
	x		    5
	y		    5
    }

    send curtrack_warn "set text \{  CURSOR READOUT FROZEN  \}"
    set ypos [ expr ($winHeight - 25) ]
    send curtrack_warn "markpos; setAttributes x 5 y $ypos; redraw"
    send curtrack_warn "redraw noerase"
    set ct_warn 1

    # Mark the position of the cursor.
    send imagewin createMarker x_curpos \
        type            box \
        createMode      noninteractive \
        lineColor       red \
        x               1 \
        y               $last_y \
        width           $winWidth \
        height          1 \
        activated       True \
        visible         True \
        sensitive       False

    send imagewin createMarker y_curpos \
        type            box \
        createMode      noninteractive \
        lineColor       red \
        x               $last_x \
        y               1 \
        width           1 \
        height          $winHeight \
        activated       True \
        visible         True \
        sensitive       False

    # Raise the coordinate marker so we can see where we are.
    send wcsbox raise
}


proc curtrack_destroy args \
{
    global ct_warn

    if {$ct_warn} {
	send curtrack_warn destroy
	send x_curpos destroy
	send y_curpos destroy
	set ct_warn 0
    }
}


################################################################################
# CURSOR CENTEROID AND AUTO-REGISTER FUNCTIONS.
################################################################################

# Set the centroiding box size.
set ctid	0
set cid		0

proc cbxDestroy args \
{
    global centerBoxSize cid ctid
    catch { 
	if {$ctid != 0} {
	    send cbm$cid destroy 
	    deleteTimedCallback $ctid
	    set ctid 0
	}
    }
}

proc setCtrBoxSize { x y delta args } \
{
    global centerBoxSize cid ctid
    global cpXscale cpYscale

    incr centerBoxSize $delta
    if {$centerBoxSize <= 1} { set centerBoxSize 1 }

    # Kill off any old markers before drawing the new one.
    catch { 
	if {$ctid != 0} {
	    send cbm$cid destroy 
	    deleteTimedCallback $ctid
	    set ctid 0
	}
    }

    # create a transient marker indicating the centering box and post a
    # callback to delete it in about a second.
    incr cid
    send imagewin createMarker cbm$cid \
	type            box \
	createMode      noninteractive \
	lineColor       red \
	x               $x \
	y               $y \
	width           [expr $cpXscale * $centerBoxSize] \
	height          [expr $cpXscale * $centerBoxSize] \
	activated       True \
	visible         True \
	sensitive       False

    set ctid [ postTimedCallback cbxDestroy 500]
}


# Box size is half-width of the marker size.  Value is the slider value.
set focusBoxSize	$winWidth			
set focusValue	       100.0
set fid			 0
set ftid		 0
set moving		 0

proc setFocusBoxSize { sz args } \
{
    global focusBoxSize fid ftid focusValue moving
    global winWidth winHeight


    if { $moving == 0 } {
        return done
    }

    if { $winWidth < $winHeight } {
	set max [expr $winWidth / 2 - 64]
    } else {
	set max [expr $winHeight / 2 - 64]
    }
    set focusBoxSize [expr 64 + ($sz * $max) - 1]
    #send client setOption cmfocus [expr ($focusBoxSize / 2)]
    send client setOption cmfocus $focusBoxSize

    # Destroy any existing markers.
    catch { 
        if {$ftid != 0} {
            send fm$fid destroy 
            set ftid 0
	}
    }

    # create a transient marker indicating the centering box and post a
    # callback to delete it in about a second.
    incr fid
    send imagewin createMarker fm$fid \
	type            box \
	createMode      noninteractive \
	lineColor       green \
	lineWidth       4 \
	x               [expr $winWidth / 2] \
	y               [expr $winHeight / 2] \
	width           $focusBoxSize \
	height          $focusBoxSize \
	activated       True \
	visible         True \
	sensitive       False

    set ftid [ postTimedCallback fbxDestroy 500]
    set moving  0
}

proc fbxDestroy args \
{
    global fid ftid moving
    catch { 
        if {$ftid != 0} {
            send fm$fid destroy 
            set ftid 0
        }
    }
}

proc setFocusSize { widget cbtype x y } \
{
    global focusValue ftid moving

    # Only update once we've stopped the movement.
    if { $x == $focusValue && $moving == 1 } {
	set ftid [ postWorkProc setFocusBoxSize $x ]
    } else {
        set moving  1
    }
    set focusValue $x
} ; send focusSlider addCallback setFocusSize scroll


# Compute a centroid offset for the current position to peak-up on the
# feature.

proc centroid { x y type args } \
{
    global centerBoxSize
    global cpXscale cpYscale

    # Convert to image coords.
    set sz [expr "int ($centerBoxSize * $cpXscale)"]

    # Get the centroid position.
    if {$type != "min"} {
        if {[send peakupButton get on]} {
            set center [ send client centroid $x $y $sz ]
        } else {
            set center [ send client centroid $x $y $sz max ]
        }
    } else {
        set center [ send client centroid $x $y $sz min ]
    }

    # Now reposition the cursor.
    set xoff [lindex $center 0 ]
    set yoff [lindex $center 1 ]
    move_cursor $xoff $yoff
}


# Set the auto-register center offset position
proc offset { x y args } \
{
    global frame blinkFrames auto_reg
    global frameCenterX frameCenterY
    global frameOffsetX frameOffsetY

    # No-op of auto-register isn't on.
    if { $auto_reg == 0 } {
	Wexec client "Auto-Register is not enabled!"
	return
    }

    # If we're not in the blink frames list ignore the request.
    if { [string first $frame $blinkFrames] == -1 } {
	Wexec client "Frame not in current\nregister list."
	return
    }

    set rx $x;  set ry $y
    set raster 0

    # Convert raw screen coordinates to frame buffer raster coordinates.
    send imagewin unmapPixel $x $y raster rx ry

    # Select a pixel.
    set xoff  [expr "int ($rx) - $frameCenterX($frame)" ]
    set yoff  [expr "int ($ry) - $frameCenterY($frame)" ]

    set frameOffsetX($frame)  $xoff
    set frameOffsetY($frame)  $yoff

    # Adjust the display.
    send client setOffset $xoff $yoff
}



################################################################################
# MAIN CONTROL PANEL
################################################################################


# Global control panel buttons.
# -------------------------------
proc cpInitialize args \
{
    send imagewin setCursorType busy
    send client initialize
    send imagewin setCursorType idle
}
send initializeButton 	addCallback cpInitialize
send normalizeButton 	addCallback normalize

# Temporarily deactivate some buttons.
send optimizeButton setSensitive false

#-----------------------------------------------------------------------------

foreach i $frames {set saveView($i) "1 1"}

send prevFrame 		set bitmap larrow
send nextFrame 		set bitmap rarrow
send contrastLabel	set bitmap contrast
send brightnessLabel	set bitmap brightness
send contrastSlider	resizeThumb 0.1 1.0
send brightnessSlider	resizeThumb 0.1 1.0
send focusSlider	"resizeThumb 0.1 1.0 ; moveThumb 1.0"


# panel -- Toggle control panel display.
proc panel args \
{
    global panel_up
    if {$panel_up} {
	send panelShell unmap
	set panel_up 0
    } else {
	send panelShell map
	set panel_up 1
    }
}

proc pbTracePanel {name element op} \
{
    catch {
        upvar $name panel_up
        send controlButton set state $panel_up
    }
} ; trace variable panel_up w pbTracePanel


# resetPanel -- Calling during startup or in an initialize, to reset things.
proc resetPanel {param old new} \
{
    global frame nframes frames
    global displayPanner displayMagnifier displayCoords
    global blinkFrames warnings peakCentroid

    switch $new {
    startup	{
		}
    restart	{   foreach i $frames {
			send frame$frame set on 0
		    }

		    # Initialize to hide the extra frames.
		    send frlistBox set width 30
		}
    done	{   if {$frame} {
			send frame$frame set on 1
		    }

		    cpResetBlink
		    set button 1
		    foreach i {1 2 3 4} {
			send blinkFrame$button set label $i
			incr button
		    }
		    for {set i 1} {$i <= 16} {incr i} {
			send brFrame$i set label $i
		    }

		    cpResetEnhance
		    send pannerButton set on [true $displayPanner]
		    send magnifierButton set on [true $displayMagnifier]
		    send coordsBoxButton set on [true $displayCoords]
		    send warningsButton set on $warnings
		    send peakupButton set on [true $peakCentroid]
		}
    }
}; send initialize addCallback resetPanel



#  Control Panel Tabs widget procedures.
#----------------------------------------

set cpTabs   { display_panel print_panel load_panel save_panel \
	       info_panel wcs_panel tile_panel}
set tabTop   "display_panel"


# Resize the control panel depending on the Tab selected.
proc cpResizeCB { widget event a b c d e args } \
{
    global tabTop fileList

    # Handle only the first exposure event generated.
    if { $a == 0 && $b == 0 && $c == 0 && $d == 0 && $e == 0 } {
	set tabTop $widget

	switch $widget {
	display_panel   { send panel set height 595 }
	print_panel     { send panel set height 545 }
	load_panel      { send panel set height 485 
			  if { [send browseHdrs get on] } {
			      send imageList setList $fileList resize
			  } else {
        		      send client setLoadOption rescan
			  }
        		}
	save_panel      { send panel set height 325 }
	info_panel      { send panel set height 380 }
	tile_panel      { send panel set height 405 }
	wcs_panel       { setCoordPanelHeight	    }
	}
    }
} ; foreach w $cpTabs {  send $w addEventHandler cpResizeCB exposureMask }


proc panelDismiss args \
{
    global panel_up
    send panelShell unmap
    set panel_up 0
} ; send panelClose addCallback panelDismiss


proc panelTabToggle { panel args } \
{
    global tabTop panel_up TabToWidget

    if {$tabTop == $panel && $panel_up} {
	send panelShell unmap
	send $TabToWidget($panel) set state 0
	set panel_up 0

    } else {
        # Special cases for each panel.
        if {$panel == "load_panel"} {
            send client setLoadOption rescan
        }

        send panelTabs setTop $panel
        set tabTop $panel

        # Now fire it up if it's not already open.
        if {$panel_up == 0} {
	    send panelShell map
	    set panel_up 1
        }

    }
}

proc displayPanel args  { panelTabToggle display_panel }
proc infoPanel args     { panelTabToggle info_panel    }
proc loadPanel args     { panelTabToggle load_panel    }
proc savePanel args     { panelTabToggle save_panel    }
proc printPanel args    { panelTabToggle print_panel   }
proc tilePanel args     { panelTabToggle tile_panel    }
proc wcsPanel args      { panelTabToggle wcs_panel     }




# Frame selection.
# -------------------------------
proc cpSetFrame {widget args} \
{
    send $widget set on 0
    send client setFrame [send $widget get label]
}

proc cpFrameChanged {param old new} \
{
    global frameCache

    if {$old > 0} {
	send frame$old set on 0
    }
    if {$new > 0} {
	send frame$new set on 1
    }

    # The first time we request frame 5 or higher reset 
    # the extra frame buttons on the control panel to make
    # them visible.
    if {$new >= 5} {
	send frlistBox set width 49
    }

    # Update the header panel object list.
    catch {
	# Only update when the header panel is open.
        if {[info exists frameCache($new)] && [send imageHeader get on]} {
            setHdrObjMenu $new
            getHeader [lindex $frameCache($new) 0] [lindex $frameCache($new) 1]
        }
    }
}

send prevFrame addCallback prevFrame
send nextFrame addCallback nextFrame
send frame addCallback cpFrameChanged
for {set i 1} {$i <= 16} {incr i} {send frame$i addCallback cpSetFrame}

# Initialize to hide the extra frames.
send frlistBox  set width 30

proc blinkPanelCB { widget type state args } \
{
    if {$state} {
	send blink_panel map
    } else {
	send blink_panel unmap
    }
} ; send blinkPanel addCallback blinkPanelCB

proc blinkPanelClose args \
{
    send blink_panel unmap
    send blinkPanel set state 0
} ; send brClose addCallback blinkPanelClose



# Frame buttons.
proc cpFrameAction {widget args} \
{
    global frameZoomX frameZoomY frame
    switch $widget {
    aspect	{   set xmag $frameZoomX($frame)
		    set ymag $frameZoomY($frame)
		    set zoom [expr round (($xmag + $ymag) / 2.0)]
		    cpZoom $zoom $zoom fixed
		}
    flipX	{   send client flip x }
    flipY	{   send client flip y }
    flipXY	{   send client flip x y }
    clearFrame	{   clearFrame }
    fitFrame	{   fitFrame }
    }
}
foreach widget {aspect flipX flipY flipXY clearFrame fitFrame} {
    send $widget addCallback cpFrameAction
}

# clearFrame -- Clear the current display frame.
proc clearFrame	args \
{
    global warnings
    if {$warnings} {
	Wexec client \
	    "Clearing the frame will destroy\n\
	    all data in the frame" \
	    clearFrame
    } else {
	send client clearFrame
    }
}

# fitFrame -- Resize the display window to fit the frame buffer.
proc fitFrame args \
{
    global frameWidth frameHeight winWidth winHeight
    set dw [expr [send display get width] - $winWidth]
    set dh [expr [send display get height] - $winHeight]
    send display "resize [expr $frameWidth + $dw] [expr $frameHeight + $dh]"
}

proc initFitFrame { param old new } \
{
    if { [lindex $new 0] == "resize"} {
	fitFrame
    }
    pannerMapImage init
}; send frameFit addCallback initFitFrame



# Zoom and pan buttons.
# -------------------------------
proc cpZoomAction {widget args} \
{
    global frameWidth frameHeight

    switch $widget {
    x1		{   cpZoom 1 1 fixed }
    z2		{   cpZoom 2 2 fixed }
    z3		{   cpZoom 3 3 fixed }
    z4		{   cpZoom 4 4 fixed }
    z5		{   cpZoom 5 5 fixed }
    z8		{   cpZoom 8 8 fixed }

    d2		{   cpZoom [expr 1.0/2] [expr 1.0/2] fixed }
    d3		{   cpZoom [expr 1.0/3] [expr 1.0/3] fixed }
    d4		{   cpZoom [expr 1.0/4] [expr 1.0/4] fixed }
    d5		{   cpZoom [expr 1.0/5] [expr 1.0/5] fixed }
    d8		{   cpZoom [expr 1.0/8] [expr 1.0/8] fixed }

    zoomIn	{   cpZoom 2.0 2.0 relative }
    zoomOut	{   cpZoom 0.5 0.5 relative }

    centerFrame	{   send client pan \
			[expr $frameWidth/2.0] \
			[expr $frameHeight/2.0]
		}
    toggleZoom	{   toggleZoom }
    }
}

proc cpZoom {zoom_x zoom_y mode} \
{
    global frameZoomX frameZoomY zoomindex frame
    global frameOffsetX frameOffsetY frameCenterX frameCenterY

    if {$mode == "fixed"} {
	#send client zoom $zoom_x $zoom_y
	send client zoomAbs $zoom_x $zoom_y \
	    $frameCenterX($frame) $frameCenterY($frame) \
	    $frameOffsetX($frame) $frameOffsetY($frame)
    } else {
	#send client zoom \
	#    [expr $frameZoomX($frame) * $zoom_x] \
	#    [expr $frameZoomY($frame) * $zoom_y]
	send client zoomAbs \
	    [expr $frameZoomX($frame) * $zoom_x] \
	    [expr $frameZoomY($frame) * $zoom_y] \
	    $frameCenterX($frame) $frameCenterY($frame) \
	    $frameOffsetX($frame) $frameOffsetY($frame)
    }

    set zoomindex($frame) 0
}

proc toggleZoom	args \
{
    global frameZoomX frameZoomY frameCenterX frameCenterY
    global frameWidth frameHeight saveView frame

    if {$frameZoomX($frame) != 1 && $frameZoomY($frame) != 1} {
	set saveView($frame) \
	    "$frameZoomX($frame) $frameZoomY($frame) \
	     $frameCenterX($frame) $frameCenterY($frame)"
	send client zoom 1 1 \
	    [expr $frameWidth/2.0] \
	    [expr $frameHeight/2.0]
    } else {
	send client zoom $saveView($frame)
    }
}

foreach widget { toggleZoom centerFrame zoomIn zoomOut \
	x1  z2 z3 z4 z5 z8  d2 d3 d4 d5 d8  } {
    send $widget addCallback cpZoomAction
}

# Frame data display.
# -------------------------------
set cpFrame  0
set cpXcen   0
set cpYcen   0
set cpXmag   0
set cpYmag   0
set cpXscale 0
set cpYscale 0
set cpXoff   0
set cpYoff   0

proc cpDisplayFrameData {name old new} \
{
    global cpFrame cpXcen cpYcen cpXoff cpYoff
    global cpXmag cpYmag cpXscale cpYscale

    set update 0
    switch $name {
    frame	{   if {$new != $cpFrame} {
			set cpFrame $new
			set update 1
		    }
		}
    frameView	{   # Parse the frameView input.
		    set xmag  [lindex $new 0]; set ymag  [lindex $new 1]
		    set xcen  [lindex $new 2]; set ycen  [lindex $new 3]
		    set xnorm [lindex $new 4]; set ynorm [lindex $new 5]
		    set xoff  [lindex $new 6]; set yoff  [lindex $new 7]

		    # We need client coords and the overall scale factors.
		    set text [send client encodewcs $xcen $ycen]
		    set xcen [lindex $text 0]
		    set ycen [lindex $text 1]
		    set xscale [expr $xmag * $xnorm]
		    set yscale [expr $ymag * $ynorm]

		    if {$xcen != $cpXcen || $ycen != $cpYcen ||
			$xmag != $cpXmag || $ymag != $cpYmag ||
			$xoff != $cpXoff || $yoff != $cpYoff ||
			$xscale != $cpXscale || $yscale != $cpYscale} {

			    set cpXcen $xcen;  set cpXscale $xscale
			    set cpYcen $ycen;  set cpYscale $yscale
			    set cpXmag $xmag;  set cpXoff   $xoff;  
			    set cpYmag $ymag;  set cpYoff   $yoff;
			    set update 1
		    }
		}
    }

    if {$update} {
	set header [format "-- Frame %d --" $cpFrame]
	set center [format "X center: %0.1f\nY center: %0.1f" $cpXcen $cpYcen]
	if {int($cpXmag) >= 10} {
	    set zoom1 [format " X zoom: %0.1f" $cpXmag]
	    set zoom2 [format " Y zoom: %0.1f" $cpYmag]
	} else {
	    set zoom1 [format "X zoom: %0.1f" $cpXmag]
	    set zoom2 [format "Y zoom: %0.1f" $cpYmag]
	}
	if {int($cpXscale) >= 10} {
	    set scale1 [format "X scale: %0.1f" $cpXscale]
	    set scale2 [format "Y scale: %0.1f" $cpYscale]
	} else {
	    set scale1 [format "X scale: %0.2f" $cpXscale]
	    set scale2 [format "Y scale: %0.2f" $cpYscale]
	}
	set offset [format "  Offset: (%0.1f,%0.1f)" $cpXoff $cpYoff]

	send frameData set label [format "%s\n%s\n%s\n%s\n%s\n%s\n%s" \
	    $header $center $scale1 $scale2 $zoom1 $zoom2 $offset \
	]
    }
}; foreach p {frame frameView} {send $p addCallback cpDisplayFrameData}


# Frame enhancement.
# -------------------------------
set cpEnhanceDisable 0
set cpEnhanceId 0
set cpEnhanceMode none
set cpEnhanceVal 0
set cpListItem none

# Windowing the colormap is slow when the mouse is not in the image window,
# so it is necessary to execute the windowColormap in a work procedure.
# This allows any number of slider motion events to be processed for each
# windowColormap, preventing slider events from queueing up.

proc cpResetEnhance args \
{
    global cpListItem cpEnhanceId
    set cpListItem none
    set cpEnhanceId 0
}

proc cpSetEnhancement {widget cbtype x y} \
{
    global cpEnhanceMode cpEnhanceVal cpEnhanceId cpEnhanceDisable
    set cpEnhanceMode $widget
    set cpEnhanceVal $x
    if {!$cpEnhanceId && !$cpEnhanceDisable} {
	set cpEnhanceId [postWorkProc cpEnhanceProc]
    }
}
proc cpEnhanceProc args \
{
    global cpEnhanceMode cpEnhanceVal cpEnhanceId
    global enhancement frame maxContrast
    set val $cpEnhanceVal

    if {$cpEnhanceMode == "contrastSlider"} {
	set contrast [lindex $enhancement($frame) 2]
	send client windowColormap [lindex $enhancement($frame) 1] \
	    [expr (($contrast < 0) ? -$val : $val) * $maxContrast] 
    } else {
	send client windowColormap $val
    }

    set cpEnhanceId 0
    return done
}

proc cpInvert args \
{
    global enhancement frame
    set contrast [lindex $enhancement($frame) 2]
    send client updateColormap [lindex $enhancement($frame) 1] \
	[expr -1.0 * $contrast]
}

proc cpDisplayEnhancement {param old new} \
{
    global cpEnhanceId maxContrast cpEnhanceDisable
    global cpListItem enhancement frame

    if {!$frame} \
	return
    set enhance $enhancement($frame)
    if {[llength $enhance] < 3} \
	return

    set colortable [lindex $enhance 0]
    set offset     [lindex $enhance 1]
    set scale      [lindex $enhance 2]

    send colordata set label [format "-- %s --\nCon %0.2f  Brt %0.2f" \
	$colortable $scale $offset]

    if {$colortable != $cpListItem} {
	send colorlist highlight $colortable
	set cpListItem $colortable
    }

    if {!$cpEnhanceId && !$cpEnhanceDisable} {
	set cpEnhanceDisable 1
	send contrastSlider moveThumb [expr abs($scale) / $maxContrast]
	send brightnessSlider moveThumb $offset
	set cpEnhanceDisable 0
    }
}

foreach i {enhancement frame} {
    send $i addCallback cpDisplayEnhancement
}
send contrastSlider addCallback cpSetEnhancement scroll
send brightnessSlider addCallback cpSetEnhancement scroll
send invertButton addCallback cpInvert


# Colortable display and selection.
# -------------------------------
set colorTables	   {}

proc cpSetColorList {param old new} \
{
    set colorTables $new
    send colorlist setList $new resize
}; send colortables addCallback cpSetColorList

proc colorlistResize args \
{
    global colorTables
    send colorlist setList $colorTables resize
}; send colorlist addEventHandler colorlistResize ResizeRedirectMask

proc cpSelectColor {widget cbtype selections indices} \
{
    global colortable
    foreach selection $selections {
	send client setColormap $selection
    }
}; send colorlist addCallback cpSelectColor
    

# Frame blink.
# -------------------------------
send BRtext   set label $blinkRate
send brBRtext set label $blinkRate

proc cpSetBlinkRate {w args} \
{
    global blinkRate
    if {$w == "BRincrease" || $w == "brBRincrease"} {
	if {$blinkRate < 0.01} {
	    set blinkRate 0.125
	} else {
	    set blinkRate [expr $blinkRate * 2.0]
	}
    } else {
	set blinkRate [expr $blinkRate / 2.0]
	if {$blinkRate < 0.01} {
	    set blinkRate 0
	}
    }
    send BRtext   set label $blinkRate
    send brBRtext set label $blinkRate
}
foreach w {BRincrease BRdecrease brBRincrease brBRdecrease} {
    send $w addCallback cpSetBlinkRate
}

proc cpSetBlinkFrame {widget args} \
{
    global blinkFrames frames nframes

    set frame [send $widget get label]
    if {$frame == " "} {
	set frame 1
    } else {
	incr frame
	if {$frame > $nframes} {
	    set frame " "
	}
    }
    send $widget set label $frame

    set blinkFrames {}
    foreach i {1 2 3 4} {
	set frame [send blinkFrame$i get label]
	if {$frame != " "} {
	    lappend blinkFrames $frame
	}
    }
}; foreach i {1 2 3 4} {send blinkFrame$i addCallback cpSetBlinkFrame}

proc cpBlink {widget args} \
{
    global blinkRate blinkId

    if {$blinkRate < 0.01} {
	send blinkButton set on False
	send brBlinkButton set on False
	blink
    } elseif {($blinkId != 0) != [send $widget get on]} {
	toggleBlink
    }
} ; foreach w {blinkButton brBlinkButton} {send $w addCallback cpBlink}


proc cpAutoRegister {widget type state args} \
{
    global auto_reg frame frames blinkFrames
    global frameZoomX frameZoomY frameOffsetX frameOffsetY

    set auto_reg $state
    if {$auto_reg == 1} {
	send autoregButton set on True
	send brAregButton set on True
    } else {
	send autoregButton set on False
	send brAregButton set on False
    }

    # Register the frames to zero the offsets.
    send client registerFrames \{$blinkFrames\}
    foreach f $frames {
	set frameOffsetX($f) 0
	set frameOffsetY($f) 0
    }
} ; foreach w {autoregButton brAregButton} {send $w addCallback cpAutoRegister}


proc toggleAutoReg args \
{
    global auto_reg
    if {$auto_reg} {
	cpAutoRegister autoregButton dummy 0 
	set auto_reg 0
    } else {
	cpAutoRegister autoregButton dummy 1 
	set auto_reg 1
    }
}

proc resetAutoReg args \
{
    global auto_reg
    if {$auto_reg} \
	toggleAutoReg
}; send initialize addCallback resetAutoReg


proc cpResetBlink args \
{
    global blinkRate blinkFrames blinkIndex frames
    global defaultBlinkRate

    foreach i {1 2 3 4} {
	send blinkFrame$i set label " "
    }
    for {set i 1} {$i <= 16} {incr i} {
	send brFrame$i set label $i
    }
    set blinkRate $defaultBlinkRate
    send BRtext   set label $blinkRate
    send brBRtext set label $blinkRate
    set blinkIndex 0
} 
send blinkReset addCallback cpResetBlink
send brReset    addCallback cpResetBlink

proc cpTraceBlink {name element op} \
{
    upvar $name blinkId
    send blinkButton set on [expr $blinkId != 0]
    send brBlinkButton set on [expr $blinkId != 0]
}; trace variable blinkId w cpTraceBlink

proc cpSetBlinkFrames {param old new} \
{
    global blinkFrames frames

    set blinkFrames {}
    foreach i $frames {
	if {$i <= $new} {
	    lappend blinkFrames $i
	}
    }
    cpResetBlink
    set button 1
    for {set i 1} {$i <= $new} {incr i} {
	if {$i <= 4} {
	    send blinkFrame$button set label $i
	}
	send brFrame$button set label $i
	incr button
    }
}; send nframes addCallback cpSetBlinkFrames

proc cpRegisterFrames args \
{
    global frames blinkFrames
    global frameOffsetX frameOffsetY

    foreach f $frames {
	set frameOffsetX($f)  0
	set frameOffsetY($f)  0
    }
    send client registerFrames \{$blinkFrames\}
}
send registerButton addCallback cpRegisterFrames
send brRegButton    addCallback cpRegisterFrames

proc cpMatchFrames args \
{
    global blinkFrames
    send client matchFrames \{$blinkFrames\}
}
send matchButton   addCallback cpMatchFrames
send brMatchButton addCallback cpMatchFrames


# Options buttons.
# -------------------------------
proc cpSetPanner {widget args} \
{
    setPanner [send $widget get on]
}; send pannerButton addCallback cpSetPanner

proc cpTracePanner {name element op} \
{
    upvar $name panner_enable
    send pannerButton set on $panner_enable
}; trace variable panner_enable w cpTracePanner

proc cpSetMagnifier {widget args} \
{
    setMagnifier [send $widget get on]
}; send magnifierButton addCallback cpSetMagnifier

proc cpTraceMagnifier {name element op} \
{
    upvar $name magnifier_enable
    send magnifierButton set on $magnifier_enable
}; trace variable magnifier_enable w cpTraceMagnifier

proc cpSetCoordsBox {widget args} \
{
    setTrack [send $widget get on]
}; send coordsBoxButton addCallback cpSetCoordsBox

proc cpTraceCoordsBox {name element op} \
{
    upvar $name track_enable
    send coordsBoxButton set on $track_enable
}; trace variable track_enable w cpTraceCoordsBox

proc cpSetWarnings args \
{
    global warnings
    set warnings [send warningsButton get on]
}; send warningsButton addCallback cpSetWarnings

proc cpSetAutoscale args \
{
    set value [send autoscaleButton get on]
    send client setOption autoscale [expr {$value ? "True" : "False"}]
}; send autoscaleButton addCallback cpSetAutoscale

proc cpTrackAutoscale {param old new} \
{
    send autoscaleButton set on [true $new]
}; send autoscale addCallback cpTrackAutoscale

proc cpSetAntialias args \
{
    set value [send antialiasButton get on]
    send client setOption antialias [expr {$value ? "True" : "False"}]
}; send antialiasButton addCallback cpSetAntialias

proc cpTrackAntialias {param old new} \
{
    send antialiasButton set on [true $new]
}; send antialias addCallback cpTrackAntialias

proc cpSetTileFrames { widget type state args } \
{
    global tile_frames tileOpt

    set value [send tileFramesButton get on]
    if {$value} {
        selectTileOrientation junk junk [tileSelToLabel $tileOpt]
    } else {
        selectTileOrientation junk junk Disabled
    }
   send client setOption tileFrames \
	[expr {$value ? "True" : "False"}] \{ $tile_frames \}
} ; send tileFramesButton addCallback cpSetTileFrames

proc cpTrackTileFrames {param old new} \
{
    send tileFramesButton set on [true $new]
}; send tileFrames addCallback cpTrackTileFrames

proc tileFramesToggle args \
{
    set value [send tileFramesButton get on]
    send tileFramesButton set on [expr !$value]
    cpSetTileFrames
}


################################################################################
# MAGNIFIER.  A subraster around the cursor in the main image window is
# displayed at a high resolution in a marker (known as the magnifier window)
# within the main image window.
################################################################################

set magnifier_x 0
set magnifier_y 0
set magnifier_width 0
set magnifier_height 0
set mrm_width 0
set mrm_height 0

set magnifier_enable 0
set magnifier_mag_enable 0
set magnifier_mapping 0

createMenu magzoomMenu imagewin {
    {   "Zoom Factors"        	f.title                         }
    {                           f.dblline                       }
    {   "Zoom 1"                f.exec "setMagnifierZoom 1"     }
    {   "Zoom 2"                f.exec "setMagnifierZoom 2"     }
    {   "Zoom 4"                f.exec "setMagnifierZoom 4"     }
    {   "Zoom 8"                f.exec "setMagnifierZoom 8"     }
    {   "Zoom 16"               f.exec "setMagnifierZoom 16"    }
} 

# Magnifier window translations.
set magnifierWinTranslations { \
       !Shift <Btn1Motion>:	m_rotateResize()
	      <Btn1Motion>:	m_moveResize()
	 !Shift <Btn1Down>:	m_raise() m_markpos()
		<Btn1Down>:	m_raise() m_markposAdd()
		  <Btn1Up>:	m_redraw() m_destroyNull()
		<Btn2Down>:	m_lower()
		<Btn3Down>:     popup(magzoomMenu)
		  <Btn3Up>:     popdown(magzoomMenu)
	      !Ctrl <Key>m:     call(toggleMagnifier)
	      !Ctrl <Key>p:     call(togglePanner)
	    <Key>BackSpace:	m_deleteDestroy()
	       <Key>Delete:	m_deleteDestroy()
		<KeyPress>:     graphics-input()
		  <Motion>:	track-cursor() call(wcsUpdate,$x,$y)
}


# setMagnifier -- Turn the magnifier on or off.

set magAlreadyOn	0

proc setDynamicMagnifier {state} \
{
    global magAlreadyOn magnifier_enable

    if {$state} {
	set magAlreadyOn $magnifier_enable
    }
    if {$magAlreadyOn} {
	return
    } else {
	setMagnifier $state
    }
}

proc toggleMagnifier args \
{
    global magnifier_enable
    if {$magnifier_enable} {
	setMagnifier 0
    } else {
	setMagnifier 1
    }
}


proc setMagnifier {state} \
{
    global winWidth winHeight frameWidth frameHeight
    global frame magnifier_mapping magnifierWinTranslations magnifierArea
    global magnifier_enable magnifier_height
    global magnifierGeom magnifier_x magnifier_y magnifier_width

    if {$state} {
	if {$magnifier_enable} \
	    return

	# Determine where to place the magnifier.
	set scale  [expr sqrt(double($magnifierArea) / (512 * 512))]
	set scaled_width [expr int(512 * $scale) / 2 * 2 + 1]
	set scaled_height [expr int(512 * $scale) / 2 * 2 + 1]
	set defGeom [format "%sx%s-5+5" $scaled_width $scaled_height]
	send imagewin parseGeometry $magnifierGeom $defGeom x y width height

	# Create the main magnifier window (marker).
	send imagewin createMarker magnifierWin \
	    type		rectangle \
	    createMode		noninteractive \
	    width		[expr $width / 2] \
	    height		[expr $height / 2] \
	    x			[expr $x + $width / 2] \
	    y			[expr $y + $height / 2] \
	    lineColor		8 \
	    highlightColor	8 \
	    translations	$magnifierWinTranslations \
	    visible		true \
	    sensitive		true \
	    activated		true

	# Update the magnifier window position variables so that it comes up
	# in the same place the next time.

	send magnifierWin getRect boundary \
	    magnifier_x magnifier_y magnifier_width magnifier_height
	set magnifierGeom [send imagewin getGeometry \
	    $magnifier_x $magnifier_y $magnifier_width $magnifier_height]

	# Register callbacks.
	send imagewin addCallback magnifierImagewinResized resize
	send resize addCallback magnifierImagewinResized
	send magnifierWin addCallback magnifierMovedMapImage moveResize

	send magnifierWin {
	    addCallback magnifierMoved moveResize;
	    addCallback magnifierDestroy destroy;
	    addCallback magnifierWinConstraint constraint;
	}

	# Map display frame to magnifier window.
	set magnifier_enable 1
	set magnifier_mapping [send imagewin nextMapping]
	send imagewin refreshMapping $magnifier_mapping

	# create cross-hair
	send imagewin createMarker magPointer \
		type                rectangle \
		createMode          noninteractive \
		width               3 \
		height              3 \
		lineWidth           3 \
		lineColor           green \
		highlightcolor      green \
		activated           true \
		visible             true

	# set its position and size
	setMagPointerPosition 
	magnifierMapImage [expr $winWidth / 2] [expr $winHeight / 2]

    } elseif {$magnifier_enable} {
	magnifierDestroy
    }
}


# magnifierDestroy -- Delete the magnifier.

proc magnifierDestroy args \
{
    global magnifier_enable 
    global magnifier_mapping

    if {$magnifier_enable} {
	set magnifier_enable 0

	send imagewin freeMapping $magnifier_mapping
	send imagewin deleteCallback magnifierImagewinResized
	send resize deleteCallback magnifierImagewinResized
	send frame deleteCallback magnifierMapImage

	if [send server queryObject magnifierWin] {
	    send magnifierWin destroy
	}
	if [send server queryObject magPointer] {
	    send magPointer destroy
	}  
    }
}


# magnifierMoved -- Called when the user moves the magnifier window.  We need to
# move the region marker to the new window location and record the new location
# so that the window will come up in the same place if closed and reopened.

proc magnifierMoved {marker event position} \
{
    global winWidth winHeight magnifierGeom frame 
    global magnifier_x magnifier_y magnifier_width magnifier_height

    # Move the region marker to the new location.
    send client getSource raster sx sy snx sny

    # Update the magnifier window position variables so that it comes up
    # in the same place the next time.

    send magnifierWin getRect boundary \
	magnifier_x magnifier_y magnifier_width magnifier_height
    set magnifierGeom [send imagewin getGeometry \
	$magnifier_x $magnifier_y $magnifier_width $magnifier_height]
}


# magnifierWinConstraint -- Called when the magnifier window is moved, resized,
# or rotated. Constrain the magnifier window to remain within the image window;
# rotation is not permitted.

proc magnifierWinConstraint {marker event attributes} \
{
    global winWidth winHeight
    global magnifier_width magnifier_height

    set width $magnifier_width
    set height $magnifier_height
    set constraints [list {}]

    # Check the width and height first as we need these below.
    foreach i $attributes {
	set new [lindex $i 2]
	switch [lindex $i 0] {
	    width	{   set ww [expr $winWidth / 2]
			    if {$new > $ww} {
				lappend constraints "width $ww"
				set width $ww
			    } else {
				set width $new
			    }
			}
	    height	{   set wh [expr $winHeight / 2]
			    if {$new > $wh} {
				lappend constraints "height $wh"
				set height $wh
			    } else {
				set height $new
			    }
			}
	    rotangle	{    lappend constraints "rotangle 0"
			}
	}
    }

    # Constrain X and Y.
    foreach i $attributes {
	set new [lindex $i 2]
	switch [lindex $i 0] {
	    x		{   set pw [expr $width / 2]
			    if {$new < $pw} {
				lappend constraints "x $pw"
			    } elseif {$new > $winWidth - $pw} {
				lappend constraints "x [expr $winWidth - $pw]"
			    }
			}
	    y		{   set ph [expr $height / 2]
			    if {$new < $ph} {
				lappend constraints "y $ph"
			    } elseif {$new > $winHeight - $ph} {
				lappend constraints "y [expr $winHeight - $ph]"
			    }
			}
	}
    }

    return $constraints
}


# magnifierRegionConstraint -- Called when the region marker in the magnifier
# window is moved, resized, or rotated.

proc magnifierRegionConstraint {marker event attributes} \
{
    global winWidth winHeight

    set constraints [list {}]
    send magnifierWin getRect interior p_x p_y p_width p_height

    # Since the magnifier region marker is a box marker x,y and width,height
    # will not both change in the same call, so we can process them all
    # independently.

    foreach i $attributes {
	set new [lindex $i 2]

	switch [lindex $i 0] {
	    x		{   set left [expr $p_x + $rwidth + 1]
			    set right [expr $p_x + $p_width - $rwidth - 1]
			    if {$new < $left} {
				lappend constraints "x $left"
			    } elseif {$new > $right} {
				lappend constraints "x $right"
			    }
			}
	    y		{   set top [expr $p_y + $rheight + 1]
			    set bottom [expr $p_y + $p_height - $rheight - 1]
			    if {$new < $top} {
				lappend constraints "y $top"
			    } elseif {$new > $bottom} {
				lappend constraints "y $bottom"
			    }
			}
	    width	{   set ww [expr $winWidth / 2]
			    if {$new > $ww / 2} {
				lappend constraints "width $ww"
			    }
			}
	    height	{   set wh [expr $winHeight / 2]
			    if {$new > $wh / 2} {
				lappend constraints "height $wh"
			    }
			}
	    rotangle	{    lappend constraints "rotangle 0"
			}
	}
    }

    return $constraints
}


# magnifierImagewinResized -- If the display window is resized make the
# magnifier track the corner.

proc magnifierImagewinResized args \
{
    global magnifier_enable magnifier_mapping magnifier_height
    global magnifierGeom magnifier_x magnifier_y magnifier_width

    if {$magnifier_enable} {
	set old_x $magnifier_x;  set old_width $magnifier_width
	set old_y $magnifier_y;  set old_height $magnifier_height

	# Get new location of magnifier window.
	set defGeom [format "%sx%s+5+5" $magnifier_width $magnifier_height]
	send imagewin parseGeometry $magnifierGeom $defGeom x y width height

	# Reposition the marker.
	send magnifierWin "\
	    markpos; \
	    setAttributes \
		x		[expr $x + $width / 2] \
		y		[expr $y + $height / 2] \
		width		[expr $width / 2] \
		height		[expr $height / 2]; \
	    redraw"

	# Update the magnifier window position variables so that it comes up
	# in the same place the next time.
	send magnifierWin getRect boundary \
	    magnifier_x magnifier_y magnifier_width magnifier_height
	set magnifierGeom [send imagewin getGeometry \
	    $magnifier_x $magnifier_y $magnifier_width $magnifier_height]

	# Make sure the magnifier window is on top.
	send imagewin raiseMapping $magnifier_mapping

	# Refresh the magnifier window if it did not move.
	if {$magnifier_x == $old_x && $magnifier_y == $old_y &&
	    $magnifier_width == $old_width && $magnifier_height == $old_height} {
	    send imagewin refreshMapping $magnifier_mapping
	}
    }
}


# resetMagnifier -- Reinitialize the magnifier.

proc resetMagnifier {param old new} \
{
    global magnifierGeom displayMagnifier

    if {$new == "done"} {
	setMagnifier [true $displayMagnifier]
    } else {
	setMagnifier 0
	if {$new != "startup"} {
	    set magnifierGeom +5+5
	}
    }
}; send initialize addCallback resetMagnifier


set last_mag_x [expr $winWidth / 2]
set last_mag_y [expr $winHeight / 2]

# magnifierMovedMapImage -- Front end to magnifierMapImage, called when 
# magnifier window is moved or resized.

proc magnifierMovedMapImage args \
{
    global last_mag_x last_mag_y

    magnifierMapImage $last_mag_x $last_mag_y
    setMagPointerPosition
}

# The following code was borrowed from the SAOtng GUI by Eric Mandel of SAO
#--------------------------------------------------------------------------

# globals for magnifier
set mag_w 0
set mag_h 0

#
# setMagnifierZoom -- set the zoom factor for the magnifier
#
proc setMagnifierZoom { zoom } \
{
    global mag_w mag_h

    send magnifierWin getRect boundary \
		magnifier_x magnifier_y magnifier_width magnifier_height
    set mag_w [expr int( ( $magnifier_width  + $zoom - 1 ) / $zoom) ]
    set mag_h [expr int( ( $magnifier_height + $zoom - 1 ) / $zoom) ]

    #set mw [expr int (($magnifier_width - 1) / ($mag_w * 2))]
    #if { $mw < 4 } { set mw 4 }
    #set mh [expr int (($magnifier_height - 1) / ($mag_h * 2))]
    #if { $mh < 4 } { set mh 4 }
    #send magPointer "setAttributes width $mw height $mh; redraw"
}

# magnifierMapImage -- Map the of the current display frame centered on the
# pointer into the magnifier window.  Called when the frame changes, the
# pointer moves in the main image window, or (via magnifierMovedMapImage)
# the magnifier window is moved or resized.

set magnifierROP 0

proc magnifierMapImage {x y} \
{
    global magnifier_enable frame
    global last_mag_x last_mag_y
    global magnifier_mapping
    global winWidth winHeight
    global mag_w mag_h
    global magnifierROP

    if {!$magnifier_enable || $frame == 0} \
	return

#    if {abs($last_mag_x-$x) != 1 && abs($last_mag_y-$y) != 1} {
#	# For efficiency we won't compute the sqrt of the distance but instead
#	# just compare the square.  Use a threshold of 6 pixels so when we
#	# narrow in on the ROI the magnifier is still (mostly) correct.
#        set diff  [expr (($last_mag_x-$x) * ($last_mag_x-$x)) + \
#			(($last_mag_y-$y) * ($last_mag_y-$y))]
#        if {$diff > 36} {
#    	    set last_mag_x $x
#    	    set last_mag_y $y
#	    return
#  	}
#    }

    set last_mag_x $x
    set last_mag_y $y

    send magnifierWin getRect interior dx dy dnx dny
    if [send imagewin activeMapping $magnifier_mapping] {
	send imagewin raiseMapping $magnifier_mapping
    }

    # initialize the magnifier zoom factor, if necessary
    if { !$mag_w || !$mag_h } {
	setMagnifierZoom 4
    }

    set sx [expr $x - $mag_w / 2 ]
    set sy [expr $y - $mag_h / 2 ]

    # Constrain the source rectangle within the main image window 
    # (not overlapping an edge or the magnifier window).

    if {$sx > [expr $dx - $mag_w] && $sx < [expr $dx + $dnx] && 
	$sy > [expr $dy - $mag_h] && $sy < [expr $dy + $dny]    } {

	# The source rectangle would overlap the magnifier window; fix that.

	set dist(l) [expr $sx - ($dx - $mag_w)]
	set dist(b) [expr $dy + $dny - $sy]
	set dist(r) [expr $dx + $dnx - $sx]
	set dist(t) [expr $sy - ($dy - $mag_h)]

	#  Put the distances in order.

	foreach j [array names dist] {
	    set alreadyset($j) 0
	}

	for {set i 0} {$i < 4} {incr i} {
	    set candidate ""
	    foreach j [array names dist] {
		if {!$alreadyset($j)} {
		    if {$candidate == ""} {
			set candidate $j
			set minsofar $dist($j)
		    } elseif {$dist($j) < $minsofar} {
			set candidate $j
			set minsofar $dist($j)
		    }
		}
	    }
	    set order($i) $candidate
	    set alreadyset($candidate) 1
	}

	# Try the sides in order, using the first one where there's room.

	for {set i 0} {$i < 4} {incr i} {
	    if {$order($i) == "l"} {
		if {$dx >= $mag_w} {
		    set sx [expr $dx - $mag_w]
		    break
		}
	    } elseif {$order($i) == "b"} {
		if {$winHeight >= $dy + $dny + $mag_h} {
		    set sy [expr $dy + $dny]
		    break
		}
	    } elseif {$order($i) == "r"} {
		if {$winWidth >= $dx + $dnx + $mag_w} {
		    set sx [expr $dx + $dnx]
		    break
		}
	    } elseif {$order($i) == "t"} {
		if {$dy >= $mag_h} {
		    set sy [expr $dy - $mag_h]
		    break
		}
	    }
	}
    }

    # Make sure we don't go beyond an edge of the main window.

    if {$sx < 0} {
	set sx 0
    } else {
	set sxmax [expr $winWidth - $mag_w]
	if {$sx > $sxmax} {
	    set sx $sxmax
	}
    }

    if {$sy < 0} {
	set sy 0
    } else {
	set symax [expr $winHeight - $mag_h]
	if {$sy > $symax} {
	    set sy $symax
	}
    }

    # Map 32 x 32 centered on pointer in main window.
    set err [catch {send imagewin setMapping $magnifier_mapping $magnifierROP \
	0 pixel $sx $sy $mag_w $mag_h \
	0 pixel $dx $dy $dnx   $dny}]
    if { $err != 0 } {
	Print "There was a problem setting up the magnifier ... recovering"
    }
}


# set the position of the magnifier marker in the center of the mag window
proc setMagPointerPosition args \
{
    global magnifier_enable

    if { !$magnifier_enable } \
	return

    send magnifierWin "getAttributes x x y y"
    set xpos [expr $x + 1]
    set ypos [expr $y + 1]

    send magPointer "setAttributes x $xpos y $ypos visible true; redraw"
}



################################################################################
# PANNER.  The full frame mapped into the main image window is displayed at a
# reduced resolution in a marker (known as the panner window) within the main
# image window.  The currently displayed region of the frame is indicated
# using a small marker within the panner window.  This small marker may be
# moved or resized to pan or zoom the image in the main display window.
################################################################################

set panner_x 0
set panner_y 0
set panner_width 0
set panner_height 0
set prm_width 0
set prm_height 0

set panner_enable 0
set panner_pan_enable 0
set panner_mag_enable 0
set panner_region_enable 0
set panner_mapping 0

# Panner window translations.
set pannerWinTranslations { \
       !Shift <Btn1Motion>:	m_rotateResize()
	      <Btn1Motion>:	m_moveResize()
	 !Shift <Btn1Down>:	m_raise() m_markpos()
		<Btn1Down>:	m_raise() m_markposAdd()
		  <Btn1Up>:	m_redraw() m_destroyNull()
		<Btn2Down>:	m_lower()
		  <Btn2Up>:	call(pannerPanXY,$x,$y)
	      !Ctrl <Key>b:     call(prevFrame,$name)
	      !Ctrl <Key>f:     call(nextFrame,$name)
	      !Ctrl <Key>h:     call(move_cursor,-1,0)
	      !Ctrl <Key>j:     call(move_cursor,0,1)
	      !Ctrl <Key>k:     call(move_cursor,0,-1)
	      !Ctrl <Key>l:     call(move_cursor,1,0)
	      !Ctrl <Key>n:     call(normalize)
	      !Ctrl <Key>c:     call(cpZoomAction,centerFrame)
	      !Ctrl <Key>i:     call(cpInvert)
	      !Ctrl <Key>m:     call(toggleMagnifier)
	      !Ctrl <Key>p:     call(togglePanner)
	      !Ctrl <Key>r:     call(cpRegisterFrames)
	      !Ctrl <Key>s:     call(cpMatchFrames)
	       !Alt <Key>1: 	call(cpSetFrame,frame1)
	       !Alt <Key>2: 	call(cpSetFrame,frame2)
	       !Alt <Key>3: 	call(cpSetFrame,frame3)
	       !Alt <Key>4: 	call(cpSetFrame,frame4)
	      !Ctrl <Key>1: 	call(cpZoom,1,1,fixed)
	      !Ctrl <Key>2: 	call(cpZoom,2,2,fixed)
	      !Ctrl <Key>3: 	call(cpZoom,3,3,fixed)
	      !Ctrl <Key>4: 	call(cpZoom,4,4,fixed)
	      !Ctrl <Key>5: 	call(cpZoom,5,5,fixed)
	      !Ctrl <Key>6: 	call(cpZoom,6,6,fixed)
	      !Ctrl <Key>7: 	call(cpZoom,7,7,fixed)
	      !Ctrl <Key>8: 	call(cpZoom,8,8,fixed)
	      !Ctrl <Key>9: 	call(cpZoom,9,9,fixed)
	    <Key>BackSpace:	m_deleteDestroy()
	       <Key>Delete:	m_deleteDestroy()
		<KeyPress>:     graphics-input()
		  <Motion>:	track-cursor() call(wcsUpdate,$x,$y)
}


# setPanner -- Turn the panner on or off.

proc togglePanner args \
{
    global panner_enable

    if {$panner_enable} {
	setPanner 0
    } else {
	setPanner 1
    }
}


proc setPanner {state} \
{
    global winWidth winHeight frameWidth frameHeight
    global frame panner_mapping pannerWinTranslations pannerArea
    global panner_enable panner_region_enable panner_pan_enable
    global pannerGeom panner_x panner_y panner_width panner_height
    global last_compass

    if {$state} {
	if {$panner_enable} \
	    return

	# Determine where to place the panner.
	set scale \
	    [expr sqrt(double($pannerArea) / ($frameWidth * $frameHeight))]
	set scaled_width [expr int($frameWidth * $scale) / 2 * 2 + 1]
	set scaled_height [expr int($frameHeight * $scale) / 2 * 2 + 1]
	set defGeom [format "%sx%s-5+5" $scaled_width $scaled_height]
	send imagewin parseGeometry $pannerGeom $defGeom x y width height

	# Create the main panner window (marker).
	send imagewin createMarker pannerWin \
	    type		rectangle \
	    createMode		noninteractive \
	    width		[expr $width / 2] \
	    height		[expr $height / 2] \
	    x			[expr $x + $width / 2] \
	    y			[expr $y + $height / 2] \
	    lineColor		8 \
	    highlightColor	8 \
	    translations	$pannerWinTranslations \
	    visible		true \
	    sensitive		true \
	    autoRedraw		true \
	    activated		true

	# Update the panner window position variables so that it comes up
	# in the same place the next time.

	send pannerWin getRect boundary \
	    panner_x panner_y panner_width panner_height
	set pannerGeom [send imagewin getGeometry \
	    $panner_x $panner_y $panner_width $panner_height]

	# Register callbacks.
	send frame addCallback pannerMapImage
	send frameRegion addCallback pannerSetRegion
	send imagewin addCallback pannerImagewinResized resize
	send resize addCallback pannerImagewinResized

	send pannerWin {
	    addCallback pannerMapImage moveResize;
	    addCallback pannerMoved moveResize;
	    addCallback pannerDestroy destroy;
	    addCallback pannerWinConstraint constraint;
	}

	# Map display frame to panner window.
	set panner_enable 1
	set panner_region_enable 1
	set panner_mapping [send imagewin nextMapping]
	pannerMapImage init; send imagewin refreshMapping $panner_mapping

	# Redraw the compass if necessary.
	send compass "setSensitive True ; set on $last_compass"
	if { $last_compass } \
	    drawCompass

	# Draw a marker in the panner window outlining displayed region.
	send imagewin createMarker pannerRegionMarker \
	    type		box \
	    createMode		noninteractive \
	    translations	$pannerWinTranslations \
	    lineColor		green \
	    highlightColor	green \
	    sensitive		true

	# Fire up the panner region marker.
	send client getSource raster sx sy snx sny
	pannerSetRegion dummy dummy [concat $frame $sx $sy $snx $sny]
	send pannerRegionMarker "\
	    addCallback pannerPanImage moveResize; \
	    addCallback pannerDestroy destroy; \
	    addCallback pannerRegionConstraint constraint; \
	    setAttributes visible true activated true; \
	    redraw"
	set panner_pan_enable 1

    } elseif {$panner_enable} {
	pannerDestroy
    }
}


# pannerDestroy -- Delete the panner.

proc pannerDestroy args \
{
    global panner_enable panner_region_enable panner_pan_enable
    global panner_mapping

    if {$panner_enable} {
	set panner_enable 0
	set panner_pan_enable 0
	set panner_region_enable 0

	send imagewin freeMapping $panner_mapping
	send imagewin deleteCallback pannerImagewinResized
	send resize deleteCallback pannerImagewinResized
	send frame deleteCallback pannerMapImage
	send frameRegion deleteCallback pannerSetRegion

	if [send server queryObject pannerRegionMarker] {
	    send pannerRegionMarker destroy
	}
	if [send server queryObject pannerWin] {
	    send pannerWin destroy
	}

	# Disable the compass.
	send compass "setSensitive False ; set on False"
    }
}


# pannerMapImage -- Map the current display frame into the panner window.
# Called when the frame changes or the panner window is moved or resized.
# The panner window displays a small dezoomed version of the full frame.

proc pannerMapImage args \
{
    global panner_enable frame
    global panner_mapping

    if {!$panner_enable || $frame == 0} \
	return

    set raster [send client getRaster]
    send pannerWin getRect interior dx dy dnx dny
    send imagewin queryRaster $raster width height

    if [send imagewin activeMapping $panner_mapping] {
	send imagewin raiseMapping $panner_mapping
    }
    send imagewin setMapping $panner_mapping 0 \
	$raster pixel 0 0 $width $height \
	0 pixel $dx $dy $dnx $dny
}


# pannerSetRegion -- Adjust the pannerWin region marker to outline the
# region displayed in the main display window.  This is called in response
# to a frameRegion event when the main display mapping changes, e.g. when
# the frame changes or the user zooms or pans the main window.  The region
# marker is moved and resized to reflect the new view.

proc pannerSetRegion {param old new} \
{
    global panner_enable panner_region_marker
    global panner_region_enable panner_pan_enable
    global frame frameWidth frameHeight prm_width prm_height

    if {!$panner_enable || !$panner_region_enable || $frame == 0} \
	return

    # new: frame sx sy snx sny
    set src_frame [lindex $new 0]
    set sx [lindex $new 1];  set snx [lindex $new 3]
    set sy [lindex $new 2];  set sny [lindex $new 4]

    if {$src_frame != $frame} \
	return

    send pannerWin getRect interior px py pnx pny

    set x [expr ($sx + $snx/2.0) / $frameWidth * $pnx + $px]
    set y [expr ($sy + $sny/2.0) / $frameHeight * $pny + $py]
    set width  [expr ($snx/2.0) / $frameWidth * $pnx + 1]
    set height [expr ($sny/2.0) / $frameHeight * $pny + 1]

    set pan_save $panner_pan_enable;  set panner_pan_enable 0
    set panner_region_enable 0

    send pannerRegionMarker "\
	markpos; \
	setAttributes x $x y $y width $width height $height; \
	redraw; raise"
    send pannerRegionMarker getAttributes width prm_width height prm_height

    set panner_region_enable 1
    set panner_pan_enable $pan_save
}


# pannerPanImage -- Pan or zoom the image in the main image window.  This is
# called when the user moves the region marker within the panner window.

proc pannerPanImage {marker event position} \
{
    global panner_pan_enable
    global winWidth winHeight
    global prm_width prm_height
    global frame auto_reg frameOffsetX frameOffsetY

    if {!$panner_pan_enable} \
	return

    # position: x y width height.
    set new_width [lindex $position 2]
    set new_height [lindex $position 3]

    # region: type raster x y width height.
    set region [send pannerRegionMarker getRegion unmap]
    set x [expr [lindex $region 2] + 1];  set width [lindex $region 4]
    set y [expr [lindex $region 3] + 1];  set height [lindex $region 5]

    set panner_pan_enable 0
    if {$new_width == $prm_width && $new_height == $prm_height} {
	send client pan $x $y
    } else {
	set xscale [expr ($winWidth / 2.0) / $width]
	set yscale [expr ($winHeight / 2.0) / $height]
	if {$auto_reg == 1} {
	    send client zoomAbs $xscale $yscale $x $y \
		$frameOffsetX($frame) $frameOffsetY($frame)
	} else {
	    send client zoom $xscale $yscale $x $y
	}
    }
    set panner_pan_enable 1
}


# pannerPanXY -- Pan to the point X,Y in the panner window coordinate
# system.  Called when the user clicks MB2 in the panner window.

proc pannerPanXY {x y} \
{
    send imagewin unmapPixel $x $y raster rx ry
    send client pan $rx $ry
}


# pannerMoved -- Called when the user moves the panner window.  We need to
# move the region marker to the new window location and record the new location
# so that the window will come up in the same place if closed and reopened.

proc pannerMoved {marker event position} \
{
    global winWidth winHeight
    global frame panner_pan_enable pannerGeom
    global panner_x panner_y panner_width panner_height

    # Move the region marker to the new location.
    set pan_save $panner_pan_enable;  set panner_pan_enable 0
    send client getSource raster sx sy snx sny
    pannerSetRegion dummy dummy [concat $frame $sx $sy $snx $sny]
    set panner_pan_enable $pan_save

    # Update the panner window position variables so that it comes up
    # in the same place the next time.

    send pannerWin getRect boundary \
	panner_x panner_y panner_width panner_height
    set pannerGeom [send imagewin getGeometry \
	$panner_x $panner_y $panner_width $panner_height]

    drawCompass

    send pannerRegionMarker raise
}


# pannerWinConstraint -- Called when the panner window is moved, resized, or
# rotated.  Constrain the panner window to remain within the image window;
# rotation is not permitted.

proc pannerWinConstraint {marker event attributes} \
{
    global winWidth winHeight
    global panner_width panner_height

    set width $panner_width
    set height $panner_height
    set constraints [list {}]

    # Check the width and height first as we need these below.
    foreach i $attributes {
	set new [lindex $i 2]
	switch [lindex $i 0] {
	    width	{   set ww [expr $winWidth / 2]
			    if {$new > $ww} {
				lappend constraints "width $ww"
				set width $ww
			    } else {
				set width $new
			    }
			}
	    height	{   set wh [expr $winHeight / 2]
			    if {$new > $wh} {
				lappend constraints "height $wh"
				set height $wh
			    } else {
				set height $new
			    }
			}
	    rotangle	{    lappend constraints "rotangle 0"
			}
	}
    }

    # Constrain X and Y.
    foreach i $attributes {
	set new [lindex $i 2]
	switch [lindex $i 0] {
	    x		{   set pw [expr $width / 2]
			    if {$new < $pw} {
				lappend constraints "x $pw"
			    } elseif {$new > $winWidth - $pw} {
				lappend constraints "x [expr $winWidth - $pw]"
			    }
			}
	    y		{   set ph [expr $height / 2]
			    if {$new < $ph} {
				lappend constraints "y $ph"
			    } elseif {$new > $winHeight - $ph} {
				lappend constraints "y [expr $winHeight - $ph]"
			    }
			}
	}
    }

    return $constraints
}


# pannerRegionConstraint -- Called when the region marker in the panner
# window is moved, resized, or rotated.

proc pannerRegionConstraint {marker event attributes} \
{
    global winWidth winHeight
    global frame

    set constraints [list {}]
    send pannerWin getRect interior p_x p_y p_width p_height
    send pannerRegionMarker getAttributes width rwidth height rheight

    # Since the panner region marker is a box marker x,y and width,height
    # will not both change in the same call, so we can process them all
    # independently.

    foreach i $attributes {
	set new [lindex $i 2]

	switch [lindex $i 0] {
	    x		{   set left [expr $p_x + $rwidth + 1]
			    set right [expr $p_x + $p_width - $rwidth - 1]
			    if {$new < $left} {
				lappend constraints "x $left"
			    } elseif {$new > $right} {
				lappend constraints "x $right"
			    }
			}
	    y		{   set top [expr $p_y + $rheight + 1]
			    set bottom [expr $p_y + $p_height - $rheight - 1]
			    if {$new < $top} {
				lappend constraints "y $top"
			    } elseif {$new > $bottom} {
				lappend constraints "y $bottom"
			    }
			}
	    width	{   set ww [expr $winWidth / 2]
			    if {$new > $ww / 2} {
				lappend constraints "width $ww"
			    }
			}
	    height	{   set wh [expr $winHeight / 2]
			    if {$new > $wh / 2} {
				lappend constraints "height $wh"
			    }
			}
	    rotangle	{    lappend constraints "rotangle 0"
			}
	}
    }
    drawCompass

    return $constraints
}


# pannerImagewinResized -- If the display window is resized make the panner
# track the corner.

proc pannerImagewinResized args \
{
    global panner_enable panner_mapping 
    global pannerGeom panner_x panner_y panner_width panner_height
    global frame

    if {$panner_enable} {
	set old_x $panner_x;  set old_width $panner_width
	set old_y $panner_y;  set old_height $panner_height

        eraseCompass

	# Get new location of panner window.
	set defGeom [format "%sx%s-5+5" $panner_width $panner_height]
	send imagewin parseGeometry $pannerGeom $defGeom x y width height

	# Reposition the marker.
	send pannerWin "\
	    markpos; \
	    setAttributes \
		x		[expr $x + $width / 2] \
		y		[expr $y + $height / 2] \
		width		[expr $width / 2] \
		height		[expr $height / 2]; \
	    redraw"

	# Update the panner window position variables so that it comes up
	# in the same place the next time.
	send pannerWin getRect boundary \
	    panner_x panner_y panner_width panner_height
	set pannerGeom [send imagewin getGeometry \
	    $panner_x $panner_y $panner_width $panner_height]

	# Make sure the panner window is on top.
	send imagewin raiseMapping $panner_mapping

	# Refresh the panner window if it did not move.
	if {$panner_x == $old_x && $panner_y == $old_y &&
	    $panner_width == $old_width && $panner_height == $old_height} {
	    send imagewin refreshMapping $panner_mapping
	}

        drawCompass
    }
}


# resetPanner -- Reinitialize the panner.

proc resetPanner {param old new} \
{
    global pannerGeom displayPanner
    if {$new == "done"} {
	setPanner [true $displayPanner]
    } else {
	setPanner 0
	if {$new != "startup"} {
	    set pannerGeom -5+5
	}
    }
}; send initialize addCallback resetPanner



################################################################################
# Print Panel Functions.
################################################################################

# Global variables needed for the print setup panel

set printColor	prGrayButton
set orientation	epsPortButton
set page_size	epsLetterButton
set imageScale	100

set epsWidgets { epsPageGroup epsOrientLabel epsSizeLabel 
	epsPortButton epsLandButton epsLetterButton epsLegalButton epsA4Button
	ScaleFrame SCdecrease SCtext SCincrease 
}


proc psetup_init args \
{
    global printColor orientation page_size imageScale #format

    set_printer toPrinter callback 1
    send SCtext set label [ format "%d %%" $imageScale ]
    send $printColor set on true
    send $orientation set on true
    send $page_size set on true
}


proc doPrintOptions { param old new } \
{
    global imageScale page_size orientation imageScale printColor
    global warnings

    send printStatus set label {}
    set val [join [lrange $new 1 end] " "]

    # print [format "doPrintOptions %s = %s" [lindex $new 0] $val]
    switch [lindex $new 0] {
    autoscale	    { 	if { $val == "True" } {
			    send epsscaleButton set on true
			} elseif { $val == "False" } {
			    send epsscaleButton set on false
			}
		    }
    autorotate	    { 	if { $val == "True" } {
			    send autorotateButton set on true
			} elseif { $val == "False" } {
			    send autorotateButton set on false
			}
		    }
    maxaspect	    { 	if { $val == "True" } {
			    send aspectButton set on true
			} elseif { $val == "False" } {
			    send aspectButton set on false
			}
		    }
    annotate	    { 	if { $val == "True" } {
			    send annotateButton set on true
		            send titleButton setSensitive true
		            send colorbarButton setSensitive true
		            send bordersButton setSensitive true
		            send titleLabel setSensitive true
		            send titleString setSensitive true
			} elseif { $val == "False" } {
			    send annotateButton set on false
		            send titleButton setSensitive false
		            send colorbarButton setSensitive false
		            send bordersButton setSensitive false
		            send titleLabel setSensitive false
		            send titleString setSensitive false
			}
		    }
    compress	    { 	if { $val == "True" } {
			    send compressButton set on true
			} elseif { $val == "False" } {
			    send compressButton set on false
			}
		    }
    orientation	    { 	send $orientation set on false
			if { $val == "portrait" } {
			    send epsPortButton set on true
			    set orientation epsPortButton
			} elseif { $val == "landscape" } {
			    send epsPortButton set on false
			    set orientation epsLandButton
			}
		    }
    papersize	    { 	send $page_size set on false
			if { $val == "letter" } {
			    send epsLetterButton set on true
			    set page_size epsLetterButton
			} elseif { $val == "legal" } {
			    send epsLegalButton set on true
			    set page_size epsLegalButton
			} elseif { $val == "A4" } {
			    send epsA4Button set on true
			    set page_size epsA4Button
			} elseif { $val == "B5" } {
			    send epsB5Button set on true
			    set page_size epsB5Button
			}
		    }
    imscale	    { 	set imageScale $val
    			send SCtext set label [ format "%d %%" $imageScale ]
		    }
    colortype	    { 	send $printColor set on false
			if { $val == "gray" } {
			    send prGrayButton set on true
			    set printColor prGrayButton
			} elseif { $val == "pseudo" } {
			    send prPseudoButton set on true
			    set printColor prPseudoButton
			} elseif { $val == "rgb" } {
			    send prRGBButton set on true
			    set printColor prRGBButton
			}
		    }
    printerName	    {	if [send toPrinter get on] {
			    send printlist highlight $val
			}
		    }
    printCmd	    {	if [send toPrinter get on] {
			    send printcmd set string $val
			}
		    }
    printFile	    {	if [send toFile get on] {
			    send printcmd set string $val
			}
		    }
    deviceType      {   if { $val == "Printer" } {
			    send printerLabel set label "Print Command:"
			    send toPrinter set on true
			    send toFile set on false
		        } elseif { $val == "File" } {
			    send printerLabel set label "File Name:"
			    send toPrinter set on false
			    send toFile set on true
			    send printlist unhighlight
		        }
		    }
    dotitle         {   if { $val == "True" } {
		            send titleButton set on true
		        } elseif { $val == "False" } {
		            send titleButton set on false
		        }
		    }
    doborders       {   if { $val == "True" } {
		            send bordersButton set on true
		        } elseif { $val == "False" } {
		            send bordersButton set on false
		        }
		    }
    docolorbar      {   if { $val == "True" } {
		            send colorbarButton set on true
		        } elseif { $val == "False" } {
		            send colorbarButton set on false
		        }
		    }
    title           {   send titleString set string $val
		    }

    status	    {   send printStatus set label $val
			send server synchronize
	 	    }
    warning	    {   if {$warnings} { Wexec server $val }
		    }
    }
}; send printOptions addCallback doPrintOptions


# Print options procedures.
# -------------------------------

set prOptsWidgets { 
    toPrinter toFile
    prGrayButton prPseudoButton prRGBButton
    epsLandButton epsPortButton
    epsLetterButton epsLegalButton epsA4Button epsB5Button
    SCincrease SCdecrease
}
set prSimpleOptions { 
    epsscaleButton autorotateButton aspectButton annotateButton compressButton 
    titleButton bordersButton colorbarButton
}

proc prPrintCommand { widget cbtype args } \
{
    if [send toFile get on] {
	send client setPrintOption printfile $args
	send printStatus set label [format "output file set to %s" $args]
    } else {
	send client setPrintOption printcmd $args
	send printStatus set label [format "print command set to %s" $args]
    }
}; send printcmd addCallback prPrintCommand

proc prTitleString { widget cbtype args } \
{
    send client setPrintOption title $args
}; send titleString addCallback prTitleString

proc prOptionToggle { widget cbtype args } \
{
    global imageScale

    # Handle the image scale widgets first.
    switch $widget {
    SCincrease	{ set scale [expr $imageScale + 5] 
  		  send client setPrintOption imscale $scale
		  return
		}
    SCdecrease	{ set scale [ expr $imageScale - 5 ]
		  send client setPrintOption imscale $scale
		  return
		}
    }

    # If it's not one of those it must be one of the radio toggles.
    set val [ send $widget get on ]
    #print [ format "prOptionToggle %s = %s" $widget $val ]
    if { $val == 1 } {
	switch $widget {
	toPrinter  	{ send client setPrintOption devicetype printer }
	toFile  	{ send client setPrintOption devicetype file }

	epsLandButton   { send client setPrintOption orientation landscape }
	epsPortButton   { send client setPrintOption orientation portrait }

	epsLetterButton { send client setPrintOption papersize letter }
	epsLegalButton  { send client setPrintOption papersize legal }
	epsA4Button     { send client setPrintOption papersize A4 }
	epsB5Button     { send client setPrintOption papersize B5 }

	prGrayButton    { send client setPrintOption colortype gray }
	prPseudoButton  { send client setPrintOption colortype pseudo }
	prRGBButton     { send client setPrintOption colortype rgb }
	}
    } else {
	send $widget set on true
    }

} ; foreach w $prOptsWidgets { send $w addCallback prOptionToggle }

proc prSimpleOptionToggle { widget args } \
{
    set val [ send $widget get on ]
    #print [ format "prSimpleOptionToggle %s = %s" $widget $val ]

    switch $widget {
    epsscaleButton   { send client setPrintOption autoscale  $val }
    autorotateButton { send client setPrintOption autorotate $val }
    aspectButton     { send client setPrintOption maxaspect  $val }
    annotateButton   { send client setPrintOption annotate   $val }
    compressButton   { send client setPrintOption compress   $val }

    titleButton      { send client setPrintOption dotitle    $val }
    bordersButton    { send client setPrintOption doborders  $val }
    colorbarButton   { send client setPrintOption docolorbar $val }
    }
} ; foreach w $prSimpleOptions { send $w addCallback prSimpleOptionToggle }



# Printer display and selection.
# -------------------------------
set lprList	{}

proc psSetPrintList {param old new} \
{
    global lprList
    set lprList $new
    send printlist setList $new resize
    send printlist highlight 0
}; send printerList addCallback psSetPrintList

proc lprResize args \
{
    global lprList
    send printlist setList $lprList resize
    send printlist highlight 0
}; send printlist addEventHandler lprResize ResizeRedirectMask

proc psSelectPrint {widget cbtype selections indices} \
{
    global printerlist
    foreach selection $selections {
	send client setPrintOption printername $selection
    }
}; send printlist addCallback psSelectPrint


proc Print args \
{
    global winWidth winHeight
    send imagewin setCursorType busy

    # Get the print command or file template if not previous reset.
    set val [ send printcmd get string ]
    if [send toFile get on] {
	send client setPrintOption printfile $val
    } else {
	send client setPrintOption printcmd $val
    }
    set val [ send titleString get string ]
    send client setPrintOption title $val
    setPrintCorners 0 [expr $winWidth - 1] [expr $winHeight - 1] 0

    send client print
    send imagewin setCursorType idle
} ; send okayPrint addCallback Print



# setPrintCorners -- Tell the client the WCS of the image being printed.

proc setPrintCorners { lx ly ux uy args } \
{
    global winWidth winHeight

    # Convert raw corner screen coordinates to frame buffer raster coords.
    send imagewin unmapPixel $lx $ly raster llx lly
    set llx [expr "int ($llx)"]
    set lly [expr "int ($lly)"]
    set str  [send client encodewcs $llx $lly]
    scan $str "%g %g %g" llx_r lly_r z
    set llx_i [expr "int ($llx_r)"]
    set lly_i [expr "int ($lly_r)"]

    send imagewin unmapPixel $ux $uy raster urx ury
    set urx [expr "int ($urx)"]
    set ury [expr "int ($ury)"]
    set str [send client encodewcs $urx $ury]
    scan $str "%g %g %g" urx_r ury_r z
    set urx_i [expr "int ($urx_r)"]
    set ury_i [expr "int ($ury_r)"]

    send client setPrintOption corners $llx_i $lly_i $urx_i $ury_i
}



################################################################################
# INFO box.
################################################################################

set	infoMode	infoOptFr


# Current Frame information.
proc infoFrameUpdate args \
{
    global version frame nframes
    global frameWidth frameHeight frameDepth
    global enhancement
    global cpXcen cpYcen cpXoff cpYoff
    global cpXmag cpYmag cpXscale cpYscale

    if { [send infoOptWCS get on] } {
	send client info wcs
	return
    } elseif {! [send infoOptFr get on]} \
	return


    if {$frame == 0} {
       send infoText set string "initializing display..."
    } else {
       set line1 $version
       set line2 [format "Image:\t\t%s" [send imageTitle get label]]
       set line3 [format "Frame %d of %d:\t%d x %d" \
	    		$frame $nframes $frameWidth $frameHeight]
       set cmap  [lindex $enhancement($frame) 0]
       set brt   [lindex $enhancement($frame) 1]
       set con   [lindex $enhancement($frame) 2]
       set line4 [format "Colormap:\t%s" $cmap]
       set line5 [format "Enhancement:\tBrt=%s  Cont=%s" $brt $con]

       set cntr  [format "X: %0.1f\n\t\tY: %0.1f" $cpXcen $cpYcen]
       set line6 [format "Center:\t\t%s" $cntr]

       set line7 [format "Zoom:\t\tX: %0.2f\n\t\tY: %0.2f" $cpXmag $cpYmag]
       set line8 [format "Scale:\t\tX: %0.2f\n\t\tY: %0.2f" $cpXscale $cpYscale]
       set line9 [format "Offset:\t\tX: %0.2f\n\t\tY: %0.2f" $cpXoff $cpYoff]

       send infoText set string [
	    format "%s\n\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n" \
		$line1 $line2 $line3 $line4 $line5 $line6 $line7 $line8 $line9
       ]
    }
}
set params {frame frameView nframes frameSize frameTitle enhancement}
foreach p $params { send $p addCallback infoFrameUpdate }


# Server Program State information.
proc infoOptToggle { widget type state args } \
{
    global infoMode ismInfoText

    if {$state} { set not False } else { set not True }

    send $infoMode set on $not
    set infoMode $widget

    switch $widget {
    infoOptFr	   { infoFrameUpdate				}
    infoOptSvr	   { set bp [send imagewin get basePixel] 
		     set mc [send imagewin get maxColors]
		     send client info server $bp $mc
		   }
    infoOptIsm     { send infoText set string $ismInfoText	}
    infoOptClients { send client info clients			}
    infoOptWCS     { send client info wcs			}
    infoOptFB	   { send client info imtoolrc			}
    }
}
set iopts {infoOptFr infoOptSvr infoOptIsm infoOptClients infoOptWCS infoOptFB }
foreach w $iopts { send $w addCallback infoOptToggle }


proc infoSetText { param old new } \
{
   send infoText set string $new
} ; send info addCallback infoSetText



################################################################################
# Image and objects list display and section
################################################################################

proc filesTextHighlight { widget event args } \
{
    if { $event == "enterNotify" } {
	send $widget set displayCaret True
    } elseif { $event == "leaveNotify" } {
	send $widget set displayCaret False
    }
}
foreach w {imtemplateText fnameText z1Value z2Value} {
    send $w addEventHandler filesTextHighlight enterWindowMask
    send $w addEventHandler filesTextHighlight leaveWindowMask
}

send rootButton     addCallback "send client setLoadOption root"
send homeButton     addCallback "send client setLoadOption home"
send upButton       addCallback "send client setLoadOption up"
send rescanButton   addCallback "send client setLoadOption rescan"

set label \
    [format "%-35.35s %6s   %12s  %12s"\
         "              Image" "Bitpix" "  Size" "          Title"]
send imlistLabel set label $label
send imlistLabel "set height 0 ; unmap"


# Create the Frames menu on the load panel window.
set loadItems { "Current f.exec \{send frameFrame set label Current\}"}
for {set i 1} {$i <= $MAX_FRAMES} {incr i} {
    lappend loadItems "\"\ \ $i\ \ \" f.exec \{send frameFrame set label $i\}"
}; createMenu loadFrames frameFrame $loadItems





# Filename pattern callback.
proc setPattern { widget mode pattern args } \
{
    send client setLoadOption pattern $pattern
} ; send imtemplateText addCallback setPattern


# Load options parameter callback.
proc doLoadOptions { param old new } \
{
    global warnings panel_up

    set val     [ join [lrange $new 1 end] " " ]

    switch [lindex $new 0] {
    pattern  	{ send imtemplateText set string [format "%s" $val ] }
    curdir   	{ send dirLabel set label [format "  Directory:    %s" $val ] }
    newfile  	{ send fnameText set string $val }
    status  	{ send filesStatus set label $val
	          if { ! $panel_up } { send imageTitle set label $val }
	          send server synchronize
	    	}
    warning 	{ if {$warnings} { Wexec server $val } 		}
    gray	{ send grayscale set on $val 			}
    zscale	{ send zscale set on $val
    		  if {$val} {
		      send zrange setSensitive False
		  } else {
		      send zrange setSensitive True
		  }
		}
    zrange	{ send zrange set on $val
    		  if {$val} {
		      foreach w {z1Label z1Value z2Label z2Value} {
		          send $w setSensitive False
		      }
		  } else {
		      foreach w {z1Label z1Value z2Label z2Value} {
		          send $w setSensitive True
		      }
		  }
		}
    z1		{ send z1Value    set string [format "%s" $val ] }
    z2		{ send z2Value    set string [format "%s" $val ] }
    nsample	{ send nsampValue set string [format "%s" $val ] }
    }
} ; send loadOptions addCallback doLoadOptions

# Option utility routines.
proc toggleGraymap args \
{
    send client setLoadOption gray [ send grayscale get on ]
} ; send grayscale addCallback toggleGraymap

proc toggleHeaders args \
{
    if { [send browseHdrs get on] } {
        send client setLoadOption headers 
	send rootButton   setSensitive False
	send homeButton   setSensitive False
	send upButton     setSensitive False
	send rescanButton setSensitive False
	send imlistLabel "set height 10 ; map"
    } else {
        send client setLoadOption rescan 
	send rootButton   setSensitive True
	send homeButton   setSensitive True
	send upButton     setSensitive True
	send rescanButton setSensitive True
	send imlistLabel "set height 0 ; unmap"
    }
} ; send browseHdrs addCallback toggleHeaders

proc toggleZscale args \
{
    send client setLoadOption zscale [send zscale get on]
} ; send zscale addCallback toggleZscale

proc toggleZrange args \
{
    send client setLoadOption zrange [send zrange get on]
} ; send zrange addCallback toggleZrange

proc setZ1 { widget mode pattern args } \
{
    send client setLoadOption z1 $pattern
} ; send z1Value addCallback setZ1

proc setZ2 { widget mode pattern args } \
{
    send client setLoadOption z2 $pattern
} ; send z2Value addCallback setZ2

proc setNsamp { widget mode pattern args } \
{
    send client setLoadOption nsample $pattern
} ; send nsampValue addCallback setNsamp

proc fileLoad { widget mode fname args } \
{
    loadImage $fname
} ; send fnameText addCallback fileLoad



# Image list selection routines.

set fileList	{}

proc setFileList { param old new } \
{
    global fileList
    set fileList $new

    # Get the max length of the strings so we can set
    # the list columns appropriately.
    set max 0
    foreach n $new {
	set len [string length $n]
	if {$len > $max} { set max $len }
    }

    # Optimize the number of columns for the file list.
    if {$max > 35}  { 
	send imageList set defaultColumns 1
    } elseif {$max > 21} { 
	send imageList set defaultColumns 2
    } elseif {$max > 12} { 
	send imageList set defaultColumns 3
    } elseif {$max > 5} { 
	send imageList set defaultColumns 4
    } else { 
	send imageList set defaultColumns 5
    }

    send imageList setList $new resize
}; send filelist addCallback setFileList

proc flResize args \
{
    global fileList
    send imageList setList $fileList resize
}; send imageList addEventHandler flResize ResizeRedirectMask

proc flSelectPrint { widget cbtype selections args } \
{
    if {! [send autoload get on]} \
	return

    foreach selection $selections { 
        if { [send zrange get on] } {
	    loadImage [lindex $selection 0]
        } else {
	    loadImage $selection
        }
    }
}; send imageList addCallback flSelectPrint


# Load the named image in the display.
proc loadImage { name } \
{
    global frame

    set fr [send frameFrame get label]

    if { $fr == "Current" } { set fr $frame }

    if { [fileSetOptions] >= 0 } {
        send imagewin setCursorType busy
        send client load $name $fr
        send imagewin setCursorType idle
        send fnameText set string $name
    }
}

# Load button callback.
proc fileLoadB args \
{
    set fname [send fnameText get string]
    if {$fname == ""} {
	Wexec client "No image name specified"
    } else {
	loadImage $fname
    }
} ; send filesLoadButton addCallback fileLoadB


# Send and selected options to the client before loading the image.
proc fileSetOptions args \
{
    if { ![send zscale get on] && ![send zrange get on] } {
        set z1 [send z1Value get string]
        set z2 [send z2Value get string]

        if {$z1 == $z2} {
	    Wexec client "z1/z2 values are not set properly"
	    return -1
	} else {
            send client setLoadOption z1 $z1
            send client setLoadOption z2 $z2
	}
    }

    return 0
}


################################################################################
# Save panel functions.
################################################################################

# Global variables needed for the save setup panel

set format	rasButton
set saveColor	svPseudoButton

set fileFmtButtons {
    rasButton gifButton jpegButton tiffButton 
    fitsButton x11Button epsButton rawButton 
}


# Format group procedures.
#---------------------------------

# Select a format.

proc set_format { widget func state args } \
{
    global format saveColor

    send $format set on false
    if {$widget == $format} {
	send $widget set on true
    } else {
	switch $widget  { 
	rasButton	{ send client setSaveOption format ras  } 
	gifButton	{ send client setSaveOption format gif  }
	jpegButton	{ send client setSaveOption format jpeg }
	tiffButton	{ send client setSaveOption format tiff }
	fitsButton	{ send client setSaveOption format fits }
	x11Button	{ send client setSaveOption format x11  }
	epsButton	{ send client setSaveOption format eps  }
	rawButton	{ send client setSaveOption format raw  }
	}
    }
} ; foreach fmt $fileFmtButtons { send $fmt addCallback set_format }

proc setSaveFile { widget cbtype args } \
{
	send client setSaveOption fname $args
	send saveStatus set label [format "output file set to %s" $args]
}; send saveFile addCallback setSaveFile


proc doSaveOptions { param old new } \
{
    global format saveColor
    global warnings

    send saveStatus set label {}
    set val [join [lrange $new 1 end] " "]

    #print [format "doSaveOptions %s = %s" [lindex $new 0] $val]
    switch [lindex $new 0] {
    format  {   
		# Now (de)sensitize the color options depending on the format,
		# force the color choice when needed.
    		send $format set on false
		switch [lindex $val 0] {
		ras       { #send svRGBButton setSensitive false
		            send svPseudoButton setSensitive true
			    set format rasButton
		          }
		gif       { send svRGBButton setSensitive false
		            send svPseudoButton setSensitive true
		            if {$saveColor == "svRGBButton"} {
		                send $saveColor set on false
		                send svPseudoButton set on true
		                set saveColor svPseudoButton
		            }
			    set format gifButton
		          }
		jpeg      { send svRGBButton setSensitive true
		            send svPseudoButton setSensitive true
			    set format jpegButton
		          }
		tiff      { send svRGBButton setSensitive false
		            send svPseudoButton setSensitive true
			    set format tiffButton
		          }
		fits      { send svRGBButton setSensitive false
		            send svPseudoButton setSensitive false
		            send $saveColor set on false
		            send svGrayButton set on true
		            set saveColor svGrayButton
			    set format fitsButton
		          }
		x11       { send svRGBButton setSensitive true
		            send svPseudoButton setSensitive true
			    set format x11Button
		          }
		eps       { send svRGBButton setSensitive true
		            send svPseudoButton setSensitive true
			    set format epsButton
		          }
		raw       { send svRGBButton setSensitive true
		       	    send svPseudoButton setSensitive true
			    set format rawButton
		          }
		}
    		send $format set on true
	    }
    color   { send $saveColor set on false
	      switch [lindex $val 0] {
	      grayscale   { send svGrayButton set on true
     			    set saveColor svGrayButton
			  }
	      pseudocolor { send svPseudoButton set on true
     			    set saveColor svPseudoButton
			  }
	      rgb	  { send svRGBButton set on true
     			    set saveColor svRGBButton
			  }
	      }
	    }
    fname   { send saveFile set string $val
	    }
    status  { send saveStatus set label $val
	      send server synchronize
	    }
    text    { send saveData set label $val
	    }
    warning { if {$warnings} { Wexec server $val }
	    }
    }
} ; send saveOptions addCallback doSaveOptions


# Color group procedures.
#---------------------------------
send svGrayButton   addCallback "send client setSaveOption color grayscale"
send svPseudoButton addCallback "send client setSaveOption color pseudocolor"
send svRGBButton    addCallback "send client setSaveOption color rgb"


proc Save args \
{
    global panel_up

    send imagewin setCursorType busy

    # Get the print command or file template if not previous reset.
    set val [ send saveFile get string ]
    send client setSaveOption fname $val
    send saveStatus set label [format "output file set to %s" $args]

    send client save
    send imagewin setCursorType idle
} ; send okaySave addCallback Save



################################################################################
# TILE GEOMETRY
################################################################################

set tileSel	2
set tileOpt	0
set tileNcols	2
set tileNrows	1
set tile_frames {}

proc selectTileOrientation { widget type select args } \
{
    global tileSel tileOpt

    set w { nrowLab ncolLab nrdecrease nrincrease ncdecrease ncincrease }
    if {$select == "Manual"} {
	foreach p $w { send $p setSensitive True }
    } elseif {$select != "none"} {
	foreach p $w { send $p setSensitive False }
    }

    set w { byCols bottomUp labelFrames labelImname labelTitles }
    if {$select == "Disabled"} {
	foreach p $w { send $p setSensitive False }
    } else {
	foreach p $w { send $p setSensitive True }
    }

    switch $select {
    Disabled	 { set tileSel 0 }
    Manual	 { set tileSel 1
		   set nx [send nctext get label]
    		   set ny [send nrtext get label]
		   set select [format "%dx%d" $nx $ny]
		 }
    Best	 { set tileSel 2 }
    Square	 { set tileSel 3 }
    Horizontal	 { set tileSel 4 }
    Vertical	 { set tileSel 5 }
    "One Row"	 { set tileSel 6 }
    "One Column" { set tileSel 7 }
    none	 { send tileMode set selection $tileSel	; return }
    }

    # Reset the button in case we're called directly from elsewhere.
    send tileMode set selection $tileSel

    # Send the option to the client.
    if {$tileSel > 0} {
        setTileFrames
        send client setOption tileFrames "True"
	set tileOpt $tileSel
    } else {
        send client setOption tileFrames "False"
    }

} ; send tileMode addCallback selectTileOrientation

proc tileSelToLabel { selection args } \
{
    switch $selection {
    0    { return "Disabled"	}
    1    { return "Manual"	}
    2    { return "Best"	}
    3    { return "Square"	}
    4    { return "Horizontal"	}
    5    { return "Vertical"	}
    6    { return "One Row"	}
    7    { return "One Column"	}
    }
    return "Best"
}

# Callback for the fill style options.
proc selectFillStyle { widget type state args } \
{
    if {$state} { set not False } else { set not True }

    switch $widget {
    byCols   	{ send client setOption tileByRows $not  }
    bottomUp 	{ send client setOption tileTopDown $not }
    }
} ; foreach w {byCols bottomUp} { send $w addCallback selectFillStyle }

# Callback for the tile labelling options.
proc selectTileLabels { widget type state args } \
{
    if {$state} { 
        switch $widget {
        labelFrames { send client setOption tileLabels 1 }
        labelImname { send client setOption tileLabels 2 }
        labelTitles { send client setOption tileLabels 3 }
        }
    } else {
	send client setOption tileLabels 0
    }
    send $widget set on $state
}
foreach w {labelFrames labelImname labelTitles} {
   send $w addCallback selectTileLabels
}

# Callback for the Tile Frame selection toggles.
proc setTileFrames args \
{
    global tile_frames tileSel tileNcols tileNrows

    # No-op if tiling isn't enabled.
    if {$tileSel == 0} \
	return

    # Get the new tile frames list.
    set tile_frames {}
    for {set i 1} {$i <= 16} {incr i} {
	if {[send tFrame$i get state]} {
	    lappend tile_frames $i
	}
    }

    # Reset the geometry.
    set geom [format "%dx%d" $tileNcols $tileNrows]
    switch $tileSel {
    1   { send client setOption tileGeom $geom      \{ $tile_frames \} }
    2   { send client setOption tileGeom Best       \{ $tile_frames \} }
    3   { send client setOption tileGeom Square     \{ $tile_frames \} }
    4   { send client setOption tileGeom Horizontal \{ $tile_frames \} }
    5   { send client setOption tileGeom Vertical   \{ $tile_frames \} }
    6   { send client setOption tileGeom Row        \{ $tile_frames \} }
    7   { send client setOption tileGeom Column     \{ $tile_frames \} }
    }
}; for {set i 1} {$i <= 16} {incr i} {send tFrame$i addCallback setTileFrames}

proc setAllTileFrames args \
{
    global tileNcols tileNrows
    for {set i 1} {$i <= 16} {incr i} {
	if {[send tFrame$i get sensitive]} {
	    send tFrame$i set state True
	}
    }
    setTileFrames
} ; send tAll addCallback setAllTileFrames

proc setNoTileFrames args \
{
    global tileNcols tileNrows
    for {set i 1} {$i <= 16} {incr i} {
	if {[send tFrame$i get sensitive]} {
	    send tFrame$i set state False
	}
    }
    setTileFrames
} ; send tNone addCallback setNoTileFrames

proc tileOptions { param old new } \
{
    global tileNcols tileNrows

    set tileNcols [lindex $new 0]
    set tileNrows [lindex $new 1]

    # Set the geometry.
    send nctext set label $tileNcols
    send nrtext set label $tileNrows
    send tileGeometry set label [format \
    	"Tile Geometry:  %-2dx%2d" $tileNcols $tileNrows]

} ; send tileOptions addCallback tileOptions


proc tileSetRows { widget args } \
{
    global nframes tile_frames

    set nx [send nctext get label]
    set ny [send nrtext get label]

    if {$widget == "nrdecrease" && [expr ($ny-1)] > 0} {
	incr ny -1
    } elseif {$widget == "nrincrease" && [expr ($ny+1)] <= $nframes} {
	incr ny 1
    } else {
	return
    }
    set geom [format "%dx%d" $nx $ny]
    send client setOption tileGeom $geom $tile_frames
} ; foreach w { nrdecrease nrincrease } { send $w addCallback tileSetRows }

proc tileSetCols { widget args } \
{
    global nframes tile_frames

    set nx [send nctext get label]
    set ny [send nrtext get label]

    if {$widget == "ncdecrease" && [expr ($nx-1)] > 0} {
	incr nx -1
    } elseif {$widget == "ncincrease" && [expr ($nx+1)] <= $nframes} {
	incr nx 1
    } else {
	return
    }
    set geom [format "%dx%d" $nx $ny]
    send client setOption tileGeom $geom $tile_frames
} ; foreach w { ncdecrease ncincrease } { send $w addCallback tileSetCols }


# Initialize the frame tiling.
setAllTileFrames
selectTileOrientation junk junk Disabled
selectFillStyle byRows  junk True
selectFillStyle topDown junk True
selectTileLabels labelImname junk False

################################################################################
#  Coords Panel Callbacks.
################################################################################

# In case we need to change the values....
#global wcsPHeight wcsPTxtHeight wcsPGrHeight wcsPOptHeight
#set wcsPHeight		267
#set wcsPTxtHeight	132
#set wcsPGrHeight	175
#set wcsPOptHeight	233
#setCoordPanelHeight

set wcsPHeight		267		;# full panel no options
set wcsPTxtHeight	132		;# size of text area box
set wcsPGrHeight	175		;# size of text area group
set wcsPOptHeight	233		;# extra height for opts boxes

# Set the WCS readout panel sensitivity depending on whether the ISM
# is currently enabled.
proc setCoordPanelSensitivity args \
{
    set widgets { 
	wpWcs2 wpWcs3 wpWcs4 
	wiWcs2 wiWcs3 wiWcs4 
	wlWcs2 wlWcs3 wlWcs4
	sysWcs2 sysWcs3 sysWcs4 
	fmtWcs2 fmtWcs3 fmtWcs4
    }

    send sysWcs1 set label "Display"
    send fmtWcs1 set label "Default"

    for {set i 2} {$i <= 4} {incr i} {
        send sysWcs$i set label "None" ; send fmtWcs$i set label "Default"
        send wpWcs$i  set on False     ; send wiWcs$i  set on False
        send wtWcs$i  set height 4
    }

    if {[send ismToggle get on]} {
        send sysWcs2 set label "World" ; send fmtWcs2 set label "Default"
	send wpWcs2  set on True       ; send wiWcs2  set on True
        send wtWcs2  set height 17

        foreach w $widgets { send $w setSensitive True }
    } else {
        foreach w $widgets { send $w setSensitive False }
    }
}


# Set the Coords Panel height  depending on the option settings.
proc setCoordPanelHeight args \
{
    global wcsPHeight wcsPOptHeight wcsPTxtHeight wcsPGrHeight
    global tabTop

    if {$tabTop != "wcs_panel"} \
	return

    # Get the height of the text area
    set panel_h $wcsPHeight
    set shrinkage 0
    foreach w { wpWcs1 wpWcs2 wpWcs3 wpWcs4 woptFBinfo } {
	if {[send $w get on] == 0} {
	    incr shrinkage 13
	}
    }
    if {[send woptTitles get on] == 0} {
	incr shrinkage 26
    }

    set ph [expr ($wcsPHeight - $shrinkage)]
    if {[send wcsOptions get on] == 1} {
	incr ph $wcsPOptHeight
    }

    send wcsGroup set height [ expr ($wcsPGrHeight - $shrinkage) ]
    send wcsFrame set height [ expr ($wcsPTxtHeight - $shrinkage) ]
    send panel    set height $ph
}

# Toggle the options display for the panel.
proc wcsOptToggle { widget type state args } \
{
    global wcsPOptHeight
    set h [ send panel get height ] 
    if {$state == 1} {
	send panel set height [ expr ($h + $wcsPOptHeight) ]
    } else { 
	send panel set height [ expr ($h - $wcsPOptHeight) ]
    }
} ; send wcsOptions addCallback wcsOptToggle

# Handle the panel display toggles.
proc wcsCoordsCB { widget type state args } \
{

    set hght [ expr (($state == 1) ? 17 : 4)]
    switch $widget {
    wpWcs1	{ send wtWcs1 set height $hght	}
    wpWcs2	{ send wtWcs2 set height $hght	}
    wpWcs3	{ send wtWcs3 set height $hght	}
    wpWcs4	{ send wtWcs4 set height $hght	}
    woptFBinfo	{ send wtFBCfg set height $hght }
    woptTitles	{ send wtName set height $hght ; send wtTitle set height $hght }
    }
    setCoordPanelHeight                 
}
set wcValues { wpWcs1 wpWcs2 wpWcs3 wpWcs4 woptFBinfo woptTitles }
foreach w $wcValues { send $w addCallback wcsCoordsCB }


# Handle WCS label string options.
set wcsLabels 1
proc wcsLabelsCB { widget type state args } \
{
    global up_todo wcsLabels
    set wcsLabels $state
    #resizeCoordsBox 0
    resizeCoordsBox $up_todo
    updateCoordsBox
} ; send woptLabels addCallback wcsLabelsCB


# Toggle the BPM tracking state.
proc wcsBPMCB { widget type state args } \
{
    global ism_enable
    if ($ism_enable) { catch { send wcspix set bpm $state } }
} ; send woptBPM addCallback wcsBPMCB


# Procedures to format lines in the wcsText box.
proc wcsFmtImname { name } \
{
    send wtName    set string [format "     Name:  %s" [string trimleft $name]]
}

proc wcsFmtImtitle { title } \
{
    send wtTitle   set string [format "    Title:  %s" [string trimleft $title]]
}

proc wcsFmtFBConfig args \
{
    global frameWidth frameHeight frame nframes
    set buf [ format "%5d x %-5d" $frameWidth $frameHeight ]
    set line [ format "Frame Buf:  %-13s             Frame:  %d of %d" \
	[string trimleft $buf] $frame $nframes ]
    send wtFBCfg set string $line
}

proc wcsFmtIValue { value } \
{
    global coord
    set line [ format " Pixel:  %.11s" $value ]
    send wtIPixval set string $line
    if {[info exists coord(ival)]} {
        set coord(ival) $value
        updateCoordsBox
    }
}

proc wcsFmtSValue { value } \
{
    global coord
    set line [ format " Scaled:  %.8s" $value ]
    send wtSPixval set string $line
    set coord(sval) [format "%s" $value]
}

proc wcsFmtBValue { value } \
{
    global coord

    if { [send woptBPM get on] } {
        set line [ format " BPM:  %s" $value ]
        set color [expr { ($value == 0) ? "black" : "red" } ]
        set msg [format "set string \{%s\}; set background %s" $line $color ]
        set coord(bval) [format "%s" $value]
    } else {
        set line [ format " BPM:  (off)" ]
        set msg [format "set string \{%s\}" $line]
    }
    send wtBPixval $msg
}

proc wcsFmtWcs { num wcsname x y xunit yunit args } \
{ 
    global coord coordLab wcsLabels

    if {$wcsLabels} {
        set line [ format "%4s: %12s  %4s: %12s  WCS: %s" \
            $xunit $x $yunit $y [string trimleft $wcsname] ]
    } else {
        set line [ format "%4s  %12s  %4s  %12s       %s" \
            "    " $x "    " $y [string trimleft $wcsname] ]
    }
    send wtWcs$num set string $line

    if {[info exists coord(wcs$num)]} {
	if {$num == 1} {
            set coord(wcs1) [ format "\{%s\} \{%s\} \{%s\}" $x $y $coord(sval) ]
	} elseif {$num == 2} {
            set coord(wcs2) [ format "\{%s\} \{%s\} \{%s\}" $x $y $coord(ival) ]
	} else {
	    set coord(wcs$num) [ format "\{%s\} \{%s\} \{%s\}" $x $y $wcsname  ]
	}

	set coordLab(wcs$num) [ format "\{%s\} \{%s\} \{%s\}" \
	    $xunit $yunit [string trimleft $wcsname ] ]
        updateCoordsBox
    }
}



# Handle the wcsbox readout.
#------------------------------
set  up_todo	  2
set  up_done	  0
set  coord(ival)  0.
set  coord(sval)  0.
set  coord(bval)  0
set  coord(wcs1)  { 0. 0. 0. }
set  coord(wcs2)  { 0. 0. 0. }
set  coord(wcs3)  { 0. 0. 0. }
set  coord(wcs4)  { 0. 0. 0. }

proc wcsCoordB { widget type state args } \
{
    global coord up_todo

    switch $widget {
    wiWcs1	{ set line wcs1  ;set coord($line) { 0. 0. "" } }
    wiWcs2	{ set line wcs2  ;set coord($line) { 0. 0. "" } }
    wiWcs3	{ set line wcs3  ;set coord($line) { 0. 0. "" } }
    wiWcs4	{ set line wcs4  ;set coord($line) { 0. 0. "" } }
    }

    if {$state} {
	incr up_todo
    } else {
	unset coord($line)
	incr up_todo -1
    }

    resizeCoordsBox $up_todo
    updateCoordsBox
}
set wiValues { wiWcs1 wiWcs2 wiWcs3 wiWcs4 }
foreach w $wiValues { send $w addCallback wcsCoordB }


# Resize the coords box depending on the panel options.
proc resizeCoordsBox { nlines } \
{
    global track_enable wcsLabels winWidth winHeight wcsboxGeom 

    if {! $track_enable} \
	return

    send wcsbox getAttributes width cur_w height cur_h 
    set defGeom [format "%sx%s-5-5" $cur_w $cur_h]
    send imagewin parseGeometry $wcsboxGeom $defGeom x y width height

    set ew [expr (($wcsLabels == 1) ? 125 : 65)]

    # Reset to the default geometry
    if {$nlines == 0} {
	set x [expr ($x + $ew)]
	set y [expr ($y + $height - 17 + 1)]
	set new_w  166
	set new_h  17

    } else {
	if {$width > 166} {			;# not using default wcsbox
	    set new_w $width
	} else {
	    set new_w [expr ($width + $ew)]
	    set x [expr ($x - $ew)]
	    if {$wcsLabels == 0} {
		incr x 60
	    }
	}
        set new_h [ expr ($nlines * 17) ]
	set y [expr ($y + $height - $new_h + 1)]
    }

    # Bounds checking.
    if {$x < 5} {
	set x 5
    } elseif {$x > [expr ($winWidth - $new_w - 5)]} {
        set x [expr ($winWidth - $new_w - 5)]
    }
    if {$y < 5} {
	set y 5
    } elseif {$y > [expr ($winHeight - $new_h - 5)]} {
        set y [expr ($winHeight - $new_h - 5)]
    }

    # Finally redraw the marker.
    send wcsbox "\
        setAttributes     \
	    width  $new_w \
	    height $new_h \
	    x	   $x     \
	    y	   $y;    \
	redraw"

    set wcsboxGeom [send imagewin getGeometry $x $y $new_w $new_h]
    send client encodewcs [expr ($winWidth / 2)] [expr ($winHeight / 2)]
    updateCoordsBox
}


# Shortcuts for known WCS labels.
set labels(display)		"TV"
set labels(logical)		"Log"
set labels(physical)		"Phys"
set labels(equatorial)		"Eq"
set labels(ecliptic)		"Ecl"
set labels(galactic)		"Gal"
set labels(supergalactic)	"SGal"
set labels(amplifier)		"Amp"
set labels(ccd)			"CCD"
set labels(detector)		"Det"


# Format the coords box marker with the selected output options.
proc updateCoordsBox args \
{
    global ism_enable coord coordLab wcsLabels
    global up_done up_todo labels track_enable
    global coord

    if {! $ism_enable} \
	return

    incr up_done

    set text ""
    foreach l {wcs1 wcs2 wcs3 wcs4} {
	if {[info exists coord($l)]} {
	    set x [lindex $coord($l) 0]
	    set y [lindex $coord($l) 1]
	    set z [string tolower [string trimleft [lindex $coord($l) 2] ] ]
	    if {[info exists labels($z)]} {
		set z $labels($z)
	    }

	    if {$wcsLabels && [info exists coordLab($l)]} {
	        set lx [lindex $coordLab($l) 0]
	        set ly [lindex $coordLab($l) 1]
	        append text [format " %4s %12.12s %4s %12.12s %9.9s \n" \
		    $lx $x $ly $y $z ]
	    } else {
	        append text [format " %12.12s %12.12s %9.9s \n" $x $y $z ]
	    }
	}
    }

    # Now send the string.
    if {$track_enable} {
	set color [expr { ($coord(bval) == 0) ? "black" : "red" } ]
        set txt [format "set text \{%s\}; set textBgColor %s; redraw noerase" \
		$text $color ]
        send wcsbox $txt
    }

    if {$up_done >= $up_todo} {
        set up_done	0			;# reset counter
    }
}


# Create the WCS format menus.
#------------------------------------
proc setWcsFmt { format line } \
{
    catch { send wcspix set format $format $line }
}

for {set i 1} {$i <= 4} {incr i} {
   set items {}
   lappend items "\"Default\"     f.exec \{setWcsFmt default $i\}"
   lappend items "\"Sexigesimal\" f.exec \{setWcsFmt hms     $i\}"
   lappend items "\"Degrees\"     f.exec \{setWcsFmt deg     $i\}"
   lappend items "\"Radians\"     f.exec \{setWcsFmt rad     $i\}"
   editMenu fmtMenu$i fmtWcs$i $items
}


# Create the default WCS type menus.
#------------------------------------

set defaultWcsMenu {
   { "None"		f.exec	{setWcsSys none     WCS_LINE } }
   { "Display"		f.exec	{setWcsSys display  WCS_LINE } }
   { "World"		f.exec	{setWcsSys world    WCS_LINE } }
   { "Logical"		f.exec	{setWcsSys logical  WCS_LINE } }
   { "Physical"		f.exec	{setWcsSys physical WCS_LINE } }
   { 			f.dblline	}
}

proc setWcsSys { sys line } \
{
    if {[string tolower $sys] == "none"} {
        wcsCoordB wiWcs$line junk 0
        send sysWcs$line set label "None"; send fmtWcs$line set label "Default"
        send wpWcs$line  set on False    ; send wiWcs$line  set on False
        send wtWcs$line  set height 4
	setCoordPanelHeight

    } else {
        catch { send wcspix set wcs $sys $line }
    }
}

proc resetDefaultWcsMenu args \
{
    global defaultWcsMenu

    for {set i 1} {$i <= 4} {incr i} {
        regsub -all WCS_LINE $defaultWcsMenu $i menu_def
        editMenu sysMenu$i sysWcs$i $menu_def
    }
} ; resetDefaultWcsMenu


# Initialize the coordinates panel.
#------------------------------------

proc initCoordsPanel args \
{
    #send wcLine set height 2		;# kludge for label widget

    # Initialize the display strings in the coords box.
    wcsFmtImname   ""
    wcsFmtImtitle  ""
    wcsFmtFBConfig
    wcsFmtIValue  "0." ; wcsFmtSValue "0." ; wcsFmtBValue "0"
    wcsFmtWcs      1 "" "" "" "   X" "   Y"
    wcsFmtWcs      2 "" "" "" "   X" "   Y"
    wcsFmtWcs      3 "" "" "" "   X" "   Y"
    wcsFmtWcs      4 "" "" "" "   X" "   Y"

    send fmtWcs1 set label Default
    send wpWcs1 set on True  ;send wiWcs1 set on True
    send wpWcs2 set on True  ;send wiWcs2 set on True
    send wpWcs3 set on False ;send wiWcs3 set on False ;send wtWcs3 set height 4
    send wpWcs4 set on False ;send wiWcs4 set on False ;send wtWcs4 set height 4

    # Set the Coords Panel height.
    set wcsPTxtHeight [send wcsText get height]
    setCoordPanelHeight

    # Set the WCS readout panel sensitivity.
    setCoordPanelSensitivity

} ; initCoordsPanel




################################################################################
# Compass indicator procedures.
################################################################################

set compassColor	207			;# normally this is yellow
set last_compass	[send compass get on]	;# save compass state

proc drawCompass args \
{
    global ism_enable frame frameCache compassColor Compass Orient
    global panner_x panner_y panner_width panner_height cur_objid
    global redraw_compass last_compass

	
    if {! [send compass get on]} \
	return

    eraseCompass 				;# erase the old compass

    if {! [info exists frameCache($frame)] } {
        set id -1
    } elseif {$cur_objid != [lindex $frameCache($frame) 1]} {
        set id [lindex $frameCache($frame) 1]
    } else {
        set id $cur_objid
    }

    if { [info exists Compass($id)] } {
        set angle     [lindex $Compass($id) 0]
        set north_x   [lindex $Compass($id) 1]
        set north_y   [lindex $Compass($id) 2]
        set east_x    [lindex $Compass($id) 3]
        set east_y    [lindex $Compass($id) 4]
        set transpose [lindex $Compass($id) 5]
        set xlab      [lindex $Compass($id) 6]
        set ylab      [lindex $Compass($id) 7]
    } else {
	set north_x  0.0   	; set north_y  1.0
	set east_x   1.0	; set east_y   0.0
	set xlab       X   	; set ylab       Y
        set angle    0.0   	; set transpose  0
	set Compass($id) { 0.0 1.0 0.0 1.0 0.0 0 X Y }
    }
    set xflip 1
    set yflip 1

    # Adjust the compass for the display orientation (e.g. image sections
    # used to flip an image during display).
    if { [info exists Orient($id)] } {
        set xflip [expr $xflip * [lindex $Orient($id) 1] ]
        set yflip [expr $yflip * [lindex $Orient($id) 2] ]
    }

    # Get the panner center position.
    set pcx [expr ($panner_x + $panner_width  / 2)]
    set pcy [expr ($panner_y + $panner_height / 2)]

    # Setup for the overlay.
    send imagewin getLogRes  sv_xl sv_yl
    send imagewin getPhysRes sv_xp sv_yp
    send imagewin setLogRes $sv_xp $sv_yp
    send imagewin setLineWidth 2

    set xflip [ expr ($xflip * ([send xflipButton get state] ?  -1 : 1))]
    set yflip [ expr ($yflip * ([send yflipButton get state] ?  -1 : 1))]

    # Normalized compass points.  The first row are the axes, second is
    # the pointer head, and last are the X/Y label coords.  Assumes a
    # zero rotation with North up and East left, or standard X/Y orientation.
    set cpoints {
	{-1 0} {0 0} {0 -1}
	{-0.07 -0.85} {0 -1} {0.07 -0.85} {-0.07 -0.85}
	{-1.2 0} {0 -1.2}
    }


    # Get rotation and scale factors.
    set angle [expr "atan2($north_y,$north_x)"]
    set coso  [expr "cos (-$angle)"]
    set sino  [expr "sin (-$angle)"]
    set scale [expr ([min $panner_width $panner_height] * 0.3)]

    # Initialize the drawing points.
    set pts {}

    set cpoints { }
    lappend cpoints [list $east_x  $east_y ]
    lappend cpoints [list 0 0]
    lappend cpoints [list $north_x $north_y]
    foreach p $cpoints {
	# Get the scaled position.
	set sx [expr ($scale * [lindex $p [expr "($transpose > 0) ? 1 : 0"]])]
	set sy [expr ($scale * [lindex $p [expr "($transpose > 0) ? 0 : 1"]])]

	# Translate to the scaled position.
	set rx [expr int($pcx + $sx + 0.5)]
	set ry [expr int($pcy - $sy + 0.5)]

	# Now handle the axis flip.
	set rx [expr (($xflip < 0) ? ($pcx + ($pcx - $rx)) : $rx)]
	set ry [expr (($yflip < 0) ? ($pcy + ($pcy - $ry)) : $ry)]
	lappend pts $rx $ry
    }


    set rpoints { }
    set hpoints { {0.0 0.0} {-0.1 -0.07} {-0.1 0.07} {0.0 0.0} }
    foreach p $hpoints {
	# Break out the position.
	set sx [lindex $p [expr "($transpose > 0) ? 1 : 0"]]
	set sy [lindex $p [expr "($transpose > 0) ? 0 : 1"]]

	# Do the rotation of the head at the origin.
	set rx [expr ($north_x + ($sx * $coso + $sy * $sino))]
	set ry [expr ($north_y - ($sx * $sino + $sy * $coso))]

	lappend rpoints [list $rx $ry]
    }
    foreach p $rpoints {
	# Get the scaled position.
	set sx [expr ($scale * [lindex $p [expr "($transpose > 0) ? 1 : 0"]])]
	set sy [expr ($scale * [lindex $p [expr "($transpose > 0) ? 0 : 1"]])]

	# Translate to the scaled position.
	set rx [expr int($pcx + $sx + 0.5)]
	set ry [expr int($pcy - $sy + 0.5)]

	# Now handle the axis flip.
	set rx [expr (($xflip < 0) ? ($pcx + ($pcx - $rx)) : $rx)]
	set ry [expr (($yflip < 0) ? ($pcy + ($pcy - $ry)) : $ry)]
	lappend pts $rx $ry
    }

    set lpoints { }
    lappend lpoints [list [expr "$east_x-0.2"] $east_y ]
    lappend lpoints [list $north_x [expr "$north_y+0.2"] ]
    foreach p $lpoints {
	# Get the scaled position.
	set sx [expr ($scale * [lindex $p [expr "($transpose > 0) ? 1 : 0"]])]
	set sy [expr ($scale * [lindex $p [expr "($transpose > 0) ? 0 : 1"]])]

	# Translate to the scaled position.
	set rx [expr int($pcx + $sx + 0.5)]
	set ry [expr int($pcy - $sy - 0.5)]

	# Now handle the axis flip.
	set rx [expr (($xflip < 0) ? ($pcx + ($pcx - $rx)) : $rx)]
	set ry [expr (($yflip < 0) ? ($pcy + ($pcy - $ry)) : $ry)]
	lappend pts $rx $ry
    }


    # Draw the compass axes.
    set compassPts [lrange $pts 0 5]
    send imagewin setColorIndex $compassColor
    send imagewin drawPolyline $compassPts

    
    # Draw the compass pointer.
    set head [lrange $pts 6 13]
    send imagewin setFillType solid
    send imagewin drawPolygon $head

    # Draw the labels.
    send imagewin drawAlphaText [lindex $pts 14] [lindex $pts 15] $xlab
    send imagewin drawAlphaText [lindex $pts 16] [lindex $pts 17] $ylab

    send imagewin setLogRes $sv_xl $sv_yl

    set redraw_compass 0

} ; foreach w {xflip yflip} { send $w addCallback drawCompass }


# This is a kludge to redraw the compass after it is erased when displaying
# a new image.  Once the user moves the mouse back into the main window we'll
# do the redraw.
send imagewin addEventHandler drawCompass enterWindowMask



proc createCompassMarker { pts args } \
{
    set cm_points { }
    lappend cm_points [lrange $pts 0 1]
    lappend cm_points [lrange $pts 2 3]
    lappend cm_points [lrange $pts 4 5]

    print [list $cm_points]

}


proc eraseCompass args \
{
    global panner_mapping
    send imagewin refreshMapping $panner_mapping
}

proc toggleCompass { widget type state args } \
{
    global last_compass

    if {$state} {
	drawCompass
	set last_compass True
    } else {
	eraseCompass
	set last_compass False
    }
} ; send compass addCallback toggleCompass



     
################################################################################
# RULER MARKERS
################################################################################

set rulerX	0			;# ruler start in screen coords
set rulerY	0
set rulerPts	{ {0 0} {0 0} {0 0} }	;# ruler vertices
set rulerList	{ }			;# ruler list

set rulerSticky	{ }			;# list of sticky rulers
set isSticky	"Sticky"		;# menu label

set rulerWCS	0			;# use WCS coords
set rulerXWCS	0			;# ruler start in WCS units
set rulerYWCS	0
set rulerXWCS2	0			;# ruler end in WCS units
set rulerYWCS2	0
set rulerFmt	pixel			;# ruler label format


# Translations when pointer is inside marker.
set rulerTranslations { \
      !Ctrl <Key>b: call(prevFrame,$name)
      !Ctrl <Key>b: call(prevFrame,$name)
      !Ctrl <Key>f: call(nextFrame,$name)
      !Ctrl <Key>h: call(move_cursor,-1,0)
      !Ctrl <Key>j: call(move_cursor,0,1)
      !Ctrl <Key>k: call(move_cursor,0,-1)
      !Ctrl <Key>l: call(move_cursor,1,0)
      !Ctrl <Key>n: call(normalize)
      !Ctrl <Key>c: call(cpZoomAction,centerFrame)
      !Ctrl <Key>i: call(cpInvert)
      !Ctrl <Key>m: call(cpMatchFrames)
      !Ctrl <Key>r: call(cpRegisterFrames)
      !Ctrl <Key>p: call(togglePanner)
       !Alt <Key>1: call(cpSetFrame,frame1)
       !Alt <Key>2: call(cpSetFrame,frame2)
       !Alt <Key>3: call(cpSetFrame,frame3)
       !Alt <Key>4: call(cpSetFrame,frame4)
      !Ctrl <Key>1: call(cpZoom,1,1,fixed)
      !Ctrl <Key>2: call(cpZoom,2,2,fixed)
      !Ctrl <Key>3: call(cpZoom,3,3,fixed)
      !Ctrl <Key>4: call(cpZoom,4,4,fixed)
      !Ctrl <Key>5: call(cpZoom,5,5,fixed)
      !Ctrl <Key>6: call(cpZoom,6,6,fixed)
      !Ctrl <Key>7: call(cpZoom,7,7,fixed)
      !Ctrl <Key>8: call(cpZoom,8,8,fixed)
      !Ctrl <Key>9: call(cpZoom,9,9,fixed)
    <Key>BackSpace: call(deleteNamedRuler,NAME,$x,$y)
       <Key>Delete: call(deleteNamedRuler,NAME,$x,$y)
	<KeyPress>: m_input()
	<Btn3Down>: call(setRulerMenu) popup(rulerMenu)
	  <Btn3Up>: popdown(rulerMenu)
!Ctrl <Btn1Motion>: track-cursor() call(wcsUpdate,$x,$y) call(resizeRuler,$x,$y,0)
    !Ctrl <Btn1Up>: call(deleteRuler,$x,$y)
	  <Motion>: track-cursor() call(wcsUpdate,$x,$y) call(magnifierMapImage,$x,$y)
}



# Popup menu in effect when inside marker.
set rulerMenuDescription {
    {	"Ruler"    	  f.title			}
    {		    	  f.dblline			}
    {	"$isSticky"	  f.exec { 
			      toggleSticky $ruler
			  }				}
    {		    	  f.line			}
    {	"Units"	  	  f.menu rulerUnits		}
    {	"Color"	  	  f.menu rulerColor		}
    {		    	  f.line			}
    {	"Draw into Frame" f.exec { 
			      writeRuler $ruler
			  } sensitive False		}
    {		    	  f.line			}
    {	"Destroy"	  f.exec { 
		              scan $ruler "ruler%d" num
		              deleteNamedRuler $num x y
		    	  }				}
} ; createMenu rulerMenu imagewin $rulerMenuDescription

set rulerUnitsDescription {
    {	Units		f.title				  }
    {			f.dblline			  }
    {	"Pixels"	f.exec { setUnits $ruler pixel  } }
    {	"Arc Seconds"  	f.exec { setUnits $ruler arcsec  
			} sensitive { ($rulerWCS > 0) ? "True" : "False"} }
    {	"Arc Minutes"   f.exec { setUnits $ruler arcmin  
			} sensitive { ($rulerWCS > 0) ? "True" : "False"} }
    {	"Degrees"   	f.exec { setUnits $ruler degrees 
			} sensitive { ($rulerWCS > 0) ? "True" : "False"} }
} ; createMenu rulerUnits rulerMenu $rulerUnitsDescription

set rulerColorDescription {
    {	Color	f.title					}
    {		f.dblline				}
    {	""	f.exec "r_setColor $ruler black yellow"
		    bitmap solid foreground black 	}
    {	""	f.exec "r_setColor $ruler white black" 
		    bitmap solid foreground white 	}
    {	""	f.exec "r_setColor $ruler red yellow" 
		    bitmap solid foreground red 	}
    {	""	f.exec "r_setColor $ruler green black" 
		    bitmap solid foreground green 	}
    {	""	f.exec "r_setColor $ruler blue white" 
		    bitmap solid foreground blue 	}
    {	""	f.exec "r_setColor $ruler magenta black" 
		    bitmap solid foreground magenta 	}
    {	""	f.exec "r_setColor $ruler cyan black" 
		    bitmap solid foreground cyan 	}
    {	""	f.exec "r_setColor $ruler yellow black" 
		    bitmap solid foreground yellow 	}
} ; createMenu rulerColor rulerMenu $rulerColorDescription


proc makeRuler {parent x y} \
{
    global rulerTranslations ruleno rulerWCS rulerXWCS rulerYWCS
    global rulerPts rulerX rulerY rulerList
    global isSticky rulerMenuDescription rulerUnitsDescription
    global coord coordLab


    incr ruleno ; set ruler ruler$ruleno

    # Substitute so the marker translation will delete the marker
    # by it's number rather than the default parent widget name.
    regsub -all NAME $rulerTranslations $ruleno translations

    # Create the polygon for the marker.
    send $parent createMarker $ruler \
	type		polygon\
	createMode	noninteractive\
	translations	$translations\
        lineColor       yellow\
        fill       	False\
        highlightWidth  1\
        highlightColor  yellow\
        knotSize        0\
        activated       True\
        visible         False\
        sensitive       True\
	x		$x\
	y		$y

    # Define a callback so we can identify the ruler.
    send $ruler addCallback selectRuler focusIn focusOut

    # Create the text markers for the labels.
    send $parent set markerTextFont 6x9
    makeLabelMarker $parent rulerXlab$ruleno 5ch 1ch
    makeLabelMarker $parent rulerYlab$ruleno 5ch 1ch
    makeLabelMarker $parent rulerHlab$ruleno 8ch 1ch
    send $parent set markerTextFont 6x13

    set rulerX	$x				;# save the reference point
    set rulerY	$y

    set ref [ list $x $y ]			;# initialize the polygon
    set rx [ list [expr "$x +1"] $y ]
    set ry [ list $x [expr "$y +1"] ]
    set rulerPts [list $ref $rx $ry ]

    send $ruler setVertices $rulerPts		;# set attributes
    send $ruler set visible True"
    send $ruler setAttribute autoRedraw True

    # See whether we have a WCS to use.
    set rulerWCS  0
    set rulerXWCS 0
    set rulerYWCS 0
    for {set num 1} {$num <= 4 && $rulerWCS == 0} {incr num} {
	if { [info exists coordLab(wcs$num)] } {
	    set xl  [string tolower [lindex $coordLab(wcs$num) 0]]
	    set yl  [string tolower [lindex $coordLab(wcs$num) 1]]
	    set fmt [string tolower [send fmtWcs$num get label] ]
	    if {$xl=="  ra" || $xl=="elon" || $xl=="glon" || $xl=="slon"} {
		set rulerWCS $num
        	set rulerXWCS [wcs2log [lindex $coord(wcs$num) 0] $xl $fmt]
        	set rulerYWCS [wcs2log [lindex $coord(wcs$num) 1] $yl $fmt]
	    }
	}
    }

    # Edit the menus.
    set isSticky "Sticky"
    editMenu rulerMenu  imagewin $rulerMenuDescription
    editMenu rulerUnits imagewin $rulerUnitsDescription


    lappend rulerList $ruleno
}

proc wcs2log { val label fmt} \
{
    set newval $val
    if {$fmt == "sexigesimal" || $fmt == "default"} {
	scan $val "%d:%d:%f"  h m s
	set newval [expr "double($h) + double($m) / 60.0 + double($s) / 3600.0"]
	if {$label == "  ra"} {
	    set newval [expr "double($newval * 15.0)"]
	}
    }
    return [expr "double($newval)" ]
}


proc resizeRuler {x y redraw} \
{
    global rulerPts rulerX rulerY ruleno coord coordLab
    global rulerWCS rulerXWCS rulerYWCS rulerFmt
    global rulerXWCS2 rulerYWCS2


    # Track the mouse.
    set ref [ list $rulerX $rulerY ]
    set rx  [ list $x      $rulerY ]
    set ry  [ list $x      $y      ]
    set rulerPts [list $ref $rx $ry ]

    # Compute the distances.
    if {$rulerWCS > 0} {
 	set num $rulerWCS
	set xl  [string tolower [lindex $coordLab(wcs$num) 0]]
	set yl  [string tolower [lindex $coordLab(wcs$num) 1]]
	set fmt [string tolower [send fmtWcs$num get label] ]

	# Save the cursor coords in WCS so we can convert labels.
	if {$redraw} {
            set nx $rulerXWCS2
            set ny $rulerYWCS2
	} else {
            set nx  [wcs2log [lindex $coord(wcs$num) 0] $xl $fmt]
       	    set ny  [wcs2log [lindex $coord(wcs$num) 1] $yl $fmt]
            set rulerXWCS2 $nx
            set rulerYWCS2 $ny
	}
    }

    if {$rulerFmt == "pixel"} {
        set xdist [ expr "abs($x - $rulerX)" ]
        set ydist [ expr "abs($y - $rulerY)" ]
        set hdist [ expr "sqrt($xdist * $xdist + $ydist * $ydist)" ]
    } else {
        set xdist [ expr "abs($nx - $rulerXWCS)" ]
        set ydist [ expr "abs($ny - $rulerYWCS)" ]
        set hdist [ expr "sqrt($xdist * $xdist + $ydist * $ydist)" ]
    }

    # Redraw the polygon.
    send ruler$ruleno setVertices $rulerPts

    # Label the distances.
    setXRulerLabel $x $y $xdist
    setYRulerLabel $x $y $ydist
    setHRulerLabel $x $y $hdist
}

# Create a label marker for the ruler.
proc makeLabelMarker { parent name width height } \
{
    send $parent createMarker $name \
        type            text \
        createMode      noninteractive \
        width           $width \
        height          $height \
        lineWidth       0 \
        imageText       true \
        textBgColor     yellow \
        textColor       black \
        activated       true \
        visible         false
}

proc setXRulerLabel { cx cy dist } \
{
    global rulerX rulerY ruleno winWidth winHeight
    global cpXscale rulerFmt

    send rulerXlab$ruleno set visible False

    if {[expr "abs($cx - $rulerX)"] > 30} {
	switch $rulerFmt {
	pixel	{ set text [format "%.1f" [expr "$dist / $cpXscale"] ]	}
	arcsec	{ set text [format "%.2f\"" [expr "$dist * 3600.0"] ] 	}
	arcmin	{ set text [format "%.2f\'" [expr "$dist * 60.0"] ] 	}
	degrees	{ set text [format "%.2fd" "$dist" ] 			}
	}
	set len [expr [string length $text] + 1]
	send rulerXlab$ruleno "set width ${len}ch"

	# Compute the placement of the label marker.
	if {$cy > $rulerY} {
	    set yp [expr "$rulerY - 14"]
	} else {
	    set yp [expr "$rulerY + 2"]
	}
	if {$cx > $rulerX} {
	    set xp [expr "$rulerX + abs($cx - $rulerX)/2 - 10"]
	} else {
	    set xp [expr "$rulerX - abs($cx - $rulerX)/2 - 10"]
	}

	# Bounds checking.
	if {$xp < 0} { set xp 1 }
	if {$yp < 0} { set yp 1 }
	if {$xp > $winWidth}  { set xp [expr "$winWidth - 20" }
	if {$yp > $winHeight} { set yp [expr "$winHeight - 20" }

	send rulerXlab$ruleno "setAttributes x $xp y $yp"
	send rulerXlab$ruleno "set text \{$text\}; redraw erase"

	send rulerXlab$ruleno set visible True
    }
}

proc setYRulerLabel { cx cy dist } \
{
    global rulerX rulerY ruleno winWidth winHeight
    global cpYscale rulerFmt

    send rulerYlab$ruleno set visible False

    if {[expr "abs($cy - $rulerY)"] > 20} {
	switch $rulerFmt {
	pixel	{ set text [format "%.1f" [expr "$dist / $cpYscale"] ]	}
	arcsec	{ set text [format "%.2f\"" [expr "$dist * 3600.0"] ] 	}
	arcmin	{ set text [format "%.2f\'" [expr "$dist * 60.0"] ] 	}
	degrees	{ set text [format "%.2fd" "$dist" ] 			}
	}
	set len [expr [string length $text] + 1]
	send rulerYlab$ruleno "set width ${len}ch"

	# Compute the placement of the label marker.
	if {$cx > $rulerX} {
	    set xp [expr "$cx + 2"]
	} else {
	    set xp [expr "$cx - $len * 6 - 5"]
	}
	if {$cy > $rulerY} {
	    set yp [expr "$rulerY + abs($cy - $rulerY)/2"]
	} else {
	    set yp [expr "$rulerY - abs($cy - $rulerY)/2"]
	}

	# Bounds checking.
	if {$xp < 0} { set xp 1 }
	if {$yp < 0} { set yp 1 }
	if {$xp > $winWidth}  { set xp [expr "$winWidth - 20" }
	if {$yp > $winHeight} { set yp [expr "$winHeight - 20" }

	send rulerYlab$ruleno "setAttributes x $xp y $yp"
	send rulerYlab$ruleno "set text \{$text\}; redraw erase"
	send rulerYlab$ruleno set visible True
    } 
}

proc setHRulerLabel { cx cy dist } \
{
    global rulerX rulerY ruleno winWidth winHeight
    global cpYscale cpXscale rulerFmt

    send rulerHlab$ruleno set visible False

    set xdist [ expr "abs($cx - $rulerX)" ]
    set ydist [ expr "abs($cy - $rulerY)" ]
    set hdist [ expr "sqrt($xdist * $xdist + $ydist * $ydist)" ]

    if {$hdist > 30} {
	switch $rulerFmt {
	pixel	{ set text [format "%.1f" [expr "$dist / $cpXscale"] ]	}
	arcsec	{ set text [format "%.2f\"" [expr "$dist * 3600.0"] ] 	}
	arcmin	{ set text [format "%.2f\'" [expr "$dist * 60.0"] ] 	}
	degrees	{ set text [format "%.2fd" "$dist" ] 			}
	}
	set len [expr [string length $text] + 1]
	send rulerHlab$ruleno "set width ${len}ch"

	# Compute the placement of the label marker.
	if {$cx > $rulerX} {
	    set xp [expr "$rulerX + abs($cx - $rulerX)/2 - $len * 6"]
	} else {
	    set xp [expr "$rulerX - abs($cx - $rulerX)/2 - $len * 3"]
	}
	if {$cy > $rulerY} {
	    set yp [expr "$rulerY + abs($cy - $rulerY)/2"]
	} else {
	    set yp [expr "$rulerY - abs($cy - $rulerY)/2"]
	}

	# Bounds checking.
	if {$xp < 0} { set xp 1 }
	if {$yp < 0} { set yp 1 }
	if {$xp > $winWidth}  { set xp [expr "$winWidth - 20" }
	if {$yp > $winHeight} { set yp [expr "$winHeight - 20" }

	send rulerHlab$ruleno "setAttributes x $xp y $yp"
	send rulerHlab$ruleno "set text \{$text\}; redraw erase"
	send rulerHlab$ruleno set visible True
    } else {
	send rulerHlab$ruleno set visible False
    }
}


# Callback executed when a marker gets or loses the focus.
proc selectRuler {active_ruler event event_data} \
{
    global ruler
    switch $event {
	focusIn		{ set ruler $active_ruler }
	focusOut	{  }
    }
}

# Reset the ruler format type.
proc setUnits { ruler units } \
{
    global rulerFmt rulerX rulerY

    send $ruler getVertices pts
    set rulerX [lindex [lindex [lindex $pts 0] 0] 0]
    set rulerY [lindex [lindex [lindex $pts 0] 0] 1]
    set cx [lindex [lindex [lindex $pts 0] 1] 0] ; incr cx -1
    set cy [lindex [lindex [lindex $pts 0] 2] 1] ; incr cy -1

    set rulerFmt $units
    resizeRuler $cx $cy 1
}

# Menu option toggle callbacks.
proc toggleSticky { ruler } \
{
    global isSticky rulerSticky rulerMenuDescription

    set index [ lsearch $rulerSticky $ruler]
    if { $index >= 0 } {
	# Remove it from the list.
    	set rulerSticky [lreplace $rulerSticky $index $index]
	set isSticky "Sticky"
    } else {
	# Add it to the list.
	lappend rulerSticky $ruler 
	set isSticky "UnSticky"
    }
    editMenu rulerMenu imagewin $rulerMenuDescription
}

proc setRulerMenu args \
{
    global ruler isSticky rulerSticky rulerMenuDescription

    if { [lsearch $rulerSticky $ruler] >= 0 } {
	set isSticky "UnSticky"
    } else {
	set isSticky "Sticky"
    }
    editMenu rulerMenu imagewin $rulerMenuDescription
}


# Draw the ruler to the frame buffer as a graphic.
proc writeRuler { ruler } \
{
}

# Change the color of the ruler.
proc r_setColor {ruler bgcolor fgcolor}  {
			    
    # Recolor the polygon.
    send $ruler \
	"markpos; set lineColor $bgcolor; set highlightColor $bgcolor; redraw"

    # Recolor the labels.
    scan $ruler "ruler%d" num
    send rulerXlab$num \
	"markpos; set textBgColor $bgcolor; set textColor $fgcolor; redraw"
    send rulerYlab$num \
	"markpos; set textBgColor $bgcolor; set textColor $fgcolor; redraw"
    send rulerHlab$num \
	"markpos; set textBgColor $bgcolor; set textColor $fgcolor; redraw"
}


# Delete the current ruler, called when we have a Btn1Up on the current ruler.
proc deleteRuler {x y} { global ruleno ; deleteNamedRuler $ruleno $x $y }

# Delete all rulers on the screen, usually called when the view changes.
# We preserve the rulers marked as 'sticky'.
proc deleteAllRulers args \
{
    global rulerList rulerSticky

    foreach r $rulerList { 
        # Delete the ruler if it's not in the sticky list.
        if { [lsearch $rulerSticky ruler$r] == -1 } {
	    deleteNamedRuler $r x y 
        }
    }
}

# Delete a particular ruler, usually called from the translation table on
# the marker itself.
proc deleteNamedRuler {name x y} \
{
    global rulerList

    catch {
	send ruler$name      destroy
	send rulerXlab$name  destroy
	send rulerYlab$name  destroy
	send rulerHlab$name  destroy
    }

    # Remove the ruler from the list.
    set index [lsearch $rulerList $name]
    set rulerList [lreplace $rulerList $index $index]
}





###############################################
# Define procedure for the help panel
###############################################

# Help Panel Bitmaps
#-------------------
createBitmap iraf_logo 45 45 {
0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff,
0xff, 0x3f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0xff,
0xff, 0x3f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xf0, 0xff, 0xff, 0xff,
0xff, 0x3f, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xe0, 0xff, 0xff, 0xff,
0xff, 0x3f, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xc0, 0xff, 0xff, 0xff,
0xff, 0x3f, 0x80, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x80, 0xfc, 0xff, 0xff,
0xff, 0x3f, 0x84, 0xf8, 0xff, 0xff, 0xff, 0x1f, 0x84, 0xf4, 0xff, 0xff,
0xff, 0x1b, 0x04, 0x09, 0x00, 0xfc, 0xff, 0x11, 0x04, 0x11, 0xf8, 0xff,
0x7f, 0x10, 0x04, 0x21, 0xc0, 0xff, 0x1f, 0x10, 0x04, 0x41, 0xf0, 0xff,
0x00, 0x18, 0x04, 0x01, 0xe0, 0xff, 0x00, 0x18, 0x00, 0x81, 0xc0, 0xff,
0x00, 0x08, 0x00, 0x01, 0xe0, 0xff, 0x07, 0x08, 0x00, 0x01, 0xf1, 0xff,
0x1f, 0x08, 0x80, 0x21, 0xf0, 0xff, 0xff, 0x08, 0xc0, 0x41, 0xf4, 0xff,
0xff, 0x08, 0xc0, 0x41, 0xf8, 0xff, 0xff, 0x09, 0xc0, 0xc1, 0xf0, 0xff,
0xff, 0x0b, 0x80, 0xc1, 0xf1, 0xff, 0xff, 0x07, 0x80, 0x81, 0xe1, 0xff,
0xff, 0x07, 0x80, 0x01, 0xc1, 0xff, 0xff, 0x07, 0x00, 0x01, 0xc0, 0xff,
0xff, 0x07, 0xc2, 0x05, 0x81, 0xff, 0xff, 0x07, 0xf2, 0x07, 0x81, 0xff,
0xff, 0x07, 0xf2, 0x17, 0x03, 0xff, 0xff, 0x03, 0xfa, 0x7f, 0x02, 0xfe,
0xff, 0x03, 0xfe, 0xff, 0x02, 0xfe, 0xff, 0x03, 0xfe, 0xff, 0x03, 0xfc,
0xff, 0x03, 0xff, 0xff, 0x07, 0xfc, 0xff, 0x83, 0xff, 0xff, 0x0f, 0xf8,
0xff, 0xc1, 0xff, 0xff, 0x3f, 0xf0, 0xff, 0xe1, 0xff, 0xff, 0x7f, 0xf8,
0xff, 0xf1, 0xff, 0xff, 0xff, 0xf0, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xe0,
0xff, 0xf8, 0xff, 0xff, 0xff, 0xe3, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xe7,
0xff, 0xfc, 0xff, 0xff, 0xff, 0xef}; send helpIRAFLogo "set bitmap iraf_logo"
 
createBitmap noao_logo 45 45 {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xfe, 0xff, 0xff,
0xff, 0xff, 0x01, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0xff, 0xff,
0xff, 0xff, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0xff, 0xff,
0xff, 0x7f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0xff, 0xff,
0xff, 0xff, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0xff, 0xff,
0xff, 0xff, 0x01, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x03, 0xfe, 0xff, 0xff,
0xff, 0xff, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xff, 0xff, 0xff,
0xff, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xff,
0xff, 0xff, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xff, 0xff, 0xff,
0xff, 0xff, 0x03, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x03, 0xfe, 0xff, 0xff,
0xff, 0xff, 0x01, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x01, 0xfc, 0xff, 0xff,
0xff, 0xff, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x7f, 0x00, 0xf0, 0xff, 0xff,
0xff, 0x7f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x3f, 0x00, 0xe0, 0xff, 0xff,
0xff, 0x3f, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x1f, 0x00, 0xc0, 0xff, 0xff,
0xff, 0x1f, 0x00, 0xc0, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x80, 0xff, 0xff,
0xff, 0x0f, 0x00, 0x80, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff,
0xff, 0x03, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x03, 0x00, 0x00, 0xfe, 0xff,
0xff, 0x01, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x01, 0x00, 0x00, 0xfc, 0xff,
0xff, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x00, 0xf8, 0xff,
0x7f, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x7f, 0x00, 0x00, 0x00, 0xf0, 0xff,
0x3f, 0x00, 0x00, 0x00, 0xe0, 0xff}; send helpNOAOLogo "set bitmap noao_logo"
  
send helpInfo1 set label $version

# Stuff for keeping track of visited anchors.
set links       { 0 }
set linkIndex     0
set visited(0)  empty

proc Help args \
{
    global help_up
    if {$help_up == 0} {
	send client help
    } else {
	send help_panel unmap
	set help_up 0
    } 
}

proc helpPanel args \
{
    global help_up
    if {$help_up} {
	send help_panel unmap
	set help_up 0
    } else {
	send help_panel map
	set help_up 1
    }
}

proc panelHelp args \
{
    Help
} ; send panelHelp addCallback panelHelp

proc helpQuit args \
{
    global help_up
    send help_panel unmap
    set help_up 0
}; send helpClose addCallback helpQuit

proc getHelpText { param old new } \
{
    send helpText setText $new
    helpPanel
}; send help addCallback getHelpText

proc anchorSelected {widget cbtype event text href args} \
{
    global visited links linkIndex
    set anchID [send helpText anchorToId $href]
    set visited($href) 1
    if {$linkIndex == 0} {
	send helpBack setSensitive True
	if {[lindex $links 1] != $anchID} {
	    set links { 0 }
	    send helpForward setSensitive False
	}
    }
    if {$linkIndex > 0 && [lindex $links [expr $linkIndex + 1]] != $anchID} {
	set links [lrange $links 0 $linkIndex]
    }
    if {[lindex $links [expr $linkIndex + 1]] != $anchID} {
	lappend links $anchID
	incr linkIndex
    } else {
	send helpForward setSensitive False
	incr linkIndex
    }
    if {$linkIndex == [expr [llength $links] - 1]} {
	send helpForward setSensitive False
    }
    send helpText gotoId $anchID
    send helpText retestAnchors
}; send helpText addCallback anchorSelected anchor     

proc testAnchor {widget cbtype href} \
{
    global visited
    return [info exists visited($href)]
}; send helpText addCallback testAnchor testAnchor


# Callbacks to position forwards and backwards in link list.
proc hlpForward args \
{
    global links linkIndex
    incr linkIndex
    if {$linkIndex <= [llength $links]} {
	set anchID [lindex $links $linkIndex]
	send helpText gotoId $anchID
	send helpText retestAnchors
	if {$linkIndex == [expr [llength $links] - 1]} {
	    send helpForward setSensitive False
	    send helpBack setSensitive True
	} else {
	    send helpBack setSensitive True
	}
    } else {
	incr linkIndex -1
    }
}; send helpForward addCallback hlpForward
       
proc hlpBack args \
{
    global links linkIndex
    incr linkIndex -1
    if {$linkIndex >= 0} {
	set anchID [lindex $links $linkIndex]
	send helpText gotoId $anchID
	send helpText retestAnchors
	if {$linkIndex == 0} { send helpBack setSensitive False   }
	if {$linkIndex >= 0} { send helpForward setSensitive True }
    } else {
	incr linkIndex 1
    }
}; send helpBack addCallback hlpBack

proc hlpHome args \
{
    global links linkIndex
    set links { 0 }
    set linkIndex  0
    send helpText gotoId 0
    send helpForward setSensitive False
    send helpBack setSensitive False
}; send helpHome addCallback hlpHome


proc helpFind args \
{
    set phrase  [send hfEntry get string]

    if { $phrase != "" } {
        if {[send helpText searchText $phrase start end forward caseless] > 0} {
            set elid [lindex [lindex $start 0] 0]
            set id   [max 1 [expr $elid - 10] ]
            send helpText gotoId $id
            send helpText setSelection $start $end
        } else {
            send warnText set label "Search string not found."
            send warning map
        }
    } else {
        send warnText set label "Warning: No search phrase entered."
        send warning map
    }
} ; foreach w { hfEntry hfFind } { send $w addCallback helpFind }

send hfClear addCallback { send hfEntry set string "" }


################################################################################
#  Header Display Callbacks.
################################################################################

set hdrImage		""
set hdrImageId		""
set hdrKeywords		"*"


proc fitsHdrClose args \
{
    global hdr_up

    send hdr_panel unmap
    send imageHeader set on False
    set hdr_up 0
} ; send hdrClose addCallback fitsHdrClose

proc ptFitsHeader {widget type state args} \
{
    global hdr_up

    set hdr_up $state
    if {$hdr_up == 1} {
	send imageHeader set on True
	send hdr_panel map
    } else {
	send imageHeader set on False
	send hdr_panel unmap
    }
}; send imageHeader addCallback ptFitsHeader

proc getHeader { name id } \
{
    global hdrImage hdrImageId hdrKeywords

    set hdrImage $name
    set hdrImageId $id
    send hdrObjMenu set label $name
    send hdrText   setText ""
    send hdrIGText set string ""
    send hdrKGText set string ""

    catch { send wcspix objinfo $hdrImageId $hdrKeywords }
}

proc hdrKeywFilter args \
{
    global hdrImageId hdrKeywords

    set str [ send hFindEntry get string ]
    if {$str != ""} {
	set hdrKeywords $str
	send hdrText setText ""
	catch { send wcspix objinfo $hdrImageId $hdrKeywords }
    }
} ; send hdrFilter addCallback hdrKeywFilter


# Set the image menu in the header panel.
proc setHdrObjMenu { frame args } \
{
    global frameCache ism_enable

    if {! $ism_enable} \
	return

    # Create the menu of images for the header panel.
    set items { }
    foreach i [list $frameCache($frame)] {
        set l [lindex $i 0]
        set lid [lindex $i 1]
        regsub -all {[\[]} $l  "\\\[" l2
	catch {
            lappend items [format "%s f.exec \{getHeader %s %d\}" $l $l2 $lid]
	}
    }
    editMenu objMenu hdrObjMenu $items
}


# Search box for the header.
proc hdrFind args \
{
    set phrase  [send hFindEntry get string]

    if { $phrase != "" } {
        if {[send hdrText searchText $phrase start end forward caseless] > 0} {
            set elid [lindex [lindex $start 0] 0]
            set id   [max 1 [expr $elid - 10] ]
            send hdrText gotoId $id
            send hdrText setSelection $start $end
        } else {
            send warnText set label "Search string not found."
            send warning map
        }
    } else {
        send warnText set label "Warning: No search phrase entered."
        send warning map
    }
} ; foreach w { hFindEntry hdrFind } { send $w addCallback hdrFind }

send hdrClear addCallback { send hFindEntry set string "" }


################################################################################
#  Pixel Table Callbacks.
################################################################################

set psize	5
set pixtab_up	0
set hdr_up	0

createMenu pixtabMenu pixtabSize {
    {   "3x3"          f.exec { pixtabSetSize 3 } }
    {   "5x5"          f.exec { pixtabSetSize 5 } }
    {   "7x7"          f.exec { pixtabSetSize 7 } }
    {   "9x9"          f.exec { pixtabSetSize 9 } }
}


proc updatePixelTable { cx cy wx wy args } \
{
    global psize pixtab_up ism_enable

    if {! $pixtab_up} \
	return
    if {$ism_enable} \
	return

    set delta [expr int($psize / 2) ]
    set x1 [expr ($wx - $delta) ]
    set x2 [expr ($wx + $delta) ]
    set y1 [expr ($wy - $delta) ]
    set y2 [expr ($wy + $delta) ]
    set c [ expr int($psize / 2) ]


    # Update the table labels.
    set x $x1 ;      set xl {}
    set y $y2 ;      set yl {}
    for {set i 0} {$i < $psize} {incr i} {
	lappend xl  [format " %10.1f " $x] ; set x [ expr ($x + 1.) ]
	lappend yl  [format " %10.1f " $y] ; set y [ expr ($y - 1.) ]
    }
    send ptColLabs setList $xl ; send ptColLabs highlight $c
    send ptRowLabs setList $yl ; send ptRowLabs highlight $c

    # Update the pixel table itself.
    #set pix [ send client getPixels $cx $cy $psize True ]

    set x0  [ expr int($cx - $psize / 2. + 0.5)]
    set y0  [ expr int($cy - $psize / 2. + 0.5)]
    set pix [ send client getPixels $x0 $y0 $psize $psize ]
    send pixtab setList [ lrange $pix 4 end ]
    set c [ expr int(($psize * $psize) / 2) ]
    send pixtab highlight $c

    # Update the pixtab stats.
    set sum   0.0
    set sum2  0.0
    set npix  [ expr ($psize * $psize) ]
    set nend  [ expr ($psize * $psize) + 4 ]
    for {set i 4} {$i < $nend} {incr i} {
	set val  [lindex $pix $i]
	catch {
	    set sum  [ expr ($sum + $val) ]
	    set sum2 [ expr ($sum2 + $val * $val) ]
	}
    }

    set mean [ expr ($sum / ($npix * 1.0)) ]
    set var  [ expr (($sum2 - $sum * $mean) / ($npix - 1)) ]
    if {$var <= 0.0} {
	set stdev 0.0
    } else {
	set stdev  [ expr sqrt ($var) ]
    }
    send meanValue set label [ format "%10.2f" $mean ]
    send sigValue set label  [ format "%10.4f" $stdev ]
}


proc pixtabClose args \
{
    global pixtab_up

    send pixel_panel unmap
    send pixelTable set on False
    set pixtab_up 0
    catch { send wcspix set psize 0 }
} ; send pixtabClose addCallback pixtabClose


proc pixtabSetSize { size args } \
{
    global psize ism_enable

    set c [ expr int(($psize * $psize) / 2) ]
    send pixtab highlight $c

    # Now reset the window size.
    switch $size {
    3	{ send pixel_panel "resize 265 175"
	  send pixtab "set width 180 ; set height 60"
	}
    5	{ send pixel_panel "resize 375 215"
	  send pixtab "set width 290 ; set height 105"
	}
    7	{ send pixel_panel "resize 495 265"
	  send pixtab "set width 410 ; set height 150"
	}
    9	{ send pixel_panel "resize 610 310"
	  send pixtab "set width 525 ; set height 195"
	}
    }

    send pixtab    set defaultColumns $size
    send ptColLabs set defaultColumns $size
    set psize $size

    # Notify the ISM we've changed size.
    if ($ism_enable) {
	catch { send wcspix set psize $psize }
    }

    send imagewin getCursorPos xc yc
    updatePixelTable $xc $yc $xc $yc

} ; pixtabSetSize $psize


proc ptPixelTable {widget type state args} \
{
    global pixtab_up psize

    set pixtab_up $state
    if {$pixtab_up == 1} {
	send pixelTable set on True
	send pixel_panel map
	catch { send wcspix set psize $psize }
    } else {
	send pixelTable set on False
	send pixel_panel unmap
	catch { send wcspix set psize 0 }
    }
}; send pixelTable addCallback ptPixelTable


################################################################################
# Warning dialog.  This pops up a dialog box with the given warning message,
# and executes the given command if the user pushes OK.
#
# Usage:	Wexec object message [ok_action [cancel_action]]
#
# The message text is displayed in a popup and the user hits the ok or
# cancel button to close the popup.  If an action has been posted for the
# button selected then it is sent to the named object.  Only one alert can
# be in effect at a time; posting another alert before the first has
# completed causes the new alert to override the first.
################################################################################

set W_object ""
set W_ok_cmd ""
set W_cancel_cmd ""

proc Wexec {object msg args} \
{
    global W_object W_ok_cmd W_cancel_cmd
    set W_object $object
    set W_ok_cmd [lindex $args 0]
    set W_cancel_cmd [lindex $args 1]
    send warnText set label $msg
    send warning map
}

proc Wbutton {widget args} \
{
    global W_object W_ok_cmd W_cancel_cmd
    switch $widget {
    warnOk	{ if [llength $W_ok_cmd] { send $W_object $W_ok_cmd }
		}
    warnCancel	{ if [llength $W_cancel_cmd] { send $W_object $W_cancel_cmd }
		}
    }
    send warning unmap
}
send warnOk     addCallback Wbutton
send warnCancel addCallback Wbutton

# The parameter "alert" is used to forward alerts from the client.
proc setAlert {param old new} \
{
    Wexec client [lindex $new 0] [lindex $new 1]
}; send alert addCallback setAlert



################################################
# Define some TCL debug procedures.
################################################

set tcl_up 0

proc tclCommandClear {widget args}   { send tclEntry set string "" }
proc tclCommandExecute {widget args} { send server [send tclEntry {get string}]
}
proc tclCommand {widget mode command args} { send server $command }
proc tclClose {widget args}                { tclPanel }
proc tclOpen args \
{ 
    global tcl_up
    send tcl_panel map 
    set tcl_up 1
}

proc tclPanel args \
{
    global tcl_up
    if {$tcl_up} {
	send tcl_panel unmap
	set tcl_up 0
    } else {
	send tcl_panel map
	set tcl_up 1
    }
}

send tclClear   addCallback tclCommandClear
send tclExecute addCallback tclCommandExecute
send tclEntry   addCallback tclCommand
send tclDismiss addCallback tclClose



################################################
# ISM Module support routines.
################################################


# Turn the ISM on or off.
proc ismToggle { widget type state args } \
{
    global ism_enable ism_capable psize

    set ism_enable $state

    # Set the coord-panel header option availability.
    if {$ism_enable == 1 && $ism_capable} {
	send imageHeader setSensitive True
	send woptBPM setSensitive True
	catch { send client ism_start wcspix }
    } else {
	send imageHeader setSensitive False
	send woptBPM set on False
	send woptBPM setSensitive False
	catch { send client ism_stop wcspix }
	send hdr_panel unmap
    }
    setCoordPanelSensitivity

} ; send ismToggle addCallback ismToggle



# Handle messages from ISM clients and pass them on to the appropiate
# callback.

proc ism_msg { param old new } \
{
    global ism_enable 

    set cmd  [lindex $new 0]				;# command name
    set ism  [lindex $new 1]				;# determine ISM name
    set argv [lrange $new 2 end]			;# get args
    set argc [llength $argv]

    switch  $cmd {
    source   { source [lindex $new 1]		}
    alert    { Wexec client [lindex $new 1]	}
    deliver  { ${ism}_msg $argc $argv		}
    info     { ism_info $ism			}
    }
} ; send ism_msg addCallback ism_msg



# Log a client message to the info panel
set ismInfoText " " 

proc ism_info { text } \
{
    global infoMode ismInfoText

    set ismInfoText [format "%s\n%s" $ismInfoText $text]
    if {$infoMode == "infoOptIsm"} {
	send infoText set string $ismInfoText
    }
}

# Initialize the text.
proc ismInitInfoText args \
{
    global ismInfoText

    set ismInfoText ""
    ism_info  "\t    ISM Client Message Logs"
    ism_info  "\t    -----------------------"
    ism_info  " "
} ; ismInitInfoText



################################################
# WPIX module support routines.
################################################

set cur_objid		0
set cur_regid		0
set redraw_compass	0
#set Compass(0)		{ 0.0 1 1 0 X Y }
set Compass(0)		{ 0.0 0.0 1.0 -1.0 0.0 0 X Y }
set Orient(0)		{ 1 1 1 }

set wcspix_debug	0

proc wcspix_msg { argc argv } \
{
    global wcspix_debug

    set arg [string trimleft [ string trimright [lindex $argv 0] ] ]
    set cmd [lindex $arg 0]

    if {$wcspix_debug} { print "wcspix_msg:  $cmd" }


    switch $cmd {
    startup	{ wcspix_startup					}
    shutdown	{ wcspix_shutdown					}
    disable	{ wcspix_disable					}
    capable	{ wcspix_capable					}

    cache	{ wcspix_cache   [lrange $arg 1 end]			}
    uncache	{ wcspix_uncache [lrange $arg 1 end]			}
    wcstran	{ wcspix_wcstran [lrange $arg 1 end]			}
    wcslist	{ wcspix_wcslist [lrange $arg 1 end] 			}

    imghdr	{ send hdrText \
			setText [format "<pre>%s\n%s</pre>" \
			[string trimright [send hdrText getText simple] "\n"]\
			[lindex $arg 1] ]
		}
    wcshdr	{ send hdrKGText append [lindex $arg 1]			}

    wcsinfo	{ send hdrIGText append [lindex $arg 1]		
		  send hdrText   gotoId 0
		  send hdrKGText set insertPosition 0
		}

    compass	{ wcspix_compass [lrange $arg 1 end] ; drawCompass 	}
    orient	{ wcspix_orient  [lrange $arg 1 end] 			}
    wcstype	{ wcspix_wcstype [lindex $arg 1] [lindex $arg 2]	}
    wcsfmt	{ set num [lindex $arg 2]
		  send fmtWcs$num set label [lindex $arg 1] 		}

    wcspix_cmd	{ send wcsIsmCmd set string [lindex $arg 1]		}

    pixtab	{ set tab  [lindex [lindex $arg 1] 0]
		  set col  [lindex [lindex $arg 1] 1]
		  set row  [lindex [lindex $arg 1] 2]
		  set stat [lindex [lindex $arg 1] 3]
		  wcspix_pixtab $tab $col $row $stat
		}
    }
}


# Startup and initialize the wcspix module with the GUI state.
proc wcspix_startup args \
{
    global ism_enable frame
    global up_todo psize pixtab_up frameCache

    set ism_enable 1
    send ismToggle set on True
    send imageHeader setSensitive True
    send woptBPM setSensitive True
    setCoordPanelSensitivity
    ismInitInfoText

    if {$up_todo < 3} {
        resizeCoordsBox $up_todo
    }
    updateCoordsBox
    drawCompass

    # Initialize the frame cache.
    foreach c [array names frameCache] {
	if {$c != "0"} { unset frameCache($c) }
    }

    catch { 
	if {$pixtab_up} { send wcspix set psize $psize }
	for {set i 1} {$i <= 4} {incr i} {
    	    send wcspix set wcs    [send sysWcs$i get label] $i
    	    send wcspix set format [send fmtWcs$i get label] $i
	}
    }

    if { [send infoOptClients get on] } {
	send client info clients
    }
}

# Shutdown the WPIX module.
proc wcspix_shutdown args \
{
    global ism_enable frame

    set ism_enable 0
    send ismToggle set on False
    send imageHeader setSensitive False
    send woptBPM set on False
    send woptBPM setSensitive False
    setCoordPanelSensitivity
    setCoordPanelHeight

    wcsFmtIValue "N/A"
    wcsFmtBValue "0"

    resizeCoordsBox 0
    drawCompass

    if { [send infoOptClients get on] } {
	send client info clients
    }
}


# Disable the WPIX module.  We are only called when a display client has
# indicated it doesn't use the new mapping facilities and having the WPIX
# ISM visible will only confuse the user.

proc wcspix_disable args \
{
    global ism_enable ism_capable rulerWCS

    if {$ism_enable} {
        send wcspix quit
    }
    set ism_capable 0
    set rulerWCS 0
    wcspix_shutdown
    send ismToggle setSensitive False
}


# Client connected is capable of using the ISM, but don't necessarily turn
# it on at this point.

proc wcspix_capable args \
{
    global ism_capable

    set ism_capable 1
    wcsFmtIValue "0"
    wcsFmtBValue "0"
    send ismToggle setSensitive True
}


# Cache an image in the GUI.
proc wcspix_cache { argv } \
{
    global frameCache redraw_compass cur_objid

    set name	[lindex $argv 0]
    set frame	[lindex $argv 1]
    set id	[lindex $argv 2]

    # Store the image name and id in a local cache.
    lappend frameCache($frame) $name $id
    send hdrObjMenu set label $name

    # Automatically get the header.
    regsub -all {[\[]} $name  "\\\[" image
    catch { getHeader $image $id }

    setHdrObjMenu $frame

    set cur_objid $id
    set redraw_compass 1
}

# Uncache an image in the GUI.
proc wcspix_uncache { argv } \
{
    global frameCache Compass

    set id [lindex $argv 0]
    foreach c [array names frameCache] {
	set i1 0
	set i2 1
	set new { }
	while { $i2 < [llength $frameCache($c)] } {
            if {[lindex $frameCache($c) $i2] != $id} { 
		lappend new [lindex $frameCache($c) $i1]
		lappend new [lindex $frameCache($c) $i2]
            }
	    incr i1 2
	    incr i2 2
        }
	set frameCache($c) $new
    }
    if [info exists Compass($id)] {
        unset Compass($id)
    }
}

# Format the results of the WCSTRAN method.
proc wcspix_wcstran { argv } \
{
    global frameCache cur_objid cur_regid redraw_compass

    set objid  [ lindex [lindex $argv 0] 1]
    set regid  [ lindex [lindex $argv 1] 1]
    set pixval [ lindex [lindex $argv 2] 1]
    set bpmval [ lindex [lindex $argv 3] 1]

    wcsFmtIValue $pixval
    wcsFmtBValue $bpmval

    set args [lrange $argv 4 end]
    set nargs [llength $args]
    for {set i 0} {$i < 4} {incr i} {
	set coord   [lindex $args $i]
	set wcsname [lindex $coord 1]
	set xval    [lindex $coord 2]
	set yval    [lindex $coord 3]
	set xunits  [lindex $coord 4]
	set yunits  [lindex $coord 5]
	wcsFmtWcs [expr ($i + 1)] $wcsname $xval $yval $xunits $yunits
    }

    set cur_objid $objid
    set cur_regid $regid

    if {$redraw_compass} \
	drawCompass
}

# Save the object compass information.
proc wcspix_compass { argv } \
{
    global Compass

    set objid     [lindex $argv 0]
    set angle     [lindex $argv 1]

    #set xflip     [lindex $argv 2]
    #set yflip     [lindex $argv 3]
    #set transpose [lindex $argv 4]
    #set xlab      [lindex $argv 5]
    #set ylab      [lindex $argv 6]

    set north_x   [lindex $argv 2]
    set north_y   [lindex $argv 3]
    set east_x    [lindex $argv 4]
    set east_y    [lindex $argv 5]
    set transpose [lindex $argv 6]
    set xlab      [lindex $argv 7]
    set ylab      [lindex $argv 8]

    #lappend Compass($objid) $angle $xflip $yflip $transpose $xlab $ylab
    #set Compass($objid) [list $angle $xflip $yflip $transpose $xlab $ylab]
    set Compass($objid) [list $angle $north_x $north_y $east_x $east_y \
	$transpose $xlab $ylab]
    drawCompass
}

# Save the image display orientation information.
proc wcspix_orient { argv } \
{
    global Orient

    set objid [lindex $argv 0]
    set frame [lindex $argv 1]
    set xflip [lindex $argv 2]
    set yflip [lindex $argv 3]

    set Orient($objid) [list $frame $xflip $yflip]
}


# Handle the list of WCSs available for the current image.
proc wcspix_wcslist { argv } \
{
    set wcslist [lindex $argv 0]

    for {set i 1} {$i <= 4} {incr i} {
        set items {}
	foreach nam $wcslist {
	    if {[string tolower $nam] == "line"} {
	        lappend items "f.dblline"
	    } else {
	        lappend items "\"$nam\" f.exec \{setWcsSys $nam $i\}"
	    }
	}
	editMenu sysMenu$i sysWcs$i $items
    }
}

# Set the type of the WCS.
proc wcspix_wcstype { label num } \
{
    global up_todo

    send sysWcs$num set label $label
    if {[string tolower $label] == "none"} {
	send wpWcs$num "set on False ; setSensitive False"
	send wiWcs$num "set on False ; setSensitive False"
	send fmtWcs$num setSensitive False
    	set hght 4
    } else {
        send wpWcs$num "set on True  ; setSensitive True"
        send wiWcs$num setSensitive True
	send fmtWcs$num setSensitive True
    	set hght 17
    }
    send wtWcs$num set height $hght
    setCoordPanelHeight

    #resizeCoordsBox $up_todo
    updateCoordsBox
}

# Display the pixel table.
proc wcspix_pixtab { tab col row stat } \
{
    global psize

    # Update the pixel table.
    send pixtab setList [lindex $tab 1]
    send pixtab highlight [expr int(($psize * $psize) / 2)]

    # Update the table labels.
    set c [ expr int($psize / 2) ]
    send ptColLabs setList $col ; send ptColLabs highlight $c
    send ptRowLabs setList $row ; send ptRowLabs highlight $c

    # Update the pixtab stats.
    send meanValue set label [ format "%10.2f" [lindex $stat 0] ]
    send sigValue  set label [ format "%10.4f" [lindex $stat 1] ]
}




################################################################################
#
#  XIMTOOL-ALT -- Procedures and declarations for the ALT GUI.
#
################################################################################

# Creat the bitmaps needed for the alternate optional bars.

createBitmap tools 16 16 {
   0xff, 0xff, 0xff, 0xff, 0x03, 0xc0, 0xf3, 0xcf, 0xf3, 0xcf, 0xf3, 0xcf,
   0x83, 0xc1, 0x83, 0xc1, 0x83, 0xc1, 0x83, 0xc1, 0x83, 0xc1, 0x83, 0xc1,
   0x83, 0xc1, 0x03, 0xc0, 0xff, 0xff, 0xff, 0xff};

createBitmap control 16 16 {
   0xff, 0xff, 0xff, 0xff, 0x03, 0xc0, 0xe3, 0xc7, 0xe3, 0xcf, 0x33, 0xcc,
   0x33, 0xc0, 0x1b, 0xc0, 0x1b, 0xc0, 0x1b, 0xc0, 0x33, 0xcc, 0xf3, 0xcf,
   0xe3, 0xc7, 0x03, 0xc0, 0xff, 0xff, 0xff, 0xff};

createBitmap tile 16 16 {
   0xff, 0xff, 0xff, 0xff, 0x83, 0xc1, 0x83, 0xc1, 0x83, 0xc1, 0x83, 0xc1,
   0x83, 0xc1, 0xff, 0xff, 0xff, 0xff, 0x83, 0xc1, 0x83, 0xc1, 0x83, 0xc1,
   0x83, 0xc1, 0x83, 0xc1, 0xff, 0xff, 0xff, 0xff};

createBitmap compass 16 16 {
   0x00, 0x00, 0x00, 0x02, 0x00, 0x07, 0x80, 0x0f, 0xc0, 0x1f, 0x00, 0x07,
   0x00, 0x07, 0x00, 0x07, 0x00, 0x07, 0x00, 0x07, 0x00, 0x07, 0xfc, 0x07,
   0xfc, 0x07, 0xfc, 0x07, 0x00, 0x00, 0x00, 0x00}

createBitmap plus 11 11 {
   0x00, 0x00, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0xfe, 0x03, 0xfe, 0x03,
   0xfe, 0x03, 0x70, 0x00, 0x70, 0x00, 0x70, 0x00, 0x00, 0x00};

createBitmap minus 11 11 {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x03, 0xfe, 0x03,
   0xfe, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

createBitmap disk 16 16 {
 0xfe,0x1f,0x11,0x25,0x11,0x45,0x11,0x44,0xf1,0x47,0x01,0x40,0x01,0x40,0xf9,
 0x4f,0x05,0x50,0x05,0x50,0x05,0x50,0x05,0x50,0x05,0x50,0x05,0x50,0xff,0x7f,
 0x00,0x00};

createBitmap printer 32 16 {
   0x00, 0xfe, 0x07, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x02, 0x12, 0x00,
   0x00, 0x02, 0x22, 0x00, 0x00, 0x02, 0x3e, 0x00, 0x00, 0x02, 0x20, 0x00,
   0x00, 0x02, 0x20, 0x00, 0xe0, 0x03, 0xe0, 0x03, 0x10, 0x03, 0xe0, 0x06,
   0x08, 0xff, 0x7f, 0x09, 0x04, 0x00, 0x00, 0x10, 0xfc, 0xff, 0xff, 0x1f,
   0x04, 0x00, 0x00, 0x10, 0xfc, 0xff, 0xff, 0x1f, 0x08, 0x00, 0x00, 0x08,
   0xf8, 0xff, 0xff, 0x0f};


send tbBlinkDec   "set bitmap larrow" 	;# Assign the bitmaps to the buttons.
send tbBlinkInc   "set bitmap rarrow"
send tbZoomIn     "set bitmap plus"
send tbZoomOut    "set bitmap minus"
send tbTile       "set bitmap tile"
send tbCompass    "set bitmap compass;  addCallback toggleCompass"
#send helpButton   "set bitmap qmark;    addCallback Help"
send mXflipButton "set bitmap xflip;    addCallback xflip"
send mYflipButton "set bitmap yflip;    addCallback yflip"
send mNextButton  "set bitmap rarrow;   addCallback nextFrame"
send mPrevButton  "set bitmap larrow;   addCallback prevFrame"


# toolBox -- Toggle the toolbox and panelbar display.

set toolbox_up [ true $showToolBar ]
set panelbar_up [ true $showPanelBar ]

proc toolBoxToggle args \
{
    global toolbox_up 

    set w  [send display get width]  ; set h  [send display get height]
    set iw [send imagewin get width] ; set ih [send imagewin get height]

    if {$toolbox_up} {
	send toolbar set height 0
	send toolButton set state 0
        send imagewin "set width $iw; set height $ih"
	set nh [expr $h - 25]
	send display "set width $w; set height $nh"
	set toolbox_up 0
	send mXflipButton map
	send mYflipButton map
	send mPrevButton map
	send mFrameButton map
	send mNextButton map
    } else {
	send toolbar set height 25
	send toolButton set state 1
        send imagewin "set width $iw; set height $ih"
	set nh [expr $h + 25]
	send display "set width $w ; set height $nh"
	set toolbox_up 1
	send mXflipButton unmap
	send mYflipButton unmap
	send mPrevButton unmap
	send mFrameButton unmap
	send mNextButton unmap
    }
}

proc panelBarToggle args \
{
    global panelbar_up

    set w  [send display get width]  ; set h  [send display get height]
    set iw [send imagewin get width] ; set ih [send imagewin get height]

    if {$panelbar_up} {
	send panelbar set height 0
	send panelButton set state 0
        send imagewin "set width $iw; set height $ih"
	set nh [expr $h - 25]
	send display "set width $w ; set height $nh"
	set panelbar_up 0
    } else {
	send panelbar set height 25
	send panelButton set state 1
        send imagewin "set width $iw; set height $ih"
	set nh [expr $h + 25]
	send display "set width $w ; set height $nh"
	set panelbar_up 1
    }
}



# Initialize the bars to be displayed if the resource was set.

send toolButton   "set bitmap tools;    addCallback toolBoxToggle"
if { ! [ true $showToolBar ] } {
    send display set height [expr [send display get height] - 25]
    send toolbar set height 0
    send toolButton set state 0
} else {
    send toolButton set state 1
    send mXflipButton unmap
    send mYflipButton unmap
    send mPrevButton unmap
    send mFrameButton unmap
    send mNextButton unmap
}

send panelButton  "deleteCallback panel"
send panelButton  "set bitmap control;  addCallback panelBarToggle"

if { ! [ true $showPanelBar ] } {
    send display set height [expr [send display get height] - 25]
    send panelbar set height 0
    send panelButton set state 0
} else {
    send panelButton set state 1
}


##############################################
# Panelbar callbacks.
##############################################

send pbQuit  addCallback Quit
send helpClose addCallback "send helpButton set state 0"


# Control Panel.
#------------------------------------------------------
proc pbToggleControl {name element op} \
{
    upvar $name panel_up
    send pbDisplayP set state [expr !($panel_up)]
} ; #trace variable panel_up w pbToggleControl

proc pbResetPanel {param old new} \
{
    global displayPanner displayMagnifier displayCoords
    switch $new {
    done	{ send pbPanM set state [true $displayPanner]
		  send pbMagM set state [true $displayMagnifier]
		  send pbWcsM set state [true $displayCoords]
		}
    }
} ; send initialize addCallback pbResetPanel

set WidgetToTab(pbDisplayP)	display_panel
set WidgetToTab(pbInfoP)	info_panel
set WidgetToTab(pbLoadP)	load_panel
set WidgetToTab(pbPrintP)	print_panel
set WidgetToTab(pbSaveP)	save_panel
set WidgetToTab(pbTileP)	tile_panel
set WidgetToTab(pbCoordP)	wcs_panel

set TabToWidget(display_panel)	pbDisplayP
set TabToWidget(print_panel)	pbPrintP
set TabToWidget(load_panel)	pbLoadP
set TabToWidget(save_panel)	pbSaveP
set TabToWidget(info_panel)	pbInfoP
set TabToWidget(tile_panel)	pbTileP
set TabToWidget(wcs_panel)	pbCoordP

set pbTabTop	"pbDisplayP"

proc pbPanelDismiss args \
{
    global tabTop TabToWidget WidgetToTab
    set panel $TabToWidget($tabTop)
    send $panel set state 0
} ; send panelClose addCallback pbPanelDismiss

proc pbResizeCB {widget event a b c d e args} \
{
    global pbTabTop TabToWidget WidgetToTab
    if { $a == 0 && $b == 0 && $c == 0 && $d == 0 && $e == 0 } {
	send $pbTabTop set state 0
	set new $TabToWidget($widget)
	send $new set state 1
	set pbTabTop $new
    }
} ; foreach w $cpTabs {send $w addEventHandler pbResizeCB exposureMask}

proc pbPanelTabs { widget type state args } \
{
    global pbTabTop tabTop panel_up
    global TabToWidget WidgetToTab

    set panel $WidgetToTab($widget)
    if {$tabTop == $panel && $panel_up} {
        send panelShell unmap
        send $widget set state 0
        set panel_up 0
        return
    }

    send $TabToWidget($tabTop) set state 0
    set tabTop $panel
    set pbTabTop $TabToWidget($panel)
    send panelTabs setTop $panel

    # Now fire it up if it's not already open.
    if {$panel_up == 0} {
        send $widget set state 1
        send panelShell map
        set panel_up 1
    }
}
foreach w { pbDisplayP pbInfoP pbLoadP pbPrintP pbSaveP pbTileP pbCoordP } {
        send $w addCallback pbPanelTabs
}



# Load Panel.  (Really need to clean this up.)
#------------------------------------------------------
proc pbDoLoadOptions { param old new } \
{
    set val     [ join [lrange $new 1 end] " " ]
    switch [lindex $new 0] {
    newfile     { send fnameText set string $val }
    }
} ; send loadOptions addCallback pbDoLoadOptions

proc pbFileLoad { widget mode fname args } \
{
    set fpath [format "%s/%s" \
        [string range [send dirLabel get label] 12 end] $fname ]
    send imagewin setCursorType idle
} ; send fnameText addCallback pbFileLoad

proc pbflSelectPrint {widget cbtype selections args} \
{
    foreach selection $selections {
	;
    }
}; #send imageList addCallback pbflSelectPrint

proc pbFileLoadB args \
{
    set fname [send fnameText get string]
    if {$fname != ""} {
        set fpath [format "%s/%s" \
            [string range [send dirLabel get label] 12 end] $fname ]
    }
} ; send filesLoadButton addCallback pbFileLoadB


# Panner Marker.
#------------------------------------------------------
proc pbTracePanner {name element op} \
{
    global last_compass

    catch {
        upvar $name panner_enable
        send pbPanM set state $panner_enable

	if { $panner_enable } {
	    send tbCompass "setSensitive True  ; set state $last_compass"
	    drawCompass
	} else {
	    send tbCompass "setSensitive False ; set state False"
	    eraseCompass
	}
    }
} ; trace variable panner_enable w pbTracePanner

proc pannerPanel args \
{
    global panner_enable displayPanner

    setPanner [expr !$panner_enable]
    send pannerButton set on [expr $panner_enable]
}; send pbPanM  addCallback pannerPanel


# Magnifier Marker.
#------------------------------------------------------
proc pbTraceMagnifier {name element op} \
{
    upvar $name magnifier_enable
    send pbMagM set state $magnifier_enable
} ; trace variable magnifier_enable w pbTraceMagnifier

proc magnifierPanel args \
{
    global magnifier_enable displayMagnifier
    setMagnifier [expr !$magnifier_enable]
    send magnifierButton set on  [expr $magnifier_enable]
}; send pbMagM addCallback magnifierPanel


# CoordsBox Marker.
#------------------------------------------------------
proc pbTraceCoordsBox {name element op} \
{
    upvar $name track_enable
    send pbWcsM set state $track_enable
} ; trace variable track_enable w pbTraceCoordsBox

proc wcsPanel args \
{
    global track_enable
    setTrack [expr !$track_enable]
}; send pbWcsM  addCallback wcsPanel



# WPIX ISM Callbacks.
#------------------------------------------------------

proc altIsmToggle { widget type state args } \
{
    ismToggle pbIsm junk $state
} ; send pbIsm addCallback altIsmToggle

proc pbTraceIsm {name element op} \
{
    upvar $name ism_enable
    send pbIsm set state $ism_enable
} ; trace variable ism_enable w pbTraceIsm


proc altIsmMsgCB { param old new } \
{
    set cmd  [lindex $new 0]                            ;# command name
    set ism  [lindex $new 1]                            ;# determine ISM name
    set argv [lrange $new 2 end]                        ;# get args
    set argc [llength $argv]

    switch  $cmd {
    deliver  { ${ism}_alt_msg $argc $argv           }
    }
} ; send ism_msg addCallback altIsmMsgCB


proc wcspix_alt_msg { argc argv } \
{
    set arg [string trimleft [ string trimright [lindex $argv 0] ] ]
    set cmd [lindex $arg 0]
    switch $cmd {
    startup	{ }
    shutdown	{ }
    disable	{ send pbIsm "set state False ; setSensitive False" }
    capable	{ send pbIsm "setSensitive True" }
    }
}



##############################################
# Toolbar callbacks.
##############################################

send tbNormalize	addCallback normalize
send tbInvert		addCallback cpInvert
send tbRegister		addCallback cpRegisterFrames
send tbMatchLUT		addCallback cpMatchFrames


# Frame Selection.
#------------------
createMenu mFrameMenu mFrameButton $frameMenuDescription

proc altFrameChanged {param old new} \
{
    send mFrameButton set label $new
} ; send frame addCallback altFrameChanged


# Image Flipping.
#------------------------------------------------------
proc tbSetFlip {param old new} \
{
    if {$param == "xflip"} {
        send mXflipButton set state [true $new]
    } else {
        send mYflipButton set state [true $new]
    }
}; foreach i {xflip yflip} { send $i addCallback tbSetFlip }


# Zoom/Pan buttons.
#------------------------------------------------------
proc tbZoomAction { widget args } \
{
    global frameWidth frameHeight

    switch $widget {
    tbZoom0   { cpZoom 1 1 fixed }
    tbZoomIn  { cpZoom 2.0 2.0 relative }
    tbZoomOut { cpZoom 0.5 0.5 relative }
    tbCenter  { send client pan [expr $frameWidth/2.0] [expr $frameHeight/2.0] }
    }
}
foreach widget { tbCenter tbZoomIn tbZoom0 tbZoomOut } {
    send $widget addCallback tbZoomAction
}


# Frame Blink.
#------------------------------------------------------
proc tbSetBlinkRate {w args} \
{
    if {$w == "tbBlinkInc"} {
	cpSetBlinkRate BRincrease
    } else {
	cpSetBlinkRate BRdeccrease
    }
}
foreach w  {tbBlinkDec tbBlinkInc} { send $w addCallback tbSetBlinkRate }

proc tbBlink { widget args } \
{
    global blinkRate blinkId

    if {$blinkRate < 0.01} {
	send tbBlink set state 0
    } else {
        if {$widget != "tbBlink"} {
            if {($blinkId != 0) != [send $widget get on]} {
                toggleBlink
            }
        } else {
            if {($blinkId != 0) != [send $widget get state]} {
                toggleBlink
            }
        }
    }
} ; send tbBlink addCallback tbBlink

proc tbTraceBlink {name element op} \
{
    upvar $name blinkId
    send tbBlink set state [expr $blinkId != 0]
} ; trace variable blinkId w tbTraceBlink


# Auto-register.
#------------------------------------------------------
proc tbAutoRegister { widget type state args } \
{
    send tbAutoReg set state $state
}
foreach w {autoregButton brAregButton tbAutoReg} {
    send $w addCallback cpAutoRegister
}

proc tbToggleAutoReg args \
{
    global auto_reg
    if {$auto_reg} {
        cpAutoRegister autoregButton dummy 0
        set auto_reg 0
        send tbAutoReg set state 0
    } else {
        cpAutoRegister autoregButton dummy 1
        set auto_reg 1
        send tbAutoReg set state 1
    }
}


# Frame Tiles.
#------------------------------------------------------
proc tbSetTileFrames args \
{
    global tileOpt

    # Send the option to the client.
    if {[send tbTile get state ]} {
	if {$tileOpt == 0} {
	    # If mode is disabled, turn on the tile selection.
            selectTileOrientation junk junk Best
	} else {
	    # Otherwise, turn on in current mode.
            selectTileOrientation junk junk [tileSelToLabel $tileOpt]
	}
    } else {
        selectTileOrientation junk junk Disabled
    }
}; send tbTile addCallback tbSetTileFrames

proc tbTrackTileFrames {param old new} \
{
    send tileFramesButton set on [true $new]
    send tbTile set state $new
}; send tileFrames addCallback tbTrackTileFrames

proc tbTileFramesToggle args \
{
    set value [send tileFramesButton get on]
    if {$value} { set not 0 } else { set not 1 }

    send tileFramesButton set on $not
    send tbTile set state $not
    cpSetTileFrames tbTile junk $not
}


# Compass Indicator.
#------------------------------------------------------
proc tbToggleCompass { widget type state args } \
{
    global frame

    if {$state} {
	send compass set on True
	send tbCompass set state 1
        drawCompass
    } else {
	send compass set on False
	send tbCompass set state 0
        eraseCompass
    }
} ; foreach w {compass tbCompass} { send $w addCallback tbToggleCompass }