Package ucar.nc2
Class Structure
java.lang.Object
ucar.nc2.CDMNode
ucar.nc2.Variable
ucar.nc2.Structure
- All Implemented Interfaces:
Comparable<VariableSimpleIF>,Iterable<Attribute>,AttributeContainer,ProxyReader,VariableSimpleIF
- Direct Known Subclasses:
Sequence,StructureDS
A Structure is a type of Variable that contains other Variables, like a struct in C.
A Structure can be scalar or multidimensional.
A call to structure.read() will read all of the data in a Structure, including nested structures, and returns an Array of StructureData, with all of the data in memory. If there is a nested sequence, the sequence data may be read into memory all at once, or it may be read in increments as the iteration proceeds.
Generally, the programmer can assume that the data in one Structure are stored together, so that it is efficient to read an entire Structure, and then access the Variable data through the Arrays in the StructureData.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classStructure.Builder<T extends Structure.Builder<T>>A builder of Structures. -
Field Summary
Fields inherited from class ucar.nc2.Variable
defaultCoordsSizeToCache, defaultSizeToCache, permitCaching -
Method Summary
Modifier and TypeMethodDescriptionstatic Structure.Builder<?>builder()Get Builder for this class that allows subclassing.findVariable(String shortName) Find the Variable member with the specified (short) name.intGet the size of one element of the Structure.Get String with name and attributes.intGet the number of variables contained directly in this Structure.Iterator over all the data in a Structure.getStructureIterator(int bufferSize) Get an efficient iterator over all the data in the Structure.com.google.common.collect.ImmutableList<String>Get the (short) names of the variables contained directly in this Structure.com.google.common.collect.ImmutableList<Variable>Get the variables contained directly in this Structure.booleanCaching is not allowedbooleanisSubset()Find if this was created from a subset() method.Create a StructureMembers object that describes this Structure.readStructure(int index) Use this when this is a one dimensional array of Structures, or you are doing the index calculation yourself for a multidimension array.readStructure(int start, int count) For rank 1 array of Structures, read count Structures and return the data as an ArrayStructure.Create a subset of the Structure consisting only of the one member variableCreate a subset of the Structure consisting only of the given member variablesvoidsetCaching(boolean caching) Caching is not allowedTurn into a mutable Builder.Methods inherited from class ucar.nc2.Variable
attributes, compareTo, createNewCache, equals, findAttribute, findAttributeString, findDimensionIndex, getDatasetLocation, getDataType, getDescription, getDimension, getDimensions, getDimensionsString, getEnumTypedef, getFileTypeId, getFullName, getNameAndDimensions, getNameAndDimensions, getNameAndDimensions, getNetcdfFile, getParentGroup, getParentStructure, getRanges, getRank, getShape, getShape, getShapeAsSection, getSize, getSizeToCache, getSPobject, getUnitsString, hasCachedData, hashCode, isCoordinateVariable, isMemberOfStructure, isMetadata, isScalar, isUnlimited, isVariableLength, lookupEnumString, read, read, read, read, read, readScalarByte, readScalarDouble, readScalarFloat, readScalarInt, readScalarLong, readScalarShort, readScalarString, readToStream, reallyRead, reallyRead, reduce, section, section, slice, toString, toStringDebugMethods inherited from class ucar.nc2.CDMNode
getShortNameMethods inherited from interface ucar.nc2.AttributeContainer
findAttributeDouble, findAttributeIgnoreCase, findAttributeInteger, getName, hasAttribute, hasAttributeIgnoreCase, isEmpty, iteratorMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface ucar.nc2.VariableSimpleIF
getShortName
-
Method Details
-
select
Create a subset of the Structure consisting only of the given member variables- Parameters:
memberNames- list of Variable names, already a member- Returns:
- Structure containing just those members
-
select
Create a subset of the Structure consisting only of the one member variable- Parameters:
varName- name of member Variable- Returns:
- containing just that member
-
isSubset
public boolean isSubset()Find if this was created from a subset() method.- Returns:
- true if this is a subset
-
isCaching
public boolean isCaching()Caching is not allowed -
setCaching
public void setCaching(boolean caching) Caching is not allowed -
getVariables
Get the variables contained directly in this Structure. -
getNumberOfMemberVariables
public int getNumberOfMemberVariables()Get the number of variables contained directly in this Structure. -
getVariableNames
Get the (short) names of the variables contained directly in this Structure. -
findVariable
Find the Variable member with the specified (short) name.- Parameters:
shortName- name of the member variable.- Returns:
- the Variable member with the specified (short) name, or null if not found.
-
makeStructureMembers
Create a StructureMembers object that describes this Structure. CAUTION: Do not use for iterating over a StructureData or ArrayStructure - get the StructureMembers object directly from the StructureData or ArrayStructure.- Returns:
- a StructureMembers object that describes this Structure.
-
getElementSize
public int getElementSize()Get the size of one element of the Structure.- Overrides:
getElementSizein classVariable- Returns:
- size (in bytes)
-
readStructure
Use this when this is a one dimensional array of Structures, or you are doing the index calculation yourself for a multidimension array. This will read only the ith structure, and return the data as a StructureData object.- Parameters:
index- index into 1D array- Returns:
- ith StructureData
- Throws:
IOException- on read errorInvalidRangeException- if index out of range
-
readStructure
For rank 1 array of Structures, read count Structures and return the data as an ArrayStructure. Use only when this is a one dimensional array of Structures.- Parameters:
start- start at this indexcount- return this many StructureData- Returns:
- the StructureData recordsfrom start to start+count-1
- Throws:
IOException- on read errorInvalidRangeException- if start, count out of range
-
getStructureIterator
Iterator over all the data in a Structure.StructureDataIterator ii = structVariable.getStructureIterator(); while (ii.hasNext()) { StructureData sdata = ii.next(); }- Returns:
- StructureDataIterator over type StructureData
- Throws:
IOException- on read error- See Also:
-
getStructureIterator
Get an efficient iterator over all the data in the Structure. This is the efficient way to get all the data, it can be much faster than reading one record at a time, and is optimized for large datasets. This is accomplished by buffering bufferSize amount of data at once.Example: StructureDataIterator ii = structVariable.getStructureIterator(100 * 1000); while (ii.hasNext()) { StructureData sdata = ii.next(); }- Parameters:
bufferSize- size in bytes to buffer, set < 0 to use default size- Returns:
- StructureDataIterator over type StructureData
- Throws:
IOException- on read error
-
getNameAndAttributes
Get String with name and attributes. Used in short descriptions like tooltips.- Returns:
- name and attributes String
-
toBuilder
Turn into a mutable Builder. Can use toBuilder().build() to copy. -
builder
Get Builder for this class that allows subclassing.- See Also:
-
- "https://community.oracle.com/blogs/emcmanus/2010/10/24/using-builder-pattern-subclasses"
-