PLplot  5.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
plf2ops.c
Go to the documentation of this file.
1 // $Id: plf2ops.c 11973 2011-10-17 21:16:39Z andrewross $
2 //
3 // Predefined 2-D data access functions.
4 //
5 // Copyright (C) 2010 David H. E. MacMahon
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 #include "plplotP.h"
25 
26 //
27 // 2-D data access functions for data stored in (PLFLT **), such as the C
28 // variable z declared as...
29 //
30 // PLFLT z[nx][ny];
31 //
32 // These functions are named plf2OP1, where OP is "get", "set", etc. The
33 // plf2ops_t instance named "plf2ops1" is also defined below.
34 //
35 
36 static PLFLT
38 {
39  return ( (PLFLT **) p )[ix][iy];
40 }
41 
42 static PLFLT
44 {
45  return ( (PLFLT **) p )[ix][iy];
46 }
47 
48 static PLFLT
50 {
51  return ( ( (PLFLT **) p )[ix][iy] = z );
52 }
53 
54 static PLFLT
56 {
57  return ( ( (PLFLT **) p )[ix][iy] += z );
58 }
59 
60 static PLFLT
62 {
63  return ( ( (PLFLT **) p )[ix][iy] -= z );
64 }
65 
66 static PLFLT
68 {
69  return ( ( (PLFLT **) p )[ix][iy] *= z );
70 }
71 
72 static PLFLT
74 {
75  return ( ( (PLFLT **) p )[ix][iy] /= z );
76 }
77 
78 static PLINT
80 {
81  return isnan( ( (PLFLT **) p )[ix][iy] );
82 }
83 
84 static void
85 plf2ops_c_minmax( PLPointer p, PLINT nx, PLINT ny, PLFLT *zmin, PLFLT *zmax )
86 {
87  int i, j;
88  PLFLT min, max;
89  PLFLT **z = (PLFLT **) p;
90 
91  if ( !isfinite( z[0][0] ) )
92  {
93  max = -HUGE_VAL;
94  min = HUGE_VAL;
95  }
96  else
97  min = max = z[0][0];
98 
99  for ( i = 0; i < nx; i++ )
100  {
101  for ( j = 0; j < ny; j++ )
102  {
103  if ( !isfinite( z[i][j] ) )
104  continue;
105  if ( z[i][j] < min )
106  min = z[i][j];
107  if ( z[i][j] > max )
108  max = z[i][j];
109  }
110  }
111  *zmin = min;
112  *zmax = max;
113 }
114 
125 };
126 
127 PLF2OPS
129 {
130  return &s_plf2ops_c;
131 }
132 
133 //
134 // 2-D data access functions for data stored in (PLfGrid2 *), with the
135 // PLfGrid2's "f" field treated as type (PLFLT **).
136 //
137 
138 static PLFLT
140 {
141  return ( ( (PLfGrid2 *) p )->f )[ix][iy];
142 }
143 
144 static PLFLT
146 {
147  return ( ( (PLfGrid2 *) p )->f )[ix][iy];
148 }
149 
150 static PLFLT
152 {
153  return ( ( ( (PLfGrid2 *) p )->f )[ix][iy] = z );
154 }
155 
156 static PLFLT
158 {
159  return ( ( ( (PLfGrid2 *) p )->f )[ix][iy] += z );
160 }
161 
162 static PLFLT
164 {
165  return ( ( ( (PLfGrid2 *) p )->f )[ix][iy] -= z );
166 }
167 
168 static PLFLT
170 {
171  return ( ( ( (PLfGrid2 *) p )->f )[ix][iy] *= z );
172 }
173 
174 static PLFLT
176 {
177  return ( ( ( (PLfGrid2 *) p )->f )[ix][iy] /= z );
178 }
179 
180 static PLINT
182 {
183  return isnan( ( ( (PLfGrid2 *) p )->f )[ix][iy] );
184 }
185 
186 static void
188 {
189  int i, j;
190  PLFLT min, max;
191  PLfGrid2 *g = (PLfGrid2 *) p;
192  PLFLT **z = g->f;
193 
194  // Ignore passed in parameters
195  nx = g->nx;
196  ny = g->ny;
197 
198  if ( !isfinite( z[0][0] ) )
199  {
200  max = -HUGE_VAL;
201  min = HUGE_VAL;
202  }
203  else
204  min = max = z[0][0];
205 
206  for ( i = 0; i < nx; i++ )
207  {
208  for ( j = 0; j < ny; j++ )
209  {
210  if ( !isfinite( z[i][j] ) )
211  continue;
212  if ( z[i][j] < min )
213  min = z[i][j];
214  if ( z[i][j] > max )
215  max = z[i][j];
216  }
217  }
218  *zmin = min;
219  *zmax = max;
220 }
221 
232 };
233 
234 PLF2OPS
236 {
237  return &s_plf2ops_grid_c;
238 }
239 
240 //
241 // 2-D data access functions for data stored in (PLfGrid2 *), with the
242 // PLfGrid2's "f" field treated as type (PLFLT *) pointing to 2-D data stored
243 // in row-major order. In the context of plotting, it might be easier to think
244 // of it as "X-major" order. In this ordering, values for a single X index are
245 // stored in consecutive memory locations.
246 //
247 
248 static PLFLT
250 {
251  PLfGrid2 *g = (PLfGrid2 *) p;
252  return ( (PLFLT *) g->f )[ix * g->ny + iy];
253 }
254 
255 static PLFLT
257 {
258  PLfGrid2 *g = (PLfGrid2 *) p;
259  return ( (PLFLT *) g->f )[ix * g->ny + iy];
260 }
261 
262 static PLFLT
264 {
265  PLfGrid2 *g = (PLfGrid2 *) p;
266  return ( ( (PLFLT *) g->f )[ix * g->ny + iy] = z );
267 }
268 
269 static PLFLT
271 {
272  PLfGrid2 *g = (PLfGrid2 *) p;
273  return ( ( (PLFLT *) g->f )[ix * g->ny + iy] += z );
274 }
275 
276 static PLFLT
278 {
279  PLfGrid2 *g = (PLfGrid2 *) p;
280  return ( ( (PLFLT *) g->f )[ix * g->ny + iy] -= z );
281 }
282 
283 static PLFLT
285 {
286  PLfGrid2 *g = (PLfGrid2 *) p;
287  return ( ( (PLFLT *) g->f )[ix * g->ny + iy] *= z );
288 }
289 
290 static PLFLT
292 {
293  PLfGrid2 *g = (PLfGrid2 *) p;
294  return ( ( (PLFLT *) g->f )[ix * g->ny + iy] /= z );
295 }
296 
297 static PLINT
299 {
300  PLfGrid2 *g = (PLfGrid2 *) p;
301  return isnan( ( (PLFLT *) g->f )[ix * g->ny + iy] );
302 }
303 
304 static void
306 {
307  int i;
308  PLFLT min, max;
309  PLfGrid2 *g = (PLfGrid2 *) p;
310  PLFLT *z = (PLFLT *) ( (PLFLT *) g->f );
311 
312  // Ignore passed in parameters
313  nx = g->nx;
314  ny = g->ny;
315 
316  if ( !isfinite( z[0] ) )
317  {
318  max = -HUGE_VAL;
319  min = HUGE_VAL;
320  }
321  else
322  min = max = z[0];
323 
324  for ( i = 0; i < nx * ny; i++ )
325  {
326  if ( !isfinite( z[i] ) )
327  continue;
328  if ( z[i] < min )
329  min = z[i];
330  if ( z[i] > max )
331  max = z[i];
332  }
333  *zmin = min;
334  *zmax = max;
335 }
336 
347 };
348 
349 PLF2OPS
351 {
352  return &s_plf2ops_grid_row_major;
353 }
354 
355 //
356 // 2-D data access functions for data stored in (PLfGrid2 *), with the
357 // PLfGrid2's "f" field treated as type (PLFLT *) pointing to 2-D data stored
358 // in column-major order. In the context of plotting, it might be easier to
359 // think of it as "Y-major" order. In this ordering, values for a single Y
360 // index are stored in consecutive memory locations.
361 //
362 
363 static PLFLT
365 {
366  PLfGrid2 *g = (PLfGrid2 *) p;
367  return ( (PLFLT *) g->f )[ix + g->nx * iy];
368 }
369 
370 static PLFLT
372 {
373  PLfGrid2 *g = (PLfGrid2 *) p;
374  return ( (PLFLT *) g->f )[ix + g->nx * iy];
375 }
376 
377 static PLFLT
379 {
380  PLfGrid2 *g = (PLfGrid2 *) p;
381  return ( ( (PLFLT *) g->f )[ix + g->nx * iy] = z );
382 }
383 
384 static PLFLT
386 {
387  PLfGrid2 *g = (PLfGrid2 *) p;
388  return ( ( (PLFLT *) g->f )[ix + g->nx * iy] += z );
389 }
390 
391 static PLFLT
393 {
394  PLfGrid2 *g = (PLfGrid2 *) p;
395  return ( ( (PLFLT *) g->f )[ix + g->nx * iy] -= z );
396 }
397 
398 static PLFLT
400 {
401  PLfGrid2 *g = (PLfGrid2 *) p;
402  return ( ( (PLFLT *) g->f )[ix + g->nx * iy] *= z );
403 }
404 
405 static PLFLT
407 {
408  PLfGrid2 *g = (PLfGrid2 *) p;
409  return ( ( (PLFLT *) g->f )[ix + g->nx * iy] /= z );
410 }
411 
412 static PLINT
414 {
415  PLfGrid2 *g = (PLfGrid2 *) p;
416  return isnan( ( (PLFLT *) g->f )[ix + g->nx * iy] );
417 }
418 
429 };
430 
431 PLF2OPS
433 {
434  return &s_plf2ops_grid_col_major;
435 }