Problems with degrees and maths operations

Hi,

I have positional data containing latitudes and longitudes, and wish to
to get the average position. There are some useful Data methods such as
"add" and "divide" which help here.

However I'm getting some unexpected results, as illustrated by the
attached code (AverageUnits.java)

First of all, simply adding two Reals together which have MathType
RealType.Latitude.

The program produces this output:

Adding -10.0 Type = Latitude Unit = deg
to -20.0 Type = Latitude Unit = deg
Latitude Sum = -0.5235987755982988 Type = Latitude Unit
Latitude Average = -0.2617993877991494 Type = Latitude Unit

It appears that the latitude has been converted to radians (I'd rather it didn't), but notice that the "Unit = " is now blank. What has happened to the Units?

Secondly, the problem gets worse if the Latitude/Longitudes are
contained in a FlatField. The attached program will add two FlatFields
together to produce this output:

Now lets add 2 FlatFields containing Lats and Lons
ff1  = FlatField
    (Time -> (Latitude, Longitude))
(0.5, 0.0), (0.5, 1.0)


ff2  = FlatField
    (Time -> (Latitude, Longitude))
(0.5, 0.0), (0.5, 1.0)


ffSum  = FlatField
    (Time -> (Latitude, Longitude))
(0.017453292519943295, 0.0), (0.017453292519943295, 0.03490658503988659)

Assuming units are now radians, this seems ok, but now when I try to get the average lat/lon by dividing by two, I get:

ffAverage  = FlatField
    (Time -> (RealType_4, RealType_5))
(0.008726646259971648, 0.0), (0.008726646259971648, 0.017453292519943295)

Not only have the units changed, but now the name of the RealTypes is no
longer "Latitude" and "Longitude", but "RealType_4" and "RealType_5".

Grateful for any advice,

Cheers,

James

Australian Bureau of Meteorology

import java.rmi.RemoteException;
import visad.*;

public class AverageUnits
{
        public static void main(String[] args) throws VisADException, 
RemoteException
        {
                try {
                        // first lets sum two latitudes
                        RealType rtLatitude = RealType.Latitude;
                        RealType rtLongitude = RealType.Longitude;
                        Real two = new Real(2.0d);

                        Real rLat1 = new Real(rtLatitude, -10.0d);
                        Real rLat2 = new Real(rtLatitude, -20.0d);
                        Real rSum = (Real) rLat1.add(rLat2);
                        MathType mtSum = rSum.getType();
                        System.out.println("Adding " + rLat1 + " Type = " + 
rLat1.getType() + " Unit = " + rLat1.getUnit());
                        System.out.println("to " + rLat2 + " Type = " + 
rLat2.getType() + " Unit = " + rLat2.getUnit());
                        System.out.println("Latitude Sum = " + rSum + " Type = 
" + mtSum + " Unit = " + rSum.getUnit());

                        // now get the average of the two latitudes
                        Real rAverage = (Real) rSum.divide(two);
                        MathType mtAverage = rSum.getType();
                        System.out.println("Latitude Average = " + rAverage + " 
Type = " + mtAverage + " Unit = " + rAverage.getUnit());
                        System.out.println("\n\n\n");

                        // now see how FlatFields behave
                        System.out.println("Now lets add 2 FlatFields 
containing Lats and Lons");
                        Real minusOne = new Real(-1.0d);
                        RealType[] rtaLatLon = new RealType[] { rtLatitude, 
rtLongitude };
                        RealTupleType rttLatLon = new RealTupleType(rtaLatLon);
                        RealType rtTime = RealType.Time;
                        FunctionType ft = new FunctionType(rtTime, rttLatLon);
                        FlatField ff1 = FlatField.makeField(ft, 2, false);
                        FlatField ff2 = FlatField.makeField(ft, 2, false);
                        System.out.println("ff1  = " + ff1);
                        System.out.println("ff2  = " + ff2);
                        FlatField ffSum = (FlatField) ff1.add(ff2);
                        System.out.println("ffSum  = " + ffSum );

                        FlatField ffMinus = (FlatField) 
ffSum.multiply(minusOne);
                        System.out.println("ffMinus  = " + ffMinus );

                        FlatField ffAverage = (FlatField) ffSum.divide(two);
                        System.out.println("ffAverage  = " + ffAverage );
                } catch (VisADException e) {
                        ;
                } catch (RemoteException e) {
                        ;
                }

                System.exit(0);
        }
}