Exemplo n.º 1
0
void
plot3( void )
{
    PLINT space0 = 0, mark0 = 0, space1 = 1500, mark1 = 1500;
    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] * M_PI / 180.0 );
    }

    plcol0( 4 );
    plline( 101, x, y );
}
Exemplo n.º 2
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( (PLFLT) 0.0, (PLFLT) 360.0, (PLFLT) -1.2, (PLFLT) 1.2 );

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

    plcol0( 1 );
    plbox( "bcnst", (PLFLT) 60.0, 2, "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 );
    plcol0( 2 );
    plbox( "g", (PLFLT) 30.0, 0, "g", (PLFLT) 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] * 3.141592654 / 180.0 );
    }

    plcol0( 4 );
    plline( 101, x, y );
}
Exemplo n.º 3
0
void
c_pllsty(PLINT lin)
{
    if (plsc->level < 1) {
	plabort("pllsty: Please call plinit first");
	return;
    }
    if (lin < 1 || lin > 8) {
	plabort("pllsty: Invalid line style");
	return;
    }

    plstyl(line[lin - 1].nels,
	   &line[lin - 1].mark[0], &line[lin - 1].space[0]);
}
Exemplo n.º 4
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.º 5
0
int
main( int argc, const char *argv[] )
{
    int          i, j;
    PLFLT        xx, yy, argx, argy, distort;
    static PLINT mark = 1500, space = 1500;

    PLFLT        **z, **w;
    PLFLT        xg1[XPTS], yg1[YPTS];
    PLcGrid      cgrid1;
    PLcGrid2     cgrid2;

// Parse and process command line arguments

    (void) plparseopts( &argc, argv, PL_PARSE_FULL );

// Initialize plplot

    plinit();

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

// Set up grids

    cgrid1.xg = xg1;
    cgrid1.yg = yg1;
    cgrid1.nx = XPTS;
    cgrid1.ny = YPTS;

    plAlloc2dGrid( &cgrid2.xg, XPTS, YPTS );
    plAlloc2dGrid( &cgrid2.yg, XPTS, YPTS );
    cgrid2.nx = XPTS;
    cgrid2.ny = YPTS;

    for ( i = 0; i < XPTS; i++ )
    {
        for ( j = 0; j < YPTS; j++ )
        {
            mypltr( (PLFLT) i, (PLFLT) j, &xx, &yy, NULL );

            argx    = xx * M_PI / 2;
            argy    = yy * M_PI / 2;
            distort = 0.4;

            cgrid1.xg[i] = xx + distort * cos( argx );
            cgrid1.yg[j] = yy - distort * cos( argy );

            cgrid2.xg[i][j] = xx + distort * cos( argx ) * cos( argy );
            cgrid2.yg[i][j] = yy - distort * cos( argx ) * cos( argy );
        }
    }

// Plot using identity transform
//
//  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);
//  plstyl(0, &mark, &space);
//  plcol0(1);
//  pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
//
    pl_setcontlabelformat( 4, 3 );
    pl_setcontlabelparam( 0.006, 0.3, 0.1, 1 );
    plenv( -1.0, 1.0, -1.0, 1.0, 0, 0 );
    plcol0( 2 );
    plcont( (const PLFLT * const *) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL );
    plstyl( 1, &mark, &space );
    plcol0( 3 );
    plcont( (const PLFLT * const *) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL );
    plstyl( 0, &mark, &space );
    plcol0( 1 );
    pllab( "X Coordinate", "Y Coordinate", "Streamlines of flow" );
    pl_setcontlabelparam( 0.006, 0.3, 0.1, 0 );

// Plot using 1d coordinate transform

    plenv( -1.0, 1.0, -1.0, 1.0, 0, 0 );
    plcol0( 2 );
    plcont( (const PLFLT * const *) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
        pltr1, (void *) &cgrid1 );

    plstyl( 1, &mark, &space );
    plcol0( 3 );
    plcont( (const PLFLT * const *) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
        pltr1, (void *) &cgrid1 );
    plstyl( 0, &mark, &space );
    plcol0( 1 );
    pllab( "X Coordinate", "Y Coordinate", "Streamlines of flow" );
    //
    // pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
    // plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
    // plcol0(2);
    // plcont((const PLFLT **) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
    //     pltr1, (void *) &cgrid1);
    //
    // plstyl(1, &mark, &space);
    // plcol0(3);
    // plcont((const PLFLT **) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
    //     pltr1, (void *) &cgrid1);
    // plstyl(0, &mark, &space);
    // plcol0(1);
    // pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
    // pl_setcontlabelparam(0.006, 0.3, 0.1, 0);
    //
// Plot using 2d coordinate transform

    plenv( -1.0, 1.0, -1.0, 1.0, 0, 0 );
    plcol0( 2 );
    plcont( (const PLFLT * const *) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
        pltr2, (void *) &cgrid2 );

    plstyl( 1, &mark, &space );
    plcol0( 3 );
    plcont( (const PLFLT * const *) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
        pltr2, (void *) &cgrid2 );
    plstyl( 0, &mark, &space );
    plcol0( 1 );
    pllab( "X Coordinate", "Y Coordinate", "Streamlines of flow" );
    //
    // pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
    // plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
    // plcol0(2);
    // plcont((const PLFLT **) z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
    //     pltr2, (void *) &cgrid2);
    //
    // plstyl(1, &mark, &space);
    // plcol0(3);
    // plcont((const PLFLT **) w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11,
    //     pltr2, (void *) &cgrid2);
    // plstyl(0, &mark, &space);
    // plcol0(1);
    // pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
    //
    pl_setcontlabelparam( 0.006, 0.3, 0.1, 0 );
    polar();
    //
    // pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
    // polar();
    //
    pl_setcontlabelparam( 0.006, 0.3, 0.1, 0 );
    potential();
    //
    // pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
    // potential();
    //

// Clean up

    plFree2dGrid( z, XPTS, YPTS );
    plFree2dGrid( w, XPTS, YPTS );
    plFree2dGrid( cgrid2.xg, XPTS, YPTS );
    plFree2dGrid( cgrid2.yg, XPTS, YPTS );

    plend();

    exit( 0 );
}
Exemplo n.º 6
0
static void
plshade_int( PLFLT ( *f2eval )( PLINT, PLINT, PLPointer ),
             PLPointer f2eval_data,
             PLFLT ( * c2eval )( PLINT, PLINT, PLPointer ), // unused, but macro doesn't work
             PLPointer PL_UNUSED( c2eval_data ),
             PLINT ( *defined )( PLFLT, PLFLT ),
             PLINT nx, PLINT ny,
             PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax,
             PLFLT shade_min, PLFLT shade_max,
             PLINT sh_cmap, PLFLT sh_color, PLFLT sh_width,
             PLINT min_color, PLFLT min_width,
             PLINT max_color, PLFLT max_width,
             void ( *fill )( PLINT, const PLFLT *, const PLFLT * ), PLINT rectangular,
             void ( *pltr )( PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer ),
             PLPointer pltr_data )
{
    PLINT n, slope = 0, ix, iy;
    int   count, i, j, nxny;
    PLFLT *a, *a0, *a1, dx, dy;
    PLFLT x[8], y[8], xp[2], tx, ty, init_width;
    int   *c, *c0, *c1;

    (void) c2eval;   // Cast to void to silence compiler warning about unused parameter

    if ( plsc->level < 3 )
    {
        plabort( "plfshade: window must be set up first" );
        return;
    }

    if ( nx <= 0 || ny <= 0 )
    {
        plabort( "plfshade: nx and ny must be positive" );
        return;
    }

    if ( shade_min >= shade_max )
    {
        plabort( "plfshade: shade_max must exceed shade_min" );
        return;
    }

    if ( pltr == NULL && plsc->coordinate_transform == NULL )
        rectangular = 1;

    int_val    = shade_max - shade_min;
    init_width = plsc->width;

    pen_col_min = min_color;
    pen_col_max = max_color;

    pen_wd_min = min_width;
    pen_wd_max = max_width;

    plstyl( (PLINT) 0, NULL, NULL );
    plwidth( sh_width );
    if ( fill != NULL )
    {
        switch ( sh_cmap )
        {
        case 0:
            plcol0( (PLINT) sh_color );
            break;
        case 1:
            plcol1( sh_color );
            break;
        default:
            plabort( "plfshade: invalid color map selection" );
            return;
        }
    }
    // alloc space for value array, and initialize
    // This is only a temporary kludge
    nxny = nx * ny;
    if ( ( a = (PLFLT *) malloc( (size_t) nxny * sizeof ( PLFLT ) ) ) == NULL )
    {
        plabort( "plfshade: unable to allocate memory for value array" );
        return;
    }

    for ( ix = 0; ix < nx; ix++ )
        for ( iy = 0; iy < ny; iy++ )
            a[iy + ix * ny] = f2eval( ix, iy, f2eval_data );

    // alloc space for condition codes

    if ( ( c = (int *) malloc( (size_t) nxny * sizeof ( int ) ) ) == NULL )
    {
        plabort( "plfshade: unable to allocate memory for condition codes" );
        free( a );
        return;
    }

    sh_min = shade_min;
    sh_max = shade_max;

    set_cond( c, a, nxny );
    dx = ( xmax - xmin ) / ( nx - 1 );
    dy = ( ymax - ymin ) / ( ny - 1 );
    a0 = a;
    a1 = a + ny;
    c0 = c;
    c1 = c + ny;

    for ( ix = 0; ix < nx - 1; ix++ )
    {
        for ( iy = 0; iy < ny - 1; iy++ )
        {
            count = c0[iy] + c0[iy + 1] + c1[iy] + c1[iy + 1];

            // No filling needs to be done for these cases

            if ( count >= UNDEF )
                continue;
            if ( count == 4 * POS )
                continue;
            if ( count == 4 * NEG )
                continue;

            // Entire rectangle can be filled

            if ( count == 4 * OK )
            {
                // find biggest rectangle that fits
                if ( rectangular )
                {
                    big_recl( c0 + iy, ny, nx - ix, ny - iy, &i, &j );
                }
                else
                {
                    i = j = 1;
                }
                x[0] = x[1] = ix;
                x[2] = x[3] = ix + i;
                y[0] = y[3] = iy;
                y[1] = y[2] = iy + j;

                if ( pltr )
                {
                    for ( i = 0; i < 4; i++ )
                    {
                        ( *pltr )( x[i], y[i], &tx, &ty, pltr_data );
                        x[i] = tx;
                        y[i] = ty;
                    }
                }
                else
                {
                    for ( i = 0; i < 4; i++ )
                    {
                        x[i] = xmin + x[i] * dx;
                        y[i] = ymin + y[i] * dy;
                    }
                }
                if ( fill != NULL )
                    exfill( fill, defined, (PLINT) 4, x, y );
                iy += j - 1;
                continue;
            }

            // Only part of rectangle can be filled

            n_point = min_points = max_points = 0;
            n       = find_interval( a0[iy], a0[iy + 1], c0[iy], c0[iy + 1], xp );
            for ( j = 0; j < n; j++ )
            {
                x[j] = ix;
                y[j] = iy + xp[j];
            }

            i = find_interval( a0[iy + 1], a1[iy + 1],
                c0[iy + 1], c1[iy + 1], xp );

            for ( j = 0; j < i; j++ )
            {
                x[j + n] = ix + xp[j];
                y[j + n] = iy + 1;
            }
            n += i;

            i = find_interval( a1[iy + 1], a1[iy], c1[iy + 1], c1[iy], xp );
            for ( j = 0; j < i; j++ )
            {
                x[n + j] = ix + 1;
                y[n + j] = iy + 1 - xp[j];
            }
            n += i;

            i = find_interval( a1[iy], a0[iy], c1[iy], c0[iy], xp );
            for ( j = 0; j < i; j++ )
            {
                x[n + j] = ix + 1 - xp[j];
                y[n + j] = iy;
            }
            n += i;

            if ( pltr )
            {
                for ( i = 0; i < n; i++ )
                {
                    ( *pltr )( x[i], y[i], &tx, &ty, pltr_data );
                    x[i] = tx;
                    y[i] = ty;
                }
            }
            else
            {
                for ( i = 0; i < n; i++ )
                {
                    x[i] = xmin + x[i] * dx;
                    y[i] = ymin + y[i] * dy;
                }
            }

            if ( min_points == 4 )
                slope = plctestez( a, nx, ny, ix, iy, shade_min );
            if ( max_points == 4 )
                slope = plctestez( a, nx, ny, ix, iy, shade_max );

            // n = number of end of line segments
            // min_points = number times shade_min meets edge
            // max_points = number times shade_max meets edge

            // special cases: check number of times a contour is in a box

            switch ( ( min_points << 3 ) + max_points )
            {
            case 000:
            case 020:
            case 002:
            case 022:
                if ( fill != NULL && n > 0 )
                    exfill( fill, defined, n, x, y );
                break;
            case 040:   // 2 contour lines in box
            case 004:
                if ( n != 6 )
                    fprintf( stderr, "plfshade err n=%d !6", (int) n );
                if ( slope == 1 && c0[iy] == OK )
                {
                    if ( fill != NULL )
                        exfill( fill, defined, n, x, y );
                }
                else if ( slope == 1 )
                {
                    selected_polygon( fill, defined, x, y, 0, 1, 2, -1 );
                    selected_polygon( fill, defined, x, y, 3, 4, 5, -1 );
                }
                else if ( c0[iy + 1] == OK )
                {
                    if ( fill != NULL )
                        exfill( fill, defined, n, x, y );
                }
                else
                {
                    selected_polygon( fill, defined, x, y, 0, 1, 5, -1 );
                    selected_polygon( fill, defined, x, y, 2, 3, 4, -1 );
                }
                break;
            case 044:
                if ( n != 8 )
                    fprintf( stderr, "plfshade err n=%d !8", (int) n );
                if ( slope == 1 )
                {
                    selected_polygon( fill, defined, x, y, 0, 1, 2, 3 );
                    selected_polygon( fill, defined, x, y, 4, 5, 6, 7 );
                }
                else
                {
                    selected_polygon( fill, defined, x, y, 0, 1, 6, 7 );
                    selected_polygon( fill, defined, x, y, 2, 3, 4, 5 );
                }
                break;
            case 024:
            case 042:
                // 3 contours
                if ( n != 7 )
                    fprintf( stderr, "plfshade err n=%d !7", (int) n );

                if ( ( c0[iy] == OK || c1[iy + 1] == OK ) && slope == 1 )
                {
                    if ( fill != NULL )
                        exfill( fill, defined, n, x, y );
                }
                else if ( ( c0[iy + 1] == OK || c1[iy] == OK ) && slope == 0 )
                {
                    if ( fill != NULL )
                        exfill( fill, defined, n, x, y );
                }

                else if ( c0[iy] == OK )
                {
                    selected_polygon( fill, defined, x, y, 0, 1, 6, -1 );
                    selected_polygon( fill, defined, x, y, 2, 3, 4, 5 );
                }
                else if ( c0[iy + 1] == OK )
                {
                    selected_polygon( fill, defined, x, y, 0, 1, 2, -1 );
                    selected_polygon( fill, defined, x, y, 3, 4, 5, 6 );
                }
                else if ( c1[iy + 1] == OK )
                {
                    selected_polygon( fill, defined, x, y, 0, 1, 5, 6 );
                    selected_polygon( fill, defined, x, y, 2, 3, 4, -1 );
                }
                else if ( c1[iy] == OK )
                {
                    selected_polygon( fill, defined, x, y, 0, 1, 2, 3 );
                    selected_polygon( fill, defined, x, y, 4, 5, 6, -1 );
                }
                else
                {
                    fprintf( stderr, "plfshade err logic case 024:042\n" );
                }
                break;
            default:
                fprintf( stderr, "prog err switch\n" );
                break;
            }
            draw_boundary( slope, x, y );

            if ( fill != NULL )
            {
                plwidth( sh_width );
                if ( sh_cmap == 0 )
                    plcol0( (PLINT) sh_color );
                else if ( sh_cmap == 1 )
                    plcol1( sh_color );
            }
        }

        a0  = a1;
        c0  = c1;
        a1 += ny;
        c1 += ny;
    }

    free( c );
    free( a );
    plwidth( init_width );
}