legacy/src/main/java/ucar/nc2/NetcdfFileWriteable.java
public void addVariableAttribute(String varName, Attribute att) {
    if (!defineMode)
      throw new UnsupportedOperationException("not in define mode");

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

    Variable v = rootGroup.findVariable(varName);
    if (null == v)
      throw new IllegalArgumentException("addVariableAttribute variable name not found = <" + varName + ">");
    v.addAttribute(att);
  }
public void addVariableAttribute(String varName, Attribute att) {
    if (!defineMode)
      throw new UnsupportedOperationException("not in define mode");

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

    Variable v = rootGroup.findVariable(varName);
    if (null == v)
      throw new IllegalArgumentException("addVariableAttribute variable name not found = <" + varName + ">");
    v.addAttribute(att);
  }
public void addVariableAttribute ( String varName , Attribute att ) { if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; if ( ! N3iosp . isValidNetcdfObjectName ( att . getShortName ( ) ) ) { String attName = N3iosp . makeValidNetcdfObjectName ( att . getShortName ( ) ) ; log . warn ( "illegal netCDF-3 attribute name= " + att . getShortName ( ) + " change to " + attName ) ; att = new Attribute ( attName , att . getValues ( ) ) ; } Variable v = rootGroup . findVariable ( varName ) ; if ( null == v ) throw new IllegalArgumentException ( "addVariableAttribute variable name not found = <" + varName + ">" ) ; v . addAttribute ( att ) ; }
Add an attribute to the named Variable. Must be in define mode.

@param varName name of variable. must already have been added to the file.
@param att     Attribute to add.
Add an attribute to the named Variable . Must be in define mode .