1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
#!/usr/bin/env python
import math
from numpy import *
from pl import *
import sys
import os
module_dir = "@MODULE_DIR@"
if module_dir[0] == '@':
module_dir = os.getcwd ()
sys.path.insert (0, module_dir)
#define XPTS 35 /* Data points in x */
#define YPTS 46 /* Datat points in y */
xpts = 35
ypts = 46
#define XSPA 2./(XPTS-1)
#define YSPA 2./(YPTS-1)
##static PLFLT clevel[11] =
##{-1., -.8, -.6, -.4, -.2, 0, .2, .4, .6, .8, 1.};
clevel = array( [-1., -.8, -.6, -.4, -.2, 0, .2, .4, .6, .8, 1.] )
#/* Transformation function */
##PLFLT tr[6] =
##/*{XSPA, 0.0, -1.0, 0.0, YSPA, -1.0};*/
##{1.0, 0.0, 0.0, 0.0, 1.0, 0.0};
##
##void
##mypltr(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, void *pltr_data)
##{
## *tx = tr[0] * x + tr[1] * y + tr[2];
## *ty = tr[3] * x + tr[4] * y + tr[5];
##}
##/*--------------------------------------------------------------------------*\
## * main
## *
## * Does several contour plots using different coordinate mappings.
##\*--------------------------------------------------------------------------*/
##
##int
##main(int argc, char *argv[])
##{
def main():
## int i, j;
## PLFLT xx, yy, argx, argy, distort;
## static PLINT mark = 1500, space = 1500;
mark = 1500
space = 1500
## PLFLT **z, **w;
## PLFLT xg1[XPTS], yg1[YPTS];
## PLcGrid cgrid1;
## PLcGrid2 cgrid2;
##
##/* 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;
## }
## }
z = zeros( xpts, ypts )
w = zeros( xpts, ypts )
for i in range(xpts):
xx = (i - .5*xpts) / (.5*xpts)
for j in range(ypts):
yy = (j - .5*ypts) / (.5*ypts) - 1.
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 * PI/2;
## argy = yy * 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);
## */
## plenv(.0, 1.*XPTS, .0, 1.*YPTS, 0, 0);
## plcol0(2);
##/* plcont(z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL);
## */
## plcont(z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, pltr0, NULL);
## plstyl(1, &mark, &space);
## plcol0(3);
##/* plcont(w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL);
## */
## plcont(w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, pltr0, NULL);
## plstyl(0, &mark, &space);
## plcol0(1);
## pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
plenv( 0., 1.*xpts, 0., 1.*ypts, 0, 0 )
plcol0(2)
plcont2( z, 1, xpts, 1, ypts, clevel )
plstyl( 1, mark, space )
plcol0(3)
plcont2( w, 1, 1.*xpts, 1, 1.*ypts, clevel )
plstyl( 0, mark, space )
# other stuff
plcol0(1)
pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
pleop()
main()
|