From: Alan W. I. <ai...@us...> - 2007-03-21 20:40:19
|
Update of /cvsroot/plplot/plplot/examples/ada In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8172/examples/ada Modified Files: x01a.adb x10a.adb Log Message: AWI commit of Jerry.B patch for Ada interfaces and examples. Result passed ctest without problems. Description of patch: ---- In x01a ---- White space changes. Some LF-LF occurrences had mysteriously been converted to LF-space. I hope this isn't pervasive. ---- In x10a ---- Added package Interfaces.C to allow access to the string conversion To_C. This will be needed in most examples using the thin binding. Added To_C to the calls to plbox, replacing calls to Box_Around_Viewport of the thick binding which had the additional string conversion TUB which renames Ada.Strings.Unbounded.To_Unbounded_String. White space changes. Made comments look more like x10c. Fixed call to plptex by converting the string argument to a C string--either is legal Ada but expect problems without the null termination. The only reason that I can see that this worked before is dumb (C) luck--C was looking for a null terminator and apparently saved itself by not checking the character array boundary and finding a character 0 just past the end, but I didn't investigate further. For kicks I tried removing the To_C from from one of the other string conversions "bc" and it too worked. These would eventually fail and cause unknown havoc (e.g. extraneous tick marks). The Ada Reference Manual Annex B.3 states that it is the programmer's responsibility to null-terminate strings being passed to C. The possibility of omitting the null terminator is one danger of using the thin binding; the thick binding does everything the Ada way. ---- In plplotthin.ad? ---- Added plparseopts with both one and three arguments. Tightened type checking for command parsing by adding type Parse_Mode_Type properly ranged. ---- In plplot.ad? ---- Incorporated parse change with new type Parse_Mode_Type. Index: x10a.adb =================================================================== RCS file: /cvsroot/plplot/plplot/examples/ada/x10a.adb,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- x10a.adb 1 Mar 2007 19:45:38 -0000 1.3 +++ x10a.adb 21 Mar 2007 20:40:17 -0000 1.4 @@ -1,6 +1,6 @@ -- $Id$ --- Simple line plot and multiple windows demo. +-- Window positioning demo. -- Copyright (C) 2007 Alan W. Irwin @@ -25,14 +25,14 @@ Ada.Numerics, Ada.Numerics.Long_Elementary_Functions, Ada.Strings.Bounded, - PLplot, + Interfaces.C, PlplotThin; use Ada.Text_IO, Ada.Numerics, Ada.Numerics.Long_Elementary_Functions, Ada.Strings.Bounded, - PLplot, + Interfaces.C, PlplotThin; -- COMMENT THIS LINE IF YOUR COMPILER DOES NOT INCLUDE THESE @@ -40,21 +40,21 @@ --with Ada.Numerics.Long_Real_Arrays; use Ada.Numerics.Long_Real_Arrays; procedure x10a is - begin - -- plplot initialization +begin + -- Parse and process command line arguments + plparseopts(PL_PARSE_FULL); --- plparseopts(PL_PARSE_FULL); - Parse_Command_Line_Arguments(PL_PARSE_FULL); + -- Initialize plplot plinit; + pladv(0); plvpor(0.0, 1.0, 0.0, 1.0); plwind(0.0, 1.0, 0.0, 1.0); --- plbox("bc", 0.0, 0, "bc", 0.0, 0); - Box_Around_Viewport(TUB("bc"), 0.0, 0, TUB("bc"), 0.0, 0); + plbox(To_C("bc"), 0.0, 0, To_C("bc"), 0.0, 0); + plsvpa(50.0, 150.0, 50.0, 100.0); plwind(0.0, 1.0, 0.0, 1.0); --- plbox("bc", 0.0, 0, "bc", 0.0, 0); - Box_Around_Viewport(TUB("bc"), 0.0, 0, TUB("bc"), 0.0, 0); - plptex(0.5, 0.5, 1.0, 0.0, 0.5, "BOX at (50,150,50,100)"); + plbox(To_C("bc"), 0.0, 0, To_C("bc"), 0.0, 0); + plptex(0.5, 0.5, 1.0, 0.0, 0.5, To_C("BOX at (50,150,50,100)")); plend; end x10a; Index: x01a.adb =================================================================== RCS file: /cvsroot/plplot/plplot/examples/ada/x01a.adb,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- x01a.adb 1 Mar 2007 19:24:54 -0000 1.3 +++ x01a.adb 21 Mar 2007 20:40:17 -0000 1.4 @@ -59,11 +59,12 @@ xmax := x(x'Last); ymin := y(y'First); ymax := y(y'Last); - for i in xs'Range loop + for i in xs'Range loop xs(i) := x(i * 10 + 3); ys(i) := y(i * 10 + 3); end loop; - -- Set up the viewport and window using Set_Environment. The range in X is + + -- Set up the viewport and window using Set_Environment. The range in X is -- 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are -- scaled separately (just = 0), and we just draw a labelled -- box (axis = 0). @@ -71,13 +72,17 @@ Set_Environment(xmin, xmax, ymin, ymax, Not_Justified, Linear_Box_Plus); Set_Color(Yellow); Write_Labels(TUB("(x)"), TUB("(y)"), TUB("#frPLplot Example 1 - y=x#u2")); - -- Plot the data points + + -- Plot the data points Set_Color(Aquamarine); Draw_Points(xs, ys, 9); - -- Draw the line through the data + + -- Draw the line through the data Set_Color(Green); Draw_Curve(x, y); end plot1; + + procedure plot2 is x, y : Real_Vector (0 .. 99); begin @@ -88,7 +93,8 @@ Set_Environment(-2.0, 10.0, -0.4, 1.2, Not_Justified, Linear_Zero_Axes); Set_Color(Yellow); Write_Labels(TUB("(x)"), TUB("sin(x)/x"), TUB("#frPLplot Example 1 - Sinc Function")); - -- Fill up the arrays + + -- Fill up the arrays for i in x'Range loop x(i) := (Long_Float(i) - 19.0) / 6.0; y(i) := 1.0; @@ -113,10 +119,12 @@ -- Y range from -1.2 to 1.2. Set_Viewport_Standard; Set_Viewport_World(0.0, 360.0, -1.2, 1.2); - -- Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y. + + -- Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y. Set_Color(Red); Box_Around_Viewport(TUB("bcnst"), 60.0, 2, TUB("bcnstv"), 0.2, 2); - -- Superimpose a dashed line grid, with 1.5 mm marks and spaces. + + -- Superimpose a dashed line grid, with 1.5 mm marks and spaces. -- plstyl expects a pointer! (-- Not Ada.) Set_Line_Style(mark1, space1); Set_Color(Yellow); @@ -134,6 +142,7 @@ Set_Color(Aquamarine); Draw_Curve(x, y); end plot3; + begin -- plplot initialization @@ -145,9 +154,11 @@ -- Get version number, just for kicks Put_Line("PLplot library version: " & Get_Version_Number); - -- Initialize plplot + + -- Initialize plplot Initialize_Plotter; - -- Set up the data + + -- Set up the data -- Original case xscale := 6.0; yscale := 1.0; @@ -156,15 +167,18 @@ -- Do a plot plot1; - -- Set up the data + + -- Set up the data xscale := 1.0; yscale := 0.0014; yoff := 0.0185; + -- Do a plot Set_Floating_Point_Display_Y(Max_Digits => 5, Field_Digits => 0); - plot1; + plot1; plot2; plot3; - -- Don't forget to call PLEND to finish off! + + -- Don't forget to call PLEND to finish off! Plot_End; end x01a; |