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.c680
1 files changed, 311 insertions, 369 deletions
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c
index 067992f..eac4d23 100644
--- a/hl/src/H5DS.c
+++ b/hl/src/H5DS.c
@@ -11,9 +11,6 @@
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
#include "H5DSprivate.h"
#include "H5LTprivate.h"
#include "H5IMprivate.h"
@@ -25,29 +22,24 @@ static herr_t H5DS_is_reserved(hid_t did);
static hid_t H5DS_get_REFLIST_type(void);
/*-------------------------------------------------------------------------
-* Function: H5DSset_scale
-*
-* Purpose: The dataset DSID is converted to a Dimension Scale dataset.
-* Creates the CLASS attribute, set to the value "DIMENSION_SCALE"
-* and an empty REFERENCE_LIST attribute.
-* If DIMNAME is specified, then an attribute called NAME is created,
-* with the value DIMNAME.
-*
-* Return: Success: SUCCEED, Failure: FAIL
-*
-* Programmer: pvn@ncsa.uiuc.edu
-*
-* Date: January 04, 2005
-*
-* Comments:
-*
-* Modifications:
-*
-*-------------------------------------------------------------------------
-*/
-
-herr_t H5DSset_scale(hid_t dsid,
- const char *dimname)
+ * Function: H5DSset_scale
+ *
+ * Purpose: The dataset DSID is converted to a Dimension Scale dataset.
+ * Creates the CLASS attribute, set to the value "DIMENSION_SCALE"
+ * and an empty REFERENCE_LIST attribute.
+ * If DIMNAME is specified, then an attribute called NAME is created,
+ * with the value DIMNAME.
+ *
+ * Return: Success: SUCCEED, Failure: FAIL
+ *
+ * Programmer: Pedro Vicente
+ *
+ * Date: January 04, 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5DSset_scale(hid_t dsid, const char *dimname)
{
int has_dimlist;
H5I_type_t it;
@@ -95,34 +87,28 @@ herr_t H5DSset_scale(hid_t dsid,
/*-------------------------------------------------------------------------
-* Function: H5DSattach_scale
-*
-* Purpose: Define Dimension Scale DSID to be associated with dimension IDX
-* of Dataset DID. Entries are created in the DIMENSION_LIST and
-* REFERENCE_LIST attributes.
-*
-* Return:
-* Success: SUCCEED
-* Failure: FAIL
-*
-* Fails if: Bad arguments
-* If DSID is not a Dimension Scale
-* If DID is a Dimension Scale (A Dimension Scale cannot have scales)
-*
-* Programmer: pvn@ncsa.uiuc.edu
-*
-* Date: December 20, 2004
-*
-* Comments:
-*
-* Modifications:
-*
-*-------------------------------------------------------------------------
-*/
-
-herr_t H5DSattach_scale(hid_t did,
- hid_t dsid,
- unsigned int idx)
+ * Function: H5DSattach_scale
+ *
+ * Purpose: Define Dimension Scale DSID to be associated with dimension IDX
+ * of Dataset DID. Entries are created in the DIMENSION_LIST and
+ * REFERENCE_LIST attributes.
+ *
+ * Return:
+ * Success: SUCCEED
+ * Failure: FAIL
+ *
+ * Fails if: Bad arguments
+ * If DSID is not a Dimension Scale
+ * If DID is a Dimension Scale (A Dimension Scale cannot have scales)
+ *
+ * Programmer: Pedro Vicente
+ *
+ * Date: December 20, 2004
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5DSattach_scale(hid_t did, hid_t dsid, unsigned int idx)
{
int has_dimlist;
int has_reflist;
@@ -143,7 +129,7 @@ herr_t H5DSattach_scale(hid_t did,
H5O_info_t oi1, oi2;
H5I_type_t it1, it2;
int i;
- size_t len;
+ size_t len;
int found_ds=0;
htri_t is_scale;
@@ -156,7 +142,7 @@ herr_t H5DSattach_scale(hid_t did,
return FAIL;
/* the dataset cannot be a DS dataset */
- if ( is_scale == 1)
+ if (is_scale == 1)
return FAIL;
/* get info for the dataset in the parameter list */
@@ -177,7 +163,7 @@ herr_t H5DSattach_scale(hid_t did,
if ((it2 = H5Iget_type(dsid)) < 0)
return FAIL;
- if (H5I_DATASET!=it1 || H5I_DATASET!=it2)
+ if (H5I_DATASET != it1 || H5I_DATASET != it2)
return FAIL;
/* the DS dataset cannot have dimension scales */
@@ -202,19 +188,19 @@ herr_t H5DSattach_scale(hid_t did,
return FAIL;
/* get rank */
- if ((rank=H5Sget_simple_extent_ndims(sid)) < 0)
+ if ((rank = H5Sget_simple_extent_ndims(sid)) < 0)
goto out;
/* scalar rank */
- if (rank==0)
- rank=1;
+ if (rank == 0)
+ rank = 1;
/* close dataset space */
if (H5Sclose(sid) < 0)
return FAIL;
/* parameter range checking */
- if (idx>(unsigned)rank-1)
+ if (idx > (unsigned)rank-1)
return FAIL;
/*-------------------------------------------------------------------------
@@ -508,7 +494,7 @@ 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) {
@@ -535,39 +521,31 @@ out:
}
/*-------------------------------------------------------------------------
-* Function: H5DSdetach_scale
-*
-* Purpose: If possible, deletes association of Dimension Scale DSID with
-* dimension IDX of Dataset DID. This deletes the entries in the
-* DIMENSION_LIST and REFERENCE_LIST attributes.
-*
-* Return:
-* Success: SUCCEED
-* Failure: FAIL
-*
-* Fails if: Bad arguments
-* The dataset DID or DSID do not exist.
-* The DSID is not a Dimension Scale
-* DSID is not attached to DID.
-* Note that a scale may be associated with more than dimension of the same dataset.
-* If so, the detach operation only deletes one of the associations, for DID.
-*
-* Programmer: pvn@ncsa.uiuc.edu
-*
-* Date: December 20, 2004
-*
-* Comments:
-*
-* Modifications: Function didn't delete DIMENSION_LIST attribute, when
-* all dimension scales were detached from a dataset; added.
-* 2010/05/13 EIP
-*
-*-------------------------------------------------------------------------
-*/
-
-herr_t H5DSdetach_scale(hid_t did,
- hid_t dsid,
- unsigned int idx)
+ * Function: H5DSdetach_scale
+ *
+ * Purpose: If possible, deletes association of Dimension Scale DSID with
+ * dimension IDX of Dataset DID. This deletes the entries in the
+ * DIMENSION_LIST and REFERENCE_LIST attributes.
+ *
+ * Return:
+ * Success: SUCCEED
+ * Failure: FAIL
+ *
+ * Fails if: Bad arguments
+ * The dataset DID or DSID do not exist.
+ * The DSID is not a Dimension Scale
+ * DSID is not attached to DID.
+ * Note that a scale may be associated with more than dimension of the same dataset.
+ * If so, the detach operation only deletes one of the associations, for DID.
+ *
+ * Programmer: Pedro Vicente
+ *
+ * Date: December 20, 2004
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5DSdetach_scale(hid_t did, hid_t dsid, unsigned int idx)
{
int has_dimlist;
int has_reflist;
@@ -598,7 +576,7 @@ herr_t H5DSdetach_scale(hid_t did,
/* check for valid types of identifiers */
- if(H5I_DATASET!=H5Iget_type(did) || H5I_DATASET!=H5Iget_type(dsid))
+ if(H5I_DATASET != H5Iget_type(did) || H5I_DATASET != H5Iget_type(dsid))
return FAIL;
if((is_scale = H5DSis_scale(did)) < 0)
@@ -626,7 +604,7 @@ herr_t H5DSdetach_scale(hid_t did,
*-------------------------------------------------------------------------
*/
/* try to find the attribute "DIMENSION_LIST" on the >>data<< dataset */
- if ((has_dimlist = H5LT_find_attribute(did,DIMENSION_LIST)) < 0)
+ if ((has_dimlist = H5LT_find_attribute(did, DIMENSION_LIST)) < 0)
return FAIL;
if (has_dimlist == 0)
@@ -637,7 +615,7 @@ herr_t H5DSdetach_scale(hid_t did,
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 */
@@ -645,7 +623,7 @@ herr_t H5DSdetach_scale(hid_t did,
return FAIL;
/* parameter range checking */
- if (idx>(unsigned)rank-1)
+ if (idx > (unsigned)rank-1)
return FAIL;
/*-------------------------------------------------------------------------
@@ -704,8 +682,7 @@ herr_t H5DSdetach_scale(hid_t did,
goto out;
/* same object, reset */
- if(dsid_oi.fileno == tmp_oi.fileno && dsid_oi.addr == tmp_oi.addr)
- {
+ if(dsid_oi.fileno == tmp_oi.fileno && dsid_oi.addr == tmp_oi.addr) {
/* If there are more than one reference in the VL element
and the reference we found is not the last one,
copy the last one to replace the found one since the order
@@ -727,7 +704,7 @@ herr_t H5DSdetach_scale(hid_t did,
we do not need to continue the search if it is found */
found_ds = 1;
break;
- }
+ } /* end if */
} /* j */
} /* if */
@@ -795,7 +772,7 @@ herr_t H5DSdetach_scale(hid_t did,
if(H5Aread(aid, ntid, dsbuf) < 0)
goto out;
- for(ii=0; ii<nelmts; ii++) {
+ for(ii = 0; ii < nelmts; ii++) {
/* First check if we have the same dimension index */
if(idx == dsbuf[ii].dim_idx) {
/* get the reference to the dataset */
@@ -820,7 +797,7 @@ herr_t H5DSdetach_scale(hid_t did,
nelmts--;
found_dset=1;
break;
- } /* if */
+ } /* end if */
} /* if we have the same dimension index */
} /* ii */
@@ -911,35 +888,29 @@ out:
}
/*-------------------------------------------------------------------------
-* Function: H5DSis_attached
-*
-* Purpose: Report if dimension scale DSID is currently attached to
-* dimension IDX of dataset DID by checking if DID has a pointer in the REFERENCE_LIST
-* attribute and DSID (scale ) has a pointer in the DIMENSION_LIST attribute
-*
-* Return:
-* 1: both the DS and the dataset pointers match
-* 0: one of them or both do not match
-* FAIL (-1): error
-*
-* Fails if: Bad arguments
-* If DSID is not a Dimension Scale
-* If DID is a Dimension Scale (A Dimension Scale cannot have scales)
-*
-* Programmer: pvn@ncsa.uiuc.edu
-*
-* Date: February 18, 2005
-*
-* Comments:
-*
-* Modifications:
-*
-*-------------------------------------------------------------------------
-*/
-
-htri_t H5DSis_attached(hid_t did,
- hid_t dsid,
- unsigned int idx)
+ * Function: H5DSis_attached
+ *
+ * Purpose: Report if dimension scale DSID is currently attached to
+ * dimension IDX of dataset DID by checking if DID has a pointer in the REFERENCE_LIST
+ * attribute and DSID (scale ) has a pointer in the DIMENSION_LIST attribute
+ *
+ * Return:
+ * 1: both the DS and the dataset pointers match
+ * 0: one of them or both do not match
+ * FAIL (-1): error
+ *
+ * Fails if: Bad arguments
+ * If DSID is not a Dimension Scale
+ * If DID is a Dimension Scale (A Dimension Scale cannot have scales)
+ *
+ * Programmer: Pedro Vicente
+ *
+ * Date: February 18, 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+htri_t
+H5DSis_attached(hid_t did, hid_t dsid, unsigned int idx)
{
int has_dimlist;
int has_reflist;
@@ -990,7 +961,7 @@ htri_t H5DSis_attached(hid_t did,
if ((it2 = H5Iget_type(dsid)) < 0)
return FAIL;
- if (H5I_DATASET!=it1 || H5I_DATASET!=it2)
+ if (H5I_DATASET != it1 || H5I_DATASET != it2)
return FAIL;
/*-------------------------------------------------------------------------
@@ -1040,7 +1011,7 @@ htri_t H5DSis_attached(hid_t did,
goto out;
/* read */
- if (H5Aread(aid,tid,buf) < 0)
+ if (H5Aread(aid, tid, buf) < 0)
goto out;
/* iterate all the REFs in this dimension IDX */
@@ -1050,7 +1021,7 @@ htri_t H5DSis_attached(hid_t did,
ref = ((hobj_ref_t *)buf[idx].p)[i];
/* get the scale id for this REF */
- if ((dsid_j = H5Rdereference2(did,H5P_DEFAULT,H5R_OBJECT,&ref)) < 0)
+ if ((dsid_j = H5Rdereference2(did, H5P_DEFAULT, H5R_OBJECT, &ref)) < 0)
goto out;
/* get info for DS in the parameter list */
@@ -1073,7 +1044,7 @@ htri_t H5DSis_attached(hid_t did,
/* 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)
goto out;
@@ -1123,7 +1094,7 @@ htri_t H5DSis_attached(hid_t did,
if (dsbuf == NULL)
goto out;
- if (H5Aread(aid,ntid,dsbuf) < 0)
+ if (H5Aread(aid, ntid, dsbuf) < 0)
goto out;
/*-------------------------------------------------------------------------
@@ -1131,7 +1102,7 @@ htri_t H5DSis_attached(hid_t did,
*-------------------------------------------------------------------------
*/
- for(i=0; i<nelmts; i++)
+ for(i = 0; i < nelmts; i++)
{
/* get the reference */
ref = dsbuf[i].ref;
@@ -1202,54 +1173,47 @@ out:
}
/*-------------------------------------------------------------------------
-* Function: H5DSiterate_scales
-*
-* Purpose: H5DSiterate_scales iterates over the scales attached to dimension DIM
-* of dataset DID. For each scale in the list, the visitor_data and some
-* additional information, specified below, are passed to the visitor function.
-* The iteration begins with the IDX object in the group and the next element
-* to be processed by the operator is returned in IDX. If IDX is NULL, then the
-* iterator starts at zero.
-*
-* Parameters:
-*
-* hid_t DID; IN: the dataset
-* unsigned int DIM; IN: the dimension of the dataset
-* int *DS_IDX; IN/OUT: on input the dimension scale index to start iterating,
-* on output the next index to visit. If NULL, start at
-* the first position.
-* H5DS_iterate_t VISITOR; IN: the visitor function
-* void *VISITOR_DATA; IN: arbitrary data to pass to the visitor function.
-*
-* Iterate over all scales of DIM, calling an application callback
-* with the item, key and any operator data.
-*
-* The operator callback receives a pointer to the item ,
-* and the pointer to the operator data passed
-* in to H5SL_iterate ('op_data'). The return values from an operator are:
-* A. Zero causes the iterator to continue, returning zero when all
-* nodes of that type have been processed.
-* B. Positive causes the iterator to immediately return that positive
-* value, indicating short-circuit success.
-* C. Negative causes the iterator to immediately return that value,
-* indicating failure.
-*
-* Programmer: pvn@ncsa.uiuc.edu
-*
-* Date: January 31, 2005
-*
-* Comments:
-*
-* Modifications:
-*
-*-------------------------------------------------------------------------
-*/
-
-herr_t H5DSiterate_scales(hid_t did,
- unsigned int dim,
- int *ds_idx,
- H5DS_iterate_t visitor,
- void *visitor_data )
+ * Function: H5DSiterate_scales
+ *
+ * Purpose: H5DSiterate_scales iterates over the scales attached to dimension DIM
+ * of dataset DID. For each scale in the list, the visitor_data and some
+ * additional information, specified below, are passed to the visitor function.
+ * The iteration begins with the IDX object in the group and the next element
+ * to be processed by the operator is returned in IDX. If IDX is NULL, then the
+ * iterator starts at zero.
+ *
+ * Parameters:
+ *
+ * hid_t DID; IN: the dataset
+ * unsigned int DIM; IN: the dimension of the dataset
+ * int *DS_IDX; IN/OUT: on input the dimension scale index to start iterating,
+ * on output the next index to visit. If NULL, start at
+ * the first position.
+ * H5DS_iterate_t VISITOR; IN: the visitor function
+ * void *VISITOR_DATA; IN: arbitrary data to pass to the visitor function.
+ *
+ * Iterate over all scales of DIM, calling an application callback
+ * with the item, key and any operator data.
+ *
+ * The operator callback receives a pointer to the item ,
+ * and the pointer to the operator data passed
+ * in to H5SL_iterate ('op_data'). The return values from an operator are:
+ * A. Zero causes the iterator to continue, returning zero when all
+ * nodes of that type have been processed.
+ * B. Positive causes the iterator to immediately return that positive
+ * value, indicating short-circuit success.
+ * C. Negative causes the iterator to immediately return that value,
+ * indicating failure.
+ *
+ * Programmer: Pedro Vicente
+ *
+ * Date: January 31, 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5DSiterate_scales(hid_t did, unsigned int dim, int *ds_idx,
+ H5DS_iterate_t visitor, void *visitor_data )
{
hid_t scale_id;
int rank;
@@ -1403,24 +1367,20 @@ out:
}
/*-------------------------------------------------------------------------
-* Function: H5DSset_label
-*
-* Purpose: Set label for the dimension IDX of dataset DID to the value LABEL
-*
-* Return: Success: SUCCEED, Failure: FAIL
-*
-* Programmer: pvn@ncsa.uiuc.edu
-*
-* Date: January 11, 2005
-*
-* Comments:
-*
-* Modifications:
-*
-*-------------------------------------------------------------------------
-*/
-
-herr_t H5DSset_label(hid_t did, unsigned int idx, const char *label)
+ * Function: H5DSset_label
+ *
+ * Purpose: Set label for the dimension IDX of dataset DID to the value LABEL
+ *
+ * Return: Success: SUCCEED, Failure: FAIL
+ *
+ * Programmer: Pedro Vicente
+ *
+ * Date: January 11, 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5DSset_label(hid_t did, unsigned int idx, const char *label)
{
int has_labels;
hid_t sid = -1; /* space ID */
@@ -1434,6 +1394,9 @@ herr_t H5DSset_label(hid_t did, unsigned int idx, const char *label)
char ** buf; /* discarding the 'const' qualifier in the free */
char const ** const_buf; /* buf calls */
} u;
+
+ HDmemset(&u, 0, sizeof(u));
+
/*-------------------------------------------------------------------------
* parameter checking
*-------------------------------------------------------------------------
@@ -1609,29 +1572,24 @@ out:
}
/*-------------------------------------------------------------------------
-* Function: H5DSget_label
-*
-* Purpose: Read the label LABEL for dimension IDX of dataset DID
-* Up to 'size' characters are stored in 'label' followed by a '\0' string
-* terminator. If the label is longer than 'size'-1,
-* the string terminator is stored in the last position of the buffer to
-* properly terminate the string.
-*
-* Return: 0 if no label found, size of label if found, Failure: FAIL
-*
-* Programmer: pvn@ncsa.uiuc.edu
-*
-* Date: January 11, 2005
-*
-* Comments:
-*
-* Modifications:
-* JIRA HDFFV-7673: Added a check to see if the label name exists,
-* if not then returns zero. July 30, 2011. MSB
-*
-*-------------------------------------------------------------------------
-*/
-ssize_t H5DSget_label(hid_t did, unsigned int idx, char *label, size_t size)
+ * Function: H5DSget_label
+ *
+ * Purpose: Read the label LABEL for dimension IDX of dataset DID
+ * Up to 'size' characters are stored in 'label' followed by a '\0' string
+ * terminator. If the label is longer than 'size'-1,
+ * the string terminator is stored in the last position of the buffer to
+ * properly terminate the string.
+ *
+ * Return: 0 if no label found, size of label if found, Failure: FAIL
+ *
+ * Programmer: Pedro Vicente
+ *
+ * Date: January 11, 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+ssize_t
+H5DSget_label(hid_t did, unsigned int idx, char *label, size_t size)
{
int has_labels;
hid_t sid = -1; /* space ID */
@@ -1771,32 +1729,24 @@ out:
}
/*-------------------------------------------------------------------------
-* Function: H5DSget_scale_name
-*
-* Purpose: Read the name of dataset scale DID into buffer NAME
-* Up to 'size' characters are stored in 'name' followed by a '\0' string
-* terminator. If the name is longer than 'size'-1,
-* the string terminator is stored in the last position of the buffer to
-* properly terminate the string.
-*
-* Return: size of name if found, zero if not found, Failure: FAIL
-*
-* Programmer: pvn@ncsa.uiuc.edu
-*
-* Date: January 04, 2005
-*
-* Comments:
-*
-* Modifications:
-* The size of the name returned should not include the NULL termination
-* in its value so as to be consistent with other HDF5 APIs.
-*
-*-------------------------------------------------------------------------
-*/
-
-ssize_t H5DSget_scale_name(hid_t did,
- char *name,
- size_t size)
+ * Function: H5DSget_scale_name
+ *
+ * Purpose: Read the name of dataset scale DID into buffer NAME
+ * Up to 'size' characters are stored in 'name' followed by a '\0' string
+ * terminator. If the name is longer than 'size'-1,
+ * the string terminator is stored in the last position of the buffer to
+ * properly terminate the string.
+ *
+ * Return: size of name if found, zero if not found, Failure: FAIL
+ *
+ * Programmer: Pedro Vicente
+ *
+ * Date: January 04, 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+ssize_t
+H5DSget_scale_name(hid_t did, char *name, size_t size)
{
hid_t aid; /* attribute ID */
hid_t tid = -1; /* attribute type ID */
@@ -1898,51 +1848,49 @@ out:
}
/*-------------------------------------------------------------------------
-* Function: H5DSis_scale
-*
-* Purpose: check if the dataset DID is a dimension scale
-*
-* Return: 1, is, 0, not, FAIL, error
-*
-* Programmer: pvn@ncsa.uiuc.edu
-*
-* Date: January 04, 2005
-*
-* Comments:
-*
-* Modifications:
-*
-*-------------------------------------------------------------------------
-*/
-
+ * Function: H5DSis_scale
+ *
+ * Purpose: check if the dataset DID is a dimension scale
+ *
+ * Return: 1, is, 0, not, FAIL, error
+ *
+ * Programmer: Pedro Vicente
+ *
+ * Date: January 04, 2005
+ *
+ *-------------------------------------------------------------------------
+ */
htri_t H5DSis_scale(hid_t did)
{
- hid_t tid = -1; /* attribute type ID */
- hid_t aid = -1; /* attribute ID */
- herr_t has_class; /* has the "CLASS" attribute */
- htri_t is_ds; /* boolean return value */
- H5I_type_t it; /* ID type */
- char *buf; /* Name of attribute */
- hsize_t storage_size; /* Size of storage for attribute */
-
- /*-------------------------------------------------------------------------
+ hid_t tid = -1; /* attribute type ID */
+ hid_t aid = -1; /* attribute ID */
+ herr_t attr_class; /* has the "CLASS" attribute */
+ htri_t is_ds = -1; /* set to "not a dimension scale" */
+ H5I_type_t it; /* type of identifier */
+ char *buf = NULL; /* buffer to read name of attribute */
+ size_t string_size; /* size of storage for the attribute */
+ H5T_class_t type_class;
+ H5T_str_t strpad;
+
+ /*------------------------------------------------------------------------
* parameter checking
*-------------------------------------------------------------------------
*/
/* get ID type */
if ((it = H5Iget_type(did)) < 0)
- return FAIL;
+ goto out;
if(H5I_DATASET != it)
- return FAIL;
+ goto out;
/* try to find the attribute "CLASS" on the dataset */
- if((has_class = H5LT_find_attribute(did, "CLASS")) < 0)
- return FAIL;
+ if((attr_class = H5LT_find_attribute(did, "CLASS")) < 0)
+ goto out;
- if(has_class == 0)
+ if(attr_class == 0) {
is_ds = 0;
-
+ goto out;
+ }
else
{
if((aid = H5Aopen(did, "CLASS", H5P_DEFAULT)) < 0)
@@ -1951,19 +1899,33 @@ htri_t H5DSis_scale(hid_t did)
if((tid = H5Aget_type(aid)) < 0)
goto out;
- /* check to make sure attribute is a string */
- if(H5T_STRING != H5Tget_class(tid))
+ /* check to make sure attribute is a string;
+ if not, then it is not dimension scale */
+ if((type_class = H5Tget_class(tid)) < 0)
goto out;
-
- /* check to make sure string is null-terminated */
- if(H5T_STR_NULLTERM != H5Tget_strpad(tid))
+ if(H5T_STRING != type_class) {
+ is_ds = 0;
+ goto out;
+ }
+ /* check to make sure string is null-terminated;
+ if not, then it is not dimension scale */
+ if((strpad = H5Tget_strpad(tid)) < 0 )
goto out;
+ if(H5T_STR_NULLTERM != strpad) {
+ is_ds = 0;
+ goto out;
+ }
- /* allocate buffer large enough to hold string */
- if((storage_size = H5Aget_storage_size(aid)) == 0)
+ /* According to Spec string is ASCII and its size should be 16 to hold
+ "DIMENSION_SCALE" string */
+ if((string_size = H5Tget_size(tid)) == 0)
+ goto out;
+ if(string_size != 16) {
+ is_ds = 0;
goto out;
+ }
- buf = (char*)HDmalloc( (size_t)storage_size * sizeof(char) + 1);
+ buf = (char*)HDmalloc((size_t)string_size * sizeof(char));
if(buf == NULL)
goto out;
@@ -1972,10 +1934,9 @@ htri_t H5DSis_scale(hid_t did)
goto out;
/* compare strings */
- if(HDstrncmp(buf, DIMENSION_SCALE_CLASS, MIN(HDstrlen(DIMENSION_SCALE_CLASS),HDstrlen(buf)))==0)
+ if(HDstrncmp(buf, DIMENSION_SCALE_CLASS,
+ MIN(HDstrlen(DIMENSION_SCALE_CLASS),HDstrlen(buf)))==0)
is_ds = 1;
- else
- is_ds = 0;
HDfree(buf);
@@ -1984,44 +1945,35 @@ htri_t H5DSis_scale(hid_t did)
if (H5Aclose(aid) < 0)
goto out;
-
-
}
-
- return is_ds;
-
- /* error zone */
out:
- H5E_BEGIN_TRY {
- H5Aclose(aid);
- H5Tclose(tid);
- } H5E_END_TRY;
- return FAIL;
-
+ if(is_ds < 0) {
+ HDfree(buf);
+ H5E_BEGIN_TRY {
+ H5Aclose(aid);
+ H5Tclose(tid);
+ } H5E_END_TRY;
+ }
+ return is_ds;
}
/*-------------------------------------------------------------------------
-* Function: H5DSget_num_scales
-*
-* Purpose: get the number of scales linked to the IDX dimension of dataset DID
-*
-* Return:
-* Success: number of scales
-* Failure: FAIL
-*
-* Programmer: pvn@ncsa.uiuc.edu
-*
-* Date: January 13, 2005
-*
-* Comments:
-*
-* Modifications:
-*
-*-------------------------------------------------------------------------
-*/
-
-int H5DSget_num_scales(hid_t did,
- unsigned int idx)
+ * Function: H5DSget_num_scales
+ *
+ * Purpose: get the number of scales linked to the IDX dimension of dataset DID
+ *
+ * Return:
+ * Success: number of scales
+ * Failure: FAIL
+ *
+ * Programmer: Pedro Vicente
+ *
+ * Date: January 13, 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+H5DSget_num_scales(hid_t did, unsigned int idx)
{
int has_dimlist;
hid_t sid; /* space ID */
@@ -2124,25 +2076,20 @@ out:
}
/*-------------------------------------------------------------------------
-* Function: H5DS_is_reserved
-*
-* Purpose: Verify that a dataset's CLASS is either an image, palette or table
-*
-* Return: true, false, fail
-*
-* Programmer: pvn@ncsa.uiuc.edu
-*
-* Date: March 19, 2005
-*
-* Comments:
-*
-* Modifications:
-*
-*-------------------------------------------------------------------------
-*/
-
-static
-herr_t H5DS_is_reserved(hid_t did)
+ * Function: H5DS_is_reserved
+ *
+ * Purpose: Verify that a dataset's CLASS is either an image, palette or table
+ *
+ * Return: true, false, fail
+ *
+ * Programmer: Pedro Vicente
+ *
+ * Date: March 19, 2005
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5DS_is_reserved(hid_t did)
{
int has_class;
hid_t tid = -1;
@@ -2215,26 +2162,21 @@ out:
}
/*-------------------------------------------------------------------------
-* Function: H5DS_get_REFLIST_type
-*
-* Purpose: This is a helper function to return a native type for
-* the REFERENCE_LIST attribute.
-*
-* Return: Type identifier on success and negative on failure
-*
-* Programmer: epourmal@hdfgroup.org
-*
-* Date: May 22, 2010
-*
-* Comments:
-*
-* Modifications:
-*
-*-------------------------------------------------------------------------
-*/
-
-static
-hid_t H5DS_get_REFLIST_type(void)
+ * Function: H5DS_get_REFLIST_type
+ *
+ * Purpose: This is a helper function to return a native type for
+ * the REFERENCE_LIST attribute.
+ *
+ * Return: Type identifier on success and negative on failure
+ *
+ * Programmer: Elena Pourmal
+ *
+ * Date: May 22, 2010
+ *
+ *-------------------------------------------------------------------------
+ */
+static hid_t
+H5DS_get_REFLIST_type(void)
{
hid_t ntid_t = -1;