ncsa.hdf.object.nc2
Class NC2Datatype

java.lang.Object
  extended by ncsa.hdf.object.HObject
      extended by ncsa.hdf.object.Datatype
          extended by ncsa.hdf.object.nc2.NC2Datatype
All Implemented Interfaces:
java.io.Serializable, DataFormat

public class NC2Datatype
extends Datatype

Datatype encapsulates information of a datatype. Information includes the class, size, endian of a datatype.

Version:
1.1 9/4/2007
Author:
Peter X. Cao
See Also:
Serialized Form

Field Summary
static long serialVersionUID
           
 
Fields inherited from class ncsa.hdf.object.Datatype
CLASS_ARRAY, CLASS_BITFIELD, CLASS_CHAR, CLASS_COMPOUND, CLASS_ENUM, CLASS_FLOAT, CLASS_INTEGER, CLASS_NO_CLASS, CLASS_OPAQUE, CLASS_REFERENCE, CLASS_STRING, CLASS_VLEN, NATIVE, NSGN, ORDER_BE, ORDER_LE, ORDER_NONE, ORDER_VAX, SIGN_2, SIGN_NONE
 
Fields inherited from class ncsa.hdf.object.HObject
separator
 
Constructor Summary
NC2Datatype(ucar.ma2.DataType theType)
          Create a Datatype with a given Netcdf native datatype.
NC2Datatype(int tclass, int tsize, int torder, int tsign)
          Create an Datatype with specified class, size, byte order and sign.
 
Method Summary
static java.lang.Object allocateArray(ucar.ma2.DataType dtype, int size)
          Allocate an one-dimensional array of byte, short, int, long, float, double, or String to store data retrieved from an Netcdf file based on the given Netcdf datatype and dimension sizes.
 void close(int id)
          Closes a datatype identifier.
 void fromNative(int tid)
          Translate Netcdf datatype identifier into NC2Datatype.
 java.lang.String getDatatypeDescription()
          Returns a short text description of this datatype.
 java.util.List getMetadata(int... attrPropList)
           
 boolean hasAttribute()
          Check if the object has any attributes attached.
 boolean isUnsigned()
          Checks if this datatype is an unsigned integer.
 int toNative()
          Converts the datatype object to a native datatype.
 
Methods inherited from class ncsa.hdf.object.Datatype
getBasetype, getDatatypeClass, getDatatypeOrder, getDatatypeSign, getDatatypeSize, getEnumMembers, getMetadata, open, removeMetadata, setEnumMembers, writeMetadata
 
Methods inherited from class ncsa.hdf.object.HObject
equalsOID, getFID, getFile, getFileFormat, getFullName, getLinkTargetObjName, getName, getOID, getPath, setLinkTargetObjName, setName, setPath, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

NC2Datatype

public NC2Datatype(int tclass,
                   int tsize,
                   int torder,
                   int tsign)
Create an Datatype with specified class, size, byte order and sign. The following list a few example of how to create a Datatype.
  1. to create unsigned native integer
    NC2Datatype type = new H5Dataype(CLASS_INTEGER, NATIVE, NATIVE, SIGN_NONE);
  2. to create 16-bit signed integer with big endian
    NC2Datatype type = new H5Dataype(CLASS_INTEGER, 2, ORDER_BE, NATIVE);
  3. to create native float
    NC2Datatype type = new H5Dataype(CLASS_FLOAT, NATIVE, NATIVE, -1);
  4. to create 64-bit double
    NC2Datatype type = new H5Dataype(CLASS_FLOAT, 8, NATIVE, -1);

Parameters:
tclass - the class of the datatype.
tsize - the size of the datatype in bytes.
torder - the order of the datatype.
tsign - the sign of the datatype.

NC2Datatype

public NC2Datatype(ucar.ma2.DataType theType)
Create a Datatype with a given Netcdf native datatype.

Parameters:
theType - the netcdf native datatype.
Method Detail

hasAttribute

public boolean hasAttribute()
Description copied from interface: DataFormat
Check if the object has any attributes attached.

Returns:
true if it has any attribute(s), false otherwise.

allocateArray

public static java.lang.Object allocateArray(ucar.ma2.DataType dtype,
                                             int size)
                                      throws java.lang.OutOfMemoryError
Allocate an one-dimensional array of byte, short, int, long, float, double, or String to store data retrieved from an Netcdf file based on the given Netcdf datatype and dimension sizes.

Parameters:
dtype - the netdcdf datatype.
size - the total size of the array.
Returns:
the array object if successful and null otherwise.
Throws:
java.lang.OutOfMemoryError

fromNative

public void fromNative(int tid)
Translate Netcdf datatype identifier into NC2Datatype.

Specified by:
fromNative in class Datatype
Parameters:
nativeID - the netcdf native datatype.

getDatatypeDescription

public java.lang.String getDatatypeDescription()
Description copied from class: Datatype
Returns a short text description of this datatype.

Overrides:
getDatatypeDescription in class Datatype
Returns:
a short text description of this datatype

isUnsigned

public boolean isUnsigned()
Description copied from class: Datatype
Checks if this datatype is an unsigned integer.

Specified by:
isUnsigned in class Datatype
Returns:
true if the datatype is an unsigned integer; otherwise, returns false.

toNative

public int toNative()
Description copied from class: Datatype
Converts the datatype object to a native datatype. Subclasses must implement it so that this datatype will be converted accordingly. Use close() to close the native identifier; otherwise, the datatype will be left open.

For example, a HDF5 datatype created from

 H5Dataype dtype = new H5Datatype(CLASS_INTEGER, 4, NATIVE, SIGN_NONE);
 int tid = dtype.toNative();
 
There "tid" will be the HDF5 datatype id of a 32-bit unsigned integer, which is equivalent to
 int tid = H5.H5Tcopy(HDF5Constants.H5T_NATIVE_UNINT32);
 

Specified by:
toNative in class Datatype
Returns:
the identifier of the native datatype.

close

public void close(int id)
Description copied from class: Datatype
Closes a datatype identifier.

Sub-clases must replace this default implementation.

Specified by:
close in class Datatype
Parameters:
id - the datatype identifier to close.

getMetadata

public java.util.List getMetadata(int... attrPropList)
                           throws java.lang.Exception
Throws:
java.lang.Exception