home *** CD-ROM | disk | FTP | other *** search
- /*** plothp.c - plot out in hp format ***/
-
- #include <stdio.h>
- #include <strings.h>
- #include <math.h>
- #include "common.h"
- #include "contour.h"
- #include "plot.h"
-
- #define HX_DIM 500
- #define HY_DIM 400
- #define HBDR_DIM 50
- double Hxmin, Hxmax, Hymin, Hymax;
-
- /* draw the axes */
- axeshp()
- {
- char *sprintf();
- extern char xlabel[MAXCHAR];
- extern char ylabel[MAXCHAR];
- extern char toplabel[MAXCHAR];
- extern int grid,equalscale,xticks,yticks;
- extern double xmin, ymin, xmax, 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;
-
- Hxmin = HBDR_DIM;
- Hymin = HBDR_DIM;
- xwid = HX_DIM - 2*HBDR_DIM;
- ywid = HY_DIM - 2*HBDR_DIM;
- Hxmax = Hxmin + xwid;
- Hymax = Hymin + ywid;
- if (equalscale == ON) {
- /* max xwid = 400. max ywid = 300 */
- ratio = (ymax-ymin)/(xmax-xmin);
- if (ratio <= (ywid/xwid) ) {
- Hxmax = Hxmin + xwid;
- Hymax = Hymin + ratio*xwid;
- } else {
- Hymax = Hymin + ywid;
- Hxmax = Hxmin + ywid/ratio;
- }
- }
- xintv = (Hxmax-Hxmin)/xticks;
- yintv = (Hymax-Hymin)/yticks;
-
- /* Turn on graphics display, set line type = 1 */
- printf("%c*dfz%c*dcz%c*m1b1q3x\n",esc,esc,esc);
-
- /* Define a grid pattern */
- printf("%c*m 8 1 cz\n",esc);
-
- /* define the axes */
- printf("%c*paf %6f %6f %6f %6f z\n",esc,Hxmin,Hymin,Hxmin,Hymax);
- printf("%c*paf %6f %6f %6f %6f z\n",esc,Hxmin,Hymax,Hxmax,Hymax);
- printf("%c*paf %6f %6f %6f %6f z\n",esc,Hxmax,Hymax,Hxmax,Hymin);
- printf("%c*paf %6f %6f %6f %6f z\n",esc,Hxmax,Hymin,Hxmin,Hymin);
- printf("%c*paf %6f %6f %6f %6f z\n",esc,Hxmin-1,Hymin-1,Hxmin-1,Hymax+1);
- printf("%c*paf %6f %6f %6f %6f z\n",esc,Hxmin-1,Hymax+1,Hxmax+1,Hymax+1);
- printf("%c*paf %6f %6f %6f %6f z\n",esc,Hxmax+1,Hymax+1,Hxmax+1,Hymin-1);
- printf("%c*paf %6f %6f %6f %6f z\n",esc,Hxmax+1,Hymin-1,Hxmin-1,Hymin-1);
-
- /* Set the options for the labels */
- printf("%c*m 1n4q7x\n",esc);
-
- /* Top Label */
- printf("%c*dsk %6f %6f oz\n",esc,0.5*(Hxmax+Hxmin),Hymax+10);
- printf("%c*dS%s\n",esc,toplabel);
-
- /* Set the options for the labels */
- printf("%c*m 1n6q7x\n",esc);
-
- /* X-axis Label */
- printf("%c*dsk %6f %6f oz\n",esc,0.5*(Hxmax+Hxmin),Hymin-20);
- printf("%c*dS%s\n",esc,xlabel);
-
- /* Set the options for the labels */
- printf("%c*m 2n4q7x\n",esc);
-
- /* Y-axis Label */
- printf("%c*dsk %6f %6f oz\n",esc,Hxmin-40,0.5*(Hymin+Hymax));
- printf("%c*dS%s\n",esc,ylabel);
-
- /* Set the options for the labels */
- printf("%c*m 1n6q3x\n",esc);
-
- /* side labels */
- sprintf(label,"%s","MINIMUM");
- printf("%c*paf %6f %6f z\n",esc,Hxmax+40,Hymax-20);
- printf("%c*l%s\n",esc,label);
- sprintf(label,"%.2f",zmin);
- printf("%c*paf %6f %6f z\n",esc,Hxmax+40,Hymax-40);
- printf("%c*l%s\n",esc,label);
- sprintf(label,"%s","MAXIMUM");
- printf("%c*paf %6f %6f z\n",esc,Hxmax+40,Hymin+40);
- printf("%c*l%s\n",esc,label);
- sprintf(label,"%.2f",zmax);
- printf("%c*paf %6f %6f z\n",esc,Hxmax+40,Hymin+20);
- printf("%c*l%s\n",esc,label);
-
- /* Set the options for the labels */
- printf("%c*m 1n1q3x\n",esc);
-
- /* Tick Marks on the X-axis */
- for (i=0; i<=xticks; i++) {
- xtmp = Hxmin + xintv*i;
- ytmp = Hymin;
- printf("%c*paf %6f %6f %6f %6f z\n",esc,xtmp,ytmp,xtmp,ytmp+3);
-
- vallbl = xmin + i*xdx;
- sprintf(label,"%6.2f",vallbl);
- printf("%c*paf %6f %6f z\n",esc,xtmp-35,ytmp-15);
- printf("%c*l%s\n",esc,label);
-
- ytmp = Hymax;
- printf("%c*paf %6f %6f %6f %6f z\n",esc,xtmp,ytmp-3,xtmp,ytmp);
-
- if (grid == ON) {
- linetyphp(2);
- printf("%c*paf %6f %6f %6f %6f z\n",esc,xtmp,Hymin+3,xtmp,Hymax-3);
- linetyphp(1);
- }
- }
-
- /* Tick Marks on the Y-axis */
- for (i=0; i<=yticks; i++) {
- ytmp = Hymin + yintv*i;
- xtmp = Hxmin;
- printf("%c*paf %6f %6f %6f %6f z\n",esc,xtmp,ytmp,xtmp+3,ytmp);
-
- vallbl = ymin + i*ydy;
- sprintf(label,"%6.2f",vallbl);
- printf("%c*paf %6f %6f z\n",esc,xtmp-55,ytmp);
- printf("%c*l%s\n",esc,label);
-
- xtmp = Hxmax;
- printf("%c*paf %6f %6f %6f %6f z\n",esc,xtmp-3,ytmp,xtmp,ytmp);
-
- if (grid == ON) {
- linetyphp(2);
- printf("%c*paf %6f %6f %6f %6f z\n",esc,Hxmin+3,ytmp,Hxmax-3,ytmp);
- linetyphp(1);
- }
- }
- }
-
- /* plot the curves */
- plothp()
- {
- char *sprintf();
- extern int linetypes;
- extern double xmin, xmax, ymin, ymax;
- extern plotptr plot_listhead;
-
- plotptr P;
- nodeptr N;
- char text[10];
- double x,y,xm,ym,idx,jdy,oldlevel;
- int linepat, npts, j, m, kl=1;
-
- idx = (Hxmax-Hxmin)/(xmax-xmin);
- jdy = (Hymax-Hymin)/(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 = (int)(0.5*npts)-1;
-
- if (npts>0) {
- /* plot the points */
- if (oldlevel != P->level) kl++;
- linepat = linetyphp(kl);
- j = 0;
- printf("%c*paf \n",esc); /* new line */
- for (N=P->nodehead; N!=NULL; N=N->next) {
- x = (N->pt.x - xmin)*idx + Hxmin;
- y = (N->pt.y - ymin)*jdy + Hymin;
- printf("%6f %6f \n",x,y);
- if (j==m) { xm=x; ym=y; }
- j++;
- }
- printf(" z\n");
-
- /* label the contours */
- if ((linepat==0||linepat==1) && (m>=0 && m<npts)) {
- /* Set the options for the labels */
- printf("%c*m 1n6q3x\n",esc);
- sprintf(text,"%.2f",P->level);
- printf("%c*paf %6f %6f z\n",esc,xm,ym);
- printf("%c*l%s\n",esc,text);
- }
- }
- oldlevel = P->level;
- }
- }
-
- /* change the linetype */
- int linetyphp(line)
- int line;
- {
- extern int linetypes;
- int linepat, newline, newcolor;
-
- if (linetypes <= 2) line = line % linetypes;
- else if (linetypes == 3) line = line %4;
-
- switch (line) {
- case 0 : newline = 1; newcolor = 7; linepat = 0; break;
- case 1 : newline = 7; newcolor = 6; linepat = 2; break;
- case 2 : newline = 5; newcolor = 7; linepat = 1; break;
- case 3 : newline = 7; newcolor = 6; linepat = 2; break;
- default: newline = 1; newcolor = 7; linepat = 0; break;
- }
-
- printf("%c*m%db%dxz\n",esc,newline,newcolor);
-
- return(linepat);
- /* newline = 1 : solid line color = 0 : black */
- /* newline = 4 : dot-dash color = 1 : red */
- /* newline = 5 : long dash color = 2 : green */
- /* newline = 6 : short dash color = 3 : yellow */
- /* newline = 7 : dots color = 4 : dark blue */
- /* newline = 8 : dot-dash color = 5 : purple */
- /* newline = 9 : 3-dash color = 6 : light blue */
- /* newline = 10 : 3-dash color = 7 : white */
- /* newline = 11 : point plot */
- }
-
- /* end procedures - reset the terminal */
- endgrhp()
- {
- /* Turn off graphics text mode */
- printf("%c*dt\n",esc);
-
- printf("%c*delt %c*m1b7xZ\n",esc,esc);
- }
-
-