OpenWrt packages
Sign in or create your account | Project List | Help
OpenWrt packages Git Source Tree
Root/
| 1 | --[[ $Id: x31.lua 9533 2009-02-16 22:18:37Z smekal $ |
| 2 | |
| 3 | Copyright (C) 2008 Werner Smekal |
| 4 | |
| 5 | set/get tester |
| 6 | |
| 7 | This file is part of PLplot. |
| 8 | |
| 9 | PLplot is free software you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Library Public License as published |
| 11 | by the Free Software Foundation either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | PLplot is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU Library General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU Library General Public License |
| 20 | along with PLplot if not, write to the Free Software |
| 21 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | --]] |
| 23 | |
| 24 | |
| 25 | -- initialise Lua bindings for PLplot examples. |
| 26 | dofile("plplot_examples.lua") |
| 27 | |
| 28 | r1 = { 0, 255 } |
| 29 | g1 = { 255, 0 } |
| 30 | b1 = { 0, 0 } |
| 31 | a1 = { 1, 1 } |
| 32 | |
| 33 | -- Parse and process command line arguments |
| 34 | status = 0 |
| 35 | pl.parseopts(arg, pl.PL_PARSE_FULL) |
| 36 | |
| 37 | -- Test setting / getting familying parameters before plinit |
| 38 | -- Save values set by plparseopts to be restored later. |
| 39 | fam0, num0, bmax0 = pl.gfam() |
| 40 | fam1 = 0 |
| 41 | num1 = 10 |
| 42 | bmax1 = 1000 |
| 43 | pl.sfam(fam1, num1, bmax1) |
| 44 | |
| 45 | -- Retrieve the same values? |
| 46 | fam2, num2, bmax2 = pl.gfam() |
| 47 | print(string.format("family parameters: fam, num, bmax = %d %d %d", fam2, num2, bmax2)) |
| 48 | if fam2~=fam1 or num2~=num1 or bmax2~=bmax1 then |
| 49 | io.stderr:write("plgfam test failed\n") |
| 50 | status = 1 |
| 51 | end |
| 52 | -- Restore values set initially by plparseopts. |
| 53 | pl.sfam(fam0, num0, bmax0) |
| 54 | |
| 55 | -- Test setting / getting page parameters before plinit |
| 56 | -- Save values set by plparseopts to be restored later. |
| 57 | xp0, yp0, xleng0, yleng0, xoff0, yoff0 = pl.gpage() |
| 58 | xp1 = 200. |
| 59 | yp1 = 200. |
| 60 | xleng1 = 400 |
| 61 | yleng1 = 200 |
| 62 | xoff1 = 10 |
| 63 | yoff1 = 20 |
| 64 | pl.spage(xp1, yp1, xleng1, yleng1, xoff1, yoff1) |
| 65 | |
| 66 | -- Retrieve the same values? |
| 67 | xp2, yp2, xleng2, yleng2, xoff2, yoff2 = pl.gpage() |
| 68 | print(string.format("page parameters: xp, yp, xleng, yleng, xoff, yoff = %f %f %d %d %d %d", xp2, yp2, xleng2, yleng2, xoff2, yoff2)) |
| 69 | if xp2~=xp1 or yp2~=yp1 or xleng2~=xleng1 or yleng2~=yleng1 or xoff2~=xoff1 or yoff2~=yoff1 then |
| 70 | io.stderr:write("plgpage test failed\n") |
| 71 | status = 1 |
| 72 | end |
| 73 | -- Restore values set initially by plparseopts. |
| 74 | pl.spage(xp0, yp0, xleng0, yleng0, xoff0, yoff0) |
| 75 | |
| 76 | -- Test setting / getting compression parameter across plinit. |
| 77 | compression1 = 95 |
| 78 | pl.scompression(compression1) |
| 79 | |
| 80 | -- Initialize plplot |
| 81 | pl.init() |
| 82 | |
| 83 | -- Test if device initialization screwed around with the preset |
| 84 | -- compression parameter. |
| 85 | compression2 = pl.gcompression() |
| 86 | print("Output various PLplot parameters") |
| 87 | print("compression parameter = " .. compression2) |
| 88 | if compression2~=compression1 then |
| 89 | io.stderr:write("plgcompression test failed\n") |
| 90 | status = 1 |
| 91 | end |
| 92 | |
| 93 | |
| 94 | -- Exercise plscolor, plscol0, plscmap1, and plscmap1a to make sure |
| 95 | --they work without any obvious error messages. |
| 96 | pl.scolor(1) |
| 97 | pl.scol0(1, 255, 0, 0) |
| 98 | pl.scmap1(r1, g1, b1) |
| 99 | pl.scmap1a(r1, g1, b1, a1) |
| 100 | |
| 101 | level2 = pl.glevel() |
| 102 | print("level parameter = " .. level2) |
| 103 | if level2~=1 then |
| 104 | io.stderr:write("plglevel test failed.\n") |
| 105 | status = 1 |
| 106 | end |
| 107 | |
| 108 | pl.adv(0) |
| 109 | pl.vpor(0.01, 0.99, 0.02, 0.49) |
| 110 | xmin, xmax, ymin, ymax = pl.gvpd() |
| 111 | print(string.format("plvpor: xmin, xmax, ymin, ymax = %f %f %f %f", xmin, xmax, ymin, ymax)) |
| 112 | if xmin~=0.01 or xmax~=0.99 or ymin~=0.02 or ymax~=0.49 then |
| 113 | io.stderr:write("plgvpd test failed\n") |
| 114 | status = 1 |
| 115 | end |
| 116 | xmid = 0.5*(xmin+xmax) |
| 117 | ymid = 0.5*(ymin+ymax) |
| 118 | |
| 119 | pl.wind(0.2, 0.3, 0.4, 0.5) |
| 120 | xmin, xmax, ymin, ymax = pl.gvpw() |
| 121 | print(string.format("plwind: xmin, xmax, ymin, ymax = %f %f %f %f", xmin, xmax, ymin, ymax)) |
| 122 | if xmin~=0.2 or xmax~=0.3 or ymin~=0.4 or ymax~=0.5 then |
| 123 | io.stderr:write("plgvpw test failed\n") |
| 124 | status = 1 |
| 125 | end |
| 126 | |
| 127 | -- Get world coordinates for middle of viewport |
| 128 | wx, wy, win = pl.calc_world(xmid,ymid) |
| 129 | print(string.format("world parameters: wx, wy, win = %f %f %d", wx, wy, win)) |
| 130 | if math.abs(wx-0.5*(xmin+xmax))>1.0e-5 or math.abs(wy-0.5*(ymin+ymax))>1.0e-5 then |
| 131 | io.stderr:write("plcalc_world test failed\n") |
| 132 | status = 1 |
| 133 | end |
| 134 | |
| 135 | -- Retrieve and print the name of the output file (if any). |
| 136 | -- This goes to stderr not stdout since it will vary between tests and |
| 137 | -- we want stdout to be identical for compare test. |
| 138 | fnam = pl.gfnam() |
| 139 | if fnam=="" then |
| 140 | print("No output file name is set") |
| 141 | else |
| 142 | print("Output file name read") |
| 143 | end |
| 144 | io.stderr:write(string.format("Output file name is %s\n",fnam)) |
| 145 | |
| 146 | -- Set and get the number of digits used to display axis labels |
| 147 | -- Note digits is currently ignored in pls[xyz]ax and |
| 148 | -- therefore it does not make sense to test the returned |
| 149 | -- value |
| 150 | pl.sxax(3,0) |
| 151 | digmax, digits = pl.gxax() |
| 152 | print(string.format("x axis parameters: digmax, digits = %d %d", digmax, digits)) |
| 153 | if digmax~=3 then |
| 154 | io.stderr:write("plgxax test failed\n") |
| 155 | status = 1 |
| 156 | end |
| 157 | |
| 158 | pl.syax(4,0) |
| 159 | digmax, digits = pl.gyax() |
| 160 | print(string.format("y axis parameters: digmax, digits = %d %d", digmax, digits)) |
| 161 | if digmax~=4 then |
| 162 | io.stderr:write("plgyax test failed\n") |
| 163 | status = 1 |
| 164 | end |
| 165 | |
| 166 | pl.szax(5,0) |
| 167 | digmax,digits = pl.gzax() |
| 168 | print(string.format("z axis parameters: digmax, digits = %d %d", digmax, digits)) |
| 169 | if digmax~=5 then |
| 170 | io.stderr:write("plgzax test failed\n") |
| 171 | status = 1 |
| 172 | end |
| 173 | |
| 174 | pl.sdidev(0.05, pl.PL_NOTSET, 0.1, 0.2) |
| 175 | mar, aspect, jx, jy = pl.gdidev() |
| 176 | print(string.format("device-space window parameters: mar, aspect, jx, jy = %f %f %f %f" , mar, aspect, jx, jy)) |
| 177 | if mar~=0.05 or jx~=0.1 or jy~=0.2 then |
| 178 | io.stderr:write("plgdidev test failed\n") |
| 179 | status = 1 |
| 180 | end |
| 181 | |
| 182 | pl.sdiori(1.0) |
| 183 | ori = pl.gdiori() |
| 184 | print(string.format("ori parameter = %f", ori)) |
| 185 | if ori~=1.0 then |
| 186 | io.stderr:write("plgdiori test failed\n") |
| 187 | status = 1 |
| 188 | end |
| 189 | |
| 190 | pl.sdiplt(0.1, 0.2, 0.9, 0.8) |
| 191 | xmin, ymin, xmax, ymax = pl.gdiplt() |
| 192 | print(string.format("plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f", xmin, ymin, xmax, ymax)) |
| 193 | if xmin~=0.1 or xmax~=0.9 or ymin~=0.2 or ymax~=0.8 then |
| 194 | io.stderr:write("plgdiplt test failed\n") |
| 195 | status = 1 |
| 196 | end |
| 197 | |
| 198 | pl.sdiplz(0.1, 0.1, 0.9, 0.9) |
| 199 | zxmin, zymin, zxmax, zymax = pl.gdiplt() |
| 200 | print(string.format("zoomed plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f", zxmin, zymin, zxmax, zymax)) |
| 201 | if math.abs(zxmin -(xmin + (xmax-xmin)*0.1)) > 1.0e-5 or |
| 202 | math.abs(zxmax -(xmin+(xmax-xmin)*0.9)) > 1.0e-5 or |
| 203 | math.abs(zymin -(ymin+(ymax-ymin)*0.1)) > 1.0e-5 or |
| 204 | math.abs(zymax -(ymin+(ymax-ymin)*0.9)) > 1.0e-5 then |
| 205 | io.stderr:write("plsdiplz test failed\n") |
| 206 | status = 1 |
| 207 | end |
| 208 | |
| 209 | pl.scolbg(10, 20, 30) |
| 210 | r, g, b = pl.gcolbg() |
| 211 | print(string.format("background colour parameters: r, g, b = %d %d %d", r, g, b)) |
| 212 | if r~=10 or g~=20 or b~=30 then |
| 213 | io.stderr:write("plgcolbg test failed\n") |
| 214 | status = 1 |
| 215 | end |
| 216 | |
| 217 | pl.scolbga(20, 30, 40, 0.5) |
| 218 | r, g, b, a = pl.gcolbga() |
| 219 | print(string.format("background/transparency colour parameters: r, g, b, a = %d %d %d %f", r, g, b, a)) |
| 220 | if r~=20 or g~=30 or b~=40 or a~=0.5 then |
| 221 | io.stderr:write("plgcolbga test failed\n") |
| 222 | status = 1 |
| 223 | end |
| 224 | |
| 225 | pl.plend() |
| 226 |
