ucar.netcdf
Class ProtoVariable

java.lang.Object
  extended byucar.netcdf.ProtoVariable
All Implemented Interfaces:
Cloneable, MultiArrayInfo, Named, Serializable
Direct Known Subclasses:
ExportVar

public class ProtoVariable
extends Object
implements Named, MultiArrayInfo, Serializable, Cloneable

Prototype for Netcdf Variable. Instances of ProtoVariable provide the description of a Netcdf Variable without data i/o functionality. Instances of this class are used in a Schema, which is used when we create a new Netcdf. An instance has a name and a shape specified by an array of Dimensions. It may also have descriptive attributes. The attribute set is modifiable.

The data logically contained in a Netcdf Variable is not accessed through this object.

Although there is no explicit relationship between this class and and Variable, they share common method signatures and semantics where appropriate.

See Also:
Variable, Serialized Form

Constructor Summary
(package private) ProtoVariable(ProtoVariable pv)
          copy constructor.
  ProtoVariable(String name, Class componentType, Dimension dimension)
          Convenience constructor for 1-dimensional Variables, often used for coordinate variables.
  ProtoVariable(String name, Class componentType, Dimension[] dimArray)
          The usual constructor, used when you are going to add the attributes after construction.
  ProtoVariable(String name, Class componentType, Dimension[] dimArray, Attribute[] attrArray)
          More general constructor.
  ProtoVariable(Variable var)
          Conversion constructor.
 
Method Summary
(package private) static boolean checkComponentType(Class componentType)
          Check if the given Class corresponds to a netcdf type.
 Object clone()
          Returns a clone of this
(package private)  void connectDims(DimensionDictionary dimensions)
          Ensure that the dimensions referenced by this are members of the specified Dictionary.
 Attribute getAttribute(String name)
          Convenience function; look up Attribute by name.
 AttributeSet getAttributes()
          Returns the (modifiable) set of attributes associated with this.
 Class getComponentType()
          Returns the Class object representing the component type of the Variable.
 DimensionIterator getDimensionIterator()
          Returns a DimensionIterator of the dimensions used by this variable.
 int[] getLengths()
          Return an array whose length is the rank of this and whose elements represent the length of each of its dimensions.
 String getName()
          Returns the name of this Variable.
 int getRank()
          Returns the number of dimensions of the variable.
 boolean isScalar()
          Convenience interface; return true if and only if the rank is zero.
 boolean isUnlimited()
          Returns true if and only if the this variable can grow.
 Attribute putAttribute(Attribute attr)
          Convenience function; add attribute.
 void toCdl(StringBuffer buf)
          Format as CDL.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProtoVariable

public ProtoVariable(String name,
                     Class componentType,
                     Dimension[] dimArray)
The usual constructor, used when you are going to add the attributes after construction.

Parameters:
name - String which is to be the name of this Variable
componentType - Class (primitive type) contained herein. One of Character.Type, Byte.TYPE, Short.TYPE, Integer.TYPE, Float.TYPE, or Double.Type.
dimArray - The dimensions which define the shape of this Variable. If null or zero length array, this is a scalar variable.

ProtoVariable

public ProtoVariable(String name,
                     Class componentType,
                     Dimension dimension)
Convenience constructor for 1-dimensional Variables, often used for coordinate variables. Typically attributes would be added after construction when this constructor is used.

Parameters:
name - String which is to be the name of this Variable
componentType - Class (primitive type) contained herein. One of Character.Type, Byte.TYPE, Short.TYPE, Integer.TYPE, Float.TYPE, or Double.Type.
dimension - A single dimension to define the array.

ProtoVariable

public ProtoVariable(String name,
                     Class componentType,
                     Dimension[] dimArray,
                     Attribute[] attrArray)
More general constructor. Initializes attribute set during construction.

Parameters:
name - String which is to be the name of this Variable
componentType - Class (primitive type) contained herein. One of Character.Type, Byte.TYPE, Short.TYPE, Integer.TYPE, Float.TYPE, or Double.Type.
dimArray - The dimensions which define the shape of this Variable. If null or zero length array, this is a scalar variable.
attrArray - Attributes associated with this Variable. May be null or a zero length array.

ProtoVariable

ProtoVariable(ProtoVariable pv)
copy constructor.


ProtoVariable

public ProtoVariable(Variable var)
Conversion constructor.

Method Detail

checkComponentType

static final boolean checkComponentType(Class componentType)
Check if the given Class corresponds to a netcdf type. This method is used to check Attributes as well...

Parameters:
componentType - Class to check
Returns:
true if Okay, false otherwise.

clone

public Object clone()
Returns a clone of this


getName

public final String getName()
Returns the name of this Variable.

Specified by:
getName in interface Named
Returns:
String which identifies this Variable.

getComponentType

public final Class getComponentType()
Returns the Class object representing the component type of the Variable.

Specified by:
getComponentType in interface MultiArrayInfo
Returns:
Class The componentType
See Also:
Class.getComponentType()

getRank

public final int getRank()
Returns the number of dimensions of the variable.

Specified by:
getRank in interface MultiArrayInfo
Returns:
int number of dimensions of the variable

getLengths

public final int[] getLengths()
Return an array whose length is the rank of this and whose elements represent the length of each of its dimensions.

Specified by:
getLengths in interface MultiArrayInfo
Returns:
int array whose length is the rank of this and whose elements represent the length of each of its dimensions

isUnlimited

public final boolean isUnlimited()
Returns true if and only if the this variable can grow. This is equivalent to saying at least one of its dimensions is unlimited. In the current implementation, exactly one dimension, the most slowly varying (leftmost), can be unlimited.

Specified by:
isUnlimited in interface MultiArrayInfo
Returns:
boolean true iff this can grow

isScalar

public final boolean isScalar()
Convenience interface; return true if and only if the rank is zero.

Specified by:
isScalar in interface MultiArrayInfo
Returns:
boolean true iff rank == 0

getDimensionIterator

public DimensionIterator getDimensionIterator()
Returns a DimensionIterator of the dimensions used by this variable. The most slowly varying (leftmost for java and C programmers) dimension is first. For scalar variables, the set has no elements and the iteration is empty.

Returns:
DimensionIterator of the elements.
See Also:
DimensionIterator

getAttribute

public Attribute getAttribute(String name)
Convenience function; look up Attribute by name.

Parameters:
name - the name of the attribute
Returns:
the attribute, or null if not found

getAttributes

public AttributeSet getAttributes()
Returns the (modifiable) set of attributes associated with this.

Returns:
AttributeSet. May be empty. Won't be null.

putAttribute

public Attribute putAttribute(Attribute attr)
Convenience function; add attribute.

Parameters:
attr - the Attribute to be added to this set.
Returns:
Attribute replaced or null if not a replacement
See Also:
AttributeSet.put(ucar.netcdf.Attribute)

toCdl

public void toCdl(StringBuffer buf)
Format as CDL.

Parameters:
buf - StringBuffer into which to write

toString

public String toString()
Returns:
a string representation of this

connectDims

void connectDims(DimensionDictionary dimensions)
Ensure that the dimensions referenced by this are members of the specified Dictionary. This may modify dimArray elements to reference different (equivalent) dimension instances. package private