ncsa.hdf.object.h5
Class H5Datatype

java.lang.Object
  extended byncsa.hdf.object.HObject
      extended byncsa.hdf.object.Datatype
          extended byncsa.hdf.object.h5.H5Datatype
All Implemented Interfaces:
DataFormat, java.io.Serializable

public class H5Datatype
extends Datatype

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

See Also:
Serialized Form

Field Summary
 
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, datatypeClass, datatypeOrder, datatypeSign, datatypeSize, NATIVE, nativeID, NSGN, ORDER_BE, ORDER_LE, ORDER_NONE, ORDER_VAX, SIGN_2, SIGN_NONE
 
Fields inherited from class ncsa.hdf.object.HObject
hasAttribute, oid, separator
 
Constructor Summary
H5Datatype(FileFormat fileFormat, java.lang.String name, java.lang.String path, long[] oid)
          Constructs a named H5Datatype object with specific name and path.
H5Datatype(int nativeID)
          Create a Datatype with a given HDF native datatype.
H5Datatype(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(int tid, int size)
          Allocate an one-dimensional array of byte, short, int, long, float, double, or String to store data retrieved from an HDF5 file based on the given HDF5 datatype and dimension sizes.
 void close(int tid)
          Closes access to this object.
 void fromNative(int tid)
          Translate HDF5 datatype identifier into H5Datatype.
 java.lang.String getDatatypeDescription()
          Returns a short text description of this datatype.
static java.lang.String getDatatypeDescription(int tid)
          Returns the short description of a given datatype.
static int getDatatypeSize(int tid)
          Returns the size of this datatype in bytes.
 java.util.List getMetadata()
          Loads the metadata such as attributes and type of the the data object into memory if the metadata is not loaded.
 boolean isUnsigned()
          Checks if this datatype is an unsigned integer.
static boolean isUnsigned(int datatype)
          Checks if the datatype is an unsigned integer.
 int open()
          Opens access to this object.
 void removeMetadata(java.lang.Object info)
          Deletes an existing metadata from this data object.
 int toNative()
          Converts this datatype to a user defined datatype.
static int toNative(int tid)
          Return the HDF5 native datatype based on the HDF5 datatype on disk For example, a HDF5 datatype created from
 void writeMetadata(java.lang.Object info)
          Saves a specific metadata into file.
 
Methods inherited from class ncsa.hdf.object.Datatype
getDatatypeClass, getDatatypeOrder, getDatatypeSign, getDatatypeSize
 
Methods inherited from class ncsa.hdf.object.HObject
equalsOID, getFID, getFile, getFileFormat, getName, getOID, getPath, hasAttribute, setName, setPath, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

H5Datatype

public H5Datatype(FileFormat fileFormat,
                  java.lang.String name,
                  java.lang.String path,
                  long[] oid)
Constructs a named H5Datatype object with specific name and path.

Parameters:
fileFormat - the HDF file.
name - the name of this H5Datatype.
path - the full path of this H5Datatype.
oid - the unique identifier of this H5Datatype.

H5Datatype

public H5Datatype(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
    H5Datatype type = new H5Dataype(CLASS_INTEGER, NATIVE, NATIVE, SIGN_NONE);
  2. to create 16-bit signed integer with big endian
    H5Datatype type = new H5Dataype(CLASS_INTEGER, 2, ORDER_BE, NATIVE);
  3. to create native float
    H5Datatype type = new H5Dataype(CLASS_FLOAT, NATIVE, NATIVE, -1);
  4. to create 64-bit double
    H5Datatype 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.

H5Datatype

public H5Datatype(int nativeID)
Create a Datatype with a given HDF native datatype. The following example constructs an H5Datatype from an HDF5 32-bit unsigned integer.
 int user_type = H5.J2C( HDF5CDataTypes.JH5T_NATIVE_UNINT32);
 H5Datatype dtype = new H5atatype(user_type);
 
which is equivalent to
 H5Datatype dtype = new H5atatype(CLASS_INTEGER, 4, NATIVE, SIGN_NONE);
 

Parameters:
nativeID - the hdf native datatype.
Method Detail

fromNative

public void fromNative(int tid)
Translate HDF5 datatype identifier into H5Datatype. The following example constructs an H5Datatype from an HDF5 32-bit unsigned integer.
 int user_type = H5.J2C( HDF5CDataTypes.JH5T_NATIVE_UNINT32);
 H5Datatype dtype = new H5atatype(user_type);
 
which is equivalent to
 H5Datatype dtype = new H5atatype(CLASS_INTEGER, 4, NATIVE, SIGN_NONE);
 

Specified by:
fromNative in class Datatype
Parameters:
tid - the identifier of user defined datatype.

allocateArray

public static java.lang.Object allocateArray(int tid,
                                             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 HDF5 file based on the given HDF5 datatype and dimension sizes.

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

toNative

public static int toNative(int tid)
Return the HDF5 native datatype based on the HDF5 datatype on disk For example, a HDF5 datatype created from
 H5Dataype dtype = new H5Datatype(CLASS_INTEGER, 4, NATIVE, SIGN_NONE);
 int type = dtype.toNative();
 
here "type" will be the HDF5 datatype id of a 32-bit unsigned integer, which is equivalent to
 int type = H5.J2C( HDF5CDataTypes.JH5T_NATIVE_UNINT32);
 

Parameters:
tid - the datatype on disk.
Returns:
the native datatype if successful, and negative otherwise.

getDatatypeSize

public static final int getDatatypeSize(int tid)
Returns the size of this datatype in bytes.

Parameters:
tid - the data type.

getDatatypeDescription

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

Overrides:
getDatatypeDescription in class Datatype

getDatatypeDescription

public static final java.lang.String getDatatypeDescription(int tid)
Returns the short description of a given 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 is the datatype is an unsigned integer; otherwise returns false.

isUnsigned

public static final boolean isUnsigned(int datatype)
Checks if the datatype is an unsigned integer.

Parameters:
datatype - the data type.
Returns:
True is the datatype is an unsigned integer; otherwise returns false.

toNative

public int toNative()
Description copied from class: Datatype
Converts this datatype to a user defined datatype. Subclasses must implement it so that this datatype will be converted.

For example, a HDF5 datatype created from

 H5Dataype dtype = new H5Datatype(CLASS_INTEGER, 4, NATIVE, SIGN_NONE);
 int type = dtype.toNative();
 
here "type" will be the HDF5 datatype id of a 32-bit unsigned integer, which is equivalent to
 int type = H5.J2C( HDF5CDataTypes.JH5T_NATIVE_UNINT32);
 

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

open

public int open()
Description copied from class: HObject
Opens access to this object.

Sub-classes have to implement this interface so that different data objects have their own ways of how the data resources are opened.

Overrides:
open in class Datatype

close

public void close(int tid)
Description copied from class: HObject
Closes access to this object.

Overrides:
close in class Datatype

getMetadata

public java.util.List getMetadata()
                           throws HDF5Exception
Description copied from interface: DataFormat
Loads the metadata such as attributes and type of the the data object into memory if the metadata is not loaded. If the metadata is loaded, it returns the metadata. The metadata is stored as a collection of metadata ojbects in a List.

Specified by:
getMetadata in interface DataFormat
Overrides:
getMetadata in class Datatype
Throws:
HDF5Exception

writeMetadata

public void writeMetadata(java.lang.Object info)
                   throws java.lang.Exception
Description copied from interface: DataFormat
Saves a specific metadata into file. If the metadata exists, it updates its value. If the metadata does not exists, it creates and attach the new metadata to the object and saves it into file.

Specified by:
writeMetadata in interface DataFormat
Overrides:
writeMetadata in class Datatype
Throws:
java.lang.Exception

removeMetadata

public void removeMetadata(java.lang.Object info)
                    throws HDF5Exception
Description copied from interface: DataFormat
Deletes an existing metadata from this data object.

Specified by:
removeMetadata in interface DataFormat
Overrides:
removeMetadata in class Datatype
Throws:
HDF5Exception