List<CoordinateSystem> csList = ds.getCoordinateSystems();
for (CoordinateSystem cs : csList) {
Element csElem;
if (GridCoordSys.isGridCoordSys(null, cs, null)) {
GridCoordSys gcs = new GridCoordSys(cs, null);
csElem = new Element("gridCoordSystem");
csElem.setAttribute("name", cs.getName());
csElem.setAttribute("horizX", gcs.getXHorizAxis().getFullName());
csElem.setAttribute("horizY", gcs.getYHorizAxis().getFullName());
if (gcs.hasVerticalAxis())
csElem.setAttribute("vertical", gcs.getVerticalAxis().getFullName());
if (gcs.hasTimeAxis())
csElem.setAttribute("time", cs.getTaxis().getFullName());
} else {
csElem = new Element("coordSystem");
csElem.setAttribute("name", cs.getName());
}
List<CoordinateTransform> coordTransforms = cs.getCoordinateTransforms();
for (CoordinateTransform ct : coordTransforms) {
Element ctElem = new Element("coordTransform");
csElem.addContent(ctElem);
ctElem.setAttribute("name", ct.getName());
ctElem.setAttribute("type", ct.getTransformType().toString());
}
rootElem.addContent(csElem);
}
List<CoordinateTransform> coordTransforms = ds.getCoordinateTransforms();
for (CoordinateTransform ct : coordTransforms) {
Element ctElem = new Element("coordTransform");
rootElem.addContent(ctElem);
ctElem.setAttribute("name", ct.getName());
ctElem.setAttribute("type", ct.getTransformType().toString());
List<Parameter> params = ct.getParameters();
for (Parameter pp : params) {
Element ppElem = new Element("param");
ctElem.addContent(ppElem);
ppElem.setAttribute("name", pp.getName());
ppElem.setAttribute("value", pp.getStringValue());
}
}
for (Variable var : ds.getVariables()) {
VariableEnhanced ve = (VariableEnhanced) var;
if (ve instanceof CoordinateAxis) continue;
GridCoordSys gcs = getGridCoordSys(ve);
if (null != gcs) {
nDataVariables++;
Element gridElem = new Element("grid");
rootElem.addContent(gridElem);
gridElem.setAttribute("name", ve.getFullName());
gridElem.setAttribute("decl", getDecl(ve));
if (ve.getUnitsString() != null) {
gridElem.setAttribute("units", ve.getUnitsString());
gridElem.setAttribute("udunits", isUdunits(ve.getUnitsString()));
}
gridElem.setAttribute("coordSys", gcs.getName());
}
}
for (Variable var : ds.getVariables()) {
VariableEnhanced ve = (VariableEnhanced) var;
if (ve instanceof CoordinateAxis) continue;
GridCoordSys gcs = getGridCoordSys(ve);
if (null == gcs) {
nOtherVariables++;
Element elem = new Element("variable");
rootElem.addContent(elem);