gunnaro@hafro.is (Gunnar Orvarsson) (11/21/89)
Files: plotfilter.c splot.c Makefile.HP Description: splot is a plot(5) filter which calls routines from the Starbase Graphical Library on HP. #---------------------------------- cut here ---------------------------------- # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by Gunnar Orvarsson <gunnaro@gst> on Tue Nov 21 08:56:09 1989 # # This archive contains: # Splot # LANG=""; export LANG echo mkdir - Splot mkdir Splot echo x - Splot/plotfilter.c cat >Splot/plotfilter.c <<'@EOF' #include <stdio.h> static char buf[256]; int argc_copy; char **argv_copy; main(argc, argv) int argc; char **argv; { int x1,y1,x2,y2,x3,y3; int r; char c; argc_copy = argc; argv_copy = argv; openpl(); while ((c = getc(stdin)) != EOF) { switch (c) { case 'm': /* move */ x1 = getint(); y1 = getint(); move(x1,y1); break; case 'n': /* cont */ x1 = getint(); y1 = getint(); cont(x1,y1); break; case 'p': /* point */ x1 = getint(); y1 = getint(); point(x1,y1); break; case 'l': /* line */ x1 = getint(); y1 = getint(); x2 = getint(); y2 = getint(); line(x1,y1,x2,y2); break; case 'b': x1 = getint(); y1 = getint(); x2 = getint(); y2 = getint(); box(x1,y1,x2,y2); break; case 't': /* text */ string(buf); label(buf); break; case 'e': /* erase */ erase(); break; case 's': /* space */ x1 = getint(); y1 = getint(); x2 = getint(); y2 = getint(); space(x1,y1,x2,y2); break; case 'w': /* window */ x1 = getint(); y1 = getint(); x2 = getint(); y2 = getint(); window(x1,y1,x2,y2); break; case 'a': /* arc */ x1 = getint(); y1 = getint(); x2 = getint(); y2 = getint(); x3 = getint(); y3 = getint(); arc(x1,y1,x2,y3,x3,y3); break; case 'c': /* circle */ x1 = getint(); y1 = getint(); r = getint(); circle(x1,y1,r); break; case 'f': /* linemod */ string(buf); linemod(buf); break; case 'r': /* homemade labelrotation*/ string(buf); labelrotation(buf); break; case 'u': /* homemade labelplace*/ string(buf); labelplace(buf); break; case 'z': /* homemade colorfunction*/ x1=getint(); selectcolor(x1); break; case 'v': /* linewid */ x1=getint(); linewid(x1); break; default: fprintf(stderr, "%s: unknown command 0x%x", argv[0], c & 0xff); if (c >= ' ') fprintf(stderr, " '%c'\n", c); else fprintf(stderr, " '^%c'\n", c + '@'); } } closepl(); } getint() { /* get an integer stored in 2 ascii bytes. */ short b1, b2; if ((b1 = getchar()) == EOF) return (EOF); if ((b2 = getchar()) == EOF) return (EOF); b2 = b2 << 8; return (b2 | b1); } string(s) char *s; { for (; *s = getchar(); s++) { if (*s == '\n') break; } *s = '\0'; return; } @EOF chmod 644 Splot/plotfilter.c echo x - Splot/splot.c cat >Splot/splot.c <<'@EOF' /*****************************************************************/ /* A Plot(5) interface which uses the Starbase Graphics Library. */ /*****************************************************************/ #include <starbase.c.h> #include <stdio.h> /*****************************/ /* Starbase file descriptor. */ /*****************************/ int fildes; /**********************************************************/ /* These variables are used to keep track of the current */ /* x and y coordinates. */ /**********************************************************/ int x_save, y_save, x_old, y_old; /*********************************************************/ /* These varables are used to determine how a label is */ /* being centred and if it should be rotatated. */ /*********************************************************/ char halign_type[30], valign_type[30]; int label_place = FALSE, rotate = FALSE; /******************************************************************/ /* The destination of the graphial output may be altered by using */ /* the arguments -Pplottertype and -Ddevice. These variables */ /* and the function get_dest are used to process these arguments. */ /* The default destination and plottertype are /dev/crt and */ /* hp300h. */ /******************************************************************/ extern int argc_copy; extern char **argv_copy; get_dest(device,plottertype) char *device, *plottertype; { int i; switch(argc_copy){ case 1: strcpy(device,"/dev/crt"); strcpy(plottertype,"hp300h"); break; case 3: for(i=1;i<=2;i++){ if(!strncmp(argv_copy[i],"-D",2)) strcpy(device,argv_copy[i]+2); else if(!strncmp(argv_copy[i],"-P",2)) strcpy(plottertype,argv_copy[i]+2); else{ fprintf(stderr,"Usage: splot [-Ddevice -Pplottertype]\n"); exit(1); } } break; default: fprintf(stderr,"Usage: splot [-Ddevice -Pplottertype]\n"); exit(1); break; } } /*************************************************************/ /* openpl: Opens a window on the screen with initial world */ /* coordinates, sets the viewport and changes the default */ /* aspect ratio to normal. */ /*************************************************************/ openpl(){ char device[30], plottertype[30]; get_dest(device,plottertype); if((fildes = gopen(device,OUTDEV,plottertype,INIT)) == -1){ fprintf(stderr,"Can't open device: File descriptor = %d.\n",fildes); exit(1); } vdc_extent(fildes,0.0,0.0,0.0,1.25,1.0,0.0); mapping_mode(fildes,TRUE); view_port(fildes,0.12*1.25,0.10,0.98*1.25,0.88); space(-999999,-999999,999999,999999); interior_style(fildes,INT_HOLLOW,TRUE); rectangle(fildes,-999999.0,-999999.0,999999.0,999999.0); } /**************************************************************/ /* closepl: Closes a window, which has been opened by openpl. */ /**************************************************************/ closepl(){ gclose(fildes); while(1); /* Program must be stopped by using ctrl-c. */ } /*****************************************************************/ /* move: Sets the current point to (x,y). This is the only way */ /* to define the current point. */ /*****************************************************************/ move(x,y) int x,y; { x_save = x; y_save = y; move2d(fildes,(float)x,(float)y); } /*******************************************************/ /* cont: Draws a line from the current point to (x,y). */ /*******************************************************/ cont(x,y) int x,y; { x_save = x; y_save = y; draw2d(fildes,(float)x,(float)y); } /******************************************************************/ /* line: Draws a line from (x1,y1) to (x2,y2). The current point */ /* does not change. If it has not been defined yet, it remains */ /* undefined. */ /******************************************************************/ line(x1,y1,x2,y2) int x1,y1,x2,y2; { x_old = x_save; y_old = y_save; move(x1,y1); cont(x2,y2); move(x_old,y_old); } /****************************************************/ /* label: Places a label beneath the plotting area. */ /****************************************************/ label(s) char *s; { float inx,iny,inz,outx,outy,outz; inx = x_save; iny = y_save; inz = 0.0; if(!label_place){ strcpy(halign_type,"TA_CENTER"); strcpy(valign_type,"TA_BOTTOM"); } label_place = FALSE; text_font_index(fildes,4); text_alignment(fildes,halign_type,valign_type,0.0,0.0); character_height(fildes,0.025); if(rotate) text_orientation2d(fildes,-1.0,0.0,0.0,1.0); else text_orientation2d(fildes,0.0,1.0,1.0,0.0); rotate = FALSE; transform_point(fildes,MC_TO_VDC,inx,iny,inz,&outx,&outy,&outz); text2d(fildes,outx,outy,s,VDC_TEXT,FALSE); } /*********************************************/ /* erase: Clears the entire display surface. */ /*********************************************/ erase(){ clear_control(fildes,CLEAR_DISPLAY_SURFACE); clear_view_surface(fildes); } /*****************************************************************/ /* point: Places a point at (x,y). The current point remains */ /* the same, undefined if it has not been defined by move(). */ /*****************************************************************/ point(x,y) int x,y; { line(x,y,x,y); } /*********************************************************************/ /* circle: Draws a circle, whose centre is at (x,y). It's size may */ /* be determined by stating the radius, r. */ /*********************************************************************/ circle(x,y,r) int x,y,r; { ellipse(fildes,(float)r,(float)r,(float)x,(float)y,0.0); } /*****************************************************************/ /* space: By using world coordinates a minimum and a maximum */ /* value for x and y can be defined. This function allows */ /* the user to define a window depending upon the data he is */ /* concerned with. */ /*****************************************************************/ space(x0,y0,x1,y1) int x0,y0,x1,y1; { view_window(fildes,(float)x0,(float)y0,(float)x1,(float)y1); } /*******************************************/ /* box: Draws a box at the given location. */ /*******************************************/ box(x1,y1,x2,y2) int x1,y1,x2,y2; { line(x1,y1,x1,y2); line(x1,y2,x2,y2); line(x2,y2,x2,y1); line(x2,y1,x1,y1); } /************************************/ /* linemod: Specifies the line type */ /************************************/ linemod(s) char s[]; { int type; switch(s[3]){ case 't' : type = 2; break; /* dotted */ case 'i' : type = 0; break; /* solid */ case 'g' : type = 5; break; /* long dashed */ case 'r' : type = 1; break; /* short dashed */ case 'd' : type = 3; break; /* dot dashed */ default : type = 0; break; /* solid */ } line_type(fildes,type); } /******************************************************/ /* labelrotation: Specifies whether the label is */ /* vertical or horizontal. */ /******************************************************/ labelrotation(s) char s[]; { switch(s[1]){ case 'h' : rotate = FALSE; break; case 'v' : rotate = TRUE; break; } } /******************************************************/ /* selectcolor: Specifies the colour to be used for */ /* drawing. */ /******************************************************/ selectcolor(s) int s; { switch(s){ case 1: line_color(fildes,0.0,0.0,0.0); break; /* black */ case 2: line_color(fildes,1.0,1.0,1.0); break; /* white */ case 3: line_color(fildes,1.0,0.0,0.0); break; /* red */ case 4: line_color(fildes,1.0,1.0,0.0); break; /* yellow */ case 5: line_color(fildes,0.0,1.0,0.0); break; /* green */ case 6: line_color(fildes,0.0,1.0,1.0); break; /* cyan */ case 7: line_color(fildes,0.0,0.0,1.0); break; /* blue */ case 8: line_color(fildes,1.0,0.0,1.0); break; /* magenta */ default: line_color(fildes,0.3,0.59,0.11); break; /* monochrome */ } } /*****************************/ /* linewid: Not implemented. */ /*****************************/ linewid(wi) int wi; {} /*********************************************************/ /* labelplace: Specifies how the label is being centred. */ /*********************************************************/ labelplace(s) char s[]; { label_place = TRUE; switch(s[1]){ case 'u' : strcpy(halign_type,"TA_CENTER"); strcpy(valign_type,"TA_TOP"); break; case 'o' : strcpy(halign_type,"TA_CENTER"); strcpy(valign_type,"TA_BOTTOM"); break; case 'l' : strcpy(halign_type,"TA_LEFT"); strcpy(valign_type,"TA_HALF"); break; case 'r' : strcpy(halign_type,"TA_RIGHT"); strcpy(valign_type,"TA_HALF"); break; case 'c' : strcpy(halign_type,"TA_CENTER"); strcpy(halign_type,"TA_HALF"); break; default : strcpy(halign_type,"TA_CENTER"); strcpy(valign_type,"TA_BOTTOM"); break; } } /* window: Calls space with the same parameters. */ window(x1,y1,x2,y2) int x1,y1,x2,y2; { space(x1,y1,x2,y2); } @EOF chmod 666 Splot/splot.c echo x - Splot/Makefile.HP cat >Splot/Makefile.HP <<'@EOF' BINDIR = /usr/local/bin LIBES = -ldd300h -lsb1 -lsb2 -lm SPLOTOBJ = splot.o plotfilter.o BINARIES = splot all: splot splot: $(SPLOTOBJ) cc -o splot splot.o plotfilter.o $(LIBES) install: all cp $(BINARIES) $(BINDIR) clean: rm $(SPLOTOBJ) $(BINARIES) @EOF chmod 644 Splot/Makefile.HP chmod 777 Splot exit 0