• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

plf2ops.c

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

Generated on Wed Oct 12 2011 20:42:22 for PLplot by  doxygen 1.7.1