Array xData = Array.factory( float.class, new int[] {x_dim.getLength()});
Array yData = Array.factory( float.class, new int[] {y_dim.getLength()});
LatLonPointImpl latlon = new LatLonPointImpl();
ProjectionPointImpl pp = new ProjectionPointImpl();
Index latlonIndex = latData.getIndex();
Index xIndex = xData.getIndex();
Index yIndex = yData.getIndex();
// construct x coord
for (int i=0; i<x_dim.getLength(); i++) {
double lat = latData.getDouble( latlonIndex.set1(i));
double lon = lonData.getDouble( latlonIndex);
latlon.set( lat, lon);
proj.latLonToProj( latlon, pp);
xData.setDouble( xIndex.set(i), pp.getX());
}
// construct y coord
for (int i=0; i<y_dim.getLength(); i++) {
double lat = latData.getDouble( latlonIndex.set0(i));
double lon = lonData.getDouble( latlonIndex);
latlon.set( lat, lon);
proj.latLonToProj( latlon, pp);
yData.setDouble( yIndex.set(i), pp.getY());
}
VariableDS xaxis = new VariableDS(ds, null, null, "xCoord", DataType.FLOAT, x_dim.getName(), "km", "x on projection");
xaxis.addAttribute(new Attribute("units", "km"));
xaxis.addAttribute(new Attribute("long_name", "x on projection"));