Root/nanonote-files/example-files/data/Examples/lua-plplot-examples/x31.lua

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.
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("compression parameter = " .. 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("level parameter = " .. level2)
103if level2~=1 then
104  io.stderr:write("plglevel test failed.\n")
105  status = 1
106end
107
108pl.adv(0)
109pl.vpor(0.01, 0.99, 0.02, 0.49)
110xmin, xmax, ymin, ymax = pl.gvpd()
111print(string.format("plvpor: xmin, xmax, ymin, ymax = %f %f %f %f", xmin, xmax, ymin, ymax))
112if 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
115end
116xmid = 0.5*(xmin+xmax)
117ymid = 0.5*(ymin+ymax)
118
119pl.wind(0.2, 0.3, 0.4, 0.5)
120xmin, xmax, ymin, ymax = pl.gvpw()
121print(string.format("plwind: xmin, xmax, ymin, ymax = %f %f %f %f", xmin, xmax, ymin, ymax))
122if 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
125end
126
127-- Get world coordinates for middle of viewport
128wx, wy, win = pl.calc_world(xmid,ymid)
129print(string.format("world parameters: wx, wy, win = %f %f %d", wx, wy, win))
130if 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
133end
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.
138fnam = pl.gfnam()
139if fnam=="" then
140  print("No output file name is set")
141else
142  print("Output file name read")
143end
144io.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
150pl.sxax(3,0)
151digmax, digits = pl.gxax()
152print(string.format("x axis parameters: digmax, digits = %d %d", digmax, digits))
153if digmax~=3 then
154  io.stderr:write("plgxax test failed\n")
155  status = 1
156end
157
158pl.syax(4,0)
159digmax, digits = pl.gyax()
160print(string.format("y axis parameters: digmax, digits = %d %d", digmax, digits))
161if digmax~=4 then
162  io.stderr:write("plgyax test failed\n")
163  status = 1
164end
165
166pl.szax(5,0)
167digmax,digits = pl.gzax()
168print(string.format("z axis parameters: digmax, digits = %d %d", digmax, digits))
169if digmax~=5 then
170  io.stderr:write("plgzax test failed\n")
171  status = 1
172end
173
174pl.sdidev(0.05, pl.PL_NOTSET, 0.1, 0.2)
175mar, aspect, jx, jy = pl.gdidev()
176print(string.format("device-space window parameters: mar, aspect, jx, jy = %f %f %f %f" , mar, aspect, jx, jy))
177if mar~=0.05 or jx~=0.1 or jy~=0.2 then
178  io.stderr:write("plgdidev test failed\n")
179  status = 1
180end
181
182pl.sdiori(1.0)
183ori = pl.gdiori()
184print(string.format("ori parameter = %f", ori))
185if ori~=1.0 then
186  io.stderr:write("plgdiori test failed\n")
187  status = 1
188end
189
190pl.sdiplt(0.1, 0.2, 0.9, 0.8)
191xmin, ymin, xmax, ymax = pl.gdiplt()
192print(string.format("plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f", xmin, ymin, xmax, ymax))
193if 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
196end
197
198pl.sdiplz(0.1, 0.1, 0.9, 0.9)
199zxmin, zymin, zxmax, zymax = pl.gdiplt()
200print(string.format("zoomed plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f", zxmin, zymin, zxmax, zymax))
201if 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
207end
208
209pl.scolbg(10, 20, 30)
210r, g, b = pl.gcolbg()
211print(string.format("background colour parameters: r, g, b = %d %d %d", r, g, b))
212if r~=10 or g~=20 or b~=30 then
213  io.stderr:write("plgcolbg test failed\n")
214  status = 1
215end
216
217pl.scolbga(20, 30, 40, 0.5)
218r, g, b, a = pl.gcolbga()
219print(string.format("background/transparency colour parameters: r, g, b, a = %d %d %d %f", r, g, b, a))
220if r~=20 or g~=30 or b~=40 or a~=0.5 then
221  io.stderr:write("plgcolbga test failed\n")
222  status = 1
223end
224
225pl.plend()
226

Archive Download this file



interactive