Example #1
0
static void
plot1( void )
{
    PLFLT shade_min, shade_max, sh_color;
    PLINT sh_cmap   = 0, sh_width;
    PLINT min_color = 0, min_width = 0, max_color = 0, max_width = 0;

    pladv( 0 );
    plvpor( 0.1, 0.9, 0.1, 0.9 );
    plwind( -1.0, 1.0, -1.0, 1.0 );

/* Plot using identity transform */

    shade_min = zmin + ( zmax - zmin ) * 0.4;
    shade_max = zmin + ( zmax - zmin ) * 0.6;
    sh_color  = 7;
    sh_width  = 2;
    min_color = 9;
    max_color = 2;
    min_width = 2;
    max_width = 2;

    plpsty( 8 );
    plshade1( &z[0][0], XPTS, YPTS, NULL, -1., 1., -1., 1.,
        shade_min, shade_max,
        sh_cmap, sh_color, sh_width,
        min_color, min_width, max_color, max_width,
        plfill, 1, NULL, NULL );

    plcol0( 1 );
    plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 );
    plcol0( 2 );
    pllab( "distance", "altitude", "Bogon flux" );
}
Example #2
0
static void
plot3( void )
{
    static PLFLT xx[2][5] = { { -1.0, 1.0, 1.0, -1.0, -1.0 },
                              { -1.0, 1.0, 1.0, -1.0, -1.0 } };
    static PLFLT yy[2][5] = { {  1.0,  1.0, 0.0, 0.0,  1.0 },
                              { -1.0, -1.0, 0.0, 0.0, -1.0 } };
    static PLFLT zz[2][5] = { { 0.0, 0.0, 1.0, 1.0, 0.0 },
                              { 0.0, 0.0, 1.0, 1.0, 0.0 } };

    pladv( 0 );
    plvpor( 0.1, 0.9, 0.1, 0.9 );
    plwind( -1.0, 1.0, -1.0, 1.0 );
    plw3d( 1., 1., 1., -1.0, 1.0, -1.0, 1.0, 0.0, 1.5, 30, -40 );

/* Plot using identity transform */

    plcol0( 1 );
    plbox3( "bntu", "X", 0.0, 0, "bntu", "Y", 0.0, 0, "bcdfntu", "Z", 0.5, 0 );
    plcol0( 2 );
    pllab( "", "", "3-d polygon filling" );

    plcol0( 3 );
    plpsty( 1 );
    plline3( 5, xx[0], yy[0], zz[0] );
    plfill3( 4, xx[0], yy[0], zz[0] );
    plpsty( 2 );
    plline3( 5, xx[1], yy[1], zz[1] );
    plfill3( 4, xx[1], yy[1], zz[1] );
}
Example #3
0
//--------------------------------------------------------------------------
//! Clear current subpage.  Subpages can be set with pladv before
//! calling plclear. Not all drivers support this.
//
void
c_plclear( void )
{
    if ( m_plsc->level < 1 )
    {
        plabort( "plclear: Please call plinit first" );
        return;
    }

    if ( m_plsc->dev_clear )
        plP_esc( PLESC_CLEAR, NULL );
    else   // driver does not support clear, fill using background color

    {
        short x[5], y[5];
        int   ocolor = m_plsc->icol0;

        x[0] = x[3] = x[4] = (short) m_plsc->sppxmi;
        x[1] = x[2] = (short) m_plsc->sppxma;
        y[0] = y[1] = y[4] = (short) m_plsc->sppymi;
        y[2] = y[3] = (short) m_plsc->sppyma;
        plcol0( 0 );
        plP_fill( x, y, 5 );
        plcol0( ocolor );
    }
}
Example #4
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 );
    plwidth( 2 );
    plline( 100, x, y );
    plwidth( 1 );
}
Example #5
0
int
main(int argc, char *argv[])
{
    char text[10];
    int i, j, k;
    PLFLT x, y;

/* Parse and process command line arguments */

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

/* Initialize plplot */

    plinit();

    pladv(0);

/* Set up viewport and window */

    plcol0(2);
    plvpor(0.1, 1.0, 0.1, 0.9);
    plwind(0.0, 1.0, 0.0, 1.3);

/* Draw the grid using plbox */

    plbox("bcg", 0.1, 0, "bcg", 0.1, 0);

/* Write the digits below the frame */

    plcol0(15);
    for (i = 0; i <= 9; i++) {
	sprintf(text, "%d", i);
	plmtex("b", 1.5, (0.1 * i + 0.05), 0.5, text);
    }

    k = 0;
    for (i = 0; i <= 12; i++) {

    /* Write the digits to the left of the frame */

	sprintf(text, "%d", 10 * i);
	plmtex("lv", 1.0, (1.0 - (2 * i + 1) / 26.0), 1.0, text);
	for (j = 0; j <= 9; j++) {
	    x = 0.1 * j + 0.05;
	    y = 1.25 - 0.1 * i;

	/* Display the symbols (plpoin expects that x and y are arrays so */
	/* pass pointers) */

	    if (k < 128)
		plpoin(1, &x, &y, k);
	    k = k + 1;
	}
    }

    plmtex("t", 1.5, 0.5, 0.5, "PLplot Example 6 - plpoin symbols");
    plend();
    exit(0);
}
Example #6
0
BarChart2::BarChart2(MyPlotwindow *m_plot, wxString filename, PlotParam b2style)
{
    pls = m_plot->GetStream();

	wxFileInputStream fin( filename );
	wxTextInputStream text( fin );
	double x[36];
	float a[36],b[36];
	for(int i=0;i<36;i++)
	{
		x[i]=i+1.0;
		text>>b[i]>>a[i];
	}

    pls->adv( 0 );
	pls->vsta();
	pls->wind( 0, 37, -b2style.ymax*0.001, b2style.ymax*0.001 );
	plcol0( 15 );
    pls->box( "abcnt", 5.0, 0, "bcntv", 0, 0 );
    pls->lab( "quad index", "#gDk#d1#ul (1/m)", "" );

	plcol0( 0 );

	plcol1( 1 );
	plpsty( 0 );
	for (int i = 0; i < 36; i++ )
	{
		plfbox_solid( x[i]-0.3, b[i], 0.25);
	}
	plcol1( 0 );
	plpsty( 0 ); //pls->lsty( 1 );
	for (int i = 0; i < 36; i++ )
	{
		plfbox_solid( x[i]+0.05, a[i] , 0.25);
	}

	//legend
	pls->vpor(0.15, 0.28, 0.75, 0.85);
	pls->wind( 0, 1, 0, 1 );
	plcol0( 5 );
    pls->box( "bc", 0, 0, "bc", 0, 0 );
    pls->ptex( 0.4, 0.7, 0.0, 0.0, 0, "before" );
    pls->ptex( 0.4, 0.2, 0.0, 0.0, 0, "after " );

	plcol1( 1 );
	PLFLT x1[]={0.1,0.1,0.35,0.35};
	PLFLT y1[]={0.7,0.8,0.8 ,0.7};
    pls->fill( 4, x1, y1 );

	PLFLT x2[]={0.1,0.1,0.35 ,0.35 };
	PLFLT y2[]={0.2,0.3,0.3  ,0.2};
	plcol1( 0 );
    pls->fill( 4, x2, y2 );

    m_plot->RenewPlot();
}
Example #7
0
void PlPlotWidget::plotLinearFit(int size, std::vector<double> &xp,std::vector<double> &yp,std::vector<double> &yp_err, double m, double c){

    plot->clearWidget();
    //plot->setBackgroundColor(255,255,255,1);

    int   i;
    double max_x, max_y;

    std::vector<double>::iterator result_min_x, result_max_x;
    std::vector<double>::iterator result_min_y, result_max_y;

    PLFLT *x = new PLFLT[size];
    PLFLT *y = new PLFLT[size];
    PLFLT *y_fit = new PLFLT[size];
    PLFLT *y_err_hi = new PLFLT[size];
    PLFLT *y_err_lo = new PLFLT[size];

    for(i=0;i<size;i++){  // is there a better way with first value
        x[i]=xp[i];
        y[i]=yp[i];
        y_fit[i]=m*xp[i]+c;
        y_err_hi[i]=yp[i]+yp_err[i];
        y_err_lo[i]=yp[i]-yp_err[i];
    }

    result_min_x = std::min_element(xp.begin(), xp.end());
    result_max_x = std::max_element(xp.begin(), xp.end());
    result_min_y = std::min_element(yp.begin(), yp.end());
    result_max_y = std::max_element(yp.begin(), yp.end());

    max_x = (*result_max_x)*(1.2);	//sets the axis to be 20% larger than the max value
    max_y = (*result_max_y)*(1.2);

    plcol0( 14 );
    plenv( 0, max_x, 0, max_y, 0, 1 );
    plcol0( 1 );
    pllab( "time (s)", "\gl", "FRAP DATA" );

    plcol0( 14 );
    plwid( 2 );
    plpoin( size, x, y, 20);
    plerry( size, x, y_err_hi,y_err_lo);
    plwid( 1 );

    plcol0( 14 );
    plwid( 2 );
    plline( size, x, y_fit );
    plwid( 1 );

    delete[] x;
    delete[] y;
    delete[] y_fit;
    delete[] y_err_hi;
    delete[] y_err_lo;
}
Example #8
0
static void polar( void )
//polar contour plot example.
{
    int      i, j;
    PLcGrid2 cgrid2;
    PLFLT    **z;
    PLFLT    px[PERIMETERPTS], py[PERIMETERPTS];
    PLFLT    t, r, theta;
    PLFLT    lev[10];

    plenv( -1., 1., -1., 1., 0, -2 );
    plcol0( 1 );

//Perimeter
    for ( i = 0; i < PERIMETERPTS; i++ )
    {
        t     = ( 2. * M_PI / ( PERIMETERPTS - 1 ) ) * (double) i;
        px[i] = cos( t );
        py[i] = sin( t );
    }
    plline( PERIMETERPTS, px, py );

//create data to be contoured.
    plAlloc2dGrid( &cgrid2.xg, RPTS, THETAPTS );
    plAlloc2dGrid( &cgrid2.yg, RPTS, THETAPTS );
    plAlloc2dGrid( &z, RPTS, THETAPTS );
    cgrid2.nx = RPTS;
    cgrid2.ny = THETAPTS;

    for ( i = 0; i < RPTS; i++ )
    {
        r = i / (double) ( RPTS - 1 );
        for ( j = 0; j < THETAPTS; j++ )
        {
            theta           = ( 2. * M_PI / (double) ( THETAPTS - 1 ) ) * (double) j;
            cgrid2.xg[i][j] = r * cos( theta );
            cgrid2.yg[i][j] = r * sin( theta );
            z[i][j]         = r;
        }
    }

    for ( i = 0; i < 10; i++ )
    {
        lev[i] = 0.05 + 0.10 * (double) i;
    }

    plcol0( 2 );
    plcont( (const PLFLT * const *) z, RPTS, THETAPTS, 1, RPTS, 1, THETAPTS, lev, 10,
        pltr2, (void *) &cgrid2 );
    plcol0( 1 );
    pllab( "", "", "Polar Contour Plot" );
    plFree2dGrid( z, RPTS, THETAPTS );
    plFree2dGrid( cgrid2.xg, RPTS, THETAPTS );
    plFree2dGrid( cgrid2.yg, RPTS, THETAPTS );
}
Example #9
0
int 
main(int argc, char **argv) 
{
    PLFLT minx, maxx, miny, maxy;
    int c;

/* Parse and process command line arguments */

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

/* Longitude (x) and latitude (y) */

    miny = -70;
    maxy = 80;

    plinit();

/* Cartesian plots */
/* Most of world */

    minx = 190;
    maxx = 190+360;

    plcol0(1);
    plenv(minx, maxx, miny, maxy, 1, -1);
    plmap(NULL, "usaglobe", minx, maxx, miny, maxy);

/* The Americas */

    minx = 190;
    maxx = 340;

    plcol0(1);
    plenv(minx, maxx, miny, maxy, 1, -1);
    plmap(NULL, "usaglobe", minx, maxx, miny, maxy);

/* Polar, Northern hemisphere */

    minx = 0;
    maxx = 360;

    plenv(-75., 75., -75., 75., 1, -1);
    plmap(mapform19,"globe", minx, maxx, miny, maxy);

    pllsty(2);
    plmeridians(mapform19,10.0, 10.0, 0.0, 360.0, -10.0, 80.0);
    plend();
    exit(0);
}
Example #10
0
static void plplot_set_axis(plot_driver_type * driver , const plot_range_type * range , const char * timefmt , plot_color_type box_color , double tick_font_size) {
  plplot_state_type * state = driver->state;
  {
    double xmin , xmax , ymin , ymax;
    plot_range_get_limits( range , &xmin , &xmax , &ymin , &ymax);
    
    if (state->logx) {
      xmin = log( xmin );
      xmax = log( xmax );
    }

    if (state->logy) {
      ymin = log( ymin );
      ymax = log( ymax );
    }
    
    plwind( xmin , xmax , ymin , ymax );
  }
  plcol0(box_color);
  plschr(0, tick_font_size * PLOT_DEFAULT_LABEL_FONTSIZE);
  
  if (timefmt != NULL) {
    pltimefmt(timefmt);
    state->plbox_xopt = util_realloc_sprintf( state->plbox_xopt , "%s%c" , state->plbox_xopt , 'd');
  }
  plbox(state->plbox_xopt, 0.0, 0, state->plbox_yopt , 0.0, 0);
  
}
Example #11
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++ )
    {
        xs1[i] = x[i * 10 + 3];
        ys1[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, xs1, ys1, 9 );

// Draw the line through the data

    plcol0( 4 );
    plline( 60, x, y );
}
Example #12
0
static void
plot2( void )
{
    PLFLT        shade_min, shade_max, sh_color;
    PLINT        sh_cmap   = 0, sh_width;
    PLINT        min_color = 0, min_width = 0, max_color = 0, max_width = 0;
    int          i;
    static PLINT nlin[10]   = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 };
    static PLINT inc[10][2] = { { 450,    0 }, { -450,    0 }, { 0,   0 }, { 900,   0 },
                                { 300,    0 }, {  450, -450 }, { 0, 900 }, {   0, 450 },
                                { 450, -450 }, {    0,  900 } };
    static PLINT del[10][2] = { { 2000, 2000 }, { 2000, 2000 }, { 2000, 2000 },
                                { 2000, 2000 }, { 2000, 2000 }, { 2000, 2000 },
                                { 2000, 2000 }, { 2000, 2000 }, { 4000, 4000 },
                                { 4000, 2000 } };

    sh_width = 2;

    pladv( 0 );
    plvpor( 0.1, 0.9, 0.1, 0.9 );
    plwind( -1.0, 1.0, -1.0, 1.0 );

/* Plot using identity transform */

    for ( i = 0; i < 10; i++ )
    {
        shade_min = zmin + ( zmax - zmin ) * i / 10.0;
        shade_max = zmin + ( zmax - zmin ) * ( i + 1 ) / 10.0;
        sh_color  = i + 6;
        plpat( nlin[i], inc[i], del[i] );

        plshade1( &z[0][0], XPTS, YPTS, NULL, -1., 1., -1., 1.,
            shade_min, shade_max,
            sh_cmap, sh_color, sh_width,
            min_color, min_width, max_color, max_width,
            plfill, 1, NULL, NULL );
    }

    plcol0( 1 );
    plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 );
    plcol0( 2 );
    pllab( "distance", "altitude", "Bogon flux" );
}
Example #13
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 );
}
Example #14
0
static void
draw_boundary( PLINT slope, PLFLT *x, PLFLT *y )
{
    int i;

    if ( pen_col_min != 0 && pen_wd_min != 0 && min_points != 0 )
    {
        plcol0( pen_col_min );
        plwidth( pen_wd_min );
        if ( min_points == 4 && slope == 0 )
        {
            // swap points 1 and 3
            i          = min_pts[1];
            min_pts[1] = min_pts[3];
            min_pts[3] = i;
        }
        pljoin( x[min_pts[0]], y[min_pts[0]], x[min_pts[1]], y[min_pts[1]] );
        if ( min_points == 4 )
        {
            pljoin( x[min_pts[2]], y[min_pts[2]], x[min_pts[3]],
                y[min_pts[3]] );
        }
    }
    if ( pen_col_max != 0 && pen_wd_max != 0 && max_points != 0 )
    {
        plcol0( pen_col_max );
        plwidth( pen_wd_max );
        if ( max_points == 4 && slope == 0 )
        {
            // swap points 1 and 3
            i          = max_pts[1];
            max_pts[1] = max_pts[3];
            max_pts[3] = i;
        }
        pljoin( x[max_pts[0]], y[max_pts[0]], x[max_pts[1]], y[max_pts[1]] );
        if ( max_points == 4 )
        {
            pljoin( x[max_pts[2]], y[max_pts[2]], x[max_pts[3]],
                y[max_pts[3]] );
        }
    }
}
Example #15
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 );
}
Example #16
0
void plplot_text( plot_driver_type * driver , const plot_text_type * plot_text) {
  double just = 0.0;  // Left justified
  plschr( 0.0 , plot_text_get_font_scale( plot_text ) );
  plcol0( BLACK );
  
  plptex( plot_text_get_x( plot_text ) , 
          plot_text_get_y( plot_text ) , 
          1 , 0 , just , 
          plot_text_get_text( plot_text ));

  plschr( 0.0 , 1.0 );
}
Example #17
0
MZ_DLLEXPORT
void c_plshades( PLFLT **a, PLINT nx, PLINT ny, PLINT (*defined) (PLFLT, PLFLT),
		PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax,
		PLFLT *clevel, PLINT nlevel, PLINT fill_width,
		PLINT cont_color, PLINT cont_width,
		void (*fill) (PLINT, PLFLT *, PLFLT *), PLINT rectangular,
		void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer),
		PLPointer pltr_data )
{
   PLFLT shade_min, shade_max, shade_color;
   PLINT i, init_color, init_width;

   for (i = 0; i < nlevel-1; i++) {
      shade_min = clevel[i];
      shade_max = clevel[i+1];
      shade_color = i / (PLFLT) (nlevel-2);
      /* The constants in order mean 
       * (1) color map1,
       * (0, 0, 0, 0) all edge effects will be done with plcont rather
       * than the normal plshade drawing which gets partially blocked
       * when sequential shading is done as in the present case */
      
      plshade(a, nx, ny, defined, xmin, xmax, ymin, ymax,
	      shade_min, shade_max,
	      1, shade_color, fill_width,
	      0, 0, 0, 0,
	      fill, rectangular, pltr, pltr_data);
   }
   if(cont_color > 0 && cont_width > 0) {
      init_color = plsc->icol0;
      init_width = plsc->width;
      plcol0(cont_color);
      plwid(cont_width);
      plcont(a, nx, ny, 1, nx, 1, ny, clevel, nlevel, pltr, pltr_data);
      plcol0(init_color);
      plwid(init_width);
   }
}
Example #18
0
int
main( int argc, char *argv[] )
{
    int i, j;

    plparseopts( &argc, argv, PL_PARSE_FULL );

    plinit();

    pladv( 0 );
    plvpor( 0.0, 1.0, 0.0, 1.0 );
    plwind( 0.0, 1.0, 0.0, 1.0 );
    plcol0( 0 );
    plbox( "", 1.0, 0, "", 1.0, 0 );

    plscmap0n( 7 );
    plscmap0( red, green, blue, 7 );

    plschr( 0, 4.0 );
    plfont( 1 );

    for ( i = 0; i < 4; i++ )
    {
        plcol0( i + 1 );
        plfill( 4, px, py );

        for ( j = 0; j < 4; j++ )
            py [j] += 1.0 / 4.0;
    }

    plcol0( 0 );
    for ( i = 0; i < 12; i++ )
        plptex( sx [i], sy [i], 1.0, 0.0, 0.5, peace [i] );


    plend();
    exit( 0 );
}
Example #19
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);

}
Example #20
0
void draw_page( PLINT mode, const char *title )
{
    PLFLT xs[3], ys[3];
    PLFLT over_x, over_y, over_r;

    // A triangle for the background
    xs[0] = 0.0;
    xs[1] = 1.0;
    xs[2] = 0.0;
    ys[0] = 0.0;
    ys[1] = 1.0;
    ys[2] = 1.0;

    // A circle for the foreground
    over_x = 0.5;
    over_y = 0.5;
    over_r = 0.4;

    plcol0( 1 );

    // Setup a plot window
    plenv( 0.0, 1.0, 0.0, 1.0, 1, 0 );

    // Show which mode we're using
    pllab( "", "", title );

    // Draw a background triangle using the default drawing mode
    plcol0( 2 );
    plsdrawmode( PL_DRAWMODE_DEFAULT );
    plfill( 3, xs, ys );

    // Draw a circle in the given drawing mode
    plcol0( 3 );
    plsdrawmode( mode );
    plarc( over_x, over_y, over_r, over_r, 0.0, 360.0, 0.0, 1 );
}
/* basic "plot one line" atom */
static void plotOneLine(
    uint32_t numSamples,
    PLFLT *fx,
    LineDef *lineDef,
    bool plotPoints,		/* true: plot points */
    bool plotLine)			/* true: plot line */
{
    /* set drawing color - set the value for color map 0[1], then set it */
    const RGB *rgb = &plColors[lineDef->color];
    plscol0(1, rgb->r, rgb->g, rgb->b);
    plcol0(1);

    if(plotPoints) {
        plpoin(numSamples, fx, lineDef->fy, lineDef->pointCode);
    }
    if(plotLine) {
        plline(numSamples, fx, lineDef->fy);
    }
}
Example #22
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 );
}
Example #23
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 );
}
Example #24
0
static void potential( void )
//shielded potential contour plot example.
{
    int      i, j;
    PLcGrid2 cgrid2;
    PLFLT    rmax, xmin, xmax, x0, ymin, ymax, y0, zmin, zmax;
    PLFLT    peps, xpmin, xpmax, ypmin, ypmax;
    PLFLT    eps, q1, d1, q1i, d1i, q2, d2, q2i, d2i;
    PLFLT    div1, div1i, div2, div2i;
    PLFLT    **z;
    PLINT    nlevelneg, nlevelpos;
    PLFLT    dz, clevel2, clevelneg[PNLEVEL], clevelpos[PNLEVEL];
    PLINT    ncollin, ncolbox, ncollab;
    PLFLT    px[PPERIMETERPTS], py[PPERIMETERPTS];
    PLFLT    t, r, theta;

//create data to be contoured.
    plAlloc2dGrid( &cgrid2.xg, PRPTS, PTHETAPTS );
    plAlloc2dGrid( &cgrid2.yg, PRPTS, PTHETAPTS );
    plAlloc2dGrid( &z, PRPTS, PTHETAPTS );
    cgrid2.nx = PRPTS;
    cgrid2.ny = PTHETAPTS;

    for ( i = 0; i < PRPTS; i++ )
    {
        r = 0.5 + (double) i;
        for ( j = 0; j < PTHETAPTS; j++ )
        {
            theta           = ( 2. * M_PI / (double) ( PTHETAPTS - 1 ) ) * ( 0.5 + (double) j );
            cgrid2.xg[i][j] = r * cos( theta );
            cgrid2.yg[i][j] = r * sin( theta );
        }
    }

    rmax = r;
    f2mnmx( cgrid2.xg, PRPTS, PTHETAPTS, &xmin, &xmax );
    f2mnmx( cgrid2.yg, PRPTS, PTHETAPTS, &ymin, &ymax );
    x0 = ( xmin + xmax ) / 2.;
    y0 = ( ymin + ymax ) / 2.;

    // Expanded limits
    peps  = 0.05;
    xpmin = xmin - fabs( xmin ) * peps;
    xpmax = xmax + fabs( xmax ) * peps;
    ypmin = ymin - fabs( ymin ) * peps;
    ypmax = ymax + fabs( ymax ) * peps;

    // Potential inside a conducting cylinder (or sphere) by method of images.
    // Charge 1 is placed at (d1, d1), with image charge at (d2, d2).
    // Charge 2 is placed at (d1, -d1), with image charge at (d2, -d2).
    // Also put in smoothing term at small distances.
    //

    eps = 2.;

    q1 = 1.;
    d1 = rmax / 4.;

    q1i = -q1 * rmax / d1;
    d1i = pow( rmax, 2. ) / d1;

    q2 = -1.;
    d2 = rmax / 4.;

    q2i = -q2 * rmax / d2;
    d2i = pow( rmax, 2. ) / d2;

    for ( i = 0; i < PRPTS; i++ )
    {
        for ( j = 0; j < PTHETAPTS; j++ )
        {
            div1    = sqrt( pow( cgrid2.xg[i][j] - d1, 2. ) + pow( cgrid2.yg[i][j] - d1, 2. ) + pow( eps, 2. ) );
            div1i   = sqrt( pow( cgrid2.xg[i][j] - d1i, 2. ) + pow( cgrid2.yg[i][j] - d1i, 2. ) + pow( eps, 2. ) );
            div2    = sqrt( pow( cgrid2.xg[i][j] - d2, 2. ) + pow( cgrid2.yg[i][j] + d2, 2. ) + pow( eps, 2. ) );
            div2i   = sqrt( pow( cgrid2.xg[i][j] - d2i, 2. ) + pow( cgrid2.yg[i][j] + d2i, 2. ) + pow( eps, 2. ) );
            z[i][j] = q1 / div1 + q1i / div1i + q2 / div2 + q2i / div2i;
        }
    }
    f2mnmx( z, PRPTS, PTHETAPTS, &zmin, &zmax );
//   printf("%.15g %.15g %.15g %.15g %.15g %.15g %.15g %.15g \n",
//        q1, d1, q1i, d1i, q2, d2, q2i, d2i);
// printf("%.15g %.15g %.15g %.15g %.15g %.15g \n",
//        xmin, xmax, ymin, ymax, zmin, zmax);

    // Positive and negative contour levels.
    dz        = ( zmax - zmin ) / (double) PNLEVEL;
    nlevelneg = 0;
    nlevelpos = 0;
    for ( i = 0; i < PNLEVEL; i++ )
    {
        clevel2 = zmin + ( (double) i + 0.5 ) * dz;
        if ( clevel2 <= 0. )
            clevelneg[nlevelneg++] = clevel2;
        else
            clevelpos[nlevelpos++] = clevel2;
    }
    // Colours!
    ncollin = 11;
    ncolbox = 1;
    ncollab = 2;

    // Finally start plotting this page!
    pladv( 0 );
    plcol0( ncolbox );

    plvpas( 0.1, 0.9, 0.1, 0.9, 1.0 );
    plwind( xpmin, xpmax, ypmin, ypmax );
    plbox( "", 0., 0, "", 0., 0 );

    plcol0( ncollin );
    if ( nlevelneg > 0 )
    {
        // Negative contours
        pllsty( 2 );
        plcont( (const PLFLT * const *) z, PRPTS, PTHETAPTS, 1, PRPTS, 1, PTHETAPTS,
            clevelneg, nlevelneg, pltr2, (void *) &cgrid2 );
    }

    if ( nlevelpos > 0 )
    {
        // Positive contours
        pllsty( 1 );
        plcont( (const PLFLT * const *) z, PRPTS, PTHETAPTS, 1, PRPTS, 1, PTHETAPTS,
            clevelpos, nlevelpos, pltr2, (void *) &cgrid2 );
    }

    // Draw outer boundary
    for ( i = 0; i < PPERIMETERPTS; i++ )
    {
        t     = ( 2. * M_PI / ( PPERIMETERPTS - 1 ) ) * (double) i;
        px[i] = x0 + rmax * cos( t );
        py[i] = y0 + rmax * sin( t );
    }

    plcol0( ncolbox );
    plline( PPERIMETERPTS, px, py );

    plcol0( ncollab );
    pllab( "", "", "Shielded potential of charges in a conducting sphere" );

    plFree2dGrid( z, PRPTS, PTHETAPTS );
    plFree2dGrid( cgrid2.xg, PRPTS, PTHETAPTS );
    plFree2dGrid( cgrid2.yg, PRPTS, PTHETAPTS );
}
Example #25
0
bool plotNoiseStandardDeviation(const hoNDArray< std::complex<T> >& m, const std::vector<std::string>& coilStrings,
                    const std::string& xlabel, const std::string& ylabel, const std::string& title,
                    size_t xsize, size_t ysize, bool trueColor,
                    hoNDArray<float>& plotIm)
{
    try
    {
        size_t CHA = m.get_size(0);
        GADGET_CHECK_RETURN_FALSE(coilStrings.size() == CHA);

        hoNDArray<double> xd, yd, yd2;

        xd.create(CHA);
        yd.create(CHA);

        size_t c;
        for (c = 0; c < CHA; c++)
        {
            xd(c) = c+1;
            yd(c) = std::sqrt( std::abs(m(c, c)) );
        }

        double maxY = Gadgetron::max(&yd);

        yd2 = yd;
        std::sort(yd2.begin(), yd2.end());
        double medY = yd2(CHA / 2);

        // increase dot line to be 1 sigma ~= 33%
        double medRange = 0.33;

        if (maxY < medY*(1 + medRange))
        {
            maxY = medY*(1 + medRange);
        }

        hoNDArray<unsigned char> im;
        im.create(3, xsize, ysize);
        Gadgetron::clear(im);

        plsdev("mem");

        plsmem(im.get_size(1), im.get_size(2), im.begin());

        plinit();
        plfont(2);
        pladv(0);
        plvpor(0.15, 0.75, 0.1, 0.8);

        plwind(0, CHA+1, 0, maxY*1.05);

        plcol0(15);
        plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);

        std::string gly;
        getPlotGlyph(0, gly); // circle
        plstring(CHA, xd.begin(), yd.begin(), gly.c_str());

        // draw the median line
        pllsty(1);

        double px[2], py[2];

        px[0] = 0;
        px[1] = CHA+1;

        py[0] = medY;
        py[1] = medY;

        plline(2, px, py);

        pllsty(2);

        py[0] = medY*(1 - medRange);
        py[1] = medY*(1 - medRange);

        plline(2, px, py);

        py[0] = medY*(1 + medRange);
        py[1] = medY*(1 + medRange);

        plline(2, px, py);

        plmtex("b", 3.2, 0.5, 0.5, xlabel.c_str());
        plmtex("t", 2.0, 0.5, 0.5, title.c_str());
        plmtex("l", 5.0, 0.5, 0.5, ylabel.c_str());

        // draw the legend
        std::vector<PLINT> opt_array(CHA), text_colors(CHA), line_colors(CHA), line_styles(CHA), symbol_numbers(CHA), symbol_colors(CHA);
        std::vector<PLFLT> symbol_scales(CHA), line_widths(CHA), box_scales(CHA, 1);

        std::vector<const char*> symbols(CHA);
        PLFLT legend_width, legend_height;

        std::vector<const char*> legend_text(CHA);

        std::vector<std::string> legends(CHA);

        size_t n;
        for (n = 0; n < CHA; n++)
        {
            opt_array[n] = PL_LEGEND_SYMBOL;
            text_colors[n] = 15;
            line_colors[n] = 15;
            line_styles[n] = (n % 8 + 1);
            line_widths[n] = 0.2;
            symbol_colors[n] = 15;
            symbol_scales[n] = 0.75;
            symbol_numbers[n] = 1;
            symbols[n] = gly.c_str();

            std::ostringstream ostr;
            ostr << n+1 << ":" << coilStrings[n];

            legends[n] = ostr.str();

            legend_text[n] = legends[n].c_str();
        }

        pllegend(&legend_width,
            &legend_height,
            PL_LEGEND_BACKGROUND,
            PL_POSITION_OUTSIDE | PL_POSITION_RIGHT,
            0.02,                                       // x
            0.0,                                        // y
            0.05,                                       // plot_width
            0,                                          // bg_color
            15,                                         // bb_color
            1,                                          // bb_style
            0,                                          // nrow
            0,                                          // ncolumn
            CHA,                                        // nlegend
            &opt_array[0],
            0.05,                                       // text_offset
            0.5,                                        // text_scale
            1.0,                                        // text_spacing
            0.5,                                        // text_justification
            &text_colors[0],
            (const char **)(&legend_text[0]),
            NULL,                                       // box_colors
            NULL,                                       // box_patterns
            &box_scales[0],                             // box_scales
            NULL,                                       // box_line_widths
            &line_colors[0],
            &line_styles[0],
            &line_widths[0],
            &symbol_colors[0],
            &symbol_scales[0],
            &symbol_numbers[0],
            (const char **)(&symbols[0])
            );

        plend();

        outputPlotIm(im, trueColor, plotIm);
    }
    catch (...)
    {
        GERROR_STREAM("Errors happened in plotNoiseStandardDeviation(...) ... ");
        return false;
    }

    return true;
}
Example #26
0
template <typename T> EXPORTGTPLPLOT
bool plotCurves(const std::vector<hoNDArray<T> >& x, const std::vector<hoNDArray<T> >& y, 
                const std::string& xlabel, const std::string& ylabel, 
                const std::string& title, const std::vector<std::string>& legend, 
                const std::vector<std::string>& symbols, 
                size_t xsize, size_t ysize, 
                T xlim[2], T ylim[2], 
                bool trueColor, bool drawLine, 
                hoNDArray<float>& plotIm)
{
    try
    {
        GADGET_CHECK_RETURN_FALSE(x.size()>0);
        GADGET_CHECK_RETURN_FALSE(y.size()>0);
        GADGET_CHECK_RETURN_FALSE(x.size() == y.size());

        T minX = xlim[0];
        T maxX = xlim[1];
        T minY = ylim[0];
        T maxY = ylim[1];

        plsdev("mem");

        hoNDArray<unsigned char> im;
        im.create(3, xsize, ysize);
        Gadgetron::clear(im);

        plsmem(im.get_size(1), im.get_size(2), im.begin());

        plinit();
        plfont(2);

        pladv(0);

        if (legend.size() == x.size())
        {
            plvpor(0.11, 0.75, 0.1, 0.9);
        }
        else
        {
            plvpor(0.15, 0.85, 0.1, 0.9);
        }

        T spaceX = 0.01*(maxX - minX);
        T spaceY = 0.05*(maxY - minY);

        plwind(minX - spaceX, maxX + spaceX, minY - spaceY, maxY + spaceY);

        plcol0(15);
        plbox("bgcnst", 0.0, 0, "bgcnstv", 0.0, 0);

        // int mark[2], space[2];

        //mark[0] = 4000;
        //space[0] = 2500;
        //plstyl(1, mark, space);

        size_t num = x.size();

        size_t n;

        hoNDArray<double> xd, yd;

        // draw lines
        for (n = 0; n < num; n++)
        {
            size_t N = y[n].get_size(0);

            xd.copyFrom(x[n]);
            yd.copyFrom(y[n]);

            if (drawLine)
            {
                int c;
                getPlotColor(n, c);
                plcol0(c);
                pllsty(n % 8 + 1);
                plline(N, xd.begin(), yd.begin());
            }

            std::string gly;
            if(symbols.size()>n)
            {
                gly = symbols[n];
            }
            else
                getPlotGlyph(n, gly);

            plstring(N, xd.begin(), yd.begin(), gly.c_str());
        }

        plcol0(15);
        plmtex("b", 3.2, 0.5, 0.5, xlabel.c_str());
        plmtex("t", 2.0, 0.5, 0.5, title.c_str());
        plmtex("l", 5.0, 0.5, 0.5, ylabel.c_str());

        // draw the legend
        if (legend.size() == x.size())
        {
            std::vector<PLINT> opt_array(num), text_colors(num), line_colors(num), line_styles(num), symbol_numbers(num), symbol_colors(num);
            std::vector<PLFLT> symbol_scales(num), line_widths(num), box_scales(num, 1);

            std::vector<std::string> glyphs(num);
            std::vector<const char*> symbols(num);
            PLFLT legend_width, legend_height;

            std::vector<const char*> legend_text(num);

            for (n = 0; n < num; n++)
            {
                int c;
                getPlotColor(n, c);
                getPlotGlyph(n, glyphs[n]);

                opt_array[n] = PL_LEGEND_SYMBOL | PL_LEGEND_LINE;
                text_colors[n] = 15;
                line_colors[n] = c;
                line_styles[n] = (n%8+1);
                line_widths[n] = 0.2;
                symbol_colors[n] = c;
                symbol_scales[n] = 0.75;
                symbol_numbers[n] = 1;
                symbols[n] = glyphs[n].c_str();
                legend_text[n] = legend[n].c_str();
            }

            pllegend(&legend_width, 
                    &legend_height,
                    PL_LEGEND_BACKGROUND,
                    PL_POSITION_OUTSIDE | PL_POSITION_RIGHT | PL_POSITION_TOP,
                    0.02,                                       // x
                    0.0,                                        // y
                    0.05,                                       // plot_width
                    0,                                          // bg_color
                    15,                                         // bb_color
                    1,                                          // bb_style
                    0,                                          // nrow
                    0,                                          // ncolumn
                    num,                                        // nlegend
                    &opt_array[0], 
                    0.05,                                       // text_offset
                    0.35,                                       // text_scale
                    1.0,                                        // text_spacing
                    0.5,                                        // text_justification
                    &text_colors[0], 
                    (const char **)(&legend_text[0]), 
                    NULL,                                       // box_colors
                    NULL,                                       // box_patterns
                    &box_scales[0],                             // box_scales
                    NULL,                                       // box_line_widths
                    &line_colors[0], 
                    &line_styles[0], 
                    &line_widths[0],
                    &symbol_colors[0], 
                    &symbol_scales[0], 
                    &symbol_numbers[0], 
                    (const char **)(&symbols[0])
                    );
        }

        plend();

        outputPlotIm(im, trueColor, plotIm);
    }
    catch (...)
    {
        GERROR_STREAM("Errors happened in plotCurves(xlim, ylim) ... ");
        return false;
    }

    return true;
}
Example #27
0
int
main( int argc, const char *argv[] )
{
    int   i, j, k;
    int   npts = 0;
    PLFLT xextreme[10][2];
    PLFLT yextreme[10][2];
    PLFLT x0[10];
    PLFLT y0[10];

// Parse and process command line arguments

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

// Initialize plplot

    plssub( 3, 3 );
    plinit();

    xextreme[0][0] = -120.0; xextreme[0][1] = 120.0; yextreme[0][0] = -120.0; yextreme[0][1] = 120.0;
    xextreme[1][0] = -120.0; xextreme[1][1] = 120.0; yextreme[1][0] = 20.0; yextreme[1][1] = 120.0;
    xextreme[2][0] = -120.0; xextreme[2][1] = 120.0; yextreme[2][0] = -20.0; yextreme[2][1] = 120.0;
    xextreme[3][0] = -80.0; xextreme[3][1] = 80.0; yextreme[3][0] = -20.0; yextreme[3][1] = 120.0;
    xextreme[4][0] = -220.0; xextreme[4][1] = -120.0; yextreme[4][0] = -120.0; yextreme[4][1] = 120.0;
    xextreme[5][0] = -20.0; xextreme[5][1] = 20.0; yextreme[5][0] = -120.0; yextreme[5][1] = 120.0;
    xextreme[6][0] = -20.0; xextreme[6][1] = 20.0; yextreme[6][0] = -20.0; yextreme[6][1] = 20.0;
    xextreme[7][0] = -80.0; xextreme[7][1] = 80.0; yextreme[7][0] = -80.0; yextreme[7][1] = 80.0;
    xextreme[8][0] = 20.0; xextreme[8][1] = 120.0; yextreme[8][0] = -120.0; yextreme[8][1] = 120.0;

    for ( k = 0; k < 2; k++ )
    {
        for ( j = 0; j < 4; j++ )
        {
            if ( j == 0 )
            {
// Polygon 1: a diamond
                x0[0] = 0; y0[0] = -100;
                x0[1] = -100; y0[1] = 0;
                x0[2] = 0; y0[2] = 100;
                x0[3] = 100; y0[3] = 0;
                npts  = 4;
            }
            if ( j == 1 )
            {
// Polygon 1: a diamond - reverse direction
                x0[3] = 0; y0[3] = -100;
                x0[2] = -100; y0[2] = 0;
                x0[1] = 0; y0[1] = 100;
                x0[0] = 100; y0[0] = 0;
                npts  = 4;
            }
            if ( j == 2 )
            {
// Polygon 2: a square with punctures
                x0[0] = -100; y0[0] = -100;
                x0[1] = -100; y0[1] = -80;
                x0[2] = 80; y0[2] = 0;
                x0[3] = -100; y0[3] = 80;
                x0[4] = -100; y0[4] = 100;
                x0[5] = -80; y0[5] = 100;
                x0[6] = 0; y0[6] = 80;
                x0[7] = 80; y0[7] = 100;
                x0[8] = 100; y0[8] = 100;
                x0[9] = 100; y0[9] = -100;
                npts  = 10;
            }
            if ( j == 3 )
            {
// Polygon 2: a square with punctures - reversed direction
                x0[9] = -100; y0[9] = -100;
                x0[8] = -100; y0[8] = -80;
                x0[7] = 80; y0[7] = 0;
                x0[6] = -100; y0[6] = 80;
                x0[5] = -100; y0[5] = 100;
                x0[4] = -80; y0[4] = 100;
                x0[3] = 0; y0[3] = 80;
                x0[2] = 80; y0[2] = 100;
                x0[1] = 100; y0[1] = 100;
                x0[0] = 100; y0[0] = -100;
                npts  = 10;
            }

            for ( i = 0; i < 9; i++ )
            {
                pladv( 0 );
                plvsta();
                plwind( xextreme[i][0], xextreme[i][1], yextreme[i][0], yextreme[i][1] );

                plcol0( 2 );
                plbox( "bc", 1.0, 0, "bcnv", 10.0, 0 );
                plcol0( 1 );
                plpsty( 0 );
                if ( k == 0 )
                    plfill( npts, x0, y0 );
                else
                    plgradient( npts, x0, y0, 45. );
                plcol0( 2 );
                pllsty( 1 );
                plline( npts, x0, y0 );
            }
        }
    }

// Don't forget to call plend() to finish off!

    plend();
    exit( 0 );
}
Example #28
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
    }
}
Example #29
0
int
main( int argc, const char *argv[] )
{
    int      i, j, k;
    PLFLT    *x, *y, **z, *z_row_major, *z_col_major;
    PLFLT    dx = 2. / (PLFLT) ( XPTS - 1 );
    PLFLT    dy = 2. / (PLFLT) ( YPTS - 1 );
    PLfGrid2 grid_c, grid_row_major, grid_col_major;
    PLFLT    xx, yy, r;
    PLINT    ifshade;
    PLFLT    zmin, zmax, step;
    PLFLT    clevel[LEVELS];
    PLINT    nlevel = LEVELS;

    PLINT    indexxmin = 0;
    PLINT    indexxmax = XPTS;
    PLINT    *indexymin;
    PLINT    *indexymax;
    PLFLT    **zlimited;
    // parameters of ellipse (in x, y index coordinates) that limits the data.
    // x0, y0 correspond to the exact floating point centre of the index
    // range.
    PLFLT x0 = 0.5 * (PLFLT) ( XPTS - 1 );
    PLFLT a  = 0.9 * x0;
    PLFLT y0 = 0.5 * (PLFLT) ( YPTS - 1 );
    PLFLT b  = 0.7 * y0;
    PLFLT square_root;

    // Parse and process command line arguments
    plMergeOpts( options, "x08c options", NULL );
    (void) plparseopts( &argc, argv, PL_PARSE_FULL );

    // Initialize plplot

    plinit();

// Allocate data structures

    x = (PLFLT *) calloc( XPTS, sizeof ( PLFLT ) );
    y = (PLFLT *) calloc( YPTS, sizeof ( PLFLT ) );

    plAlloc2dGrid( &z, XPTS, YPTS );
    z_row_major = (PLFLT *) malloc( XPTS * YPTS * sizeof ( PLFLT ) );
    z_col_major = (PLFLT *) malloc( XPTS * YPTS * sizeof ( PLFLT ) );
    if ( !z_row_major || !z_col_major )
        plexit( "Memory allocation error" );

    grid_c.f         = z;
    grid_row_major.f = (PLFLT **) z_row_major;
    grid_col_major.f = (PLFLT **) z_col_major;
    grid_c.nx        = grid_row_major.nx = grid_col_major.nx = XPTS;
    grid_c.ny        = grid_row_major.ny = grid_col_major.ny = YPTS;

    for ( i = 0; i < XPTS; i++ )
    {
        x[i] = -1. + (PLFLT) i * dx;
        if ( rosen )
            x[i] *= 1.5;
    }

    for ( j = 0; j < YPTS; j++ )
    {
        y[j] = -1. + (PLFLT) j * dy;
        if ( rosen )
            y[j] += 0.5;
    }

    for ( i = 0; i < XPTS; i++ )
    {
        xx = x[i];
        for ( j = 0; j < YPTS; j++ )
        {
            yy = y[j];
            if ( rosen )
            {
                z[i][j] = pow( 1. - xx, 2. ) + 100. * pow( yy - pow( xx, 2. ), 2. );

                // The log argument might be zero for just the right grid.
                if ( z[i][j] > 0. )
                    z[i][j] = log( z[i][j] );
                else
                    z[i][j] = -5.; // -MAXFLOAT would mess-up up the scale
            }
            else
            {
                r       = sqrt( xx * xx + yy * yy );
                z[i][j] = exp( -r * r ) * cos( 2.0 * M_PI * r );
            }

            z_row_major[i * YPTS + j] = z[i][j];
            z_col_major[i + XPTS * j] = z[i][j];
        }
    }

    // Allocate and calculate y index ranges and corresponding zlimited.
    plAlloc2dGrid( &zlimited, XPTS, YPTS );
    indexymin = (PLINT *) malloc( XPTS * sizeof ( PLINT ) );
    indexymax = (PLINT *) malloc( XPTS * sizeof ( PLINT ) );
    if ( !indexymin || !indexymax )
        plexit( "Memory allocation error" );

    //printf("XPTS = %d\n", XPTS);
    //printf("x0 = %f\n", x0);
    //printf("a = %f\n", a);
    //printf("YPTS = %d\n", YPTS);
    //printf("y0 = %f\n", y0);
    //printf("b = %f\n", b);

    // These values should all be ignored because of the i index range.
#if 0
    for ( i = 0; i < indexxmin; i++ )
    {
        indexymin[i] = 0;
        indexymax[i] = YPTS;
        for ( j = indexymin[i]; j < indexymax[i]; j++ )
            // Mark with large value to check this is ignored.
            zlimited[i][j] = 1.e300;
    }
#endif
    for ( i = indexxmin; i < indexxmax; i++ )
    {
        square_root = sqrt( 1. - MIN( 1., pow( ( (PLFLT) i - x0 ) / a, 2. ) ) );
        // Add 0.5 to find nearest integer and therefore preserve symmetry
        // with regard to lower and upper bound of y range.
        indexymin[i] = MAX( 0, (PLINT) ( 0.5 + y0 - b * square_root ) );
        // indexymax calculated with the convention that it is 1
        // greater than highest valid index.
        indexymax[i] = MIN( YPTS, 1 + (PLINT) ( 0.5 + y0 + b * square_root ) );
        //printf("i, b*square_root, indexymin[i], YPTS - indexymax[i] = %d, %e, %d, %d\n", i, b*square_root, indexymin[i], YPTS - indexymax[i]);

#if 0
        // These values should all be ignored because of the j index range.
        for ( j = 0; j < indexymin[i]; j++ )
            // Mark with large value to check this is ignored.
            zlimited[i][j] = 1.e300;
#endif

        for ( j = indexymin[i]; j < indexymax[i]; j++ )
            zlimited[i][j] = z[i][j];

#if 0
        // These values should all be ignored because of the j index range.
        for ( j = indexymax[i]; j < YPTS; j++ )
            // Mark with large value to check this is ignored.
            zlimited[i][j] = 1.e300;
#endif
    }

#if 0
    // These values should all be ignored because of the i index range.
    for ( i = indexxmax; i < XPTS; i++ )
    {
        indexymin[i] = 0;
        indexymax[i] = YPTS;
        for ( j = indexymin[i]; j < indexymax[i]; j++ )
            // Mark with large value to check this is ignored.
            zlimited[i][j] = 1.e300;
    }
#endif

    plMinMax2dGrid( (const PLFLT * const *) z, XPTS, YPTS, &zmax, &zmin );
    step = ( zmax - zmin ) / ( nlevel + 1 );
    for ( i = 0; i < nlevel; i++ )
        clevel[i] = zmin + step + step * i;

    pllightsource( 1., 1., 1. );

    for ( k = 0; k < 2; k++ )
    {
        for ( ifshade = 0; ifshade < 5; ifshade++ )
        {
            pladv( 0 );
            plvpor( 0.0, 1.0, 0.0, 0.9 );
            plwind( -1.0, 1.0, -0.9, 1.1 );
            plcol0( 3 );
            plmtex( "t", 1.0, 0.5, 0.5, title[k] );
            plcol0( 1 );
            if ( rosen )
                plw3d( 1.0, 1.0, 1.0, -1.5, 1.5, -0.5, 1.5, zmin, zmax, alt[k], az[k] );
            else
                plw3d( 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, zmin, zmax, alt[k], az[k] );

            plbox3( "bnstu", "x axis", 0.0, 0,
                "bnstu", "y axis", 0.0, 0,
                "bcdmnstuv", "z axis", 0.0, 0 );
            plcol0( 2 );

            if ( ifshade == 0 ) // diffuse light surface plot
            {
                cmap1_init( 1 );
                plfsurf3d( x, y, plf2ops_c(), (PLPointer) z, XPTS, YPTS, 0, NULL, 0 );
            }
            else if ( ifshade == 1 ) // magnitude colored plot
            {
                cmap1_init( 0 );
                plfsurf3d( x, y, plf2ops_grid_c(), ( PLPointer ) & grid_c, XPTS, YPTS, MAG_COLOR, NULL, 0 );
            }
            else if ( ifshade == 2 ) //  magnitude colored plot with faceted squares
            {
                cmap1_init( 0 );
                plfsurf3d( x, y, plf2ops_grid_row_major(), ( PLPointer ) & grid_row_major, XPTS, YPTS, MAG_COLOR | FACETED, NULL, 0 );
            }
            else if ( ifshade == 3 ) // magnitude colored plot with contours
            {
                cmap1_init( 0 );
                plfsurf3d( x, y, plf2ops_grid_col_major(), ( PLPointer ) & grid_col_major, XPTS, YPTS, MAG_COLOR | SURF_CONT | BASE_CONT, clevel, nlevel );
            }
            else // magnitude colored plot with contours and index limits.
            {
                cmap1_init( 0 );
                plsurf3dl( x, y, (const PLFLT * const *) zlimited, XPTS, YPTS, MAG_COLOR | SURF_CONT | BASE_CONT, clevel, nlevel, indexxmin, indexxmax, indexymin, indexymax );
            }
        }
    }

// Clean up

    free( (void *) x );
    free( (void *) y );
    plFree2dGrid( z, XPTS, YPTS );
    free( (void *) z_row_major );
    free( (void *) z_col_major );

    plFree2dGrid( zlimited, XPTS, YPTS );
    free( (void *) indexymin );
    free( (void *) indexymax );

    plend();

    exit( 0 );
}
Example #30
0
int
main(int argc, char *argv[])
{
    int i, j;
    PLFLT dtr, theta, dx, dy, r;
    char text[4];
    static PLFLT x0[361], y0[361];
    static 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);
    }

/* Parse and process command line arguments */

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

/* Initialize plplot */

    plinit();

/* 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");

/* Close the plot at end */

    plend();
    exit(0);
}