home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / examples / example01.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  2.7 KB  |  113 lines

  1. /* Demonstration program for PLPLOT: */
  2.  
  3. /* Plots three simple functions, each function occupies a separate page */
  4.  
  5. #include "plplot.h"
  6. #include <stdio.h>
  7. #include <math.h>
  8.  
  9. static PLFLT xs[6] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
  10. static PLFLT ys[6] = {1.0, 4.0, 9.0, 16.0, 25.0, 36.0};
  11.  
  12. main()
  13. {
  14.   /* Declare these static to reduce required stack size */
  15.   static PLFLT x[101], y[101];
  16.   PLINT space0 = 0, mark0 = 0, space1 = 1500, mark1 =1500;
  17.  
  18.   PLINT i;
  19.  
  20.   /* Ask user to specify the output device */
  21.   plstar(1,1);
  22.  
  23.   /* Set up the viewport and window using PLENV. The range in X is */
  24.   /* 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are */
  25.   /* scaled separately (just = 0), and we just draw a labelled */
  26.   /* box (axis = 0). */
  27.  
  28.   plenv((PLFLT)0.0,(PLFLT)6.0,(PLFLT)0.0,(PLFLT)30.0,0,0);
  29.   plcol(2);
  30.   pllab("(x)","(y)","#frPLPLOT Example 1 - y=x#u2");
  31.  
  32.   /* Plot the data points */
  33.  
  34.   plcol(3);
  35.   plpoin(6,xs,ys,9);
  36.  
  37.   for (i=0; i<60; i++) {
  38.      x[i]=0.1*(i+1);
  39.      y[i]= pow(x[i],2.);
  40.   }
  41.  
  42.   /* Draw the line through the data */
  43.  
  44.   plcol(4);
  45.   plline(60,x,y);
  46.  
  47.   /*===============================================================*/
  48.  
  49.   /* Set up the viewport and window using PLENV. The range in X is
  50.      -2.0 to 10.0, and the range in Y is -0.4 to 2.0. The axes are
  51.      scaled separately (just = 0), and we draw a box with axes
  52.      (axis = 1). */
  53.  
  54.   plcol(1);
  55.   plenv((PLFLT)-2.0,(PLFLT)10.0,(PLFLT)-0.4,(PLFLT)1.2,0,1);
  56.   plcol(2);
  57.   pllab("(x)","sin(x)/x","#frPLPLOT Example 1 - Sinc Function");
  58.  
  59.   /* Fill up the arrays */
  60.  
  61.   for (i=0; i<100; i++) {
  62.      x[i] = (i-19.0)/6.0;
  63.      y[i] = 1.0;
  64.      if (x[i] != 0.0) y[i] = sin(x[i])/x[i];
  65.   }
  66.  
  67.   /* Draw the line */
  68.  
  69.   plcol(3);
  70.   plline(100,x,y);
  71.  
  72.   /*===============================================================*/
  73.  
  74.   /* For the final graph we wish to override the default tick intervals,
  75.      and so do not use PLENV */
  76.  
  77.   pladv(0);
  78.  
  79.   /* Use standard viewport, and define X range from 0 to 360 degrees,
  80.      Y range from -1.2 to 1.2. */
  81.  
  82.   plvsta();
  83.   plwind((PLFLT)0.0,(PLFLT)360.0,(PLFLT)-1.2,(PLFLT)1.2);
  84.  
  85.   /* Draw a box with ticks spaced 30 degrees apart in X, and 0.2 in Y. */
  86.  
  87.   plcol(1);
  88.   plbox("bcnst",(PLFLT)30.0,3,"bcnstv",(PLFLT)0.2,2);
  89.  
  90.   /* Superimpose a dashed line grid, with 1.5 mm marks and spaces.
  91.      plstyl expects a pointer!! */
  92.  
  93.   plstyl(1,&mark1,&space1);
  94.   plcol(2);
  95.   plbox("g",(PLFLT)30.0,3,"g",(PLFLT)0.2,2);
  96.   plstyl(0,&mark0,&space0);
  97.  
  98.   plcol(3);
  99.   pllab("Angle (degrees)","sine","#frPLPLOT Example 1 - Sine function");
  100.  
  101.   for (i=0; i<101; i++ ) {
  102.      x[i] = 3.6 * i;
  103.      y[i] = sin(x[i]*3.141592654/180.0);
  104.   }
  105.  
  106.   plcol(4);
  107.   plline(101,x,y);
  108.  
  109.   /* Don't forget to call PLEND to finish off! */
  110.  
  111.   plend();
  112. }
  113.