cdm/src/main/java/ucar/nc2/FileWriter2.java
public Variable addVariable(Variable oldVar) {
    List<Dimension> newDims = getNewDimensions(oldVar);

    Variable newVar;
    if ((oldVar.getDataType().equals(DataType.STRING)) && (!version.isExtendedModel())) {
      newVar = writer.addStringVariable(null, oldVar, newDims);
    } else {
      newVar = writer.addVariable(null, oldVar.getShortName(), oldVar.getDataType(), newDims);
    }
    varMap.put(oldVar, newVar);
    varList.add(oldVar);

    for (Attribute orgAtt : oldVar.getAttributes())
      writer.addVariableAttribute(newVar, convertAttribute(orgAtt));

    return newVar;
  }
public Variable addVariable(Variable oldVar) {
    List<Dimension> newDims = getNewDimensions(oldVar);

    Variable newVar;
    if ((oldVar.getDataType().equals(DataType.STRING)) && (!version.isExtendedModel())) {
      newVar = writer.addStringVariable(null, oldVar, newDims);
    } else {
      newVar = writer.addVariable(null, oldVar.getShortName(), oldVar.getDataType(), newDims);
    }
    varMap.put(oldVar, newVar);
    varList.add(oldVar);

    for (Attribute orgAtt : oldVar.getAttributes())
      writer.addVariableAttribute(newVar, convertAttribute(orgAtt));

    return newVar;
  }
public Variable addVariable ( Variable oldVar ) { List < Dimension > newDims = getNewDimensions ( oldVar ) ; Variable newVar ; if ( ( oldVar . getDataType ( ) . equals ( DataType . STRING ) ) && ( ! version . isExtendedModel ( ) ) ) { newVar = writer . addStringVariable ( null , oldVar , newDims ) ; } else { newVar = writer . addVariable ( null , oldVar . getShortName ( ) , oldVar . getDataType ( ) , newDims ) ; } varMap . put ( oldVar , newVar ) ; varList . add ( oldVar ) ; for ( Attribute orgAtt : oldVar . getAttributes ( ) ) writer . addVariableAttribute ( newVar , convertAttribute ( orgAtt ) ) ; return newVar ; }
Specify which variable will get written

@param oldVar add this variable, and all parent groups
@return new Variable.
Specify which variable will get written