Class Datatype
- Object
-
- hdf.object.HObject
-
- hdf.object.Datatype
-
- All Implemented Interfaces:
MetaDataContainer
,Serializable
public abstract class Datatype extends HObject implements MetaDataContainer
Datatype is an abstract class that defines datatype characteristics and APIs for a data type.A datatype has four basic characteristics: class, size, byte order and sign. These characteristics are defined in the HDF5 User's Guide.
These characteristics apply to all the sub-classes. The sub-classes may have different ways to describe a datatype. We here define the native datatype to the datatype used by the sub-class. For example, H5Datatype uses a datatype identifier (hid_t) to specify a datatype. NC2Datatype uses ucar.nc2.DataType object to describe its datatype. "Native" here is different from the "native" definition in the HDF5 library.
Two functions, createNative() and fromNative(), are defined to convert the general characteristics to/from the native datatype. Sub-classes must implement these functions so that the conversion will be done correctly. The values of the CLASS member are not identical to HDF5 values for a datatype class.
- Version:
- 1.1 9/4/2007
- Author:
- Peter X. Cao
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected long[]
arrayDims
The dimensions of the ARRAY element of an ARRAY datatype.protected Datatype
baseType
The base datatype of this datatype (null if this datatype is atomic).static int
CLASS_ARRAY
static int
CLASS_BITFIELD
static int
CLASS_CHAR
static int
CLASS_COMPOUND
static int
CLASS_ENUM
static int
CLASS_FLOAT
static int
CLASS_INTEGER
static int
CLASS_NO_CLASS
static int
CLASS_OPAQUE
static int
CLASS_REFERENCE
static int
CLASS_STRING
static int
CLASS_TIME
static int
CLASS_VLEN
protected List<String>
compoundMemberNames
The list of names of members of a compound Datatype.protected List<Long>
compoundMemberOffsets
The list of offsets of members of a compound Datatype.protected List<Datatype>
compoundMemberTypes
The list of types of members of a compound Datatype.protected int
datatypeClass
The class of the datatype.protected String
datatypeDescription
protected int
datatypeOrder
The byte order of the datatype.protected int
datatypeSign
The sign of the datatype.protected long
datatypeSize
The size (in bytes) of the datatype.protected Map<String,String>
enumMembers
The (name, value) pairs of enum members.protected boolean
isVariableStr
protected boolean
isVLEN
Determines whether this datatype is a variable-length type.static int
NATIVE
The default definition for datatype size, order, and sign.static int
NSGN
static int
ORDER_BE
static int
ORDER_LE
static int
ORDER_NONE
static int
ORDER_VAX
static int
SIGN_2
static int
SIGN_NONE
-
Fields inherited from class hdf.object.HObject
fileFormat, linkTargetObjName, oid, SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description Datatype(int tclass, int tsize, int torder, int tsign)
Constructs a Datatype with specified class, size, byte order and sign.Datatype(int tclass, int tsize, int torder, int tsign, Datatype tbase)
Constructs a Datatype with specified class, size, byte order and sign.Datatype(int tclass, int tsize, int torder, int tsign, Datatype tbase, Datatype pbase)
Constructs a Datatype with specified class, size, byte order and sign.Datatype(long tid)
Constructs a Datatype with a given native datatype identifier.Datatype(long tid, Datatype pbase)
Constructs a Datatype with a given native datatype identifier.Datatype(FileFormat theFile, String typeName, String typePath)
Constructs a named datatype with a given file, name and path.Datatype(FileFormat theFile, String typeName, String typePath, long[] oid)
Deprecated.Not for public use in the future.
UsingDatatype(FileFormat, String, String)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
close(long id)
Closes a datatype identifier.abstract long
createNative()
Converts the datatype object to a native datatype.abstract void
fromNative(long nativeID)
Set datatype characteristics (class, size, byte order and sign) from a given datatype identifier.long[]
getArrayDims()
Returns the dimensions of an Array Datatype.List<String>
getCompoundMemberNames()
List<Datatype>
getCompoundMemberTypes()
Datatype
getDatatypeBase()
Returns the base datatype for this datatype.int
getDatatypeClass()
Returns the class of the datatype.int
getDatatypeOrder()
Returns the byte order of the datatype.int
getDatatypeSign()
Returns the sign (SIGN_NONE, SIGN_2) of an integer datatype.long
getDatatypeSize()
Returns the size of the datatype in bytes.String
getDescription()
Returns a short text description of this datatype.Map<String,String>
getEnumMembers()
Returns the Map<String,String> pairs of enum members for enum datatype.String
getEnumMembersAsString()
Returns the HashMap pairs of enum members for enum datatype.List
getMetadata()
Retrieves the object's metadata, such as attributes, from the file.boolean
isArray()
Checks if this datatype is an array type.boolean
isBitField()
Checks if this datatype is a bitfield type.boolean
isChar()
Checks if this datatype is a character type.boolean
isCompound()
Checks if this datatype is an compound type.boolean
isEnum()
Checks if this datatype is a enum type.boolean
isFloat()
Checks if this datatype is a floating-point type.boolean
isInteger()
Checks if this datatype is an integer type.boolean
isOpaque()
Checks if this datatype is a opaque type.boolean
isRef()
Checks if this datatype is a reference type.boolean
isString()
Checks if this datatype is a string type.abstract boolean
isText()
boolean
isUnsigned()
Checks if this datatype is unsigned.boolean
isVarStr()
Checks if this datatype is a variable-length string type.boolean
isVLEN()
Checks if this datatype is a variable-length type.long
open()
Opens access to this named datatype.void
removeMetadata(Object info)
Deletes an existing piece of metadata from this object.void
setEnumMembers(String enumStr)
Sets the (key, value) pairs of enum members for enum datatype.String
toString()
Returns the name of the object.void
updateMetadata(Object info)
Updates an existing piece of metadata attached to this object.void
writeMetadata(Object info)
Writes a specific piece of metadata (such as an attribute) into the file.-
Methods inherited from class hdf.object.HObject
debug, equals, equals, equalsOID, getFID, getFile, getFileFormat, getFullName, getLinkTargetObjName, getName, getOID, getPath, hashCode, setLinkTargetObjName, setName, setPath
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface hdf.object.MetaDataContainer
hasAttribute
-
-
-
-
Field Detail
-
NATIVE
public static final int NATIVE
The default definition for datatype size, order, and sign.- See Also:
- Constant Field Values
-
CLASS_NO_CLASS
public static final int CLASS_NO_CLASS
- See Also:
- Constant Field Values
-
CLASS_INTEGER
public static final int CLASS_INTEGER
- See Also:
- Constant Field Values
-
CLASS_FLOAT
public static final int CLASS_FLOAT
- See Also:
- Constant Field Values
-
CLASS_CHAR
public static final int CLASS_CHAR
- See Also:
- Constant Field Values
-
CLASS_STRING
public static final int CLASS_STRING
- See Also:
- Constant Field Values
-
CLASS_BITFIELD
public static final int CLASS_BITFIELD
- See Also:
- Constant Field Values
-
CLASS_OPAQUE
public static final int CLASS_OPAQUE
- See Also:
- Constant Field Values
-
CLASS_COMPOUND
public static final int CLASS_COMPOUND
- See Also:
- Constant Field Values
-
CLASS_REFERENCE
public static final int CLASS_REFERENCE
- See Also:
- Constant Field Values
-
CLASS_ENUM
public static final int CLASS_ENUM
- See Also:
- Constant Field Values
-
CLASS_VLEN
public static final int CLASS_VLEN
- See Also:
- Constant Field Values
-
CLASS_ARRAY
public static final int CLASS_ARRAY
- See Also:
- Constant Field Values
-
CLASS_TIME
public static final int CLASS_TIME
- See Also:
- Constant Field Values
-
ORDER_LE
public static final int ORDER_LE
- See Also:
- Constant Field Values
-
ORDER_BE
public static final int ORDER_BE
- See Also:
- Constant Field Values
-
ORDER_VAX
public static final int ORDER_VAX
- See Also:
- Constant Field Values
-
ORDER_NONE
public static final int ORDER_NONE
- See Also:
- Constant Field Values
-
SIGN_NONE
public static final int SIGN_NONE
- See Also:
- Constant Field Values
-
SIGN_2
public static final int SIGN_2
- See Also:
- Constant Field Values
-
NSGN
public static final int NSGN
- See Also:
- Constant Field Values
-
datatypeDescription
protected String datatypeDescription
-
datatypeClass
protected int datatypeClass
The class of the datatype.
-
datatypeSize
protected long datatypeSize
The size (in bytes) of the datatype.
-
datatypeOrder
protected int datatypeOrder
The byte order of the datatype. Valid values are ORDER_LE, ORDER_BE, and ORDER_VAX.
-
datatypeSign
protected int datatypeSign
The sign of the datatype.
-
baseType
protected Datatype baseType
The base datatype of this datatype (null if this datatype is atomic).
-
arrayDims
protected long[] arrayDims
The dimensions of the ARRAY element of an ARRAY datatype.
-
isVLEN
protected boolean isVLEN
Determines whether this datatype is a variable-length type.
-
isVariableStr
protected boolean isVariableStr
-
enumMembers
protected Map<String,String> enumMembers
The (name, value) pairs of enum members.
-
compoundMemberNames
protected List<String> compoundMemberNames
The list of names of members of a compound Datatype.
-
compoundMemberTypes
protected List<Datatype> compoundMemberTypes
The list of types of members of a compound Datatype.
-
compoundMemberOffsets
protected List<Long> compoundMemberOffsets
The list of offsets of members of a compound Datatype.
-
-
Constructor Detail
-
Datatype
public Datatype(FileFormat theFile, String typeName, String typePath)
Constructs a named datatype with a given file, name and path.- Parameters:
theFile
- the HDF file.typeName
- the name of the datatype, e.g "12-bit Integer".typePath
- the full group path of the datatype, e.g. "/datatypes/".
-
Datatype
@Deprecated public Datatype(FileFormat theFile, String typeName, String typePath, long[] oid)
Deprecated.Not for public use in the future.
UsingDatatype(FileFormat, String, String)
- Parameters:
theFile
- the HDF file.typeName
- the name of the datatype, e.g "12-bit Integer".typePath
- the full group path of the datatype, e.g. "/datatypes/".oid
- the oidof the datatype.
-
Datatype
public Datatype(int tclass, int tsize, int torder, int tsign) throws Exception
Constructs a Datatype with specified class, size, byte order and sign.The following is a list of a few examples of Datatype.
- to create unsigned native integer
Datatype type = new Dataype(Datatype.CLASS_INTEGER, Datatype.NATIVE, Datatype.NATIVE, Datatype.SIGN_NONE); - to create 16-bit signed integer with big endian
Datatype type = new Dataype(Datatype.CLASS_INTEGER, 2, Datatype.ORDER_BE, Datatype.NATIVE); - to create native float
Datatype type = new Dataype(Datatype.CLASS_FLOAT, Datatype.NATIVE, Datatype.NATIVE, Datatype.NATIVE); - to create 64-bit double
Datatype type = new Dataype(Datatype.CLASS_FLOAT, 8, Datatype.NATIVE, Datatype.NATIVE);
- 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. Valid values are NATIVE or a positive value.torder
- the byte order of the datatype. Valid values are ORDER_LE, ORDER_BE, ORDER_VAX, ORDER_NONE and NATIVE.tsign
- the sign of the datatype. Valid values are SIGN_NONE, SIGN_2 and NATIVE.- Throws:
Exception
- if there is an error
- to create unsigned native integer
-
Datatype
public Datatype(int tclass, int tsize, int torder, int tsign, Datatype tbase) throws Exception
Constructs a Datatype with specified class, size, byte order and sign.The following is a list of a few examples of Datatype.
- to create unsigned native integer
Datatype type = new Dataype(Datatype.CLASS_INTEGER, Datatype.NATIVE, Datatype.NATIVE, Datatype.SIGN_NONE); - to create 16-bit signed integer with big endian
Datatype type = new Dataype(Datatype.CLASS_INTEGER, 2, Datatype.ORDER_BE, Datatype.NATIVE); - to create native float
Datatype type = new Dataype(Datatype.CLASS_FLOAT, Datatype.NATIVE, Datatype.NATIVE, Datatype.NATIVE); - to create 64-bit double
Datatype type = new Dataype(Datatype.CLASS_FLOAT, 8, Datatype.NATIVE, Datatype.NATIVE);
- 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. Valid values are NATIVE or a positive value.torder
- the byte order of the datatype. Valid values are ORDER_LE, ORDER_BE, ORDER_VAX, ORDER_NONE and NATIVE.tsign
- the sign of the datatype. Valid values are SIGN_NONE, SIGN_2 and NATIVE.tbase
- the base datatype of the new datatype- Throws:
Exception
- if there is an error
- to create unsigned native integer
-
Datatype
public Datatype(int tclass, int tsize, int torder, int tsign, Datatype tbase, Datatype pbase) throws Exception
Constructs a Datatype with specified class, size, byte order and sign.The following is a list of a few examples of Datatype.
- to create unsigned native integer
Datatype type = new Dataype(Datatype.CLASS_INTEGER, Datatype.NATIVE, Datatype.NATIVE, Datatype.SIGN_NONE); - to create 16-bit signed integer with big endian
Datatype type = new Dataype(Datatype.CLASS_INTEGER, 2, Datatype.ORDER_BE, Datatype.NATIVE); - to create native float
Datatype type = new Dataype(Datatype.CLASS_FLOAT, Datatype.NATIVE, Datatype.NATIVE, Datatype.NATIVE); - to create 64-bit double
Datatype type = new Dataype(Datatype.CLASS_FLOAT, 8, Datatype.NATIVE, Datatype.NATIVE);
- 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. Valid values are NATIVE or a positive value.torder
- the byte order of the datatype. Valid values are ORDER_LE, ORDER_BE, ORDER_VAX, ORDER_NONE and NATIVE.tsign
- the sign of the datatype. Valid values are SIGN_NONE, SIGN_2 and NATIVE.tbase
- the base datatype of the new datatypepbase
- the parent datatype of the new datatype- Throws:
Exception
- if there is an error
- to create unsigned native integer
-
Datatype
public Datatype(long tid) throws Exception
Constructs a Datatype with a given native datatype identifier.For example, if the datatype identifier is a 32-bit unsigned integer created from HDF5,
long tid = H5.H5Tcopy(HDF5Constants.H5T_NATIVE_UNINT32); Datatype dtype = new Datatype(tid);
will construct a datatype equivalent to new Datatype(CLASS_INTEGER, 4, NATIVE, SIGN_NONE);- Parameters:
tid
- the native datatype identifier.- Throws:
Exception
- if there is an error- See Also:
fromNative(long tid)
-
Datatype
public Datatype(long tid, Datatype pbase) throws Exception
Constructs a Datatype with a given native datatype identifier.For example, if the datatype identifier is a 32-bit unsigned integer created from HDF5,
long tid = H5.H5Tcopy(HDF5Constants.H5T_NATIVE_UNINT32); Datatype dtype = new Datatype(tid);
will construct a datatype equivalent to new Datatype(CLASS_INTEGER, 4, NATIVE, SIGN_NONE);- Parameters:
tid
- the native datatype identifier.pbase
- the parent datatype of the new datatype- Throws:
Exception
- if there is an error- See Also:
fromNative(long tid)
-
-
Method Detail
-
open
public long open()
Opens access to this named datatype. Sub-classes must replace this default implementation. For example, in H5Datatype, open() function H5.H5Topen(loc_id, name) to get the datatype identifier.- Specified by:
open
in classHObject
- Returns:
- the datatype identifier if successful; otherwise returns negative value.
- See Also:
HObject.close(long)
-
close
public abstract void close(long id)
Closes a datatype identifier.Sub-classes must replace this default implementation.
-
getDatatypeClass
public int getDatatypeClass()
Returns the class of the datatype. Valid values are:- CLASS_NO_CLASS
- CLASS_INTEGER
- CLASS_FLOAT
- CLASS_CHAR
- CLASS_STRING
- CLASS_BITFIELD
- CLASS_OPAQUE
- CLASS_COMPOUND
- CLASS_REFERENCE
- CLASS_ENUM
- CLASS_VLEN
- CLASS_ARRAY
- Returns:
- the class of the datatype.
-
getDatatypeSize
public long getDatatypeSize()
Returns the size of the datatype in bytes. For example, for a 32-bit integer, the size is 4 (bytes).- Returns:
- the size of the datatype.
-
getDatatypeOrder
public int getDatatypeOrder()
Returns the byte order of the datatype. Valid values are- ORDER_LE
- ORDER_BE
- ORDER_VAX
- ORDER_NONE
- Returns:
- the byte order of the datatype.
-
getDatatypeSign
public int getDatatypeSign()
Returns the sign (SIGN_NONE, SIGN_2) of an integer datatype.- Returns:
- the sign of the datatype.
-
getDatatypeBase
public Datatype getDatatypeBase()
Returns the base datatype for this datatype.For example, in a dataset of type ARRAY of integer, the datatype of the dataset is ARRAY. The datatype of the base type is integer.
- Returns:
- the datatype of the contained basetype.
-
setEnumMembers
public final void setEnumMembers(String enumStr)
Sets the (key, value) pairs of enum members for enum datatype.For Example,
- setEnumMembers("-40=lowTemp, 90=highTemp")
- sets the key of enum member lowTemp to -40 and highTemp to 90.
- setEnumMembers("lowTemp, highTemp")
- sets enum members to defaults, i.e. 0=lowTemp and 1=highTemp
- setEnumMembers("10=lowTemp, highTemp")
- sets enum member lowTemp to 10 and highTemp to 11.
- Parameters:
enumStr
- the (key, value) pairs of enum members
-
getEnumMembers
public final Map<String,String> getEnumMembers()
Returns the Map<String,String> pairs of enum members for enum datatype.- Returns:
- enumStr Map<String,String%gt; pairs of enum members
-
getEnumMembersAsString
public final String getEnumMembersAsString()
Returns the HashMap pairs of enum members for enum datatype.For Example,
- getEnumMembersAsString()
- returns "10=lowTemp, 40=highTemp"
- Returns:
- enumStr the (key, value) pairs of enum members
-
getArrayDims
public final long[] getArrayDims()
Returns the dimensions of an Array Datatype.- Returns:
- dims the dimensions of the Array Datatype
-
getCompoundMemberNames
public final List<String> getCompoundMemberNames()
-
getCompoundMemberTypes
public final List<Datatype> getCompoundMemberTypes()
-
createNative
public abstract long createNative()
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.createNative();
The "tid" will be the HDF5 datatype id of a 64-bit unsigned integer, which is equivalent toint tid = H5.H5Tcopy(HDF5Constants.H5T_NATIVE_UNINT32);
- Returns:
- the identifier of the native datatype.
-
fromNative
public abstract void fromNative(long nativeID)
Set datatype characteristics (class, size, byte order and sign) from a given datatype identifier.Sub-classes must implement it so that this datatype will be converted accordingly.
For example, if the type identifier is a 64-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);- Parameters:
nativeID
- the datatype identifier.
-
getDescription
public String getDescription()
Returns a short text description of this datatype.- Returns:
- a short text description of this datatype
-
isUnsigned
public boolean isUnsigned()
Checks if this datatype is unsigned.- Returns:
- true if the datatype is unsigned; otherwise, returns false.
-
isText
public abstract boolean isText()
-
isInteger
public boolean isInteger()
Checks if this datatype is an integer type.- Returns:
- true if the datatype is integer; false otherwise
-
isFloat
public boolean isFloat()
Checks if this datatype is a floating-point type.- Returns:
- true if the datatype is floating-point; false otherwise
-
isVarStr
public boolean isVarStr()
Checks if this datatype is a variable-length string type.- Returns:
- true if the datatype is variable-length string; false otherwise
-
isVLEN
public boolean isVLEN()
Checks if this datatype is a variable-length type.- Returns:
- true if the datatype is variable-length; false otherwise
-
isCompound
public boolean isCompound()
Checks if this datatype is an compound type.- Returns:
- true if the datatype is compound; false otherwise
-
isArray
public boolean isArray()
Checks if this datatype is an array type.- Returns:
- true if the datatype is array; false otherwise
-
isString
public boolean isString()
Checks if this datatype is a string type.- Returns:
- true if the datatype is string; false otherwise
-
isChar
public boolean isChar()
Checks if this datatype is a character type.- Returns:
- true if the datatype is character; false otherwise
-
isRef
public boolean isRef()
Checks if this datatype is a reference type.- Returns:
- true if the datatype is reference; false otherwise
-
isEnum
public boolean isEnum()
Checks if this datatype is a enum type.- Returns:
- true if the datatype is enum; false otherwise
-
isOpaque
public boolean isOpaque()
Checks if this datatype is a opaque type.- Returns:
- true if the datatype is opaque; false otherwise
-
isBitField
public boolean isBitField()
Checks if this datatype is a bitfield type.- Returns:
- true if the datatype is bitfield; false otherwise
-
getMetadata
public List getMetadata() throws Exception
Description copied from interface:MetaDataContainer
Retrieves the object's metadata, such as attributes, from the file.Metadata, such as attributes, is stored in a List.
- Specified by:
getMetadata
in interfaceMetaDataContainer
- Returns:
- the list of metadata objects.
- Throws:
Exception
- if the metadata can not be retrieved
-
writeMetadata
public void writeMetadata(Object info) throws Exception
Description copied from interface:MetaDataContainer
Writes a specific piece of metadata (such as an attribute) into the file. If an HDF(4&5) attribute exists in the file, this method updates its value. If the attribute does not exist in the file, it creates the attribute in the file and attaches it to the object. It will fail to write a new attribute to the object where an attribute with the same name already exists. To update the value of an existing attribute in the file, one needs to get the instance of the attribute by getMetadata(), change its values, then use writeMetadata() to write the value.- Specified by:
writeMetadata
in interfaceMetaDataContainer
- Parameters:
info
- the metadata to write.- Throws:
Exception
- if the metadata can not be written
-
removeMetadata
public void removeMetadata(Object info) throws Exception
Description copied from interface:MetaDataContainer
Deletes an existing piece of metadata from this object.- Specified by:
removeMetadata
in interfaceMetaDataContainer
- Parameters:
info
- the metadata to delete.- Throws:
Exception
- if the metadata can not be removed
-
updateMetadata
public void updateMetadata(Object info) throws Exception
Description copied from interface:MetaDataContainer
Updates an existing piece of metadata attached to this object.- Specified by:
updateMetadata
in interfaceMetaDataContainer
- Parameters:
info
- the metadata to update.- Throws:
Exception
- if the metadata can not be updated
-
toString
public String toString()
Description copied from class:HObject
Returns the name of the object.This method overwrites the toString() method in the Java Object class (the root class of all Java objects) so that it returns the name of the HObject instead of the name of the class.
For example, toString() returns "Raster Image #2" instead of "hdf.object.h4.H4SDS".
-
-