cdm/src/main/java/ucar/nc2/NetcdfFile.java
public Variable addVariable(Group g, Variable v) {
    if (immutable) throw new IllegalStateException("Cant modify");
    if (g == null) g = rootGroup;
    if (v != null) g.addVariable(v);
    return v;
  }
public Variable addVariable(Group g, Variable v) {
    if (immutable) throw new IllegalStateException("Cant modify");
    if (g == null) g = rootGroup;
    if (v != null) g.addVariable(v);
    return v;
  }
Add a Variable to the given group.

@param g add to this group. If group is null, use root group
@param v add this Variable
@return the variable that was added