cdm/src/main/java/ucar/nc2/Variable.java
public Variable reduce(List<Dimension> dims) throws InvalidRangeException {
    List<Integer> dimIdx = new ArrayList<>(dims.size());
    for (Dimension d : dims) {
      assert dimensions.contains(d);
      assert d.getLength() == 1;
      dimIdx.add(dimensions.indexOf(d));
    }

    // create a copy of this variable with a proxy reader
    Variable sliceV = copy(); // subclasses must override
    sliceV.setProxyReader(new ReduceReader(this, dimIdx));
    sliceV.createNewCache(); // dont share the cache
    sliceV.setCaching(false); // dont cache

    // remove dimension(s) - reduce rank
    for (Dimension d : dims) sliceV.dimensions.remove(d);
    sliceV.resetShape();
    return sliceV;
  }
public Variable reduce(List<Dimension> dims) throws InvalidRangeException {
    List<Integer> dimIdx = new ArrayList<>(dims.size());
    for (Dimension d : dims) {
      assert dimensions.contains(d);
      assert d.getLength() == 1;
      dimIdx.add(dimensions.indexOf(d));
    }

    // create a copy of this variable with a proxy reader
    Variable sliceV = copy(); // subclasses must override
    sliceV.setProxyReader(new ReduceReader(this, dimIdx));
    sliceV.createNewCache(); // dont share the cache
    sliceV.setCaching(false); // dont cache

    // remove dimension(s) - reduce rank
    for (Dimension d : dims) sliceV.dimensions.remove(d);
    sliceV.resetShape();
    return sliceV;
  }
Create a new Variable that is a logical view of this Variable, by
eliminating the specified dimension(s) of length 1.
No data is read until a read method is called on it.

@param dims   list of  dimensions of length 1 to reduce
@return a new Variable which is a logical slice of this Variable.
@throws InvalidRangeException if dimension or value is illegal