ftp.nice.ch/pub/next/unix/developer/plplot.3.0.s.tar.gz#/plplot/examples/example01.c

This is example01.c in view mode; [Download] [Up]

/* 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};


main()
{
  /* Declare these static to reduce required stack size */
  static FLOAT x[101], y[101];
  int space0 = 0, mark0 = 0, space1 = 1500, mark1 =1500;
  int i;

  /* 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);
  plcol(2);
  pllab("(x)","(y)","#frPLPLOT Example 1 - y=x#u2");

  /* Plot the data points */

  plcol(3);
  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 */

  plcol(4);
  plline(60,x,y);

  pleop();    /* end page */
  /*===============================================================*/

  /* 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). */

  plcol(1);
  plenv(-2.0,10.0,-0.4,1.2,0,1);
  plcol(2);
  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 */

  plcol(3);
  plline(100,x,y);

  pleop();    /* end page */
  /*===============================================================*/

  /* 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. */

  plcol(1);
  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);
  plcol(2);
  plbox("g",30.0,3,"g",0.2,2);
  plstyl(0,&mark0,&space0);

  plcol(3);
  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);
  }

  plcol(4);
  plline(101,x,y);

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

  plend();
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.