Package ucar.nc2

Class Dimension

  • All Implemented Interfaces:
    Comparable<Dimension>
    Direct Known Subclasses:
    UnlimitedDimension

    @Immutable
    public class Dimension
    extends Object
    implements Comparable<Dimension>
    A Dimension defines the array shape of a Variable. A Variable can be thought of as a sampled function with Domain its Dimensions. A Dimension may be shared among Variables, which provides a simple yet powerful way of associating Variables. When a Dimension is shared, it has a unique name within its Group. If not shared, it may be named or be left blank. It may have a coordinate Variable, which gives each index a coordinate value. A private Dimension cannot have a coordinate Variable, so only use shared dimensions with coordinates when possible. The Dimension length must be > 0, except for an unlimited dimension which may have length = 0, and a vlen Dimension which has a length known only when the variable is read.

    Note: this class has a natural ordering (sort by name) that is inconsistent with equals.

    • Field Detail

      • VLEN

        public static final Dimension VLEN
        A variable-length dimension: the length is not known until the data is read.
    • Constructor Detail

      • Dimension

        public Dimension​(String name,
                         int length)
        Default Constructor, shared, not unlimited, not variable length.
        Parameters:
        name - name must be unique within group
        length - length of Dimension
      • Dimension

        public Dimension​(String name,
                         int length,
                         boolean isShared,
                         boolean isUnlimited,
                         boolean isVariableLength)
        General Constructor.
        Parameters:
        name - name must be unique within group. Can be null/empty only if not shared.
        length - length, ignored if isVariableLength, ≥ 0 if unlimited, else > 0.
        isShared - whether its shared or local to Variable.
        isUnlimited - whether the length can grow.
        isVariableLength - whether the length is unknown until the data is read.
    • Method Detail

      • getLength

        public int getLength()
        Get the length of the Dimension.
      • getShortName

        public String getShortName()
        Get the name of the Dimension. May be the length if not shared and name is empty.
      • isUnlimited

        public boolean isUnlimited()
        If this is a NetCDF unlimited dimension. The length might increase between invocations, but it remains fixed for the lifetime of the NetcdfFile. If you modify the file in a separate process, you must close and reopen the file.
        Returns:
        if its an "unlimited" Dimension
      • isVariableLength

        public boolean isVariableLength()
        If variable length, then the length is unknown until the data is read.
        Returns:
        if its a "variable length" Dimension.
      • isShared

        public boolean isShared()
        If this Dimension is shared, or is private to a Variable. All Dimensions in NetcdfFile.getDimensions() or Group.getDimensions() are shared. Dimensions in the Variable.getDimensions() may be shared or private.
        Returns:
        if its a "shared" Dimension.
      • makeFullName

        public String makeFullName​(Variable v)
        Make the full name by searching for the containing group starting from the Variable's parent group.
        Throws:
        IllegalStateException - if not found in one of the Variable's parent groups.
      • makeFullName

        public String makeFullName​(Group containingGroup)
        Make the full name, starting with any group which contains the dimension in itself or a parent group.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • compareTo

        public int compareTo​(Dimension odim)
        Dimensions are compared by name. This method is inconsistent with equals()!
        Specified by:
        compareTo in interface Comparable<Dimension>
        Parameters:
        odim - compare to this Dimension
        Returns:
        0, 1, or -1
      • toBuilder

        public Dimension.Builder toBuilder()
        Turn into a mutable Builder, use toBuilder().build() to make a copy.
      • builder

        public static Dimension.Builder builder​(String name,
                                                int length)
        A builder with the Dimension name and length set