// TODO: We need to support more CRS
// Loop over dimensions
Dimension boundDimension = null;
for (NetCDFDimensionManager manager : dimensionMapping.values()) {
final DimensionBean dim = manager.getCoverageDimension();
final boolean isRange = dim.isRange();
String dimensionName = manager.getName();
final int dimensionLength = getDimensionSize(dimensionName);
if (dimensionName.equalsIgnoreCase("TIME") || dimensionName.equalsIgnoreCase("ELEVATION")) {
// Special management for TIME and ELEVATION dimensions
// we will put these dimension lowercase for NetCDF names
dimensionName = dimensionName.toLowerCase();
}
if (isRange) {
if (boundDimension == null) {
boundDimension = writer.addDimension(null, NCUtilities.BOUNDARY_DIMENSION, 2);
}
}
final Dimension netcdfDimension = writer.addDimension(null, dimensionName, dimensionLength);
manager.setNetCDFDimension(netcdfDimension);
// Assign variable to dimensions having coordinates
Variable var = writer.addVariable(null, dimensionName,
NCUtilities.getNetCDFDataType(dim.getDatatype()), dimensionName);
writer.addVariableAttribute(var, new Attribute(NCUtilities.LONGNAME, dimensionName));
writer.addVariableAttribute(var, new Attribute(NCUtilities.DESCRIPTION, dimensionName));
// TODO: introduce some lookup table to get a description if needed
if (NCUtilities.isATime(dim.getDatatype())) {
// Special management for times. We use the NetCDF convention of defining times starting from
// an origin. Right now we use the Linux EPOCH
writer.addVariableAttribute(var, new Attribute(NCUtilities.UNITS, NCUtilities.TIME_ORIGIN));
} else {
writer.addVariableAttribute(var, new Attribute(NCUtilities.UNITS, dim.getSymbol()));
}
// Add bounds variable for ranges
if (isRange) {
final List<Dimension> boundsDimensions = new ArrayList<Dimension>();
boundsDimensions.add(netcdfDimension);
boundsDimensions.add(boundDimension);
final String boundName = dimensionName + NCUtilities.BOUNDS_SUFFIX;
writer.addVariableAttribute(var, new Attribute(NCUtilities.BOUNDS, boundName));
writer.addVariable(null, boundName, NCUtilities.getNetCDFDataType(dim.getDatatype()), boundsDimensions);
}
}
setupCoordinates();
}