promoteGlobalAttributes( (DatasetOuterDimension) typicalDataset);
// create aggregation coordinate variable
DataType coordType = getCoordinateType();
VariableDS joinAggCoord = new VariableDS(ncDataset, null, null, dimName, coordType, dimName, null, null);
ncDataset.addVariable(null, joinAggCoord);
joinAggCoord.setProxyReader( this);
if (isDate)
joinAggCoord.addAttribute(new ucar.nc2.Attribute(_Coordinate.AxisType, "Time"));
// if speced externally, this variable will get replaced
CacheVar cv = new CoordValueVar(joinAggCoord.getFullName(), joinAggCoord.getDataType(), joinAggCoord.getUnitsString());
joinAggCoord.setSPobject( cv);
cacheList.add(cv);
List<String> aggVarNames = getAggVariableNames();
// if no names specified, add all "non-coordinate" variables.
// Note that we havent identified coordinate systems with CoordSysBuilder, so that info ius not available.
// So this isnt that general of a solution. But probably better than nothing
if (aggVarNames.size() == 0) {
for (Variable v : typical.getVariables()) {
if (!(v instanceof CoordinateAxis))
aggVarNames.add(v.getShortName());
}
}
// now we can create all the aggNew variables
// use only named variables
for (String varname : aggVarNames) {
Variable aggVar = ncDataset.findVariable(varname);
if (aggVar == null) {
logger.error(ncDataset.getLocation() + " aggNewDimension cant find variable " + varname);
continue;
}
// construct new variable, replace old one LOOK what about Structures?
Group newGroup = DatasetConstructor.findGroup(ncDataset, aggVar.getParentGroup());
VariableDS vagg = new VariableDS(ncDataset, newGroup, null, aggVar.getShortName(), aggVar.getDataType(),
dimName + " " + aggVar.getDimensionsString(), null, null);
vagg.setProxyReader( this);
DatasetConstructor.transferVariableAttributes(aggVar, vagg);
// _CoordinateAxes if it exists must be modified
Attribute att = vagg.findAttribute(_Coordinate.Axes);
if (att != null) {
String axes = dimName + " " + att.getStringValue();
vagg.addAttribute(new Attribute(_Coordinate.Axes, axes));
}
newGroup.removeVariable( aggVar.getShortName());
newGroup.addVariable( vagg);
aggVars.add(vagg);