- All Implemented Interfaces:
MetaDataContainer
,Serializable
- Direct Known Subclasses:
FitsDatatype
,H4Datatype
,H5Datatype
,NC2Datatype
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
Modifier and TypeFieldDescriptionprotected long[]
The dimensions of the ARRAY element of an ARRAY datatype.protected Datatype
The base datatype of this datatype (null if this datatype is atomic).static int
static int
static int
static int
static int
static int
static int
static int
static int
static int
static int
static int
static int
The list of names of members of a compound Datatype.The list of offsets of members of a compound Datatype.The list of types of members of a compound Datatype.protected int
The class of the datatype.protected String
protected int
The byte order of the datatype.protected int
The sign of the datatype.protected long
The size (in bytes) of the datatype.The (name, value) pairs of enum members.protected boolean
Determines whether this datatype is a named datatypeprotected boolean
protected boolean
Determines whether this datatype is a variable-length type.static int
The default definition for datatype size, order, and sign.static int
static int
static int
static int
static int
static int
static int
Fields inherited from class hdf.object.HObject
fileFormat, linkTargetObjName, oid, SEPARATOR
-
Constructor Summary
ConstructorDescriptionDatatype(int tclass, int tsize, int torder, int tsign)
Constructs a Datatype with specified class, size, byte order and sign.Constructs a Datatype with specified class, size, byte order and sign.Constructs a Datatype with specified class, size, byte order and sign.Datatype(FileFormat theFile, int tclass, int tsize, int torder, int tsign, Datatype tbase, Datatype pbase)
Constructs a Datatype with specified class, size, byte order and sign.Datatype(FileFormat theFile, long tid)
Constructs a Datatype with a given native datatype identifier.Datatype(FileFormat theFile, 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. -
Method Summary
Modifier and TypeMethodDescriptionabstract void
close(long id)
Closes a datatype identifier.abstract long
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[]
Returns the dimensions of an Array Datatype.Returns the base datatype for this datatype.int
Returns the class of the datatype.int
Returns the byte order of the datatype.int
Returns the sign (SIGN_NONE, SIGN_2) of an integer datatype.long
Returns the size of the datatype in bytes.Returns a short text description of this datatype.Returns the Map<String,String> pairs of enum members for enum datatype.Returns the HashMap pairs of enum members for enum datatype.Retrieves the object's metadata, such as attributes, from the file.long
If the datatype is a reference, then return the type.boolean
isArray()
Checks if this datatype is an array type.boolean
Checks if this datatype is a bitfield type.boolean
isChar()
Checks if this datatype is a character type.boolean
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
Checks if this datatype is an integer type.boolean
isNamed()
Checks if this datatype is a named 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
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.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
createFullname, debug, equals, equals, equalsOID, getFID, getFile, getFileFormat, getFullName, getLinkTargetObjName, getName, getOID, getPath, hashCode, setFullname, 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 Details
-
NATIVE
The default definition for datatype size, order, and sign.- See Also:
- Constant Field Values
-
CLASS_NO_CLASS
- See Also:
- Constant Field Values
-
CLASS_INTEGER
- See Also:
- Constant Field Values
-
CLASS_FLOAT
- See Also:
- Constant Field Values
-
CLASS_CHAR
- See Also:
- Constant Field Values
-
CLASS_STRING
- See Also:
- Constant Field Values
-
CLASS_BITFIELD
- See Also:
- Constant Field Values
-
CLASS_OPAQUE
- See Also:
- Constant Field Values
-
CLASS_COMPOUND
- See Also:
- Constant Field Values
-
CLASS_REFERENCE
- See Also:
- Constant Field Values
-
CLASS_ENUM
- See Also:
- Constant Field Values
-
CLASS_VLEN
- See Also:
- Constant Field Values
-
CLASS_ARRAY
- See Also:
- Constant Field Values
-
CLASS_TIME
- See Also:
- Constant Field Values
-
ORDER_LE
- See Also:
- Constant Field Values
-
ORDER_BE
- See Also:
- Constant Field Values
-
ORDER_VAX
- See Also:
- Constant Field Values
-
ORDER_NONE
- See Also:
- Constant Field Values
-
SIGN_NONE
- See Also:
- Constant Field Values
-
SIGN_2
- See Also:
- Constant Field Values
-
NSGN
- See Also:
- Constant Field Values
-
datatypeDescription
-
datatypeClass
The class of the datatype. -
datatypeSize
The size (in bytes) of the datatype. -
datatypeOrder
The byte order of the datatype. Valid values are ORDER_LE, ORDER_BE, and ORDER_VAX. -
datatypeSign
The sign of the datatype. -
baseType
The base datatype of this datatype (null if this datatype is atomic). -
isNamed
Determines whether this datatype is a named datatype -
arrayDims
The dimensions of the ARRAY element of an ARRAY datatype. -
isVLEN
Determines whether this datatype is a variable-length type. -
isVariableStr
-
enumMembers
The (name, value) pairs of enum members. -
compoundMemberNames
The list of names of members of a compound Datatype. -
compoundMemberTypes
The list of types of members of a compound Datatype. -
compoundMemberOffsets
The list of offsets of members of a compound Datatype.
-
-
Constructor Details
-
Datatype
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.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
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
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(FileFormat theFile, int tclass, int tsize, int torder, int tsign, Datatype tbase, Datatype pbase) throws ExceptionConstructs 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:
theFile
- the HDF file.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(int tclass, int tsize, int torder, int tsign, Datatype tbase, Datatype pbase) throws ExceptionConstructs 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
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:
theFile
- the HDF file.tid
- the native datatype identifier.- Throws:
Exception
- if there is an error- See Also:
fromNative(long tid)
-
Datatype
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:
theFile
- the HDF file.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 Details
-
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
Closes a datatype identifier.Sub-classes must replace this default implementation.
-
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
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
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
Returns the sign (SIGN_NONE, SIGN_2) of an integer datatype.- Returns:
- the sign of the 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
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
Returns the Map<String,String> pairs of enum members for enum datatype.- Returns:
- enumStr Map<String,String%gt; pairs of enum members
-
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
Returns the dimensions of an Array Datatype.- Returns:
- dims the dimensions of the Array Datatype
-
getCompoundMemberNames
-
getCompoundMemberTypes
-
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
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.
-
getReferenceType
If the datatype is a reference, then return the type.- Returns:
- the datatype reference type if successful; otherwise returns negative value.
-
getDescription
Returns a short text description of this datatype.- Returns:
- a short text description of this datatype
-
isUnsigned
Checks if this datatype is unsigned.- Returns:
- true if the datatype is unsigned; otherwise, returns false.
-
isText
-
isInteger
Checks if this datatype is an integer type.- Returns:
- true if the datatype is integer; false otherwise
-
isFloat
Checks if this datatype is a floating-point type.- Returns:
- true if the datatype is floating-point; false otherwise
-
isNamed
Checks if this datatype is a named type.- Returns:
- true if the datatype is named; false otherwise
-
isVarStr
Checks if this datatype is a variable-length string type.- Returns:
- true if the datatype is variable-length string; false otherwise
-
isVLEN
Checks if this datatype is a variable-length type.- Returns:
- true if the datatype is variable-length; false otherwise
-
isCompound
Checks if this datatype is an compound type.- Returns:
- true if the datatype is compound; false otherwise
-
isArray
Checks if this datatype is an array type.- Returns:
- true if the datatype is array; false otherwise
-
isString
Checks if this datatype is a string type.- Returns:
- true if the datatype is string; false otherwise
-
isChar
Checks if this datatype is a character type.- Returns:
- true if the datatype is character; false otherwise
-
isRef
Checks if this datatype is a reference type.- Returns:
- true if the datatype is reference; false otherwise
-
isEnum
Checks if this datatype is a enum type.- Returns:
- true if the datatype is enum; false otherwise
-
isOpaque
Checks if this datatype is a opaque type.- Returns:
- true if the datatype is opaque; false otherwise
-
isBitField
Checks if this datatype is a bitfield type.- Returns:
- true if the datatype is bitfield; false otherwise
-
getMetadata
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
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
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
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
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".
-
Using
Datatype(FileFormat, String, String)