Package ucar.nc2
Class Variable
- java.lang.Object
-
- ucar.nc2.CDMNode
-
- ucar.nc2.Variable
-
- All Implemented Interfaces:
Comparable<VariableSimpleIF>,Iterable<Attribute>,AttributeContainer,ProxyReader,VariableSimpleIF
- Direct Known Subclasses:
Structure,VariableDS
public class Variable extends CDMNode implements VariableSimpleIF, ProxyReader, AttributeContainer
A Variable is a logical container for data. It has a dataType, a set of Dimensions that define its array shape, and optionally a set of Attributes. The data is a multidimensional array of primitive types, Strings, or Structures. Data access is done through the read() methods, which return a memory resident Array.Immutable if setImmutable() was called. TODO Variable will be immutable in 6. TODO Variable will not implement AttributeContainer in 6, use Variable.attributes(). TODO Variable will not extend CDMNode in 6.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classVariable.Builder<T extends Variable.Builder<T>>A builder for Variables.protected static classVariable.Cache
-
Field Summary
Fields Modifier and Type Field Description protected AttributeContainerMutableattributesprotected Variable.Cachecacheprotected DataTypedataTypeprotected static booleandebugCachingstatic intdefaultCoordsSizeToCachestatic intdefaultSizeToCacheprotected List<Dimension>dimensionsprotected intelementSizeprotected inthashCodeprotected booleanisVariableLengthprotected NetcdfFilencfilestatic booleanpermitCachingGlobally permit or prohibit caching.protected ProxyReaderproxyReaderprotected int[]shapeprotected intsizeToCacheprotected ObjectspiObject-
Fields inherited from class ucar.nc2.CDMNode
annotations, dodsname, group, immutable, parentstruct, shortName, sort
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedVariable()Deprecated.Use Variable.builder()Variable(NetcdfFile ncfile, Group group, Structure parent, String shortName)Deprecated.Use Variable.builder()Variable(NetcdfFile ncfile, Group group, Structure parent, String shortName, DataType dtype, String dims)Deprecated.Use Variable.builder()Variable(NetcdfFile ncfile, Group group, Structure parent, String shortName, DataType dtype, List<Dimension> dims)Deprecated.Use Variable.builder()Variable(Variable from)Deprecated.Use Variable.builder()protectedVariable(Variable.Builder<?> builder, Group parentGroup)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected Array_read()protected Array_read(Section section)protected Array_readScalarData()voidaddAll(Iterable<Attribute> atts)Deprecated.Use Variable.builder()AttributeaddAttribute(Attribute att)Deprecated.Use Variable.builder()protected Variable.Builder<?>addLocalFieldsToBuilder(Variable.Builder<? extends Variable.Builder<?>> builder)AttributeContainerattributes()The attributes contained by this Variable.static Variable.Builder<?>builder()Get Builder for this class that allows subclassing.intcompareTo(VariableSimpleIF o)Sort by nameprotected Variablecopy()Deprecated.UsetoBuilder()voidcreateNewCache()Create a new data cache, use this when you dont want to share the cache.booleanequals(Object oo)Instances which have same content are equal.protected StringextraInfo()AttributefindAttribute(String name)Find the attribute by name, return null if not existdoublefindAttributeDouble(String attName, double defaultValue)Deprecated.Use attributes()AttributefindAttributeIgnoreCase(String name)Deprecated.Use attributes()intfindAttributeInteger(String attName, int defaultValue)Deprecated.Use attributes()StringfindAttributeString(String attName, String defaultValue)Find a String-valued Attribute by name (ignore case), return the String value of the Attribute.intfindDimensionIndex(String name)Find the index of the named Dimension in this Variable.List<Attribute>getAttributes()Deprecated.Use attributes()static StringgetDAPName(String name, Variable context)Deprecated.Will be moved to opendap package in 6.static StringgetDAPName(Variable v)Deprecated.Will be moved to opendap package in 6.StringgetDatasetLocation()The location of the dataset this belongs to.DataTypegetDataType()Get the data type of the Variable.StringgetDescription()Get the description of the Variable.DimensiongetDimension(int i)Get the ith dimension.com.google.common.collect.ImmutableList<Dimension>getDimensions()Get the list of dimensions used by this variable.List<Dimension>getDimensionsAll()Deprecated.use Dimensions.makeDimensionsAll(Variable);StringgetDimensionsString()Get the list of Dimension names, space delineated.intgetElementSize()Get the number of bytes for one element of this Variable.EnumTypedefgetEnumTypedef()Get the EnumTypedef, only use if getDataType.isEnum()StringgetFileTypeId()StringgetFullName()Get the full name of this Variable.StringgetNameAndDimensions()Get the display name plus the dimensions, eg 'float name(dim1, dim2)'StringgetNameAndDimensions(boolean strict)Get the display name plus the dimensions, eg 'float name(dim1, dim2)'voidgetNameAndDimensions(StringBuffer buf)Deprecated.use getNameAndDimensions(StringBuilder buf)voidgetNameAndDimensions(StringBuilder buf)Deprecated.use CDLWritervoidgetNameAndDimensions(StringBuilder buf, boolean useFullName, boolean strict)Deprecated.use CDLWritervoidgetNameAndDimensions(Formatter buf, boolean useFullName, boolean strict)Add display name plus the dimensions to the FormatterNetcdfFilegetNetcdfFile()Get the NetcdfFile that this variable is contained in.GroupgetParentGroup()Get its containing Group.GroupgetParentGroupOrRoot()Deprecated.Will go away in ver6, shouldn't be needed when builders are used.StructuregetParentStructure()Get its parent structure, or null if not in structure Not deprecated.ProxyReadergetProxyReader()Deprecated.Use Variable.builder()com.google.common.collect.ImmutableList<Range>getRanges()Get shape as a List of Range objects.intgetRank()Get the number of dimensions of the Variable, aka the rank.protected ArraygetScalarData()Deprecated.use readScalarXXXXint[]getShape()Get the shape: length of Variable in each dimension.intgetShape(int index)Get the size of the ith dimensionint[]getShapeAll()Deprecated.use Dimensions.makeDimensionsAll(Variable);SectiongetShapeAsSection()Get shape as a Section object.longgetSize()Get the total number of elements in the Variable.intgetSizeToCache()If total data size is less than SizeToCache in bytes, then cache.ObjectgetSPobject()Get immutable service provider opaque object.StringgetUnitsString()Get the Unit String for the Variable.booleanhasCachedData()Has data been read and cached.inthashCode()Override Object.hashCode() to implement equals.voidinvalidateCache()Deprecated.Use Variable.builder()booleanisCaching()Will this Variable be cached when read.booleanisCoordinateVariable()Calculate if this is a classic coordinate variable: has same name as its first dimension.booleanisEmpty()Deprecated.Use attributes()booleanisImmutable()Deprecated.Use Variable.builder()booleanisMemberOfStructure()Test for presence of parent Structure.booleanisMetadata()Is this variable metadata?.booleanisScalar()Whether this is a scalar Variable (rank == 0).booleanisUnknownLength()Deprecated.use isVariableLength()booleanisUnlimited()Can this variable's size grow?.booleanisVariableLength()Does this variable have a variable length dimension? If so, it has as one of its dimensions Dimension.VLEN.StringlookupEnumString(int val)Lookup the enum string for this value.Arrayread()Read all the data for this Variable and return a memory resident Array.Arrayread(int[] origin, int[] shape)Read a section of the data for this Variable and return a memory resident Array.Arrayread(String sectionSpec)Read data section specified by a "section selector", and return a memory resident Array.Arrayread(List<Range> ranges)Read a section of the data for this Variable from the netcdf file and return a memory resident Array.Arrayread(Section section)Read a section of the data for this Variable from the netcdf file and return a memory resident Array.bytereadScalarByte()Get the value as a byte for a scalar Variable.doublereadScalarDouble()Get the value as a double for a scalar Variable.floatreadScalarFloat()Get the value as a float for a scalar Variable.intreadScalarInt()Get the value as a int for a scalar Variable.longreadScalarLong()Get the value as a long for a scalar Variable.shortreadScalarShort()Get the value as a short for a scalar Variable.StringreadScalarString()Get the value as a String for a scalar Variable.longreadToByteChannel(Section section, WritableByteChannel wbc)Deprecated.do not uselongreadToStream(Section section, OutputStream out)Read variable data to a stream.ArrayreallyRead(Variable client, Section section, CancelTask cancelTask)public by accident, do not call directly.ArrayreallyRead(Variable client, CancelTask cancelTask)public by accident, do not call directly.Variablereduce(List<Dimension> dims)Create a new Variable that is a logical view of this Variable, by eliminating the specified dimension(s) of length 1.booleanremove(Attribute a)Deprecated.Use Variable.builder()booleanremoveAttribute(String attName)Deprecated.Use Variable.builder()booleanremoveAttributeIgnoreCase(String attName)Deprecated.Use Variable.builder()voidresetDimensions()Deprecated.Use Variable.builder()voidresetShape()Deprecated.Use Variable.builder()Variablesection(List<Range> ranges)Create a new Variable that is a logical subsection of this Variable.Variablesection(Section subsection)Create a new Variable that is a logical subsection of this Variable.voidsetCachedData(Array cacheData)Deprecated.Use Variable.builder()voidsetCachedData(Array cacheData, boolean isMetadata)Deprecated.Use Variable.builder()voidsetCaching(boolean caching)Deprecated.Use Variable.builder()voidsetDataType(DataType dataType)Deprecated.Use Variable.builder()voidsetDimension(int idx, Dimension dim)Deprecated.Use Variable.builder()voidsetDimensions(String dimString)Deprecated.Use Variable.builder()voidsetDimensions(List<Dimension> dims)Deprecated.Use Variable.builder()voidsetDimensionsAnonymous(int[] shape)Deprecated.Use Variable.builder()voidsetElementSize(int elementSize)Deprecated.Use Variable.builder()voidsetEnumTypedef(EnumTypedef enumTypedef)Deprecated.Use Variable.builder()VariablesetImmutable()Deprecated.Use Variable.builder()voidsetIsScalar()Deprecated.Use Variable.builder()StringsetName(String shortName)Deprecated.Use Variable.builder()voidsetParentGroup(Group group)Deprecated.Use Variable.builder()voidsetProxyReader(ProxyReader proxyReader)Deprecated.Use Variable.builder()voidsetSizeToCache(int sizeToCache)Deprecated.Use Variable.builder()voidsetSPobject(Object spiObject)Deprecated.Do not use.voidsetValues(int npts, double start, double incr)Deprecated.Use Variable.builder()voidsetValues(List<String> values)Deprecated.Use Variable.builder()Variableslice(int dim, int value)Create a new Variable that is a logical slice of this Variable, by fixing the specified dimension at the specified index value.Variable.Builder<?>toBuilder()Turn into a mutable Builder.StringtoString()StringtoStringDebug()String representation of Variable and its attributes.StringwriteCDL(boolean useFullName, boolean strict)Deprecated.use CDLWriterprotected voidwriteCDL(Formatter buf, Indent indent, boolean useFullName, boolean strict)Deprecated.use CDLWriter-
Methods inherited from class ucar.nc2.CDMNode
annotate, annotation, getDODSName, getFullNameEscaped, getGroup, getImmutable, getName, getShortName, getSort, localhash, setDODSName, setParentStructure, setShortName, setSort, unwrap
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ucar.nc2.AttributeContainer
findAttValueIgnoreCase, getName, hasAttribute, hasAttributeIgnoreCase, iterator
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface ucar.nc2.VariableSimpleIF
getName, getShortName
-
-
-
-
Field Detail
-
permitCaching
public static boolean permitCaching
Globally permit or prohibit caching. For use during testing and debugging.A
truevalue for this field does not indicate whether a Variableis caching, only that it's permitted to cache.
-
defaultSizeToCache
public static int defaultSizeToCache
-
defaultCoordsSizeToCache
public static int defaultCoordsSizeToCache
-
debugCaching
protected static boolean debugCaching
-
hashCode
protected int hashCode
-
ncfile
protected NetcdfFile ncfile
-
dataType
protected DataType dataType
-
attributes
protected AttributeContainerMutable attributes
-
proxyReader
protected ProxyReader proxyReader
-
spiObject
protected Object spiObject
-
shape
protected int[] shape
-
isVariableLength
protected boolean isVariableLength
-
elementSize
protected int elementSize
-
cache
protected Variable.Cache cache
-
sizeToCache
protected int sizeToCache
-
-
Constructor Detail
-
Variable
@Deprecated protected Variable()
Deprecated.Use Variable.builder()
-
Variable
@Deprecated public Variable(NetcdfFile ncfile, Group group, Structure parent, String shortName)
Deprecated.Use Variable.builder()Create a Variable. Also must call setDataType() and setDimensions()- Parameters:
ncfile- the containing NetcdfFile.group- the containing group; if null, use rootGroupparent- parent Structure, may be nullshortName- variable shortName, must be unique within the Group
-
Variable
@Deprecated public Variable(NetcdfFile ncfile, Group group, Structure parent, String shortName, DataType dtype, String dims)
Deprecated.Use Variable.builder()Create a Variable. Also must call setDataType() and setDimensions()- Parameters:
ncfile- the containing NetcdfFile.group- the containing group; if null, use rootGroupparent- parent Structure, may be nullshortName- variable shortName, must be unique within the Groupdtype- the Variable's DataTypedims- space delimited list of dimension names. may be null or "" for scalars.
-
Variable
@Deprecated public Variable(NetcdfFile ncfile, Group group, Structure parent, String shortName, DataType dtype, List<Dimension> dims)
Deprecated.Use Variable.builder()Create a Variable. Also must call setDataType() and setDimensions()- Parameters:
ncfile- the containing NetcdfFile.group- the containing group; if null, use rootGroupparent- parent Structure, may be nullshortName- variable shortName, must be unique within the Groupdtype- the Variable's DataTypedims- dimension names.
-
Variable
@Deprecated public Variable(Variable from)
Deprecated.Use Variable.builder()Copy constructor. The returned Variable is mutable. It shares the cache object and the iosp Object, attributes and dimensions with the original. Does not share the proxyReader. Use for section, slice, "logical views" of original variable.- Parameters:
from- copy from this Variable.
-
Variable
protected Variable(Variable.Builder<?> builder, Group parentGroup)
-
-
Method Detail
-
getDAPName
@Deprecated public static String getDAPName(String name, Variable context)
Deprecated.Will be moved to opendap package in 6.
-
getDAPName
@Deprecated public static String getDAPName(Variable v)
Deprecated.Will be moved to opendap package in 6.
-
getDataType
public DataType getDataType()
Get the data type of the Variable.- Specified by:
getDataTypein interfaceVariableSimpleIF- Returns:
- Variable's data type
-
getShape
public int[] getShape()
Get the shape: length of Variable in each dimension. A scalar (rank 0) will have an int[0] shape.- Specified by:
getShapein interfaceVariableSimpleIF- Returns:
- int array whose length is the rank of this Variable and whose values equal the length of that Dimension.
-
getShape
public int getShape(int index)
Get the size of the ith dimension- Parameters:
index- which dimension- Returns:
- size of the ith dimension
-
getSize
public long getSize()
Get the total number of elements in the Variable. If this is an unlimited Variable, will use the current number of elements. If this is a Sequence, will return 1. If variable length, will skip vlen dimensions- Returns:
- total number of elements in the Variable.
-
getElementSize
public int getElementSize()
Get the number of bytes for one element of this Variable. For Variables of primitive type, this is equal to getDataType().getSize(). Variables of String type don't know their size, so what they return is undefined. Variables of Structure type return the total number of bytes for all the members of one Structure, plus possibly some extra padding, depending on the underlying format. Variables of Sequence type return the number of bytes of one element.- Returns:
- total number of bytes for the Variable
-
getRank
public int getRank()
Get the number of dimensions of the Variable, aka the rank.- Specified by:
getRankin interfaceVariableSimpleIF- Returns:
- Variable rank
-
getParentGroupOrRoot
@Deprecated public Group getParentGroupOrRoot()
Deprecated.Will go away in ver6, shouldn't be needed when builders are used.Get the parent group, or if null, the root group.
-
isMetadata
public boolean isMetadata()
Is this variable metadata?. True if its values need to be included explicitly in NcML output.- Returns:
- true if Variable values need to be included in NcML
-
isScalar
public boolean isScalar()
Whether this is a scalar Variable (rank == 0).- Returns:
- true if Variable has rank 0
-
isVariableLength
public boolean isVariableLength()
Does this variable have a variable length dimension? If so, it has as one of its dimensions Dimension.VLEN.- Returns:
- true if Variable has a variable length dimension?
-
isUnlimited
public boolean isUnlimited()
Can this variable's size grow?. This is equivalent to saying at least one of its dimensions is unlimited.- Returns:
- boolean true iff this variable can grow
-
getDimensions
public com.google.common.collect.ImmutableList<Dimension> getDimensions()
Get the list of dimensions used by this variable. The most slowly varying (leftmost for Java and C programmers) dimension is first. For scalar variables, the list is empty.- Specified by:
getDimensionsin interfaceVariableSimpleIF- Returns:
- List
, will be ImmutableList in ver 6.
-
getDimension
public Dimension getDimension(int i)
Get the ith dimension.- Parameters:
i- index of the dimension.- Returns:
- requested Dimension, or null if i is out of bounds.
-
getDimensionsString
public String getDimensionsString()
Get the list of Dimension names, space delineated.- Returns:
- Dimension names, space delineated
-
findDimensionIndex
public int findDimensionIndex(String name)
Find the index of the named Dimension in this Variable.- Parameters:
name- the name of the dimension- Returns:
- the index of the named Dimension, or -1 if not found.
-
getDescription
public String getDescription()
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:
getDescriptionin interfaceVariableSimpleIF- Returns:
- description, or null if not found.
-
getUnitsString
public String getUnitsString()
Get the Unit String for the Variable. Looks for the CDM.UNITS attribute value- Specified by:
getUnitsStringin interfaceVariableSimpleIF- Returns:
- unit string, or null if not found.
-
getRanges
public com.google.common.collect.ImmutableList<Range> getRanges()
Get shape as a List of Range objects. The List is immutable.- Returns:
- List of Ranges, one for each Dimension.
-
getShapeAsSection
public Section getShapeAsSection()
Get shape as a Section object.- Returns:
- Section containing List
, one for each Dimension.
-
getProxyReader
@Deprecated public ProxyReader getProxyReader()
Deprecated.Use Variable.builder()
-
setProxyReader
@Deprecated public void setProxyReader(ProxyReader proxyReader)
Deprecated.Use Variable.builder()
-
section
public Variable section(List<Range> ranges) throws InvalidRangeException
Create a new Variable that is a logical subsection of this Variable. No data is read until a read method is called on it.- Parameters:
ranges- List of type ucar.ma2.Range, with size equal to getRank(). Each Range corresponds to a Dimension, and specifies the section of data to read in that Dimension. A Range object may be null, which means use the entire dimension.- Returns:
- a new Variable which is a logical section of this Variable.
- Throws:
InvalidRangeException- if shape and range list don't match
-
section
public Variable section(Section subsection) throws InvalidRangeException
Create a new Variable that is a logical subsection of this Variable. No data is read until a read method is called on it.- Parameters:
subsection- Section of this variable. Each Range in the section corresponds to a Dimension, and specifies the section of data to read in that Dimension. A Range object may be null, which means use the entire dimension.- Returns:
- a new Variable which is a logical section of this Variable.
- Throws:
InvalidRangeException- if section not compatible with shape
-
slice
public Variable slice(int dim, int value) throws InvalidRangeException
Create a new Variable that is a logical slice of this Variable, by fixing the specified dimension at the specified index value. This reduces rank by 1. No data is read until a read method is called on it.- Parameters:
dim- which dimension to fixvalue- at what index value- Returns:
- a new Variable which is a logical slice of this Variable.
- Throws:
InvalidRangeException- if dimension or value is illegal
-
reduce
public Variable reduce(List<Dimension> dims)
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.- Parameters:
dims- list of dimensions of length 1 to reduce- Returns:
- a new Variable which is a logical slice of this Variable.
-
copy
@Deprecated protected Variable copy()
Deprecated.UsetoBuilder()
-
getNetcdfFile
@Nullable public NetcdfFile getNetcdfFile()
Get the NetcdfFile that this variable is contained in. May be null.
-
getFileTypeId
@Nullable public String getFileTypeId()
-
lookupEnumString
@Nullable public String lookupEnumString(int val)
Lookup the enum string for this value. Can only be called on enum types, where dataType.isEnum() is true.- Parameters:
val- the integer value of this enum- Returns:
- the String value
-
setEnumTypedef
@Deprecated public void setEnumTypedef(EnumTypedef enumTypedef)
Deprecated.Use Variable.builder()Public by accident.- Parameters:
enumTypedef- set the EnumTypedef, only use if getDataType.isEnum()
-
getEnumTypedef
public EnumTypedef getEnumTypedef()
Get the EnumTypedef, only use if getDataType.isEnum()- Returns:
- enumTypedef or null if !getDataType.isEnum()
-
read
public Array read(int[] origin, int[] shape) throws IOException, InvalidRangeException
Read a section of the data for this Variable 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.assert(origin[ii] + shape[ii]*stride[ii] <= Variable.shape[ii]);- Parameters:
origin- int array specifying the starting index. If null, assume all zeroes.shape- int array specifying the extents in each dimension. This becomes the shape of the returned Array.- Returns:
- the requested data in a memory-resident Array
- Throws:
IOExceptionInvalidRangeException
-
read
public Array read(String sectionSpec) throws IOException, InvalidRangeException
Read data section specified by a "section selector", and return a memory resident Array. Uses Fortran 90 array section syntax.- Parameters:
sectionSpec- specification string, eg "1:2,10,:,1:100:10". May optionally have ().- Returns:
- the requested data in a memory-resident Array
- Throws:
IOExceptionInvalidRangeException- See Also:
for sectionSpec syntax
-
read
public Array read(List<Range> ranges) throws IOException, InvalidRangeException
Read a section of the data for this Variable from the netcdf file and return a memory resident Array.- Parameters:
ranges- list of Range specifying the section of data to read.- Returns:
- the requested data in a memory-resident Array
- Throws:
IOException- if errorInvalidRangeException- if ranges is invalid- See Also:
read(Section)
-
read
public Array read(Section section) throws IOException, InvalidRangeException
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. If the Variable is a member of an array of Structures, this returns only the variable's data in the first Structure, so that the Array shape is the same as the Variable. To read the data in all structures, use ncfile.readSectionSpec(). Note this only allows you to specify a subset of this variable. If the variable is nested in an array of structures and you want to subset that, use NetcdfFile.read(String sectionSpec, boolean flatten);- Parameters:
section- list of Range specifying 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.- Returns:
- the requested data in a memory-resident Array
- Throws:
IOException- if errorInvalidRangeException- if section is invalid
-
read
public Array read() throws IOException
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. If the Variable is a member of an array of Structures, this returns only the variable's data in the first Structure, so that the Array shape is the same as the Variable. To read the data in all structures, use ncfile.readSection().- Returns:
- the requested data in a memory-resident Array.
- Throws:
IOException
-
readScalarByte
public byte readScalarByte() throws IOExceptionGet the value as a byte for a scalar Variable. May also be one-dimensional of length 1.- Throws:
IOException- if theres an IO ErrorUnsupportedOperationException- if not a scalar Variable or one-dimensional of length 1.ForbiddenConversionException- if data type not convertible to byte
-
readScalarShort
public short readScalarShort() throws IOExceptionGet the value as a short for a scalar Variable. May also be one-dimensional of length 1.- Throws:
IOException- if theres an IO ErrorUnsupportedOperationException- if not a scalar Variable or one-dimensional of length 1.ForbiddenConversionException- if data type not convertible to short
-
readScalarInt
public int readScalarInt() throws IOExceptionGet the value as a int for a scalar Variable. May also be one-dimensional of length 1.- Throws:
IOException- if theres an IO ErrorUnsupportedOperationException- if not a scalar Variable or one-dimensional of length 1.ForbiddenConversionException- if data type not convertible to int
-
readScalarLong
public long readScalarLong() throws IOExceptionGet the value as a long for a scalar Variable. May also be one-dimensional of length 1.- Throws:
IOException- if theres an IO ErrorUnsupportedOperationException- if not a scalar VariableForbiddenConversionException- if data type not convertible to long
-
readScalarFloat
public float readScalarFloat() throws IOExceptionGet the value as a float for a scalar Variable. May also be one-dimensional of length 1.- Throws:
IOException- if theres an IO ErrorUnsupportedOperationException- if not a scalar Variable or one-dimensional of length 1.ForbiddenConversionException- if data type not convertible to float
-
readScalarDouble
public double readScalarDouble() throws IOExceptionGet the value as a double for a scalar Variable. May also be one-dimensional of length 1.- Throws:
IOException- if theres an IO ErrorUnsupportedOperationException- if not a scalar Variable or one-dimensional of length 1.ForbiddenConversionException- if data type not convertible to double
-
readScalarString
public String readScalarString() throws IOException
Get the value as a String for a scalar Variable. May also be one-dimensional of length 1. May also be one-dimensional of type CHAR, which wil be turned into a scalar String.- Throws:
IOException- if theres an IO ErrorUnsupportedOperationException- if not a scalar or one-dimensional.ClassCastException- if data type not DataType.STRING or DataType.CHAR.
-
getScalarData
@Deprecated protected Array getScalarData() throws IOException
Deprecated.use readScalarXXXX- Throws:
IOException
-
_read
protected Array _read() throws IOException
- Throws:
IOException
-
_read
protected Array _read(Section section) throws IOException, InvalidRangeException
- Throws:
IOExceptionInvalidRangeException
-
_readScalarData
protected Array _readScalarData() throws IOException
- Throws:
IOException
-
reallyRead
public Array reallyRead(Variable client, CancelTask cancelTask) throws IOException
public by accident, do not call directly.- Specified by:
reallyReadin interfaceProxyReader- Parameters:
client- the client VariablecancelTask- user may cancel- Returns:
- Array
- Throws:
IOException- on error
-
reallyRead
public Array reallyRead(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException
public by accident, do not call directly.- Specified by:
reallyReadin interfaceProxyReader- Parameters:
client- the client Variablesection- the section of data to read.cancelTask- user may cancel- Returns:
- Array
- Throws:
IOException- on errorInvalidRangeException- if section has incorrect rank or illegal shape.
-
readToByteChannel
@Deprecated public long readToByteChannel(Section section, WritableByteChannel wbc) throws IOException, InvalidRangeException
Deprecated.do not use- Throws:
IOExceptionInvalidRangeException
-
readToStream
public long readToStream(Section section, OutputStream out) throws IOException, InvalidRangeException
Read variable data to a stream. Support for NcStreamWriter.- Throws:
IOExceptionInvalidRangeException
-
getParentGroup
public Group getParentGroup()
Get its containing Group. Not deprecated. LOOK if you relied on Group being set during construction, use getParentGroupOrRoot().- Overrides:
getParentGroupin classCDMNode- Returns:
- parent Group
-
getParentStructure
@Nullable public Structure getParentStructure()
Get its parent structure, or null if not in structure Not deprecated.- Overrides:
getParentStructurein classCDMNode- Returns:
- parent structure
-
isMemberOfStructure
public boolean isMemberOfStructure()
Test for presence of parent Structure. Not deprecated.- Overrides:
isMemberOfStructurein classCDMNode- Returns:
- true iff struct != null
-
getFullName
public String getFullName()
Get the full name of this Variable. Certain characters are backslash escaped (see NetcdfFiles.getFullName(Variable)) Not deprecated.- Specified by:
getFullNamein interfaceVariableSimpleIF- Overrides:
getFullNamein classCDMNode- Returns:
- full name with backslash escapes
-
getNameAndDimensions
public String getNameAndDimensions()
Get the display name plus the dimensions, eg 'float name(dim1, dim2)'- Returns:
- display name plus the dimensions
-
getNameAndDimensions
public String getNameAndDimensions(boolean strict)
Get the display name plus the dimensions, eg 'float name(dim1, dim2)'- Parameters:
strict- strictly comply with ncgen syntax, with name escaping. otherwise, get extra info, no escaping- Returns:
- display name plus the dimensions
-
getNameAndDimensions
@Deprecated public void getNameAndDimensions(StringBuilder buf)
Deprecated.use CDLWriterGet the display name plus the dimensions, eg 'name(dim1, dim2)'- Parameters:
buf- add info to this StringBuilder
-
getNameAndDimensions
@Deprecated public void getNameAndDimensions(StringBuffer buf)
Deprecated.use getNameAndDimensions(StringBuilder buf)Get the display name plus the dimensions, eg 'name(dim1, dim2)'- Parameters:
buf- add info to this StringBuffer
-
getNameAndDimensions
@Deprecated public void getNameAndDimensions(StringBuilder buf, boolean useFullName, boolean strict)
Deprecated.use CDLWriterAdd display name plus the dimensions to the StringBuffer- Parameters:
buf- add info to thisuseFullName- use full name else short name. strict = true implies short namestrict- strictly comply with ncgen syntax, with name escaping. otherwise, get extra info, no escaping
-
getNameAndDimensions
public void getNameAndDimensions(Formatter buf, boolean useFullName, boolean strict)
Add display name plus the dimensions to the Formatter- Parameters:
buf- add info to thisuseFullName- use full name else short name. strict = true implies short namestrict- strictly comply with ncgen syntax, with name escaping. otherwise, get extra info, no escaping
-
writeCDL
@Deprecated public String writeCDL(boolean useFullName, boolean strict)
Deprecated.use CDLWriterCDL representation of a Variable.- Parameters:
useFullName- use full name, else use short namestrict- strictly comply with ncgen syntax- Returns:
- CDL representation of the Variable.
-
writeCDL
@Deprecated protected void writeCDL(Formatter buf, Indent indent, boolean useFullName, boolean strict)
Deprecated.use CDLWriter
-
toStringDebug
public String toStringDebug()
String representation of Variable and its attributes.
-
extraInfo
protected String extraInfo()
-
getDatasetLocation
public String getDatasetLocation()
The location of the dataset this belongs to. Labeling purposes only.
-
equals
public boolean equals(Object oo)
Instances which have same content are equal.
-
hashCode
public int hashCode()
Override Object.hashCode() to implement equals.
-
compareTo
public int compareTo(VariableSimpleIF o)
Sort by name- Specified by:
compareToin interfaceComparable<VariableSimpleIF>
-
setDataType
@Deprecated public void setDataType(DataType dataType)
Deprecated.Use Variable.builder()Set the data type- Parameters:
dataType- set to this value
-
setName
@Deprecated public String setName(String shortName)
Deprecated.Use Variable.builder()Set the short name, converting to valid CDM object name if needed.- Parameters:
shortName- set to this value- Returns:
- valid CDM object name
-
setParentGroup
@Deprecated public void setParentGroup(Group group)
Deprecated.Use Variable.builder()Set the parent group.- Overrides:
setParentGroupin classCDMNode- Parameters:
group- set to this value
-
setElementSize
@Deprecated public void setElementSize(int elementSize)
Deprecated.Use Variable.builder()Set the element size. Usually elementSize is determined by the dataType, use this only for exceptional cases.- Parameters:
elementSize- set to this value
-
attributes
public AttributeContainer attributes()
The attributes contained by this Variable.- Specified by:
attributesin interfaceVariableSimpleIF
-
findAttribute
@Nullable public Attribute findAttribute(String name)
Find the attribute by name, return null if not exist- Specified by:
findAttributein interfaceAttributeContainer
-
findAttributeString
public String findAttributeString(String attName, String defaultValue)
Find a String-valued Attribute by name (ignore case), return the String value of the Attribute.- Specified by:
findAttributeStringin interfaceAttributeContainer- Returns:
- the attribute value, or defaultValue if not found
-
isEmpty
public boolean isEmpty()
Deprecated.Use attributes()Description copied from interface:AttributeContainerTrue is there are no attributes in the container.- Specified by:
isEmptyin interfaceAttributeContainer
-
getAttributes
@Deprecated public List<Attribute> getAttributes()
Deprecated.Use attributes()Description copied from interface:VariableSimpleIFAttributes for the variable.- Specified by:
getAttributesin interfaceAttributeContainer- Specified by:
getAttributesin interfaceVariableSimpleIF- Returns:
- List of type ucar.nc2.Attribute
-
findAttributeIgnoreCase
@Deprecated public Attribute findAttributeIgnoreCase(String name)
Deprecated.Use attributes()Description copied from interface:VariableSimpleIFfind the attribute for the variable with the given name, ignoring case.- Specified by:
findAttributeIgnoreCasein interfaceAttributeContainer- Specified by:
findAttributeIgnoreCasein interfaceVariableSimpleIF- Parameters:
name- attribute name- Returns:
- the attribute for the variable with the given name, or null if not found.
-
findAttributeDouble
@Deprecated public double findAttributeDouble(String attName, double defaultValue)
Deprecated.Use attributes()Description copied from interface:AttributeContainerFind a Numeric Attribute by name (ignore case), return the double value of the Attribute.- Specified by:
findAttributeDoublein interfaceAttributeContainer- Returns:
- the attribute value, or defaultValue if not found
-
findAttributeInteger
@Deprecated public int findAttributeInteger(String attName, int defaultValue)
Deprecated.Use attributes()Description copied from interface:AttributeContainerFind a Numeric Attribute by name (ignore case), return the integer value of the Attribute.- Specified by:
findAttributeIntegerin interfaceAttributeContainer- Returns:
- the attribute value, or defaultValue if not found
-
addAttribute
@Deprecated public Attribute addAttribute(Attribute att)
Deprecated.Use Variable.builder()Description copied from interface:AttributeContainerAdd new or replace old if has same name- Specified by:
addAttributein interfaceAttributeContainer- Parameters:
att- add this Attribute- Returns:
- the added attribute
-
addAll
@Deprecated public void addAll(Iterable<Attribute> atts)
Deprecated.Use Variable.builder()Description copied from interface:AttributeContainerAdd all; replace old if has same name- Specified by:
addAllin interfaceAttributeContainer
-
remove
@Deprecated public boolean remove(Attribute a)
Deprecated.Use Variable.builder()Description copied from interface:AttributeContainerRemove an Attribute : uses the attribute hashCode to find it.- Specified by:
removein interfaceAttributeContainer- Parameters:
a- remove this attribute- Returns:
- true if was found and removed
-
removeAttribute
@Deprecated public boolean removeAttribute(String attName)
Deprecated.Use Variable.builder()Description copied from interface:AttributeContainerRemove an Attribute by name.- Specified by:
removeAttributein interfaceAttributeContainer- Parameters:
attName- if exists, remove this attribute- Returns:
- true if was found and removed
-
removeAttributeIgnoreCase
@Deprecated public boolean removeAttributeIgnoreCase(String attName)
Deprecated.Use Variable.builder()Description copied from interface:AttributeContainerRemove an Attribute by name, ignoring case- Specified by:
removeAttributeIgnoreCasein interfaceAttributeContainer- Parameters:
attName- if exists, remove this attribute- Returns:
- true if was found and removed
-
setDimensions
@Deprecated public void setDimensions(List<Dimension> dims)
Deprecated.Use Variable.builder()Set the shape with a list of Dimensions. The Dimensions may be shared or not. Dimensions are in order, slowest varying first. Send a null for a scalar. Technically you can use Dimensions from any group; pragmatically you should only use Dimensions contained in the Variable's parent groups.- Parameters:
dims- list of type ucar.nc2.Dimension
-
resetShape
@Deprecated public void resetShape()
Deprecated.Use Variable.builder()Use when dimensions have changed, to recalculate the shape.
-
setDimensions
@Deprecated public void setDimensions(String dimString)
Deprecated.Use Variable.builder()Set the dimensions using the dimensions names. The dimension is searched for recursively in the parent groups.- Parameters:
dimString- : whitespace separated list of dimension names, or '*' for Dimension.UNKNOWN, or number for anon dimension. null or empty String is a scalar.
-
resetDimensions
@Deprecated public void resetDimensions()
Deprecated.Use Variable.builder()Reset the dimension array. Anonymous dimensions are left alone. Shared dimensions are searched for recursively in the parent groups.
-
setDimensionsAnonymous
@Deprecated public void setDimensionsAnonymous(int[] shape) throws InvalidRangeException
Deprecated.Use Variable.builder()Set the dimensions using all anonymous (unshared) dimensions- Parameters:
shape- defines the dimension lengths. must be > 0, or -1 for VLEN- Throws:
InvalidRangeException- if any shape < 1
-
setIsScalar
@Deprecated public void setIsScalar()
Deprecated.Use Variable.builder()Set this Variable to be a scalar
-
setDimension
@Deprecated public void setDimension(int idx, Dimension dim)
Deprecated.Use Variable.builder()Replace a dimension with an equivalent one.- Parameters:
idx- index into dimension arraydim- to set
-
setImmutable
@Deprecated public Variable setImmutable()
Deprecated.Use Variable.builder()Make this immutable.- Overrides:
setImmutablein classCDMNode- Returns:
- this
-
isImmutable
@Deprecated public boolean isImmutable()
Deprecated.Use Variable.builder()Is this Variable immutable- Returns:
- if immutable
-
getSPobject
public Object getSPobject()
Get immutable service provider opaque object.
-
setSPobject
@Deprecated public void setSPobject(Object spiObject)
Deprecated.Do not use.
-
getSizeToCache
public int getSizeToCache()
If total data size is less than SizeToCache in bytes, then cache.- Returns:
- size at which caching happens
-
setSizeToCache
@Deprecated public void setSizeToCache(int sizeToCache)
Deprecated.Use Variable.builder()Set the sizeToCache. If not set, use defaults- Parameters:
sizeToCache- size at which caching happens. < 0 means use defaults
-
setCaching
@Deprecated public void setCaching(boolean caching)
Deprecated.Use Variable.builder()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.- Parameters:
caching- set if caching.
-
isCaching
public boolean isCaching()
Will this Variable be cached when read. Set externally, or calculated based on total size < sizeToCache.This will always return
falseifcaching isn't permitted.- Returns:
- true is caching
-
invalidateCache
@Deprecated public void invalidateCache()
Deprecated.Use Variable.builder()Note that standalone Ncml caches data values set in the Ncml. So one cannot invalidate those caches.
-
setCachedData
@Deprecated public void setCachedData(Array cacheData)
Deprecated.Use Variable.builder()
-
setCachedData
@Deprecated public void setCachedData(Array cacheData, boolean isMetadata)
Deprecated.Use Variable.builder()Set the data cache- Parameters:
cacheData- cache this ArrayisMetadata- : synthesized data, set true if must be saved in NcML output (ie data not actually in the file).
-
createNewCache
public void createNewCache()
Create a new data cache, use this when you dont want to share the cache.
-
hasCachedData
public boolean hasCachedData()
Has data been read and cached. Use only on a Variable, not a subclass.- Returns:
- true if data is read and cached
-
setValues
@Deprecated public void setValues(int npts, double start, double incr)
Deprecated.Use Variable.builder()Generate the list of values from a starting value and an increment. Will reshape to variable if needed.- Parameters:
npts- number of values, must = v.getSize()start- starting valueincr- increment
-
setValues
@Deprecated public void setValues(List<String> values) throws IllegalArgumentException
Deprecated.Use Variable.builder()Set the data values from a list of Strings.- Parameters:
values- list of Strings- Throws:
IllegalArgumentException- if values array not correct size, or values wont parse to the correct type
-
getDimensionsAll
@Deprecated public List<Dimension> getDimensionsAll()
Deprecated.use Dimensions.makeDimensionsAll(Variable);Get list of Dimensions, including parents if any.- Returns:
- array of Dimension, rank of v plus all parents.
-
getShapeAll
@Deprecated public int[] getShapeAll()
Deprecated.use Dimensions.makeDimensionsAll(Variable);
-
isCoordinateVariable
public boolean isCoordinateVariable()
Calculate if this is a classic coordinate variable: has same name as its first dimension. If type char, must be 2D, else must be 1D.- Returns:
- true if a coordinate variable.
-
toBuilder
public Variable.Builder<?> toBuilder()
Turn into a mutable Builder. Can use toBuilder().build() to copy.
-
addLocalFieldsToBuilder
protected Variable.Builder<?> addLocalFieldsToBuilder(Variable.Builder<? extends Variable.Builder<?>> builder)
-
builder
public static Variable.Builder<?> builder()
Get Builder for this class that allows subclassing.- See Also:
- "https://community.oracle.com/blogs/emcmanus/2010/10/24/using-builder-pattern-subclasses"
-
isUnknownLength
public boolean isUnknownLength()
Deprecated.use isVariableLength()- Returns:
- isVariableLength()
-
-