From: <and...@us...> - 2009-02-23 15:54:48
|
Revision: 9586 http://plplot.svn.sourceforge.net/plplot/?rev=9586&view=rev Author: andrewross Date: 2009-02-23 15:54:44 +0000 (Mon, 23 Feb 2009) Log Message: ----------- Initial start on making plplot NaN / Inf aware. There will be more to follow on this. Ensure isnan / isinf macros are defined in plplot.h if they are not defined on the system. Also ensure INFINITY is defined. Remove duplicate definitions of isnan from C/C++ example 21 (now in plplot.h) and from plgridd.c. Update plMinMax2dGrid to ignore NaN and +/-Inf values when finding max / min values. Update plimage/plimagefr to ignore Nan and +/- Inf when plotting images. Thanks to Hez Carty for parts of this patch. Modified Paths: -------------- trunk/examples/c/x21c.c trunk/examples/c++/x21.cc trunk/include/plplot.h trunk/src/pdfutils.c trunk/src/plgridd.c trunk/src/plimage.c Modified: trunk/examples/c/x21c.c =================================================================== --- trunk/examples/c/x21c.c 2009-02-23 14:39:52 UTC (rev 9585) +++ trunk/examples/c/x21c.c 2009-02-23 15:54:44 UTC (rev 9586) @@ -23,15 +23,6 @@ #include "plcdemos.h" -#if !defined(HAVE_ISNAN) -# define isnan(x) ((x) != (x)) -#endif - -#if defined(WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__)) -#undef isnan -#define isnan _isnan -#endif - /* Options data structure definition. */ static PLINT pts = 500; Modified: trunk/examples/c++/x21.cc =================================================================== --- trunk/examples/c++/x21.cc 2009-02-23 14:39:52 UTC (rev 9585) +++ trunk/examples/c++/x21.cc 2009-02-23 15:54:44 UTC (rev 9586) @@ -28,15 +28,6 @@ #include "plc++demos.h" -#if !defined(HAVE_ISNAN) - #define isnan(x) ((x) != (x)) -#endif - -#if defined(WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__)) -#undef isnan -#define isnan _isnan -#endif - // Need for some Mac OSX systems with broken <cmath> header #ifdef BROKEN_ISNAN_CXX extern "C" int isnan (double); Modified: trunk/include/plplot.h =================================================================== --- trunk/include/plplot.h 2009-02-23 14:39:52 UTC (rev 9585) +++ trunk/include/plplot.h 2009-02-23 15:54:44 UTC (rev 9586) @@ -184,6 +184,29 @@ typedef void* PLPointer; /*--------------------------------------------------------------------------*\ + * Add in missing isnan / isinf functions on some platforms +\*--------------------------------------------------------------------------*/ + +#if defined(WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__)) +# define isnan _isnan +# define isinf _isinf +#else +# if !defined(HAVE_ISNAN) +# define isnan(x) ((x) != (x)) +# endif +# if !defined(HAVE_ISINF) +# define isinf(x) (!isnan(x) && isnan(x-x)) +# endif +#endif + +/* Check if C99 INFINITY macro is available - if not then + * define a replacement */ +#ifndef INFINITY +#define INFINITY (1.0/0.0) +#endif + + +/*--------------------------------------------------------------------------*\ * Complex data types and other good stuff \*--------------------------------------------------------------------------*/ Modified: trunk/src/pdfutils.c =================================================================== --- trunk/src/pdfutils.c 2009-02-23 14:39:52 UTC (rev 9585) +++ trunk/src/pdfutils.c 2009-02-23 15:54:44 UTC (rev 9586) @@ -908,6 +908,7 @@ * MinMax2dGrid() * * Finds the maximum and minimum of a 2d matrix allocated with plAllc2dGrid(). + * NaN and +/- infinity values are ignored. \*--------------------------------------------------------------------------*/ void @@ -916,10 +917,16 @@ int i, j; PLFLT m, M; - M = m = f[0][0]; + if (isnan(f[0][0]) || isinf(f[0][0])) { + M = -INFINITY; + m = INFINITY; + } + else + M = m = f[0][0]; for (i = 0; i < nx; i++) { for (j = 0; j < ny; j++) { + if (isnan(f[i][j]) || isinf(f[i][j])) continue; if (f[i][j] > M) M = f[i][j]; if (f[i][j] < m) m = f[i][j]; } Modified: trunk/src/plgridd.c =================================================================== --- trunk/src/plgridd.c 2009-02-23 14:39:52 UTC (rev 9585) +++ trunk/src/plgridd.c 2009-02-23 15:54:44 UTC (rev 9586) @@ -35,10 +35,6 @@ #include <qhull/qhull_a.h> #endif -#if !defined(HAVE_ISNAN) -#define isnan(x) ((x) != (x)) -#endif - /* forward declarations */ static void grid_nnaidw (PLFLT *x, PLFLT *y, PLFLT *z, int npts, Modified: trunk/src/plimage.c =================================================================== --- trunk/src/plimage.c 2009-02-23 14:39:52 UTC (rev 9585) +++ trunk/src/plimage.c 2009-02-23 15:54:44 UTC (rev 9586) @@ -234,7 +234,7 @@ } else { datum = idata[ix][iy]; - if (datum < zmin || datum > zmax) { + if (isnan(datum) || datum < zmin || datum > zmax) { /* Set to a guaranteed-not-to-plot value */ z[ix * ny + iy] = COLOR_NO_PLOT; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |