From: <sm...@us...> - 2009-06-05 06:07:51
|
Revision: 10031 http://plplot.svn.sourceforge.net/plplot/?rev=10031&view=rev Author: smekal Date: 2009-06-05 06:07:40 +0000 (Fri, 05 Jun 2009) Log Message: ----------- Finished improvement of D bindings (more or less). Fixed example 3. Fixed example 8 and 11 due to changes in D bindings. Added D examples 16 and 26. Modified Paths: -------------- trunk/bindings/d/plplot.d trunk/examples/d/CMakeLists.txt trunk/examples/d/x03d.d trunk/examples/d/x08d.d trunk/examples/d/x11d.d Added Paths: ----------- trunk/examples/d/x16d.d trunk/examples/d/x26d.d Modified: trunk/bindings/d/plplot.d =================================================================== --- trunk/bindings/d/plplot.d 2009-06-04 15:23:16 UTC (rev 10030) +++ trunk/bindings/d/plplot.d 2009-06-05 06:07:40 UTC (rev 10031) @@ -58,8 +58,59 @@ } /* simple arrow plotter. */ -//void c_plvect(PLFLT **u, PLFLT **v, PLINT nx, PLINT ny, PLFLT scale, void function(PLFLT , PLFLT , PLFLT *, PLFLT *, PLPointer )pltr, PLPointer pltr_data); +void plvect(PLFLT[][] u, PLFLT[][] v, PLFLT scale, pltr_func pltr=null, PLPointer pltr_data=null) +{ + PLINT nx=u.length; + PLINT ny=u[0].length; + assert(nx==v.length, "plvect(): Arrays must be of same length!"); + assert(ny==v[0].length, "plvect(): Arrays must be of same length!"); + + c_plvect(convert_array(u), convert_array(v), nx, ny, scale, pltr, pltr_data); +} +void plvect(PLFLT[][] u, PLFLT[][] v, PLFLT scale, ref PLcGrid cgrid) +{ + PLINT nx=u.length; + PLINT ny=u[0].length; + assert(nx==v.length, "plvect(): Arrays must be of same length!"); + assert(ny==v[0].length, "plvect(): Arrays must be of same length!"); + + c_PLcGrid c; + c.xg = cgrid.xg.ptr; + c.nx = cgrid.xg.length; + c.yg = cgrid.yg.ptr; + c.ny = cgrid.yg.length; + c.zg = cgrid.zg.ptr; + c.nz = cgrid.zg.length; + + c_plvect(convert_array(u), convert_array(v), nx, ny, scale, &pltr1, &c); +} + +void plvect(PLFLT[][] u, PLFLT[][] v, PLFLT scale, ref PLcGrid2 cgrid2) +{ + PLINT nx=u.length; + PLINT ny=u[0].length; + assert(nx==v.length, "plvect(): Arrays must be of same length!"); + assert(ny==v[0].length, "plvect(): Arrays must be of same length!"); + + c_PLcGrid2 c2; + c2.xg = convert_array(cgrid2.xg); + c2.yg = convert_array(cgrid2.yg); + c2.zg = convert_array(cgrid2.zg); + c2.nx = cgrid2.xg.length; + c2.ny = cgrid2.xg[0].length; + if(cgrid2.yg) { + assert(c2.nx==cgrid2.yg.length, "plcont(): Arrays must be of same length!"); + assert(c2.ny==cgrid2.yg[0].length, "plcont(): Arrays must be of same length!"); + } + if(cgrid2.zg) { + assert(c2.nx==cgrid2.zg.length, "plcont(): Arrays must be of same length!"); + assert(c2.ny==cgrid2.zg[0].length, "plcont(): Arrays must be of same length!"); + } + + c_plvect(convert_array(u), convert_array(v), nx, ny, scale, &pltr2, &c2); +} + void plsvect(PLFLT[] arrowx, PLFLT[] arrowy, PLBOOL fill) { PLINT npts=arrowx.length; @@ -213,7 +264,19 @@ } /* grid irregularly sampled data */ -//void c_plgriddata(PLFLT *x, PLFLT *y, PLFLT *z, PLINT npts, PLFLT *xg, PLINT nptsx, PLFLT *yg, PLINT nptsy, PLFLT **zg, PLINT type, PLFLT data); +void plgriddata(PLFLT[] x, PLFLT[] y, PLFLT[] z, PLFLT[] xg, PLFLT[] yg, PLFLT[][] zg, PLINT type, PLFLT data) +{ + PLINT npts = x.length; + assert(npts==y.length, "plgriddata(): Arrays must be of same length!"); + assert(npts==z.length, "plgriddata(): Arrays must be of same length!"); + + PLINT nxg = xg.length; + PLINT nyg = yg.length; + assert(nxg==zg.length, "plgriddata(): Arrays must be of same length!"); + assert(nyg==zg[0].length, "plgriddata(): Arrays must be of same length!"); + + c_plgriddata(x.ptr, y.ptr, z.ptr, npts, xg.ptr, nxg, yg.ptr, nyg, convert_array(zg), type, data); +} /* Get the current library version number */ void plgver(out string p_ver) @@ -260,11 +323,29 @@ } /* Plots a mesh representation of the function z[x][y]. */ -//void c_plmesh(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt); +void plmesh(PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt) +{ + PLINT nx=z.length; + PLINT ny=z[0].length; + + assert(nx==x.length, "plmesh(): Arrays must be of same length!"); + assert(ny==y.length, "plmesh(): Arrays must be of same length!"); + c_plmesh(x.ptr, y.ptr, convert_array(z), nx, ny, opt); +} + /* Plots a mesh representation of the function z[x][y] with contour */ -//void c_plmeshc(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLFLT *clevel, PLINT nlevel); +void plmeshc(PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel) +{ + PLINT nx=z.length; + PLINT ny=z[0].length; + + assert(nx==x.length, "plmeshc(): Arrays must be of same length!"); + assert(ny==y.length, "plmeshc(): Arrays must be of same length!"); + c_plmeshc(x.ptr, y.ptr, convert_array(z), nx, ny, opt, clevel.ptr, clevel.length); +} + /* Prints out "text" at specified position relative to viewport */ void plmtex(string side, PLFLT disp, PLFLT pos, PLFLT just, string text) { @@ -278,15 +359,44 @@ } /* Plots a 3-d representation of the function z[x][y]. */ -//void c_plot3d(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLBOOL side); +void plot3d(PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLBOOL side) +{ + PLINT nx=z.length; + PLINT ny=z[0].length; + + assert(nx==x.length, "plot3d(): Arrays must be of same length!"); + assert(ny==y.length, "plot3d(): Arrays must be of same length!"); + c_plot3d(x.ptr, y.ptr, convert_array(z), nx, ny, opt, side); +} + /* Plots a 3-d representation of the function z[x][y] with contour. */ -//void c_plot3dc(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLFLT *clevel, PLINT nlevel); +void plot3dc(PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel) +{ + PLINT nx=z.length; + PLINT ny=z[0].length; + + assert(nx==x.length, "plot3dc(): Arrays must be of same length!"); + assert(ny==y.length, "plot3dc(): Arrays must be of same length!"); + c_plot3dc(x.ptr, y.ptr, convert_array(z), nx, ny, opt, clevel.ptr, clevel.length); +} + /* Plots a 3-d representation of the function z[x][y] with contour and * y index limits. */ -//void c_plot3dcl(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLFLT *clevel, PLINT nlevel, PLINT ixstart, PLINT ixn, PLINT *indexymin, PLINT *indexymax); +void plot3dcl(PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel, + PLINT ixstart, PLINT ixn, PLINT[] indexymin, PLINT[] indexymax) +{ + PLINT nx=z.length; + PLINT ny=z[0].length; + + assert(nx==x.length, "plot3dcl(): Arrays must be of same length!"); + assert(ny==y.length, "plot3dcl(): Arrays must be of same length!"); + c_plot3dcl(x.ptr, y.ptr, convert_array(z), nx, ny, opt, clevel.ptr, clevel.length, + ixstart, ixn, indexymin.ptr, indexymax.ptr); +} + /* Set fill pattern directly. */ void plpat(PLINT[] inc, PLINT[] del) { @@ -442,6 +552,51 @@ fill_width, cont_color, cont_width, &c_plfill, rectangular, pltr, pltr_data); } +void plshades(PLFLT[][] a, def_func defined, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT[] clevel, PLINT fill_width, PLINT cont_color, PLINT cont_width, + PLBOOL rectangular, ref PLcGrid cgrid) +{ + PLINT nx=a.length; + PLINT ny=a[0].length; + + c_PLcGrid c; + c.xg = cgrid.xg.ptr; + c.nx = cgrid.xg.length; + c.yg = cgrid.yg.ptr; + c.ny = cgrid.yg.length; + c.zg = cgrid.zg.ptr; + c.nz = cgrid.zg.length; + + c_plshades(convert_array(a), nx, ny, defined, xmin, xmax, ymin, ymax, clevel.ptr, clevel.length, + fill_width, cont_color, cont_width, &c_plfill, rectangular, &pltr1, &c); +} + +void plshades(PLFLT[][] a, def_func defined, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT[] clevel, PLINT fill_width, PLINT cont_color, PLINT cont_width, + PLBOOL rectangular, ref PLcGrid2 cgrid2) +{ + PLINT nx=a.length; + PLINT ny=a[0].length; + + c_PLcGrid2 c2; + c2.xg = convert_array(cgrid2.xg); + c2.yg = convert_array(cgrid2.yg); + c2.zg = convert_array(cgrid2.zg); + c2.nx = cgrid2.xg.length; + c2.ny = cgrid2.xg[0].length; + if(cgrid2.yg) { + assert(c2.nx==cgrid2.yg.length, "plcont(): Arrays must be of same length!"); + assert(c2.ny==cgrid2.yg[0].length, "plcont(): Arrays must be of same length!"); + } + if(cgrid2.zg) { + assert(c2.nx==cgrid2.zg.length, "plcont(): Arrays must be of same length!"); + assert(c2.ny==cgrid2.zg[0].length, "plcont(): Arrays must be of same length!"); + } + + c_plshades(convert_array(a), nx, ny, defined, xmin, xmax, ymin, ymax, clevel.ptr, clevel.length, + fill_width, cont_color, cont_width, &c_plfill, rectangular, &pltr2, &c2); +} + /* Initialize PLplot, passing the device name and windows/page settings. */ void plstart(string devname, PLINT nx, PLINT ny) { @@ -469,12 +624,29 @@ } /* plots a 2d image (or a matrix too large for plshade() ) */ -//void c_plimagefr(PLFLT **idata, PLINT nx, PLINT ny, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax, PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax, PLFLT valuemin, PLFLT valuemax); +void plimagefr(PLFLT[][] idata, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT zmin, PLFLT zmax, PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax, + PLFLT valuemin, PLFLT valuemax) +{ + PLINT nx=idata.length; + PLINT ny=idata[0].length; + c_plimagefr(convert_array(idata), nx, ny, xmin, xmax, ymin, ymax, zmin, zmax, Dxmin, Dxmax, + Dymin, Dymax, valuemin, valuemax); +} + /* plots a 2d image (or a matrix too large for plshade() ) - colors automatically scaled */ -//void c_plimage(PLFLT **idata, PLINT nx, PLINT ny, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax, PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax); +void plimage(PLFLT[][] idata, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT zmin, PLFLT zmax, PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax) +{ + PLINT nx=idata.length; + PLINT ny=idata[0].length; + c_plimage(convert_array(idata), nx, ny, xmin, xmax, ymin, ymax, zmin, zmax, Dxmin, Dxmax, + Dymin, Dymax); +} + /* Set up a new line style */ void plstyl(PLINT[] mark, PLINT[] space) { @@ -484,12 +656,33 @@ } /* Plots the 3d surface representation of the function z[x][y]. */ -//void c_plsurf3d(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLFLT *clevel, PLINT nlevel); +void plsurf3d(PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel=null) +{ + PLINT nx=z.length; + PLINT ny=z[0].length; + assert(nx==x.length, "plsurf3d(): Arrays must be of same length!"); + assert(ny==y.length, "plsurf3d(): Arrays must be of same length!"); + + if(clevel) + c_plsurf3d(x.ptr, y.ptr, convert_array(z), nx, ny, opt, clevel.ptr, clevel.length); + else + c_plsurf3d(x.ptr, y.ptr, convert_array(z), nx, ny, opt, null, 0); +} /* Plots the 3d surface representation of the function z[x][y] with y * index limits. */ -//void c_plsurf3dl(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLFLT *clevel, PLINT nlevel, PLINT ixstart, PLINT ixn, PLINT *indexymin, PLINT *indexymax); +void plsurf3dl(PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel, + PLINT ixstart, PLINT ixn, PLINT[] indexymin, PLINT[] indexymax) +{ + PLINT nx=z.length; + PLINT ny=z[0].length; + assert(nx==x.length, "plsurf3d(): Arrays must be of same length!"); + assert(ny==y.length, "plsurf3d(): Arrays must be of same length!"); + c_plsurf3dl(x.ptr, y.ptr, convert_array(z), nx, ny, opt, clevel.ptr, clevel.length, + ixstart, ixn, indexymin.ptr, indexymax.ptr); +} + /* Plots array y against x for n points using Hershey symbol "code" */ void plsym(PLFLT[] x, PLFLT[] y, PLINT code) { @@ -999,7 +1192,7 @@ alias c_plglevel plglevel; alias c_plgpage plgpage; alias c_plgra plgra; -alias c_plgriddata plgriddata; +//alias c_plgriddata plgriddata; alias c_plgspa plgspa; alias c_plgstrm plgstrm; //alias c_plgver plgver; @@ -1011,8 +1204,8 @@ //alias c_plhist plhist; alias c_plhls plhls; alias c_plhlsrgb plhlsrgb; -alias c_plimage plimage; -alias c_plimagefr plimagefr; +//alias c_plimage plimage; +//alias c_plimagefr plimagefr; alias c_plinit plinit; alias c_pljoin pljoin; //alias c_pllab pllab; @@ -1022,14 +1215,14 @@ alias c_pllsty pllsty; //alias c_plmap plmap; alias c_plmeridians plmeridians; -alias c_plmesh plmesh; -alias c_plmeshc plmeshc; +//alias c_plmesh plmesh; +//alias c_plmeshc plmeshc; alias c_plmkstrm plmkstrm; //alias c_plmtex plmtex; //alias c_plmtex3 plmtex3; -alias c_plot3d plot3d; -alias c_plot3dc plot3dc; -alias c_plot3dcl plot3dcl; +//alias c_plot3d plot3d; +//alias c_plot3dc plot3dc; +//alias c_plot3dcl plot3dcl; //alias c_plparseopts plparseopts; //alias c_plpat plpat; //alias c_plpoin plpoin; @@ -1087,8 +1280,8 @@ //alias c_plstripc plstripc; alias c_plstripd plstripd; //alias c_plstyl plstyl; -alias c_plsurf3d plsurf3d; -alias c_plsurf3dl plsurf3dl; +//alias c_plsurf3d plsurf3d; +//alias c_plsurf3dl plsurf3dl; //alias c_plsvect plsvect; alias c_plsvpa plsvpa; alias c_plsxax plsxax; @@ -1098,7 +1291,7 @@ alias c_pltext pltext; //alias c_pltimefmt pltimefmt; alias c_plvasp plvasp; -alias c_plvect plvect; +//alias c_plvect plvect; alias c_plvpas plvpas; alias c_plvpor plvpor; alias c_plvsta plvsta; @@ -1127,29 +1320,27 @@ \*--------------------------------------------------------------------------*/ - /* All void types */ +/* All void types */ +/* C routines callable from stub routines come first */ - /* C routines callable from stub routines come first */ - /* set the format of the contour labels */ +void c_pl_setcontlabelformat(PLINT lexp, PLINT sigdig); -void c_pl_setcontlabelformat(PLINT lexp, PLINT sigdig); - /* set offset and spacing of contour labels */ +void c_pl_setcontlabelparam(PLFLT offset, PLFLT size, PLFLT spacing, PLINT active); -void c_pl_setcontlabelparam(PLFLT offset, PLFLT size, PLFLT spacing, PLINT active); - /* Advance to subpage "page", or to the next one if "page" = 0. */ +void c_pladv(PLINT page); -void c_pladv(PLINT page); - /* simple arrow plotter. */ -void c_plvect(PLFLT **u, PLFLT **v, PLINT nx, PLINT ny, PLFLT scale, void function(PLFLT , PLFLT , PLFLT *, PLFLT *, PLPointer )pltr, PLPointer pltr_data); +void c_plvect(PLFLT **u, PLFLT **v, PLINT nx, PLINT ny, PLFLT scale, + void function(PLFLT, PLFLT, PLFLT*, PLFLT*, PLPointer) pltr, PLPointer pltr_data); void c_plsvect(PLFLT *arrowx, PLFLT *arrowy, PLINT npts, PLBOOL fill); /* This functions similarly to plbox() except that the origin of the axes */ /* is placed at the user-specified point (x0, y0). */ -void c_plaxes(PLFLT x0, PLFLT y0, char *xopt, PLFLT xtick, PLINT nxsub, char *yopt, PLFLT ytick, PLINT nysub); +void c_plaxes(PLFLT x0, PLFLT y0, char *xopt, PLFLT xtick, PLINT nxsub, + char *yopt, PLFLT ytick, PLINT nysub); /* Flags for plbin() - opt argument */ const PL_BIN_DEFAULT = 0; @@ -1161,9 +1352,8 @@ void c_plbin(PLINT nbin, PLFLT *x, PLFLT *y, PLINT opt); /* Start new page. Should only be used with pleop(). */ +void c_plbop(); -void c_plbop(); - /* This draws a box around the current viewport. */ void c_plbox(char *xopt, PLFLT xtick, PLINT nxsub, char *yopt, PLFLT ytick, PLINT nysub); @@ -1193,7 +1383,9 @@ * by way of the f2eval_data pointer. This allows arbitrary organizations * of 2d array data to be used. */ -void plfcont(PLFLT function(PLINT , PLINT , PLPointer )f2eval, PLPointer f2eval_data, PLINT nx, PLINT ny, PLINT kx, PLINT lx, PLINT ky, PLINT ly, PLFLT *clevel, PLINT nlevel, void function(PLFLT , PLFLT , PLFLT *, PLFLT *, PLPointer )pltr, PLPointer pltr_data); +void plfcont(PLFLT function(PLINT, PLINT, PLPointer) f2eval, PLPointer f2eval_data, PLINT nx, PLINT ny, + PLINT kx, PLINT lx, PLINT ky, PLINT ly, PLFLT *clevel, PLINT nlevel, + void function(PLFLT, PLFLT, PLFLT*, PLFLT*, PLPointer) pltr, PLPointer pltr_data); /* Copies state parameters from the reference stream to the current stream. */ void c_plcpstrm(PLINT iplsr, PLBOOL flags); @@ -1203,36 +1395,28 @@ /* Converts input values from relative device coordinates to relative plot */ /* coordinates. */ +void pldid2pc(PLFLT *xmin, PLFLT *ymin, PLFLT *xmax, PLFLT *ymax); -void pldid2pc(PLFLT *xmin, PLFLT *ymin, PLFLT *xmax, PLFLT *ymax); - /* Converts input values from relative plot coordinates to relative */ /* device coordinates. */ +void pldip2dc(PLFLT *xmin, PLFLT *ymin, PLFLT *xmax, PLFLT *ymax); -void pldip2dc(PLFLT *xmin, PLFLT *ymin, PLFLT *xmax, PLFLT *ymax); - /* End a plotting session for all open streams. */ +void c_plend(); -void c_plend(); - /* End a plotting session for the current stream only. */ +void c_plend1(); -void c_plend1(); - /* Simple interface for defining viewport and window. */ +void c_plenv(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLINT just, PLINT axis); -void c_plenv(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLINT just, PLINT axis); - - /* similar to plenv() above, but in multiplot mode does not advance the subpage, instead the current subpage is cleared */ +void c_plenv0(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLINT just, PLINT axis); -void c_plenv0(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLINT just, PLINT axis); - /* End current page. Should only be used with plbop(). */ +void c_pleop(); -void c_pleop(); - /* Plot horizontal error bars (xmin(i),y(i)) to (xmax(i),y(i)) */ void c_plerrx(PLINT n, PLFLT *xmin, PLFLT *xmax, PLFLT *y); @@ -1249,56 +1433,44 @@ void c_plfill3(PLINT n, PLFLT *x, PLFLT *y, PLFLT *z); /* Flushes the output stream. Use sparingly, if at all. */ +void c_plflush(); -void c_plflush(); - /* Sets the global font flag to 'ifont'. */ +void c_plfont(PLINT ifont); -void c_plfont(PLINT ifont); - /* Load specified font set. */ +void c_plfontld(PLINT fnt); -void c_plfontld(PLINT fnt); - /* Get character default height and current (scaled) height */ +void c_plgchr(PLFLT *p_def, PLFLT *p_ht); -void c_plgchr(PLFLT *p_def, PLFLT *p_ht); - /* Returns 8 bit RGB values for given color from color map 0 */ +void c_plgcol0(PLINT icol0, PLINT *r, PLINT *g, PLINT *b); -void c_plgcol0(PLINT icol0, PLINT *r, PLINT *g, PLINT *b); - /* Returns 8 bit RGB values for given color from color map 0 and alpha value */ +void c_plgcol0a(PLINT icol0, PLINT *r, PLINT *g, PLINT *b, PLFLT *a); -void c_plgcol0a(PLINT icol0, PLINT *r, PLINT *g, PLINT *b, PLFLT *a); - /* Returns the background color by 8 bit RGB value */ +void c_plgcolbg(PLINT *r, PLINT *g, PLINT *b); -void c_plgcolbg(PLINT *r, PLINT *g, PLINT *b); - /* Returns the background color by 8 bit RGB value and alpha value */ +void c_plgcolbga(PLINT *r, PLINT *g, PLINT *b, PLFLT *a); -void c_plgcolbga(PLINT *r, PLINT *g, PLINT *b, PLFLT *a); - /* Returns the current compression setting */ +void c_plgcompression(PLINT *compression); -void c_plgcompression(PLINT *compression); - /* Get the current device (keyword) name */ void c_plgdev(char *p_dev); /* Retrieve current window into device space */ +void c_plgdidev(PLFLT *p_mar, PLFLT *p_aspect, PLFLT *p_jx, PLFLT *p_jy); -void c_plgdidev(PLFLT *p_mar, PLFLT *p_aspect, PLFLT *p_jx, PLFLT *p_jy); - /* Get plot orientation */ +void c_plgdiori(PLFLT *p_rot); -void c_plgdiori(PLFLT *p_rot); - /* Retrieve current window into plot space */ +void c_plgdiplt(PLFLT *p_xmin, PLFLT *p_ymin, PLFLT *p_xmax, PLFLT *p_ymax); -void c_plgdiplt(PLFLT *p_xmin, PLFLT *p_ymin, PLFLT *p_xmax, PLFLT *p_ymax); - /* Get FCI (font characterization integer) */ void c_plgfci(PLUNICODE *pfci); @@ -1311,25 +1483,22 @@ void c_plgfnam(char *fnam); /* Get the current font family, style and weight */ +void c_plgfont(PLINT *p_family, PLINT *p_style, PLINT *p_weight); -void c_plgfont(PLINT *p_family, PLINT *p_style, PLINT *p_weight); - /* Get the (current) run level. */ +void c_plglevel(PLINT *p_level); -void c_plglevel(PLINT *p_level); - /* Get output device parameters. */ +void c_plgpage(PLFLT *p_xp, PLFLT *p_yp, PLINT *p_xleng, PLINT *p_yleng, + PLINT *p_xoff, PLINT *p_yoff); -void c_plgpage(PLFLT *p_xp, PLFLT *p_yp, PLINT *p_xleng, PLINT *p_yleng, PLINT *p_xoff, PLINT *p_yoff); - /* Switches to graphics screen. */ +void c_plgra(); -void c_plgra(); - /* grid irregularly sampled data */ +void c_plgriddata(PLFLT *x, PLFLT *y, PLFLT *z, PLINT npts, PLFLT *xg, PLINT nptsx, + PLFLT *yg, PLINT nptsy, PLFLT **zg, PLINT type, PLFLT data); -void c_plgriddata(PLFLT *x, PLFLT *y, PLFLT *z, PLINT npts, PLFLT *xg, PLINT nptsx, PLFLT *yg, PLINT nptsy, PLFLT **zg, PLINT type, PLFLT data); - /* type of gridding algorithm for plgriddata() */ const GRID_CSA = 1; const GRID_DTLI = 2; @@ -1412,13 +1581,12 @@ void c_plmesh(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt); /* Plots a mesh representation of the function z[x][y] with contour */ +void c_plmeshc(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, + PLFLT *clevel, PLINT nlevel); -void c_plmeshc(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLFLT *clevel, PLINT nlevel); - /* Creates a new stream and makes it the default. */ +void c_plmkstrm(PLINT *p_strm); -void c_plmkstrm(PLINT *p_strm); - /* Prints out "text" at specified position relative to viewport */ void c_plmtex(char *side, PLFLT disp, PLFLT pos, PLFLT just, char *text); @@ -1426,18 +1594,18 @@ void c_plmtex3(char *side, PLFLT disp, PLFLT pos, PLFLT just, char *text); /* Plots a 3-d representation of the function z[x][y]. */ +void c_plot3d(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLBOOL side); -void c_plot3d(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLBOOL side); - /* Plots a 3-d representation of the function z[x][y] with contour. */ +void c_plot3dc(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, + PLFLT *clevel, PLINT nlevel); -void c_plot3dc(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLFLT *clevel, PLINT nlevel); - /* Plots a 3-d representation of the function z[x][y] with contour and * y index limits. */ +void c_plot3dcl(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, + PLFLT *clevel, PLINT nlevel, PLINT ixstart, PLINT ixn, + PLINT *indexymin, PLINT *indexymax); -void c_plot3dcl(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLFLT *clevel, PLINT nlevel, PLINT ixstart, PLINT ixn, PLINT *indexymin, PLINT *indexymax); - /* * definitions for the opt argument in plot3dc() and plsurf3d() * @@ -1454,16 +1622,16 @@ const FACETED=1<<7; /* draw outline for each square that makes up the surface */ const MESH=1<<8; /* draw mesh */ - /* - * valid options for plot3dc(): - * - * DRAW_SIDES, BASE_CONT, TOP_CONT (not yet), - * MAG_COLOR, DRAW_LINEX, DRAW_LINEY, DRAW_LINEXY. - * - * valid options for plsurf3d(): - * - * MAG_COLOR, BASE_CONT, SURF_CONT, FACETED, DRAW_SIDES. - */ +/* + * valid options for plot3dc(): + * + * DRAW_SIDES, BASE_CONT, TOP_CONT (not yet), + * MAG_COLOR, DRAW_LINEX, DRAW_LINEY, DRAW_LINEXY. + * + * valid options for plsurf3d(): + * + * MAG_COLOR, BASE_CONT, SURF_CONT, FACETED, DRAW_SIDES. + */ /* Set fill pattern directly. */ void c_plpat(PLINT nlin, PLINT *inc, PLINT *del); @@ -1478,9 +1646,8 @@ void c_plpoly3(PLINT n, PLFLT *x, PLFLT *y, PLFLT *z, PLBOOL *draw, PLBOOL ifcc); /* Set the floating point precision (in number of places) in numeric labels. */ +void c_plprec(PLINT setp, PLINT prec); -void c_plprec(PLINT setp, PLINT prec); - /* Set fill pattern, using one of the predefined patterns.*/ void c_plpsty(PLINT patt); @@ -1666,42 +1833,39 @@ void c_plstripd(PLINT id); /* plots a 2d image (or a matrix too large for plshade() ) */ +void c_plimagefr(PLFLT **idata, PLINT nx, PLINT ny, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT zmin, PLFLT zmax, PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax, + PLFLT valuemin, PLFLT valuemax); -void c_plimagefr(PLFLT **idata, PLINT nx, PLINT ny, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax, PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax, PLFLT valuemin, PLFLT valuemax); - /* plots a 2d image (or a matrix too large for plshade() ) - colors automatically scaled */ +void c_plimage(PLFLT **idata, PLINT nx, PLINT ny, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT zmin, PLFLT zmax, PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax); -void c_plimage(PLFLT **idata, PLINT nx, PLINT ny, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax, PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax); - /* Set up a new line style */ void c_plstyl(PLINT nms, PLINT *mark, PLINT *space); /* Plots the 3d surface representation of the function z[x][y]. */ +void c_plsurf3d(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, + PLFLT *clevel, PLINT nlevel); -void c_plsurf3d(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLFLT *clevel, PLINT nlevel); - /* Plots the 3d surface representation of the function z[x][y] with y * index limits. */ +void c_plsurf3dl(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLFLT *clevel, + PLINT nlevel, PLINT ixstart, PLINT ixn, PLINT *indexymin, PLINT *indexymax); -void c_plsurf3dl(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, PLFLT *clevel, PLINT nlevel, PLINT ixstart, PLINT ixn, PLINT *indexymin, PLINT *indexymax); - /* Sets the edges of the viewport to the specified absolute coordinates */ +void c_plsvpa(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax); -void c_plsvpa(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax); - /* Set x axis labeling parameters */ +void c_plsxax(PLINT digmax, PLINT digits); -void c_plsxax(PLINT digmax, PLINT digits); - /* Set inferior X window */ +void plsxwin(PLINT window_id); -void plsxwin(PLINT window_id); - /* Set y axis labeling parameters */ +void c_plsyax(PLINT digmax, PLINT digits); -void c_plsyax(PLINT digmax, PLINT digits); - /* Plots array y against x for n points using Hershey symbol "code" */ void c_plsym(PLINT n, PLFLT *x, PLFLT *y, PLINT code); Modified: trunk/examples/d/CMakeLists.txt =================================================================== --- trunk/examples/d/CMakeLists.txt 2009-06-04 15:23:16 UTC (rev 10030) +++ trunk/examples/d/CMakeLists.txt 2009-06-05 06:07:40 UTC (rev 10031) @@ -35,13 +35,16 @@ "13" "14" "15" + "16" "17" "18" "19" "23" "24" "25" + "26" "27" +# "28" "29" "30" ) Modified: trunk/examples/d/x03d.d =================================================================== --- trunk/examples/d/x03d.d 2009-06-04 15:23:16 UTC (rev 10030) +++ trunk/examples/d/x03d.d 2009-06-05 06:07:40 UTC (rev 10031) @@ -25,6 +25,10 @@ /* Parse and process command line arguments */ plparseopts(args, PL_PARSE_FULL); + /* Set orientation to landscape - note not all device drivers + * support this, in particular most interactive drivers do not */ + plsori(1); + /* Initialize plplot */ plinit(); @@ -52,8 +56,7 @@ pljoin(0.0, 0.0, dx, dy); /* Write labels for angle */ - string text; - text = format("%d", lrint(theta)); + string text = format("%d", lrint(theta)); PLFLT offset; if(theta<9.99) Modified: trunk/examples/d/x08d.d =================================================================== --- trunk/examples/d/x08d.d 2009-06-04 15:23:16 UTC (rev 10030) +++ trunk/examples/d/x08d.d 2009-06-05 06:07:40 UTC (rev 10031) @@ -86,17 +86,13 @@ * Does a series of 3-d plots for a given data set, with different * viewing options in each plot. \*--------------------------------------------------------------------------*/ -int main( char[][] args ) +int main(char[][] args) { const nlevel=10; const XPTS=35; /* Data points in x */ const YPTS=46; /* Data points in y */ - PLFLT* x, y; - PLFLT** z; PLFLT xx, yy, r; - PLFLT zmin, zmax, step; - PLFLT[nlevel] clevel; bool rosen=true; PLFLT[] alt = [ 60.0, 20.0 ]; @@ -115,10 +111,12 @@ plinit(); /* Allocate data structures */ - x = cast(PLFLT*)std.c.stdlib.calloc( XPTS, PLFLT.sizeof ); - y = cast(PLFLT*)std.c.stdlib.calloc( YPTS, PLFLT.sizeof ); + PLFLT[XPTS] x; + PLFLT[YPTS] y; - plAlloc2dGrid( &z, XPTS, YPTS ); + PLFLT[][] z = new PLFLT[][XPTS]; + for(int i=0; i<XPTS; i++) + z[i] = new PLFLT[YPTS]; for( int i=0; i<XPTS; i++) { x[i] = (cast(PLFLT)(i-(XPTS/2))/cast(PLFLT)(XPTS/2)); @@ -150,9 +148,12 @@ } } - plMinMax2dGrid( z, XPTS, YPTS, &zmax, &zmin ); - step = (zmax-zmin)/(nlevel+1); - for( size_t i=0; i<nlevel; i++ ) + PLFLT zmin, zmax; + f2mnmx(z, zmin, zmax); + + PLFLT step = (zmax-zmin)/(nlevel+1); + PLFLT[nlevel] clevel; + for(size_t i=0; i<nlevel; i++) clevel[i] = zmin+step+step*i; pllightsource( 1.,1.,1. ); @@ -179,33 +180,45 @@ case 0: /* diffuse light surface plot */ cmap1_init( 1 ); - plsurf3d( x, y, z, XPTS, YPTS, 0, null, 0 ); + plsurf3d(x, y, z, 0); break; case 1: /* magnitude colored plot */ cmap1_init( 0 ); - plsurf3d( x, y, z, XPTS, YPTS, MAG_COLOR, null, 0 ); + plsurf3d(x, y, z, MAG_COLOR); break; case 2: /* magnitude colored plot with faceted squares */ cmap1_init( 0 ); - plsurf3d( x, y, z, XPTS, YPTS, MAG_COLOR | FACETED, null, 0 ); + plsurf3d(x, y, z, MAG_COLOR | FACETED); break; default: /* magnitude colored plot with contours */ cmap1_init( 0 ); - plsurf3d( x, y, z, XPTS, YPTS, MAG_COLOR | SURF_CONT | BASE_CONT, - cast(PLFLT*)clevel, nlevel ); + plsurf3d(x, y, z, MAG_COLOR | SURF_CONT | BASE_CONT, clevel); break; } } } - /* Clean up */ - std.c.stdlib.free( x ); - std.c.stdlib.free( y ); - plFree2dGrid( z, XPTS, YPTS ); - plend(); return 0; } + +/*--------------------------------------------------------------------------*\ + * f2mnmx + * + * Returns min & max of input 2d array. +\*--------------------------------------------------------------------------*/ +void f2mnmx(PLFLT[][] f, out PLFLT fmn, out PLFLT fmx) +{ + fmx = f[0][0]; + fmn = fmx; + + for(int i=0; i<f.length; i++) { + for(int j=0; j<f[i].length; j++) { + fmx = fmax(fmx, f[i][j]); + fmn = fmin(fmn, f[i][j]); + } + } +} Modified: trunk/examples/d/x11d.d =================================================================== --- trunk/examples/d/x11d.d 2009-06-04 15:23:16 UTC (rev 10030) +++ trunk/examples/d/x11d.d 2009-06-05 06:07:40 UTC (rev 10031) @@ -18,7 +18,7 @@ GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License - along with PLplot; if not, write to the Free Software + along with PLplot; if not, write to the Free So ftware Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -62,12 +62,7 @@ char[] title[] = [ "#frPLplot Example 11 - Alt=33, Az=24, Opt=3", "#frPLplot Example 11 - Alt=17, Az=115, Opt=3" ]; - PLFLT[XPTS] x; - PLFLT[YPTS] y; - PLFLT** z; PLFLT xx, yy; - PLFLT[nlevel] clevel; - PLFLT zmin, zmax, step; /* Parse and process command line arguments */ plparseopts(args, PL_PARSE_FULL); @@ -75,7 +70,13 @@ /* Initialize plplot */ plinit(); - plAlloc2dGrid( &z, XPTS, YPTS ); + PLFLT[XPTS] x; + PLFLT[YPTS] y; + + PLFLT[][] z = new PLFLT[][XPTS]; + for(int i=0; i<XPTS; i++) + z[i] = new PLFLT[YPTS]; + for( int i=0; i<XPTS; i++ ) x[i] = 3.*cast(PLFLT)(i-(XPTS/2))/cast(PLFLT)(XPTS/2); @@ -97,8 +98,11 @@ } } - plMinMax2dGrid( z, XPTS, YPTS, &zmax, &zmin ); - step = (zmax-zmin)/(nlevel+1); + PLFLT zmin, zmax; + f2mnmx(z, zmin, zmax); + + PLFLT step = (zmax-zmin)/(nlevel+1); + PLFLT[nlevel] clevel; for( size_t i=0; i<nlevel; i++ ) clevel[i] = zmin+step+step*i; @@ -118,20 +122,19 @@ switch( i ) { case 0: /* wireframe plot */ - plmesh( cast(PLFLT*)x, cast(PLFLT*)y, z, XPTS, YPTS, opt[k] ); + plmesh(x, y, z, opt[k]); break; case 1: /* magnitude colored wireframe plot */ - plmesh( cast(PLFLT*)x, cast(PLFLT*)y, z, XPTS, YPTS, opt[k] | MAG_COLOR ); + plmesh(x, y, z, opt[k] | MAG_COLOR ); break; case 2: /* magnitude colored wireframe plot with sides */ - plot3d( cast(PLFLT*)x, cast(PLFLT*)y, z, XPTS, YPTS, opt[k] | MAG_COLOR, 1 ); + plot3d(x, y, z, opt[k] | MAG_COLOR, 1 ); break; case 3: /* magnitude colored wireframe plot with base contour */ - plmeshc( cast(PLFLT*)x, cast(PLFLT*)y, z, XPTS, YPTS, opt[k] | MAG_COLOR | BASE_CONT, - cast(PLFLT*)clevel, nlevel ); + plmeshc(x, y, z, opt[k] | MAG_COLOR | BASE_CONT, clevel); break; } @@ -140,9 +143,24 @@ } } - /* Clean up */ - plFree2dGrid( z, XPTS, YPTS ); - plend(); return 0; } + +/*--------------------------------------------------------------------------*\ + * f2mnmx + * + * Returns min & max of input 2d array. +\*--------------------------------------------------------------------------*/ +void f2mnmx(PLFLT[][] f, out PLFLT fmn, out PLFLT fmx) +{ + fmx = f[0][0]; + fmn = fmx; + + for(int i=0; i<f.length; i++) { + for(int j=0; j<f[i].length; j++) { + fmx = fmax(fmx, f[i][j]); + fmn = fmin(fmn, f[i][j]); + } + } +} Added: trunk/examples/d/x16d.d =================================================================== --- trunk/examples/d/x16d.d (rev 0) +++ trunk/examples/d/x16d.d 2009-06-05 06:07:40 UTC (rev 10031) @@ -0,0 +1,328 @@ +/* $Id: $ + + plshade demo, using color fill. + + Maurice LeBrun + IFS, University of Texas at Austin + 20 Mar 1994 +*/ + +import std.string; +import std.math; + +import plplot; + +/* Fundamental settings. See notes[] for more info. */ + +int ns = 20; /* Default number of shade levels */ +int nx = 35; /* Default number of data points in x */ +int ny = 46; /* Default number of data points in y */ +int exclude = 0; /* By default do not plot a page illustrating + * exclusion. API is probably going to change + * anyway, and cannot be reproduced by any + * front end other than the C one. */ + +/* Transformation function */ +PLFLT[] tr; + +extern (C) { + 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]; + } +} + +/* Options data structure definition. */ +//~ static PLOptionTable options[] = { +//~ { + //~ "exclude", /* Turns on page showing exclusion */ + //~ NULL, + //~ NULL, + //~ &exclude, + //~ PL_OPT_BOOL, + //~ "-exclude", + //~ "Plot the \"exclusion\" page." }, +//~ { + //~ "ns", /* Number of shade levels */ + //~ NULL, + //~ NULL, + //~ &ns, + //~ PL_OPT_INT, + //~ "-ns levels", + //~ "Sets number of shade levels" }, +//~ { + //~ "nx", /* Number of data points in x */ + //~ NULL, + //~ NULL, + //~ &nx, + //~ PL_OPT_INT, + //~ "-nx xpts", + //~ "Sets number of data points in x" }, +//~ { + //~ "ny", /* Number of data points in y */ + //~ NULL, + //~ NULL, + //~ &ny, + //~ PL_OPT_INT, + //~ "-ny ypts", + //~ "Sets number of data points in y" }, +//~ { + //~ NULL, /* option */ + //~ NULL, /* handler */ + //~ NULL, /* client data */ + //~ NULL, /* address of variable to set */ + //~ 0, /* mode flag */ + //~ NULL, /* short syntax */ + //~ NULL } /* long syntax */ +//~ }; + +//~ static const char *notes[] = { +//~ "To get smoother color variation, increase ns, nx, and ny. To get faster", +//~ "response (especially on a serial link), decrease them. A decent but quick", +//~ "test results from ns around 5 and nx, ny around 25.", +//~ NULL}; + +extern (C) { + PLINT zdefined(PLFLT x, PLFLT y) + { + PLFLT z = sqrt(x*x + y*y); + + return z<0.4 || z>0.6; + } +} + + +/*--------------------------------------------------------------------------*\ + * main + * + * Does several shade plots using different coordinate mappings. +\*--------------------------------------------------------------------------*/ +int main(char[][] args) +{ + const int PERIMETERPTS=100; + + /* Parse and process command line arguments */ + //plMergeOpts(options, "x16c options", notes); + plparseopts(args, PL_PARSE_FULL); + + /* Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display */ + plscmap0n(3); + + /* Initialize plplot */ + plinit(); + + /* Set up transformation function */ + tr = [ 2./(nx-1), 0.0, -1.0, 0.0, 2./(ny-1), -1.0 ]; + + /* Allocate data structures */ + PLFLT[][] z = new PLFLT[][nx]; + for(int i=0; i<nx; i++) + z[i] = new PLFLT[ny]; + + PLFLT[][] w = new PLFLT[][nx]; + for(int i=0; i<nx; i++) + w[i] = new PLFLT[ny]; + + /* Set up data array */ + PLFLT x, y; + for(int i=0; i<nx; i++) { + x = cast(double)(i-(nx/2))/(nx/2); + for(int j=0; j<ny; j++) { + y = cast(double)(j-(ny/2))/(ny/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; + } + } + PLFLT zmin, zmax; + f2mnmx(z, zmin, zmax); + + PLFLT[] clevel = new PLFLT[ns]; + for(int i=0; i<ns; i++) + clevel[i] = zmin + (zmax-zmin)*(i+0.5)/ns; + + PLFLT[] shedge = new PLFLT[ns+1]; + for(int i=0; i<ns+1; i++) + shedge[i] = zmin + (zmax-zmin)*i/ns; + + /* Set up coordinate grids */ + PLcGrid cgrid1; + cgrid1.xg = new PLFLT[nx]; + cgrid1.yg = new PLFLT[ny]; + + PLcGrid2 cgrid2; + cgrid2.xg = new PLFLT[][nx]; + for(int i=0; i<nx; i++) + cgrid2.xg[i] = new PLFLT[ny]; + + cgrid2.yg = new PLFLT[][nx]; + for(int i=0; i<nx; i++) + cgrid2.yg[i] = new PLFLT[ny]; + + PLFLT argx, argy, distort; + for(int i=0; i<nx; i++) { + for(int j=0; j<ny; j++) { + mypltr(i, 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 */ + PLINT fill_width = 2, cont_color = 0, cont_width = 0; + + pladv(0); + plvpor(0.1, 0.9, 0.1, 0.9); + plwind(-1.0, 1.0, -1.0, 1.0); + + plpsty(0); + + plshades(z, null, -1., 1., -1., 1., shedge, fill_width, + cont_color, cont_width, 1); + + plcol0(1); + plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); + plcol0(2); + pllab("distance", "altitude", "Bogon density"); + + /* Plot using 1d coordinate transform */ + pladv(0); + plvpor(0.1, 0.9, 0.1, 0.9); + plwind(-1.0, 1.0, -1.0, 1.0); + + plpsty(0); + + plshades(z, null, -1., 1., -1., 1., shedge, fill_width, + cont_color, cont_width, 1, cgrid1); + + plcol0(1); + plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); + plcol0(2); + pllab("distance", "altitude", "Bogon density"); + + /* Plot using 2d coordinate transform */ + pladv(0); + plvpor(0.1, 0.9, 0.1, 0.9); + plwind(-1.0, 1.0, -1.0, 1.0); + + plpsty(0); + + plshades(z, null, -1., 1., -1., 1., shedge, fill_width, + cont_color, cont_width, 0, cgrid2); + + plcol0(1); + plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); + plcol0(2); + plcont(w, 1, nx, 1, ny, clevel, cgrid2); + + pllab("distance", "altitude", "Bogon density, with streamlines"); + + /* Plot using 2d coordinate transform */ + pladv(0); + plvpor(0.1, 0.9, 0.1, 0.9); + plwind(-1.0, 1.0, -1.0, 1.0); + + plpsty(0); + + plshades(z, null, -1., 1., -1., 1., shedge, fill_width, + 2, 3, 0, cgrid2); + + plcol0(1); + plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); + plcol0(2); + + pllab("distance", "altitude", "Bogon density"); + + /* Note this exclusion API will probably change. */ + + /* Plot using 2d coordinate transform and exclusion*/ + if(exclude) { + pladv(0); + plvpor(0.1, 0.9, 0.1, 0.9); + plwind(-1.0, 1.0, -1.0, 1.0); + + plpsty(0); + + plshades(z, &zdefined, -1., 1., -1., 1., shedge, fill_width, + cont_color, cont_width, 0, cgrid2); + + plcol0(1); + plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); + + pllab("distance", "altitude", "Bogon density with exclusion"); + } + + /* Example with polar coordinates. */ + pladv(0); + plvpor( .1, .9, .1, .9 ); + plwind( -1., 1., -1., 1. ); + + plpsty(0); + + /* Build new coordinate matrices. */ + PLFLT r, t; + for(int i=0; i<nx; i++) { + r = cast(PLFLT)i/(nx-1); + for(int j=0; j<ny; j++) { + t = 2.*PI/(ny-1.)*j; + cgrid2.xg[i][j] = r*cos(t); + cgrid2.yg[i][j] = r*sin(t); + z[i][j] = exp(-r*r)*cos(5.*PI*r)*cos(5.*t); + } + } + + /* Need a new shedge to go along with the new data set. */ + f2mnmx(z, zmin, zmax); + + for(int i=0; i<ns+1; i++) + shedge[i] = zmin + (zmax-zmin)*i/ns; + + /* Now we can shade the interior region. */ + plshades(z, null, -1., 1., -1., 1., shedge, fill_width, + cont_color, cont_width, 0, cgrid2); + + /* Now we can draw the perimeter. (If do before, shade stuff may overlap.) */ + PLFLT[PERIMETERPTS] px, py; + for(int i=0; i<PERIMETERPTS; i++) { + t = 2.*PI/(PERIMETERPTS-1)*i; + px[i] = cos(t); + py[i] = sin(t); + } + plcol0(1); + plline(px, py); + + /* And label the plot.*/ + plcol0(2); + pllab("", "", "Tokamak Bogon Instability"); + + plend(); + + return 0; +} + +/*--------------------------------------------------------------------------*\ + * f2mnmx + * + * Returns min & max of input 2d array. +\*--------------------------------------------------------------------------*/ +void f2mnmx(PLFLT[][] f, out PLFLT fmn, out PLFLT fmx) +{ + fmx = f[0][0]; + fmn = fmx; + + for(int i=0; i<f.length; i++) { + for(int j=0; j<f[i].length; j++) { + fmx = fmax(fmx, f[i][j]); + fmn = fmin(fmn, f[i][j]); + } + } +} Property changes on: trunk/examples/d/x16d.d ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/examples/d/x26d.d =================================================================== --- trunk/examples/d/x26d.d (rev 0) +++ trunk/examples/d/x26d.d 2009-06-05 06:07:40 UTC (rev 10031) @@ -0,0 +1,182 @@ +/* -*- coding: utf-8; -*- + + $Id: $ + + Multi-lingual version of the first page of example 4. + + Copyright (C) 2009 Werner Smekal + + Thanks to the following for providing translated strings for this example: + Valery Pipin (Russian) + + This file is part of PLplot. + + PLplot is free software; you can redistribute it and/or modify + it under the terms of the GNU General Library Public License as published + by the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + PLplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with PLplot; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/* + This example designed just for devices (e.g., psttfc and the + cairo-related devices) that use the pango and fontconfig libraries. The + best choice of glyph is selected by fontconfig and automatically rendered + by pango in way that is sensitive to complex text layout (CTL) language + issues for each unicode character in this example. Of course, you must + have the appropriate TrueType fonts installed to have access to all the + required glyphs. + + Translation instructions: The strings to be translated are given by + x_label, y_label, alty_label, title_label, and line_label below. The + encoding used must be UTF-8. + + The following strings to be translated involve some scientific/mathematical + jargon which is now discussed further to help translators. + + (1) dB is a decibel unit, see http://en.wikipedia.org/wiki/Decibel . + (2) degrees is an angular measure, see + http://en.wikipedia.org/wiki/Degree_(angle) . + (3) low-pass filter is one that transmits (passes) low frequencies. + (4) pole is in the mathematical sense, see + http://en.wikipedia.org/wiki/Pole_(complex_analysis) . "Single Pole" + means a particular mathematical transformation of the filter function has + a single pole, see + http://ccrma.stanford.edu/~jos/filters/Pole_Zero_Analysis_I.html . + Furthermore, a single-pole filter must have an inverse square decline + (or -20 db/decade). Since the filter plotted here does have that + characteristic, it must by definition be a single-pole filter, see also + http://www-k.ext.ti.com/SRVS/Data/ti/KnowledgeBases/analog/document/faqs/1p.htm + (5) decade represents a factor of 10, see + http://en.wikipedia.org/wiki/Decade_(log_scale) . +*/ + + +import std.string; +import std.math; + +import plplot; + +string[] x_label = [ + "Frequency", + "Частота", + null +]; + +string[] y_label = [ + "Amplitude (dB)", + "Амплитуда (dB)", + null +]; + +string[] alty_label = [ + "Phase shift (degrees)", + "Фазовый сдвиг (градусы)", + null +]; + +string[] title_label = [ + "Single Pole Low-Pass Filter", + "Однополюсный Низко-Частотный Фильтр", + null +]; + +string[] line_label = [ + "-20 dB/decade", + "-20 dB/десяток", + null +]; + + +/*--------------------------------------------------------------------------*\ + * main + * + * Illustration of logarithmic axes, and redefinition of window. +\*--------------------------------------------------------------------------*/ +int main(char[][] args) +{ + /* Parse and process command line arguments */ + plparseopts(args, PL_PARSE_FULL); + + /* Initialize plplot */ + plinit(); + plfont(2); + + /* Make log plots using two different styles. */ + int i=0; + while(x_label[i]) { + plot1(0, x_label[i], y_label[i], alty_label[i], title_label[i], line_label[i]); + i++; + } + + plend(); + return 0; +} + +/*--------------------------------------------------------------------------*\ + * plot1 + * + * Log-linear plot. +\*--------------------------------------------------------------------------*/ +void plot1(int type, string x_label, string y_label, string alty_label, + string title_label, string line_label) +{ + /* Set up data for log plot */ + PLFLT[101] freql, ampl, phase; + PLFLT f0=1.0, freq; + for(int i=0; i<101; i++) { + freql[i] = -2.0+i/20.0; + freq = pow(10.0, freql[i]); + ampl[i] = 20.0 * log10(1.0/sqrt(1.0+pow((freq/f0), 2.))); + phase[i] = -(180.0/PI) * atan(freq/f0); + } + + pladv(0); + + plvpor(0.15, 0.85, 0.1, 0.9); + plwind(-2.0, 3.0, -80.0, 0.0); + + /* Try different axis and labelling styles. */ + plcol0(1); + switch(type) { + case 0: + plbox("bclnst", 0.0, 0, "bnstv", 0.0, 0); + break; + case 1: + plbox("bcfghlnst", 0.0, 0, "bcghnstv", 0.0, 0); + break; + } + + /* Plot ampl vs freq */ + plcol0(2); + plline(freql, ampl); + plcol0(1); + plptex(1.6, -30.0, 1.0, -20.0, 0.5, line_label); + + /* Put labels on */ + plcol0(1); + plmtex("b", 3.2, 0.5, 0.5, x_label); + plmtex("t", 2.0, 0.5, 0.5, title_label); + plcol0(2); + plmtex("l", 5.0, 0.5, 0.5, y_label); + + /* For the gridless case, put phase vs freq on same plot */ + if(type==0) { + plcol0(1); + plwind(-2.0, 3.0, -100.0, 0.0); + plbox("", 0.0, 0, "cmstv", 30.0, 3); + plcol0(3); + plline(freql, phase); + plcol0(3); + plmtex("r", 5.0, 0.5, 0.5, alty_label); + } +} Property changes on: trunk/examples/d/x26d.d ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |