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 >
Text File  |  1992-09-08  |  4KB  |  79 lines

  1.  
  2. /**************************************************************************
  3.  * SAMPPLOT.C - Sample driver program for the splot plotting function.
  4.  *
  5.  * Developed in Borland C++. To compile: BCC SAMPPLOT.C PLOTS.C (small model)
  6.  *
  7.  * splot  may be included in application programs which require hard copy
  8.  * graphic output to eliminate the additional step of using a separate
  9.  * plotting program. This code compiles in the small model with about 14K
  10.  * core to spare. The splot function can be used without modification with
  11.  * the compact or large model if required by the application.
  12.  *
  13.  *  Lowell Smith
  14.  *  3368 Crestwood Drive
  15.  *  Salt Lake City, UT 84109-3202
  16.  *************************************************************************/
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <conio.h>
  21. #include <math.h>
  22. #define PI 3.14159265358979
  23. void main()
  24. { /* Max of 5 curves per graph and max of 3 strings in the message box */
  25.   int i,j,totpoints[5],numpoints[5],nmsg[3];
  26.   char title[81],xaxis[81],yaxis[81],*msg[5],msgspace[5][81];
  27.   double *xplt[5],*yplt[5],dx,x,xpltspace[5][300],ypltspace[5][300];
  28.   FILE  *pstfile, *hpfile;                /* file pointers */
  29.   void splot(FILE* pstfil, FILE *hpfile, int xdivs, int ydivs, int xgrid,
  30.       int ygrid, int nplots, double *x[], double *y[], int *npts_pnts,int *npts_tot,
  31.       char *title, char *xaxis, char *yaxis,char *msg[], int *nmsg);
  32.  
  33. /* In lieu of malloc */
  34.   for (i=0; i<5; ++i) { msg[i]=msgspace[i]; xplt[i]=xpltspace[i]; yplt[i]=ypltspace[i]; }
  35.  
  36. /* We first make a graph with a circle and an ellipse with no symbols, with
  37.  * no message box, and with both PostScript and HP LaserJet output files
  38.  */
  39.   if ((pstfile=fopen("splot1.ps","w"))==NULL) { printf("Couldn't open pstfile\n"); exit(0); }
  40. /* Be sure to make the .PCL file binary */
  41.   if ((hpfile=fopen("splot1.pcl","wb"))==NULL) { printf("Couldn't open hpfile\n"); exit(0); }
  42.   dx=2.*PI/200.;  x=0.;
  43.   for (i=0; i<201; ++i)
  44.   { x+=dx; xplt[0][i]=sin(x)*1.75/1.33333; yplt[0][i]=cos(x)*1.75;
  45.     xplt[1][i]=sin(x)*1.75/1.33333; yplt[1][i]=cos(x)*.75;
  46.   }
  47.   nmsg[0]=0; numpoints[0]=numpoints[1]=0; totpoints[0]=totpoints[1]=201;
  48.   strcpy(xaxis,"X / Aspect Ratio (1.33333)"); strcpy(yaxis,"Y");
  49.   strcpy(title,"A Circle and an Ellipse");
  50.   splot(pstfile,hpfile,2,2,1,1,2,xplt,yplt,numpoints,totpoints,title,xaxis,yaxis,
  51.                 msg,nmsg);
  52.  
  53. /* Two parabolas, one with connecting lines, one with symbols. PS file only. */
  54.   if ((pstfile=fopen("splot2.ps","w"))==NULL) { printf("Couldn't open pstfile\n"); exit(0); }
  55.   hpfile=NULL;
  56.   numpoints[0]=0; totpoints[0]=101; numpoints[1]=17; totpoints[1]=154;
  57.   strcpy(xaxis,"X"); strcpy(yaxis,"Y"); strcpy(title,"Two Parabolas");
  58.   for (i=0; i<101; ++i) { x=xplt[0][i]=(double)i/10.-5.; yplt[0][i]=.2*x*x; }
  59.   for (i=0; i<17; ++i) { x=xplt[1][i]=(double)i/2.-4.; yplt[1][i]=.5*x*x; }
  60.   for (i=0; i<137; ++i) { x=xplt[1][i+17]=(double)i/17.-4.; yplt[1][i+17]=.5*x*x; }
  61.   splot(pstfile,hpfile,10,10,0,0,2,xplt,yplt,numpoints,totpoints,title,xaxis,yaxis,
  62.                 msg,nmsg);
  63.  
  64. /* An illustration of the symbols and large numbers. Postscript file only. */
  65.   if ((pstfile=fopen("splot3.ps","w"))==NULL) { printf("Couldn't open pstfile\n"); exit(0); }
  66.   strcpy(title,"Illustrating the Selection of Symbols");
  67.   strcpy(xaxis,"X (Values should have been scaled)");
  68.   strcpy(yaxis,"Y (Values should have been scaled)");
  69.   strcpy(msg[0],"After the fourth curve");  strcpy(msg[1],"the symbols repeat");
  70.   nmsg[0]=2; nmsg[1]=370; nmsg[2]=130;
  71.   numpoints[0]=numpoints[1]=numpoints[2]=numpoints[3]=numpoints[4]=3;
  72.   totpoints[0]=totpoints[1]=totpoints[2]=totpoints[3]=totpoints[4]=6;
  73.   for(i=0; i<5; ++i) for(j=0; j<3; ++j)
  74.         { xplt[i][j]=xplt[i][j+3]=(i*.25+j)*1e9; yplt[i][j]=yplt[i][j+3]=(i*.25-j)*1e5; }
  75.   splot(pstfile,hpfile,3,3,1,1,5,xplt,yplt,numpoints,totpoints,title,xaxis,yaxis,
  76.                 msg,nmsg);
  77. } /* end main driver */
  78. WRAP_EOF
  79.