home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_10_11
/
1011124a
< prev
next >
Wrap
Text File
|
1992-09-08
|
4KB
|
79 lines
/**************************************************************************
* SAMPPLOT.C - Sample driver program for the splot plotting function.
*
* Developed in Borland C++. To compile: BCC SAMPPLOT.C PLOTS.C (small model)
*
* splot may be included in application programs which require hard copy
* graphic output to eliminate the additional step of using a separate
* plotting program. This code compiles in the small model with about 14K
* core to spare. The splot function can be used without modification with
* the compact or large model if required by the application.
*
* Lowell Smith
* 3368 Crestwood Drive
* Salt Lake City, UT 84109-3202
*************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <math.h>
#define PI 3.14159265358979
void main()
{ /* Max of 5 curves per graph and max of 3 strings in the message box */
int i,j,totpoints[5],numpoints[5],nmsg[3];
char title[81],xaxis[81],yaxis[81],*msg[5],msgspace[5][81];
double *xplt[5],*yplt[5],dx,x,xpltspace[5][300],ypltspace[5][300];
FILE *pstfile, *hpfile; /* file pointers */
void splot(FILE* pstfil, FILE *hpfile, int xdivs, int ydivs, int xgrid,
int ygrid, int nplots, double *x[], double *y[], int *npts_pnts,int *npts_tot,
char *title, char *xaxis, char *yaxis,char *msg[], int *nmsg);
/* In lieu of malloc */
for (i=0; i<5; ++i) { msg[i]=msgspace[i]; xplt[i]=xpltspace[i]; yplt[i]=ypltspace[i]; }
/* We first make a graph with a circle and an ellipse with no symbols, with
* no message box, and with both PostScript and HP LaserJet output files
*/
if ((pstfile=fopen("splot1.ps","w"))==NULL) { printf("Couldn't open pstfile\n"); exit(0); }
/* Be sure to make the .PCL file binary */
if ((hpfile=fopen("splot1.pcl","wb"))==NULL) { printf("Couldn't open hpfile\n"); exit(0); }
dx=2.*PI/200.; x=0.;
for (i=0; i<201; ++i)
{ x+=dx; xplt[0][i]=sin(x)*1.75/1.33333; yplt[0][i]=cos(x)*1.75;
xplt[1][i]=sin(x)*1.75/1.33333; yplt[1][i]=cos(x)*.75;
}
nmsg[0]=0; numpoints[0]=numpoints[1]=0; totpoints[0]=totpoints[1]=201;
strcpy(xaxis,"X / Aspect Ratio (1.33333)"); strcpy(yaxis,"Y");
strcpy(title,"A Circle and an Ellipse");
splot(pstfile,hpfile,2,2,1,1,2,xplt,yplt,numpoints,totpoints,title,xaxis,yaxis,
msg,nmsg);
/* Two parabolas, one with connecting lines, one with symbols. PS file only. */
if ((pstfile=fopen("splot2.ps","w"))==NULL) { printf("Couldn't open pstfile\n"); exit(0); }
hpfile=NULL;
numpoints[0]=0; totpoints[0]=101; numpoints[1]=17; totpoints[1]=154;
strcpy(xaxis,"X"); strcpy(yaxis,"Y"); strcpy(title,"Two Parabolas");
for (i=0; i<101; ++i) { x=xplt[0][i]=(double)i/10.-5.; yplt[0][i]=.2*x*x; }
for (i=0; i<17; ++i) { x=xplt[1][i]=(double)i/2.-4.; yplt[1][i]=.5*x*x; }
for (i=0; i<137; ++i) { x=xplt[1][i+17]=(double)i/17.-4.; yplt[1][i+17]=.5*x*x; }
splot(pstfile,hpfile,10,10,0,0,2,xplt,yplt,numpoints,totpoints,title,xaxis,yaxis,
msg,nmsg);
/* An illustration of the symbols and large numbers. Postscript file only. */
if ((pstfile=fopen("splot3.ps","w"))==NULL) { printf("Couldn't open pstfile\n"); exit(0); }
strcpy(title,"Illustrating the Selection of Symbols");
strcpy(xaxis,"X (Values should have been scaled)");
strcpy(yaxis,"Y (Values should have been scaled)");
strcpy(msg[0],"After the fourth curve"); strcpy(msg[1],"the symbols repeat");
nmsg[0]=2; nmsg[1]=370; nmsg[2]=130;
numpoints[0]=numpoints[1]=numpoints[2]=numpoints[3]=numpoints[4]=3;
totpoints[0]=totpoints[1]=totpoints[2]=totpoints[3]=totpoints[4]=6;
for(i=0; i<5; ++i) for(j=0; j<3; ++j)
{ xplt[i][j]=xplt[i][j+3]=(i*.25+j)*1e9; yplt[i][j]=yplt[i][j+3]=(i*.25-j)*1e5; }
splot(pstfile,hpfile,3,3,1,1,5,xplt,yplt,numpoints,totpoints,title,xaxis,yaxis,
msg,nmsg);
} /* end main driver */
WRAP_EOF