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 ); }
void shade(void) { int i, j; PLFLT x, y, argx, argy, distort; PLFLT **z, **w, zmin, zmax; PLFLT xg1[XPTS], yg1[YPTS]; PLcGrid cgrid1; PLcGrid2 cgrid2; PLFLT shade_min, shade_max, sh_color; PLINT sh_cmap = 1, sh_width; PLINT min_color = 1, min_width = 0, max_color = 0, max_width = 0; /* Set up function arrays */ plAlloc2dGrid(&z, XPTS, YPTS); plAlloc2dGrid(&w, XPTS, YPTS); /* Set up data array */ for (i = 0; i < XPTS; i++) { x = (double) (i - (XPTS / 2)) / (double) (XPTS / 2); for (j = 0; j < YPTS; j++) { y = (double) (j - (YPTS / 2)) / (double) (YPTS / 2) - 1.0; z[i][j] = - sin(7.*x) * cos(7.*y) + x*x - y*y; w[i][j] = - cos(7.*x) * sin(7.*y) + 2 * x * y; } } f2mnmx(z, XPTS, YPTS, &zmin, &zmax); for (i = 0; i < NCONTR; i++) clevel[i] = zmin + (zmax - zmin) * (i + 0.5) / (PLFLT) NCONTR; /* Set up coordinate 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, &x, &y, NULL); argx = x * PI/2; argy = y * PI/2; distort = 0.4; cgrid1.xg[i] = x + distort * cos(argx); cgrid1.yg[j] = y - distort * cos(argy); cgrid2.xg[i][j] = x + distort * cos(argx) * cos(argy); cgrid2.yg[i][j] = y - distort * cos(argx) * cos(argy); } } /* Plot using identity transform */ pladv(0); plvpor(0.1, 0.9, 0.1, 0.9); plwind(-1.0, 1.0, -1.0, 1.0); for (i = 0; i < NCONTR; i++) { shade_min = zmin + (zmax - zmin) * i / (PLFLT) NCONTR; shade_max = zmin + (zmax - zmin) * (i +1) / (PLFLT) NCONTR; sh_color = i / (PLFLT) (NCONTR-1); sh_width = 2; plpsty(0); plshade(z, 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); } plcol(1); plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); plcol(2); /* plcont(w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, NCONTR, mypltr, NULL); */ pllab("distance", "altitude", "Bogon density"); /* Clean up */ plFree2dGrid(z, XPTS, YPTS); plFree2dGrid(w, XPTS, YPTS); plFree2dGrid(cgrid2.xg, XPTS, YPTS); plFree2dGrid(cgrid2.yg, XPTS, YPTS); }