|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectucar.nc2.Variable
public class Variable
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.
Array| Nested Class Summary | |
|---|---|
protected static class |
Variable.Cache
|
| Field Summary | |
|---|---|
protected java.util.ArrayList |
attributes
|
protected Variable.Cache |
cache
|
protected DataType |
dataType
|
protected static boolean |
debugCaching
|
static int |
defaultSizeToCache
|
protected java.util.ArrayList |
dimensions
|
protected int |
elementSize
|
protected Group |
group
|
protected boolean |
isCoordinateAxis
|
protected boolean |
isMetadata
|
protected boolean |
isSection
|
protected boolean |
isSlice
|
protected boolean |
isVlen
|
protected NetcdfFile |
ncfile
|
protected Variable |
orgVar
|
protected Structure |
parent
|
protected Index |
scalarIndex
|
protected java.util.List |
sectionRanges
|
protected int[] |
shape
|
protected java.lang.String |
shortName
|
protected int |
sizeToCache
|
protected int |
sliceDim
|
protected java.util.List |
sliceRanges
|
| Constructor Summary | |
|---|---|
Variable(NetcdfFile ncfile,
Group group,
Structure parentStructure,
java.lang.String shortName)
Create a Variable. |
|
Variable(Variable from)
Copy constructor |
|
| Method Summary | |
|---|---|
protected Array |
_read()
|
protected Array |
_read(java.util.List section)
|
protected Array |
_readMemberData(java.util.List section,
boolean flatten)
|
void |
addAttribute(Attribute att)
Add new or replace old if has same name |
protected java.util.ArrayList |
attributes()
|
protected void |
calcIsCoordinateVariable()
|
boolean |
equals(java.lang.Object oo)
Instances which have same content are equal. |
protected java.lang.String |
extraInfo()
|
Attribute |
findAttribute(java.lang.String name)
Find an Attribute by name. |
Attribute |
findAttributeIgnoreCase(java.lang.String name)
Find an Attribute by name, ignoring the case. |
int |
findDimensionIndex(java.lang.String name)
Find the index of the named Dimension in this Variable. |
java.util.List |
getAttributes()
Returns the set of attributes for this variable. |
Dimension |
getCoordinateDimension()
If this is a coordinate variable or axis, return the corresponding dimension. |
DataType |
getDataType()
Get the data type of the Variable. |
java.lang.String |
getDescription()
Get the description of the Variable. |
Dimension |
getDimension(int i)
Get the ith dimension. |
java.util.List |
getDimensions()
Get the list of dimensions used by this variable. |
java.util.List |
getDimensionsAll()
Get list of Dimensions, including parents if any. |
java.lang.String |
getDimensionsString()
Get the list of Dimension names, space delineated. |
int |
getElementSize()
Get the number of bytes for one element of this Variable. |
Variable |
getIOVar()
should not be public. |
java.lang.String |
getName()
Get the full name of this Variable, starting from rootGroup. |
java.lang.String |
getNameAndDimensions()
display name plus the dimensions |
void |
getNameAndDimensions(java.lang.StringBuffer buf,
boolean useFullName,
boolean showDimLength)
display name plus the dimensions |
Group |
getParentGroup()
Get the containing Group. |
Structure |
getParentStructure()
Get the parent Variable if this is a member of a Structure, or null if its not. |
java.util.List |
getRanges()
Get shape as an array of Range objects. |
int |
getRank()
Get the number of dimensions of the Variable. |
java.util.List |
getSectionRanges()
Get index subsection as an array of Range objects, reletive to the original variable. |
int[] |
getShape()
Get the shape: length of Variable in each dimension. |
java.lang.String |
getShortName()
Get the short name of this Variable. |
long |
getSize()
Get the total number of elements in the Variable. |
int |
getSizeToCache()
If total data is less than SizeToCache in bytes, then cache. |
java.lang.Object |
getSPobject()
should not be public |
java.lang.String |
getUnitsString()
Get the Unit String for the Variable. |
boolean |
hasCachedData()
Does this have its data read in and cached? |
int |
hashCode()
Override Object.hashCode() to implement equals. |
void |
invalidateCache()
Invalidate the data cache |
boolean |
isCaching()
Will this Variable be cached when read. |
boolean |
isMemberOfStructure()
Is this variable is a member of a Structure?. |
boolean |
isMetadata()
Is this variable metadata?. |
boolean |
isScalar()
Whether this is a scalar Variable (rank == 0). |
protected boolean |
isSection()
Is this Variable a section of another variable ?. |
boolean |
isUnknownLength()
Deprecated. use isVariableLength() |
boolean |
isUnlimited()
Can this variable's size grow?. |
boolean |
isUnsigned()
Is this Variable unsigned?. |
boolean |
isVariableLength()
Does this variable have an variable length dimension. |
protected void |
makeSection(Variable newVar,
java.util.List section)
|
protected java.util.List |
makeSectionAddParents(java.util.List section,
boolean firstOnly)
Composes this variable's ranges with another list of ranges, adding parent ranges; resolves nulls. |
protected static java.util.List |
makeSectionRanges(Variable v,
java.util.List section)
Composes a variable's ranges with another list of ranges; resolves nulls. |
protected java.util.List |
makeSectionWithParents(java.util.List result,
java.util.List orgSection,
Variable v)
|
protected void |
makeSlice(Variable newVar,
int dim,
int value)
|
protected java.util.List |
makeSliceRanges(java.util.List section)
|
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(java.util.List section)
Read a section of the data for this Variable from the netcdf file and return a memory resident Array. |
Array |
read(java.lang.String sectionSpec)
Read data section specified by a "section selector", and return a memory resident Array. |
Array |
readAllStructures(java.util.List sectionAll,
boolean flatten)
Read data from all structures for this Variable. |
Array |
readAllStructuresSpec(java.lang.String sectionSpec,
boolean flatten)
Read data in all structures for this Variable, using a string sectionSpec to specify the section. |
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. |
java.lang.String |
readScalarString()
Get the value as a String for a scalar Variable. |
boolean |
remove(Attribute a)
Remove an Attribute : uses the attribute hashCode to find it. |
void |
replaceDimension(Dimension dim)
Replace a dimension with an equivalent one. |
Variable |
section(java.util.List section)
Create a new Variable that is a logical subsection of this Variable. |
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)
Set a dimension with an equivalent one. |
void |
setDimensions(java.util.List dims)
Set the shape with a list of Dimensions. |
void |
setDimensions(java.lang.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 |
setIOVar(Variable orgVar)
should not be public. |
void |
setIsCoordinateAxis(Dimension dim)
true is its a 1D coordinate axis or variable for its dimension |
void |
setName(java.lang.String shortName)
Set the short name |
void |
setParentGroup(Group group)
Set the parent group. |
void |
setParentStructure(Structure parent)
Set the parent structure. |
void |
setSizeToCache(int sizeToCache)
Set sizeToCache. |
void |
setSPobject(java.lang.Object spiObject)
should not be public |
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. |
java.lang.String |
toString()
String representation of Variable and its attributes. |
java.lang.String |
toStringDebug()
String representation of Variable and its attributes. |
java.lang.String |
writeCDL(java.lang.String indent,
boolean useFullName,
boolean strict)
String representation of a Variable and its attributes. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int defaultSizeToCache
protected static boolean debugCaching
protected NetcdfFile ncfile
protected Variable orgVar
protected Group group
protected java.lang.String shortName
protected int[] shape
protected DataType dataType
protected int elementSize
protected java.util.ArrayList dimensions
protected java.util.ArrayList attributes
protected boolean isCoordinateAxis
protected boolean isVlen
protected boolean isMetadata
protected Variable.Cache cache
protected int sizeToCache
protected Structure parent
protected boolean isSection
protected boolean isSlice
protected java.util.List sectionRanges
protected java.util.List sliceRanges
protected int sliceDim
protected Index scalarIndex
| Constructor Detail |
|---|
public Variable(NetcdfFile ncfile,
Group group,
Structure parentStructure,
java.lang.String shortName)
ncfile - the containing NetcdfFile.group - the containing group; if null, use rootGroupparentStructure - the containing structure; may be nullshortName - variable shortName.public Variable(Variable from)
| Method Detail |
|---|
public java.lang.String getName()
getName in interface VariableIFpublic java.lang.String getShortName()
getShortName in interface VariableIFpublic DataType getDataType()
getDataType in interface VariableIFpublic int[] getShape()
getShape in interface VariableIFpublic long getSize()
getSize in interface VariableIFpublic int getElementSize()
getElementSize in interface VariableIFpublic int getRank()
getRank in interface VariableIFpublic Group getParentGroup()
getParentGroup in interface VariableIFpublic Dimension getCoordinateDimension()
getCoordinateDimension in interface VariableIFDimension.getCoordinateVariables()public boolean isMetadata()
isMetadata in interface VariableIFpublic boolean isScalar()
isScalar in interface VariableIFpublic boolean isUnknownLength()
public boolean isVariableLength()
isVariableLength in interface VariableIFpublic boolean isUnsigned()
isUnsigned in interface VariableIFpublic boolean isUnlimited()
isUnlimited in interface VariableIFpublic java.util.List getDimensions()
getDimensions in interface VariableIFpublic Dimension getDimension(int i)
getDimension in interface VariableIFi - index of the dimension.
public java.lang.String getDimensionsString()
public int findDimensionIndex(java.lang.String name)
findDimensionIndex in interface VariableIFname - the name of the dimension
public java.util.List getAttributes()
getAttributes in interface VariableIFpublic Attribute findAttribute(java.lang.String name)
findAttribute in interface VariableIFname - the name of the attribute
public Attribute findAttributeIgnoreCase(java.lang.String name)
findAttributeIgnoreCase in interface VariableIFname - the name of the attribute
public java.lang.String getDescription()
public java.lang.String getUnitsString()
public java.util.List getRanges()
getRanges in interface VariableIFpublic java.util.List getSectionRanges()
protected boolean isSection()
public Variable section(java.util.List section)
throws InvalidRangeException
section in interface VariableIFsection - 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
protected void makeSection(Variable newVar,
java.util.List section)
throws InvalidRangeException
InvalidRangeException
protected static java.util.List makeSectionRanges(Variable v,
java.util.List section)
throws InvalidRangeException
v - the variablesection - List of ucar.ma2.Range, same rank as v, may have nulls.
InvalidRangeException
protected java.util.List makeSectionAddParents(java.util.List section,
boolean firstOnly)
throws InvalidRangeException
section - List of ucar.ma2.Range, same rank as v, may have nulls.firstOnly - if true, get first parent, else get all parrents.
InvalidRangeException
public Variable slice(int dim,
int value)
throws InvalidRangeException
dim - which dimension to fixvalue - at what index value
InvalidRangeException
protected void makeSlice(Variable newVar,
int dim,
int value)
throws InvalidRangeException
InvalidRangeException
protected java.util.List makeSliceRanges(java.util.List section)
throws InvalidRangeException
InvalidRangeException
public Array read(int[] origin,
int[] shape)
throws java.io.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. If null, assume getShape();
This becomes the shape of the returned Array.
java.io.IOException
InvalidRangeException
public Array read(java.lang.String sectionSpec)
throws java.io.IOException,
InvalidRangeException
read in interface VariableIFsectionSpec - specification string, eg "1:2,10,:,1:100:10". May optionally have ().
java.io.IOException
InvalidRangeExceptionfor sectionSpec syntax
public Array read(java.util.List section)
throws java.io.IOException,
InvalidRangeException
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 readAllStructures().
Note this only allows you to specify a subset of this variable. If the variable is nested in a array of structures and you want to subset that, use NetcdfFile.read(String sectionSpec, boolean flatten);
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.
java.io.IOException
InvalidRangeExceptionto read member variables in all structures,
to read nested variables with Structure subsetting
public Array read()
throws java.io.IOException
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 readAllStructures().
read in interface VariableIFjava.io.IOExceptionto read member variables in all structurespublic boolean isMemberOfStructure()
isMemberOfStructure in interface VariableIFpublic Structure getParentStructure()
getParentStructure in interface VariableIFpublic java.util.List getDimensionsAll()
getDimensionsAll in interface VariableIF
public Array readAllStructuresSpec(java.lang.String sectionSpec,
boolean flatten)
throws java.io.IOException,
InvalidRangeException
readAllStructuresSpec in interface VariableIFsectionSpec - specification string, eg "1:2,10,:,1:100:10"flatten - if true, remove enclosing StructureData.
java.io.IOException
InvalidRangeExceptionreadAllStructures(java.util.List, boolean),
Range.parseSpec(String sectionSpec)
public Array readAllStructures(java.util.List sectionAll,
boolean flatten)
throws java.io.IOException,
InvalidRangeException
If flatten is false, return nested Arrays of StructureData that correspond to the nested Structures. The innermost Array(s) will match the rank and type of the Variable, but they will be inside Arrays of StructureData.
If flatten is true, remove the Arrays of StructureData that wrap the data, and return an Array of the same type as the Variable. The shape of the returned Array will be an accumulation of all the shapes of the Structures containing the variable.
readAllStructures in interface VariableIFsectionAll - an array of Range objects, one for each Dimension of the enclosing Structures, as well as
for the Variable itself. If the list is null, use the full shape for everything.
If an individual Range is null, use the full shape for that dimension.flatten - if true, remove enclosing StructureData. Otherwise, each parent Structure will create a
StructureData container for the returned data array.
java.io.IOException
InvalidRangeException
protected java.util.List makeSectionWithParents(java.util.List result,
java.util.List orgSection,
Variable v)
throws InvalidRangeException
InvalidRangeException
public byte readScalarByte()
throws java.io.IOException
readScalarByte in interface VariableIFjava.io.IOException - if theres an IO Error
java.lang.UnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.
ForbiddenConversionException - if data type not convertible to byte
public short readScalarShort()
throws java.io.IOException
readScalarShort in interface VariableIFjava.io.IOException - if theres an IO Error
java.lang.UnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.
ForbiddenConversionException - if data type not convertible to short
public int readScalarInt()
throws java.io.IOException
readScalarInt in interface VariableIFjava.io.IOException - if theres an IO Error
java.lang.UnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.
ForbiddenConversionException - if data type not convertible to int
public long readScalarLong()
throws java.io.IOException
readScalarLong in interface VariableIFjava.io.IOException - if theres an IO Error
java.lang.UnsupportedOperationException - if not a scalar Variable
ForbiddenConversionException - if data type not convertible to long
public float readScalarFloat()
throws java.io.IOException
readScalarFloat in interface VariableIFjava.io.IOException - if theres an IO Error
java.lang.UnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.
ForbiddenConversionException - if data type not convertible to float
public double readScalarDouble()
throws java.io.IOException
readScalarDouble in interface VariableIFjava.io.IOException - if theres an IO Error
java.lang.UnsupportedOperationException - if not a scalar Variable or one-dimensional of length 1.
ForbiddenConversionException - if data type not convertible to double
public java.lang.String readScalarString()
throws java.io.IOException
readScalarString in interface VariableIFjava.io.IOException - if theres an IO Error
java.lang.UnsupportedOperationException - if not a scalar or one-dimensional.
java.lang.ClassCastException - if data type not DataType.STRING or DataType.CHAR.
protected Array _read()
throws java.io.IOException
java.io.IOException
protected Array _read(java.util.List section)
throws java.io.IOException,
InvalidRangeException
java.io.IOException
InvalidRangeException
protected Array _readMemberData(java.util.List section,
boolean flatten)
throws java.io.IOException,
InvalidRangeException
java.io.IOException
InvalidRangeExceptionpublic java.lang.String getNameAndDimensions()
public void getNameAndDimensions(java.lang.StringBuffer buf,
boolean useFullName,
boolean showDimLength)
getNameAndDimensions in interface VariableIFpublic java.lang.String toString()
toString in class java.lang.Object
public java.lang.String writeCDL(java.lang.String indent,
boolean useFullName,
boolean strict)
indent - start each line with this much spaceuseFullName - use full name, else use short namestrict - stictly comply with ncgen syntax
public java.lang.String toStringDebug()
toStringDebug in interface VariableIFprotected java.lang.String extraInfo()
public boolean equals(java.lang.Object oo)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic void setDataType(DataType dataType)
public void setName(java.lang.String shortName)
public void setParentStructure(Structure parent)
public void setParentGroup(Group group)
public void setElementSize(int elementSize)
protected java.util.ArrayList attributes()
public void addAttribute(Attribute att)
public boolean remove(Attribute a)
public void setDimensions(java.util.List dims)
dims - list of type ucar.nc2.Dimensionpublic void setDimensions(java.lang.String dimString)
dimString - : whitespace seperated list of dimension names, or '*' for Dimension.UNKNOWN.public void setDimensionsAnonymous(int[] shape)
shape - defines the dimension lengthspublic void replaceDimension(Dimension dim)
dim - must have the same name, length as old one
public void setDimension(int idx,
Dimension dim)
idx - index into dimension arraydim - to setprotected void calcIsCoordinateVariable()
public void setIsCoordinateAxis(Dimension dim)
public java.lang.Object getSPobject()
public void setSPobject(java.lang.Object spiObject)
public Variable getIOVar()
public void setIOVar(Variable orgVar)
public int getSizeToCache()
public void setSizeToCache(int sizeToCache)
public void setCaching(boolean caching)
caching - set if caching.public boolean isCaching()
public void invalidateCache()
public void setCachedData(Array cacheData,
boolean isMetadata)
isMetadata - : synthesized data, set true if must be saved in NcML output (ie data not actually in the file).public boolean hasCachedData()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||