cdm/src/main/java/ucar/nc2/NetcdfFileWriter.java
public Variable addVariable(Group g, Structure parent, String shortName, DataType dataType, List<Dimension> dims) {
    if (!defineMode)
      throw new UnsupportedOperationException("not in define mode");

    DataType writeType =  version.isExtendedModel() ?
            dataType : dataType.withSignedness(DataType.Signedness.SIGNED); // use signed type for netcdf3
    boolean usingSignForUnsign = writeType != dataType;
    if (!isValidDataType(writeType))
      throw new IllegalArgumentException("illegal dataType: " + dataType + " not supported in netcdf-3");

    // check unlimited if classic model
    if (!version.isExtendedModel()) {
      for (int i = 0; i < dims.size(); i++) {
        Dimension d = dims.get(i);
        if (d.isUnlimited() && (i != 0))
          throw new IllegalArgumentException("Unlimited dimension " + d.getShortName() + " must be first (outermost) in netcdf-3 ");
      }
    }

    shortName = makeValidObjectName(shortName);
    Variable v;
    if (dataType == DataType.STRUCTURE) {
      v = new Structure(ncfile, g, parent, shortName);
    } else {
      v = new Variable(ncfile, g, parent, shortName);
    }
    v.setDataType(writeType);
    v.setDimensions(dims);
    if (usingSignForUnsign)
      v.addAttribute(new Attribute(CDM.UNSIGNED, "true"));

    long size = v.getSize() * v.getElementSize();
    if (version == Version.netcdf3 && size > N3iosp.MAX_VARSIZE)
      throw new IllegalArgumentException("Variable size in bytes " + size + " may not exceed " + N3iosp.MAX_VARSIZE);
      //System.out.printf("Variable size in bytes " + size + " may not exceed " + N3iosp.MAX_VARSIZE);

    ncfile.addVariable(g, v);
    return v;
  }
public Variable addVariable(Group g, Structure parent, String shortName, DataType dataType, List<Dimension> dims) {
    if (!defineMode)
      throw new UnsupportedOperationException("not in define mode");

    DataType writeType =  version.isExtendedModel() ?
            dataType : dataType.withSignedness(DataType.Signedness.SIGNED); // use signed type for netcdf3
    boolean usingSignForUnsign = writeType != dataType;
    if (!isValidDataType(writeType))
      throw new IllegalArgumentException("illegal dataType: " + dataType + " not supported in netcdf-3");

    // check unlimited if classic model
    if (!version.isExtendedModel()) {
      for (int i = 0; i < dims.size(); i++) {
        Dimension d = dims.get(i);
        if (d.isUnlimited() && (i != 0))
          throw new IllegalArgumentException("Unlimited dimension " + d.getShortName() + " must be first (outermost) in netcdf-3 ");
      }
    }

    shortName = makeValidObjectName(shortName);
    Variable v;
    if (dataType == DataType.STRUCTURE) {
      v = new Structure(ncfile, g, parent, shortName);
    } else {
      v = new Variable(ncfile, g, parent, shortName);
    }
    v.setDataType(writeType);
    v.setDimensions(dims);
    if (usingSignForUnsign)
      v.addAttribute(new Attribute(CDM.UNSIGNED, "true"));

    long size = v.getSize() * v.getElementSize();
    if (version == Version.netcdf3 && size > N3iosp.MAX_VARSIZE)
      throw new IllegalArgumentException("Variable size in bytes " + size + " may not exceed " + N3iosp.MAX_VARSIZE);
      //System.out.printf("Variable size in bytes " + size + " may not exceed " + N3iosp.MAX_VARSIZE);

    ncfile.addVariable(g, v);
    return v;
  }
public Variable addVariable ( Group g , Structure parent , String shortName , DataType dataType , List < Dimension > dims ) { if ( ! defineMode ) throw new UnsupportedOperationException ( "not in define mode" ) ; DataType writeType = version . isExtendedModel ( ) ? dataType : dataType . withSignedness ( DataType . Signedness . SIGNED ) ; // use signed type for netcdf3
 boolean usingSignForUnsign = writeType != dataType ; if ( ! isValidDataType ( writeType ) ) throw new IllegalArgumentException ( "illegal dataType: " + dataType + " not supported in netcdf-3" ) ; // check unlimited if classic model
 if ( ! version . isExtendedModel ( ) ) { for ( int i = 0 ; i < dims . size ( ) ; i ++ ) { Dimension d = dims . get ( i ) ; if ( d . isUnlimited ( ) && ( i != 0 ) ) throw new IllegalArgumentException ( "Unlimited dimension " + d . getShortName ( ) + " must be first (outermost) in netcdf-3 " ) ; } } shortName = makeValidObjectName ( shortName ) ; Variable v ; if ( dataType == DataType . STRUCTURE ) { v = new Structure ( ncfile , g , parent , shortName ) ; } else { v = new Variable ( ncfile , g , parent , shortName ) ; } v . setDataType ( writeType ) ; v . setDimensions ( dims ) ; if ( usingSignForUnsign ) v . addAttribute ( new Attribute ( CDM . UNSIGNED , "true" ) ) ; long size = v . getSize ( ) * v . getElementSize ( ) ; if ( version == Version . netcdf3 && size > N3iosp . MAX_VARSIZE ) throw new IllegalArgumentException ( "Variable size in bytes " + size + " may not exceed " + N3iosp . MAX_VARSIZE ) ; //System.out.printf("Variable size in bytes " + size + " may not exceed " + N3iosp.MAX_VARSIZE);
 ncfile . addVariable ( g , v ) ; return v ; }
Add a variable to the file. Must be in define mode.

@param g         add to this group in the new file
@param parent    parent Structure (netcdf4 only), or null if not a member of a Structure
@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 in the new file, 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 .