PLplot
5.10.0
Main Page
Namespaces
Classes
Files
File List
File Members
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
37
plf2ops_c_get
(
PLPointer
p,
PLINT
ix,
PLINT
iy )
38
{
39
return
( (
PLFLT
**) p )[ix][iy];
40
}
41
42
static
PLFLT
43
plf2ops_c_f2eval
(
PLINT
ix,
PLINT
iy,
PLPointer
p )
44
{
45
return
( (
PLFLT
**) p )[ix][iy];
46
}
47
48
static
PLFLT
49
plf2ops_c_set
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
50
{
51
return
( ( (
PLFLT
**) p )[ix][iy] = z );
52
}
53
54
static
PLFLT
55
plf2ops_c_add
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
56
{
57
return
( ( (
PLFLT
**) p )[ix][iy] += z );
58
}
59
60
static
PLFLT
61
plf2ops_c_sub
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
62
{
63
return
( ( (
PLFLT
**) p )[ix][iy] -= z );
64
}
65
66
static
PLFLT
67
plf2ops_c_mul
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
68
{
69
return
( ( (
PLFLT
**) p )[ix][iy] *= z );
70
}
71
72
static
PLFLT
73
plf2ops_c_div
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
74
{
75
return
( ( (
PLFLT
**) p )[ix][iy] /= z );
76
}
77
78
static
PLINT
79
plf2ops_c_isnan
(
PLPointer
p,
PLINT
ix,
PLINT
iy )
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
115
static
plf2ops_t
s_plf2ops_c
= {
116
plf2ops_c_get
,
117
plf2ops_c_set
,
118
plf2ops_c_add
,
119
plf2ops_c_sub
,
120
plf2ops_c_mul
,
121
plf2ops_c_div
,
122
plf2ops_c_isnan
,
123
plf2ops_c_minmax
,
124
plf2ops_c_f2eval
125
};
126
127
PLF2OPS
128
plf2ops_c
()
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
139
plf2ops_grid_c_get
(
PLPointer
p,
PLINT
ix,
PLINT
iy )
140
{
141
return
( ( (
PLfGrid2
*) p )->f )[ix][iy];
142
}
143
144
static
PLFLT
145
plf2ops_grid_c_f2eval
(
PLINT
ix,
PLINT
iy,
PLPointer
p )
146
{
147
return
( ( (
PLfGrid2
*) p )->f )[ix][iy];
148
}
149
150
static
PLFLT
151
plf2ops_grid_c_set
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
152
{
153
return
( ( ( (
PLfGrid2
*) p )->f )[ix][iy] = z );
154
}
155
156
static
PLFLT
157
plf2ops_grid_c_add
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
158
{
159
return
( ( ( (
PLfGrid2
*) p )->f )[ix][iy] += z );
160
}
161
162
static
PLFLT
163
plf2ops_grid_c_sub
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
164
{
165
return
( ( ( (
PLfGrid2
*) p )->f )[ix][iy] -= z );
166
}
167
168
static
PLFLT
169
plf2ops_grid_c_mul
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
170
{
171
return
( ( ( (
PLfGrid2
*) p )->f )[ix][iy] *= z );
172
}
173
174
static
PLFLT
175
plf2ops_grid_c_div
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
176
{
177
return
( ( ( (
PLfGrid2
*) p )->f )[ix][iy] /= z );
178
}
179
180
static
PLINT
181
plf2ops_grid_c_isnan
(
PLPointer
p,
PLINT
ix,
PLINT
iy )
182
{
183
return
isnan
( ( ( (
PLfGrid2
*) p )->f )[ix][iy] );
184
}
185
186
static
void
187
plf2ops_grid_c_minmax
(
PLPointer
p,
PLINT
nx
,
PLINT
ny,
PLFLT
*zmin,
PLFLT
*zmax )
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
222
static
plf2ops_t
s_plf2ops_grid_c
= {
223
plf2ops_grid_c_get
,
224
plf2ops_grid_c_set
,
225
plf2ops_grid_c_add
,
226
plf2ops_grid_c_sub
,
227
plf2ops_grid_c_mul
,
228
plf2ops_grid_c_div
,
229
plf2ops_grid_c_isnan
,
230
plf2ops_grid_c_minmax
,
231
plf2ops_grid_c_f2eval
232
};
233
234
PLF2OPS
235
plf2ops_grid_c
()
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
249
plf2ops_grid_row_major_get
(
PLPointer
p,
PLINT
ix,
PLINT
iy )
250
{
251
PLfGrid2
*g = (
PLfGrid2
*) p;
252
return
( (
PLFLT
*) g->
f
)[ix * g->
ny
+ iy];
253
}
254
255
static
PLFLT
256
plf2ops_grid_row_major_f2eval
(
PLINT
ix,
PLINT
iy,
PLPointer
p )
257
{
258
PLfGrid2
*g = (
PLfGrid2
*) p;
259
return
( (
PLFLT
*) g->
f
)[ix * g->
ny
+ iy];
260
}
261
262
static
PLFLT
263
plf2ops_grid_row_major_set
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
264
{
265
PLfGrid2
*g = (
PLfGrid2
*) p;
266
return
( ( (
PLFLT
*) g->
f
)[ix * g->
ny
+ iy] = z );
267
}
268
269
static
PLFLT
270
plf2ops_grid_row_major_add
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
271
{
272
PLfGrid2
*g = (
PLfGrid2
*) p;
273
return
( ( (
PLFLT
*) g->
f
)[ix * g->
ny
+ iy] += z );
274
}
275
276
static
PLFLT
277
plf2ops_grid_row_major_sub
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
278
{
279
PLfGrid2
*g = (
PLfGrid2
*) p;
280
return
( ( (
PLFLT
*) g->
f
)[ix * g->
ny
+ iy] -= z );
281
}
282
283
static
PLFLT
284
plf2ops_grid_row_major_mul
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
285
{
286
PLfGrid2
*g = (
PLfGrid2
*) p;
287
return
( ( (
PLFLT
*) g->
f
)[ix * g->
ny
+ iy] *= z );
288
}
289
290
static
PLFLT
291
plf2ops_grid_row_major_div
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
292
{
293
PLfGrid2
*g = (
PLfGrid2
*) p;
294
return
( ( (
PLFLT
*) g->
f
)[ix * g->
ny
+ iy] /= z );
295
}
296
297
static
PLINT
298
plf2ops_grid_row_major_isnan
(
PLPointer
p,
PLINT
ix,
PLINT
iy )
299
{
300
PLfGrid2
*g = (
PLfGrid2
*) p;
301
return
isnan
( ( (
PLFLT
*) g->
f
)[ix * g->
ny
+ iy] );
302
}
303
304
static
void
305
plf2ops_grid_xxx_major_minmax
(
PLPointer
p,
PLINT
nx
,
PLINT
ny,
PLFLT
*zmin,
PLFLT
*zmax )
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
337
static
plf2ops_t
s_plf2ops_grid_row_major
= {
338
plf2ops_grid_row_major_get
,
339
plf2ops_grid_row_major_set
,
340
plf2ops_grid_row_major_add
,
341
plf2ops_grid_row_major_sub
,
342
plf2ops_grid_row_major_mul
,
343
plf2ops_grid_row_major_div
,
344
plf2ops_grid_row_major_isnan
,
345
plf2ops_grid_xxx_major_minmax
,
346
plf2ops_grid_row_major_f2eval
347
};
348
349
PLF2OPS
350
plf2ops_grid_row_major
()
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
364
plf2ops_grid_col_major_get
(
PLPointer
p,
PLINT
ix,
PLINT
iy )
365
{
366
PLfGrid2
*g = (
PLfGrid2
*) p;
367
return
( (
PLFLT
*) g->
f
)[ix + g->
nx
* iy];
368
}
369
370
static
PLFLT
371
plf2ops_grid_col_major_f2eval
(
PLINT
ix,
PLINT
iy,
PLPointer
p )
372
{
373
PLfGrid2
*g = (
PLfGrid2
*) p;
374
return
( (
PLFLT
*) g->
f
)[ix + g->
nx
* iy];
375
}
376
377
static
PLFLT
378
plf2ops_grid_col_major_set
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
379
{
380
PLfGrid2
*g = (
PLfGrid2
*) p;
381
return
( ( (
PLFLT
*) g->
f
)[ix + g->
nx
* iy] = z );
382
}
383
384
static
PLFLT
385
plf2ops_grid_col_major_add
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
386
{
387
PLfGrid2
*g = (
PLfGrid2
*) p;
388
return
( ( (
PLFLT
*) g->
f
)[ix + g->
nx
* iy] += z );
389
}
390
391
static
PLFLT
392
plf2ops_grid_col_major_sub
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
393
{
394
PLfGrid2
*g = (
PLfGrid2
*) p;
395
return
( ( (
PLFLT
*) g->
f
)[ix + g->
nx
* iy] -= z );
396
}
397
398
static
PLFLT
399
plf2ops_grid_col_major_mul
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
400
{
401
PLfGrid2
*g = (
PLfGrid2
*) p;
402
return
( ( (
PLFLT
*) g->
f
)[ix + g->
nx
* iy] *= z );
403
}
404
405
static
PLFLT
406
plf2ops_grid_col_major_div
(
PLPointer
p,
PLINT
ix,
PLINT
iy,
PLFLT
z )
407
{
408
PLfGrid2
*g = (
PLfGrid2
*) p;
409
return
( ( (
PLFLT
*) g->
f
)[ix + g->
nx
* iy] /= z );
410
}
411
412
static
PLINT
413
plf2ops_grid_col_major_isnan
(
PLPointer
p,
PLINT
ix,
PLINT
iy )
414
{
415
PLfGrid2
*g = (
PLfGrid2
*) p;
416
return
isnan
( ( (
PLFLT
*) g->
f
)[ix + g->
nx
* iy] );
417
}
418
419
plf2ops_t
s_plf2ops_grid_col_major
= {
420
plf2ops_grid_col_major_get
,
421
plf2ops_grid_col_major_set
,
422
plf2ops_grid_col_major_add
,
423
plf2ops_grid_col_major_sub
,
424
plf2ops_grid_col_major_mul
,
425
plf2ops_grid_col_major_div
,
426
plf2ops_grid_col_major_isnan
,
427
plf2ops_grid_xxx_major_minmax
,
428
plf2ops_grid_col_major_f2eval
429
};
430
431
PLF2OPS
432
plf2ops_grid_col_major
()
433
{
434
return
&
s_plf2ops_grid_col_major
;
435
}
plplot
src
plf2ops.c
Generated on Wed Feb 12 2014 15:33:50 for PLplot by
1.8.1.2