home *** CD-ROM | disk | FTP | other *** search
- /*** plotps.c - plot the contours in Postscript ***/
-
- #include <stdio.h>
- #include <strings.h>
- #include <math.h>
- #include "common.h"
- #include "contour.h"
- #include "plot.h"
-
- #define PX_DIM 600
- #define PY_DIM 800
- #define PBDR_DIM 100
- #define PXL_DIM 800
- #define PYL_DIM 600
-
- double Pxmin,Pymin,Pxmax,Pymax;
-
- /* Output some postscript subroutines */
- initps(ips)
- FILE *ips;
- {
- extern double scale;
- char time[MAXCHAR];
-
- /* begin postscript output */
- fprintf(ips,"%c!\n",'%');
-
- if (landscape) fprintf(ips,"-90 rotate -790 0 translate\n");
- /*
- if (scale < 1.0) fprintf(ips,"%6.3f %6.3f scale\n",scale,scale);
- scale = 1.0;
- */
-
- fprintf(ips,"/defFontSizeTop %6.2f def\n",25*scale);
- fprintf(ips,"/defFontSizeSide %6.2f def\n",20*scale);
- fprintf(ips,"/defFontSizeAxes %6.2f def\n",15*scale);
- fprintf(ips,"/defFontSizeMkrs %6.2f def\n",12*scale);
- fprintf(ips,"/defFontSizeLbls %6.2f def\n",8*scale);
-
- fprintf(ips,"/UPJ {} def\n");
- fprintf(ips,"/MIJT {0 defFontSizeTop -2 div rmoveto} def\n");
- fprintf(ips,"/BOJT {0 defFontSizeTop neg rmoveto} def\n");
- fprintf(ips,"/MIJS {0 defFontSizeSide -2 div rmoveto} def\n");
- fprintf(ips,"/BOJS {0 defFontSizeSide neg rmoveto} def\n");
- fprintf(ips,"/MIJA {0 defFontSizeAxes -2 div rmoveto} def\n");
- fprintf(ips,"/BOJA {0 defFontSizeAxes neg rmoveto} def\n");
- fprintf(ips,"/MIJM {0 defFontSizeLbls -2 div rmoveto} def\n");
- fprintf(ips,"/BOJM {0 defFontSizeLbls neg rmoveto} def\n");
- fprintf(ips,"/MIJL {0 defFontSizeMkrs -3 div rmoveto} def\n");
- fprintf(ips,"/BOJL {0 defFontSizeMkrs neg rmoveto} def\n");
-
- fprintf(ips,"/LEJ {} def\n");
- fprintf(ips,"/CEJ {dup stringwidth pop -2 div 0 rmoveto} def\n");
- fprintf(ips,"/RIJ {dup stringwidth pop neg 0 rmoveto} def\n");
-
- /* print the time */
- get_localtime(time);
- fprintf(ips,"/Times-Bold findfont\n");
- fprintf(ips,"10 scalefont setfont\n");
- if (landscape)
- fprintf(ips,"%6.2f %6.2f moveto ",30.0,570.0);
- else
- fprintf(ips,"%6.2f %6.2f moveto ",30.0,750.0);
- fprintf(ips,"(%s) show\n",time);
- }
-
- /* draw the axes */
- axesps(ips)
- FILE *ips;
- {
- char *sprintf();
- extern char xlabel[MAXCHAR];
- extern char ylabel[MAXCHAR];
- extern char toplabel[MAXCHAR];
- extern int grid,equalscale,xticks,yticks;
- extern double scale;
- extern double xmin, xmax, ymin, ymax;
-
- double xdx,ydy;
- double xintv,yintv,xtmp,ytmp,xwid,ywid,ratio;
- double vallbl;
- int i;
- char label[10];
-
- /* Initialize */
- xdx = (xmax-xmin)/xticks;
- ydy = (ymax-ymin)/yticks;
-
- Pxmin = PBDR_DIM;
- Pymin = PBDR_DIM;
- xwid = PX_DIM - 2*PBDR_DIM;
- ywid = PY_DIM - 2*PBDR_DIM;
- if (landscape) {
- xwid = PXL_DIM - 2*PBDR_DIM; /* 600 */
- ywid = PYL_DIM - 2*PBDR_DIM; /* 400 */
- }
- Pxmax = Pxmin + scale*xwid;
- Pymax = Pymin + scale*ywid;
- if (equalscale == ON) {
- /* max xwid = 400, max ywid = 600 */
- ratio = (ymax-ymin)/(xmax-xmin);
- if (ratio <= (ywid/xwid)) {
- Pxmax = Pxmin + scale*xwid;
- Pymax = Pymin + ratio*scale*xwid;
- } else {
- Pymax = Pymin + scale*ywid;
- Pxmax = Pxmin + scale*ywid/ratio;
- }
- }
- xintv = (Pxmax-Pxmin)/xticks;
- yintv = (Pymax-Pymin)/yticks;
-
- /* define the axes */
- fprintf(ips,"/rectanglepath {\n");
- fprintf(ips,"newpath\n %6.2f %6.2f moveto\n",Pxmin,Pymin);
- fprintf(ips," 0.0 %6.2f rlineto\n",Pymax-Pymin);
- fprintf(ips," %6.2f 0.0 rlineto\n",Pxmax-Pxmin);
- fprintf(ips," 0.0 %6.2f rlineto\n",Pymin-Pymax);
- fprintf(ips,"closepath } def\n");
- fprintf(ips,"%6.2f setlinewidth\nrectanglepath stroke\n",2*scale);
-
- /* Top Label */
- fprintf(ips,"/Times-Bold findfont\n");
- fprintf(ips,"defFontSizeTop scalefont setfont\n");
- fprintf(ips," %6.2f %6.2f moveto ",0.5*(Pxmax+Pxmin),Pymax+25*scale);
- fprintf(ips,"(%s) UPJ CEJ show\n",toplabel);
-
- /* X-axis Label */
- fprintf(ips,"/Times-Bold findfont\n");
- fprintf(ips,"defFontSizeSide scalefont setfont\n");
- fprintf(ips," %6.2f %6.2f moveto ",0.5*(Pxmax+Pxmin),Pymin-20*scale);
- fprintf(ips,"(%s) BOJS CEJ show\n",xlabel);
-
- /* Y-axis Label */
- fprintf(ips,"/Times-Bold findfont\n");
- fprintf(ips,"defFontSizeSide scalefont setfont\n");
- fprintf(ips,"/Ylabel {");
- fprintf(ips,"%6.2f %6.2f moveto ",0.5*(Pymax+Pymin),50*scale-Pxmin);
- fprintf(ips,"(%s) UPJ CEJ show ",ylabel);
- fprintf(ips,"} def\n 90 rotate\n Ylabel\n -90 rotate\n");
-
- /* side labels */
- fprintf(ips,"/Times-Roman findfont\n");
- fprintf(ips,"defFontSizeMkrs scalefont setfont\n");
- sprintf(label,"%s","MINIMUM");
- fprintf(ips," %6.2f %6.2f moveto",Pxmax+40*scale,Pymax-20*scale);
- fprintf(ips," (%s) MIJM CEJ show\n",label);
- sprintf(label,"%.2f",zmin);
- fprintf(ips," %6.2f %6.2f moveto",Pxmax+40*scale,Pymax-40*scale);
- fprintf(ips," (%s) MIJM CEJ show\n",label);
- sprintf(label,"%s","MAXIMUM");
- fprintf(ips," %6.2f %6.2f moveto",Pxmax+40*scale,Pymin+40*scale);
- fprintf(ips," (%s) MIJM CEJ show\n",label);
- sprintf(label,"%.2f",zmax);
- fprintf(ips," %6.2f %6.2f moveto",Pxmax+40*scale,Pymin+20*scale);
- fprintf(ips," (%s) MIJM CEJ show\n",label);
-
- /* Tick Marks on the X-axis */
- fprintf(ips,"/Times-Roman findfont\n");
- fprintf(ips,"defFontSizeAxes scalefont setfont\n");
- for (i=0; i<=xticks; i++) {
- xtmp = Pxmin + xintv*i;
- ytmp = Pymin;
- fprintf(ips,"newpath %6.2f %6.2f moveto\n",xtmp,ytmp);
- fprintf(ips," 0 %6.2f rlineto stroke\n",3*scale);
-
- vallbl = xmin + i*xdx;
- sprintf(label,"%.2g",vallbl);
- fprintf(ips," %6.2f %6.2f moveto",xtmp,ytmp);
- fprintf(ips," (%s) BOJA CEJ show\n",label);
-
- ytmp = Pymax;
- fprintf(ips,"newpath %6.2f %6.2f moveto\n",xtmp,ytmp);
- fprintf(ips," 0 %6.2f rlineto stroke\n",-3*scale);
- }
-
- /* Tick Marks on the Y-axis */
- for (i=0; i<=yticks; i++) {
- ytmp = Pymin + yintv*i;
- xtmp = Pxmin;
- fprintf(ips,"newpath %6.2f %6.2f moveto\n",xtmp,ytmp);
- fprintf(ips," %6.2f 0 rlineto stroke\n",3*scale);
-
- vallbl = ymin + i*ydy;
- sprintf(label,"%.2g",vallbl);
- fprintf(ips," %6.2f %6.2f moveto",xtmp-5*scale,ytmp+3*scale);
- fprintf(ips," (%s) MIJA RIJ show\n",label);
-
- xtmp = Pxmax;
- fprintf(ips,"newpath %6.2f %6.2f moveto\n",xtmp,ytmp);
- fprintf(ips," %6.2f 0 rlineto stroke\n",-3*scale);
- }
-
- /* draw the grid */
- for (i=1; i<xticks; i++) {
- xtmp = Pxmin + xintv*i;
- ytmp = Pymax - 3*scale;
- if (grid == ON) {
- fprintf(ips,"[1 4] 0 setdash\n");
- fprintf(ips,"%6.2f setlinewidth 0.5 setgray\n",0.3*scale);
- fprintf(ips,"newpath %6.2f %6.2f moveto ",xtmp,ytmp);
- fprintf(ips,"0 %6.2f rlineto stroke\n",Pymin-Pymax+6*scale);
- fprintf(ips,"%6.2f setlinewidth 0.0 setgray\n",2.0*scale);
- linetypps(ips,0);
- }
- }
- for (i=1; i<yticks; i++) {
- ytmp = Pymin + yintv*i;
- xtmp = Pxmax - 3*scale;
- if (grid == ON) {
- fprintf(ips,"[1 4] 0 setdash\n");
- fprintf(ips,"%6.2f setlinewidth 0.5 setgray\n",0.3*scale);
- fprintf(ips,"newpath %6.2f %6.2f moveto ",xtmp,ytmp);
- fprintf(ips,"%6.2f 0 rlineto stroke\n",Pxmin-Pxmax+6*scale);
- fprintf(ips,"%6.2f setlinewidth 0.0 setgray\n",2.0*scale);
- linetypps(ips,0);
- }
- }
-
- fprintf(ips,"%6.2f setlinewidth\n",0.5*scale);
- fprintf(ips,"rectanglepath clip\n");
- }
-
- /* draw the plot */
- plotps(ips)
- FILE *ips;
- {
- int set_label_pt();
- extern int linetypes,contlabel;
- extern double xmin, xmax, ymin, ymax;
- extern plotptr plot_listhead;
-
- nodeptr N;
- plotptr P;
- double x,y,xn, xm, yn, ym, idx, jdy, oldlevel, angle;
- int linepat, npts, j, m, n, kl=1;
-
- idx = (Pxmax-Pxmin)/(xmax-xmin);
- jdy = (Pymax-Pymin)/(ymax-ymin);
-
- if (plot_listhead!=NULL) oldlevel = plot_listhead->level;
- for (P=plot_listhead; P!=NULL; P=P->next) {
- /* first count the number of points in the plot */
- npts=0;
- for (N=P->nodehead; N!=NULL; N=N->next) npts++;
- m = set_label_pt(npts);
- /*
- m = (int)(0.45*npts)-1;
- */
- n = m+1;
-
- if (npts>0) {
- /* plot the points */
- if (oldlevel != P->level) kl++;
- linepat = linetypps(ips,kl);
- N = P->nodehead;
- x = (N->pt.x-xmin)*idx + Pxmin;
- y = (N->pt.y-ymin)*jdy + Pymin;
- fprintf(ips,"newpath\n %8.2f %8.2f moveto\n",x,y);
- j = 1;
- N = N->next;
- for ( ; N!=NULL; N=N->next) {
- x = (N->pt.x-xmin)*idx + Pxmin;
- y = (N->pt.y-ymin)*jdy + Pymin;
- fprintf(ips," %8.2f %8.2f lineto\n",x,y);
- if (j==m) {xm = x; ym = y;}
- if (j==n) {xn = x; yn = y;}
- j++;
- }
- fprintf(ips,"stroke\n");
-
- /* now put on the labels */
- if (contlabel && (linepat==0 || linepat==1) && (m>=0 && n<npts)) {
- if (fabs(xm-xn)<SMALL)
- angle = -90.0;
- else
- angle = 360.0/(2*3.14159)*atan((yn-ym)/(xn-xm));
- labelps(ips,xm,ym,angle,P->level);
- }
- }
- oldlevel = P->level;
- }
- }
-
- /* return a linetype */
- int linetypps(ips,line)
- FILE *ips;
- int line;
- {
- extern int linetypes;
- int linepat;
-
- if (linetypes <= 2) line = line % linetypes;
- else if (linetypes == 3) line = line % 4;
-
- switch (line) {
- case 0 : fprintf(ips,"[] 0 setdash\n"); linepat = 0; break;
- case 1 : fprintf(ips,"[1 2] 0 setdash\n"); linepat = 2; break;
- case 2 : fprintf(ips,"[6 6] 0 setdash\n"); linepat = 1; break;
- case 3 : fprintf(ips,"[1 2] 0 setdash\n"); linepat = 2; break;
- default: fprintf(ips,"[] 0 setdash\n"); linepat = 0; break;
- }
- return (linepat);
- }
-
- /* paste on labels */
- labelps(ips,xn,yn,angle,level)
- FILE *ips;
- double xn,yn,angle,level;
- {
- char *sprintf();
- extern double scale;
- char text[100];
-
- sprintf(text,"%.2g",level);
- fprintf(ips,"/Times-Roman findfont\n");
- fprintf(ips,"defFontSizeLbls scalefont setfont\n");
- fprintf(ips,"/label {");
- fprintf(ips,"newpath\n ");
- fprintf(ips,"%6.2f %6.2f moveto\n",-8*scale,-4*scale);
- fprintf(ips,"0 %6.2f rlineto\n",8*scale);
- fprintf(ips,"%6.2f 0 rlineto\n",16*scale);
- fprintf(ips,"0 %6.2f rlineto\n",-8*scale);
- fprintf(ips,"closepath\n 1.0 setgray \n fill \n 0 setgray\n");
- fprintf(ips,"0 0 moveto\n");
- fprintf(ips,"(%s) MIJL CEJ show } def\n",text);
- fprintf(ips,"%6.2f %6.2f translate\n",xn,yn);
- fprintf(ips,"%6.2f rotate\nlabel\n %6.2f rotate\n",angle,-angle);
- fprintf(ips,"%6.2f %6.2f translate\n",-xn,-yn);
- }
-
- int set_label_pt(npts)
- int npts;
- {
- int rand();
- int i= -1,m;
- double mult;
-
- if (npts < 20)
- m = (int)(0.45*npts)-1;
- else {
- i = rand() % 10;
- mult = 0.1*i + 0.05;
- m = 10 + (int)(mult*(npts-20));
- }
- return(m);
- }
-
- /* End procedure */
- endgrps(ips)
- FILE *ips;
- {
- fprintf(ips,"showpage\n");
-
- /* Close the file */
- fclose(ips);
- }
-