public class H5Datatype extends Datatype
This class provides several methods to convert an HDF5 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.
arrayDims, baseType, CLASS_ARRAY, CLASS_BITFIELD, CLASS_CHAR, CLASS_COMPOUND, CLASS_ENUM, CLASS_FLOAT, CLASS_INTEGER, CLASS_NO_CLASS, CLASS_OPAQUE, CLASS_REFERENCE, CLASS_STRING, CLASS_TIME, CLASS_VLEN, compoundMemberNames, compoundMemberOffsets, compoundMemberTypes, datatypeClass, datatypeDescription, datatypeOrder, datatypeSign, datatypeSize, enumMembers, is_variable_str, is_VLEN, NATIVE, NSGN, ORDER_BE, ORDER_LE, ORDER_NONE, ORDER_VAX, SIGN_2, SIGN_NONE
fileFormat, linkTargetObjName, oid, separator
Constructor and Description |
---|
H5Datatype(FileFormat theFile,
String name,
String path)
Constructs an named HDF5 data type object for a given file, dataset name and group path.
|
H5Datatype(FileFormat theFile,
String name,
String path,
long[] oid)
Deprecated.
Not for public use in the future.
Using H5Datatype(FileFormat, String, String) |
H5Datatype(int tclass,
int tsize,
int torder,
int tsign)
Constructs a Datatype with specified class, size, byte order and sign.
|
H5Datatype(int tclass,
int tsize,
int torder,
int tsign,
Datatype tbase)
Constructs a Datatype with specified class, size, byte order and sign.
|
H5Datatype(int tclass,
int tsize,
int torder,
int tsign,
Datatype tbase,
Datatype pbase)
Constructs a Datatype with specified class, size, byte order and sign.
|
H5Datatype(int tclass,
int tsize,
int torder,
int tsign,
Datatype tbase,
Datatype pbase,
List<H5Datatype> members)
Constructs a Datatype with specified class, size, byte order and sign.
|
H5Datatype(long nativeID)
Constructs a Datatype with a given native datatype identifier.
|
H5Datatype(long nativeID,
Datatype pbase)
Constructs a Datatype with a given native datatype identifier.
|
Modifier and Type | Method and Description |
---|---|
Object |
allocateArray(int spaceSize)
Allocates a one-dimensional array of byte, short, int, long, float, double,
or String to store data in memory.
|
void |
close(long tid)
Closes a datatype identifier.
|
Object[] |
convertEnumNameToValue(String[] in)
Converts names in an Enumeration Datatype to values.
|
String[] |
convertEnumValueToName(Object inValues)
Converts values in an Enumeration Datatype to names.
|
long |
createCompoundFieldType(String member_name)
Creates a datatype of a compound with one field.
|
long |
createNative()
Converts the datatype object to a native datatype.
|
void |
extractCompoundInfo(String name,
List<String> names,
List<Datatype> flatListTypes)
Extracts compound information into flat structure.
|
void |
fromNative(long tid)
Set datatype characteristics (class, size, byte order and sign) from a given datatype identifier.
|
static long |
getDatatypeSize(long tid)
Returns the size (in bytes) of a given datatype identifier.
|
String |
getDescription()
Returns a short text description of this datatype.
|
List<Attribute> |
getMetadata()
Retrieves the object's metadata, such as attributes, from the file.
|
List<Attribute> |
getMetadata(int... attrPropList) |
int |
getNativeStrPad() |
boolean |
hasAttribute()
Check if the object has any attributes attached.
|
boolean |
isRefObj() |
boolean |
isRegRef() |
boolean |
isText() |
static boolean |
isUnsigned(long tid)
Checks if a datatype specified by the identifier is an unsigned integer.
|
long |
open()
Opens access to a named datatype.
|
void |
removeMetadata(Object info)
Deletes an existing piece of metadata from this object.
|
void |
setName(String newName)
Sets the name of the object.
|
static long |
toNative(long tid) |
void |
writeMetadata(Object info)
Writes a specific piece of metadata (such as an attribute) into the file.
|
getArrayDims, getCompoundMemberNames, getCompoundMemberTypes, getDatatypeBase, getDatatypeClass, getDatatypeOrder, getDatatypeSign, getDatatypeSize, getEnumMembers, getEnumMembersAsString, isArray, isBitField, isChar, isCompound, isEnum, isFloat, isInteger, isOpaque, isRef, isString, isUnsigned, isVarStr, isVLEN, setEnumMembers, toString, updateMetadata
debug, equals, equalsOID, getFID, getFile, getFileFormat, getFullName, getLinkTargetObjName, getName, getOID, getPath, setLinkTargetObjName, setPath
public H5Datatype(FileFormat theFile, String name, String path)
The datatype object represents an existing named datatype in file. For example,
new H5Datatype(file, "dtype1", "/g0")constructs a datatype object that corresponds to the dataset,"dset1", at group "/g0".
theFile
- the file that contains the dataset.name
- the name of the dataset such as "dset1".path
- the group path to the dataset such as "/g0/".@Deprecated public H5Datatype(FileFormat theFile, String name, String path, long[] oid)
H5Datatype(FileFormat, String, String)
theFile
- the file that contains the dataset.name
- the name of the dataset such as "dset1".path
- the group path to the dataset such as "/g0/".oid
- the oid of the dataset.public H5Datatype(int tclass, int tsize, int torder, int tsign)
The following is a list of a few example of H5Datatype.
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_NONEtsign
- the sign of the datatype. Valid values are SIGN_NONE, SIGN_2 and MSGNpublic H5Datatype(int tclass, int tsize, int torder, int tsign, Datatype tbase)
The following is a list of a few example of H5Datatype.
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_NONEtsign
- the sign of the datatype. Valid values are SIGN_NONE, SIGN_2 and MSGNtbase
- the base datatype of the new datatypepublic H5Datatype(int tclass, int tsize, int torder, int tsign, Datatype tbase, Datatype pbase)
The following is a list of a few example of H5Datatype.
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_NONEtsign
- the sign of the datatype. Valid values are SIGN_NONE, SIGN_2 and MSGNtbase
- the base datatype of the new datatypepbase
- the parent datatype of the new datatypepublic H5Datatype(int tclass, int tsize, int torder, int tsign, Datatype tbase, Datatype pbase, List<H5Datatype> members)
The following is a list of a few example of H5Datatype.
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_NONEtsign
- the sign of the datatype. Valid values are SIGN_NONE, SIGN_2 and MSGNtbase
- the base datatype of the new datatypepbase
- the parent datatype of the new datatypemembers
- the list of member datatypespublic H5Datatype(long nativeID)
For example, if the datatype identifier is a 32-bit unsigned integer created from HDF5,
int 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);
nativeID
- the native datatype identifier.fromNative(long nativeID)
public H5Datatype(long nativeID, Datatype pbase)
For example, if the datatype identifier is a 32-bit unsigned integer created from HDF5,
int 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);
nativeID
- the native datatype identifier.pbase
- the parent datatype of the new datatypefromNative(long nativeID)
public long open()
It calls H5.H5Topen(loc, name).
public void close(long tid)
It calls H5.H5close(tid).
public boolean hasAttribute()
MetaDataContainer
public String[] convertEnumValueToName(Object inValues) throws hdf.hdf5lib.exceptions.HDF5Exception
This method searches the identified enumeration datatype for the values appearing in
inValues
and returns the names corresponding to those values. If a given value is
not found in the enumeration datatype, the name corresponding to that value will be set to
"ENUM ERR value"
in the string array that is returned.
If the method fails in general, null will be returned instead of a String array. An empty
inValues
parameter would cause general failure.
inValues
- The array of enumerations values to be converted.hdf.hdf5lib.exceptions.HDF5Exception
- If there is an error at the HDF5 library level.public Object[] convertEnumNameToValue(String[] in) throws hdf.hdf5lib.exceptions.HDF5Exception
This method searches the identified enumeration datatype for the names appearing in
inValues
and returns the values corresponding to those names.
in
- The array of enumerations names to be converted.hdf.hdf5lib.exceptions.HDF5Exception
- If there is an error at the HDF5 library level.public void fromNative(long tid)
Datatype
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
fromNative
in class Datatype
tid
- the datatype identifier.public static long toNative(long tid)
tid
- the datatype identification disk.public long createNative()
Datatype
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 to
int tid = H5.H5Tcopy(HDF5Constants.H5T_NATIVE_UNINT32);
createNative
in class Datatype
public Object allocateArray(int spaceSize) throws OutOfMemoryError
long tid = H5.H5Tcopy(HDF5Constants.H5T_NATIVE_INT32); int[] data = (int[]) allocateArray(100);returns a 32-bit integer array of size 100.
spaceSize
- the total number of data points of the array.OutOfMemoryError
- If there is a failure.public static final long getDatatypeSize(long tid)
It basically just calls H5Tget_size(tid).
tid
- The datatype identifier.H5.H5Tget_size(long)
public String getDescription()
Datatype
getDescription
in class Datatype
public static final boolean isUnsigned(long tid)
tid
- the datatype ID to be checked.public List<Attribute> getMetadata() throws hdf.hdf5lib.exceptions.HDF5Exception
MetaDataContainer
Metadata, such as attributes, is stored in a List.
getMetadata
in interface MetaDataContainer
getMetadata
in class Datatype
hdf.hdf5lib.exceptions.HDF5Exception
public List<Attribute> getMetadata(int... attrPropList) throws hdf.hdf5lib.exceptions.HDF5Exception
hdf.hdf5lib.exceptions.HDF5Exception
public void writeMetadata(Object info) throws Exception
MetaDataContainer
writeMetadata
in interface MetaDataContainer
writeMetadata
in class Datatype
info
- the metadata to write.Exception
- if the metadata can not be writtenpublic void removeMetadata(Object info) throws hdf.hdf5lib.exceptions.HDF5Exception
MetaDataContainer
removeMetadata
in interface MetaDataContainer
removeMetadata
in class Datatype
info
- the metadata to delete.hdf.hdf5lib.exceptions.HDF5Exception
public void setName(String newName) throws Exception
HObject
public boolean isRefObj()
public boolean isRegRef()
public int getNativeStrPad()
public void extractCompoundInfo(String name, List<String> names, List<Datatype> flatListTypes)
For example, compound datatype "nest" has {nest1{a, b, c}, d, e} then extractCompoundInfo() will put the names of nested compound fields into a flat list as
nest.nest1.a nest.nest1.b nest.nest1.c nest.d nest.e
name
- the name of the compound datatypenames
- the list to store the member names of the compound datatypeflatListTypes
- the list to store the nested member names of the compound datatypepublic long createCompoundFieldType(String member_name) throws hdf.hdf5lib.exceptions.HDF5Exception
This function is needed to read/write data field by field.
member_name
- The name of the datatypehdf.hdf5lib.exceptions.HDF5Exception
- If there is an error at the HDF5 library level.Copyright © 2018. All Rights Reserved.