legacy/src/main/java/ucar/nc2/NetcdfFileWriteable.java
public Variable addVariable(String shortName, DataType dataType, List<Dimension> dims) {
    if (!defineMode)
      throw new UnsupportedOperationException("not in define mode");
    if (!N3iosp.isValidNetcdfObjectName(shortName))
      throw new IllegalArgumentException("illegal netCDF-3 variable name: "+shortName);
    if (!valid.contains(dataType))
      throw new IllegalArgumentException("illegal dataType for netcdf-3 format: "+dataType);

    // check unlimited
    int count = 0;
    for (Dimension d : dims) {
      if (d.isUnlimited())
        if (count != 0)
          throw new IllegalArgumentException("Unlimited dimension "+d+" must be first instead its  ="+count);
      count++;
    }

    Variable v = new Variable(this, rootGroup, null, shortName);
    v.setDataType(dataType);
    v.setDimensions(dims);

    long size = v.getSize() * v.getElementSize();
    if (size > N3iosp.MAX_VARSIZE)
      throw new IllegalArgumentException("Variable size in bytes "+size+" may not exceed "+ N3iosp.MAX_VARSIZE);
    
    super.addVariable(null, v);
    return v;
  }
public Variable addVariable(String shortName, DataType dataType, List<Dimension> dims) {
    if (!defineMode)
      throw new UnsupportedOperationException("not in define mode");
    if (!N3iosp.isValidNetcdfObjectName(shortName))
      throw new IllegalArgumentException("illegal netCDF-3 variable name: "+shortName);
    if (!valid.contains(dataType))
      throw new IllegalArgumentException("illegal dataType for netcdf-3 format: "+dataType);

    // check unlimited
    int count = 0;
    for (Dimension d : dims) {
      if (d.isUnlimited())
        if (count != 0)
          throw new IllegalArgumentException("Unlimited dimension "+d+" must be first instead its  ="+count);
      count++;
    }

    Variable v = new Variable(this, rootGroup, null, shortName);
    v.setDataType(dataType);
    v.setDimensions(dims);

    long size = v.getSize() * v.getElementSize();
    if (size > N3iosp.MAX_VARSIZE)
      throw new IllegalArgumentException("Variable size in bytes "+size+" may not exceed "+ N3iosp.MAX_VARSIZE);
    
    super.addVariable(null, v);
    return v;
  }
public Variable addVariable ( String shortName , DataType dataType , List < Dimension > dims ) { if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; if ( ! N3iosp . isValidNetcdfObjectName ( shortName ) ) throw new IllegalArgumentException ( "illegal netCDF-3 variable name: " + shortName ) ; if ( ! valid . contains ( dataType ) ) throw new IllegalArgumentException ( "illegal dataType for netcdf-3 format: " + dataType ) ; // check unlimited int count = 0 ; for ( Dimension d : dims ) { if ( d . isUnlimited ( ) ) if ( count != 0 ) throw new IllegalArgumentException ( "Unlimited dimension " + d + " must be first instead its  =" + count ) ; count ++ ; } Variable v = new Variable ( this , rootGroup , null , shortName ) ; v . setDataType ( dataType ) ; v . setDimensions ( dims ) ; long size = v . getSize ( ) * v . getElementSize ( ) ; if ( size > N3iosp . MAX_VARSIZE ) throw new IllegalArgumentException ( "Variable size in bytes " + size + " may not exceed " + N3iosp . MAX_VARSIZE ) ; super . addVariable ( null , v ) ; return v ; }
Add a variable to the file. Must be in define mode.

@param shortName  name of Variable, must be unique with the file.
@param dataType type of underlying element
@param dims     list of Dimensions for the variable, must already have been added. Use a list of length 0
for a scalar variable.
@return the Variable that has been added
Add a variable to the file . Must be in define mode .