1--[[
2  Copyright (C) 2008 Werner Smekal
3  Copyright (C) 2008-2016 Alan W. Irwin
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 Library General 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.
26dofile("plplot_examples.lua")
27
28r1 = { 0, 255 }
29g1 = { 255, 0 }
30b1 = { 0, 0 }
31a1 = { 1, 1 }
32
33-- Parse and process command line arguments
34status = 0
35pl.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.
39fam0, num0, bmax0 = pl.gfam()
40fam1 = 0
41num1 = 10
42bmax1 = 1000
43pl.sfam(fam1, num1, bmax1)
44
45-- Retrieve the same values?
46fam2, num2, bmax2 = pl.gfam()
47print(string.format("family parameters: fam, num, bmax = %d %d %d", fam2, num2, bmax2))
48if fam2~=fam1 or num2~=num1 or bmax2~=bmax1 then
49  io.stderr:write("plgfam test failed\n")
50  status = 1
51end
52-- Restore values set initially by plparseopts.
53pl.sfam(fam0, num0, bmax0)
54
55-- Test setting / getting page parameters before plinit
56-- Save values set by plparseopts to be restored later.
57xp0, yp0, xleng0, yleng0, xoff0, yoff0 = pl.gpage()
58xp1 = 200.
59yp1 = 200.
60xleng1 = 400
61yleng1 = 200
62xoff1 = 10
63yoff1 = 20
64pl.spage(xp1, yp1, xleng1, yleng1, xoff1, yoff1)
65
66-- Retrieve the same values?
67xp2, yp2, xleng2, yleng2, xoff2, yoff2 = pl.gpage()
68print(string.format("page parameters: xp, yp, xleng, yleng, xoff, yoff = %f %f %d %d %d %d", xp2, yp2, xleng2, yleng2, xoff2, yoff2))
69if 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
72end
73-- Restore values set initially by plparseopts.
74pl.spage(xp0, yp0, xleng0, yleng0, xoff0, yoff0)
75
76-- Test setting / getting compression parameter across plinit.
77compression1 = 95
78pl.scompression(compression1)
79
80-- Initialize plplot
81pl.init()
82
83-- Test if device initialization screwed around with the preset
84-- compression parameter.
85compression2 = pl.gcompression()
86print("Output various PLplot parameters")
87print(string.format("compression parameter = %d", compression2))
88if compression2~=compression1 then
89  io.stderr:write("plgcompression test failed\n")
90  status = 1
91end
92
93
94-- Exercise plscolor, plscol0, plscmap1, and plscmap1a to make sure
95--they work without any obvious error messages.
96pl.scolor(1)
97pl.scol0(1, 255, 0, 0)
98pl.scmap1(r1, g1, b1)
99pl.scmap1a(r1, g1, b1, a1)
100
101level2 = pl.glevel()
102print(string.format("level parameter = %d", level2))
103if level2~=1 then
104  io.stderr:write("plglevel test failed.\n")
105  status = 1
106end
107
108pl.adv(0)
109
110xmin0 = 0.01
111xmax0 = 0.99
112ymin0 = 0.02
113ymax0 = 0.49
114pl.vpor(xmin0, xmax0, ymin0, ymax0)
115xmin, xmax, ymin, ymax = pl.gvpd()
116print(string.format("plvpor: xmin, xmax, ymin, ymax = %f %f %f %f", xmin, xmax, ymin, ymax))
117if xmin~=xmin0 or xmax~=xmax0 or ymin~=ymin0 or ymax~=ymax0 then
118  io.stderr:write("plgvpd test failed\n")
119  status = 1
120end
121xmid = 0.5*(xmin+xmax)
122ymid = 0.5*(ymin+ymax)
123
124xmin0 = 0.2
125xmax0 = 0.3
126ymin0 = 0.4
127ymax0 = 0.5
128pl.wind(xmin0, xmax0, ymin0, ymax0)
129xmin, xmax, ymin, ymax = pl.gvpw()
130print(string.format("plwind: xmin, xmax, ymin, ymax = %f %f %f %f", xmin, xmax, ymin, ymax))
131if xmin~=xmin0 or xmax~=xmax0 or ymin~=ymin0 or ymax~=ymax0 then
132  io.stderr:write("plgvpw test failed\n")
133  status = 1
134end
135
136-- Get world coordinates for middle of viewport
137wx, wy, win = pl.calc_world(xmid,ymid)
138print(string.format("world parameters: wx, wy, win = %f %f %d", wx, wy, win))
139if math.abs(wx-0.5*(xmin+xmax))>1.0e-5 or math.abs(wy-0.5*(ymin+ymax))>1.0e-5 then
140  io.stderr:write("plcalc_world test failed\n")
141  status = 1
142end
143
144-- Retrieve and print the name of the output file (if any).
145-- This goes to stderr not stdout since it will vary between tests and
146-- we want stdout to be identical for compare test.
147fnam = pl.gfnam()
148if fnam=="" then
149  print("No output file name is set")
150else
151  print("Output file name read")
152end
153io.stderr:write(string.format("Output file name is %s\n",fnam))
154
155-- Set and get the number of digits used to display axis labels
156-- Note digits is currently ignored in pls[xyz]ax and
157-- therefore it does not make sense to test the returned
158-- value
159pl.sxax(3,0)
160digmax, digits = pl.gxax()
161print(string.format("x axis parameters: digmax, digits = %d %d", digmax, digits))
162if digmax~=3 then
163  io.stderr:write("plgxax test failed\n")
164  status = 1
165end
166
167pl.syax(4,0)
168digmax, digits = pl.gyax()
169print(string.format("y axis parameters: digmax, digits = %d %d", digmax, digits))
170if digmax~=4 then
171  io.stderr:write("plgyax test failed\n")
172  status = 1
173end
174
175pl.szax(5,0)
176digmax,digits = pl.gzax()
177print(string.format("z axis parameters: digmax, digits = %d %d", digmax, digits))
178if digmax~=5 then
179  io.stderr:write("plgzax test failed\n")
180  status = 1
181end
182
183mar0 = 0.05
184aspect0 = pl.PL_NOTSET
185jx0 = 0.1
186jy0 = 0.2
187pl.sdidev(mar0, aspect0, jx0, jy0)
188mar, aspect, jx, jy = pl.gdidev()
189print(string.format("device-space window parameters: mar, aspect, jx, jy = %f %f %f %f" , mar, aspect, jx, jy))
190if mar~=mar0 or jx~=jx0 or jy~=jy0 then
191  io.stderr:write("plgdidev test failed\n")
192  status = 1
193end
194
195ori0 = 1.0
196pl.sdiori(ori0)
197ori = pl.gdiori()
198print(string.format("ori parameter = %f", ori))
199if ori~=ori0 then
200  io.stderr:write("plgdiori test failed\n")
201  status = 1
202end
203
204xmin0 = 0.1
205ymin0 = 0.2
206xmax0 = 0.9
207ymax0 = 0.8
208pl.sdiplt(xmin0, ymin0, xmax0, ymax0)
209xmin, ymin, xmax, ymax = pl.gdiplt()
210print(string.format("plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f", xmin, ymin, xmax, ymax))
211if xmin~=xmin0 or ymin~=ymin0 or xmax~=xmax0 or ymax~=ymax0 then
212  io.stderr:write("plgdiplt test failed\n")
213  status = 1
214end
215
216zxmin0 = 0.1
217zymin0 = 0.1
218zxmax0 = 0.9
219zymax0 = 0.9
220pl.sdiplz(zxmin0, zymin0, zxmax0, zymax0)
221zxmin, zymin, zxmax, zymax = pl.gdiplt()
222print(string.format("zoomed plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f", zxmin, zymin, zxmax, zymax))
223if math.abs(zxmin -(xmin + (xmax-xmin)*zxmin0)) > 1.0e-5 or
224   math.abs(zymin -(ymin + (ymax-ymin)*zymin0)) > 1.0e-5 or
225   math.abs(zxmax -(xmin + (xmax-xmin)*zxmax0)) > 1.0e-5 or
226   math.abs(zymax -(ymin + (ymax-ymin)*zymax0)) > 1.0e-5 then
227  io.stderr:write("plsdiplz test failed\n")
228  status = 1
229end
230
231r0 = 10
232g0 = 20
233b0 = 30
234pl.scolbg(r0, g0, b0)
235r, g, b = pl.gcolbg()
236print(string.format("background colour parameters: r, g, b = %d %d %d", r, g, b))
237if r~=r0 or g~=g0 or b~=b0 then
238  io.stderr:write("plgcolbg test failed\n")
239  status = 1
240end
241
242r0 = 20
243g0 = 30
244b0 = 40
245a0 = 0.5
246pl.scolbga(r0, g0, b0, a0)
247r, g, b, a = pl.gcolbga()
248print(string.format("background/transparency colour parameters: r, g, b, a = %d %d %d %f", r, g, b, a))
249if r~=r0 or g~=g0 or b~=b0 or a~=a0 then
250  io.stderr:write("plgcolbga test failed\n")
251  status = 1
252end
253
254pl.plend()
255