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 ); }
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]] ); } } }
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 ); }
void plfshades( PLF2OPS zops, PLPointer zp, PLINT nx, PLINT ny, PLINT ( *defined )( PLFLT, PLFLT ), PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, const PLFLT *clevel, PLINT nlevel, PLFLT fill_width, PLINT cont_color, PLFLT cont_width, void ( *fill )( PLINT, const PLFLT *, const PLFLT * ), PLINT rectangular, void ( *pltr )( PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer ), PLPointer pltr_data ) { PLFLT shade_min, shade_max, shade_color; PLINT i, init_color; PLFLT init_width, color_min, color_max, color_range; // Color range to use color_min = plsc->cmap1_min; color_max = plsc->cmap1_max; color_range = color_max - color_min; for ( i = 0; i < nlevel - 1; i++ ) { shade_min = clevel[i]; shade_max = clevel[i + 1]; shade_color = color_min + i / (PLFLT) ( nlevel - 2 ) * color_range; // 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 plfshade1( zops, zp, 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 ); plwidth( cont_width ); if ( pltr ) { plfcont( zops->f2eval, zp, nx, ny, 1, nx, 1, ny, clevel, nlevel, pltr, pltr_data ); } else { // For this case use the same interpretation that occurs internally // for plshade. That is set up x and y grids that map from the // index ranges to xmin, xmax, ymin, ymax, and use those grids // for the plcont call. // PLcGrid cgrid1; PLFLT *x, *y; cgrid1.nx = nx; cgrid1.ny = ny; x = (PLFLT *) malloc( (size_t) nx * sizeof ( PLFLT ) ); if ( x == NULL ) plexit( "plfshades: Out of memory for x" ); cgrid1.xg = x; for ( i = 0; i < nx; i++ ) cgrid1.xg[i] = xmin + ( xmax - xmin ) * (float) i / (float) ( nx - 1 ); y = (PLFLT *) malloc( (size_t) ny * sizeof ( PLFLT ) ); if ( y == NULL ) plexit( "plfshades: Out of memory for y" ); cgrid1.yg = y; for ( i = 0; i < ny; i++ ) cgrid1.yg[i] = ymin + ( ymax - ymin ) * (float) i / (float) ( ny - 1 ); plfcont( zops->f2eval, zp, nx, ny, 1, nx, 1, ny, clevel, nlevel, pltr1, (void *) &cgrid1 ); free( x ); free( y ); } plcol0( init_color ); plwidth( init_width ); } }
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 ); }
static void plplot_setup_linestyle( line_attribute_type line_attr ) { pllsty(line_attr.line_style); /* Setting solid/dashed/... */ plwidth(line_attr.line_width * PLOT_DEFAULT_LINE_WIDTH); /* Setting line width.*/ plcol0(line_attr.line_color); /* Setting line color. */ }