(FILECREATED "11-Feb-84 14:54:07" {PHYLUM}<SPEECH>PLOT.SOURCE;2 15396  

      changes to:  (RECORDS PLOTINFO AXIS TRANSLATE)
		   (FNS PLOT.FN PLOT.PATH PLOT \PLOT.XAXIS \PLOT.YAXIS \PLOT.TEXT \PLOT.ADDPATH 
			\PLOT.ADDCURVE \PLOT.TRANSLATE \PLOT.TRANSLATE.POINTS \PLOT.TRANSLATE.POINT 
			\PLOT.TRANSLATE.XCOORD \PLOT.TRANSLATE.YCOORD \PLOT.ROUND \PLOT.FLOOR 
			\PLOT.CEILING \PLOT.MAX \PLOT.MIN))


(PRETTYCOMPRINT PLOTCOMS)

(RPAQQ PLOTCOMS ((RECORDS PLOTINFO AXIS TRANSLATE)
	(FNS PLOT.FN PLOT.PATH PLOT \PLOT.XAXIS \PLOT.YAXIS \PLOT.TEXT \PLOT.ADDPATH \PLOT.ADDCURVE 
	     \PLOT.TRANSLATE \PLOT.TRANSLATE.POINTS \PLOT.TRANSLATE.POINT \PLOT.TRANSLATE.XCOORD 
	     \PLOT.TRANSLATE.YCOORD \PLOT.ROUND \PLOT.FLOOR \PLOT.CEILING \PLOT.MAX \PLOT.MIN)))
[DECLARE: EVAL@COMPILE 

(RECORD PLOTINFO (XAXIS YAXIS PATHS CURVES))

(RECORD AXIS (MIN MAX INCREMENT LABEL FONT))

(RECORD TRANSLATE (MU BU MV BV))
]
(DEFINEQ

(PLOT.FN
  (LAMBDA (FN XMIN XMAX NPOINTS WINDOW)                      (* kbr: "11-Feb-84 14:54")
    (COND
      ((NULL NPOINTS)
	(SETQ NPOINTS 100)))
    (COND
      ((NULL WINDOW)
	(SETQ WINDOW (CREATEW))))
    (PROG (YMIN YMAX K X Y PATH XAXIS YAXIS PLOTINFO)
          (SETQ YMIN MAX.FLOAT)
          (SETQ YMAX MIN.FLOAT)
          (FOR I FROM 0 TO NPOINTS
	     DO (SETQ K (FQUOTIENT I NPOINTS))
		(SETQ X (FPLUS (FTIMES (FDIFFERENCE 1.0 K)
				       XMIN)
			       (FTIMES K XMAX)))
		(SETQ Y (APPLY* FN X))
		(SETQ YMIN (MIN YMIN Y))
		(SETQ YMAX (MAX YMAX Y))
		(PUSH PATH (CREATE POSITION
				   XCOORD ← X
				   YCOORD ← Y)))
          (SETQ PATH (DREVERSE PATH))
          (SETQ XAXIS (CREATE AXIS
			      MIN ← XMIN
			      MAX ← XMAX))
          (SETQ YAXIS (CREATE AXIS
			      MIN ← YMIN
			      MAX ← YMAX))
          (SETQ PLOTINFO (CREATE PLOTINFO
				 XAXIS ← XAXIS
				 YAXIS ← YAXIS
				 PATHS ← (LIST PATH)))
          (PLOT PLOTINFO NIL WINDOW))))

(PLOT.PATH
  (LAMBDA (PATH WINDOW)                                      (* kbr: "11-Feb-84 14:54")
    (COND
      ((NULL WINDOW)
	(SETQ WINDOW (CREATEW))))
    (PROG (XMIN XMAX YMIN YMAX XAXIS YAXIS PLOTINFO)
          (SETQ YMIN MAX.FLOAT)
          (SETQ YMAX MIN.FLOAT)
          (SETQ XMIN (fetch (POSITION XCOORD) of (CAR PATH)))
          (FOR POINT IN PATH
	     DO (SETQ YMIN (MIN (fetch (POSITION YCOORD) of POINT)
				YMIN))
		(SETQ YMAX (MAX (fetch (POSITION YCOORD) of POINT)
				YMAX))
	     FINALLY (SETQ XMAX (fetch (POSITION XCOORD) of POINT)))
          (SETQ XAXIS (CREATE AXIS
			      MIN ← XMIN
			      MAX ← XMAX))
          (SETQ YAXIS (CREATE AXIS
			      MIN ← YMIN
			      MAX ← YMAX))
          (SETQ PLOTINFO (CREATE PLOTINFO
				 XAXIS ← XAXIS
				 YAXIS ← YAXIS
				 PATHS ← (LIST PATH)))
          (PLOT PLOTINFO NIL WINDOW))))

(PLOT
  (LAMBDA (PLOTINFO REGION WINDOW)                           (* kbr: "11-Feb-84 14:54")
    (COND
      ((NULL WINDOW)
	(SETQ WINDOW (CREATEW))))
    (PROG (XAXIS YAXIS TRANSLATE)
          (COND
	    ((NULL REGION)                                   (* Default REGION. *)
	      (SETQ REGION (CREATE REGION
				   LEFT ← 0
				   BOTTOM ← 0
				   WIDTH ← (WINDOWPROP WINDOW 'WIDTH)
				   HEIGHT ← (WINDOWPROP WINDOW 'HEIGHT)))))
                                                             (* Plot PLOTINFO. *)
          (SETQ XAXIS (fetch (PLOTINFO XAXIS) of PLOTINFO))
          (SETQ YAXIS (fetch (PLOTINFO YAXIS) of PLOTINFO))
          (SETQ TRANSLATE (\PLOT.TRANSLATE XAXIS YAXIS REGION))
          (\PLOT.XAXIS XAXIS YAXIS TRANSLATE WINDOW)
          (\PLOT.YAXIS XAXIS YAXIS TRANSLATE WINDOW)
          (FOR PATH IN (fetch (PLOTINFO PATHS) of PLOTINFO) DO (\PLOT.ADDPATH PATH TRANSLATE WINDOW))
          (FOR CURVE IN (fetch (PLOTINFO CURVES) of PLOTINFO) DO (\PLOT.ADDCURVE CURVE TRANSLATE 
										 WINDOW))
                                                             (* Return TRANSLATE in case user would like to call 
							     \PLOT.ADDPATH or \PLOT.ADDCURVE directly.
							     *)
          (RETURN TRANSLATE))))

(\PLOT.XAXIS
  (LAMBDA (XAXIS YAXIS TRANSLATE WINDOW)                     (* kbr: "11-Feb-84 14:54")
    (PROG (XMIN XMAX XINC YMIN YMAX UMIN UMAX VORIGIN UORIGIN U)
          (SETQ XMAX (fetch (AXIS MAX) of XAXIS))
          (SETQ XMIN (fetch (AXIS MIN) of XAXIS))
          (SETQ YMAX (fetch (AXIS MAX) of YAXIS))
          (SETQ YMIN (fetch (AXIS MIN) of YAXIS))
          (COND
	    ((FGREATERP (FTIMES YMIN YMAX)
			0.0)
	      (RETURN)))                                     (* Coordinates of axis endpoints *)
          (SETQ UMIN (\PLOT.ROUND (\PLOT.TRANSLATE.XCOORD XMIN TRANSLATE)))
          (SETQ UMAX (\PLOT.ROUND (\PLOT.TRANSLATE.XCOORD XMAX TRANSLATE)))
          (SETQ UORIGIN (\PLOT.ROUND (\PLOT.TRANSLATE.XCOORD 0.0 TRANSLATE)))
          (SETQ VORIGIN (\PLOT.ROUND (\PLOT.TRANSLATE.YCOORD 0.0 TRANSLATE)))
                                                             (* Extremes *)
          (\PLOT.TEXT XMAX (fetch (AXIS FONT) of XAXIS)
		      (CREATE POSITION
			      XCOORD ← UMAX
			      YCOORD ← VORIGIN)
		      'NNE WINDOW)
          (\PLOT.TEXT 0 (fetch (AXIS FONT) of XAXIS)
		      (CREATE POSITION
			      XCOORD ← UORIGIN
			      YCOORD ← VORIGIN)
		      'NW WINDOW)
          (\PLOT.TEXT XMIN (fetch (AXIS FONT) of XAXIS)
		      (CREATE POSITION
			      XCOORD ← UMIN
			      YCOORD ← VORIGIN)
		      'NNW WINDOW)                           (* Label .. do this before drawing line to avoid erasing
							     *)
          (COND
	    ((fetch (AXIS LABEL) of XAXIS)
	      (\PLOT.TEXT (fetch (AXIS LABEL) of XAXIS)
			  (fetch (AXIS FONT) of XAXIS)
			  (CREATE POSITION
				  XCOORD ← UMAX
				  YCOORD ← VORIGIN)
			  'SSE WINDOW)))                     (* Solid line *)
          (DRAWLINE UMIN VORIGIN UMAX VORIGIN NIL NIL WINDOW)
                                                             (* Tic marks *)
          (SETQ XINC (fetch (AXIS INCREMENT) of XAXIS))
          (COND
	    ((NULL XINC)
	      (RETURN)))
          (FOR I FROM (\PLOT.CEILING (FQUOTIENT XMIN XINC)) TO (\PLOT.FLOOR (FQUOTIENT XMAX XINC))
	     DO (SETQ U (\PLOT.TRANSLATE.XCOORD (FTIMES I XINC)
						TRANSLATE))
		(DRAWLINE U (SUB1 VORIGIN)
			  U
			  (ADD1 VORIGIN)
			  NIL NIL WINDOW)))))

(\PLOT.YAXIS
  (LAMBDA (XAXIS YAXIS TRANSLATE WINDOW)                     (* kbr: "11-Feb-84 14:54")
    (PROG (XMIN XMAX YMIN YMAX YINC MAX VMIN UORIGIN VORIGIN V)
          (SETQ XMAX (fetch (AXIS MAX) of XAXIS))
          (SETQ XMIN (fetch (AXIS MIN) of XAXIS))
          (SETQ YMAX (fetch (AXIS MAX) of YAXIS))
          (SETQ YMIN (fetch (AXIS MIN) of YAXIS))
          (COND
	    ((FGREATERP (FTIMES XMIN XMAX)
			0.0)
	      (RETURN)))                                     (* Coordinates of axis endpoints *)
          (SETQ VMIN (\PLOT.ROUND (\PLOT.TRANSLATE.YCOORD YMIN TRANSLATE)))
          (SETQ VMAX (\PLOT.ROUND (\PLOT.TRANSLATE.YCOORD YMAX TRANSLATE)))
          (SETQ VORIGIN (\PLOT.ROUND (\PLOT.TRANSLATE.YCOORD 0.0 TRANSLATE)))
          (SETQ UORIGIN (\PLOT.ROUND (\PLOT.TRANSLATE.XCOORD 0.0 TRANSLATE)))
                                                             (* Extremes *)
          (\PLOT.TEXT YMAX (fetch (AXIS FONT) of YAXIS)
		      (CREATE POSITION
			      XCOORD ← UORIGIN
			      YCOORD ← VMAX)
		      'ENE WINDOW)
          (\PLOT.TEXT 0 (fetch (AXIS FONT) of YAXIS)
		      (CREATE POSITION
			      XCOORD ← UORIGIN
			      YCOORD ← VORIGIN)
		      'SE WINDOW)
          (\PLOT.TEXT YMIN (fetch (AXIS FONT) of YAXIS)
		      (CREATE POSITION
			      XCOORD ← UORIGIN
			      YCOORD ← VMIN)
		      'ESE WINDOW)                           (* Label *)
          (COND
	    ((fetch (AXIS LABEL) of YAXIS)
	      (\PLOT.TEXT (fetch (AXIS LABEL) of YAXIS)
			  (fetch (AXIS FONT) of YAXIS)
			  (CREATE POSITION
				  XCOORD ← UORIGIN
				  YCOORD ← VMAX)
			  'WNW WINDOW)))                     (* Solid line *)
          (DRAWLINE UORIGIN VMIN UORIGIN VMAX NIL NIL WINDOW)
                                                             (* Tic marks *)
          (SETQ YINC (fetch (AXIS INCREMENT) of YAXIS))
          (COND
	    ((NULL YINC)
	      (RETURN)))
          (FOR I FROM (\PLOT.CEILING (FQUOTIENT YMIN YINC)) TO (\PLOT.FLOOR (FQUOTIENT YMAX YINC))
	     DO (SETQ V (\PLOT.TRANSLATE.YCOORD (FTIMES I YINC)
						TRANSLATE))
		(DRAWLINE (SUB1 UORIGIN)
			  V
			  (ADD1 UORIGIN)
			  V NIL NIL WINDOW)))))

(\PLOT.TEXT
  (LAMBDA (TEXT FONT POS DIRECTION WINDOW)                   (* kbr: "11-Feb-84 14:54")
                                                             (* DIRECTION = compass direction of point at POS wrt 
							     position of TEXT *)
    (COND
      ((NULL DIRECTION)
	(SETQ DIRECTION 'SW)))
    (PROG (XCOORD YCOORD WIDTH HEIGHT)
          (SETQ XCOORD (fetch (POSITION XCOORD) of POS))
          (SETQ YCOORD (fetch (POSITION YCOORD) of POS))
          (SETQ WIDTH (STRINGWIDTH TEXT FONT))
          (SETQ HEIGHT (FONTPROP FONT 'HEIGHT))
          (SELECTQ DIRECTION
		   ((NW NNW N NNE NE)
		     (SETQ YCOORD (FDIFFERENCE YCOORD (FPLUS HEIGHT 3.0))))
		   ((WNW ENE)
		     (SETQ YCOORD (FDIFFERENCE YCOORD HEIGHT)))
		   ((W E)
		     (SETQ YCOORD (FDIFFERENCE YCOORD (FQUOTIENT HEIGHT 2.0))))
		   ((WSW ESE)                                (* Do nothing *)
		     )
		   ((SW SSW S SSE SE)
		     (SETQ YCOORD (FPLUS YCOORD 3.0)))
		   (SHOULDNT))
          (SELECTQ DIRECTION
		   ((NE ENE E ESE SE)
		     (SETQ XCOORD (FDIFFERENCE XCOORD (FPLUS WIDTH 3.0))))
		   ((NNE SSE)
		     (SETQ XCOORD (FDIFFERENCE XCOORD WIDTH)))
		   ((N S)
		     (SETQ XCOORD (FDIFFERENCE XCOORD (FQUOTIENT WIDTH 2.0))))
		   ((NNW SSW)                                (* Do nothing *)
		     )
		   ((NW WNW W WSW SW)
		     (SETQ XCOORD (FPLUS XCOORD 3.0)))
		   (SHOULDNT))
          (MOVETO XCOORD YCOORD WINDOW)
          (DSPFONT FONT WINDOW)
          (PRIN1 TEXT WINDOW))))

(\PLOT.ADDPATH
  (LAMBDA (POINTS TRANSLATE WINDOW)                          (* kbr: "11-Feb-84 14:54")
    (PROG NIL
          (SETQ POINTS (\PLOT.TRANSLATE.POINTS POINTS TRANSLATE))
          (FOR PT1 IN POINTS AS PT2 IN (CDR POINTS) WHEN PT2 DO (DRAWBETWEEN PT1 PT2 NIL NIL WINDOW)))
    ))

(\PLOT.ADDCURVE
  (LAMBDA (CURVE TRANSLATE WINDOW)                           (* kbr: "11-Feb-84 14:54")
    (PROG (POINTS)
          (SETQ POINTS (\PLOT.TRANSLATE.POINTS (CURVE.KNOTS CURVE)
					       TRANSLATE))
          (DRAWCURVE POINTS (CURVE.CLOSE CURVE)
		     (CURVE.BRUSH CURVE)
		     (CURVE.DASHED CURVE)
		     WINDOW))))

(\PLOT.TRANSLATE
  (LAMBDA (XAXIS YAXIS REGION)                               (* kbr: "11-Feb-84 14:54")
                                                             (* User = XY system and WINDOW = UV system *)
                                                             (* U=MU*X+BU and V=MV*Y+BV *)
    (PROG (XMAX XMIN YMAX YMIN DELTAX DELTAY UMIN VMIN UMAX VMAX MU BU MV BV TRANSLATE)
                                                             (* XY system. *)
          (SETQ XMAX (fetch (AXIS MAX) of XAXIS))
          (SETQ XMIN (fetch (AXIS MIN) of XAXIS))
          (SETQ YMAX (fetch (AXIS MAX) of YAXIS))
          (SETQ YMIN (fetch (AXIS MIN) of YAXIS))
          (SETQ DELTAX (FDIFFERENCE XMAX XMIN))
          (SETQ DELTAY (FDIFFERENCE YMAX YMIN))              (* UV system. *)
          (SETQ UMIN (FPLUS (fetch (REGION LEFT) of REGION)
			    .5))
          (SETQ VMIN (FPLUS (fetch (REGION BOTTOM) of REGION)
			    .5))
          (SETQ UMAX (FPLUS (fetch (REGION RIGHT) of REGION)
			    .5))
          (SETQ VMAX (FPLUS (fetch (REGION TOP) of REGION)
			    .5))                             (* Calc TRANSLATE. *)
          (SETQ MU (FQUOTIENT (FDIFFERENCE UMAX UMIN)
			      DELTAX))
          (SETQ BU (FQUOTIENT (FDIFFERENCE (FTIMES XMAX UMIN)
					   (FTIMES XMIN UMAX))
			      DELTAX))
          (SETQ MV (FQUOTIENT (FDIFFERENCE VMAX VMIN)
			      DELTAY))
          (SETQ BV (FQUOTIENT (FDIFFERENCE (FTIMES YMAX VMIN)
					   (FTIMES YMIN VMAX))
			      DELTAY))
          (SETQ TRANSLATE (CREATE TRANSLATE
				  MU ← MU
				  BU ← BU
				  MV ← MV
				  BV ← BV))
          (RETURN TRANSLATE))))

(\PLOT.TRANSLATE.POINTS
  (LAMBDA (POINTS TRANSLATE)                                 (* kbr: "11-Feb-84 14:54")
    (FOR POINT IN POINTS COLLECT (\PLOT.TRANSLATE.POINT POINT TRANSLATE))))

(\PLOT.TRANSLATE.POINT
  (LAMBDA (POINT TRANSLATE)                                  (* kbr: "11-Feb-84 14:54")
    (CREATE POSITION
	    XCOORD ← (\PLOT.TRANSLATE.XCOORD (fetch (POSITION XCOORD) of POINT)
					     TRANSLATE)
	    YCOORD ← (\PLOT.TRANSLATE.YCOORD (fetch (POSITION YCOORD) of POINT)
					     TRANSLATE))))

(\PLOT.TRANSLATE.XCOORD
  (LAMBDA (X TRANSLATE)                                      (* kbr: "11-Feb-84 14:54")
    (FPLUS (FTIMES (fetch (TRANSLATE MU) of TRANSLATE)
		   X)
	   (fetch (TRANSLATE BU) of TRANSLATE))))

(\PLOT.TRANSLATE.YCOORD
  (LAMBDA (Y TRANSLATE)                                      (* kbr: "11-Feb-84 14:54")
    (FPLUS (FTIMES (fetch (TRANSLATE MV) of TRANSLATE)
		   Y)
	   (fetch (TRANSLATE BV) of TRANSLATE))))

(\PLOT.ROUND
  (LAMBDA (N)                                                (* kbr: "11-Feb-84 14:54")
    (\PLOT.FLOOR (FPLUS N .5))))

(\PLOT.FLOOR
  (LAMBDA (N)                                                (* kbr: "11-Feb-84 14:54")
    (COND
      ((OR (FEQP N (FIX N))
	   (NOT (FLESSP N 0.0)))
	(FIX N))
      (T (SUB1 (FIX N))))))

(\PLOT.CEILING
  (LAMBDA (N)                                                (* kbr: "11-Feb-84 14:54")
    (IMINUS (\PLOT.FLOOR (IMINUS N)))))

(\PLOT.MAX
  (LAMBDA (NS)                                               (* kbr: "11-Feb-84 14:54")
                                                             (* Safer than MAX%, which can%'t have more than 80 args 
							     *)
    (PROG (ANSWER)
          (SETQ ANSWER MIN.FLOAT)
          (FOR N IN NS WHEN (FGREATERP N ANSWER) DO (SETQ ANSWER N))
          (RETURN ANSWER))))

(\PLOT.MIN
  (LAMBDA (NS)                                               (* kbr: "11-Feb-84 14:54")
                                                             (* Safer than MIN%, which can%'t have more than 80 args 
							     *)
    (PROG (ANSWER)
          (SETQ ANSWER MAX.FLOAT)
          (FOR N IN NS WHEN (FLESSP N ANSWER) DO (SETQ ANSWER N))
          (RETURN ANSWER))))
)
(DECLARE: DONTCOPY
  (FILEMAP (NIL (929 15374 (PLOT.FN 939 . 1965) (PLOT.PATH 1967 . 2901) (PLOT 2903 . 4254) (\PLOT.XAXIS 
4256 . 6680) (\PLOT.YAXIS 6682 . 9041) (\PLOT.TEXT 9043 . 10565) (\PLOT.ADDPATH 10567 . 10895) (
\PLOT.ADDCURVE 10897 . 11243) (\PLOT.TRANSLATE 11245 . 12969) (\PLOT.TRANSLATE.POINTS 12971 . 13182) (
\PLOT.TRANSLATE.POINT 13184 . 13542) (\PLOT.TRANSLATE.XCOORD 13544 . 13785) (\PLOT.TRANSLATE.YCOORD 
13787 . 14028) (\PLOT.ROUND 14030 . 14175) (\PLOT.FLOOR 14177 . 14387) (\PLOT.CEILING 14389 . 14543) (
\PLOT.MAX 14545 . 14959) (\PLOT.MIN 14961 . 15372)))))
STOP