cdm/src/main/java/ucar/nc2/NetcdfFileWriter.java
public Variable renameVariable(String oldName, String newName) {
    if (!defineMode) throw new UnsupportedOperationException("not in define mode");
    Variable v = ncfile.findVariable(oldName);
    if (null != v) {
      String fullOldNameEscaped = v.getFullNameEscaped();
      v.setName(newName);
      varRenameMap.put(v.getFullNameEscaped(), fullOldNameEscaped);
    }
    return v;
  }
public Variable renameVariable(String oldName, String newName) {
    if (!defineMode) throw new UnsupportedOperationException("not in define mode");
    Variable v = ncfile.findVariable(oldName);
    if (null != v) {
      String fullOldNameEscaped = v.getFullNameEscaped();
      v.setName(newName);
      varRenameMap.put(v.getFullNameEscaped(), fullOldNameEscaped);
    }
    return v;
  }
Rename a Variable. Must be in define mode.

@param oldName existing Variable has this name
@param newName rename to this
@return renamed Variable, or null if not found