[comp.sys.concurrent] Masscomp's GPS data to PostScript converter

mahmud@soma.neusc.bcm.tmc.edu (Mahmud Haque) (02/12/90)

This package includes the  source  for   "gpstops,"   a   program
to   create    a    PostScript   representation   of   Masscomp's
graphics  primitive   string   data.   Output   from   the   data
presentation  library subroutines,  the   graphical   editor ged,
or the commands plot, bar, pie, or hist can be used  as input for
gpstops.  A  README, Makefile, and manual  page   are included as
well as a sample GPS file.

--
Mahmud Haque                  uucp:{uunet,shell,rice}!bcm!soma!mahmud
Division of Neuroscience  Internet: mahmud@soma.neusc.bcm.tmc.edu
Baylor College of Medicine 
Houston, Tx 77030

-----------------------------cut---------------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	Makefile
#	README
#	all.g.uu
#	defs.h
#	do_arc.c
#	do_line.c
#	do_pie.c
#	do_rect.c
#	do_text.c
#	gpstops.1
#	gpstops.c
#	linetype.c
#	prologue.c
#	readgps.c
#	utils.c
#	version.c
# This archive created: Sun Dec  3 21:33:18 1989
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'Makefile'
then
	echo shar: "will not over-write existing file 'Makefile'"
else
cat << \SHAR_EOF > 'Makefile'
PROGS = gpstops
SRC   = gpstops.c utils.c readgps.c prologue.c linetype.c do_text.c \
	do_arc.c do_pie.c do_rect.c do_line.c version.c
OBJ   = gpstops.o utils.o readgps.o prologue.o linetype.o do_text.o \
	do_arc.o do_pie.o do_rect.o do_line.o version.o
HEADR = defs.h

CFLAGS = -O -f68881
MANDIR = /usr/man/manl/man1
INSTALLDIR = /usr/local/bin

.SUFFIXES: .c,v

.c,v.o:
	co -q $*.c
	cc ${CFLAGS} -c $*.c
	rm -f $*.c

all:	${PROGS}

gpstops: $(OBJ)
	cc ${CFLAGS} $(OBJ) -o $@

clean:
	rm -f *.BAK *.CKP *.o *~

install:
	mv gpstops $(INSTALLDIR)
	mv gpstops.1 $(MANDIR)

###
${OBJ} : ${HEADR}
SHAR_EOF
fi
if test -f 'README'
then
	echo shar: "will not over-write existing file 'README'"
else
cat << \SHAR_EOF > 'README'

This package includes the  source  for   "gpstops,"   a   program
to   create    a    PostScript   representation   of   Masscomp's
graphics  primitive   string   data.   Output   from   the   data
presentation  library subroutines,  the   graphical   editor ged,
or the commands plot, bar, pie, or hist can be used  as input for
gpstops.  A  README, Makefile, and manual  page   are included as
well as a sample GPS file.

The filters use the the  procedure  "getopt"  which  is  used  to
interpret  command  line  options  and  arguments and is normally
available on 4.3 bsd and SysV  Unix. If you don't  have "getopt",
you  will  need  to rewrite the code that interprets command line
arguments.

For filled Pie slice and filled rectangles, fill type  and  delta
are not  handled  properly.  This  filter only takes care of fill
types in a kludge fashion, that  is  fill  types  1  thru  10  is
represented  by  various shades of gray. Fill delta is ignored by
this program.

This    version   of   "gpstops"   is     distributed     without
any promise  of  support,  though  I would appreciate bug reports
and changes and will gladly respond  to  any  bug  reports  if  a
suitable example displaying the bug is sent to me.



Mahmud Haque                  uucp:{uunet,shell,rice}!soma!mahmud
Division of Neuroscience  Internet: mahmud@soma.neuro.bcm.tmc.edu
Baylor College of Medicine 
Houston, Tx 77030









































































































































































SHAR_EOF
fi
if test -f 'all.g.uu'
then
	echo shar: "will not over-write existing file 'all.g.uu'"
else
cat << \SHAR_EOF > 'all.g.uu'
begin 644 all.g
M, CJ% -J\8<*F_<" U04 . &#DC[7PK=!A("I> ("4@ "@#(^U\*W082 J7@
M!@X4^XL!&@6D^Z'@!@X4[H@%NO1$ KO@" D4  $  .Z(!;KT1 *[, CTLOLS
MYE#[,_2R^S,4   *^D+P$@%<^#012?,1$E "(10   @(> N,#+\"8Q  !T13
M . )"Q0     !"P &O_F$I(,J> )"A0 !0#(!"P &@%.$I(,J> )"Q0     
M C$ ,__4 !000N )"A0  0   C$ ,P$\ !000B +](SP$A0 4 !(96EG:'0@
M-# P ,T@"P:V[A 4 % @2&5I9VAT(#0P, #UX 8.%."_$0?IZ LUX @)%  !
F ,C@OQ$'Z>@+-> &#A3MEQ&*\Y4,J> ("10  P#([9<1BO.5#*DU
 
end
SHAR_EOF
fi
if test -f 'defs.h'
then
	echo shar: "will not over-write existing file 'defs.h'"
else
cat << \SHAR_EOF > 'defs.h'
#include <stdio.h>
#include <fcntl.h>
#include <ctype.h>
#include <math.h> 
#include <errno.h>

#define PI      3.141592654

#define max(a,b) ( (a > b) ? a : b )
#define min(a,b) ( (a < b) ? a : b )
#define dtor(a)  ( a * PI / 180.0 )

#define LIN 0
#define TXT 2
#define ARC 3
#define HTXT 4
#define MISC 14
#define FBOX 9
#define EBOX 14
#define FPIE 10
#define EPIE 11
#define FILL 1
#define CIRCLE 1

union {
	char	cbuf[2];
	short	sbuf;
} space;

typedef struct {
	short	bundle;
	short	count;
	short	x[2050];
	short	y[2050];
} LINE;

typedef struct {
	short	bundle;
	short	x;
	short	y;
	short	size;
	short	ort;
	short	count;
	char	label[256];
} TEXT;

typedef struct {
	short	x[3];
	short	y[3];
	short	type;
	short	cx;
	short	cy;
	short	sa;
	short	ea;
	short	radius;
	short	bundle;
} ARCS;

typedef struct {
	short	x[2];
	short	y[2];
	short	type;
	short	fill;
	short	delta;
	short	bundle;
} BOX;

typedef struct {
	short	cx;
	short	cy;
	short	sa;
	short	ea;
	short	radius;
	short	delta;
	short	fill;
	short	type;
	short	bundle;
} PIE;

static int	lbun[101][3] = 
	{{0, 0, 0}, {4, 1, 1}, {4, 1, 1}, {4, 1, 1}, {4, 1, 1}, 
	{16, 1, 1}, {1, 1, 1}, {2, 1, 1}, {2, 1, 1}, {3, 1, 1},
	{4, 1, 1}, {4, 1, 1}, {5, 1, 1}, {5, 1, 1}, {6, 1, 1},
	{6, 1, 1}, {7, 1, 1}, {7, 1, 1}, {8, 1, 1}, {8, 1, 1},
	{1, 1, 1}, {2, 1, 1}, {3, 1, 1}, {4, 1, 1}, {5, 1, 1},
	{6, 1, 1}, {7, 1, 1}, {8, 1, 1}, {9, 1, 1}, {10, 1, 1},
	{11, 1, 1}, {12, 1, 1}, {13, 1, 1}, {14, 1, 1}, {15, 1, 1},
	{1, 1, 2}, {2, 1, 2}, {3, 1, 2}, {4, 1, 2}, {5, 1, 2},
	{6, 1, 2}, {7, 1, 2}, {8, 1, 2}, {9, 1, 2}, {10, 1, 2},
	{11, 1, 2}, {12, 1, 2}, {13, 1, 2}, {14, 1, 2}, {15, 1, 2},
	{1, 1, 3}, {2, 1, 3}, {3, 1, 3}, {4, 1, 3}, {5, 1, 3},
	{6, 1, 3}, {7, 1, 3}, {8, 1, 3}, {9, 1, 3}, {10, 1, 3},
	{11, 1, 3}, {12, 1, 3}, {13, 1, 3}, {14, 1, 3}, {15, 1, 3},
	{1, 1, 4}, {2, 1, 4}, {3, 1, 4}, {4, 1, 4}, {5, 1, 4},
	{6, 1, 4}, {7, 1, 4}, {8, 1, 4}, {9, 1, 4}, {10, 1, 4},
	{11, 1, 4}, {12, 1, 4}, {13, 1, 4}, {14, 1, 4}, {15, 1, 4},
	{1, 1, 5}, {2, 1, 5}, {3, 1, 5}, {4, 1, 5}, {5, 1, 5},
	{6, 1, 5}, {7, 1, 5}, {8, 1, 5}, {9, 1, 5}, {10, 1, 5},
	{11, 1, 5}, {12, 1, 5}, {13, 1, 5}, {14, 1, 5}, {15, 1, 5},
	{1, 1, 6}, {2, 1, 6}, {3, 1, 6}, {4, 1, 6}, {5, 1, 6},
	{6, 1, 6}} ;

LINE   lines[256];
TEXT   text[512];
ARCS   arcs[256];
BOX    boxes[256];
PIE    pies[256];

int     xmax, xmin, ymin, ymax;
int     linecount, boxcount, arccount, piecount, textcount;
int	width, height;
int	curfont, curtype;
float	scale;

int	abs();
char    *init(), *version();
float	xnew(), ynew();

extern  int     errno;
extern  double	sin();
extern  double	cos();
extern  double	asin();
extern  double	sqrt();
extern  char	*ctime(), *getlogin();

SHAR_EOF
fi
if test -f 'do_arc.c'
then
	echo shar: "will not over-write existing file 'do_arc.c'"
else
cat << \SHAR_EOF > 'do_arc.c'
/************************************************************************
Copyright (C) 1989 by Mahmud Haque.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.  This software is provided "as is" without express or
implied warranty.
************************************************************************/


#include "defs.h"

do_arc(indx)
int	indx;
{
	float	xc, yc, r, sa, ea;
	int     bundle;

	xc = xnew(arcs[indx].cx);
	yc = ynew(arcs[indx].cy);
	r = arcs[indx].radius * scale;
	sa = (float)arcs[indx].sa;
	ea = (float)arcs[indx].ea;
	bundle = arcs[indx].bundle;
	setlinetype(lbun[bundle][2]);

	if ( arcs[indx].type == CIRCLE )
		printf("newpath\n\t%g %g %g 0 360 arc\nstroke\n", xc, yc, r);
	else
		printf("newpath\n\t%g %g %g %g %g arc\nstroke\n", xc, yc, r, sa, ea );
}





SHAR_EOF
fi
if test -f 'do_line.c'
then
	echo shar: "will not over-write existing file 'do_line.c'"
else
cat << \SHAR_EOF > 'do_line.c'
/************************************************************************
Copyright (C) 1989 by Mahmud Haque.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.  This software is provided "as is" without express or
implied warranty.
************************************************************************/


#include "defs.h"

do_line(indx)
int     indx;
{
	int	i, np, bundle;
	float   xf[4096], yf[4096];

	np = lines[indx].count;
	for (i = 0; i < np; i++) {
		xf[i] = xnew( lines[indx].x[i]);
		yf[i] = ynew( lines[indx].y[i]);
	}
	bundle = lines[indx].bundle;
	setlinetype(lbun[bundle][2]);
	printf("newpath\n\t%g %g M\n", xf[0], yf[0]);
	for ( i = 1; i < np; i++)
		printf("\t%g %g D\n", xf[i], yf[i]);
	printf("stroke\n");
}


SHAR_EOF
fi
if test -f 'do_pie.c'
then
	echo shar: "will not over-write existing file 'do_pie.c'"
else
cat << \SHAR_EOF > 'do_pie.c'
/************************************************************************
Copyright (C) 1989 by Mahmud Haque.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.  This software is provided "as is" without express or
implied warranty.
************************************************************************/


#include "defs.h"

do_pie(indx)
int     indx;
{
	int	radius, stang, endang, bundle;
	float	x1, y1, xc, yc, gray_level;
	int	fillit = 0;

	radius = pies[indx].radius;
	stang = pies[indx].sa;
	endang = pies[indx].ea;
	bundle = pies[indx].bundle;
	setlinetype(lbun[bundle][2]);

	gray_level = ( 11 - pies[indx].fill ) * 0.09;
	if ( pies[indx].delta == 0 )
	  gray_level = 0.0;
	
	x1 = xnew( pies[indx].cx + (int)(radius * (float)cos((double)dtor(stang))));
	y1 = ynew( pies[indx].cy + (int)(radius * (float)sin((double)dtor(stang))));

	xc = xnew( pies[indx].cx);
	yc = ynew( pies[indx].cy);

	if (pies[indx].type == FILL) /* filled pie */
		fillit = 1;
	printf("%g %g %g %g %g %d %d %g %d Pie\n", x1, y1,
	    xc, yc, radius * scale, stang, endang, gray_level, fillit);
}


SHAR_EOF
fi
if test -f 'do_rect.c'
then
	echo shar: "will not over-write existing file 'do_rect.c'"
else
cat << \SHAR_EOF > 'do_rect.c'
/************************************************************************
Copyright (C) 1989 by Mahmud Haque.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.  This software is provided "as is" without express or
implied warranty.
************************************************************************/


#include "defs.h"

do_rect(indx)
int     indx;
{
        int	thistype;
	int	i, bundle;
	float   xf[2], yf[2], gray_level;

	for ( i = 0; i < 2; i++) {
		xf[i] = xnew( boxes[indx].x[i]);
		yf[i] = ynew( boxes[indx].y[i]);
	}
	bundle = boxes[indx].bundle;
	setlinetype(lbun[bundle][2]);

	gray_level = ( 11 - boxes[indx].fill ) * 0.09;
	if ( boxes[indx].delta == 0 )
	  gray_level = 0.0;

	if ( boxes[indx].type == FILL)
		printf("%g %g %g %g %g 1 Box\n",
		    xf[0], yf[0], xf[1], yf[1], gray_level);
	else
		printf("%g %g %g %g 0 0 Box\n", xf[0], yf[0], xf[1], yf[1]);
}


SHAR_EOF
fi
if test -f 'do_text.c'
then
	echo shar: "will not over-write existing file 'do_text.c'"
else
cat << \SHAR_EOF > 'do_text.c'
/************************************************************************
Copyright (C) 1989 by Mahmud Haque.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.  This software is provided "as is" without express or
implied warranty.
************************************************************************/


#include "defs.h"

float	cwidth = 1.0;        /* 100% of char height */
float	cheight = 1.5;        /* 150% of default char height */


do_text(indx)
int indx;
{
	int	char_size;
	float	char_slant, char_width, char_height;
	float   x, y;

	char_slant = 0.0;

	x = xnew( text[indx].x);
	y = ynew( text[indx].y);
	char_size = text[indx].size;
	char_height = cheight * char_size * scale;
	char_width  =  char_height * cwidth;
	do_font(char_size, char_width, char_height, char_slant);
	printf("%g %g %g (%s) Text\n", x, y, (float)text[indx].ort, text[indx].label);
}

do_font(csize, cw, ch, cs)
int csize;
float cw, ch, cs;
{
        if ( curfont == csize ) 
	     return;
	printf("basefont %g %g %g Font\n", cw, ch, cs);
	curfont = csize;
}
	


SHAR_EOF
fi
if test -f 'gpstops.1'
then
	echo shar: "will not over-write existing file 'gpstops.1'"
else
cat << \SHAR_EOF > 'gpstops.1'
.ds CF
.deTH
.PD
.nrIN \\n()Mu
.ift .ds ]H \\$1\^(\^\\$2\^)
.ifn .ds ]H \\$1(\\$2)
.if\\n()s .ds ]D
.if\\n()t .ds ]D  Local Version 1.0
.ifn .ds ]D Local Version 1.0
.ds]L
.if!\\$3 .ds ]L (\^\\$3\^)
.if!\\$4 .ds ]D \\$4
.wh0 }H
.wh-\\n(:mu }F
.em}M
.if\\n(nl .bp
.nr)I \\n()Mu
.nr)R 0
.}E
.DT
.ifn \{.na
.nh\}
.ift \{.bd S 3 3
.hy14 \}
..
.bd S B 3
.ds ]D "SP-45 4.1"
.TH GPSTOPS 1L
.SH NAME
gpstops \- filter to change Masscomp's graphic primitive string data to Postscript.
.SH SYNOPSIS
.B gpstops
[ options ]  \fIfile.g\fR
.SH DESCRIPTION
.I gpstops
codes masscomp's graphic primitive string 
.I ( gps )
data for Postscript Laser Printer.
Output from the data presentation libray subroutines, the graphical editor 
.I ged, 
or the commands 
.I plot, bar, pie, 
or
.I hist
can be used as input for gpstops.
The following options are recognized:
.PP
options:
.PP
.PD 0
.TP 9
.BI \-x " x_offset"
Specifies the horizontal distance between the left side of the plot and 
the left side of the page ( in mm ). Default is 0 mm.
.TP
.BI \-y " y_offset"
Specifies the vertical distance between the top of the plot and 
the top of the page ( in mm ). Default is 0 mm.
.TP
.BI \-s " size"
Specifies the dimension of the plot ( in mm ), will create a 
.I size X size 
plot.  Default is 100mm X 100mm.

.SH EXAMPLES
gpstops -x 15 -y 35.5 -s 120 file.g > file.ps
.br
or
.br
gpstops -x 15 -y 35.5 -s 120 file.g | lpr 

.SH AUTHOR
Copyright (C) 1989 by Mahmud Haque ( mahmud@cortex.neuro.bcm.tmc.edu ).

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.  This software is provided "as is" without express or
implied warranty.
SHAR_EOF
fi
if test -f 'gpstops.c'
then
	echo shar: "will not over-write existing file 'gpstops.c'"
else
cat << \SHAR_EOF > 'gpstops.c'
/************************************************************************
Copyright (C) 1989 by Mahmud Haque.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.  This software is provided "as is" without express or
implied warranty.

This program translates Masscomp's gps metafile format data to Postscript.
The output is written to stdout.

Usage:
	gpstops -x xoff_set -y yoff_set -s size input_file

	options:
	
	-x x_offset	horizontal distance between the left side of the
			page and the left side of the plot.
	-y y_offset	vertical distance between top of the page and the 
			top of the plot.
	-s size		plot's dimension, will create sizeXsize plot.
	input_file	gps file.
**************************************************************************/

#include "defs.h"

main(argc, argv)
int	argc;
char	**argv;
{
	int	i, code, subcode, bundle, nc, dummy;
	int	fill_type, delta;
	char	*filename;
	FILE    * fp, *fpmm ;

	filename = init(argc, argv);

	convertgps(filename);

	width = abs(xmax - xmin);
	height = abs(ymax - ymin);

	curfont = 0;
	curtype = 0;

	/* compute sacling factor */
	compute_scale();

	/* write out postscript header */
	prologue(filename);

	for(i = 0 ; i < textcount; i++)
		do_text(i);

	for(i = 0 ; i < arccount; i++)
		do_arc(i);

	for(i = 0 ; i < piecount; i++)
		do_pie(i);

	for(i = 0 ; i < boxcount; i++)
		do_rect(i);

	for(i = 0 ; i < linecount; i++)
		do_line(i);

	printf("\nshowpage\n%%%%Trailer\n");
}
SHAR_EOF
fi
if test -f 'linetype.c'
then
	echo shar: "will not over-write existing file 'linetype.c'"
else
cat << \SHAR_EOF > 'linetype.c'
/************************************************************************
Copyright (C) 1989 by Mahmud Haque.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.  This software is provided "as is" without express or
implied warranty.
************************************************************************/

#include "defs.h"

setlinetype(thistype)
int	thistype;
{
        if ( curtype == thistype )
	     return;
	switch (thistype) {
	case 1:
	case 9:
	case 16:
		printf("[] 0 setdash\n");
		break;
	case 2:
		printf("[16] 0 setdash\n");
		break;
	case 3:
		printf("[4] 0 setdash\n");
		break;
	case 4:
		printf("[8] 0 setdash\n");
		break;
	case 5:
		printf("[20] 0 setdash\n");
		break;
	case 6:
		printf("[12 4 4 4 4 4] 0 setdash\n");
		break;
	case 7:
		printf("[1] 0 setdash\n");
		break;
	case 8:
		printf("[24 8] 0 setdash\n");
		break;
	case 10:
		printf("[4 28] 0 setdash\n");
		break;
	case 11:
		printf("[8 24] 0 setdash\n");
		break;
	case 12:
		printf("[12 20] 0 setdash\n");
		break;
	case 13:
		printf("[4 12] 0 setdash\n");
		break;
	case 14:
		printf("[20 4 4 4] 0 setdash\n");
		break;
	case 15:
		printf("[12 4] 0 setdash\n");
		break;
	}
	curtype = thistype;
}


SHAR_EOF
fi
if test -f 'prologue.c'
then
	echo shar: "will not over-write existing file 'prologue.c'"
else
cat << \SHAR_EOF > 'prologue.c'
/************************************************************************
Copyright (C) 1989 by Mahmud Haque.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.  This software is provided "as is" without express or
implied warranty.
************************************************************************/


#include "defs.h"

float	xoff_set;
float	yoff_set;
float	size;
prologue(filename)
char * filename;
{
	long	now;

	now = time(0);

	/* generate postscript definition */
	printf("%%!PS-Adobe-2.0 EPSF-1.2\n");
	printf("%%%%Title: %s\n", filename);
	printf("%%%%Creator: gpstops %s\n", version());
	printf("%%%%CreationDate: %s", ctime(&now));
	printf("%%%%For: %s\n", getlogin());
	printf("%%%%Page: 1 of 1\n");
	printf("%%%%BoundingBox: 0 0 %d %d\n", 
	    (int)(width * scale + 0.5), (int)(height * scale + 0.5));
	printf("%%%%EndComments\n");

	printf("%% default font is Times-Roman 10pt\n");
	printf("/basefont {/Times-Roman} def\n");
	/* Move macro */
	printf("/M { /Y exch def /X exch def X Y moveto } def\n");
	/* Relative move macro */
	printf("/RM { /Yd exch def /Xd exch def Xd Yd rmoveto } def\n");
	/* Draw macro */
	printf("/D { /Y exch def /X exch def X Y lineto } def\n");
	/* Relative draw  macro */
	printf("/RD { /Yd exch def /Xd exch def Xd Yd rlineto } def\n");
	/*
         *		Procedure to change font, width, slant and height
         *		font width height slant Font 
         *
         *	        slant = height * tan( slant_angle )
         */
	printf("/Font {\n");
	printf("    /Slant exch def /Height exch def /Width exch def /FontName exch def\n");
	printf("    FontName findfont [ Width 0 Slant Height 0 0] makefont setfont\n");
	printf("} def\n");
	/*
         *		General Text Layout Procedure
         *		x y angle (text) Text   
         */
	printf("/Text {\n");
	printf("    /String exch def /Angle exch def /Y exch def /X exch def\n");
	printf("    /StrH Height 2.0 div 0.75 mul def /StrW Width 2.0 div 0.75 mul def\n");
	printf("    /Xdiff StrW Angle cos mul StrH Angle sin mul sub def\n");
	printf("    /Ydiff StrW Angle sin mul StrH Angle cos mul add def\n");
	printf("    X Xdiff sub Y Ydiff sub moveto\n");
	printf("    gsave Angle rotate String show grestore\n");
	printf("} def\n");
	/*
	 *      Filled and unfilled rectangle procedure.
	 *      xl yl xr yr graylevel action
	 *      action == 1 --> filled box
	 *      action != 1 --> unfilled box
	 */
	printf("/Box {\n");
	printf("    gsave newpath\n");
	printf("    /Dofill exch def /Gray exch def /UY exch def");
	printf(" /UX exch def /LY exch def /LX exch def\n");
	printf("    LX LY moveto UX LY lineto UX UY lineto LX UY lineto\n");
	printf("    closepath Gray setgray Dofill 1 ne {stroke} {fill} ifelse grestore\n");
	printf("} def\n");
	/*
	 *      Fill and edge pie procedure.
	 *      xs ys xc yc radius start_angle end_angle graylevel action
	 *      action == 1 --> filled pie
	 *      action != 1 --> unfilled pie
	*/
	printf("/Pie {\n");
	printf("    gsave newpath\n");
	printf("    /Dofill exch def /Gray exch def /endA exch def /startA exch def\n");
	printf("    /radiuS exch def /cY exch def /cX exch def /sY exch def /sX exch def\n");
	printf("    cX cY moveto sX sY lineto cX cY radiuS startA endA arc\n");
	printf("    closepath Gray setgray Dofill 1 ne {stroke} {fill} ifelse grestore\n");
	printf("} def\n");
	printf("%%%%EndProlog\n\n");

	printf("basefont 10 10 0 Font\n");              /* Set the default font */
	printf("1 setlinecap\n");	                /* Use round caps */
	printf("1 setlinejoin\n");	                /* Use round joins */
	printf("3 setmiterlimit\n");	                /* Bevel small angle miters */
	printf("%g setlinewidth\n", (float)lbun[1][2]/2.0); /* setup line thickness */
	/* minimum offset is 0.2 inch that is 14.45 pts */
	printf("%g %g translate\n", (15 + xoff_set), (15 + yoff_set));
}
SHAR_EOF
fi
if test -f 'readgps.c'
then
	echo shar: "will not over-write existing file 'readgps.c'"
else
cat << \SHAR_EOF > 'readgps.c'
/************************************************************************
Copyright (C) 1989 by Mahmud Haque.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.  This software is provided "as is" without express or
implied warranty.
************************************************************************/


#include "defs.h"

extern int	errno;

convertgps(filename)
char * filename;
{
	int	fp;
	short	rcount, code, subcode, bundle;
	short	i, n, radius, ort, diffx, diffy, textwid;


	linecount = boxcount = arccount = piecount = textcount = 0;

	xmax = -32768;
	xmin =  32767;
	ymax = -32768;
	ymin =  32767;


	if ((fp = open(filename, O_RDONLY)) < 0) {
		perror(filename);
		exit(1);
	}

	while ((n = read(fp, space.cbuf, 2)) > 0) {
		code = (space.sbuf >> 12) & 0x000f;
		rcount = ( space.sbuf & 0x0fff );
#ifdef DEBUG
		fprintf(stderr, "CODE ---> %d\n", code);
#endif
		switch (code) {
		case LIN: /*	line	*/
			lines[linecount].count = rcount / 2 - 1;
			for (i = 0; i < lines[linecount].count; i++) {
				read(fp, space.cbuf, 2);
				lines[linecount].x[i] = space.sbuf;
				read(fp, space.cbuf, 2);
				lines[linecount].y[i] = space.sbuf;
				mmxy(lines[linecount].x[i], lines[linecount].y[i]);
			}
			read(fp, space.cbuf, 2);
			lines[linecount].bundle = ((short)space.cbuf[0] & 0x00ff);
			linecount++;
			break;
		case TXT: /*	text	*/
			read(fp, space.cbuf, 2);
			text[textcount].x = space.sbuf;
			read(fp, space.cbuf, 2);
			text[textcount].y = space.sbuf;
			read(fp, space.cbuf, 2);
			text[textcount].bundle = ((short)space.cbuf[0] & 0x00ff);
			read(fp, space.cbuf, 2);
			text[textcount].size = 5 * ((short)space.cbuf[0] & 0x00ff);
			ort = ((short)(space.cbuf[1]) < 0) ? 
			    (short)(space.cbuf[1]) + 256 : (short)(space.cbuf[1]);
			ort = (short)((float)ort * 360.0 / 256.0 + 0.5);
			text[textcount].ort = ort;
			read(fp, text[textcount].label, (rcount - 6) * 2);
			read(fp, space.cbuf, 2);
			text[textcount].count = ( rcount - 6) * 2 ;
			if (!isprint(space.cbuf[0]))
				text[textcount].label[(rcount-6)*2] = 0;
			else if (!isprint(space.cbuf[1])) {
				text[textcount].label[(rcount-6)*2] = space.cbuf[0];
				text[textcount].label[(rcount-6)*2 +1] = 0;
				text[textcount].count++;
			} else
			 {
				text[textcount].label[(rcount-6)*2] = space.cbuf[0];
				text[textcount].label[(rcount-6)*2 +1] = space.cbuf[1];
				text[textcount].label[(rcount-6)*2 +2] = 0;
				text[textcount].count += 2;
			}
			textwid = text[textcount].size / 2;
/*
			mmxy(text[textcount].x - (short)(textwid * 
			    (float)cos((double)text[textcount].ort * PI / 180.0)),
			    text[textcount].y - (short)(textwid * 
			    (float)sin((double)text[textcount].ort * PI / 180.0)));
			textwid = (text[textcount].count + 0) * text[textcount].size;
			mmxy(text[textcount].x + (short)(textwid * 
			    (float)cos((double)text[textcount].ort * PI / 180.0)),
			    text[textcount].y + (short)(textwid * 
			    (float)sin((double)text[textcount].ort * PI / 180.0)));
*/
			diffx = (short)(textwid * 
			    ((float)cos((double)dtor(text[textcount].ort))-
			    (float)sin((double)dtor(text[textcount].ort))));
			diffy = (short)(textwid * 
			    ((float)cos((double)dtor(text[textcount].ort))+
			    (float)sin((double)dtor(text[textcount].ort))));

			mmxy(text[textcount].x - diffx, text[textcount].y - diffy);
			textwid = (text[textcount].count - 1) * text[textcount].size;
			mmxy(text[textcount].x + (short)(textwid * 
			    (float)cos((double)dtor(text[textcount].ort))) + diffx,
			    text[textcount].y + (short)(textwid * 
			    (float)sin((double)dtor(text[textcount].ort))) + diffy);

			textcount++;
			break;
		case ARC:	/*	arcs	*/
			for (i = 0; i < 3; i++) {
				read(fp, space.cbuf, 2);
				arcs[arccount].x[i] = space.sbuf;
				read(fp, space.cbuf, 2);
				arcs[arccount].y[i] = space.sbuf;
			}
			if (( arcs[arccount].x[0] == arcs[arccount].x[2]) && 
			    ( arcs[arccount].y[0] == arcs[arccount].y[2])) {
				arcs[arccount].type = CIRCLE;
				diffx =   arcs[arccount].x[0] - arcs[arccount].x[1];
				diffy = arcs[arccount].y[0] - arcs[arccount].y[1];
				arcs[arccount].radius = (short) ( sqrt((float)( 
				    diffx * diffx + diffy * diffy))) / 2;
				arcs[arccount].cx = arcs[arccount].x[0] - 
				    ( arcs[arccount].x[0] - arcs[arccount].x[1]) / 2;
				arcs[arccount].cy = arcs[arccount].y[0] - 
				    ( arcs[arccount].y[0] - arcs[arccount].y[1]) / 2;
			} else
			 {
				arcs[arccount].type = 0;
				if ( tailor_arc(arcs[arccount].x, arcs[arccount].y, 
				    &arcs[arccount].cx, &arcs[arccount].cy, 
				    &arcs[arccount].radius, &arcs[arccount].sa, 
				    &arcs[arccount].ea ) == LIN) {
					lines[linecount].count = 3;
					for (i = 0; i < lines[linecount].count; i++) {
						lines[linecount].x[i] = arcs[arccount].x[i];
						lines[linecount].y[i] = arcs[arccount].y[i];
						mmxy(lines[linecount].x[i], lines[linecount].y[i]);
					}
					linecount++;
					read(fp, space.cbuf, 2);
					lines[linecount].bundle = (space.sbuf >> 8) & 0x00ff;
					break;
				}
			}
			mmxy(arcs[arccount].cx + arcs[arccount].radius, 
			    arcs[arccount].cy + arcs[arccount].radius);
			mmxy(arcs[arccount].cx - arcs[arccount].radius, 
			    arcs[arccount].cy - arcs[arccount].radius);
			read(fp, space.cbuf, 2);
			arcs[arccount].bundle = (space.sbuf >> 8) & 0x00ff ;
			arccount++;
			break;
		case HTXT: /*	harware text	*/
			for (i = 0; i < rcount - 1; i++)
				read(fp, space.cbuf, 2);
			break;
		case MISC: /*	pie/rect./ch_line_bun/ch_text_bun */
			read(fp, space.cbuf, 2);
			subcode = space.cbuf[0];
			bundle = space.cbuf[1];
#ifdef DEBUG
			fprintf(stderr, "SUBCODE ---> %d\n", subcode);
#endif
			switch (subcode) {
			case FBOX: /*	fill rectangle	*/
				boxes[boxcount].type = FILL;
				read(fp, space.cbuf, 2);
				boxes[boxcount].fill = space.sbuf;
				read(fp, space.cbuf, 2);
				boxes[boxcount].delta = space.sbuf;
			case EBOX: /* edge rectangle */
				if ( subcode != FBOX )
					boxes[boxcount].type = 0;
				for (i = 0; i < 2; i++) {
					read(fp, space.cbuf, 2);
					boxes[boxcount].x[i] = space.sbuf;
					read(fp, space.cbuf, 2);
					boxes[boxcount].y[i] = space.sbuf;
					mmxy(boxes[boxcount].x[i], boxes[boxcount].y[i]);
				}
				boxes[boxcount].bundle = bundle;
				boxcount++;
				break;
			case FPIE: /*	fill/edge pie	*/
			case EPIE:
				if (subcode == FPIE)
					pies[piecount].type = FILL;
				else
					pies[piecount].type = 0;
				read(fp, space.cbuf, 2);
				pies[piecount].fill = space.sbuf;
				read(fp, space.cbuf, 2);
				pies[piecount].delta = space.sbuf;
				read(fp, space.cbuf, 2);
				pies[piecount].radius = space.sbuf;
				read(fp, space.cbuf, 2);
				pies[piecount].sa = space.sbuf;
				read(fp, space.cbuf, 2);
				pies[piecount].ea = space.sbuf;
				read(fp, space.cbuf, 2);
				pies[piecount].cx = space.sbuf;
				read(fp, space.cbuf, 2);
				pies[piecount].cy = space.sbuf;
				mmxy(pies[piecount].cx + pies[piecount].radius, 
				    pies[piecount].cy + pies[piecount].radius);
				mmxy(pies[piecount].cx - pies[piecount].radius, 
				    pies[piecount].cy - pies[piecount].radius);
				pies[piecount].bundle = bundle;
				piecount++;
				break;
			case 12: /* 	change line bundle */
				for (i = 0; i < 4; i++) {
					read(fp, space.cbuf, 2);
				}
				break;
			case 13: /* 	change text bundle */
				for (i = 0; i < 4; i++) {
					read(fp, space.cbuf, 2);
				}
				break;
			default:
				fprintf(stderr, "Bad code %3d - %3d\n", code, subcode);
				fprintf(stderr, "conversion is not done\n");
				exit(1);
			}
			break;
		case 15: /*	comments	*/
			for (i = 0; i < rcount - 1; i++)
				read(fp, space.cbuf, 2);
			break;
		default:
			fprintf(stderr, "Bad code %3d\n", code);
			fprintf(stderr, "conversion is not done\n");
			exit(1);
		}

	}
#ifdef DEBUG
	fprintf(stderr,"(%d %d) (%d %d) w = %d h = %d\n",xmin,ymin,xmax,ymax,(xmax - xmin), (ymax- ymin));
#endif
}


mmxy(x, y)
short	x, y;
{
	xmax = max( x, xmax );
	xmin = min( x, xmin );
	ymax = max( y, ymax );
	ymin = min( y, ymin );
}


int
tailor_arc(x, y, xcntr, ycntr, radius, sa, ea)
short	x[], y[];
short	*xcntr, *ycntr, *radius, *sa, *ea;
{
	float	xc, yc, xf[3], yf[3], a[3], b[3], c[3];
	float	r, a12, a13, b12, b13, c12, c13, d1, d2, d;
	int	i, theta;
	float	ang1, ang2, ang3;
	float	tang1, tang2, tang3;

	for (i = 0; i < 3; i++) {
		xf[i] = (float)x[i];
		yf[i] = (float)y[i];
		a[i] = -2.0 * xf[i];
		b[i] = -2.0 * yf[i];
		c[i] = xf[i] * xf[i] + yf[i] * yf[i];
	}
	a12 = a[0] - a[1];
	a13 = a[0] - a[2];
	b12 = b[0] - b[1];
	b13 = b[0] - b[2];
	c12 = c[0] - c[1];
	c13 = c[0] - c[2];

	d = a12 * b13 - a13 * b12;
	d1 =  -1.0 * c12 * b13 - (-1.0 * c13 * b12);
	d2 =  -1.0 * c13 * a12 - (-1.0 * c12 * a13);
	if ( d == 0.0 ) {
		fprintf(stderr, "Cannot do arc will draw line\n");
		return(LIN);
	}
	xc = d1 / d;
	yc = d2 / d;
	r  = (float)sqrt((double)(xc * xc + a[0] * xc + xf[0] * xf[0] + 
	    yc * yc + b[0] * yc + yf[0] * yf[0]));

	check_quad(xf[0], yf[0], xc, yc, r, &tang1);
	check_quad(xf[1], yf[1], xc, yc, r, &tang2);
	check_quad(xf[2], yf[2], xc, yc, r, &tang3);
	if ( tang2 < tang1) {
		ang1 = tang3;
		ang3 = tang1;
	} else
	 {
		ang1 = tang1;
		ang3 = tang3;
	}

	*xcntr = (short)xc;
	*ycntr = (short)yc;
	*radius = (short)r;
	*sa = (short)ang1;
	*ea = (short)ang3;
	return(ARC);
}


int
check_quad(x, y, xc, yc, r, angle)
float	x, y, xc, yc, r, *angle;
{
	int	qd;

	if ( x == xc )
		x += 0.05;
	if ( x > xc ) {
		if ( y > yc )
			qd = 1;
		else if ( y < yc )
			qd = 4;
		else	 {
			y += 0.05;
			qd = 1;
		}
	} else if ( x < xc ) {
		if ( y > yc )
			qd = 2;
		else if ( y < yc )
			qd = 3;
		else	 {
			y += 0.05;
			qd = 2;
		}
	}
	switch (qd) {
	case 1:
		*angle = (qd - 1) * 90.0 + (float)asin((double)(y - yc) / r) * 180.0 / PI;
		break;
	case 2:
		*angle = (qd - 1) * 90.0 + (float)asin((double)(xc - x) / r) * 180.0 / PI;
		break;
	case 3:
		*angle = (qd - 1) * 90.0 + (float)asin((double)(yc - y) / r) * 180.0 / PI;
		break;
	case 4:
		*angle = (qd - 1) * 90.0 + (float)asin((double)(x - xc) / r) * 180.0 / PI;
		break;
	}
}



SHAR_EOF
fi
if test -f 'utils.c'
then
	echo shar: "will not over-write existing file 'utils.c'"
else
cat << \SHAR_EOF > 'utils.c'
/************************************************************************
Copyright (C) 1989 by Mahmud Haque.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.  This software is provided "as is" without express or
implied warranty.
************************************************************************/


#include "defs.h"

char	*Usage = 
"Usage: gpstops [-x xoff_set(mm)] [-y yoff_set(mm)] [-s size(mm)] gps_file\n" ;

/*
 *	init - process arguments and initialize options
 */
char	*
init(argc, argv)
int	argc;		/* Arg count from main() */
char	**argv;		/* Arg vector from main() */
{
	extern int	optind;		/* From getopt() */
	extern char	*optarg;	/* From getopt() */
	extern float	xoff_set, yoff_set, size;

	int	i;
	int	argchar;	/* Temp */
	char	*optstring = "x:y:s:?";	/* Option list */

	xoff_set = 0.0;
	yoff_set = 0.0;
	size = 285.0;   /* 100 mm */

	while ((argchar = getopt(argc, argv, optstring)) != EOF) {
		switch (argchar) {
		case 'x':
			xoff_set = 0.03937008 * (float)atof(optarg) * 72.24;
			break;
		case 'y':
			yoff_set = 0.03937008 * (float)atof(optarg) * 72.24;
			break;
		case 's':
			size = 0.03937008 * (float)atof(optarg) * 72.24;
			break;
		case '?':
			printf(Usage);
			exit(1);
		}

	}

	if (access(argv[optind], 4)) {	/* let us open the input file */
		fprintf( stderr, "gpstops: can't access %s\n", argv[optind]);
		exit (1);
	}
	return(argv[optind]);
}


compute_scale()
{
	float	ratio;

	ratio = (float)(width) / (float)(height);       /* x / y */

	if ( ratio > 1.0 )   /* we need to scale width */
		scale = size / (float)(width);
	else
		scale = size / (float)(height);
}


float	xnew( x )
short	x;
{
	return( ( x - xmin ) * scale);
}


float	ynew( y )
short	y;
{
	return( (y - ymin) * scale );
}


int	abs( val )
int	val;
{
	val = (val > 0) ? val : (-1 * val);
	return(val);
}


SHAR_EOF
fi
if test -f 'version.c'
then
	echo shar: "will not over-write existing file 'version.c'"
else
cat << \SHAR_EOF > 'version.c'
/************************************************************************
Copyright (C) 1989 by Mahmud Haque.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.  This software is provided "as is" without express or
implied warranty.
************************************************************************/


char *version () {
  static char thisvers[] =  "1.0 (Tue Nov 21 16:16:44 CST 1989 by mahmud@cortex)";
  return thisvers;
}
SHAR_EOF
fi
exit 0
#	End of shell archive

Articles to: concurrent@soma.bcm.tmc.edu or uunet!soma.bcm.tmc.edu!concurrent
Administrative stuff: concurrent-request@soma.bcm.tmc.edu
Stan Barber, Moderator