Dear Sylvain,
I compiled and ran your test program and did not get any
NullPointerException. In fact, all the results were correct.
Note that Float.MIN_VALUE is the smallest positive float,
rather than the least negative. So in Test1 the low value
is a negative number rather than Float.MIN_VALUE. Here is
the output I got:
doll% java TestIrregular1DSet
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)
missing
Cheers,
Bill
"Letourneau, Sylvain" wrote:
>
> 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 visad.Irregular1DSet.valueToInterp(Irregular1DSet.java:127)
> at visad.FlatField.resample(FlatField.java:3446)
> at visad.FunctionImpl.evaluate(FunctionImpl.java:169)
> at visad.FunctionImpl.evaluate(FunctionImpl.java:128)
> at TestIrregular1DSet.test3(TestIrregular1DSet.java:51)
> at TestIrregular1DSet.main(TestIrregular1DSet.java:60)
> Exception in thread "main"
> 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;
> import visad.*;
>
> 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
> National Research Council of Canada
> 1500 Montreal road, Build. M-50, Rm 367A
> Ottawa, Ontario Canada K1A 0R6
> Phone:(613) 990-1178
> Fax:(613) 952-0215
--
----------------------------------------------------------
Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI 53706
hibbard@xxxxxxxxxxxxxxxxx 608-263-4427 fax: 608-263-6738
http://www.ssec.wisc.edu/~billh/vis.html