1 // set/get tester
2 //
3 // Copyright (C) 2008 Andrew Ross
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 //
22
23 #include "plc++demos.h"
24
25 #ifdef PL_USE_NAMESPACE
26 using namespace std;
27 #endif
28
29 class x31 {
30 public:
31 x31( int, char ** );
32 int status;
33
34 private:
35 plstream *pls;
36 };
37
38 //--------------------------------------------------------------------------
39 // main
40 //
41 // Demonstrates absolute positioning of graphs on a page.
42 //--------------------------------------------------------------------------
43
x31(int argc,char * argv[])44 x31::x31( int argc, char *argv[] )
45 {
46 PLFLT xmin0, xmax0, ymin0, ymax0, zxmin0, zxmax0, zymin0, zymax0;
47 PLFLT xmin, xmax, ymin, ymax, zxmin, zxmax, zymin, zymax;
48 PLFLT xmid, ymid, wx, wy;
49 PLFLT mar0, aspect0, jx0, jy0, ori0;
50 PLFLT mar, aspect, jx, jy, ori;
51 PLINT win, level2, digmax, digits, compression1, compression2;
52 PLFLT xp0, yp0;
53 PLINT xleng0, yleng0, xoff0, yoff0;
54 PLFLT xp1, yp1;
55 PLINT xleng1, yleng1, xoff1, yoff1;
56 PLFLT xp2, yp2;
57 PLINT xleng2, yleng2, xoff2, yoff2;
58 PLINT fam0, num0, bmax0;
59 PLINT fam1, num1, bmax1;
60 PLINT fam2, num2, bmax2;
61 PLINT r0, g0, b0;
62 PLFLT a0;
63 PLINT r, g, b;
64 PLFLT a;
65 PLINT r1[] = { 0, 255 };
66 PLINT g1[] = { 255, 0 };
67 PLINT b1[] = { 0, 0 };
68 PLFLT a1[] = { 1.0, 1.0 };
69 char fnam[256];
70
71 pls = new plstream();
72
73 status = 0;
74
75 // Set floating point precision for cout consistent with C printf.
76 cout.setf( ios::fixed, ios::floatfield );
77 cout.setf( ios::showpoint );
78 cout.precision( 6 );
79
80 pls->parseopts( &argc, argv, PL_PARSE_FULL );
81
82 // Test setting / getting familying parameters before plinit.
83 // Save values set by plparseopts to be restored later.
84 pls->gfam( fam0, num0, bmax0 );
85 fam1 = 0;
86 num1 = 10;
87 bmax1 = 1000;
88 pls->sfam( fam1, num1, bmax1 );
89
90 // Retrieve the same values?
91 pls->gfam( fam2, num2, bmax2 );
92 cout << "family parameters: fam, num, bmax = " << fam2 << " " <<
93 num2 << " " << bmax2 << endl;
94 if ( fam2 != fam1 || num2 != num1 || bmax2 != bmax1 )
95 {
96 cerr << "plgfam test failed" << endl;
97 status = 1;
98 }
99 // Restore values set initially by plparseopts.
100 pls->sfam( fam0, num0, bmax0 );
101
102 // Test setting / getting page parameters before plinit.
103 // Save values set by plparseopts to be restored later.
104 pls->gpage( xp0, yp0, xleng0, yleng0, xoff0, yoff0 );
105 xp1 = 200.;
106 yp1 = 200.;
107 xleng1 = 400;
108 yleng1 = 200;
109 xoff1 = 10;
110 yoff1 = 20;
111 pls->spage( xp1, yp1, xleng1, yleng1, xoff1, yoff1 );
112
113 // Retrieve the same values?
114 pls->gpage( xp2, yp2, xleng2, yleng2, xoff2, yoff2 );
115 cout << "page parameters: xp, yp, xleng, yleng, xoff, yoff = " << xp2 <<
116 " " << yp2 << " " << xleng2 << " " << yleng2 << " " << xoff2 << " " <<
117 yoff2 << endl;
118 if ( xp2 != xp1 || yp2 != yp1 || xleng2 != xleng1 || yleng2 != yleng1 ||
119 xoff2 != xoff1 || yoff2 != yoff1 )
120 {
121 cerr << "plgpage test failed" << endl;
122 status = 1;
123 }
124 // Restore values set initially by plparseopts.
125 pls->spage( xp0, yp0, xleng0, yleng0, xoff0, yoff0 );
126
127 // Test setting / getting compression parameter across plinit.
128 compression1 = 95;
129 pls->scompression( compression1 );
130
131 // Initialize plplot
132 pls->init();
133
134 // Test if device initialization screwed around with the preset
135 // compression parameter.
136 pls->gcompression( compression2 );
137 cout << "Output various PLplot parameters" << endl;
138 cout << "compression parameter = " << compression2 << endl;
139 if ( compression2 != compression1 )
140 {
141 cerr << "plgcompression test failed" << endl;
142 status = 1;
143 }
144
145 // Exercise plscolor, plscol0, plscmap1, and plscmap1a to make sure
146 // they work without any obvious error messages.
147 pls->scolor( 1 );
148 pls->scol0( 1, 255, 0, 0 );
149 pls->scmap1( r1, g1, b1, 2 );
150 pls->scmap1a( r1, g1, b1, a1, 2 );
151
152 pls->glevel( level2 );
153 cout << "level parameter = " << level2 << endl;
154 if ( level2 != 1 )
155 {
156 cerr << "plglevel test failed." << endl;
157 status = 1;
158 }
159
160 pls->adv( 0 );
161
162 xmin0 = 0.01;
163 xmax0 = 0.99;
164 ymin0 = 0.02;
165 ymax0 = 0.49;
166 pls->vpor( xmin0, xmax0, ymin0, ymax0 );
167 pls->gvpd( xmin, xmax, ymin, ymax );
168 cout << "plvpor: xmin, xmax, ymin, ymax = " << xmin << " " << xmax << " " << ymin << " " << ymax << endl;
169 if ( xmin != xmin0 || xmax != xmax0 || ymin != ymin0 || ymax != ymax0 )
170 {
171 cerr << "plgvpd test failed" << endl;
172 status = 1;
173 }
174 xmid = 0.5 * ( xmin + xmax );
175 ymid = 0.5 * ( ymin + ymax );
176
177 xmin0 = 0.2;
178 xmax0 = 0.3;
179 ymin0 = 0.4;
180 ymax0 = 0.5;
181 pls->wind( xmin0, xmax0, ymin0, ymax0 );
182 pls->gvpw( xmin, xmax, ymin, ymax );
183 cout << "plwind: xmin, xmax, ymin, ymax = " << xmin << " " << xmax << " " << ymin << " " << ymax << endl;
184 if ( xmin != xmin0 || xmax != xmax0 || ymin != ymin0 || ymax != ymax0 )
185 {
186 cerr << "plgvpw test failed" << endl;
187 status = 1;
188 }
189
190 // Get world coordinates for middle of viewport
191 pls->calc_world( xmid, ymid, wx, wy, win );
192 cout << "world parameters: wx, wy, win = " << wx << " " << wy << " " << win << endl;
193 if ( fabs( wx - 0.5 * ( xmin + xmax ) ) > 1.0E-5 || fabs( wy - 0.5 * ( ymin + ymax ) ) > 1.0E-5 )
194 {
195 cerr << "plcalc_world test failed" << endl;
196 status = 1;
197 }
198
199 // Retrieve and print the name of the output file (if any).
200 // This goes to stderr not stdout since it will vary between tests and
201 // we want stdout to be identical for compare test.
202 pls->gfnam( fnam );
203 if ( fnam[0] == '\0' )
204 {
205 cout << "No output file name is set" << endl;
206 }
207 else
208 {
209 cout << "Output file name read" << endl;
210 }
211 cerr << "Output file name is " << fnam << endl;
212
213 // Set and get the number of digits used to display axis labels
214 // Note digits is currently ignored in pls[xyz]ax and
215 // therefore it does not make sense to test the returned
216 // value
217 pls->sxax( 3, 0 );
218 pls->gxax( digmax, digits );
219 cout << "x axis parameters: digmax, digits = " << digmax << " " << digits << endl;
220 if ( digmax != 3 )
221 {
222 cerr << "plgxax test failed" << endl;
223 status = 1;
224 }
225
226 pls->syax( 4, 0 );
227 pls->gyax( digmax, digits );
228 cout << "y axis parameters: digmax, digits = " << digmax << " " << digits << endl;
229 if ( digmax != 4 )
230 {
231 cerr << "plgyax test failed" << endl;
232 status = 1;
233 }
234
235 pls->szax( 5, 0 );
236 pls->gzax( digmax, digits );
237 cout << "z axis parameters: digmax, digits = " << digmax << " " << digits << endl;
238 if ( digmax != 5 )
239 {
240 cerr << "plgzax test failed" << endl;
241 status = 1;
242 }
243
244 mar0 = 0.05;
245 aspect0 = PL_NOTSET;
246 jx0 = 0.1;
247 jy0 = 0.2;
248 pls->sdidev( mar0, aspect0, jx0, jy0 );
249 pls->gdidev( mar, aspect, jx, jy );
250 cout << "device-space window parameters: mar, aspect, jx, jy = " << mar << " " << aspect << " " << jx << " " << jy << endl;
251 if ( mar != mar0 || jx != jx0 || jy != jy0 )
252 {
253 cerr << "plgdidev test failed" << endl;
254 status = 1;
255 }
256
257 ori0 = 1.0;
258 pls->sdiori( ori0 );
259 pls->gdiori( ori );
260 cout << "ori parameter = " << ori << endl;
261 if ( ori != ori0 )
262 {
263 cerr << "plgdiori test failed" << endl;
264 status = 1;
265 }
266
267 xmin0 = 0.1;
268 ymin0 = 0.2;
269 xmax0 = 0.9;
270 ymax0 = 0.8;
271 pls->sdiplt( xmin0, ymin0, xmax0, ymax0 );
272 pls->gdiplt( xmin, ymin, xmax, ymax );
273 cout << "plot-space window parameters: xmin, ymin, xmax, ymax = " << xmin << " " << ymin << " " << xmax << " " << ymax << endl;
274 if ( xmin != xmin0 || ymin != ymin0 || xmax != xmax0 || ymax != ymax0 )
275 {
276 cerr << "plgdiplt test failed" << endl;
277 status = 1;
278 }
279
280 zxmin0 = 0.1;
281 zymin0 = 0.1;
282 zxmax0 = 0.9;
283 zymax0 = 0.9;
284 pls->sdiplz( zxmin0, zymin0, zxmax0, zymax0 );
285 pls->gdiplt( zxmin, zymin, zxmax, zymax );
286 cout << "zoomed plot-space window parameters: xmin, ymin, xmax, ymax = " << zxmin << " " << zymin << " " << zxmax << " " << zymax << endl;
287 if ( fabs( zxmin - ( xmin + ( xmax - xmin ) * zxmin0 ) ) > 1.0E-5 ||
288 fabs( zymin - ( ymin + ( ymax - ymin ) * zymin0 ) ) > 1.0E-5 ||
289 fabs( zxmax - ( xmin + ( xmax - xmin ) * zxmax0 ) ) > 1.0E-5 ||
290 fabs( zymax - ( ymin + ( ymax - ymin ) * zymax0 ) ) > 1.0E-5 )
291 {
292 cerr << "plsdiplz test failed" << endl;
293 status = 1;
294 }
295
296 r0 = 10;
297 g0 = 20;
298 b0 = 30;
299 pls->scolbg( r0, g0, b0 );
300 pls->gcolbg( r, g, b );
301 cout << "background colour parameters: r, g, b = " << r << " " << g << " " << b << endl;
302 if ( r != r0 || g != g0 || b != b0 )
303 {
304 cerr << "plgcolbg test failed" << endl;
305 status = 1;
306 }
307
308 r0 = 20;
309 g0 = 30;
310 b0 = 40;
311 a0 = 0.5;
312 pls->scolbga( r0, g0, b0, a0 );
313 pls->gcolbga( r, g, b, a );
314 cout << "background/transparency colour parameters: r, g, b, a = " << r << " " << g << " " << b << " " << a << endl;
315 if ( r != r0 || g != g0 || b != b0 || a != a0 )
316 {
317 cerr << "plgcolbga test failed" << endl;
318 status = 1;
319 }
320
321 delete pls;
322 }
323
main(int argc,char ** argv)324 int main( int argc, char **argv )
325 {
326 int status;
327
328 x31 *x = new x31( argc, argv );
329 status = x->status;
330
331 delete x;
332 return status;
333 }
334