1-- set/get tester 2 3-- Copyright (C) 2008 Jerry Bauck 4-- Copyright (C) 2008-2016 Alan W. Irwin 5 6-- This file is part of PLplot. 7 8-- PLplot is free software; you can redistribute it and/or modify 9-- it under the terms of the GNU Library General Public License as published 10-- by the Free Software Foundation; either version 2 of the License, or 11-- (at your option) any later version. 12 13-- PLplot is distributed in the hope that it will be useful, 14-- but WITHOUT ANY WARRANTY; without even the implied warranty of 15-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16-- GNU Library General Public License for more details. 17 18-- You should have received a copy of the GNU Library General Public License 19-- along with PLplot; if not, write to the Free Software 20-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 22with 23 Ada.Text_IO, 24 Ada.Long_Float_Text_IO, 25 Ada.Strings, 26 Ada.Strings.Fixed, 27 Ada.Strings.Unbounded, 28 Ada.Numerics, 29 Ada.Numerics.Long_Elementary_Functions, 30 PLplot_Auxiliary, 31 PLplot_Traditional; 32use 33 Ada.Text_IO, 34 Ada.Long_Float_Text_IO, 35 Ada.Strings, 36 Ada.Strings.Fixed, 37 Ada.Strings.Unbounded, 38 Ada.Numerics, 39 Ada.Numerics.Long_Elementary_Functions, 40 PLplot_Auxiliary, 41 PLplot_Traditional; 42 43-- This example mostly outputs text. As part of the PLplot testing regime, we 44-- require that the text output match that of the C version, x31c.c, exactly. 45-- Therefore, certain extra measures were made in this Ada version to assure 46-- that matching text is created. 47 48procedure xtraditional31a is 49 xmin0, xmax0, ymin0, ymax0, zxmin0, zxmax0, zymin0, zymax0 : Long_Float; 50 xmin, xmax, ymin, ymax, zxmin, zxmax, zymin, zymax : Long_Float; 51 xmid, ymid, wx, wy : Long_Float; 52 mar0, aspect0, jx0, jy0, ori0 : Long_Float; 53 mar, aspect, jx, jy, ori : Long_Float; 54 win, level2, digmax, digit, compression1, compression2 : Integer; 55 xp0, yp0, xp1, yp1, xp2, yp2 : Long_Float; 56 xleng0, yleng0, xoff0, yoff0 : Integer; 57 xleng1, yleng1, xoff1, yoff1, xleng2, yleng2, xoff2, yoff2 : Integer; 58 num0, bmax0, num1, bmax1, num2, bmax2, r0, g0, b0, r, g, b : Integer; 59 fam0, fam1, fam2 : Boolean; 60 a0, a : Long_Float; 61 r1 : Integer_0_255_Array(0 .. 1) := (0, 255); 62 g1 : Integer_0_255_Array(0 .. 1) := (0, 255); 63 b1 : Integer_0_255_Array(0 .. 1) := (0, 0); 64 a1 : Real_Vector(0 .. 1) := (1.0, 1.0); 65 status : Integer; 66 fnam : Unbounded_String; 67 68 -- Convert a boolean to integers 0 or 1. 69 function Boolean_To_Integer(B : Boolean) return Integer is 70 begin 71 if B then 72 return 1; 73 else 74 return 0; 75 end if; 76 end Boolean_To_Integer; 77 78 -- Function to return a formated float that looks like what C does. 79 function PF(x : Long_Float) return String is 80 A_String : String(1 .. 30); 81 begin 82 Put(A_String, x, Aft => 6, Exp => 0); 83 return Trim(A_String, Left); 84 end PF; 85 86begin 87 -- Parse and process command line arguments 88 status := 0; 89 90 plparseopts(PL_PARSE_FULL); 91 92 -- Test setting / getting familying parameters before plinit. 93 -- Save values set by plparseopts to be restored later. 94 plgfam(fam0, num0, bmax0); 95 fam1 := False; 96 num1 := 10; 97 bmax1 := 1000; 98 plsfam(fam1, num1, bmax1); 99 100 -- Retrieve the same values? 101 plgfam(fam2, num2, bmax2); 102 Put_Line("family parameters: fam, num, bmax =" 103 & Integer'image(Boolean_To_Integer(fam2)) 104 & Integer'image(num2) & Integer'image(bmax2)); 105 if fam2 /= fam1 or num2 /= num1 or bmax2 /= bmax1 then 106 Put_Line(Standard_Error, "plgfam test failed"); 107 status := 1; 108 end if; 109 -- Restore values set initially by plparseopts. 110 plsfam(fam0, num0, bmax0); 111 112 -- Test setting / getting page parameters before plinit. 113 -- Save values set by plparseopts to be restored later. 114 plgpage(xp0, yp0, xleng0, yleng0, xoff0, yoff0); 115 xp1 := 200.0; 116 yp1 := 200.0; 117 xleng1 := 400; 118 yleng1 := 200; 119 xoff1 := 10; 120 yoff1 := 20; 121 plspage(xp1, yp1, xleng1, yleng1, xoff1, yoff1); 122 123 -- Retrieve the same values? 124 plgpage(xp2, yp2, xleng2, yleng2, xoff2, yoff2); 125 Put("page parameters: xp, yp, xleng, yleng, xoff, yoff = " 126 & PF(xp2) & " " & PF(yp2)); 127 Put_Line(Integer'image(xleng2) & Integer'image(yleng2) 128 & Integer'image(xoff2) & Integer'image(yoff2)); 129 if xp2 /= xp1 or yp2 /= yp1 or xleng2 /= xleng1 or yleng2 /= yleng1 or 130 xoff2 /= xoff1 or yoff2 /= yoff1 then 131 Put_Line(Standard_Error, "plgpage test failed"); 132 status := 1; 133 end if; 134 -- Restore values set initially by plparseopts. 135 plspage(xp0, yp0, xleng0, yleng0, xoff0, yoff0); 136 137 -- Test setting / getting compression parameter across plinit. 138 compression1 := 95; 139 plscompression(compression1); 140 141 -- Initialize plplot. 142 plinit; 143 144 -- Test if device initialization screwed around with the preset 145 -- compression parameter. 146 plgcompression(compression2); 147 Put_Line("Output various PLplot parameters"); 148 Put_Line("compression parameter =" & Integer'image(compression2)); 149 if (compression2 /= compression1) then 150 Put_Line(Standard_Error, "plgcompression test failed"); 151 status := 1; 152 end if; 153 154 -- Exercise plscolor, plscol0, plscmap1, and plscmap1a to make sure 155 -- they work without any obvious error messages. 156 plscolor(True); 157 plscol0(1, 255, 0, 0); 158 plscmap1(r1, g1, b1); 159 plscmap1a(r1, g1, b1, a1); 160 161 plglevel(level2); 162 Put_Line("level parameter =" & Integer'image(level2)); 163 if (level2 /= 1) then 164 Put_Line(Standard_Error, "plglevel test failed."); 165 status := 1; 166 end if; 167 168 pladv(0); 169 170 xmin0 := 0.01; 171 xmax0 := 0.99; 172 ymin0 := 0.02; 173 ymax0 := 0.49; 174 plvpor(xmin0, xmax0, ymin0, ymax0); 175 plgvpd(xmin, xmax, ymin, ymax); 176 Put_Line("plvpor: xmin, xmax, ymin, ymax = " 177 & PF(xmin) & " " & PF(xmax) & " " & PF(ymin) & " " & PF(ymax)); 178 if xmin /= xmin0 or xmax /= xmax0 or ymin /= ymin0 or ymax /= ymax0 then 179 Put_Line(Standard_Error, "plgvpd test failed"); 180 status := 1; 181 end if; 182 xmid := 0.5 * (xmin + xmax); 183 ymid := 0.5 * (ymin + ymax); 184 185 xmin0 := 0.2; 186 xmax0 := 0.3; 187 ymin0 := 0.4; 188 ymax0 := 0.5; 189 plwind(xmin0, xmax0, ymin0, ymax0); 190 plgvpw(xmin, xmax, ymin, ymax); 191 Put_Line("plwind: xmin, xmax, ymin, ymax = " 192 & PF(xmin) & " " & PF(xmax) & " " & PF(ymin) & " " & PF(ymax)); 193 if xmin /= xmin0 or xmax /= xmax0 or ymin /= ymin0 or ymax /= ymax0 then 194 Put_Line(Standard_Error, "plgvpw test failed"); 195 status := 1; 196 end if; 197 198 -- Get world coordinates for middle of viewport. 199 plcalc_world(xmid,ymid,wx,wy,win); 200 Put_Line("world parameters: wx, wy, win = " 201 & PF(wx) & " " & PF(wy) & Integer'image(win)); 202 if abs(wx-0.5*(xmin+xmax))>1.0E-5 or abs(wy-0.5*(ymin+ymax))>1.0E-5 then 203 Put_Line(Standard_Error, "plcalc_world test failed"); 204 status := 1; 205 end if; 206 207 -- Retrieve and print the name of the output file (if any). 208 -- This goes to stderr not stdout since it will vary between tests and 209 -- we want stdout to be identical for compare test. 210 fnam := To_Unbounded_String(plgfnam); 211 if fnam = Null_Unbounded_String then 212 Put_Line("No output file name is set"); 213 else 214 Put_Line("Output file name read"); 215 end if; 216 Put_Line(Standard_Error, "Output file name is " & plgfnam); 217 218 -- Set and get the number of digits used to display axis labels. 219 -- Note digit is currently ignored in pls[xyz]ax and 220 -- therefore it does not make sense to test the returned value. 221 plsxax(3, 0); 222 plgxax(digmax, digit); 223 Put_Line("x axis parameters: digmax, digits =" 224 & Integer'image(digmax) & Integer'image(digit)); 225 if digmax /= 3 then 226 Put_Line(Standard_Error, "plgxax test failed"); 227 status := 1; 228 end if; 229 230 plsyax(4, 0); 231 plgyax(digmax, digit); 232 Put_Line("y axis parameters: digmax, digits =" 233 & Integer'image(digmax) & Integer'image(digit)); 234 if digmax /= 4 then 235 Put_Line(Standard_Error, "plgyax test failed"); 236 status := 1; 237 end if; 238 239 plszax(5, 0); 240 plgzax(digmax, digit); 241 Put_Line("z axis parameters: digmax, digits =" 242 & Integer'image(digmax) & Integer'image(digit)); 243 if digmax /= 5 then 244 Put_Line(Standard_Error, "plgzax test failed"); 245 status := 1; 246 end if; 247 248 mar0 := 0.05; 249 aspect0 := PL_NOTSET; 250 jx0 := 0.1; 251 jy0 := 0.2; 252 plsdidev(mar0, aspect0, jx0, jy0); 253 plgdidev(mar, aspect, jx, jy); 254 Put_Line("device-space window parameters: mar, aspect, jx, jy = " 255 & PF(mar) & " " & PF(aspect) & " " & PF(jx) & " " & PF(jy)); 256 if mar /= mar0 or jx /= jx0 or jy /= jy0 then 257 Put_Line(Standard_Error, "plgdidev test failed"); 258 status := 1; 259 end if; 260 261 ori0 := 1.0; 262 plsdiori(ori0); 263 plgdiori(ori); 264 Put_Line("ori parameter = " & PF(ori)); 265 if ori /= ori0 then 266 Put_Line(Standard_Error, "plgdiori test failed"); 267 status := 1; 268 end if; 269 270 xmin0 := 0.1; 271 ymin0 := 0.2; 272 xmax0 := 0.9; 273 ymax0 := 0.8; 274 plsdiplt(xmin0, ymin0, xmax0, ymax0); 275 plgdiplt(xmin, ymin, xmax, ymax); 276 Put_Line("plot-space window parameters: xmin, ymin, xmax, ymax = " 277 & PF(xmin) & " " & PF(ymin) & " " & PF(xmax) & " " & PF(ymax)); 278 if xmin /= xmin0 or ymin /= ymin0 or xmax /= xmax0 or ymax /= ymax0 then 279 Put_Line(Standard_Error, "plgdiplt test failed"); 280 status := 1; 281 end if; 282 283 zxmin0 := 0.1; 284 zymin0 := 0.1; 285 zxmax0 := 0.9; 286 zymax0 := 0.9; 287 plsdiplz(zxmin0, zymin0, zxmax0, zymax0); 288 plgdiplt(zxmin, zymin, zxmax, zymax); 289 Put_Line("zoomed plot-space window parameters: xmin, ymin, xmax, ymax = " 290 & PF(zxmin) & " " & PF(zymin) & " " & PF(zxmax) & " " & PF(zymax)); 291 if 292 abs(zxmin - (xmin + (xmax - xmin) * zxmin0)) > 1.0E-5 or 293 abs(zymin - (ymin + (ymax - ymin) * zymin0)) > 1.0E-5 or 294 abs(zxmax - (xmin + (xmax - xmin) * zxmax0)) > 1.0E-5 or 295 abs(zymax - (ymin + (ymax - ymin) * zymax0)) > 1.0E-5 296 then 297 Put_Line(Standard_Error, "plsdiplz test failed"); 298 status := 1; 299 end if; 300 301 plscolbg(10, 20, 30); 302 plgcolbg(r, g, b); 303 Put_Line("background colour parameters: r, g, b =" 304 & Integer'image(r) & Integer'image(g) & Integer'image(b)); 305 if r /= 10 or g /= 20 or b /= 30 then 306 Put_Line(Standard_Error, "plgcolbg test failed"); 307 status := 1; 308 end if; 309 310 r0 := 20; 311 g0 := 30; 312 b0 := 40; 313 a0 := 0.5; 314 plscolbga(r0, g0, b0, a0); 315 plgcolbga(r, g, b, a); 316 Put_Line("background/transparency colour parameters: r, g, b, a =" 317 & Integer'image(r) & Integer'image(g) & Integer'image(b) & " " & PF(a)); 318 if r /= r0 or g /= g0 or b /= b0 or a /= a0 then 319 Put_Line(Standard_Error, "plgcolbga test failed"); 320 status := 1; 321 end if; 322 323 plend; 324end xtraditional31a; 325