Curtis,
It looks like the binary option promotes to double, and the serial
option forces float?
Tom
Curtis Rueden wrote:
Hi,
I was using Java serialization to save some FlatFields to a disk
cache file. I decided to switch this logic over to the VisADForm
binary writer. I noticed that the size of the FlatFields on disk
doubled with this scheme.
These FlatFields were populated with setSamples(float[][], boolean).
I did some experiments with VisADForm in serialization vs binary
mode, and with float[][] vs double[][], and I'm confused.
Below is my test program. And here is the output:
C:\java\test>java BinaryFieldSizeTest
Float files should be ~400000 bytes.
Double files should be ~800000 bytes.
C:\java\test>ls -l *.vad
-rw-r--r-- 1 root None 800271 Jul 21 16:58 binary-double.vad
-rw-r--r-- 1 root None 800271 Jul 21 16:58 binary-float.vad
-rw-r--r-- 1 root None 403626 Jul 21 16:58 serial-double.vad
-rw-r--r-- 1 root None 403626 Jul 21 16:58 serial-float.vad
It doesn't seem to matter if the FlatField has double[][] samples
or float[][] samples. And the binary version is twice as large as
the serialized version. In particular, it is disconcerting that
the "serial-double.vad" is twice as small as it should be.
Is something wrong with my code? Or is this behavior a bug? Is
there an easy way around the problem? Is there an easy fix that
could be applied to the VisADForm writer?
Thanks,
Curtis
---------
//
// BinaryFieldSizeTest.java
//
import visad.*;
import visad.data.visad.VisADForm;
public class BinaryFieldSizeTest {
public static void main(String[] args) throws Exception {
int cx = 500;
int cy = 200;
int count = cx * cy;
double[][] sampsD = new double[1][count];
float[][] sampsF = new float[1][count];
for (int i=0; i<count; i++) {
sampsD[0][i] = count * Math.random();
sampsF[0][i] = (float) sampsD[0][i];
}
RealType x = RealType.getRealType("x");
RealType y = RealType.getRealType("y");
RealTupleType xy = new RealTupleType(x, y);
RealType value = RealType.getRealType("value");
FunctionType ftype = new FunctionType(xy, value);
Integer2DSet fset = new Integer2DSet(xy, cx, cy);
FlatField fieldD = new FlatField(ftype, fset);
fieldD.setSamples(sampsD, false);
FlatField fieldF = new FlatField(ftype, fset);
fieldF.setSamples(sampsF, false);
VisADForm binaryD = new VisADForm(true);
binaryD.save("binary-double.vad", fieldD, true);
VisADForm serialD = new VisADForm(false);
serialD.save("serial-double.vad", fieldD, true);
VisADForm binaryF = new VisADForm(true);
binaryF.save("binary-float.vad", fieldF, true);
VisADForm serialF = new VisADForm(false);
serialF.save("serial-float.vad", fieldF, true);
int sizeF = 4 * count;
System.out.println("Float files should be ~" + sizeF + " bytes.");
int sizeD = 8 * count;
System.out.println("Double files should be ~" + sizeD + " bytes.");
}
}