|
From: Ethan M. <merritt@u.washington.edu> - 2010-02-05 23:36:55
|
It seems that the code implementing "index" has been broken since
at least version 3.7. It always loads one too many data points.
This is most easily seen by selecting table output.
Here is output from gnuplot v3.7, but it is the same in current CVS.
==========
gnuplot> set term table
gnuplot> plot '-' index 0 using 1:2
1 1.
2 2.
3 3.
4 4.
e
#Curve 0, 4 points
#x y type
1 1 i
2 2 i
3 3 i
0 0 u
===========
If you are simply plotting the points, this error is usually hidden
because the extra point is marked UNDEFINED and doesn't appear in the graph.
But if you actually care about the exact number of points in the data set,
it is a problem.
The new (CVS only) plot style "with boxplot" does care about the number of
points, and this bug triggered a report from Péter Juhász about boxplot
errors. But the underlying bug is not specific to the plot style,
and the fix must surely belong in the "index" handling code.
Now I am on shaky ground.
Where does the fix go, exactly?
Maybe df_readascii() in datafile.c needs to explicitly return
DF_SECOND_BLANK rather than DF_EOF in places
like this:
/* Found two blank lines after a block of data with a named index */
if (indexname && index_found) {
df_eof = 1;
return DF_EOF;
}
and this:
/* df_upper_index is MAXINT-1 if we are not doing index */
if (df_current_index > df_upper_index) {
/* oops - need to gobble rest of input if mixed */
if (mixed_data_fp)
continue;
else {
df_eof = 1;
return DF_EOF; /* no point continuing */
}
}
Or maybe it is OK to simply strip undefined points from the end of
all data sets?
--- cvs/gnuplot/src/plot2d.c 2010-01-12 19:04:51.000000000 -0800
+++ test/gnuplot/src/plot2d.c 2010-02-05 15:18:34.000000000 -0800
@@ -926,6 +926,9 @@ images:
} /*while */
+ /* Trim off extra point at end of indexed data */
+ if (current_plot->points[i-1].type == UNDEFINED)
+ i--;
current_plot->p_count = i;
cp_extend(current_plot, i); /* shrink to fit */
That simple patch does seem to solve the boxplot problem.
Maybe both of these changes, along with a new point type that is
set when the second blank line is encountered?
INRANGE/OUTRANGE/UNDEFINED/DATASET_SEPARATOR
Ethan
--
Ethan A Merritt
|