|
From: <jb...@us...> - 2013-12-13 10:18:11
|
Revision: 12862
http://sourceforge.net/p/plplot/code/12862
Author: jbauck
Date: 2013-12-13 10:18:08 +0000 (Fri, 13 Dec 2013)
Log Message:
-----------
Merge my edits with Andrew's from 12852.
Modified Paths:
--------------
trunk/bindings/ada/plplot.adb
trunk/bindings/ada/plplot.ads
trunk/bindings/ada/plplot_thin.ads
trunk/bindings/ada/plplot_traditional.adb
trunk/bindings/ada/plplot_traditional.ads
trunk/examples/ada/x22a.adb
trunk/examples/ada/xthick22a.adb
Modified: trunk/bindings/ada/plplot.adb
===================================================================
--- trunk/bindings/ada/plplot.adb 2013-12-13 05:28:03 UTC (rev 12861)
+++ trunk/bindings/ada/plplot.adb 2013-12-13 10:18:08 UTC (rev 12862)
@@ -2332,15 +2332,12 @@
-- Draw a line connecting two points, accounting for coordinate transform
- procedure Draw_Line_Segment
- (n : Integer;
- x1 : Long_Float;
- y1 : Long_Float;
- x2 : Long_Float;
- y2 : Long_Float) is
+ procedure Draw_Line_With_Transform
+ (Num_Segments : Integer;
+ x1, y1, x2, y2 : Long_Float) is
begin
- plpath(n, x1, y1, x2, y2);
- end Draw_Line_Segment;
+ plpath(Num_Segments, x1, y1, x2, y2);
+ end Draw_Line_With_Transform;
-- Plots array y against x for n points using ASCII code "code".
Modified: trunk/bindings/ada/plplot.ads
===================================================================
--- trunk/bindings/ada/plplot.ads 2013-12-13 05:28:03 UTC (rev 12861)
+++ trunk/bindings/ada/plplot.ads 2013-12-13 10:18:08 UTC (rev 12862)
@@ -1506,12 +1506,9 @@
-- Draw a line connecting two points, accounting for coordinate transform
- procedure Draw_Line_Segment
- (n : Integer;
- x1 : Long_Float;
- y1 : Long_Float;
- x2 : Long_Float;
- y2 : Long_Float);
+ procedure Draw_Line_With_Transform
+ (Num_Segments : Integer;
+ x1, y1, x2, y2 : Long_Float);
-- Plots array y against x for n points using ASCII code "code".
Modified: trunk/bindings/ada/plplot_thin.ads
===================================================================
--- trunk/bindings/ada/plplot_thin.ads 2013-12-13 05:28:03 UTC (rev 12861)
+++ trunk/bindings/ada/plplot_thin.ads 2013-12-13 10:18:08 UTC (rev 12862)
@@ -1272,6 +1272,7 @@
plpat(nlin : PLINT; inc : PL_Integer_Array; del : PL_Integer_Array);
pragma Import(C, plpat, "c_plpat");
+
-- Draw a line connecting two points, accounting for coordinate transforms.
procedure
Modified: trunk/bindings/ada/plplot_traditional.adb
===================================================================
--- trunk/bindings/ada/plplot_traditional.adb 2013-12-13 05:28:03 UTC (rev 12861)
+++ trunk/bindings/ada/plplot_traditional.adb 2013-12-13 10:18:08 UTC (rev 12862)
@@ -2247,13 +2247,10 @@
-- Draw a line connecting two points, accounting for coordinate transform
procedure plpath
- (n : Integer;
- x1 : Long_Float;
- y1 : Long_Float;
- x2 : Long_Float;
- y2 : Long_Float) is
+ (Num_Segments : Integer;
+ x1, y1, x2, y2 : Long_Float) is
begin
- PLplot_Thin.plpath(n, x1, y1, x2, y2);
+ PLplot_Thin.plpath(Num_Segments, x1, y1, x2, y2);
end plpath;
Modified: trunk/bindings/ada/plplot_traditional.ads
===================================================================
--- trunk/bindings/ada/plplot_traditional.ads 2013-12-13 05:28:03 UTC (rev 12861)
+++ trunk/bindings/ada/plplot_traditional.ads 2013-12-13 10:18:08 UTC (rev 12862)
@@ -1413,13 +1413,11 @@
Spacings : Integer_Array_1D);
+
-- Draw a line connecting two points, accounting for coordinate transform
procedure plpath
- (n : Integer;
- x1 : Long_Float;
- y1 : Long_Float;
- x2 : Long_Float;
- y2 : Long_Float);
+ (Num_Segments : Integer;
+ x1, y1, x2, y2 : Long_Float);
-- Plots array y against x for n points using ASCII code "code".
Modified: trunk/examples/ada/x22a.adb
===================================================================
--- trunk/examples/ada/x22a.adb 2013-12-13 05:28:03 UTC (rev 12861)
+++ trunk/examples/ada/x22a.adb 2013-12-13 10:18:08 UTC (rev 12862)
@@ -2,7 +2,7 @@
-- Simple vector plot example
--- Copyright (C) 2008 Jerry Bauck
+-- Copyright (C) 2008, 2013 Jerry Bauck
-- This file is part of PLplot.
@@ -22,6 +22,7 @@
with
System,
+ System.Address_To_Access_Conversions,
Ada.Numerics,
Ada.Numerics.Long_Elementary_Functions,
PLplot_Traditional,
@@ -40,7 +41,6 @@
arrow2_x : Real_Vector(0 .. 5) := (-0.5, 0.3, 0.3, 0.5, 0.3, 0.3);
arrow2_y : Real_Vector(0 .. 5) := ( 0.0, 0.0, 0.2, 0.0, -0.2, 0.0);
- xmax_data : Long_Float;
-- Vector plot of the circulation about the origin
procedure circulation is
@@ -122,7 +122,8 @@
end loop;
plenv(xmin, xmax, ymin, ymax, 0, 0);
- pllab("(x)", "(y)", "#frPLplot Example 22 - constriction (arrow style"&Integer'image(astyle)&")");
+ pllab("(x)", "(y)", "#frPLplot Example 22 - constriction (arrow style" &
+ Integer'image(astyle) & ")");
plcol0(2);
plvect(u, v, -1.0, pltr2'access, cgrid2'Address);
plcol0(1);
@@ -136,79 +137,87 @@
data : PLPointer);
pragma Convention(C, transform);
- procedure transform
- (x, y : Long_Float;
- xt, yt : out Long_Float;
- data : PLPointer)
- is
+ -- Global transform function for a constriction using data passed in
+ -- This is the same transformation used in constriction.
+ procedure transform(x, y : Long_Float; xt, yt : out Long_Float; Data : PLPointer) is
+
+ -- Convert the generic pointer represented as System.Address to a proper Ada pointer aka
+ -- access variable. Recall that PLpointer is a subtype of System.Address.
+ package Data_Address_Conversions is new System.Address_To_Access_Conversions(Long_Float);
+ Data_Pointer : Data_Address_Conversions.Object_Pointer; -- An Ada access variable
+ xmax : Long_Float;
begin
+ Data_Pointer := Data_Address_Conversions.To_Pointer(Data);
+ xmax := Data_Pointer.all;
xt := x;
- yt := y / 4.0 * ( 3.0 - cos( pi * x / xmax_data ) );
+ yt := y / 4.0 * (3.0 - cos(Pi * x / xmax));
end transform;
- -- Vector plot of flow through a constricted pipe
- -- with a coordinate transformation
+
+ -- Vector plot of flow through a constricted pipe with a coordinate transform
procedure constriction2 is
dx, dy, x, y : Long_Float;
xmin, xmax, ymin, ymax : Long_Float;
Q, b : Long_Float;
nx : constant Integer := 20;
ny : constant Integer := 20;
- nc : constant Integer := 11;
- nseg : constant Integer := 20;
- u, v : Real_Matrix(0 .. nx - 1, 0 .. ny -1);
- clev : Real_Vector(0 .. nc - 1);
cgrid2 : aliased Transformation_Data_Type_2
(x_Last => nx - 1,
y_Last => ny - 1);
+ u, v : Real_Matrix(0 .. nx - 1, 0 .. ny - 1);
+ nc : constant Integer := 11;
+ nseg : constant Integer := 20;
+ clev : Real_Vector(0 .. nc - 1);
begin
dx := 1.0;
dy := 1.0;
- xmin := Long_Float(-nx / 2) * dx;
+ xmin := Long_Float(-nx / 2) * dx; -- Careful; Ada / rounds, C / truncates.
xmax := Long_Float( nx / 2) * dx;
ymin := Long_Float(-ny / 2) * dy;
ymax := Long_Float( ny / 2) * dy;
-
- xmax_data := xmax;
- plstransform( transform'Unrestricted_Access, System.Null_Address );
+ plstransform(transform'Unrestricted_Access, xmax'Address);
+ cgrid2.nx := nx;
+ cgrid2.ny := ny;
Q := 2.0;
+
for i in 0 .. nx - 1 loop
x := (Long_Float(i - nx / 2) + 0.5) * dx;
- for j in 0 .. ny - 1 loop
- y := (Long_Float(j - ny / 2) + 0.5) * dy;
- cgrid2.xg(i, j) := x;
- cgrid2.yg(i, j) := y;
- b := ymax / 4.0 * (3.0 - cos(pi * x / xmax));
- u(i, j) := Q * ymax / b;
- v(i, j) := 0.0;
+ for j in 0 .. ny - 1 loop
+ y := (Long_Float(j - ny / 2) + 0.5) * dy;
+ cgrid2.xg(i, j) := x;
+ cgrid2.yg(i, j) := y;
+ b := ymax / 4.0 * (3.0 - cos(Pi * x / xmax));
+ u(i, j) := Q * ymax / b;
+ v(i, j) := 0.0;
end loop;
end loop;
-
- for i in 0 .. nc - 1 loop
- clev(i) := Q + Long_Float(i) * Q / Long_Float( nc - 1 );
- end loop;
+ for i in 0 .. nc - 1 loop
+ clev(i) := Q + Long_Float(i) * Q / Long_Float(nc - 1);
+ end loop;
+
plenv(xmin, xmax, ymin, ymax, 0, 0);
pllab("(x)", "(y)", "#frPLplot Example 22 - constriction with plstransform");
plcol0(2);
- plshades(u, Null, xmin + dx / 2.0, xmax - dx / 2.0,
- ymin + dy / 2.0, ymax - dy / 2.0,
- clev, 0.0, 1, 1.0,
- plfill'access, False, Null, System.Null_Address);
- plvect(u, v, -1.0, pltr2'access, cgrid2'Address);
- plpath( nseg, xmin, ymax, xmax, ymax );
- plpath( nseg, xmin, ymin, xmax, ymin );
+ plshades(u, Null,
+ xmin + dx / 2.0, xmax - dx / 2.0, ymin + dy / 2.0, ymax - dy / 2.0,
+ clev, 0.0, 1, 1.0, plfill'access, False, Null, System.Null_Address);
+ plvect(u, v,
+ -1.0, pltr2'access, cgrid2'Address);
+
+ -- Plot edges using plpath (which accounts for coordinate transformation) rather than plline
+ plpath(nseg, xmin, ymax, xmax, ymax);
+ plpath(nseg, xmin, ymin, xmax, ymin);
plcol0(1);
-
- -- Clear the global transform.
- Clear_Custom_Coordinate_Transform;
- -- or...
- -- plstransform(null, System.Null_Address);
-
+
+ Clear_Custom_Coordinate_Transform;
+ -- or...
+ -- plstransform(null, System.Null_Address);
end constriction2;
+
-- Vector plot of the gradient of a shielded potential (see example 9)
procedure potential is
@@ -318,7 +327,6 @@
-- Generates several simple vector plots.
----------------------------------------------------------------------------
begin
-
-- Parse and process command line arguments
plparseopts(PL_PARSE_FULL);
@@ -339,10 +347,10 @@
-- Reset arrow style to the default by passing two NULL arrays.
-- This line uses the awkward method of the C API to reset the default arrow style.
- plsvect(System.Null_Address, System.Null_Address, False);
+ -- plsvect(System.Null_Address, System.Null_Address, False);
-- This method of resetting the default arrow style is a little more Ada-friendly...
- -- plsvect;
+ plsvect;
-- ... as is this one which is identical but for name.
-- Reset_Vector_Arrow_Style;
Modified: trunk/examples/ada/xthick22a.adb
===================================================================
--- trunk/examples/ada/xthick22a.adb 2013-12-13 05:28:03 UTC (rev 12861)
+++ trunk/examples/ada/xthick22a.adb 2013-12-13 10:18:08 UTC (rev 12862)
@@ -2,7 +2,7 @@
-- Simple vector plot example
--- Copyright (C) 2008 Jerry Bauck
+-- Copyright (C) 2008, 2013 Jerry Bauck
-- This file is part of PLplot.
@@ -22,6 +22,7 @@
with
System,
+ System.Address_To_Access_Conversions,
Ada.Numerics,
Ada.Numerics.Long_Elementary_Functions,
PLplot,
@@ -33,17 +34,14 @@
PLplot,
PLplot_Auxiliary;
-
-
procedure xthick22a is
-- Pairs of points making the line segments used to plot the user defined arrow
arrow_x : Real_Vector(0 .. 5) := (-0.5, 0.5, 0.3, 0.5, 0.3, 0.5);
arrow_y : Real_Vector(0 .. 5) := ( 0.0, 0.0, 0.2, 0.0, -0.2, 0.0);
arrow2_x : Real_Vector(0 .. 5) := (-0.5, 0.3, 0.3, 0.5, 0.3, 0.3);
arrow2_y : Real_Vector(0 .. 5) := ( 0.0, 0.0, 0.2, 0.0, -0.2, 0.0);
-
- xmax_data : Long_Float;
+
-- Vector plot of the circulation about the origin
procedure circulation is
dx, dy, x, y : Long_Float;
@@ -139,80 +137,88 @@
data : PLPointer);
pragma Convention(C, transform);
- procedure transform
- (x, y : Long_Float;
- xt, yt : out Long_Float;
- data : PLPointer)
- is
+ -- Global transform function for a constriction using data passed in
+ -- This is the same transformation used in constriction.
+ procedure transform(x, y : Long_Float; xt, yt : out Long_Float; Data : PLPointer) is
+
+ -- Convert the generic pointer represented as System.Address to a proper Ada pointer aka
+ -- access variable. Recall that PLpointer is a subtype of System.Address.
+ package Data_Address_Conversions is new System.Address_To_Access_Conversions(Long_Float);
+ Data_Pointer : Data_Address_Conversions.Object_Pointer; -- An Ada access variable
+ xmax : Long_Float;
begin
+ Data_Pointer := Data_Address_Conversions.To_Pointer(Data);
+ xmax := Data_Pointer.all;
xt := x;
- yt := y / 4.0 * ( 3.0 - cos( pi * x / xmax_data ) );
+ yt := y / 4.0 * (3.0 - cos(Pi * x / xmax));
end transform;
- -- Vector plot of flow through a constricted pipe
- -- with a coordinate transformation
+ -- Vector plot of flow through a constricted pipe with a coordinate transform
procedure constriction2 is
dx, dy, x, y : Long_Float;
xmin, xmax, ymin, ymax : Long_Float;
Q, b : Long_Float;
nx : constant Integer := 20;
ny : constant Integer := 20;
- nc : constant Integer := 11;
- nseg : constant Integer := 20;
- u, v : Real_Matrix(0 .. nx - 1, 0 .. ny -1);
- clev : Real_Vector(0 .. nc - 1);
cgrid2 : aliased Transformation_Data_Type_2
(x_Last => nx - 1,
y_Last => ny - 1);
+ u, v : Real_Matrix(0 .. nx - 1, 0 .. ny - 1);
+ nc : constant Integer := 11;
+ nseg : constant Integer := 20;
+ clev : Real_Vector(0 .. nc - 1);
begin
dx := 1.0;
dy := 1.0;
- xmin := Long_Float(-nx / 2) * dx;
+ xmin := Long_Float(-nx / 2) * dx; -- Careful; Ada / rounds, C / truncates.
xmax := Long_Float( nx / 2) * dx;
ymin := Long_Float(-ny / 2) * dy;
ymax := Long_Float( ny / 2) * dy;
- xmax_data := xmax;
-
- Set_Custom_Coordinate_Transform(transform'Unrestricted_Access, System.Null_Address);
-
+ Set_Custom_Coordinate_Transform(transform'Unrestricted_Access, xmax'Address);
+
+ cgrid2.nx := nx;
+ cgrid2.ny := ny;
Q := 2.0;
+
for i in 0 .. nx - 1 loop
x := (Long_Float(i - nx / 2) + 0.5) * dx;
- for j in 0 .. ny - 1 loop
- y := (Long_Float(j - ny / 2) + 0.5) * dy;
- cgrid2.xg(i, j) := x;
- cgrid2.yg(i, j) := y;
- b := ymax / 4.0 * (3.0 - cos(pi * x / xmax));
- u(i, j) := Q * ymax / b;
- v(i, j) := 0.0;
+ for j in 0 .. ny - 1 loop
+ y := (Long_Float(j - ny / 2) + 0.5) * dy;
+ cgrid2.xg(i, j) := x;
+ cgrid2.yg(i, j) := y;
+ b := ymax / 4.0 * (3.0 - cos(Pi * x / xmax));
+ u(i, j) := Q * ymax / b;
+ v(i, j) := 0.0;
end loop;
end loop;
- for i in 0 .. nc - 1 loop
- clev(i) := Q + Long_Float(i) * Q / Long_Float( nc - 1 );
- end loop;
+ for i in 0 .. nc - 1 loop
+ clev(i) := Q + Long_Float(i) * Q / Long_Float(nc - 1);
+ end loop;
- Set_Environment(xmin, xmax, ymin, ymax, Not_Justified, Linear_Box_Plus);
+ Set_Environment(xmin, xmax, ymin, ymax, 0, 0);
Write_Labels("(x)", "(y)", "#frPLplot Example 22 - constriction with plstransform");
Set_Pen_Color(Yellow);
- Shade_Regions(u, Null, xmin + dx / 2.0, xmax - dx / 2.0,
- ymin + dy / 2.0, ymax - dy / 2.0,
- clev, 0.0, 1, 1.0,
- Fill_Polygon'access, False, Null, System.Null_Address);
- Vector_Plot(u, v, -1.0, Plot_Transformation_2'access, cgrid2'Address);
- Draw_Line_Segment( nseg, xmin, ymax, xmax, ymax );
- Draw_Line_Segment( nseg, xmin, ymin, xmax, ymin );
+ Shade_Regions(u, Null,
+ xmin + dx / 2.0, xmax - dx / 2.0, ymin + dy / 2.0, ymax - dy / 2.0,
+ clev, 0.0, 1, 1.0, Fill_Polygon'access, False, Null, System.Null_Address);
+ Vector_Plot(u, v,
+ -1.0, Plot_Transformation_2'access, cgrid2'Address);
+
+ -- Plot edges using plpath (which accounts for coordinate transformation) rather than plline
+ Draw_Line_With_Transform(nseg, xmin, ymax, xmax, ymax);
+ Draw_Line_With_Transform(nseg, xmin, ymin, xmax, ymin);
Set_Pen_Color(Red);
-
- -- Clear the global transform.
- Clear_Custom_Coordinate_Transform;
+ Clear_Custom_Coordinate_Transform;
+ -- or...
+ -- plstransform(null, System.Null_Address);
end constriction2;
-
-
+
+
-- Vector plot of the gradient of a shielded potential (see example 9)
procedure potential is
nper : constant Integer := 100;
@@ -342,13 +348,13 @@
-- Reset arrow style to the default by passing two NULL arrays.
-- This line uses the awkward method of the C API to reset the default arrow style.
- Set_Arrow_Style_For_Vector_Plots(System.Null_Address, System.Null_Address, False);
+ -- Set_Arrow_Style_For_Vector_Plots(System.Null_Address, System.Null_Address, False);
-- This method of resetting the default arrow style is a little more Ada-friendly...
-- plsvect;
-- ... as is this one which is identical but for name.
- -- Reset_Vector_Arrow_Style;
+ Reset_Vector_Arrow_Style;
potential;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|