plb@cbnewsi.ATT.COM (peter.l.berghold) (08/17/89)
Hi Folks, Here is a filter that I whipped up to fix problems with spooling to HP plotters from STARBASE. The problem that it fixes is one of sizing. Normally STARBASE spools thinking it is working with E size paper. This is fine if you really are, but if you are using an A size plotter, most of your plot ends up off the page. So, here it is... # 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 plb at violin on Tue Aug 15 12:47:33 1989 # # This archive contains: # Makefile hp7550a.l hp7550a.doc README # # Error checking via wc(1) will be performed. LANG=""; export LANG echo x - Makefile cat >Makefile <<'@EOF' ################################################################################ # @(#)Makefile 1.12 06/09/89 # # awkscript=../bin/prog_fltr.awk LIBES=-ll -lddhpgl -ldvio -lsb1 -lsb2 save_files=Makefile hp7550a.l hp7550a.doc README all:hp7550a listing shar README document hp7550a: hp7550a.c cc -g -v hp7550a.c $(LIBES) -o hp7550a size hp7550a hp7550a.c: hp7550a.l lex hp7550a.l set -vx ; awk -f ../lib/prog_fltr.awk lex.yy.c > hp7550a.c rm -fr lex.yy.c listing: hp7550a.c cc -C -Wc,-m -Wc,-L -Wc,-o hp7550a.c $(LIBES) -o hp7550a 2> /dev/null | lp -s & touch listing shar: $(save_files) set -ex ; shar -t -v -b -c $(save_files) > ../etc/hp7550a.shar.1 touch shar README: hp7550a.doc set -ex;tbl hp7550a.doc | nroff -mm -Tlp -e > README document: hp7550a.doc set -ex;tbl hp7550a.doc | nroff -mm -Tlp -e | col -l | lp -s -dlaser touch document .DEFAULT: get ../sccs/s.$< # # ################################################################################ ### hp7550a.o: /usr/include/starbase.c.h @EOF if test "`wc -lwc <Makefile`" != ' 35 123 1015' then echo ERROR: wc results of Makefile are `wc -lwc <Makefile` should be 35 123 1015 fi chmod 444 Makefile echo x - hp7550a.l cat >hp7550a.l <<'@EOF' %{ /*============================================================================*/ #pragma VERSIONID "@(#)hp7550a.l 2.7 06/09/89" #pragma COPYRIGHT_DATE "@(#) Spooled plotter filter for hp7550a. (c) 1987." #pragma COPYRIGHT "@(#) Peter L. Berghold, Microwave Semiconductor Corp." /* Authorship: */ /* Peter L. Berghold */ /* Microwave Semiconductor Corporation */ /* 100 School House Rd. */ /* Somerset, NJ 08873 */ /* (201) 563-6535 */ /* (c) Copyright 1987, All rights reserved */ /* */ /*============================================================================*/ #include <starbase.c.h> #define BUGS 0 #define TRACE if (BUGS == 1) typedef struct { float x,y; } coords; int a,b,c,d; int i; float x1,y1,x2,y2; float fix_y_parm(),fix_x_parm(); int pen_state=0; /* We will start with the pen up! */ int plotter; int plotter_open=0; int speed=80; int transparency=0; float basex=0.0; float basey=0.0; float maxx=1000.0; float maxy=1000.0; coords P1={80.0,320.0}; coords P2={10080.0,7520.0}; gescape_arg arg1,arg2; extern int getopt(); extern int optind,opterr; extern char *optarg; %} pval [0-9]* nval [-0-9]* %start PEN_AT1 PEN_AT2 IP1 IP2 IP3 IP4 SP VS %start LT1 %% <INITIAL>";" { /*Ignore a solitary ";" */ } <INITIAL>"PA" { BEGIN PEN_AT1; } <PEN_AT1>{pval}[","] { a=atoi(yytext); BEGIN PEN_AT2; } <PEN_AT1>{nval}[","] { a=atoi(yytext); BEGIN PEN_AT2; } <PEN_AT2>{nval}[";""\n"] { b=atoi(yytext); x1=a; x1=fix_x_parm((float)a); y1=b; y1=fix_y_parm((float)b); if (pen_state == 0) { TRACE printf("Pen moved to %1.6f,%1.6f\n",x1,y1); move2d(plotter,x1,y1); make_picture_current(plotter); } else { TRACE printf("Line draw to %1.6f,%1.6f\n",x1,y1); draw2d(plotter,x1,y1); make_picture_current(plotter); } BEGIN 0; } <PEN_AT2>{nval}[","] { b=atoi(yytext); x1=a; x1=fix_x_parm((float)a); y1=b; y1=fix_y_parm((float)b); if (pen_state == 0) { TRACE printf("Pen moved to %1.6f,%1.6f\n",x1,y1); move2d(plotter,x1,y1); make_picture_current(plotter); } else { TRACE printf("Line draw to %1.6f,%1.6f\n",x1,y1); draw2d(plotter,x1,y1); make_picture_current(plotter); } BEGIN PEN_AT1; } <PEN_AT2>{pval}[";""\n"] { b=atoi(yytext); x1=a; x1=fix_x_parm((float)a); y1=b; y1=fix_y_parm((float)b); if (pen_state == 0) { TRACE printf("Pen moved to %1.6f,%1.6f\n",x1,y1); move2d(plotter,x1,y1); make_picture_current(plotter); } else { TRACE printf("Line draw to %1.6f,%1.6f\n",x1,y1); draw2d(plotter,x1,y1); make_picture_current(plotter); } BEGIN 0; } <PEN_AT2>{pval}[","] { b=atoi(yytext); x1=a; x1=fix_x_parm((float)a); y1=b; y1=fix_y_parm((float)b); if (pen_state == 0) { TRACE printf("Pen moved to %1.6f,%1.6f\n",x1,y1); move2d(plotter,x1,y1); make_picture_current(plotter); } else { TRACE printf("Line draw to %1.6f,%1.6f\n",x1,y1); draw2d(plotter,x1,y1); make_picture_current(plotter); } BEGIN PEN_AT1; } <INITIAL>"IP" { BEGIN IP1; } <IP1>{pval}[","] | <IP1>{nval}[","] { a=atoi(yytext); BEGIN IP2; } <IP2>{pval}[","] | <IP2>{nval}[","] { b=atoi(yytext); BEGIN IP3; } <IP3>{pval}[","] | <IP3>{pval}[","] { c=atoi(yytext); BEGIN IP4; } <IP4>{pval}[";""\n"] | <IP4>{nval}[";""\n"] { d=atoi(yytext); basex=a; basey=b; maxx=c; maxy=d; TRACE printf("Scaling set: (x1,y1)=%4.3f,%4.3f ",basex,basey); TRACE printf("(x2,y2)=%4.3f,%4.3f\n",maxx,maxy); BEGIN 0; } <INITIAL>"PG"[";""\n"] { clear_view_surface(plotter); TRACE printf("Plotter paper fed."); } <INITIAL>"VS" { BEGIN VS; } <VS>{pval}[";""\n"] { speed=atoi(yylex); if (! transparency ) { arg1.i[0]=speed; arg2.i[0]=0; gescape(plotter,HPGL_SET_PEN_SPEED,&arg1,&arg2); } BEGIN 0; } <INITIAL>[a-zA-Z0-9",""."";""\n"] { for (i=0;i<yyleng;i++) arg1.c[i]=yytext[i]; arg2.i[0]=yyleng; gescape(plotter,HPGL_WRITE_BUFFER,&arg1,&arg2); } %% float fix_x_parm(xx) float xx; { float tmp; float range; TRACE printf("fix_x_parm: value passed: %3.3f\n",xx); tmp=(xx+15710.0)/31420.0; TRACE printf("Returned value= %12.6f\n",tmp); return(tmp); } float fix_y_parm(xx) float xx; { float tmp; float range; TRACE printf("fix_y_parm: value passed: %3.3f\n",xx); tmp=(xx+10060.0)/20120.0; TRACE printf("returned value= %12.6f\n",tmp); return(tmp); } main(argc,argv) int argc; char *argv[]; { int dummy; int c; int flag=0; while((c=getopt(argc,argv,"ts:"))!=EOF) switch(c){ case 't': speed=10; /* Let's go real slow for overheads! */ transparency=1; break; case 's': speed=atoi(optarg); break; case '?': flag++; break; } plotter=gopen("/dev/hpib/1a7",OUTDEV,"hpgl",INIT); mapping_mode(plotter,1); vdc_extent(plotter,0.0,0.0,0.0,1.0,1.0,1.0); fprintf(stderr,"Setting plotter speed to %d CM/SEC\n",speed); arg1.i[0]=speed; arg2.i[0]=0; gescape(plotter,HPGL_SET_PEN_SPEED,&arg1,&arg2); while((dummy=yylex())!=NULL); strcpy(arg1.c,"PG;"); arg2.i[0]=3; gescape(plotter,HPGL_WRITE_BUFFER,&arg1,&arg2); plotter=gclose(plotter); } @EOF if test "`wc -lwc <hp7550a.l`" != ' 261 488 5436' then echo ERROR: wc results of hp7550a.l are `wc -lwc <hp7550a.l` should be 261 488 5436 fi chmod 444 hp7550a.l echo x - hp7550a.doc cat >hp7550a.doc <<'@EOF' .PH "'hp7550a 1.8 06/09/89''Printed: \*(DT'" .PF "'MSC, ATE Group'[%]'Peter L. Berghold'" .H 1 "The problem:" To spool the output of a STARBASE driven graphics program to a plotter, one needs to use the HPGL graphics drivers. As a result, this spooled output will not result in the expected results on the hp7550a plotter as well as other plotters. .P 1 The reason for this is that the HPGL driver expects to be sending its output to an E sized plotter. The reality of this may be (and probably is) that one is attempting to plot to an A sized plotter as in the case of an hp7550a plotter. Where the difficulty lies is in how "P1" and "P2", the lower left hand and upper right hand corners respectively, on the plotter are defined in plotter units. .DS .nf .sp 2 .PS move right 0.2 P1CORN: "P1 " rjust line up 2.0 then right 5.0 P2CORN: " P2" ljust line from P2CORN -0,0 down 2.0 then left 5.0 .PE HPGL driver: .EQ P1 sub {xy}=[-15710,-10060] P2 sub {xy}=[15710,10060] .EN .sp 2 HP7550a plotter: [For "A" sized paper] .EQ P1 sub {xy}=[80,320] P2 sub {xy}=[10080,7520] .EN .sp 2 Above values in logical plotter units. .fi .sp 2 .FG "P1 & P2 Illustrated." .DE .bp .sp 2 .H 1 "The solution:" The spooled plot data is piped through a filter that will plot directly to the plotter via the STARBASE device drivers. This filter is driven by the line printer spooler via the interface script. .P 1 Scaling is performed to turn the integer value coordinate data into values between 0 and 1 which STARBASE will accept as values to be plotted. Also the plot data in the form of HPGL instructions is parsed for the applicable instructions to be translated into STARBASE function calls. .H 1 "The nitty gritty:" The three basic HPGL instructions that effect the plotting are as follows: .sp 3 .BL .LI PU - Pen up. .LI PD - Pen down. .LI PA - Pen at. .LE .sp 2 A lexical analysis program was written through the use of LEX to perform the parsing of the HPGL instructions. The xy coordinate information is extracted and the scaling performed. .nf .sp 2 .EQ x'={x+15710} over 31420 y'={y+10060} over 20120 .EN .sp 2 .fi .FG "Equations used to normalize the xy coordinate data parsed from the HPGL data file stream." .sp 2 The action that takes place on these xy coordinate data is dependant on the instruction itself, and the last PU or PD HPGL instruction parsed. .P 1 When the lexical analysis program encounters either a PU or a PD instruction a flag is set accordingly. When a PA is encountered and the flag is a FALSE condition as a result of a PU instruction the pen is moved with no line being drawn. When a PD is encountered and the flag is a TRUE condition a line is drawn. Simple. .P 1 The other instruction that is parsed is the SP (Select Pen) instruction. This allows the plotting of multi-colored plots. Pen numbers of 0-9 are allowed. .H 1 "The last word:" There are many other featured instructions of the HPGL instruction set that are not parsed, but are probably not needed. They will be added in future releases of this package. .TC @EOF if test "`wc -lwc <hp7550a.doc`" != ' 87 554 3118' then echo ERROR: wc results of hp7550a.doc are `wc -lwc <hp7550a.doc` should be 87 554 3118 fi chmod 444 hp7550a.doc echo x - README cat >README <<'@EOF' hp7550a 1.8 06/09/89 Printed: August 15, 1989 1. TTTThhhheeee pppprrrroooobbbblllleeeemmmm:::: To spool the output of a STARBASE driven graphics program to a plotter, one needs to use the HPGL graphics drivers. As a result, this spooled output will not result in the expected results on the hp7550a plotter as well as other plotters. The reason for this is that the HPGL driver expects to be sending its output to an E sized plotter. The reality of this may be (and probably is) that one is attempting to plot to an A sized plotter as in the case of an hp7550a plotter. Where the difficulty lies is in how "P1" and "P2", the lower left hand and upper right hand corners respectively, on the plotter are defined in plotter units. move right 0.2 P1CORN: "P1 " rjust line up 2.0 then right 5.0 P2CORN: " P2" ljust line from P2CORN -0,0 down 2.0 then left 5.0 HPGL driver: HP7550a plotter: [For "A" sized paper] Above values in logical plotter units. FFFFiiiigggguuuurrrreeee 1111.... P1 & P2 Illustrated. MSC, ATE Group [1] Peter L. Berghold hp7550a 1.8 06/09/89 Printed: August 15, 1989 2. TTTThhhheeee ssssoooolllluuuuttttiiiioooonnnn:::: The spooled plot data is piped through a filter that will plot directly to the plotter via the STARBASE device drivers. This filter is driven by the line printer spooler via the interface script. Scaling is performed to turn the integer value coordinate data into values between 0 and 1 which STARBASE will accept as values to be plotted. Also the plot data in the form of HPGL instructions is parsed for the applicable instructions to be translated into STARBASE function calls. 3. TTTThhhheeee nnnniiiittttttttyyyy ggggrrrriiiittttttttyyyy:::: The three basic HPGL instructions that effect the plotting are as follows: o+ PU - Pen up. o+ PD - Pen down. o+ PA - Pen at. A lexical analysis program was written through the use of LEX to perform the parsing of the HPGL instructions. The xy coordinate information is extracted and the scaling performed. FFFFiiiigggguuuurrrreeee 2222.... Equations used to normalize the xy coordinate data parsed from the HPGL data file stream. The action that takes place on these xy coordinate data is dependant on the instruction itself, and the last PU or PD HPGL instruction parsed. When the lexical analysis program encounters either a PU or a PD instruction a flag is set accordingly. When a PA is encountered and the flag is a FALSE condition as a result of a PU instruction the pen is moved with no line being drawn. When a PD is encountered and the flag is a TRUE condition a line is drawn. Simple. MSC, ATE Group [2] Peter L. Berghold hp7550a 1.8 06/09/89 Printed: August 15, 1989 The other instruction that is parsed is the SP (Select Pen) instruction. This allows the plotting of multi-colored plots. Pen numbers of 0-9 are allowed. 4. TTTThhhheeee llllaaaasssstttt wwwwoooorrrrdddd:::: There are many other featured instructions of the HPGL instruction set that are not parsed, but are probably not needed. They will be added in future releases of this package. MSC, ATE Group [3] Peter L. Berghold CONTENTS 1. The problem:......................................... 1 2. The solution:........................................ 2 3. The nitty gritty:.................................... 2 4. The last word:....................................... 3 - i - LIST OF FIGURES Figure 1. P1 & P2 Illustrated........................... 1 Figure 2. Equations used to normalize the xy coordinate data parsed from the HPGL data file stream........................................ 2 - ii - @EOF if test "`wc -lwc <README`" != ' 330 572 4910' then echo ERROR: wc results of README are `wc -lwc <README` should be 330 572 4910 fi chmod 600 README exit 0 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > _ /| \`o_O' Formerly of MSC, Now with AT&T. ( ) UUCP: ..!att!violin!plb U Aachk! Phft!