summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/expressg/expressg.dtx
blob: f8a737c8e51a53d36efcc63991a09890acff8395 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
% \iffalse meta-comment
%
% expressg.dtx
% Author: Peter Wilson (CUA) now at peter.r.wilson@boeing.com until June 2004
%                            (or: pandgwilson at earthlink dot net) 
% Copyright 1996, 2003, 2004 Peter R. Wilson
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3 of this license or (at your option) any 
% later version.
% The latest version of the license is in
%    http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of
% LaTeX version 2003/06/01 or later.
%
% This work has the LPPL maintenance status "author-maintained".
%
% This work consists of the files listed in the README file.
%
% If you do not have the docmfp package (available from CTAN in
% tex-archive/macros/latex/contrib/supported), comment out the
% \usepackage{docmfp} line below and uncomment the line following it.
% 
%<*driver>
\documentclass{ltxdoc}
\usepackage{docmfp}
%%%% \newenvironment{variable}[1]{}{} \newenvironment{routine}[1]{}{}
\providecommand{\DescribeVariable}[1]{} \providecommand{\DescribeRoutine}[1]{}
\providecommand{\variablestring}{} \renewcommand{\variablestring}{\space(v)}
\providecommand{\routinestring}{} \renewcommand{\routinestring}{\space(r)}
\EnableCrossrefs
\CodelineIndex
\setcounter{StandardModuleDepth}{1}

\begin{document}
  \DocInput{expressg.dtx}
\end{document}
%</driver>
%
% \fi
%
% \CheckSum{171}
%
% \DoNotIndex{\',\.,\@M,\@@input,\@addtoreset,\@arabic,\@badmath}
% \DoNotIndex{\@centercr,\@cite}
% \DoNotIndex{\@dotsep,\@empty,\@float,\@gobble,\@gobbletwo,\@ignoretrue}
% \DoNotIndex{\@input,\@ixpt,\@m}
% \DoNotIndex{\@minus,\@mkboth,\@ne,\@nil,\@nomath,\@plus,\@set@topoint}
% \DoNotIndex{\@tempboxa,\@tempcnta,\@tempdima,\@tempdimb}
% \DoNotIndex{\@tempswafalse,\@tempswatrue,\@viipt,\@viiipt,\@vipt}
% \DoNotIndex{\@vpt,\@warning,\@xiipt,\@xipt,\@xivpt,\@xpt,\@xviipt}
% \DoNotIndex{\@xxpt,\@xxvpt,\\,\ ,\addpenalty,\addtolength,\addvspace}
% \DoNotIndex{\advance,\Alph,\alph}
% \DoNotIndex{\arabic,\ast,\begin,\begingroup,\bfseries,\bgroup,\box}
% \DoNotIndex{\bullet}
% \DoNotIndex{\cdot,\cite,\CodelineIndex,\cr,\day,\DeclareOption}
% \DoNotIndex{\def,\DisableCrossrefs,\divide,\DocInput,\documentclass}
% \DoNotIndex{\DoNotIndex,\egroup,\ifdim,\else,\fi,\em,\endtrivlist}
% \DoNotIndex{\EnableCrossrefs,\end,\end@dblfloat,\end@float,\endgroup}
% \DoNotIndex{\endlist,\everycr,\everypar,\ExecuteOptions,\expandafter}
% \DoNotIndex{\fbox}
% \DoNotIndex{\filedate,\filename,\fileversion,\fontsize,\framebox,\gdef}
% \DoNotIndex{\global,\halign,\hangindent,\hbox,\hfil,\hfill,\hrule}
% \DoNotIndex{\hsize,\hskip,\hspace,\hss,\if@tempswa,\ifcase,\or,\fi,\fi}
% \DoNotIndex{\ifhmode,\ifvmode,\ifnum,\iftrue,\ifx,\fi,\fi,\fi,\fi,\fi}
% \DoNotIndex{\input}
% \DoNotIndex{\jobname,\kern,\leavevmode,\let,\leftmark}
% \DoNotIndex{\list,\llap,\long,\m@ne,\m@th,\mark,\markboth,\markright}
% \DoNotIndex{\month,\newcommand,\newcounter,\newenvironment}
% \DoNotIndex{\NeedsTeXFormat,\newdimen}
% \DoNotIndex{\newlength,\newpage,\nobreak,\noindent,\null,\number}
% \DoNotIndex{\numberline,\OldMakeindex,\OnlyDescription,\p@}
% \DoNotIndex{\pagestyle,\par,\paragraph,\paragraphmark,\parfillskip}
% \DoNotIndex{\penalty,\PrintChanges,\PrintIndex,\ProcessOptions}
% \DoNotIndex{\protect,\ProvidesClass,\raggedbottom,\raggedright}
% \DoNotIndex{\refstepcounter,\relax,\renewcommand,\reset@font}
% \DoNotIndex{\rightmargin,\rightmark,\rightskip,\rlap,\rmfamily,\roman}
% \DoNotIndex{\roman,\secdef,\selectfont,\setbox,\setcounter,\setlength}
% \DoNotIndex{\settowidth,\sfcode,\skip,\sloppy,\slshape,\space}
% \DoNotIndex{\symbol,\the,\trivlist,\typeout,\tw@,\undefined,\uppercase}
% \DoNotIndex{\usecounter,\usefont,\usepackage,\vfil,\vfill,\viiipt}
% \DoNotIndex{\viipt,\vipt,\vskip,\vspace}
% \DoNotIndex{\wd,\xiipt,\year,\z@}
%
% \changes{v1.0}{1996/05/09}{First public release}
% \changes{v1.1}{1999/10/30}{Improved documentation using docmfp package}
% \changes{v1.1}{1999/10/30}{Reordered descriptions and code}
% \changes{v1.1}{1999/10/30}{Deleted Express Book examples}
% \changes{v1.1}{1999/10/30}{Updated references}
% \changes{v1.2}{1999/11/15}{Reincluded Express Book examples, plus NIAM and S-M}
% \changes{v1.3}{2000/05/22}{Added smoothing, drawdrum, and others}
% \changes{v1.4}{2000/07/10}{Added sharp and smooth lines}
% \changes{v1.5}{2003/07/31}{Minor bug fixes}
% \changes{v1.6}{2004/02/29}{More boxes}
% \changes{v1.61}{2004/03/17}{Minor namespace feature fix}
%
% \newcommand{\dtxfilename}{\texttt{expressg.dtx}}
% ^^A \def\fileversion{v1.0}
% \def\firstfiledate{1996/05/09}
% ^^A \def\fileversion{v1.1}
% ^^A \def\filedate{1999/10/30}
% ^^A \def\fileversion{v1.2}
% ^^A \def\filedate{1999/11/15}
% ^^A \def\fileversion{v1.3}
% ^^A \def\filedate{2000/05/22}
% \def\fileversion{v1.4} \def\filedate{2000/07/10}
% \def\fileversion{v1.5} \def\filedate{2003/07/31}
% \def\fileversion{v1.6} \def\filedate{2004/02/29}
% \def\fileversion{v1.61} \def\filedate{2004/03/17}
% \newcommand*{\Lpack}[1]{\textsf {#1}}           ^^A typeset a package
% \newcommand*{\Lopt}[1]{\textsf {#1}}            ^^A typeset an option
% \newcommand*{\file}[1]{\texttt {#1}}            ^^A typeset a file
% \newcommand*{\Lcount}[1]{\textsl {\small#1}}    ^^A typeset a counter
% \newcommand*{\pstyle}[1]{\textsl {#1}}          ^^A typeset a pagestyle
% \newcommand*{\Lenv}[1]{\texttt {#1}}            ^^A typeset an environment
% \newcommand*{\Express}{\textsc{express}}
% \newcommand*{\ExpressG}{\textsc{express-g}}
% \newcommand*{\Mpost}{\textsc{MetaPost}}
% \newcommand*{\Mfont}{METAFONT}
% \newcommand*{\fref}[1]{Figure~\ref{#1}}
% \newcommand*{\pref}[1]{page~\pageref{#1}}
% \newcommand*{\PS}{PostScript}
% \newcommand*{\EPS}{Encapsulated \PS}
% \newcommand*{\pdflatex}{pdf\LaTeX}
%
% \title{The \Lpack{Expressg} \Mpost{} package for drawing
%        box-line-annotation diagrams\thanks{This
%        file (\dtxfilename) has version number \fileversion, last revised
%        \filedate.}}
%
% \author{%
% Peter Wilson\\
% Catholic University of America \\
% Now at \texttt{peter.r.wilson@boeing.com}
% }
% \date{(First published \firstfiledate) \\ \filedate}
% \maketitle
% \begin{abstract}
%    The \Lpack{expressg} \Mpost{} package provides facilities to assist in
% drawing diagrams that consist of boxes, lines, and annotations.
% Particular support is provided for creating \ExpressG{} diagrams
% \end{abstract}
% \tableofcontents
% \listoffigures
%
% \StopEventually{}
%
% \section{Introduction}
%
%    \ExpressG{} is an ISO international standard graphical information 
% modeling
% language~\cite{STEP11,EBOOK}, and is a subset of the \Express{} lexical
% object-flavoured information modeling language. Like most graphical
% modeling languages, \ExpressG{} diagrams consist of boxes, lines, and
% annotations associated with the boxes and the lines. As a colleague
% of mine once put it, these kinds of graphical languages are BLA 
% (boxes, lines, annotations) with respect to lexical languages.
%
%    \Mpost~\cite{MPOST} is a powerful lexical language for producing
% \EPS\footnote{\PS{} is a registered trademark of Adobe
% Systems Incorporated.} diagrams, and is based on the \Mfont~\cite{MFONT} 
% language for creating fonts.
%
%    The \Lpack{expressg} package provides extensions to the base
% \Mpost{} language to facilitate the creation of \ExpressG{} diagrams.
% The package may also be used as is, or certainly by
% extension, for the creation of other BLA diagrams. 
%
%    \Mpost{} is typically used to generate pictures for inclusion
% in \LaTeX{} documents~\cite{LATEX}. By default it uses \TeX{} for
% typesetting any text; this behaviour can be modified so that \LaTeX{}
% is used instead. If standard \PS{} fonts (like Times) are
% used, then \LaTeX{} typesetting may be avoided altogether. Running
% \Mpost{} and methods of including \Mpost{} diagrams in (pdf)LaTeX
% documents are described in~\cite{METAFP}.
%
%
%    The \Lpack{expressg} package has been some years 
% in the making. For
% occasional diagrams I got by with using either the simple \LaTeX{}
% picture commands, 
% or general GUI drawing packages. As time went on and the number
% and complexity of the diagrams increased it became, to me at least, more
% important to use a robust and powerful drawing language than fancy
% GUI packages. This was especially important if a diagram had to be
% changed at a later date, as the language denoted exactly how the drawing
% had been produced. With the GUI tools all that you had was the picture
% and whatever graphics file format the tool used --- there was no 
% user-sensible record
% of how any result was achieved. Also, generally speaking I find it quicker
% to use \Mpost{} than a GUI tool as too much time has to be spent using
% a mouse or a cursor to reposition and rescale the drawing elements.
% 
%    Section~\ref{sec:usc} describes the facilities provided by the package.
% Several worked 
% example diagrams are presented in Section~\ref{sec:example}, together
% with information on how to run \Mpost.
% Commented code for the package macros\footnote{If requested, 
% I may be prepared to consider providing additional macros, but no promises.}
% is in Section~\ref{sec:mf}.
%
%    It is assumed that the reader has some understanding of \Mpost, although
% the example in Section~\ref{sec:example} does provide an 
% \textit{aide-memoire} for most of the \Mpost{} constructs that are likely
% to be used in creating BLA diagrams. The definitive \Mpost{}
% manual is~\cite{MPOST} but both~\cite{HOENIG98} and~\cite{GOOSSENS97}
% give some interesting examples of how to use it; in fact the front cover
% of Hoenig's book is a \Mpost{} picture. 
% Similarly, some familiarity with
% BLA diagramming would be of assistance.
%
%    I suggest that on first reading it may be sensible to skim
% Section~\ref{sec:usc} first 
% and then peruse the example in Section~\ref{sec:example} more closely. 
% After this
% go back and re-read Section~\ref{sec:usc} as it then should make 
% more sense.
%
% This manual is typeset according to the conventions of the
% \LaTeX{} \textsc{docstrip} utility which enables the automatic
% extraction of the \LaTeX{} macro source files~\cite{GOOSSENS94}.
%
%
%
% \section{The \Lpack{expressg} package} \label{sec:usc}
%
% \subsection{Internal variables}
%
% The package includes several internal variables that are initialised to
% commonly appropriate values.
%    This section describes the principal internal variables. 
% Short descriptions
% of the others, which
% are likely to be used in diagrams only very occasionally, can be found
% in Section~\ref{sec:mf}.
%
%    The values of internal variables in \Mpost{} can only be changed via
% assignment. For example:
% \begin{verbatim}
% internal_variable := expression;
% \end{verbatim}
%
% \DescribeVariable{u}
% \DescribeVariable{maxx}
% \DescribeVariable{maxy}
% |u| is the value of the unit of length for a diagram; it is initialised
% to 1mm. All lengths, except for line thicknesses,
%  are defined in terms of |u|. 
% |maxx| and |maxy| are the maximum x and y coordinate values
% for a diagram. These are initialised to the maximum size for a diagram
% within an ISO standard document (i.e., |maxx:=159.5u| and |maxy:=210u|).
%
%    The next set of variables control the thickness of lines and the
% dimensions of line end styles.
%
% \DescribeVariable{normalpen}
% Lines with normal linethickness are drawn with |normalpen|.
%
% \DescribeVariable{thickpen}
% Thick lines are drawn with |thickpen|.
%
% \DescribeVariable{thinpenpen}
% Thin lines are drawn with |thinpen|.
%
% \DescribeVariable{dotspen}
% Dotted lines are drawn with |dotspen|.
%
% \DescribeVariable{dotpen}
%  |dotpen| is for drawing the black dot line end style.
%
% \DescribeVariable{dotdiam}
% |dotdiam| is the diameter of an open circle or dot line end style.
%
% \DescribeVariable{smoothrad}
% |smoothrad| is the radius of the circular arc used to round the join between
% two straight lines.
%
% \DescribeVariable{drumlid}
% |drumlid| is the ratio of the minor to major diameter of the ellipse
% forming the top of the drum box; the larger the value the more the 
% apparent viewpoint shifts to above the drum. The default value is 0.2.
%
% \begin{figure}
%   \setlength{\unitlength}{1mm}
%   \centering
%   \begin{picture}(105,40)
%     \put(0,0){\framebox(105,40){}}
%     \put(5,0){\begin{picture}(60,40)
%   ^^A    \put(0,0){\framebox(60,40){}}
%       \thicklines
%       \put(0,20){\line(1,0){10}}
%       \put(10,10){\line(2,1){20}}
%       \put(10,30){\line(2,-1){20}}
%       \put(10,10){\line(0,1){20}}
%       \thinlines
%       \put(10,5){\vector(1,0){20}} \put(10,5){\vector(-1,0){0}}
%       \put(20,3){\makebox(0,0)[t]{length}}
%       \put(35,10){\vector(0,1){20}} \put(35,10){\vector(0,-1){0}}
%       \put(40,20){\makebox(0,0)[l]{base width}}
%     \end{picture}}
%     \put(65,0){\begin{picture}(35,40)
%  ^^A     \put(0,0){\framebox(60,40){}}
%       \thicklines
%       \put(5,20){\line(1,0){30}}
%       \put(5,10){\line(2,1){20}}
%       \put(5,30){\line(2,-1){20}}
%       \thinlines
%       \put(5,5){\vector(1,0){20}} \put(5,5){\vector(-1,0){0}}
%       \put(15,3){\makebox(0,0)[t]{length}}
%       \put(0,10){\vector(0,1){20}} \put(0,10){\vector(0,-1){0}}
%     \end{picture}}
%  \end{picture}
%  \caption{Length parameters for arrowhead and fanin line end styles}\label{fig:trifan}
% \end{figure}
%
%
% \DescribeVariable{gal}
% \DescribeVariable{gab}
% An arrowhead is defined by the height of the triangle and the base of
% the triangle forming the arrowhead, as shown in \fref{fig:trifan}. 
% |gal| and |gab| are the length 
% and base width of arrows for arrowed line end styles. 
% 
% \DescribeVariable{gfl}
% \DescribeVariable{gfb}
% Like an arrowhead, a fanin is defined by the height and the base of
% the triangular fan shape, as shown in \fref{fig:trifan}. 
% |gfl| and |gfb| are the length and base
% width of fans for fanin line end styles. They are initialised to the
% default values.
%
%    The next set of variables control certain geometric aspects of
% the various \ExpressG{} boxes.
%
% \DescribeVariable{onelineh}
% |onelineh| is the minimum height of a box that encloses a single
% line of text. This is initialised to |5u|.
%
% \begin{figure}
%   \setlength{\unitlength}{1mm}
%   \centering
%   \begin{picture}(65,40)
%     \put(0,0){\framebox(65,40){}}
%     \put(5,0){\begin{picture}(60,40)
%  ^^A     \put(0,0){\framebox(60,40){}}
%       \thicklines
%       \put(0,10){\framebox(40,15){}}
%       \put(30,10){\line(0,1){15}}
%       \thinlines
%       \put(0,5){\vector(1,0){40}} \put(0,5){\vector(-1,0){0}}
%       \put(20,3){\makebox(0,0)[t]{length}}
%       \put(45,10){\vector(0,1){15}} \put(45,10){\vector(0,-1){0}}
%       \put(47,17.5){\makebox(0,0)[l]{height}}
%       \put(40,30){\vector(-1,0){10}} \put(40,30){\vector(1,0){0}}
%       \put(35,32){\makebox(0,0)[b]{inset}}
%     \end{picture}}
%  \end{picture}
%  \caption{Parameters for (inset) boxes}\label{fig:bool}
% \end{figure}
%
% \DescribeVariable{sdtbl}
% \DescribeVariable{sdtbh}
% \DescribeVariable{sdtbs}
% The length (|sdtbl|), height (|sdtbh|) and line inset (|sdtbs|) for 
% simple data type boxes (e.g., a BOOLEAN data type box), as illustrated
% in \fref{fig:bool}. These are
% initialised as |22u|, |onelineh| and |2u| respectively.
% 
% \DescribeVariable{sdtebl}
% \DescribeVariable{sdtebh}
% \DescribeVariable{sdtebs}
% The length (|sdtebl|), height (|sdtebh|) and line inset (|sdtebs|) 
% for a simple data type EXPRESSION box. The value of |sdtebl| is |28u|,
% and the other values are the same as for the other simple data type boxes.
%
% \DescribeVariable{sdtbgel}
% \DescribeVariable{sdtbgeh}
% \DescribeVariable{sdtbges}
% The length (|sdtbgel|), height (|sdtbgeh|) and inset for GENERICENT
% data type boxes. The value of |sdtbgel| is |38u|,
% and the other values are the same as for the other simple data type boxes.
%
% \DescribeVariable{pconl}
% \DescribeVariable{pconh}
% The length (|pconl|) of an average numeric (proxy) page connector 
% (e.g., for |(9,9 (9,9))|) 
% and the height (|pconh|)  
% of an average page connector, which is initialised for one line of text.
%
% \DescribeVariable{enth}
% \DescribeVariable{typeh}
% \DescribeVariable{schemah}
% The heights of an average entity (|enth|), 
% type --- including enumeration and select --- (|typeh|),
% and schema (|schemah|) boxes. These are all initialised to cater for
% one line of text.
%
% \DescribeVariable{ish}
% \DescribeVariable{isrh}
% |ish| is the height of an interschema reference box with one line of text.
% |isrh| is the height of an interschema reference box with a rename, where
% there is one line of text each for the original and renamed
% names.
%
% \DescribeVariable{eventh}
% \DescribeVariable{eventslope}
% The height (|eventh|) of a one-lined event box, and the slope (|eventslope|)
% of the sides of an
% event box (e.g., 0.25 or 1/4).
%
%    The next set of variables control the amount of space surrounding text
% on \ExpressG{} diagrams.
%
% \DescribeVariable{nextra}
% |nextra| is the margin around names when put into entity, schema, 
% interschema reference,
% page connector, and event boxes.
% 
% \DescribeVariable{niextra}
% |niextra| is the margin around names when put into type boxes.
% 
% \DescribeVariable{ndextra}
% |ndextra| is the margin around names when used on attribute lines.
%
% \subsection{Routines}
%
% The principal aspects of an \ExpressG{} diagram are lines and line ends of 
% various styles, and boxes of several different kinds. Many routines
% are provided for positioning and drawing these on a diagram.
%
%    The following sections describe most of the routines. Short descriptions
% of the others, which
% are effectively only used as internal support routines, can be found
% in Section~\ref{sec:mf}.
%
%     A note on naming conventions used in describing the routines:
% \begin{itemize}
% \item As usual with \Mpost, a name starting with |z| is a point, and
% names staring with |x| or |y| are x- and y-coordinates respectively.
% \item The letters |i| through |n| denote (point, coordinate) suffixes.
%       Suffixes are usually a number, such as |37|, but may also have 
%       alphanumeric characters after the number (e.g., |37C2D|).
% \end{itemize}
%
%
% \subsubsection{Utility routines}
%
% Several utility routines are provided defining some shortcuts and 
% to ease some of the calculations
% that may be required when producing a diagram.
%
% \DescribeRoutine{VH}
% |VH(j, k)| calculates the intersection point, |zjvh|, between the vertical
% line through the point |zj| and the horizontal line through the point |zk|,
% as shown in \fref{fig:vhvh}.
%
%     
% \DescribeRoutine{VhV}
% |VhV(j, k)| calculates the point |zjvhv| on the vertical line through
% the point |zj| and the point |zkvhv| on the vertical line through the
% point |zk|, such that the line |zjvhv--zkvhv| is horizontal and centered
% vertically between the two given points,
% as shown in \fref{fig:vhvh}.
%
% \begin{figure}
%   \setlength{\unitlength}{1mm}
%   \centering
%   \begin{picture}(130,50)
%     \put(0,0){\framebox(120,50){}}
%     \put(5,5){\begin{picture}(30,40)
%   ^^A    \put(0,0){\framebox(30,40){}}
%       \put(5,35){\circle*{2}}
%       \put(3,37){\makebox(0,0)[br]{\texttt{zj}}}
%       \put(25,5){\circle*{2}}
%       \put(27,3){\makebox(0,0)[tl]{\texttt{zk}}}
%       \put(5,5){\circle{2}}
%       \put(3,3){\makebox(0,0)[tr]{\texttt{zjvh}}}
%       \put(5,0){\line(0,1){40}}
%       \put(0,5){\line(1,0){30}}
%     \end{picture}}
%     \put(45,5){\begin{picture}(30,40)
%   ^^A    \put(0,0){\framebox(30,40){}}
%       \put(5,35){\circle*{2}}
%       \put(3,37){\makebox(0,0)[br]{\texttt{zj}}}
%       \put(25,5){\circle*{2}}
%       \put(27,3){\makebox(0,0)[tl]{\texttt{zk}}}
%       \put(5,20){\circle{2}}
%       \put(3,18){\makebox(0,0)[tr]{\texttt{zjvhv}}}
%       \put(25,20){\circle{2}}
%       \put(27,22){\makebox(0,0)[bl]{\texttt{zkvhv}}}
%       \put(5,40){\line(0,-1){25}}
%       \put(0,20){\line(1,0){30}}
%       \put(25,0){\line(0,1){25}}
%     \end{picture}}
%     \put(85,5){\begin{picture}(30,40)
%   ^^A    \put(0,0){\framebox(30,40){}}
%       \put(5,35){\circle*{2}}
%       \put(3,37){\makebox(0,0)[br]{\texttt{zj}}}
%       \put(25,5){\circle*{2}}
%       \put(27,3){\makebox(0,0)[tl]{\texttt{zk}}}
%       \put(15,35){\circle{2}}
%       \put(17,37){\makebox(0,0)[bl]{\texttt{zjhvh}}}
%       \put(15,5){\circle{2}}
%       \put(13,3){\makebox(0,0)[tr]{\texttt{zkhvh}}}
%       \put(15,0){\line(0,1){40}}
%       \put(0,35){\line(1,0){20}}
%       \put(30,5){\line(-1,0){20}}
%     \end{picture}}
%  \end{picture}
%  \caption[Results of the \texttt{VH}, \texttt{VhV} and \texttt{HvH} 
%          routines]%
%         {Results of the \texttt{VH} (left), \texttt{VhV} (middle)
%          and \texttt{HvH} (right) routines}\label{fig:vhvh}
% \end{figure}
%
% \DescribeRoutine{HvH}
% |HvH(j, k)| calculates the point |zjhvh| on the horizontal line through
% the point |zj| and the point |zkhvh| on the horizontal line through the
% point |zk|, such that the line |zjhvh--zkhvh| is vertical and centered
% horizontally between the two given points,
% as shown in \fref{fig:vhvh}.
%
% \DescribeRoutine{VyV}
% |VyV(j, i, k)| is a generalisation of the |VhV| routine. It calculates
% the point |zjvyv| which is on the vertical line through |zj| and the
% horizontal line through |yi|, and the point |zkvyv| which is on the
% vertical line through |zk| and the horizontal line through |yi|. An example
% result is shown in \fref{fig:vyxh}.
% 
% \begin{figure}
%   \setlength{\unitlength}{1mm}
%   \centering
%   \begin{picture}(90,50)
%     \put(0,0){\framebox(90,50){}}
%     \put(10,5){\begin{picture}(30,40)
%       \put(5,35){\circle*{2}}
%       \put(3,37){\makebox(0,0)[br]{\texttt{zj}}}
%       \put(25,5){\circle{2}}
%       \put(27,3){\makebox(0,0)[tl]{\texttt{zkvyv}}}
%       \put(5,5){\circle{2}}
%       \put(3,3){\makebox(0,0)[tr]{\texttt{zjvyv}}}
%       \put(25,20){\circle*{2}}
%       \put(27,22){\makebox(0,0)[bl]{\texttt{zk}}}
%       \put(5,40){\line(0,-1){40}}  ^^A V through zj
%       \put(0,5){\line(1,0){30}}    ^^A H through yi
%       \put(32,5){\makebox(0,0)[bl]{\texttt{yi}}}
%       \put(25,0){\line(0,1){25}}   ^^A V through zk
%     \end{picture}}
%     \put(50,5){\begin{picture}(30,40)
%       \put(5,35){\circle*{2}}
%       \put(3,37){\makebox(0,0)[br]{\texttt{zj}}}
%       \put(25,5){\circle{2}}
%       \put(27,3){\makebox(0,0)[tl]{\texttt{zkhxh}}}
%       \put(25,35){\circle{2}}
%       \put(27,33){\makebox(0,0)[tl]{\texttt{zjhxh}}}
%       \put(15,5){\circle*{2}}
%       \put(13,3){\makebox(0,0)[tr]{\texttt{zk}}}
%       \put(25,0){\line(0,1){40}}    ^^A V through xi
%       \put(25,42){\makebox(0,0)[b]{\texttt{xi}}}
%       \put(0,35){\line(1,0){30}}    ^^A H through zj
%       \put(30,5){\line(-1,0){20}}   ^^A H through zk
%     \end{picture}}
%  \end{picture}
%  \caption[Results of the \texttt{VyV} and \texttt{HxH} 
%           routines]%
%          {Results of the \texttt{VyV} (left) and \texttt{HxH} (right) 
%           routines}\label{fig:vyxh}
% \end{figure}
%
% \DescribeRoutine{HxH}
% |HxH(j, i, k)| is a generalisation of the |HvH| routine. It calculates
% the point |zjhxh| which is on the horizontal line through |zj| and the
% vertical line through |xi|, and the point |zkhxh| which is on the
% horizontal line through |zk| and the vertical line through |xi|. An example
% result is shown in \fref{fig:vyxh}.
% 
% \DescribeRoutine{namespace}
% |namespace(|\meta{name}|)(|\meta{margin}|)| calculates the length of
% the text string \meta{name} plus the \meta{margin} length. You may
% use it like: \\
% |c = 3/2namespace(btex name etex)(4u)|
%
%     
% \DescribeRoutine{dashes}
% |dashes| is shorthand for a dashed linestyle. Use it like: |draw ... dashes;|.
%     
% \DescribeRoutine{dots}
% |dots| is shorthand for a dotted linestyle. Use it like: |draw ... dots;|.
%     
% \DescribeRoutine{drawgrid}
% |drawgrid| draws a 16 by 21cm, 1cm spaced grid composed of thin dashed lines.
% Labels are typeset giving the distance of the lines from the bottom left
% corner of the grid in millimetres.
%
% \subsubsection{Path routines}
%
%    The package provides some general path making routines.
%
% \DescribeRoutine{sharply}
% |sharply(zi, zj, ... zn)| will generate a piecewise linear
% path consisting of the
% straight lines from point |zi| to point |zj| \ldots to point |zn|.
% It may be used like: \\
% |draw sharply(z1, z2, z3, z4);| \\
% to draw a line through the given points.
%
% \DescribeRoutine{smoothly}
% Like the |sharply| routine, |smoothly(zi, zj, ... zn)| will generate a 
% piecewise linear path consisting of the
% straight lines from point |zi| to point |zj| \ldots to point |zn|, except
% that the corners of the path at the interior points are rounded with an
% arc of radius |smoothrad|.
% It may be used like: \\
% |draw smoothly(z1, z2, z3, z4) dashes;| \\
% to draw a dashed line with rounded corners at the given points. Or if
% a dotted line is needed:
% \begin{verbatim}
% pickup dotspen;
% draw smoothly(z1, z2, z3, z4) dots;
% pickup normalpen;
% \end{verbatim}
%
% \DescribeRoutine{~}
% Like the |&| operator, the binary |~| operator concatenates two paths
% replacing the sharp join with a circular arc of radius |smoothrad|.
%
% \subsubsection{Line drawing routines}
%
%  Routines are provided for drawing a variety of lines with differing line 
% ending styles. Line styles include dotted, dashed, and continuous, and line
% thicknesses may be normal or thick. Line end styles include open circles,
% black dots, open and closed (black) arrowheads, and a fanin style.
%
% The final uppercase characters of a line drawing routine indicate the kind
% of line end style that will be used. 
% The character |O| (uppercase O, not zero) is for an \textbf{O}pen circle, 
% |D| is for a black \textbf{D}ot,
% |OA| is for an \textbf{O}pen \textbf{A}rrowhead,
% |CA| is for a \textbf{C}losed (black) \textbf{A}rrowhead,
% and |F| is for a \textbf{F}anin.
%
%    The line ending drawing routines are described first.
% \DescribeRoutine{drawO}
% |drawO(i, j)| draws an open circle, diameter |dotdiam|, at the |zj| end
% of the vector from |zi| to |zj|.
%
% \DescribeRoutine{drawD}
% |drawD(i, j)| draws a black dot, diameter |dotdiam|, at the |zj| end
% of the vector from |zi| to |zj|.
%
% \DescribeRoutine{drawOA}
% |drawOA(i, j)| draws an open arrowhead, length |gal| and base width
% |gab|, at the |zj| end
% of the vector from |zi| to |zj|.
%
% \DescribeRoutine{drawCA}
% |drawCA(i, j)| draws a closed (black) arrowhead, length |gal| and base width
% |gab|, at the |zj| end
% of the vector from |zi| to |zj|.
%
% \DescribeRoutine{drawF}
% |drawF(i, j)| draws a fanin, length |gfl| and base width |gfb|, 
% at the |zj| end
% of the vector from |zi| to |zj|.
%
%    The line drawing routines are essentially prepackaged versions of
% different combinations of the path and line ending routines.
%     
% \DescribeRoutine{drawdots}
% |drawdots(i, j)| draws the dotted line |zi--zj|.
%
% \DescribeRoutine{drawdotsthree}
% |drawdotsthree(i, j, k)| draws the dotted piecewise linear line |zi--zj--zk|.
%
% \DescribeRoutine{drawdotsfour}
% |drawdotsfour(i, j, k, l)| draws the dotted piecewise linear line |zi--zj--zk--zl|.
%
% \DescribeRoutine{drawdotsO}
% |drawdotsO(i, j)| draws the dotted line |zi--zj|, 
% ending in an open circle, diameter |dotdiam|, at |zj|.
%
% \DescribeRoutine{drawdotsthreeO}
% |drawdotsthreeO(i, j, k)| draws the dotted piecewise linear line |zi--zj--zk|.
% ending in an open circle, diameter |dotdiam|, at |zk|.
%
% \DescribeRoutine{drawdotsfourO}
% |drawdotsfourO(i, j, k, l)| draws the dotted piecewise linear line |zi--zj--zk--zl|,
% ending in an open circle, diameter |dotdiam|, at |zl|.
%
% \DescribeRoutine{drawdotsOO}
% |drawdotsOO(i, j)| draws the dotted line |zi--zj|, 
% ending in open circles, diameter |dotdiam|, at |zi| and |zj|.
%
% \DescribeRoutine{drawdash}
% |drawdash(i, j)| draws the dashed line |zi--zj|.
%
% \DescribeRoutine{drawdashthree}
% |drawdashthree(i, j, k)| draws the dashed piecewise linear line |zi--zj--zk|.
%
% \DescribeRoutine{drawdashfour}
% |drawdashfour(i, j, k, l)| draws the dashed piecewise linear line |zi--zj--zk--zl|.
%
% \DescribeRoutine{drawdashO}
% |drawdashO(i, j)| draws the dashed line |zi--zj|,
% ending in an open circle, diameter |dotdiam|, at |zj|.
%
% \DescribeRoutine{drawdashthreeO}
% |drawdashthreeO(i, j, k)| draws the dashed piecewise linear line |zi--zj--zk|.
% ending in an open circle, diameter |dotdiam|, at |zk|.
%
% \DescribeRoutine{drawdashfourO}
% |drawdashfourO(i, j, k, l)| draws the dashed piecewise linear line |zi--zj--zk--zl|.
% ending in an open circle, diameter |dotdiam|, at |zl|.
%
% \DescribeRoutine{drawdashOO}
% |drawdashOO(i, j)| draws the dashed line |zi--zj--zk--zl|.
% ending in open circles, diameter |dotdiam|, at |zi| and |zj|.
%
% \DescribeRoutine{drawnormal}
% |drawnormal(i, j)| draws the normal thickness line |zi--zj|.
%
% \DescribeRoutine{drawnormalthree}
% |drawnormalthree(i, j, k)| draws the normal thickness piecewise linear 
% line |zi--zj--zk|.
%
% \DescribeRoutine{drawnormalfour}
% |drawnormalfour(i, j, k, l)| draws the normal thickness piecewise linear 
% line |zi--zj--zk--zl|.
%
% \DescribeRoutine{drawnormalO}
% |drawnormalO(i, j)| draws the normal thickness line |zi--zj|,
% ending in an open circle, diameter |dotdiam|, at |zj|.
%
% \DescribeRoutine{drawnormalthreeO}
% |drawnormalthreeO(i, j, k)| draws the normal thickness piecewise linear 
% line |zi--zj--zk|,
% ending in an open circle, diameter |dotdiam|, at |zk|.
%
% \DescribeRoutine{drawnormalfourO}
% |drawnormalfourO(i, j, k, l)| draws the normal thickness piecewise linear 
% line |zi--zj--zk--zl|,
% ending in an open circle, diameter |dotdiam|, at |zl|.
%
% \DescribeRoutine{drawnormalOO}
% |drawnormalOO(i, j)| draws the normal thickness line |zi--zj|,
% ending in open circles, diameter |dotdiam|, at |zi| and |zj|.
%
% \DescribeRoutine{drawnormalD}
% |drawnormalD(i, j)| draws the normal thickness line |zi--zj|,
% ending in a black dot, diameter |dotdiam|, at |zj|.
%
% \DescribeRoutine{drawnormalthreeD}
% |drawnormalthreeD(i, j, k)| draws the normal thickness piecewise linear 
% line |zi--zj--zk|,
% ending in a black dot, diameter |dotdiam|, at |zk|.
%
% \DescribeRoutine{drawnormalfourD}
% |drawnormalfourD(i, j, k, l)| draws the normal thickness piecewise linear 
% line |zi--zj--zk--zl|,
% ending in a black dot, diameter |dotdiam|, at |zl|.
%
% \DescribeRoutine{drawnormalDD}
% |drawnormalDD(i, j)| draws the normal thickness line |zi--zj|,
% ending in black dots, diameter |dotdiam|, at |zi| and |zj|.
%
% \DescribeRoutine{drawnormalCA}
% |drawnormalCA(i, j)| draws the normal thickness line |zi--zj|,
% ending in a closed (black) arrowhead, length |gal| and base width |gab|, 
% at |zj|.
%
% \DescribeRoutine{drawnormalthreeCA}
% |drawnormalthreeCA(i, j, k)| draws the normal thickness piecewise linear
% line |zi--zj--zk|
% ending in a closed (black) arrowhead, length |gal| and base width |gab|, 
% at |zk|.
%
% \DescribeRoutine{drawnormalfourCA}
% |drawnormalfourCA(i, j, k, l)| draws the normal thickness piecewise linear
% line |zi--zj--zk--zl|
% ending in a closed (black) arrowhead, length |gal| and base width |gab|, 
% at |zl|.
%
% \DescribeRoutine{drawnormalOA}
% |drawnormalOA(i, j)| draws the normal thickness line |zi--zj|,
% ending in an open arrowhead, length |gal| and base width |gab|, 
% at |zj|.
%
% \DescribeRoutine{drawnormalF}
% |drawnormalF(i, j)| draws the normal thickness line |zi--zj|,
% ending in a fanin, length |gfl| and base width |gfb|, 
% at |zj|.
%
% \DescribeRoutine{drawnormalFO}
% |drawnormalFO(i, j)| draws the normal thickness line |zi--zj|,
% ending in a fanin, length |gfl| and base width |gfb|, 
% at |zi| and an open circle, diameter |dotdiam|, at |zj|.
%
% \DescribeRoutine{drawthick}
% |drawthick(i, j)| draws the thick line |zi--zj|.
%
% \DescribeRoutine{drawthickO}
% |drawthickO(i, j)| draws the thick line |zi--zj|,
% ending in an open circle, diameter |dotdiam|, at |zj|.
%
% \DescribeRoutine{drawthickOO}
% |drawthickOO(i, j)| draws the thick line |zi--zj|,
% ending in open circles, diameter |dotdiam|, at |zi| and |zj|.
%
% \DescribeRoutine{smooth}
% |smooth(i, j, k)| replaces the sharp corner on the line |zi--zj--zk|
% with an arc radius |smoothrad|.
%
% \DescribeRoutine{smoothtwo}
% |smoothtwo(i, j, k, l)| replaces the sharp corners on the line |zi--zj--zk--zl|
% with arcs radius |smoothrad|.
%
% \DescribeRoutine{smoothdash}
% |smoothdash(i, j, k)| replaces the sharp corner on the dashed line |zi--zj--zk|
% with an arc radius |smoothrad|.
%
% \DescribeRoutine{smoothdots}
% |smoothdots(i, j, k)| replaces the sharp corner on the dotted line |zi--zj--zk|
% with an arc radius |smoothrad|.
%
%
%
% \subsubsection{Box drawing routines}
%
%    Routines are provided for drawing the different kinds of \ExpressG{} 
% boxes.
%
%    The first argument to the box drawing routines is the suffix of the
% point that will be the left-hand bottom corner point of the box. The
% last argument, except where noted below, is the text that is to be placed
% at the center of the box. Intermediate arguments, if any, are the length
% and height of the box.
%
%  Every box routine calculates the four corner points of the box and the 
% midpoints of each side of the box. For example, if the suffix is |j|,
% then as illustrated in figure~\ref{fig:boxpoints}, the corner points
% will be called |zjbl|, |zjbr|, |zjtr| and |zjtl| and the midpoints
% will be called |zjbm|, |zjmr|, |zjtm| and |zjml|. The center point for
% postioning the text is |zjc| and the center of the text is placed at
% this point. 
%
%    The text center point is not necessarily the geometric center of the box.
% The geometric center is not calculated but lies at the intersection of
% the lines |zjml--zjmr| and |zjbm--zjtm|.
%
% \begin{figure}
% \centering
% \setlength{\unitlength}{1mm}
% \begin{picture}(50,40)
%   \put(0,0){\framebox(50,40){}}
%   \put(10,10){\begin{picture}(30,20)
%     \put(0,0){\framebox(30,20){}}
%     \multiput(0,0)(15,0){3}{\circle*{2}}
%     \multiput(0,10)(15,0){3}{\circle*{2}}
%     \multiput(0,20)(15,0){3}{\circle*{2}}
%     \put(-2,-2){\makebox(0,0)[tr]{\texttt{zjbl}}}
%     \put(15,-2){\makebox(0,0)[t]{\texttt{zjbm}}}
%     \put(32,-2){\makebox(0,0)[tl]{\texttt{zjbr}}}
%     \put(-2,10){\makebox(0,0)[r]{\texttt{zjml}}}
%     \put(13,10){\makebox(0,0)[r]{\texttt{zjc}}}
%     \put(32,10){\makebox(0,0)[l]{\texttt{zjmr}}}
%     \put(-2,22){\makebox(0,0)[br]{\texttt{zjtl}}}
%     \put(15,22){\makebox(0,0)[b]{\texttt{zjtm}}}
%     \put(32,22){\makebox(0,0)[bl]{\texttt{zjtr}}}
%     \end{picture}}
%  \end{picture}
%  \setlength{\unitlength}{1pt}
%  \caption[Calculated points on rectangular boxes]%
%          {Calculated points on rectangular boxes 
%           (suffix is \texttt{j} and located at \texttt{zjbl=zj})}
%  \label{fig:boxpoints}
% \end{figure}
%     
% \DescribeRoutine{drawSCHEMA}
% A SCHEMA box is rectangular with a normal perimeter and the box is divided
% into top and bottom halves by a horizontal line.
%
% |drawSCHEMA(j, len, ht)(btex schema\_a etex)| draws a SCHEMA double rectangular 
% box of length |len| and height |ht| with its left-hand bottom corner
% at |zj|. The string |schema_a| is placed at the text center of the box,
% which is central within the upper half.
%
% \DescribeRoutine{drawBINARY}
% A simple data type box is rectangular with a solid boundary and a solid
% interior vertical line near the right hand edge.
%
% |drawBINARY(j)| draws a simple data type rectangular 
% box of length |sdtbl| and height |sdtbh| with its left-hand bottom corner
% at |zj|. The string |BINARY| is placed at the text center of the box,
% which is central within the main part of the box.
%
% \DescribeRoutine{drawBOOLEAN}
% |drawBOOLEAN(j)| draws a simple data type rectangular 
% box of length |sdtbl| and height |sdtbh| with its left-hand bottom corner
% at |zj|. The string |BOOLEAN| is placed at the text center of the box,
% which is central within the main part of the box.
%
% \DescribeRoutine{drawCOMPLEX}
% |drawCOMPLEX(j)| draws a simple data type rectangular 
% box of length |sdtbl| and height |sdtbh| with its left-hand bottom corner
% at |zj|. The string |COMPLEX| is placed at the text center of the box,
% which is central within the main part of the box.
%
% \DescribeRoutine{drawEXPRESSION}
% |drawEXPRESSION(j)| draws a simple data type rectangular 
% box of length |sdtbel| and height |sdtbeh| with its left-hand bottom corner
% at |zj|. The string |EXPRESSION| is placed at the text center of the box,
% which is central within the main part of the box.
%
% \DescribeRoutine{drawGENERIC}
% |drawGENERIC(j)| draws a simple data type rectangular 
% box of length |sdtbl| and height |sdtbh| with its left-hand bottom corner
% at |zj|. The string |GENERIC| is placed at the text center of the box,
% which is central within the main part of the box.
%
% \DescribeRoutine{drawINTEGER}
% |drawINTEGER(j)| draws a simple data type rectangular 
% box of length |sdtbl| and height |sdtbh| with its left-hand bottom corner
% at |zj|. The string |INTEGER| is placed at the text center of the box,
% which is central within the main part of the box.
%
% \DescribeRoutine{drawLOGICAL}
% |drawLOGICAL(j)| draws a simple data type rectangular 
% box of length |sdtbl| and height |sdtbh| with its left-hand bottom corner
% at |zj|. The string |LOGICAL| is placed at the text center of the box,
% which is central within the main part of the box.
%
% \DescribeRoutine{drawNUMBER}
% |drawNUMBER(j)| draws a simple data type rectangular 
% box of length |sdtbl| and height |sdtbh| with its left-hand bottom corner
% at |zj|. The string |NUMBER| is placed at the text center of the box,
% which is central within the main part of the box.
%
% \DescribeRoutine{drawREAL}
% |drawREAL(j)| draws a simple data type rectangular 
% box of length |sdtbl| and height |sdtbh| with its left-hand bottom corner
% at |zj|. The string |REAL| is placed at the text center of the box,
% which is central within the main part of the box.
%
% \DescribeRoutine{drawSTRING}
% |drawSTRING(j)| draws a simple data type rectangular 
% box of length |sdtbl| and height |sdtbh| with its left-hand bottom corner
% at |zj|. The string |STRING| is placed at the text center of the box,
% which is central within the main part of the box.
%
% \DescribeRoutine{drawENUM}
% An ENUMERATION box is a rectangular box with a dashed perimeter and an 
% interior dashed vertical line near the right hand edge.
%
% |drawENUM(j, len, ht)(btex an\_enum etex)| draws a rectangular dashed ENUMERATION type
% box of length |len| and height |ht| with its left-hand bottom corner
% at |zj|. The string |an_enum| is placed at the text center of the box,
% which is central within the main part of the box.
%
% \DescribeRoutine{drawSELECT}
% A SELECT box is rectangular with a dashed boundary and an interior
% dashed vertical
% line near the left hand edge.
%
% |drawSELECT(j, len, ht)(btex a\_select etex)| draws a rectangular dashed SELECT type
% box of length |len| and height |ht| with its left-hand bottom corner
% at |zj|. The string |a_select| is placed at the text center of the box,
% which is central within the main part of the box.
%
% \DescribeRoutine{drawTYPE}
% A TYPE box is rectangular with a dashed boundary.
%
% |drawTYPE(j, len, ht)(btex a\_type etex)| draws a rectangular dashed TYPE type
% box of length |len| and height |ht| with its left-hand bottom corner
% at |zj|. The string |a_type| is placed at the text center of the box,
% which is central within the main part of the box.
%
% \DescribeRoutine{drawENT}
% An ENTITY box is a rectangular box with a solid boundary.
%
% |drawENT(j, len, ht)(btex an\_entity etex)| draws a rectangular ENTITY type
% box of length |len| and height |ht| with its left-hand bottom corner
% at |zj|. The string |an_entity| is placed at the text center of the box,
% which is also the geometric center of the box.
%
% \DescribeRoutine{drawPREF}
% A page reference box is a rectangle with rounded ends and a solid boundary.
%
% |drawPREF(j, len, ht)(btex page ref etex)| draws an oval page
% reference 
% box of length |len| and height |ht| with its left-hand bottom corner
% at |zj|. The string |page ref| is placed at the text center of the box,
% which is also the geometric center of the box.
%
% \DescribeRoutine{drawISU}
% An interschema box is a rectangle surrounding a page reference like box.
% The rectangular box may have either a solid or a dashed boundary.
%
% |drawISU(j, len, ht)(btex sch.ent etex)| draws a three-part rectangular
% interschema USE 
% box of length |len| and height |ht| with its left-hand bottom corner
% at |zj|. The string |sch.ent| is placed at the text center of the box,
% which is also the geometric center of the box.
%
% \DescribeRoutine{drawISUR}
% |drawISUR(j, len, ht)(btex sch.ent etex)(btex newname etex)| draws a three-part rectangular
% interschema USE and RENAME
% box of length |len| and height |ht| with its left-hand bottom corner
% at |zj|. The string |sch.ent| is placed at the text center of the box,
% which is also the geometric center of the box. The string |newname| is
% placed at the geometric center of the bottom third of the box (this is
% the point |zjrnm|).
%
% \DescribeRoutine{drawISR}
% |drawISR(j, len, ht)(btex sch.ent etex)| draws a three-part rectangular
% dashed interschema REFERENCE 
% box of length |len| and height |ht| with its left-hand bottom corner
% at |zj|. The string |sch.ent| is placed at the text center of the box,
% which is also the geometric center of the box.
%
% \DescribeRoutine{drawISRR}
% |drawISRR(j, len, ht)(btex sch.ent etex)(btex newname etex)| draws a three-part rectangular
% dashed interschema REFERENCE and RENAME
% box of length |len| and height |ht| with its left-hand bottom corner
% at |zj|. The string |sch.ent| is placed at the text center of the box,
% which is also the geometric center of the box. The string |newname| is
% placed at the geometric center of the bottom third of the box (this is
% the point |zjrnm|).
%
% \DescribeRoutine{drawLEVENT}
% An EVENT box is a rhomboid with a solid boundary.
%
% |drawLEVENT(j, len, ht)(btex local\_event etex)| draws a rhomboidal
% Local EVENT 
% box of length |len|, height |ht| and slope |eventslope|  with its left-hand bottom corner
% at |zj|. The string |local_event| is placed at the text center of the box,
% which is also the geometric center of the box. Like the rectangular boxes,
% the calculated bottom and top middle points are vertically below and above
% the geometric center, but this means that they are \emph{not} midway
% beteen the bottom and top corner points. This is illustrated in
% \fref{fig:eventpoints}.
%
% \begin{figure}
% \centering
% \setlength{\unitlength}{1mm}
% \begin{picture}(55,40)
%   \put(0,0){\framebox(55,40){}}
%   \put(10,10){\begin{picture}(40,20)
% ^^A    \put(0,0){\framebox(30,20){}}
%     \put(0,0){\line(1,0){30}}
%     \put(5,20){\line(1,0){30}}
%     \put(0,0){\line(1,4){5}}
%     \put(30,0){\line(1,4){5}}
%     \multiput(0,0)(30,0){2}{\circle*{2}}
%     \multiput(2.5,10)(30,0){2}{\circle*{2}}
%     \multiput(5,20)(30,0){2}{\circle*{2}}
%     \multiput(17.5,0)(0,10){3}{\circle*{2}}
%     \put(-2,-2){\makebox(0,0)[tr]{\texttt{zjbl}}}
%     \put(17.5,-2){\makebox(0,0)[t]{\texttt{zjbm}}}
%     \put(32,-2){\makebox(0,0)[tl]{\texttt{zjbr}}}
%     \put(0.5,10){\makebox(0,0)[r]{\texttt{zjml}}}
%     \put(15.5,10){\makebox(0,0)[r]{\texttt{zjc}}}
%     \put(34.5,10){\makebox(0,0)[l]{\texttt{zjmr}}}
%     \put(3,22){\makebox(0,0)[br]{\texttt{zjtl}}}
%     \put(17.5,22){\makebox(0,0)[b]{\texttt{zjtm}}}
%     \put(37,22){\makebox(0,0)[bl]{\texttt{zjtr}}}
%     \end{picture}}
%  \end{picture}
%  \setlength{\unitlength}{1pt}
%  \caption[Calculated points on rhomboidal boxes]%
%          {Calculated points on rhomboidal boxes 
%           (suffix is \texttt{j} and located at \texttt{zjbl=zj})}
%  \label{fig:eventpoints}
% \end{figure}
%     
% \DescribeRoutine{drawGEVENT}
% |drawGEVENT(j, len, ht)(btex global\_event etex)| draws a thick rhomboidal 
% Global EVENT 
% box of length |len|, height |ht| and slope |eventslope| with its left-hand bottom corner
% at |zj|. The string |global_event| is placed at the text center of the box,
% which is also the geometric center of the box.
%
%     
% \DescribeRoutine{drawcirclebox}
% A circle box is a circle with a solid boundary.
%
% |drawcirclebox(j, diam)(btex ABC etex)| draws a circle diameter |diam|
% and center at |zj|. The string |ABC| is placed at the center of the circle.
% In this case the four midside points,  |zjbm|, |zjmr|, |zjtm| and |zjml|,
% are at on the circle at the extreme bottom, right, top and left (i.e., at
% the S, E, N and W compass points). The
% corner points, |zjbl|, |zjbr|, |zjtr| and |zjtl|, are also on the 
% circumference midway between the midpoints (i.e., at the SW, SE, NE and NW
% compass points).
%
% \DescribeRoutine{drawdashcircle}
% |drawdashcircle(j, diam)| draws a dashed circle. The location
% and size parameters are the same as for |drawcirclebox|, as are the
% calculated points.
%
% \subsection{Extra BLA variables and routines}
%
%    In addition to the facilities described above for \ExpressG{}
% diagrams, extra line styles and boxes are provided for other
% kinds of diagrams.
%
%    Additional line end styles are coded by: 
% |A| for an \textbf{A}rrowhead,
% |OD| for an \textbf{O}pen \textbf{D}iamond,
% |CD| for a \textbf{C}losed \textbf{D}iamond.
%
% \DescribeVariable{gdl}
% \DescribeVariable{gdb}
% The variables |gdl| and |gdb| hold the the length and base width of
% diamond line end styles (see \fref{fig:diales}), 
% analagous to the corresponding variables
% for arrow heads and fanin. By default, |gdl| is twice the default
% arrowhead length and |gdb| is three quarters of the default
% arrowhead base width.
%
% \begin{figure}
%   \setlength{\unitlength}{1mm}
%   \centering
%   \begin{picture}(90,40)
%     \put(0,0){\framebox(90,40){}}
%     \put(5,0){\begin{picture}(85,40)
%   ^^A    \put(0,0){\framebox(85,40){}}
%       \thicklines
%       \put(0,20){\line(1,0){10}}
%  ^^A     \put(10,10){\line(2,1){20}}
%  ^^A     \put(10,30){\line(2,-1){20}}
%  ^^A     \put(10,10){\line(0,1){20}}
%       \put(10,20){\line(2,1){20}}
%       \put(10,20){\line(2,-1){20}}
%       \put(50,20){\line(-2,1){20}}
%       \put(50,20){\line(-2,-1){20}}
%       \thinlines
%  ^^A     \put(10,5){\vector(1,0){20}} \put(10,5){\vector(-1,0){0}}
%  ^^A     \put(20,3){\makebox(0,0)[t]{length}}
%  ^^A     \put(35,10){\vector(0,1){20}} \put(35,10){\vector(0,-1){0}}
%  ^^A     \put(40,20){\makebox(0,0)[l]{base width}}
%       \put(10,5){\vector(1,0){40}} \put(10,5){\vector(-1,0){0}}
%       \put(30,3){\makebox(0,0)[t]{length}}
%       \put(55,10){\vector(0,1){20}} \put(55,10){\vector(0,-1){0}}
%       \put(60,20){\makebox(0,0)[l]{base width}}
%     \end{picture}}
%  \end{picture}
%  \caption{Length parameters for diamond line end styles}\label{fig:diales}
% \end{figure}
%
% \DescribeRoutine{drawA}
% |drawA(i, j)| draws a simple arrowhead, length |gal| and base width
% |gab|, at the |zj| end
% of the vector from |zi| to |zj|.
%
%
% \DescribeRoutine{drawDCA}
% |drawDCA(i, j)| draws a double closed arrowhead, each of length |gal| 
% and base width
% |gab|, at the |zj| end
% of the vector from |zi| to |zj|.
%
%
% \DescribeRoutine{drawOD}
% |drawOD(i, j)| draws an open diamond, length |gdl| and base width
% |gdb|, at the |zj| end
% of the vector from |zi| to |zj|.
%
% \DescribeRoutine{drawCD}
% |drawCD(i, j)| draws a closed (black) diamond, length |gdl| and base width
% |gdb|, at the |zj| end
% of the vector from |zi| to |zj|.
%
%
% \DescribeRoutine{drawdashA}
% |drawdashA(i, j)| draws the dashed line |zi--zj|,
% ending in an arrowhead, length |gal| and base width |gab|, 
% at |zj|.
%
% \DescribeRoutine{drawdashOA}
% |drawdashOA(i, j)| draws the dashed line |zi--zj|,
% ending in an open arrowhead, length |gal| and base width |gab|, 
% at |zj|.
%
% \DescribeRoutine{drawnormalOD}
% |drawnormalOD(i, j)| draws the normal thickness line |zi--zj|,
% ending in an open diamond, length |gdl| and base width |gdb|, 
% at |zj|.
%
% \DescribeRoutine{drawnormalCD}
% |drawnormalCD(i, j)| draws the normal thickness line |zi--zj|,
% ending in a closed (black) diamond, length |gdl| and base width |gdb|, 
% at |zj|.
%
% \DescribeRoutine{drawcircleA}
% |drawcircleA(j, diam)| draws a circle diameter |diam| centered at |zj|.
% A counterclockwise pointing arrow is placed at the top of the circle.
% The midside and `corner' points are the same as calculated by
% the |drawcirclebox| routine.
%
% \DescribeRoutine{drawDot}
% |drawDot(j, diam)| draws a black dot, diameter |diam| centered at |zj|.
% There are no calculated points.
%
% \DescribeRoutine{drawCircledDot}
% |drawCircledDot(j, diam)| draws a black dot with a circle outside
% it, overall diameter |diam|, centered at |zj|.
% There are no calculated points. This could be used for a UML
% `bullseye'. The white ring should obscure anything 
% drawn earlier that lies underneath it (by definition the black dot covers 
% up anything underneath itself). For example: 
% \begin{verbatim}
% draw z1--z2;            % line from z1 to z2
% drawCircledDot(2, len); % obscures last len of above line
% draw z3--z2;            % not obscured
% \end{verbatim}
%
%    Commands of the form |draw...box| have a text argument
% which is printed at the center of the box. If an empty box is
% required the text argument should be an empty string (|""|). For
% example |draw...box(...)("")|.
%
% \DescribeRoutine{drawcardbox}
% |drawcardbox(j, len, ht, fold)(btex note etex)| draws a rectangular
% box, length |len| and height |ht|, with its bottom left corner at |zj|.
% The top right corner of the box is folded down, with the side length
% of the fold given by |fold|. The string |note| is placed at the
% center of the box. If no text is required, then use an empty string (i.e.,
% |""|), as in \\
% |\drawcardbox(23, el, eh, 1/8eh)("")|
%
% \DescribeRoutine{drawdiamondbox}
% |drawdiamondbox(j, len, ht)(btex str etex)| draws a diamond shaped 
% box, length |len| and height |ht|, with its center at |zj|. The usual
% corner, center and midpoints are also calculated except that the points
% |z$tm| etc., are at the corners of the diamond and the points |z$tl| etc.,
% are at the middle of each line, as shown in \fref{fig:diamondpoints}.
% The text |str| is placed at the center of the box.
%
% \begin{figure}
% \centering
% \setlength{\unitlength}{1mm}
% \begin{picture}(50,40)
%   \put(0,0){\framebox(50,40){}}
%   \put(10,10){\begin{picture}(30,20)
%  ^^A   \put(0,0){\framebox(30,20){}}
%     \put(0,10){\line(3,2){15}}
%     \put(0,10){\line(3,-2){15}}
%     \put(30,10){\line(-3,2){15}}
%     \put(30,10){\line(-3,-2){15}}
%     \multiput(0,10)(15,0){3}{\circle*{2}}
%     \multiput(15,0)(0,20){2}{\circle*{2}}
%     \multiput(7.5,5)(0,10){2}{\circle*{2}}
%     \multiput(22.5,5)(0,10){2}{\circle*{2}}
%     \put(13,10){\makebox(0,0)[r]{\texttt{zjc}}}
%     \put(15,-2){\makebox(0,0)[t]{\texttt{zjbm}}}
%     \put(-2,10){\makebox(0,0)[r]{\texttt{zjml}}}
%     \put(32,10){\makebox(0,0)[l]{\texttt{zjmr}}}
%     \put(15,22){\makebox(0,0)[b]{\texttt{zjtm}}}
%
%     \put(5.5,3){\makebox(0,0)[tr]{\texttt{zjbl}}}
%     \put(24.5,3){\makebox(0,0)[tl]{\texttt{zjbr}}}
%     \put(5.5,17){\makebox(0,0)[br]{\texttt{zjtl}}}
%     \put(24.5,17){\makebox(0,0)[bl]{\texttt{zjtr}}}
%     \end{picture}}
%  \end{picture}
%  \setlength{\unitlength}{1pt}
%  \caption[Calculated points on diamond boxes]%
%          {Calculated points on diamond boxes 
%           (suffix is \texttt{j} and located at \texttt{zjc=zj})}
%  \label{fig:diamondpoints}
% \end{figure}
%     
%
% \DescribeRoutine{drawtwodiamondbox}
% |drawtwodiamondbox(j, len, ht, inset)(btex str etex)| draws a diamond shaped 
% box, length |len| and height |ht|, with its center at |zj|. 
% The text |str| is placed at the center of the box.
% A second diamond is drawn inside the first. The parameter |inset| is
% the space between adjacent outer and inner lines.
% No calculated points are available for the inner diamond.
%
% \DescribeRoutine{drawdoublerectangle}
% |drawdoublerectangle(j, len, ht, tf)| draws a rectangular box, length |len|
% and height |ht|, located with its bottom left corner at |zj|. The box
% is divided horizontally
% into a top and bottom portion, with the height of the top portion being
% the fraction |tf| of the total height of the box. The center points of
% the two portions are calculated as |zjct| and |zjcb| for the top and
% bottom respectively. 
% The ends of the dividing line are at |zjtfl| and |zjtfr|.
%
% \DescribeRoutine{drawtriplerectangle}
% |drawtriplerectangle(j, len, ht, tf, bf)| draws a rectangular box, length |len|
% and height |ht|, located with its bottom left corner at |zj|. The box
% is divided horizontally
% into a top, middle and bottom portion.
% The height of the top portion is the fraction |tf| of the total height 
% of the box. 
% The height of the bottom portion is the fraction |bf| of the total height 
% of the box. 
% The center points of
% the three portions are calculated as |zjct|, |zjcm| and |zjcb| for the 
% top, middle and bottom respectively.
% The ends of the dividing lines are at |zjtfl| and |zjtfr| for the upper
% line, and at |zjbfl| and |zjbfr| for the lower line.
%
% \DescribeRoutine{hiderectangle}
% |hiderectangle(j, len, ht)| draws an invisible rectangular box, length |len|
% and height |ht|, located with its bottom left corner at |zj|. The box
% covers up anything underneath it. Note that unlike all the other boxes
% the only point handle to the box is the bottom left corner --- the
% |zjbl|, |zjtr|, etc.,  points are not available and hence cannot
% be used for positioning or alignment purposes.
%
% \DescribeRoutine{drawdashboxover}
% |drawdashboxover(j, len, ht)| draws a dashed rectangular box, length |len|
% and height |ht|, located with its bottom left corner at |zj|. The box
% covers up anything underneath it.
%
% \DescribeRoutine{drawindexbox}
% |drawindexbox(j, len, ht, lenp, htp)(btex str etex)| 
% draws a rectangular box, length |len|
% and height |ht|, located with its bottom left corner at |zj|. Another
% rectangular box, length |lenp| and height |htp|, is drawn with its
% bottom left corner at the top left corner of the first box (like an index
% card). The main box points are |zjbl| etc., but the secondary box
% points are |zjP.bl|, |zjP.bm| etc. The text |str| is placed at the center
% (|zjP.c|) of the secondary box.
%
% \DescribeRoutine{drawroundedbox}
% |drawroundedbox(j, len, ht, rad)(btex str etex)| 
% draws a rectangular box, length |len|
% and height |ht|, located with its bottom left corner at |zj|. The corners
% of the box are rounded using radius |rad|. If |2rad| is greater
% than |len| or |ht|, then |2rad| is reduced to the lesser of |len| and
% |ht|, thereby producing at least one pair of semicircular sides.
% The text |str| is placed at the center of the box.
%
% \DescribeRoutine{drawovalbox}
% |drawovalbox(j, len, ht)(btex str etex)|
% draws an elliptical box, 
% horizontal diameter |len|
% and vertical diameter |ht|, located with its center at |zj|. Like the 
% diamond box, |zjtm|, |zjmr|, etc., are at the extremes of the ellipse
% and the points |zjtr|, |zjbr|, etc., are on the ellipse approximately
% halfway between the extremum points, similar to the positions shown
% in \fref{fig:diamondpoints}. The text |str| is placed at the center 
% of the box.
%
% \DescribeRoutine{drawoutputbox}
% |drawoutputbox(j, len, ht)(btex str etex)|
% draws a box, 
% length |len| and height |ht|, located with its bottom left corner at |zj|. 
% The bottom of the box is a wavy line and the other three sides
% are straight. The text |str| is placed at the center of the box.
% This kind of box is often used as a flowchart symbol for output; 
% it is meant to be a represention of printed paper which has been
% torn from a long continuous roll.
%
%
% \DescribeRoutine{drawdashellipse}
% |drawdashellipse(j, len, ht)| 
% draws a dashed ellipse. The location and dimensional parameters 
% correspond to those for |drawovalbox|, as do the calculated points.
% 
% \DescribeRoutine{drawdrum}
% |drawdrum(j, len, ht)(btex str etex)|
% draws a `drum' box. This is constructed as a rectangular box of width
% width |len| and height |ht|, with its bottom left hand corner at |zj|.
% The horizontal line at the bottom of the
% rectangle is replaced by a half-ellipse with a major diameter of |len|
% and the minor diameter given by |drumlid*len|. The horizontal line
% at the top is replaced by a full ellipse with the same dimensions.
%
%\begin{figure}
%\centering
%\setlength{\unitlength}{0.6mm}
%
%\begin{picture}(100,100)
%  \put(0,0){\framebox(120,120){}}
%  \put(20,20){\begin{picture}(80,80)
%    \put(0,10){\line(0,1){60}}
%    \put(80,10){\line(0,1){60}}
%    \qbezier(0,10)(0,0)(40,0)
%    \qbezier(40,0)(80,0)(80,10)
%
%    \qbezier(0,70)(0,80)(40,80)
%    \qbezier(40,80)(80,80)(80,70)
%    \qbezier(0,70)(0,60)(40,60)
%    \qbezier(40,60)(80,60)(80,70)
%
%    \multiput(0,10)(0,30){3}{\circle*{2}}
%    \put(-2,10){\makebox(0,0)[r]{\texttt{zjbl}}}
%    \put(-2,40){\makebox(0,0)[r]{\texttt{zjml}}}
%    \put(-2,70){\makebox(0,0)[r]{\texttt{zjtl}}}
%    \multiput(80,10)(0,30){3}{\circle*{2}}
%    \put(82,10){\makebox(0,0)[l]{\texttt{zjbr}}}
%    \put(82,40){\makebox(0,0)[l]{\texttt{zjmr}}}
%    \put(82,70){\makebox(0,0)[l]{\texttt{zjtr}}}
%    \put(40,0){\circle*{2}}
%    \put(40,-2){\makebox(0,0)[t]{\texttt{zjbm}}}
%    \put(40,80){\circle*{2}}
%    \put(40,82){\makebox(0,0)[b]{\texttt{zjtm}}}
%    \put(40,35){\circle*{2}}
%    \put(40,37){\makebox(0,0)[b]{\texttt{zjc}}}
%
%    \put(20,1){\circle*{2}}
%    \put(20,-1){\makebox(0,0)[t]{\texttt{zjbml}}}
%    \put(60,1){\circle*{2}}
%    \put(60,-1){\makebox(0,0)[t]{\texttt{zjbmr}}}
%    \put(20,79){\circle*{2}}
%    \put(20,81){\makebox(0,0)[b]{\texttt{zjtml}}}
%    \put(60,79){\circle*{2}}
%    \put(60,81){\makebox(0,0)[b]{\texttt{zjtmr}}}
%    
%  \end{picture}}
%\end{picture}
%\setlength{\unitlength}{1pt}
%\caption[Calculated points on a drum]{Calculated points on a drum 
%         (suffix is \texttt{j} and located at \texttt{zjbl=zj})} 
%  \label{fig:drum}
%\end{figure}
%
% As shown in Figure~\ref{fig:drum}, 
% the calculated points on the vertical sides of the drum are the same
% as for a rectangular box. There are three calculated points on the base
% of the drum, called |zjbml|, |zjbm| and |zjbmr|. Similarly there are
% three points on the top of the drum called |zjtml|, |zjtm| and |zjtmr|.
% The center point, |zjc| is halfway between the sides and halfway between
% the two lower ellipse halves. The text |str| is placed at this center point.
%
% \DescribeRoutine{drawstickman}
% |drawstickman(j, len, ht)|
% draws a genderless full frontal (or rear) stick figure enclosed in 
% an invisible box, 
% length |len| and height |ht|, located with its bottom left corner at |zj|. 
% This can be used, for example to represent an actor in a UML Use Case
% diagram. Setting the height to be twice the length produces a reasonable
% result, for instance:
% \verb?drawstickman(3, wd, 2wd);?
%
%     
% \section{An example} \label{sec:example}
%
%    The example attempts to bring out the main methods that can be used
% in defining \ExpressG{} diagrams. The code for eleven diagrams is provided, none
% of which necessarily has anything to do with a real example of \ExpressG{}
% modeling, but rather is meant to be illustrative of diagramming techniques.
%
%    This section is best studied with a copy of the printed diagrams to
% hand. Section~\ref{sec:run} on \pref{sec:run} explains briefly how
% to run the example and obtain the diagrams.
% 
%    The default extension for a \Mpost{} file is \file{.mp}.
%    \begin{macrocode}
%<*eg>
%%% EXPEG.MP  Example MetaPost EXPRESS-G diagrams

%    \end{macrocode}
%
%    Assuming that the diagrams are to be eventually embedded in, or processed
% through, a \LaTeX{} document then any \TeX{} macros must come at the
% start of the file between a |verbatimtex| \ldots |etex| pair. When dealing
% with text, \Mpost{} does not handle more than a single line. The macro
% below is to enable two lines of text to be handled by \Mpost.
%     
%    \begin{macrocode}

% use btex \twolines{first}{second} etex for two-line labels
verbatimtex \def\twolines#1#2{\vbox{\hbox{#1} \hbox{#2}}} etex

%    \end{macrocode}
%
%    The \Lpack{expressg} package file has to be input to make the routines
% available.
%    \begin{macrocode}
input expressg

%    \end{macrocode}
%
% \subsection{Diagram 1: Some boxes and lines}
%
%   Many diagrams can be defined in one file. Each diagram starts with
% |beginfig(N)|, where N is a unique integer, and ends with |endfig;|.
% \EPS{} for each diagram is written to a file called
% \file{mproot.N}, where \file{mproot} is the root name of the input file. 
% In our
% case the output files will be \file{expeg.1} through \file{expeg.11}.
%    \begin{macrocode}
beginfig(1)

%    \end{macrocode}
%
%    The first diagram consists of some of the \Lpack{expressg} box and line styles.
% The main point is to illustrate how \Mpost{} allows the boxes to be aligned.
% Start off by defining a point |z1| at the origin. By default, a variable name
% starting with the letter |z| is assumed to be a point. Similarly, variables
% starting with |x| and |y| are assumed to be x- and y-coordinates. If |zk|
% is defined with a value then automatically |xk| is the value of the x 
% coordinate of 
% the point |zk| and |yk| is the value of the
% y coordinate. Conversely, if |xj| and |yj| are defined, |zj| is automatically
% defined.
%
%    Note that the |=| sign denotes an equation, not an assignment. The power
% of \Mpost{} comes from its ability to solve linear equations.
%
%    Having defined the point |z1|, draw an EXPRESSION box with its bottom
% left hand corner at |z1|.
%    \begin{macrocode}
z1=(0,0);
drawEXPRESSION(1);

%    \end{macrocode}
%
%    Remember that when a box is drawn, its corner and mid points are 
% calculated. These can be used in defining other points. In particular
% there is the point |z1tr| which is the top right hand corner
% of the EXPRESSION box. Also, if another box is drawn at point |z2| then
% it will have its bottom left hand corner at |z2bl|.
%
%    The point |z2bl| is defined by a linear equation with respect to
% the point |z2|. As \Mpost{} can solve linear equations, given the
% point |z2bl| it can solve for the point |z2|. 
%
%    The next box has its bottom left hand corner at the top right hand
% corner of the EXPRESSION box, by specifying that the
% point |z2bl| and |z1tr| are the same location and then drawing a box located
% at |z2|. The third (BOOLEAN) box is also stacked in the same way with 
% respect to the second (INTEGER) box.
% 
%    \begin{macrocode}
z2bl=z1tr;
drawINTEGER(2);

z3bl=z2tr;
drawBOOLEAN(3);

%    \end{macrocode}
%
%    Next a piece of circled text is drawn. Using the same method as before,
% the bottom of the circle is made to be coincident with the middle of the top
% of the BOOLEAN box. The |namespace| routine is used to specify the circle
% diameter. Note that an argument to a routine can itself be a routine.
%    \begin{macrocode}
z4bm=z3tm;
drawcirclebox(4, namespace(btex ABS etex)(nextra))(btex ABS etex);

%    \end{macrocode}
%
% \Mpost{} is a typed language, and new variables can be declared of a
% particular type. A |numeric| variable holds a number (or a length).
% The diameter of the circle just drawn is going to be used as a length
% in later parts of this diagram, so it is sensible to store its value
% in a new variable called |diam|. We then use it in drawing another
% circle directly on top of the first one.
%    \begin{macrocode}
numeric diam;
diam = namespace(btex ABS etex)(nextra);

z5bm=z4tm;
drawcirclebox(5, diam)(btex SAB etex);

%    \end{macrocode}
%
% The next element in the diagram is an ENTITY box. 
% We use the default height for the entity box and the default page connector
% length as its length (no reason, but it saves inventing another variable 
% or value).
%
%    The ENTITY box is positioned with respect to the SAB circle, but in a
% slightly more complicated way than earlier positions. We want the left hand
% side of the box to align with the right hand side of the circle. Also,
% the middle of the box should align with the top of the circle. 
%
%    The ENTITY box will be located at point |z6|. The easiest way is to
% specify |z6| is |z6ml=(x5mr, y5tm)|, but to demonstrate more of \Mpost's
% equation solving abilities a more complicated approach is taken to the 
% specification of the x coordinate. The horizontal distance between the
% points |z5ml| and |z5tl| on the circle is the same as the distance
% between the points |z5tr| and |z5mr|. We can express this as
% |x5ml-x5tl = x5tr-x5mr|. As we want |x6ml|, which is the same as |x6bl|,
%  to be the same as |x5mr| we
% can substitute into this equation, as done in the code below. Note that
% \Mpost{} can solve for the unknown |x6bl| even though it is on  
% the right hand side
% of the equation because the other three values are known.
%
%     The y coordinate of the point |z6mr| is specified as
% equal to the y coordinate of the top of the circle. Because of the linear
% relations involving all the points on a box, it is sufficient to provide
% one x coordinate and one y coordinate to fix all the points on the box.
%    \begin{macrocode}
x5ml-x5tl = x5tr-x6bl;
y6mr=y5tm;
drawENT(6, pconl, enth)(btex an\_ent etex);

%    \end{macrocode}
%
%    The geometric center of the next box, an LEVENT, is vertically above
% the geometric center of the ENTITY box, and the bottom of LEVENT is slightly
% (one lenth unit) above the top of the ENTITY box. This is accomplished here
% by specifying |z7bm| in terms of expressions involving the coordinates
% of the point |z6tm|.
%    \begin{macrocode}
z7bm=(x6tm,y6tm+u);
drawLEVENT(7, pconl, eventh)(btex levent etex);

%    \end{macrocode}
%
%    At point |z8| a GEVENT box is drawn. It's bottom left hand corner is
% vertically above the top left hand corner of the LEVENT box. If you look
% at the resulting diagram, you will see that GEVENT is shifted right with
% respect to LEVENT. For vertical alignment of EVENT boxes it is best to
% use the middle rather than corner points.
%    \begin{macrocode}
z8=(x7tl, y7tr+u);
drawGEVENT(8, pconl, eventh)(btex gevent etex);

%    \end{macrocode}
%
% \DescribeRoutine{mediation}
%    For the last of the aligned boxes another aspect of \Mpost{} is used.
% \Mpost{} provides a \emph{mediation} facility whose syntax is |frac[a,b]|.
% The result of a mediation is a value that is |frac| between the value |a|
% and the value |b|. For example, the result of |0.25[10,30]| is 15. Similarly,
% the result of |1/3[zj,zk]| is the point one third of the way between point
% |zj| and point |zk|.
%
%    The SCHEMA box is positioned with its bottom right hand corner at one
% eighth of the way along, and at the top of, the BOOLEAN box.
%    \begin{macrocode}
z9br=1/8[z3tl,z3tr];
drawSCHEMA(9, pconl, schemah)(btex a\_schema etex);

%    \end{macrocode}
%
%    The second half of the diagram illustrates various line and end 
% styles. These are all horizontal, the same length and are aligned 
% vertically, so
% define the x coordinate |xmid| of the left hand end of the lines, and
% the length |len| of the lines.
%    \begin{macrocode}
numeric xmid, len;
xmid = x8tr + diam;
len = 2diam;

%    \end{macrocode}
%
% \DescribeRoutine{shifted}
%    The next line of code exhibits another \Mpost{} function. A point can
% be specified as being some other point that is \emph{shifted} by given
% amounts in the x and y directions. More precisely, the shift is specified
% by a pair of values, written as |(a,b)|. The first line is aligned
% vertically with the center of the first box and its start point is |z11|.
% The end point, |z111|, is specified as being the start point shifted 
% horizontally by the length of the line.
%    \begin{macrocode}
z11=(xmid, y1ml); z111=z11 shifted (len, 0);
drawdashO(11, 111);

%    \end{macrocode}
%
%    Because we will be using the same horizontal shift for all the lines,
% define a \emph{pair}, called |moveright|, that is the required shift.
% The next two lines are also aligned vertically with the centers of the
% second and third boxes.
%    \begin{macrocode}
pair moveright;
moveright = (len, 0);

z12=(xmid, y2ml); z121=z12 shifted moveright;
drawnormalO(12, 121);

z13=(xmid, y3ml); z131=z13 shifted moveright;
drawthickO(13, 131);

%    \end{macrocode}
%
%   The remaining lines will have the same vertical spacing as the first three,
% so define another pair, |moveup|, that we can use for vertical shift.
%    \begin{macrocode}
pair moveup;
moveup = (0, y13-y12);

z14=z13 shifted moveup; z141=z14 shifted moveright;
drawnormalD(14, 141);

z15=z14 shifted moveup; z151=z15 shifted moveright;
drawnormalCA(15, 151);

z16=z15 shifted moveup; z161=z16 shifted moveright;
drawnormalOA(16, 161);

z17=z16 shifted moveup; z171=z17 shifted moveright;
drawnormalF(17, 171);

%    \end{macrocode}
%
%    The upper part of the diagram illustrates some of the additional
% line styles and boxes provided that are not part of the
% \ExpressG{} language. 
% \changes{v1.1}{1999/10/30}{Extended upper half of diagram 1 for new box
%  types}
%
%    The upper half is seperated from the bottom half by a dashed line, just
% to make the distinction. The line is set above the highest box so far,
% which is located at |z8|, and extends across the width of the diagram.
%    \begin{macrocode}
z300=(0,y8tm+diam); z301=(x111,y300);
draw z300--z301 dashes;

%    \end{macrocode}
% Define |mup| to be a distance, which we will use for vertical seperation.
%    \begin{macrocode}
numeric mup; mup := onelineh;

%    \end{macrocode}
%
%    As previously, we'll start with the boxes which will be placed in
% a column at the left side of the diagram. The first box, high enough
% for one line of enclosed text, has its top right hand corner folded 
% down by one quarter the box height. Text is placed at the center
% of the box, but if this is not required then it can be given as an
% empty string (i.e., |""|).
%    \begin{macrocode}
z302=(0,y300+mup);
drawcardbox(302, pconl, onelineh, 1/4onelineh)("");

%    \end{macrocode}
%
% The next box is a diamond shape. Unlike the rectangular and rhomboidal
% boxes, these are positioned
% via the center of the box instead of the bottom left hand corner.
%    \begin{macrocode}
z303bm=(x302tm, y302tm+mup);
drawdiamondbox(303, pconl, 2onelineh)(btex jewel etex);

%    \end{macrocode}
%
%   Now there is a double box with the top portion being 3/4 of the box 
% height. Text is put into the top half of the box using \Mpost's
% labeling routine (see \pref{page:label}).
%    \begin{macrocode}
z304=(0, y303tm+mup);
drawdoublerectangle(304, pconl, 2onelineh, 3/4);
label(btex top etex, z304ct);

%    \end{macrocode}
%
%   Next comes a triple box with the bottom portion being one fifth of
% the height, and the top portion being two fifths of the height.
% Text is placed in the top and middle portions, but not into the bottom.
%    \begin{macrocode}
z305=(0, y304tm+mup);
drawtriplerectangle(305, pconl, 3onelineh, 2/5, 0.2);
label(btex top etex, z305ct);
label("middle", z305cm);

%    \end{macrocode}
%
%   Some languages include a box that looks a little like an index card, and
% this is shown next.
% A small box is also drawn inside the main part of the index box, 
% just to illustrate
% that drawings may be placed inside boxes.
%    \begin{macrocode}
z306=(0,y305tm+mup);
drawindexbox(306, 2pconl, 3onelineh, 3/4pconl, onelineh)(btex pack etex);
z307=1/8[z306bl,z306tr];
drawENT(307, 1/4pconl, onelineh)(btex E etex);

%    \end{macrocode}
%
% Another box shown here is a dotted box that covers up anything that
% is underneath it. To demonstrate, a folded corner box is drawn first, 
% and then the
% dashed box is drawn second. They have to be done in this order.
% (The reason for the notation |y306P.tl| is explained under diagram 2
% on \pref{page:dotsuffix}).
%    \begin{macrocode}
z308=(0, y306P.tl+mup);
z309ml=z308c;
drawcardbox(308, pconl, 2onelineh, 1/4onelineh)(btex covered etex);
drawdashboxover(309, pconl, onelineh);

%    \end{macrocode}
%
%    An oval box comes next. The perimeter is an ellipse.
%    \begin{macrocode}
z310bm=(x306bm,y309tm+mup);
drawovalbox(310, 2pconl, 2onelineh)("");

%    \end{macrocode}
%
%    Now we have two rounded boxes. In the first one the corner radius is
% small and the corners are neatly rounded. The radius is large in the
% second case, and it is automatically reduced to give semicircular ends.
% Further, the center portion of the second of these boxes is `deleted'
% by putting a |hiderectangle| over it.
%    \begin{macrocode}
z311ml=(x310mr+mup, y310ml);
drawroundedbox(311, 2pconl, 2onelineh, 1/2onelineh)("rounded");

z312ml=(x311mr+mup, y311mr);
drawroundedbox(312, 2pconl, 2onelineh, 3/2onelineh)(btex large radius etex);

z314=(x312bm-1/4pconl, y312bm-1/2mup);
hiderectangle(314, 1/2pconl, (3/2onelineh + mup));

%    \end{macrocode}
%
%    The last of the simple enclosed shapes are a dashed ellipse and a dashed circle,
% which are aligned below the partially obscured rounded box.
%    \begin{macrocode}
z315tm=(x312bm, y312bm-mup);
drawdashellipse(315, 2pconl, 2onelineh);

z316tm=(x315bm, y315bm-mup);
drawdashcircle(316, diam);

%    \end{macrocode}
%
%    A drum box is now presented. This is centered with respect to the 
% rounded box and aligned with the bottom of the triple box. It is the
% same nominal size as the triple box.
%    \begin{macrocode}
z317bc=(x311bm,y304br);
drawdrum(317, pconl, 3onelineh)(btex drum etex);
%    \end{macrocode}
% To be a little different, I'll add a `handle' to the top of the drum. The
% top of the handle will be above the drum at the point |z317A|, and the
% attachement points are at the |tml| and |tmr| points on the drum. The
% normally sharp join in the middle of the handle is smoothed off.
%    \begin{macrocode}
z317A=(x317tc, y317tc+2onelineh);
drawnormalthree(317tml, 317A, 317tmr);
smooth(317tml, 317A, 317tmr);

%    \end{macrocode}
%
% Below the drum box is a stick figure. It is centered with respect to the
% drum box and based on the bottom row.
% \changes{v1.6}{2004/02/29}{Added stickman to example drawing}
%    \begin{macrocode}
z320bm = (x317bm, y302);
drawstickman(320, onelineh, 2onelineh);

%    \end{macrocode}
%
%   Above the drum box there is an output box, vertically aligned with the
% stick figure, labelled `output'.
% \changes{v1.6}{2004/02/29}{Added output box to example drawing}
%    \begin{macrocode}
z325bm = (x320bm, y306);
drawoutputbox(325, pconl, 2onelineh)(btex output etex);

%    \end{macrocode}
%
%   Above the output box there is a simple circled dot.
% \changes{v1.6}{2004/02/29}{Added circled dot to example drawing}
%    \begin{macrocode}
z330 = (x320bm, y309ml);
drawCircledDot(330, 3/2onelineh);

%    \end{macrocode}
%
%    As in the bottom half, line styles are drawn on the right side of
% of the diagram. First, though, there is an arrowed circle symbol.
% This is vertically aligned with the centers of the lines.
%    \begin{macrocode}
z401bm=(1/2[x11,x111], y301+mup);
drawcircleA(401, diam);

%    \end{macrocode}
%
%    Finish off with assorted linestyles.
%    \begin{macrocode}
z402=(xmid, y401tm+mup); z502=(x111, y402);
drawdashA(402, 502);

z403=(xmid, y402+mup); z503=(x111, y403);
drawdashOA(403, 503);

z404=(xmid, y403+mup); z504=(x111, y404);
drawnormalOD(404, 504);

z405=(xmid, y404+mup); z505=(x111, y405);
drawnormalCD(405, 505);

z406=(xmid, y405+mup); z506=(x111, y406);
drawnormalDCA(406, 506);

%    \end{macrocode}
%
%    Lines can be drawn at any angle, and the non-circular line end styles
% remain aligned.
%    
%    A set of lines and endstyles are drawn rotating about the common
% start point of the lines.
% \DescribeRoutine{rotatedaround}
% |pt1 rotatatedaround(pt2, ang)| is \Mpost{} code that rotates
% the point |pt1| around the point |pt2| counterclockwise through the angle 
% |ang| in degrees.
%
%    \begin{macrocode}
numeric ang; ang = 180/7;
z600=(xmid, y406+2mup);
z699=(x600+len, y600);
z601=z699 rotatedaround(z600, ang);
z602=z699 rotatedaround(z600, 2ang);
z603=z699 rotatedaround(z600, 3ang);
z604=z699 rotatedaround(z600, 4ang);
z605=z699 rotatedaround(z600, 5ang);
z606=z699 rotatedaround(z600, 6ang);
z607=z699 rotatedaround(z600, 7ang);
drawnormalCA(600,601);
drawnormalOA(600,602);
drawnormalF(600,603);
drawdashA(600,604);
drawnormalOD(600,605);
drawnormalCD(600,606);

%    \end{macrocode}
%
%    This is the end of the first diagram.
%    \begin{macrocode}
endfig;   % end figure 1

%    \end{macrocode}
%
% \subsection{Diagrams 2--5: EXPRESS-G like models}
%
%    The diagrams in this section are all drawn using the \ExpressG{}
% specific routines. Nevertheless, they do illustrate general BLA techniques.
%
% \subsubsection{Diagram 2: Schema level diagram}
%
%    In contrast to the first diagram, this one is much more like an 
% \ExpressG{} diagram. It illustrates a diagram consisting of SCHEMA
% boxes and interconnections.
%
%    \begin{macrocode}
beginfig(2)                       % schema level model

%    \end{macrocode}
%
%    First define some lengths to assist in laying out the diagram, which is
% going to consists of three rows of boxes with varying numbers of boxes
% in each row; the bottom row has two, the middle has four, and the top row
% has one. We also want to align the boxes vertically in a `nice' manner.
%
%    \begin{macrocode}
numeric lb, hb;                 % length & height of boxes
lb=20u; hb=schemah;
numeric upshift;                % vertical distance between rows
upshift = 20u;
numeric sideshift;              % horizontal distance between boxes
sideshift = 10u;

%    \end{macrocode}
%
%    The bottom row has two boxes and the second four. The two bottom boxes
% will be aligned vertically under the two middle boxes in the middle row.
% Allowance must be made for a `missing' box at the start of the bottom
% row. The second box on the bottom row is spaced from the first one. 
%    \begin{macrocode}
%%% bottom row

z9=(lb+sideshift,0); 
drawSCHEMA(9, lb, hb)("nine"); 

z11=(x9br+sideshift,y9); 
drawSCHEMA(11, lb, hb)("eleven"); 

%    \end{macrocode}
%
%    The bottom of the boxes on the second row are all at a fixed distance
% above the top of the boxes on the first row. We only need to specify the
% y coordinate of the bottom of one box in the row, and use that for the 
% remainder,
%    \begin{macrocode}
%%% middle row

z1=(0,y9tl+upshift); 
drawSCHEMA(1, lb, hb)("one"); 

z3=(x1br+sideshift, y1); 
drawSCHEMA(3, lb, hb)("three"); 

z5=(x3br+sideshift, y1); 
drawSCHEMA(5, lb, hb)("five");  

z7=(x5br+sideshift, y1); 
drawSCHEMA(7, lb, hb)("seven"); 

%    \end{macrocode}
%
%    The single box on the top row will be position centrally above the
% two middle boxes of the middle row. Mediation is used to calculate
% the x coordinate that is halfway between the right side of the left
% box and the left side of the right box.
%    \begin{macrocode}
%%% top row

x50 = 1/2[x3br,x5bl];
z31bm=(x50,y1tl+upshift); 
drawSCHEMA(31, lb, hb)("thirtyone"); 

%    \end{macrocode}
%
%    This completes the boxes. The diagram is finished off by drawing 
% connections between the boxes. The first set of connections are just
% straight lines between known points on boxes.
%    \begin{macrocode}
%%% connectors

drawdashOO(9tm, 3bm);   % three/nine 
drawdashO(5bm, 11tm);   % five/eleven 
drawdashO(3ml, 1mr);    % three/one 
drawdashO(3mr, 5ml);    % three/five 
drawdashOO(9mr, 11ml);  % nine/eleven

%    \end{macrocode}
%
%    The next connection is more complex. It goes from schema thirtyone 
% to schema nine on a three-legged route. It goes horizontally left from
% thirtynine, then vertically down, and finally horizontally right to nine. It
% also passes to the left of schema one. 
%
%    The route is constructed by specifying a point |z90| to the left of
% schema nine, and the point |z31A| on the left hand of schema thirtynine.
% The |VH| routine is then called to generate the corner point on the 
% (rotated) L shaped path between |z90| and |z31A|. The connection is then
% drawn using these four points.
%    \begin{macrocode}
%%% thirtyone/nine 
z90=((x1bl-sideshift), y9ml);
z31A=3/4[z31bl,z31tl];
VH(90, 31A);
drawdashO(90vh, 31A);
drawdashthreeO(90vh, 90, 9ml);
%    \end{macrocode}
%
% \DescribeRoutine{pickup}
%    To demonstrate another aspect of \Mpost, a dot is drawn at the location
% of |z90|. If the drawing pen is thick enough, just drawing one point is
% sufficient to make a noticeable dot. The code |pickup thickpen;| drops
% the current pen and picks up 
% the thickpen for drawing. The code |pickup normalpen;| picks up the
% normal pen, which is the one that is normally used.
%
% \DescribeRoutine{label}
% \DescribeRoutine{dotlabel}
%    The last line of code here is |label.lft("z90", z90);| which puts the
% text `z90' at the left of point |z90|.\label{page:label} 
% The label routine has two arguments,
% the first the text and the second the point at or near which the text is
% to be placed. The simplest form of the routine is |label("text", zk)| which
% centers the text over the point |zk|. A
% suffix can be used after the |label| (e.g., |.lft| in the code below) to
% modify the placement. |.lft| positions the text at the left of the point.
% The other modifiers are: |.rt|, |.top|, |.bot|, |.ulft|, |.urt|, |.llft| and
% |.lrt|. There is also a |dotlabel.suffix("text", zk)| routine which draws
% the point as well. For complicated diagrams it can be useful to label 
% some points during development, and then comment them out for the final 
% picture.
%    \begin{macrocode}
pickup thickpen;
draw z90;
pickup normalpen;
label.lft("z90", z90);

%    \end{macrocode}
%
%    The next two connectors, between schemas one and eleven and between
% thirtyone and eleven are of a similar U shape. There is, though, one tricky
% point to remember. Up till now, all point arguments to the \Lpack{expressg} 
% routines have been of the form |3| or |4bm|; 
% that is, either a number or a number
% followed by letter(s). For example, |VH(3,4bm)| will calculate
% the point |z3vh|. However, if a routine adds more letters to an argument
% that already has letters, such as |VH(4bm,3)|, the calculated point is 
% \emph{not} |z4bmvh| as might be expected, but instead 
% is |z4bm.vh|.\label{page:dotsuffix}
% This has tripped me up on several occasions.
%    \begin{macrocode}
%%% one/eleven 
z1A=1/3[z1bl,z1br];
z11A=(x11bm, (y11bm-sideshift));
VH(1A, 11A);
drawdashthree(1A, 1A.vh, 11A);   % note it is 1A.vh and not 1Avh
drawdashO(11A, 11bm);
dotlabel.rt("z11A", z11A);
dotlabel.lft("z1A.vh", z1A.vh);   % note it is z1A.vh and not z1Avh

%    \end{macrocode}
%
%    The connector between thirtyone and eleven is the same general shape
% as the thirtyone to nine connector. This time, I'll use the |HxH| routine
% to calculate the turning points
%    \begin{macrocode}
%%% thirtyone/eleven 
z31B=3/4[z31br,z31tr];
x31BC=x7br+sideshift;
HxH(31B, 31BC, 11mr);
drawdashfourO(31B, 31B.hxh, 11mr.hxh, 11mr);

%    \end{macrocode}
%
%    The next two connectors, between thirtyone and seven, and between 
% thirtyone and one, are simple L shapes, which are easier to produce than the
% U shaped ones.
%    \begin{macrocode}
%%% thirtyone/seven 
z31D=1/4[z31br,z31tr];
VH(7tm, 31D);
drawnormalthreeO(31D, 7tm.vh, 7tm);

%%% thirtyone/one 
z31C=1/4[z31bl,z31tl];
VH(1tm, 31C);
drawdashO(1tm.vh, 31C);
drawdashO(1tm.vh, 1tm);

%    \end{macrocode}
%
% The last two connectors are also simple, each consisting of vertical then 
% horizontal then vertical lines and the turning points can be calculated 
% by the |VhV| routine..
%    \begin{macrocode}
%%% thirtyone/three 
z31E=1/4[z31bl,z31br];
VhV(31E, 3tm);
drawnormalfourO(31E, 31E.vhv, 3tm.vhv, 3tm);

%%% thirtyone/five 
z31F=3/4[z31bl,z31br];
VhV(31F, 5tm);
drawnormalfourO(31F, 31F.vhv, 5tm.vhv, 5tm);

%    \end{macrocode}
%
%    The last element in the diagram is a vertical closed arrowheaded line
% with a label alongside. The arrowhead is on the top line of the connector
% between thirtyone and eleven. Note the point mediation expression expression
% in the |label| routine call.
%    \begin{macrocode}
%%% labeled arrow
z3111=1/4[z31B,z31B.hxh];
numeric arrowsize;
arrowsize := schemah;
z3112=(x3111, y3111+arrowsize);
drawnormalCA(3112, 3111);
label.rt(btex an\_import etex, 1/2[z3111, z3112]);

%    \end{macrocode}
%
%    The end of this diagram.
%    \begin{macrocode}
endfig;  % end fig 2

%    \end{macrocode}
%
%
% \subsubsection{Diagram 3: Tree structure}
%
%    This diagram is the first of three that are related in style. It is
% useful at this point to define some variables, and values for some of
% these as they will probably be used in all three diagrams.
%
%    Values are assigned (e.g., |var := val;|) so that they can be changed
% later if necessary (e.g., |var := newval;|). If values were equated like
% |var = val;| then they cannot be changed afterwards\footnote{Except
% by assignment.} as |var = newval;|
% will then have specified two incompatible equations for |var| and \Mpost will
% report a problem.
%    \begin{macrocode}

%%%% some commonly used variables & values

numeric pl, ph;           % length & height of numeric page connectors
pl:=pconl; ph:=pconh;     % for eg., 9,9 (9,9)
numeric plnamed;          % length of named page connector
numeric irh;              % height of interschema boxes
irh:=ish;                 % normally one line of text
numeric sdtl, sdth;       % length & height of SDT (e.g. INTEGER) boxes
sdtl:=sdtbl; sdth:=sdtbh;
numeric edtl, edth;       % length & height of enum boxes (inset is sdtbs)
edth:=sdtbh;              % normally one text line
numeric el, eh;           % length & height of entity boxes
eh:=enth;                 % normally one text line
numeric upshift;          % vertical space between rows of boxes
numeric nextup;           % vertical space between bases of rows of boxes
%    \end{macrocode}
%
%    Now another bit of \Mpost. There is another type of variable called
% a |picture| variable. This can hold something as trivial as a dot or
% a text string, up to a complete diagram. References to an Index
% type is a common element in some of the diagrams. It is useful to
% create a shorthand for these by using picture variables.
%    \begin{macrocode}
picture sindex, pindex;
sindex := btex eleven.Index etex;      % interschema reference text
pindex := btex 9,9 Index etex;         % page reference text
numeric slindex, plindex;
slindex := namespace(sindex)(nextra);  % length of Index interschema 
plindex := namespace(pindex)(nextra);  % length of Index page reference
%    \end{macrocode}
%
%    Yet more new \Mpost. Array variables are supported. These are declared
% by giving the variable name immediately followed by a pair of square 
% brackets. An element of an array can be simply accessed by suffixing the
% variable name with the integer number denoting the desired position.
% Actually we have been using array variables all along, as |z3| or |x7|
% are elements of the arrays |z[]| and |x[]| respectively. We define
% two arrays, one to be used for specifying horizontal spaces (lengths)
% and the other for vertical (y) coordinates. 
%    \begin{macrocode}
numeric hspace[];         % horizontal spaces
numeric lyc[];            % Y coords of box bases

%%%%%%%%%%% end commonly used variables & values

%    \end{macrocode}
%
% Diagram 3 consists of type boxes. We will make these all the same length
% and height.
%    \begin{macrocode}
beginfig(3)                      % example fig 3 
%%%drawgrid;

%    \end{macrocode}
%
%    The space required for the longest name is |edtl|.
%    \begin{macrocode}
edtl := namespace(btex standard\_data\_name etex)(niextra);
%    \end{macrocode}
%
%    There are several rows in the diagram. Specify the vertical space
% between the rows, and the space between the bottoms of the boxes (the
% height of a box is the normal height, |sdth|,  for a type box). Also
% specify the y coordinates for each row, counting from the bottom.
%    \begin{macrocode}
upshift=2sdth;
nextup=sdth+upshift;
%%%        the y coords of box bases
lyc1:=0;
lyc2:=lyc1+nextup;
lyc3:=lyc2+nextup;
lyc4:=lyc3+nextup;
lyc5:=lyc4+nextup;
lyc6:=lyc5+nextup;
lyc7:=lyc6+nextup;
lyc8:=lyc7+nextup;
%    \end{macrocode}
% Specify two horizontal spaces.
%    \begin{macrocode}
hspace1 := 1/3edtl;  % space between data enums
hspace2 := 2/3edtl;  % initial space at start of second row

%    \end{macrocode}
%    Draw the 3 boxes in the first row and the 3 in the second; these are
% staggered with respect to each other and overlap as otherwise there
% there is not enough space to get them all onto one page. 
% I'll use a numbering scheme for
% points so that |zCR| is a point in the Cth column and the Rth row.
%    \begin{macrocode}
%%% bottom two rows (1 & 2)

z11=(0,lyc1);
drawENUM(11, edtl, edth)(btex coordinates etex);

z22=(hspace2, lyc2);
drawENUM(22, edtl, edth)(btex solution\_data etex);

z31=(x11br+hspace1, lyc1);
drawENUM(31, edtl, edth)(btex pressure\_loads etex);

z42=(x22br+hspace1, lyc2);
drawENUM(42, edtl, edth)(btex nondimensional etex);

z51=(x31br+hspace1, lyc1);
drawENUM(51, edtl, edth)(btex temperature etex);

z62=(x42br+hspace1, lyc2);
drawENUM(62, edtl, edth)(btex force\_loads etex);

%    \end{macrocode}
%
% The third `row' consists of a horizontal line stretching from the middle
% of the leftmost box to the middle of the rightmost box. There are 
% connections from this line to the top middle of each of the boxes. We can
% use the |VyV| routine for the end points of the line.
%    \begin{macrocode}
%%% third row (horizontal line between 2 & 4 row)

z13=(x11tm,lyc3); 
VyV(11tm, 13, 62tm);
drawnormal(11tm.vyv, 62tm.vyv);
%    \end{macrocode}
%
%    Calculate the points on this line vertically above the midpoints of
% the boxes and draw the connections.
%    \begin{macrocode}
z23=(x22tm,lyc3); z33=(x31tm,lyc3); z43=(x42tm,lyc3); z53=(x51tm,lyc3);
drawnormalO(11tm.vyv,11tm);
drawnormalO(23,22tm);
drawnormalO(33,31tm);
drawnormalO(43,42tm);
drawnormalO(53,51tm);
drawnormalO(62tm.vyv,62tm);

%    \end{macrocode}
%
%    The fourth row consists of three boxes. There is a vertical line 
% from the bottom
% of the leftmost box to the horizontal line drawn in row 4. The three
% boxes are aligned horizontally with respect to this line.
%    \begin{macrocode}
%%% fourth row 

z3224=1/3[z13,z62tm.vyv];
z3554=2/3[z13,z62tm.vyv];

%%% standard_data_name
z24bm=(x3224,lyc4);
drawSELECT(24, edtl, edth)(btex standard\_data\_name etex);
drawnormal(24bm,3224);

%%% adhoc_data_name
z54bm=(x3554,lyc4);
drawTYPE(54, edtl, edth)(btex adhoc\_data\_name etex);

%%% STRING
z64br=(x62br,lyc4);
drawSTRING(64);

%    \end{macrocode}
%
%    The fifth `row' consists of two vertical connectors to the tops of
% the SELECT and TYPE boxes, with a horizontal line connecting the tops
% of the connectors.
%    \begin{macrocode}
%%% fifth row

z35=(1/2[x24tm,x54tm], lyc5);
VyV(24tm, 35, 54tm);
drawnormalthreeO(35, 24tm.vyv, 24tm);
drawnormalthreeO(35, 54tm.vyv, 54tm);

%    \end{macrocode}
%
%    The top row consists of a SELECT box vertically aligned above the center
% of the horizontal line from the 5th row, together with a line joining
% these two, and also a page reference box
% off towards the right hand side
%    \begin{macrocode}
%%% sixth row

z36bm=(x35,lyc6);
drawSELECT(36,edtl, edth)(btex data\_name etex);
drawnormal(36bm,35);

%%% data_name
z66=(x62,lyc6);
drawPREF(66, sdtl, ph)(btex 3,1 (4) etex);

%    \end{macrocode}
%
%    The remaining elements on the diagram are: 
% a connector on the 4th row from adhoc\_data\_name to STRING;
% and a connector on the 6th row from the page reference to data\_name.
%    \begin{macrocode}
%%%% rest of the connectors 

%%% adhoc/STRING (54, 64)
drawnormalO(54mr,64ml);

%%% PREF/data_name (36, 66)
drawdashO(66ml,36mr);

%    \end{macrocode}
%
%    The end of this diagram
%    \begin{macrocode}
endfig;                         % end fig 3

%    \end{macrocode}
%
% \subsubsection{Diagram 4: Supertypes and subtypes}
%
%    This diagram consists of a supertype entity and its four subtypes. The
% entities have various attributes.
%
%    \begin{macrocode}

beginfig(4)                     % example 4 
%%%drawgrid;

%    \end{macrocode}
%
%    Define some useful lengths.
%    \begin{macrocode}
%%% length of named page reference boxes
plnamed := namespace(btex 9,9 data\_name etex)(nextra);

%%% length of entity boxes
el := namespace(btex (ABS) Data\_t etex)(nextra);

upshift := 2sdth;         % vertical space between boxes
nextup := sdth+upshift;   % vertical space between bases of boxes
hspace1 := 1/2el;         % space between entity boxes

%%% the y coords of box bases
lyc1:=0;
lyc2:=lyc1+nextup;
lyc3:=lyc2+nextup;
lyc4:=lyc3+nextup;
lyc5:=lyc4+nextup;
lyc6:=lyc5+nextup;
lyc7:=lyc6+nextup;
lyc8:=lyc7+nextup;

%    \end{macrocode}
%
%    We'll start with the second row which consists of 4 entity (subtype)
% boxes. The numbering scheme for point suffixes is |zCR|, where |C|
% is the column number and |R| is the row number.
%    \begin{macrocode}
%%%% 2nd row

%%% IntArray
z12=(0,lyc2);
drawENT(12, el, eh)(btex IntArray etex);

%%% RealArray
z22=(x12br+hspace1, lyc2);
drawENT(22, el, eh)(btex RealArray etex);

%%% CharArray
z42=(x22br+hspace1, lyc2);
drawENT(42, el, eh)(btex CharArray etex);

%%% BitArray
z52=(x42br+hspace1, lyc2);
drawENT(52, el, eh)(btex BitArray etex);

%    \end{macrocode}
%
%    The first row is four simple data type boxes, aligned underneath the
% entity boxes.
%    \begin{macrocode}
%%%% 1st row

z11bm=(x12bm,lyc1);
drawINTEGER(11);

z21bm=(x22bm,lyc1);
drawREAL(21);

z41bm=(x42bm,lyc1);
drawSTRING(41);

z51bm=(x52bm,lyc1);
drawBINARY(51);

%    \end{macrocode}
%
%    The third `row' is the thick lines connecting the subtype boxes.
%    \begin{macrocode}
%%% 3rd row

y13=       y23=       y43=       y53=lyc3;
x13=x12tm; x23=x22tm; x43=x42tm; x53=x52tm;
drawthick(13,53);      % horizontal line
%%% vertical connectors
drawthickO(13,12tm); drawthickO(23,22tm); 
drawthickO(43, 42tm); drawthickO(53, 52tm);

z33=1/2[z13,z53];   % midpoint of horizontal line

%    \end{macrocode}
%
%    The 4th row is an abstract supertype entity box, which is made 3 times
% taller than the default entity box height. The entity box is centered 
% with respect to the row of subtype boxes and is connected to the
% subtype boxes connector. The digit 1 is placed near the connection point.
%  There is also a page reference
% and an INTEGER box at the left and right (as attributes of the supertype).
%    \begin{macrocode}
%%% 4th row

%%% Data_t
z34bm=(x33,lyc4);
drawENT(34, el, 3eh)(btex \twolines{(ABS)}{Data\_t} etex);
drawthick(34bm,33);
label.urt("1", z33);   % label the connection point

%%% Index
z14=(0,lyc4);
drawPREF(14, plindex, ph)(pindex);

%%% INTEGER
z54br=(x51br,lyc4);
drawINTEGER(54);

%    \end{macrocode}
%
%    The 5th row has page reference boxes at the left and right 
% (as attributes of the supertype).
%    \begin{macrocode}
%%% 5th row

lyc5:=y34tm-ph;   % change the initial y coord value

%%% Index
z15=(0,lyc5);
drawPREF(15, plindex, ph)(pindex);

%%% DataType
z55=(x54,lyc5);
drawPREF(55, plnamed, ph)(btex 3,1 data\_name etex);

%    \end{macrocode}
%
%    The 6th, and last, row, just consists of a page reference centered
% above the supertype box.
%    \begin{macrocode}
%%% 6th row

%%% PREF to Data_t
lyc6:=lyc5+nextup;
z36bm=(x34tm,lyc6);
drawPREF(36, pl, ph)(btex 7,5 (6) etex);

%    \end{macrocode}
%
%    The rest of the diagram consists of the labelled attribute lines.
%    \begin{macrocode}
%%%% attributes

%%% Sizes  Data_t/Index (34, 14)
z3414=(x34,y14mr);
drawnormal(3414,14mr);
label.ulft(btex Sizes A[1:Limit] etex, z3414);

%%% num  Data_t/INTEGER (34, 54)
z3454=(x34mr,y54ml);
drawnormalO(3454,54ml);
label.urt(btex (DER) num etex, z3454);

%%% Limit Data_t/Index (34, 15)
z3415=(x34,y15mr);
drawnormal(3415,15mr);
label.ulft(btex Limit etex, z3415);

%%% Kind Data_t/data_name (34, 55)
z3455=(x34mr, y55ml);
drawnormal(3455, 55ml);
label.urt(btex Kind etex, z3455);

%%% PREF into Data_t (36, 34)
drawdashO(36bm, 34tm);

%%% Data IntArray/INTEGER (12, 11)
drawnormalO(12bm, 11tm);
label.lrt(btex Data A[1:num] etex, z12bm);

%%% Data RealArray/REAL (22, 21)
drawnormalO(22bm, 21tm);
label.lrt(btex Data A[1:num] etex, z22bm);

%%% Data CharArray/STRING (42, 41)
drawnormalO(42bm, 41tm);
label.lrt(btex Data A[1:num] etex, z42bm);

%%% Data BitArray/BINARY (52, 51)
drawnormalO(52bm, 51tm);
label.lrt(btex Data A[1:num] etex, z52bm);

%    \end{macrocode}
%
%     The end of this diagram.
%    \begin{macrocode}
endfig;                              % end fig 4

%    \end{macrocode}
%
%    \subsubsection{Diagram 5: Portion of larger model}
%
%    This diagram is more complex than the previous ones. It is, nevertheless,
% presented with virtually no commentary. It consists of three entity boxes
% and various page reference and interschema boxes to support the
% entities' attributes.
%
%    \begin{macrocode}
beginfig(5)                 % example 5 
%%drawgrid;

%    \end{macrocode}
%
%    As usual, specify commonly used variables and values.
%    \begin{macrocode}
plnamed := namespace(btex 7,4 Unstructured\_Donor etex)(nextra);

numeric irls, irll;             % length of short and long ISR boxes
irls = namespace(btex eleven.MeshLocation etex)(nextra);
irll = namespace(btex eleven.MeshConnectivityType etex)(nextra);

upshift := irh;
nextup := irh+upshift;

numeric maxrx;         % max x coordinate value of LH of right column boxes
maxrx := maxx-irrl; 
numeric xmid;          % x coord of figure center
xmid := 1/2[irls, maxx-irll];

el := namespace(btex MeshConnectivity1\_1 etex)(nextra);
eh := irh;

%%% y coords
lyc1 := 0;
lyc2 := lyc1+nextup;
lyc3 := lyc2+nextup;
lyc4 := lyc3+nextup+irh;
lyc5 := lyc4+nextup;
lyc6 := lyc5+nextup;
lyc7 := lyc6+nextup;
lyc8 := lyc7+nextup;
lyc9 := lyc8+nextup;

%    \end{macrocode}
%
%    Rows one and two have one centered box each.
%    \begin{macrocode}
%%% Zcol/row
%%% row 1

%%% PREF for Overlapping
z21bm=(xmid,lyc1);
drawPREF(21, pl, ph)(btex 5,3 (8) etex)

%%% row 2

%%% OverlappingArea
z22bm=(x21bm,lyc2);
drawENT(22, el, eh)(btex OverlappingArea etex);

%    \end{macrocode}
%
%    Row three has three boxes, and the middle one is centered.
%    \begin{macrocode}
%%% row 3

%%% IndexArray
z13=(pl,lyc3);
drawISR(13, irls, irh)(btex eleven.IndexArray etex);

%%% Index
z23bm=(x22bm,lyc3);
drawISR(23, slindex, irh)(sindex);

%%% MeshLocation
z33br=(maxx,lyc3);
drawISR(33, irls, irh)(btex eleven.MeshLocation etex);

%    \end{macrocode}
%
%    Row four has three boxes, and the middle one is centered.
%    \begin{macrocode}
%%% row 4

%%% MeshConnectivity
z24bm=(x23bm,lyc4);
drawENT(24, el, eh)(btex MeshConnectivity etex);

%%% PREF for MeshConnectivity
z14ml=(pl,y24ml);
drawPREF(14, pl, ph)(btex 5,2 (8) etex);

%%% Structured_Donor
z34br=(maxx,lyc4);
drawPREF(34, plnamed, ph)(btex 7,5 Structured\_Donor etex);

%    \end{macrocode}
%
%    Rows five and six have one box each, at the right hand side.
%    \begin{macrocode}
%%% row 5

%%% Unstructured_donor
z35br=(maxx,lyc5);
drawPREF(35, plnamed, ph)(btex 7,4 Unstructured\_Donor etex);

%%% row 6

%%% MeshConnType
z36br=(maxx,lyc6);
drawISR(36, irll, irh)(btex eleven.MeshConnectivityType etex);

%    \end{macrocode}
%
%    Row seven has three boxes, and the middle one is centered.
%    \begin{macrocode}
%%% row 7

%%% IndexRange
z17=(0,lyc7);
drawISR(17, irls, irh)(btex eleven.IndexRange etex);

%%% INTEGER
x27bm=x24bm; y27ml=y17mr;
drawINTEGER(27);

%%% Zone
z37br=(maxx,lyc7);
drawISR(37, irls, irh)(btex seven.Zone etex);

%    \end{macrocode}
%
%    Rows eight and nine have one centered box each.
%    \begin{macrocode}
%%% row 8

%%% 1to1
z28bm=(x24bm,lyc8);
drawENT(28, el, eh)(btex MeshConnectivity1\_1 etex);

%%% row 9

%%% PREF to 1to1
z29bm=(x28bm,lyc9);
drawPREF(29, pl, ph)(btex 5,1 (8) etex);

%    \end{macrocode}
%
%    All the boxes have been drawn. The remainder is adding and labelling
% attribute lines. First page references to subtype entities.
%    \begin{macrocode}
%%%% attributes, etc

drawthickO(21tm,22bm);   % PREF to Overlap (21, 22)
drawthickO(14mr,24ml);   % PREF to MeshConn (14, 24)
drawthickO(29bm,28tm);   % PREF to 1to1 (29, 28)

%    \end{macrocode}
%
%    The attributes of entity OverlappingArea (|z22|)
%    \begin{macrocode}
%%% PointListSize (22, 23)
drawdashO(22tm,23bm);
label.llft(btex PointListSize etex, z23bm);

%%% PointRange (22, 17)
z22A=1/4[z22bl,z22tl]; z17A=(1/2[0,x13], y17);
VH(17A,22A);
drawdashthreeO(22A, 17A.vh, 17A);
label.ulft(btex PointRange etex, z22A);

%%% PointList (22, 13)
z22B=3/4[z22bl,z22tl];
VH(13bm,22B);
drawdashthreeO(22B, 13bm.vh, 13bm);
label.ulft(btex PointList etex, z22B);

%%% MeshLocation (22, 33)
z22C=1/4[z22br,z22tr];
z33B=2/3[z33bl,z33br];
VH(33B,22C);
drawnormalthreeO(22C, 33B.vh, 33B);
label.urt(btex (DER) Location etex, z22C);

%%% Meshloc (22, 33)
z22D=3/4[z22br,z22tr];
z33A=1/3[z33bl,z33br];
VH(33A,22D);
drawdashthreeO(22D, 33A.vh, 33A);
label.urt(btex Meshloc etex, z22D);

%    \end{macrocode}
%
%    The attributes of entity MeshConnectivity (|z24|).
%    \begin{macrocode}
%%% PointListSize (24, 23)
drawnormalO(24bm, 23tm);
label.ulft(btex PointListSize etex, z23tm);

%%% StructuredDonor (24, 34)
z24A=(x24br,y34ml);
draw z24A--z34ml dashes;
label.lrt(btex StructuredDonor etex, z24A);

%%% UnstructuredDonor (24, 35)
z24B=3/4[z24br,z24tr];
HvH(24B,35ml);
drawdashfourO(24B, 24B.hvh, 35ml.hvh, 35ml);
label.urt(btex UnstructuredDonor etex, z24B.hvh);

%%% Meshloc (24, 33)
z24C=4/6[z24bl,z24br];
z33C=(x33A,y33tm);
y2433C=1/3[y33C,y24C];
VyV(24C, 2433C, 33C);
drawdashfourO(24C, 24C.vyv, 33C.vyv, 33C);
label.lrt(btex Meshloc etex, z24C.vyv);

%%% Location (24, 33)
z24D=5/6[z24bl,z24br];
z33D=(x33B,y33tm);
y2433D=2/3[y33D,y24D];
VyV(24D, 2433D, 33D);
drawnormalfourO(24D, 24D.vyv, 33D.vyv, 33D);
label.lrt(btex (DER) Location etex, z24D.vyv);

%%% ConnectivityType (24, 36)
z24H=(x24D,y24tr); 
z36H=z36bm;
y2436H=1/2[y35tr,y36br];
VyV(24H, 2436H, 36H);
drawnormalfourO(24H, 24H.vyv, 36H.vyv, 36H);
label.urt(btex (DER) ConnectivityType etex, z24H.vyv);

%%% Meshcon (24, 36)
z24G=(x24C,y24tr);
z36G=z36ml;
VH(24G,36G);
drawdashthreeO(24G, 24G.vh, 36G);
label.urt(btex Meshcon etex, z24G.vh);

%%% K (24, 27)
drawnormalO(24tm, 27bm);
label.ulft(btex K etex, z24tm);

%%% PointRange (24, 17)
z24E=1/4[z24tl,z24tr];
x17br-x17E = x17A-x17bl;
y17E = y17A;
VhV(24E,17E);
drawdashfourO(24E, 24E.vhv, 17E.vhv, 17E);
label.ulft(btex PointRange etex, z24E);

%%% PointList (24, 13)
z24F=1/4[z24bl,z24br];
z13F=1/2[z13tl,z13tr];
VhV(24F,13F);
drawnormalfourO(24F, 24F.vhv, 13F.vhv, 13F);
label.llft(btex PointList etex, z24F);
 
%    \end{macrocode}
%
%    The attributes of entity MeshConnectivity1\_1 (|z28|)
%    \begin{macrocode}
%%% N (28, 27)
z27A=1/5[z27tl,z27tr];
z28A=(x27A,y28bl);
drawnormalO(28A,27A);
label.llft(btex N etex, z28A);

%%% trans (28, 27)
z27B=1/2[z27tl,z27tr];
z28B=(x27B,y28bl);
drawdashO(28B,27B);
label.lrt(btex \twolines{trans}{A[1:N]} etex, z28B);

%%% Transform (28, 27)
z27C=1/2[z27br,z27tr];
z28C=(1/2[x27C,x28br], y28br);
VH(28C,27C);
drawnormalthreeO(28C,28C.vh,27C);
label.lrt(btex (DER) Transform A[1:N] etex , z28C);

%%% DonorZone (28, 37)
z28D=1/2[z28br,z28tr];
z37D=z37tm;
VH(37D,28D);
drawdashthreeO(28D,37D.vh,37D);
label.urt(btex DonorZone etex, z28D);

%%% DonorPointRange (28, 17)
z28G=3/4[z28bl,z28tl];
z17G=(x17A,y17tl);
VH(17G,28G);
drawnormalthreeO(28G,17G.vh,17G);
label.ulft(btex DonorPointRange etex, z28G);

%%% PointRange (28, 17)
z28H=1/4[z28bl,z28tl];
z17H=(x17E,y17G);
VH(17H,28H);
drawnormalthreeO(28H,17H.vh,17H);
label.ulft(btex PointRange etex, z28H);

%    \end{macrocode}
%
%    The end of this diagram.
%    \begin{macrocode}
endfig;                             % end fig 5

%    \end{macrocode}
%
% \subsection{Diagrams 6--11: Car model}
%
%    The diagrams in this section are all taken from~\cite[Chapter~2]{EBOOK}.
% A simple information/data model of a car, car model, and car manufacturer
% is presented in a variety of BLA languages, among which is, 
% of course, \ExpressG. In words, the model is:
% \begin{quote} \itshape
%     A car is made by a manufacturer. Each manufacturer has a unique name.
% A manufacturer constructs cars in several models and a car is of a
% particular model. A manufacturer gives a serial number to each car 
% he produces and this is unique across all cars produced by that
% manufacturer. Each model also has a name, and this is unique across
% all models. A car has a year of production.
% \end{quote}
% This model is a small portion of a conceptual model developed as a common
% specification for comparing modeling languages~\cite{TR9007}.
%
% The purpose of these diagrams is to 
% illustrate how the \Lpack{expressg} package supports a range of graphical
% languages.
%
%
% \subsubsection{Diagram 6: \ExpressG}
%
%    Having already seen several examples of \ExpressG{} diagrams, this one
% is presented with no further comments.
%    \begin{macrocode}

beginfig(6)            % example 6  EXPRESS-G
%%%drawgrid;

upshift := 3/2onelineh;
nextup := onelineh+upshift;

el := namespace(btex manufacturer etex)(nextra);
eh := onelineh;

hspace1 := 1/2el;

%%% y coords
lyc1 := 0;
lyc2 := lyc1+nextup;
lyc3 := lyc2+nextup;
lyc4 := lyc3+nextup;
lyc5 := lyc4+nextup;

%%% Zcol/row

%%% rows 4 and 5
z14=(0,lyc4);
drawENT(14, el, eh)(btex manufacturer etex);

z25=(x14br+hspace1, lyc5);
drawSTRING(25);

z34=(x25br+hspace1, lyc4);
drawENT(34, el, eh)(btex car\_model etex);

%%% row 3

z33bm=(x34bm, lyc3);
drawENT(33, el, eh)(btex car etex);

%%% row 2

z22=(x25, lyc2);
drawINTEGER(22);

%%% row 1

z21=(x22, lyc1);
drawSTRING(21);

%%% attributes

%%% manufacturer name (14, 25)
VH(14tm, 25ml);
drawnormalthreeO(14tm, 14tm.vh, 25ml);
label.urt(btex *name etex, z14tm.vh);

%%% model name (34, 25)
VH(34tm, 25mr);
drawnormalthreeO(34tm, 34tm.vh, 25mr);
label.ulft(btex *name etex, z34tm.vh);

%%% made_by (34, 14)
drawnormalO(34ml, 14mr);
label.ulft(btex made\_by etex, z34ml);

%%% model_type (33, 34)
drawnormalO(33tm, 34bm);
label.urt(btex model\_type etex, z33tm);

%%% DER made_by (33, 14)
VH(14bm, 33ml);
drawnormalthreeO(33ml, 14bm.vh, 14bm);
label.ulft(btex (DER) *made\_by etex, z33ml);

%%% year (33, 22)
z33A=1/3[z33bl, z33br];
VH(33A, 22mr);
drawnormalthreeO(33A, 33A.vh, 22mr);
label.ulft(btex year etex, z33A.vh);

%%% serial_no
z33B=2/3[z33bl, z33br];
VH(33B, 21mr);
drawnormalthreeO(33B, 33B.vh, 21mr);
label.ulft(btex *serial\_no etex, z33B.vh);

%    \end{macrocode}
%
% The end of this diagram
%    \begin{macrocode}
endfig;               % end fig 6

%    \end{macrocode}
%
%
% \subsubsection{Diagram 7: Shlaer-Mellor}
%
%    The Shlaer-Mellor graphical language~\cite{SHLAER88} is fairly simple,
% consisting basically of rectangles and arrowheaded lines. However, unlike
% \ExpressG{} each box usually has several lines of text. These are placed
% individually at the desired positions within each box.
%
%    Notice below that
% I have used |drawENT| with an empty string to draw the rectangular boxes;
% the routines for \ExpressG{} diagrams can, if suitable, be used in any
% sort of diagram.
%
%    \begin{macrocode}

beginfig(7)            % example 7
%%%drawgrid;

el := namespace(btex MANUFACTURER etex)(niextra);
eh := onelineh;

hspace1 := namespace(btex made by maker of etex)(4ndextra);

hspace2 := 6onelineh;   % height of CAR
hspace3 := 5onelineh;   % space between rows
hspace4 := 3onelineh;   % height of MANUFACTURER

%%% y coords
lyc1 := 0;
lyc2 := lyc1+hspace2+hspace3;

%%% Zcol/row

%%% row 2

z12=(0, lyc2);
drawENT(12, el, hspace4)("");
x121=x12+sdtbs;
label.rt(btex MANUFACTURER etex, (x121, 2/3[y12bl, y12tl]));
label.rt(btex * manuf-name etex, (x121, 1/3[y12bl, y12tl]));

z22=(x12br+hspace1, lyc2);
drawENT(22, el, hspace4)("");
x221=x22+sdtbs;
label.rt(btex CAR-MODEL etex, (x221, 2/3[y12bl, y12tl]));
label.rt(btex * model-name etex, (x221, 1/3[y12bl, y12tl]));

%%% row 1

z21=(x22, lyc1);
drawENT(21, el, hspace2)("");
x211=x21+sdtbs;
label.rt(btex CAR etex,         (x211, 5/6[y21bl, y21tl]));
label.rt(btex o year etex,      (x211, 4/6[y21bl, y21tl]));
label.rt(btex o model (R) etex, (x211, 3/6[y21bl, y21tl]));
label.rt(btex * serial-no etex, (x211, 2/6[y21bl, y21tl]));
label.rt(btex * maker (R) etex, (x211, 1/6[y21bl, y21tl]));

%%%%% relationship lines

%    \end{macrocode}
% In this diagram the labels on the relationship lines tend to bump
% into the line ending symbol. \Mpost{} ignores initial and final spaces
% within |btex...etex|. The paired braces below, each enclosing one space,
%  supply non-discarded spaces. (These could also have been written as 
% |\space|).
%    \begin{macrocode}
%%% MANUFACTURER / CAR-MODEL (12, 22)
drawnormalDCA(12mr, 22ml);
drawnormalCA(22ml, 12mr);
label.urt(btex { }{ }made by etex, z12mr);
label.llft(btex maker of{ }{ } etex, z22ml);

%%% MANUFACTURER / CAR (12, 21)
VH(12bm, 21ml);
drawnormalCA(12bm.vh, 12bm);
drawnormalDCA(12bm.vh, 21ml);
label.llft(btex { }{ }made by etex, z12bm);
label.ulft(btex maker of{ }{ }  etex, z21ml);

%%% CAR-MODEL / CAR (22, 21)
drawnormalDCA(22bm, 21tm);
drawnormalCA(21tm, 22bm);
label.lrt(btex { }one of etex, z22bm);
label.ulft(btex type of{ }  etex, z21tm);

%    \end{macrocode}
%
% The end of this diagram
%    \begin{macrocode}
endfig;               % end fig 7

%    \end{macrocode}
%
%
% \subsubsection{Diagram 8: IDEF1X}
%
%    IDEF1X is a popular language in America for representing the structure
% of relational databases, and was developed under the auspices of the 
% US Air Force~\cite{IDEF1X}.
%
%    The general layout of the diagram mimics the previous one. All the boxes
% are divided horizontally into an upper and lower part. 
% The |drawdoublerectangle| is used for the rectangular boxes, but the dividing
% line in the rounded box has to be added by hand, as it were.
%
%    \begin{macrocode}

beginfig(8)            % example 8  IDEF1X
%%%drawgrid;

el := namespace(btex MANUFACTURER etex)(niextra);
eh := onelineh;

hspace1 := namespace(btex made by maker of etex)(4ndextra);

hspace2 := 5onelineh;   % height of CAR
hspace3 := 5onelineh;   % space between rows
hspace4 := 3onelineh;   % height of MANUFACTURER

%%% y coords
lyc1 := 0;
lyc2 := lyc1+hspace2+hspace3;

%%% Zcol/row

%%% row 2

z12=(0, lyc2);
drawdoublerectangle(12, el, hspace4, 1/2);
label.urt(btex Manufacturer etex, z12tl);
x121=x12+sdtbs;
label.rt(btex manuf-name etex, (x121, 3/4[y12bl, y12tl]));

z22=(x12br+hspace1, lyc2);
drawdoublerectangle(22, el, hspace4, 1/2);
label.urt(btex Car-model etex, z22tl);
x221=x22+sdtbs;
label.rt(btex Model-name etex, (x221, 3/4[y12bl, y12tl]));
label.rt(btex Manuf-name (FK) etex, (x221, 1/4[y12bl, y12tl]));

%%% row 1

z21=(x22, lyc1);
drawroundedbox(21, el, hspace2, 2sdtbs)("");
label.urt(btex Car etex, z21tl);
draw z21ml--z21mr;
x211=x21+sdtbs;
label.rt(btex Serial-no etex,       (x211, 5/6[y21bl, y21tl]));
label.rt(btex Manuf-name (FK) etex, (x211, 4/6[y21bl, y21tl]));
label.rt(btex Model-name (FK) etex, (x211, 2/6[y21bl, y21tl]));
label.rt(btex Year etex,            (x211, 1/6[y21bl, y21tl]));

%%%%% relationship lines

%%% MANUFACTURER / CAR-MODEL (12, 22)
drawnormalD(12mr, 22ml);
label.top(btex of etex, 1/2[z12mr, z22ml]);

%%% MANUFACTURER / CAR (12, 21)
VH(12bm, 21ml);
drawnormalthreeD(12bm, 12bm.vh, 21ml);
label.top(btex makes etex, 1/2[z12bm.vh, z21ml]);
label.ulft(btex P{ }  etex, z21ml);

%%% CAR-MODEL / CAR (22, 21)
drawnormalD(22bm, 21tm);
label.lft(btex of etex, 1/2[z21tm,z22bm]);
label.urt(btex { }P etex, z21tm);

%    \end{macrocode}
%
% The end of this diagram
%    \begin{macrocode}
endfig;               % end fig 8

%    \end{macrocode}
%
%
% \subsubsection{Diagram 9: OMT}
%
%    OMT~\cite{RUMBAUGH91} was the precursor to the currently popular UML
% structure modeling language. 
%    If you are curious as to why I believe that lexical languages are in 
% general better than BLA languages, the chapter on developing a compiler
% for OMT highlights, probably unintentionally, some of the disadvantages 
% of BLAs.
%
% The general look of the OMT diagram is almost identical
% to the IDEF1X diagram.
%
%    \begin{macrocode}

beginfig(9)            % example 9  OMT
%%%drawgrid;

el := namespace(btex {\bf MANUFACTURER} etex)(niextra);
eh := onelineh;

hspace1 := namespace(btex made by maker of etex)(4ndextra);

hspace2 := 4onelineh;   % height of CAR
hspace3 := 4onelineh;   % space between rows
hspace4 := 3onelineh;   % height of MANUFACTURER

%%% y coords
lyc1 := 0;
lyc2 := lyc1+hspace2+hspace3;

%%% Zcol/row

%%% row 2

z12=(0, lyc2);
drawdoublerectangle(12, el, hspace4, 1/2);
x121=x12+sdtbs;
label.rt(btex {\bf Manufacturer} etex, (x121, 3/4[y12bl, y12tl]));
label.rt(btex name : String etex,      (x121, 1/4[y12bl, y12tl]));

z22=(x12br+hspace1, lyc2);
drawdoublerectangle(22, el, hspace4, 1/2);
x221=x22+sdtbs;
label.rt(btex {\bf Car Model} etex, (x221, 3/4[y22bl, y22tl]));
label.rt(btex name: String etex,    (x221, 1/4[y22bl, y22tl]));

%%% row 1

z21=(x22, lyc1);
drawdoublerectangle(21, el, hspace2, 1/3);
x211=x21+sdtbs;
label.rt(btex {\bf Car} etex,          (x211, 5/6[y21bl, y21tl]));
label.rt(btex serial-no : String etex, (x211, 4/9[y21bl, y21tl]));
label.rt(btex year : Integer etex,     (x211, 2/9[y21bl, y21tl]));

%%%%% relationship lines

%%% MANUFACTURER / CAR-MODEL (12, 22)
drawnormalD(12mr, 22ml);
label.top(btex {\it makes} etex, 1/2[z12mr, z22ml]);
label.ulft(btex 1+{ } etex, z22ml);

%%% MANUFACTURER / CAR (12, 21)
VH(12bm, 21ml);
drawnormalthreeD(12bm, 12bm.vh, 21ml);
label.top(btex {\it makes} etex, 1/2[z12bm.vh, z21ml]);
label.ulft(btex 1+{ }  etex, z21ml);

%%% CAR-MODEL / CAR (22, 21)
drawnormalD(22bm, 21tm);
label.lft(btex {\it produced as} etex, 1/2[z21tm,z22bm]);

%    \end{macrocode}
%
% The end of this diagram
%    \begin{macrocode}
endfig;               % end fig 9

%    \end{macrocode}
%
%
% \subsubsection{Diagram 10: E-R}
%
%    There are several flavours of Entity-Relationship modeling icons.
% I have used a style from~\cite{ELMASRI89}.
%
%    This example introduces some new icons and \Mpost{} modeling.
%
%    \begin{macrocode}

beginfig(10)            % example 10 E-R
%%%drawgrid;

numeric diam; diam := 2onelineh;

upshift := diam;            % circle diameter
nextup := diam+upshift;

el := namespace(btex MANUFACTURER etex)(niextra);
eh := onelineh;

numeric dl, dh;             % length and height of diamond boxes
dl := 1/2el; dh := 2eh;

numeric marg; marg := 4u;   % double the seperation between parallel lines

hspace1 := 1/2el;

%%% y coords
lyc1 := 0;
lyc2 := lyc1+nextup;
lyc3 := lyc2+nextup;
lyc4 := lyc3+nextup;
lyc5 := lyc4+nextup;

%    \end{macrocode}
%
%    The diagram has 5 rows. Start with the 4th as it is the widest row.
%    \begin{macrocode}
%%% Zcol/row
%%% row 4

z14=(0,lyc4);
drawENT(14, el, eh)(btex manufacturer etex);

z34ml=(x14br+hspace1, y14mr);
drawdiamondbox(34, dl, dh)(btex has etex);

z54ml=(x34mr+hspace1, y34mr);
drawENT(54, el, eh)(btex car\_model etex);

%%% row 5

z15bm=(x14bm, lyc5);
drawcirclebox(15, diam)(btex Name etex);

z55bm=(x54bm, lyc5);
drawcirclebox(55, diam)(btex Name etex);

%    \end{macrocode}
%
%    The third row consists of an ordinary diamond box at the right and
% a doubly enclosed diamond on the left. The |drawtwodiamondbox| routine
% is used for the latter. Note that values of |marg| are
% used to make the oustside of the double diamond larger than the single
% diamonds. 
%    \begin{macrocode}
%%% row 3

z53bm=(x54bm, lyc3);
drawdiamondbox(53, dl, dh)(btex of etex);

z13c=(x14bm, y53c);
drawtwodiamondbox(13, dl+marg, dh+marg, 2/5marg)(btex Makes etex);

%    \end{macrocode}
%
%    The second row just consists of a doubly enclosed rectangular box.
% There is no explicit routine for drawing this, so two |drawENT| routines
% are used for drawing smaller and larger superimposed boxes (one with
% an empty text argument).
%    \begin{macrocode}
%%% row 2

z32bm=(x34bm, lyc2);
drawENT(32, el, eh)(btex car etex);
z31c=z32c;
drawENT(31, el+marg, eh+marg)("");

%%% row 1

z21bm=(x32bl, lyc1);
drawcirclebox(21, 5/4diam)(btex \twolines{Serial}{No} etex);

z41bm=(x32br, lyc1);
drawcirclebox(41, diam)(btex Year etex);

%%%%%% lines

%%% Name / manufacturer (15, 14)
drawnormal(15bm, 14tm);

%%% Name / model (55, 54)
drawnormal(55bm, 54tm);

%%% Mnf / has (14, 34)
drawnormal(14mr, 34ml);
label.top(btex 1 etex, 1/2[z14mr,z34ml]);

%%% has/ model (34, 54)
drawnormal(34mr, 54ml);
label.top(btex N etex, 1/2[z34mr,z54ml]);

%%% Mnf / makes (14, 13)
drawnormal(14bm, 13tm);
label.rt(btex 1 etex, 1/2[z14bm,z13tm]);

%%% model / of (54, 53)
drawnormal(54bm, 53tm);
label.rt(btex 1 etex, 1/2[z54bm,z53tm]);

%    \end{macrocode}
%    In the diagrams so far, except trivially in the first, 
% the lines have all been vertical and/or
% horizontal. Now we meet lines in arbitrary directions, and parallel 
% to boot. 
%
%    A pair of parallel lines joins the bottom of the doubly enclosed diamond
% to the left side of the doubly enclosed rectangle. Drawing one of these is
% simple --- just draw a straight line between the bottom middle of the
% diamond to the middle left of the rectangle.
%    \begin{macrocode}
%%% makes / car (13, 31)
drawnormal(13bm, 31ml);
%    \end{macrocode}
%
%    The point |z31A| is |1/2marg| above the point |z31ml|. This is one end
% of the parallel line.
%    \begin{macrocode}
z31A=(x31ml, y31ml+1/2marg);
%    \end{macrocode}
%
%    The \Mpost{} equation |z1-z2 = frac*(z3-z4)| means that 
% (a) the line |z1--z2| is parallel to the line |z3--z4|, and (b)
% the length of the line |z1--z2| is |frac| of the length of |z3--z4|.
% We next specify that the line |z13U--z31A| is parallel to, and the same
% length as, the line |z13bm--z31ml|;
%    \begin{macrocode}
z13U-z31A = z13bm-z31ml;
%    \end{macrocode}
%
%    The final part of the calculation is to determine the point |z13A| so
% that the line |z31A--z13A| is parallel to our first line and starts
% and ends at the outer perimeters of the boxes (and we already
% know what |z31A| is).
%
% \DescribeVariable{whatever}
%    Remember mediation? A point, |z1234| is on the line |z1--z2| if \\
% |z1234=frac1[z1,z2| holds. \\
% Similarly a point |z1234| is on the line |z3--z4| if \\
% |z1234=frac2[z3,z4]| holds.
%
%    These two equations are linear and provided enough variables are known 
% it is easy, even if tedious and error
% prone, to solve
% for all the unknowns using simple mathematics. Fortunately \Mpost{} has an
% idiom for this kind of calculation using the built-in variable 
% called |whatever|. Each time |whatever| is used it is internally given
% a new name which saves a lot of name inventions on the part of the user.
% The following line of code results in \Mpost{} calculating the intersection
% point, which I call |z13A|, between the two lines |z13U,z31A|, which is
% our parallel lines whose points are known, and the line |z13bm--z13mr|
% which is the lower right line of the outer diamond whose points are known.
%    \begin{macrocode}
z13A = whatever[z13U,z31A] = whatever[z13bm,z13mr];
%    \end{macrocode}
%
%    Finally, draw the second parallel line in the desired position and length.
%    \begin{macrocode}
draw z13A--z31A;
label.urt(btex N etex, 1/2[z13A,z31A]);

%    \end{macrocode}
%
%    Another pair of parallel lines connects the doubly bounded rectangle
% and the singly bounded diamond, and we use a similar calculation as above.
%    \begin{macrocode}
%%% of / car (53, 31)
drawnormal(53bm, 31mr);
z31B=(x31mr, y31mr+1/2marg);
z53U - z31B = z53bm - z31mr;
z53B = whatever[z53U,z31B] = whatever[z53bm,z53ml];
draw z53B--z31B;
label.ulft(btex N etex, 1/2[z53B,z31B]);

%    \end{macrocode}
%
% That's the end of the tricky bits for this diagram.
%    \begin{macrocode}
%%% car / serial no (31, 21)
z31C=(x21tm, y31bl);
drawnormal(31C, 21tm);

%%% car / year (31, 41)
z31D=(x41tm, y31br);
drawnormal(31D, 41tm);

%    \end{macrocode}
%
% The end of this diagram
%    \begin{macrocode}
endfig;               % end fig 10

%    \end{macrocode}
%
%
% \subsubsection{Diagram 11: NIAM}
%
%    Like IDEF1X, NIAM~\cite{NIJSSEN89} is a language for relational database
% structures. In Europe it tends to be preferred to IDEF1X.
%
%    Although the layout and icons of the NIAM illustration differ from 
% the prior
% diagrams, no new techniques are used. The most obvious of the differences
% are the use of oval and circular boxes in place of the rectangular boxes,
% and the use of pairs of rectangular boxes in the middle of the relationship
% lines.
%    \begin{macrocode}

beginfig(11)            % example 11  NIAM
%%%drawgrid;

numeric diam; diam := 2onelineh;    % circle diameter

upshift := diam;
nextup := diam+upshift;

numeric hel, vel;        % length of horizontal and vertical box pairs
eh := onelineh;
hel = namespace(btex made by etex)(nextra);
vel = namespace(btex of prod etex)(nextra);

numeric del, deh;        % horizontal & vertical diameters of oval boxes
del := namespace(btex MANUFACTURER etex)(niextra);
deh := 2eh;

numeric marg; marg := 2u;       % margin for doubly enclosed oval boxes
numeric lmarg; lmarg := marg;   % gap for short lines

numeric dashel, dasheh;         % diameters of dashed ellipses
dashel := del+2marg;
dasheh := deh+2marg;

hspace1 := diam;

%%% y coords
lyc1 := 0;
lyc2 := lyc1+nextup;
lyc3 := lyc2+nextup;

%%% Zcol/row

%%% row 3

x13ml=0; y13bm=lyc3;
drawovalbox(13, del, deh)(btex manufacturer etex);
z14=z13c;
drawdashellipse(14, dashel, dasheh);

z23ml=(x14mr+hspace1, y14mr);
drawENT(23, hel, eh)(btex of etex);

z33bl=z23br;
drawENT(33, hel, eh)(btex made by etex);

z44ml=(x33mr+hspace1, y33mr);
drawdashellipse(44, dashel, dasheh);
z43=z44c;
drawovalbox(43, del, deh)(btex car model etex);

z53ml=(x44mr+hspace1, y44mr);
drawdashcircle(53, diam);
label(btex year etex, z53c);

%%% row 2

z22c=(x23bm,lyc2);
drawcirclebox(22, namespace(btex U etex)(2nextra))(btex U etex);

x42tm=x43bm; y42ml=lyc2;
drawdoublerectangle(42, vel, 2eh, 1/2);
label(btex of etex, z42ct);
label(btex is of etex, z42cb);

%%z52c=(x53x,lyc2);
x52tm=x53bm; y52ml=lyc2;
drawdoublerectangle(52, vel, 2eh, 1/2);
label(btex of prod etex, z52ct);
label(btex prod in etex, z52cb);

%%% row 1

z11ml=(x13ml,lyc1);
drawdashellipse(11, del, deh);
label(btex serial no etex, z11c);

z21ml=(x23ml,lyc1);
drawENT(21, hel, eh)(btex of etex);

z31bl=z21br;
drawENT(31, hel, eh)(btex has etex);

z41c=(x43c,lyc1);
drawcirclebox(41, diam)(btex car etex);

%%%%%% lines

%%% manufacturer / of (14, 23)
drawnormal(14mr, 23ml);

%%% made by / car model (33, 44)
drawnormal(33mr, 44ml);
draw (x33tl, y33tl+lmarg)--(x33tr, y33tl+lmarg);
draw (x33mr, y33mr+lmarg)--(x33mr+eh, y33mr+lmarg);

%%% serial no / of (11, 21)
drawnormal(11mr, 21ml);

%%% of / of (23, 22, 21)
drawnormal(23bm, 22tm); drawnormal(22bm, 21tm);
label.rt(btex id etex, z22mr);

%%% has / car (31, 41)
drawnormal(31mr, 41ml);
draw (x31tl, y31tl+lmarg)--(x31tr, y31tl+lmarg);
draw (x31mr, y31mr+lmarg)--(x33mr+eh, y31mr+lmarg);

%%% model / of (44, 42)
drawnormal(43bm, 42tm);

%%% is of / car (42, 41)
drawnormal(42bm, 41tm);
draw (x42tfr+lmarg, y42tfr)--(x42tfr+lmarg, y42br);
draw (x42bm+lmarg, y42bm)--(x42bm+lmarg, y42bm-eh);

%%% year / of prod (53, 52)
drawnormal(53bm, 52tm);

%%% prod in / car (52, 41)
VH(52bm,41mr);
drawnormalthree(52bm, 52bm.vh, 41mr);
draw (x52tfr+lmarg, y52tfr)--(x52tfr+lmarg, y52br);
draw (x52bm+lmarg, y52bm)--(x52bm+lmarg, y52bm-eh);

%    \end{macrocode}
%
% The end of this diagram
%    \begin{macrocode}
endfig;               % end fig 11

%    \end{macrocode}
%
%    Note that the centers of the boxes on the bottom row are all at |y=0|,
% and hence the bottom halves have negative y values. This does not matter
% as \Mpost{} determines the actual space required for a diagram and does
% not base it on the origin of the coordinate system.
%
%
%    The end of the \Mpost{} examples file.
%    \begin{macrocode}
end

%    \end{macrocode}
%     The end of the example.
%    \begin{macrocode}
%</eg>
%    \end{macrocode}
%
% \subsection{Comments}
%
%    Everyone is likely to have a different style of diagramming. You have
% seen how I do it but that might not be what suits you. Nevertheless,
% the following comments may be of assistance.
%   
%    In my own work I tend to draw a lot of diagrams, using different 
% \file{.mp} files, that have similar sets of `commonly used variables 
% \& values'. Rather than repeating the list in each file, I create a
% \Mpost{} file, called say \file{mycommons.mp}, that includes these 
% and then |input mycommons| after the |input expressg| near the start
% of each diagram file.
%
%    I find it a help to sketch out the diagrams using pencil and paper
% before coding them up. I have to admit, though, that the final results
% often look very different from my initial ideas of the layout.
%
%    You might have noticed that I start the coding at different places
% in the diagrams. Basically I try and plan on getting the boxes aligned
% roughly in rows and/or columns. I then typically start with the longest
% column, or more often with the widest row, and then fill in the rest 
% from there.
%
% \subsection{Running the \Mpost{} example file} \label{sec:run}
%
%    The \file{expeg.mp} file has to be processed by \Mpost{} to obtain
% \EPS{} (\file{eps}) files for viewing or printing. 
% Depending on your installation the command to run \Mpost{} may be
% either: \\
% |mpost expeg| or \\
% |mp expeg| \\
% or perhaps something similar. This will produce eleven files, \file{expeg.1}
% to \file{expeg.11}, each of which is an \file{eps} file for the corresponding
% |beginfig(N)| in \file{expeg.mp}. \Mpost{} defaults to using \TeX{} for
% processing labels which outputs them using Computer Modern
% fonts. Unfortunately \PS{} applications do not understand these so it
% is necessary to get the fonts inserted. This is most simply done by 
% \LaTeX ing a document that includes the \Mpost{} output. A suitable
% file is provided below and is configured to be processed by either
% \LaTeX{} or \pdflatex. Run \LaTeX{} and then dvips (or what you normally
% use to generate printable output) and you will get all eleven diagrams.
%
%
%    \begin{macrocode}
%<*egt>
%    \end{macrocode}
%
%    \begin{macrocode}
%%% expeg.tex    display expressg.dtx MetaPost examples

\documentclass[11pt]{article}
\newif\ifpdf
\ifx\pdfoutput\undefined
  \pdffalse
\else
  \pdftrue
\fi

\ifpdf
  \pdfoutput=1
  \usepackage[pdftex,final]{graphicx}
  \DeclareGraphicsRule{*}{mps}{*}{}
\else
  \usepackage[final]{graphicx}
\fi

%%%% page sizes for ISO document on A4 paper
\setlength{\headheight}{11pt}
\setlength{\headsep}{10mm}
\setlength{\topskip}{11pt}
\setlength{\footskip}{11mm}
\setlength{\textwidth}{160mm}
\setlength{\textheight}{221.5mm}
\setlength{\columnsep}{10mm}
\setlength{\topmargin}{0mm}
\setlength{\oddsidemargin}{0mm}
\setlength{\evensidemargin}{0mm}
\setlength{\marginparwidth}{0pt}
\setlength{\marginparsep}{0pt}
\setlength{\marginparpush}{0pt}
\setlength{\footnotesep}{12pt}
  %%%% for US letterpaper need to change some margins
\setlength{\topmargin}{-9.4mm}
\setlength{\oddsidemargin}{1.55mm}
\setlength{\evensidemargin}{1.55mm}

\begin{document}

\begin{figure}
\centering
  \includegraphics{expeg.1}
\caption{Some boxes and line styles}
\end{figure}

\begin{figure}
\centering
  \includegraphics{expeg.2}
\caption{Example schema level diagram}
\end{figure}

\begin{figure}
\centering
  \includegraphics{expeg.3}
\caption{Example diagram of a tree structure}
\end{figure}

\begin{figure}
\centering
  \includegraphics{expeg.4}
\caption{Supertypes and subtypes}
\end{figure}

\begin{figure}
\centering
  \includegraphics{expeg.5}
\caption{A portion of a large model}
\end{figure}

\begin{figure}
\centering
  \includegraphics{expeg.6}
\caption{Car model using EXPRESS-G}
\end{figure}

\begin{figure}
\centering
  \includegraphics{expeg.7}
\caption{Car model using Shlaer-Mellor}
\end{figure}

\begin{figure}
\centering
  \includegraphics{expeg.8}
\caption{Car model using IDEF1X}
\end{figure}

\begin{figure}
\centering
  \includegraphics{expeg.9}
\caption{Car model using OMT}
\end{figure}

\begin{figure}
\centering
  \includegraphics{expeg.10}
\caption{Car model using E-R}
\end{figure}

\begin{figure}
\centering
  \includegraphics{expeg.11}
\caption{Car model using NIAM}
\end{figure}

\end{document}

%    \end{macrocode}
%
% The end of the \LaTeX{} file.
%    \begin{macrocode}
%</egt>
%    \end{macrocode}
%
% \subsubsection{Using \pdflatex}
%
%    \pdflatex{} generates a \file{.pdf} file directly from \LaTeX{} source
% instead of a \file{.dvi} file. Unfortunately \pdflatex{} does not understand
% \EPS{} in general, but it \emph{does} understand the restricted form
% of \EPS{} generated by \Mpost. By default \pdflatex{} will recognise
% files with an \file{.mps} extension as coming from \Mpost, but \Mpost{}
% generates files with a numeric extension. 
% If you like to use both \Mpost{} and \pdflatex, then it can
% get tedious changing all the numeric extensions to \file{.mps}. The
% following two scripts can help with this. The first is a shell 
% script\footnote{You may well have to modify this to run on your
% operating system.} which calls a Perl script. 
%
% The shell script is called \file{n2mps.sh}. To get suitable versions
% of the example \Mpost{} output files for use with \pdflatex, just do: \\
% |n2mps.sh expeg| \\
% after having run \Mpost{} on \file{expeg.mp}.
%
%    \begin{macrocode}
%<*shell>
#! /bin/sh

#####################################################################
# Shell script n2mps.sh
# Call as: n2mps.sh basename
# List each file basename.* in the directory and run the Perl script
# to copy each basename.N to basenameN.mps, where N is an integer
#
# Copyright 2000, Mauro S. Costa and Peter R. Wilson
#####################################################################

basename=${1:?"A file basename is required."}
extname=N.mps
echo Files $basename.N, where N is a number, will be copied to $basename$extname
for file in `ls $basename.*`
do
 n2mpsprl.prl $file
done

####################### end shell script ###########################

%</shell>
%    \end{macrocode}
% The Perl script, which is called by the \file{n2mps} script:
%    \begin{macrocode}
%<*perl>

#!/usr/local/bin/perl -w

###################################################################
# Perl script: n2mpsprl.prl
# Call as: n2mpsprl.prl filename
# If filename is of the form basename.N, where N is an integer,
# copies file basename.N to file basenameN.mps
#
# Copyright 2000, Mauro S. Costa and Peter R. Wilson
##################################################################

# Test for correct number of input parameters
die "Invalid command line arguments.\nTry $0 <src> \n" if($#ARGV > 1);
die "Invalid command line arguments.\nTry $0 <src> \n" if($#ARGV < 0);

# Assign input file name to variable
$input_file = $ARGV[0];

## test if ends with a number, exit if not
if ($input_file =~ /\w\.\d/) { ; } else { exit; }

# Remove the "dot" from the string variable 
# holding the input file name
$input_file =~ s/\.// ;

# Create a list variable composed of the string variable holding
# the concatenated input file name and the extension ".mps"
@name_list = ($input_file,'.mps') ;

# Join the string variables in the name_list variable into
# a single string variable
$output_file = join("",@name_list) ;

# create a list variable composed to the parameters needed
# for the system copy command excution
@exec_list = ('cp', $ARGV[0], $output_file) ;

# Execute the system copy  ("cp") command
system(@exec_list) ;

############################ end perl script ##########################

%</perl>
%    \end{macrocode}
%
% As an alternative when using \pdflatex{} and the \Lpack{graphicx} package,
% putting \\
% |\DeclareGraphicsRule{*}{mps}{*}{}|    \\
% will cause included graphics files with unknown extensions 
% (e.g., as generated by \Mpost) to be treated as \file{.mps} files.
% \begin{verbatim}
% \documentclass...
% \usepackage{ifpdf}%   you should have this
% \ifpdf
%   \pdfoutput=1
%   \usepackage[pdftex,final]{graphicx}
%   \DeclareGraphicsRule{*}{mps}{*}{}
% \else
%   \usepackage[final]{graphicx}
% \fi
% ...
% \includegraphics{mpfig.23}
% ...
% \end{verbatim}
%
%
% \subsection{Using \LaTeX{} instead of \TeX}
%
%    As already noted, \Mpost{} defaults to using \TeX{} for typesetting
% labels. If you would prefer it to use \LaTeX{} instead, then two things
% have to be done.
% \begin{enumerate}
% \item \Mpost{} looks at the value of an environment variable called |TEX|
%       to see what typesetting system it should use. If the variable is
%       not set, then it uses \TeX. To get it to use \LaTeX{} the environment
%       variable has to be set to |latex|. For example, on the system I use
%       this is done by:
% \begin{verbatim}
% TEX=latex
% export TEX
% \end{verbatim}
%
% \item \LaTeX{} |\documentclass| and |\begin{document}| commands must
%       be put into the |verbatimtex|\ldots|etex| group at the start of
%       the diagramming file. For the example, this might look like
% \begin{verbatim}
% verbatimtex
%   \documentclass{article}
%   % \usepackage{...} % for any packages
%   \def\twolines#1#2{\vbox{\hbox{#1} \hbox{#2}}}
%   \begin{document}
% etex
% \end{verbatim}
%
% \end{enumerate}
%
% \textbf{NOTE:} Both the above are required for \LaTeX. On the other hand,
% if |TEX| is either undefined or has a value other than |tex|, 
% then there must
% be no \LaTeX{} code anywhere in the \file{.mp} file.
%
%    If you need to generate individual self-contained \file{ps} files
% for inclusion in non-\LaTeX{} documents where the font used for labels
% is a member of the Computer Modern family,
% then you need to use LaTeX{} and dvips on \file{*.tex} files that consist
% of only a single diagram and no other text at all. At least on my setup
% I have found it best to run dvips as normal but with output to a file
% instead of a printer. Then use whatever tools are available to you to
% convert the \file{.ps} file to an \file{.eps} one (or at least set the
% correct bounding box values). The primary source on generating and
% using \EPS{} in the \LaTeX{} world is~\cite{RECKDAHL97},
% and~\cite{GOOSSENS97} also has useful information.
%
% \subsection{Using \PS{} fonts}
%
%    \Mpost{} can be made to use \PS{} fonts and, providing the labels
% don't require any special (\TeX) processing, then use of \LaTeX{} may
% be avoided altogether. In order to do this, certain requirements have
% to be put on the content on the \file{.mp} file.
%
% \begin{itemize}
% \item \DescribeVariable{prologues} The 
% diagram file must begin with the line \\
% |prologues:=2;| \\
% which will add a prologue for \PS{} font to the output file.
%
% \item \DescribeVariable{defaultfont} The 
% |defaultfont| must be changed. What it has to be changed
% to depends on the font you want to use. For example, to use the
% Times Roman font, put: \\
% |defaultfont:="ptmr8r";| \\
% just after the |prologues| line.
%
%    For this incantation to work, the file \file{ptmr8r.tfm} must exist
% in a location where \Mpost{} looks for \file{.tfm} files (on the system
% I use it is in directory \texttt{../texmf/fonts/tfm/adobe/times}). Also,
% the file \file{psfonts.map} must include a line like \\
% |ptmr8r  Times-Roman ...| \\
% Again, on my system \file{psfonts.map} is in directory 
% \texttt{../texmf/dvips/misc}.
%
%    I don't know whether or not this works if you don't have a \LaTeX{}
% distribution --- it probably doesn't. But it's unlikely that you don't 
% have one if you
% intend to use \Mpost.
%
% \end{itemize}
%     
%     As a final note on changing fonts, the \Mpost{} |defaultfont| and
% |defaultscale| values only apply to quoted text 
% (e.g., \texttt{"quoted text"}) and not to `btexed' text 
% (e.g., \texttt{btex btexed text etex}). Conversely, \TeX{} or \LaTeX{}
% commands only apply to btexed text and not to quoted text. For more
% details on this, see~\cite{METAFP}.
%    
%
%
%
% \section{The \Mpost{} code} \label{sec:mf}
%
%
%    We start by announcing what it is for.
%
%    \begin{macrocode}
%<*up>
%%% EXPRESSG.MP  MetaPost macros for EXPRESS-G and other BLA diagrams
%%% version 1.5, 31 July 2003
%%% version 1.6, 29 February 2004
%%% version 1.61, 17 March 2004

show "expressg.mp version 1.61, 2004/03/17";

%    \end{macrocode}
%
% \subsection{Variables}
%
% \begin{variable}{u}
%    The unit of length.
%    \begin{macrocode}
newinternal u; numeric u;
u := 1mm;

%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{maxx}
% \begin{variable}{maxy}
%    The maximum x and y coordinates for a diagram.
%    \begin{macrocode}
newinternal maxx, maxy;
numeric maxx, maxy;
maxx := 159.5u;        % smidgeon under 160mm for ISO
maxy := 210u;          % 210mm for ISO

%    \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{variable}{defaultdotdiam}
% \begin{variable}{dotdiam}
%    The default and actual diameter of circle and dot line end styles.
%    \begin{macrocode}
newinternal defaultdotdiam, dotdiam;
numeric defaultdotdiam, dotdiam;   
defaultdotdiam := 2u;
dotdiam := defaultdotdiam;

%    \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{variable}{normalpensize}
% \begin{variable}{normalpensize}
% \begin{variable}{normalpensize}
% The diameters of the pens for drawing normal, thick and thin lines. (The
% size of the default \Mpost{} pen is 0.5bp).
%    \begin{macrocode}
newinternal normalpensize, thickpensize, thinpensize;
numeric normalpensize, thickpensize, thinpensize;
normalpensize := 0.5bp;
thickpensize  := 1.5bp;
thinpensize   := 0.25bp;
%    \end{macrocode}
% \end{variable}
% \end{variable}
% \end{variable}
%
% \begin{variable}{dotsscale}
% |dotsscale| is the amount the |...pensize| has to be increased so that a 
% dotted line looks as thick as a continuous or dashed line.
%    \begin{macrocode}
newinternal dotsscale; numeric dotsscale;
dotsscale := 2;

%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{normalpen}
% \begin{variable}{thickpen}
% \begin{variable}{thinpen}
% \begin{variable}{dotspen}
% \begin{variable}{dotpen}
%  The pens for drawing lines, plus |dotpen| for drawing a dot line end style.
%    \begin{macrocode}
newinternal normalpen, thickpen, thinpen, dotspen, dotpen;
pen normalpen, thickpen, thinpen, dotspen, dotpen;
normalpen := pencircle scaled normalpensize; % i.e. defaultpen;
thickpen  := pencircle scaled thickpensize;
thinpen   := pencircle scaled thinpensize;
dotspen   := pencircle scaled (dotsscale*normalpensize);
dotpen    := pencircle scaled dotdiam;

%    \end{macrocode}
% \end{variable}
% \end{variable}
% \end{variable}
% \end{variable}
% \end{variable}
%
% \begin{variable}{defaultsmoothrad}
% \begin{variable}{smoothrad}
% The default and initial values for the radius of the arc used for joining
% two lines.
% \changes{v1.3}{2000/05/22}{Added defaultsmoothrad and smoothrad variables}
%    \begin{macrocode}
newinternal defaultsmoothrad;
numeric smoothrad, defaultsmoothrad;
smoothrad := defaultsmoothrad := 2u;

%    \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{variable}{defaultdrumlid}
% \begin{variable}{drumlid}
% The default and initial values for the ratio of the minor to major
% diameter of ellipses for the top and bottom of drums.
% \changes{v1.3}{2000/05/22}{Added defaultdrumlid and drumlid variables}
%    \begin{macrocode}
newinternal defaultdrumlid;
numeric drumlid, defaultdrumlid;
drumlid := defaultdrumlid := 0.2;

%    \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{variable}{defaultgal}
% \begin{variable}{defaultgab}
% \begin{variable}{defaultgfl}
% \begin{variable}{defaultgfb}
% The default values for the length and base width width of arrowheads and fanins.
%
%    \begin{macrocode}
%%% default length and base width for arrowheads and fanin
newinternal defaultgal, defaultgab, defaultgfl, defaultgfb; 
numeric defaultgal, defaultgab, defaultgfl, defaultgfb; 
defaultgal := defaultgfl := defaultdotdiam;
defaultgab := defaultgfb := defaultgal;

%    \end{macrocode}
% \end{variable}
% \end{variable}
% \end{variable}
% \end{variable}
%
% \begin{variable}{gal}
% \begin{variable}{gab}
% \begin{variable}{gfl}
% \begin{variable}{gfb}
% Values of length and base width of arrowheads and fanins.
%    \begin{macrocode}
%%% length and base width of arrowheads and fanins
newinternal gal, gab, gfl, gfb;  
numeric gal, gab, gfl, gfb;  
gal := defaultgal;
gab := defaultgab;
gfl := defaultgfl;
gfb := defaultgfb;

%    \end{macrocode}
% \end{variable}
% \end{variable}
% \end{variable}
% \end{variable}
%
% \begin{variable}{onelineh}
% The minimum height of a box that encloses a single line of text. 
%
%    \begin{macrocode}
newinternal onelineh;
numeric onelineh;
onelineh := 5u;

%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{sdtbl}
% \begin{variable}{sdtbh}
% \begin{variable}{sdtbs}
% The length, height and inset for a simple data type box. The length is
% sufficient for the name `BOOLEAN' and the height for one line of text.
%    \begin{macrocode}
%%% length, height & inset for simple data type boxes
newinternal sdtbl, sdtbh, sdtbs;
numeric sdtbl, sdtbh, sdtbs; 
sdtbl := 22u; 
sdtbh := onelineh;  
sdtbs := 2u;  

%    \end{macrocode}
% \end{variable}
% \end{variable}
% \end{variable}
%
% \begin{variable}{sdtbel}
% \begin{variable}{sdtbeh}
% \begin{variable}{sdtbes}
% The length, height and inset for a simple EXPRESSION data type box. 
% The length is
% sufficient for the name `EXPRESSION' and the height for one line of text.
%    \begin{macrocode}
%%% length, height & inset for EXPRESSION data type boxes
newinternal sdtbel, sdtbeh, sdtbes; 
numeric sdtbel, sdtbeh, sdtbes; 
sdtbel := 28u;
sdtbeh := sdtbh; sdtbes := sdtbs;

%    \end{macrocode}
% \end{variable}
% \end{variable}
% \end{variable}
%
% \begin{variable}{sdtbgel}
% \begin{variable}{sdtbgeh}
% \begin{variable}{sdtbges}
% The length, height and inset for a simple GENERICENT data type box. 
% The length is
% sufficient for the name `GENERIC\_ENTITY' and the height for one line of text.
% \changes{v1.5}{2003/07/31}{Added sdtbgel, sdtbgeh and sdtbges box lengths}
%    \begin{macrocode}
%%% length, height & inset for GENERICENT data type boxes
newinternal sdtbgel, sdtbgeh, sdtbges; 
numeric sdtbgel, sdtbgeh, sdtbges; 
sdtbgel := 38u;
sdtbgeh := sdtbh; sdtbges := sdtbs;

%    \end{macrocode}
% \end{variable}
% \end{variable}
% \end{variable}
%
% \begin{variable}{pconl}
% The average length of a numeric page connector (e.g., for |9,9 (9,9)|).
%    \begin{macrocode}
%%% average length of numeric page connector
newinternal pconl;
numeric pconl; % length of page connector (for e.g., 9,9 (9,9) )
pconl:=15u;
%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{pconh}
% Height of average page connector (one line of text).
%    \begin{macrocode}
%%% height of page connectors (one line)
newinternal pconh;
numeric pconh; 
pconh := onelineh; 

%    \end{macrocode}
% \end{variable}
%
% \begin{variable}{enth}
% \begin{variable}{typeh}
% The height of a one line ENT(ITY) box (|enth|) and the height of a
% one line ENUM(ERATION), SELECT or TYPE box.
%
%    \begin{macrocode}
%%% heights of entity, enum, select, type boxes (One text line)
newinternal enth, typeh;
numeric enth, typeh; 
enth := onelineh;
typeh := onelineh;

%    \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{variable}{ish}
% \begin{variable}{isrh}
% The height of a normal one line interschema box (|ish|) and an
% interschema box with one line each for the name and rename (|isrh|).
%    \begin{macrocode}
%%% height of interschema boxes (one text line, no rename), and (name + rename)
newinternal ish, isrh;
numeric ish, isrh;   
ish  := 2onelineh;
isrh := 3onelineh;

%    \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{variable}{schemah}
% Height of a one line SCHEMA box.
%    \begin{macrocode}
%%% height of schema boxes (one text line)
newinternal schemah;
numeric schemah; 
schemah := 2onelineh;

%    \end{macrocode}
% \end{variable}
% 
% \begin{variable}{eventh}
% \begin{variable}{eventslope}
% The height (|eventh|) of a one line (G/L)EVENT box and the slope of the 
% sides of a (G/L)EVENT box.
%    \begin{macrocode}
%%% height and slope of event boxes
newinternal eventh, eventslope;
numeric eventh, eventslope; 
eventh := onelineh;
eventslope := 0.25;

%    \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{variable}{nextra}
% \begin{variable}{niextra}
% Margins for namespaces in normal (|nextra|) and inset (|niextra|) boxes.
% Inset boxes are the ENUM, SELECT and TYPE boxes.
%    \begin{macrocode}
%%% extra namespaces for boxed names
newinternal nextra, niextra; 
numeric nextra, niextra; 
nextra := 2u;
niextra := nextra+sdtbs;

%    \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{variable}{ndextra}
% Margin for namespace on a relationship line.
%    \begin{macrocode}
%%% extra namespace for attribute names
newinternal ndextra;
numeric ndextra;   
ndextra := nextra+dotdiam;

%    \end{macrocode}
% \end{variable}
%
% \subsection{Utility routines}
%
% \begin{routine}{VH}
% \changes{v1.1}{1999/10/30}{Added VH routine}
% Calculates the intersection point |z$vh| between the vertical line through
% |z$| and the horizontal line through |z$$| (see \fref{fig:vhvh}).
%    \begin{macrocode}
%%% calculates mid-point on a path like |_ (vertical, horizontal)
%%% final points are: z$, z$vh, z$$, where z$vh=(x$,y$$)
def VH(suffix $, $$) = 
  z$vh=(x$,y$$); 
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{VhV}
% \changes{v1.1}{1999/10/30}{Added VhV routine}
% Calculates the point |z$vhv| on the vertical line through |z$| and the
% point |z$$vhv| on the vertical line through |z$$|, such that the line
% |z$vhv--z$$vhv| is horizontal and centered vertically between the given
% points (see \fref{fig:vhvh}).
%    \begin{macrocode}
%%% Calculates mid-points on a path like |_ 
%%%                                        |  (vertical, horizontal, vertical)
%%% final points are: z$, z$vhv, z$$vhv, z$$
def VhV(suffix $, $$) =
  y$$vhv=1/2[y$,y$$]; x$$vhv=x$$;
  z$vhv=(x$,y$$vhv);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{HvH}
% \changes{v1.1}{1999/10/30}{Added HvH routine}
% Calculates the point |z$hvh| on the horizontal line through |z$| and the
% point |z$$hvh| on the horizontal line through |z$$|, such that the line
% |z$hvh--z$$hvh| is vertical and centered horizontally between the given
% points (see \fref{fig:vhvh}).
%    \begin{macrocode}
%%% Calculates mid-points on a path like -|_ (horizontal, vertical, horizontal)
%%% final points are: z$, z$hvh, z$$hvh, z$$
def HvH(suffix $, $$) =
  x$hvh=1/2[x$,x$$]; y$hvh=y$;
  z$$hvh=(x$hvh,y$$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{VyV}
% \changes{v1.1}{1999/10/30}{Added VyV routine}
% A generalisation of |VhV|.
% Calculates the point |z$vyv| on the vertical line through |z$| and the
% horizontal line through |y@|, and the point |z$$vyv| on the vertical 
% line through |z$$| and the horizontal line through |y@| (see \fref{fig:vyxh}).
%    \begin{macrocode}
%%% Calculates turning points on a U shaped path (vertical, horizontal, vertical)
%%% final points are: z$, z$vyv, z$$vyv, z$$
def VyV(suffix $, @, $$) =
  z$$vyv=(x$$,y@);
  z$vyv =(x$, y@);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{HxH}
% \changes{v1.1}{1999/10/30}{Added HxH routine}
% A generalisation of |HvH|.
% Calculates the point |z$hxh| on the horizontal line through |z$| and the
% vertical line through |x@|, and the 
% point |z$$hgh| on the horizontal line through |z$$| and the vertical
% line through |x@| (see \fref{fig:vyxh}).
%    \begin{macrocode}
%%% Calculates corner points rotated U shaped path (horizontal, vertical, horizontal)
%%% final points are: z$, z$hxh, z$$hxh, z$$
def HxH(suffix $, @, $$) =
  z$$hxh=(x@,y$$);
  z$hxh =(x@,y$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{namespace}
% |namespace(|\meta{name}|)(|\meta{margin}|)| calculates the length of
% the text string \meta{name} plus the \meta{margin} length. The
% body is enclosed in parentheses\footnote{Requested by Stephan Hennig, 
% \texttt{ctt} thread \textit{[MP, expressg, latexmp] namespace and textext},
% 16 March 2004} 
% so you can do \verb?c=2namespace...?
% \changes{v1.61}{2004/03/17}{Added parentheses to namespace macro}
%    \begin{macrocode}
%%% calculates length taken up by typesetting str, plus margin 
def namespace(text str)(expr margin) =
  (xpart lrcorner(str) - xpart llcorner(str) + margin)
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{dashes}
% Shorthand for a dashed line style. Use as: |draw ... dashes;|.
%    \begin{macrocode}
def dashes = 
  dashed evenly
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{dots}
% Shorthand for a dotted line style. Use as: |draw ... dots;|.
%    \begin{macrocode}
def dots =
  dashed withdots
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{dashedgrid}
% |dashedgrid(|\meta{nx}, \meta{ny}, \meta{dist}|)| draws a thin dashed grid
% with \meta{nx} and \meta{ny} divisions in the $x$ and $y$ directions,
% with \meta{dist} between the grid lines. The grid lines are numbered.
%    \begin{macrocode}
% draw a general dashed grid
def dashedgrid(expr nx, ny, dist) =
  save zg_, zg__, oldpen;
  pair zg_[], zg__[];
  pen oldpen; oldpen = currentpen;
  pickup thinpen;
  for i = 0 upto nx:
    zg_[i] = (i*dist, 0); zg_[i+1000] = (i*dist, ny*dist);
    draw zg_[i]--zg_[i+1000] dashes;
    label.bot(decimal(i), zg_[i]);
  endfor
  for i = 0 upto ny:
    zg__[i] = (0, i*dist); zg__[i+1000] = (nx*dist, i*dist);
    draw zg__[i]--zg__[i+1000] dashes;
    label.lft(decimal(i), zg__[i]);
  endfor
  pickup oldpen;
enddef; 

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawgrid}
% |drawgrid| draws a thin dashed grid filling the permitted space for an
% ISO Standard diagram. The units are in mm and the lines are at 10mm intervals
% with labeling in terms of mm.
%    \begin{macrocode}
%%% draw a 1cm spaced grid of 16(x) by 21(y) cms. (units are mm)
def drawgrid =
  dashedgrid(16, 21, 10mm);
enddef;

%    \end{macrocode}
% \end{routine}
%
% The box drawing routines take as an argument the suffix (|$|) of the 
% left-hand bottom corner point of the box, and normally the length and
% height of the box. 
% The coordinates of the box corners
% are calculated (|z$bl|, |z$br|, |z$tr| and |z$tl|). The midpoints of
% the sides of the box (|z$bm|, |z$mr|, |z$tm|, |z$ml|) are calculated
% as well. The text `center' of the box is |z$c|, while the geometric
% center of the box will be at the intersection point of the lines
% |z$bm--z$tm| and |z$ml--z$mr|. See \fref{fig:boxpoints} for an 
% illustration.
%
% \begin{routine}{rectpoints}
% \changes{v1.1}{1999/10/30}{Added rectpoints routine}
% The routine |rectpoints($, l, h)| calculates
% the corner and midpoints of a rectangular box with bottom left
% at |z$|, length |l| and height |h|. Note that it does \emph{not}
% calculate the center point (see \fref{fig:boxpoints}).
%    \begin{macrocode}
%%% calculates corner and midpoints of a rectangle, 
%%% bottom left at $, length l, height h
def rectpoints(suffix $)(expr l, h) =
  z$bl = z$; 
  z$tr = (x$+l, y$+h);
  z$br = (x$tr, y$bl);
  z$tl = (x$bl, y$tr);
  z$ml = 1/2[z$bl, z$tl];
  z$mr = 1/2[z$br, z$tr];
  z$bm = 1/2[z$bl, z$br];
  z$tm = 1/2[z$tl, z$tr];
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{rhompoints}
% \changes{v1.1}{1999/10/30}{Added rhompoints routine}
% The routine |rhompoints($, l, h, s)| calculates the corner and midpoints
% of a rhomboid length |l|, height |h|, sideslope |s|, and positioned
% with its bottom left hand corner at |z$|. The center point is \emph{not} 
% calculated (see \fref{fig:eventpoints}).
%    \begin{macrocode}
%%% calculate corner, midpoints and center point of a rhomboid.
def rhompoints(suffix $)(expr l, h, s) =
  save eshift;
  numeric eshift; eshift = s*h;
  z$bl = z$;
  z$tr = (x$+l+eshift, y$+h);
  z$br = (x$bl+l, y$bl);
  z$tl = (x$bl+eshift, y$tr);
  z$ml = 1/2[z$bl, z$tl];
  z$mr = 1/2[z$br, z$tr];
  z$bm = (1/2[x$ml,x$mr], y$bl);
  z$tm = (x$bm, y$tr);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{circpoints}
% \changes{v1.1}{1999/10/30}{Added circpoints routine}
% The routine |circpoints($, d)| calculates the `corner' and `midpoints'
% on the circumference of a circle, center |z$| and diameter |d|.
%    \begin{macrocode}
%%% calculate circumferential points on a circle
def circpoints(suffix $)(expr diam) =
  save rad, sinrad, cosrad;
  numeric rad, sinrad, cosrad;
  rad = diam/2;
  sinrad = rad*(sind 45);
  cosrad = rad*(cosd 45);
  z$c=z$;
  z$ml=(x$c-rad, y$c);
  z$mr=(x$c+rad, y$c);
  z$bm=(x$c, y$c-rad);
  z$tm=(x$c, y$c+rad);
  z$tr=(x$c+cosrad, y$c+sinrad);
  z$bl=(x$c-cosrad, y$c-sinrad);
  z$br=(x$tr, y$bl);
  z$tl=(x$bl, y$tr);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \subsection{Path routines}
% \changes{v1.4}{2000/07/10}{Added path routines}
%
% \begin{routine}{~}
% The binary operator |~| is a reimplementation of the METAFONT plain base
% |softjoin| path connector (METAFONTbook, page 266); 
% it connects paths via a small circular arc
% radius |smoothrad|.
%    \begin{macrocode}
%%% circular arc join between two paths
tertiarydef p ~ q =
  begingroup
  c_ := fullcircle scaled 2smoothrad shifted point 0 of q;
  a_ := ypart(c_ intersectiontimes p);
  b_ := ypart(c_ intersectiontimes q);
  if a_ < 0: point 0 of p{direction 0 of p} else: subpath(0,a_) of p fi
    ... if b_ < 0: {direction infinity of q}point infinity of q
        else: subpath(b_,infinity) of q fi
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{sharply}
% |sharply(zi, zj, ...zn)| creates a piecewise linear path through the
% given points. (The code is based on the |flex| routine,
% page 267 of the METAFONTbook).
%    \begin{macrocode}
%%% piecewise linear path between the given points
def sharply(text t) =     % t is a list of pairs
  hide(n_:=0; for z=t: z_[incr n_]:=z; endfor)
  z_1 for k=2 upto n_: --z_[k] endfor
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{smoothly}
% |smoothly(zi, zj, ...zn)| creates a piecewise linear path through the
% given points, with the sharp corners replaced by circular arcs of radius
% |smoothrad|.
% page 267 of the METAFONTbook).
%    \begin{macrocode}
%%% piecewise linear path between the given points with smooth corners
def smoothly(text t) =     % t is a list of pairs
  hide(n_:=0; for z=t: z_[incr n_]:=z; endfor)
  (z_1 for k=2 upto n_-1: --z_[k]) ~ (z_[k] endfor --z_[n_])
enddef;

%    \end{macrocode}
% \end{routine}
%
% \subsection{Line end drawing routines}
%
% \changes{v1.4}{2000/07/10}{Added individual line end drawing routines}
% \begin{routine}{drawO}
% Draw an open circle, diameter |dotdiam| at the end of the vector
% |z$| to |z$$|. Any underlying graphic/text will be hidden.
% All the line end drawing routines have similar code.
%    \begin{macrocode}
%%% Draw an open circle at end of vector from $ to $$ 
def drawO(suffix $, $$) = 
%    \end{macrocode}
% Keep everything inside a group and specify the local variables.
%    \begin{macrocode}
  begingroup
  save v_, c_, l, p;
%    \end{macrocode}
% Specify the types of the local variables.
%    \begin{macrocode}
  pair v_, c_;
  numeric l;
  path p;
%    \end{macrocode}
% |v_| is the difference between the start and end points of the line. 
% That is, it is the vector from the end point to the start point.
%    \begin{macrocode}
  v_ := z$-z$$;
%    \end{macrocode}
% \DescribeRoutine{++}
% \DescribeRoutine{xpart}
% \DescribeRoutine{ypart}
% Using \Mpost's Pythagorean addition operator |++|, where |a++b| means
% $\sqrt{a^{2}+b^{2}}$, we can calculate the length |l| of the line from
% the x and y dimension (|xpart| and |ypart|) of the vector |v_|.
%    \begin{macrocode}
  l := (xpart v_)++(ypart v_);  % length of the line
%    \end{macrocode}
% Using mediation involving the ratio of the circle radius to the length
% of the line, calculate |c_|, the required position of the center of 
% the circle at the end of the line.
%    \begin{macrocode}
  c_ := (dotdiam/(2l))[z$$,z$];
%    \end{macrocode}
% |p| is the path for drawing the circle.
%    \begin{macrocode}
  p := fullcircle scaled dotdiam shifted c_;
%    \end{macrocode}
% Erase anything underneath the circle.
%    \begin{macrocode}
  unfill p;
%    \end{macrocode}
% Now we can draw the circle (twice to make sure it shows).
%    \begin{macrocode}
  draw p; draw p;
%    \end{macrocode}
% Finish the local group and end.
%    \begin{macrocode}
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawD}
% Draw a closed circle, diameter |dotdiam| at the end of the vector
% |z$| to |z$$|. Any underlying graphic/text will be hidden.
%    \begin{macrocode}
%%% Draw a closed circle at end of vector from $ to $$ 
def drawD(suffix $, $$) = 
  begingroup
  save v_, c_, l, p;
  pair v_, c_;
  numeric l;
  path p;
  v_ := z$-z$$;
  l := (xpart v_)++(ypart v_);  % length of the line
  c_ := (dotdiam/(2l))[z$$,z$];
  p := fullcircle scaled dotdiam shifted c_;
  fill p;
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawOA}
% Draw an open arrowhead, length |gal| and base width |gab|,
% at the end of the vector from |z$| to |z$$|.
% The same general code pattern is used for non-circular
% line end styles, and is described here. It is not too different
% from drawing circular ends, except that the orientation of the line
% has to be taken into account.
%    \begin{macrocode}
%%% draw an open arrowhead at end of vector from $ to $$
def drawOA(suffix $, $$) =
  begingroup
  save v_, c_, v_u, c_t, c_b, l, hb, p;
  pair v_, c_, v_u, c_t, c_b;
  numeric l, hb;
  path p;
  hb := gab/2;
  v_ := z$-z$$;
  l := (xpart v_)++(ypart v_);  % length of the line
  c_ := (gal/(l))[z$$,z$];      % base of arrowhead
%    \end{macrocode}
% Calculate the unit vector in the direction of the line.
%    \begin{macrocode}
  v_u := unitvector v_;
%    \end{macrocode}
% Calculate one of the corner points on the base of the triangle by
% shifting the midbase point in the direction of the normal to the
% line by half the base width.
%    \begin{macrocode}
  c_t := c_ shifted (-hb*(ypart v_u), hb*(xpart v_u));
%    \end{macrocode}
% Specify that the other corner point is symmetrically opposite the first.
%    \begin{macrocode}
  c_b - c_ = c_ - c_t;
%    \end{macrocode}
% Draw the triangular arrowhead.
%    \begin{macrocode}
  p = c_b--z$$--c_t--cycle;
  unfill p;
  draw p; draw p;
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawCA}
% Draw a closed (black) arrowhead, length |gal| and base width |gab|,
% at the end of the vector from |z$| to |z$$|.
%    \begin{macrocode}
%%% draw a closed arrowhead at end of vector from $ to $$
def drawCA(suffix $, $$) =
  begingroup
  save v_, c_, v_u, c_t, c_b, l, hb, p;
  pair v_, c_, v_u, c_t, c_b;
  numeric l, hb;
  path p;
  hb := gab/2;
  v_ := z$-z$$;
  l := (xpart v_)++(ypart v_);  % length of the line
  c_ := (gal/(l))[z$$,z$];      % base of arrowhead
  v_u := unitvector v_;
  c_t := c_ shifted (-hb*(ypart v_u), hb*(xpart v_u));
  c_b - c_ = c_ - c_t;
  p = c_b--z$$--c_t--cycle;
  filldraw p;
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawA}
% Draw a simple arrowhead, length |gal| and base width |gab|,
% at the end of the vector from |z$| to |z$$|.
%    \begin{macrocode}
%%% draw a simple arrowhead at end of vector from $ to $$
def drawA(suffix $, $$) =
  begingroup
  save v_, c_, v_u, c_t, c_b, l, hb, p;
  pair v_, c_, v_u, c_t, c_b;
  numeric l, hb;
  path p;
  hb := gab/2;
  v_ := z$-z$$;
  l := (xpart v_)++(ypart v_);  % length of the line
  c_ := (gal/(l))[z$$,z$];      % base of arrowhead
  v_u := unitvector v_;
  c_t := c_ shifted (-hb*(ypart v_u), hb*(xpart v_u));
  c_b - c_ = c_ - c_t;
  p = c_b--z$$--c_t;
  draw p;
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawF}
% Draw a fanin, length |gfl| and base width |gfb|,
% at the end of the vector from |z$| to |z$$|.
%    \begin{macrocode}
%%% draws a fanin at the end of the vector from $ to $$
def drawF(suffix $, $$) =
  begingroup
  save v_, c_, v_u, c_t, c_b, l, hb, p;
  pair v_, c_, v_u, c_t, c_b;
  numeric l, hb;
  path p;
  hb := gfb/2;
  v_ := z$-z$$;
  l := (xpart v_)++(ypart v_);  % length of the line
  c_ := (gfl/(l))[z$$,z$];      % apex of fan
  v_u := unitvector v_;
  c_t := z$$ shifted (-hb*(ypart v_u), hb*(xpart v_u));
  c_b - z$$ = z$$ - c_t;
  p = c_b--c_--c_t;
  draw p;
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
%
% \subsection{Line drawing routines}
% \changes{v1.4}{2000/07/10}{Stripped in-line line end code from line drawing routines}
%
% \begin{routine}{drawdots}
% Draw a dotted line between the two points |z$| and |z$$|.
%    \begin{macrocode}
%%% Draw a dotted line from $ to $$
def drawdots(suffix $, $$) = 
  pickup dotspen;
  draw z$--z$$ dots; 
  pickup normalpen;
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdotsthree}
% Draw a straight dotted line between the three points |z$|, |z@| and |z$$|.
%    \begin{macrocode}
%%% Draws the dotted line $--@--$$
def drawdotsthree(suffix $, @, $$) = 
  pickup dotspen;
  draw z$--z@--z$$ dots; 
  pickup normalpen;
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdotsfour}
% Draw a straight dotted line between the four points |z$|, |z@|, |z@@| and |z$$|.
%    \begin{macrocode}
%%% Draw the dotted line $--@--@@--$$
def drawdotsfour(suffix $, @, @@, $$) = 
  pickup dotspen;
  draw z$--z@--z@@--z$$ dots; 
  pickup normalpen;
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdotsO}
% Draw a dotted line between the two points |z$| and |z$$|, 
% ending in an open circle, diameter |dotdiam|, at |z$$|. 
%    \begin{macrocode}
%%% Draw a dotted line from $ to $$ with open circle at $$
def drawdotsO(suffix $, $$) = 
  pickup dotspen;
  draw z$--z$$ dots;
  pickup normalpen;
  drawO($, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdotsthreeO}
% Draw a straight dotted line between the three points |z$|, |z@| and |z$$|,
% ending in an open circle, diameter |dotdiam|, at |z$$|.
%    \begin{macrocode}
%%% Draws the dotted line $--@--$$
def drawdotsthreeO(suffix $, @, $$) = 
  pickup dotspen;
  draw z$--z@--z$$ dots; 
  pickup normalpen;
  drawO(@, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdotsfourO}
% Draw a straight dotted line between the four points |z$|, |z@|, |z@@| and |z$$|,
% ending in an open circle, diameter |dotdiam|, at |z$$|.
%    \begin{macrocode}
%%% Draw the dotted line $--@--@@--$$
def drawdotsfourO(suffix $, @, @@, $$) = 
  pickup dotspen;
  draw z$--z@--z@@--z$$ dots; 
  pickup normalpen;
  drawO(@@, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdotsOO}
% Draw a dotted line between the two points |z$| and |z$$|, 
% ending in open circles, diameter |dotdiam|, at |z$| and |z$$|.
%    \begin{macrocode}
%%% Draw the dotted line from $ to $$, ending in circles diameter dotdiam at $ and $$
def drawdotsOO(suffix $, $$) =
  pickup dotspen;
  draw z$--z$$ dots;
  pickup normalpen;
  drawO($, $$); drawO($$, $);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdash}
% Draw a dashed line between the two points |z$| and |z$$|.
%    \begin{macrocode}
%%% draws a dashed line from $ to $$
def drawdash(suffix $, $$) = 
  draw z$--z$$ dashes; 
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdashthree}
% Draw a straight dashed line between the three points |z$|, |z@| and |z$$|.
%    \begin{macrocode}
%%% draws the dashed line $--@--$$
def drawdashthree(suffix $, @, $$) = 
  draw z$--z@--z$$ dashes; 
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdashfour}
% Draw a straight dashed line between the four points |z$|, |z@|, |z@@| and |z$$|.
%    \begin{macrocode}
%%% draws the dashed line $--@--@@--$$
def drawdashfour(suffix $, @, @@, $$) = 
  draw z$--z@--z@@--z$$ dashes; 
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdashO}
% Draw a dashed line between the two points |z$| and |z$$|, 
% ending in an open circle, diameter |dotdiam|, at |z$$|.
%    \begin{macrocode}
%%% draws a dashed line from $ to $$, ending in a circle diameter dotdiam at $$
def drawdashO(suffix $, $$) =
  draw z$--z$$ dashes;
  drawO($, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdashthreeO}
% Draw a straight dashed line between the three points |z$|, |z@| and |z$$|, 
% ending in an open circle, diameter |dotdiam|, at |z$$|.
%    \begin{macrocode}
%%% draws the dashed line $--@--$$ with circle at $$
def drawdashthreeO(suffix $, @, $$) =
  draw z$--z@--z$$ dashes;
  drawO(@, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdashfourO}
% Draw a straight dashed line between the four points |z$|, |z@|, |z@@| and |z$$|, 
% ending in an open circle, diameter |dotdiam|, at |z$$|.
%    \begin{macrocode}
%%% draws the dashed line $--@--@@--$$ with circle at $$
def drawdashfourO(suffix $, @, @@, $$) =
  draw z$--z@--z@@--z$$ dashes;
  drawO(@@, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdashOO}
% Draw a dashed line between the two points |z$| and |z$$|, 
% ending in open circles, diameter |dotdiam|, at |z$| and |z$$|.
%    \begin{macrocode}
% drawdashOO($, $$)
%%% draws a dashed line from $ to $$, ending in circles diameter dotdiam at $ and $$
def drawdashOO(suffix $, $$) =
  draw z$--z$$ dashes;
  drawO($, $$); drawO($$, $);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormal}
% Draw a normal thickness line between the two points |z$| and |z$$|.
%    \begin{macrocode}
%%% draws a normal line from $ to $$.
def drawnormal(suffix $, $$) =
  draw z$--z$$;
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalthree}
% Draw a straight normal thickness line between the three points |z$|, |z@| and |z$$|.
%    \begin{macrocode}
% drawnormalthree($, @, $$)
%%% draws the normal line $--@--$$
def drawnormalthree(suffix $, @, $$) = 
  draw z$--z@--z$$; 
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalfour}
% Draw a straight normal thickness line between the four points |z$|, |z@|, |z@@| and |z$$|.
%    \begin{macrocode}
%%% draws the normal line $--@--@@--$$
def drawnormalfour(suffix $, @, @@, $$) = 
  draw z$--z@--z@@--z$$; 
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalO}
% Draw a straight normal thickness line between the two points |z$| and |z$$|, 
% ending in an open circle, diameter |dotdiam|, at |z$$|.
%    \begin{macrocode}
% drawnormalO($, $$)
%%% draws a normal line from $ to $$, ending in a circle diameter dotdiam at $$
def drawnormalO(suffix $, $$) =
  draw z$--z$$;
  drawO($, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalthreeO}
% Draw a straight normal thickness line between the three points |z$|, |z@| and |z$$|, 
% ending in an open circle, diameter |dotdiam|, at |z$$|.
%    \begin{macrocode}
%%% draws the normal line $--@--$$, ending in a circle at $$
def drawnormalthreeO(suffix $, @, $$) =
  draw z$--z@--z$$;
  drawO(@, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalfourO}
% Draw a straight normal thickness line between the four points |z$|, |z@|, |z@@| and |z$$|, 
% ending in an open circle, diameter |dotdiam|, at |z$$|.
%    \begin{macrocode}
%%% draws the line $--@--@@--$$, ending in a circle at $$
def drawnormalfourO(suffix $, @, @@, $$) =
  draw z$--z@--z@@--z$$;
  drawO(@@, $$);
enddef;


%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalOO}
% Draw a straight normal thickness line between the two points |z$| and |z$$|, 
% ending in open circles, diameter |dotdiam|, at |z$| and |z$$|.
%    \begin{macrocode}
% drawnormalOO($, $$)
%%% draws a normal line from $ to $$, ending in circles diameter dotdiam at $ and $$
def drawnormalOO(suffix $, $$) =
  draw z$--z$$;
  drawO($, $$); drawO($$, $);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalD}
% Draw a straight normal thickness line between the two points |z$| and |z$$|, 
% ending in a black dot, diameter |dotdiam|, at |z$$|.
%    \begin{macrocode}
%%% draws a normal line from $ to $$, ending in a dot diameter dotdiam at $$
def drawnormalD(suffix $, $$) =
  draw z$--z$$;
  drawD($, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalthreeD}
% Draw a straight normal thickness line between the three points |z$|, |z@| and |z$$|, 
% ending in a black dot, diameter |dotdiam|, at |z$$|.
%    \begin{macrocode}
%%% draws the normal line $--@--$$, ending in a dot at $$
def drawnormalthreeD(suffix $, @, $$) =
  draw z$--z@--z$$;
  drawD(@, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalfourD}
% Draw a straight normal thickness line between the four points |z$|, |z@|, |z@@| and |z$$|, 
% ending in a black dot, diameter |dotdiam|, at |z$$|.
%    \begin{macrocode}
%%% draws the normal line $--@--@@--$$, ending in a dot at $$
def drawnormalfourD(suffix $, @, @@, $$) =
  draw z$--z@--z@@--z$$;
  drawD(@@, $$);
enddef;


%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalDD}
% Draw a straight normal thickness line between the two points |z$| and |z$$|, 
% ending in black dots, diameter |dotdiam|, at |z$| and |z$$|.
%    \begin{macrocode}
%%% draws a normal line from $ to $$, ending in dots diameter dotdiam at $ and $$
def drawnormalDD(suffix $, $$) =
  draw z$--z$$;
  drawD($, $$); drawD($$, $);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalOA}
% Draw a straight normal thickness line between the two points |z$| and |z$$|,
% ending with an open arrowhead, length |gal| and base width |gab|,
% at |z$$|. 
%    \begin{macrocode}
%%% draws a normal line from $ to $$, ending with an open arrowhead at $$
def drawnormalOA(suffix $, $$) =
  draw z$--z$$;
  drawOA($, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalCA}
% Draw a straight normal thickness line between the two points |z$| and |z$$|,
% ending with a closed (black) arrowhead, length |gal| and base width |gab|,
% at |z$$|.
%    \begin{macrocode}
%%% draws a normal line from $ to $$, ending with a closed arrowhead at $$
def drawnormalCA(suffix $, $$) =
  draw z$--z$$;
  drawCA($, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalthreeCA}
% Draw a straight normal thickness line between the three points |z$|, |z@| and |z$$|, 
% ending in a closed arrowhead at |z$$|.
%    \begin{macrocode}
%%% draws the normal line $--@--$$, ending in a black arrowhead at $$
def drawnormalthreeCA(suffix $, @, $$) =
  draw z$--z@--z$$;
  drawCA(@, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalfourCA}
% Draw a straight normal thickness line between the four points |z$|, |z@|, |z@@| and |z$$|, 
% ending in a closed arrowhead at |z$$|.
%    \begin{macrocode}
%%% draws the normal line $--@--@@--$$, ending in a black arrowhead at $$
def drawnormalfourCA(suffix $, @, @@, $$) =
  draw z$--z@--z@@--z$$;
  drawCA(@@, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalF}
% Draw a straight normal thickness line between the two points |z$| and |z$$|,
% ending with a fanin, length |gfl| and base width |gfb|,
% at |z$$|.
%    \begin{macrocode}
%%% draws a normal line from $ to $$, ending with a fanin at $$
def drawnormalF(suffix $, $$) =
  draw z$--z$$;
  drawF($, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalFO}
% Draw a straight normal thickness line between the two points |z$| and |z$$|,
% ending with a fanin, length |gfl| and base width |gfb|,
% at |z$| and an open circle, diameter |dotdiam|, at |z$$|.
%    \begin{macrocode}
%%% draws a normal line from $ to $$, with a fanin at $ and an open circle at $$
def drawnormalFO(suffix $, $$) =
  draw z$--z$$;
  drawO($, $$); drawF($$, $);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawthick}
% Draw a straight thick line between the two points |z$| and |z$$|
%    \begin{macrocode}
%%% draws a thick line from $ to $$.
def drawthick(suffix $, $$) =
  pickup thickpen;
  draw z$--z$$;
  pickup normalpen;
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawthickO}
% Draw a straight thick line between the two points |z$| and |z$$|,
% ending with an open circle, diameter |dotdiam|, at |z$$|.
%    \begin{macrocode}
%%% draws a thick line from $ to $$, ending in a circle diameter dotdiam at $$
def drawthickO(suffix $, $$) =
  pickup thickpen;
  draw z$--z$$;
  drawO($, $$);
  pickup normalpen;
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawthickOO}
% Draw a straight thick line between the two points |z$| and |z$$|,
% ending with open circles, diameter |dotdiam|, at |z$| and |z$$|.
% \changes{v1.5}{2003/07/31}{Added thickpen to drawthickOO}
%    \begin{macrocode}
%%% draws a thick line from $ to $$, ending in circles diameter dotdiam at $ and $$
def drawthickOO(suffix $, $$) =
  pickup thickpen;
  draw z$--z$$;
  drawO($, $$); drawO($$, $);
  pickup normalpen;
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{smooth}
% Rounds the join at |z@| between the two straight lines |z$--z@--z$$|.
% The radius of the circular arc is |smoothrad|. The code employs the
% same technique as used for putting dots, etc., at the end of a line.
% However, in this case we `undraw' the sharp corner before drawing the
% arc.
% \changes{v1.3}{2000/05/22}{Added smooth routine}
%    \begin{macrocode}
%%% replaces the sharp corner on $--@--$$ with a circular arc radius smoothrad
def smooth(suffix $, @, $$) =
  begingroup
  save v_, c_, l, p;
  pair v_, v_', c_, c_';
  path p;
  v_ := z@-z$;
  l := (xpart v_)++(ypart v_);     % length of $--@
  c_ := (smoothrad/l)[z@,z$];      % start of arc on $--@
  v_' := z$$-z@;
  l := (xpart v_')++(ypart v_');   % length of @--$$
  c_' := (smoothrad/l)[z@,z$$];    % end of arc on @--$$
  undraw c_--z@--c_';              % blank original join
  draw c_{v_}..{v_'}c_';           % draw the arc
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{smoothtwo}
% Rounds the joins at |z@| and |z@@| between the three straight lines 
% |z$--z@--z@@--z$$|.
% The radius of the circular arc is |smoothrad|. 
% \changes{v1.3}{2000/05/22}{Added smoothtwo routine}
%    \begin{macrocode}
%%% replaces the sharp corners on $--@--@@--$$ with a circular arc radius smoothrad
def smoothtwo(suffix $, @, @@, $$) =
  smooth($, @, @@); smooth(@, @@, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{smoothdash}
% Rounds the join at |z@| between the two dashed straight lines |z$--z@--z$$|.
% The radius of the circular arc is |smoothrad|. 
% \changes{v1.3}{2000/05/22}{Added smoothdash routine}
%    \begin{macrocode}
%%% replaces the sharp corner on the dashed lines $--@--$$ 
%%% with a circular arc radius smoothrad
def smoothdash(suffix $, @, $$) =
  begingroup
  save v_, c_, l, p;
  pair v_, v_', c_, c_';
  path p;
  v_ := z@-z$;
  l := (xpart v_)++(ypart v_);     % length of $--@
  c_ := (smoothrad/l)[z@,z$];      % start of arc on $--@
  v_' := z$$-z@;
  l := (xpart v_')++(ypart v_');   % length of @--$$
  c_' := (smoothrad/l)[z@,z$$];    % end of arc on @--$$
  undraw c_--z@--c_';              % blank original join
  draw c_{v_}..{v_'}c_' dashes;    % draw the dashed arc
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{smoothdots}
% Rounds the join at |z@| between the two dotted straight lines |z$--z@--z$$|.
% The radius of the circular arc is |smoothrad|. 
% \changes{v1.3}{2000/05/22}{Added smoothdots routine}
%    \begin{macrocode}
%%% replaces the sharp corner on the dotted line $--@--$$ 
%%% with a circular arc radius smoothrad
def smoothdots(suffix $, @, $$) =
  begingroup
  save oldpen;
  pen oldpen; oldpen := currentpen;
  save v_, c_, l, p;
  pair v_, v_', c_, c_';
  path p;
  v_ := z@-z$;
  l := (xpart v_)++(ypart v_);     % length of $--@
  c_ := (smoothrad/l)[z@,z$];      % start of arc on $--@
  v_' := z$$-z@;
  l := (xpart v_')++(ypart v_');   % length of @--$$
  c_' := (smoothrad/l)[z@,z$$];    % end of arc on @--$$
  undraw c_--z@--c_';              % blank original join
  pickup dotspen;
  draw c_{v_}..{v_'}c_' dots;      % draw the dotted arc
  pickup oldpen;
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
%
% \subsection{Box drawing routines}
%
% The box drawing routines take as an argument the suffix (|$|) of the 
% left-hand bottom corner point of the box, and normally the length and
% height of the box. There is normally also a text argument that gets
% typeset at the `center' of the box. The coordinates of the box corners
% are calculated (|z$bl|, |z$br|, |z$tr| and |z$tl|). The midpoints of
% the sides of the box (|z$bm|, |z$mr|, |z$tm|, |z$ml|) are calculated
% as well. The text `center' of the box is |z$c|, while the geometric
% center of the box will be at the intersection point of the lines
% |z$bm--z$tm| and |z$ml--z$mr|. See \fref{fig:boxpoints} for an
% illustration.
%
%
% \begin{routine}{drawSCHEMA}
% |drawSCHEMA(|\meta{suffix}, \meta{l}, \meta{h}|)(|\meta{name}|)| draws
% a SCHEMA box.
%    \begin{macrocode}
%%% draws a schema box, bottom left at $, length l, height h
def drawSCHEMA(suffix $)(expr l, h)(text str) =
  rectpoints($, l, h);
  x$c = 1/2[x$ml, x$mr];
  y$c = 1/2[y$ml, y$tl];
  draw z$bl--z$br--z$tr--z$tl--cycle;  % outer box
  draw z$ml--z$mr;                     % dividing line
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawSDT}
% |drawSDT(|\meta{suffix}|)(|\meta{name}|)| draws
% a simple data type box of length |sdtbl| and height |sdtbh|.
%    \begin{macrocode}
% drawSDT($)(name)
% draw a simple data type box, bottom left at $
def drawSDT(suffix $)(text str) =
  rectpoints($, sdtbl, sdtbh);
  z$ti = (x$tr-sdtbs, y$tr);
  z$bi = (x$ti, y$br);
  z$c = 1/2[z$bl,z$ti];
  draw z$bl--z$br--z$tr--z$tl--cycle;
  draw z$bi--z$ti;
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawASDT}
% |drawASDT(|\meta{suffix}, \meta{l}, \meta{h}|)(|\meta{name}|)| draws
% a simple data type box.
%    \begin{macrocode}
% drawASDT($, l, h)(name)
% draw a simple data type box, bottom left at $, length l, height h
def drawASDT(suffix $)(expr l, h)(text str) =
  rectpoints($, l, h);
  z$ti = (x$tr-sdtbs, y$tr);
  z$bi = (x$ti, y$br);
  z$c = 1/2[z$bl,z$ti];
  draw z$bl--z$br--z$tr--z$tl--cycle;
  draw z$bi--z$ti;
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% The |drawNAME(|\meta{suffix}|)| routines draw a simple data type
% box of the given name using the applicable lengths and heights.
% \begin{routine}{drawBINARY}
% \begin{routine}{drawBOOLEAN}
% \begin{routine}{drawCOMPLEX}
% \begin{routine}{drawEXPRESSION}
%    \begin{macrocode}
def drawBINARY(suffix $) =  drawASDT($)(sdtbl, sdtbh)("BINARY"); 
  enddef;
def drawBOOLEAN(suffix $) = drawASDT($)(sdtbl, sdtbh)("BOOLEAN"); 
  enddef;
def drawCOMPLEX(suffix $) = drawASDT($)(sdtbl, sdtbh)("COMPLEX"); 
  enddef;
def drawEXPRESSION(suffix $) = drawASDT($)(sdtbel, sdtbeh)("EXPRESSION"); 
  enddef;
%    \end{macrocode}
% \end{routine}
% \end{routine}
% \end{routine}
% \end{routine}
%
% \begin{routine}{drawGENERIC}
% \begin{routine}{drawINTEGER}
% \begin{routine}{drawLOGICAL}
% \begin{routine}{drawNUMBER}
%    \begin{macrocode}
def drawGENERIC(suffix $) = drawASDT($)(sdtbl, sdtbh)("GENERIC"); 
  enddef;
def drawINTEGER(suffix $) = drawASDT($)(sdtbl, sdtbh)("INTEGER"); 
  enddef;
def drawLOGICAL(suffix $) = drawASDT($)(sdtbl, sdtbh)("LOGICAL"); 
  enddef;
def drawNUMBER(suffix $) =  drawASDT($)(sdtbl, sdtbh)("NUMBER"); 
  enddef;
%    \end{macrocode}
% \end{routine}
% \end{routine}
% \end{routine}
% \end{routine}
%
% \begin{routine}{drawREAL}
% \begin{routine}{drawSTRING}
%    \begin{macrocode}
def drawREAL(suffix $) =    drawASDT($)(sdtbl, sdtbh)("REAL"); 
  enddef;
def drawSTRING(suffix $) =  drawASDT($)(sdtbl, sdtbh)("STRING"); 
  enddef;

%    \end{macrocode}
% \end{routine}
% \end{routine}
%
% \begin{routine}{drawENUM}
% |drawENUM(|\meta{suffix}, \meta{l}, \meta{h}|)(|\meta{name}|)| draws
% an ENUMERATION type box.
%    \begin{macrocode}
% drawENUM($, l, h)(name)
%%% draw an enumeration type box, bottom left at $, length l, height h
def drawENUM(suffix $)(expr l, h)(text str) =
  rectpoints($, l, h);
  z$ti = (x$tr-sdtbs, y$tr);
  z$bi = (x$ti, y$br);
  z$c = 1/2[z$bl,z$ti];
  draw z$bl--z$br--z$tr--z$tl--cycle dashes;
  draw z$bi--z$ti dashes;
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawSELECT}
% |drawSELECT(|\meta{suffix}, \meta{l}, \meta{h}|)(|\meta{name}|)| draws
% a SELECT type box.
%    \begin{macrocode}
% drawSELECT($, l, h)(name)
%%% draw a select type box, bottom left at $, length l, height h
def drawSELECT(suffix $)(expr l, h)(text str) =
  rectpoints($, l, h);
  z$ti = (x$tl+sdtbs, y$tl);
  z$bi = (x$ti, y$bl);
  z$c = 1/2[z$br,z$ti];
  draw z$bl--z$br--z$tr--z$tl--cycle dashes;
  draw z$bi--z$ti dashes;
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawTYPE}
% |drawTYPE(|\meta{suffix}, \meta{l}, \meta{h}|)(|\meta{name}|)| draws
% a user-defined TYPE type box.
%    \begin{macrocode}
% drawTYPE($, l, h)(name)
%%% draw a simple user defined TYPE box, bottom left at $, length l, height h
def drawTYPE(suffix $)(expr l, h)(text str) =
  rectpoints($, l, h);
  z$c = 1/2[z$bl,z$tr];
  draw z$bl--z$br--z$tr--z$tl--cycle dashes;
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawENT}
% |drawENT(|\meta{suffix}, \meta{l}, \meta{h}|)(|\meta{name}|)| draws
% an ENTITY box.
%    \begin{macrocode}
% drawENT($, l, h)(name)
%%% draw an entity  box, bottom left at $, length l, height h
def drawENT(suffix $)(expr l, h)(text str) =
  rectpoints($, l, h);
  z$c = 1/2[z$bl,z$tr];
  draw z$bl--z$br--z$tr--z$tl--cycle;
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawOB}
% |drawOB(|\meta{suffix}, \meta{l}, \meta{h}|)| draws
% a rectangular box with rounded corners (an \ExpressG{} oval box).
%    \begin{macrocode}
% drawOB($, l, h)
% draw an oval box, bottom left at $, length l, height h
def drawOB(suffix $)(expr l, h) =
  save rad;
  numeric rad; rad := h/2;
  rectpoints($, l, h);
  z$cl = 1/2[z$bl, z$tl];
  z$cr = 1/2[z$br, z$tr];
  z$bli = (x$bl+rad, y$bl);
  z$tli = (x$bli, y$tl);
  z$bri = (x$br-rad, y$br);
  z$tri = (x$bri, y$tr);
  z$c = 1/2[z$bl,z$tr];
  draw z$bli--z$bri..z$cr..z$tri--z$tli..z$cl..cycle;
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawPREF}
% |drawPREF(|\meta{suffix}, \meta{l}, \meta{h}|)(|\meta{name}|)| draws
% a page reference oval box.
%    \begin{macrocode}
% drawPREF($, l, h)(name)
%%% draw a page reference box oval, bottom left at $, length l, height h
def drawPREF(suffix $)(expr l, h)(text str) =
  drawOB($, l, h);
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
%
% \begin{routine}{drawISU}
% |drawISU(|\meta{suffix}, \meta{l}, \meta{h}|)(|\meta{name}|)| draws
% an interschema USE box.
%    \begin{macrocode}
% drawISU($, l, h)(name)
%%% draw an interschema USE box, bottom left at $, length l, height h
def drawISU(suffix $)(expr l, h)(text str) =
  save quarter;
  numeric quarter; quarter := h/4;
  rectpoints($, l, h);
  z$o = (x$, y$+quarter);
  drawOB($o, l, 2quarter);
  z$c = 1/2[z$bl,z$tr];
  label(str, z$c);
  draw z$bl--z$br--z$tr--z$tl--cycle;
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawISUR}
% |drawISUR(|\meta{suffix}, \meta{l}, \meta{h}|)(|\meta{name}|)(|\meta{rename}|)| draws
% an interschema USE RENAME box.
% \changes{v1.5}{2003/07/31}{Changed rnm to rname in drawISUR}
%    \begin{macrocode}
% drawISUR($, l, h)(name)(rename)
%%% draw an interschema USE RENAME box, bottom left at $, length l, height h
def drawISUR(suffix $)(expr l, h)(text str, rname) =
  save third;
  numeric third; third := h/3;
  rectpoints($, l, h);
  z$o = (x$, y$+third);
  drawOB($o, l, third);
  z$c = 1/2[z$bl, z$tr];
  label(str, z$c);
  z$rnm = 1/2[z$bl,(x$br,y$br+third)];
  draw z$bl--z$br--z$tr--z$tl--cycle;
  label(rname, z$rnm);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawISR}
% |drawISR(|\meta{suffix}, \meta{l}, \meta{h}|)(|\meta{name}|)| draws
% an interschema RERERENCE box.
%    \begin{macrocode}
% drawISR($, l, h)(name)
%%% draw an interschema REFERENCE box, bottom left at $, length l, height h
def drawISR(suffix $)(expr l, h)(text str) =
  save quarter;
  numeric quarter; quarter := h/4;
  rectpoints($, l, h);
  z$o = (x$, y$+quarter);
  drawOB($o, l, 2quarter);
  z$c = 1/2[z$bl,z$tr];
  label(str, z$c);
  draw z$bl--z$br--z$tr--z$tl--cycle dashes;
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawISRR}
% |drawISRR(|\meta{suffix}, \meta{l}, \meta{h}|)(|\meta{name}|)(|\meta{rename}|)| draws
% an interschema REFERENCE RENAME box.
% \changes{v1.5}{2003/07/31}{Changed rnm to rname in drawISSR} 
%    \begin{macrocode}
% drawISRR($, l, h)(name)(rename)
%%% draw an interschema REFERENCE RENAME box, bottom left at $, length l, height h
def drawISRR(suffix $)(expr l, h)(text str, rname) =
  save third;
  numeric third; third := h/3;
  rectpoints($, l, h);
  z$o = (x$, y$+third);
  drawOB($o, l, third);
  z$c = 1/2[z$bl,z$tr];
  label(str, z$c);
  z$rnm = 1/2[z$bl,(x$br,y$br+third)];
  draw z$bl--z$br--z$tr--z$tl--cycle dashes;
  label(rname, z$rnm);
enddef;

%    \end{macrocode}
% \end{routine}
%
%
% \begin{routine}{drawLEVENT}
% |drawLEVENT(|\meta{suffix}, \meta{l}, \meta{h}|)(|\meta{name}|)| draws
% a Local EVENT box, with side slope |eventslope|.
%    \begin{macrocode}
% drawLEVENT($, l, h)(name)
%%% draw a Local EVENT box, bottom left at $, length l, height h
def drawLEVENT(suffix $)(expr l, h)(text str) =
  rhompoints($, l, h, eventslope);
  z$c = 1/2[z$ml,z$mr];
  draw z$bl--z$br--z$tr--z$tl--cycle;
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawGEVENT}
% |drawGEVENT(|\meta{suffix}, \meta{l}, \meta{h}|)(|\meta{name}|)| draws
% a Global EVENT box, with side slope |eventslope|.
%    \begin{macrocode}
% drawGEVENT($, l, h)(name)
%%% draw a Global EVENT box, bottom left at $, length l, height h
def drawGEVENT(suffix $)(expr l, h)(text str) =
  rhompoints($, l, h, eventslope);
  z$c = 1/2[z$ml,z$mr];
  pickup thickpen;
  draw z$bl--z$br--z$tr--z$tl--cycle;
  pickup normalpen;
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
%
%
% \begin{routine}{drawcirclebox}
% |drawcirclebox(|\meta{suffix}, \meta{diam}|)(|\meta{name}|)| draws
% a circle, center |zsuffix| and diameter \meta{diam}, around \meta{name}.
%    \begin{macrocode}
% drawcirclebox($, diam)(name)
%%% draw a circled name, diameter diam centered at $
def drawcirclebox(suffix $)(expr diam)(text str) =
  circpoints($, diam);
  draw z$bl..z$bm..z$br..z$mr..z$tr..z$tm..z$tl..z$ml..cycle;
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \subsection{Extra BLA variables and routines}
%
%    Some extra facilities are provided for assistance in drawing 
% non-\ExpressG{} BLA diagrams, such as flow charts, IDEF diagrams
%  or UML structure diagrams.
%
% \begin{variable}{gdl}
% \begin{variable}{gdb}
% |gdl| is the length of a diamond line end style and |gdb| is the base 
% width. 
%    \begin{macrocode}
%%% length and base width of diamond line end styles
newinternal gdl, gdb;
numeric gdl, gdb;
gdl := 2defaultgal;
gdb := 0.75defaultgab;

%    \end{macrocode}
% \end{variable}
% \end{variable}
%
% \begin{routine}{ellipsepoints}
% \changes{v1.2}{1999/11/15}{Added ellipsepoints routine}
% Calculates the points on an ellipse, center at |z$| with horizontal 
% diameter |l| and vertical diameter |h|. It does \emph{not} calculate
% the center point. 
%    \begin{macrocode}
def ellipsepoints(suffix $)(expr l, h) =
  save epp, move;
  path epp;
  pair move;
  z$ml=(x$-l/2, y$); z$mr=(x$ml+l,y$);
  z$tm=(x$, y$+h/2); z$bm=(x$, y$tm-h);
  move = 1/2[z$ml,z$mr];
  epp = fullcircle scaled h xscaled (l/h) shifted move;
  z$tr = point 1.2 of epp;
  z$tl = point 2.8 of epp;
  z$bl = point 5.2 of epp;
  z$br = point 6.8 of epp;
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawDCA}
% Draw double closed arrowheads, each length |gal| and base 
% width |gab|, at end of vector from |z$| to |z$$|.
% \changes{v1.4}{2000/07/10}{Added drawDCA}
%    \begin{macrocode}
%%% draws double closed arrowheads at end of vector from $ to $$
def drawDCA(suffix $, $$) =
  begingroup
  save v_, c_, v_u, c_t, c_b, l, hb, p;
  pair v_, c_, v_u, c_t, c_b;
  path p[];
  numeric l, hb;
  hb := gab/2;
  v_ := z$-z$$;
  l := (xpart v_)++(ypart v_);  % length of the line
  c_ := (gal/(l))[z$$,z$];      % base of arrowhead
  v_u := unitvector v_;
  c_t := c_ shifted (-hb*(ypart v_u), hb*(xpart v_u));
  c_b - c_ = c_ - c_t;
  p1 := c_b--z$$--c_t--cycle;
  filldraw p1;
  p2 := p1 shifted ((xpart c_ - x$$), (ypart c_ - y$$));
  filldraw p2;
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawOD}
% Draw an open diamond, length |gdl| and base width |gdb|,
% at end of vector from |z$| to |z$$|.
%    \begin{macrocode}
%%% draws an open diamond at end of vector from $ to $$
def drawOD(suffix $, $$) =
  begingroup
  save v_, c_, c__, v_u, c_t, c_b, l, hb, p;
  pair v_, c_, c__, v_u, c_t, c_b;
  numeric l, hb;
  path p;
  hb := gdb/2;
  v_ := z$-z$$;
  l := (xpart v_)++(ypart v_);  % length of the line
  c_ := (gdl/(2l))[z$$,z$];     % base of diamond
  c__ := (gdl/(l))[z$$,z$];     % interior tip of diamond
  v_u := unitvector v_;
  c_t := c_ shifted (-hb*(ypart v_u), hb*(xpart v_u));
  c_b - c_ = c_ - c_t;
  p = c_b--z$$--c_t--c__--cycle;
  unfill p;
  draw p; draw p;
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawCD}
% Draw a closed diamond, length |gdl| and base width |gdb|,
% at end of vector from |z$| to |z$$|.
%    \begin{macrocode}
%%% draws a closed diamond at end of vector from $ to $$
def drawCD(suffix $, $$) =
  begingroup
  save v_, c_, c__, v_u, c_t, c_b, l, hb, p;
  pair v_, c_, c__, v_u, c_t, c_b;
  numeric l, hb;
  path p;
  hb := gdb/2;
  v_ := z$-z$$;
  l := (xpart v_)++(ypart v_);  % length of the line
  c_ := (gdl/(2l))[z$$,z$];     % base of diamond
  c__ := (gdl/(l))[z$$,z$];     % interior tip of diamond
  v_u := unitvector v_;
  c_t := c_ shifted (-hb*(ypart v_u), hb*(xpart v_u));
  c_b - c_ = c_ - c_t;
  p = c_b--z$$--c_t--c__--cycle;
  filldraw p;
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
%
% \begin{routine}{drawdashA}
% Draw a straight dashed line between the two points |z$| and |z$$|,
% ending with an arrowhead, length |gal| and base width |gab|,
% at |z$$|.
%    \begin{macrocode}
%%% draws a dashed line from $ to $$, ending with an arrowhead at $$
def drawdashA(suffix $, $$) =
  draw z$--z$$ dashes;
  drawA($, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdashOA}
% Draw a straight dashed line between the two points |z$| and |z$$|,
% ending with an open arrowhead, length |gal| and base width |gab|,
% at |z$$|.
%    \begin{macrocode}
%%% draws a dashed line from $ to $$, ending with an open arrowhead at $$
def drawdashOA(suffix $, $$) =
  draw z$--z$$ dashes;
  drawOA($, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalDCA}
% Draw a straight normal line between the two points |z$| and |z$$|,
% ending with double closed arrowheads, each length |gal| and base 
% width |gab|, at |z$$|.
% \changes{v1.2}{1999/11/15}{Added drawnormalDCA}
%    \begin{macrocode}
%%% draws a normal line from $ to $$, ending with double closed arrowheads at $$
def drawnormalDCA(suffix $, $$) =
  draw z$--z$$;
  drawDCA($, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalOD}
% Draw a straight normal thickness line between the two points |z$| and |z$$|,
% ending with an open diamond, length |gdl| and base width |gdb|,
% at |z$$|.
%    \begin{macrocode}
%%% draws a normal line from $ to $$, ending with an open diamond at $$
def drawnormalOD(suffix $, $$) =
  draw z$--z$$;
  drawOD($, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawnormalCD}
% Draw a straight normal thickness line between the two points |z$| and |z$$|,
% ending with a closed diamond, length |gdl| and base width |gdb|,
% at |z$$|.
%    \begin{macrocode}
%%% draws a normal line from $ to $$, ending with a closed diamond at $$
def drawnormalCD(suffix $, $$) =
  draw z$--z$$;
  drawCD($, $$);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdashcircle}
% \changes{v1.2}{1999/11/15}{Added drawdashcircle}
% Draw a normal thickness dashed open circle, center |z$|, diameter |diam|.
%    \begin{macrocode}
%%% draws an open dashed circle, center z$, diameter diam
def drawdashcircle(suffix $)(expr diam) =
  circpoints($, diam);
  draw z$bl..z$bm..z$br..z$mr..z$tr..z$tm..z$tl..z$ml..cycle dashes;
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawcircleA}
% \changes{v1.1}{1999/10/30}{Added drawcircleA routine}
% Draw a normal thickness open circle, center |z$|, diameter |diam|, and with
% a counterclockwise pointing arrow at the topmost point. The arrow has
% length |gal| and base width |gab|.
%    \begin{macrocode}
%%% draws an open circle, center z$, diameter diam, with an arrow at the top
def drawcircleA(suffix $)(expr diam) =
  circpoints($, diam);
  begingroup
  save c_, c_t, c_b, hb;
  pair c_, c_t, c_b;
  numeric hb;
  hb := gab/2;
  c_ := z$tm shifted (gal*right);  % base of arrowhead
  c_t := c_ shifted (hb*up);
  c_b := c_ shifted (hb*down);
  draw z$bl..z$bm..z$br..z$mr..z$tr..z$tm..z$tl..z$ml..cycle;
  draw c_t--z$tm--c_b;
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawDot}
% Draw a black dot, center |z$|, diameter |diam|.
% \changes{v1.6}{2004/02/29}{Added drawDot}
%    \begin{macrocode}
%%% draws black dot, center z$, diameter diam
def drawDot(suffix $)(expr diam) =
  begingroup
    save p;
    path p;
    p := fullcircle scaled diam shifted z$;
    filldraw p;
  endgroup
enddef;

%    \nd{macrocode}
% \end{routine}
%
% \begin{routine}{drawCircledDot}
% Draw a black dot, center |z$|, surrounded by a circle, overall 
% diameter |diam|.
% \changes{v1.6}{2004/02/29}{Added drawCircledDot}
%    \begin{macrocode}
%%% draws black dot surrounded by a circle, center z$, diameter diam
def drawCircledDot(suffix $)(expr diam) =
  begingroup
    save l_, p;
    numeric l_;
    path p[];
    l_ := 5/7diam;
    p1 := fullcircle scaled diam shifted z$;
    unfill p1;
    draw p1;
    p2 := fullcircle scaled l_ shifted z$;
    filldraw p2;
  endgroup
enddef;

%    \nd{macrocode}
% \end{routine}
%
%
% \begin{routine}{drawcardbox}
% \changes{v1.1}{1999/10/30}{Added drawcardbox routine}
%  Draw a rectangular box that has its top righthand corner folded down.
% |m| is the height/length of the fold.
%    \begin{macrocode}
def drawcardbox(suffix $)(expr l, h, m)(text str) =
  rectpoints($, l, h);
  begingroup
  save c;
  pair c[];
  c1 = (x$tr-m, y$tr);
  c3 = (x$tr, y$tr-m);
  c2 = (xpart c1, ypart c3);
  draw z$bl--z$br--c3--c1--z$tl--cycle;
  draw c1--c2--c3;
  endgroup;
  z$c = 1/2[z$ml,z$mr];
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdiamondbox}
% Draw a diamond shaped box. Like circles, the box is located at its 
% center point and
% not at the bottom left corner (see \fref{fig:diamondpoints}).
%
%    \begin{macrocode}
def drawdiamondbox(suffix $)(expr l, h)(text str) =
  z$ml=(x$-l/2, y$); z$tm=(x$, y$+h/2);
  z$mr=(x$ml+l, y$); z$bm=(x$, y$tm-h);
  z$bl=1/2[z$ml,z$bm];
  z$br=1/2[z$bm,z$mr];
  z$tr=1/2[z$mr,z$tm];
  z$tl=1/2[z$tm,z$ml];
  z$c=z$;
  draw z$ml--z$bm--z$mr--z$tm--cycle;
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawtwodiamondbox}
% \changes{v1.2}{1999/11/15}{Added drawtwodiamondbox routine}
% Draw a diamond shaped box with a smaller diamond inside. 
%
%    \begin{macrocode}
def drawtwodiamondbox(suffix $)(expr l, h, mrg)(text str) =
  z$ml=(x$-l/2, y$); z$tm=(x$, y$+h/2);
  z$mr=(x$ml+l, y$); z$bm=(x$, y$tm-h);
  z$bl=1/2[z$ml,z$bm];
  z$br=1/2[z$bm,z$mr];
  z$tr=1/2[z$mr,z$tm];
  z$tl=1/2[z$tm,z$ml];
  z$c=z$;
  begingroup
  save v_, p, tl, sf;
  pair v_;
  numeric tl, sf;
  path p[];
  p1 = z$ml--z$bm--z$mr--z$tm--cycle;
  draw p1;
  v_ := z$c-z$tr;
  tl := (xpart v_)++(ypart v_);
  sf = 1.0 - mrg/tl;
  p2 = p1 shifted -z$c scaled sf shifted z$c;
  draw p2;
  endgroup;
  label(str, z$c);

enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdoublerectangle}
% Draw a double box where |tf| is the fraction of the height of the 
% top portion. The ends of the dividing line are |z$tfl| and |z$tfr|.
% The text centers are |z$ct| and |z$cb| for the top and bottom portions.
%    \begin{macrocode}
def drawdoublerectangle(suffix $)(expr l, h, tf) =
  rectpoints($, l, h);
  z$tfl=tf[z$tl,z$bl]; z$tfr=tf[z$tr,z$br];
  z$cb=1/2[z$bl,z$tfr];
  z$ct=1/2[z$tfl,z$tr];
  draw z$bl--z$br--z$tr--z$tl--cycle;
  draw z$tfl--z$tfr;
enddef;

%    \end{macrocode}
% \end{routine}
%
%
%
% \begin{routine}{drawtriplerectangle}
% \changes{v1.1}{1999/10/30}{Added drawtriplerectangle routine}
%  Draws a triple box, where |tf| is the fraction of the height for the
% top portion and |bf| is the fraction of the height for the bottom
% portion. Text centers for the three portions are |z$ct|, |z$cm| and |z$cb|
% for the top, middle and bottom portions. The points at the ends of the
% dividing lines are |z$tfl| and |z$tfr| for the top portion
% and |z$bfl| and |z$bfr| for the bottom.
%
%    \begin{macrocode}
def drawtriplerectangle(suffix $)(expr l, h, tf, bf) =
  rectpoints($, l, h);
  z$tfl=tf[z$tl,z$bl]; z$tfr=tf[z$tr,z$br];
  z$bfl=bf[z$bl,z$tl]; z$bfr=bf[z$br,z$tr];
  z$cb=1/2[z$bl,z$bfr];
  z$cm=1/2[z$bfl,z$tfr];
  z$ct=1/2[z$tfl,z$tr];
  draw z$bl--z$br--z$tr--z$tl--cycle;
  draw z$bfl--z$bfr;
  draw z$tfl--z$tfr;
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{hiderectangle}
% Draws an invisible rectangular box of the usual dimensions that 
% covers up anything underneath it.
%    \begin{macrocode}
def hiderectangle(suffix $)(expr l, h) =
  begingroup
  save c;
  pair c[];
  c1=(x$,y$);
  c2=c1+(l,0);
  c3=c1+(l,h);
  c4=c1+(0,h);
  unfilldraw c1--c2--c3--c4--cycle;
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdashboxover}
% Draws a dashed box that covers up anything underneath it.
%    \begin{macrocode}
def drawdashboxover(suffix $)(expr l, h) =
  rectpoints($, l, h);
  hiderectangle($, l, h);
  z$c = 1/2[z$bl,z$tr];
  draw z$bl--z$br--z$tr--z$tl--cycle dashes;
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawindexbox}
% Draws an index box. The main box is |l| by |h| and the small box
% at the top left is |lp| by |hp|. The main box points are the usual
% |z$bl| etc, but the top box points are |z$P.bl| etc. The |str|
% is put at the center (|z$P.c|) of the small box.
%    \begin{macrocode}
def drawindexbox(suffix $)(expr l, h, lp, hp)(text str) =
  rectpoints($, l, h);
  z$c = 1/2[z$bl,z$tr];
  z$P = z$tl;
  rectpoints($P, lp, hp);
  z$P.c = 1/2[z$P.bl, z$P.tr];
  draw z$bl--z$br--z$tr--z$tl--cycle;
  draw z$P.bl--z$P.br--z$P.tr--z$P.tl--cycle;
  label(str, z$P.c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawroundedbox}
% Draws a rectangular box with rounded corners (like the \LaTeX{} |\oval|).
% The box is |l| by |h| and located by the bottom left corner. The
% corners are rounded with a radius of |r|. If the radius is too large for
% the box it is reduced so that at least two opposite sides are semi-circular.
% The |str| is put at the center (|z$c|) of the box.
%    \begin{macrocode}
def drawroundedbox(suffix $)(expr l, h, r)(text str) =
  rectpoints($, l, h);
  begingroup
  save rad;
  numeric rad; rad := r;
  if rad > l/2:
    rad := l/2;
  fi
  if rad > h/2:
    rad := h/2;
  fi
  draw (x$br-rad, y$br){right}..{up}(x$br, y$br+rad)--
       (x$tr, y$tr-rad){up}..{left}(x$tr-rad, y$tr)--
       (x$tl+rad, y$tl){left}..{down}(x$tl, y$tl-rad)--
       (x$bl, y$bl+rad){down}..{right}(x$bl+rad, y$bl)--cycle;
  endgroup;
  z$c = 1/2[z$bl,z$tr];
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawovalbox}
% \changes{v1.1}{1999/10/30}{Added drawovalbox routine}
% Draws an elliptical box with horizontal diameter |l| and vertical diameter
% |h|. The box is located by the center point.
%    \begin{macrocode}
def drawovalbox(suffix $)(expr l, h)(text str) =
  ellipsepoints($, l, h);
  z$c = 1/2[z$ml,z$mr];
  begingroup
  save p;
  path p;
  p = fullcircle scaled h xscaled (l/h) shifted z$c;
  draw p;
  endgroup;
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdashellipse}
% \changes{v1.2}{1999/11/15}{Added drawdashellipse routine}
% Draws a dashed elliptical box with horizontal diameter |l| and vertical diameter
% |h|. The ellipse is located by the center point.
%    \begin{macrocode}
def drawdashellipse(suffix $)(expr l, h) =
  ellipsepoints($, l, h);
  z$c = 1/2[z$ml,z$mr];
  begingroup
  save p;
  path p;
  p = fullcircle scaled h xscaled (l/h) shifted z$c;
  draw p dashes;
  endgroup
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawdrum}
% \changes{v1.3}{2000/05/22}{Added drawdrum routine}
% Draws a drum box with length |l| and height |h|. The top and bottom
% ellipse minor/major diamter ratio id |drumlid|. The text is put at the
% (curved) center of the drum.
%    \begin{macrocode}
def drawdrum(suffix $)(expr l, h)(text str) =
  save vdia; numeric vdia;
  vdia := drumlid*l;                % ellipse vertical diameter
  save pf, ph; path pf, ph;         % full & half ellipse paths

  % points on the basic rectangle
  z$bl = z$;
  z$tr = (x$+l, y$+h);
  z$br = (x$tr, y$);
  z$tl = (x$, y$tr);
  z$ml = 1/2[z$bl,z$tl];
  z$mr = 1/2[z$br,z$tr];
  z$tc = 1/2[z$tl,z$tr];    % center of top rectangle line
  z$bc = 1/2[z$bl,z$br];
  % draw box sides
  draw z$tl--z$bl; draw z$tr--z$br;

  % points on top ellipse
  z$T''' = z$tc;            % ellipse center
  ellipsepoints($T''', l, vdia);
  z$tm  = z$T'''.tm;
  z$tml = z$T'''.tl;
  z$tmr = z$T'''.tr;

  % points on bottom ellipse
  z$B''' = z$bc;
  ellipsepoints($B''', l, vdia);
  z$bm  = z$B'''.bm;
  z$bml = z$B'''.bl;
  z$bmr = z$B'''.br;

  % box center point
  z$c = 1/2[z$T'''.bm, z$B'''.bm];

  % draw top ellipse
  pf = fullcircle scaled vdia xscaled (l/vdia) shifted z$T''';
  draw pf;
  % draw bottom half ellipse
  ph = (halfcircle rotated 180) scaled vdia  xscaled (l/vdia) shifted z$B''';
  draw ph;
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
% \begin{routine}{drawoutputbox}
% Draws an output box. The box is |l| by |h| and the |str|
% is put at the center. The bottom of the box is a wavy line.
%
% This code was supplied by Guy Worthington (see \texttt{comp.text.tex}
% newsgroup thread \textit{Trial, ignore}, January 2004, and in 
% particuar Guy's message of 2004/01/27).
% \changes{v1.6}{2004/02/29}{Added drawoutputbox}
%    \begin{macrocode}
def drawoutputbox(suffix $)(expr l, h)(text str) =
  rectpoints($, l, h);
  begingroup
    save c;
    pair c[];
    c1 = (x$br, y$br+1/8h); % right side of box is shorter
    c2 = (x$bm, y$bm+1/16h);
    % draw the tear
    draw z$bl..c2{dir 45}..c1{dir -15}--z$tr--z$tl--cycle;
  endgroup;
  z$c = (x$bm, 1/2(y$bm+y$tm));
  label(str, z$c);
enddef;

%    \end{macrocode}
% \end{routine}
%
%
% \begin{routine}{drawstickman}
% Draws a full frontal genderless stick figure, inside a rectangle
% |l| by |h|.
% \changes{v1.6}{2004/02/29}{Added drawstickman}
%    \begin{macrocode}
\def drawstickman(suffix $)(expr l, h) =
  rectpoints($,l,h);
  begingroup
    save c;
    pair c[];
    c1 = 8/24[z$bm,z$tm];
    c2 = 15/24[z$bm,z$tm];
    c3 = 18/24[z$bm,z$tm];
    c4 = 1/2[c3,z$tm];
    c6 = (x$bl, ypart(c2));
    c7 = (x$br, ypart(c2));
    draw z$bl--c1--z$br;               % legs
    draw c1--c3;                       % body
    draw c6--c7;                       % arms
    draw c3{right}..z$tm{left}..cycle; % head
  endgroup;
enddef;

%    \end{macrocode}
% \end{routine}
%
%
%
%
% The end of the package
%
%    \begin{macrocode}
%</up>
%    \end{macrocode}
%
%
% \bibliographystyle{alpha}
% \begin{thebibliography}{RBP+91}
%
% \bibitem[EN89]{ELMASRI89}
% R.~Elmasri and S.~B.~Navathe.
% \newblock \emph{Fundamentals of Database Systems}.
% \newblock Benjamin Cummings Publishing Co. Inc., 1989.
%
% \bibitem[GMS94]{GOOSSENS94}
% Michel Goossens, Frank Mittelbach, and Alexander Samarin.
% \newblock \emph{The LaTeX Companion}.
% \newblock Addison-Wesley Publishing Company, 1994.
%
% \bibitem[GRM97]{GOOSSENS97}
% Michel Goossens, Sebastian Rahtz, and Frank Mittelbach.
% \newblock \emph{The LaTeX Graphics Companion}.
% \newblock Addison-Wesley Publishing Company, 1997.
%
% \bibitem[Hob92]{MPOST}
% John D.~Hobby.
% \newblock \emph{A user's manual for MetaPost}.
% \newblock Computing Science Technical Report no. 162, 
%           AT\&T Bell Laboratories, Murray Hill, NJ, April 1992.
%           (Available from CTAN with the MetaPost distribution
%            in \texttt{.../graphics/metapost}).
%
% \bibitem[Hoe98]{HOENIG98}
% Alan Hoenig.
% \newblock \emph{TeX Unbound}.
% \newblock Oxford University Press, 1998.
%
% \bibitem[IDE85]{IDEF1X}
% AFWAL/MLTC, Wright-Patterson AFB, OH.
% \newblock \emph{Integrated Informatiuon Support Systems (IISS), Vol.~V:
%    Common Data Model Subsystem, Part 4: Information Modeling Manual
%    --- IDEF1X}.
% \newblock Report Number: AFWAL--TR--86--4006, Volume~V, 1985.
%
% \bibitem[ISO87]{TR9007}
% ISO TR9007.
% \newblock \emph{Information processing systems ---
%    Concepts and terminology for the conceptual schema and
%    the information base}, 1987.
%
% \bibitem[ISO94]{STEP11}
% ISO 10303-11:1994.
% \newblock \emph{Industrial automation systems and integration ---
%    Product data representation and exchange ---
%    Part~11: Description methods: The EXPRESS language reference manual},
%    1994.
%
% \bibitem[Knu86]{MFONT}
% Donald E~Knuth.
% \newblock \emph{The METAFONTbook}.
% \newblock Addison-Wesley Publishing Company, 1986.
%
% \bibitem[Lam94]{LATEX}
% Leslie Lamport.
% \newblock \emph{\LaTeX: A Document Preperation System}.
% \newblock Second edition. Addison-Wesley Publishing Company, 1994.
%
% \bibitem[NH89]{NIJSSEN89}
% G.~M.~Nijssen and T.~A.~Halpin.
% \newblock \emph{Conceptual Schema and Relational Database Design}.
% \newblock Prentice Hall, 1989.
%
% \bibitem[Rec97]{RECKDAHL97}
% Keith Reckdahl.
% \newblock \emph{Using EPS Graphics in LaTeX2e Documents}.
% \newblock February 1997.
% (Available from CTAN as \texttt{../info/epslatex.ps}).
%
%
% \bibitem[RBP+91]{RUMBAUGH91}
% J.~Rumbaugh, M.~Blaha, W.~Premerlani, F.~Eddy and W.~Lorensen.
% \newblock \emph{Object-Oriented Modeling and Design }
% \newblock Prentice Hall, 1991.
%
% \bibitem[SW94]{EBOOK}
% Douglas A.~Schenck and Peter R.~Wilson.
% \newblock \emph{Information Modeling the EXPRESS Way}.
% \newblock Oxford University Press, 1994.
%           (ISBN 0-19-508714-3)
%
% \bibitem[SM88]{SHLAER88}
% S.~Shlaer and S.~J.~Mellor.
% \newblock \emph{Object-Oriented System Analysis}.
% \newblock Yourdon Press, 1988.
%
% \bibitem[Wil99]{METAFP}
% Peter Wilson.
% \newblock \emph{Some Experiences in Running METAFONT and MetaPost}.
% \newblock November, 1999.
% (Available from CTAN as \texttt{../info/metafp.ps}).
%
% \end{thebibliography}
%
% \textbf{Note:} See \texttt{http://www.tug.org} for information on accessing 
% CTAN --- the Comprehensive \TeX{} Archive Network.
%
%
% \Finale
% \PrintIndex
%
\endinput

%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}