cdm/src/main/java/ucar/nc2/NetcdfFileWriter.java
public Variable addStringVariable(Group g, String shortName, List<Dimension> dims, int max_strlen) {
    if (!defineMode)
      throw new UnsupportedOperationException("not in define mode");
    shortName = makeValidObjectName(shortName);

    Variable v = new Variable(ncfile, g, null, shortName);
    v.setDataType(DataType.CHAR);

    Dimension d = addDimension(g, shortName + "_strlen", max_strlen);
    List<Dimension> sdims = new ArrayList<>(dims);
    sdims.add(d);
    v.setDimensions(sdims);

    ncfile.addVariable(g, v);
    return v;
  }
public Variable addStringVariable(Group g, String shortName, List<Dimension> dims, int max_strlen) {
    if (!defineMode)
      throw new UnsupportedOperationException("not in define mode");
    shortName = makeValidObjectName(shortName);

    Variable v = new Variable(ncfile, g, null, shortName);
    v.setDataType(DataType.CHAR);

    Dimension d = addDimension(g, shortName + "_strlen", max_strlen);
    List<Dimension> sdims = new ArrayList<>(dims);
    sdims.add(d);
    v.setDimensions(sdims);

    ncfile.addVariable(g, v);
    return v;
  }
Add a variable with DataType = String to the file. Must be in define mode.
The variable will be stored in the file as a CHAR variable.
A new dimension with name "varName_strlen" is automatically added, with length max_strlen.

@param shortName  name of Variable, must be unique within the file.
@param dims       list of Dimensions for the variable, must already have been added. Use a list of length 0
for a scalar variable. Do not include the string length dimension.
@param max_strlen maximum string length.
@return the Variable that has been added