Package opendap.dap
Class DGrid
- java.lang.Object
-
- opendap.dap.DAPNode
-
- opendap.dap.BaseType
-
- opendap.dap.DConstructor
-
- opendap.dap.DGrid
-
- All Implemented Interfaces:
Serializable
,Cloneable
,ClientIO
public class DGrid extends DConstructor implements ClientIO
This class holds aDArray
and a set of "Map" vectors. The Map vectors are one-dimensional arrays corresponding to each dimension of the centralArray
. Using this scheme, aGrid
can represent, in a rectilinear array, data which is not in reality rectilinear. An example will help make this clear. Assume that the following array contains measurements of some real quantity, conducted at nine different points in space:
To locate thisA = [ 1 2 3 4 ] [ 2 4 6 8 ] [ 3 6 9 12]
Array
in the real world, we could note the location of one corner of the grid, and the grid spacing. This would allow us to calculate the location of any of the other points of theArray
. This approach will not work, however, unless the grid spacing is precisely regular. If the distance between Row 1 and Row 2 is not the same as the distance between Row 2 and Row 3, the scheme will break down. The solution is to equip theArray
with twoMap
vectors that define the location of each row or column of the array:
The real location of the point in the first row and column of the array is now exactly fixed at (0,0), and the point in the last row and last column is at (8,27).A = [ 1 2 3 4 ] Row = [ 0 ] [ 2 4 6 8 ] [ 3 ] [ 3 6 9 12] [ 8 ] Column = [ 0 2 8 27]
- See Also:
BaseType
,DArray
, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class opendap.dap.DAPNode
DAPNode.CloneMap
-
-
Field Summary
Fields Modifier and Type Field Description static int
ARRAY
TheArray
part of theDGrid
protected DArray
arrayVar
The Array component of thisDGrid
.static int
MAPS
The Map part of theDGrid
protected Vector
mapVars
The Map component of thisDGrid
.-
Fields inherited from class opendap.dap.DAPNode
_nameClear, _nameEncoded, log
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addVariable(BaseType v, int part)
Adds a variable to the container.void
checkSemantics(boolean all)
Checks for internal consistency.DAPNode
cloneDAG(DAPNode.CloneMap map)
Returns a clone of thisDGrid
.void
deserialize(DataInputStream source, ServerVersion sv, StatusUI statusUI)
Reads data from aDataInputStream
.int
elementCount(boolean leaves)
Returns the number of variables contained in this object.void
externalize(DataOutputStream sink)
Writes data to aDataOutputStream
.DArray
getArray()
Vector<DArrayDimension>
getArrayDims()
String
getTypeName()
Returns the OPeNDAP type name of the class instance as aString
.BaseType
getVar(int index)
Gets the indexed variable.int
getVarCount()
Get the number of contained variables (for use with getVar()BaseType
getVariable(String name)
Returns the named variable.Enumeration
getVariables()
Return an Enumeration that can be used to iterate over the members of a Structure.void
printDecl(PrintWriter os, String space, boolean print_semi, boolean constrained)
Write the variable's declaration in a C-style syntax.void
printVal(PrintWriter os, String space, boolean print_decl_p)
Prints the value of the variable, with its declaration.void
printXML(PrintWriter pw, String pad, boolean constrained)
int
projectedComponents(boolean constrained)
How many prohected components of this Grid object?boolean
projectionYieldsGrid(boolean constrained)
When projected (using whatever the current constraint provides in the way of a projection) am I still a Grid?-
Methods inherited from class opendap.dap.DConstructor
addVariable, someChildHasAttributes
-
Methods inherited from class opendap.dap.BaseType
addAttributeAlias, addAttributeContainer, appendAttribute, appendAttribute, appendAttributeContainer, checkSemantics, delAttribute, delAttribute, elementCount, getAttribute, getAttribute, getAttributeNames, getAttributeTable, getLongName, hasAttributes, newPrimitiveVector, printAttributes, printAttributes, printAttributes, printAttributes, printConstraint, 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
-
ARRAY
public static final int ARRAY
TheArray
part of theDGrid
- See Also:
- Constant Field Values
-
MAPS
public static final int MAPS
The Map part of theDGrid
- See Also:
- Constant Field Values
-
arrayVar
protected DArray arrayVar
The Array component of thisDGrid
.
-
mapVars
protected Vector mapVars
The Map component of thisDGrid
.
-
-
Constructor Detail
-
DGrid
public DGrid()
Constructs a newDGrid
.
-
DGrid
public DGrid(String n)
Constructs a newDGrid
with 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
.- Specified by:
getTypeName
in classBaseType
- Returns:
- the OPeNDAP type name of the class instance as a
String
.
-
elementCount
public int elementCount(boolean leaves)
Returns the number of variables contained in this object. For simple and vector type variables, it always returns 1. To count the number of simple-type variable in the variable tree rooted at this variable, setleaves
totrue
.- Overrides:
elementCount
in classBaseType
- Parameters:
leaves
- If true, count all the simple types in the `tree' of variables rooted at this variable.- Returns:
- the number of contained variables.
-
addVariable
public void addVariable(BaseType v, int part)
Adds a variable to the container.- Specified by:
addVariable
in classDConstructor
- Parameters:
v
- the variable to add.part
- the part of theDGrid
to be modified. Allowed values areARRAY
orMAPS
.- Throws:
IllegalArgumentException
- if an invalid part was given.
-
getVariable
public BaseType getVariable(String name) throws NoSuchVariableException
Returns the named variable.- Specified by:
getVariable
in classDConstructor
- Parameters:
name
- the name of the variable.- Returns:
- the named variable.
- Throws:
NoSuchVariableException
- if the named variable does not exist in this container.
-
getVar
public BaseType getVar(int index) throws NoSuchVariableException
Gets the indexed variable. For a DGrid the index 0 returns theDArray
and indexes 1 and higher return the associated mapVector
s.- Specified by:
getVar
in classDConstructor
- Parameters:
index
- the index of the variable in theVector
Vars.- Returns:
- the indexed variable.
- Throws:
NoSuchVariableException
- if the named variable does not exist in this container.
-
getVarCount
public int getVarCount()
Get the number of contained variables (for use with getVar()- Specified by:
getVarCount
in classDConstructor
- Returns:
- the number of contained variables
-
getVariables
public Enumeration getVariables()
Return an Enumeration that can be used to iterate over the members of a Structure. This implementation provides access to the elements of the Structure. Each Object returned by the Enumeration can be cast to a BaseType.- Specified by:
getVariables
in classDConstructor
- Returns:
- An Enumeration
-
checkSemantics
public void checkSemantics(boolean all) throws BadSemanticsException
Checks for internal consistency. ForDGrid
, verify that the map variables have unique names and match the number of dimensions of the array variable.- Overrides:
checkSemantics
in 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:
printDecl
in classBaseType
- Parameters:
os
- ThePrintWriter
on 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 os, 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.- Specified by:
printVal
in classBaseType
- Parameters:
os
- thePrintWriter
on which to print the value.space
- this value is passed to theprintDecl
method, 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)
-
deserialize
public void deserialize(DataInputStream source, ServerVersion sv, StatusUI statusUI) throws IOException, DataReadException
Reads data from aDataInputStream
. This method is only used on the client side of the OPeNDAP client/server connection.- Specified by:
deserialize
in interfaceClientIO
- Parameters:
source
- aDataInputStream
to read from.sv
- theServerVersion
returned by the server.statusUI
- theStatusUI
object to use for GUI updates and user cancellation notification (may be null).- Throws:
EOFException
- if EOF is found before the variable is completely deserialized.IOException
- thrown on any other InputStream exception.DataReadException
- if an unexpected value was read.- See Also:
ClientIO.deserialize(DataInputStream, ServerVersion, StatusUI)
-
externalize
public void externalize(DataOutputStream sink) throws IOException
Writes data to aDataOutputStream
. This method is used primarily by GUI clients which need to download OPeNDAP data, manipulate it, and then re-save it as a binary file.- Specified by:
externalize
in interfaceClientIO
- Parameters:
sink
- aDataOutputStream
to write to.- Throws:
IOException
- thrown on anyOutputStream
exception.
-
printXML
public void printXML(PrintWriter pw, String pad, boolean constrained)
- Overrides:
printXML
in classDConstructor
- Parameters:
pw
- Where to printpad
- Padding for iondentation (makes the output easier for humans to read).constrained
- If true then only projected variables (and their Attributes) will be printed.
-
getArray
public DArray getArray()
-
getArrayDims
public Vector<DArrayDimension> getArrayDims()
-
projectedComponents
public int projectedComponents(boolean constrained)
How many prohected components of this Grid object?- Returns:
- The number of projected components.
-
projectionYieldsGrid
public boolean projectionYieldsGrid(boolean constrained)
When projected (using whatever the current constraint provides in the way of a projection) am I still a Grid?- Returns:
- True if projected grid is still a grid. False otherwise.
-
cloneDAG
public DAPNode cloneDAG(DAPNode.CloneMap map) throws CloneNotSupportedException
Returns a clone of thisDGrid
. See DAPNode.cloneDag()- Overrides:
cloneDAG
in classBaseType
- Parameters:
map
- track previously cloned nodes- Returns:
- a clone of this object.
- Throws:
CloneNotSupportedException
-
-