public abstract class Datatype extends HObject implements MetaDataContainer
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.
Modifier and Type | Field and 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 |
is_variable_str |
protected boolean |
is_VLEN
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
|
fileFormat, linkTargetObjName, oid, separator
Constructor and Description |
---|
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.
Using Datatype(FileFormat, String, String) |
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.
|
Modifier and Type | Method and 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 datatype of the elements 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 or NSGN) 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 (name, 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.
|
debug, equals, equalsOID, getFID, getFile, getFileFormat, getFullName, getLinkTargetObjName, getName, getOID, getPath, setLinkTargetObjName, setName, setPath
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
hasAttribute
public static final int NATIVE
public static final int CLASS_NO_CLASS
public static final int CLASS_INTEGER
public static final int CLASS_FLOAT
public static final int CLASS_CHAR
public static final int CLASS_STRING
public static final int CLASS_BITFIELD
public static final int CLASS_OPAQUE
public static final int CLASS_COMPOUND
public static final int CLASS_REFERENCE
public static final int CLASS_ENUM
public static final int CLASS_VLEN
public static final int CLASS_ARRAY
public static final int CLASS_TIME
public static final int ORDER_LE
public static final int ORDER_BE
public static final int ORDER_VAX
public static final int ORDER_NONE
public static final int SIGN_NONE
public static final int SIGN_2
public static final int NSGN
protected String datatypeDescription
protected int datatypeClass
protected long datatypeSize
protected int datatypeOrder
protected int datatypeSign
protected Datatype baseType
protected long[] arrayDims
protected boolean is_VLEN
protected boolean is_variable_str
protected Map<String,String> enumMembers
protected List<String> compoundMemberNames
protected List<Datatype> compoundMemberTypes
protected List<Long> compoundMemberOffsets
public Datatype(FileFormat theFile, String typeName, String typePath)
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/".@Deprecated public Datatype(FileFormat theFile, String typeName, String typePath, long[] oid)
Datatype(FileFormat, String, String)
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.public Datatype(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 Datatype(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 Datatype(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 Datatype(long tid)
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);
tid
- the native datatype identifier.fromNative(long tid)
public Datatype(long tid, Datatype pbase)
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);
tid
- the native datatype identifier.pbase
- the parent datatype of the new datatypefromNative(long tid)
public long open()
open
in class HObject
HObject.close(long)
public abstract void close(long id)
Sub-classes must replace this default implementation.
public int getDatatypeClass()
public long getDatatypeSize()
public int getDatatypeOrder()
public int getDatatypeSign()
public Datatype getDatatypeBase()
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.
public final void setEnumMembers(String enumStr)
For Example,
enumStr
- the (name, value) pairs of enum memberspublic final Map<String,String> getEnumMembers()
public final String getEnumMembersAsString()
For Example,
public final long[] getArrayDims()
public final List<String> getCompoundMemberNames()
public final List<Datatype> getCompoundMemberTypes()
public abstract long createNative()
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);
public abstract void fromNative(long nativeID)
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
nativeID
- the datatype identifier.public String getDescription()
public boolean isUnsigned()
public abstract boolean isText()
public boolean isInteger()
public boolean isFloat()
public boolean isVarStr()
public boolean isVLEN()
public boolean isCompound()
public boolean isArray()
public boolean isString()
public boolean isChar()
public boolean isRef()
public boolean isEnum()
public boolean isOpaque()
public boolean isBitField()
public List getMetadata() throws Exception
MetaDataContainer
Metadata, such as attributes, is stored in a List.
getMetadata
in interface MetaDataContainer
Exception
- if the metadata can not be retrievedpublic void writeMetadata(Object info) throws Exception
MetaDataContainer
writeMetadata
in interface MetaDataContainer
info
- the metadata to write.Exception
- if the metadata can not be writtenpublic void removeMetadata(Object info) throws Exception
MetaDataContainer
removeMetadata
in interface MetaDataContainer
info
- the metadata to delete.Exception
- if the metadata can not be removedpublic void updateMetadata(Object info) throws Exception
MetaDataContainer
updateMetadata
in interface MetaDataContainer
info
- the metadata to update.Exception
- if the metadata can not be updatedpublic String toString()
HObject
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".
Copyright © 2018. All Rights Reserved.