summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/H5A.c99
-rw-r--r--src/H5Adeprec.c95
-rw-r--r--src/H5Apkg.h2
-rw-r--r--src/H5Apublic.h16
-rw-r--r--src/H5Oattribute.c8
5 files changed, 184 insertions, 36 deletions
diff --git a/src/H5A.c b/src/H5A.c
index f93f7a5..3484d45e 100644
--- a/src/H5A.c
+++ b/src/H5A.c
@@ -69,8 +69,6 @@ typedef struct H5A_iter_cb1 {
static hid_t H5A_create(const H5G_loc_t *loc, const char *name,
const H5T_t *type, const H5S_t *space, hid_t acpl_id, hid_t dxpl_id);
static herr_t H5A_open_common(const H5G_loc_t *loc, H5A_t *attr);
-static H5A_t *H5A_open_by_idx(const H5G_loc_t *loc, const char *obj_name,
- H5_index_t idx_type, H5_iter_order_t order, hsize_t n, hid_t lapl_id, hid_t dxpl_id);
static H5A_t *H5A_open_by_name(const H5G_loc_t *loc, const char *obj_name,
const char *attr_name, hid_t lapl_id, hid_t dxpl_id);
static herr_t H5A_write(H5A_t *attr, const H5T_t *mem_type, const void *buf, hid_t dxpl_id);
@@ -474,13 +472,19 @@ done:
/*--------------------------------------------------------------------------
NAME
- H5Aopen_idx
+ H5Aopen_by_idx
PURPOSE
- Opens the n'th attribute for an object
+ Opens the n'th attribute for an object, according to the order within
+ an index
USAGE
- hid_t H5Aopen_idx (loc_id, idx)
- hid_t loc_id; IN: Object that attribute is attached to
- unsigned idx; IN: Index (0-based) attribute to open
+ hid_t H5Aopen_by_idx(loc_id, obj_ame, idx_type, order, n, aapl_id, lapl_id)
+ hid_t loc_id; IN: Object that attribute is attached to
+ const char *obj_name; IN: Name of object relative to location
+ H5_index_t idx_type; IN: Type of index to use
+ H5_iter_order_t order; IN: Order to iterate over index
+ hsize_t n; IN: Index (0-based) attribute to open
+ hid_t aapl_id; IN: Attribute access property list
+ hid_t lapl_id; IN: Link access property list
RETURNS
ID of attribute on success, negative on failure
@@ -489,27 +493,36 @@ done:
index specified is used to look up the corresponding attribute for the
object. The attribute ID 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.
--------------------------------------------------------------------------*/
hid_t
-H5Aopen_idx(hid_t loc_id, unsigned idx)
+H5Aopen_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type,
+ H5_iter_order_t order, hsize_t n, hid_t UNUSED aapl_id, hid_t lapl_id)
{
- H5G_loc_t loc; /* Object location */
H5A_t *attr = NULL; /* Attribute opened */
- hid_t ret_value;
+ H5G_loc_t loc; /* Object location */
+ hid_t ret_value; /* Return value */
- FUNC_ENTER_API(H5Aopen_idx, FAIL)
- H5TRACE2("i", "iIu", loc_id, idx);
+ FUNC_ENTER_API(H5Aopen_by_idx, FAIL)
/* check arguments */
if(H5I_ATTR == H5I_get_type(loc_id))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
if(H5G_loc(loc_id, &loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
+ if(!obj_name || !*obj_name)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name")
+ if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid index type specified")
+ if(order <= H5_ITER_UNKNOWN || order >= H5_ITER_N)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid iteration order specified")
+ if(H5P_DEFAULT == lapl_id)
+ lapl_id = H5P_LINK_ACCESS_DEFAULT;
+ else
+ if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID")
/* Open the attribute in the object header */
- if(NULL == (attr = H5A_open_by_idx(&loc, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)idx, H5P_LINK_ACCESS_DEFAULT, H5AC_ind_dxpl_id)))
+ if(NULL == (attr = H5A_open_by_idx(&loc, obj_name, idx_type, order, n, lapl_id, H5AC_ind_dxpl_id)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open attribute")
/* Register the attribute and get an ID for it */
@@ -523,7 +536,7 @@ done:
HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute")
FUNC_LEAVE_API(ret_value)
-} /* H5Aopen_idx() */
+} /* H5Aopen_by_idx() */
/*-------------------------------------------------------------------------
@@ -595,7 +608,7 @@ done:
*
*-------------------------------------------------------------------------
*/
-static H5A_t *
+H5A_t *
H5A_open_by_idx(const H5G_loc_t *loc, const char *obj_name, H5_index_t idx_type,
H5_iter_order_t order, hsize_t n, hid_t lapl_id, hid_t dxpl_id)
{
@@ -1533,44 +1546,72 @@ done:
/*-------------------------------------------------------------------------
- * Function: H5Arename
+ * Function: H5Arename2
*
* Purpose: Rename an attribute
*
* Return: Success: Non-negative
* Failure: Negative
*
- * Programmer: Raymond Lu
- * October 23, 2002
+ * Programmer: Quincey Koziol
+ * February 20, 2007
*
*-------------------------------------------------------------------------
*/
herr_t
-H5Arename(hid_t loc_id, const char *old_name, const char *new_name)
+H5Arename2(hid_t loc_id, const char *obj_name, const char *old_attr_name,
+ const char *new_attr_name, hid_t lapl_id)
{
H5G_loc_t loc; /* Object location */
+ H5G_loc_t obj_loc; /* Location used to open group */
+ H5G_name_t obj_path; /* Opened object group hier. path */
+ H5O_loc_t obj_oloc; /* Opened object object location */
+ hbool_t loc_found = FALSE; /* Entry at 'obj_name' found */
herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_API(H5Arename, FAIL)
- H5TRACE3("e", "iss", loc_id, old_name, new_name);
+ FUNC_ENTER_API(H5Arename2, FAIL)
/* check arguments */
- if(!old_name || !new_name)
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "name is nil")
if(H5I_ATTR == H5I_get_type(loc_id))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
- if(H5G_loc(loc_id, & loc) < 0)
+ if(H5G_loc(loc_id, &loc) < 0)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
+ if(!obj_name || !*obj_name)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name")
+ if(!old_attr_name || !*old_attr_name)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no old attribute name")
+ if(!new_attr_name || !*new_attr_name)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no new attribute name")
+ if(H5P_DEFAULT == lapl_id)
+ lapl_id = H5P_LINK_ACCESS_DEFAULT;
+ else
+ if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID")
/* Avoid thrashing things if the names are the same */
- if(HDstrcmp(old_name, new_name))
+ if(HDstrcmp(old_attr_name, new_attr_name)) {
+ /* Set up opened group location to fill in */
+ obj_loc.oloc = &obj_oloc;
+ obj_loc.path = &obj_path;
+ H5G_loc_reset(&obj_loc);
+
+ /* Find the object's location */
+ if(H5G_loc_find(&loc, obj_name, &obj_loc/*out*/, lapl_id, H5AC_ind_dxpl_id) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "object not found")
+ loc_found = TRUE;
+
/* Call attribute rename routine */
- if(H5O_attr_rename(loc.oloc, H5AC_dxpl_id, old_name, new_name) < 0)
+ if(H5O_attr_rename(obj_loc.oloc, H5AC_dxpl_id, old_attr_name, new_attr_name) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTRENAME, FAIL, "can't rename attribute")
+ } /* end if */
done:
+ /* Release resources */
+ if(loc_found && H5G_loc_free(&obj_loc) < 0)
+ HDONE_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "can't free location")
+
FUNC_LEAVE_API(ret_value)
-} /* H5Arename() */
+} /* H5Arename2() */
/*--------------------------------------------------------------------------
diff --git a/src/H5Adeprec.c b/src/H5Adeprec.c
index 3baca88..9b49b81 100644
--- a/src/H5Adeprec.c
+++ b/src/H5Adeprec.c
@@ -108,6 +108,60 @@ H5A_init_deprec_interface(void)
/*--------------------------------------------------------------------------
NAME
+ H5Aopen_idx
+ PURPOSE
+ Opens the n'th attribute for an object
+ USAGE
+ hid_t H5Aopen_idx (loc_id, idx)
+ hid_t loc_id; IN: Object that attribute is attached to
+ unsigned idx; IN: Index (0-based) attribute to open
+ RETURNS
+ ID of attribute on success, negative on failure
+
+ DESCRIPTION
+ This function opens an existing attribute for access. The attribute
+ index specified is used to look up the corresponding attribute for the
+ object. The attribute ID 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.
+--------------------------------------------------------------------------*/
+hid_t
+H5Aopen_idx(hid_t loc_id, unsigned idx)
+{
+ H5G_loc_t loc; /* Object location */
+ H5A_t *attr = NULL; /* Attribute opened */
+ hid_t ret_value;
+
+ FUNC_ENTER_API(H5Aopen_idx, FAIL)
+ H5TRACE2("i", "iIu", loc_id, idx);
+
+ /* check arguments */
+ if(H5I_ATTR == H5I_get_type(loc_id))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
+ if(H5G_loc(loc_id, &loc) < 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
+
+ /* Open the attribute in the object header */
+ if(NULL == (attr = H5A_open_by_idx(&loc, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)idx, H5P_LINK_ACCESS_DEFAULT, H5AC_ind_dxpl_id)))
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open attribute")
+
+ /* Register the attribute and get an ID for it */
+ if((ret_value = H5I_register(H5I_ATTR, attr)) < 0)
+ HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register attribute for ID")
+
+done:
+ /* Cleanup on failure */
+ if(ret_value < 0)
+ if(attr && H5A_close(attr) < 0)
+ HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute")
+
+ FUNC_LEAVE_API(ret_value)
+} /* H5Aopen_idx() */
+
+
+/*--------------------------------------------------------------------------
+ NAME
H5Aget_num_attrs
PURPOSE
Determines the number of attributes attached to an object
@@ -166,6 +220,47 @@ done:
} /* H5Aget_num_attrs() */
+/*-------------------------------------------------------------------------
+ * Function: H5Arename
+ *
+ * Purpose: Rename an attribute
+ *
+ * Return: Success: Non-negative
+ * Failure: Negative
+ *
+ * Programmer: Raymond Lu
+ * October 23, 2002
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5Arename(hid_t loc_id, const char *old_name, const char *new_name)
+{
+ H5G_loc_t loc; /* Object location */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_API(H5Arename, FAIL)
+ H5TRACE3("e", "iss", loc_id, old_name, new_name);
+
+ /* check arguments */
+ if(!old_name || !new_name)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "name is nil")
+ if(H5I_ATTR == H5I_get_type(loc_id))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
+ if(H5G_loc(loc_id, & loc) < 0)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
+
+ /* Avoid thrashing things if the names are the same */
+ if(HDstrcmp(old_name, new_name))
+ /* Call attribute rename routine */
+ if(H5O_attr_rename(loc.oloc, H5AC_dxpl_id, old_name, new_name) < 0)
+ HGOTO_ERROR(H5E_ATTR, H5E_CANTRENAME, FAIL, "can't rename attribute")
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* H5Arename() */
+
+
/*--------------------------------------------------------------------------
NAME
H5Aiterate
diff --git a/src/H5Apkg.h b/src/H5Apkg.h
index 261f7be..c7d5ba3 100644
--- a/src/H5Apkg.h
+++ b/src/H5Apkg.h
@@ -171,6 +171,8 @@ H5_DLLVAR const H5B2_class_t H5A_BT2_CORDER[1];
/* Function prototypes for H5A package scope */
H5_DLL herr_t H5A_init(void);
+H5_DLL H5A_t *H5A_open_by_idx(const H5G_loc_t *loc, const char *obj_name,
+ H5_index_t idx_type, H5_iter_order_t order, hsize_t n, hid_t lapl_id, hid_t dxpl_id);
H5_DLL H5A_t *H5A_copy(H5A_t *new_attr, const H5A_t *old_attr);
H5_DLL herr_t H5A_get_info(const H5A_t *attr, H5A_info_t *ainfo);
H5_DLL herr_t H5A_free(H5A_t *attr);
diff --git a/src/H5Apublic.h b/src/H5Apublic.h
index 8c97e46..cde9bc6 100644
--- a/src/H5Apublic.h
+++ b/src/H5Apublic.h
@@ -48,7 +48,9 @@ typedef herr_t (*H5A_operator2_t)(hid_t location_id/*in*/,
H5_DLL hid_t H5Acreate(hid_t loc_id, const char *name, hid_t type_id,
hid_t space_id, hid_t plist_id);
H5_DLL hid_t H5Aopen_name(hid_t loc_id, const char *name);
-H5_DLL hid_t H5Aopen_idx(hid_t loc_id, unsigned idx);
+H5_DLL hid_t H5Aopen_by_idx(hid_t loc_id, const char *obj_name,
+ H5_index_t idx_type, H5_iter_order_t order, hsize_t n, hid_t aapl_id,
+ hid_t lapl_id);
H5_DLL herr_t H5Awrite(hid_t attr_id, hid_t type_id, const void *buf);
H5_DLL herr_t H5Aread(hid_t attr_id, hid_t type_id, void *buf);
H5_DLL herr_t H5Aclose(hid_t attr_id);
@@ -56,16 +58,17 @@ H5_DLL hid_t H5Aget_space(hid_t attr_id);
H5_DLL hid_t H5Aget_type(hid_t attr_id);
H5_DLL hid_t H5Aget_create_plist(hid_t attr_id);
H5_DLL ssize_t H5Aget_name(hid_t attr_id, size_t buf_size, char *buf);
+H5_DLL ssize_t H5Aget_name_by_idx(hid_t loc_id, const char *obj_name,
+ H5_index_t idx_type, H5_iter_order_t order, hsize_t n,
+ char *name /*out*/, size_t size, hid_t lapl_id);
H5_DLL hsize_t H5Aget_storage_size(hid_t attr_id);
H5_DLL herr_t H5Aget_info(hid_t loc_id, const char *obj_name,
const char *attr_name, H5A_info_t *ainfo /*out*/, hid_t lapl_id);
H5_DLL herr_t H5Aget_info_by_idx(hid_t loc_id, const char *obj_name,
H5_index_t idx_type, H5_iter_order_t order, hsize_t n,
H5A_info_t *ainfo /*out*/, hid_t lapl_id);
-H5_DLL ssize_t H5Aget_name_by_idx(hid_t loc_id, const char *obj_name,
- H5_index_t idx_type, H5_iter_order_t order, hsize_t n,
- char *name /*out*/, size_t size, hid_t lapl_id);
-H5_DLL herr_t H5Arename(hid_t loc_id, const char *old_name, const char *new_name);
+H5_DLL herr_t H5Arename2(hid_t loc_id, const char *obj_name,
+ const char *old_attr_name, const char *new_attr_name, hid_t lapl_id);
H5_DLL herr_t H5Aiterate2(hid_t loc_id, const char *obj_name, H5_index_t idx_type,
H5_iter_order_t order, hsize_t *idx, H5A_operator2_t op, void *op_data,
hid_t lapd_id);
@@ -79,7 +82,9 @@ H5_DLL herr_t H5Adelete_by_idx(hid_t loc_id, const char *obj_name,
*
* Use of these functions and variables is deprecated.
*/
+H5_DLL hid_t H5Aopen_idx(hid_t loc_id, unsigned idx);
H5_DLL int H5Aget_num_attrs(hid_t loc_id);
+H5_DLL herr_t H5Arename(hid_t loc_id, const char *old_name, const char *new_name);
H5_DLL herr_t H5Aiterate(hid_t loc_id, unsigned *attr_num, H5A_operator_t op,
void *op_data);
H5_DLL herr_t H5Adelete(hid_t loc_id, const char *name);
@@ -89,3 +94,4 @@ H5_DLL herr_t H5Adelete(hid_t loc_id, const char *name);
#endif
#endif /* _H5Apublic_H */
+
diff --git a/src/H5Oattribute.c b/src/H5Oattribute.c
index ea0f073..3d3ae2c 100644
--- a/src/H5Oattribute.c
+++ b/src/H5Oattribute.c
@@ -337,8 +337,8 @@ done:
*-------------------------------------------------------------------------
*/
static herr_t
-H5O_attr_open_cb(H5O_t UNUSED *oh, H5O_mesg_t *mesg/*in,out*/,
- unsigned UNUSED sequence, unsigned UNUSED *oh_flags_ptr, void *_udata/*in,out*/)
+H5O_attr_open_cb(H5O_t *oh, H5O_mesg_t *mesg/*in,out*/, unsigned sequence,
+ unsigned UNUSED *oh_flags_ptr, void *_udata/*in,out*/)
{
H5O_iter_opn_t *udata = (H5O_iter_opn_t *)_udata; /* Operator user data */
herr_t ret_value = H5_ITER_CONT; /* Return value */
@@ -356,6 +356,10 @@ H5O_attr_open_cb(H5O_t UNUSED *oh, H5O_mesg_t *mesg/*in,out*/,
if(NULL == (udata->attr = H5A_copy(NULL, (H5A_t *)mesg->native)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, H5_ITER_ERROR, "unable to copy attribute")
+ /* Assign [somewhat arbitrary] creation order value, for older versions of the format */
+ if(oh->version == H5O_VERSION_1)
+ udata->attr->crt_idx = sequence;
+
/* Stop iterating */
ret_value = H5_ITER_STOP;
} /* end if */