PLplot developers,
The attached patch is an attempt at making plimagefr and plimage nan
infinite value friendly by skipping those values in plotted images.
To facilitate this the patch also modifies plMinMax2dGrid in an
attempt to avoid nan and infinite values. I think the isnan check in
the
The attached OCaml program illustrates the issue. Without this patch,
it crashes with a segfault on my system (64bit Ubuntu Intrepid). With
the patch, the neg_infinity and infinity values are not plotted and
the image colors are scaled from -1.0 to 1.0.
I don't know what sort of cross-platform compatibility issues may
exist with handling nan and infinite floating point values this way.
If there are not any then I think this would be a useful addition to
PLplot.
Hez
--
Hezekiah M. Carty
Graduate Research Assistant
University of Maryland
Department of Atmospheric and Oceanic Science
diff --git a/src/pdfutils.c b/src/pdfutils.c
index b96cde2..e95a3d1 100644
--- a/src/pdfutils.c
+++ b/src/pdfutils.c
@@ -915,13 +915,22 @@ plMinMax2dGrid(PLFLT **f, PLINT nx, PLINT ny, PLFLT *fmax, PLFLT *fmin)
{
int i, j;
PLFLT m, M;
+ PLFLT tmp;
- M = m = f[0][0];
+ tmp = f[0][0];
+ if (isnan(tmp) || isinf(tmp)) {
+ M = -HUGE_VAL;
+ m = HUGE_VAL;
+ }
+ else
+ M = m = f[0][0];
for (i = 0; i < nx; i++) {
for (j = 0; j < ny; j++) {
- if (f[i][j] > M) M = f[i][j];
- if (f[i][j] < m) m = f[i][j];
+ tmp = f[i][j];
+ if (isnan(tmp) || isinf(tmp)) continue;
+ if (tmp > M) M = tmp;
+ if (tmp < m) m = tmp;
}
}
*fmax = M;
diff --git a/src/plimage.c b/src/plimage.c
index 4060793..5901825 100644
--- a/src/plimage.c
+++ b/src/plimage.c
@@ -234,7 +234,7 @@ c_plimagefr(PLFLT **idata, PLINT nx, PLINT ny,
}
else {
datum = idata[ix][iy];
- if (datum < zmin || datum > zmax) {
+ if (isnan(datum) || isinf(datum) || datum < zmin || datum > zmax) {
/* Set to a guaranteed-not-to-plot value */
z[ix * ny + iy] = COLOR_NO_PLOT;
}
open Plplot
let () =
let image = [|[|neg_infinity; -1.0; 0.0; 1.0; infinity|]|] in
plsdev "xwin";
plinit ();
plenv 0. 1. 0. 1. 1 0;
plimage image 0. 1. 0. 1. 0.0 0.0 0. 1. 0. 1.;
plend ();
()
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel