@Immutable public class Variable extends Object implements VariableSimpleIF, ProxyReader
| Modifier and Type | Class and Description |
|---|---|
static class |
Variable.Builder<T extends Variable.Builder<T>> |
protected static class |
Variable.Cache |
| Modifier and Type | Field and Description |
|---|---|
protected AttributeContainer |
attributes |
protected Variable.Cache |
cache |
protected ArrayType |
dataType |
protected com.google.common.collect.ImmutableList<Dimension> |
dimensions |
protected int |
elementSize |
protected int |
hashCode |
protected boolean |
isVariableLength |
protected NetcdfFile |
ncfile |
static boolean |
permitCaching
Globally permit or prohibit caching.
|
protected ProxyReader |
proxyReader |
protected int[] |
shape |
protected Object |
spiObject |
| Modifier | Constructor and Description |
|---|---|
protected |
Variable(Variable.Builder<?> builder,
Group parentGroup) |
| Modifier and Type | Method and Description |
|---|---|
protected Array |
_read() |
protected Array |
_read(Section section) |
protected Array |
_readScalarData()
Deprecated.
do not use
|
protected Variable.Builder<?> |
addLocalFieldsToBuilder(Variable.Builder<? extends Variable.Builder<?>> builder) |
AttributeContainer |
attributes()
The attributes contained by this Variable.
|
static Variable.Builder<?> |
builder()
Get Builder for this class that allows subclassing.
|
int |
compareTo(VariableSimpleIF o)
Sort by name
|
boolean |
equals(Object oo) |
protected String |
extraInfo() |
Attribute |
findAttribute(String name)
Find the attribute by name, return null if not exist
|
String |
findAttributeString(String attName,
String defaultValue)
Find a String-valued Attribute by name (ignore case), return the String value of the Attribute.
|
int |
findDimensionIndex(String name)
Find the index of the named Dimension in this Variable.
|
ArrayType |
getArrayType()
Get the data type of the Variable.
|
String |
getDatasetLocation()
The location of the dataset this belongs to.
|
DataType |
getDataType()
Deprecated.
use getArrayType()
|
String |
getDescription()
Get the description of the Variable.
|
Dimension |
getDimension(int i)
Get the ith dimension.
|
com.google.common.collect.ImmutableList<Dimension> |
getDimensions()
Get the list of dimensions used by this variable.
|
com.google.common.collect.ImmutableSet<Dimension> |
getDimensionSet()
Get the variable's Dimensions as a Set.
|
String |
getDimensionsString()
Get the list of Dimension names, space delineated.
|
int |
getElementSize()
Get the number of bytes for one element of this Variable.
|
EnumTypedef |
getEnumTypedef()
Get the EnumTypedef, only use if getDataType.isEnum()
|
String |
getFileTypeId()
Get the file type id for the underlying data source.
|
String |
getFullName()
Get the full name of this Variable.
|
String |
getNameAndDimensions()
Get the display name plus the dimensions, eg 'float name(dim1, dim2)'
|
void |
getNameAndDimensions(Formatter buf,
boolean useFullName,
boolean strict)
Add display name plus the dimensions to the Formatter
|
NetcdfFile |
getNetcdfFile()
Get the NetcdfFile that this variable is contained in.
|
Group |
getParentGroup()
Get its containing Group, never null
|
Structure |
getParentStructure()
Get its parent structure, or null if not in structure
|
com.google.common.collect.ImmutableList<Range> |
getRanges()
Get shape as an List of Range objects.
|
int |
getRank()
Get the number of dimensions of the Variable, aka the rank.
|
Section |
getSection()
Get shape as a Section object.
|
int[] |
getShape()
Get the shape: length of Variable in each dimension.
|
int |
getShape(int index)
Get the size of the ith dimension
|
Section |
getShapeAsSection()
Deprecated.
use getSection()
|
String |
getShortName()
The short name of the variable
|
long |
getSize()
Get the total number of elements in the Variable.
|
int |
getSizeToCache()
If total data size is less than SizeToCache in bytes, then cache.
|
Object |
getSPobject()
Get immutable service provider opaque object.
|
String |
getUnitsString()
Get the Unit String for the Variable.
|
boolean |
hasCachedData()
If this has cached data, or source data.
|
int |
hashCode() |
void |
invalidateCache()
Remove any cached values (but not srcData)
|
boolean |
isCaching()
Will this Variable be cached when read.
|
boolean |
isCoordinateVariable()
Calculate if this is a classic coordinate variable: has same name as its first dimension.
|
boolean |
isMemberOfStructure()
Is this a Structure Member?
|
boolean |
isMetadata()
Is this variable metadata?.
|
boolean |
isScalar()
Whether this is a scalar Variable (rank == 0).
|
boolean |
isUnlimited()
Can this variable's size grow?.
|
boolean |
isVariableLength()
Does this variable have a variable length dimension?
If so, it has as one of its dimensions Dimension.VLEN.
|
String |
lookupEnumString(int val)
Lookup the enum string for this value.
|
Array<?> |
proxyReadArray(Variable client,
CancelTask cancelTask)
public by accident, do not call directly.
|
Array<?> |
proxyReadArray(Variable client,
Section section,
CancelTask cancelTask)
public by accident, do not call directly.
|
Array |
read()
Deprecated.
use readArray()
|
Array |
read(int[] origin,
int[] shape)
Deprecated.
use readArray(Section)
|
Array |
read(List<Range> ranges)
Deprecated.
use readArray(new Section(ranges))
|
Array |
read(Section section)
Deprecated.
use readArray(Section)
|
Array |
read(String sectionSpec)
Deprecated.
use readArray(new Section(sectionSpec))
|
Array<?> |
readArray()
Read all the data for this Variable and return a memory resident Array.
|
Array<?> |
readArray(Section section)
Read a section of the data for this Variable from the netcdf file and return a memory resident Array.
|
byte |
readScalarByte()
Deprecated.
use (byte) readArray().getScalar();
|
double |
readScalarDouble()
Deprecated.
use (double) readArray().getScalar();
|
float |
readScalarFloat()
Deprecated.
use (float) readArray().getScalar();
|
int |
readScalarInt()
Deprecated.
use (int) readArray().getScalar();
|
long |
readScalarLong()
Deprecated.
use (long) readArray().getScalar();
|
short |
readScalarShort()
Deprecated.
use (short) readArray().getScalar();
|
String |
readScalarString()
Deprecated.
use (String) readArray().getScalar() or if CHAR, readArray().makeStringFromChar()
|
long |
readToStream(Section section,
OutputStream out)
Deprecated.
do not use.
|
Array |
reallyRead(Variable client,
CancelTask cancelTask)
Deprecated.
|
Array |
reallyRead(Variable client,
Section section,
CancelTask cancelTask)
Deprecated.
|
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.
|
void |
resetShape()
Deprecated.
Use Variable.builder()
|
Variable |
section(List<Range> ranges)
Create a new Variable that is a logical subsection of this Variable.
|
Variable |
section(Section subsection)
Create a new Variable that is a logical subsection of this Variable.
|
protected void |
setCachedData(Array<?> cacheData) |
void |
setCaching(boolean caching)
Set whether to cache or not.
|
Variable |
slice(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.
|
String |
toString() |
String |
toStringDebug()
Debugging info
|
protected void |
writeCDL(Formatter buf,
Indent indent,
boolean useFullName,
boolean strict) |
public static boolean permitCaching
A true value for this field does not indicate whether a Variable
is caching, only that it's permitted to cache.
protected int hashCode
@Nullable protected final NetcdfFile ncfile
protected final com.google.common.collect.ImmutableList<Dimension> dimensions
protected final AttributeContainer attributes
protected final ProxyReader proxyReader
protected int[] shape
protected boolean isVariableLength
protected int elementSize
protected ArrayType dataType
protected Variable.Cache cache
protected Variable(Variable.Builder<?> builder, Group parentGroup)
public int findDimensionIndex(String name)
name - the name of the dimensionpublic String getDatasetLocation()
@Deprecated public DataType getDataType()
getDataType in interface VariableSimpleIFpublic ArrayType getArrayType()
getArrayType in interface VariableSimpleIFpublic String getDescription()
getDescription in interface VariableSimpleIFpublic com.google.common.collect.ImmutableList<Dimension> getDimensions()
getDimensions in interface VariableSimpleIFpublic com.google.common.collect.ImmutableSet<Dimension> getDimensionSet()
public Dimension getDimension(int i)
i - index of the dimension.public String getDimensionsString()
public int getElementSize()
@Nullable public EnumTypedef getEnumTypedef()
@Nullable public String getFileTypeId()
public String getFullName()
NetcdfFiles.makeFullName(Variable)getFullName in interface VariableSimpleIF@Nullable public NetcdfFile getNetcdfFile()
public Group getParentGroup()
@Nullable public Structure getParentStructure()
public com.google.common.collect.ImmutableList<Range> getRanges()
public int getRank()
getRank in interface VariableSimpleIFpublic int[] getShape()
getShape in interface VariableSimpleIFpublic int getShape(int index)
@Deprecated public Section getShapeAsSection()
public Section getSection()
public String getShortName()
getShortName in interface VariableSimpleIFpublic long getSize()
@Nullable public String getUnitsString()
getUnitsString in interface VariableSimpleIFpublic boolean isCoordinateVariable()
public boolean isMemberOfStructure()
public boolean isMetadata()
public boolean isScalar()
public boolean isUnlimited()
public boolean isVariableLength()
@Nullable public String lookupEnumString(int val)
val - the integer value of this enumpublic Variable section(List<Range> ranges) throws InvalidRangeException
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.InvalidRangeException - if shape and range list dont matchpublic Variable section(Section subsection) throws InvalidRangeException
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.InvalidRangeException - if section not compatible with shapepublic Variable slice(int dim, int value) throws InvalidRangeException
dim - which dimension to fixvalue - at what index valueInvalidRangeException - if dimension or value is illegalpublic Variable reduce(List<Dimension> dims)
dims - list of dimensions of length 1 to reduce@Deprecated public long readToStream(Section section, OutputStream out) throws IOException, InvalidRangeException
IOExceptionInvalidRangeException@Deprecated public Array read(int[] origin, int[] shape) throws IOException, InvalidRangeException
assert(origin[ii] + shape[ii]*stride[ii] <= Variable.shape[ii]);
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.IOExceptionInvalidRangeException@Deprecated public Array read(String sectionSpec) throws IOException, InvalidRangeException
sectionSpec - specification string, eg "1:2,10,:,1:100:10". May optionally have ().IOExceptionInvalidRangeExceptionfor sectionSpec syntax@Deprecated public Array read(List<Range> ranges) throws IOException, InvalidRangeException
ranges - list of Range specifying the section of data to read.IOException - if errorInvalidRangeException - if ranges is invalidread(Section)@Deprecated public Array read(Section section) throws IOException, InvalidRangeException
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.IOException - if errorInvalidRangeException - if section is invalid@Deprecated public Array read() throws IOException
IOException@Deprecated public byte readScalarByte() throws IOException
IOException - if theres an IO ErrorUnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.RuntimeException - if data type not convertible to byte@Deprecated public short readScalarShort() throws IOException
IOException - if theres an IO ErrorUnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.RuntimeException - if data type not convertible to byte@Deprecated public int readScalarInt() throws IOException
IOException - if theres an IO ErrorUnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.RuntimeException - if data type not convertible to byte@Deprecated public long readScalarLong() throws IOException
IOException - if theres an IO ErrorUnsupportedOperationException - if not a scalar VariableRuntimeException - if data type not convertible to byte@Deprecated public float readScalarFloat() throws IOException
IOException - if theres an IO ErrorUnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.RuntimeException - if data type not convertible to byte@Deprecated public double readScalarDouble() throws IOException
IOException - if theres an IO ErrorUnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.RuntimeException - if data type not convertible to byte@Deprecated public String readScalarString() throws IOException
IOException - if theres an IO ErrorUnsupportedOperationException - if not a scalar or one-dimensional.ClassCastException - if data type not DataType.STRING or DataType.CHAR.protected Array _read() throws IOException
IOExceptionpublic Array<?> readArray() throws IOException
IOExceptionprotected Array _read(Section section) throws IOException, InvalidRangeException
IOExceptionInvalidRangeExceptionpublic Array<?> readArray(@Nullable Section section) throws IOException, InvalidRangeException
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.IOExceptionInvalidRangeException@Deprecated protected Array _readScalarData() throws IOException
IOException@Deprecated public Array reallyRead(Variable client, CancelTask cancelTask) throws IOException
reallyRead in interface ProxyReaderclient - the client VariablecancelTask - user may cancelIOExceptionpublic Array<?> proxyReadArray(Variable client, CancelTask cancelTask) throws IOException
proxyReadArray in interface ProxyReaderIOException@Deprecated public Array reallyRead(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException
reallyRead in interface ProxyReaderclient - the client Variablesection - the section of data to read.cancelTask - user may cancelInvalidRangeException - if section has incorrect rank or illegal shape.IOExceptionpublic Array<?> proxyReadArray(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException
proxyReadArray in interface ProxyReaderIOExceptionInvalidRangeExceptionpublic String getNameAndDimensions()
public void getNameAndDimensions(Formatter buf, boolean useFullName, boolean strict)
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 escapingpublic String toStringDebug()
protected String extraInfo()
public int compareTo(VariableSimpleIF o)
compareTo in interface Comparable<VariableSimpleIF>public AttributeContainer attributes()
attributes in interface VariableSimpleIF@Nullable public Attribute findAttribute(String name)
public String findAttributeString(String attName, String defaultValue)
@Deprecated public void resetShape()
public Object getSPobject()
public int getSizeToCache()
public void setCaching(boolean caching)
public boolean isCaching()
This will always return false if caching isn't permitted.
public void invalidateCache()
protected void setCachedData(Array<?> cacheData)
public boolean hasCachedData()
public Variable.Builder<?> toBuilder()
protected Variable.Builder<?> addLocalFieldsToBuilder(Variable.Builder<? extends Variable.Builder<?>> builder)
public static Variable.Builder<?> builder()