From: <jb...@us...> - 2008-08-16 05:41:35
|
Revision: 8665 http://plplot.svn.sourceforge.net/plplot/?rev=8665&view=rev Author: jbauck Date: 2008-08-16 05:41:44 +0000 (Sat, 16 Aug 2008) Log Message: ----------- Implement the new PLplot random number generation capability in the Ada bindings. Adjust Ada examples x21a.adb and xthick21a.adb accordingly. Other tweaks to Ada examples 21. Modified Paths: -------------- trunk/bindings/ada/plplot.adb.cmake trunk/bindings/ada/plplot.ads.cmake trunk/bindings/ada/plplot_thin.ads.cmake trunk/bindings/ada/plplot_traditional.adb.cmake trunk/bindings/ada/plplot_traditional.ads.cmake trunk/examples/ada/x21a.adb.cmake trunk/examples/ada/xthick21a.adb.cmake Modified: trunk/bindings/ada/plplot.adb.cmake =================================================================== --- trunk/bindings/ada/plplot.adb.cmake 2008-08-15 19:34:56 UTC (rev 8664) +++ trunk/bindings/ada/plplot.adb.cmake 2008-08-16 05:41:44 UTC (rev 8665) @@ -2083,6 +2083,15 @@ end Write_Text_World_3D; + -- Random number generator based on Mersenne Twister. + -- Obtain real random number in range [0,1]. + -- randd + function Random_Number return Long_Float is + begin + return plrandd; + end Random_Number; + + -- Replays contents of plot buffer to current device/file. -- plreplot procedure Replot is @@ -2401,6 +2410,14 @@ end Set_Zoom; + -- Set seed for internal random number generator + -- plseed + procedure Random_Number_Seed(Seed : Unsigned_Int) is + begin + plseed(Seed); + end Random_Number_Seed; + + -- Set the escape character for text strings. -- plsesc procedure Set_Escape_Character(Escape_Character : Character) is Modified: trunk/bindings/ada/plplot.ads.cmake =================================================================== --- trunk/bindings/ada/plplot.ads.cmake 2008-08-15 19:34:56 UTC (rev 8664) +++ trunk/bindings/ada/plplot.ads.cmake 2008-08-16 05:41:44 UTC (rev 8665) @@ -1239,6 +1239,12 @@ The_Text : String); + -- Random number generator based on Mersenne Twister. + -- Obtain real random number in range [0,1]. + -- plrandd + function Random_Number return Long_Float; + + -- Replays contents of plot buffer to current device/file. -- plreplot procedure Replot; @@ -1424,6 +1430,11 @@ y_Max_Relative : Long_Float); + -- Set seed for internal random number generator + -- plseed + procedure Random_Number_Seed(Seed : Unsigned_Int); + + -- Set the escape character for text strings. -- plsesc procedure Set_Escape_Character(Escape_Character : Character); Modified: trunk/bindings/ada/plplot_thin.ads.cmake =================================================================== --- trunk/bindings/ada/plplot_thin.ads.cmake 2008-08-15 19:34:56 UTC (rev 8664) +++ trunk/bindings/ada/plplot_thin.ads.cmake 2008-08-16 05:41:44 UTC (rev 8665) @@ -59,6 +59,7 @@ PLtrue : constant Integer := 1; subtype PLBOOL is Integer range PLfalse..PLtrue; type PLUNICODE is mod 2**32; + type Unsigned_Int is mod 2**32; -- for e.g. plseed subtype PL_Integer_Array is Integer_Array_1D; subtype PL_Float_Array is Real_Vector; @@ -1110,6 +1111,14 @@ pragma Import(C, plptex3, "c_plptex3"); + -- Random number generator based on Mersenne Twister. + -- Obtain real random number in range [0,1]. + + function + plrandd return Long_Float; + pragma Import(C, plrandd, "c_plrandd"); + + -- Replays contents of plot buffer to current device/file. procedure @@ -1294,6 +1303,13 @@ pragma Import(C, plsdiplz, "c_plsdiplz"); + -- Set seed for internal random number generator + + procedure + plseed(s : Unsigned_Int); + pragma Import(C, plseed, "c_plseed"); + + -- Set the escape character for text strings. procedure Modified: trunk/bindings/ada/plplot_traditional.adb.cmake =================================================================== --- trunk/bindings/ada/plplot_traditional.adb.cmake 2008-08-15 19:34:56 UTC (rev 8664) +++ trunk/bindings/ada/plplot_traditional.adb.cmake 2008-08-16 05:41:44 UTC (rev 8665) @@ -2000,6 +2000,14 @@ end plptex3; + -- Random number generator based on Mersenne Twister. + -- Obtain real random number in range [0,1]. + function plrandd return Long_Float is + begin + return PLplot_Thin.plrandd; + end plrandd; + + -- Replays contents of plot buffer to current device/file. procedure plreplot is begin @@ -2290,6 +2298,13 @@ end plsdiplz; + -- Set seed for internal random number generator + procedure plseed(Seed : Unsigned_Int) is + begin + PLplot_Thin.plseed(Seed); + end plseed; + + -- Set the escape character for text strings. procedure plsesc(Escape_Character : Character) is Modified: trunk/bindings/ada/plplot_traditional.ads.cmake =================================================================== --- trunk/bindings/ada/plplot_traditional.ads.cmake 2008-08-15 19:34:56 UTC (rev 8664) +++ trunk/bindings/ada/plplot_traditional.ads.cmake 2008-08-16 05:41:44 UTC (rev 8665) @@ -1153,6 +1153,11 @@ The_Text : String); + -- Random number generator based on Mersenne Twister. + -- Obtain real random number in range [0,1]. + function plrandd return Long_Float; + + -- Replays contents of plot buffer to current device/file. procedure plreplot; @@ -1313,6 +1318,10 @@ y_Max_Relative : Long_Float); + -- Set seed for internal random number generator + procedure plseed(Seed : Unsigned_Int); + + -- Set the escape character for text strings. procedure plsesc(Escape_Character : Character); Modified: trunk/examples/ada/x21a.adb.cmake =================================================================== --- trunk/examples/ada/x21a.adb.cmake 2008-08-15 19:34:56 UTC (rev 8664) +++ trunk/examples/ada/x21a.adb.cmake 2008-08-16 05:41:44 UTC (rev 8665) @@ -32,7 +32,7 @@ with Ada.Numerics, Ada.Numerics.Long_Elementary_Functions, - Ada.Numerics.Float_Random, + -- Ada.Numerics.Float_Random, Ada.Strings, Ada.Strings.Fixed, Ada.Calendar, @@ -43,7 +43,7 @@ use Ada.Numerics, Ada.Numerics.Long_Elementary_Functions, - Ada.Numerics.Float_Random, + -- Ada.Numerics.Float_Random, Ada.Strings, Ada.Strings.Fixed, Ada.Calendar, @@ -73,7 +73,7 @@ yg : Real_Vector(0 .. yp - 1); zg : Real_Matrix(0 .. xp - 1, 0 .. yp - 1); opt : Real_Vector(0 .. 5) := (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - Random_Generator : Generator; -- From Ada.Numerics.Float_Random + -- Random_Generator : Generator; -- From Ada.Numerics.Float_Random function title(which : Integer) return String is @@ -98,6 +98,7 @@ i(1) := 1.0; -- right boundary h(0) := 240.0; -- blue -> green -> yellow -> red + h(1) := 0.0; l(0) := 0.6; l(1) := 0.6; @@ -126,8 +127,10 @@ r, xt, yt : Long_Float; begin for i in x'range loop - xt := Long_Float(Random(Random_Generator)); - yt := Long_Float(Random(Random_Generator)); + -- xt := Long_Float(Random(Random_Generator)); + -- yt := Long_Float(Random(Random_Generator)); + xt := (xMM - xm) * plrandd; -- Use the PLplot random number generator + yt := (yMM - ym) * plrandd; -- to make the same plot as C example 21. if randn = 0 then x(i) := xt + xm; y(i) := yt + ym; @@ -144,6 +147,7 @@ end loop; end create_data; + -- Ada lacks full access to IEEE 754 aka IEC 559. The following works -- because a NaN is not equal to any other float, including itself. -- Use of the 'valid attribute might also work, as might casting to a 64-bit @@ -242,8 +246,10 @@ lzm := Vector_Min((lzm, zmin)); lzMM := Vector_Max((lzMM, zmax)); - lzm := lzm - 0.01; - lzMM := lzMM + 0.01; + -- Increase limits slightly to prevent spurious contours + -- due to rounding errors. + lzm := lzm - 0.01; + lzMM := lzMM + 0.01; plcol0(1); pladv(alg); Modified: trunk/examples/ada/xthick21a.adb.cmake =================================================================== --- trunk/examples/ada/xthick21a.adb.cmake 2008-08-15 19:34:56 UTC (rev 8664) +++ trunk/examples/ada/xthick21a.adb.cmake 2008-08-16 05:41:44 UTC (rev 8665) @@ -32,7 +32,7 @@ with Ada.Numerics, Ada.Numerics.Long_Elementary_Functions, - Ada.Numerics.Float_Random, + -- Ada.Numerics.Float_Random, Ada.Strings, Ada.Strings.Fixed, Ada.Calendar, @@ -43,7 +43,7 @@ use Ada.Numerics, Ada.Numerics.Long_Elementary_Functions, - Ada.Numerics.Float_Random, + -- Ada.Numerics.Float_Random, Ada.Strings, Ada.Strings.Fixed, Ada.Calendar, @@ -73,7 +73,7 @@ yg : Real_Vector(0 .. yp - 1); zg : Real_Matrix(0 .. xp - 1, 0 .. yp - 1); opt : Real_Vector(0 .. 5) := (0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - Random_Generator : Generator; -- From Ada.Numerics.Float_Random + -- Random_Generator : Generator; -- From Ada.Numerics.Float_Random function title(which : Integer) return String is @@ -98,6 +98,7 @@ i(1) := 1.0; -- right boundary h(0) := 240.0; -- blue -> green -> yellow -> red + h(1) := 0.0; l(0) := 0.6; l(1) := 0.6; @@ -126,8 +127,10 @@ r, xt, yt : Long_Float; begin for i in x'range loop - xt := Long_Float(Random(Random_Generator)); - yt := Long_Float(Random(Random_Generator)); + -- xt := Long_Float(Random(Random_Generator)); + -- yt := Long_Float(Random(Random_Generator)); + xt := (xMM - xm) * Random_Number; -- Use the PLplot random number generator + yt := (yMM - ym) * Random_Number; -- to make the same plot as C example 21. if randn = 0 then x(i) := xt + xm; y(i) := yt + ym; @@ -240,12 +243,18 @@ lzm := Matrix_Min(zg); lzMM := Matrix_Max(zg); + lzm := Vector_Min((lzm, zmin)); + lzMM := Vector_Max((lzMM, zmax)); + + -- Increase limits slightly to prevent spurious contours + -- due to rounding errors. + lzm := lzm - 0.01; + lzMM := lzMM + 0.01; + Set_Pen_Color(Red); Advance_To_Subpage(alg); if k = 0 then - lzm := Vector_Min((lzm, zmin)); - lzMM := Vector_Max((lzMM, zmax)); for i in clev'range loop clev(i) := lzm + (lzMM - lzm) / Long_Float(nl-1) * Long_Float(i); end loop; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |