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); }
void c_plhist(PLINT n, PLFLT *data, PLFLT datmin, PLFLT datmax, PLINT nbin, PLINT flags) { PLINT i, bin; PLFLT *x, *y, dx, ymax; if (plsc->level < 1) { plabort("plhist: Please call plinit first"); return; } if (plsc->level < 3 && (flags & 1)) { plabort("plhist: Please set up window first"); return; } if (datmin >= datmax) { plabort("plhist: Data range invalid"); return; } if ( ! (x = (PLFLT *) malloc((size_t) nbin * sizeof(PLFLT)))) { plabort("plhist: Out of memory"); return; } if ( ! (y = (PLFLT *) malloc((size_t) nbin * sizeof(PLFLT)))) { free((void *) x); plabort("plhist: Out of memory"); return; } dx = (datmax - datmin) / nbin; for (i = 0; i < nbin; i++) { x[i] = datmin + i * dx; y[i] = 0.0; } for (i = 0; i < n; i++) { bin = (data[i] - datmin) / dx; if ((flags & 2) == 0) { bin = bin > 0 ? bin : 0; bin = bin < nbin ? bin : nbin - 1; y[bin]++; } else { if(bin >= 0 && bin < nbin) { y[bin]++; } } } if (!(flags & 1)) { ymax = 0.0; for (i = 0; i < nbin; i++) ymax = MAX(ymax, y[i]); plenv(datmin, datmax, (PLFLT) 0.0, (PLFLT) (1.1 * ymax), 0, 0); } /* We pass on the highest couple of bits to the 'plbin' routine */ plbin(nbin, x, y, (flags & (4+8+16+32)) >> 2); free((void *) x); free((void *) y); }
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 ); }
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). */ plcol(1); plenv((PLFLT) -2.0, (PLFLT) 10.0, (PLFLT) -0.4, (PLFLT) 1.2, 0, 1); plcol(2); pllab("(x)", "sin(x)/x", "#frPLplot Example 1 - Sinc Function"); /* Fill up the arrays */ for (i = 0; i < 100; i++) { x[i] = (i - 19.0) / 6.0; y[i] = 1.0; if (x[i] != 0.0) y[i] = sin(x[i]) / x[i]; } /* Draw the line */ plcol(3); plline(100, x, y); }
void setup_plot_drawable( App *a ) { struct { Display *display; Drawable drawable; } xinfo; PLFLT x[3] = { 1, 3, 4 }; PLFLT y[3] = { 3, 2, 5 }; plsdev( "xcairo" ); plsetopt( "drvopt", "external_drawable" ); plinit(); #if TO_PIXMAP == 1 // Here we set up to draw to a pixmap xinfo.display = GDK_PIXMAP_XDISPLAY( a->plotwindow_pixmap ); xinfo.drawable = GDK_PIXMAP_XID( a->plotwindow_pixmap ); #else // Alternatively, we can do direct to a visible X Window xinfo.display = GDK_WINDOW_XDISPLAY( a->plotwindow->window ); xinfo.drawable = GDK_WINDOW_XID( a->plotwindow->window ); #endif pl_cmd( PLESC_DEVINIT, &xinfo ); plenv( 0, 5, 0, 5, 0, 0 ); plline( 3, x, y ); plend(); }
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 ); }
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; }
int main(int argc, char **argv) { enum Constexpr {n_points = 1000}; double mu = 1.0; gsl_odeiv2_system sys = {ode_func, ode_jac, 2, &mu}; gsl_odeiv2_driver * d= gsl_odeiv2_driver_alloc_y_new( &sys, gsl_odeiv2_step_rk8pd, 1e-6, 1e-6, 0.0 ); int i; double t = 0.0; double t1 = 100.0; /* Initial condition: f = 0 with speed 0. */ double y[2] = {1.0, 0.0}; double dt = t1 / n_points; double datax[n_points]; double datay[n_points]; for (i = 0; i < n_points; i++) { double ti = i * dt; int status = gsl_odeiv2_driver_apply(d, &t, ti, y); if (status != GSL_SUCCESS) { fprintf(stderr, "error, return value=%d\n", status); break; } /* Get output. */ printf("%.5e %.5e %.5e\n", t, y[0], y[1]); datax[i] = y[0]; datay[i] = y[1]; } /* Cleanup. */ gsl_odeiv2_driver_free(d); /* Plot. */ if (argc > 1 && argv[1][0] == '1') { plsdev("xwin"); plinit(); plenv( gsl_stats_min(datax, 1, n_points), gsl_stats_max(datax, 1, n_points), gsl_stats_min(datay, 1, n_points), gsl_stats_max(datay, 1, n_points), 0, 1 ); plstring(n_points, datax, datay, "*"); plend(); } return EXIT_SUCCESS; }
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 ); }
int main( int argc, const char *argv[] ) { cairo_surface_t *cairoSurface; cairo_t *cairoContext; cairoSurface = cairo_ps_surface_create( "ext-cairo-test.ps", 720, 540 ); cairoContext = cairo_create( cairoSurface ); plparseopts( &argc, argv, PL_PARSE_FULL ); plsdev( "extcairo" ); plinit(); pl_cmd( PLESC_DEVINIT, cairoContext ); plenv( 0.0, 1.0, 0.0, 1.0, 1, 0 ); pllab( "x", "y", "title" ); plend(); cairo_destroy( cairoContext ); cairo_surface_destroy( cairoSurface ); exit( 0 ); }
int main( int argc, const char *argv[] ) { PLFLT x[NSIZE], y[NSIZE]; PLFLT xmin = 0., xmax = 1., ymin = 0., ymax = 100.; for (int i = 0; i < NSIZE; i++) { x[i] = (PLFLT) (i) / (PLFLT) (NSIZE-1); y[i] = ymax * x[i] * x[i]; } plparseopts( &argc, argv, PL_PARSE_FULL ); plinit(); plenv(xmin, xmax, ymin, ymax, 0, 0); pllab("x", "y", "Simple PLplot demo of a 2D line plot"); plline(NSIZE, x, y); plend(); return 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); }
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 ); }
struct fft_average *do_fft(double *in, int max) { fftw_complex *out; double *fft_in; fftw_plan p; int i; double xmax = 0, xmin = 0, ymin = 0, ymax = 0; double average = 0; struct fft_average *avg; avg = malloc(sizeof(struct fft_average)); if (!avg) exit(1); fft_in = (double *)fftw_malloc(sizeof(double) * max); out = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * max); p = fftw_plan_dft_r2c_1d(max, fft_in, out, FFTW_PRESERVE_INPUT); for (i = 0; i < max; i++) fft_in[i] = in[i]; // memcpy(fft_in, in, sizeof(double) * max); fftw_execute(p); for (i = 0; i < max; i++) { double *d; d = out[i]; if (d[0] > xmax) xmax = d[0]; else if (d[0] < xmin) xmin = d[0]; if (d[1] > ymax) ymax = d[1]; else if (d[1] < ymin) ymin = d[1]; } plsdev("xwin"); plinit(); plenv(-1, 1, -1, 1, 0, 0); for (i = 0; i < max; i++) { PLFLT x; PLFLT y; double *d; d = out[i]; if (d[0] < 0) { x = d[0] / -xmin; avg->xavg += (d[0] / -xmin); if (i > 0) avg->xavg /= 2; } else { x = d[0] / xmax; avg->xavg += (d[0] / xmax); if (i > 0) avg->xavg /= 2; } if (d[1] < 0) { y = d[1] / -ymin; avg->yavg += (d[1] / -ymin); if (i > 0) avg->yavg /= 2; } else { y = d[1] / ymax; avg->yavg += (d[1] / ymax); if (i > 0) avg->yavg /= 2; } plpoin(1, &x, &y, 1); } plend(); fftw_destroy_plan(p); fftw_free(fft_in); fftw_free(out); return avg; }
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 ); }
int main( int argc, char **argv ) { PLFLT minx, maxx, miny, maxy; PLFLT x, y; //variables for the shapelib example const PLINT nbeachareas = 2; const PLINT beachareas[] = { 23, 24 }; const PLINT nwoodlandareas = 94; PLINT woodlandareas[94]; const PLINT nshingleareas = 22; const PLINT shingleareas[] = { 0, 1, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 217, 2424, 2425, 2426, 2427, 2428, 2491, 2577 }; const PLINT ncragareas = 2024; PLINT cragareas[2024]; const PLINT majorroads[] = { 33, 48, 71, 83, 89, 90, 101, 102, 111 }; int i; // 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 = -170; maxx = minx + 360; // Setup a custom latitude and longitude-based scaling function. plslabelfunc( geolocation_labeler, NULL ); plcol0( 1 ); plenv( minx, maxx, miny, maxy, 1, 70 ); plmap( NULL, "usaglobe", minx, maxx, miny, maxy ); // The Americas minx = 190; maxx = 340; plcol0( 1 ); plenv( minx, maxx, miny, maxy, 1, 70 ); plmap( NULL, "usaglobe", minx, maxx, miny, maxy ); // Clear the labeling function plslabelfunc( NULL, NULL ); // 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 ); // Polar, Northern hemisphere, this time with a PLplot-wide transform minx = 0; maxx = 360; plstransform( map_transform, NULL ); pllsty( 1 ); plenv( -75., 75., -75., 75., 1, -1 ); // No need to set the map transform here as the global transform will be // used. plmap( NULL, "globe", minx, maxx, miny, maxy ); pllsty( 2 ); plmeridians( NULL, 10.0, 10.0, 0.0, 360.0, -10.0, 80.0 ); // Show Baltimore, MD on the map plcol0( 2 ); plssym( 0.0, 2.0 ); x = -76.6125; y = 39.2902778; plpoin( 1, &x, &y, 18 ); plssym( 0.0, 1.0 ); plptex( -76.6125, 43.0, 0.0, 0.0, 0.0, "Baltimore, MD" ); // For C, this is how the global transform is cleared plstransform( NULL, NULL ); // An example using shapefiles. The shapefiles used are from Ordnance Survey, UK. // These were chosen because they provide shapefiles for small grid boxes which // are easilly manageable for this demo. pllsty( 1 ); minx = 240570; maxx = 621109; miny = 87822; maxy = 722770; plscol0( 0, 255, 255, 255 ); plscol0( 1, 0, 0, 0 ); plscol0( 2, 150, 150, 150 ); plscol0( 3, 0, 50, 200 ); plscol0( 4, 50, 50, 50 ); plscol0( 5, 150, 0, 0 ); plscol0( 6, 100, 100, 255 ); minx = 265000; maxx = 270000; miny = 145000; maxy = 150000; plscol0( 0, 255, 255, 255 ); //white plscol0( 1, 0, 0, 0 ); //black plscol0( 2, 255, 200, 0 ); //yelow for sand plscol0( 3, 60, 230, 60 ); // green for woodland plscol0( 4, 210, 120, 60 ); //brown for contours plscol0( 5, 150, 0, 0 ); //red for major roads plscol0( 6, 180, 180, 255 ); //pale blue for water plscol0( 7, 100, 100, 100 ); //pale grey for shingle or boulders plscol0( 8, 100, 100, 100 ); //dark grey for custom polygons - generally crags plcol0( 1 ); plenv( minx, maxx, miny, maxy, 1, -1 ); pllab( "", "", "Martinhoe CP, Exmoor National Park, UK (shapelib only)" ); //Beach plcol0( 2 ); plmapfill( NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, beachareas, nbeachareas ); //woodland plcol0( 3 ); for ( i = 0; i < nwoodlandareas; ++i ) woodlandareas[i] = i + 218; plmapfill( NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, (PLINT_VECTOR) woodlandareas, nwoodlandareas ); //shingle or boulders plcol0( 7 ); plmapfill( NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, shingleareas, nshingleareas ); //crags plcol0( 8 ); for ( i = 0; i < ncragareas; ++i ) cragareas[i] = i + 325; plmapfill( NULL, "ss/ss64ne_Landform_Area", minx, maxx, miny, maxy, (PLINT_VECTOR) cragareas, ncragareas ); //draw contours, we need to separate contours from high/low coastline //draw_contours(pls, "ss/SS64_line", 433, 20, 4, 3, minx, maxx, miny, maxy ); plcol0( 4 ); plmapline( NULL, "ss/ss64ne_Height_Contours", minx, maxx, miny, maxy, NULL, 0 ); //draw the sea and surface water plwidth( 0.0 ); plcol0( 6 ); plmapfill( NULL, "ss/ss64ne_Water_Area", minx, maxx, miny, maxy, NULL, 0 ); plwidth( 2.0 ); plmapfill( NULL, "ss/ss64ne_Water_Line", minx, maxx, miny, maxy, NULL, 0 ); //draw the roads, first with black and then thinner with colour to give an //an outlined appearance plwidth( 5.0 ); plcol0( 1 ); plmapline( NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, NULL, 0 ); plwidth( 3.0 ); plcol0( 0 ); plmapline( NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, NULL, 0 ); plcol0( 5 ); plmapline( NULL, "ss/ss64ne_Road_Centreline", minx, maxx, miny, maxy, majorroads, 9 ); //draw buildings plwidth( 1.0 ); plcol0( 1 ); plmapfill( NULL, "ss/ss64ne_Building_Area", minx, maxx, miny, maxy, NULL, 0 ); //labels plsfci( 0x80000100 ); plschr( 0, 0.8 ); plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "MARTINHOE CP", minx, maxx, miny, maxy, 202 ); plschr( 0, 0.7 ); plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Heale\nDown", minx, maxx, miny, maxy, 13 ); plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "South\nDown", minx, maxx, miny, maxy, 34 ); plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Martinhoe\nCommon", minx, maxx, miny, maxy, 42 ); plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Woody Bay", minx, maxx, miny, maxy, 211 ); plschr( 0, 0.6 ); plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Mill Wood", minx, maxx, miny, maxy, 16 ); plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Heale Wood", minx, maxx, miny, maxy, 17 ); plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 1.0, "Bodley", minx, maxx, miny, maxy, 31 ); plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.0, "Martinhoe", minx, maxx, miny, maxy, 37 ); plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Woolhanger\nCommon", minx, maxx, miny, maxy, 60 ); plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "West Ilkerton\nCommon", minx, maxx, miny, maxy, 61 ); plmaptex( NULL, "ss/ss64ne_General_Text", 1.0, 0.0, 0.5, "Caffyns\nHeanton\nDown", minx, maxx, miny, maxy, 62 ); plend(); exit( 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 } }
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); }
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(); }
/* * Plot specified x/y coordinates, x as int32_t and y as float, with an arbitrary number * of separate lines, as lines and/or points. * Output is PDF file, location specified by 'fileName'. */ int plplotLines( PlplotSetup *setup, uint32_t numSamples, /* size of ix[] and fy[] arrays */ uint32_t numLines, /* size of lineDef[] array */ int32_t *ix, /* numSamples */ LineDef *lineDef, /* numLines */ const char *graphName, const char *fileName, bool plotPoints, /* true: plot points */ bool plotLine, /* true: plot line */ bool skipTrailZeroes) /* don't plot zero Y values at end of graph */ { if(setup == NULL) { printf("***plplotLine: setup required\n"); return -1; } char tmpFile[TEMP_FN_LEN]; makeTempFile(tmpFile, TEMP_FN_LEN); PLFLT fx[numSamples]; PLFLT minX = setup->minX; PLFLT maxX = setup->maxX; PLFLT minY = setup->minY; PLFLT maxY = setup->maxY; for(uint32_t dex=0; dex<numSamples; dex++) { fx[dex] = ix[dex]; } const char *yName = ""; if(setup->yAxisName) { yName = setup->yAxisName; } const char *xName = ""; if(setup->xAxisName) { xName = setup->xAxisName; } plsdev ("psc"); /* standard: background white, foreground (axes, labels, etc.) black */ plscolbg(PLOT_WHITE); plscol0(1, PLOT_BLACK); plsfnam(tmpFile); plsdiori(1.0); // portrait plinit(); plenv(minX, maxX, minY, maxY, 0, 0); pllab(xName, yName, graphName); for(uint32_t dex=0; dex<numLines; dex++) { uint32_t thisSamples = numSamples; if(skipTrailZeroes) { while((lineDef[dex].fy[thisSamples-1] == 0.0) && (thisSamples > 0)) { thisSamples--; } if(thisSamples == 0) { printf("***plplotLines: Warning: line with all zeroes skipped\n"); continue; } } plotOneLine(thisSamples, fx, &lineDef[dex], plotPoints, plotLine); } plend(); int ourRtn = psToPdf(tmpFile, fileName); unlink(tmpFile); return ourRtn; }
/* * Plot a histogram of prebinned data. X values are int32_t's, and the corresponding * Y values - the counts for each X - are uint32_t's. */ int plplotBins( uint32_t numBins, const int32_t *x, /* numBins of X values, monotonically increasing */ const uint32_t *y, /* numBins of Y values for each associated X */ const char *graphName, const char *fileName, const char *xAxisName, /* optional */ const char *yAxisName) /* optional */ { char tmpFile[TEMP_FN_LEN]; makeTempFile(tmpFile, TEMP_FN_LEN); PLINT totalBins = numBins + 2; /* PLFLT array of sample values */ PLFLT *xf = (PLFLT *)malloc(totalBins * sizeof(PLFLT)); /* these two will have Y values of zero */ xf[0] = x[0] - 1; xf[totalBins - 1] = x[numBins-1] + 1; const int32_t *ip = x; PLFLT *op = xf + 1; for(uint32_t dex=0; dex<numBins; dex++) { *op++ = *ip++; } /* PLFLT array of bins */ PLFLT *yf = (PLFLT *)malloc(totalBins * sizeof(PLFLT)); yf[0] = 0.0; yf[totalBins - 1] = 0.0; const uint32_t *uip = y; op = yf + 1; for(uint32_t dex=0; dex<numBins; dex++) { *op++ = *uip++; } /* get max Y value */ uint32_t maxY = 0; uip = y; for(uint32_t dex=0; dex<numBins; dex++) { uint32_t currY = *uip++; if(currY > maxY) { maxY = currY; } } const char *yName = yAxisName ? yAxisName : ""; const char *xName = xAxisName ? xAxisName : ""; #if HIST_COLOR plsdev ("psc"); plscolbg(255, 255, 255); /* white background */ #else plsdev ("ps"); #endif plsfnam(tmpFile); plsdiori(1.0); // portrait plinit(); plenv(xf[0], xf[totalBins - 1], 0, maxY, 0, 0); #if HIST_COLOR /* can we alter colors of lines and the spaces inside the histograms? */ plscolbg(255, 0, 0); /* red background */ plscol0(1, 255, 0, 0); /* red foreground - no effect */ #endif pllab(xName, yName, graphName); plbin(totalBins, xf, yf, PL_BIN_CENTRED); plend(); free(xf); free(yf); int ourRtn = psToPdf(tmpFile, fileName); unlink(tmpFile); return ourRtn; }
/* * Plot a histogram showing the number of occurences of each possible * value of 'samples'. */ int plplotHist( const int32_t *samples, uint32_t numSamples, const char *graphName, const char *fileName, const char *xAxisName, /* optional */ const char *yAxisName) /* optional */ { char tmpFile[TEMP_FN_LEN]; makeTempFile(tmpFile, TEMP_FN_LEN); /* First determine the range, i.e. the number of bins */ int32_t minSamp = samples[0]; int32_t maxSamp = samples[0]; for(uint32_t dex=0; dex<numSamples; dex++) { int32_t s = samples[dex]; if(s < minSamp) { minSamp = s; } if(s > maxSamp) { maxSamp = s; } } /* When we specify PL_BIN_CENTRED, the min and max values are half the normal width */ minSamp--; maxSamp++; PLINT numBins = maxSamp - minSamp + 1; /* One array containing the sample values, x */ PLFLT *x = (PLFLT *)malloc(numBins * sizeof(PLFLT)); int32_t binNum = minSamp; for(uint32_t dex=0; dex<(uint32_t)numBins; dex++) { x[dex] = binNum++; } /* Now make and fill the bins proper */ PLFLT *y = (PLFLT *)malloc(numBins * sizeof(PLFLT)); for(uint32_t dex=0; dex<(uint32_t)numBins; dex++) { y[dex] = 0; } PLFLT maxY = 0.0; for(uint32_t dex=0; dex<numSamples; dex++) { int32_t s = samples[dex]; PLFLT *yp = y + s - minSamp; *yp += 1.0; if(*yp > maxY) { maxY = *yp; } } const char *yName = yAxisName ? yAxisName : ""; const char *xName = xAxisName ? xAxisName : ""; #if HIST_COLOR plsdev ("psc"); plscolor(1); plscolbg(255, 255, 255); /* white background */ #else plsdev ("ps"); #endif plsfnam(tmpFile); plsdiori(1.0); // portrait plinit(); plenv(minSamp, maxSamp, 0, maxY, 0, 0); #if HIST_COLOR /* can we alter colors of lines and the spaces inside the histograms? */ plscolbg(255, 0, 0); /* red background */ plscol0(1, 255, 0, 0); /* red foreground - no effect */ #endif pllab(xName, yName, graphName); plbin(numBins, x, y, PL_BIN_CENTRED); plend(); free(x); free(y); int ourRtn = psToPdf(tmpFile, fileName); unlink(tmpFile); return ourRtn; }
int main( int argc, const char *argv[] ) { int i; PLFLT dtr, theta, dx, dy, r, offset; char text[4]; static PLFLT x0[361], y0[361]; static PLFLT x[361], y[361]; dtr = M_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 ); // Set orientation to portrait - note not all device drivers // support this, in particular most interactive drivers do not plsori( 1 ); // Initialize plplot plinit(); // Set up viewport and window, but do not draw box plenv( -1.3, 1.3, -1.3, 1.3, 1, -2 ); // Draw circles for polar grid for ( i = 1; i <= 10; i++ ) { plarc( 0.0, 0.0, 0.1 * i, 0.1 * i, 0.0, 360.0, 0.0, 0 ); } 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 if ( theta < 9.99 ) { offset = 0.45; } else if ( theta < 99.9 ) { offset = 0.30; } else { offset = 0.15; } // Slightly off zero to avoid floating point logic flips at 90 and 270 deg. if ( dx >= -0.00001 ) plptex( dx, dy, dx, dy, -offset, text ); else plptex( dx, dy, -dx, -dy, 1. + offset, 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 ); }
int main(int argc, char **argv) { SNDFILE *file1, *file2; SF_INFO info1, info2; double *in1, *in2; int min_frames, i; int like = 0, unlike = 0; int total = 0; int max1, max2; struct fft_average *avg; memset(&info1, 0, sizeof(SF_INFO)); memset(&info2, 0, sizeof(SF_INFO)); if (argc < 3) { printf("compare file1 file2"); return 1; } file1 = sf_open(argv[1], SFM_READ, &info1); if (!file1) { printf("Error opening wave file %s\n", argv[1]); exit(1); } file2 = sf_open(argv[2], SFM_READ, &info2); if (!file2) { printf("Error opening wave file %s\n", argv[2]); sf_close(file2); exit(1); } /* seconds = (float)info1.frames/(float)info1.samplerate; printf("Opened %s\n", argv[1]); printf("frames: %d\n", info1.frames); printf("samplerate: %d\n", info1.samplerate); printf("length (in seconds): %f\n", seconds); printf("channels: %d\n", info1.channels); printf("format: %x\n", info1.format); printf("sections: %d\n", info1.sections); printf("seekable: %d\n", info1.seekable); */ in1 = (double *)malloc(sizeof(double) * info1.frames); if (!in1) { printf("Failed to allocate input array\n"); sf_close(file1); sf_close(file2); return 1; } in2 = (double *)malloc(sizeof(double) * info2.frames); if (!in2) { printf("Failed to allocate input array\n"); free(in1); sf_close(file1); sf_close(file2); return 1; } normalize_wave(file1, in1, info1.frames, info1.channels); normalize_wave(file2, in2, info2.frames, info2.channels); max1 = shift_wave(in1, info1.frames); max2 = shift_wave(in2, info2.frames); // max1 = find_max(in1, info1.frames); // max2 = find_max(in2, info2.frames); /* shift_wave(in1, info1.frames); shift_wave(in2, info2.frames); */ plsdev("xwin"); plinit(); plenv(0.0f, info1.frames, -1, 1, 0, 0); for (i = 0; i < info1.frames; i++) { PLFLT x; PLFLT sample = i; if (in1[i] == -2) continue; x = in1[i]; plpoin(1, &sample, &x, 1); } plend(); plsdev("xwin"); plinit(); plenv(0.0f, info2.frames, -1, 1, 0, 0); for (i = 0; i < info2.frames; i++) { PLFLT x; PLFLT sample = i; if (in2[i] == -2) continue; x = in2[i]; plpoin(1, &sample, &x, 1); } plend(); avg = do_fft(in1, max1); printf("yavg = %f, xavg=%f\n", avg->yavg, avg->xavg); free(avg); avg = do_fft(in2, max2); printf("yavg = %f, xavg=%f\n", avg->yavg, avg->xavg); free(avg); min_frames = (info1.frames < info2.frames) ? info1.frames : info2.frames; for (i = 0; i < min_frames; i++) { double diff; if (in1[i] == -2 || in2[i] == -2) break; if (in1[i] > in2[i]) diff = in1[i] - in2[i]; else diff = in2[i] - in1[i]; if (diff <= 0.05) like++; else unlike++; total++; } printf("Minimum frames: %d\n", min_frames); printf("Total compares: %d\n", total); printf("Like: %d\n", like); printf("Unlike: %d\n", unlike); printf("Percentage alike: %f\n", ((double)like / (double)total) * 100); printf("Max1: %d\n", max1); printf("Max2: %d\n", max2); free(in1); free(in2); sf_close(file1); sf_close(file2); return 0; }
int main(int argc, char *argv[]) { PLFLT *x, *y, *z, *clev; PLFLT *xg, *yg, **zg, **szg; PLFLT zmin, zmax, lzm, lzM; long ct; int i, j, k; PLINT alg; char ylab[40], xlab[40]; char *title[] = {"Cubic Spline Approximation", "Delaunay Linear Interpolation", "Natural Neighbors Interpolation", "KNN Inv. Distance Weighted", "3NN Linear Interpolation", "4NN Around Inv. Dist. Weighted"}; PLFLT opt[] = {0., 0., 0., 0., 0., 0.}; xm = ym = -0.2; xM = yM = 0.8; plMergeOpts(options, "x21c options", NULL); plparseopts(&argc, argv, PL_PARSE_FULL); opt[2] = wmin; opt[3] = (PLFLT) knn_order; opt[4] = threshold; /* Initialize plplot */ plinit(); create_data(&x, &y, &z, pts); /* the sampled data */ zmin = z[0]; zmax = z[0]; for (i=1; i<pts; i++) { if (z[i] > zmax) zmax = z[i]; if (z[i] < zmin) zmin = z[i]; } create_grid(&xg, xp, &yg, yp); /* grid the data at */ plAlloc2dGrid(&zg, xp, yp); /* the output grided data */ clev = (PLFLT *) malloc(nl * sizeof(PLFLT)); sprintf(xlab, "Npts=%d gridx=%d gridy=%d", pts, xp, yp); plcol0(1); plenv(xm, xM, ym, yM, 2, 0); plcol0(15); pllab(xlab, "", "The original data"); plcol0(2); plpoin(pts, x, y, 5); pladv(0); plssub(3,2); for (k=0; k<2; k++) { pladv(0); for (alg=1; alg<7; alg++) { ct = clock(); plgriddata(x, y, z, pts, xg, xp, yg, yp, zg, alg, opt[alg-1]); sprintf(xlab, "time=%d ms", (clock() - ct)/1000); sprintf(ylab, "opt=%.3f", opt[alg-1]); /* - CSA can generate NaNs (only interpolates?!). * - DTLI and NNI can generate NaNs for points outside the convex hull * of the data points. * - NNLI can generate NaNs if a sufficiently thick triangle is not found * * PLplot should be NaN/Inf aware, but changing it now is quite a job... * so, instead of not plotting the NaN regions, a weighted average over * the neighbors is done. */ if (alg == GRID_CSA || alg == GRID_DTLI || alg == GRID_NNLI || alg == GRID_NNI) { int ii, jj; PLFLT dist, d; for (i=0; i<xp; i++) { for (j=0; j<yp; j++) { if (isnan(zg[i][j])) { /* average (IDW) over the 8 neighbors */ zg[i][j] = 0.; dist = 0.; for (ii=i-1; ii<=i+1 && ii<xp; ii++) { for (jj=j-1; jj<=j+1 && jj<yp; jj++) { if (ii >= 0 && jj >= 0 && !isnan(zg[ii][jj])) { d = (abs(ii-i) + abs(jj-j)) == 1 ? 1. : 1.4142; zg[i][j] += zg[ii][jj]/(d*d); dist += d; } } } if (dist != 0.) zg[i][j] /= dist; else zg[i][j] = zmin; } } } } plMinMax2dGrid(zg, xp, yp, &lzM, &lzm); plcol0(1); pladv(alg); if (k == 0) { lzm = MIN(lzm, zmin); lzM = MAX(lzM, zmax); for (i=0; i<nl; i++) clev[i] = lzm + (lzM-lzm)/(nl-1)*i; plenv0(xm, xM, ym, yM, 2, 0); plcol0(15); pllab(xlab, ylab, title[alg-1]); plshades(zg, xp, yp, NULL, xm, xM, ym, yM, clev, nl, 1, 0, 1, plfill, 1, NULL, NULL); plcol0(2); } else { for (i=0; i<nl; i++) clev[i] = lzm + (lzM-lzm)/(nl-1)*i; cmap1_init(); plvpor(0.0, 1.0, 0.0, 0.9); plwind(-1.0, 1.0, -1.0, 1.5); /* * For the comparition to be fair, all plots should have the * same z values, but to get the max/min of the data generated * by all algorithms would imply two passes. Keep it simple. * * plw3d(1., 1., 1., xm, xM, ym, yM, zmin, zmax, 30, -60); */ plw3d(1., 1., 1., xm, xM, ym, yM, lzm, lzM, 30, -60); plbox3("bnstu", ylab, 0.0, 0, "bnstu", xlab, 0.0, 0, "bcdmnstuv", "", 0.0, 4); plcol0(15); pllab("", "", title[alg-1]); plot3dc(xg, yg, zg, xp, yp, DRAW_LINEXY | MAG_COLOR | BASE_CONT, clev, nl); } } } plend(); free_data(x, y, z); free_grid(xg, yg); free((void *)clev); plFree2dGrid(zg, xp, yp); }