Package opendap.dap
Class DArray
- java.lang.Object
-
- opendap.dap.DAPNode
-
- opendap.dap.BaseType
-
- opendap.dap.DVector
-
- opendap.dap.DArray
-
- All Implemented Interfaces:
Serializable,Cloneable,ClientIO
public class DArray extends DVector
This class is used to hold arrays of other OPeNDAP data. The elements of the array can be simple or compound data types. There is no limit on the number of dimensions an array can have, or on the size of each dimension. If desired, the user can give each dimension of an array a name. You can, for example, have a 360x180 array of temperatures, covering the whole globe with one-degree squares. In this case, you could name the first dimension "Longitude" and the second dimension "Latitude". This can help prevent a great deal of confusion. TheDArrayis used as part of theDGridclass, where the dimension names are crucial to its structure. The dimension names correspond to "Map" vectors, holding the actual values for that column of the array. Each array dimension carries with it its own projection information. The projection inforamtion takes the form of three integers: the start, stop, and stride values. This is clearest with an example. Consider a one-dimensional array 10 elements long. If the start value of the dimension constraint is 3, then the constrained array appears to be seven elements long. If the stop value is changed to 7, then the array appears to be five elements long. If the stride is changed to two, the array will appear to be 3 elements long. Array constraints are written as[start:stride:stop].NB: OPeNDAP uses zero-based indexing.A = [1 2 3 4 5 6 7 8 9 10] A[3::] = [4 5 6 7 8 9 10] A[3::7] = [4 5 6 7 8] A[3:2:7] = [4 6 8] A[0:3:9] = [1 4 7 10]
- See Also:
DGrid,DVector,BaseType, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class opendap.dap.DAPNode
DAPNode.CloneMap
-
-
Field Summary
Fields Modifier and Type Field Description protected ArrayList<DArrayDimension>dimVectorA List of DArrayDimension information (i.e.-
Fields inherited from class opendap.dap.DAPNode
_nameClear, _nameEncoded, log
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendDim(int size)Add a dimension to the array.voidappendDim(int size, String name)Given a size and a name, this function adds a dimension to the array.voidcheckSemantics(boolean all)Checks for internal consistency.DArraycloneDAG(DAPNode.CloneMap map)Returns a clone of thisArray.DArrayDimensiongetDimension(int dimension)Returns theDArrayDimensionobject for the dimension requested.com.google.common.collect.ImmutableList<DArrayDimension>getDimensions()Returns anEnumerationofDArrayDimensions in this array.DArrayDimensiongetFirstDimension()Returns theDArrayDimensionobject for the first dimension.StringgetTypeName()Returns the OPeNDAP type name of the class instance as aString.intnumDimensions()Returns the number of dimensions in this array.voidprintAsMapXML(PrintWriter pw, String pad, boolean constrained)voidprintConstraint(PrintWriter os)voidprintDecl(PrintWriter os, String space, boolean print_semi, boolean constrained)Write the variable's declaration in a C-style syntax.voidprintVal(PrintWriter pw, String space, boolean print_decl_p)Prints the value of the variable, with its declaration.voidprintXML(PrintWriter pw, String pad, boolean constrained)voidsqueeze()Use this method to "squeeze" out all of the array dimensions whose size is equal to 1.-
Methods inherited from class opendap.dap.DVector
addVariable, deserialize, externalize, getContainerVar, getLength, getPrimitiveVector, setContainerVar, setLength
-
Methods inherited from class opendap.dap.BaseType
addAttributeAlias, addAttributeContainer, appendAttribute, appendAttribute, appendAttributeContainer, checkSemantics, delAttribute, delAttribute, elementCount, elementCount, getAttribute, getAttribute, getAttributeNames, getAttributeTable, getLongName, hasAttributes, newPrimitiveVector, printAttributes, printAttributes, printAttributes, printAttributes, printDecl, printDecl, printDecl, printDecl, printDecl, printDecl, printDecl, printVal, printVal, printVal, printXML, printXML, printXML, printXML, setClearName
-
Methods inherited from class opendap.dap.DAPNode
clone, cloneDAG, getClearName, getEncodedName, getParent, isProject, setEncodedName, setParent, setProject, setProject, setProjected
-
-
-
-
Field Detail
-
dimVector
protected ArrayList<DArrayDimension> dimVector
A List of DArrayDimension information (i.e. the shape)
-
-
Constructor Detail
-
DArray
public DArray()
Constructs a newDArray.
-
DArray
public DArray(String n)
Constructs a newDArraywith namen.- Parameters:
n- the name of the variable.
-
-
Method Detail
-
getTypeName
public String getTypeName()
Returns the OPeNDAP type name of the class instance as aString.- Overrides:
getTypeNamein classDVector- Returns:
- the OPeNDAP type name of the class instance as a
String.
-
checkSemantics
public void checkSemantics(boolean all) throws BadSemanticsExceptionChecks for internal consistency. ForDArray, verify that the dimension vector is not empty.- Overrides:
checkSemanticsin classBaseType- Parameters:
all- for complex constructor types, this flag indicates whether to check the semantics of the member variables, too.- Throws:
BadSemanticsException- if semantics are bad, explains why.- See Also:
BaseType.checkSemantics(boolean)
-
printDecl
public void printDecl(PrintWriter os, String space, boolean print_semi, boolean constrained)
Write the variable's declaration in a C-style syntax. This function is used to create textual representation of the Data Descriptor Structure (DDS). See The OPeNDAP User Manual for information about this structure.- Overrides:
printDeclin classDVector- Parameters:
os- ThePrintWriteron which to print the declaration.space- Each line of the declaration will begin with the characters in this string. Usually used for leading spaces.print_semi- a boolean value indicating whether to print a semicolon at the end of the declaration.constrained- a boolean value indicating whether to print the declartion dependent on the projection information. This is only used by Server side code.- See Also:
BaseType.printDecl(PrintWriter, String, boolean)
-
printVal
public void printVal(PrintWriter pw, String space, boolean print_decl_p)
Prints the value of the variable, with its declaration. This function is primarily intended for debugging OPeNDAP applications and text-based clients such as geturl.- Overrides:
printValin classDVector- Parameters:
pw- thePrintWriteron which to print the value.space- this value is passed to theprintDeclmethod, and controls the leading spaces of the output.print_decl_p- a boolean value controlling whether the variable declaration is printed as well as the value.- See Also:
BaseType.printVal(PrintWriter, String, boolean)
-
appendDim
public void appendDim(int size, String name)Given a size and a name, this function adds a dimension to the array. For example, if theDArrayis already 10 elements long, callingappendDimwith a size of 5 will transform the array into a 10x5 matrix. Calling it again with a size of 2 will create a 10x5x2 array, and so on.- Parameters:
size- the size of the desired new dimension.name- the name of the new dimension.
-
appendDim
public void appendDim(int size)
Add a dimension to the array. Same asappendDim(size, null).- Parameters:
size- the size of the desired new dimension.- See Also:
appendDim(int, String)
-
getDimensions
public final com.google.common.collect.ImmutableList<DArrayDimension> getDimensions()
Returns anEnumerationofDArrayDimensions in this array.- Returns:
- an
EnumerationofDArrayDimensions in this array.
-
numDimensions
public final int numDimensions()
Returns the number of dimensions in this array.- Returns:
- the number of dimensions in this array.
-
squeeze
public void squeeze()
Use this method to "squeeze" out all of the array dimensions whose size is equal to 1.
Many queries that contstrain Arrays return an Array that has dimensions whose size has been reduced to 1. In effect that the dimension no longer really exists, except as a notational convention for tracking the hyperslab that the array represents. Since many clients have difficulty handling n-dimensional arrays this method was added to allow the client to easily "squeeze" the "extra" dimensions out of the array.
-
getDimension
public DArrayDimension getDimension(int dimension) throws InvalidDimensionException
Returns theDArrayDimensionobject for the dimension requested. It makes sure that the dimension requested exists.- Throws:
InvalidDimensionException
-
getFirstDimension
public DArrayDimension getFirstDimension()
Returns theDArrayDimensionobject for the first dimension.
-
printXML
public void printXML(PrintWriter pw, String pad, boolean constrained)
-
printAsMapXML
public void printAsMapXML(PrintWriter pw, String pad, boolean constrained)
-
printConstraint
public void printConstraint(PrintWriter os)
- Overrides:
printConstraintin classBaseType
-
cloneDAG
public DArray cloneDAG(DAPNode.CloneMap map) throws CloneNotSupportedException
Returns a clone of thisArray. See DAPNode.cloneDag()- Overrides:
cloneDAGin classDVector- Parameters:
map- track previously cloned nodes- Returns:
- a clone of this object.
- Throws:
CloneNotSupportedException
-
-