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