# corrupted Low-Hi values in SampledSet

```Hi,

I got a NullPointerException during interpolation (with the evaluate method)
and finally found out that the error was due to a bad LowX value in my
Irregular1DSet. The problem seems to be related to the use of extreme values
(e.g. Float.MIN_VALUES, Float.MAX_VALUE) as samples for the set but doesn't
happen in a consistent manner.  Please find below a small program which
illustrates the problem:
1- method test1() provides an example for which the Low value gets corrupted
2- method test2() provides a similar example but for which the Low and Hi
values are correct
3- method test3() generates the NullPointerException

The output of the program is:

Test 1: low=-1124.069   hi=3.4028235E38
aSet is  visad.Irregular1DSet: Dimension = 1 Length = 4
Dimension 0: Range = -1124.069 to 3.4028235E38

Test 2: low=1.4E-45   hi=3.4028235E38
aSet is  visad.Irregular1DSet: Dimension = 1 Length = 4
Dimension 0: Range = 1.4E-45 to 3.4028235E38

Test 3: interField.evaluate(-2000.0f)
java.lang.NullPointerException
at TestIrregular1DSet.test3(TestIrregular1DSet.java:51)
at TestIrregular1DSet.main(TestIrregular1DSet.java:60)
Process TestIrregular1DSet exited abnormally with code 1

I got the same error with jdk1.1.3 and jdk1.1.4.  I also replaced
Float.MIN_VALUE by Float.NEGATIVE_INFINITE, no luck. I'm really not
convinced that the problem is in the VisAD logic.  Nevertheless, it would be
good to have a solution.

Thanks,
Sylvain

import java.rmi.RemoteException;

public class TestIrregular1DSet {

public TestIrregular1DSet() {
}

public void test1() throws VisADException {
float[][] samples = new float[][] {
{Float.MIN_VALUE, -1124.06897f, -1047.077026f,
Float.MAX_VALUE}};

Irregular1DSet aSet = new Irregular1DSet(
RealType.getRealType("x1", null, null), samples);
float[] hi = aSet.getHi();
float[] low = aSet.getLow();

System.out.println("Test 1: low=" + low[0] + "   hi=" + hi[0]);
System.out.println("        aSet is " + aSet.longString(" "));

}

public void test2() throws VisADException {
float[][] samples = new float[][] {
{Float.MIN_VALUE, 208.561829f, 326.168915f,
Float.MAX_VALUE}};
Irregular1DSet aSet =
new Irregular1DSet(RealType.getRealType("x2", null, null),
samples);

float[] hi = aSet.getHi();
float[] low = aSet.getLow();
System.out.println("Test 2: low=" + low[0] + "   hi=" + hi[0]);
System.out.println("        aSet is " + aSet.longString(" "));
}

public void test3() throws VisADException, RemoteException {
float[][] samples = new float[][] {
{Float.MIN_VALUE, -1124.06897f, -1047.077026f,
Float.MAX_VALUE}};

Irregular1DSet aSet =
new Irregular1DSet(RealType.getRealType("x1", null,
null),samples);

RealType x1RT = RealType.getRealType("x1");
FunctionType interFuncType =
new FunctionType(x1RT, RealType.getRealType("value", null,
null));
FlatField interField = new FlatField(interFuncType, aSet);
interField.setSamples(new float[][] {
{100.0f, 150.0f, 110.0f, 75.0f}});
System.out.println("Test 3: interField.evaluate(-2000.0f)=");
System.out.println(interField.evaluate(new Real(x1RT, -2000.0),

Data.WEIGHTED_AVERAGE,
Data.NO_ERRORS));
}

public static void main(String[] args) throws VisADException,
RemoteException {
TestIrregular1DSet aTest = new TestIrregular1DSet();
aTest.test1();
aTest.test2();
aTest.test3();
}

}

===
Sylvain Létourneau
Research Officer
• Search the `visad` archives: