This file is indexed.

/usr/share/tau/tools/src/racy.tcl is in tau-racy 2.17.3.1.dfsg-4.2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
#*********************************************************************#
#*                TAU/pC++/Sage++  Copyright (C) 1994                *#
#*                        Jerry Manic Saftware                       *#
#*  Indiana University  University of Oregon  University of Rennes   *#
#*********************************************************************#

#*********************************************************************#
#* TAU notes
#* April 28, 1997
#* Kurt Windisch (kurtw@cs.uoregon.edu)
#*
#* Currently profiling via pprof supports only projects consisting of
#* a single program file (*.C file).  Therefore, racy is not yet 
#* generalized for multifile projects and the variable racy_progfile
#* can be used to determine the progfile to associate with local tags
#* when interacting with the rest of TAU.
#*
#* Racy gets its profiling information from pprof.  Pprof provides
#* information on functions, collections and aggregates, but
#* collections and aggregates should never be reported for the
#* same project.
#*********************************************************************#

#
# A debugging framework, for installing scaffolding.
#
set DEBUG_SET 0
proc DEBUG {} {
    global DEBUG_SET

    return $DEBUG_SET
}

#
#  ALONE - for standalone racy
#
set ALONE_SET 0
proc ALONE {} {
    global ALONE_SET
    return $ALONE_SET
}

displayMessage hourglass "Loading racy..."

source "$TAUDIR/inc/help.tcl"
source "$TAUDIR/inc/printcan.tcl"
source "$TAUDIR/inc/stack.tcl"

set racy_progfile "";   # the single program file

set tcl_precision 17

#set Colors [list \
#    magenta green red blue yellow purple orange gold brown \
#    tan grey coral forestgreen skyblue seagreen beige steelblue1 royalblue \
#    pink cyan violet snow steelblue white ]
#set Colors [list \
#    coral  lavender cornflowerblue turquoise yellow palevioletred \
#    mediumaquamarine dodgerblue1 salmon cadetblue1 orchid peachpuff1 \
#    springgreen papayawhip hotpink royalblue mistyrose powderblue \
#    chartreuse plum ] 
#set TextColors [list \
#    black black black white black white black black white \
#    black black black black black black black black black \
#    black black black black black black ]

set Colors [list \
    lightseagreen  lightskyblue1  lemonchiffon1  rosybrown1 \
    royalblue4 darkcyan mistyrose  cornflowerblue lightcoral \
    mediumaquamarine lavenderblush1   palevioletred3  \
    lightgoldenrodyellow lightblue papayawhip   paleturquoise \
    peachpuff1 powderblue ] 

set TextColors [list \
    black black black black white white black black black \
    black black black black black black black black black ]


set Stipples [list \
    hline1.bm cross.bm xline1.bm gray1.bm hline22.bm \
    vline1.bm gray3.bm cross0.bm xline2.bm \
    cross1.bm cross3.bm xline3.bm cross2.bm \
    cross5.bm vline2.bm xline4.bm cross4.bm hline2.bm \
    vline22.bm cross6.bm ]


#
# exit - TAU exit function that communicates the event to other tau tools.
#
rename exit exit.old
proc exit {{status 0}} {
    global myself uEventFlag

    PM_RemGlobalSelect $myself { global_selectFuncTag }
    if {$uEventFlag != 0} {
	PM_RemGlobalSelect $myself { global_selectUserTag }
    }
    PM_RemTool $myself
    exit.old
}


#
# wraplindex: like lindex, but index "wraps around" if bigger
#             than length of list
#

proc wraplindex {list index} {
  lindex $list [expr $index%[llength $list]]
}

#
# min: returns minimum of two values
#

proc min {x1 x2} {
  if { $x1 < $x2 } { return $x1 } else { return $x2 }
}

#
# max: returns maximum of two values
#

proc max {x1 x2} {
  if { $x1 > $x2 } { return $x1 } else { return $x2 }
}

#
# max3: returns maximum of three values
#

proc max3 {x1 x2 x3} {
  if { $x1 >= $x2 && $x1 >= $x3 } {
      return $x1  
  } elseif { $x2 >= $x1 && $x2 >= $x3 } {
      return $x2
  } else {return $x3}
}

#
# max4: returns maximum of four values
#

proc max4 {x1 x2 x3 x4} {
  if { $x1 >= $x2 && $x1 >= $x3 && $x1 >= $x4} {
      return $x1  
  } elseif { $x2 >= $x1 && $x2 >= $x3 && $x2 >= $x4} {
      return $x2
  } elseif { $x3 >= $x1 && $x3 >= $x2 && $x3 >= $x4} {
      return $x3
  } else {return $x4}
}

#
# vectorsum: returns sum of all elements in a vector
#

proc vectorsum {vector} {

  upvar $vector v

  if [DEBUG] {
      puts "vectorsum:"
      puts "  vector: $vector"
      #puts "  v: $v"
  }

  set r 0.0
  foreach elem $v {
    set r [expr $r+$elem]
  }
  return $r
}



#
# vectormax: returns maximum of all elements in a vector
#

proc vectormax {vector} {
  upvar $vector v
  set r [lindex $v 0]
  foreach elem $v {
    if { $elem > $r } { set r $elem }
  }
  return $r
}

#
# vectorop: apply scalar operation to vector
#

proc vectorop {vector op val} {
  upvar $vector v

  if [DEBUG] {
      puts "vectorop:"
      puts "  vector: $vector"
      puts "  v: $v"
  }

  set r ""
  foreach elem $v {
    lappend r [format "%.1f" [expr ${elem}${op}${val}]]
  }
  return $r
}

#
# vectorpercent: scale elements of vector according to max and scale
#

proc vectorpercent {vector max scale} {
  upvar $vector v

  if { $max == 0 } { return $v }
  set r ""
  foreach elem $v {
    lappend r [format "%.2f" [expr (double($elem)/double($max))*$scale]]
  }
  return $r
}


#
# numberInput: widget for input of 1 integer number
#
#         win: widget name
#       label: optional label to display
#     varname: name of global variable which holds input value
#

proc numberInput {win label varname} {
  global $varname

  frame $win
  if { $label != "" } {
    label $win.t -text $label
    pack $win.t -side top -fill x
  }
  button $win.b1 -text "<<" -width 3 -command "incr $varname -5"
  button $win.b2 -text "<"  -width 3 -command "incr $varname -1"
  entry $win.e -textvariable $varname -width 5 -relief sunken
  button $win.b3 -text ">"  -width 3 -command "incr $varname +1"
  button $win.b4 -text ">>" -width 3 -command "incr $varname +5"
  pack $win.b1 $win.b2 $win.e $win.b3 $win.b4 -side left -padx 10 -pady 10
}

set pr_sel_tag -99;  # currently selected function
set ue_sel_tag -99;  # currently selected user-defined event

#
# bargraph: horizontal bargraph widget
#
#         win: pathname for bargraph
#     bgtitle: title for bargraph
# rightlabels: list of labels
#     percent: list of percent values
#      values: list of values
#        tags: list of corresponding Sage++ id of functions
#       nodes: list of corresponding node identifiers
#              (if nonempty used instead of tags)
#        mode: what to show as labels on the right side: per / val / none
#

proc bargraph {win bgtitle rightlabels percent values tags {nodes {}} {mode per}} {
  global tagcol tagstip
  global pr_sel_tag
  global racy_progfile

  if [DEBUG] {
      puts " "
      puts "bargraph: "
      puts "  bgtitle: $bgtitle"
      puts "  rightlabels: $rightlabels"
      puts "  percent: $percent"
      puts "  values: $values"
      puts "  tags: $tags"
      puts "  nodes: $nodes"
      puts "  mode: $mode"
      puts "  pr_sel_tag: $pr_sel_tag"
      puts "  racy_progfile: $racy_progfile"
  }

  set num [llength $rightlabels];  # number of bars

  # -- create or reset canvas
  if { [winfo exists $win] } {
    $win delete all
  } else {
    canvas $win -background white
  }

  # -- scale percentage vector, so that it uses most of the display
  set pmax [vectormax percent]
  if { $pmax < 0.1 } {
    set pers [vectorop percent * 750]
  } elseif { $pmax < 1 } {
    set pers [vectorop percent * 75]
  } elseif { $pmax < 10 } {
    set pers [vectorop percent * 7.5]
  } elseif { $pmax < 25 } {
    set pers [vectorop percent * 3]
  } elseif { $pmax < 50 } {
    set pers [vectorop percent * 1.5]
  } else {
    set pers $percent
  }

#----------------------------------------------------------------------------
# display function name on the left side of bar graph
#----------------------------------------------------------------------------  
#  set max_llabel_width 0
#  for {set i 0} {$i<$num} {incr i} {
#    # -- create left labels; highlight selected functions in red
#    set t [lindex $tags $i]
#    if { $t == $pr_sel_tag } {
#      set ll_obj($i) [$win create text 0 [expr 40+$i*20] \
#               -text "[lindex $leftlabels $i]" -anchor e -fill red \
#               -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
#    } else {
#      set ll_obj($i) [$win create text 0 [expr 40+$i*20] \
#               -text "[lindex $leftlabels $i]" -anchor e \
#               -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
#    }
#    set bbox [$win bbox $ll_obj($i)]
#    set llabel_width [expr [lindex $bbox 2] - [lindex $bbox 0]]
#    if {$llabel_width > $max_llabel_width} {set max_llabel_width $llabel_width}
#
#    # -- setup bindings for clicking on left labels
#    if { $nodes == {} } {
#      $win bind $ll_obj($i) <Button-1> "showFuncgraph $t"
#      # showFuncTag is not implemented by racy
#      # $win bind $ll_obj($i) <Button-2> \
#      #     "PM_GlobalSelect $racy_progfile global_showFuncTag $t"
#      $win bind $ll_obj($i) <Button-3> \
#	  "PM_GlobalSelect $racy_progfile global_selectFuncTag $t"
#    } else {
#      $win bind $ll_obj($i) <Button-1> \
#	  "showBargraph [lindex $nodes $i] {[lindex $leftlabels $i]}"
#      $win bind $ll_obj($i) <Button-2> \
#	  "showText [lindex $nodes $i] {[lindex $leftlabels $i]}"
#    }
#  }
#
#  # -- create title
#  set title [$win create text 0 20 \
#		 -text "$bgtitle" -anchor e \
#		 -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
#  set bbox [$win bbox $title]
#  set title_width [expr [lindex $bbox 2] - [lindex $bbox 0]]
#  set max_l_width [max $title_width $max_llabel_width]
#  $win coords $title [expr $max_l_width+5] 20
#
#  set max_r_width 0
#  for {set i 0} {$i<$num} {incr i} {
#    # -- position left labels
#    $win coords $ll_obj($i) [expr $max_l_width+5] [expr 40+$i*20]
#
#    # -- display bars and right labels according to mode
#    set p [lindex $pers $i]
#    if { $p > 0 } {
#      set t [lindex $tags $i]
#      $win create rectangle \
#	  [expr $max_l_width+10]\
#	  [expr 31+$i*20] \
#	  [expr $max_l_width+10+$p*2] \
#	  [expr 49+$i*20] \
#	  -fill $tagcol($t) -stipple $tagstip($t)
#      switch -exact $mode {
#	  per   { set rl_obj [$win create text \
#				  [expr $max_l_width+15+$p*2] \
#				  [expr 40+$i*20] \
#				  -text "[lindex $percent $i]%" -anchor w \
#				  -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]}
#
#	  val   { set rl_obj [$win create text \
#				  [expr $max_l_width+15+$p*2] \
#				  [expr 40+$i*20] \
#				  -text "[wraplindex $values $i]" -anchor w \
#				  -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]}
#
#          none  {}
#      }
#      set bbox [$win bbox $rl_obj]
#      set r_width [expr $p*2 + [lindex $bbox 2] - [lindex $bbox 0]]
#      if {$r_width > $max_r_width} {set max_r_width $r_width}
#    }
#  }
#
#  set w [expr $max_l_width + $max_r_width + 20]
#  set h [expr ($num+2)*20];       # height of window
#  $win configure -scrollregion [list 0 0 $w $h]
#  $win xview moveto 1; # to shift view of canvas to right


#----------------------------------------------------------------------------
# display function name on the right side of bar graph
#----------------------------------------------------------------------------
  set max_llabel_width 0
  set max_bar_width 0
  for {set i 0} {$i<$num} {incr i} {
    # -- display leftt labels according to mode
  if [DEBUG] {
      #puts "  pers: $pers"
  }
    set p [lindex $pers $i]
    if { $p > 0 } {
      # -- set the width of bar graph
      set bar_width($i) [expr $p*2]
      if {$bar_width($i) > $max_bar_width} {set max_bar_width $bar_width($i)}
      # -- create left label according to its mode
      switch -exact $mode {
	  per   { set ll_obj($i) [$win create text 0 [expr 40+$i*20] \
				  -text "[lindex $percent $i]%" -anchor e \
				  -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]}

	  val   { set ll_obj($i) [$win create text 0 [expr 40+$i*20] \
				  -text "[wraplindex $values $i]" -anchor e \
				  -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]}

          none  {}
      }
      set bbox [$win bbox $ll_obj($i)]
      set llabel_width [expr [lindex $bbox 2] - [lindex $bbox 0]]
      if {$llabel_width > $max_llabel_width} {set max_llabel_width $llabel_width}
    }
  }
  set max_llabel_width [expr $max_llabel_width + 10]
  set max_rlabel_width 0
  for {set i 0} {$i<$num} {incr i} {
    # -- create right labels/function names; highlight selected functions in red
    set t [lindex $tags $i]
    set p [lindex $pers $i]
    if { $t == $pr_sel_tag } {
      set rl_obj($i) [$win create text 0 [expr 40+$i*20] \
                             -text "[lindex $rightlabels $i]" -anchor w -fill red \
                             -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
    } else {
      set rl_obj($i) [$win create text 0 [expr 40+$i*20] \
                             -text "[lindex $rightlabels $i]" -anchor w \
                             -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
    }
    set bbox [$win bbox $rl_obj($i)]
    set rlabel_width [expr [lindex $bbox 2] - [lindex $bbox 0]]
    if {$rlabel_width > $max_rlabel_width} {set max_rlabel_width $rlabel_width}

    # -- setup bindings for clicking on right labels
    if { $nodes == {} } {
      $win bind $rl_obj($i) <Button-1> "showFuncgraph $t"
      # showFuncTag is not implemented by racy
      # $win bind $ll_obj($i) <Button-2> \
      #     "PM_GlobalSelect $racy_progfile global_showFuncTag $t"
      $win bind $rl_obj($i) <Button-3> \
	  "PM_GlobalSelect $racy_progfile global_selectFuncTag $t"
    } else {
      $win bind $rl_obj($i) <Button-1> \
	  "showBargraph [lindex $nodes $i] {[lindex $rightlabels $i]}"
      $win bind $rl_obj($i) <Button-2> \
	  "showText [lindex $nodes $i] {[lindex $rightlabels $i]}"
    }
  }

  # -- create title
  set title [$win create text 0 20 \
		 -text "$bgtitle" -anchor w \
		 -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
  set bbox [$win bbox $title]
  set title_width [expr [lindex $bbox 2] - [lindex $bbox 0]]
  set max_r_width [max $title_width $max_rlabel_width]
  $win coords $title [expr $max_llabel_width + $max_bar_width + 5] 20

  # -- display bars and left labels according to mode
  for {set i 0} {$i<$num} {incr i} {
    set p [lindex $pers $i]
    if { $p > 0 } {
	# -- position left labels
	$win coords $ll_obj($i) [expr $max_llabel_width+$max_bar_width-$bar_width($i)-5] \
                            [expr 40+$i*20]

	# -- display bars and right labels according to mode
    
	set t [lindex $tags $i]
	$win create rectangle \
	  [expr $max_llabel_width+$max_bar_width-1-$bar_width($i)]  \
	  [expr 31+$i*20] \
	  [expr $max_llabel_width+$max_bar_width] \
	  [expr 49+$i*20] \
	  -fill $tagcol($t) -stipple $tagstip($t)
    }
    # -- position right labels
    $win coords $rl_obj($i) [expr $max_llabel_width + $max_bar_width + 5] \
                            [expr 40+$i*20]
  }

  #set w [expr $max_llabel_width + $max_bar_width + $max_rlabel_width + 40]
  set w [expr [expr $max_llabel_width + $max_bar_width + $max_rlabel_width]*500]
  set h [expr ($num+2)*20];       # height of window
  $win configure -scrollregion [list 0 0 $w $h]
  #$win xview moveto 1; # to shift view of canvas to right

}

#
# UserEbargraph: horizontal bargraph widget
#
#         win: pathname for bargraph
#     bgtitle: title for bargraph
# rightlabels: list of labels
#     percent: list of percent values
#      values: list of values
#        tags: list of corresponding Sage++ id of functions
#       nodes: list of corresponding node identifiers
#              (if nonempty used instead of tags)
#        mode: what to show as labels on the right side: per / val / none
#

#proc UserEbargraph {win bgtitle labels numval maxval minval stdval tags {unodes {}} {mode num} {orient right} } {
proc UserEbargraph {win bgtitle labels numval maxval minval  tags {unodes {}} {mode num} {orient right} } {
  global uecol uestip event
  global ue_sel_tag
  global racy_progfile

  if [DEBUG] {
      puts " "
      puts "UserEbargraph: "
      puts "  labels: $labels"
      puts "  numval: $numval"
      puts "  maxval: $maxval"
      puts "  minval: $minval"
      #puts "  stdval: $stdval"
      puts "  tags: $tags"
      puts "  unodes: $unodes"
      puts "  mode: $mode"
      puts "  ue_sel_tag: $ue_sel_tag"
  }

  set num [llength $labels];  # number of bars

  # -- create or reset canvas
  if { [winfo exists $win] } {
    $win delete all
  } else {
    canvas $win -background white
  }

  switch -exact $mode {
      num    { set totalnum [vectorsum numval] }
      max    { set totalmax [vectorsum maxval] }
      min    { set totalmin [vectorsum minval] }
      #stddev { set totalstd [vectorsum stdval] }
  }
   #------------------------------------------------------
   # display function name on the left side of bar graph
   #------------------------------------------------------
  if { $orient == "left" } {
    set max_llabel_width 0
    for {set i 0} {$i<$num} {incr i} {
    # -- create left labels; highlight selected functions in red
    set t [lindex $tags $i]
    if { $t == $ue_sel_tag } {
      set ll_obj($i) [$win create text 0 [expr 40+$i*20] \
               -text "[lindex $labels $i]" -anchor e -fill red \
               -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
    } else {
      set ll_obj($i) [$win create text 0 [expr 40+$i*20] \
               -text "[lindex $labels $i]" -anchor e \
               -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
    }
    set bbox [$win bbox $ll_obj($i)]
    set llabel_width [expr [lindex $bbox 2] - [lindex $bbox 0]]
    if {$llabel_width > $max_llabel_width} {set max_llabel_width $llabel_width}

    # -- setup bindings for clicking on left labels
    if { $unodes == {} } {
      $win bind $ll_obj($i) <Button-1> "showuserEgraph $t"
      $win bind $ll_obj($i) <Button-3> \
	  "PM_GlobalSelect $racy_progfile global_selectUserTag $t"
    } else {
      $win bind $ll_obj($i) <Button-1> \
	  "showUserEBargraph [lindex $unodes $i] {[lindex $labels $i]}"
      $win bind $ll_obj($i) <Button-2> \
	  "showUserEText [lindex $unodes $i] {[lindex $labels $i]}"
    }
  }

  # -- create title
  set title [$win create text 0 20 \
		 -text "$bgtitle" -anchor e \
		 -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
  set bbox [$win bbox $title]
  set title_width [expr [lindex $bbox 2] - [lindex $bbox 0]]
  set max_l_width [max $title_width $max_llabel_width]
  $win coords $title [expr $max_l_width+5] 20

  set max_r_width 0
  for {set i 0} {$i<$num} {incr i} {
    # -- position left labels
    $win coords $ll_obj($i) [expr $max_l_width+5] [expr 40+$i*20]

    # -- display bars and right labels according to mode

    if { [llength $numval] != 0 } {
      switch -exact $mode {
	  num { set p [format "%4.0f" [expr [lindex $numval $i] / $totalnum * 100]] }
	  max { set p [ expr [lindex $maxval $i] / $totalmax * 100 ] }
	  min { set p [ expr [lindex $minval $i] / $totalmin * 100 ] }
	  #stddev { set p [ expr [lindex $stdval $i] / $totalstd * 100 ] }
      }
    } else {
      switch -exact $mode {
	  num {  set totalnum [vectorsum event($unodes,$mode)]
	         set p [format "%4.0f" [expr [lindex $numval $i] / $totalnum * 100]] }
	  max {  set totalmax [vectorsum event($unodes,$mode)]
	         set p [ expr [lindex $maxval $i] / $totalmax * 100 ] }
	  min {  set totalmin [vectorsum event($unodes,$mode)]
	         set p [ expr [lindex $minval $i] / $totalmin * 100 ] }
	  #stddev { set totalstd [vectorsum event($unodes,$mode)]
	  #         set p [ expr [lindex $stdval $i] / $totalstd * 100 ] }
      }	
    }
    if { $p > 0 } {
      set t [lindex $tags $i]
      $win create rectangle \
	  [expr $max_l_width+10]\
	  [expr 31+$i*20] \
	  [expr $max_l_width+10+$p*2] \
	  [expr 49+$i*20] \
	  -fill $uecol($t) -stipple $uestip($t)
      switch -exact $mode {
	  num   { set rl_obj [$win create text \
				  [expr $max_l_width+15+$p*2] \
				  [expr 40+$i*20] \
				  -text "[lindex $numval $i]" -anchor w \
				  -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]}

	  max   { set rl_obj [$win create text \
				  [expr $max_l_width+15+$p*2] \
				  [expr 40+$i*20] \
				  -text "[wraplindex $maxval $i]" -anchor w \
				  -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]}

	  min   { set rl_obj [$win create text \
				  [expr $max_l_width+15+$p*2] \
				  [expr 40+$i*20] \
				  -text "[wraplindex $minval $i]" -anchor w \
				  -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]}

	  #stddev   { set rl_obj [$win create text \
	  #			  [expr $max_l_width+15+$p*2] \
	  #      		  [expr 40+$i*20] \
	  #			  -text "[wraplindex $stdval $i]" -anchor w \
	  #			  -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]}

          none  {}
      }
      set bbox [$win bbox $rl_obj]
      set r_width [expr $p*2 + [lindex $bbox 2] - [lindex $bbox 0]]
      if {$r_width > $max_r_width} {set max_r_width $r_width}
    }
  }

  set w [expr $max_l_width + $max_r_width + 20]
  set h [expr ($num+2)*20];       # height of window
  $win configure -scrollregion [list 0 0 $w $h]
  $win xview moveto 1; # to shift view of canvas to right

  } else {
   #-------------------------------------------------------
   # display function name on the right side of bar graph
   #-------------------------------------------------------
  set max_llabel_width 0
  set max_bar_width 0

  
  for {set i 0} {$i<$num} {incr i} {
    # -- display left labels according to mode
    if { [llength $numval] != 0 } {
      switch -exact $mode {
	  num { set p [format "%4.0f" [expr [lindex $numval $i] / $totalnum * 100]] }
	  max { set p [ expr [lindex $maxval $i] / $totalmax * 100 ] }
	  min { set p [ expr [lindex $minval $i] / $totalmin * 100 ] }
	  #stddev { set p [ expr [lindex $stdval $i] / $totalstd * 100 ] }
      }
    } else {
      switch -exact $mode {
	  num {  set totalnum [vectorsum event($unodes,$mode)]
	         set p [format "%4.0f" [expr [lindex $numval $i] / $totalnum * 100]] }
	  max {  set totalmax [vectorsum event($unodes,$mode)]
	         set p [ expr [lindex $maxval $i] / $totalmax * 100 ] }
	  min {  set totalmin [vectorsum event($unodes,$mode)]
	         set p [ expr [lindex $minval $i] / $totalmin * 100 ] }
	  #stddev { set totalstd [vectorsum event($unodes,$mode)]
	  #         set p [ expr [lindex $stdval $i] / $totalstd * 100 ] }
      }	
    }

    if { $p > 0 } {
      # -- set the width of bar graph
      set bar_width($i) [expr $p*2]
      if {$bar_width($i) > $max_bar_width} {set max_bar_width $bar_width($i)}
      # -- create left label according to its mode
      switch -exact $mode {
	  num   { set ll_obj($i) [$win create text 0 [expr 40+$i*20] \
				  -text "[wraplindex $numval $i]" -anchor e \
				  -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]}

	  max   { set ll_obj($i) [$win create text 0 [expr 40+$i*20] \
				  -text "[wraplindex $maxval $i]" -anchor e \
				  -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]}

	  min   { set ll_obj($i) [$win create text 0 [expr 40+$i*20] \
				  -text "[lindex $minval $i]" -anchor e \
				  -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]}

	  #stddev   { set ll_obj($i) [$win create text 0 [expr 40+$i*20] \
	  #			  -text "[wraplindex $stdval $i]" -anchor e \
	  #			  -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]}
          none  {}
      }
      set bbox [$win bbox $ll_obj($i)]
      set llabel_width [expr [lindex $bbox 2] - [lindex $bbox 0]]
      if {$llabel_width > $max_llabel_width} {set max_llabel_width $llabel_width}
    }
  }
  set max_llabel_width [expr $max_llabel_width + 10]
  set max_rlabel_width 0
  for {set i 0} {$i<$num} {incr i} {
    # -- create right labels/function names; highlight selected functions in red
    set t [lindex $tags $i]
    switch -exact $mode {
	num { set p [lindex $numval $i] }
	max { set p [lindex $maxval $i] }
	min { set p [lindex $minval $i] }
	#stddev { set p [lindex $stdval $i] }
    }
    if { $t == $ue_sel_tag } {
      set rl_obj($i) [$win create text 0 [expr 40+$i*20] \
                             -text "[lindex $labels $i]" -anchor w -fill red \
                             -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
    } else {
      set rl_obj($i) [$win create text 0 [expr 40+$i*20] \
                             -text "[lindex $labels $i]" -anchor w \
                             -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
    }
    set bbox [$win bbox $rl_obj($i)]
    set rlabel_width [expr [lindex $bbox 2] - [lindex $bbox 0]]
    if {$rlabel_width > $max_rlabel_width} {set max_rlabel_width $rlabel_width}

    # -- setup bindings for clicking on right labels
    if { $unodes == {} } {
	$win bind $rl_obj($i) <Button-1> "showuserEgraph $t"
	$win bind $rl_obj($i) <Button-3> \
	    "PM_GlobalSelect $racy_progfile global_selectUserTag $t"
    } else {
	$win bind $rl_obj($i) <Button-1> \
	    "showUserEBargraph [lindex $unodes $i] {[lindex $labels $i]}"
	$win bind $rl_obj($i) <Button-2> \
	    "showUserEText [lindex $unodes $i] {[lindex $labels $i]}"
    }
  }

  # -- create title
  set title [$win create text 0 20 \
		 -text "$bgtitle" -anchor w \
		 -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
  set bbox [$win bbox $title]
  set title_width [expr [lindex $bbox 2] - [lindex $bbox 0]]
  set max_r_width [max $title_width $max_rlabel_width]
  $win coords $title [expr $max_llabel_width + $max_bar_width + 5] 20

  # -- display bars and left labels according to mode
  for {set i 0} {$i<$num} {incr i} {
    switch -exact $mode {
	num { set p [lindex $numval $i] }
	max { set p [lindex $maxval $i] }
	min { set p [lindex $minval $i] }
	#stddev { set p [lindex $stdval $i] }
    }
    if { $p > 0 } {
	# -- position left labels
	$win coords $ll_obj($i) [expr $max_llabel_width+$max_bar_width-$bar_width($i)-5] \
                            [expr 40+$i*20]

	# -- display bars and right labels according to mode
    	set t [lindex $tags $i]
	$win create rectangle \
	  [expr $max_llabel_width+$max_bar_width-1-$bar_width($i)]  \
	  [expr 31+$i*20] \
	  [expr $max_llabel_width+$max_bar_width] \
	  [expr 49+$i*20] \
	  -fill $uecol($t) -stipple $uestip($t)
    }
    # -- position right labels
    $win coords $rl_obj($i) [expr $max_llabel_width + $max_bar_width + 5] \
                            [expr 40+$i*20]
  }

  #set w [expr $max_llabel_width + $max_bar_width + $max_rlabel_width + 40]
  set w [expr [expr $max_llabel_width + $max_bar_width + $max_rlabel_width]*500]
  set h [expr ($num+2)*20];       # height of window
  $win configure -scrollregion [list 0 0 $w $h]
  #$win xview moveto 1; # to shift view of canvas to right
  }
}

#
# selectFuncTag: implementation of global feature "selectFunction" for racy
#                display all instances of selected function in red and
#                show function profile, if possible
#
#           progfile: had better be == racy_progfile
#           tag: id of function to select
#

proc selectFuncTag {progfile tag} {
  global pr_sel_tag \
	  tagname racy_progfile

  if {$progfile != $racy_progfile} {
      return
  }

  if [DEBUG] {
    puts "\nselectFuncTag:"
    puts "  progfile: $progfile"
    puts "  racy_progfile: $racy_progfile"
    puts "  pr_sel_tag: $pr_sel_tag"
    puts "  tag: $tag"
  }

  set pr_sel_tag $tag
  redraw {} {}
  if [ info exists tagname($tag) ] { showFuncgraph $tag }
}

#
# selectUserTag: implementation of global feature "selectUserEvent" for racy
#                display all instances of selected event in red and
#                show user-defined event profile, if possible
#
#           progfile: had better be == racy_progfile
#           tag: id of user-defined event to select
#

proc selectUserTag {progfile tag} {
  global ue_sel_tag \
	  uename racy_progfile

  if {$progfile != $racy_progfile} {
      return
  }

  if [DEBUG] {
    puts "\nselectUserTag:"
    puts "  progfile: $progfile"
    puts "  racy_progfile: $racy_progfile"
    puts "  ue_sel_tag: $ue_sel_tag"
    puts "  tag: $tag"
  }

  set ue_sel_tag $tag
  redrawue {} {}
  if [ info exists uename($tag) ] { showuserEgraph $tag }
}



#
# showText: display text node profile window
#
#     node: id of node
#     name: full nameof node
#

proc showText {node name} {
  global myself
  global data
  global textorder1 textorder2
  global proforder profvalue profmode profunit

  if [DEBUG] {
    puts "\nshowText:"
    puts "  node: $node"
    puts "  name: $name"
  }

  if { ! [winfo exists .text$node] } {
    set textorder1($node) $profvalue(all)
    #if { $proforder(all) == "glob" } {
    #  set textorder2($node) $proforder(all)
    #} else {
    #  set textorder2($node) $node
    #}
    if { $proforder(all) == "all" } {
      set textorder2($node) $node
    } else {
      set textorder2($node) $proforder(all)
    }

    #toplevel .text$node
    #wm title .text$node "$name profile"
    set win2 [ toplevel .text$node]
    wm minsize $win2 1000 250
    wm title .text$node "$name profile"
   # $win2 configure  -scrollregion [list 0 0 1500 250]

    frame .text$node.mbar -relief raised -borderwidth 2

    menubutton .text$node.mbar.b1 -text File -menu .text$node.mbar.b1.m1 \
                                  -underline 0
    menu .text$node.mbar.b1.m1
    .text$node.mbar.b1.m1 add command -label "Close"  -underline 0 \
                    -command "destroy .text$node"

    menubutton .text$node.mbar.b2 -text Order -menu .text$node.mbar.b2.m1 \
                                  -underline 0
    menu .text$node.mbar.b2.m1
    submenu2 .text$node.mbar.b2.m1 textorder1 redrawText $node {$name}
    .text$node.mbar.b2.m1 add separator
    submenu3 .text$node.mbar.b2.m1 textorder2 redrawText $node {$name}

    menubutton .text$node.mbar.b3 -text Help -menu .text$node.mbar.b3.m1 \
                                  -underline 0
    menu .text$node.mbar.b3.m1
    if [ALONE] {
      .text$node.mbar.b3.m1 add command -label "on text node profile" \
	  -underline 3 \
	  -command "showHelp $myself 1.2.3-text 1"
    } else {
      .text$node.mbar.b3.m1 add command -label "on text node profile" \
	  -underline 3 \
	  -command "xsend tau \[list showHelp $myself 1.2.3-text 1\]"
    } 

    pack .text$node.mbar.b1 .text$node.mbar.b2 -side left -padx 5
    pack .text$node.mbar.b3 -side right -padx 5

    redrawText $node {$name}

    scrollbar .text$node.sv -orient vert -relief sunken \
	-command ".text$node.text yview"
    .text$node.text configure -yscrollcommand ".text$node.sv set"

    scrollbar .text$node.sh -orient horiz -relief sunken \
	-command ".text$node.text xview"
    .text$node.text configure -xscrollcommand ".text$node.sh set"

    button .text$node.but -text "close" -command "destroy .text$node"

    pack .text$node.mbar -side top -fill x
    pack .text$node.but -side bottom -fill x
    pack .text$node.sh -side bottom -fill x
    pack .text$node.sv -side right -fill y
    #pack .text$node.text -side left -ipadx 10 -ipady 10 -anchor center
    pack .text$node.text -side left -fill both -expand yes
  } else {
    raise .text$node
  }
}

#
# redrawText: create or update contents of text node profile window
#
#       node: id of node
#       name: full nameof node
#

proc redrawText {node name} {
  global data
  global tagname tagcol tagfcol
  global textorder1 textorder2
  global pr_sel_tag
  global racy_progfile alltags
  global newver
  global stddev
  global heading
  #global mheading
  global column


  if [DEBUG] {
    puts "\nredrawText:"
    puts "  node: $node"
    puts "  name: $name"
    puts "  newver: $newver"
  }

  set win .text$node.text
  set v $textorder1($node)
  #set tags $data($textorder2($node),${v}tags)
  #set tags $alltags
  if {$textorder2($node) == "glob"} {
    set tags $alltags
  } else {
    set tags $data($textorder2($node),${v}tags)
  }

  # -- create or reset text widget
  if { [winfo exists $win] } {
    $win configure -state normal
    $win delete 1.0 end
    $win configure -height [min 35 [expr 3+[llength $tags]]]
  } else {
      text $win -height [min 35 [expr 3+[llength $tags]]] \
	  -background white -foreground black -padx 5 -pady 5
  }

  # -- redraw text area

  if { $newver == 1 } {
    $win insert end \
     "---------------------------------------------------------------------------------------------------------------\n"
    foreach line $heading {
       $win insert end "$line\n"
    }
    $win insert end \
     "---------------------------------------------------------------------------------------------------------------\n"
  } else {
  $win insert end \
    "---------------------------------------------------------------------------------------------------\n"
  $win insert end \
    "%time         msec   total msec    #call   #subrs  usec/call name\n"
  $win insert end \
    "---------------------------------------------------------------------------------------------------\n"
  }
  #if { $newver == 1 } {
  #  $win insert end \
  #   "---------------------------------------------------------------------------------------------------------------\n"
  #  if { $node == "m" && $stddev == 1 } {
  #	foreach line $mheading {
  #	   $win insert end "$line\n"
  #	   set column [expr [llength $line]-1]
  #	}
  #  } else {
  #	foreach line $heading {
  #	   $win insert end "$line\n"
  #	   set column [expr [llength $line]-1]
  #	}
  #  }
  #  $win insert end \
  #    "---------------------------------------------------------------------------------------------------------------\n"
  #} else {
  #  $win insert end \
  #   "---------------------------------------------------------------------------------------------------\n"
  #  $win insert end \
  #   "%time         msec   total msec    #call   #subrs  usec/call name\n"
  #  $win insert end \
  #   "---------------------------------------------------------------------------------------------------\n"
  #} 


  set n 3
  set txt [order $textorder2($node) $node $tags $v text {}]

  foreach line $txt {
    incr n

    set t [lindex $tags [expr $n-4]]
    if { $line == "" } {
	if { $column == 8 } {
	    $win insert end \
		  "                                                                        $tagname($t)\n"
	} else {
	    $win insert end \
	       "                                                             $tagname($t)\n"
	}
    } else {
      $win insert end "$line\n"


      if { $t == $pr_sel_tag } {
	  if { $column == 8} {
	      $win tag add seltag $n.0 $n.78
	  } else { 
	      $win tag add seltag $n.0 $n.67
	  }
        $win tag configure seltag -foreground red
      }
    }
    #$win tag add t$n $n.67 "$n.67 lineend"
    if { $newver == 1 } {
	if { $column == 8} {
	    $win tag add t$n $n.78 "$n.78 lineend"
	} else {
	    $win tag add t$n $n.67 "$n.67 lineend"
	}
    } else {
        $win tag add t$n $n.67 "$n.67 lineend"   
    }
    if { [winfo depth .] == 2 } {
      $win tag configure t$n -background white -foreground black
    } else {
      $win tag configure t$n -background $tagcol($t) -foreground $tagfcol($t)
    }
    $win tag bind t$n <Button-1> "showFuncgraph $t"
    # showFuncTag is not implemented by racy
    # $win tag bind t$n <Button-2> "PM_GlobalSelect $racy_progfile global_showFuncTag $t"
    $win tag bind t$n <Button-3> "PM_GlobalSelect $racy_progfile global_selectFuncTag $t"
  }

  $win configure -wrap none
  $win configure -state disabled
}

#
# showUserEText: display text node profile window
#
#     node: id of node
#     name: full nameof node
#

proc showUserEText {node name} {
  global myevent
  global event
  global uetextorder1
  global eventorder eventmode

  if [DEBUG] {
    puts "\nshowUserEText:"
    puts "  node: $node"
    puts "  name: $name"
  }

  if { ! [winfo exists .eventtext$node] } {
    if { $eventorder(all) == "all" } {
      set uetextorder1($node) $node
    } else {
      set uetextorder1($node) $eventorder(all)
    }

    set winU2 [ toplevel .eventtext$node]
    wm minsize $winU2 700 250
    wm title .eventtext$node "$name profile"

    frame .eventtext$node.mbar -relief raised -borderwidth 2

    menubutton .eventtext$node.mbar.b1 -text File -menu .eventtext$node.mbar.b1.m1 \
                                  -underline 0
    menu .eventtext$node.mbar.b1.m1
    .eventtext$node.mbar.b1.m1 add command -label "Close"  -underline 0 \
                    -command "destroy .eventtext$node"

    menubutton .eventtext$node.mbar.b2 -text Order -menu .eventtext$node.mbar.b2.m1 \
                                  -underline 0
    menu .eventtext$node.mbar.b2.m1
    uesubmenu1 .eventtext$node.mbar.b2.m1 uetextorder1 redrawUserEText $node {$name}

    menubutton .eventtext$node.mbar.b3 -text Help -menu .eventtext$node.mbar.b3.m1 \
                                  -underline 0
    menu .eventtext$node.mbar.b3.m1
##HERE##
    #if [ALONE] {
    #  .eventtext$node.mbar.b3.m1 add command -label "on text node profile" \
    #	  -underline 3 \
    #	  -command "showHelp $myevent 1.2.3-text 1"
    #} else {
    #  .eventtext$node.mbar.b3.m1 add command -label "on text node profile" \
    #	  -underline 3 \
    #	  -command "xsend tau \[list showHelp $myevent 1.2.3-text 1\]"
    #} 

    pack .eventtext$node.mbar.b1 .eventtext$node.mbar.b2 -side left -padx 5
    pack .eventtext$node.mbar.b3 -side right -padx 5

    redrawUserEText $node {$name}

    scrollbar .eventtext$node.sv -orient vert -relief sunken \
	-command ".eventtext$node.text yview"
    .eventtext$node.text configure -yscrollcommand ".eventtext$node.sv set"

    scrollbar .eventtext$node.sh -orient horiz -relief sunken \
	-command ".eventtext$node.text xview"
    .eventtext$node.text configure -xscrollcommand ".eventtext$node.sh set"

    button .eventtext$node.but -text "close" -command "destroy .eventtext$node"

    pack .eventtext$node.mbar -side top -fill x
    pack .eventtext$node.but -side bottom -fill x
    pack .eventtext$node.sh -side bottom -fill x
    pack .eventtext$node.sv -side right -fill y
    #pack .eventtext$node.text -side left -ipadx 10 -ipady 10 -anchor center
    pack .eventtext$node.text -side left -fill both -expand yes
  } else {
    raise .eventtext$node
  }
}

#
# redrawUserEText: create or update contents of user-defined events
#                  text node profile window
#
#       node: id of node
#       name: full nameof node
#

proc redrawUserEText {node name} {
  global event
  global uename uecol uecol uefcol
  global uetextorder1
  global ue_sel_tag
  global racy_progfile usertags
  global eventheading

  if [DEBUG] {
    puts "\nredrawUserEText:"
    puts "  node: $node"
    puts "  name: $name"
  }

  set winU .eventtext$node.text

  if {$uetextorder1($node) == "glob"} {
    set tags $usertags
  } else {
    set tags $event($node,tags)
  }

  # -- create or reset text widget
  if { [winfo exists $winU] } {
    $winU configure -state normal
    $winU delete 1.0 end
    $winU configure -height [min 35 [expr 3+[llength $tags]]]
  } else {
      text $winU -height [min 35 [expr 3+[llength $tags]]] \
	  -background white -foreground black -padx 5 -pady 5
  }

  # -- redraw text area

  $winU insert end \
     "---------------------------------------------------------------------------------------------------------------\n"
    foreach line $eventheading {
       $winU insert end "$line\n"
    }
    $winU insert end \
     "---------------------------------------------------------------------------------------------------------------\n"



  set n 3
  set txt [ueorder $uetextorder1($node) $node $tags  text {}]

  foreach line $txt {
    incr n

    set t [lindex $tags [expr $n-4]]
    if { $line == "" } {
	$winU insert end \
	    "                                                                        $uename($t)\n"
    } else {
	$winU insert end "$line\n"


      if { $t == $ue_sel_tag } {
	  $winU tag add seltag $n.0 $n.56
	  $winU tag configure seltag -foreground red
      }
    }

    $winU tag add t$n $n.56 "$n.56 lineend"   
    
    if { [winfo depth .] == 2 } {
      $winU tag configure t$n -background white -foreground black
    } else {
      $winU tag configure t$n -background $uecol($t) -foreground $uefcol($t)
    }
    $winU tag bind t$n <Button-1> "showuserEgraph $t"
    $winU tag bind t$n <Button-3> "PM_GlobalSelect $racy_progfile global_selectUserTag $t"
  }

  $winU configure -wrap none
  $winU configure -state disabled
}


#
# order: return field of a data item in the same order it appear in
#        other data item. order is determined by "tags" field
#
# source: id of data which values determine sorting
# target: id of data to order
#  value: excl or incl
#  field: field of data to be sorted
#     NA: NULL value for this field
#

proc order {source target tags value field NA} {
  global data alltags
  if [DEBUG] {
    puts "\norder:"
    puts "  source: $source"
    puts "  target: $target"
    puts "  tags: $tags"
    puts "  value: $value"
    puts "  field: $field"
    puts "  NA: $NA"
  }

  if { $source == $target } {
    return $data($target,$value$field)
  } else {
    set result ""
    #foreach t $data($source,${value}tags)
    #foreach t $alltags
    foreach t $tags {
      set i [lsearch -exact $data($target,${value}tags) $t]
      if { $i == -1 } {
        lappend result $NA
      } else {
        lappend result [lindex $data($target,$value$field) $i]
      }
    }
    return $result
  }
}

#
# specialOrder: basically like order above, but only for numeric fields
#               corrects "other" entry in field
#

proc specialOrder {source target tags value field} {
  global data alltags
  if [DEBUG] {
    puts "\nspecialOrder:"
    puts "  source: $source"
    puts "  target: $target"
    puts "  tags: $tags"
    puts "  value: $value"
    puts "  field: $field"
  }
  if { $source == $target } {
    return $data($target,$value$field)
  } else {
    set result ""
    set na [vectorsum data($target,$value$field)]; #sum of all values
    #foreach t $data($source,${value}tags) 
    #foreach t $alltags 
    foreach t $tags {
      set i [lsearch -exact $data($target,${value}tags) $t]
      if { $i == -1 } {
        lappend result 0.0
      } else {
        set x [lindex $data($target,$value$field) $i]
        if { $t == -1 } {
          # -- tag -1 is the "others" element; always last one
          # -- use "notused" values instead of precalculated ones
          lappend result [format "%4.2f" $na]
        } else {
          set na [expr $na-$x]; #value used; subtract it from "notused" value
          lappend result $x
        }
      }
      }
    return $result
  }
}

#
# ueorder: return field of a data item in the same order it appear in
#          other data item. order is determined by "tags" field
#
#  source: id of data which values determine sorting
#  target: id of data to order
#   field: field of data to be sorted: num max min stddev
#      NA: NULL value for this field
#

proc ueorder {source target tags field NA} {
  global event usertags
  if [DEBUG] {
    puts "\nueorder:"
    puts "  source: $source"
    puts "  target: $target"
    puts "  tags: $tags"
    puts "  field: $field"
    puts "  NA: $NA"
  }

  if { $source == $target } {
    return $event($target,$field)
  } else {
    set result ""
    foreach t $tags {
      set i [lsearch -exact $event($target,tags) $t]
      if { $i == -1 } {
        lappend result $NA
      } else {
        lappend result [lindex $event($target,$field) $i]
      }
    }
    return $result
  }
}

#
# uespecialOrder: basically like order above, but only for numeric fields
#               corrects "other" entry in field
#

proc uespecialOrder {source target tags field} {
  global event usertags
  if [DEBUG] {
    puts "\nuespecialOrder:"
    puts "  source: $source"
    puts "  target: $target"
    puts "  tags: $tags"
    puts "  field: $field"
  }
  if { $source == $target } {
    return $event($target,$field)
  } else {
    set result ""
    set na [vectorsum event($target,$field)];
    #set total $na
    foreach t $tags {
      set i [lsearch -exact $event($target,tags) $t]
      if { $i == -1 } {
        lappend result 0.0
      } else {
        set x [lindex $event($target,$field) $i]
        if { $t == -1 } {
          # -- tag -1 is the "others" element; always last one
          # -- use "notused" values instead of precalculated ones
	    lappend result [format "%4.2f" [expr $na/$total*100]]
        } else {
          set na [expr $na-$x]; #value used; subtract it from "notused" value
	    #lappend result [expr $x/$total*100]
	    lappend result $x
        }
      }
      }
    return $result
  }
}


#
# submenu2: create "Value" menu
#
#      menu: pathname of menu
#       var: basename of global variable to store selection
#      func: function to call for redraw
# node,name: arguments to func
#

proc submenu2 {menu var func node name} {
  $menu add radiobutton -label "microseconds" \
                 -underline 0 -variable ${var}($node) -value excl \
                 -command "$func $node {$name}"
  $menu add radiobutton -label "total microseconds" \
                 -underline 0 -variable ${var}($node) -value incl \
                 -command "$func $node {$name}"
}

#
# submenu3: create "Order" menu
#
#      menu: pathname of menu
#       var: basename of global variable to store selection
#      func: function to call for redraw
# node,name: arguments to func
#

proc submenu3 {menu var func node name} {
  global funodes fulabels

  $menu add radiobutton -label "global" \
            -underline 0 -variable ${var}($node) -value glob \
            -command "$func $node {$name}"
  $menu add radiobutton -label "decreasing" \
            -underline 0 -variable ${var}($node) -value $node \
            -command "$func $node {$name}"

  $menu add cascade -label "node" \
            -underline 0 -menu $menu.1

  # -- create "node" submenu
  menu $menu.1
  set i 0
  foreach n $funodes {
    if { $n != {} } {
      $menu.1 add radiobutton -label [lindex $fulabels $i] \
                  -variable ${var}($node) -value $n \
	          -command "$func {$node} {$name}"
    } else {
      $menu.1 add separator
    }
    incr i
  }
}

#
# submenu4: create function profile "Mode" menu
#
#      menu: pathname of menu
#       var: basename of global variable to store selection
#      func: function to call for redraw
# node,name: arguments to func
#

proc submenu4 {menu var func node name} {
  $menu add radiobutton -label "percent" \
            -underline 0 -variable ${var}($node) -value per \
            -command "$func $node {$name}"
  $menu add radiobutton -label "value" \
            -underline 0 -variable ${var}($node) -value val \
            -command "$func $node {$name}"
}

#
# submenu5: create "Units" menu
#
#      menu: pathname of menu
#       var: basename of global variable to store selection
#      func: function to call for redraw
# node,name: arguments to func
#

proc submenu5 {menu var func node name} {
  $menu add radiobutton -label "microseconds" \
            -underline 0 -variable ${var}($node) -value 1.0 \
            -command "$func $node {$name}"
  $menu add radiobutton -label "milliseconds" \
            -underline 0 -variable ${var}($node) -value 1.0e3 \
            -command "$func $node {$name}"
  $menu add radiobutton -label "seconds" \
            -underline 0 -variable ${var}($node) -value 1.0e6 \
            -command "$func $node {$name}"
}

#
# submenu6: create collection profile "Mode" menu
#
#      menu: pathname of menu
#       var: basename of global variable to store selection
#      func: function to call for redraw
# node,name: arguments to func
#

proc submenu6 {menu var func node name} {
  $menu add radiobutton -label "local percent" \
            -underline 0 -variable ${var}($node) -value lper \
            -command "$func $node {$name}"
  $menu add radiobutton -label "global percent" \
            -underline 0 -variable ${var}($node) -value gper \
            -command "$func $node {$name}"
  $menu add radiobutton -label "value" \
            -underline 0 -variable ${var}($node) -value val \
            -command "$func $node {$name}"
}

#
# submenu6a: create aggregate profile "Mode" menu
#
#      menu: pathname of menu
#       var: basename of global variable to store selection
#      func: function to call for redraw
# node,name: arguments to func
#

proc submenu6a {menu var func node name} {
  $menu add radiobutton -label "percent" \
            -underline 0 -variable ${var}($node) -value lper \
            -command "$func $node {$name}"
  $menu add radiobutton -label "value" \
            -underline 0 -variable ${var}($node) -value val \
            -command "$func $node {$name}"
}

#
# uesubmenu1: create "Order" menu
#
#      menu: pathname of menu
#       var: basename of global variable to store selection
#      func: function to call for redraw
# node,name: arguments to func
#

proc uesubmenu1 {uemenu var func node name} {
  global uenodes uelabels

  $uemenu add radiobutton -label "global" \
            -underline 0 -variable ${var}($node) -value glob \
            -command "$func $node {$name}"
  $uemenu add radiobutton -label "decreasing" \
            -underline 0 -variable ${var}($node) -value $node \
            -command "$func $node {$name}" \
            -state disabled
  $uemenu add cascade -label "node" \
            -underline 0 -menu $uemenu.1

  # -- create "node" submenu
  menu $uemenu.1
  set i 0
  foreach n $uenodes {
    if { $n != {} } {
      $uemenu.1 add radiobutton -label [lindex $uelabels $i] \
                  -variable ${var}($node) -value $n \
	          -command "$func {$node} {$name}"
    } else {
      $uemenu.1 add separator
    }
    incr i
  }
}


#
# uesubmenu2: create "Mode" menu
#
#      menu: pathname of menu
#       var: basename of global variable to store selection
#      func: function to call for redrawevent
# node,name: arguments to func
#

proc uesubmenu2 {uemenu var func node name} {
  $uemenu add radiobutton -label "number" \
                 -underline 0 -variable ${var}($node) -value num \
                 -command "$func $node {$name}"
  $uemenu add radiobutton -label "maximum" \
                 -underline 0 -variable ${var}($node) -value max \
                 -command "$func $node {$name}"
  $uemenu add radiobutton -label "minimum" \
                 -underline 0 -variable ${var}($node) -value min \
                 -command "$func $node {$name}"
  $uemenu add radiobutton -label "standard deviation" \
                 -underline 0 -variable ${var}($node) -value stddev \
                 -command "$func $node {$name}" \
                 -state disabled
}
#
# uesubmenu3: create "Orient" menu
#
#      menu: pathname of menu
#       var: basename of global variable to store selection
#      func: function to call for redrawevent
# node,name: arguments to func
#

proc uesubmenu3 {uemenu var func node name} {
  $uemenu add radiobutton -label "left" \
                 -underline 0 -variable ${var}($node) -value left \
                 -command "$func $node {$name}" 
  $uemenu add radiobutton -label "right" \
                 -underline 0 -variable ${var}($node) -value right \
                 -command "$func $node {$name}"
}

#
# bargraphmenu: create menubar for node profile windows
#
#       parent: pathname for parent of menubar
#       prefix: prefix for global variables to store selections
#         func: function to call for redraw
#    node,name: arguments to func
#

proc bargraphmenu {parent prefix func node name} {
  global myself
  if [DEBUG] {
    puts "\nbargraphmenu:"
    puts "  parent: $parent"
    puts "  prefix: $prefix"
    puts "  func: $func"
    puts "  node: $node"
    puts "  name: $name"
  }
  set menubar $parent.mbar
  frame $menubar -relief raised -borderwidth 2
  menubutton $menubar.b1 -text File -menu $menubar.b1.m1 -underline 0
  menu $menubar.b1.m1
  $menubar.b1.m1 add command -label "Print" -underline 0 \
                    -command "printCanvas .bar${node}.bar node.$node"
  $menubar.b1.m1 add separator
  $menubar.b1.m1 add command -label "Close" -underline 0 \
                    -command "destroy .bar$node"

  menubutton $menubar.b2 -text Value -menu $menubar.b2.m1 -underline 0
  menu $menubar.b2.m1
  submenu2 $menubar.b2.m1 ${prefix}value $func $node {$name}

  menubutton $menubar.b3 -text Order -menu $menubar.b3.m1 -underline 0
  menu $menubar.b3.m1
  submenu3 $menubar.b3.m1 ${prefix}order $func $node {$name}

  menubutton $menubar.b4 -text Mode -menu $menubar.b4.m1 -underline 0
  menu $menubar.b4.m1
  submenu4 $menubar.b4.m1 ${prefix}mode $func $node {$name}

  menubutton $menubar.b5 -text Units -menu $menubar.b5.m1 -underline 0
  menu $menubar.b5.m1
  submenu5 $menubar.b5.m1 ${prefix}unit $func $node {$name}

  menubutton $menubar.b6 -text Help -menu $menubar.b6.m1 -underline 0
  menu $menubar.b6.m1
  if [ALONE] {
    $menubar.b6.m1 add command -label "on node profile" -underline 3 \
	              -command "showHelp $myself 1.2.2-node 1"
  } else {
    $menubar.b6.m1 add command -label "on node profile" -underline 3 \
	              -command "xsend tau \[list showHelp $myself 1.2.2-node 1\]"
  }

  pack $menubar.b1 $menubar.b2 $menubar.b3 $menubar.b4 $menubar.b5\
       -side left -fill x -padx 5
  pack $menubar.b6 -side right -fill x -padx 5
}

#
# eventbargraphmenu: create menubar for node profile windows
#
#            parent: pathname for parent of menubar
#            prefix: prefix for global variables to store selections
#              func: function to call for redraw
#         node,name: arguments to func
#

proc eventbargraphmenu {parent prefix func node name} {
  global myevent
  if [DEBUG] {
    puts "\neventbargraphmenu:"
    puts "  parent: $parent"
    puts "  prefix: $prefix"
    puts "  func: $func"
    puts "  node: $node"
    puts "  name: $name"
  }
  set menubar $parent.mbar
  frame $menubar -relief raised -borderwidth 2
  menubutton $menubar.b1 -text File -menu $menubar.b1.m1 -underline 0
  menu $menubar.b1.m1
  $menubar.b1.m1 add command -label "Print" -underline 0 \
                    -command "printCanvas .eventbar${node}.bar node.$node"
  $menubar.b1.m1 add separator
  $menubar.b1.m1 add command -label "Close" -underline 0 \
                    -command "destroy .eventbar$node"

  menubutton $menubar.b2 -text Order -menu $menubar.b2.m1 -underline 0
  menu $menubar.b2.m1
  uesubmenu1 $menubar.b2.m1 ${prefix}order $func $node {$name}

  menubutton $menubar.b3 -text Mode -menu $menubar.b3.m1 -underline 0
  menu $menubar.b3.m1
  uesubmenu2 $menubar.b3.m1 ${prefix}mode $func $node {$name}

  menubutton $menubar.b4 -text Orientation -menu $menubar.b4.m1 -underline 0 
  menu $menubar.b4.m1 
  uesubmenu3 $menubar.b4.m1 ${prefix}orient $func $node {$name}

  menubutton $menubar.b5 -text Help -menu $menubar.b5.m1 -underline 0
  menu $menubar.b5.m1
##HERE##
  #if [ALONE] {
  #  $menubar.b5.m1 add command -label "on node profile" -underline 3 \
  #	              -command "showHelp $myevent 1.2.2-node 1"
  #} else {
  #  $menubar.b5.m1 add command -label "on node profile" -underline 3 \
  #	              -command "xsend tau \[list showHelp $myevent 1.2.2-node 1\]"
  #}

  pack $menubar.b1 $menubar.b2 $menubar.b3 $menubar.b4 \
       -side left -fill x -padx 5
  pack $menubar.b5 -side right -fill x -padx 5
}

#
# showBargraph: display node profile window
#
#         node: id of node
#         name: full nameof node
#

proc showBargraph {node name} {
  global barorder barmode barvalue barunit
  global proforder profvalue profmode profunit
  if [DEBUG] {
    puts "\nshowBargraph:"
    puts "  node: $node"
    puts "  name: $name"
    #puts "  barorder($node): $barorder($node)"
    #puts "  barmode($node): $barmode($node)"
    #puts "  barvalue($node): $barvalue($node)"
    #puts "  barunit($node): $barunit($node)"
    puts "  proforder(all): $proforder(all)"
    puts "  profvalue(all): $profvalue(all)"
    puts "  profmode(all): $profmode(all)"
    puts "  profunit(all): $profunit(all)"
  }

  if { ! [winfo exists .bar$node] } {
    #if { $proforder(all) == "glob" } {
    #  set barorder($node) $proforder(all)
    #} else {
    #  set barorder($node) $node
    #}
    if { $proforder(all) == "all" } {
      set barorder($node) $node
    } else {
      set barorder($node) $proforder(all)
    }
    set barmode($node) $profmode(all)
    set barvalue($node) $profvalue(all)
    set barunit($node) $profunit(all)

    set win [toplevel .bar$node]
    wm title $win "$name profile"
    #wm minsize $win 250 250
    wm minsize $win 500 250

    bargraphmenu .bar$node bar redrawBargraph $node {$name}
    redrawBargraph $node {$name}

    scrollbar .bar$node.sv -orient vert -relief sunken \
	-command ".bar$node.bar yview"
    .bar$node.bar configure -yscrollcommand ".bar$node.sv set"

    scrollbar .bar$node.sh -orient horiz -relief sunken \
	-command ".bar$node.bar xview"
    .bar$node.bar configure -xscrollcommand ".bar$node.sh set"

    button .bar$node.but -text "close" -command "destroy $win"

    pack .bar$node.mbar -side top -fill x
    pack .bar$node.but -side bottom -fill x
    pack .bar$node.sh -side bottom -fill x
    pack .bar$node.sv -side right -fill y
    pack .bar$node.bar -side left -fill both -expand yes
  } else {
    raise .bar$node
  }
}

#
# redrawBargraph: create or update contents of node profile window
#
#           node: id of node
#           name: full nameof node
#

proc redrawBargraph {node name} {
  global data
  global barorder barmode barvalue barunit
  global tagname alltags
  if [DEBUG] {
    puts "\nredrawBargraph:"
    puts "  node: $node"
    puts "  name: $name"
    puts "  barorder($node): $barorder($node)"
    puts "  barmode($node): $barmode($node)"
    puts "  barvalue($node): $barvalue($node)"
    puts "  barunit($node): $barunit($node)"
    #puts "  tagname: $tagname"
    puts "  alltags: $alltags"
  }    
  set v $barvalue($node)
  #foreach t $data($barorder($node),${v}tags) 
  #foreach t $alltags {
  #  lappend n $tagname($t)
  #}
  if {$barorder($node) == "glob"} {
      set currtags $alltags
  } else {
      #puts " data($barorder($node),${v}tags): $data($barorder($node),${v}tags)"
      set currtags $data($barorder($node),${v}tags)
  }
  foreach t $currtags {
      lappend n $tagname($t)
  }
  set u [specialOrder $barorder($node) $node $currtags $v usecs]

  # -- add title within window for bargraph
  # -- $name is not always available, so must use $node
  switch $node {
      t       {set title "total"}
      m       {set title "mean"}
#      <       {set title "min"}
#      >       {set title "max"}
      default {
	  set title ""
	  set title [append $title "n,c,t " $node]
      }
  }
  bargraph .bar$node.bar $title $n \
                         [specialOrder $barorder($node) $node $currtags $v percent] \
                         [vectorop u / $barunit($node)] \
                         [order $barorder($node) $node $currtags $v tags -2] \
                         {} $barmode($node)
  if { $barmode($node) == "val" } {
    .bar$node.mbar.b5 configure -state normal
  } else {
    .bar$node.mbar.b5 configure -state disabled
  }
}

#
# showUserEBargraph: display user-event node profile window
#
#         node: id of node
#         name: full name of node
#

proc showUserEBargraph {node name} {
  global eventmode eventorder eventorient
  global eventbarmode eventbarorder eventbarorient

  if [DEBUG] {
    puts "\nshowUserEBargraph:"
    puts "  node: $node"
    puts "  name: $name"
    puts "  eventorder(all): $eventorder(all)"
    puts "  eventmode(all): $eventmode(all)"
    puts "  eventorient(all): $eventorient(all)"
  }

  if { ! [winfo exists .eventbar$node] } {
    if { $eventorder(all) == "all" } {
      set eventbarorder($node) $node
    } else {
      set eventbarorder($node) $eventorder(all)
    }
    set eventbarmode($node) $eventmode(all)
    set eventbarorient($node) $eventorient(all)

    set win [toplevel .eventbar$node]
    wm title $win "$name - event profile"
    #wm minsize $win 250 250
    wm minsize $win 500 250

    eventbargraphmenu .eventbar$node eventbar redrawUserEBargraph $node {$name}
    redrawUserEBargraph $node {$name}

    scrollbar .eventbar$node.sv -orient vert -relief sunken \
	-command ".eventbar$node.bar yview"
    .eventbar$node.bar configure -yscrollcommand ".eventbar$node.sv set"

    scrollbar .eventbar$node.sh -orient horiz -relief sunken \
	-command ".eventbar$node.bar xview"
    .eventbar$node.bar configure -xscrollcommand ".eventbar$node.sh set"

    button .eventbar$node.but -text "close" -command "destroy $win"

    pack .eventbar$node.mbar -side top -fill x
    pack .eventbar$node.but -side bottom -fill x
    pack .eventbar$node.sh -side bottom -fill x
    pack .eventbar$node.sv -side right -fill y
    pack .eventbar$node.bar -side left -fill both -expand yes
  } else {
    raise .eventbar$node
  }
}

#
# redrawUserEBargraph: create or update contents of node profile window
#
#           node: id of node
#           name: full nameof node
#

proc redrawUserEBargraph {node name} {
  global event
  global eventbarorder eventbarmode eventbarorient
  global usertags uename
  if [DEBUG] {
    puts "\nredrawUserEBargraph:"
    puts "  node: $node"
    puts "  name: $name"
  }    

  if {$eventbarorder($node) == "glob"} {
      set currtags $usertags
  } else {
      set currtags $event($eventbarorder($node),tags)
  }
  foreach t $currtags {
      lappend n $uename($t)
  }
 
  set nm [uespecialOrder $eventbarorder($node) $node $currtags num]
  set mx [uespecialOrder $eventbarorder($node) $node $currtags max]
  set mn [uespecialOrder $eventbarorder($node) $node $currtags min]
  #set sd [uespecialOrder $eventbarorder($node) $node $currtags stddev]

  # -- add title within window for bargraph
  # -- $name is not always available, so must use $node
  switch $node {
      t       {set title "total"}
      m       {set title "mean"}
#      <       {set title "min"}
#      >       {set title "max"}
      default {
	  set title ""
	  set title [append $title "n,c,t " $node]
      }
  }

#  UserEbargraph .eventbar$node.bar $title $n $nm $mx $mn $sd \
#                        [ueorder $eventbarorder($node) $node $currtags tags -2] \
#                         {} $eventbarmode($node) $eventbarorient($node)
# This doesn't have std dev option...
  UserEbargraph .eventbar$node.bar $title $n $nm $mx $mn  \
      [ueorder $eventbarorder($node) $node $currtags tags -2] \
      {} $eventbarmode($node) $eventbarorient($node)
}


#
# multiFuncgraph: create summary function bargraphs
#
#            win: pathname for canvas
#     leftlabels: list of labels for left side of bargraphs
#          nodes: list of node ids
#       percents: list of list of percentage values
#           tags: list of tags 
#

proc multiFuncgraph {win leftlabels nodes percents tags} {
  global tagcol tagstip
  global minheight
  global racy_progfile

  if [DEBUG] {
      puts "multiFuncgraph:"
      puts "  leftlabels: $leftlabels"
      puts "  nodes: $nodes"
      puts "  percents: $percents"
      puts "  tags: $tags"
      puts "  minheight: $minheight"
      puts "  racy_progfile: $racy_progfile"
  }

  set num [llength $leftlabels];  #number of bars
  set h [expr ($num+1)*20];       #height of the display

  # -- create or reset canvas
  if { [winfo exists $win] } {
    $win delete all
    $win configure -height [min 420 $minheight]
  } else {
    canvas $win -width 300 -height [min 420 $minheight] -background white
  }
  bind $win <2> "$win scan mark %x %y"
  bind $win <B2-Motion> "$win scan dragto %x %y"
  $win configure -scrollregion [list 0 0 300 $h]

  set max_rlabel_width 0 ;# previously constant at 60
  for {set i 0} {$i<$num} {incr i} {
      # -- draw left labels
      if {[lindex $leftlabels $i] != {}} {
	  set rl_obj($i) [$win create text 0 [expr 20+$i*20] \
		  -text "[lindex $leftlabels $i]" -anchor e \
		  -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
	  set bbox [$win bbox $rl_obj($i)]
	  set lwidth [expr [lindex $bbox 2] - [lindex $bbox 0]]
	  if {$lwidth > $max_rlabel_width} {set max_rlabel_width $lwidth}
	  
	  # -- setup bindings for left labels, if necessary
 	  $win bind $rl_obj($i) <Button-1> \
		  "showBargraph [lindex $nodes $i] {[lindex $leftlabels $i]}"
	  $win bind $rl_obj($i) <Button-2> \
		  "showText [lindex $nodes $i] {[lindex $leftlabels $i]}"
      }
  }

  for {set i 0} {$i<$num} {incr i} {
    
    # -- move the right labels into place
    if {[lindex $leftlabels $i] != {}} {
      $win coords $rl_obj($i) \
	      [expr $max_rlabel_width + 5] [expr 20+$i*20]
    }
      
    # -- display multibar, and create bindings for each subbar
    set p [lindex $percents $i]
    set sum 0.0
    for {set j 0} {$j<[llength $p]} {incr j} {
      #if { [lindex $p $j] > 0 } {
      #  set obj [$win create rectangle \
      #		[expr $max_rlabel_width+10+$sum*2] \
      #		[expr 29+$i*20] \
      #		[expr $max_rlabel_width+10+($sum+[lindex $p $j])*2] \
      #		[expr 11+$i*20]\
      #		-fill $tagcol([lindex $tags $j]) \
      #		-stipple $tagstip([lindex $tags $j])]
      #  set t [lindex $tags $j]
      #  $win bind $obj <Button-1> "showFuncgraph $t"
      #	# showFuncTag is not implemented by racy
      #  # $win bind $obj <Button-2> "PM_GlobalSelect $racy_progfile global_showFuncTag $t"
      #  $win bind $obj <Button-3> "PM_GlobalSelect $racy_progfile global_selectFuncTag $t"
      #  set sum [expr $sum+[lindex $p $j]]
      # }

      #fix the jagged edge of multiFuncgraph
      if { [lindex $p $j] > 0 } {
        set obj [$win create rectangle \
		[expr $max_rlabel_width+10+$sum*2] \
		[expr 29+$i*20] \
		[expr $max_rlabel_width+11+($sum+[lindex $p $j])*2] \
		[expr 11+$i*20]\
		-fill $tagcol([lindex $tags $j]) \
		-stipple $tagstip([lindex $tags $j])]
        set t [lindex $tags $j]
        $win bind $obj <Button-1> "showFuncgraph $t"
	# showFuncTag is not implemented by racy
        # $win bind $obj <Button-2> "PM_GlobalSelect $racy_progfile global_showFuncTag $t"
        $win bind $obj <Button-3> "PM_GlobalSelect $racy_progfile global_selectFuncTag $t"
        set sum [expr $sum+[lindex $p $j]]
      }
    }
  } 

  set w [expr $max_rlabel_width + 230]
  $win configure -width $w
  $win configure -scrollregion [list 0 0 $w $h]
}

#
# multiCollgraph: create collection profile bargraphs
#
#            win: pathname for canvas
#     leftlabels: list of labels for left side of bargraphs
#         idents: list of collection ids
#       percents: list of list of percentage values
#         values: list of values
#           mode: display mode: none or lper or gper
#          scale: scale factor for bars
#

proc multiCollgraph {win leftlabels idents percents \
	{values {}} {mode none} {scale 1.0}} {
  global minheight
  global TAUDIR

  if [DEBUG] {
	puts "multiCollgraph:"
	puts "  leftlabels: $leftlabels"
	puts "  idents: $idents"
	puts "  percents: $percents"
	puts "  values: $values"
	puts "  mode: $mode"
	puts "  scale: $scale"
  }

  if { [winfo depth .] == 2 } {
    set cols {black black}
    set stipps [list @$TAUDIR/xbm/gray3.bm {}]
  } else {
    set cols {green red}
    set stipps [list {} {}]
  }
  set num [llength $leftlabels];           #number of bars (lines)
  set h [expr ($num+1)*20];                #screen height
  set nbar [llength [lindex $percents 0]]; #number of subbars per bar

  # -- screen width different with and without right side labels
  if { $mode == "none" } {
    set w 300
  } else {
    set w [expr 300+$nbar*60]
  }

  # -- create or update drawing canvas
  if { [winfo exists $win] } {
    $win delete all
    $win configure -height [min 420 $minheight]
  } else {
    canvas $win -width $w -height [min 420 $minheight] -background white
    bind $win <2> "$win scan mark %x %y"
    bind $win <B2-Motion> "$win scan dragto %x %y"
  }
  #$win configure -scrollregion [list 0 0 $w $h]

    set max_rlabel_width 0 ;# previously constant at 60
    for {set i 0} {$i<$num} {incr i} {
	# -- draw left labels
	if {[lindex $leftlabels $i] != {}} {
	    set rl_obj($i) [$win create text 0 [expr 20+$i*20] \
		    -text "[lindex $leftlabels $i]" -anchor e \
		    -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
	    set bbox [$win bbox $rl_obj($i)]
	    set lwidth [expr [lindex $bbox 2] - [lindex $bbox 0]]
	    if {$lwidth > $max_rlabel_width} {set max_rlabel_width $lwidth}
	    
	    # -- setup bindings for left labels, if necessary
	    if { $idents != "" } {
		$win bind $rl_obj($i) <Button-1> \
			"showCollgraph [lindex $idents $i]"
	    }
	}
    }

  for {set i 0} {$i<$num} {incr i} {
      
    # -- move the right labels into place
    if {[lindex $leftlabels $i] != {}} {
      $win coords $rl_obj($i) \
	      [expr $max_rlabel_width + 5] [expr 20+$i*20]
    }

    # -- draw bars and right labels
    set p [lindex $percents $i]
    set sum 0.0
    for {set j 0} {$j<$nbar} {incr j} {
      # -- draw subbars, if value > 0
      set sc [expr [lindex $p $j]*$scale]
      if { $sc > 0 } {
        # -- don't draw first bar (total) if mode is global percent, as this
        # -- bar would be *very* big
        if { $i != 0 || $mode == "lper" || $mode == "none" } {
          set obj [$win create rectangle \
		  [expr $max_rlabel_width+10+$sum*2] \
		  [expr 29+$i*20] \
		  [expr $max_rlabel_width+10+($sum+$sc)*2] \
		  [expr 11+$i*20] \
		  -fill [lindex $cols $j] -stipple [lindex $stipps $j]]
	  set sum [expr $sum+$sc]
        }

        # -- draw right labels according to mode
        switch -glob $mode {
          none {}
          [lg]per { $win create text \
		  [expr $max_rlabel_width+280+$j*60] \
		  [expr 20+$i*20] \
                 -text [format "%.2f%%" [lindex $p $j]] -anchor e \
                 -font -Adobe-Helvetica-Bold-R-Normal--*-120-*}
	   val  { $win create text \
		 [expr $max_rlabel_width+280+$j*60] \
		 [expr 20+$i*20] \
                 -text [lindex [lindex $values $i] $j] -anchor e \
                 -font -Adobe-Helvetica-Bold-R-Normal--*-120-*}
        }
      }
    }
  }

  if {$mode == "none"} {
      set w [expr $max_rlabel_width + 280]
  } else {
      set w [expr $max_rlabel_width + 290 + 60*$nbar]
  }      
  $win configure -width $w
  $win configure -scrollregion [list 0 0 $w $h]

}

#
# multiAggrgraph: create aggregate profile bargraphs
#
#            win: pathname for canvas
#     leftlabels: list of labels for left side of bargraphs
#         idents: list of aggregate ids
#       percents: list of list of percentage values
#         values: list of values
#           mode: display mode: none or lper or gper
#          scale: list of scale factor for bars
#        bar_for: bars drawn for "aggr" or "node"
#

proc multiAggrgraph {win leftlabels idents percents \
	{values {}} {mode none} {scale {}}  {bar_for "aggr"}} {
    global minheight evcol evstip evname aggr
    global TAUDIR
    
    if [DEBUG] {
	puts "multiAggrgraph:"
	puts "  leftlabels: $leftlabels"
	puts "  idents: $idents"
	puts "  percents: $percents"
	puts "  values: $values"
	puts "  mode: $mode"
	puts "  scale: $scale"
	puts "  bar_for: $bar_for"
    }

    if {$scale == {}} {
	set fill_scales 1
    } else {
	set fill_scales 0
    }

    set head 25
    set num [llength $leftlabels];           #number of bars (lines)
    set h [expr $head+($num+1)*20];             #screen height

    set maxnbar 0
    for {set i 0} {$i < $num} {incr i} {
	if {$fill_scales} { lappend scale 1.0}
	if {[llength [lindex $percents $i]] > $maxnbar} {
	    set maxnbar [llength [lindex $percents $i]]
	}
    }
    
    # -- screen width different with and without right side labels
    if { $mode == "none" } {
	set w 300
    } else {
	set w 500
    }
    
    # -- create or update drawing canvas
    if { [winfo exists $win] } {
	$win delete all
	$win configure -height [min 420 $minheight]
    } else {
	canvas $win -width $w -height [min 420 $minheight] -background white
	bind $win <2> "$win scan mark %x %y"
	bind $win <B2-Motion> "$win scan dragto %x %y"
    }
    #$win configure -scrollregion [list 0 0 $w $h]
    
    set max_rlabel_width 0 ;# previously constant at 60
    for {set i 0} {$i<$num} {incr i} {
	# -- draw left labels
	if {[lindex $leftlabels $i] != {}} {
	    set rl_obj($i) [$win create text 0 [expr $head+20+$i*20] \
		    -text "[lindex $leftlabels $i]" -anchor e \
		    -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
	    set bbox [$win bbox $rl_obj($i)]
	    set lwidth [expr [lindex $bbox 2] - [lindex $bbox 0]]
	    if {$lwidth > $max_rlabel_width} {set max_rlabel_width $lwidth}
	    
	    # -- setup bindings for left labels, if necessary
	    if { $bar_for == "aggr" } {
		$win bind $rl_obj($i) <Button-1> \
			"showAggrgraph [lindex $idents $i]"
	    }
	}
    }

    # -- draw the event titles
    if {$mode != "none"} {
	set xpos [expr 220 + $max_rlabel_width] ;#280
	for {set j 0} {$j<$maxnbar} {incr j} {
	    set obj [$win create text -100 5 \
		    -text $evname([lindex $aggr([lindex $idents 0],counter_set) $j]) \
		    -font -Adobe-Helvetica-Bold-R-Normal--*-120-* \
		    -anchor ne]
	    set objrect [$win bbox $obj]
	    set label_width \
		    [expr [lindex $objrect 2] - [lindex $objrect 0]]
	    if {$label_width < 55} {set label_width 55}
	    set label_pos($j) [expr $xpos + $label_width]
	    $win coords $obj [expr $xpos + $label_width] 5
	    set xpos [expr $xpos + $label_width + 5]
	}
    } else {
	set xpos $w
    }

    for {set i 0} {$i<$num} {incr i} {
	set nbar [llength [lindex $percents $i]]; #number of subbars per bar
	# -- move the right labels into place
	if {[lindex $leftlabels $i] != {}} {
	    $win coords $rl_obj($i) \
		    [expr $max_rlabel_width + 5] [expr $head+20+$i*20]
	}

	# -- draw bars and right labels
	set p [lindex $percents $i]
	set sum 0.0
	for {set j 0} {$j<$nbar} {incr j} {
	    # -- draw subbars, if value > 0
	    set sc [lindex $p $j]
	    if {$i != 0} { set sc [expr $sc * [lindex $scale $i]] }
	    if { $sc >= 0 } {
		if {$bar_for == "aggr" } {
		    set col $evcol([lindex $aggr([lindex $idents $i],counter_set) $j])
		    set stip $evstip([lindex $aggr([lindex $idents $i],counter_set) $j])
		} else {
		    # bar_for == "node"
		    set col $evcol([lindex $aggr([lindex $idents 0],counter_set) $j])
		    set stip $evstip([lindex $aggr([lindex $idents 0],counter_set) $j])
		}
		set obj [$win create rectangle \
			[expr $max_rlabel_width+10+$sum*2] \
			[expr $head+29+$i*20] \
			[expr $max_rlabel_width+10+($sum+$sc)*2] \
			[expr $head+11+$i*20] \
                        -fill $col -stipple $stip]
		$win bind $obj <Button-1> "showEventLegend"
		set sum [expr $sum+$sc]
		
		# -- draw right labels according to mode
		switch -glob $mode {
		    none {}
		    [lg]per { $win create text \
			    $label_pos($j) [expr $head+20+$i*20] \
			    -text [format "%.2f%%" [lindex $p $j]] -anchor e \
			    -font -Adobe-Helvetica-Bold-R-Normal--*-120-*}
		    val  { $win create text \
			    $label_pos($j) [expr $head+20+$i*20] \
			    -text [lindex [lindex $values $i] $j] -anchor e \
			    -font -Adobe-Helvetica-Bold-R-Normal--*-120-*}
		}
	    }
	}
    }

    if {$mode == "none"} {
	set w [expr $max_rlabel_width + 10 + 215]
	$win configure -width $w
	$win configure -scrollregion [list 0 0 $w $h]
    } else {
	$win configure -scrollregion [list 0 0 $xpos $h]
    }
}

#
# multiEventgraph: create user events bargraphs
#
#            win: pathname for canvas
#     leftlabels: list of labels for left side of bargraphs
#          nodes: list of node ids
#       percents: list of list of user defined values
#           tags: list of tags 
#

proc multiEventgraph {win leftlabels nodes values tags} {
  global uecol uestip
  global minheight
  global TAUDIR
  global racy_progfile

  if [DEBUG] {
      puts "multiEventgraph:"
      puts "  leftlabels: $leftlabels"
      puts "  nodes: $nodes"
      puts "  values: $values"
      puts "  tags: $tags"
      puts "  minheight: $minheight"
      #puts "  racy_progfile: $racy_progfile"
  }

  set num [llength $leftlabels];  #number of bars
  set h [expr ($num+1)*20];       #height of the display

  # -- create or reset canvas
  if { [winfo exists $win] } {
    $win delete all
    $win configure -height [min 420 $minheight]
  } else {
    canvas $win -width 300 -height [min 420 $minheight] -background white
    bind $win <2> "$win scan mark %x %y"
    bind $win <B2-Motion> "$win scan dragto %x %y"
  }
  $win configure -scrollregion [list 0 0 300 $h]

  set max_rlabel_width 0 ;# previously constant at 60
  for {set i 0} {$i<$num} {incr i} {
      # -- draw left labels
      if {[lindex $leftlabels $i] != {}} {
	  set rl_obj($i) [$win create text 0 [expr 20+$i*20] \
		  -text "[lindex $leftlabels $i]" -anchor e \
		  -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
	  set bbox [$win bbox $rl_obj($i)]
	  set lwidth [expr [lindex $bbox 2] - [lindex $bbox 0]]
	  if {$lwidth > $max_rlabel_width} {set max_rlabel_width $lwidth}
	  
	  # -- setup bindings for left labels, if necessary
 	  $win bind $rl_obj($i) <Button-1> \
	  	  "showUserEBargraph [lindex $nodes $i] {[lindex $leftlabels $i]}"
	  $win bind $rl_obj($i) <Button-2> \
	  	  "showUserEText [lindex $nodes $i] {[lindex $leftlabels $i]}"
      }
  }

  for {set i 0} {$i<$num} {incr i} {
    
    # -- move the right labels into place
    if {[lindex $leftlabels $i] != {}} {
      $win coords $rl_obj($i) \
	      [expr $max_rlabel_width + 5] [expr 20+$i*20]
    }
      
    # -- display multibar, and create bindings for each subbar
    set p [lindex $values $i]
    set sum 0.0
    for {set j 0} {$j<[llength $p]} {incr j} {
      #fix the jagged edge of multiFuncgraph
      if { [lindex $p $j] > 0 } {
        set obj [$win create rectangle \
		[expr $max_rlabel_width+10+$sum*2] \
		[expr 29+$i*20] \
		[expr $max_rlabel_width+11+($sum+[lindex $p $j])*2] \
		[expr 11+$i*20]\
		-fill $uecol([lindex $tags $j]) \
		-stipple $uestip([lindex $tags $j])]
        set t [lindex $tags $j]
          $win bind $obj <Button-1> "showuserEgraph $t"
	  $win bind $obj <Button-3> "PM_GlobalSelect $racy_progfile global_selectUserTag $t"
        set sum [expr $sum+[lindex $p $j]]
      }
    }
  } 

  set w [expr $max_rlabel_width + 230]
  $win configure -width $w
  $win configure -scrollregion [list 0 0 $w $h]
}


#
# readProfile: read in profile data by using the "pprof" tool
#
#         dir: directory in which profile data should be looked for
#

set wantnum 100000

proc readProfile {} {
    global depfile \
	    alltags \
	    usertags \
	    data \
	    nodes \
	    numfunc wantnum \
	    numaggr \
	    numevents \
	    tagname tagcol tagfcol tagstip Colors TextColors Stipples \
	    evcol evstip evname \
	    uecol uefcol uestip uename \
	    coll colls \
	    aggr aggrs \
	    event events uEventFlag uenodes\
	    newver \
	    stddev \
	    heading \
	    eventheading \
	    column ucolumn\
	    BINDIR REMBINDIR REMSH TAUDIR
  if [DEBUG] {
    puts "\nreadProfile:"
  }

    set dir $depfile(dir)
    if {$depfile(host) == "localhost"} {
	#set dir "."
	set file "$dir/profile"
	
	# -- open connection to pprof to read profile data
	#if { ! [file readable $file.ftab] } {
	#    return NOT_OK
	#}
	#set in [open "|$BINDIR/pprof -d -m -n $wantnum -f $file" r]
	if [catch {open "|$BINDIR/pprof -d -m -n $wantnum -f $file" r} in ] {
	    showError "pprof missing from directory $BINDIR"
	    return NOT_OK
	}
    } else {
	set REMBINDIR "$depfile(root)/bin/$depfile(arch)"
	#set in [open "|$REMSH $depfile(host) \
	#       -n \"cd $dir; $REMBINDIR/pprof -d -m -n $wantnum\"" r]
	if [catch {open "|$REMSH $depfile(host) \
	        -n \"cd $dir; $REMBINDIR/pprof -d -m -n $wantnum\"" r} in ] {
	    showError "pprof missing from directory $REMBINDIR"
            return NOT_OK
        }
    }
    set n NA

    # -- read header: 1) name of corresponding depfile
    # --              2) number of profiled functions
    # --              3) column headings, #-line
    if { [gets $in line] <= 0 } {
	showError "environment variables not configured correctly in racy"
	return NOT_OK
    }
    scan $line "%s" depfile(file)
    gets $in line
    scan $line "%d" numfunc
    set f [lindex $line 1]
    if {$f == "templated_functions" || $f == "templated_functions_hw_counters" } {
	set newver 1
	#read line 3, the heading & count number of columns
#	gets $in line
#	set column [expr [llength $line]-1]
#	lappend heading $line

	#check if the profile includes standard deviation
	set two [lindex $line 2]
	set three [lindex $line 3]
	if {$two == "-stddev" || $three == "-stddev"} {
	    set stddev 1
	    gets $in line
	    set column [expr [llength $line]-1]
	    if { $column == 0 } {
		lappend heading $line
	    } else {
		#if there is old heading, delete old heading
		set heading {}
		lappend heading $line
	    }
	} else {
	    set stddev 0
	    gets $in line
	    set column [expr [llength $line]-1]
	    if { $column == 0 } {
		lappend heading $line
	    } else {
		#if there is old heading, delete old heading
		set heading {}
		lappend heading $line
	    }
	}
    } else {
	set newver 0
	#old version ignores the heading line
	gets $in line
    }
   

    # -- init
    set depfile(path) $dir/$depfile(file)
    set tagcol(-1) black
    set evcol(-1) black
    set uecol(-1) black
    set tagfcol(-1) white
    set uefcol(-1) white
    set tagstip(-1) {}
    set evstip(-1) {}
    set uestip(-1) {}
    set tagname(-1) "-others-"
    set evname(-1) "-others-"
    set uename(-1) "-other-"
    set tagcol(-2) white
    set evcol(-2) white
    set uecol(-2) white
    set tagfcol(-2) black
    set uefcol(-2) black
    set tagstip(-2) {}
    set evstip(-2) {}
    set uestip(-2) {}
    set tagname(-2) ""
    set i 0
    set j 0
    set k 0
    set colls ""
    set aggrs ""
    set events ""
    set uEventFlag 0
    set lastnode NA
    
    # -- read line by line
    while {[gets $in line] >= 0} {
	set node [lindex $line 0]
	if { $node == "coll" } {
	    #scan $line "%s %s %d %d %f %d %f" dummy node no local lper remote rper
	    set node [lindex $line 1]
	    if {![string match "*,*,*" $node]} {
		if {$node != "t" && $node != "m"} {
		    set node "$node,0,0"
		}
	    }
	    set no [lindex $line 2]
	    set coll($no,$node,val) [list [lindex $line 3] [lindex $line 5]]
	    set coll($no,$node,per) [list [lindex $line 4] [lindex $line 6]]
	} elseif { $node == "cinfo" } {
	    #scan $line "%s %s %s %s %d %d %d %d %f %d %f" \
	    #     dummy no type name elem size dim local lper remote rper
	    set no [lindex $line 1]
	    lappend colls $no
	    set coll($no,name) [lindex $line 3]
	    set coll($no,type) [lindex $line 2]
	    set coll($no,info) [lrange $line 4 6]
	    set coll($no,t,val) [list [lindex $line 7] [lindex $line 9]]
	    set coll($no,t,per) [list [lindex $line 8] [lindex $line 10]]
	} elseif {$node == "aggregates"} {
	    # HPC++ Aggregates
	    set node [lindex $line 1]
	    if {![string match "*,*,*" $node]} {
		if {$node != "t" && $node != "m"} {
		    set node "$node,0,0"
		}
	    }
	    set no [lindex $line 2]
	    set num_counters [lindex $line 3]
	    set aggr($no,$node,num_counters) $num_counters
	    set index 4
	    for {set counter 0} \
		    {$counter < $num_counters} \
		    {incr counter; incr index 4} {
		set eid [lindex $line $index]
		set aggr($no,$node,counter,$eid,name) \
			[lindex $line [expr $index + 1]]
		set aggr($no,$node,counter,$eid,value) \
			[lindex $line [expr $index + 2]]
		set aggr($no,$node,counter,$eid,percent) \
			[lindex $line [expr $index + 3]]

		if { ! [info exists evcol($eid)] } {
		    if { [winfo depth .] == 2 } {
			set evcol($eid) black
			set evstip($eid) @$TAUDIR/xbm/[wraplindex $Stipples $j]
		    } else {
			set evcol($eid) [wraplindex $Colors $j]
			set evstip($eid) {}
		    }
		    set evname($eid) [lindex $line [expr $index + 1]]
		    incr j
		}
	    }
	    set aggr($no,$node,container_name) [lindex $line $index]
	    set aggr($no,$node,container_type) [lindex $line [expr $index + 1]]
	    set aggr($no,$node,variable_name)  [lindex $line [expr $index + 2]]
	} elseif {$node == "ainfo"} {
	    # HPC++ Aggregates - Total info
	    set no [lindex $line 1]
	    lappend aggrs $no
	    set aggr($no,container_name) [lindex $line 2]
	    set aggr($no,container_type) [lindex $line 3]
	    set aggr($no,variable_name)  [lindex $line 4]
	    set aggr($no,elem)           [lindex $line 5]
	    set aggr($no,size)           [lindex $line 6]
	    set aggr($no,dim)            [lindex $line 7]
	    if {![info exists aggr($no,counter_set)]} {
		set aggr($no,counter_set)    [list]
		set accumulate_counters 1
	    } else {
		set accumulate_counters 0
	    }

	    set num_counters [lindex $line 8]
	    set aggr($no,num_counters) $num_counters
	    set index 9
	    for {set counter 0} \
		    {$counter < $num_counters} \
		    {incr counter; incr index 4} {
		set eid [lindex $line $index]
		set aggr($no,counter_t,$eid,name) \
			[lindex $line [expr $index + 1]]
		set aggr($no,counter_t,$eid,value) \
			[lindex $line [expr $index + 2]]
		set aggr($no,counter_t,$eid,percent) \
			[lindex $line [expr $index + 3]]
		if {$accumulate_counters} {
		    lappend aggr($no,counter_set) $eid
		}
	    }
	} elseif {$node == "userevent"} {
	    #user defined events
	    set uEventFlag 1
	    # -- event profile data
	    #scan $line "%s %d %s %i %g %g %g %g" 
	    #    node utag uname unum umax umin umean ustddev
	    set node [lindex $line 1]
	    set utag [lindex $line 2]
	    set uname [lindex $line 3]

	    if {![info exists usertags_tmp($utag)]} {
		set usertags_tmp($utag) 1
		lappend usertags $utag
	    }
	    if {![string match "*,*,*" $node]} {
		if {$node != "t" && $node != "m"} {
		    set node "$node,0,0"
		}
	    }
	    if { $lastnode != $node } {
		set lastnode $node
		lappend uenodes $node
		lappend events $node
	    }
	    set unum [lindex $line 4]
	    set umax [lindex $line 5]
	    set umin [lindex $line 6]
	    set umean [lindex $line 7]
	    set ustddev [lindex $line 8]
		
	    lappend event($node,tags) $utag
	    if { ! [info exists uecol($utag)] } {
		if { [winfo depth .] == 2 } {
		    set uecol($utag) black
		    set uefcol($utag) white
		    set uestip($utag) @$TAUDIR/xbm/[wraplindex $Stipples $k]
		} else {
		    set uecol($utag) [wraplindex $Colors $k]
		    set uefcol($utag) [wraplindex $TextColors $k]
		    set uestip($utag) {}
		}
		set uename($utag) $uname
		incr k
	    }
	    
	    lappend event($node,num) [format "%4.2f" $unum]
	    lappend event($node,max) [format "%4.2f" $umax]
	    lappend event($node,min) [format "%4.2f" $umin]
	    lappend event($node,mean) [format "%4.2f" $umean]
	    lappend event($node,stddev) [format "%4.2f" $ustddev]

	    #second line of data
	    gets $in line
	    lappend event($node,text) $line
	
	} else {
	    # -- this could be either headings of function profile data
	    # check if it is headings
	    set g [lindex $line 1]
	    if { $g == "aggregates" } {
		scan $line "%d" numaggr
	    } elseif { $g == "userevents" } {
		scan $line "%d" numevents
		# next line is heading for user-defined events
		gets $in line
		set ucolumn [ llength $line]
		if { $ucolumn == 0 } {
		    lappend eventheading $line
		} else {
		    set eventheading {}
		    lappend eventheading $line
		}
	    } else {
		# -- function profile data
		#scan $line "%s %d %s %s %g %g %f" node tag name mode usec per
		set tag   [lindex $line 1]
		set name  [lindex $line 2]
		set mode  [lindex $line 3]
                set usec  [lindex $line 4]
		set per   [lindex $line 5]

		if {![info exists alltags_tmp($tag)]} {
		    set alltags_tmp($tag) 1
		    lappend alltags $tag
		}
		if {![string match "*,*,*" $node]} {
		    if {$node != "t" && $node != "m"} {
			set node "$node,0,0"
		    }
		}
		if { $n != $node && $mode == "incl"} {
		    set n $node
		    lappend nodes $node
		}
		
		lappend data($node,${mode}tags) $tag
		lappend data($node,${mode}usecs) [format "%8.4G" $usec]
#               lappend data($node,${mode}usecs) $usec
		lappend data($node,${mode}percent) [format "%4.2f" $per]
		
		if { ! [info exists tagcol($tag)] } {
		    if { [winfo depth .] == 2 } {
			set tagcol($tag) black
			set tagfcol($tag) white
			set tagstip($tag) @$TAUDIR/xbm/[wraplindex $Stipples $i]
		    } else {
			set tagcol($tag) [wraplindex $Colors $i]
			set tagfcol($tag) [wraplindex $TextColors $i]
			set tagstip($tag) {}
		    }
		    set tagname($tag) $name
		    incr i
		}

		gets $in line
		lappend data($node,${mode}text) $line
	    }
	}
    }
#    if [catch {close $in} errmsg] {
#	showError "$readcom: `$errmsg'."
#	return NOT_OK
#    }
    
    if { ! [info exists nodes] } {
	return NOT_OK
    }
    return OK
}

#
# funcgraphmenu: create menubar for function profile windows
#
#        parent: pathname for parent of menubar
#        prefix: prefix for global variables to store selections
#          func: function to call for redraw
#     node,name: arguments to func
#

proc funcgraphmenu {parent prefix func node name} {
  global myself

  if [DEBUG] {
    puts "\nfuncgraphmenu:"
  }

  set menubar $parent.mbar
  frame $menubar -relief raised -borderwidth 2
  menubutton $menubar.b1 -text File -menu $menubar.b1.m1 -underline 0
  menu $menubar.b1.m1
  $menubar.b1.m1 add command -label "Print" -underline 0 \
                    -command "printCanvas .func${node}.bar func.$node"
  $menubar.b1.m1 add separator
  $menubar.b1.m1 add command -label "Close" -underline 0 \
                    -command "destroy .func$node"

  menubutton $menubar.b2 -text Value -menu $menubar.b2.m1 -underline 0
  menu $menubar.b2.m1
  submenu2 $menubar.b2.m1 ${prefix}value $func $node {$name}

  menubutton $menubar.b4 -text Mode -menu $menubar.b4.m1 -underline 0
  menu $menubar.b4.m1
  submenu4 $menubar.b4.m1 ${prefix}mode $func $node {$name}

  menubutton $menubar.b5 -text Units -menu $menubar.b5.m1 -underline 0
  menu $menubar.b5.m1
  submenu5 $menubar.b5.m1 ${prefix}unit $func $node {$name}

  menubutton $menubar.b6 -text Help -menu $menubar.b6.m1 -underline 0
  menu $menubar.b6.m1
  if [ALONE] {
    $menubar.b6.m1 add command -label "on function profile" -underline 3 \
	              -command "showHelp $myself 1.2.4-func 1"
  } else {
    $menubar.b6.m1 add command -label "on function profile" -underline 3 \
	              -command "xsend tau \[list showHelp $myself 1.2.4-func 1\]"
  }

  pack $menubar.b1 $menubar.b2 $menubar.b4 $menubar.b5\
       -side left -fill x -padx 5
  pack $menubar.b6 -side right -fill x -padx 5
}

#
# showFuncgraph: display function profile window
#
#           tag: Sage++ id of function
#

proc showFuncgraph {tag} {
  global data
  global funcvalue funcmode funcunit
  global proforder profvalue profmode profunit
  global tagname

  if [DEBUG] {
    puts "\nshowFuncgraph:"
    #puts "  tags: $tags"
  }  

  if { ! [winfo exists .func$tag] } {
    set funcvalue($tag) $profvalue(all)
    set funcmode($tag) $profmode(all)
    set funcunit($tag) $profunit(all)

    set win [toplevel .func$tag]
    set name $tagname($tag)
    wm title $win "$name profile"
    wm minsize $win 250 250

    funcgraphmenu .func$tag func redrawFuncgraph $tag {}
    redrawFuncgraph $tag {}

    scrollbar .func$tag.sv -orient vert -relief sunken \
	-command ".func$tag.bar yview"
    .func$tag.bar configure -yscrollcommand ".func$tag.sv set"

    scrollbar .func$tag.sh -orient horiz -relief sunken \
	-command ".func$tag.bar xview"
    .func$tag.bar configure -xscrollcommand ".func$tag.sh set"

    button .func$tag.but -text "close" -command "destroy .func$tag"

    bind .func$tag.bar <2> ".func$tag.bar scan mark %x %y"
    bind .func$tag.bar <B2-Motion> ".func$tag.bar scan dragto %x %y"

    pack .func$tag.mbar -side top -fill x
    pack .func$tag.but -side bottom -fill x
    pack .func$tag.sh -side bottom -fill x
    pack .func$tag.sv -side right -fill y
    pack .func$tag.bar -side left -fill both -expand yes
  } else {
    raise .func$tag
  }
}

#
# redrawFuncgraph: create or update contents of function profile window
#
#             tag: Sage++ id of function
#           dummy: unused parameter so it can be used with the generic
#                  menu construction functions
#

proc redrawFuncgraph {tag dummy} {
  global data
  global funodes fulabels
  global funcvalue funcmode funcunit
  global tagname
  if [DEBUG] {
    puts "\nredrawFuncgraph:"
    #puts "  tags: $tags"
    #puts "  dummy: $dummy"
  }
  # -- compute arguments for bargraph widget
  set value $funcvalue($tag)
  foreach n $funodes {
    if { $n == "" } {
      lappend pers 0.0
      lappend vals 0.0
      lappend tags -2
    } else {
      set i [lsearch -exact $data($n,${value}tags) $tag]
      if { $i == -1 } {
        lappend pers 0.0
        lappend vals 0.0
      } else {
        lappend pers [lindex $data($n,${value}percent) $i]
        lappend vals [lindex $data($n,${value}usecs) $i]
      }
      lappend tags $tag
    }
  }
  if { $funcmode($tag) == "val" } {
    set vmax [vectormax vals]
    set pers [vectorpercent vals $vmax 80.0]
  }

  # -- create display using bargraph widget
  bargraph .func$tag.bar $tagname($tag) $fulabels $pers \
                         [vectorop vals / $funcunit($tag)] \
                         $tags $funodes $funcmode($tag)
  if { $funcmode($tag) == "val" } {
    .func$tag.mbar.b5 configure -state normal
  } else {
    .func$tag.mbar.b5 configure -state disabled
  }
}

#
# userEgraphmenu: create menubar for function profile windows
#
#        parent: pathname for parent of menubar
#        prefix: prefix for global variables to store selections
#          func: function to call for redraw
#     node,name: arguments to func
#

proc userEgraphmenu {parent prefix func node name} {
  global myevent

  if [DEBUG] {
    puts "\nuserEgraphmenu:"
  }

  set menubar $parent.mbar
  frame $menubar -relief raised -borderwidth 2
  menubutton $menubar.b1 -text File -menu $menubar.b1.m1 -underline 0
  menu $menubar.b1.m1
  $menubar.b1.m1 add command -label "Print" -underline 0 \
                    -command "printCanvas .usrevent${node}.bar func.$node"
  $menubar.b1.m1 add separator
  $menubar.b1.m1 add command -label "Close" -underline 0 \
                    -command "destroy .usrevent$node"

  menubutton $menubar.b3 -text Mode -menu $menubar.b3.m1 -underline 0
  menu $menubar.b3.m1
  uesubmenu2 $menubar.b3.m1 ${prefix}mode $func $node {$name}

  menubutton $menubar.b4 -text Orientation -menu $menubar.b4.m1 -underline 0 
  menu $menubar.b4.m1 
  uesubmenu3 $menubar.b4.m1 ${prefix}orient $func $node {$name}


  menubutton $menubar.b5 -text Help -menu $menubar.b5.m1 -underline 0
  menu $menubar.b5.m1
## HERE ##
  #if [ALONE] {
  #  $menubar.b5.m1 add command -label "on events profile" -underline 3 \
  #	              -command "showHelp $myevent 1.2.4-func 1"
  #} else {
  #  $menubar.b5.m1 add command -label "on events profile" -underline 3 \
  #	              -command "xsend tau \[list showHelp $myevent 1.2.4-func 1\]"
  #}

  pack $menubar.b1 $menubar.b3 $menubar.b4 \
       -side left -fill x -padx 5
  pack $menubar.b5 -side right -fill x -padx 5
}


#
# showuserEgraph: display function profile window
#
#           tag: Sage++ id of function
#

proc showuserEgraph {tag} {
  global event
  global eventbarmode
  global eventorder eventmode
  global uename

  if [DEBUG] {
    puts "\nshowuserEgraph:"
    #puts "  tags: $tags"
  }  

  if { ! [winfo exists .usrevent$tag] } {
    set eventbarmode($tag) $eventmode(all)

    set win [toplevel .usrevent$tag]
    set name $uename($tag)
    wm title $win "$name profile"
    wm minsize $win 250 250

    userEgraphmenu .usrevent$tag eventbar redrawuserEgraph $tag {}
    redrawuserEgraph $tag {}

    scrollbar .usrevent$tag.sv -orient vert -relief sunken \
	-command ".usrevent$tag.bar yview"
    .usrevent$tag.bar configure -yscrollcommand ".usrevent$tag.sv set"

    scrollbar .usrevent$tag.sh -orient horiz -relief sunken \
	-command ".usrevent$tag.bar xview"
    .usrevent$tag.bar configure -xscrollcommand ".usrevent$tag.sh set"

    button .usrevent$tag.but -text "close" -command "destroy .usrevent$tag"

    bind .usrevent$tag.bar <2> ".usrevent$tag.bar scan mark %x %y"
    bind .usrevent$tag.bar <B2-Motion> ".usrevent$tag.bar scan dragto %x %y"

    pack .usrevent$tag.mbar -side top -fill x
    pack .usrevent$tag.but -side bottom -fill x
    pack .usrevent$tag.sh -side bottom -fill x
    pack .usrevent$tag.sv -side right -fill y
    pack .usrevent$tag.bar -side left -fill both -expand yes
  } else {
    raise .usrevent$tag
  }
}

#
# redrawuserEgraph: create or update contents of user-defined event profile window
#
#             tag: Sage++ id of function
#           dummy: unused parameter so it can be used with the generic
#                  menu construction functions
#

proc redrawuserEgraph {tag dummy} {
  global event
  global uenodes uelabels
  global eventbarmode
  global uename
  if [DEBUG] {
    puts "\nredrawuserEgraph:"
    #puts "  tags: $tags"
    #puts "  dummy: $dummy"
  }
  # -- compute arguments for bargraph widget
  #set value $funcvalue($tag)
  foreach n $uenodes {
    if { $n == "" } {
      lappend evnum 0.0
      lappend evmax 0.0
      lappend evmin 0.0
      lappend evstd 0.0
      lappend tags -2
    } else {
      set i [lsearch -exact $event($n,tags) $tag]
      if { $i == -1 } {
	lappend evnum 0.0
	lappend evmax 0.0
	lappend evmin 0.0
	lappend evstd 0.0
      } else {
        lappend evnum [lindex $event($n,num) $i]
        lappend evmax [lindex $event($n,max) $i]
        lappend evmin [lindex $event($n,min) $i]
        lappend evstd [lindex $event($n,stddev) $i]
      }
      lappend tags $tag
    }
  }


  # -- create display using bargraph widget
#  UserEbargraph .usrevent$tag.bar $uename($tag) $uelabels \
#                         $evnum $evmax $evmin $evstd \
#                         $tags $uenodes $usreventmode($tag)
  UserEbargraph .usrevent$tag.bar $uename($tag) $uelabels \
                         $evnum $evmax $evmin  \
                         $tags $uenodes $eventbarmode($tag)

}



#
# collgraphmenu: create menubar for collection profile windows
#
#        parent: pathname for parent of menubar
#        prefix: prefix for global variables to store selections
#          func: function to call for redraw
#     node,name: arguments to func
#

proc collgraphmenu {parent prefix func node name} {
  global myself

  set menubar $parent.mbar
  frame $menubar -relief raised -borderwidth 2
  menubutton $menubar.b1 -text File -menu $menubar.b1.m1 -underline 0
  menu $menubar.b1.m1
  $menubar.b1.m1 add command -label "Print" -underline 0 \
                    -command "printCanvas .coll${node}.bar coll.$node"
  $menubar.b1.m1 add separator
  $menubar.b1.m1 add command -label "Close" -underline 0 \
                    -command "destroy .coll$node"

  menubutton $menubar.b6 -text Mode -menu $menubar.b6.m1 -underline 0
  menu $menubar.b6.m1
  submenu6 $menubar.b6.m1 ${prefix}mode $func $node {$name}

  menubutton $menubar.b7 -text Help -menu $menubar.b7.m1 -underline 0
  menu $menubar.b7.m1
  if [ALONE] {
    $menubar.b7.m1 add command -label "on collection profile" -underline 3 \
	              -command "showHelp $myself 1.3.1-coll 1"
  } else {
    $menubar.b7.m1 add command -label "on collection profile" -underline 3 \
	              -command "xsend tau \[list showHelp $myself 1.3.1-coll 1\]"
  }

  pack $menubar.b1 $menubar.b6 -side left -fill x -padx 5
  pack $menubar.b7 -side right -fill x -padx 5
}

#
# aggrgraphmenu: create menubar for the aggregate event profile windows
#
#        parent: pathname for parent of menubar
#        prefix: prefix for global variables to store selections
#          func: function to call for redraw
#     node,name: arguments to func
#

proc aggrgraphmenu {parent prefix func node name} {
  global myself

  set menubar $parent.mbar
  frame $menubar -relief raised -borderwidth 2
  menubutton $menubar.b1 -text File -menu $menubar.b1.m1 -underline 0
  menu $menubar.b1.m1
  $menubar.b1.m1 add command -label "show Event Legend" -underline 5 \
	            -command showEventLegend
  $menubar.b1.m1 add command -label "Print" -underline 0 \
                    -command "printCanvas .aggr${node}.bar aggr.$node"
  $menubar.b1.m1 add separator
  $menubar.b1.m1 add command -label "Close" -underline 0 \
                    -command "destroy .aggr$node"

  menubutton $menubar.b6 -text Mode -menu $menubar.b6.m1 -underline 0
  menu $menubar.b6.m1
  submenu6a $menubar.b6.m1 ${prefix}mode $func $node {$name}

  menubutton $menubar.b7 -text Help -menu $menubar.b7.m1 -underline 0
  menu $menubar.b7.m1
  if [ALONE] {
    $menubar.b7.m1 add command -label "on aggregate event profile" -underline 3 \
                      -command "showHelp $myself 1.4.1-aggr 1"
  } else {
    $menubar.b7.m1 add command -label "on aggregate event profile" -underline 3 \
                      -command "xsend tau \[list showHelp $myself 1.4.1-aggr 1\]"
  }

  pack $menubar.b1 $menubar.b6 -side left -fill x -padx 5
  pack $menubar.b7 -side right -fill x -padx 5
}

#
# showCollgraph: display collection profile window
#
#         ident: collection id
#

proc showCollgraph {ident} {
  global coll
  global collmode profmode

  if { ! [winfo exists .coll$ident] } {
    set win [toplevel .coll$ident]

    set name $coll($ident,name)
    wm title $win "$name profile"
    wm minsize $win 300 50

    if { $profmode(all) == "per" } {
      set collmode($ident) lper
    } else {
      set collmode($ident) $profmode(all)
    }

    collgraphmenu .coll$ident coll redrawCollgraph $ident {}
    pack .coll$ident.mbar -side top -fill x

    set e [lindex $coll($ident,info) 0]
    set s [lindex $coll($ident,info) 1]
    set d [lindex $coll($ident,info) 2]
    set t [expr $e*$s]
    if { $t > 1000000 } {
      set t "[format {%.1f MB} [expr $t/1e6]]"
    } elseif { $t > 1000 } {
      set t "[format {%.1f kB} [expr $t/1e3]]"
    } else {
      set t "$t B"
    }
    frame .coll$ident.info -background white -relief raised -borderwidth 2
    label .coll$ident.l1 -text "$coll($ident,type) $name" \
                         -background white -foreground black
    label .coll$ident.l2 -text "$e elements of size $s \[$t\]" \
                         -background white -foreground black
    label .coll$ident.l3 -text "$d-dimensional shape" \
                         -background white -foreground black
    pack .coll$ident.l1 .coll$ident.l2 .coll$ident.l3 \
                        -side top -anchor w -in .coll$ident.info
    pack .coll$ident.info -side top -fill x

    redrawCollgraph $ident {}

    bind .coll$ident.bar <2> ".coll$ident.bar scan mark %x %y"
    bind .coll$ident.bar <B2-Motion> ".coll$ident.bar scan dragto %x %y"

    scrollbar .coll$ident.s1 -orient vert -relief sunken \
                           -command ".coll$ident.bar yview"
    .coll$ident.bar configure -yscrollcommand ".coll$ident.s1 set"

    button .coll$ident.but -text "close" -command "destroy .coll$ident"
    pack .coll$ident.but -side bottom -fill x
    pack .coll$ident.s1 -side right -fill y
    pack .coll$ident.bar -side left -fill both -expand yes
  } else {
    raise .coll$ident
  }
}


#
# showAggrgraph: display aggregate profile window
#
#         ident: aggregate id
#

proc showAggrgraph {ident} {
  global aggr
  global aggrmode profmode

  if { ! [winfo exists .aggr$ident] } {
    set win [toplevel .aggr$ident]

    set name $aggr($ident,container_name)
    set var_name $aggr($ident,variable_name)
    set cont_type $aggr($ident,container_type)

    wm title $win "$name event profile"
    wm minsize $win 300 50

    if { $profmode(all) == "per" } {
	set aggrmode($ident) lper
    } elseif {$profmode(all) == "gper" } {
	set aggrmode($ident) lper
    } else {
      set aggrmode($ident) $profmode(all)
    }

    aggrgraphmenu .aggr$ident aggr redrawAggrgraph $ident {}
    pack .aggr$ident.mbar -side top -fill x

    set e $aggr($ident,elem)
    set s $aggr($ident,size)
    set d $aggr($ident,dim)
    set t [expr $e*$s]
    if { $t > 1000000 } {
      set t "[format {%.1f MB} [expr $t/1e6]]"
    } elseif { $t > 1000 } {
      set t "[format {%.1f kB} [expr $t/1e3]]"
    } else {
      set t "$t B"
    }
    frame .aggr$ident.info -background white -relief raised -borderwidth 2
    if {$cont_type == "NULL"} {
	label .aggr$ident.l1 -text "$name $var_name" \
		-background white -foreground black
    } else {
	label .aggr$ident.l1 -text "$name<$cont_type> $var_name" \
		-background white -foreground black
    }
    label .aggr$ident.l2 -text "$e elements of size $s \[$t\]" \
                         -background white -foreground black
    label .aggr$ident.l3 -text "$d-dimensional shape" \
                         -background white -foreground black
    pack .aggr$ident.l1 .aggr$ident.l2 .aggr$ident.l3 \
                        -side top -anchor w -in .aggr$ident.info
    pack .aggr$ident.info -side top -fill x

    redrawAggrgraph $ident {}

    bind .aggr$ident.bar <2> ".aggr$ident.bar scan mark %x %y"
    bind .aggr$ident.bar <B2-Motion> ".aggr$ident.bar scan dragto %x %y"

    scrollbar .aggr$ident.s1 -orient vert -relief sunken \
                           -command ".aggr$ident.bar yview"
    .aggr$ident.bar configure -yscrollcommand ".aggr$ident.s1 set"
    if {$aggrmode($ident) != "none"} {
	scrollbar .aggr$ident.s2 -orient horiz -relief sunken \
		-command ".aggr$ident.bar xview"
	.aggr$ident.bar configure -xscrollcommand ".aggr$ident.s2 set"
    }

    button .aggr$ident.but -text "close" -command "destroy .aggr$ident"
    pack .aggr$ident.but -side bottom -fill x
    pack .aggr$ident.s1 -side right -fill y
    if {$aggrmode($ident) != "none"} {
	pack .aggr$ident.s2 -side bottom -fill x
    }
    pack .aggr$ident.bar -side right -fill both -expand yes
  } else {
    raise .aggr$ident
  }
}


#
# redrawCollgraph: create or update contents of collection profile window
#
#           ident: collection id
#           dummy: unused parameter so it can be used with the generic
#                  menu construction functions
#

proc redrawCollgraph {ident dummy} {
  global conodes colabels
  global coll
  global collmode

  set mode $collmode($ident)
  if { $mode == "gper" || $mode == "val" } {
    # -- global percent / value display mode
    # -- compute data from local percent available from pprof
    set max   0.0
    foreach n $conodes {
      if [ info exists coll($ident,$n,val) ] {
        set v $coll($ident,$n,val)
        lappend value $v
        if { $n != "t" } {
          set s [expr [lindex $v 0]+[lindex $v 1]]
          if { $s > $max } { set max $s }
        }
      } else {
        lappend value [list 0.0 0.0]
      }
    }
    set total [expr \
          double([lindex $coll($ident,t,val) 0]+[lindex $coll($ident,t,val) 1])]
    set scale [expr $total/$max]

    foreach n $conodes {
      if [ info exists coll($ident,$n,val) ] {
        set v $coll($ident,$n,val)
        lappend percent [list [expr [lindex $v 0]/$total*100.0] \
                              [expr [lindex $v 1]/$total*100.0]]
      } else {
        lappend percent [list 0.0 0.0]
      }
    }
  } elseif { $mode == "lper" } {
    # -- local percent display mode
    foreach n $conodes {
      if [ info exists coll($ident,$n,per) ] {
        lappend percent $coll($ident,$n,per)
      } else {
        lappend percent [list 0.0 0.0]
      }
    }
    set value {}
    set scale 1.0
  }
  multiCollgraph .coll$ident.bar $colabels {} $percent $value $mode $scale
}

#
# redrawAggrgraph: create or update contents of aggregate profile window
#
#           ident: aggregate id
#           dummy: unused parameter so it can be used with the generic
#                  menu construction functions
#

proc redrawAggrgraph {ident dummy} {
    global agnodes aglabels
    global aggr
    global aggrmode
    
    if [DEBUG] {
	puts "redrawAggrgraph:"
	puts "  ident: $ident"
    }

    set mode $aggrmode($ident)
    if { $mode == "val" } {
	# -- value display mode
	# -- compute data from local percent available from pprof
	set max   0.0
      
	set value [list]
	foreach n $agnodes {
	    # create a list of all the value sets
	    set tmp_values {}
	    foreach event $aggr($ident,counter_set) {
		if {$n == "t"} {
		    if [info exists aggr($ident,counter_t,$event,value)] {
			lappend tmp_values \
				$aggr($ident,counter_t,$event,value)
		    } else {
			lappend tmp_values -1.0
		    }
		} else {
		    if [info exists aggr($ident,$n,counter,$event,value)] {
			lappend tmp_values \
				$aggr($ident,$n,counter,$event,value)
		    } else {
			lappend tmp_values -1.0
		    }
		}
	    }
	    set s [vectorsum tmp_values]
	    if { $n != "t" && $n != {}} {
		lappend sums $s
		if { $s > $max } { set max $s }
	    } else {
		lappend sums 1.0
	    }
	    lappend value $tmp_values
	}
	    
	# Total the counter totals
	set total 0.0
	foreach event $aggr($ident,counter_set) {
	    set total [expr $total + \
		    double($aggr($ident,counter_t,$event,value))]
	}
	#set scale [expr $total/$max]
	for {set i 0} {$i < [llength $agnodes]} {incr i} {
	    if {[lindex $sums $i] == 0} {
		lappend scales 1.0
	    } else {
		lappend scales [expr $total / [lindex $sums $i]]
	    }
	}
	
	set percent [list]
	foreach n $agnodes {
	    # create a list of all the value sets
	    set tmp_percents {}
	    foreach event $aggr($ident,counter_set) {
		if {$n == "t"} {
		    if [ info exists aggr($ident,counter_t,$event,value) ] {
			lappend tmp_percents \
				[expr $aggr($ident,counter_t,$event,value) \
				/$total*100.0]
		    } else {
			lappend tmp_percents -1.0
		    }
		} else {
		    if [ info exists aggr($ident,$n,counter,$event,value) ] {
			lappend tmp_percents \
				[expr $aggr($ident,$n,counter,$event,value) \
				/$total*100.0]
		    } else {
			lappend tmp_percents -1.0
		    }
		}
	    }
	    lappend percent $tmp_percents
	}

    } elseif { $mode == "lper" } {
	# -- local percent display mode
	set percent [list]
	foreach n $agnodes {
	    # create a list of all the value sets
	    set tmp_percents {}
	    foreach event $aggr($ident,counter_set) {
		if {$n == "t"} {
		    if [ info exists aggr($ident,counter_t,$event,percent) ] {
			lappend tmp_percents \
				$aggr($ident,counter_t,$event,percent)
		    } else {
			lappend tmp_percents -1.0
		    }
		} else {
		    if [ info exists aggr($ident,$n,counter,$event,percent) ] {
			lappend tmp_percents \
				$aggr($ident,$n,counter,$event,percent)
		    } else {
			lappend tmp_percents -1.0
		    }
		}
	    }
	    lappend percent $tmp_percents
	}
	set value {}
	#set scale 1.0
	for {set i 0} {$i < [llength $agnodes]} {incr i} {
	    lappend scales 1.0
	}
    }
    multiAggrgraph .aggr$ident.bar $aglabels [list $ident] $percent $value $mode $scales "node"
}

#
# computeMultiBars: compute data for summary function profile
#                   as well as often used lists of labels
#

proc computeMultiBars {} {
  global data alltags
  global nodes funodes conodes agnodes uenodes
  global fulabels colabels clabels aglabels alabels uelabels
  global exclpercent collpercent aggrpercent eventscale
  global coll colls
  global aggr aggrs
  global event usertags uEventFlag eventmode 
  global minheight

  if [DEBUG] {
    puts "\ncomputeMultiBars:"
    #puts "  uenodes: $uenodes"
  }

  foreach n $nodes {
    set p ""
    set na [vectorsum data($n,exclpercent)]
    foreach t $alltags {
      set i [lsearch -exact $data($n,excltags) $t]
      if { $i == -1 } {
        lappend p 0.0
      } else {
        set x [lindex $data($n,exclpercent) $i]
        if { $t == -1 } {
          lappend p $na
        } else {
          set na [expr $na-$x]
          lappend p $x
	}
      }
    }
    set data($n,meanper) $p
  }

  #set fulabels [list "mean" "min" "max" {}]
  set fulabels [list "mean" {}]
  set colabels [list "total" {}]
  set aglabels [list "total" {}]

  #set exclpercent \
  #    [list $data(m,exclpercent) $data(<,meanper) $data(>,meanper) {}]
  #  set exclpercent [list $data(m,exclpercent) {}]
  set exclpercent [list $data(m,meanper) {}]
  #set funodes "m < > {} [lrange $nodes 0 [expr [llength $nodes]-5]]"
  set funodes "m {} [lrange $nodes 0 [expr [llength $nodes]-3]]"
  #set conodes "t {} [lrange $nodes 0 [expr [llength $nodes]-5]]"
  set conodes "t {} [lrange $nodes 0 [expr [llength $nodes]-3]]"
  #set agnodes "t {} [lrange $nodes 0 [expr [llength $nodes]-5]]"
  set agnodes "t {} [lrange $nodes 0 [expr [llength $nodes]-3]]"

  #foreach n [lrange $nodes 0 [expr [llength $nodes]-5]] 
  foreach n [lrange $nodes 0 [expr [llength $nodes]-3]] {
    lappend fulabels [format "n,c,t %5s" $n]
    lappend colabels [format "n,c,t %5s" $n]
    lappend aglabels [format "n,c,t %5s" $n]
    lappend exclpercent $data($n,meanper)
  }

  set clabels ""
  set collpercent ""
  foreach c $colls {
    lappend clabels $coll($c,name)
    lappend collpercent $coll($c,t,per)
  }

  set alabels ""
  set aggrpercent ""
  foreach c $aggrs {
      lappend alabels $aggr($c,variable_name)

      set tmp_percents [list]
      foreach agevent $aggr($c,counter_set) {
	  lappend tmp_percents $aggr($c,counter_t,$agevent,percent)
      }
      lappend aggrpercent $tmp_percents
  }

    if {$uEventFlag != 0} {
	set eventscale ""
	foreach nd $uenodes {
	    set e ""
	    set ns [vectorsum event($nd,num)]
	    set total $ns
	    foreach ut $usertags {
		set i [lsearch -exact $event($nd,tags) $ut]
		if { $i == -1 } {
		    lappend e 0.0
		} else {
		    set x [lindex $event($nd,num) $i]
		    if { $ut == -1 } {
			lappend e [format "%.4f" [expr $ns/$total * 100]]
		    } else {
			set ns [expr $ns - $x]
			lappend e [format "%.4f" [expr $x/$total * 100]]
		    }
		}
	    }
	   
	    set  temp_scale $e
	}
	
	foreach n $uenodes {
	    lappend uelabels [format "n,c,t %5s" $n]  
	    lappend eventscale $temp_scale
	}
    }

    set minheight [expr ([max3 [llength $fulabels] \
			       [llength $clabels] \
			       [llength $alabels] ]+1)*20]
}



#
# redraw: redraw all windows currently displayed, after user selected
#         global order from Configure main menu
#
# dummy1:
# dummy2: unused parameters so it can be used with the generic
#         menu construction functions
#

proc redraw {dummy1 dummy2} {
  global myself
  global data
  global funodes fulabels
  global barorder barmode barvalue barunit
  global textorder1 textorder2
  global funcmode funcvalue funcunit
  global proforder profvalue profmode profunit
  global collmode colls aggrmode aggrs
  if [DEBUG] {
    puts "\nredraw:"
  }


  # -- redraw node and text node profile windows
  set i 0
  foreach n $funodes {
    if [winfo exists .bar$n] {
      set barvalue($n) $profvalue(all)
      #if { $proforder(all) == "glob" } {
      #  set barorder($n) $proforder(all)
      #} else {
      #  set barorder($n) $n
      #}
      if { $proforder(all) == "all" } {
        set barorder($n) $n
      } else {
        set barorder($n) $proforder(all)
      }
      set barmode($n) $profmode(all)
      set barunit($n) $profunit(all)
      redrawBargraph $n [lindex $fulabels $i]
    }
    if [winfo exists .text$n] {
      set textorder1($n) $profvalue(all)
      #if { $proforder(all) == "glob" } {
      #  set textorder2($n) $proforder(all)
      #} else {
      #  set textorder2($n) $n
      #}
      if { $proforder(all) == "all" } {
        set textorder2($n) $n
      } else {
        set textorder2($n) $proforder(all)
      }

      redrawText $n [lindex $fulabels $i]
    }
    incr i
  }

  # -- redraw function profile windows
  foreach t $data(m,excltags) {
    if [winfo exists .func$t] {
      set funcvalue($t) $profvalue(all)
      set funcmode($t) $profmode(all)
      set funcunit($t) $profunit(all)
      redrawFuncgraph $t {}
    }
  }

  # -- redraw collection profile windows
  foreach c $colls {
    if [winfo exists .coll$c] {
      if { $profmode(all) == "per" } {
        set collmode($c) lper
      } else {
        set collmode($c) $profmode(all)
      }
      redrawCollgraph $c {}
    }
  }

  # -- redraw aggregate profile windows
  foreach a $aggrs {
    if [winfo exists .aggr$a] {
      if { $profmode(all) == "per" } {
        set aggrmode($a) lper
      } else {
        set aggrmode($a) $profmode(all)
      }
      redrawAggrgraph $a {}
    }
  }

  # -- redraw function/event legends
  if [winfo exists .$myself.led.can] {
    redrawFuncLegend .$myself.led.can
  }
  if [winfo exists .$myself.eventled.can] {
    redrawUserELegend .$myself.eventled.can
  }

  if { $profmode(all) == "val" } {
    .$myself.mbar.b2.m1 entryconfigure 4 -state normal
  } else {
    .$myself.mbar.b2.m1 entryconfigure 4 -state disabled
  }
}

#
# redrawue: redraw all user-defined event windows currently displayed, 
#           after user selected global mode from Configure main menu
#
#   dummy1:
#   dummy2: unused parameters so it can be used with the generic
#         menu construction functions
#

proc redrawue {dummy1 dummy2} {
  global myevent
  global event
  global uenodes uelabels uetextorder1
  global eventbarorder eventbarmode eventbarorient
  global eventmode eventorder eventorient

  if [DEBUG] {
    puts "\nredrawue:"
    puts "  uenodes: $uenodes"
  }


  # -- redraw node and text node profile windows
  set i 0
  foreach n $uenodes {
    if [winfo exists .eventbar$n] {
      if { $eventorder(all) == "glob" } {
        set eventbarorder($n) $eventorder(all)
      } else {
        set eventbarorder($n) $n
      }
      if { $eventorder(all) == "all" } {
        set eventbarorder($n) $n
      } else {
        set eventbarorder($n) $eventorder(all)
      }
      set eventbarmode($n) $eventmode(all)
      set eventbarorient($n) $eventorient(all)
      redrawUserEBargraph $n [lindex $uelabels $i]
    }
    if [winfo exists .eventtext$n] {
      set uetextorder1($n) $eventorder(all)
      redrawUserEText $n [lindex $uelabels $i]
    }
    incr i
  }

  # -- redraw event profile windows
  foreach t $event($n,tags) {
    if [winfo exists .usrevent$t] {
      set eventbarmode($t) $eventmode(all)
      set eventbarorient($t) $eventorient(all)
      redrawuserEgraph $t {}
    }
  }


  # -- redraw function/event legends
  if [winfo exists .$myevent.led.can] {
    redrawUserELegend .$myevent.led.can
  }


}


#
# showFuncLegend: display function legend
#

proc showFuncLegend {} {
  global myself
  if [DEBUG] {
    puts "\nshowFuncLegend:"
  }
  if { ! [winfo exists .$myself.led] } {
    toplevel .$myself.led
    wm title .$myself.led "Function Legend"
    wm minsize .$myself.led 250 250

    # -- create canvas, scrollbars, "close" button
    canvas .$myself.led.can -background white

    scrollbar .$myself.led.sv -orient vert -relief sunken \
	                      -command ".$myself.led.can yview"
    .$myself.led.can configure -yscrollcommand ".$myself.led.sv set"

    scrollbar .$myself.led.sh -orient horiz -relief sunken \
                              -command ".$myself.led.can xview"
    .$myself.led.can configure -xscrollcommand ".$myself.led.sh set"

    button .$myself.led.b -text close -command "destroy .$myself.led"

    pack .$myself.led.b -side bottom -fill x
    pack .$myself.led.sh -side bottom -fill x
    pack .$myself.led.sv -side right -fill y
    pack .$myself.led.can -side left -fill both -expand yes

    # -- draw color legend 
    redrawFuncLegend .$myself.led.can
  } else {
    raise .$myself.led
  }
}

#
# showEventLegend: display event legend
#  (for Agg-graph)
#
proc showEventLegend {} {
  global myself

  if { ! [winfo exists .$myself.eventled] } {
    toplevel .$myself.eventled
    wm title .$myself.eventled "Event Legend"

    # -- create canvas and "close" button
    canvas .$myself.eventled.can -width 250 -background white
    pack .$myself.eventled.can

    button .$myself.eventled.b -text close -command "destroy .$myself.eventled"
    pack .$myself.eventled.b -fill x

    # -- draw color legend
    redrawEventLegend .$myself.eventled.can
  } else {
    raise .$myself.eventled
  }
}


#
# showUserELegend: display user-defined event legend
#

proc showUserELegend {} {
  global myevent
  if [DEBUG] {
    puts "\nshowUserLegend:"
  }
  if { ! [winfo exists .$myevent.led] } {
    toplevel .$myevent.led
    wm title .$myevent.led "User-defined Event Legend"
    wm minsize .$myevent.led 250 250

    # -- create canvas, scrollbars, "close" button
    canvas .$myevent.led.can -background white

    scrollbar .$myevent.led.sv -orient vert -relief sunken \
	                      -command ".$myevent.led.can yview"
    .$myevent.led.can configure -yscrollcommand ".$myevent.led.sv set"

    scrollbar .$myevent.led.sh -orient horiz -relief sunken \
                              -command ".$myevent.led.can xview"
    .$myevent.led.can configure -xscrollcommand ".$myevent.led.sh set"

    button .$myevent.led.b -text close -command "destroy .$myevent.led"

    pack .$myevent.led.b -side bottom -fill x
    pack .$myevent.led.sh -side bottom -fill x
    pack .$myevent.led.sv -side right -fill y
    pack .$myevent.led.can -side left -fill both -expand yes

    # -- draw color legend 
    redrawUserELegend .$myevent.led.can
  } else {
    raise .$myevent.led
  }
}



#
# redrawFuncLegend: draw or update function legend canvas
#
#          can: canvas id
#

proc redrawFuncLegend {can} {
  global tagcol tagstip tagname alltags
  global pr_sel_tag
  global racy_progfile
  if [DEBUG] {
    puts "\nredrawFuncLegend:"
  }
  # -- generate alphabetical list of functions
  #foreach t [array names tagcol] 
  foreach t $alltags {
    if { $t != -2 && $t != -1 } {
      lappend map [list $tagname($t) $t $tagcol($t) $tagstip($t)]
    }
  }
  set map [lsort $map]
  lappend map [list $tagname(-1) -1 $tagcol(-1) {}]

  # -- set height of map
  set num [llength $map];    # number of funcs
  set h [expr ($num+1)*20];  # height of canvas

  # -- draw color legend
  $can delete all
  set i 11
  set max_lwidth 0
  foreach m $map {
    set t [lindex $m 1]
    $can create rectangle 10 [expr $i] 28 [expr 18+$i] \
	-fill [lindex $m 2] -tag fl$t -stipple [lindex $m 3]
    if { $t == $pr_sel_tag } {
	set label [$can create text 40 [expr 9+$i] -text [lindex $m 0] \
		       -anchor w -tag fl$t -fill red \
		       -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
    } else {
	set label [$can create text 40 [expr 9+$i] -text [lindex $m 0] \
		       -anchor w -tag fl$t \
		       -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
    }
    set bbox [$can bbox $label]
    set lwidth [expr [lindex $bbox 2] - [lindex $bbox 0]]
    if {$lwidth > $max_lwidth} {set max_lwidth $lwidth}
    $can bind fl$t <Button-1> "showFuncgraph $t"
    # showFuncTag is not implemented by racy
    # $can bind fl$t <Button-2> "PM_GlobalSelect $racy_progfile global_showFuncTag $t"
    $can bind fl$t <Button-3> "PM_GlobalSelect $racy_progfile global_selectFuncTag $t"
    incr i 20
  }

  set w [expr $max_lwidth + 50]
  $can configure -scrollregion [list 0 0 $w $h]
}

#
# redrawEventLegend: draw or update event legend canvas
#  (for Agg-graph)
#          can: canvas id
#

proc redrawEventLegend {can} {
  global evcol evstip evname
  global pr_sel_tag
  global racy_progfile

  # -- generate alphabetical list of functions
  foreach t [array names evcol] {
    if { $t != -2 && $t != -1 } {
      lappend map [list $evname($t) $t $evcol($t) $evstip($t)]
    }
  }
  set map [lsort $map]

  # -- set height of map
  set num [llength $map];    # number of funcs
  set h [expr ($num+1)*20];  # height of canvas
  $can configure -height $h

  # -- draw color legend
  $can delete all
  set i 11
  foreach m $map {
    set t [lindex $m 1]
    $can create rectangle 10 [expr $i] 28 [expr 18+$i] \
         -fill [lindex $m 2] -tag el$t -stipple [lindex $m 3]
    if { $t == $pr_sel_tag } {
      $can create text 40 [expr 9+$i] -text [lindex $m 0] \
           -anchor w -tag el$t -fill red \
           -font -Adobe-Helvetica-Bold-R-Normal--*-120-*
    } else {
      $can create text 40 [expr 9+$i] -text [lindex $m 0] -anchor w -tag fl$t \
           -font -Adobe-Helvetica-Bold-R-Normal--*-120-*
    }
    incr i 20
  }
}

#
# redrawUserELegend: draw or update event legend canvas
#
#             uecan: canvas id
#

proc redrawUserELegend {can} {
  global uecol uestip uename usertags
  global ue_sel_tag
  global racy_progfile

  # -- generate alphabetical list of functions
    foreach tg $usertags {
    if { $tg != -2 && $tg != -1 } {
      lappend uemap [list $uename($tg) $tg $uecol($tg) $uestip($tg)]
    }
  }
  set uemap [lsort $uemap]
  lappend uemap [list $uename(-1) -1 $uecol(-1) {}]

  # -- set height of uemap
  set unum [llength $uemap];     # number of funcs
  set ht [expr ($unum+1)*20];    # height of canvas


  # -- draw color legend
  $can delete all
  set d 11
  set max_width 0
  foreach mp $uemap {
    set tg [lindex $mp 1]
    $can create rectangle 10 [expr $d] 28 [expr 18+$d] \
         -fill [lindex $mp 2] -tag evl$tg -stipple [lindex $mp 3]
    if { $tg == $ue_sel_tag } {
	set uelabel [$can create text 40 [expr 9+$d] -text [lindex $mp 0] \
		       -anchor w -tag evl$tg -fill red \
		       -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
    } else {
	set uelabel [$can create text 40 [expr 9+$d] -text [lindex $mp 0] \
		       -anchor w -tag evl$tg \
		       -font -Adobe-Helvetica-Bold-R-Normal--*-120-*]
    }
    set bbox [$can bbox $uelabel]
    set width [expr [lindex $bbox 2] - [lindex $bbox 0]]
    if {$width > $max_width} {set max_width $width}
    $can bind evl$tg <Button-1> "showuserEgraph $tg"
    $can bind evl$tg <Button-3> "PM_GlobalSelect $racy_progfile global_selectUserTag $tg"
    incr d 20
  }

  set wd [expr $max_width + 50]
  $can configure -scrollregion [list 0 0 $wd $ht]
}

#
# setNumFunc: set maximal number of functions included in profile data displays
#

proc setNumFunc {} {
  global myself
  global depfile
  global wantnum

  set copy $wantnum

  if { ! [winfo exists .$myself.num] } {
    toplevel .$myself.num
    wm title .$myself.num "Set #Functions"

    numberInput .$myself.num.i "Number of functions to display:" wantnum
    pack .$myself.num.i -side top

    frame .$myself.num.b -relief sunken -bd 1
    pack .$myself.num.b -side left -padx 15 -pady 10
    button .$myself.num.b.b1 -text "set" -command {
      destroy .$myself.num
      loadProfile
    }
    pack .$myself.num.b.b1 -side top -padx 5 -pady 5

    button .$myself.num.b2 -text "cancel" -command "
      set wantnum $copy
      destroy .$myself.num
    "
    pack .$myself.num.b2 -side right -padx 15

    bind .$myself.num.i.e <Return> {.$myself.num.b.b1 invoke}
    bind .$myself.num <Return> {.$myself.num.b.b1 invoke}
  } else {
    raise .$myself.num
  }
}

#
#  mainmenu: create menubar for main window
#
#    parent: pathname for parent of menubar
#    prefix: prefix for global variables to store selections
#      func: function to call for redraw
# node,name: arguments to func
#

proc mainmenu {parent prefix func node name} {
  global myself colls aggrs
  if [DEBUG] {
      puts "mainmenu: "
      puts "  prefix: $prefix"
  }
  set menubar $parent.mbar
  frame $menubar -relief raised -borderwidth 2

  menubutton $menubar.b1 -text File -menu $menubar.b1.m1 -underline 0
  menu $menubar.b1.m1
  $menubar.b1.m1 add command -label "set #Functions" -underline 0 \
                    -command setNumFunc
  $menubar.b1.m1 add command -label "show Function Legend" -underline 5 \
                    -command showFuncLegend
  if [llength $aggrs] {
      $menubar.b1.m1 add command -label "show Event Legend" -underline 5 \
	      -command showEventLegend
  }

  $menubar.b1.m1 add command -label "print Functions" -underline 0 \
                    -command "printCanvas .$myself.fu.bar profile.fu"
  if [llength $colls] {
      $menubar.b1.m1 add command -label "print Collections" -underline 6 \
	      -command "printCanvas .$myself.co.bar profile.co"
  } elseif [llength $aggrs] {
      $menubar.b1.m1 add command -label "print Aggregates" -underline 6 \
	      -command "printCanvas .$myself.ag.bar profile.ag"
  }
  $menubar.b1.m1 add separator
  $menubar.b1.m1 add command -label "Exit" -underline 0 -command "exit"

  menubutton $menubar.b2 -text Configure -menu $menubar.b2.m1 -underline 0
  menu $menubar.b2.m1

  $menubar.b2.m1 add cascade -label "Value" -menu $menubar.b2.m1.1 -underline 0
  menu $menubar.b2.m1.1
  submenu2 $menubar.b2.m1.1 ${prefix}value $func $node {$name}

  $menubar.b2.m1 add cascade -label "Order" -menu $menubar.b2.m1.2 -underline 0
  menu $menubar.b2.m1.2
  submenu3 $menubar.b2.m1.2 ${prefix}order $func $node {$name}

  $menubar.b2.m1 add cascade -label "Mode" -menu $menubar.b2.m1.3 -underline 0
  menu $menubar.b2.m1.3
  submenu4 $menubar.b2.m1.3 ${prefix}mode $func $node {$name}

  $menubar.b2.m1 add cascade -label "Units" -menu $menubar.b2.m1.4 -underline 0
  menu $menubar.b2.m1.4
  submenu5 $menubar.b2.m1.4 ${prefix}unit $func $node {$name}
  $menubar.b2.m1 entryconfigure 4  -state disabled

  menubutton $menubar.b3 -text Help -menu $menubar.b3.m1 -underline 0
  menu $menubar.b3.m1
  if [ALONE] {
    $menubar.b3.m1 add command -label "on $myself" -underline 3 \
	-command "showHelp $myself 1-$myself 1"
    $menubar.b3.m1 add separator
    $menubar.b3.m1 add command -label "on menubar" -underline 3 \
	-command "showHelp $myself 1.1-menu 1"
    $menubar.b3.m1 add command -label "on function summary" -underline 3 \
	-command "showHelp $myself 1.2-funcsum 1"
    if [llength $colls] {
      $menubar.b3.m1 add command -label "on collection summary" -underline 3 \
	  -command "showHelp $myself 1.3-collsum 1"
    } elseif [llength $aggrs] {
      $menubar.b3.m1 add command -label "on aggregate summary" -underline 3 \
	  -command "showHelp $myself 1.4-aggrsum 1"
    }
    $menubar.b3.m1 add separator
    $menubar.b3.m1 add command -label "on using help" -underline 3 \
	-command "showHelp general 1-help 1"
  } else {
    $menubar.b3.m1 add command -label "on $myself" -underline 3 \
	-command "xsend tau \[list showHelp $myself 1-$myself 1\]"
    $menubar.b3.m1 add separator
    $menubar.b3.m1 add command -label "on menubar" -underline 3 \
	-command "xsend tau \[list showHelp $myself 1.1-menu 1\]"
    $menubar.b3.m1 add command -label "on function summary" -underline 3 \
	-command "xsend tau \[list showHelp $myself 1.2-funcsum 1\]"
    if [llength $colls] {
      $menubar.b3.m1 add command -label "on collection summary" -underline 3 \
	  -command "xsend tau \[list showHelp $myself 1.3-collsum 1\]"
    } elseif [llength $aggrs] {
      $menubar.b3.m1 add command -label "on aggregate summary" -underline 3 \
	  -command "xsend tau \[list showHelp $myself 1.4-aggrsum 1\]"
    }
    $menubar.b3.m1 add separator
    $menubar.b3.m1 add command -label "on using help" -underline 3 \
	-command "xsend tau \[list showHelp general 1-help 1\]"
  }

  if {![ALONE]} {
    createToolMenu $menubar.b4
  }

  pack $menubar.b1 $menubar.b2 -side left -padx 5
  if [ALONE] {
    pack $menubar.b3  -side right -padx 5
  } else {
    pack $menubar.b3 $menubar.b4 -side right -padx 5
  }
}

#
#  uemainmenu: create menubar for main window of user-defined events
#
#      parent: pathname for parent of menubar
#      prefix: prefix for global variables to store selections
#        func: function to call for redraw
#   node,name: arguments to func
#

proc uemainmenu {parent prefix func node name} {
  global myevent
  if [DEBUG] {
      puts "uemainmenu: "
      puts "  prefix: $prefix"
  }

  set uemenubar $parent.mbar
  frame $uemenubar -relief raised -borderwidth 2

  menubutton $uemenubar.b1 -text File -menu $uemenubar.b1.m1 -underline 0
  menu $uemenubar.b1.m1
  $uemenubar.b1.m1 add command -label "set #User Events" -underline 0 \
                    -command setNumEvent -state disabled
  $uemenubar.b1.m1 add command -label "show User Event Legend" -underline 16 \
                    -command showUserELegend
  $uemenubar.b1.m1 add command -label "print User Events" -underline 0 \
                    -command "printCanvas .$myevent.ue.bar profile.ue"
  $uemenubar.b1.m1 add separator
  $uemenubar.b1.m1 add command -label "Close" -underline 0 \
                    -command "destroy .$myevent"



  menubutton $uemenubar.b2 -text Configure -menu $uemenubar.b2.m1 -underline 0
  menu $uemenubar.b2.m1

  $uemenubar.b2.m1 add cascade -label "Order" -menu $uemenubar.b2.m1.1 -underline 0
  menu $uemenubar.b2.m1.1
  uesubmenu1 $uemenubar.b2.m1.1 ${prefix}order $func $node {$name}

  $uemenubar.b2.m1 add cascade -label "Mode" -menu $uemenubar.b2.m1.2 -underline 0
  menu $uemenubar.b2.m1.2
  uesubmenu2 $uemenubar.b2.m1.2 ${prefix}mode $func $node {$name}


  menubutton $uemenubar.b3 -text Help -menu $uemenubar.b3.m1 -underline 0
  menu $uemenubar.b3.m1

#  $uemenubar.b3.m1 add command -label "on $myevent" -underline 3 \
#      -command "showHelp $myevent 1-$myevent 1"
#  $uemenubar.b3.m1 add separator
#  $uemenubar.b3.m1 add command -label "on uemenubar" -underline 3 \
#      -command "showHelp $myevent 1.1-menu 1"
#  $uemenubar.b3.m1 add command -label "on user event summary" -underline 3 \
#      -command "showHelp $myevent 1.2-eventsum 1"

#  $uemenubar.b3.m1 add separator
#  $uemenubar.b3.m1 add command -label "on using help" -underline 3 \
#      -command "showHelp general 1-help 1"


  pack $uemenubar.b1 $uemenubar.b2  -side left -padx 5

  pack $uemenubar.b3  -side right -padx 5

}


#
# loadProfile: switch to another application
#              this is invoked from the TAU master control window
#

proc loadProfile {} {
  global myself
  global data
  global numfunc
  global nodes funodes fulabels conodes colabels exclpercent agnodes aglabels
  global barorder barmode barvalue barunit
  global textorder1 textorder2
  global funcmode funcvalue funcunit
  global collmode aggrmode
  global proforder profvalue profmode profunit
  global tagname tagcol tagfcol tagstip
  global evname evcol evstip
  global colls coll clabels collpercent
  global aggrs aggr alabels aggrpercent
  global depfile alltags
  global event events
  global uecol uefcol uestip uename uenodes uelabels eventscale
  global eventmode eventorder eventorient usertags uetextorder1
  global eventbarmode eventbarorder eventbarorient
  if [DEBUG] {
    puts "\nloadProfile:"
  }
  set dir  $depfile(dir)
  set root $depfile(root)
  set arch $depfile(arch)

  foreach n $funodes {
    if [winfo exists .bar$n]  { destroy .bar$n  }
    if [winfo exists .text$n] { destroy .text$n }
  }
  foreach t $data(m,excltags) {
    if [winfo exists .func$t] { destroy .func$t }
  }
  foreach c $colls {
    if [winfo exists .coll$c] { destroy .coll$c }
  }
  foreach a $aggrs {
    if [winfo exists .aggr$a] { destroy .aggr$a }
  }
  if [winfo exists .$myself.num] { destroy .$myself.num }
  if [winfo exists .$myself.led] { destroy .$myself.led }
  if [winfo exists .$myself.eventled] { destroy .$myself.eventled }

  # -- destroy old profile data database
  unset data
  unset alltags
  unset nodes funodes fulabels conodes colabels exclpercent
  unset agnodes aglabels evname evcol evstip alabels aggrpercent
  unset tagname tagcol tagfcol tagstip
  unset clabels collpercent
  if { [info exists barorder]    } { unset barorder barmode barvalue barunit }
  if { [info exists textorder1]  } { unset textorder1 textorder2 }
  if { [info exists funcmode]    } { unset funcmode funcvalue funcunit }
  if { [info exists collmode]    } { unset collmode }
  if { [info exists aggrmode]    } { unset aggrmode }
  if { [info exists colls]       } { unset colls }
  if { [info exists coll]        } { unset coll }
  if { [info exists aggrs]       } { unset aggrs }
  if { [info exists aggr]        } { unset aggr }
  if { [info exists event]       } { unset event eventscale usertags uenodes \
                                           uecol uefcol uestip uename uelabels} 
  if { [info exists eventmode]   } { unset eventmode eventorder eventorient}
  if { [info exists eventbarmode]} { unset eventbarmode eventbarorder eventbarorient}
  if { [info exists uetextorder1]} { unset uetextorder1 }

  # -- reset global configuration parameters
  set profvalue(all) excl
  #set proforder(all) glob
  set proforder(all) all
  set profmode(all) per
  set profunit(all) 1.0
  if { uEventFlag != 0} {         
      set eventorder(all) glob
      set eventmode(all) num
      set eventorient(all) right
  }

  # -- read new profile data
  if { [readProfile] == "NOT_OK" } {
    #showError "No profile data available in directory $dir."
    after 1 exit
    return
  }
  if {![ALONE]} {
    xsend tau "set depfile(numprof) $numfunc"
  }

  # -- redraw summary bargraphs
  computeMultiBars
  # multiFuncgraph .$myself.fu.bar $fulabels $funodes \
                 $exclpercent $data(m,excltags)
  multiFuncgraph .$myself.fu.bar $fulabels $funodes \
                 $exclpercent $alltags
  if [llength $colls] {
      multiCollgraph .$myself.co.bar $clabels $colls $collpercent
  } elseif [llength $aggrs] {
      multiAggrgraph .$myself.ag.bar $alabels $aggrs $aggrpercent
  }
  if {$uEventFlag != 0} {
      multiEventgraph .$myevent.ue.bar $uelabels $uenodes $eventscale $usertags
  }

  # -- rebuild configure-order-node submenu
  .$myself.mbar.b2.m1.2.1 delete 0 last
  set i 0
  foreach n $funodes {
    if { $n != {} } {
      .$myself.mbar.b2.m1.2.1 add radiobutton -label [lindex $fulabels $i] \
	          -variable proforder(all) -value $n \
                  -command "redraw all {}"
    } else {
      .$myself.mbar.b2.m1.2.1 add separator
    }
    incr i
  }
}

#
# createWindow: create and display main window of racy
#

proc createWindow {} {
  global myself
  global TAUDIR
  global data
  global fulabels funodes clabels colls collpercent exclpercent \
	 aggrs alabels aggrpercent alltags \
 
  if [DEBUG] {
      puts " "
      puts "createWindow: "
      puts "  myself: $myself"
  }
  toplevel .$myself
  wm title .$myself "RACY"
  wm minsize .$myself 300 50
  wm iconbitmap .$myself @$TAUDIR/xbm/$myself.xbm

  mainmenu .$myself prof redraw all {}
  pack .$myself.mbar -side top -fill x

  frame .$myself.fu
  label .$myself.fu.l1 -text Functions -relief raised
  multiFuncgraph .$myself.fu.bar $fulabels $funodes \
                 $exclpercent $alltags 
  scrollbar .$myself.fu.s1 -orient vert -relief sunken \
                        -command ".$myself.fu.bar yview"
  .$myself.fu.bar configure -yscrollcommand ".$myself.fu.s1 set"
  pack .$myself.fu.l1 -side top -fill x
  pack .$myself.fu.s1 -side right -fill y
  pack .$myself.fu.bar -side left -fill both -expand yes

  if [llength $colls] {
      frame .$myself.co
      label .$myself.co.l1 -text Collections -relief raised
      multiCollgraph .$myself.co.bar $clabels $colls $collpercent
      scrollbar .$myself.co.s1 -orient vert -relief sunken \
	      -command ".$myself.co.bar yview"
      .$myself.co.bar configure -yscrollcommand ".$myself.co.s1 set"
      pack .$myself.co.l1 -side top -fill x
      pack .$myself.co.s1 -side right -fill y
      pack .$myself.co.bar -side left -fill both -expand yes
      pack .$myself.fu .$myself.co -side left -padx 15 -pady 15 \
	      -fill both -expand yes
  } elseif [llength $aggrs] {
      frame .$myself.ag
      label .$myself.ag.l1 -text Aggregates -relief raised
      multiAggrgraph .$myself.ag.bar $alabels $aggrs $aggrpercent
      scrollbar .$myself.ag.s1 -orient vert -relief sunken \
	      -command ".$myself.ag.bar yview"
      .$myself.ag.bar configure -yscrollcommand ".$myself.ag.s1 set"
      pack .$myself.ag.l1 -side top -fill x
      pack .$myself.ag.s1 -side right -fill y
      pack .$myself.ag.bar -side left -fill both -expand yes
      pack .$myself.fu .$myself.ag -side left -padx 15 -pady 15 \
	      -fill both -expand yes
  }  else {
      pack .$myself.fu -side left -padx 15 -pady 15 \
	      -fill both -expand yes
  }
}

#
# createEventWindow: create and display main window of user-defined events
#

proc createEventWindow {} {
  global myevent myself
  global TAUDIR
  global events uelabels uenodes usertags eventscale
  if [DEBUG] {
      puts " "
      puts "createEventWindow: "
  }
  set myevent user
  toplevel .$myevent
  wm title .$myevent "USER EVENTS"
  wm minsize .$myevent 300 50
  wm iconbitmap .$myevent @$TAUDIR/xbm/$myself.xbm

  uemainmenu .$myevent event redrawue all {}
  pack .$myevent.mbar -side top -fill x

  frame .$myevent.ue
  label .$myevent.ue.l1 -text UserEvents -relief raised
  multiEventgraph .$myevent.ue.bar $uelabels $uenodes $eventscale $usertags
  scrollbar .$myevent.ue.s1 -orient vert -relief sunken \
      -command ".$myevent.ue.bar yview"
  .$myevent.ue.bar configure -yscrollcommand ".$myevent.ue.s1 set"
  pack .$myevent.ue.l1 -side top -fill x
  pack .$myevent.ue.s1 -side right -fill y
  pack .$myevent.ue.bar -side left -fill both -expand yes
  pack .$myevent.ue .$myevent.ue -side left -padx 15 -pady 15 \
      -fill both -expand yes

  pack .$myevent.ue -side left -padx 15 -pady 15 \
      -fill both -expand yes
  
}



#
# getColorCode: return list of actual function name <-> color mapping
#

proc getColorCode {} {
  global tagcol
  if [DEBUG] {
    puts "\ngetColorCode:"
  }
  foreach t [array names tagcol] {
    if { $t != -2 } { lappend result [list $t $tagcol($t)] }
  }
  return $result
}


proc Tool_AcceptChanges {progfiles flag} {
    global myself depfile \
	    showFile selectBox racy_progfile \
	   myevent uEventFlag

  if [DEBUG] {
    puts "\nTool_AcceptChanges:"
  }
    switch $flag {

        d {
        }


        a {
        }


        u {
        }
	
	e {
	    loadProfile
	}

	p {
	    set pm_status [PM_Status]
	    if {$pm_status != "NO_PROJECT"} {
		set depfile(project) [lindex $pm_status 0]
		set depfile(host)    [lindex $pm_status 1]
		set depfile(arch)    [lindex $pm_status 2]
		set depfile(root)    [lindex $pm_status 3]
		set depfile(dir)     [lindex $pm_status 4]
	    }
	    # Check for language-tool compatibility
	    if {![Lang_CheckCompatibility [PM_GetProjectLangs] $myself]} {
		showError "$myself is not compatible with the project language(s)."
		exit
	    }
	    
	    #reset
	    global racy_progfile
	    set racy_progfile "";
	    
	    destroy .$myself
	    if [winfo exists .$myevent] { destroy .$myevent }
	    initRacy
	    if { [readProfile] == "NOT_OK" } {
		#showError "No profile data available in current directory."
		exit
	    }
	    computeMultiBars
	    createWindow
	    if {$uEventFlag != 0} { createEventWindow }
	}
    }
}



#  initRacy - Racy only works with simple pc++ projects, ie, pc++ projects
#             with only one program file.
proc initRacy {} {
    global racy_progfile alltags

    set alltags [list]
    
    set file [Bdb_GetMaintag]
    set racy_progfile [lindex $file 0]

  if [DEBUG] {
    puts "\ninitRacy:"
    puts "  file: $file"
  }
    if {0} {
    set files [PM_GetFiles]
    if {[llength $files] != 1} {
	showError "A Racy-compatible project only must have one program (.C) file!"
	exit
    }
    set racy_progfile [lindex $files 0]
    }

    if { [readProfile] == "NOT_OK" } {
	#showError "No profile data available in current directory."
	exit
    }
}


# ------------
# -- main code
# ------------


set profvalue(all) excl
#set proforder(all) glob
set proforder(all) all
set profmode(all) per
set profunit(all) 1.0
set uEventFlag 0
set eventorder(all) glob
set eventmode(all) num
set eventorient(all) right

# racy is currently a standalone tool
set ALONE_SET 1
if {$argc == 0} {
    set parg [pwd]
} elseif {$argc == 1} {
    set parg [lindex $argv 0]
    if {[file extension $parg] != ".pmf"} {
	set parg "$parg.pmf"
    }
} else {
    puts stderr "usage: $myself \[\[host:\]projFile \| \[host:\]directory\]"
    exit
}

# if want other than standalone tool, comment out above
# and uncomment the following
#set ALONE_SET 0
#switch $argc {
#    0   {
#	set parg [pwd]
#    }
#    1   {
#	if {[lindex $argv 0] == "-sa" } {
#	    set ALONE_SET 1
#	    set parg [pwd]
#        } else {
#  	    set parg [lindex $argv 0]
#	    if {[file extension $parg] != ".pmf"} {
#	        set parg "$parg.pmf"
#	    }
#	}
#    }
#    2   {
#	if {[lindex $argv 0] == "-sa" } {
#	    set ALONE_SET 1
#	    set parg [lindex $argv 1]
#	    if {[file extension $parg] != ".pmf"} {
#		set parg "$parg.pmf"
#	    }
#	} else {
#	    puts stderr "usage: $myself \[-sa\] \[\[host:\]projFile \| \[host:\]directory\]"
#	    exit
#	}
#    }
#    default {
#	puts stderr "usage: $myself \[-sa\] \[\[host:\]projFile \| \[host:\]directory\]"
#	exit
#    }
#}

# Init the project manager (taud)
launchTauDaemon -waitfor
PM_AddTool $myself
PM_AddGlobalSelect $myself {global_selectFuncTag}

# Initialize the project
# Coordinate w/ PM
set pm_status [PM_Status]
if {[lindex $pm_status 0] == "NO_PROJECT"} {
    # Open or create a project
    set colon [string first ":" $parg]
    if {$colon > 0} {
        set hostarg [string range $parg 0 [expr $colon - 1]]
        set patharg [string range $parg [expr $colon + 1] end]
    } else {
        set hostarg localhost
        set patharg $parg
    }

    set projfile [PM_OpenProject $patharg $hostarg]

    if {$projfile == "NO_PROJECT"} {
        showError "No project opened!"
        exit
    }
    set pm_status [PM_Status]
}

set depfile(project) [lindex $pm_status 0]
set depfile(host)    [lindex $pm_status 1]
set depfile(arch)    [lindex $pm_status 2]
set depfile(root)    [lindex $pm_status 3]
set depfile(dir)     [lindex $pm_status 4]


# Check for language-tool compatibility
if {![Lang_CheckCompatibility [PM_GetProjectLangs] $myself]} {
    showError "$myself is not compatible with the project language(s)."
    exit
}

# Tool Init
initRacy

# -- create new toplevel window
computeMultiBars
createWindow
if {$uEventFlag != 0} {
    createEventWindow
    PM_AddGlobalSelect $myself {global_selectUserTag}
}
if {![ALONE]} {
    launchTAU
}

# -- notify tau about number of functions profiled
if {![ALONE]} {
    xsend tau "set depfile(numprof) $numfunc"
}

wm protocol .$myself WM_DELETE_WINDOW exit

removeMessage