ncsa.hdf.object.h4
Class H4Datatype

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

public class H4Datatype
extends Datatype

This class defines HDF4 data type characteristics and APIs for a data type.

This class provides several methods to convert an HDF4 datatype identifier to a datatype object, and vice versa. A datatype object is described by four basic fields: datatype class, size, byte order, and sign, while an HDF5 datatype is presented by a datatype identifier.

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
H4Datatype(int nativeID)
          Constructs a H4Datatype with a given native datatype identifier.
H4Datatype(int tclass, int tsize, int torder, int tsign)
          Constructs a H4Datatype with specified class, size, byte order and sign.
 
Method Summary
static java.lang.Object allocateArray(int datatype, int datasize)
          Allocate a 1D array large enough to hold a multidimensional array of 'datasize' elements of 'datatype' numbers.
 void close(int id)
          Closes a datatype identifier.
 void fromNative(int tid)
          Set datatype characteristics (class, size, byte order and sign) from a given datatye identifier.
 java.lang.String getDatatypeDescription()
          Returns a short text description of this datatype.
static java.lang.String getDatatypeDescription(int datatype)
          Returns the short description of a given 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.
static boolean isUnsigned(int datatype)
          Checks if the 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:
HObject.serialVersionUID, Constant Field Values
Constructor Detail

H4Datatype

public H4Datatype(int tclass,
                  int tsize,
                  int torder,
                  int tsign)
Constructs a H4Datatype with specified class, size, byte order and sign.

The following is a list of a few example of H5Datatype.

  1. to create unsigned native integer
    H4Datatype type = new H4Dataype(CLASS_INTEGER, NATIVE, NATIVE, SIGN_NONE);
  2. to create 16-bit signed integer with big endian
    H4Datatype type = new H4Dataype(CLASS_INTEGER, 2, ORDER_BE, NATIVE);
  3. to create native float
    H4Datatype type = new H4Dataype(CLASS_FLOAT, NATIVE, NATIVE, -1);
  4. to create 64-bit double
    H4Datatype type = new H4Dataype(CLASS_FLOAT, 8, NATIVE, -1);

Parameters:
tclass - the class of the datatype, e.g. CLASS_INTEGER, CLASS_FLOAT and etc.
tsize - the size of the datatype in bytes, e.g. for a 32-bit integer, the size is 4.
torder - the byte order of the datatype. Valid values are ORDER_LE, ORDER_BE, ORDER_VAX and ORDER_NONE
tsign - the sign of the datatype. Valid values are SIGN_NONE, SIGN_2 and MSGN

H4Datatype

public H4Datatype(int nativeID)
Constructs a H4Datatype with a given native datatype identifier.

For example,

 Datatype dtype = new H4Datatype(HDFConstants.DFNT_INT32);
 
will construct a datatype equivalent to new H4Datatype(CLASS_INTEGER, 4, NATIVE, SIGN_NONE);

Parameters:
nativeID - the native datatype identifier.
See Also:
fromNative(int nativeID)
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.

fromNative

public void fromNative(int tid)
Description copied from class: Datatype
Set datatype characteristics (class, size, byte order and sign) from a given datatye identifier.

Sub-classes must implement it so that this datatype will be converted accordingly.

For example, if the type identifier is a 32-bit unsigned integer created from HDF5,

 H5Datatype dtype = new H5Datatype();
 dtype.fromNative(HDF5Constants.H5T_NATIVE_UNINT32);
 
Where dtype is equivalent to
new H5Datatype(CLASS_INTEGER, 4, NATIVE, SIGN_NONE);

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

allocateArray

public static final java.lang.Object allocateArray(int datatype,
                                                   int datasize)
                                            throws java.lang.OutOfMemoryError
Allocate a 1D array large enough to hold a multidimensional array of 'datasize' elements of 'datatype' numbers.

Parameters:
datatype - the data type
datasize - the size of the data array
Returns:
an array of 'datasize' numbers of datatype.
Throws:
java.lang.OutOfMemoryError

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

getDatatypeDescription

public static final java.lang.String getDatatypeDescription(int datatype)
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 if 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 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