/* Demonstration program for PLPLOT: */

/* Plots three simple functions, each function occupies a separate page */

#include <stdio.h>
#include <math.h>

static float xs[6] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
static float ys[6] = {1.0, 4.0, 9.0, 16.0, 25.0, 36.0};
static int space0 = 0;
static int mark0 = 0;
static int space1 = 1500;
static int mark1 =1500;

main()
{
      int i;
      float x[101], y[101];

/* Ask user to specify the output device */

      plstar(1,1);

/* Set up the viewport and window using PLENV. The range in X is */
/* 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are */
/* scaled separately (just = 0), and we just draw a labelled */
/* box (axis = 0). */

      plenv(0.0,6.0,0.0,30.0,0,0);
      pllab("(x)","(y)","\\frPLPLOT Example 1 - y=x\\u2");

/* Plot the data points */

      plpoin(6,xs,ys,9);

      for (i=0; i<60; i++) {
        x[i]=0.1*(i+1);
        y[i]= pow(x[i],2.);
      }

/* Draw the line through the data */

      plline(60,x,y);

/*======================================================================*/

/* Set up the viewport and window using PLENV. The range in X is */
/*  -2.0 to 10.0, and the range in Y is -0.4 to 2.0. The axes are */
/*  scaled separately (just = 0), and we draw a box with axes */
/*  (axis = 1). */

      plenv(-2.0,10.0,-0.4,1.2,0,1);
      pllab("(x)","sin(x)/x","\\frPLPLOT Example 1 - Sinc Function");

/* Fill up the arrays */

      for (i=0; i<100; i++) {
        x[i] = (i-19.0)/6.0;
        y[i] = 1.0;
        if (x[i] != 0.0) y[i] = sin(x[i])/x[i];
      }

/* Draw the line */

      plline(100,x,y);

/*======================================================================*/

/* For the final graph we wish to override the default tick intervals, */
/* and so do not use PLENV */

      pladv(0);

/* Use standard viewport, and define X range from 0 to 360 degrees, */
/* Y range from -1.2 to 1.2. */

      plvsta();
      plwind(0.0,360.0,-1.2,1.2);

/* Draw a box with ticks spaced 30 degrees apart in X, and 0.2 in Y. */

      plbox("bcnst",30.0,3,"bcnstv",0.2,2);

/* Superimpose a dashed line grid, with 1.5 mm marks and spaces. */
/* plstyl expects a pointer!! */

      plstyl(1,&mark1,&space1);
      plbox("g",30.0,3,"g",0.2,2);
      plstyl(0,&mark0,&space0);

      pllab("Angle (degrees)","sine","\\frPLPLOT Example 1 - Sine function");

      for (i=0; i<101; i++ ) {
        x[i] = 3.6 * i;
        y[i] = sin(x[i]*3.141592654/180.0);
      }

      plline(101,x,y);

/* Don't forget to call PLEND to finish off! */

      plend();
}
