/* Tue Jul 7 15:47:29 EDT 1992 /leverrier/h1/ksg/src/test llout_.c */ /* llout_ps.c this file includes routines to make a postscript file out of the plots and to send them for printing. */ /* modified Oct 17, 1995 by gsg jr. to allow -h option for lpr command */ #include static float xmin=0.,xmax=12.0,ymin=0.,ymax=8.55,mx0=100,my0=100; static float ax=2450.,ay=3300.; static float ax0=2450.,ay0=3300.; static float a00=1.0; static int ic = -1,jf=0; static int lport=0; /* 0 => landscape, 1 => portrait */ static char name[80],*tempfilename=".temp.plot.file.0987654321..." ; static FILE *filename; static int ipage; static int new_org=0; static int anycolor=0; static float ps=1.0; static int force_line=0; static float w=0.; lloutc_( x0,x2,y0,y2) float *x0,*x2,*y0,*y2; { xmin = *x0; xmax = *x2; ymin = *y0; ymax = *y2; } static int points=0; /* if we are in a string of points */ static int mxo, myo, ipeno=1; static float wmult=1.6; /* line width multiplier */ static int last_m=1; /* was call call a move */ static int last_s=0; /* just did a stroke */ llout_( itype, x, y, npen) int *itype,*npen; float *x, *y; { int mx,my,ipen; /* fprintf(stderr," inside llout itype = %d npen = %d\n",*itype,*npen); */ if ( *npen == 999) { /* finish the plot and send for printing */ exx(); } if ( *itype == 2 ) { /* change a pen */ if ( anycolor == 0 ) fprintf(filename," %d setpen\n",*npen); else fprintf(filename," %d setpen\n", 0); ipeno = *npen; } if ( *itype == 3 ) { /* set landscape etc. */ lport = *npen; return(0); } if ( *itype == 4) { ipage++; fprintf(filename,"\n S\n"); fprintf(filename,"\n showpage \n"); fprintf(filename,"\n%%%%Page:%d %d \n restore \n save \n", ipage,ipage); if ( *npen == 0) { /* erase old data */ fclose(filename); } else if ( *npen == 1) /* print file on laser */ { exx(); } else if ( *npen == 2) { /* just write file */ fclose(filename); } return(0); } if ( *itype == 5) { ipage++; new_org = 0; fprintf(filename,"\n S\n"); fprintf(filename,"\n%% NEW_ORG \n"); fprintf(filename,"\n showpage \n"); fprintf(filename,"\n%%%%Page:%d %d \n restore \n save \n", ipage,ipage); return(0); } if ( *itype == 6) { new_org = 0; fprintf(filename,"\n%% NEW_ORG \n"); return(0); } if ( ic == -1) { ic = 0; ax = ax0 - 2*mx0; ay = ay0 - 2*my0; } if (*itype == 2 ) { return(0); } if (( *x < xmin) || ( *x > xmax)) return(1); if (( *y < ymin) || ( *y > ymax)) return(1); if ( lport == 1) { mx = ax*( *x - xmin)/(xmax - xmin) + mx0; my = ay*( *y - ymin)/(ymax - ymin) + my0; } else { my = ay*( *x - xmin)/(xmax - xmin) + my0; mx = ax*(a00 - ( *y - ymin)/(ymax - ymin)) + mx0; } ipen = ( *npen > 0) ? *npen : -*npen; ipen %= 10; if ( new_org == 0 ) { new_org++; fprintf(filename,"\n%% new_org \n"); /* fprintf(filename,"\n%% new_org \n"); */ fprintf(filename," S %d %d M\n",mx,my); last_m = 1; } if ( ipen == 3 ) { /* fprintf(filename," S %d %d M\n",mx,my); */ last_m++; if ( last_s == 1 ) { last_s = 0; fprintf(filename," %5.1f W\n", w); fprintf(filename," %d %d M\n",mxo,myo); fprintf(filename," %d %d L\n",mxo,myo); points++; } } else { last_s = 0; if ( mx == mxo && my == myo && force_line == 0 ) { if ( points == 0 && last_m > 0 ) { /* start of points string */ points++; last_s = 1; w = ipeno*wmult*ps; } } else { if ( points > 0 ) { /* done with points string */ points = 0; w = ipeno*wmult; fprintf(filename," %5.1f W\n", w); last_s = 2; } } if ( last_m > 0 || last_s > 0 ) { fprintf(filename," S %d %d M\n",mxo,myo); } fprintf(filename," %d %d L\n",mx,my); last_m=0; } mxo = mx; myo = my; } llchpn_( ipen) int *ipen; { if ( *ipen == -100 ) anycolor ^= 1; } static char st_parm[]=" -h "; static char *pt_st_parm[2]={ " -h ", " "}; static int i_st_parm=1; void set_exx_( ii) int *ii; { i_st_parm = *ii; } set_ps_( ps0) float *ps0; { ps = *ps0; } void startline_() { force_line = 1; } void endline_() { force_line = 0; } static exx() { int ii; char cmd[80]; fprintf(filename,"\n stroke\n"); fclose(filename); sprintf(cmd,"/usr/ucb/lpr %s %s\n", pt_st_parm[ i_st_parm], tempfilename); /* sprintf(cmd,"/plas5/h1/vgr/plt_prt/print %s\n",tempfilename); */ if ((ii = system( cmd )) != 0 ) fprintf( stderr, " system returned error %d \n", ii); ic = -1; } void getplotname_() { /* get the plot name */ fprintf(stderr, "\nWhat name do you wish the plot be called ( - don't save)?"); (void) gets(name); /* now rename the file to the requested name */ if ( *name && rename(tempfilename,name)) { fprintf(stderr,"\n problems in saving the plot file.quitting\n"); exit(1); } } void opentempplotfile_() { /* open a temporary file for the plots */ if ((filename = fopen(tempfilename,"w")) == NULL) { fprintf(stderr,"\n problems in opening temporary file.quitting.\n"); exit(1); } fprintf( filename,"%%!\n\ %%%%Page: 1 1\n\ /setpen {\n\ %f mul setlinewidth\n\ } def\n\ /L {lineto } def\n /M { moveto } def\n /S { stroke } def\n /W { stroke setlinewidth } def\n 0.25 0.25 scale\n 1 setlinecap\n", wmult*ipeno); if ( lport == 0 ) fprintf( filename,"0 -50 translate\n"); fprintf( filename," save \n"); ipage = 1; new_org = 0; } void closetempplotfile() { /* close the temporary file for the plots */ fclose(filename); }