Exemplo n.º 1
0
void
plot2(void)
{
    int i;

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

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

    plcol0(3);
    plline(100, x, y);
    plflush();
}
Exemplo n.º 2
0
static void plstrip_legend(PLStrip *mystripc, int first)
{
    int i;
    PLFLT sc, dy;

/* draw legend */

    plgchr(&sc, &dy);
    sc = dy = dy/100;
    plwind(-0.01, 1.01, -0.01, 1.01);
    for (i=0; i<PEN; i++) {
	if (mystripc->npts[i] || first) {
	    plcol(mystripc->colline[i]);
	    pllsty(mystripc->styline[i]);
	    pljoin(mystripc->xlpos, mystripc->ylpos - sc,
		   mystripc->xlpos + 0.1, mystripc->ylpos - sc);
	    plcol(mystripc->collab);
	    plptex(mystripc->xlpos + 0.11, mystripc->ylpos - sc,
		   0., 0., 0, mystripc->legline[i]);
	    sc += dy;
	}
    }
    plwind(mystripc->xmin, mystripc->xmax, mystripc->ymin, mystripc->ymax);
    plflush();
}
Exemplo n.º 3
0
int   myplotCmd( ClientData cd, Tcl_Interp *interp, int argc, char **argv )
{
    if (!strcmp(argv[1],"1"))
      myplot1();

    if (!strcmp(argv[1],"2"))
      myplot2();

    if (!strcmp(argv[1],"3"))
      myplot3();

    if (!strcmp(argv[1],"4"))
      shade();

    plflush();
    return TCL_OK;
}
Exemplo n.º 4
0
int   myplotCmd( ClientData PL_UNUSED( cd ), Tcl_Interp *PL_UNUSED( interp ), int PL_UNUSED( argc ), char **argv )
{
    if ( !strcmp( argv[1], "1" ) )
        myplot1();

    if ( !strcmp( argv[1], "2" ) )
        myplot2();

    if ( !strcmp( argv[1], "3" ) )
        myplot3();

    if ( !strcmp( argv[1], "4" ) )
        shade();

    plflush();
    return TCL_OK;
}
Exemplo n.º 5
0
void
plot1(void)
{
    int i;
    PLFLT xmin, xmax, ymin, ymax;

    for (i = 0; i < 60; i++) {
	x[i] = xoff + xscale * (i + 1) / 60.0;
	y[i] = yoff + yscale * pow(x[i], 2.);
    }

    xmin = x[0];
    xmax = x[59];
    ymin = y[0];
    ymax = y[59];

    for (i = 0; i < 6; i++) {
	xs[i] = x[i * 10 + 3];
	ys[i] = y[i * 10 + 3];
    }

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

    plcol0(1);
    plenv(xmin, xmax, ymin, ymax, 0, 0);
    plcol0(6);
    pllab("(x)", "(y)", "#frPLplot Example 1 - y=x#u2");

/* Plot the data points */

    plcol0(9);
    plpoin(6, xs, ys, 9);

/* Draw the line through the data */

    plcol0(4);
    plline(60, x, y);
    plflush();
}
Exemplo n.º 6
0
void
plot3(void)
{
    int i;

/* 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 60 degrees apart in X, and 0.2 in Y. */

    plcol0(1);
    plbox("bcnst", 60.0, 2, "bcnstv", 0.2, 2);

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

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

    plcol0(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] * PI / 180.0);
    }

    plcol0(4);
    plline(101, x, y);
    plflush();
}
Exemplo n.º 7
0
void
plot5(void)
{
    int i, j;
    PLFLT xx, yy;
    PLFLT **z, **w;
    static PLINT mark = 1500, space = 1500;

/* Set up function arrays */

    plAlloc2dGrid(&z, XPTS, YPTS);
    plAlloc2dGrid(&w, XPTS, YPTS);

    for (i = 0; i < XPTS; i++) {
	xx = (double) (i - (XPTS / 2)) / (double) (XPTS / 2);
	for (j = 0; j < YPTS; j++) {
	    yy = (double) (j - (YPTS / 2)) / (double) (YPTS / 2) - 1.0;
	    z[i][j] = xx * xx - yy * yy;
	    w[i][j] = 2 * xx * yy;
	}
    }

    plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
    plcol0(2);
    plcont(z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL);
    plstyl(1, &mark, &space);
    plcol0(3);
    plcont(w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL);
    plcol0(1);
    pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
    plflush();

/* Clean up */
    plFree2dGrid(z, XPTS, YPTS);
    plFree2dGrid(w, XPTS, YPTS);

}
Exemplo n.º 8
0
void
plot1( int do_test )
{
    int   i;
    PLFLT xmin, xmax, ymin, ymax;

    for ( i = 0; i < 60; i++ )
    {
        x[i] = xoff + xscale * ( i + 1 ) / 60.0;
        y[i] = yoff + yscale * pow( x[i], 2. );
    }

    xmin = x[0];
    xmax = x[59];
    ymin = y[0];
    ymax = y[59];

    for ( i = 0; i < 6; i++ )
    {
        xs[i] = x[i * 10 + 3];
        ys[i] = y[i * 10 + 3];
    }

// 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).
//
    plcol0( 1 );
    plenv( xmin, xmax, ymin, ymax, 0, 0 );
    plcol0( 2 );
    pllab( "(x)", "(y)", "#frPLplot Example 1 - y=x#u2" );

// Plot the data points

    plcol0( 4 );
    plpoin( 6, xs, ys, 9 );

// Draw the line through the data

    plcol0( 3 );
    plline( 60, x, y );

// xor mode enable erasing a line/point/text by replotting it again
// it does not work in double buffering mode, however

    if ( do_test && test_xor )
    {
#ifdef PL_HAVE_NANOSLEEP
        PLINT           st;
        struct timespec ts;
        ts.tv_sec  = 0;
        ts.tv_nsec = 50000000;
        plxormod( 1, &st ); // enter xor mode
        if ( st )
        {
            for ( i = 0; i < 60; i++ )
            {
                plpoin( 1, x + i, y + i, 9 );   // draw a point
                nanosleep( &ts, NULL );         // wait a little
                plflush();                      // force an update of the tk driver
                plpoin( 1, x + i, y + i, 9 );   // erase point
            }
            plxormod( 0, &st );                 // leave xor mode
        }
#else
        printf( "The -xor command line option can only be exercised if your "
            "system\nhas nanosleep(), which does not seem to happen.\n" );
#endif
    }
}
Exemplo n.º 9
0
void c_plstripa( PLINT id, PLINT p, PLFLT x, PLFLT y )
{
    int j, yasc=0, istart;

    if (p >= PEN) {
    	plabort("Non existent pen");
    	return;
    }

    if ((id < 0) || (id >= MAX_STRIPC) ||
	((stripc = strip[id]) == NULL)) {
    	plabort("Non existent stripchart");
    	return;
    }

/* Add new point, allocating memory if necessary */

    if (++stripc->npts[p] > stripc->nptsmax[p]) {
	stripc->nptsmax[p] += 32;
	stripc->x[p] = (PLFLT *) realloc((void *) stripc->x[p], sizeof(PLFLT)*stripc->nptsmax[p]);
	stripc->y[p] = (PLFLT *) realloc((void *) stripc->y[p], sizeof(PLFLT)*stripc->nptsmax[p]);
	if (stripc->x[p] == NULL || stripc->y[p] == NULL) {
	    plabort("plstripc: Out of memory.");
	    plstripd(id);
	    return;
	}
    }

    stripc->x[p][stripc->npts[p]-1] = x;
    stripc->y[p][stripc->npts[p]-1] = y;

    stripc->xmax = x;

    if (stripc->y_ascl == 1 && (y > stripc->ymax || y < stripc->ymin))
	yasc=1;

    if (y > stripc->ymax)
	stripc->ymax = stripc->ymin + 1.1*(y - stripc->ymin);
	if (y < stripc->ymin)
	  stripc->ymin = stripc->ymax - 1.1*(stripc->ymax - y);

/* Now either plot new point or regenerate plot */

        if (stripc->xmax - stripc->xmin < stripc->xlen) {
            if( yasc == 0) {

            /* If user has changed subwindow, make shure we have the correct one */
                plvsta();
                plwind(stripc->wxmin, stripc->wxmax, stripc->wymin, stripc->wymax); /* FIXME - can exist some redundancy here */
		plcol(stripc->colline[p]); pllsty(stripc->styline[p]);
		if ((stripc->npts[p]-2) < 0)
		  plP_movwor(stripc->x[p][stripc->npts[p]-1], stripc->y[p][stripc->npts[p]-1]);
		else
		  plP_movwor(stripc->x[p][stripc->npts[p]-2], stripc->y[p][stripc->npts[p]-2]);
		plP_drawor(stripc->x[p][stripc->npts[p]-1], stripc->y[p][stripc->npts[p]-1]);
		plflush();
            }
            else {
		stripc->xmax = stripc->xmin + stripc->xlen;
                plstrip_gen(stripc);
	    }
	}
    else {
/* Regenerating plot */
	if (stripc->acc == 0) {
	    for (j=0; j<PEN; j++) {
		if (stripc->npts[j] > 0) {
		    istart = 0;
		    while (stripc->x[j][istart] < stripc->xmin + stripc->xlen*stripc->xjump)
			istart++;

		    stripc->npts[j] = stripc->npts[j] - istart;
		    memcpy( &stripc->x[j][0], &stripc->x[j][istart], (stripc->npts[j])*sizeof(PLFLT));
		    memcpy( &stripc->y[j][0], &stripc->y[j][istart], (stripc->npts[j])*sizeof(PLFLT));
		}
	    }
	} else
	    stripc->xlen = stripc->xlen * (1 + stripc->xjump);

	stripc->xmin = stripc->x[p][0];
	stripc->xmax = stripc->xmax + stripc->xlen*stripc->xjump;

	plstrip_gen(stripc);
    }
}
Exemplo n.º 10
0
nemo_main()
{
    int i, j, np;
    string name, dumpfile;

    name = getparam("name");
    dumpfile = getparam("screendump");
    np = getiparam("pages");
    printf("Testing wth pages=%d\n",np);
    plinit(name, 0.0, 20.0, 0.0, 20.0);     /* open device */
    x_init_plobj();
    plmove(0.0, 0.0);
    plcolor(0);
    plline(20.0, 0.0);
    plcolor(1);
    plline(20.0, 20.0);
    plcolor(2);
    plline(0.0, 20.0);
    plcolor(3);
    plline(0.0, 0.0);
    plcolor(4);
    plline(20.0, 20.0);
    plmove(20.0, 0.0);
    plcolor(5);
    plline(0.0, 20.0);
    plltype(12, 0);
    plmove(4.0, 18.0);
    plcolor(6);
    plline(16.0, 18.0);
    plltype(-6, 0);
    plmove(6.0, 18.0);
    plcolor(7);
    plline(14.0, 18.0);
    
    for (i = 1; i <= 4; i++) {
	plcolor(8+i);
	plltype(i, 1);
        plmove(1.0, 13.0 - i);
        plline(3.0, 13.0 - i);
        plpoint(3.5, 13.0 - i);
	plltype(1, i);
	for (j = 1; j <= 4; j++) {
	    plmove(1.5, 13.0 - i - 0.2*j);
	    plline(1.5 + j, 13.0 - i - 0.2*j);
	}
    }
    plcolor(12);
    plltype(1, 1);
    plcircle(15.0, 9.0, -0.5);
    plcolor(13);
    plcircle(16.0, 9.0, 0.25);
    plcolor(14);
    plcircle(17.0, 9.0, 0.125);
    plcolor(15);
    plcircle(18.0, 9.0, 0.0625);
    plbox(16.0, 8.0, 0.4);
    plbox(17.0, 8.0, 0.2);
    plbox(18.0, 8.0, -0.2);
    plcross(16.0, 7.0, 0.4);
    plcross(17.0, 7.0, 0.2);
    plcross(18.0, 7.0, -0.2);
    plcolor(4);
    pltext("Foo Bar!", 8.0, 5.0, 0.5, 0.0);
    plcolor(5);
    pltext("Fum Bar!", 8.0, 3.0, 0.25, 0.0);
    plcolor(6);
    for (i = 0; i <= 4; i++)
	pltext(" testing angles", 16.0, 10.0, 0.2, 45.0*i);
    plmove(10.0, 8.5);
    plline(10.0, 11.5);
    pljust(-1);
    plcolor(3);
    pltext("left justified",  10.0,  9.0, 0.25, 0.0);
    plcolor(2);
    pljust(0);
    pltext("centered",        10.0, 10.0, 0.25, 0.0);
    plcolor(1);
    pljust(1);
    pltext("right justified", 10.0, 11.0, 0.25, 0.0);
    pljust(0);
    plcolor(7);
    pltext(getparam("headline"),10.0, 19.0, 0.5, 0.0);
    plcolor(1);
    plflush();
    if (*dumpfile)
        pl_screendump(dumpfile);
    if (np>1) {
        plflush();
        plframe();
        plmove(0.0, 0.0);
        plline(20.0, 0.0);
        plline(20.0, 20.0);
        plline(0.0, 20.0);
        plline(0.0, 0.0);

        pljust(0);
        pltext("This is page 2", 10.0,10.0,0.25,0.0);

#define IMAX 100
#define ISTEP 20.0/IMAX

        plmove (0.0,0.0);
        for (i=0; i<IMAX; i++)
           plline(i*ISTEP, i*ISTEP);
    }
    plstop();
}
Exemplo n.º 11
0
void
plot4(void)
{
    int i, j;
    PLFLT dtr, theta, dx, dy, r;
    char text[3];
    PLFLT x0[361], y0[361];
    PLFLT x[361], y[361];

    dtr = PI / 180.0;
    for (i = 0; i <= 360; i++) {
	x0[i] = cos(dtr * i);
	y0[i] = sin(dtr * i);
    }

/* Set up viewport and window, but do not draw box */

    plenv(-1.3, 1.3, -1.3, 1.3, 1, -2);
    for (i = 1; i <= 10; i++) {
	for (j = 0; j <= 360; j++) {
	    x[j] = 0.1 * i * x0[j];
	    y[j] = 0.1 * i * y0[j];
	}

/* Draw circles for polar grid */

	plline(361, x, y);
    }

    plcol0(2);
    for (i = 0; i <= 11; i++) {
	theta = 30.0 * i;
	dx = cos(dtr * theta);
	dy = sin(dtr * theta);

/* Draw radial spokes for polar grid */

	pljoin(0.0, 0.0, dx, dy);
	sprintf(text, "%d", ROUND(theta));

/* Write labels for angle */

/* Slightly off zero to avoid floating point logic flips at 90 and 270 deg. */
	if (dx >= -0.00001)
	    plptex(dx, dy, dx, dy, -0.15, text);
	else
	    plptex(dx, dy, -dx, -dy, 1.15, text);
    }

/* Draw the graph */

    for (i = 0; i <= 360; i++) {
	r = sin(dtr * (5 * i));
	x[i] = x0[i] * r;
	y[i] = y0[i] * r;
    }
    plcol0(3);
    plline(361, x, y);

    plcol0(4);
    plmtex("t", 2.0, 0.5, 0.5,
	   "#frPLplot Example 3 - r(#gh)=sin 5#gh");
    plflush();
}
Exemplo n.º 12
0
Arquivo: plp.c Projeto: a4a881d4/aloe
int plp_draw(double *signal, int *signal_lengths, int ylog_scale) {
	int count;
	int i,j;
	int col;
	int dowind;

	for (i=0;i<2*NOF_INPUT_ITF;i++) {
		if (signal_lengths[i] > INPUT_MAX_SAMPLES) {
			moderror_msg("plplot buffer configured for %d samples but received %d in signal %d\n",
					INPUT_MAX_SAMPLES,signal_lengths[i],i);
			return -1;
		}
	}

	dowind=0;
	xmax=-1;
	for(i=0;i<2*NOF_INPUT_ITF;i++) {
		if (signal_lengths[i]) {
			dowind=1;
			xmax = (PLFLT) MAX(xmax,signal_lengths[i]);
			for (j=0;j<signal_lengths[i];j++) {
				ymin = (PLFLT) MIN(ymin,signal[i*INPUT_MAX_SAMPLES+j]);
				ymax = (PLFLT) MAX(ymax,signal[i*INPUT_MAX_SAMPLES+j]);
			}
		}
	}

	if (!dowind) {
		xmin=0;
		xmax=100;
		ymin=-1;
		ymax=1;
	}

	plclear();

	plscolbg(255, 255, 255);
	plvsta();
	plwid(1);
	plwind(xmin, xmax, ymin*1.1, ymax*1.1);

	plcol0(1);
	if (ylog_scale) {
		plbox(logaxis_x, 0., 0, logaxis_y, 0., 0);
	} else {
		plbox(axis_x, 0., 0, axis_y, 0., 0);
	}
	plcol0(4);
	plbox("g", 0, 0, "g", 0, 0);
	plcol0(1);
	pllab(xlabel, ylabel, "");

	draw_legend();

	plwid(4);
	col=3;
	for (i=0;i<2*NOF_INPUT_ITF;i++) {
		if (signal_lengths[i]) {
			plcol0(line_colors[i]);
			plline(signal_lengths[i], t, &signal[i*INPUT_MAX_SAMPLES]);
			col++;
			if (col==4) col++;
		}
	}

	plflush();                      // force an update of the tk driver

}