home *** CD-ROM | disk | FTP | other *** search
- /* This file contains drivers for the HP7475A plotter */
-
- #include "plplot.h"
- #include <stdio.h>
- #include <string.h>
-
- #define AEGX 10000
- #define AEGY 10000
-
- static FILE *OutDev;
- static PLINT select=0;
- static char FileName[80];
- static short *buffptr, bufflen;
- #define BSIZE 25
-
- void aegissetup(xdpi, ydpi, xwid, ywid)
- PLINT xwid, ywid;
- PLFLT xdpi, ydpi;
- {
- }
-
- void aegisselect(ori, name)
- PLINT ori;
- char *name;
- {
- strncpy(FileName,name,sizeof(FileName)-1);
- FileName[sizeof(FileName)-1] = '\0';
- select = 1;
- }
-
- /* Set up device specific stuff and initialize the device */
- void aegisinit()
- {
- /* setpxl() sets the dots/mm in the x and y directions */
- setpxl((PLFLT)39.37, (PLFLT)39.37);
-
- /* setphy() sets the device coordinates. These are integer */
- /* values. Set up for landscape orientation (long axis of page in the */
- /* x direction). Origin is in the lower left hand corner. */
- setphy(0,AEGX,0,AEGY);
-
- /* Set default pen color using scol(color). */
- /* Any default pen color can be used but a black pen is probably best. */
- scol(1);
-
- /* Set default pen width using swid(width) */
- swid(1);
-
- /* Set device interaction mode using smod(mode). Set mode to 0 for */
- /* a noninteractive device, Unless you are writing your */
- /* own Amiga screen driver mode should be 0. */
- smod(0);
-
- bufflen = 2*BSIZE;
- buffptr = (short *)malloc(sizeof(short)*bufflen);
- if(buffptr == NULL)
- plexit("Out of memory!");
-
- }
-
- /* Sets to text mode */
- void aegistext()
- {
- }
-
- /* Sets to graphics mode */
- void aegisgraph()
- {
- }
-
- static PLINT firstline;
- /* Clears the page */
- void aegisclear()
- {
- void flushbuffer();
-
- /* Close the file */
- if(!firstline) {
- flushbuffer();
- }
- fclose(OutDev);
- }
-
- static short xlast, ylast;
-
- void aegispage()
- {
- char line[80];
- for(;;) {
- if(!select) {
- printf("Enter graphics file name. ");
- fgets(line,sizeof(line),stdin);
- if(sscanf(line,"%s",FileName)!=1)
- continue;
- }
-
- if (!(OutDev = fopen(FileName,"w"))) {
- fprintf(stderr,"Can't open %s.\n",FileName);
- select = 0;
- }
- else
- break;
- }
- select = 0;
- firstline = 1;
- xlast = -10000; ylast = -10000;
-
- /* Write out header */
- fprintf(OutDev,"81086 0.0 0.0 100.0 100.0 0 10.\n");
- fprintf(OutDev,"\"%s\"\n-1\n",FileName);
- }
-
- static int curwid;
- void aegiswidth(width)
- PLINT width;
- {
- void flushbuffer();
-
- flushbuffer();
- firstline = 1;
-
- if(width <= 1)
- curwid = 0;
- else if(width >= 4)
- curwid = 3;
- else
- curwid = width-1;
- }
-
- static int curcol;
- /* Change the pen color */
- void aegiscolor(color)
- PLINT color;
- {
- void flushbuffer();
-
- flushbuffer();
- firstline = 1;
- /* Aegis pen 1 is the "paper" color */
- if (color >= 2 && color <=15)
- curcol = color;
- else
- curcol = 0;
- }
-
- static short count, xmin, xmax, ymin, ymax;
-
- /* Draws a line from (x1,y1) to (x2,y2) */
- void aegisline(x1,y1,x2,y2)
- PLINT x1,y1,x2,y2;
- {
- short *tempptr;
- void flushbuffer();
-
- /* If starting point of this line is the same as the ending point of */
- /* the previous line then don't raise the pen. (This really speeds up */
- /* plotting and reduces the size of the file. */
- if(firstline) {
- count = 0;
- *(buffptr+count++) = x1;
- *(buffptr+count++) = y1;
- *(buffptr+count++) = x2;
- *(buffptr+count++) = y2;
- xmin = min(x1,x2); ymin = min(y1,y2);
- xmax = max(x1,x2); ymax = max(y1,y2);
- firstline = 0;
- }
- else if(x1 == xlast && y1 == ylast) {
- if(count+2 >= bufflen) {
- bufflen += 2*BSIZE;
- tempptr = (short *)realloc((void *)buffptr,bufflen*sizeof(short));
- if(tempptr == NULL){
- free((void *)buffptr);
- plexit("Out of memory!");
- }
- buffptr = tempptr;
- }
- *(buffptr+count++) = x2;
- *(buffptr+count++) = y2;
- xmin = min(x2,xmin); ymin = min(y2,ymin);
- xmax = max(x2,xmax); ymax = max(y2,ymax);
- }
- else {
- flushbuffer();
- *(buffptr+count++) = x1;
- *(buffptr+count++) = y1;
- *(buffptr+count++) = x2;
- *(buffptr+count++) = y2;
- xmin = min(x1,x2); ymin = min(y1,y2);
- xmax = max(x1,x2); ymax = max(y1,y2);
- }
-
- xlast = x2;
- ylast = y2;
- }
-
- static void flushbuffer()
- {
- short i=0;
-
- fprintf(OutDev,"1 52 %.2f %.2f",xmin/100.,ymin/100.);
- fprintf(OutDev," %.2f %.2f",xmax/100.,ymax/100.);
- fprintf(OutDev," %d 0 0 %d 0\n",curcol,curwid);
- while(i<count) {
- fprintf(OutDev," 1 %.2f %.2f\n",*(buffptr+i)/100.,*(buffptr+i+1)/100.);
- i += 2;
- }
- fprintf(OutDev," 0\n");
- count = 0;
- }
-
- /* Cleanup and close file. */
- void aegistidy()
- {
- flushbuffer();
- free((VOID *)buffptr);
- fclose(OutDev);
- }
-
-
-
-