PLplot
5.10.0
|
00001 // Predefined 2-D data access functions. 00002 // 00003 // Copyright (C) 2010 David H. E. MacMahon 00004 // 00005 // This file is part of PLplot. 00006 // 00007 // PLplot is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU Library General Public License as published 00009 // by the Free Software Foundation; either version 2 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // PLplot is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU Library General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU Library General Public License 00018 // along with PLplot; if not, write to the Free Software 00019 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 // 00021 00022 #include "plplotP.h" 00023 00024 // 00025 // 2-D data access functions for data stored in (PLFLT **), such as the C 00026 // variable z declared as... 00027 // 00028 // PLFLT z[nx][ny]; 00029 // 00030 // These functions are named plf2OP1, where OP is "get", "set", etc. The 00031 // plf2ops_t instance named "plf2ops1" is also defined below. 00032 // 00033 00034 static PLFLT 00035 plf2ops_c_get( PLPointer p, PLINT ix, PLINT iy ) 00036 { 00037 return ( (PLFLT **) p )[ix][iy]; 00038 } 00039 00040 static PLFLT 00041 plf2ops_c_f2eval( PLINT ix, PLINT iy, PLPointer p ) 00042 { 00043 return ( (PLFLT **) p )[ix][iy]; 00044 } 00045 00046 static PLFLT 00047 plf2ops_c_set( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00048 { 00049 return ( ( (PLFLT **) p )[ix][iy] = z ); 00050 } 00051 00052 static PLFLT 00053 plf2ops_c_add( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00054 { 00055 return ( ( (PLFLT **) p )[ix][iy] += z ); 00056 } 00057 00058 static PLFLT 00059 plf2ops_c_sub( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00060 { 00061 return ( ( (PLFLT **) p )[ix][iy] -= z ); 00062 } 00063 00064 static PLFLT 00065 plf2ops_c_mul( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00066 { 00067 return ( ( (PLFLT **) p )[ix][iy] *= z ); 00068 } 00069 00070 static PLFLT 00071 plf2ops_c_div( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00072 { 00073 return ( ( (PLFLT **) p )[ix][iy] /= z ); 00074 } 00075 00076 static PLINT 00077 plf2ops_c_isnan( PLPointer p, PLINT ix, PLINT iy ) 00078 { 00079 return isnan( ( (PLFLT **) p )[ix][iy] ); 00080 } 00081 00082 static void 00083 plf2ops_c_minmax( PLPointer p, PLINT nx, PLINT ny, PLFLT *zmin, PLFLT *zmax ) 00084 { 00085 int i, j; 00086 PLFLT min, max; 00087 PLFLT **z = (PLFLT **) p; 00088 00089 if ( !isfinite( z[0][0] ) ) 00090 { 00091 max = -HUGE_VAL; 00092 min = HUGE_VAL; 00093 } 00094 else 00095 min = max = z[0][0]; 00096 00097 for ( i = 0; i < nx; i++ ) 00098 { 00099 for ( j = 0; j < ny; j++ ) 00100 { 00101 if ( !isfinite( z[i][j] ) ) 00102 continue; 00103 if ( z[i][j] < min ) 00104 min = z[i][j]; 00105 if ( z[i][j] > max ) 00106 max = z[i][j]; 00107 } 00108 } 00109 *zmin = min; 00110 *zmax = max; 00111 } 00112 00113 static plf2ops_t s_plf2ops_c = { 00114 plf2ops_c_get, 00115 plf2ops_c_set, 00116 plf2ops_c_add, 00117 plf2ops_c_sub, 00118 plf2ops_c_mul, 00119 plf2ops_c_div, 00120 plf2ops_c_isnan, 00121 plf2ops_c_minmax, 00122 plf2ops_c_f2eval 00123 }; 00124 00125 PLF2OPS 00126 plf2ops_c() 00127 { 00128 return &s_plf2ops_c; 00129 } 00130 00131 // 00132 // 2-D data access functions for data stored in (PLfGrid2 *), with the 00133 // PLfGrid2's "f" field treated as type (PLFLT **). 00134 // 00135 00136 static PLFLT 00137 plf2ops_grid_c_get( PLPointer p, PLINT ix, PLINT iy ) 00138 { 00139 return ( ( (PLfGrid2 *) p )->f )[ix][iy]; 00140 } 00141 00142 static PLFLT 00143 plf2ops_grid_c_f2eval( PLINT ix, PLINT iy, PLPointer p ) 00144 { 00145 return ( ( (PLfGrid2 *) p )->f )[ix][iy]; 00146 } 00147 00148 static PLFLT 00149 plf2ops_grid_c_set( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00150 { 00151 return ( ( ( (PLfGrid2 *) p )->f )[ix][iy] = z ); 00152 } 00153 00154 static PLFLT 00155 plf2ops_grid_c_add( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00156 { 00157 return ( ( ( (PLfGrid2 *) p )->f )[ix][iy] += z ); 00158 } 00159 00160 static PLFLT 00161 plf2ops_grid_c_sub( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00162 { 00163 return ( ( ( (PLfGrid2 *) p )->f )[ix][iy] -= z ); 00164 } 00165 00166 static PLFLT 00167 plf2ops_grid_c_mul( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00168 { 00169 return ( ( ( (PLfGrid2 *) p )->f )[ix][iy] *= z ); 00170 } 00171 00172 static PLFLT 00173 plf2ops_grid_c_div( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00174 { 00175 return ( ( ( (PLfGrid2 *) p )->f )[ix][iy] /= z ); 00176 } 00177 00178 static PLINT 00179 plf2ops_grid_c_isnan( PLPointer p, PLINT ix, PLINT iy ) 00180 { 00181 return isnan( ( ( (PLfGrid2 *) p )->f )[ix][iy] ); 00182 } 00183 00184 static void 00185 plf2ops_grid_c_minmax( PLPointer p, PLINT nx, PLINT ny, PLFLT *zmin, PLFLT *zmax ) 00186 { 00187 int i, j; 00188 PLFLT min, max; 00189 PLfGrid2 *g = (PLfGrid2 *) p; 00190 PLFLT **z = g->f; 00191 00192 // Ignore passed in parameters 00193 nx = g->nx; 00194 ny = g->ny; 00195 00196 if ( !isfinite( z[0][0] ) ) 00197 { 00198 max = -HUGE_VAL; 00199 min = HUGE_VAL; 00200 } 00201 else 00202 min = max = z[0][0]; 00203 00204 for ( i = 0; i < nx; i++ ) 00205 { 00206 for ( j = 0; j < ny; j++ ) 00207 { 00208 if ( !isfinite( z[i][j] ) ) 00209 continue; 00210 if ( z[i][j] < min ) 00211 min = z[i][j]; 00212 if ( z[i][j] > max ) 00213 max = z[i][j]; 00214 } 00215 } 00216 *zmin = min; 00217 *zmax = max; 00218 } 00219 00220 static plf2ops_t s_plf2ops_grid_c = { 00221 plf2ops_grid_c_get, 00222 plf2ops_grid_c_set, 00223 plf2ops_grid_c_add, 00224 plf2ops_grid_c_sub, 00225 plf2ops_grid_c_mul, 00226 plf2ops_grid_c_div, 00227 plf2ops_grid_c_isnan, 00228 plf2ops_grid_c_minmax, 00229 plf2ops_grid_c_f2eval 00230 }; 00231 00232 PLF2OPS 00233 plf2ops_grid_c() 00234 { 00235 return &s_plf2ops_grid_c; 00236 } 00237 00238 // 00239 // 2-D data access functions for data stored in (PLfGrid2 *), with the 00240 // PLfGrid2's "f" field treated as type (PLFLT *) pointing to 2-D data stored 00241 // in row-major order. In the context of plotting, it might be easier to think 00242 // of it as "X-major" order. In this ordering, values for a single X index are 00243 // stored in consecutive memory locations. 00244 // 00245 00246 static PLFLT 00247 plf2ops_grid_row_major_get( PLPointer p, PLINT ix, PLINT iy ) 00248 { 00249 PLfGrid2 *g = (PLfGrid2 *) p; 00250 return ( (PLFLT *) g->f )[ix * g->ny + iy]; 00251 } 00252 00253 static PLFLT 00254 plf2ops_grid_row_major_f2eval( PLINT ix, PLINT iy, PLPointer p ) 00255 { 00256 PLfGrid2 *g = (PLfGrid2 *) p; 00257 return ( (PLFLT *) g->f )[ix * g->ny + iy]; 00258 } 00259 00260 static PLFLT 00261 plf2ops_grid_row_major_set( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00262 { 00263 PLfGrid2 *g = (PLfGrid2 *) p; 00264 return ( ( (PLFLT *) g->f )[ix * g->ny + iy] = z ); 00265 } 00266 00267 static PLFLT 00268 plf2ops_grid_row_major_add( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00269 { 00270 PLfGrid2 *g = (PLfGrid2 *) p; 00271 return ( ( (PLFLT *) g->f )[ix * g->ny + iy] += z ); 00272 } 00273 00274 static PLFLT 00275 plf2ops_grid_row_major_sub( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00276 { 00277 PLfGrid2 *g = (PLfGrid2 *) p; 00278 return ( ( (PLFLT *) g->f )[ix * g->ny + iy] -= z ); 00279 } 00280 00281 static PLFLT 00282 plf2ops_grid_row_major_mul( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00283 { 00284 PLfGrid2 *g = (PLfGrid2 *) p; 00285 return ( ( (PLFLT *) g->f )[ix * g->ny + iy] *= z ); 00286 } 00287 00288 static PLFLT 00289 plf2ops_grid_row_major_div( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00290 { 00291 PLfGrid2 *g = (PLfGrid2 *) p; 00292 return ( ( (PLFLT *) g->f )[ix * g->ny + iy] /= z ); 00293 } 00294 00295 static PLINT 00296 plf2ops_grid_row_major_isnan( PLPointer p, PLINT ix, PLINT iy ) 00297 { 00298 PLfGrid2 *g = (PLfGrid2 *) p; 00299 return isnan( ( (PLFLT *) g->f )[ix * g->ny + iy] ); 00300 } 00301 00302 static void 00303 plf2ops_grid_xxx_major_minmax( PLPointer p, PLINT nx, PLINT ny, PLFLT *zmin, PLFLT *zmax ) 00304 { 00305 int i; 00306 PLFLT min, max; 00307 PLfGrid2 *g = (PLfGrid2 *) p; 00308 PLFLT *z = (PLFLT *) ( (PLFLT *) g->f ); 00309 00310 // Ignore passed in parameters 00311 nx = g->nx; 00312 ny = g->ny; 00313 00314 if ( !isfinite( z[0] ) ) 00315 { 00316 max = -HUGE_VAL; 00317 min = HUGE_VAL; 00318 } 00319 else 00320 min = max = z[0]; 00321 00322 for ( i = 0; i < nx * ny; i++ ) 00323 { 00324 if ( !isfinite( z[i] ) ) 00325 continue; 00326 if ( z[i] < min ) 00327 min = z[i]; 00328 if ( z[i] > max ) 00329 max = z[i]; 00330 } 00331 *zmin = min; 00332 *zmax = max; 00333 } 00334 00335 static plf2ops_t s_plf2ops_grid_row_major = { 00336 plf2ops_grid_row_major_get, 00337 plf2ops_grid_row_major_set, 00338 plf2ops_grid_row_major_add, 00339 plf2ops_grid_row_major_sub, 00340 plf2ops_grid_row_major_mul, 00341 plf2ops_grid_row_major_div, 00342 plf2ops_grid_row_major_isnan, 00343 plf2ops_grid_xxx_major_minmax, 00344 plf2ops_grid_row_major_f2eval 00345 }; 00346 00347 PLF2OPS 00348 plf2ops_grid_row_major() 00349 { 00350 return &s_plf2ops_grid_row_major; 00351 } 00352 00353 // 00354 // 2-D data access functions for data stored in (PLfGrid2 *), with the 00355 // PLfGrid2's "f" field treated as type (PLFLT *) pointing to 2-D data stored 00356 // in column-major order. In the context of plotting, it might be easier to 00357 // think of it as "Y-major" order. In this ordering, values for a single Y 00358 // index are stored in consecutive memory locations. 00359 // 00360 00361 static PLFLT 00362 plf2ops_grid_col_major_get( PLPointer p, PLINT ix, PLINT iy ) 00363 { 00364 PLfGrid2 *g = (PLfGrid2 *) p; 00365 return ( (PLFLT *) g->f )[ix + g->nx * iy]; 00366 } 00367 00368 static PLFLT 00369 plf2ops_grid_col_major_f2eval( PLINT ix, PLINT iy, PLPointer p ) 00370 { 00371 PLfGrid2 *g = (PLfGrid2 *) p; 00372 return ( (PLFLT *) g->f )[ix + g->nx * iy]; 00373 } 00374 00375 static PLFLT 00376 plf2ops_grid_col_major_set( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00377 { 00378 PLfGrid2 *g = (PLfGrid2 *) p; 00379 return ( ( (PLFLT *) g->f )[ix + g->nx * iy] = z ); 00380 } 00381 00382 static PLFLT 00383 plf2ops_grid_col_major_add( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00384 { 00385 PLfGrid2 *g = (PLfGrid2 *) p; 00386 return ( ( (PLFLT *) g->f )[ix + g->nx * iy] += z ); 00387 } 00388 00389 static PLFLT 00390 plf2ops_grid_col_major_sub( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00391 { 00392 PLfGrid2 *g = (PLfGrid2 *) p; 00393 return ( ( (PLFLT *) g->f )[ix + g->nx * iy] -= z ); 00394 } 00395 00396 static PLFLT 00397 plf2ops_grid_col_major_mul( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00398 { 00399 PLfGrid2 *g = (PLfGrid2 *) p; 00400 return ( ( (PLFLT *) g->f )[ix + g->nx * iy] *= z ); 00401 } 00402 00403 static PLFLT 00404 plf2ops_grid_col_major_div( PLPointer p, PLINT ix, PLINT iy, PLFLT z ) 00405 { 00406 PLfGrid2 *g = (PLfGrid2 *) p; 00407 return ( ( (PLFLT *) g->f )[ix + g->nx * iy] /= z ); 00408 } 00409 00410 static PLINT 00411 plf2ops_grid_col_major_isnan( PLPointer p, PLINT ix, PLINT iy ) 00412 { 00413 PLfGrid2 *g = (PLfGrid2 *) p; 00414 return isnan( ( (PLFLT *) g->f )[ix + g->nx * iy] ); 00415 } 00416 00417 plf2ops_t s_plf2ops_grid_col_major = { 00418 plf2ops_grid_col_major_get, 00419 plf2ops_grid_col_major_set, 00420 plf2ops_grid_col_major_add, 00421 plf2ops_grid_col_major_sub, 00422 plf2ops_grid_col_major_mul, 00423 plf2ops_grid_col_major_div, 00424 plf2ops_grid_col_major_isnan, 00425 plf2ops_grid_xxx_major_minmax, 00426 plf2ops_grid_col_major_f2eval 00427 }; 00428 00429 PLF2OPS 00430 plf2ops_grid_col_major() 00431 { 00432 return &s_plf2ops_grid_col_major; 00433 }