summaryrefslogtreecommitdiffstats
path: root/hl/src/H5DS.c
diff options
context:
space:
mode:
Diffstat (limited to 'hl/src/H5DS.c')
-rw-r--r--hl/src/H5DS.c266
1 files changed, 102 insertions, 164 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c
index faa6d30..432a725 100644
--- a/hl/src/H5DS.c
+++ b/hl/src/H5DS.c
@@ -132,12 +132,12 @@ herr_t H5DSattach_scale(hid_t did,
hid_t ntid = -1; /* attribute native type ID */
hid_t aid = -1; /* attribute ID */
int rank; /* rank of dataset */
- hsize_t dims[1]; /* dimension of the "REFERENCE_LIST" array */
+ hsize_t dims[1]; /* dimension of the "REFERENCE_LIST" array */
ds_list_t dsl; /* attribute data in the DS pointing to the dataset */
- ds_list_t *dsbuf=NULL; /* array of attribute data in the DS pointing to the dataset */
+ ds_list_t *dsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */
hobj_ref_t ref_to_ds; /* reference to the DS */
hobj_ref_t ref_j; /* iterator reference */
- hvl_t *buf=NULL; /* VL buffer to store in the attribute */
+ hvl_t *buf = NULL; /* VL buffer to store in the attribute */
hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
H5O_info_t oi1, oi2;
H5I_type_t it1, it2;
@@ -254,8 +254,7 @@ herr_t H5DSattach_scale(hid_t did,
goto out;
/* allocate and initialize the VL */
- buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
+ buf = (hvl_t *)malloc((size_t)rank * sizeof(hvl_t));
if(buf == NULL)
goto out;
@@ -270,25 +269,21 @@ herr_t H5DSattach_scale(hid_t did,
((hobj_ref_t *)buf[idx].p)[0] = ref_to_ds;
/* write the attribute with the reference */
- if (H5Awrite(aid,tid,buf) < 0)
+ if(H5Awrite(aid, tid, buf) < 0)
goto out;
/* close */
- if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
+ if(H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, buf) < 0)
goto out;
- if (H5Sclose(sid) < 0)
+ if(H5Sclose(sid) < 0)
goto out;
- if (H5Tclose(tid) < 0)
+ if(H5Tclose(tid) < 0)
goto out;
- if (H5Aclose(aid) < 0)
+ if(H5Aclose(aid) < 0)
goto out;
- if (buf)
- {
- free(buf);
- buf = NULL;
- }
-
+ free(buf);
+ buf = NULL;
}
/*-------------------------------------------------------------------------
@@ -296,8 +291,7 @@ herr_t H5DSattach_scale(hid_t did,
* and insert the new reference
*-------------------------------------------------------------------------
*/
-
- else if ( has_dimlist == 1 )
+ else if(has_dimlist == 1)
{
if((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
goto out;
@@ -309,8 +303,7 @@ herr_t H5DSattach_scale(hid_t did,
goto out;
/* allocate and initialize the VL */
- buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
+ buf = (hvl_t *)malloc((size_t)rank * sizeof(hvl_t));
if(buf == NULL)
goto out;
@@ -320,13 +313,12 @@ herr_t H5DSattach_scale(hid_t did,
/* check to avoid inserting duplicates. it is not FAIL, just do nothing */
/* iterate all the REFs in this dimension IDX */
- for (i=0; i<(int)buf[idx].len; i++)
- {
+ for(i = 0; i < (int)buf[idx].len; i++) {
/* get the reference */
ref_j = ((hobj_ref_t *)buf[idx].p)[i];
/* get the scale id for this REF */
- if ((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref_j)) < 0)
+ if((dsid_j = H5Rdereference(did,H5R_OBJECT,&ref_j)) < 0)
goto out;
/* get info for DS in the parameter list */
@@ -342,48 +334,41 @@ herr_t H5DSattach_scale(hid_t did,
found_ds = 1;
/* close the dereferenced dataset */
- if (H5Dclose(dsid_j) < 0)
+ if(H5Dclose(dsid_j) < 0)
goto out;
- }
+ } /* end for */
- if (found_ds==0)
- {
+ if(found_ds == 0) {
/* we are adding one more DS to this dimension */
- if ( buf[idx].len > 0 )
- {
+ if(buf[idx].len > 0) {
buf[idx].len++;
len = buf[idx].len;
- buf[idx].p = realloc( buf[idx].p, len * sizeof(hobj_ref_t));
- ((hobj_ref_t *)buf[idx].p)[ len-1 ] = ref_to_ds;
- }
- else
- {
+ buf[idx].p = realloc(buf[idx].p, len * sizeof(hobj_ref_t));
+ ((hobj_ref_t *)buf[idx].p)[len - 1] = ref_to_ds;
+ } /* end if */
+ else {
/* store the REF information in the index of the dataset that has the DS */
buf[idx].len = 1;
- buf[idx].p = malloc( 1 * sizeof(hobj_ref_t));
+ buf[idx].p = malloc(sizeof(hobj_ref_t));
((hobj_ref_t *)buf[idx].p)[0] = ref_to_ds;
- }
- }
+ } /* end else */
+ } /* end if */
/* write the attribute with the new references */
- if (H5Awrite(aid,tid,buf) < 0)
+ if(H5Awrite(aid, tid, buf) < 0)
goto out;
/* close */
- if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
+ if(H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, buf) < 0)
goto out;
- if (H5Sclose(sid) < 0)
+ if(H5Sclose(sid) < 0)
goto out;
- if (H5Tclose(tid) < 0)
+ if(H5Tclose(tid) < 0)
goto out;
- if (H5Aclose(aid) < 0)
+ if(H5Aclose(aid) < 0)
goto out;
- if (buf)
- {
- free(buf);
- buf = NULL;
- }
-
+ free(buf);
+ buf = NULL;
} /* has_dimlist */
/*-------------------------------------------------------------------------
@@ -392,20 +377,18 @@ herr_t H5DSattach_scale(hid_t did,
*/
/* try to find the attribute "REFERENCE_LIST" on the >>DS<< dataset */
- if ((has_reflist = H5LT_find_attribute(dsid,REFERENCE_LIST)) < 0)
+ if((has_reflist = H5LT_find_attribute(dsid, REFERENCE_LIST)) < 0)
goto out;
/*-------------------------------------------------------------------------
* it does not exist. we create the attribute and its reference data
*-------------------------------------------------------------------------
*/
- if (has_reflist == 0)
- {
-
+ if(has_reflist == 0) {
dims[0] = 1;
/* space for the attribute */
- if ((sid = H5Screate_simple(1,dims,NULL)) < 0)
+ if((sid = H5Screate_simple(1,dims,NULL)) < 0)
goto out;
/* create the compound datatype for the attribute "REFERENCE_LIST" */
@@ -438,16 +421,13 @@ herr_t H5DSattach_scale(hid_t did,
goto out;
if(H5Aclose(aid) < 0)
goto out;
-
- }
+ } /* end if */
/*-------------------------------------------------------------------------
* the "REFERENCE_LIST" array already exists, open it and extend it
*-------------------------------------------------------------------------
*/
-
- else if(has_reflist == 1)
- {
+ else if(has_reflist == 1) {
if((aid = H5Aopen(dsid, REFERENCE_LIST, H5P_DEFAULT)) < 0)
goto out;
@@ -468,17 +448,16 @@ herr_t H5DSattach_scale(hid_t did,
nelmts++;
dsbuf = (ds_list_t*) malloc((size_t)nelmts * sizeof(ds_list_t));
-
- if (dsbuf == NULL)
+ if(dsbuf == NULL)
goto out;
- if (H5Aread(aid,ntid,dsbuf) < 0)
+ if(H5Aread(aid, ntid, dsbuf) < 0)
goto out;
/* close */
- if (H5Sclose(sid) < 0)
+ if(H5Sclose(sid) < 0)
goto out;
- if (H5Aclose(aid) < 0)
+ if(H5Aclose(aid) < 0)
goto out;
/*-------------------------------------------------------------------------
@@ -492,7 +471,7 @@ herr_t H5DSattach_scale(hid_t did,
/* store the IDX information (index of the dataset that has the DS) */
dsl.dim_idx = idx;
- dsbuf[nelmts-1] = dsl;
+ dsbuf[nelmts - 1] = dsl;
/* create a new data space for the new references array */
dims[0] = nelmts;
@@ -518,12 +497,8 @@ herr_t H5DSattach_scale(hid_t did,
if (H5Tclose(ntid) < 0)
goto out;
- if (dsbuf)
- {
- free(dsbuf);
- dsbuf = NULL;
- }
-
+ free(dsbuf);
+ dsbuf = NULL;
} /* has_reflist */
/*-------------------------------------------------------------------------
@@ -531,11 +506,10 @@ herr_t H5DSattach_scale(hid_t did,
*-------------------------------------------------------------------------
*/
- if ((is_ds=H5DSis_scale(dsid)) < 0)
+ if((is_ds=H5DSis_scale(dsid)) < 0)
return FAIL;
- if (is_ds == 0 )
- {
+ if(is_ds == 0) {
if (H5LT_set_attribute_string(dsid,"CLASS",DIMENSION_SCALE_CLASS) < 0)
return FAIL;
}
@@ -544,17 +518,10 @@ herr_t H5DSattach_scale(hid_t did,
/* error zone */
out:
-
- if (buf)
- {
+ if(buf)
free(buf);
- buf = NULL;
- }
- if (dsbuf)
- {
+ if(dsbuf)
free(dsbuf);
- dsbuf = NULL;
- }
H5E_BEGIN_TRY {
H5Sclose(sid);
@@ -706,13 +673,12 @@ herr_t H5DSdetach_scale(hid_t did,
goto out;
/* allocate and initialize the VL */
- buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
+ buf = (hvl_t *)malloc((size_t)rank * sizeof(hvl_t));
if(buf == NULL)
goto out;
/* read */
- if (H5Aread(aid,tid,buf) < 0)
+ if(H5Aread(aid, tid, buf) < 0)
goto out;
/* reset */
@@ -747,7 +713,8 @@ herr_t H5DSdetach_scale(hid_t did,
and reset to NULL */
size_t len = buf[idx].len;
- if(j<len-1)
+
+ if(j < len - 1)
((hobj_ref_t *)buf[idx].p)[j] = ((hobj_ref_t *)buf[idx].p)[len-1];
len = --buf[idx].len;
if(len == 0) {
@@ -768,36 +735,33 @@ herr_t H5DSdetach_scale(hid_t did,
/* Write the attribute, but check first, if we have any scales left,
because if not, we should delete the attribute according to the spec */
- for(i=0; i < rank; i++) {
+ for(i = 0; i < rank; i++) {
if(buf[i].len > 0) {
have_ds = 1;
break;
}
}
if(have_ds) {
- if(H5Awrite(aid,tid,buf) < 0)
+ if(H5Awrite(aid, tid, buf) < 0)
goto out;
}
else {
- if(H5Adelete(did,DIMENSION_LIST) < 0)
+ if(H5Adelete(did, DIMENSION_LIST) < 0)
goto out;
}
/* close */
- if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
+ if(H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, buf) < 0)
goto out;
- if (H5Sclose(sid) < 0)
+ if(H5Sclose(sid) < 0)
goto out;
- if (H5Tclose(tid) < 0)
+ if(H5Tclose(tid) < 0)
goto out;
- if (H5Aclose(aid) < 0)
+ if(H5Aclose(aid) < 0)
goto out;
- if (buf)
- {
- free(buf);
- buf = NULL;
- }
+ free(buf);
+ buf = NULL;
/*-------------------------------------------------------------------------
@@ -826,7 +790,7 @@ herr_t H5DSdetach_scale(hid_t did,
if(dsbuf == NULL)
goto out;
- if (H5Aread(aid,ntid,dsbuf) < 0)
+ if(H5Aread(aid, ntid, dsbuf) < 0)
goto out;
for(ii=0; ii<nelmts; ii++) {
@@ -914,12 +878,8 @@ herr_t H5DSdetach_scale(hid_t did,
if (H5Tclose(ntid) < 0)
goto out;
- if (dsbuf)
- {
- free(dsbuf);
- dsbuf=NULL;
- }
-
+ free(dsbuf);
+ dsbuf = NULL;
return SUCCEED;
@@ -931,21 +891,19 @@ out:
H5Tclose(ntid);
H5Tclose(tid);
- if (dsbuf)
- {
+ if(dsbuf) {
free(dsbuf);
- dsbuf=NULL;
+ dsbuf = NULL;
}
- if (buf)
- {
+ if(buf) {
/* Failure occured before H5Dvlen_reclaim was called;
free the pointers allocated when we read data in */
- for(i=0; i<rank; i++) {
+ for(i = 0; i < rank; i++) {
if(buf[i].p)
free(buf[i].p);
}
free(buf);
- buf=NULL;
+ buf = NULL;
}
} H5E_END_TRY;
return FAIL;
@@ -991,9 +949,9 @@ htri_t H5DSis_attached(hid_t did,
hid_t ntid = -1; /* attribute native type ID */
hid_t aid = -1; /* attribute ID */
int rank; /* rank of dataset */
- ds_list_t *dsbuf; /* array of attribute data in the DS pointing to the dataset */
+ ds_list_t *dsbuf = NULL; /* array of attribute data in the DS pointing to the dataset */
hobj_ref_t ref; /* reference to the DS */
- hvl_t *buf; /* VL buffer to store in the attribute */
+ hvl_t *buf = NULL; /* VL buffer to store in the attribute */
hid_t dsid_j; /* DS dataset ID in DIMENSION_LIST */
hid_t did_i; /* dataset ID in REFERENCE_LIST */
H5O_info_t oi1, oi2, oi3, oi4;
@@ -1078,7 +1036,6 @@ htri_t H5DSis_attached(hid_t did,
/* allocate and initialize the VL */
buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
if(buf == NULL)
goto out;
@@ -1124,11 +1081,8 @@ htri_t H5DSis_attached(hid_t did,
goto out;
if (H5Aclose(aid) < 0)
goto out;
- if (buf)
- {
- free(buf);
- buf = NULL;
- }
+ free(buf);
+ buf = NULL;
} /* has_dimlist */
/*-------------------------------------------------------------------------
@@ -1217,11 +1171,9 @@ htri_t H5DSis_attached(hid_t did,
goto out;
if (H5Aclose(aid) < 0)
goto out;
- if (dsbuf)
- {
- free(dsbuf);
- dsbuf = NULL;
- }
+
+ free(dsbuf);
+ dsbuf = NULL;
} /* has_reflist */
if (found_ds && found_dset)
@@ -1238,13 +1190,11 @@ out:
H5Tclose(ntid);
} H5E_END_TRY;
- if (buf)
- {
+ if (buf) {
free(buf);
buf = NULL;
}
- if (dsbuf)
- {
+ if(dsbuf) {
free(dsbuf);
dsbuf = NULL;
}
@@ -1307,7 +1257,7 @@ herr_t H5DSiterate_scales(hid_t did,
hid_t sid; /* space ID */
hid_t tid = -1; /* attribute type ID */
hid_t aid = -1; /* attribute ID */
- hvl_t *buf=NULL; /* VL buffer to store in the attribute */
+ hvl_t *buf = NULL; /* VL buffer to store in the attribute */
H5I_type_t it; /* ID type */
herr_t ret_value=0;
int j_idx;
@@ -1431,20 +1381,16 @@ herr_t H5DSiterate_scales(hid_t did,
goto out;
if (H5Aclose(aid) < 0)
goto out;
- if (buf)
- {
- free(buf);
- buf = NULL;
- }
+ free(buf);
+ buf = NULL;
} /* if has_dimlist */
return ret_value;
out:
H5E_BEGIN_TRY {
- if (buf)
- {
+ if(buf) {
H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf);
free(buf);
}
@@ -1452,6 +1398,7 @@ out:
H5Aclose(aid);
H5Tclose(tid);
} H5E_END_TRY;
+
return FAIL;
}
@@ -2048,7 +1995,7 @@ int H5DSget_num_scales(hid_t did,
hid_t tid = -1; /* attribute type ID */
hid_t aid = -1; /* attribute ID */
int rank; /* rank of dataset */
- hvl_t *buf; /* VL buffer to store in the attribute */
+ hvl_t *buf = NULL; /* VL buffer to store in the attribute */
H5I_type_t it; /* ID type */
int nscales;
@@ -2057,10 +2004,10 @@ int H5DSget_num_scales(hid_t did,
*-------------------------------------------------------------------------
*/
/* get ID type */
- if ((it = H5Iget_type(did)) < 0)
+ if((it = H5Iget_type(did)) < 0)
return FAIL;
- if (H5I_DATASET!=it)
+ if(H5I_DATASET != it)
return FAIL;
/*-------------------------------------------------------------------------
@@ -2068,19 +2015,19 @@ int H5DSget_num_scales(hid_t did,
*-------------------------------------------------------------------------
*/
/* get dataset space */
- if ((sid = H5Dget_space(did)) < 0)
+ if((sid = H5Dget_space(did)) < 0)
return FAIL;
/* get rank */
- if ((rank=H5Sget_simple_extent_ndims(sid)) < 0)
+ if((rank = H5Sget_simple_extent_ndims(sid)) < 0)
goto out;
/* close dataset space */
- if (H5Sclose(sid) < 0)
+ if(H5Sclose(sid) < 0)
goto out;
/* dimemsion index IDX range checking */
- if (idx>=(unsigned int )rank)
+ if(idx >= (unsigned int )rank)
return FAIL;
/* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
@@ -2095,9 +2042,7 @@ int H5DSget_num_scales(hid_t did,
* the attribute exists, open it
*-------------------------------------------------------------------------
*/
-
- else
- {
+ else {
if((aid = H5Aopen(did, DIMENSION_LIST, H5P_DEFAULT)) < 0)
goto out;
if((tid = H5Aget_type(aid)) < 0)
@@ -2106,8 +2051,7 @@ int H5DSget_num_scales(hid_t did,
goto out;
/* allocate and initialize the VL */
- buf = (hvl_t*)malloc((size_t)rank * sizeof(hvl_t));
-
+ buf = (hvl_t *)malloc((size_t)rank * sizeof(hvl_t));
if(buf == NULL)
goto out;
@@ -2115,23 +2059,19 @@ int H5DSget_num_scales(hid_t did,
if(H5Aread(aid, tid, buf) < 0)
goto out;
- nscales=(int)buf[idx].len;
+ nscales = (int)buf[idx].len;
/* close */
- if (H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf) < 0)
+ if(H5Dvlen_reclaim(tid, sid, H5P_DEFAULT, buf) < 0)
goto out;
- if (H5Sclose(sid) < 0)
+ if(H5Sclose(sid) < 0)
goto out;
- if (H5Tclose(tid) < 0)
+ if(H5Tclose(tid) < 0)
goto out;
- if (H5Aclose(aid) < 0)
+ if(H5Aclose(aid) < 0)
goto out;
- if (buf)
- {
- free(buf);
- buf = NULL;
- }
-
+ free(buf);
+ buf = NULL;
} /* has_dimlist */
return nscales;
@@ -2144,11 +2084,9 @@ out:
H5Tclose(tid);
} H5E_END_TRY;
- if (buf)
- {
+ if(buf)
free(buf);
- buf = NULL;
- }
+
return FAIL;
}