cdm/src/main/java/ucar/nc2/NetcdfFileWriter.java
public boolean addVariableAttribute(Variable v, Attribute att) {
    if (!defineMode)
      throw new UnsupportedOperationException("not in define mode");

    if (!isValidObjectName(att.getShortName())) {
      String attName = createValidObjectName(att.getShortName());
      log.warn("illegal netCDF-3 attribute name= " + att.getShortName() + " change to " + attName);
      att = new Attribute(attName, att.getValues());
    }

    v.addAttribute(att);
    return true;
  }
public boolean addVariableAttribute(Variable v, Attribute att) {
    if (!defineMode)
      throw new UnsupportedOperationException("not in define mode");

    if (!isValidObjectName(att.getShortName())) {
      String attName = createValidObjectName(att.getShortName());
      log.warn("illegal netCDF-3 attribute name= " + att.getShortName() + " change to " + attName);
      att = new Attribute(attName, att.getValues());
    }

    v.addAttribute(att);
    return true;
  }
Add an attribute to the named Variable. Must be in define mode.

@param v   Variable to add attribute to
@param att Attribute to add.
@return true if attribute was added, false if not allowed by CDM.