# From sbcs.sunysb.edu!theo Mon Dec 10 13:51:21 EST 1990
# Date: Mon, 10 Dec 90 13:51:21 EST
# From: theo@sbcs.sunysb.edu
# To: ehg@research.att.com
# 
# To unbundle, delete the above lines and then sh this file
mkdir examples man Fpt SUNplotter Xplotter
echo README 1>&2
sed 's/.//' >README <<'//GO.SYSIN DD README'
-This package contains the software implementing the function
-plotting method described in the paper
-
-J. Hu & T. Pavlidis "Function Plotting using Conic Splines,"
-IEEE CGNA, to appear in the January 1991 issue.
-
-The software consists of the FPT library which contains
-the "plotc()" function which must linked to the user's
-program and the plotting libraries for SUNVIEW and
-X-windows.
-
-
-To generate the FPT liberary, run the Makefile in src/FPT
-
-To generate the SUNVIEW plotter, run the Makefile in src/SUNplotter
-
-To generate the X-window plotter, run the Makefile in src/Xlotter
-
-
-Some examples of using FPT to plot a function are given in
-the directory "examples". Read README file in that directory
-for information on programming and compiling.
-
-BUGS: some unexpected behavior may occur when plotting functions
-      with fast oscillations of small magnitudes. Shifting
-      the starting and ending points a little may help.
//GO.SYSIN DD README
echo examples/README 1>&2
sed 's/.//' >examples/README <<'//GO.SYSIN DD examples/README'
-THis directory contains some example of application programms.
-
-You can follow the pattern of these examples to write a programm
-to plot your own function.
-
-To compile and run , follow the following steps:
-
-cc -o fast fast.c ../fpt.a -lm
-
-fast|../bin/xplot	(if you are in X window system)
-
-fast|../bin/splot    (if you are in SUN window system)
-
-After the window appears, use button 3 of the mouse to
-activate plotting from the menu.
//GO.SYSIN DD examples/README
echo examples/fast.c 1>&2
sed 's/.//' >examples/fast.c <<'//GO.SYSIN DD examples/fast.c'
-
-
-
-
-
-#include <stdio.h>
-#include <math.h>
-
-float fy(t)
-float t;
-{
-	return(t*sin(1/t));
-}
-
-float fx(t)
-float t;
-{
-	return(t);
-}
-
-
-float fy_p(t)
-float t;
-{
-	return(sin(1/t)-cos(1/t)/t);
-}
-
-
-float fx_p(t)
-float t;
-{
-	return(1);
-}
-
-
-main(arc,arv)
-	char **arv;
-{
-	char c;
-	double t, t1= 0.05, t2=0.5;
-
-	while(arc>1 && arv[1][0]=='-'){
-		c = arv[1][1];
-		switch(c){
-		case 's': t1 = atof(arv[1]+2); break;
-		case 'e': t2 = atof(arv[1]+2); break;
-		}
-		arc--; arv++;
-	}
-
-	plotc(fx, fy, fx_p, fy_p, t1,t2);
-}
//GO.SYSIN DD examples/fast.c
echo examples/osci.c 1>&2
sed 's/.//' >examples/osci.c <<'//GO.SYSIN DD examples/osci.c'
-/* Test program for fpt to draw a sine oscilation function */
-
-#include <stdio.h>
-#include <math.h>
-
-double w=6.0;
-
-float fy(t)
-float t;
-{
-
-	return(exp(-t)*sin(w*t));
-}
-
-float fx(t)
-float t;
-{
-	return(t);
-}
-
-float fy_p(t)
-float t;
-{
-	return(exp(-t)*(w*cos(w*t)-sin(w*t)));
-}
-
-float fx_p(t)
-float t;
-{
-	return(1);
-}
-
-y
-main(arc,arv)
-	char **arv;
-{
-	char c;
-	double t, t1= -1.0, t2=2.0;
-
-	while(arc>1 && arv[1][0]=='-'){
-		c = arv[1][1];
-		switch(c){
-		case 's': t1 = atof(arv[1]+2); break;
-		case 'e': t2 = atof(arv[1]+2); break;
-		case 'w': w = atof(arv[1]+2); break;
-		}
-		arc--; arv++;
-	}
-
-/*	printf("s:t1=%g e:t2=%g w=%g\n",t1,t2,w);*/
-#define DEBUG
-#ifdef DEBUG
-/*	for(t=t1;t<=t2;t+=0.05)
-		printf("%g %g %g\n",t,fx(t),fx_p(t));
-*/
-#endif
-	plotc(fx,fy,fx_p,fy_p,t1,t2);
-}
//GO.SYSIN DD examples/osci.c
echo examples/singular.c 1>&2
sed 's/.//' >examples/singular.c <<'//GO.SYSIN DD examples/singular.c'
-#include <stdio.h>
-#include <math.h>
-
-float fx(t)
-float t;
-{
-	return(t);
-}
-
-float fy(t)
-float t;
-{
-	return(1/t);
-}
-
-float fxp(t)
-float t;
-{
-	return(1);
-}
-
-float fyp(t)
-float t;
-{
-	return(-1/(t*t));
-}
-
-main(arc,arv)
-	char **arv;
-{
-	char c;
-	double t1= -2.0, t2=2.0;
-	while(arc>1 && arv[1][0]=='-'){
-		c = arv[1][1];
-		switch(c){
-		case 's': t1 = atof(arv[1]+2); break;
-		case 'e': t2 = atof(arv[1]+2); break;
-		}
-		arc--; arv++;
-	}
-
-	plotc(fx,fy,fxp,fyp,t1,t2);
-}
-
//GO.SYSIN DD examples/singular.c
echo man/plotc.n 1>&2
sed 's/.//' >man/plotc.n <<'//GO.SYSIN DD man/plotc.n'
-.TH CPLOT 3 " Augest 1989"
-.SH NAME
-plotc
-.SH SYNOPSIS
-.B plotc(fx, fy, fxp, fyp, t1, t2)
-.SH DESCRIPTION
-.I plotc()
-is a function in the curve fitting library \fIfpt.a\fP for 
-plotting arbitrary functions using conic fitting. It computes
-piecewise conic approximation to any function according to
-the parametric functions and their derivatives given by user
-, and outputs the data representing this set of conic arcs,
-which can become input data to a plotter that plots the conics
-piece by piece to form the complete curve.
-The format of output data of \fIplotc()\fP is as following:
-.LP
-xmin,xmax,ymin,ymax
-.LP
-x1,y1,x2,y2,a,b,c,d,e,f
-.LP
-\......................
-.LP
-\......................
-.LP
-xmin, xmax, ymin, ymax specify the range of the curve to be
-plotted. For each piece of conic arc, x1, y1 are x and y 
-coordinates of the starting point, and x2, y2 are those of
-the ending point. a, b, c, d, e, f are coefficients of 
-standard conic function which has the form:
-.LP
-a*x*x+2*b*x*y+c*y*y+d*x+e*y+f=0
-.SH USAGE
-.LP
-1. Progamming
-.LP
-In user program, the user should first provide the parametric 
-functions and their derivatives then, call the function 
-plotc(fx,fy,fxp,fyp,t1,t2). fx, fy, fxp, fyp are
-pointers to the four given functions, t1,t2 give the range of
-parameter t over which the function is to be plotted.
-.LP
-A sample user program is given below:
-.LP
-/*      a sample program to plot: y=sin(x)                 */
-.sp 1
-#include <stdio.h>
-.LP
-#include <math.h>
-.sp 2
-float fx(t)  float t; {   return(t); }
-.LP
-.sp 1
-float fy(t)  float t; {   return(sin(t)); }
-.sp 1
-float fxp(t) float t; {   return(1); }
-.sp 1
-float fyp(t) float t; {   return(cos(t)); }
-.sp 2
-main()
-.LP
-{   plotc(x,y,x_p,y_p,-6.0,4.0); }
-.sp 1
-.LP
-2. Compilation and excution
-.LP
-User should first compile the user source file with the
-curve fitting library to generate a excutable file, then pipeline
-this file to the plotter.
-.SH SEE ALSO
-CPLOT(1) CPLOT(5)
-.SH BUGS
-.LP
-PLEASE send comments and bug reports to "theo" or "jianhu"
-
-
-
-
//GO.SYSIN DD man/plotc.n
echo man/splot.n 1>&2
sed 's/.//' >man/splot.n <<'//GO.SYSIN DD man/splot.n'
-
-.TH splot 1 " Augest 1989" 
-.SH NAME
-splot \- conic plotter on \fISunView\fP.
-.SH SYNOPSIS
-\fBsplot\fP [ \fI -xN -yN -wN \fP ]
-.SH DESCIRPTION
-.I splot
-is a \fISunView\fP plotter for conic segments. It is used
-after the conic approximation of a given curve is obtained
-using function \fIplotc()\fP in library ftp.a (see ftp(1)).
-.LP
-splot reads descriptions of a list of conic segments from
-standard input. the input data format is as following:
-.LP
-xmin,xmax,ymin,ymax
-.LP
-x1,y1,x2,y2,a,b,c,d,e,f
-.LP
-\......................
-.LP
-\......................
-.LP
-xmin, xmax, ymin, ymax specify the range of the curve to be
-plotted. For each piece of conic arc, x1, y1 are x and y 
-coordinates of the starting point, and x2, y2 are those of
-the ending point. a, b, c, d, e, f are coefficients of 
-standard conic function which has the form:
-.LP
-a*x*x+2*b*x*y+c*y*y+d*x+e*y+f=0
-
-.LP
-The x,y,w flags specify the position of top left coner of 
-the \fIsplot\fP window and size of the window.
-The window has to be square. Defalt values are: 100, 100, 500.
-.LP
-After the window is displayed, click the left button of the mouse
-and the manu will be displayed. Here is the specification of the manu
-items:
-.LP
-.IP "\fBclaer\fP"
-Claer the window
-.IP "\fBplotconi\fP"
-Plot the conic approximation of the given curve
-.IP "\fBplotpoly\fP
-Plot the corresponding polygonal approximation of the given curve.
-.SH SEE ALSO
-xplot(1) fpt(1)
-.LP
-PLEASE send comments and bug reports to
-	theo@visgate.sbcs.sunysb.edu
-	jianhu@visgate.sbcs.sunysb.edu
-
//GO.SYSIN DD man/splot.n
echo man/xplot.n 1>&2
sed 's/.//' >man/xplot.n <<'//GO.SYSIN DD man/xplot.n'
-.TH xplot 1 "October 1990"
-.SH NAME
-xplot \- conic plotter on \fIX window\fP
-.SH SYNOPSIS
-\fBxplot\fP [ \fI -xN -yN -wN \fP ]
-.SH DESCIRPTION
-.I splot
-is a \fIX window\fP plotter for conic segments. It runs under
-X version 11 resease 4. It is used
-after the conic approximation of a given curve is obtained
-using function \fIplotc()\fP in library ftp.a (see ftp(1)).
-.LP
-splot reads descriptions of a list of conic segments from
-standard input. the input data format is as following:
-.LP
-xmin,xmax,ymin,ymax
-.LP
-x1,y1,x2,y2,a,b,c,d,e,f
-.LP
-\......................
-.LP
-\......................
-.LP
-xmin, xmax, ymin, ymax specify the range of the curve to be
-plotted. For each piece of conic arc, x1, y1 are x and y 
-coordinates of the starting point, and x2, y2 are those of
-the ending point. a, b, c, d, e, f are coefficients of 
-standard conic function which has the form:
-.LP
-a*x*x+2*b*x*y+c*y*y+d*x+e*y+f=0
-.LP
-The x,y,w flags specify the position of top left coner of 
-the \fIsplot\fP window and size of the window.
-The window has to be square. Defalt values are: 100, 100, 500.
-.LP
-After the window is displayed, click the left button of the mouse
-and the manu will be displayed. Here is the specification of the manu
-items:
-.LP
-.IP "\fBplot curve\fP"
-Plot the conic segments
-.LP 
-.IP "\fBshow coordinates"
-Plot x and y coordinates
-.LP
-.IP "\fBshow segments\fP"
-Plot the chord corresponding to each segment
-.LP
-.IP "\fBclaer\fP"
-Claer the window
-.IP "\fBquit\fP"
-Quit
-.SH SEE ALSO
-xplot(1) fpt(1)
-.LP
-PLEASE send comments and bug reports to
-	theo@visgate.sbcs.sunysb.edu
-	jianhu@visgate.sbcs.sunysb.edu
-
//GO.SYSIN DD man/xplot.n
echo Fpt/Makefile 1>&2
sed 's/.//' >Fpt/Makefile <<'//GO.SYSIN DD Fpt/Makefile'
-SBASE=.
-CFLAGS= -g -I$(SBASE)
-
-OFILES= plotc.o triangle.o coni.o outputc.o mod.o mergec.o merget.o preproc.o
-CFILES= plotc.c triangle.c coni.c outputc.c mod.c mergec.c merget.c preproc.c
-LIBFIT= ../../fpt.a
-
-$(LIBFIT): $(LIBFIT)(plotc.o) $(LIBFIT)(triangle.o) $(LIBFIT)(coni.o) \
-           $(LIBFIT)(outputc.o) $(LIBFIT)(mod.o) $(LIBFIT)(mergec.o) \
-           $(LIBFIT)(merget.o) $(LIBFIT)(preproc.o)
-	ranlib $(LIBFIT)
-
-$(LIBFIT)(plotc.o): plotc.o
-	ar rv $(LIBFIT) plotc.o
-
-$(LIBFIT)(triangle.o): triangle.o
-	ar rv $(LIBFIT) triangle.o
-
-$(LIBFIT)(coni.o): coni.o
-	ar rv $(LIBFIT) coni.o
-
-$(LIBFIT)(outputc.o): outputc.o
-	ar rv $(LIBFIT) outputc.o
-
-$(LIBFIT)(mod.o): mod.o
-	ar rv $(LIBFIT) mod.o
-
-$(LIBFIT)(mergec.o): mergec.o
-	ar rv $(LIBFIT) mergec.o
-
-$(LIBFIT)(merget.o): merget.o
-	ar rv $(LIBFIT) merget.o
-
-$(LIBFIT)(preproc.o): preproc.o
-	ar rv $(LIBFIT) preproc.o
-
-$(OFILES):  coni.h
-
//GO.SYSIN DD Fpt/Makefile
echo Fpt/README 1>&2
sed 's/.//' >Fpt/README <<'//GO.SYSIN DD Fpt/README'
-
-
-This directory contains the source codes for the function plotting tool (fpt)
-library. excuting "make" will generate ../../fit.a
//GO.SYSIN DD Fpt/README
echo Fpt/coni.c 1>&2
sed 's/.//' >Fpt/coni.c <<'//GO.SYSIN DD Fpt/coni.c'
-/*****************************************************************/
-/*	Copyright (c) 1990 SUNY at Stony Brook                   */
-/*****************************************************************/
-
-
-#include "coni.h"
-#include <math.h>
-#define MINC 0.000001	/*minimum coefficient after normalization*/
-
-extern mergec();
-
-/*	function name: coni
-*	parameters:
-*		trip: pointer to a list of guiding triangles
-*		fx,fy,fxp,fyp: pointers to the parametric functions and
-*			       their directives
-*	
-*		delta: parameter interval of initial division
-*	description: get conic fitting from guiding triangle list and merge
-*		     similar segments
-*/
-
-coni(trip, fx,fy,delta)
-Coninode *trip;
-float (*fx)(), (*fy)();
-float delta;
-{
-	init_coni(trip,fx,fy);
-	mergec(trip,delta); 
-}
-
-
-/*	function name: init_coni
-*	parameters:
-*		p: pointer to a list of guiding triangles
-*		fx, fy: pointers to the parametric functions of original curve
-*	description: fit conic to each guiding triangle
-*/
-
-init_coni(p,fx,fy)
-Coninode *p;
-float (*fx)(), (*fy)();
-{	while (p!=0) {
-		fit_coni(p,fx,fy);
-		p=p->next;
-	}
-}
-
-/* function name: fit_coni
-*  parameters:
-*	tp: pointer to one segment of conic and its guiding triangle
-*	fx,fy: pointers to original functions
-*	discription: fit conic to each the guiding triangle
-*/
-fit_coni(tp,fx,fy)	
-Coninode *tp;
-float (*fx)(), (*fy)();
-{
-	int i;
-	float x1,y1,x2,y2,x3,y3,x0,y0,k,t,d,max;
-	float a1,b1,c1,a2,b2,c2,a3,b3,c3;
-
-	x1=tp->node1.x;	y1=tp->node1.y; 
-	x2=tp->node2.x; y2=tp->node2.y;
-	x3=tp->node3.x; y3=tp->node3.y;			
-	
-	/*check for straight line  */
-	if (fabs((x3-x2)*(y2-y3)-(x2-x1)*(y3-y2))
-		<ERR*fabs((x2-x1)*(x3-x2))){
-		tp->c[0]=tp->c[1]=tp->c[2]=0;
-		tp->c[3]=y1-y2;
-		tp->c[4]=x2-x1;
-		tp->c[5]=x1*y2-x2*y1;
-	}
-	else {				
-		/* introduce one more point on the curve  */
-		t=0.5*(tp->node1.t+tp->node2.t);	
-		x0=sx*fx(t);	y0=sy*fy(t);
-		
-		/* parameters for the edge functions  of the triangle   */
-		a1=y2-y3;	
-		b1=x3-x2;
-		c1=x2*y3-x3*y2;		
-		a2=y1-y3;		 
-		b2=x3-x1;
-		c2=x1*y3-x3*y1;
-		a3=y1-y2;
-		b3=x2-x1;
-		c3=x1*y2-x2*y1;
-
-		/* get the algebraic function of the conic :  */
-		/* (a1*x+b1*y+c1)*(a3*x+b3*y+c3)=	      */
-		/* k*(a2*x+b2*y+c2)*(a2*x+b2*y+c2)            */
-
-		k=(a1*x0+b1*y0+c1)*(a2*x0+b2*y0+c2);
-		k=k/((a3*x0+b3*y0+c3)*(a3*x0+b3*y0+c3));
-		
-		tp->c[0]=k*a3*a3-a1*a2;	
-		tp->c[1]=0.5*(2*k*a3*b3-b1*a2-a1*b2);
-		tp->c[2]=k*b3*b3-b1*b2;
-		tp->c[3]=2*k*a3*c3-a1*c2-a2*c1;
-		tp->c[4]=2*k*b3*c3-c1*b2-b1*c2;
-		tp->c[5]=k*c3*c3-c1*c2;
-	}
-
-	/* mormalize the parameters */
-	max=0;
-	for (i=0; i<=5; i++) 
-		if (fabs(tp->c[i])>max) max=fabs(tp->c[i]);
-        if   (max!=0)     	
-		for (i=0; i<=5;i++) {
-			tp->c[i]=tp->c[i]/max;
-			if (fabs(tp->c[i])<MINC) tp->c[i]=0;
-		}
-
-
-}
-
-
-		
//GO.SYSIN DD Fpt/coni.c
echo Fpt/coni.h 1>&2
sed 's/.//' >Fpt/coni.h <<'//GO.SYSIN DD Fpt/coni.h'
-/********************************************************/
-/*	Copyright (c)   1990    SUNY st Stony Brook     */
-/********************************************************/
-
-
-#define BIG(x,y) (x>y? x:y)
-#define SMALL(x,y) (x<y? x:y)
-
-#define MINT 0.0001     /* ratio of minimum interval considered and the */
-		        /* initial interval of parameter t.             */
-#define SIN 0.1         /* criterion for straight line. a loose one */
-
-#define ERR 0.0001      /*criterion for straight line, a tight one*/
-
-typedef struct brkpt {  /* data structure for break point */
-	float t;
-	float x;
-	float y;
-} Brkpt;
-
-typedef struct guidpt { /* data structure for guide point */
-	float x;
-	float y;
-} Guidpt;
-
-/* 	data structure for a conic segment and its guiding triangle */
-typedef struct coninode {	
-	Brkpt node1;		
-	Brkpt node2;	        /* nodes of the triangle   */
-	Guidpt node3;
-	float c[6];		/* array of parameters of the conic */
-	struct coninode *next;
-} Coninode;
-
-/*	data structure for conic approximation for a continous curve seg. */
-typedef struct cpiece {
-	Coninode *head;        	/* pointer to the head of list */
-	float t1;		/* range over the parameter */	
-	float t2;
-	struct cpiece *next;
-} Cpiece;
-
-/*	globle variables */
-extern float xmin,xmax,ymax,ymin;	/* domain of the function */
-extern int sx,sy;			/* scaling factor	  */
//GO.SYSIN DD Fpt/coni.h
echo Fpt/mergec.c 1>&2
sed 's/.//' >Fpt/mergec.c <<'//GO.SYSIN DD Fpt/mergec.c'
-/***************************************************************/
-/*      Copyright (c)   1990    SUNY st Stony Brook            */
-/***************************************************************/
-#include "coni.h"
-#include <math.h>
-#define E 0.001		/* threshold in comparing parameters */
-
-/*	function name: mergec
-*	parameters: 
-*		head: pointer to a list of conic segments
-*		delta: initial interval over paramter
-*	description: goes through the list of conics, merge similar
-*			segments.
-*/
-
-mergec(head, delta)
-Coninode *head;
-float delta;
-{
-	Coninode *p,*q;
-	int tag,i;
-	float x1,y1,x2,y2,x3,y3,dx1,dy1,dx2,dy2,b;
-
-	p=head;
-	if (p==0) return ; else q=p->next;
-	while (q!=0) {
-		tag=1;
-		for (i=0; i<=5; i++) 
-		  if (fabs(p->c[i]-q->c[i])>E) {tag=0; break;}
-		if (tag) {
-			x1=p->node1.x;  y1=p->node1.y;
-			x2=q->node2.x;  y2=q->node2.y;
-			dx1=p->node3.x-x1;
-			dy1=p->node3.y-y1;
-			dx2=x2-q->node3.x;
-			dy2=y2-q->node3.y;
-
-			/* check for parallel derivatives */
-			if ((b=dx1*dy2-dy1*dx2)==0) { 
-					
-					p=q;          
-					q=q->next;
-			}
-			else {
-			   /* compute the intersection point */
-			   x3=(dx2*(y1*dx1-x1*dy1)-dx1*(y2*dx2-x2*dy2))/b; 
-			   y3=(dy2*(y1*dx1-x1*dy1)-dy1*(y2*dx2-x2*dy2))/b;
-
- 	     	           /* check if it does not contain two quatrants  */
-			   if (((x3-SMALL(x1,x2))> -MINT*delta)
-			   && ((x3-BIG(x1,x2))<MINT*delta)
-			   && ((y3-SMALL(y1,y2))> -MINT*delta) 
-			   && ((y3-BIG(y1,y2))<MINT*delta)){
-				p->node3.x=x3; p->node3.y=y3;
-				p->node2.x=x2; p->node2.y=y2;
-				p->node2.t=q->node2.t;
-				q=q->next;
-				p->next=q;
-			   }  
-			   else {
-	       			/* no modification is made if 
-				 *there will be two quatrants
-				*/
-				p=q; q=q->next; 
-			   }
-			}
-		}
-		else { p=q; q=q->next; }			
-	}
-}
//GO.SYSIN DD Fpt/mergec.c
echo Fpt/merget.c 1>&2
sed 's/.//' >Fpt/merget.c <<'//GO.SYSIN DD Fpt/merget.c'
-/***************************************************************/
-/*      Copyright (c)   1990    SUNY st Stony Brook            */
-/***************************************************************/
-#include "coni.h"
-#include <math.h>
-#include <stdio.h>
-
-extern int check_tri();
-
-/*	function: merget
-*	parameters: 
-*		head: point to the list of triangles to be checked
-*		fx,fy: pointers to the original functions
-*	description: going through the list of triangles, merging when
-*			appropriate
-*/
-merget(head,fx,fy) 
-Coninode *head;
-float (*fx)(), (*fy)();
-{
-	Coninode *p, *q,*r;
-	float x1,y1,x2,y2,x3,y3,dx1,dy1,dx2,dy2,b;
-	int tag;
-
-
-	if ((p=head)==0) return;
-	q=p;
-	while (q->next!=0){
-		x1=p->node1.x;  y1=p->node1.y;
-		dx1=p->node3.x-x1;
-		dy1=p->node3.y-y1;
-
-		tag=1;
-		while (tag && (q->next!=0)) {
-			r=q; q=q->next;
-			x2=q->node2.x;  y2=q->node2.y;
-			dx2=x2-q->node3.x;
-			dy2=y2-q->node3.y;
-
-			/* check for parallel derivatives */
-			if ((b=dx1*dy2-dy1*dx2)==0) tag=0;
-			else{
-
-			  /* compute the intersection point */
-			  x3=(dx2*(y1*dx1-x1*dy1)-dx1*(y2*dx2-x2*dy2))/b;
-			  y3=(dy2*(y1*dx1-x1*dy1)-dy1*(y2*dx2-x2*dy2))/b;
-
-			  /*  check if it's mergable */
-			   tag=check_tri(x1,y1,p->node1.t, 
-				         x2,y2,q->node2.t, x3,y3,fx,fy);
-			}			   
-		}
-		if (q->next==0) r=q;
-		if (r!=p){
-
-			/* merge p,r  */
-			x2=r->node2.x;  y2=r->node2.y;
-			dx2=x2-r->node3.x;
-			dy2=y2-r->node3.y;
-
-			/* compute the intersection point */
-			b=dx1*dy2-dy1*dx2;
-			x3=(dx2*(y1*dx1-x1*dy1)-dx1*(y2*dx2-x2*dy2))/b;
-			y3=(dy2*(y1*dx1-x1*dy1)-dy1*(y2*dx2-x2*dy2))/b;
-
-			/*merge */
-			p->node3.x=x3; p->node3.y=y3;
-			p->node2.x=x2; p->node2.y=y2;
-			p->node2.t=r->node2.t;
-			p->next=r->next;
-		
-		}
-		p=q;
-	}
-}
//GO.SYSIN DD Fpt/merget.c
echo Fpt/mod.c 1>&2
sed 's/.//' >Fpt/mod.c <<'//GO.SYSIN DD Fpt/mod.c'
-/***************************************************************/
-/*      Copyright (c)   1990    SUNY st Stony Brook            */
-/***************************************************************/
-
-#include <math.h>
-#include "coni.h"
-#include <stdio.h>
-
-#define DENS 4	/* sample density in error cheching    */
-
-extern half();
-extern fit_coni(); /* this function is in file coni.c */
-
-/*	function name: check_coin
-*	parameters:
-*		p: pointer to a list of conics and thier guiding triangles
-*		fx,fy: pointers to the parametric functions of the org. curve
-*		err: absolute error threshold, passed from mod()
-*	return value: 1 if error is within the threshold, 0 if not.
-*/
-
-int check_coni(p,fx,fy,err)	
-Coninode *p;
-float (*fx)(), (*fy)();
-float err;
-{
-	float t1,t2,t,x,y,delta,ff,gf,a,b,c,d,e,f;
-
-	t1=p->node1.t;
-	t2=p->node2.t;
-	a=p->c[0]; b=p->c[1]; c=p->c[2];
-	d=p->c[3]; e=p->c[4]; f=p->c[5];
-	delta=(t2-t1)/DENS;
-	t=t1+delta;
-	while(t<t2){
-		x=sx*fx(t); y=sy*fy(t);
-		ff=a*x*x+2*b*x*y+c*y*y+d*x+e*y+f;
-		gf=sqrt((2*a*x+2*b*y+d)*(2*a*x+2*b*y+d)+
-			(2*b*x+2*c*y+e)*(2*b*x+2*c*y+e));
-		if (fabs(ff/gf)>err) return(0);
-		t+=delta;
-	}
-	return (1);
-}
-
-/*	function name: mod
-*		parameters:
-*			cp: pointer to a list of conics and their 
-*			    guiding triangles
-*			fx,fy,fxp,fyp: pointers to parameter functions
-*			               and their derivatives
-*			deltat: initial interval over parameter
-*			err_r: threshold in error checking
-*/	
-
-mod(cp,fx,fy,fxp,fyp,deltat,err_r)
-float (*fx)(), (*fy)(), (*fxp)(), (*fyp)();
-Coninode *cp;
-float deltat,err_r;
-
-{
-	Coninode *p,*pp,*q;
-	float err,range;
-	int i;
-	
-	/* compute absolute srror according to the range of the */
-	/* original function                                    */
-	range=((xmax-xmin)>(ymax-ymin)? (xmax-xmin):(ymax-ymin));
-	err=err_r*range;
-
-	/* check for each segment                               */
-	p=cp;
-	while (p!=0) {
-		if (check_coni(p,fx,fy,err))
-			{pp=p; p=p->next; } 	/* no modification */
-		else
-			if ((p->node2.t-p->node1.t)<MINT*deltat){
-				/* ignore it if it's over a very small 
-				* interval of parameter t
-		 		*/
-				if (p==cp) {
-				   cp=cp->next;
-				   p=cp;
-				}
-				else {
-				   pp->next=p->next;
-				   p=pp->next;
-				}
-			}
-			else {
-				/* split it 	*/
-				half(fx,fy,fxp,fyp,p);
-				q=p;
-				for (i=0; i<2; i++){
-					fit_coni(q,fx,fy);
-					q=q->next;
-				}
-			}
-	}
-}
//GO.SYSIN DD Fpt/mod.c
echo Fpt/outputc.c 1>&2
sed 's/.//' >Fpt/outputc.c <<'//GO.SYSIN DD Fpt/outputc.c'
-/***************************************************************/
-/*      Copyright (c)   1990    SUNY st Stony Brook            */
-/***************************************************************/
-
-
-#include <math.h>
-#include "coni.h"
-#include <stdio.h>
-
-#define MIN 0.0001 /* minimum insteresting interval */
-		    /* the consideration here is that*/
-		    /* usually size of window is no  */
-		    /* larger than 1000              */
-		    /* so MIN*windowsize<1           */
-#define E 0.001	/* tolerant range when checking for zero coefficients */
-
-extern Coninode *conicp;
-
-outputc(mlist)
-Cpiece *mlist;
-{
-	Cpiece *p;
-	Coninode *cp;
-	float x1,x2,y1,y2,x3,y3,a,b,c,d,e,f,ba,bb,bc,dd,s1,s2;
-	float tempx,tempy, x0,y0, side0,sidet;
-
-	printf("%d %d\n",sx,sy);
-	printf("%g %g %g %g\n",xmin,xmax,ymin,ymax);  
-
-	for (p=mlist; p!=0; p=p->next) {
-	   cp=p->head;
-	   while (cp!=0){
-		x1=cp->node1.x;
-		y1=cp->node1.y;
-		x2=cp->node2.x;
-		y2=cp->node2.y;
-		x3=cp->node3.x;
-		y3=cp->node3.y;
-		a=cp->c[0]; b=cp->c[1]; c=cp->c[2];
-		d=cp->c[3]; e=cp->c[4]; f=cp->c[5];
-
-		/*check for straight line  */
-		dd=fabs(x3*(y1-y2)+y3*(x2-x1)+y2*x1-y1*x2);
-		dd=dd/sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
-		s1=dd/sqrt((y3-y1)*(y3-y1)+(x3-x1)*(x3-x1));
-		s2=dd/sqrt((y3-y2)*(y3-y2)+(x3-x2)*(x3-x2));
-		if ((s1<SIN) && (s2<SIN))  {
-			a=b=c=0;
-			d=y1-y2;
-			e=x2-x1;
-			f=x1*y2-x2*y1;			
-	printf("%g %g %g %g %g %g %g %g %g %g\n", x1,y1,x2,y2,a,b,c,d,e,f);
-			cp=cp->next;
-			continue;
-		}
-
-
-		/* check if it contains two quatrants  */	
-		if (((x3-SMALL(x1,x2))> -MINT*(xmax-xmin)) 
-		 && ((x3-BIG(x1,x2))<MINT*(xmax-xmin))
-		 && ((y3-SMALL(y1,y2))> -MINT*(ymax-ymin)) 
-		 && ((y3-BIG(y1,y2))<MINT*(ymax-ymin))){
-	printf("%g %g %g %g %g %g %g %g %g %g\n", x1,y1,x2,y2,a,b,c,d,e,f);
-			cp=cp->next;
-			continue;
-		}
-
-		if (((y3-SMALL(y1,y2))> -MINT*(ymax-ymin)) 
-			|| ((y3-BIG(y1,y2))<MINT*(ymax-ymin))) {
-		   /* look for point with horizontal derivative */
-		  if (fabs(b/a)<E) {
-			tempx=x0= -d/(2*a);
-			ba=4*a*c;
-			bb=4*a*e;
-			bc=4*a*f-d*d;
-			if (fabs(ba/bb)<E) tempy=y0= -bc/bb;		
-			else 	{ y0=(-bb+sqrt(bb*bb-4*ba*bc))/(2*ba);
-				  tempy=(-bb-sqrt(bb*bb-4*ba*bc))/(2*ba);
-			}
-		   }	  
-		  else {
-				
-		   	ba=4*a*(a*c-b*b);
-		   	bb=4*a*(c*d-b*e);
-		   	bc=d*d*c-2*b*e*d+4*b*b*f;
-		   	if (fabs(ba/bb)<E) {tempx=x0= -bc/bb;
-			       	    tempy=y0= -(2*a*x0+d)/(2*b); 
-		   	}
-		   	else {
-		      	   x0=(-bb+sqrt(bb*bb-4*ba*bc))/(2*ba);
-		           y0= -(2*a*x0+d)/(2*b);
-		           tempx=(-bb-sqrt(bb*bb-4*ba*bc))/(2*ba);
-		           tempy= -(2*a*tempx+d)/(2*b);
-		   	}
-		  }
-		}
-		else {
-		   /* look for point with vertical derivative  */
-		   if (fabs(b/a)<E) {
-			tempy=y0= -e/(2*c);
-			ba=4*a*c;
-			bb=4*c*d;
-			bc=4*c*f-e*e;
-			if (fabs(ba/bb)<E) tempx=x0= -bc/bb;
-			else  { x0=(-bb+sqrt(bb*bb-4*ba*bc))/(2*ba);
-				tempx=(-bb-sqrt(bb*bb-4*ba*bc))/(2*ba);
-			}				
-		   }
-		   else {
-
-		   	ba=4*c*(a*c-b*b);
-		   	bb=4*c*(a*e-b*d);
-		   	bc=e*e*a-2*b*e*d+4*b*b*f;
-		   	if (fabs(ba/bb)<E) {tempy=y0= -bc/bb; 
-				    tempx=x0= -(2*c*y0+e)/(2*b); }
-		   	else {
-		      	   y0=(-bb+sqrt(bb*bb-4*ba*bc))/(2*ba);	
-                      	   x0= -(2*c*y0+e)/(2*b);
-                      	   tempy=(-bb-sqrt(bb*bb-4*ba*bc))/(2*ba);	
-                           tempx= -(2*c*tempy+e)/(2*b);
-		   	}
-		   }
-		}
-
-		/* choose the appropriate root */ 
-		ba=y1-y2;
-		bb=x2-x1;
-		bc=x1*y2-x2*y1;
-		side0=(ba*x3+bb*y3+bc)*(ba*x0+bb*y0+bc);
-		sidet=(ba*x3+bb*y3+bc)*(ba*tempx+bb*tempy+bc);
-	
-		s1=(x0-x1)*(x0-x1)+(y0-y1)*(y0-y1)
-			+(x0-x2)*(x0-x2)+(y0-y2)*(y0-y2);
-		s2=(tempx-x1)*(tempx-x1)+(tempy-y1)*(tempy-y1)
-			+(tempx-x2)*(tempx-x2)+(tempy-y2)*(tempy-y2);
-		if ((side0<0.0) || ((side0>0) && (sidet>0) && (s1>s2))){
-		        x0=tempx;       y0=tempy;     /* choose one root */ 
-		}
-
-	/*           output the two pieces seperatly           */
-	printf("%g %g %g %g %g %g %g %g %g %g\n",x1,y1,x0,y0,a,b,c,d,e,f);
-	printf("%g %g %g %g %g %g %g %g %g %g\n",x0,y0,x2,y2,a,b,c,d,e,f);
-		
-		cp=cp->next;
-	   }
-	}
-}
-
//GO.SYSIN DD Fpt/outputc.c
echo Fpt/plotc.c 1>&2
sed 's/.//' >Fpt/plotc.c <<'//GO.SYSIN DD Fpt/plotc.c'
-/***************************************************************/
-/*      Copyright (c)   1990    SUNY st Stony Brook            */
-/***************************************************************/
-
-
-/*	plotc.c: main plotting subroutine                        */
-/*	function called: preproc.c() in file preproc.c           */
-/*      		 triangle()  in file triangle.c          */
-/*	                 coni()      in file coni.c              */
-/*			 mod()       in file mod.c               */
-/*			 outputc()   in file outputc.c           */
-
-
-#include <math.h>
-#include "coni.h"
-#include <stdio.h>
-
-#define NUM 10		/* number of initial divition  */
-
-float err_ratio=0.001;   /* ratio of error / range    */
-
-float xmax,xmin,ymax,ymin;
-int sx,sy;
-
-Cpiece *preproc();
-Coninode *triangle();
-coni();
-mod();
-output();
-
-plotc(fx,fy,fxp,fyp,t1,t2)
-float (*fx)(), (*fy)(), (*fxp)(), (*fyp)();
-float t1,t2;
-{
-	Cpiece *mlist, *p;
-	float deltat;
-
-	mlist=preproc(fx,fy,fxp,fyp,t1,t2);
-
-	for (p=mlist; p!=0; p=p->next){
-	
-		/* interval of initial division*/
-		deltat=fabs(p->t1-p->t2)/NUM;  
-		/* triangulation */
-		p->head=triangle(fx,fy,fxp,fyp,p->t1,p->t2,deltat); 
-		/* fit conics */
-		coni(p->head,fx,fy,deltat); 
-		/* modification through error checking  	*/
-		/* switch to be added to let user decide whether*/
-		/* this function is called                      */
-		mod(p->head,fx,fy,fxp,fyp,deltat,err_ratio);
-	}
-	outputc(mlist);
-}
-
//GO.SYSIN DD Fpt/plotc.c
echo Fpt/preproc.c 1>&2
sed 's/.//' >Fpt/preproc.c <<'//GO.SYSIN DD Fpt/preproc.c'
-/***************************************************************/
-/*      Copyright (c)   1990    SUNY st Stony Brook            */
-/***************************************************************/
-
-
-/*	preproc.c: preprocesing function to estimate and    */
-/*		   clip the range of the function, detect   */
-/*		   singular point, through dense sampling   */
-
-#include <math.h> 
-#include "coni.h" 
-#include <stdio.h>
-
-#define SAMN 500
-#define MAXSCALE 50
-
-
-Cpiece *preproc(fx,fy,fxp,fyp,t1,t2)
-float (*fx)(), (*fy)(), (*fxp)(), (*fyp)();
-float t1,t2;
-{
-	int i;
-	float t,dt,x,y;
-	Cpiece *head=0,*p;
-	
-	xmax=xmin=fx(t1);
-	ymax=ymin=fy(t1);
-	sx=sy=1.0;
-
-	if (t1>t2) { t=t1; t1=t2; t2=t; }
-	dt=(t2-t1)/SAMN;
-	for (i=1; i<=SAMN; i++){
-		x=fx(t1+i*dt);
-		y=fy(t1+i*dt);
-		xmin=(x>xmin? xmin:x);
-		xmax=(x<xmax? xmax:x);
-		ymin=(y>ymin? ymin:y);
-		ymax=(y<ymax? ymax:y);
-	}
-
-
-	if (((xmin-xmax)!=0) && ((ymin-ymax)!=0)){
-		if ((xmax-xmin)/(ymax-ymin)>1){
- 		   if ((xmax-xmin)/(ymax-ymin) > MAXSCALE){
-			x=0.0;
-			xmin=x-(ymax-ymin)*0.5*MAXSCALE;
-			xmax=x+(ymax-ymin)*0.5*MAXSCALE;
-			sy=MAXSCALE;
-		   }
-		   else sy=(int)((xmax-xmin)/(ymax-ymin));
-	   	   ymin=ymin*sy;
-		   ymax=ymax*sy;
-	    	}
-	
-		if (((ymax-ymin)/(xmax-xmin))>1){
-		   if (((ymax-ymin)/(xmax-xmin)) > MAXSCALE){
-			y=0.0;
-			ymin=y-(xmax-xmin)*0.5*MAXSCALE;
-			ymax=y+(xmax-xmin)*0.5*MAXSCALE;
-			sx=MAXSCALE;
-		   } 
-		   else sx=(int)((ymax-ymin)/(xmax-xmin));	
-		   xmin=xmin*sx;
-		   xmax=xmax*sx;
-		}
-	}
-
-	t=t2;
-	while (t>=t1) {
-		p=(Cpiece *)malloc(sizeof(Cpiece));
-		p->t2=t;
-		while ((t>=t1) && (sx*fx(t)>=xmin) && (sx*fx(t)<=xmax)
-			&& (sy*fy(t)>=ymin) && (sy*fy(t)<=ymax)) 
-			t=t-dt;
-		p->t1=t+dt;
-		if (t<=t1) p->t1=t1;
-		p->next=head;
-		head=p;
-		while ((t>=t1) && ((sx*fx(t)<xmin) || (sx*fx(t)>xmax)
-				 || (sy*fy(t)<ymin) || (sy*fy(t)>ymax)))
-			t=t-dt;
-	}
-	return (head);
-}
//GO.SYSIN DD Fpt/preproc.c
echo Fpt/triangle.c 1>&2
sed 's/.//' >Fpt/triangle.c <<'//GO.SYSIN DD Fpt/triangle.c'
-/***************************************************************/
-/*      Copyright (c)   1990    SUNY st Stony Brook            */
-/***************************************************************/
-#include "coni.h"
-#include <math.h>
-#include <stdio.h>
-
-#define TANG 0.5      /*criterion in checking the shape of guiding triangle*/
-
-Coninode *init_tri();
-split();
-merget();
-
-
-/*	function name: Coninode
-*	parameters:
-*		fx, fy, fxp, fyp: pointers to the original parametric
-*			functions and their derivatives.
-*		t1,t2: range over the parameter t where the curve is to 
-*			be fit
-*		deltat: interval of t after initial devision
-*	return value: pointer to a list of guiding triangles
-*/
-Coninode *triangle(fx,fy,fxp,fyp,t1,t2,deltat)
-float (*fx)(), (*fy)(), (*fxp)(), (*fyp)();
-float t1,t2,deltat;
-{
-	Coninode *trilist;
-
-	trilist=init_tri(fx,fy,fxp,fyp,t1,t2,deltat);
-
-	split(fx,fy,fxp,fyp,deltat,trilist); 
-  
-	merget(trilist, fx,fy);	
-	
-	return(trilist);
-}
-
-/*	function name: init_tri
-*	parameters: the same as those of triangle()
-*	return value: a pointer to a list of guiding triangles obtained 
-*		from initial division
-*/
-Coninode *init_tri(fx,fy,fxp,fyp,tb,te,deltat)
-float (*fx)(), (*fy)(), (*fxp)(), (*fyp)();
-float te,tb,deltat;
-{
-	float x1,y1,x2,y2,xp1,xp2,yp1,yp2,t1,t2,b,x3,y3;
-	Coninode *p;
-	Coninode *head=0;
-
-	t2=te;
-	t1=te-deltat;
-	while ((t2-tb)>MINT*deltat) {
-		if (t1<tb) t1=tb;
-		if ((t2-t1)<MINT*deltat)
-			{t2=t1; t1-=deltat; continue;}	
-		
-		/* scaling    	*/
-		x1=sx*fx(t1); x2=sx*fx(t2); 		
-		y1=sy*fy(t1); y2=sy*fy(t2); 
-		xp1=sx*fxp(t1); yp1=sy*fyp(t1);
-		xp2=sx*fxp(t2); yp2=sy*fyp(t2);
-		
-
-		/* check for straight line    */ 		
-		if (fabs(yp1*(x2-x1)-xp1*(y2-y1))<ERR*fabs(xp1*(x2-x1))){
-			p=(Coninode *)malloc(sizeof(Coninode));
-			p->node1.x=x1;  p->node1.y=y1; p->node1.t=t1;
-			p->node2.x=x2;  p->node2.y=y2; p->node2.t=t2;
-			p->node3.x=(x1+x2)/2;	p->node3.y=(y1+y2)/2;
-	
-			p->next=head;
-			head=p;
-			t2=t1; t1-=deltat;
-			continue;
-		}
-		
-		/* if dy/dx is undecidable at node1 or node2, use the value*/ 
-		/* at a nearby point within the interval (t1,t2)           */
-
-		if ((xp1==0) && (yp1==0)) { 
-			xp1=sx*fxp(t1+0.01*deltat);
-			yp1=sy*fyp(t1+0.01*deltat);
-		}
-
-
-		if ((xp2==0) && (yp2==0)) {
-			xp2=sx*fxp(t2-0.01*deltat);
-			yp2=sy*fyp(t2-0.01*deltat);
-		}
-
-		/* check for parallel derivatives */
-		if ((b=xp1*yp2-yp1*xp2)==0) { t2=0.5*(t2+t1); continue;}
-		
-		/* compute the intersection point  */
-		x3=(xp2*(y1*xp1-x1*yp1)-xp1*(y2*xp2-x2*yp2))/b;	
-		y3=(yp2*(y1*xp1-x1*yp1)-yp1*(y2*xp2-x2*yp2))/b;
-
-		/* make a node for this segment    	*/
-		p=(Coninode *)malloc(sizeof(Coninode));
-		p->node1.x=x1;	p->node1.y=y1; p->node1.t=t1;
-		p->node2.x=x2;  p->node2.y=y2; p->node2.t=t2;
-		p->node3.x=x3;  p->node3.y=y3; 
-		p->next=head;
-		head=p;
-		t2=t1; t1-=deltat;
-	}
-	return(head);
-
-}
-
-
-/*	function name: check_tri
-*	parameters: 
-*		x1,y1,t1,x2,y2,t2,x3,y3: coordinates of vertice of the 
-*		  	guiding triangle
-*		fx,fy: pointers to the original parametric functions
-*		return value: 1 if the triangle is in proper shape
-*				0 if not.
-*/
-int check_tri(x1,y1,t1,x2,y2,t2,x3,y3,fx,fy)	
-float x1,y1,x2,y2,x3,y3,t1,t2;
-float (*fx)(), (*fy)();
-{
-	float d,d1,d2,d3,a,b,c,t10,t20,t30;
-
-	/* check for side */
-	a=y1-y2;
-	b=x2-x1;
-	c=x1*y2-x2*y1;
-	t10=t1+0.01*(t2-t1);
-	t20=t2-0.01*(t2-t1);
-	t30=t1+0.5*(t2-t1);
-	if (((a*sx*fx(t10)+b*sy*fy(t10)+c)*(a*sx*fx(t30)+b*sy*fy(t30)+c)<0)
-	    || 
-	  ((a*sx*fx(t20)+b*sy*fy(t20)+c)*(a*sx*fx(t30)+b*sy*fy(t30)+c)<0)) 
-		return(0);
-
-	/* check for shape of the triangle */
-	d3=(y2-y1)*(y2-y1)+(x2-x1)*(x2-x1);
-	d=fabs(x3*(y1-y2)+y3*(x2-x1)+y2*x1-y1*x2)/d3;
-	if ((d)>TANG) return(0);		
-	d1=(y3-y1)*(y3-y1)+(x3-x1)*(x3-x1);
-	d2=(y3-y2)*(y3-y2)+(x3-x2)*(x3-x2);
-	if ( (d2>d3) || (d1>d3) ) return(0);	
-	return (1);
-}
-
-/*	function name: half
-*	parameters: 
-*		fx,fy,fxp,fyp: pointers to the original functions and their
-*				derivatives
-*		p: pointer to the node to be split in a list of triangle 
-*		deltat: initial interval of parameter t
-*/
-half(fx,fy,fxp,fyp,p,deltat)
-float (*fx)(), (*fy)(), (*fxp)(), (*fyp)(); 
-Coninode *p;
-float deltat;
-{
-	Coninode *tp;
-	float t1,t2,t0,x0,y0,x1,y1,x2,y2,x3,y3,x4,y4;
-	float xp0, yp0, xp1, yp1, xp2, yp2;
-	int done=0;
-
-	t1=p->node1.t; x1=p->node1.x;  y1=p->node1.y; 
-	xp1=p->node3.x-x1; yp1=p->node3.y-y1; 	
-	t2=p->node2.t; x2=p->node2.x;  y2=p->node2.y;
-	xp2=x2-p->node3.x; yp2=y2-p->node3.y;
-
-	t0=(t1+t2)/2;   x0=sx*fx(t0);      y0=sy*fy(t0); 
-	xp0=sx*fxp(t0); yp0=sy*fyp(t0);
-
-
-
-	/* looking for an appropriate spliting point */
-	while (!done) {
-   	
-		if ((xp0==0) && (yp0==0)) {
-			xp0=sx*fxp(t2-0.01*deltat);
-			yp0=sy*fyp(t2-0.01*deltat);
-			continue;
-		}
-		if ((xp1*yp0-yp1*xp0)==0) {
-		  if (fabs(yp1*(x0-x1)-xp1*(y0-y1))
-			<ERR*fabs(xp1*(x0-x1))){
-			done=1; continue;
-		   }
-		   else { t0=0.75*t1+0.25*t0; x0=fx(t0); y0=fy(t0);
-			  xp0=sx*fxp(t0); yp0=sy*fyp(t0);
-			   continue;
-		   }
-		}
-		if ((xp2*yp0-yp2*xp0)==0) {
-		   if (fabs(yp2*(x0-x2)-xp2*(y0-y2))<ERR*fabs(xp2*(x0-x2))){
-			done=1; continue;
-	 	   }
-		   else { t0=0.75*t0+0.25*t2; x0=fx(t0); y0=fy(t0);
-			   xp0=sx*fxp(t0); yp0=sy*fyp(t0);
-			    continue;
-		   }
-		}
-		done=1;
-	}
-      
-	/* check for straight line    */
-	if (fabs(yp1*(x0-x1)-xp1*(y0-y1))<ERR*fabs(xp1*(x0-x1))){
-		x3=(x1+x0)/2; y3=(y1+y2)/2;
-	}
-	else {	 		
-		x3=(xp0*(y1*xp1-x1*yp1)-xp1*(y0*xp0-x0*yp0))/(xp1*yp0-yp1*xp0);
-		y3=(yp0*(y1*xp1-x1*yp1)-yp1*(y0*xp0-x0*yp0))/(xp1*yp0-yp1*xp0);
-	}
-
-	if (fabs(yp1*(x0-x1)-xp1*(y0-y1))<ERR*fabs(xp1*(x0-x1))){
-		x4=(x1+x0)/2; y4=(y1+y2)/2;
-	}
-	else{
-		x4=(xp2*(y0*xp0-x0*yp0)-xp0*(y2*xp2-x2*yp2))/(xp0*yp2-yp0*xp2);
-		y4=(yp2*(y0*xp0-x0*yp0)-yp0*(y2*xp2-x2*yp2))/(xp0*yp2-yp0*xp2);
-	}
-
-	/* modify the old node */                          
-	p->node2.t=t0;	p->node2.x=x0;	p->node2.y=y0;
-	p->node3.x=x3;	p->node3.y=y3;
-
-	/* insert a new node */
-	tp=(Coninode *)malloc(sizeof(Coninode));
-	tp->node1.t=t0;	tp->node1.x=x0;	tp->node1.y=y0;
-	tp->node2.t=t2; tp->node2.x=x2; tp->node2.y=y2;
-	tp->node3.x=x4; tp->node3.y=y4;
-
-	tp->next=p->next;
-	p->next=tp; 
-}
-
-
-/* 	function name: split
-*	parameters: 
-*		fx,fy,fxp,fyp: pointers to orig. func. and their derivatives
-*		deltat: initial interval of parameter t
-*		tlist: pointer to the list of triangle to be checked
-*	description: 
-*		going through the list of guiding triangles, splitting when
-*		necessary
-*/
-split(fx,fy,fxp,fyp,deltat,tlist)
-float (*fx)(), (*fy)(), (*fxp)(), (*fyp)();
-float deltat;
-Coninode *tlist;
-{
-	Coninode *p,*pp;
-	p=tlist;
-	while (p!=0) {
-		if (check_tri(p->node1.x, p->node1.y, p->node1.t,
-			      p->node2.x, p->node2.y, p->node2.t,
-			      p->node3.x, p->node3.y,fx,fy)) 
-			/* the triangle is ok. no split necessary*/
-			{pp=p; p=p->next;}
-		else 
-			if ((p->node2.t-p->node1.t)<MINT*deltat){
-			/* the current interval is vsry small */
-			/* The following part may be of future use in */
-			/* dealing with singular points               */
-				/*if (p==tlist) {
-				   tlist=tlist->next;
-				   p=tlist;
-				}
-				else {
-				   pp->next=p->next;
-				   p=pp->next;
-				}
-				*/
-			fprintf(stderr,"Sorry, I can't draw this curve\n");
-			exit(); 
-			}
-			else
-				/* split it  */
-		        	half(fx,fy,fxp,fyp,p,deltat);
-	}
-}
//GO.SYSIN DD Fpt/triangle.c
echo SUNplotter/Makefile 1>&2
sed 's/.//' >SUNplotter/Makefile <<'//GO.SYSIN DD SUNplotter/Makefile'
-SBASE=.
-CFLAGS= -I$(SBASE)
-
-O_S_FILES= sview.o setenv.o
-C_S_FILES= sview.c setenv.c
-O_P_FILES=user_acts.o
-C_P_FILES=user_acts.c
-O_C_FILES=conic_p.o  plotconi.o plotpoly.o cord.o
-C_C_FILES=conic_p.c  plotconi.c plotpoly.c cord.c
-
-OFILES= $(O_S_FILES) $(O_P_FILES)  $(O_C_FILES)
-CFILES= $(C_S_FILES) $(C_P_FILES)  $(C_C_FILES)
-
-plot :	$(OFILES) 
-	cc $(CFLAGS) -o ../../bin/splot $(OFILES) -L$(SBASE) -I$(SBASE) -lsuntool -lsunwindow -lpixrect -lm
-
-$(OFILES): sundef.h plotter.h
-
//GO.SYSIN DD SUNplotter/Makefile
echo SUNplotter/README 1>&2
sed 's/.//' >SUNplotter/README <<'//GO.SYSIN DD SUNplotter/README'
-
-
-This directory contains the source codes for a conic plotter on SUN.
-Excuting "make" will generate the binerary: ../../bin/splot
//GO.SYSIN DD SUNplotter/README
echo SUNplotter/conic_p.c 1>&2
sed 's/.//' >SUNplotter/conic_p.c <<'//GO.SYSIN DD SUNplotter/conic_p.c'
-/***************************************************************/
-/*	Copyright (c)  1990  SUNY at Stony Brook               */
-/***************************************************************/
-
-/* This program draws a given quadrant of a conic              */
-/* input:                                                      */
-/* 	x_b, y_b: begining position                            */
-/*	x_e, y_e: end position                                 */
-/*      a, b, c, d, e, f: cofficients of the given conic       */
-/*		ax*x+2bxy+cy*y+dx+ey+f=0                       */
-/*      delta: distance between adjacent pixels                */
-/*                                                             */
-/* algorithm: the tracking algorithm given by Pratt(85) with   */
-/* 	      modification.                                    */
-
-
-#include <stdio.h>
-#include "sundef.h"
-#include <math.h>
-
-
-struct pixrect *screen, *subscreen;
-
-/* macros to update the value of function and derivatives in   */
-/* differente movements                                        */
-#define UP f+= f_y; f_x+= f_xy; f_y+= f_yy
-#define DOWN f_y-= f_yy; f_x-= f_xy; f-=f_y
-#define RIGHT f+= f_x; f_x+= f_xx; f_y+= f_xy
-#define LEFT f_y-= f_xy; f_x-= f_xx; f-= f_x
- 
-extern int x_w,y_w;
-
-conic_p(x1, y1, x2, y2, a, b, c, d, e, h,w)
-float x1,y1,x2,y2,a,b,c,d,e,h;
-int w;
-{
-	float f, f_x, f_y, f_xx, f_yy, f_xy;
-	int xi,yi,x,y,xdir,ydir,x_b,y_b,x_e,y_e;
-
-	if ((fabs(x2-x1)<=1) && (fabs(y2-y1)<=1)){
-		x=(int)x1-x_w;
-		y=y_w-(int)y1;
-		pw_rop(pixwin,x,y,w,w,PIX_SET,0,0,0);
-		return;
-	}
-
-/*  the following codes draws a line segment using pixrect function  */
-/*  it's not used right now for some pratical reason                 */
-/*
-
-	if ((a==0) && (b==0) && (c==0)) { straight line 
-		xi=(int)x1-x_w; x=(int)x2-x_w;
-		yi=y_w-(int)y1; y=y_w-(int)y2;
-		pw_line(pixwin,xi,yi,x,y,0,0,PIX_SET);
-		return;
-	}
-*/
-
-	ydir=(y2>y1? 1: -1);
-	xdir=(x2>x1? 1: -1);
-
-
-	x_b=(int)x1;
-	y_b=(int)y1;
-	x_e=(int)x2;
-	y_e=(int)y2;	
-
-
-	f=a*x_b*x_b+2*b*x_b*y_b+c*y_b*y_b+d*x_b+e*y_b+h;
-	f_x=2*a*x_b+a+2*b*y_b+d;
-	f_y=2*c*y_b+c+2*b*x_b+e;
-	f_xx=2*a;
-	f_yy=2*c;
-	f_xy=2*b;
-
-	xi=x_b; 	yi=y_b;
-
-	if (abs(y_b-y_e)<abs(x_b-x_e)) /* x greedy   */
-		while ((xdir*(x_e-xi)>= -1) && (ydir*(y_e-yi)>= -1)){
-			x=xi-x_w; 
-			y=y_w-yi;
-			pw_rop(pixwin,x,y,w,w,PIX_SET,0,0,0);
-			
-			/* update */
- 			if (fabs(f+ydir*f_y)<fabs(f))
-				if (ydir==1) {UP; yi+=1;}
-					else {DOWN; yi-=1;}
-  			else 
-				if (xdir==1) {RIGHT; xi+=1;}
-					else {LEFT; xi-=1;}
-		}
-
-	else  	/* y greedy   */
-		while ((xdir*(x_e-xi)>= -1) && (ydir*(y_e-yi)>= -1)){
-			x=xi-x_w;
-			y=y_w-yi;
-			pw_rop(pixwin,x,y,w,w,PIX_SET,0,0,0);
-
-			/* update */
-			if (fabs(f+xdir*f_x)<fabs(f))
-				if (xdir==1) {RIGHT; xi+=1;}
-					else {LEFT; xi-=1;}
-			else
-				if (ydir==1) {UP; yi+=1;}
-					else {DOWN; yi-=1;}
-	}
-	return;	
-}
//GO.SYSIN DD SUNplotter/conic_p.c
echo SUNplotter/cord.c 1>&2
sed 's/.//' >SUNplotter/cord.c <<'//GO.SYSIN DD SUNplotter/cord.c'
-/***************************************************************/
-/*	Copyright (c)  1990  SUNY at Stony Brook               */
-/***************************************************************/
-#include <math.h>
-#include "plotter.h"
-#include "sundef.h"
-#include <stdio.h>
-
-
-/* function to draw the coordinates */
-cord()
-{
-        float length,delta,inc;
-        int i,cx, cy, p;
-        char s[10];
-		
-        delta=range/(w_width-2*MARGIN);
-	cx=0-x_w; cy=y_w;	
-
-	/* draw x axis */
-	inc=1;			
-	length=(x_max-x_min)/(x_s*NI);
-	if (length>=1){
-		while (inc<length) inc*=10;
-		if (inc>=2*length) inc=inc/2;
-	}
-	else{
-		while (inc>length) inc*=0.1;
-		if ((inc=inc*10)>2*length) inc=inc/2;
-	}
-
-	pw_line(pixwin,10, cy, w_width-10, cy, 0,0,PIX_SET);
-	if (inc!=0){
-	   for (i=1; (p=cx+i*inc*x_s/delta)<w_width; i++){
-		sprintf(s,"%g",(i*inc));
-		pw_line(pixwin,p,cy-2, p, cy+2, 0,0, PIX_SET);
-		pw_text(pixwin,p,cy+10,PIX_SRC,deffont,s);
-	   }
-	   for (i=1; (p=cx-i*inc*x_s/delta)>0; i++){
-		sprintf(s,"%g",(-i*inc));
-		pw_line(pixwin,p,cy-2, p, cy+2, 0,0, PIX_SET);
-		pw_text(pixwin,p,cy+10,PIX_SRC,deffont,s); 
-	   }
-	}
-
-	/* draw y axis */
-	inc=1;
-	length=(y_max-y_min)/(y_s*NI);
-	if (length>=1){
-		while (inc<length) inc*=10;
-		if (inc>=2*length) inc=inc/2;
-	}
-	else{
-		while (inc>length) inc*=0.1;
-		if ((inc=inc*10)>2*length) inc=inc/2;
-	}
-
-	pw_line(pixwin,cx,10,cx,w_height-10, 0,0,PIX_SET);
-	if (inc!=0) {
-      	   for (i=1; (p=cy+i*inc*y_s/delta)<w_height; i++){
-		sprintf(s,"%g",(-i*inc));
-		pw_line(pixwin,cx-2,p, cx+2,p, 0,0, PIX_SET);
-		pw_text(pixwin,cx+1,p,PIX_SRC,deffont,s);
-	   }
-	   for (i=1; (p=cy-i*inc*y_s/delta)>0; i++){
-		sprintf(s,"%g",(i*inc));
-                pw_line(pixwin,cx-2,p, cx+2,p, 0,0, PIX_SET);
-		pw_text(pixwin,cx+1,p,PIX_SRC,deffont,s);
-	   }
-	}
-}	
//GO.SYSIN DD SUNplotter/cord.c
echo SUNplotter/plotconi.c 1>&2
sed 's/.//' >SUNplotter/plotconi.c <<'//GO.SYSIN DD SUNplotter/plotconi.c'
-/***************************************************************/
-/*      Copyright (c)  1990  SUNY at Stony Brook               */
-/***************************************************************/
-
-
-/*	plotconi.c: subroutine for plotting a list of conics        */
-/*		    It makes proper scale transformation before     */
-/*		    calling the the conic plotting function         */
-/*	functions called: conic_p() in conic_p.c                    */
-
-
-
-#include <math.h>
-#include "sundef.h"
-#include <stdio.h>
-#include "plotter.h"
-
-
-plotconi()
-
-{	
-	float temp,delta,x1,x2,y1,y2,a,b,c,d,e,f;
-	int i;
-
-	delta=range/(w_width-2*MARGIN);
-	
-	for (i=0; i<num; i++){
-		/* scale transformation */
-		x1=cc[i].x1/delta;	
-		y1=cc[i].y1/delta;
-		x2=cc[i].x2/delta;	
-		y2=cc[i].y2/delta;
-		a=cc[i].a;	
-		b=cc[i].b;
-		c=cc[i].c;	
-		d=cc[i].d/delta;
-		e=cc[i].e/delta;	
-		f=cc[i].f/(delta*delta);
-
-		conic_p(x1,y1,x2,y2,a,b,c,d,e,f,c_width);
-	}
-}
//GO.SYSIN DD SUNplotter/plotconi.c
echo SUNplotter/plotpoly.c 1>&2
sed 's/.//' >SUNplotter/plotpoly.c <<'//GO.SYSIN DD SUNplotter/plotpoly.c'
-/***************************************************************/
-/*      Copyright (c)  1990  SUNY at Stony Brook               */
-/***************************************************************/
-
-
-/*   plotpoly.c: function for plotting polygons                   */
-#include <math.h>		
-#include "plotter.h"
-#include "sundef.h"
-#include <stdio.h>
-
-
-plotpoly()
-
-{
-
-	float temp,delta;
-	int i,x1,x2,y1,y2;
-
-
-	delta=range/(w_width-2*MARGIN);
-
-
-
-
-for (i=0; i<num; i++){
-
-                x1=(int)(cc[i].x1/delta)-x_w;
-		y1=y_w-(int)(cc[i].y1/delta);
-		x2=(int)(cc[i].x2/delta)-x_w;
-		y2=y_w-(int)(cc[i].y2/delta);
-								
-		pw_line(pixwin,x1,y1,x2,y2,0,0,PIX_SET);
-
-	}
-	return;
-			
-}
//GO.SYSIN DD SUNplotter/plotpoly.c
echo SUNplotter/plotter.h 1>&2
sed 's/.//' >SUNplotter/plotter.h <<'//GO.SYSIN DD SUNplotter/plotter.h'
-/***************************************************************/
-/*      Copyright (c)  1990  SUNY at Stony Brook               */
-/***************************************************************/
-
-
-/*	plotter.h: head file for plotter on sunview	        */
-
-#define NUM 100     /* maximum expected number of conics */
-#define NI 6        /* number of intervals disgnated along each 
-		     * axis
-		     */
-typedef struct coniq{
-	float x1,x2,y1,y2,a,b,c,d,e,f;
-} Coniq;
-
-extern Coniq cc[];  /* array of conic curves	*/
//GO.SYSIN DD SUNplotter/plotter.h
echo SUNplotter/setenv.c 1>&2
sed 's/.//' >SUNplotter/setenv.c <<'//GO.SYSIN DD SUNplotter/setenv.c'
-/***************************************************************/
-/*      Copyright (c)  1990  SUNY at Stony Brook               */
-/***************************************************************/
-
-/* 	setenv.c: routines to set up sun view enviroment for          */
-/*    		  curve display                                       */
-
-#include "sundef.h"
-
-init_frame()
-{
-	deffont = pf_open("/usr/lib/fonts/fixedwidthfonts/cour.r.10");
-	frame = window_create(NULL, FRAME,
-	    WIN_X,      w_x_start,
-	    WIN_Y,      w_y_start,
-	    WIN_ERROR_MSG,  "Cant create base fr",
-	    0);
-
-	canvas = window_create(frame, CANVAS,
-	    WIN_EVENT_PROC, work_proc,
-       	    WIN_CONSUME_KBD_EVENT, WIN_ASCII_EVENTS,
-	    WIN_CONSUME_PICK_EVENT, LOC_DRAG,
-	    WIN_WIDTH,      w_width,
-	    WIN_HEIGHT,     w_height,
-	    WIN_ERROR_MSG,  "Cant create canvas",
-	    0);
-
-	pixwin = canvas_pixwin(canvas);
-
-	/*	Make frame fit canvas exactly */
-	window_fit(frame);
-	
-	/* create the menu */
-	menu = menu_create(
-	    MENU_DEFAULT_SELECTION,     MENU_DEFAULT,
-	    MENU_INITIAL_SELECTION,     MENU_SELECTED,
-	    MENU_INITIAL_SELECTION_SELECTED,        TRUE,
-	    MENU_TITLE_ITEM,        "Activities",
-		MENU_STRINGS,		MENU_LIST, 0,
-	    0 );
-}
//GO.SYSIN DD SUNplotter/setenv.c
echo SUNplotter/sundef.h 1>&2
sed 's/.//' >SUNplotter/sundef.h <<'//GO.SYSIN DD SUNplotter/sundef.h'
-/***************************************************************/
-/*      Copyright (c)  1990  SUNY at Stony Brook               */
-/***************************************************************/
-
-/* sundef.h	definitions for SUNVIEW		*/
-
-#include <suntool/sunview.h>
-#include <suntool/canvas.h>
-#include <ctype.h>
-#include <fcntl.h>
-
-#define MENU_LIST "clear","plot curve","coordinates","show segments","exit"
-#define UPPER_LEFT_X    100
-#define UPPER_LEFT_Y    100
-#define WINDOW_WIDTH    500
-#define WINDOW_HEIGHT   500
-#define MARGIN 50
-
-extern Frame frame;
-extern Canvas canvas;
-extern Pixwin *pixwin;
-extern Menu menu;
-extern struct pixfont *deffont;
-
-extern void work_proc();
-extern init_frame();
-
-extern int w_x_start;
-extern int w_y_start;
-extern int w_width;
-extern int w_height;
-extern int c_width;   /* width of the curve */
-
-extern int    x_w,y_w;    /*position of the upper left conner of window in */
-		         /*the object coordinate                          */
-extern float x_min,x_max,y_min,y_max,range; /*range of the input function */
-					    /* (scaled) */
-extern int x_s, y_s;   /* scaling factor of x and y coordinate       */
-
-extern int num;          /* number of conics */
//GO.SYSIN DD SUNplotter/sundef.h
echo SUNplotter/sview.c 1>&2
sed 's/.//' >SUNplotter/sview.c <<'//GO.SYSIN DD SUNplotter/sview.c'
-/*******************************************************/
-/*	Copyright (c)  1990  SUNY at Stony Brook       */
-/*******************************************************/
-
-/*	sview.c: main function of sunview plotter                */
-
-#include "sundef.h"
-#include "plotter.h"
-#include <stdio.h>
-#include <math.h>
-
-Frame frame;
-Canvas canvas;
-Pixwin *pixwin;
-Menu menu;
-struct pixfont *deffont;
-
-int x_w,y_w;	/* position of the upper left corner of the window */
-int num;	/* number of conics */
-float x_min,x_max,y_min,y_max,range;
-int x_s, y_s;
-Coniq cc[NUM];
-
-int w_x_start = UPPER_LEFT_X;	/* window position and size */
-int w_y_start = UPPER_LEFT_Y;
-int w_width = WINDOW_WIDTH;
-int w_height = WINDOW_HEIGHT;
-int c_width=1;                  /* width of curve */
-
-input();
-
-main(arc, arv)
-char **arv;
-{	
-	float xr,yr;	
-	
-	while(arc>1 && arv[1][0]=='-') {
-		switch(arv[1][1]){
-		case 'x':       w_x_start = atoi(arv[1]+2);
-				break;
-		case 'y':       w_y_start = atoi(arv[1]+2);
-				break;
-		case 'W':       w_width=w_height= atoi(arv[1]+2);
-				break;
-		case 'w': 	c_width=atoi(arv[1]+2);
-		}
-		arc--;  arv++;
-	}
-
-	input();
-
-	xr=fabs(x_min-x_max);
-	yr=fabs(y_min-y_max);
-
-/*printf("xmax:%f, xmin:%f, ymax:%f, ymin:%f",x_max,x_min,y_max,y_min);*/
-
-	range=(xr>yr? xr:yr);
-
-        /* compute the position of the upper left corner of the window    */
-	/* ( this decide the relative position of the curve in the window */ 
-	x_w=0.5*(x_min+x_max)/range*(w_width-2*MARGIN)-0.5*w_width;
-	y_w=0.5*(y_min+y_max)/range*(w_height-2*MARGIN)+0.5*w_height;
-		
-	init_frame();		
-	window_main_loop(frame); 
-
-}
-
-/* input(): function to input data of the curve to be plotted  */
-input()
-{	static char s[512];
-	register i=0;
-
-	gets(s);
-	sscanf(s,"%d %d", &x_s, &y_s);
-	gets(s);
-	sscanf(s,"%g %g %g %g ",&x_min,&x_max,&y_min,&y_max);
-	
-	while (gets(s)){
-	sscanf(s,"%g%g%g%g%g%g%g%g%g%g",&cc[i].x1,&cc[i].y1,&cc[i].x2,&cc[i].y2,&cc[i].a,&cc[i].b,&cc[i].c,&cc[i].d,&cc[i].e,&cc[i].f);
-	i++;
-	}
-	num=i+1;
-}
//GO.SYSIN DD SUNplotter/sview.c
echo SUNplotter/user_acts.c 1>&2
sed 's/.//' >SUNplotter/user_acts.c <<'//GO.SYSIN DD SUNplotter/user_acts.c'
-/*****************************************************/
-/*	Copyright (c)  1990  SUNY at Stony Brook     */
-/*****************************************************/
-
-/* user_acts.c  mouse manu selection	       */
-/*	      and event procedure for canvas   */
-
-
-#include <stdio.h>
-#include "sundef.h"
-
-
-/*	Procedure handling events. it's registered with 	 */
-/*	the WIN_EVENT_PROC attribute of window_create(.. CANVAS) */
-/*	in file setenv.c                                         */
-
-void work_proc(window, event, arg)
-Window window;
-Event *event;
-caddr_t arg;	/*	pointer to char string	*/
-{
-	int itemnum;
-	register j;
-
-
-/*	log_mouse_state(event);      */
-	switch(event_id(event)) {
-	case MS_RIGHT:
-
-		/* Bring up the menu */
-		itemnum= (int) menu_show(menu, frame, event, 0);
-
-		/* Menu item numbering starts at 2;correct for this. */
-		itemnum--;
-		mselect(itemnum);
-	default:
-		break;
-	}
-}
-
-
-/* procedure to call user programs according to mouse selection*/
-extern cord();
-extern plotconi();
-extern plotpoly();
-
-mselect(num)
-int num;
-{
-
-	switch(num) {
-	case 1:
-		pw_rop(pixwin, 0, 0, w_width,w_height,PIX_CLR,0,0,0);
-		return;
-	case 2:
-		plotconi();		
-		return;
-	case 3: 
-		cord();
-		return;
-	case 4:		
-		plotpoly();
-		return;
-	case 5:
-		exit();
-	default:
-		return;
-	}
-}
//GO.SYSIN DD SUNplotter/user_acts.c
echo Xplotter/Makefile 1>&2
sed 's/.//' >Xplotter/Makefile <<'//GO.SYSIN DD Xplotter/Makefile'
-CFLAGS= -g
-O_S_FILES= xmain.o setenv.o
-O_C_FILES=conic_p.o  plotconi.o plotpoly.o coord.o extra.o
-
-
-
-
-OFILES= $(O_S_FILES) $(O_C_FILES)
-
-xplot :	$(OFILES) 
-	cc $(CFLAGS) -o ../../bin/xplot $(OFILES) -L/usr/lib/X11 -lXaw -lXmu -lXext -lXt -lX11 -lm
-
-$(OFILES): xdef.h plotter.h
-
//GO.SYSIN DD Xplotter/Makefile
echo Xplotter/README 1>&2
sed 's/.//' >Xplotter/README <<'//GO.SYSIN DD Xplotter/README'
-
-
-This directory contains the source codes for a conic plotter on X window.
-Excuting "make" generates the binerary: ../../bin/xplot
-
//GO.SYSIN DD Xplotter/README
echo Xplotter/conic_p.c 1>&2
sed 's/.//' >Xplotter/conic_p.c <<'//GO.SYSIN DD Xplotter/conic_p.c'
-/***************************************************************/
-/*	Copyright (c)  1990  SUNY at Stony Brook               */
-/***************************************************************/
-
-
-
-/* conic_p.c: This program draws a given quadrant of a conic   */
-/* input:                                                      */
-/* 	x_b, y_b: begining position                            */
-/*	x_e, y_e: end position                                 */
-/*      a, b, c, d, e, f: cofficients of the given conic       */
-/*		ax*x+2bxy+cy*y+dx+ey+f=0                       */
-/*      delta: distance between adjacent winels                */
-/*                                                             */
-/* algorithm: the tracking algorithm given by Pratt with       */
-/* 	      modification.                                    */
-
-
-#include <stdio.h>
-#include "xdef.h"
-#include <math.h>
-
-
-
-/* macros to update the value of function and derivatives in   */
-/* differente movements                                        */
-#define UP f+= f_y; f_x+= f_xy; f_y+= f_yy
-#define DOWN f_y-= f_yy; f_x-= f_xy; f-=f_y
-#define RIGHT f+= f_x; f_x+= f_xx; f_y+= f_xy
-#define LEFT f_y-= f_xy; f_x-= f_xx; f-= f_x
- 
-extern int x_w,y_w;
-
-conic_p(x1, y1, x2, y2, a, b, c, d, e, h,w)
-float x1,y1,x2,y2,a,b,c,d,e,h;
-int w;
-{
-	float f, f_x, f_y, f_xx, f_yy, f_xy;
-	int xi,yi,x,y,xdir,ydir,x_b,y_b,x_e,y_e;
-
-	if ((fabs(x2-x1)<=1) && (fabs(y2-y1)<=1)){
-		x=(int)x1-x_w;
-		y=y_w-(int)y1;
-		XDrawRectangle(display,win,gc,x,y,w,w);
-		return;
-	}
-
-/*  the following codes draws a line segment using winrect function  */
-/*  it's not used right now for some pratical reason                 */
-/*
-
-	if ((a==0) && (b==0) && (c==0)) { straight line 
-		xi=(int)x1-x_w; x=(int)x2-x_w;
-		yi=y_w-(int)y1; y=y_w-(int)y2;
-		pw_line(winwin,xi,yi,x,y,0,0,PIX_SET);
-		return;
-	}
-*/
-
-	ydir=(y2>y1? 1: -1);
-	xdir=(x2>x1? 1: -1);
-
-
-	x_b=(int)x1;
-	y_b=(int)y1;
-	x_e=(int)x2;
-	y_e=(int)y2;	
-
-
-	f=a*x_b*x_b+2*b*x_b*y_b+c*y_b*y_b+d*x_b+e*y_b+h;
-	f_x=2*a*x_b+a+2*b*y_b+d;
-	f_y=2*c*y_b+c+2*b*x_b+e;
-	f_xx=2*a;
-	f_yy=2*c;
-	f_xy=2*b;
-
-	xi=x_b; 	yi=y_b;
-
-	if (abs(y_b-y_e)<abs(x_b-x_e)) /* x greedy   */
-		while ((xdir*(x_e-xi)>= -1) && (ydir*(y_e-yi)>= -1)){
-			x=xi-x_w; 
-			y=y_w-yi;
-			XDrawRectangle(display, win, gc, x, y, w, w);
-			
-			/* update */
- 			if (fabs(f+ydir*f_y)<fabs(f))
-				if (ydir==1) {UP; yi+=1;}
-					else {DOWN; yi-=1;}
-  			else 
-				if (xdir==1) {RIGHT; xi+=1;}
-					else {LEFT; xi-=1;}
-		}
-
-	else  	/* y greedy   */
-		while ((xdir*(x_e-xi)>= -1) && (ydir*(y_e-yi)>= -1)){
-			x=xi-x_w;
-			y=y_w-yi;
-			XDrawRectangle(display, win, gc, x, y, w, w);
-
-			/* update */
-			if (fabs(f+xdir*f_x)<fabs(f))
-				if (xdir==1) {RIGHT; xi+=1;}
-					else {LEFT; xi-=1;}
-			else
-				if (ydir==1) {UP; yi+=1;}
-					else {DOWN; yi-=1;}
-	}
-	return;	
-}
//GO.SYSIN DD Xplotter/conic_p.c
echo Xplotter/coord.c 1>&2
sed 's/.//' >Xplotter/coord.c <<'//GO.SYSIN DD Xplotter/coord.c'
-/***************************************************************/
-/*	Copyright (c)  1990  SUNY at StonyBrook                */
-/***************************************************************/
-#include <math.h>
-#include "plotter.h"
-#include "xdef.h"
-#include <stdio.h>
-#include <string.h>
-
-void coord()
-{
-        float length,delta,inc;
-        int i,cx, cy, p;
-        char s[10];
-		
-        delta=range/(w_width-2*MARGIN);
-	cx=0-x_w; cy=y_w;	
-
-	/* draw x axis */
-	inc=1;			
-	length=(x_max-x_min)/(x_s*NI);
-	if (length>=1){
-		while (inc<length) inc*=10;
-		if (inc>=2*length) inc=inc/2;
-	}
-	else{
-		while (inc>length) inc*=0.1;
-		if ((inc=inc*10)>2*length) inc=inc/2;
-	}
-
-	XDrawLine(display,win,gc,10, cy, w_width-10, cy);
-	if (inc!=0){
-	   for (i=1; (p=cx+i*inc*x_s/delta)<w_width; i++){
-		sprintf(s,"%g",(i*inc));
-		XDrawLine(display,win,gc,p,cy-2, p, cy+2);
-		XDrawString(display,win,gc,p,cy+10,s,strlen(s));
-	   }
-	   for (i=1; (p=cx-i*inc*x_s/delta)>0; i++){
-		sprintf(s,"%g",(-i*inc));
-		XDrawLine(display,win,gc,p,cy-2, p, cy+2);
-		XDrawString(display,win,gc,p,cy+10,s,strlen(s)); 
-	   }
-	}
-
-	/* draw y axis */
-	inc=1;
-	length=(y_max-y_min)/(y_s*NI);
-	if (length>=1){
-		while (inc<length) inc*=10;
-		if (inc>=2*length) inc=inc/2;
-	}
-	else{
-		while (inc>length) inc*=0.1;
-		if ((inc=inc*10)>2*length) inc=inc/2;
-	}
-
-	XDrawLine(display,win,gc,cx,10,cx,w_height-10);
-	if (inc!=0) {
-      	   for (i=1; (p=cy+i*inc*y_s/delta)<w_height; i++){
-		sprintf(s,"%g",(-i*inc));
-		XDrawLine(display,win,gc,cx-2,p, cx+2,p);
-		XDrawString(display,win,gc,cx+1,p,s,strlen(s));
-	   }
-	   for (i=1; (p=cy-i*inc*y_s/delta)>0; i++){
-		sprintf(s,"%g",(i*inc));
-                XDrawLine(display,win,gc,cx-2,p, cx+2,p);
-		XDrawString(display,win,gc,cx+1,p,s,strlen(s));
-	   }
-	}
-	/* backup to pixmap */
-	 XCopyArea(display, win,pix, gc, 0, 0, w_width,w_height,0,0);
-	return;
-}	
//GO.SYSIN DD Xplotter/coord.c
echo Xplotter/extra.c 1>&2
sed 's/.//' >Xplotter/extra.c <<'//GO.SYSIN DD Xplotter/extra.c'
-/***************************************************************/
-/*      Copyright (c)  1990  SUNY at StonyBrook                */
-/***************************************************************/
-
-#include "xdef.h"
-#include "plotter.h"
-
-void clear()
-{
-	XClearWindow(display, win);
-	XCopyArea(display, win,pix, gc, 0, 0, w_width,w_height,0,0);
-}
-
-void quit(w)
-Widget w;
-{
-	XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
-	exit(0);
-}
//GO.SYSIN DD Xplotter/extra.c
echo Xplotter/plotconi.c 1>&2
sed 's/.//' >Xplotter/plotconi.c <<'//GO.SYSIN DD Xplotter/plotconi.c'
-/***************************************************************/
-/*      Copyright (c)  1990  SUNY at StonyBrook                */
-/***************************************************************/
-
-
-/*	plotconi.c: subroutine for plotting a list of conics        */
-/*		    It makes proper scale transformation before     */
-/*		    calling the the conic plotting function         */
-/*	functions called: conic_p() in conic_p.c                    */
-
-
-
-#include <math.h>
-#include "xdef.h"
-#include <stdio.h>
-#include "plotter.h"
-
-
-void plotconi()
-
-{	
-	float temp,delta,x1,x2,y1,y2,a,b,c,d,e,f;
-	int i;
-
-	delta=range/(w_width-2*MARGIN);
-	
-	for (i=0; i<num; i++){
-		/* scale transformation */
-		x1=cc[i].x1/delta;	
-		y1=cc[i].y1/delta;
-		x2=cc[i].x2/delta;	
-		y2=cc[i].y2/delta;
-		a=cc[i].a;	
-		b=cc[i].b;
-		c=cc[i].c;	
-		d=cc[i].d/delta;
-		e=cc[i].e/delta;	
-		f=cc[i].f/(delta*delta);
-
-		conic_p(x1,y1,x2,y2,a,b,c,d,e,f,c_width);
-	}
-	/* backup to pixmap */
-	XCopyArea(display, win,pix, gc, 0, 0, w_width,w_height,0,0);
-}
//GO.SYSIN DD Xplotter/plotconi.c
echo Xplotter/plotpoly.c 1>&2
sed 's/.//' >Xplotter/plotpoly.c <<'//GO.SYSIN DD Xplotter/plotpoly.c'
-/***************************************************************/
-/*      Copyright (c)  1990  SUNY at StonyBrook                */
-/***************************************************************/
-#include <math.h>		
-#include "plotter.h"
-#include "xdef.h"
-#include <stdio.h>
-
-
-void plotpoly()
-
-{
-
-	float temp,delta;
-	int i,x1,x2,y1,y2;
-
-
-	delta=range/(w_width-2*MARGIN);
-
-
-
-
-	for (i=0; i<num; i++){
-
-                x1=(int)(cc[i].x1/delta)-x_w;
-		y1=y_w-(int)(cc[i].y1/delta);
-		x2=(int)(cc[i].x2/delta)-x_w;
-		y2=y_w-(int)(cc[i].y2/delta);
-								
-		XDrawLine(display, win, gc, x1,y1,x2,y2);
-
-	}
-       XCopyArea(display, win, pix, gc, 0, 0, w_width,w_height,0,0);
-			
-}
//GO.SYSIN DD Xplotter/plotpoly.c
echo Xplotter/plotter.h 1>&2
sed 's/.//' >Xplotter/plotter.h <<'//GO.SYSIN DD Xplotter/plotter.h'
-/***************************************************************/
-/*      Copyright (c)  1990  SUNY at StonyBrook                */
-/***************************************************************/
-
-#define NUM 100     /* maximum expected number of conics */
-#define NI 6        /* number of intervals disgnated along each
-		     * axis
-		     */ 
-
-typedef struct coniq{
-	float x1,x2,y1,y2,a,b,c,d,e,f;
-} Coniq;
-
-extern Coniq cc[];  /* array of conic curves	*/
//GO.SYSIN DD Xplotter/plotter.h
echo Xplotter/setenv.c 1>&2
sed 's/.//' >Xplotter/setenv.c <<'//GO.SYSIN DD Xplotter/setenv.c'
-/***************************************************************/
-/*      Copyright (c)  1990  SUNY at StonyBrook                */
-/***************************************************************/
-
-
-/* setenv.c: subroutines to set up x win enviroment for */
-/*	     curve display                              */
-
-#include "xdef.h"
-
-XtTranslations localTranslationsParsed;
-String fallback_resources[] = { 
-  "*menu.label:		    Xwindow Plotter",
-  "*menuLabel.vertSpace:	    100",
-  "*blank.height:		    20",
-  "*canvas.height:   		    500",
-  "*canvas.width:   		    500",
-  NULL,
-};
-
-/* Add whatever fields you want passed to the callback proc
-   upon menu activation
-   */
-typedef int menu_arg;
-
-struct menu_item_desc {
-  char *label;
-  XtCallbackProc p;
-  menu_arg arg;
-};
-
-
-struct menu_item_desc mid[] = {
-  {"plot curve", plotconi, 0},
-  {"show coordinates", coord , 1},
-  {"show segments", plotpoly, 2},
-  {"clear", clear, 3},
-  {"quit", quit, 4}
-};
-
-void setup_menu(canvas, menup)
-     Widget canvas;
-     Widget *menup;
-{
-  int i;
-  Widget entry;
-  *menup = XtCreatePopupShell("menu", simpleMenuWidgetClass, canvas, 
-			    NULL, ZERO);
-  
-  for (i = 0; i < (int) XtNumber(mid) ; i++) {
-    
-    entry = XtCreateManagedWidget(mid[i].label, smeBSBObjectClass, *menup,
-				  NULL, ZERO);
-    XtAddCallback(entry, XtNcallback, mid[i].p,
-		  (caddr_t)(mid+i));
-
-  }
-  
-}
-
-/*function name: redraw
-*description: copy the contents from the pixmap to the canvas
-*/
-void redraw()
-{
-	 XCopyArea(display, pix,win, gc, 0, 0, w_width,w_height,0,0);
-}
-	
-
-init_frame(argc, argv)
-int argc;
-char **argv;
-{
-
-	static XtActionsRec act_rec[]={
-	    {"Expose_canvas", redraw}
-	};
-
-	static String localTranslations=
-	    "<Btn1Down>:XawPositionSimpleMenu(menu) MenuPopup(menu)\n\
-	     <Expose>:Expose_canvas()";
-  
-	top = XtAppInitialize(&app_con, "Xmenu1", NULL, ZERO,
-			&argc, argv, fallback_resources, NULL, ZERO);
-  
-  	XtAppAddActions(app_con, act_rec, XtNumber(act_rec));
- 
-	canvas =
-	XtCreateManagedWidget("canvas", coreWidgetClass,top,
-			  NULL, ZERO);
-
-	localTranslationsParsed=XtParseTranslationTable(localTranslations);
-	XtAugmentTranslations(canvas, localTranslationsParsed);  
-
-	setup_menu(canvas, &menu);
-
-  	XtRealizeWidget(top);
-
-	/* Retrieve standard Xlib-level parameters */
-	display=XtDisplay(canvas);
-	screen=XDefaultScreen(display);
-	gc=DefaultGC(display, screen);
-	win=XtWindow(canvas);
-
-	/* creat pixmap */
-	pix=XCreatePixmap(display, win, w_width, w_height,8);
-
-	/* clear the pixmap */
-
-	XSetFunction(display, gc, GXclear);
-	XFillRectangle(display, pix, gc, 0, 0, w_width, w_height);
-	XSetFunction(display, gc, GXcopy);
-
-	/* clear the canvas and pixmap*/
-	XClearWindow(display, win);
-	XCopyArea(display, win,pix, gc, 0, 0, w_width,w_height,0,0);
-
-	
-}
-
-
//GO.SYSIN DD Xplotter/setenv.c
echo Xplotter/xdef.h 1>&2
sed 's/.//' >Xplotter/xdef.h <<'//GO.SYSIN DD Xplotter/xdef.h'
-/***************************************************************/
-/*      Copyright (c)  1990  SUNY at StonyBrook                */
-/***************************************************************/
-
-/*	xdef.h	definitions for xwindow		*/
-
-#include <stdio.h>
-#include <X11/Intrinsic.h>
-#include <X11/StringDefs.h>
-
-#include <X11/Xaw/SimpleMenu.h>
-#include <X11/Xaw/Sme.h>
-#include <X11/Xaw/SmeBSB.h>
-#include <X11/Xaw/Paned.h>
-#include <X11/Xaw/Command.h>
-#include <X11/Xaw/Box.h>
-#include <X11/Xaw/Cardinals.h>
-
-extern void plotconi(), plotpoly(), coord(), clear(), quit();
-
-#define W_WIDTH    500
-#define W_HEIGHT   500
-#define MARGIN 50
-
-extern XtAppContext app_con;
-extern Widget top, canvas;
-extern Widget menu;
-
-extern Display *display;
-extern int screen;
-extern Window win;
-extern GC gc;
-extern Pixmap pix;
-
-extern unsigned int w_width;	/* width of the window*/
-extern unsigned int w_height;	/* height of the window */
-extern int c_width;   /* width of the curve */
-
-extern int    x_w,y_w;    /*position of the upper left conner of window in */
-		         /*the object coordinate                          */
-extern float x_min,x_max,y_min,y_max,range; /*range of the input function */
-					    /* (scaled) */
-extern int x_s, y_s;   /* scaling factor of x and y coordinate       */
-
-extern int num;          /* number of conics */
//GO.SYSIN DD Xplotter/xdef.h
echo Xplotter/xmain.c 1>&2
sed 's/.//' >Xplotter/xmain.c <<'//GO.SYSIN DD Xplotter/xmain.c'
-/***************************************************************/
-/*      Copyright (c)  1990  SUNY at StonyBrook                */
-/***************************************************************/
-
-/* xmain.c: main function for x window plotter */
-
-#include "xdef.h"
-#include "plotter.h"
-#include <stdio.h>
-#include <math.h>
-
-XtAppContext app_con;
-Widget top, canvas;
-Widget menu; 
-Display *display;
-int screen;
-Window win;
-GC gc;
-Pixmap pix;
-
-int x_w,y_w;    /* position of the upper left corner of the window */
-int num;       	 	/* number of conics */ 
-float x_min,x_max,y_min,y_max,range;
-int x_s, y_s;   	/* scaling factor */
-Coniq cc[NUM];  	/* list of conics */
-
-unsigned int w_width = W_WIDTH;	/* window size */
-unsigned int w_height = W_HEIGHT;
-int c_width=1; 		/* width of curve */
-
-input();
-
-main(arc, arv)
-char **arv;
-{
-	float xr,yr;
-	while(arc>1 && arv[1][0]=='-') {
-		switch(arv[1][1]){
-		case 'W':       w_width=w_height= atoi(arv[1]+2);
-				break;
-		case 'w':       c_width=atoi(arv[1]+2);
-				break;
-		}
-		arc--;  arv++;
-	}
-
-	input();
-	
-	xr=fabs(x_min-x_max);
-	yr=fabs(y_min-y_max);
-	range=(xr>yr? xr:yr);
-	
-	/* compute the position of the upper left corner of the window    */
-	/* ( this decide the relative position of the curve in the window */
-	x_w=0.5*(x_min+x_max)/range*(w_width-2*MARGIN)-0.5*w_width;
-	y_w=0.5*(y_min+y_max)/range*(w_height-2*MARGIN)+0.5*w_height;
-	
-	init_frame(arc,arv);
-	XtAppMainLoop(app_con);
-}
-
-/* function name: input()
- * description: input a list of conics to be plotted
-*/
-input()
-{	static char s[512];
-	register i=0;
-	
-	gets(s);
-	sscanf(s,"%d %d", &x_s, &y_s);
-	gets(s);
-	sscanf(s,"%g %g %g %g ",&x_min,&x_max,&y_min,&y_max);
-
-	while (gets(s)){
-	sscanf(s,"%g%g%g%g%g%g%g%g%g%g",&cc[i].x1,&cc[i].y1,&cc[i].x2,&cc[i].y2,&cc[i].a,&cc[i].b,&cc[i].c,&cc[i].d,&cc[i].e,&cc[i].f);
-	i++;
-	}
-	num=i+1;
-}
//GO.SYSIN DD Xplotter/xmain.c