public class Variable extends CDMNode implements VariableIF, ProxyReader, AttributeContainer
Immutable if setImmutable() was called.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
Variable.Cache
Public by accident.
|
| Modifier and Type | Field and Description |
|---|---|
protected AttributeContainerHelper |
attributes |
protected Variable.Cache |
cache |
protected DataType |
dataType |
protected static boolean |
debugCaching |
static int |
defaultCoordsSizeToCache |
static int |
defaultSizeToCache |
protected List<Dimension> |
dimensions |
protected int |
elementSize |
protected int |
hashCode |
protected boolean |
isMetadata |
protected boolean |
isVariableLength |
protected NetcdfFile |
ncfile |
static boolean |
permitCaching
Globally permit or prohibit caching.
|
protected ProxyReader |
proxyReader |
protected int[] |
shape |
protected Section |
shapeAsSection |
protected int |
sizeToCache |
protected Object |
spiObject |
annotations, dodsname, group, immutable, parentstruct, shortName, sort| Modifier | Constructor and Description |
|---|---|
protected |
Variable() |
|
Variable(NetcdfFile ncfile,
Group group,
Structure parent,
String shortName)
Create a Variable.
|
|
Variable(NetcdfFile ncfile,
Group group,
Structure parent,
String shortName,
DataType dtype,
List<Dimension> dims)
Create a Variable.
|
|
Variable(NetcdfFile ncfile,
Group group,
Structure parent,
String shortName,
DataType dtype,
String dims)
Create a Variable.
|
|
Variable(Variable from)
Copy constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected Array |
_read() |
protected Array |
_read(Section section) |
void |
addAll(Iterable<Attribute> atts)
Add all; replace old if has same name
|
Attribute |
addAttribute(Attribute att)
Add new or replace old if has same name
|
int |
compareTo(VariableSimpleIF o)
Sort by name
|
protected Variable |
copy() |
void |
createNewCache()
Create a new data cache, use this when you dont want to share the cache.
|
boolean |
equals(Object oo)
Instances which have same content are equal.
|
protected String |
extraInfo() |
Attribute |
findAttribute(String name) |
Attribute |
findAttributeIgnoreCase(String name)
find the attribute for the variable with the given name, ignoring case.
|
String |
findAttValueIgnoreCase(String attName,
String defaultValue)
Find a String-valued Attribute by Attribute name (ignore case), return the (string) value of the Attribute.
|
int |
findDimensionIndex(String name)
Find the index of the named Dimension in this Variable.
|
AttributeContainer |
getAttributeContainer() |
List<Attribute> |
getAttributes()
Attributes for the variable.
|
static String |
getDAPName(String name,
Variable context) |
static String |
getDAPName(Variable v) |
String |
getDatasetLocation() |
DataType |
getDataType()
Get the data type of the Variable.
|
String |
getDescription()
Get the description of the Variable.
|
Dimension |
getDimension(int i)
Get the ith dimension.
|
List<Dimension> |
getDimensions()
Get the list of dimensions used by this variable.
|
List<Dimension> |
getDimensionsAll()
Get list of Dimensions, including parents if any.
|
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 |
getNameAndDimensions()
Get the display name plus the dimensions, eg 'float name(dim1, dim2)'
|
String |
getNameAndDimensions(boolean strict)
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 StringBuffer
|
void |
getNameAndDimensions(StringBuffer buf)
Deprecated.
use getNameAndDimensions(StringBuilder buf)
|
void |
getNameAndDimensions(StringBuilder buf)
Get the display name plus the dimensions, eg 'name(dim1, dim2)'
|
void |
getNameAndDimensions(StringBuilder buf,
boolean useFullName,
boolean strict)
Add display name plus the dimensions to the StringBuffer
|
NetcdfFile |
getNetcdfFile() |
Group |
getParentGroup()
Get the parent group.
|
ProxyReader |
getProxyReader() |
List<Range> |
getRanges()
Get shape as an List of Range objects.
|
int |
getRank()
Get the number of dimensions of the Variable.
|
protected Array |
getScalarData() |
int[] |
getShape()
Get the shape: length of Variable in each dimension.
|
int |
getShape(int index)
Get the size of the ith dimension
|
int[] |
getShapeAll() |
Section |
getShapeAsSection()
Get shape as a Section object.
|
int[] |
getShapeNotScalar() |
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()
Should not be public.
|
String |
getUnitsString()
Get the Unit String for the Variable.
|
boolean |
hasCachedData()
Has data been read and cached.
|
int |
hashCode()
Override Object.hashCode() to implement equals.
|
void |
hashCodeShow(Indent indent) |
void |
invalidateCache()
Invalidate the data cache
|
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 |
isImmutable()
Is this Variable immutable
|
boolean |
isMetadata()
Is this variable metadata?.
|
boolean |
isScalar()
Whether this is a scalar Variable (rank == 0).
|
boolean |
isUnknownLength()
Deprecated.
use isVariableLength()
|
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 |
read()
Read all the data for this Variable and return a memory resident Array.
|
Array |
read(int[] origin,
int[] shape)
Read a section of the data for this Variable and return a memory resident Array.
|
Array |
read(List<Range> ranges)
Read a section of the data for this Variable from the netcdf file and return a memory resident Array.
|
Array |
read(Section section)
Read a section of the data for this Variable from the netcdf file and return a memory resident Array.
|
Array |
read(String sectionSpec)
Read data section specified by a "section selector", and return a memory resident Array.
|
byte |
readScalarByte()
Get the value as a byte for a scalar Variable.
|
double |
readScalarDouble()
Get the value as a double for a scalar Variable.
|
float |
readScalarFloat()
Get the value as a float for a scalar Variable.
|
int |
readScalarInt()
Get the value as a int for a scalar Variable.
|
long |
readScalarLong()
Get the value as a long for a scalar Variable.
|
short |
readScalarShort()
Get the value as a short for a scalar Variable.
|
String |
readScalarString()
Get the value as a String for a scalar Variable.
|
long |
readToByteChannel(Section section,
WritableByteChannel wbc) |
long |
readToStream(Section section,
OutputStream out) |
Array |
reallyRead(Variable client,
CancelTask cancelTask)
public by accident, do not call directly.
|
Array |
reallyRead(Variable client,
Section section,
CancelTask cancelTask)
public by accident, do not call directly.
|
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.
|
boolean |
remove(Attribute a)
Remove an Attribute : uses the attribute hashCode to find it.
|
boolean |
removeAttribute(String attName)
Remove an Attribute by name.
|
boolean |
removeAttributeIgnoreCase(String attName)
Remove an Attribute by name, ignoring case
|
void |
resetDimensions()
Reset the dimension array.
|
void |
resetShape()
Use when dimensions have changed, to recalculate the shape.
|
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.
|
void |
setCachedData(Array cacheData) |
void |
setCachedData(Array cacheData,
boolean isMetadata)
Set the data cache
|
void |
setCaching(boolean caching)
Set whether to cache or not.
|
void |
setDataType(DataType dataType)
Set the data type
|
void |
setDimension(int idx,
Dimension dim)
Replace a dimension with an equivalent one.
|
void |
setDimensions(List<Dimension> dims)
Set the shape with a list of Dimensions.
|
void |
setDimensions(String dimString)
Set the dimensions using the dimensions names.
|
void |
setDimensionsAnonymous(int[] shape)
Set the dimensions using all anonymous (unshared) dimensions
|
void |
setElementSize(int elementSize)
Set the element size.
|
void |
setEnumTypedef(EnumTypedef enumTypedef)
Public by accident.
|
Variable |
setImmutable()
Make this immutable.
|
void |
setIsScalar()
Set this Variable to be a scalar
|
String |
setName(String shortName)
Set the short name, converting to valid CDM object name if needed.
|
void |
setParentGroup(Group group)
Set the parent group.
|
void |
setProxyReader(ProxyReader proxyReader) |
void |
setSizeToCache(int sizeToCache)
Set the sizeToCache.
|
void |
setSPobject(Object spiObject)
Should not be public.
|
void |
setValues(int npts,
double start,
double incr)
Generate the list of values from a starting value and an increment.
|
void |
setValues(List<String> values)
Set the data values from a list of Strings.
|
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.
|
String |
toString()
CDL representation of Variable, not strict.
|
String |
toStringDebug()
String representation of Variable and its attributes.
|
String |
writeCDL(boolean useFullName,
boolean strict)
CDL representation of a Variable.
|
protected void |
writeCDL(Formatter buf,
Indent indent,
boolean useFullName,
boolean strict) |
annotate, annotation, getDODSName, getFullName, getFullNameEscaped, getGroup, getImmutable, getName, getParentStructure, getShortName, getSort, isMemberOfStructure, localhash, setDODSName, setParentStructure, setShortName, setSort, unwrapclone, finalize, getClass, notify, notifyAll, wait, wait, waitgetFullName, getFullNameEscaped, getParentStructure, getShortName, isMemberOfStructuregetNamegetNamepublic static boolean permitCaching
A true value for this field does not indicate whether a Variable
is caching, only that it's permitted to cache.
public static int defaultSizeToCache
public static int defaultCoordsSizeToCache
protected static boolean debugCaching
protected NetcdfFile ncfile
protected int[] shape
protected Section shapeAsSection
protected DataType dataType
protected int elementSize
protected AttributeContainerHelper attributes
protected boolean isVariableLength
protected boolean isMetadata
protected Variable.Cache cache
protected int sizeToCache
protected ProxyReader proxyReader
protected int hashCode
protected Object spiObject
protected Variable()
public Variable(NetcdfFile ncfile, Group group, Structure parent, String shortName)
ncfile - the containing NetcdfFile.group - the containing group; if null, use rootGroupparent - parent Structure, may be nullshortName - variable shortName, must be unique within the Grouppublic Variable(NetcdfFile ncfile, Group group, Structure parent, String shortName, DataType dtype, String dims)
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.public Variable(NetcdfFile ncfile, Group group, Structure parent, String shortName, DataType dtype, List<Dimension> dims)
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.public Variable(Variable from)
from - copy from this Variable.public DataType getDataType()
getDataType in interface VariableIFgetDataType in interface VariableSimpleIFpublic int[] getShape()
getShape in interface VariableIFgetShape in interface VariableSimpleIFpublic int[] getShapeNotScalar()
public int getShape(int index)
index - which dimensionpublic long getSize()
getSize in interface VariableIFpublic int getElementSize()
getElementSize in interface VariableIFpublic int getRank()
getRank in interface VariableIFgetRank in interface VariableSimpleIFpublic Group getParentGroup()
getParentGroup in interface VariableIFgetParentGroup in class CDMNodepublic boolean isMetadata()
isMetadata in interface VariableIFpublic boolean isScalar()
isScalar in interface VariableIFpublic boolean isVariableLength()
isVariableLength in interface VariableIFpublic boolean isUnlimited()
isUnlimited in interface VariableIFpublic List<Dimension> getDimensions()
getDimensions in interface VariableIFgetDimensions in interface VariableSimpleIFpublic Dimension getDimension(int i)
getDimension in interface VariableIFi - index of the dimension.public String getDimensionsString()
public int findDimensionIndex(String name)
findDimensionIndex in interface VariableIFname - the name of the dimensionpublic String getDescription()
getDescription in interface VariableIFgetDescription in interface VariableSimpleIFpublic String getUnitsString()
getUnitsString in interface VariableIFgetUnitsString in interface VariableSimpleIFpublic List<Range> getRanges()
getRanges in interface VariableIFpublic Section getShapeAsSection()
getShapeAsSection in interface VariableIFpublic ProxyReader getProxyReader()
public void setProxyReader(ProxyReader proxyReader)
public Variable section(List<Range> ranges) throws InvalidRangeException
section in interface VariableIFranges - 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.InvalidRangeExceptionpublic 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) throws InvalidRangeException
dims - list of dimensions of length 1 to reduceInvalidRangeException - if dimension or value is illegalprotected Variable copy()
public NetcdfFile getNetcdfFile()
public String lookupEnumString(int val)
val - the integer value of this enumpublic void setEnumTypedef(EnumTypedef enumTypedef)
enumTypedef - set the EnumTypedef, only use if getDataType.isEnum()public EnumTypedef getEnumTypedef()
getEnumTypedef in interface VariableIFpublic Array read(int[] origin, int[] shape) throws IOException, InvalidRangeException
assert(origin[ii] + shape[ii]*stride[ii] <= Variable.shape[ii]);
read in interface VariableIForigin - 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.IOExceptionInvalidRangeExceptionpublic Array read(String sectionSpec) throws IOException, InvalidRangeException
read in interface VariableIFsectionSpec - specification string, eg "1:2,10,:,1:100:10". May optionally have ().IOExceptionInvalidRangeExceptionfor sectionSpec syntaxpublic 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)public Array read(Section section) throws IOException, InvalidRangeException
read in interface VariableIFsection - 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 invalidpublic Array read() throws IOException
read in interface VariableIFIOExceptionpublic byte readScalarByte()
throws IOException
readScalarByte in interface VariableIFIOException - if theres an IO ErrorUnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.ForbiddenConversionException - if data type not convertible to bytepublic short readScalarShort()
throws IOException
readScalarShort in interface VariableIFIOException - if theres an IO ErrorUnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.ForbiddenConversionException - if data type not convertible to shortpublic int readScalarInt()
throws IOException
readScalarInt in interface VariableIFIOException - if theres an IO ErrorUnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.ForbiddenConversionException - if data type not convertible to intpublic long readScalarLong()
throws IOException
readScalarLong in interface VariableIFIOException - if theres an IO ErrorUnsupportedOperationException - if not a scalar VariableForbiddenConversionException - if data type not convertible to longpublic float readScalarFloat()
throws IOException
readScalarFloat in interface VariableIFIOException - if theres an IO ErrorUnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.ForbiddenConversionException - if data type not convertible to floatpublic double readScalarDouble()
throws IOException
readScalarDouble in interface VariableIFIOException - if theres an IO ErrorUnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.ForbiddenConversionException - if data type not convertible to doublepublic String readScalarString() throws IOException
readScalarString in interface VariableIFIOException - if theres an IO ErrorUnsupportedOperationException - if not a scalar or one-dimensional.ClassCastException - if data type not DataType.STRING or DataType.CHAR.protected Array getScalarData() throws IOException
IOExceptionprotected Array _read() throws IOException
IOExceptionpublic Array reallyRead(Variable client, CancelTask cancelTask) throws IOException
reallyRead in interface ProxyReaderclient - the client VariablecancelTask - user may cancelIOException - on errorprotected Array _read(Section section) throws IOException, InvalidRangeException
IOExceptionInvalidRangeExceptionpublic 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 cancelIOException - on errorInvalidRangeException - if section has incorrect rank or illegal shape.public long readToByteChannel(Section section, WritableByteChannel wbc) throws IOException, InvalidRangeException
IOExceptionInvalidRangeExceptionpublic long readToStream(Section section, OutputStream out) throws IOException, InvalidRangeException
IOExceptionInvalidRangeExceptionpublic String getNameAndDimensions()
public String getNameAndDimensions(boolean strict)
strict - strictly comply with ncgen syntax, with name escaping. otherwise, get extra info, no escapingpublic void getNameAndDimensions(StringBuilder buf)
buf - add info to this StringBuilderpublic void getNameAndDimensions(StringBuffer buf)
buf - add info to this StringBufferpublic void getNameAndDimensions(StringBuilder 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 void getNameAndDimensions(Formatter buf, boolean useFullName, boolean strict)
getNameAndDimensions in interface VariableIFbuf - 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 toString()
public String writeCDL(boolean useFullName, boolean strict)
useFullName - use full name, else use short namestrict - strictly comply with ncgen syntaxpublic String toStringDebug()
toStringDebug in interface VariableIFprotected String extraInfo()
public String getDatasetLocation()
public boolean equals(Object oo)
public int hashCode()
public void hashCodeShow(Indent indent)
hashCodeShow in class CDMNodepublic int compareTo(VariableSimpleIF o)
compareTo in interface Comparable<VariableSimpleIF>public void setDataType(DataType dataType)
dataType - set to this valuepublic String setName(String shortName)
shortName - set to this valuepublic void setParentGroup(Group group)
setParentGroup in class CDMNodegroup - set to this valuepublic void setElementSize(int elementSize)
elementSize - set to this valuepublic List<Attribute> getAttributes()
VariableSimpleIFgetAttributes in interface AttributeContainergetAttributes in interface VariableIFgetAttributes in interface VariableSimpleIFpublic AttributeContainer getAttributeContainer()
public Attribute findAttribute(String name)
findAttribute in interface AttributeContainerfindAttribute in interface VariableIFpublic Attribute findAttributeIgnoreCase(String name)
VariableSimpleIFfindAttributeIgnoreCase in interface AttributeContainerfindAttributeIgnoreCase in interface VariableIFfindAttributeIgnoreCase in interface VariableSimpleIFname - attribute namepublic String findAttValueIgnoreCase(String attName, String defaultValue)
AttributeContainerfindAttValueIgnoreCase in interface AttributeContainerpublic Attribute addAttribute(Attribute att)
AttributeContaineraddAttribute in interface AttributeContaineratt - add this Attributepublic void addAll(Iterable<Attribute> atts)
AttributeContaineraddAll in interface AttributeContainerpublic boolean remove(Attribute a)
AttributeContainerremove in interface AttributeContainera - remove this attributepublic boolean removeAttribute(String attName)
AttributeContainerremoveAttribute in interface AttributeContainerattName - if exists, remove this attributepublic boolean removeAttributeIgnoreCase(String attName)
AttributeContainerremoveAttributeIgnoreCase in interface AttributeContainerattName - if exists, remove this attributepublic void setDimensions(List<Dimension> dims)
dims - list of type ucar.nc2.Dimensionpublic void resetShape()
public void setDimensions(String dimString)
dimString - : whitespace separated list of dimension names, or '*' for Dimension.UNKNOWN, or number for anon dimension. null or empty String is a scalar.public void resetDimensions()
public void setDimensionsAnonymous(int[] shape)
throws InvalidRangeException
shape - defines the dimension lengths. must be > 0, or -1 for VLENInvalidRangeException - if any shape < 1public void setIsScalar()
public void setDimension(int idx,
Dimension dim)
idx - index into dimension arraydim - to setpublic Variable setImmutable()
setImmutable in class CDMNodepublic boolean isImmutable()
public Object getSPobject()
public void setSPobject(Object spiObject)
spiObject - the IOSP objectpublic int getSizeToCache()
public void setSizeToCache(int sizeToCache)
sizeToCache - size at which caching happens. < 0 means use defaultspublic void setCaching(boolean caching)
caching - set if caching.public boolean isCaching()
This will always return false if caching isn't permitted.
public void invalidateCache()
public void setCachedData(Array cacheData)
public void setCachedData(Array cacheData, boolean isMetadata)
cacheData - cache this ArrayisMetadata - : synthesized data, set true if must be saved in NcML output (ie data not actually in the file).public void createNewCache()
public boolean hasCachedData()
public void setValues(int npts,
double start,
double incr)
npts - number of values, must = v.getSize()start - starting valueincr - incrementpublic void setValues(List<String> values) throws IllegalArgumentException
values - list of StringsIllegalArgumentException - if values array not correct size, or values wont parse to the correct typepublic List<Dimension> getDimensionsAll()
getDimensionsAll in interface VariableIFpublic int[] getShapeAll()
public boolean isCoordinateVariable()
isCoordinateVariable in interface VariableIFpublic boolean isUnknownLength()