visad/src/main/java/ucar/nc2/iosp/grid/GridCoordSys.java
void addToNetcdfFile(NetcdfFile ncfile, Group g) {
    if (dontUseVertical) {
      return;
    }

    if (g == null) {
      g = ncfile.getRootGroup();
    }

    String dims = "time";
    if (!dontUseVertical) {
      dims = dims + " " + verticalName;
    }
    if (hcs.isLatLon()) {
      dims = dims + " lat lon";
    } else {
      dims = dims + " y x";
    }

    //Collections.sort( levels);
    int nlevs = levels.size();
    // ncfile.addDimension(g, new Dimension(verticalName, nlevs, true));

    // coordinate axis and coordinate system Variable
    Variable v = new Variable(ncfile, g, null, verticalName);
    v.setDataType(DataType.DOUBLE);

    v.addAttribute(new Attribute("long_name",
            lookup.getLevelDescription(record)));
    v.addAttribute(new Attribute("units", lookup.getLevelUnit(record)));

    // positive attribute needed for CF-1 Height and Pressure
    if (positive != null) {
      v.addAttribute(new Attribute("positive", positive));
    }

    if (units != null) {
      AxisType axisType;
      if (SimpleUnit.isCompatible("millibar", units)) {
        axisType = AxisType.Pressure;
      } else if (SimpleUnit.isCompatible("m", units)) {
        axisType = AxisType.Height;
      } else {
        axisType = AxisType.GeoZ;
      }

      v.addAttribute(
              new Attribute(
                      "grid_level_type",
                      Integer.toString(record.getLevelType1())));

      v.addAttribute(new Attribute(_Coordinate.AxisType,
              axisType.toString()));
      v.addAttribute(new Attribute(_Coordinate.Axes, dims));
      if (!hcs.isLatLon()) {
        v.addAttribute(new Attribute(_Coordinate.Transforms,
                hcs.getGridName()));
      }
    }

    double[] data = new double[nlevs];
    for (int i = 0; i < levels.size(); i++) {
      Double d = (Double) levels.get(i);
      data[i] = d.doubleValue();
    }
    Array dataArray = Array.factory(DataType.DOUBLE, new int[]{nlevs}, data);

    v.setDimensions(verticalName);
    v.setCachedData(dataArray, false);

    ncfile.addVariable(g, v);

    // look for vertical transforms
    if (record.getLevelType1() == 109) {
      findCoordinateTransform(g, "Pressure", record.getLevelType1());
    }
  }
void addToNetcdfFile(NetcdfFile ncfile, Group g) {
    if (dontUseVertical) {
      return;
    }

    if (g == null) {
      g = ncfile.getRootGroup();
    }

    String dims = "time";
    if (!dontUseVertical) {
      dims = dims + " " + verticalName;
    }
    if (hcs.isLatLon()) {
      dims = dims + " lat lon";
    } else {
      dims = dims + " y x";
    }

    //Collections.sort( levels);
    int nlevs = levels.size();
    // ncfile.addDimension(g, new Dimension(verticalName, nlevs, true));

    // coordinate axis and coordinate system Variable
    Variable v = new Variable(ncfile, g, null, verticalName);
    v.setDataType(DataType.DOUBLE);

    v.addAttribute(new Attribute("long_name",
            lookup.getLevelDescription(record)));
    v.addAttribute(new Attribute("units", lookup.getLevelUnit(record)));

    // positive attribute needed for CF-1 Height and Pressure
    if (positive != null) {
      v.addAttribute(new Attribute("positive", positive));
    }

    if (units != null) {
      AxisType axisType;
      if (SimpleUnit.isCompatible("millibar", units)) {
        axisType = AxisType.Pressure;
      } else if (SimpleUnit.isCompatible("m", units)) {
        axisType = AxisType.Height;
      } else {
        axisType = AxisType.GeoZ;
      }

      v.addAttribute(
              new Attribute(
                      "grid_level_type",
                      Integer.toString(record.getLevelType1())));

      v.addAttribute(new Attribute(_Coordinate.AxisType,
              axisType.toString()));
      v.addAttribute(new Attribute(_Coordinate.Axes, dims));
      if (!hcs.isLatLon()) {
        v.addAttribute(new Attribute(_Coordinate.Transforms,
                hcs.getGridName()));
      }
    }

    double[] data = new double[nlevs];
    for (int i = 0; i < levels.size(); i++) {
      Double d = (Double) levels.get(i);
      data[i] = d.doubleValue();
    }
    Array dataArray = Array.factory(DataType.DOUBLE, new int[]{nlevs}, data);

    v.setDimensions(verticalName);
    v.setCachedData(dataArray, false);

    ncfile.addVariable(g, v);

    // look for vertical transforms
    if (record.getLevelType1() == 109) {
      findCoordinateTransform(g, "Pressure", record.getLevelType1());
    }
  }
Add this coordinate system to the netCDF file

@param ncfile the netCDF file
@param g      the group to add to