This is aegis.c in view mode; [Download] [Up]
/* 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=NULL; static int fileopen=0; static short *buffptr, bufflen; #define BSIZE 25 void aegissetup(xdpi, ydpi, xwid, ywid) int xwid, ywid; double xdpi, ydpi; { } void aegisorient(orient) int orient; { } void aegisselect(fptr) FILE *fptr; { OutDev = fptr; } /* Set up device specific stuff and initialize the device */ void aegisinit() { char line[80]; /* setpxl() sets the dots/mm in the x and y directions */ setpxl(39.37, 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); while(!OutDev) { printf("Enter graphics file name. "); fgets(line,sizeof(line),stdin); line[strlen(line)-1] = '\0'; if (!(OutDev = fopen(line,"w"))) { fprintf(stderr,"Can't open %s.\n",line); } else { fileopen = 1; break; } } /* Write out header */ fprintf(OutDev,"81086 0.0 0.0 100.0 100.0 0 10.\n"); fprintf(OutDev,"\"%s\"\n-1\n","PLPLOT Graph"); 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 int firstline; /* Clears the page */ void aegisclear() { void flushbuffer(); /* Close the file */ if(!firstline) { flushbuffer(); } } static short xlast, ylast; void aegispage() { firstline = 1; xlast = -10000; ylast = -10000; } void aegiseop() { } static int curwid; void aegiswidth(width) int 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) int 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) int 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); if(fileopen) fclose(OutDev); } void aegiscwin() { } void aegisgwin() { }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.