From: <and...@us...> - 2008-07-22 10:42:35
|
Revision: 8551 http://plplot.svn.sourceforge.net/plplot/?rev=8551&view=rev Author: andrewross Date: 2008-07-22 10:42:44 +0000 (Tue, 22 Jul 2008) Log Message: ----------- Add support for plrandd, plrandi and plseed to java bindings. Update example 21 to use these. Now consistent with C version. Modified Paths: -------------- trunk/bindings/java/PLStream.java trunk/bindings/swig-support/plplotcapi.i trunk/examples/java/x21.java Modified: trunk/bindings/java/PLStream.java =================================================================== --- trunk/bindings/java/PLStream.java 2008-07-22 09:32:10 UTC (rev 8550) +++ trunk/bindings/java/PLStream.java 2008-07-22 10:42:44 UTC (rev 8551) @@ -549,6 +549,16 @@ plplotjavac.plptex3(x, y, z, dx, dy, dz, sx, sy, sz, just, text); } +public double randd() { + if (set_stream() == -1) return 0.0; + return plplotjavac.plrandd(); +} + +public long randi() { + if (set_stream() == -1) return 0; + return plplotjavac.plrandi(); +} + public void replot() { if (set_stream() == -1) return; plplotjavac.plreplot(); @@ -674,6 +684,11 @@ plplotjavac.plsdiplz(xmin, ymin, xmax, ymax); } +public void seed(long s) { + if (set_stream() == -1) return; + plplotjavac.plseed(s); +} + public void sesc(char esc) { if (set_stream() == -1) return; plplotjavac.plsesc(esc); Modified: trunk/bindings/swig-support/plplotcapi.i =================================================================== --- trunk/bindings/swig-support/plplotcapi.i 2008-07-22 09:32:10 UTC (rev 8550) +++ trunk/bindings/swig-support/plplotcapi.i 2008-07-22 10:42:44 UTC (rev 8551) @@ -560,6 +560,14 @@ void plptex3(PLFLT x, PLFLT y, PLFLT z, PLFLT dx, PLFLT dy, PLFLT dz, PLFLT sx, PLFLT sy, PLFLT sz, PLFLT just, const char *text); +%feature("autodoc","Return a random number in the range [0,1].") plrandd; +PLFLT +plrandd(); + +%feature("autodoc","Return a random number in the range [0,1].") plrandi; +unsigned long +plrandi(); + %feature("autodoc", "Replay contents of plot buffer to current device/file.") plreplot; void plreplot(void); @@ -659,6 +667,10 @@ void plsdiplz(PLFLT xmin, PLFLT ymin, PLFLT xmax, PLFLT ymax); +%feature("autodoc", "Seed the random number generator.") plseed; +void +plseed(unsigned int s); + %feature("autodoc", "Set the escape character for text strings.") plsesc; void plsesc(char esc); Modified: trunk/examples/java/x21.java =================================================================== --- trunk/examples/java/x21.java 2008-07-22 09:32:10 UTC (rev 8550) +++ trunk/examples/java/x21.java 2008-07-22 10:42:44 UTC (rev 8551) @@ -31,7 +31,6 @@ import plplot.core.*; import java.lang.Math; -import java.util.Random; class x21 { @@ -150,7 +149,7 @@ double opt[] = {0., 0., 0., 0., 0., 0.}; xm = ym = -0.2; - xM = yM = 0.8; + xM = yM = 0.6; // plplot initialization @@ -197,11 +196,10 @@ clev = new double[nl]; - xlab = new String("Npts="+pts+" gridx="+xp+" gridy="+yp); pls.col0(1); pls.env(xm, xM, ym, yM, 2, 0); pls.col0(15); - pls.lab(xlab, "", "The original data"); + pls.lab("X", "Y", "The original data sampling"); pls.col0(2); pls.poin(x, y, 5); pls.adv(0); @@ -212,10 +210,7 @@ pls.adv(0); for (alg=1; alg<7; alg++) { - ct = System.currentTimeMillis(); pls.griddata(x, y, z, xg, yg, zg, alg, opt[alg-1]); - xlab = new String("time="+(System.currentTimeMillis() - ct)/1000+" ms"); - ylab = new String("opt="+opt[alg-1]); /* - CSA can generate NaNs (only interpolates?!). * - DTLI and NNI can generate NaNs for points outside the @@ -274,7 +269,7 @@ pls.env0(xm, xM, ym, yM, 2, 0); pls.col0(15); - pls.lab(xlab, ylab, title[alg-1]); + pls.lab("X", "Y", title[alg-1]); pls.shades(zg, xm, xM, ym, yM, clev, 1, 0, 1, true, xg0, yg0); pls.col0(2); @@ -285,7 +280,7 @@ cmap1_init(); pls.vpor(0.0, 1.0, 0.0, 0.9); - pls.wind(-1.0, 1.0, -1.0, 1.5); + pls.wind(-1.1, 0.75, -0.65, 1.20); /* * For the comparison to be fair, all plots should have the * same z values, but to get the max/min of the data @@ -295,10 +290,10 @@ * plw3d(1., 1., 1., xm, xM, ym, yM, zmin, zmax, 30, -60); */ - pls.w3d(1., 1., 1., xm, xM, ym, yM, lzm[0], lzM[0], 30, -60); - pls.box3("bnstu", ylab, 0.0, 0, - "bnstu", xlab, 0.0, 0, - "bcdmnstuv", "", 0.0, 4); + pls.w3d(1., 1., 1., xm, xM, ym, yM, lzm[0], lzM[0], 30, -40); + pls.box3("bntu", "X", 0.0, 0, + "bntu", "Y", 0.0, 0, + "bcdfntu", "Z", 0.5, 0); pls.col0(15); pls.lab("", "", title[alg-1]); pls.plot3dc(xg, yg, zg, PLStream.DRAW_LINEXY | @@ -352,12 +347,11 @@ int i; double r; double xt, yt; - Random rnd = new Random(); int pts = x.length; for(i=0; i<pts; i++) { - xt = rnd.nextDouble(); - yt = rnd.nextDouble(); + xt = (xM-xm)*pls.randd(); + yt = (yM-ym)*pls.randd(); if (randn == 0) { x[i] = xt + xm; y[i] = yt + ym; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |