From: <and...@us...> - 2013-12-11 12:06:44
|
Revision: 12852 http://sourceforge.net/p/plplot/code/12852 Author: andrewross Date: 2013-12-11 12:06:41 +0000 (Wed, 11 Dec 2013) Log Message: ----------- Implement plpath for Ada bindings and update example 22 to remove the remaining differences. 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-11 10:11:54 UTC (rev 12851) +++ trunk/bindings/ada/plplot.adb 2013-12-11 12:06:41 UTC (rev 12852) @@ -2331,6 +2331,18 @@ end Set_Fill_Pattern; + -- 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 + begin + plpath(n, x1, y1, x2, y2); + end Draw_Line_Segment; + + -- Plots array y against x for n points using ASCII code "code". -- plpoin procedure Draw_Points Modified: trunk/bindings/ada/plplot.ads =================================================================== --- trunk/bindings/ada/plplot.ads 2013-12-11 10:11:54 UTC (rev 12851) +++ trunk/bindings/ada/plplot.ads 2013-12-11 12:06:41 UTC (rev 12852) @@ -1505,6 +1505,15 @@ Spacings : Integer_Array_1D); + -- 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); + + -- Plots array y against x for n points using ASCII code "code". -- plpoin procedure Draw_Points Modified: trunk/bindings/ada/plplot_thin.ads =================================================================== --- trunk/bindings/ada/plplot_thin.ads 2013-12-11 10:11:54 UTC (rev 12851) +++ trunk/bindings/ada/plplot_thin.ads 2013-12-11 12:06:41 UTC (rev 12852) @@ -1272,7 +1272,13 @@ 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 + plpath(n : PLINT; x1 : PLFLT; y1 : PLFLT; x2 : PLFLT; y2 : PLFLT); + pragma Import(C, plpath, "c_plpath"); + + -- Plots array y against x for n points using ASCII code "code". procedure Modified: trunk/bindings/ada/plplot_traditional.adb =================================================================== --- trunk/bindings/ada/plplot_traditional.adb 2013-12-11 10:11:54 UTC (rev 12851) +++ trunk/bindings/ada/plplot_traditional.adb 2013-12-11 12:06:41 UTC (rev 12852) @@ -2245,6 +2245,18 @@ end plpat; + -- 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 + begin + PLplot_Thin.plpath(n, x1, y1, x2, y2); + end plpath; + + -- Plots array y against x for n points using ASCII code "code". procedure plpoin (x, y : Real_Vector; Modified: trunk/bindings/ada/plplot_traditional.ads =================================================================== --- trunk/bindings/ada/plplot_traditional.ads 2013-12-11 10:11:54 UTC (rev 12851) +++ trunk/bindings/ada/plplot_traditional.ads 2013-12-11 12:06:41 UTC (rev 12852) @@ -1413,6 +1413,15 @@ 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); + + -- Plots array y against x for n points using ASCII code "code". procedure plpoin (x, y : Real_Vector; Modified: trunk/examples/ada/x22a.adb =================================================================== --- trunk/examples/ada/x22a.adb 2013-12-11 10:11:54 UTC (rev 12851) +++ trunk/examples/ada/x22a.adb 2013-12-11 12:06:41 UTC (rev 12852) @@ -33,8 +33,6 @@ PLplot_Traditional, PLplot_Auxiliary; - - procedure x22a 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); @@ -42,6 +40,7 @@ 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 @@ -102,7 +101,7 @@ xmax := Long_Float( nx / 2) * dx; ymin := Long_Float(-ny / 2) * dy; ymax := Long_Float( ny / 2) * dy; - + Q := 2.0; for i in 0 .. nx - 1 loop x := (Long_Float(i - nx / 2) + 0.5) * dx; @@ -129,7 +128,88 @@ plcol0(1); end constriction; + -- This spec is necessary in order to enforce C calling conventions, used + -- in the callback by intervening C code. + procedure transform + (x, y : Long_Float; + xt, yt : out Long_Float; + data : PLPointer); + pragma Convention(C, transform); + procedure transform + (x, y : Long_Float; + xt, yt : out Long_Float; + data : PLPointer) + is + begin + xt := x; + yt := y / 4.0 * ( 3.0 - cos( pi * x / xmax_data ) ); + end transform; + + -- Vector plot of flow through a constricted pipe + -- with a coordinate transformation + 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); + begin + dx := 1.0; + dy := 1.0; + + xmin := Long_Float(-nx / 2) * dx; + 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 ); + + 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; + end loop; + 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 ); + plcol0(1); + + -- Clear the global 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; @@ -254,6 +334,8 @@ -- Set arrow style using arrow2_x and arrow2_y then plot using these filled arrows. plsvect(arrow2_x, arrow2_y, True); constriction(2); + + constriction2; -- 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. Modified: trunk/examples/ada/xthick22a.adb =================================================================== --- trunk/examples/ada/xthick22a.adb 2013-12-11 10:11:54 UTC (rev 12851) +++ trunk/examples/ada/xthick22a.adb 2013-12-11 12:06:41 UTC (rev 12852) @@ -41,8 +41,9 @@ 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; @@ -128,8 +129,90 @@ Vector_Plot(u, v, -1.0, Plot_Transformation_2'access, cgrid2'Address); Set_Pen_Color(Red); end constriction; + + + -- This spec is necessary in order to enforce C calling conventions, used + -- in the callback by intervening C code. + procedure transform + (x, y : Long_Float; + xt, yt : out Long_Float; + data : PLPointer); + pragma Convention(C, transform); + procedure transform + (x, y : Long_Float; + xt, yt : out Long_Float; + data : PLPointer) + is + begin + xt := x; + yt := y / 4.0 * ( 3.0 - cos( pi * x / xmax_data ) ); + end transform; + + -- Vector plot of flow through a constricted pipe + -- with a coordinate transformation + 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); + begin + dx := 1.0; + dy := 1.0; + + xmin := Long_Float(-nx / 2) * dx; + 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); + + 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; + end loop; + 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); + 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 ); + Set_Pen_Color(Red); + + -- Clear the global transform. + Clear_Custom_Coordinate_Transform; + + end constriction2; + + -- Vector plot of the gradient of a shielded potential (see example 9) procedure potential is nper : constant Integer := 100; @@ -254,7 +337,9 @@ -- Set arrow style using arrow2_x and arrow2_y then plot using these filled arrows. Set_Arrow_Style_For_Vector_Plots(arrow2_x, arrow2_y, True); constriction(2); - + + constriction2; + -- 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); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |