aboutsummaryrefslogtreecommitdiffstats
path: root/include/save_graphf
blob: 8bb9d05eaf790c9c82ba07f288ab3a166caf8ff9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891

###############################################################################
#                                                                             #
#  Lout @Graph package for drawing graphs (Version 1.0)                       #
#                                                                             #
#  Version 1.0 by Jeffrey H. Kingston, December 1993.                         #
#                                                                             #
#  This package draws graphs, the statistical kind not the graph-theoretical  #
#  kind.  See the User's Guide (Advanced Graphics) for user info.             #
#                                                                             #
###############################################################################

@SysInclude { graphf.etc }		# @GraphMath
@SysInclude { lengths }			# @LoutLengths
@SysInclude { coltex }			# @ColourCommand and @TextureCommand
@SysPrependGraphic { graphf.lpg }


def @GraphObj
    left p
    named margin { 0c }
    named adj { 0 0 }
    right x
{
  @BackEnd @Case {
    PostScript @Yield {
	@Null &  # kills previous white space
	@HContract @VContract {
	  //0io ||0io @HContract @VContract 
	  { p "trpoint translate" adj "translate gsave" // "grestore" }
	  @Graphic { //margin ||margin x ||margin //margin }
	  ||0io //0io
	}
    }
# VT: PDF does nothing
    PDF @Yield {
	@Null &  # kills previous white space
	@HContract @VContract {
	  //0io ||0io @HContract @VContract 
	  { "% @GraphObj UNIMPLEMENTED" }
	  @Graphic { //margin ||margin x ||margin //margin }
	  ||0io //0io
	}
    }
  }
}

def @GraphCross
    import @LoutLengths named symbolsize { 0.15f }
{
  @BackEnd @Case {

    PostScript @Yield {
	@HContract @VContract
	{ "newpath 0 0 moveto xsize ysize lineto 0 ysize moveto"
	  "xsize 0 lineto [] 0 setdash stroke"
	}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

    PDF @Yield {
	@HContract @VContract
	{ "n [] 0 d 0 0 m __xsize __ysize l 0 __ysize m __xsize 0 l S"}
	  # uses S because PostScript version does NOT use closepath
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

  }
}

def @GraphPlus
    import @LoutLengths named symbolsize { 0.15f }
{
  @BackEnd @Case {

    PostScript @Yield {
	@HContract @VContract
	{ "newpath xmark 0 moveto xmark ysize lineto 0 ymark moveto"
	  "xsize ymark lineto [] 0 setdash stroke"
	}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

    PDF @Yield {
	@HContract @VContract
	{ "n [] 0 d __xmark 0 m __xmark __ysize l 0 __ymark m __xsize __ymark l S"}
	  # uses S because PostScript version does NOT use closepath
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

  }
}

def @GraphSquare
    import @LoutLengths named symbolsize { 0.15f }
{
  @BackEnd @Case {

    PostScript @Yield {
	@HContract @VContract
	{ "newpath 0 0 moveto xsize 0 lineto xsize ysize lineto"
	  "0 ysize lineto closepath [] 0 setdash stroke"
	}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

    PDF @Yield {
	@HContract @VContract
	{"n [] 0 d 0 0 __xsize __ysize re s"}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

  }
}

def @GraphFilledSquare
    import @LoutLengths named symbolsize { 0.15f }
{
  @BackEnd @Case {

    PostScript @Yield {
	@HContract @VContract
	{ "newpath 0 0 moveto xsize 0 lineto xsize ysize lineto"
	  "0 ysize lineto closepath gsave [] 0 setdash stroke grestore fill"
	}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

    PDF @Yield {
	@HContract @VContract
	{"n [] 0 d 0 0 __xsize __ysize re b"}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

  }
}

def @GraphDiamond
    import @LoutLengths named symbolsize { 0.15f }
{
  @BackEnd @Case {

    PostScript @Yield {
	@HContract @VContract
	{ "newpath 0 ymark moveto xmark 0 lineto xsize ymark lineto"
	  "xmark ysize lineto closepath [] 0 setdash stroke"
	}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

    PDF @Yield {
	@HContract @VContract
	{"n [] 0 d 0 __ymark m __xmark 0 l __xsize __ymark l __xmark __ysize l s"}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

  }
}

def @GraphFilledDiamond
    import @LoutLengths named symbolsize { 0.15f }
{
  @BackEnd @Case {

    PostScript @Yield {
	@HContract @VContract
	{ "newpath 0 ymark moveto xmark 0 lineto xsize ymark lineto"
	  "xmark ysize lineto closepath gsave [] 0 setdash stroke grestore fill"
	}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

    PDF @Yield {
	@HContract @VContract
	{"n [] 0 d 0 __ymark m __xmark 0 l __xsize __ymark l __xmark __ysize l b"
	}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

  }
}

def @GraphCircle
    import @LoutLengths named symbolsize { 0.15f }
{
  @BackEnd @Case {

    PostScript @Yield {
	@HContract @VContract
	{ "newpath xmark ymark xmark 0 360 arc"
	  "[] 0 setdash stroke"
	}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

    PDF @Yield {
	@HContract @VContract
#
# draw a circle whose centre is at (xmark, ymark) and whose radius is xmark units;
#
# for curveto to work, we need to calculate the control points of the Bezier curve
# as well as move the pen to the correct initial point. The circle is drawn as two
# arcs of 180 degrees
#
#   pt0 = (xmark + xmark, ymark)
#   pt1 = (xmark + xmark, ymark + 4/3 * xmark)
#   pt2 = (0, ymark + 4/3 * xmark)
#   pt3 = (0, ymark)
#
#   pt0 = (0, ymark)
#   pt1 = (0, ymark - 4/3 * xmark)
#   pt2 = (xmark + xmark, ymark - 4/3 * xmark)
#   pt3 = (xmark + xmark, ymark)
#
	{"n [] 0 d"
	 "__mul(2, __xmark) __ymark m"
	 "__mul(2, __xmark) __add(__ymark, __div(__mul(4, __xmark), 3))"	# pt1
	 "0 __add(__ymark, __div(__mul(4, __xmark), 3))"			# pt2
	 "0 __ymark c"									# pt3

	 "0 __sub(__ymark, __div(__mul(4, __xmark), 3))"			# pt1
	 "__mul(2, __xmark) __sub(__ymark, __div(__mul(4, __xmark), 3))"	# pt2
	 "__mul(2, __xmark) __ymark c S"						# pt3
	}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

  }
}

def @GraphFilledCircle
    import @LoutLengths named symbolsize { 0.15f }
{
  @BackEnd @Case {
    PostScript @Yield {
	@HContract @VContract
	{ "newpath xmark ymark xmark 0 360 arc"
	  "gsave [] 0 setdash stroke grestore fill"
	}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

    PDF @Yield {
	@HContract @VContract
#
# draw a filled circle whose centre is at (xmark, ymark) and whose radius is xmark units;
#
# for curveto to work, we need to calculate the control points of the Bezier curve
# as well as move the pen to the correct initial point. The circle is drawn as two
# arcs of 180 degrees
#
#   pt0 = (xmark + xmark, ymark)
#   pt1 = (xmark + xmark, ymark + 4/3 * xmark)
#   pt2 = (0, ymark + 4/3 * xmark)
#   pt3 = (0, ymark)
#
#   pt0 = (0, ymark)
#   pt1 = (0, ymark - 4/3 * xmark)
#   pt2 = (xmark + xmark, ymark - 4/3 * xmark)
#   pt3 = (xmark + xmark, ymark)
#
# Note: this is not a strict translation because there is a setdash bracketed by
#   gsave/grestore in the above PostScript but there is no closepath before it;
#   but in PDF, it is not possible to execute a setdash within a path definition.
#
	{"n [] 0 d"
	 "__mul(2, __xmark) __ymark m"
	 "__mul(2, __xmark) __add(__ymark, __div(__mul(4, __xmark), 3))"	# pt1
	 "0 __add(__ymark, __div(__mul(4, __xmark), 3))"			# pt2
	 "0 __ymark c"									# pt3

	 "0 __sub(__ymark, __div(__mul(4, __xmark), 3))"			# pt1
	 "__mul(2, __xmark) __sub(__ymark, __div(__mul(4, __xmark), 3))"	# pt2
	 "__mul(2, __xmark) __ymark c b"						# pt3
	}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

  }
}

def @GraphTriangle
    import @LoutLengths named symbolsize { 0.15f }
{
  @BackEnd @Case {

    PostScript @Yield {
	@HContract @VContract
	{ "newpath 0 0 moveto xsize 0 lineto xmark ysize 1.25 mul lineto"
	  "closepath [] 0 setdash stroke"
	}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

    PDF @Yield {
	@HContract @VContract
	{"n [] 0 d 0 0 m __xsize 0 l __xmark __mul(__ysize, 1.25) l s"}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

  }
}

def @GraphFilledTriangle
    import @LoutLengths named symbolsize { 0.15f }
{
  @BackEnd @Case {

    PostScript @Yield {
	@HContract @VContract
	{ "newpath 0 0 moveto xsize 0 lineto xmark ysize 1.25 mul lineto"
	  "closepath gsave [] 0 setdash stroke grestore fill"
	}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

    PDF @Yield {
	@HContract @VContract
	{"n [] 0 d 0 0 m __xsize 0 l __xmark __mul(__ysize, 1.25) l h b"}
	@Graphic
	{symbolsize @High symbolsize @Wide ^| symbolsize @Wide ^/ symbolsize @High}
    }

  }
}

def @GraphNoLine
    import @PSLengths named dashlength { 0.2f }
    import @PSLengths named linewidth  { "currentlinewidth" }
    import @LoutLengths named length { 1.0f }
{
    length @Wide {}
}

def @GraphSolid
    import @PSLengths named dashlength { 0.2f }
    import @PSLengths named linewidth  { "currentlinewidth" }
    import @LoutLengths named length { 1.0f }
{
  @BackEnd @Case {
    PostScript @Yield {
	@HContract @VContract
	{ "xsize 0 lgraphdict begin newpath 0 0 moveto lineto"
	   "/linewidth" linewidth "def xsize" dashlength "solid end"
	} @Graphic { length @Wide }
    }
# VT: PDF does nothing
    PDF @Yield {
	@HContract @VContract
      { "% @GraphSolid UNIMPLEMENTED" } @Graphic { length @Wide }
    }
  }
}

def @GraphDashed
    import @PSLengths named dashlength { 0.2f }
    import @PSLengths named linewidth  { "currentlinewidth" }
    import @LoutLengths named length { 1.0f }
{
  @BackEnd @Case {
    PostScript @Yield {
	@HContract @VContract
	{ "xsize 0 lgraphdict begin newpath 0 0 moveto lineto"
	   "/linewidth" linewidth "def xsize" dashlength "dashed end"
	} @Graphic { length @Wide }
    }
# VT: PDF does nothing
    PDF @Yield {
	@HContract @VContract
      { "% @GraphDashed UNIMPLEMENTED" } @Graphic { length @Wide }
    }
  }
}

def @GraphDotted
    import @PSLengths named dashlength { 0.2f }
    import @PSLengths named linewidth  { "currentlinewidth" }
    import @LoutLengths named length { 1.0f }
{
  @BackEnd @Case {
    PostScript @Yield {
	@HContract @VContract
	{ "xsize 0 lgraphdict begin newpath 0 0 moveto lineto"
	   "/linewidth" linewidth "def xsize" dashlength "dotted end"
	} @Graphic { length @Wide }
    }
# VT: PDF does nothing
    PDF @Yield {
	@HContract @VContract
      { "% @GraphDotted UNIMPLEMENTED" } @Graphic { length @Wide }
    }
  }
}

def @GraphDotDashed
    import @PSLengths named dashlength { 0.2f }
    import @PSLengths named linewidth  { "currentlinewidth" }
    import @LoutLengths named length { 1.0f }
{
  @BackEnd @Case {
    PostScript @Yield {
	@HContract @VContract
	{ "xsize 0 lgraphdict begin newpath 0 0 moveto lineto"
	   "/linewidth" linewidth "def xsize" dashlength "dotdashed end"
	} @Graphic { length @Wide }
    }
# VT: PDF does nothing
    PDF @Yield {
	@HContract @VContract
      { "% @GraphDotDashed UNIMPLEMENTED" } @Graphic { length @Wide }
    }
  }
}

def @GraphDotDotDashed
    import @PSLengths named dashlength { 0.2f }
    import @PSLengths named linewidth  { "currentlinewidth" }
    import @LoutLengths named length { 1.0f }
{
  @BackEnd @Case {
    PostScript @Yield {
	@HContract @VContract
	{ "xsize 0 lgraphdict begin newpath 0 0 moveto lineto"
	   "/linewidth" linewidth "def xsize" dashlength "dotdotdashed end"
	} @Graphic { length @Wide }
    }
# VT: PDF does nothing
    PDF @Yield {
	@HContract @VContract
      { "% @GraphDotDotDashed UNIMPLEMENTED" } @Graphic { length @Wide }
    }
  }
}

def @GraphDotDotDotDashed
    import @PSLengths named dashlength { 0.2f }
    import @PSLengths named linewidth  { "currentlinewidth" }
    import @LoutLengths named length { 1.0f }
{
  @BackEnd @Case {
    PostScript @Yield {
	@HContract @VContract
	{ "xsize 0 lgraphdict begin newpath 0 0 moveto lineto"
	   "/linewidth" linewidth "def xsize" dashlength "dotdotdotdashed end"
	} @Graphic { length @Wide }
    }
# VT: PDF does nothing
    PDF @Yield {
	@HContract @VContract
      { "% @GraphDotDotDotDashed UNIMPLEMENTED" } @Graphic { length @Wide }
    }
  }
}


export @Data
def @Graph
    named save						{ no		}
    named style						{ frame		}
    import @LoutLengths named width			{ 6.0c		}
    import @LoutLengths named height			{ 4.0c		}
    import @PSLengths named xextra			{ "none"	}
    import @PSLengths named yextra			{ "none"	}
    named xdecreasing					{ no		}
    named ydecreasing					{ no		}
    named leftcaption					{		}
    named rightcaption					{		}
    named abovecaption					{		}
    named belowcaption					{		}
    import @LoutLengths named leftgap			{ 1.5c		}
    import @LoutLengths named rightgap			{ 0.5c		}
    import @LoutLengths named abovegap			{ 0.5c		}
    import @LoutLengths named belowgap			{ 0.5c		}
    named hidecaptions					{ yes		}
    named objects
	named @NW
	    import @GraphMath named at { 0 0 }
	    import @LoutLengths named margin { 0.3f }
	    right x
	{ at @GraphObj adj { "xsize neg ysize" } margin { margin } x }
	named @SW
	    import @GraphMath named at { 0 0 }
	    import @LoutLengths named margin { 0.3f }
	    right x
	{ at @GraphObj adj { "xsize neg 0" } margin { margin } x }
	named @SE
	    import @GraphMath named at { 0 0 }
	    import @LoutLengths named margin { 0.3f }
	    right x
	{ at @GraphObj adj { "0 0" } margin { margin } x }
	named @NE
	    import @GraphMath named at { 0 0 }
	    import @LoutLengths named margin { 0.3f }
	    right x
	{ at @GraphObj adj { "0 ysize" } margin { margin } x }
	named @W
	    import @GraphMath named at { 0 0 }
	    import @LoutLengths named margin { 0.3f }
	    right x
	{ at @GraphObj adj { "xsize neg ysize 2 div" } margin { margin } x }
	named @S
	    import @GraphMath named at { 0 0 }
	    import @LoutLengths named margin { 0.3f }
	    right x
	{ at @GraphObj adj { "xsize neg 2 div 0" } margin { margin } x }
	named @E
	    import @GraphMath named at { 0 0 }
	    import @LoutLengths named margin { 0.3f }
	    right x
	{ at @GraphObj adj { "0 ysize 2 div" } margin { margin } x }
	named @N
	    import @GraphMath named at { 0 0 }
	    import @LoutLengths named margin { 0.3f }
	    right x
	{ at @GraphObj adj { "xsize neg 2 div ysize" } margin { margin } x }
	named @CTR
	    import @GraphMath named at { 0 0 }
	    import @LoutLengths named margin { 0.3f }
	    right x
	{ at @GraphObj adj { "xsize neg 2 div ysize 2 div" } margin {margin} x }
		       {}
    named xorigin  named none { "false" }		{ none		}
    named yorigin  named none { "false" }		{ none		}
    named xlog     named none { "0" }			{ none		}
    named ylog     named none { "0" }			{ none		}
    named points   named none { "none" }		{ none		}
    named pairs    named none { "none" }		{ none		}
    named colour color  named none { "none" }		{ none		}
    named paint    named none { "none" }		{ none		}
    import @TextureImport named texture    		{ solid		}
    named xmin     named none { "false" }		{ none		}
    named xmax     named none { "false" }		{ none		}
    named ymin     named none { "false" }		{ none		}
    named ymax     named none { "false" }		{ none		}
    named xticksep named none { "0" }			{ none		}
    named yticksep named none { "0" }			{ none		}
    named rticksep named none { "0" }			{ none		}
    import @GraphMath named xticks
	named none { "false" }
	named auto { "false" }
	named "@"  { " lgen" }
	named "^"  { "^" }
							{ false		}
    import @GraphMath named yticks
	named none { "false" }
	named auto { "false" }
	named "@"  { " lgen" }
	named "^"  { "^" }
							{ false		}
    import @GraphMath named rticks
	named none { "false" }
	named auto { "false" }
	named "@"  { " lgen" }
	named "^"  { "^" }
							{		}
    import @PSLengths named xticklength			{ 0.5f		}
    import @PSLengths named yticklength			{ 0.5f		}
    import @PSLengths named rticklength			{ 0.5f		}
    named dataformat					{ xandy		}
    import @PSLengths named dashlength			{ 0.2f		}
    import @PSLengths named linewidth			{ "currentlinewidth" }
    import @PSLengths named symbolsize			{ 0.15f		}
    body @Body
@Begin

    def @Above
    {
	abovecaption @Case {
	    ""   @Yield {}
	    else @Yield @OneCol { ||0.5rt clines @Break abovecaption || //abovegap }
	}
    }

    def @Below
    {
	belowcaption @Case {
	    ""   @Yield {}
	    else @Yield @OneCol { //belowgap ||0.5rt clines @Break belowcaption || }
	}
    }

    def @Left
    {
	leftcaption @Case {
	    ""   @Yield {}
	    else @Yield @OneCol @OneRow {
		 { //0.5rt @OneRow clines @Break leftcaption // } ^||leftgap }
	}
    }

    def @Right
    {
	rightcaption @Case {
	    ""   @Yield {}
	    else @Yield @OneCol @OneRow {
		 ||rightgap { //0.5rt @OneRow lines @Break rightcaption // } }
	}
    }

    def @ZeroWidth
	right x
    {
	hidecaptions @Case {
	    { No  no  } @Yield x
	    { Yes yes } @Yield @OneCol { ||0io x ||0io }
	}
    }

    def @AddCaptions right x
    {
	def belowextra
	{
	    xticks @Case {
		""   @Yield { 0i }
		else @Yield { 1.7f }
	    }
	}

	@HContract @VContract
	{
	                       | @Above    |
	    / @ZeroWidth @Left | &0.5rt x  | @ZeroWidth @Right
	    /belowextra        | @Below    |
	}
    }

    export pi e sqrt abs ceiling floor truncate round cos sin atan exp log rand
	   "*" "/" idiv mod "-" "-0" "-1" "-2" "-3" "-4" "-5" "-6" "-7" "-8"
	   "-9" "-." "+" "=" "!=" "<" "<=" ">" ">=" not and xor or
	   if xloop yloop zloop

    def @Data
	named points   named none { "none" }            { points     }
	named pairs    named none { "none" }            { pairs      }
	named colour color   named none { "none" }      { colour     }
	named paint    named none { "none" }            { paint      }
	import @TextureImport named texture    		{ texture    }
	import @PSLengths named dashlength              { dashlength }
	import @PSLengths named linewidth               { linewidth  }
	import @PSLengths named symbolsize              { symbolsize }
	named dataformat                                { dataformat }
	body data
    {
	def pi                                    {     "3.14159"  }
	def e                                     {     "2.71828"  }
	def sqrt     precedence 40        right y {   y "sqrt"     }
	def abs      precedence 40        right y {   y "abs"      }
	def ceiling  precedence 40        right y {   y "ceiling"  }
	def floor    precedence 40        right y {   y "floor"    }
	def truncate precedence 40        right y {   y "truncate" }
	def round    precedence 40        right y {   y "round"    }
	def cos      precedence 40        right y {   y "cos"      }
	def sin      precedence 40        right y {   y "sin"      }
	def atan     precedence 39 left x right y { x y "atan"     }
	def exp      precedence 38 left x right y { x y "exp"      }
	def log      precedence 37 left x right y { x y "dolog"    }
	def rand     precedence 36 left x right y { x y "dorand"   }
	def "*"      precedence 35 left x right y { x y "mul"      }
	def "/"      precedence 34 left x right y { x y "div"      }
	def idiv     precedence 34 left x right y { x y "idiv"     }
	def mod      precedence 34 left x right y { x y "mod"      }
	def "-"      precedence 33 left x right y
	{ x @Case { "" @Yield {y "neg"} else @Yield { x y "sub" } }  }
	def "-0"				    {     "-0"       }
	def "-1"				    {     "-1"       }
	def "-2"				    {     "-2"       }
	def "-3"				    {     "-3"       }
	def "-4"				    {     "-4"       }
	def "-5"				    {     "-5"       }
	def "-6"				    {     "-6"       }
	def "-7"				    {     "-7"       }
	def "-8"				    {     "-8"       }
	def "-9"				    {     "-9"       }
	def "-."				    {     "-."       }
	def "+"      precedence 32 left x right y
	{ x @Case { "" @Yield { y }     else @Yield { x y "add" } }  }
	def "="      precedence 30 left x right y { x y "eq"       }
	def "!="     precedence 30 left x right y { x y "ne"       }
	def "<"      precedence 30 left x right y { x y "lt"       }
	def "<="     precedence 30 left x right y { x y "le"       }
	def ">"      precedence 30 left x right y { x y "gt"       }
	def ">="     precedence 30 left x right y { x y "ge"       }
	def not      precedence 25        right y {   y "not"      }
	def and      precedence 24 left x right y { x y "and"      }
	def xor      precedence 23 left x right y { x y "xor"      }
	def or       precedence 22 left x right y { x y "or"       }
	def if
	    named cond { true }
	    named then {}
	    named else {}
	{ cond "{" then "} {" else "} ifelse" }
	def xloop
	    named from { 0 }
	    named to { 0 }
	    named by { 1 }
	    named do named x { "xval" } {}
	{ from by to "{ /xval exch def" do "} for" }
	def yloop
	    named from { 0 }
	    named to { 0 }
	    named by { 1 }
	    named do named y { "yval" } {}
	{ from by to "{ /yval exch def" do "} for" }
	def zloop
	    named from { 0 }
	    named to { 0 }
	    named by { 1 }
	    named do named z { "zval" } {}
	{ from by to "{ /zval exch def" do "} for" }

	def @IfPt
	   left no
	   right yes
	{
	    points @Case {
		none @Yield no
		else @Yield yes
	    }
	}

	def @Points
	{
	    points @Case {
		none            @Yield ""
		plus            @Yield "plus"
		cross           @Yield "cross"
		square          @Yield "square"
		filledsquare    @Yield "filledsquare"
		diamond         @Yield "diamond"
		filleddiamond   @Yield "filleddiamond"
		circle          @Yield "circle"
		filledcircle    @Yield "filledcircle"
		triangle        @Yield "triangle"
		filledtriangle  @Yield "filledtriangle"
	    }
	}

	def @Pairs
	{
	  pairs @Case {
	    none       @Yield {}
	    solid      @Yield { "linesetup solid"   @IfPt "ilinesetup solid"  }
	    dashed     @Yield { "linesetup cdashed" @IfPt "ilinesetup dashed" }
	    dotted     @Yield { "linesetup dotted"  @IfPt "ilinesetup dotted" }
	    dotdashed  @Yield { "linesetup dotcdashed" @IfPt
				"ilinesetup dotdashed" }
	    dotdotdashed  @Yield { "linesetup dotdotcdashed" @IfPt
				"ilinesetup dotdotdashed" }
	    dotdotdotdashed  @Yield { "linesetup dotdotdotcdashed" @IfPt
				"ilinesetup dotdotdotdashed" }
	    surfacexhisto @Yield { "surfacexhisto" }
	    surfaceyhisto @Yield { "surfaceyhisto" }
	    xhisto        @Yield { "xhisto" }
	    yhisto        @Yield { "yhisto" }
	    filledxhisto  @Yield { "filledxhisto" }
	    filledyhisto  @Yield { "filledyhisto" }
	  }
	}

        def @DataFormat
        {
	    dataformat @Case {
	        xandy     @Yield xandy
	        swapxandy @Yield swapxandy
	        yonly     @Yield yonly
	        xonly     @Yield xonly
	    }
        }

	def @Paint
	{
	    paint @Case {
	       { none no No } @Yield "false"
	       { yes Yes } @Yield "true"
	    }
	}

       "[ [" data "]" dataformat
	  "{" @Points "}"
	  "{" @Pairs "}"
	  "{ /dashlength" dashlength "def"
	  "  /linewidth"  linewidth  "def" @ColourCommand colour
	  "  /symbolsize" symbolsize "def }"
	  "{" @Paint "}"
	  "{" texture "}"
       "]"
    }

    def @Style
    {
	style @Case {
	    frame    @Yield { "framestyle" }
	    none     @Yield { "nonestyle"  }
	    axes     @Yield { "axesstyle"  }
	}
    }

    def @XExtra
    {
	xextra @Case {
	    "none" @Yield {
		style @Case {
	            frame    @Yield { "0.5 cm" }
	            none     @Yield { "0"  }
	            axes     @Yield { "0"  }
		}
	    }
	    else @Yield xextra
	}
    }

    def @YExtra
    {
	yextra @Case {
	    "none" @Yield {
		style @Case {
	            frame @Yield { "0.5 cm" }
	            none  @Yield { "0"  }
	            axes  @Yield { "0"  }
		}
	    }
	    else @Yield yextra
	}
    }

    def @XDecreasing
    {
	xdecreasing @Case {
	    { No no } @Yield "false"
	    { Yes yes } @Yield "true"
	}
    }

    def @YDecreasing
    {
	ydecreasing @Case {
	    { No no } @Yield "false"
	    { Yes yes } @Yield "true"
	}
    }

    @AddCaptions width @Wide height @High
    @BackEnd @Case {
	PostScript @Yield {
	    {
		"grestore"
		save @Case { { Yes yes } @Yield "save" else @Yield {} }
		"gsave xsize ysize lgraphdict begin /ysize exch def /xsize exch def"
		"/alldata [" @Body "] def"
		xticksep "[" xticks "] 0 alldata" xmin xmax xlog
		  @XExtra @XDecreasing xorigin xticklength "xset"
		yticksep "[" yticks "] 1 alldata" ymin ymax ylog
		  @YExtra @YDecreasing yorigin yticklength "yset"

		rticks @Case {

		  ""   @Yield "norset"

		  else @Yield {
		    rticksep "[" rticks "] 1 alldata" ymin ymax ylog
		    @YExtra @YDecreasing yorigin rticklength "rset"
		  }
		}

		"rundata" @Style // "end"
		save @Case { { Yes yes } @Yield "restore" else @Yield {} }
	    } @Graphic { //1rt objects }
	}
	PDF @Yield { {"% @Graph UNIMPLEMENTED"} @Graphic { //1rt objects } }
    }

@End @Graph