summaryrefslogtreecommitdiffstats
path: root/src/H5A.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5A.c')
-rw-r--r--src/H5A.c109
1 files changed, 50 insertions, 59 deletions
diff --git a/src/H5A.c b/src/H5A.c
index 0c08dc8..f19732c 100644
--- a/src/H5A.c
+++ b/src/H5A.c
@@ -105,7 +105,7 @@ H5A_init_interface(void)
static void
H5A_term_interface(void)
{
- H5I_destroy_group (H5_ATTR);
+ H5I_destroy_group(H5_ATTR);
}
@@ -152,12 +152,14 @@ H5Acreate(hid_t loc_id, const char *name, hid_t datatype, hid_t dataspace,
H5T_t *type = NULL;
H5S_t *space = NULL;
const H5D_create_t *create_parms = NULL;
+ H5A_t found_attr;
+ intn seq=0;
hid_t ret_value = FAIL;
FUNC_ENTER(H5Acreate, FAIL);
/* check arguments */
- if (!(H5_DATASET != H5I_group(loc_id) || H5_GROUP != H5I_group(loc_id))) {
+ if (!(H5_DATASET == H5I_group(loc_id) || H5_GROUP == H5I_group(loc_id))) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "attribute target not a dataset or group");
}
if (!name || !*name) {
@@ -189,6 +191,20 @@ H5Acreate(hid_t loc_id, const char *name, hid_t datatype, hid_t dataspace,
else
ent = H5G_entof ((H5G_t*)obj);
+ /* Read in the existing attributes to check for duplicates */
+ seq=0;
+ while(H5O_read(ent, H5O_ATTR, seq, &found_attr)!=NULL)
+ {
+ /* Compare found attribute name to new attribute name reject creation if names are the same */
+ if(HDstrcmp(found_attr.name,name)==0) {
+ H5O_reset (H5O_ATTR, &found_attr);
+ HRETURN_ERROR(H5E_ATTR, H5E_CANTCREATE, FAIL,
+ "attribute already exists");
+ }
+ seq++;
+ H5O_reset (H5O_ATTR, &found_attr);
+ } /* end while */
+
/* Go do the real work for attaching the attribute to the dataset */
ret_value=H5A_create(ent,name,type,space);
@@ -220,8 +236,6 @@ static hid_t
H5A_create(const H5G_entry_t *ent, const char *name, const H5T_t *type, const H5S_t *space)
{
H5A_t *attr = NULL;
- H5A_t found_attr;
- intn seq=0;
hid_t ret_value = FAIL;
FUNC_ENTER(H5A_create, FAIL);
@@ -254,22 +268,6 @@ H5A_create(const H5G_entry_t *ent, const char *name, const H5T_t *type, const H5
}
attr->ent_opened=1;
- /* Read in the existing attributes to check for duplicates */
- seq=0;
- while(H5O_read(&(attr->ent), H5O_ATTR, seq, &found_attr)!=NULL) {
- /*
- * Compare found attribute name to new attribute name reject creation
- * if names are the same.
- */
- if(HDstrcmp(found_attr.name,attr->name)==0) {
- H5O_reset (H5O_ATTR, &found_attr);
- HGOTO_ERROR(H5E_ATTR, H5E_CANTCREATE, FAIL,
- "attribute already exists");
- }
- H5O_reset (H5O_ATTR, &found_attr);
- seq++;
- } /* end while */
-
/* Create the attribute message and save the attribute index */
if (H5O_modify(&(attr->ent), H5O_ATTR, H5O_NEW_MESG, 0, attr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL,
@@ -324,24 +322,21 @@ H5A_get_index(H5G_entry_t *ent, const char *name)
/* Look up the attribute for the object */
i=0;
- while(H5O_read(ent, H5O_ATTR, i, &found_attr)!=NULL) {
- /*
- * Compare found attribute name to new attribute name reject creation
- * if names are the same.
- */
- if(HDstrcmp(found_attr.name,name)==0) {
- H5O_reset (H5O_ATTR, &found_attr);
- ret_value = i;
- break;
- }
- H5O_reset (H5O_ATTR, &found_attr);
- i++;
- } /* end while */
-
+ while(H5O_read(ent, H5O_ATTR, i, &found_attr)!=NULL)
+ {
+ /* Compare found attribute name to new attribute name reject creation if names are the same */
+ if(HDstrcmp(found_attr.name,name)==0) {
+ H5O_reset (H5O_ATTR, &found_attr);
+ ret_value=i;
+ break;
+ }
+ H5O_reset (H5O_ATTR, &found_attr);
+ i++;
+ } /* end while */
if(ret_value<0) {
HRETURN_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL,
"attribute not found");
- }
+ }
FUNC_LEAVE(ret_value);
} /* H5A_get_index() */
@@ -380,7 +375,7 @@ H5Aopen_name(hid_t loc_id, const char *name)
FUNC_ENTER(H5Aopen_name, FAIL);
/* check arguments */
- if (!(H5_DATASET != H5I_group(loc_id) || H5_GROUP != H5I_group(loc_id))) {
+ if (!(H5_DATASET == H5I_group(loc_id) || H5_GROUP == H5I_group(loc_id))) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "attribute target not a dataset or group");
}
if (!name || !*name) {
@@ -440,7 +435,7 @@ H5Aopen_idx(hid_t loc_id, unsigned idx)
FUNC_ENTER(H5Aopen_idx, FAIL);
/* check arguments */
- if (!(H5_DATASET != H5I_group(loc_id) || H5_GROUP != H5I_group(loc_id))) {
+ if (!(H5_DATASET == H5I_group(loc_id) || H5_GROUP == H5I_group(loc_id))) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "attribute target not a dataset or group");
}
@@ -613,7 +608,6 @@ H5A_write(H5A_t *attr, const H5T_t *mem_type, void *buf)
assert(mem_type);
assert(buf);
-
/* Create buffer for data to store on disk */
nelmts=H5S_get_npoints (attr->ds);
@@ -1021,7 +1015,7 @@ H5Anum_attrs(hid_t loc_id)
FUNC_ENTER(H5Anum_attrs, FAIL);
/* check arguments */
- if (!(H5_DATASET != H5I_group(loc_id) || H5_GROUP != H5I_group(loc_id))) {
+ if (!(H5_DATASET == H5I_group(loc_id) || H5_GROUP == H5I_group(loc_id))) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "attribute target not a dataset or group");
}
@@ -1090,7 +1084,7 @@ H5Aiterate(hid_t loc_id, unsigned *attr_num, H5A_operator_t op, void *op_data)
FUNC_ENTER(H5Anum_attrs, FAIL);
/* check arguments */
- if (!(H5_DATASET != H5I_group(loc_id) || H5_GROUP != H5I_group(loc_id))) {
+ if (!(H5_DATASET == H5I_group(loc_id) || H5_GROUP == H5I_group(loc_id))) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "attribute target not a dataset or group");
}
if (!attr_num) {
@@ -1117,9 +1111,9 @@ H5Aiterate(hid_t loc_id, unsigned *attr_num, H5A_operator_t op, void *op_data)
/* Compare found attribute name to new attribute name reject creation if names are the same */
(*attr_num)++;
if((ret_value=op(loc_id,found_attr.name,op_data))!=0) {
- H5O_reset (H5O_ATTR, &found_attr);
+ H5O_reset (H5O_ATTR, &found_attr);
break;
- }
+ }
H5O_reset (H5O_ATTR, &found_attr);
} /* end while */
@@ -1159,7 +1153,7 @@ H5Adelete(hid_t loc_id, const char *name)
FUNC_ENTER(H5Aopen_name, FAIL);
/* check arguments */
- if (!(H5_DATASET != H5I_group(loc_id) || H5_GROUP != H5I_group(loc_id))) {
+ if (!(H5_DATASET == H5I_group(loc_id) || H5_GROUP == H5I_group(loc_id))) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "attribute target not a dataset or group");
}
if (!name || !*name) {
@@ -1178,20 +1172,18 @@ H5Adelete(hid_t loc_id, const char *name)
/* Look up the attribute for the object */
idx=0;
- while(H5O_read(ent, H5O_ATTR, idx, &found_attr)!=NULL) {
- /*
- * Compare found attribute name to new attribute name reject
- * creation if names are the same.
- */
- if(HDstrcmp(found_attr.name,name)==0) {
- H5O_reset (H5O_ATTR, &found_attr);
- found = idx;
- break;
- }
- H5O_reset (H5O_ATTR, &found_attr);
- idx++;
- } /* end while */
- if (found<0) {
+ while(H5O_read(ent, H5O_ATTR, idx, &found_attr)!=NULL)
+ {
+ /* Compare found attribute name to new attribute name reject creation if names are the same */
+ if(HDstrcmp(found_attr.name,name)==0) {
+ H5O_reset (H5O_ATTR, &found_attr);
+ found=idx;
+ break;
+ }
+ H5O_reset (H5O_ATTR, &found_attr);
+ idx++;
+ } /* end while */
+ if(found<0) {
HRETURN_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL,
"attribute not found");
}
@@ -1228,8 +1220,7 @@ H5Aclose(hid_t attr_id)
FUNC_ENTER(H5Aclose, FAIL);
/* check arguments */
- if (H5_ATTR != H5I_group(attr_id) ||
- NULL == H5I_object(attr_id)) {
+ if (H5_ATTR != H5I_group(attr_id) || NULL == H5I_object(attr_id)) {
HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute");
}