The new "set link" command gives a very confusing error message when the linking functions do not contain the right independent variable:
set link y2 via 10**(x) inv log10(x) internal error : type neither INT or CMPLX
This here even gives a different error:
# set xr[1:10]; set yr[1:10] # doesn't matter set link y2 via log10(x) inv 10**x unknown type in magnitude()
And sometimes a wrong inverse does not give an error at all:
set link x2 via 10**x inv log(x) # OK, error warning: could not confirm linked axis inverse mapping function min: -10 inv(via(min)): -23.0259 max: 10 inv(via(max)): 23.0259 set link x2 via 1-exp(-10**x) inv log10(-log(1-x)) # correct, no error set link x2 via 1-exp(-10**x) inv log10(-log(2-x)) # should give an error
Could it be this is because the wrong inverse function returns a complex value?
print log10(-log(1-(1-exp(-10**.4)))) 0.4 print log10(-log(2-(1-exp(-10**.4)))) {-1.10794444658882, 1.36437635384184}
I agree that better error messages for errors in the variable name would be nice. At the time I think I couldn't figure out how to do that, but I'm sure it's possible somehow.
As to the rest...
The tests for validity of the inverse function are pretty minimal, and could probably be improved. Your test case is really pushing it :-)
1) Only the endpoints of the range are tested. Nonsense values in between would go undetected.
2) Both inv log10(-log(1-x)) and inv log10(-log(2-x)) are "incorrect" in the sense that unless you limit the x range to less than 1 or less than 2 respectively. In a sense you can say that's "because the inverse returns a complex value". It happens that the implementation of log(x) is extended to handle complex values, other functions would return NaN if the x value goes out of range.
3) The test compares absolute values. I cannot quite recall why, but I think the idea was to forgive pairs like (x**2) | sqrt(x) that are correct except for sign. Having said that, I think the fabs is in the wrong place so it really is a bug. I need to stare at it harder.
So yeah, probably a complex return should be treated as NaN and therefore fail the sanity check. Also maybe the fabs() should be moved or maybe a 2nd one is needed.
I suppose we could check not just the endpoints but every sampled value, although the sampling itself would have no meaning for data plots.
I think was OK if your example pair (x**2) | sqrt(x) threw a warning (as it does now, but that´s probably because of the bug).
Whoever sets up such a linkage knows it´s only partly right. I´d be rather confused to not get a warning.
For such case there could be a "nowarn" option. It might be annoying to get cautioned at every replot. Also in case i don´t need the inverse and am too lazy to derive it.
Last edit: Karl Ratzsch 2014-11-30
cvs source for 5.1 now adds an error test for correct dummy variable use in "set link". This probably should go in 5.0 also but I haven't done that yet.
There is still something weird in both 5.0 and 5.1:
If no explicit yrange is set, then the test (min == inv(via(min))) is always done for -10 (resp. 10 for max), regardless of the actual yrange in the present plot (as shown by "show yr").
This is somewhat annoying, because it gives a warning on every replot
And the maximum test returns the value from the minimum test if inv(via(max)) is not defined. I don´t think this could lead to an error, but it´s definitely odd.
default range:
The default range is [-10:10] pretty much everywhere in gnuplot.
Checking the range used in a previous plot would be possible, but why would you assume that the range will be the same as before? What if there was no previous plot? Even in the case of "replot", the data being plotted may have changed or there may have been an error or ...
report of NaN:
Yeah, that looks like a bug.
OK, let me change the example a bit:
The axes are only generated after the data is read in, so the autoranged minimum/maximum is already known, and could be used to check the linkage.
Does that make sense?
Perhaps the test could additionally be skipped on "set link" (only there) if the respective axis is autoranging.