Using setDefaultSet and clone()
martin schweitzer
visad at martinschweitzer.com
Mon Oct 2 19:20:38 MDT 2006
Hi
In an application here, we recently found that our main FlatField is
storing data as floats rather than doubles. At first we tried changing
the FlatField to a FieldImpl, however that produced problems with
DirectManipulationRenderer, so another approach was tried. We then
tried calling setDefaultSet() on our RealTypes, which worked in all
ways except our data cloning now appears to not give us a copy as it
used to.
We were surprised that calling setDefaultSet() appears to change
the behaviour of FieldImpl.clone()
When we run the program below, we get a 'deep copy' when using clone. If we
uncomment the following two lines, we get a 'shallow copy':
// lat.setDefaultSet(new DoubleSet(lat));
// lon.setDefaultSet(new DoubleSet(lon));
Any feedback or suggestions will be welcome.
Regards,
Martin
Here is the program:
import visad.*;
public class FlatFieldTest
{
public static void main(String[] args)
{
try {
RealType lat = RealType.getRealType("Latitude");
RealType lon = RealType.getRealType("Longitude");
RealTupleType range = new RealTupleType(lat, lon);
RealType time = RealType.getRealType("time");
* // If the following two lines are commented out, then
// clone works...
// lat.setDefaultSet(new DoubleSet(lat));
// lon.setDefaultSet(new DoubleSet(lon));
*
double samples[][] = {{1, 2}};
Set domain = new Gridded1DDoubleSet(RealType.getRealType("time"),
samples, 2);
FunctionType func = new FunctionType(time, range);
Field myField1 = new FlatField(func, domain);
double[][] values = new double[2][2];
values[0][0] = 100;
values[0][1] = 200;
myField1.setSamples(values);
values[0][0] = 130;
values[0][1] = 180;
Field myField2 = (FieldImpl)((FieldImpl)myField1).clone();
myField2.setSamples(values);
System.out.println("ff1" + myField1);
System.out.println("ff1" + myField2);
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
*Output when the lines are commented out:*
ff1: FlatField
(time -> (Latitude, Longitude))
(100.0, 0.0), (200.0, 0.0)
ff2: FlatField
(time -> (Latitude, Longitude))
(130.0, 0.0), (180.0, 0.0)
*Output when the lines are uncommented:*
ff1: FlatField
(time -> (Latitude, Longitude))
(130.0, 0.0), (180.0, 0.0)
ff2: FlatField
(time -> (Latitude, Longitude))
(130.0, 0.0), (180.0, 0.0)
More information about the visad
mailing list