|
From: Ethan M. <merritt@u.washington.edu> - 2006-08-23 22:57:55
|
While investigating a bug report on comp.graphics.apps.gnuplot
I discovered what appears to be a long-standing coding bug in
the data input loop of plot3d.c. In outline, the main loop
looks like this:
while ((j = df_readline(v,MAXDATACOLS)) != DF_EOF) {
cp = local_this_iso->points + xdatum;
... lots of conditional stuff ...
come_here_if_undefined:
++xdatum;
} /* end of whileloop - end of surface */
The tricky bit is the increment of xdatum at the end, which
is the only thing that advances the cp (current point) pointer.
Most of the conditional tests either reach the end of the while
clause naturally, or terminate prematurely via an explicit jump:
goto come_here_if_undefined;
However, two cases terminate via a "continue" statement instead,
which means that the current point is not incremented.
In particular there is this test:
if (j == DF_UNDEFINED || j == DF_MISSING) {
cp->type = UNDEFINED;
continue;
}
Setting cp->type to UNDEFINED is useless, because cp itself is not
incremented. So during the next iteration of the while clause it is
over-written with the next data point. This messes up the gridding
structure, and leads to the problem reported on the newsgroup.
It seems clear to me that at least for gridded surfaces the
"continue" statement should be replaced by a jump to
come_here_if_undefined. That does, in fact, fix the specific
problem reported on the newsgroup.
However, I am dubious about the affect this has on PM3D output.
I tried replacing one of the data points in triangle.dat with a
nonsense string, or with NaN, and issuing the commands
splot 'triangle.dat' using 1:2:3 with pm3d
splot 'triangle.dat' using ($1):($2):($3) with pm3d
The results are odd, to say the least.
Version 4.0:
Very, very odd behavior (try rotating it!).
The current cvs version:
1st command distorts the grid, which I would predict,
2nd command distorts and also produces a strange coloring.
Current cvs patched to increment xdatum before continuing:
1st command distorts the grid (but why?)
2nd command has no grid distortion, but loses the entire rest of
the grid line after the invalid point
No version of gnuplot that I have here acts as I would expect.
What is supposed to happen if pm3d sees an invalid point?
Leave a hole in the surface?
Interpolate the color from the surrounding blocks?
Error exit?
Something else? (see note)
Note:
I originally understood the documentation under
"help splot datafile" to mean that in case the 3rd value on the
input line was unusable, the previous z value was used
("last value"). But upon rereading I am not sure that was the
intent. It says:
If two or four values are provided, `gnuplot` uses the last
value for calculating the color in pm3d plots.
--
Ethan A Merritt
Biomolecular Structure Center
University of Washington, Seattle WA
|