Class VariableDS

  • All Implemented Interfaces:
    Comparable<Variable>, VariableEnhanced, ProxyReader
    Direct Known Subclasses:
    CoordinateAxis

    @Immutable
    public class VariableDS
    extends Variable
    implements VariableEnhanced
    A wrapper around a Variable, creating an "enhanced" Variable. The original Variable is used for the I/O. There are several distinct uses:
    1. Handle scale/offset/missing/enum/unsigned conversion; this can change DataType and data values
    2. Container for coordinate system information
    3. NcML modifications to underlying Variable
    • Method Detail

      • fromVar

        public static VariableDS fromVar​(Group group,
                                         Variable orgVar,
                                         boolean enhance)
        Create a VariableDS from orgVar, with default enhancements if requested.
        Parameters:
        group - Reparent to this Group.
        orgVar - Wrap this Variable.
        enhance - opriona default enhancements.
      • getNetcdfFile

        public NetcdfFile getNetcdfFile()
        Description copied from class: Variable
        Get the NetcdfFile that this variable is contained in. May be null when the Variable is self contained.
        Overrides:
        getNetcdfFile in class Variable
      • hasMissing

        public boolean hasMissing()
        true if Variable has missing data values
      • isMissing

        public boolean isMissing​(double val)
        true if the argument is a missing value. Note that Float.NaN and Double.NaN are always considered missing data.
        Parameters:
        val - an unpacked value.
      • convertNeeded

        public boolean convertNeeded()
        Does data need to be converted?
      • convertArray

        public Array<?> convertArray​(Array<?> data)
        Convert the data using the VariableDS enhancements. Generally the user does not have to call this.
      • getEnhanceMode

        public Set<NetcdfDataset.Enhance> getEnhanceMode()
        Returns the enhancements applied to this variable. If this variable wraps another variable, the returned set will also contain the enhancements applied to the nested variable, recursively.
        Returns:
        the enhancements applied to this variable.
      • getOriginalArrayType

        public ArrayType getOriginalArrayType()
        When this wraps another Variable, get the original Variable's ArrayType.
        Returns:
        original Variable's ArrayType, or current data type if it doesnt wrap another variable
      • getOriginalName

        @Nullable
        public String getOriginalName()
        When this wraps another Variable, get the original Variable's name.
        Specified by:
        getOriginalName in interface VariableEnhanced
        Returns:
        original Variable's name, or null.
      • lookupEnumString

        @Nullable
        public String lookupEnumString​(int val)
        Description copied from class: Variable
        Lookup the enum string for this value. Can only be called on enum types, where dataType.isEnum() is true.
        Overrides:
        lookupEnumString in class Variable
        Parameters:
        val - the integer value of this enum
        Returns:
        the String value, or null if not exist.
      • getDatasetLocation

        public String getDatasetLocation()
        Description copied from class: Variable
        The location of the dataset this belongs to. Labeling purposes only.
        Overrides:
        getDatasetLocation in class Variable
      • setCaching

        public void setCaching​(boolean caching)
        Description copied from class: Variable
        Set whether to cache or not. Implies that the entire array will be stored, once read. Normally this is set automatically based on size of data. if false, cachedData is cleared.
        Overrides:
        setCaching in class Variable
      • readArray

        public Array<?> readArray()
                           throws IOException
        Description copied from class: Variable
        Read all the data for this Variable and return a memory resident Array. The Array has the same element type and shape as the Variable.
        Overrides:
        readArray in class Variable
        Throws:
        IOException
      • readArray

        public Array<?> readArray​(Section section)
                           throws IOException,
                                  InvalidRangeException
        Description copied from class: Variable
        Read a section of the data for this Variable from the netcdf file and return a memory resident Array. The Array has the same element type as the Variable, and the requested shape. Note that this does not do rank reduction, so the returned Array has the same rank as the Variable. Use Array.reduce() for rank reduction.
        Overrides:
        readArray in class Variable
        Parameters:
        section - The section of data to read. Must be null or same rank as variable. If list is null, assume all data. Each Range corresponds to a Dimension. If the Range object is null, it means use the entire dimension.
        Throws:
        IOException
        InvalidRangeException
      • scaleMissingUnsignedProxy

        public ucar.nc2.internal.dataset.EnhanceScaleMissingUnsigned scaleMissingUnsignedProxy()
        Visible for testing, do not use directly.
      • getDescription

        public String getDescription()
        Description copied from class: Variable
        Get the description of the Variable. Default is to use CDM.LONG_NAME attribute value. If not exist, look for "description", "title", or "standard_name" attribute value (in that order).
        Specified by:
        getDescription in interface VariableEnhanced
        Overrides:
        getDescription in class Variable
        Returns:
        description, or null if not found.
      • builder

        public static VariableDS.Builder<?> builder()
        Get Builder for this class that allows subclassing.