H5A: Attribute Interface

Attribute API Functions

These functions create and manipulate attributes and information about attributes.
             

Name: H5Acreate
Signature:
hid_t H5Acreate(hid_t loc_id, const char *name, hid_t datatype, hid_t dataspace, hid_t create_plist )
Purpose:
Creates a dataset as an attribute of another dataset or group.
Description:
SC: H5Acreate creates an attribute which is attached to the object specified with 'location_id'. The name specified with 'name' for each attribute for an object must be unique for that object. The 'type_id' and 'space_id' are created with the H5T and H5S interfaces respectively. Currently only simple dataspaces are allowed for attribute dataspaces. The 'create_plist_id' property list is currently un-used, but will be used int the future for optional properties of attributes. The attribute identifier returned from this function must be released with H5Aclose or resource leaks will develop.

The link created (see H5G API documentation for more information on link types) is a hard link, so the attribute may be shared among datasets and will not be removed from the file until the reference count for the attribute is reduced to zero.

The location object may be either a group or a dataset, both of which may have any sort of attribute.

UG: H5Acreate creates an attribute which is attached to the object specified with loc_id. The name specified with name for each attribute for an object must be unique for that object. The type_id and space_id are created with the H5T and H5S interfaces respectively. Currently only simple dataspaces are allowed for attribute dataspaces. The create_plist_id property list is currently unused, but will be used int the future for optional properties of attributes. The attribute identifier returned from this function must be released with H5Aclose or resource leaks will develop. Attempting to create an attribute with the same name as an already existing attribute will fail, leaving the pre-existing attribute in place.

datatype, dataspace, create_plist in the UG are type_id, space_id, and create_plist_id, respectively, in the SC

Parameters:
hid_t loc_id
IN: Object (dataset or group) to be attached to
const char *name
IN: Name of attribute to create
hid_t datatype
IN: Identifier of datatype for attribute
hid_t dataspace
IN: Identifier of dataspace for attribute
hid_t create_plist
IN: Identifier of creation property list (currently not used)
Returns:
Returns an attribute identifier if successful; otherwise FAIL (-1).

Name: H5Aopen_name
Signature:
hid_t H5Aopen_name(hid_t loc_id, const char *name )
Purpose:
Opens an attribute for an object by looking up the attribute name.
Description:
SC: H5Aopen_name opens an existing attribute for access. The attribute name specified is used to look up the corresponding attribute for the object. The attribute identifier returned from this function must be released with H5Aclose or resource leaks will develop.

The location object may be either a group or a dataset, both of which may have any sort of attribute.

UG: H5Aopen_name opens an attribute which is attached to the object specified with loc_id. The name specified with name indicates the attribute to access. The attribute identifier returned from this function must be released with H5Aclose or resource leaks will develop.

Parameters:
hid_t loc_id
IN: Object (dataset or group) to be attached to
const char *name
IN: Name of attribute to locate and open
Returns:
Returns attribute identifier if successful; otherwise FAIL (-1).

Name: H5Aopen_idx
Signature:
hid_t H5Aopen_idx(hid_t loc_id, unsigned int idx )
Purpose:
Opens the nth attribute for an object.
Description:
SC: H5Aopen_idx opens an existing attribute for access. The attribute index specified is used to look up the corresponding attribute for the object. The attribute identifier returned from this function must be released with H5Aclose or resource leaks will develop.

The location object may be either a group or a dataset, both of which may have any sort of attribute.

UG: H5Aopen_idx opens an attribute which is attached to the object specified with loc_id. The attribute specified with idx indicates the idxth attribute to access, starting with '0'. The attribute identifier returned from this function must be released with H5Aclose or resource leaks will develop.

Parameters:
hid_t loc_id
IN: Object (dataset or group) to be attached to
unsigned int idx
IN: Index (0-based) attribute to open
Returns:
Returns attribute identifier if successful; otherwise FAIL (-1).

Name: H5Awrite
Signature:
herr_t H5Awrite(hid_t attr_id, hid_t mem_dt, void *buf )
Purpose:
Write out data to an attribute.
Description:
SC: H5Awrite writes a complete attribute to disk.

UG: H5Awrite writes an attribute, specified with attr_id, with mem_type_id specifying the datatype in memory. The entire attribute is written from buf to the file. This function returns non-negative on success, negative on failure.

mem_dt in SC is mem_type_id in UG.

Parameters:
hid_t attr_id
IN: Attribute to write
hid_t mem_dt
IN: Memory datatype of buffer
void *buf
IN: Buffer of data to write
Returns:
Returns SUCCEED (0) if successful; otherwise FAIL (-1).

Name: H5Aread
Signature:
herr_t H5Aread(hid_t attr_id, hid_t mem_dt, void *buf )
Purpose:
Read in data from an attribute.
Description:
SC: H5Aread reads a complete attribute from disk.

UG: H5Aread reads an attribute, specified with attr_id, with mem_type_id specifying the datatype in memory. The entire attribute is read into buf from the file. This function returns non-negative on success, negative on failure.

mem_dt in SC is mem_type_id in UG.

Parameters:
hid_t attr_id
IN: Attribute to read
hid_t mem_dt
IN: Memory datatype of buffer
void *buf
IN: Buffer for data to read
Returns:
Returns SUCCEED (0) if successful; otherwise FAIL (-1).

Name: H5Aget_space
Signature:
hid_t H5Aget_space(hid_t attr_id)
Purpose:
Gets a copy of the dataspace for an attribute.
Description:
H5Aget_space retrieves a copy of the dataspace for an attribute. The dataspace identifier returned from this function must be released with H5Sclose or resource leaks will develop.

(Identical desc in UG and SC.)

Parameters:
hid_t attr_id
IN: Attribute to get dataspace of
Returns:
Returns dataspace identifier if successful; otherwise FAIL (-1).

Name: H5Aget_type
Signature:
hid_t H5Aget_type(hid_t attr_id)
Purpose:
Gets a copy of the datatype for an attribute.
Description:
H5Aget_type retrieves a copy of the datatype for an attribute. The datatype identifier returned from this function must be released with H5Tclose or resource leaks will develop.

(Identical desc in UG and SC.)

Parameters:
hid_t attr_id
IN: Attribute to get datatype of
Returns:
Returns a datatype identifier if successful; otherwise FAIL (-1).

Name: H5Aget_name
Signature:
size_t H5Aget_name(hid_t attr_id, char *buf, size_t buf_size )
Purpose:
Gets a copy of the name for an attribute.
Description:
H5Aget_name retrieves the name of an attribute for an attribute identifier. Up to 'buf_size' characters are stored in 'buf' followed by a '\0' string terminator. If the name of the attribute is longer than 'buf_size'-1, the string terminator is stored in the last position of the buffer to properly terminate the string.

(Identical desc in UG and SC.)

Parameters:
hid_t attr_id
IN: Attribute to get name of
char *buf
IN: Buffer to store name in
size_t buf_size
IN: The size of the buffer to store the string in
Returns:
Returns the length of the attribute's name, which may be longer than buf_size, if successful. Otherwise returns FAIL (-1).

Name: H5Anum_attrs
Signature:
int H5Anum_attrs(hid_t loc_id)
Purpose:
Determines the number of attributes attached to an object.
Description:
H5Anum_attrs returns the number of attributes attached to the dataset or group, loc_id.

(Identical desc in UG and SC.)

Parameters:
hid_t loc_id
IN: The object, a dataset or group, to be queried
Returns:
Returns the number of attributes if successful; otherwise FAIL (-1).

Name: H5Aiterate
Signature:
int H5Aiterate(hid_t loc_id, unsigned * attr_num, H5A_operator_t op, void *op_data )
Purpose:
Calls a user's function for each attribute on an object.
Description:
SC: H5Aiterate interates over the attributes of dataset or group specified with 'loc_id'. For each attribute of the object, the 'op_data' and some additional information (specified below) are passed to the 'op' function. The iteration begins with the '*attr_number' object in the group and the next attribute to be processed by the operator is returned in '*attr_number'.

The operation receives the identifier for the group or dataset being iterated over ('loc_id'), the name of the current attribute about the object ('attr_name') and the pointer to the operator data passed in to H5Aiterate ('op_data'). The return values from an operator are:

UG: H5Aiterate interates over the attributes of dataset or group specified with loc_id. For each attribute of the object, the operator_data and some additional information (specified below) are passed to the operator function. The iteration begins with the *attr_number object in the group and the next attribute to be processed by the operator is returned in *attr_number.

The prototype for H5A_operator_t is:
typedef herr_t (*H5A_operator_t)(hid_t loc_id, const char *attr_name, void *operator_data);

The operation receives the identifier for the group or dataset being iterated over (loc_id), the name of the current attribute about the object (attr_name) and the pointer to the operator data passed in to H5Aiterate (operator_data). The return values from an operator are:

attr_num, op, and op_data in SC are attr_number, operator, and operator_data, respectively, in UG.

Parameters:
hid_t loc_id
IN: Object (dataset or group) to be iterated over
unsigned * attr_num
IN/OUT: Starting (IN) & Ending (OUT) attribute number
H5A_operator_t op
IN: User's function to pass each attribute to
void *op_data
IN/OUT: User's data to pass through to iterator operator function
Returns:
If successful, returns the return value of the last operator if it was non-zero, or zero if all attributes were processed. Otherwise returns FAIL (-1).

Name: H5Adelete
Signature:
herr_t H5Adelete(hid_t loc_id, const char *name )
Purpose:
Deletes an attribute from a location.
Description:
SC: H5Adelete removes the named attribute from a dataset or group. This function should not be used when attribute identifiers are open on 'loc_id' as it may cause the internal indexes of the attributes to change and future writes to the open attributes to produce incorrect results.

UG: H5Adelete removes the named attribute from a dataset or group. This function should not be used when attribute identifiers are open on loc_id as it may cause the internal indexes of the attributes to change and future writes to the open attributes to produce incorrect results. Returns non-negative on success, negative on failure.

Parameters:
hid_t loc_id
IN: Object (dataset or group) to have attribute deleted from
const char *name
IN: Name of attribute to delete
Returns:
Returns SUCCEED (0) if successful; otherwise FAIL (-1).

Name: H5Aclose
Signature:
herr_t H5Aclose(hid_t attr_id)
Purpose:
Close an attribute identifier.
Description:
SC: H5Aclose releases an attribute from use. Further use of the attribute identifier will result in undefined behavior.

UG: H5Aclose releases an attribute from use. Further use of the attribute identifier will result in undefined behavior. This function returns non-negative on success, negative on failure.

Parameters:
hid_t attr_id
IN: Attribute to release access to
Returns:
Returns SUCCEED (0) if successful; otherwise FAIL (-1).

Frank Baker
HDF5 Documentation
Last modified: 6 July 1998