home *** CD-ROM | disk | FTP | other *** search
- /* Demonstration program for PLPLOT: */
-
- /* Plots three simple functions, each function occupies a separate page */
-
- #include "plplot.h"
- #include <stdio.h>
- #include <math.h>
-
- static PLFLT xs[6] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
- static PLFLT ys[6] = {1.0, 4.0, 9.0, 16.0, 25.0, 36.0};
-
- main()
- {
- /* Declare these static to reduce required stack size */
- static PLFLT x[101], y[101];
- PLINT space0 = 0, mark0 = 0, space1 = 1500, mark1 =1500;
-
- PLINT 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((PLFLT)0.0,(PLFLT)6.0,(PLFLT)0.0,(PLFLT)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);
-
- /*===============================================================*/
-
- /* 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((PLFLT)-2.0,(PLFLT)10.0,(PLFLT)-0.4,(PLFLT)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);
-
- /*===============================================================*/
-
- /* 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((PLFLT)0.0,(PLFLT)360.0,(PLFLT)-1.2,(PLFLT)1.2);
-
- /* Draw a box with ticks spaced 30 degrees apart in X, and 0.2 in Y. */
-
- plcol(1);
- plbox("bcnst",(PLFLT)30.0,3,"bcnstv",(PLFLT)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",(PLFLT)30.0,3,"g",(PLFLT)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();
- }
-