Object
hdf.object.HObject
hdf.object.Dataset
hdf.object.Attribute
hdf.object.h5.H5Attribute
- All Implemented Interfaces:
- CompoundDataFormat,- DataFormat,- MetaDataContainer,- Serializable
public class H5Attribute extends Attribute
An attribute is a (name, value) pair of metadata attached to a primary data object such as a
 dataset, group or named datatype.
 
Like a dataset, an attribute has a name, datatype and dataspace.
For more details on attributes, HDF5 User's Guide
The following code is an example of an attribute with 1D integer array of two elements.
 // Example of creating a new attribute
 // The name of the new attribute
 String name = "Data range";
 // Creating an unsigned 1-byte integer datatype
 Datatype type = new Datatype(Datatype.CLASS_INTEGER, // class
                              1,                      // size in bytes
                              Datatype.ORDER_LE,      // byte order
                              Datatype.SIGN_NONE);    // unsigned
 // 1-D array of size two
 long[] dims = {2};
 // The value of the attribute
 int[] value = {0, 255};
 // Create a new attribute
 Attribute dataRange = new Attribute(name, type, dims);
 // Set the attribute value
 dataRange.setValue(value);
 // See FileFormat.writeAttribute() for how to attach an attribute to an object,
 @see hdf.object.FileFormat#writeAttribute(HObject, Attribute, boolean)
 
 For an atomic datatype, the value of an Attribute will be a 1D array of integers, floats and
 strings. For a compound datatype, it will be a 1D array of strings with field members separated
 by a comma. For example, "{0, 10.5}, {255, 20.0}, {512, 30.0}" is a compound attribute of {int,
 float} of three data points.- Version:
- 2.0 4/2/2018
- Author:
- Peter X. Cao, Jordan T. Henderson
- See Also:
- Datatype, Serialized Form
- 
Field SummaryFields inherited from class hdf.object.AttributeflatNameList, flatTypeList, isMemberSelected, isScalar, memberDims, memberNames, memberOrders, memberTypes, numberOfMembers, parentObject, unsignedConvertedFields inherited from class hdf.object.DatasetchunkSize, compression, COMPRESSION_GZIP_TXT, convertByteToString, convertedBuf, data, datatype, dimNames, dims, filters, inited, isDataLoaded, maxDims, nPoints, originalBuf, rank, selectedDims, selectedIndex, selectedStride, startDims, storage, storageLayoutFields inherited from class hdf.object.HObjectfileFormat, linkTargetObjName, oid, SEPARATOR
- 
Constructor SummaryConstructors Constructor Description H5Attribute(HObject parentObj, String attrName, Datatype attrType, long[] attrDims)Create an attribute with specified name, data type and dimension sizes.H5Attribute(HObject parentObj, String attrName, Datatype attrType, long[] attrDims, Object attrValue)Create an attribute with specific name and value.
- 
Method SummaryModifier and Type Method Description voidclose(long aid)Closes access to the object.protected ObjectconvertCompoundByteMember(byte[] data, long data_type, long start, long len)Given an array of bytes representing a compound Datatype and a start index and length, converts len number of bytes into the correct Object type and returns it.voidinit()longopen()Opens an existing object such as a dataset or group for access.Methods inherited from class hdf.object.AttributeclearData, convertFromUnsignedC, convertToUnsignedC, copy, equals, getDatatype, getFillValue, getMemberCount, getMemberDims, getMemberNames, getMemberOrders, getMemberTypes, getMetadata, getParentObject, getProperty, getPropertyKeys, getSelectedMemberCount, getSelectedMemberNames, getSelectedMemberOrders, getSelectedMemberTypes, hasAttribute, hashCode, isMemberSelected, isScalar, read, readBytes, removeMetadata, resetSelection, selectMember, setAllMemberSelection, setParentObject, setProperty, toString, toString, updateMetadata, write, writeMetadataMethods inherited from class hdf.object.DatasetbyteToString, clear, convertFromUnsignedC, convertFromUnsignedC, convertToUnsignedC, convertToUnsignedC, getChunkSize, getCompression, getConvertByteToString, getData, getDimNames, getDims, getFilters, getHeight, getMaxDims, getOriginalClass, getRank, getSelectedDims, getSelectedIndex, getSize, getStartDims, getStorage, getStorageLayout, getStride, getVirtualFilename, getVirtualMaps, getWidth, isInited, isString, isVirtual, setConvertByteToString, setData, stringToByte, writeMethods inherited from class hdf.object.HObjectcreateFullname, debug, equals, equalsOID, getFID, getFile, getFileFormat, getFullName, getLinkTargetObjName, getName, getOID, getPath, setFullname, setLinkTargetObjName, setName, setPath, toStringMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface hdf.object.DataFormatgetCompression, getData, getDims, getHeight, getOriginalClass, getRank, getSelectedDims, getSelectedIndex, getStartDims, getStride, getWidth, isInited, setData, write
- 
Constructor Details- 
H5AttributeCreate an attribute with specified name, data type and dimension sizes. For scalar attribute, the dimension size can be either an array of size one or null, and the rank can be either 1 or zero. Attribute is a general class and is independent of file format, e.g., the implementation of attribute applies to both HDF4 and HDF5.The following example creates a string attribute with the name "CLASS" and value "IMAGE". long[] attrDims = { 1 }; String attrName = "CLASS"; String[] classValue = { "IMAGE" }; Datatype attrType = null; try { attrType = new H5Datatype(Datatype.CLASS_STRING, classValue[0].length() + 1, Datatype.NATIVE, Datatype.NATIVE); } catch (Exception ex) {} Attribute attr = new Attribute(attrName, attrType, attrDims); attr.setValue(classValue);- Parameters:
- parentObj- the HObject to which this Attribute is attached.
- attrName- the name of the attribute.
- attrType- the datatype of the attribute.
- attrDims- the dimension sizes of the attribute, null for scalar attribute
- See Also:
- Datatype
 
- 
H5Attributepublic H5Attribute(HObject parentObj, String attrName, Datatype attrType, long[] attrDims, Object attrValue)Create an attribute with specific name and value. For scalar attribute, the dimension size can be either an array of size one or null, and the rank can be either 1 or zero. Attribute is a general class and is independent of file format, e.g., the implementation of attribute applies to both HDF4 and HDF5.The following example creates a string attribute with the name "CLASS" and value "IMAGE". long[] attrDims = { 1 }; String attrName = "CLASS"; String[] classValue = { "IMAGE" }; Datatype attrType = null; try { attrType = new H5Datatype(Datatype.CLASS_STRING, classValue[0].length() + 1, Datatype.NATIVE, Datatype.NATIVE); } catch (Exception ex) {} Attribute attr = new Attribute(attrName, attrType, attrDims, classValue);- Parameters:
- parentObj- the HObject to which this Attribute is attached.
- attrName- the name of the attribute.
- attrType- the datatype of the attribute.
- attrDims- the dimension sizes of the attribute, null for scalar attribute
- attrValue- the value of the attribute, null if no value
- See Also:
- Datatype
 
 
- 
- 
Method Details- 
openDescription copied from class:HObjectOpens an existing object such as a dataset or group for access. The return value is an object identifier obtained by implementing classes such as H5.H5Dopen(). This function is needed to allow other objects to be able to access the object. For instance, H5File class uses the open() function to obtain object identifier for copyAttributes(long src_id, long dst_id) and other purposes. The open() function should be used in pair with close(long) function.- Overrides:
- openin class- Attribute
- Returns:
- the object identifier if successful; otherwise returns a negative value.
- See Also:
- HObject.close(long)
 
- 
closeDescription copied from class:HObjectCloses access to the object.Sub-classes must implement this interface because different data objects have their own ways of how the data resources are closed. For example, H5Group.close() calls the hdf.hdf5lib.H5.H5Gclose() method and closes the group resource specified by the group id. 
- 
init- Specified by:
- initin interface- DataFormat
- Overrides:
- initin class- Attribute
 
- 
convertCompoundByteMemberGiven an array of bytes representing a compound Datatype and a start index and length, converts len number of bytes into the correct Object type and returns it.- Overrides:
- convertCompoundByteMemberin class- Attribute
- Parameters:
- data- The byte array representing the data of the compound Datatype
- data_type- The type of data to convert the bytes to
- start- The start index of the bytes to get
- len- The number of bytes to convert
- Returns:
- The converted type of the bytes
 
 
-