summaryrefslogtreecommitdiffstats
path: root/src/H5S.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>1998-07-06 21:01:13 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>1998-07-06 21:01:13 (GMT)
commit43f13aeca28a722d6436d43dcd84a59918dc0950 (patch)
tree1ee94e4f1b64a7d027112d616d8617992c09520a /src/H5S.c
parentd70e61b1dbd7ff16aa4ac5cad4a69bf87b84f208 (diff)
downloadhdf5-43f13aeca28a722d6436d43dcd84a59918dc0950.zip
hdf5-43f13aeca28a722d6436d43dcd84a59918dc0950.tar.gz
hdf5-43f13aeca28a722d6436d43dcd84a59918dc0950.tar.bz2
[svn-r451] Completely tore out existing dataspace API and replaced with code to match
API defined in the html/Dataspaces.html document. This code does not include support for strides, merging selections, or permutations of coordinates yet, but it's a drop-in replacement for the existing API with the same features.
Diffstat (limited to 'src/H5S.c')
-rw-r--r--src/H5S.c1326
1 files changed, 624 insertions, 702 deletions
diff --git a/src/H5S.c b/src/H5S.c
index 8802a68..ad4cb1a 100644
--- a/src/H5S.c
+++ b/src/H5S.c
@@ -20,7 +20,7 @@ static char RcsId[] = "@(#)$Revision$";
#include <H5Iprivate.h> /* ID Functions */
#include <H5Eprivate.h> /* Error handling */
#include <H5MMprivate.h> /* Memory Management functions */
-#include <H5Oprivate.h> /*object headers */
+#include <H5Oprivate.h> /* object headers */
#include <H5Sprivate.h> /* Data-space functions */
/* Interface initialization */
@@ -51,9 +51,8 @@ H5S_init_interface(void)
/* Initialize the atom group for the file IDs */
if ((ret_value = H5I_init_group(H5_DATASPACE, H5I_DATASPACEID_HASHSIZE,
- H5S_RESERVED_ATOMS,
- (herr_t (*)(void *)) H5S_close)) != FAIL) {
- ret_value = H5_add_exit(&H5S_term_interface);
+ H5S_RESERVED_ATOMS, (herr_t (*)(void *)) H5S_close)) != FAIL) {
+ ret_value = H5_add_exit(&H5S_term_interface);
}
FUNC_LEAVE(ret_value);
}
@@ -82,116 +81,97 @@ H5S_term_interface(void)
H5I_destroy_group(H5_DATASPACE);
}
-/*-------------------------------------------------------------------------
- * Function: H5Screate_simple
- *
- * Purpose: Creates a new simple data space object and opens it for
- * access. The DIMS argument is the size of the simple dataset
- * and the MAXDIMS argument is the upper limit on the size of
- * the dataset. MAXDIMS may be the null pointer in which case
- * the upper limit is the same as DIMS. If an element of
- * MAXDIMS is H5S_UNLIMITED then the corresponding dimension is
- * unlimited, otherwise no element of MAXDIMS should be smaller
- * than the corresponding element of DIMS.
- *
- * Return: Success: The ID for the new simple data space object.
- *
- * Failure: FAIL
- *
- * Errors:
- *
- * Programmer: Quincey Koziol
- * Tuesday, January 27, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-hid_t
-H5Screate_simple (int rank, const hsize_t *dims, const hsize_t *maxdims)
+/*--------------------------------------------------------------------------
+ NAME
+ H5S_create
+ PURPOSE
+ Create empty, typed dataspace
+ USAGE
+ H5S_t *H5S_create(type)
+ H5S_type_t type; IN: Dataspace type to create
+ RETURNS
+ Pointer to dataspace on success, NULL on failure
+ DESCRIPTION
+ Creates a new dataspace of a given type. The extent & selection are
+ undefined
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+H5S_t *H5S_create(H5S_class_t type)
{
- H5S_t *ds = NULL;
+ H5S_t *ret_value = NULL;
+
+ FUNC_ENTER(H5S_create, NULL);
+
+ /* Create a new data space */
+ if((ret_value = H5MM_calloc(sizeof(H5S_t)))!=NULL)
+ {
+ ret_value->extent.type = type;
+ ret_value->select.type = H5S_SEL_ALL; /* Entire extent selected by default */
+ }
+
+#ifdef LATER
+done:
+#endif
+ FUNC_LEAVE(ret_value);
+} /* end H5S_create() */
+
+/*--------------------------------------------------------------------------
+ NAME
+ H5Screate
+ PURPOSE
+ Create empty, typed dataspace
+ USAGE
+ hid_t H5Screate(type)
+ H5S_type_t type; IN: Dataspace type to create
+ RETURNS
+ Valid dataspace ID on success, negative on failure
+ DESCRIPTION
+ Creates a new dataspace of a given type. The extent & selection are
+ undefined
+ GLOBAL VARIABLES
+ COMMENTS, BUGS, ASSUMPTIONS
+ EXAMPLES
+ REVISION LOG
+--------------------------------------------------------------------------*/
+hid_t H5Screate(H5S_class_t type)
+{
+ H5S_t *new_ds=NULL;
hid_t ret_value = FAIL;
- int i;
FUNC_ENTER(H5Screate, FAIL);
- H5TRACE3("i","Is*h*h",rank,dims,maxdims);
- /* Check arguments */
- if (rank<0) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
- "dimensionality cannot be negative");
- }
- if (!dims && dims!=0) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
- "no dimensions specified");
- }
- if (maxdims) {
- for (i=0; i<rank; i++) {
- if (H5S_UNLIMITED!=maxdims[i] && maxdims[i]<dims[i]) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
- "maxdims is smaller than dims");
- }
- }
- }
+ /* Check args */
+ if(type<=H5S_NO_CLASS || type> H5S_SIMPLE) /* don't allow complex dataspace yet */
+ HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
+ "invalid dataspace type");
- /* Create a new data space */
- if (NULL==(ds = H5MM_calloc(sizeof(H5S_t)))) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
+ if (NULL==(new_ds=H5S_create(type))) {
+ HRETURN_ERROR (H5E_DATASPACE, H5E_CANTCREATE, FAIL, "unable to create dataspace");
}
- if(rank>0) /* for creating simple dataspace */
- {
- ds->type = H5S_SIMPLE;
- ds->hslab_def = FALSE; /* no hyperslab defined currently */
-
- /* Initialize rank and dimensions */
- ds->u.simple.rank = rank;
-
- if (NULL==(ds->u.simple.size = H5MM_calloc(1*rank*sizeof(hsize_t)))) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
- }
- HDmemcpy(ds->u.simple.size, dims, rank*sizeof(hsize_t));
-
- if (maxdims) {
- if (NULL==(ds->u.simple.max=H5MM_calloc(rank*sizeof(hsize_t)))) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
- }
- HDmemcpy (ds->u.simple.max, maxdims, rank*sizeof(hsize_t));
- }
- } /* end if */
- else /* rank==0, for scalar data space */
- {
- ds->type = H5S_SCALAR;
- ds->u.simple.rank = 0;
- } /* end else */
-
- /* Register the new data space and get an ID for it */
- if ((ret_value = H5I_register(H5_DATASPACE, ds)) < 0) {
- HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL,
- "unable to register data space for ID");
+
+ /* Atomize */
+ if ((ret_value=H5I_register (H5_DATASPACE, new_ds))<0) {
+ HGOTO_ERROR (H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register data space atom");
}
- done:
+done:
if (ret_value < 0) {
- H5MM_xfree(ds);
}
FUNC_LEAVE(ret_value);
-}
+} /* end H5Screate() */
/*-------------------------------------------------------------------------
- * Function: H5Sclose
+ * Function: H5S_close
*
- * Purpose: Release access to a data space object.
+ * Purpose: Releases all memory associated with a data space.
*
* Return: Success: SUCCEED
*
* Failure: FAIL
*
- * Errors:
- *
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
*
@@ -199,33 +179,55 @@ H5Screate_simple (int rank, const hsize_t *dims, const hsize_t *maxdims)
*
*-------------------------------------------------------------------------
*/
-herr_t
-H5Sclose (hid_t space_id)
+herr_t H5S_close(H5S_t *ds)
{
- FUNC_ENTER(H5Sclose, FAIL);
- H5TRACE1("e","i",space_id);
+ FUNC_ENTER(H5S_close, FAIL);
- /* Check args */
- if (H5_DATASPACE != H5I_group(space_id) ||
- NULL == H5I_object(space_id)) {
- HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
- }
- /* When the reference count reaches zero the resources are freed */
- if (H5I_dec_ref(space_id) < 0) {
- HRETURN_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "problem freeing id");
+ assert(ds);
+
+ /* Release selection (this should come before the extent release) */
+ H5S_select_release(ds);
+
+ /* release extent */
+ switch (ds->extent.type) {
+ case H5S_NO_CLASS:
+ /*nothing needed */
+ break;
+
+ case H5S_SCALAR:
+ /*nothing needed */
+ break;
+
+ case H5S_SIMPLE:
+ H5S_release_simple(&(ds->extent.u.simple));
+ break;
+
+ case H5S_COMPLEX:
+ /* nothing yet */
+ break;
+
+ default:
+ assert("unknown dataspace (extent) type" && 0);
+ break;
}
+
+ /* Release the main structure */
+ H5MM_xfree(ds);
+
FUNC_LEAVE(SUCCEED);
}
/*-------------------------------------------------------------------------
- * Function: H5S_close
+ * Function: H5Sclose
*
- * Purpose: Releases all memory associated with a data space.
+ * Purpose: Release access to a data space object.
*
* Return: Success: SUCCEED
*
* Failure: FAIL
*
+ * Errors:
+ *
* Programmer: Robb Matzke
* Tuesday, December 9, 1997
*
@@ -234,41 +236,25 @@ H5Sclose (hid_t space_id)
*-------------------------------------------------------------------------
*/
herr_t
-H5S_close(H5S_t *ds)
+H5Sclose (hid_t space_id)
{
- FUNC_ENTER(H5S_close, FAIL);
-
- assert(ds);
-
- switch (ds->type) {
- case H5S_SCALAR:
- /*nothing needed */
- break;
-
- case H5S_SIMPLE:
- H5S_close_simple(&(ds->u.simple));
- break;
-
- case H5S_COMPLEX:
- /* nothing */
- break;
+ FUNC_ENTER(H5Sclose, FAIL);
+ H5TRACE1("e","i",space_id);
- default:
- assert("unknown data space type" && 0);
- break;
+ /* Check args */
+ if (H5_DATASPACE != H5I_group(space_id) ||
+ NULL == H5I_object(space_id)) {
+ HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
+ }
+ /* When the reference count reaches zero the resources are freed */
+ if (H5I_dec_ref(space_id) < 0) {
+ HRETURN_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "problem freeing id");
}
- if(ds->hslab_def==TRUE) {
- H5MM_xfree(ds->h.start);
- H5MM_xfree(ds->h.count);
- H5MM_xfree(ds->h.stride);
- } /* end if */
- H5MM_xfree(ds);
-
FUNC_LEAVE(SUCCEED);
}
/*-------------------------------------------------------------------------
- * Function: H5S_close_simple
+ * Function: H5S_release_simple
*
* Purpose: Releases all memory associated with a simple data space.
* (but doesn't free the simple space itself)
@@ -284,16 +270,16 @@ H5S_close(H5S_t *ds)
*
*-------------------------------------------------------------------------
*/
-herr_t
-H5S_close_simple(H5S_simple_t *simple)
+herr_t H5S_release_simple(H5S_simple_t *simple)
{
- FUNC_ENTER(H5S_close_simple, FAIL);
+ FUNC_ENTER(H5S_release_simple, FAIL);
assert(simple);
- H5MM_xfree(simple->size);
- H5MM_xfree(simple->max);
- H5MM_xfree(simple->perm);
+ if(simple->size)
+ H5MM_xfree(simple->size);
+ if(simple->max)
+ H5MM_xfree(simple->max);
FUNC_LEAVE(SUCCEED);
}
@@ -325,21 +311,18 @@ H5Scopy (hid_t space_id)
H5TRACE1("i","i",space_id);
/* Check args */
- if (H5_DATASPACE!=H5I_group (space_id) ||
- NULL==(src=H5I_object (space_id))) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
+ if (H5_DATASPACE!=H5I_group (space_id) || NULL==(src=H5I_object (space_id))) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
}
/* Copy */
if (NULL==(dst=H5S_copy (src))) {
- HRETURN_ERROR (H5E_DATASPACE, H5E_CANTINIT, FAIL,
- "unable to copy data space");
+ HRETURN_ERROR (H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to copy data space");
}
/* Atomize */
if ((ret_value=H5I_register (H5_DATASPACE, dst))<0) {
- HRETURN_ERROR (H5E_ATOM, H5E_CANTREGISTER, FAIL,
- "unable to register data space atom");
+ HRETURN_ERROR (H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register data space atom");
}
FUNC_LEAVE (ret_value);
@@ -347,9 +330,67 @@ H5Scopy (hid_t space_id)
/*-------------------------------------------------------------------------
+ * Function: H5S_extent_copy
+ *
+ * Purpose: Copies a dataspace extent
+ *
+ * Return: SUCCEED/FAIL
+ *
+ * Programmer: Quincey Koziol
+ * Wednesday, June 3, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t H5S_extent_copy(H5S_extent_t *dst, const H5S_extent_t *src)
+{
+ int i;
+
+ FUNC_ENTER(H5S_extent_copy, NULL);
+
+ /* Copy the regular fields */
+ *dst=*src;
+
+ switch (src->type) {
+ case H5S_SCALAR:
+ /*nothing needed */
+ break;
+
+ case H5S_SIMPLE:
+ if (src->u.simple.size) {
+ dst->u.simple.size = H5MM_malloc(src->u.simple.rank *
+ sizeof(src->u.simple.size[0]));
+ for (i = 0; i < src->u.simple.rank; i++) {
+ dst->u.simple.size[i] = src->u.simple.size[i];
+ }
+ }
+ if (src->u.simple.max) {
+ dst->u.simple.max = H5MM_malloc(src->u.simple.rank *
+ sizeof(src->u.simple.max[0]));
+ for (i = 0; i < src->u.simple.rank; i++) {
+ dst->u.simple.max[i] = src->u.simple.max[i];
+ }
+ }
+ break;
+
+ case H5S_COMPLEX:
+ /*void */
+ break;
+
+ default:
+ assert("unknown data space type" && 0);
+ break;
+ }
+
+ FUNC_LEAVE(SUCCEED);
+}
+
+/*-------------------------------------------------------------------------
* Function: H5S_copy
*
- * Purpose: Copies a data space.
+ * Purpose: Copies a data space, by copying the extent and selection through
+ * H5S_extent_copy and H5S_select_copy
*
* Return: Success: A pointer to a new copy of SRC
*
@@ -362,11 +403,9 @@ H5Scopy (hid_t space_id)
*
*-------------------------------------------------------------------------
*/
-H5S_t *
-H5S_copy(const H5S_t *src)
+H5S_t * H5S_copy(const H5S_t *src)
{
H5S_t *dst = NULL;
- int i;
FUNC_ENTER(H5S_copy, NULL);
@@ -376,55 +415,13 @@ H5S_copy(const H5S_t *src)
}
*dst = *src;
- switch (dst->type) {
- case H5S_SCALAR:
- /*nothing needed */
- break;
-
- case H5S_SIMPLE:
- if (dst->u.simple.size) {
- dst->u.simple.size = H5MM_malloc(dst->u.simple.rank *
- sizeof(dst->u.simple.size[0]));
- if (NULL==dst->u.simple.size) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed");
- }
- for (i = 0; i < dst->u.simple.rank; i++) {
- dst->u.simple.size[i] = src->u.simple.size[i];
- }
- }
- if (dst->u.simple.max) {
- dst->u.simple.max = H5MM_malloc(dst->u.simple.rank *
- sizeof(dst->u.simple.max[0]));
- if (NULL==dst->u.simple.max) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed");
- }
- for (i = 0; i < dst->u.simple.rank; i++) {
- dst->u.simple.max[i] = src->u.simple.max[i];
- }
- }
- if (dst->u.simple.perm) {
- dst->u.simple.perm = H5MM_malloc(dst->u.simple.rank *
- sizeof(dst->u.simple.perm[0]));
- if (NULL==dst->u.simple.perm) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
- "memory allocation failed");
- }
- for (i = 0; i < dst->u.simple.rank; i++) {
- dst->u.simple.perm[i] = src->u.simple.perm[i];
- }
- }
- break;
-
- case H5S_COMPLEX:
- /*void */
- break;
-
- default:
- assert("unknown data space type" && 0);
- break;
- }
+ /* Copy the source dataspace's extent */
+ if (H5S_extent_copy(&(dst->extent),&(src->extent))<0)
+ HRETURN_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy extent");
+
+ /* Copy the source dataspace's selection */
+ if (H5S_select_copy(dst,src)<0)
+ HRETURN_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy select");
FUNC_LEAVE(dst);
}
@@ -455,9 +452,8 @@ H5Sget_npoints (hid_t space_id)
H5TRACE1("h","i",space_id);
/* Check args */
- if (H5_DATASPACE != H5I_group(space_id) ||
- NULL == (ds = H5I_object(space_id))) {
- HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not a data space");
+ if (H5_DATASPACE != H5I_group(space_id) || NULL == (ds = H5I_object(space_id))) {
+ HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not a data space");
}
ret_value = H5S_get_npoints(ds);
@@ -492,35 +488,25 @@ H5S_get_npoints(const H5S_t *ds)
/* check args */
assert(ds);
- switch (ds->type) {
- case H5S_SCALAR:
- ret_value = 1;
- break;
-
- case H5S_SIMPLE:
- /*
- * Count the elements selected by the hypeslab if there is one,
- * otherwise count all the elements.
- */
- if (ds->hslab_def) {
- for (ret_value=1, i=0; i<ds->u.simple.rank; i++) {
- ret_value *= ds->h.count[i];
- }
- } else {
- for (ret_value=1, i=0; i<ds->u.simple.rank; i++) {
- ret_value *= ds->u.simple.size[i];
- }
- }
- break;
-
- case H5S_COMPLEX:
- HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, 0,
- "complex data spaces are not supported yet");
-
- default:
- assert("unknown data space class" && 0);
- HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, 0,
- "internal error (unknown data space class)");
+ switch (ds->extent.type) {
+ case H5S_SCALAR:
+ ret_value = 1;
+ break;
+
+ case H5S_SIMPLE:
+ for (ret_value=1, i=0; i<ds->extent.u.simple.rank; i++) {
+ ret_value *= ds->extent.u.simple.size[i];
+ }
+ break;
+
+ case H5S_COMPLEX:
+ HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, 0,
+ "complex data spaces are not supported yet");
+
+ default:
+ assert("unknown data space class" && 0);
+ HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, 0,
+ "internal error (unknown data space class)");
}
FUNC_LEAVE(ret_value);
@@ -558,36 +544,36 @@ H5S_get_npoints_max(const H5S_t *ds)
/* check args */
assert(ds);
- switch (ds->type) {
- case H5S_SCALAR:
- ret_value = 1;
- break;
-
- case H5S_SIMPLE:
- if (ds->u.simple.max) {
- for (ret_value=1, i=0; i<ds->u.simple.rank; i++) {
- if (H5S_UNLIMITED==ds->u.simple.max[i]) {
- ret_value = MAX_HSIZET;
- break;
- } else {
- ret_value *= ds->u.simple.max[i];
- }
- }
- } else {
- for (ret_value=1, i=0; i<ds->u.simple.rank; i++) {
- ret_value *= ds->u.simple.size[i];
- }
- }
- break;
-
- case H5S_COMPLEX:
- HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, 0,
- "complex data spaces are not supported yet");
-
- default:
- assert("unknown data space class" && 0);
- HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, 0,
- "internal error (unknown data space class)");
+ switch (ds->extent.type) {
+ case H5S_SCALAR:
+ ret_value = 1;
+ break;
+
+ case H5S_SIMPLE:
+ if (ds->extent.u.simple.max) {
+ for (ret_value=1, i=0; i<ds->extent.u.simple.rank; i++) {
+ if (H5S_UNLIMITED==ds->extent.u.simple.max[i]) {
+ ret_value = MAX_HSIZET;
+ break;
+ } else {
+ ret_value *= ds->extent.u.simple.max[i];
+ }
+ }
+ } else {
+ for (ret_value=1, i=0; i<ds->extent.u.simple.rank; i++) {
+ ret_value *= ds->extent.u.simple.size[i];
+ }
+ }
+ break;
+
+ case H5S_COMPLEX:
+ HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, 0,
+ "complex data spaces are not supported yet");
+
+ default:
+ assert("unknown data space class" && 0);
+ HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, 0,
+ "internal error (unknown data space class)");
}
FUNC_LEAVE(ret_value);
@@ -620,9 +606,8 @@ H5Sget_ndims (hid_t space_id)
H5TRACE1("Is","i",space_id);
/* Check args */
- if (H5_DATASPACE != H5I_group(space_id) ||
- NULL == (ds = H5I_object(space_id))) {
- HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
+ if (H5_DATASPACE != H5I_group(space_id) || NULL == (ds = H5I_object(space_id))) {
+ HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
}
ret_value = H5S_get_ndims(ds);
@@ -656,23 +641,23 @@ H5S_get_ndims(const H5S_t *ds)
/* check args */
assert(ds);
- switch (ds->type) {
- case H5S_SCALAR:
- ret_value = 0;
- break;
+ switch (ds->extent.type) {
+ case H5S_SCALAR:
+ ret_value = 0;
+ break;
- case H5S_SIMPLE:
- ret_value = ds->u.simple.rank;
- break;
+ case H5S_SIMPLE:
+ ret_value = ds->extent.u.simple.rank;
+ break;
- case H5S_COMPLEX:
- HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL,
- "complex data spaces are not supported yet");
+ case H5S_COMPLEX:
+ HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL,
+ "complex data spaces are not supported yet");
- default:
- assert("unknown data space class" && 0);
- HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL,
- "internal error (unknown data space class)");
+ default:
+ assert("unknown data space class" && 0);
+ HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL,
+ "internal error (unknown data space class)");
}
FUNC_LEAVE(ret_value);
@@ -710,9 +695,8 @@ H5Sget_dims (hid_t space_id, hsize_t dims[]/*out*/, hsize_t maxdims[]/*out*/)
H5TRACE1("Is","i",space_id);
/* Check args */
- if (H5_DATASPACE != H5I_group(space_id) ||
- NULL == (ds = H5I_object(space_id))) {
- HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
+ if (H5_DATASPACE != H5I_group(space_id) || NULL == (ds = H5I_object(space_id))) {
+ HRETURN_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
}
ret_value = H5S_get_dims(ds, dims, maxdims);
@@ -746,35 +730,35 @@ H5S_get_dims(const H5S_t *ds, hsize_t dims[], hsize_t max_dims[])
/* check args */
assert(ds);
- assert(dims);
-
- switch (ds->type) {
- case H5S_SCALAR:
- ret_value = 0;
- break;
-
- case H5S_SIMPLE:
- ret_value = ds->u.simple.rank;
- for (i=0; i<ret_value; i++) {
- if (dims) dims[i] = ds->u.simple.size[i];
- if (max_dims) {
- if (ds->u.simple.max) {
- max_dims[i] = ds->u.simple.max[i];
- } else {
- max_dims[i] = ds->u.simple.size[i];
- }
- }
- }
- break;
-
- case H5S_COMPLEX:
- HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL,
- "complex data spaces are not supported yet");
-
- default:
- assert("unknown data space class" && 0);
- HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL,
- "internal error (unknown data space class)");
+
+ switch (ds->extent.type) {
+ case H5S_SCALAR:
+ ret_value = 0;
+ break;
+
+ case H5S_SIMPLE:
+ ret_value = ds->extent.u.simple.rank;
+ for (i=0; i<ret_value; i++) {
+ if (dims)
+ dims[i] = ds->extent.u.simple.size[i];
+ if (max_dims) {
+ if (ds->extent.u.simple.max) {
+ max_dims[i] = ds->extent.u.simple.max[i];
+ } else {
+ max_dims[i] = ds->extent.u.simple.size[i];
+ }
+ }
+ }
+ break;
+
+ case H5S_COMPLEX:
+ HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL,
+ "complex data spaces are not supported yet");
+
+ default:
+ assert("unknown data space class" && 0);
+ HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL,
+ "internal error (unknown data space class)");
}
FUNC_LEAVE(ret_value);
@@ -805,27 +789,22 @@ H5S_modify(H5G_entry_t *ent, const H5S_t *ds)
assert(ent);
assert(ds);
- switch (ds->type) {
- case H5S_SCALAR:
-#ifdef OLD_WAY
- HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL,
- "scalar data spaces are not implemented yet");
-#endif
-
- case H5S_SIMPLE:
- if (H5O_modify(ent, H5O_SDSPACE, 0, 0, &(ds->u.simple)) < 0) {
- HRETURN_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL,
- "can't update simple data space message");
- }
- break;
-
- case H5S_COMPLEX:
- HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL,
- "complex data spaces are not implemented yet");
-
- default:
- assert("unknown data space class" && 0);
- break;
+ switch (ds->extent.type) {
+ case H5S_SCALAR:
+ case H5S_SIMPLE:
+ if (H5O_modify(ent, H5O_SDSPACE, 0, 0, &(ds->extent.u.simple)) < 0) {
+ HRETURN_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL,
+ "can't update simple data space message");
+ }
+ break;
+
+ case H5S_COMPLEX:
+ HRETURN_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL,
+ "complex data spaces are not implemented yet");
+
+ default:
+ assert("unknown data space class" && 0);
+ break;
}
FUNC_LEAVE(SUCCEED);
@@ -860,24 +839,26 @@ H5S_read(H5G_entry_t *ent)
assert(ent);
if (NULL==(ds = H5MM_calloc(sizeof(H5S_t)))) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
"memory allocation failed");
}
- if (H5O_read(ent, H5O_SDSPACE, 0, &(ds->u.simple))) {
- ds->type = H5S_SIMPLE;
-
+ if (H5O_read(ent, H5O_SDSPACE, 0, &(ds->extent.u.simple))) {
+ ds->extent.type = H5S_SIMPLE;
} else {
- ds->type = H5S_SCALAR;
+ ds->extent.type = H5S_SCALAR;
}
+ /* Default to entire dataspace being selected */
+ ds->select.type=H5S_SEL_ALL;
+
FUNC_LEAVE(ds);
}
/*-------------------------------------------------------------------------
* Function: H5S_cmp
*
- * Purpose: Compares two data spaces.
+ * Purpose: Compares two data space extents.
*
* Return: Success: 0 if DS1 and DS2 are the same.
* <0 if DS1 is less than DS2.
@@ -889,6 +870,7 @@ H5S_read(H5G_entry_t *ent)
* Wednesday, December 10, 1997
*
* Modifications:
+ * 6/9/98 Changed to only compare extents - QAK
*
*-------------------------------------------------------------------------
*/
@@ -904,61 +886,42 @@ H5S_cmp(const H5S_t *ds1, const H5S_t *ds2)
assert(ds2);
/* compare */
- if (ds1->type < ds2->type)
- HRETURN(-1);
- if (ds1->type > ds2->type)
- HRETURN(1);
-
- switch (ds1->type) {
- case H5S_SIMPLE:
- if (ds1->u.simple.rank < ds2->u.simple.rank)
- HRETURN(-1);
- if (ds1->u.simple.rank > ds2->u.simple.rank)
- HRETURN(1);
-
- for (i = 0; i < ds1->u.simple.rank; i++) {
- if (ds1->u.simple.size[i] < ds2->u.simple.size[i])
- HRETURN(-1);
- if (ds1->u.simple.size[i] > ds2->u.simple.size[i])
- HRETURN(1);
- }
-
- /* don't compare max dimensions */
-
- for (i = 0; i < ds1->u.simple.rank; i++) {
- if ((ds1->u.simple.perm ? ds1->u.simple.perm[i] : i) <
- (ds2->u.simple.perm ? ds2->u.simple.perm[i] : i))
- HRETURN(-1);
- if ((ds1->u.simple.perm ? ds2->u.simple.perm[i] : i) >
- (ds2->u.simple.perm ? ds2->u.simple.perm[i] : i))
- HRETURN(1);
- }
-
- /* Check if we should compare hyperslab definitions */
- if(ds1->hslab_def==TRUE && ds2->hslab_def==TRUE) {
- for (i = 0; i < ds1->u.simple.rank; i++) {
- if (ds1->h.start[i] < ds2->h.start[i])
- HRETURN(-1);
- if (ds1->h.start[i] > ds2->h.start[i])
- HRETURN(1);
- if (ds1->h.count[i] < ds2->h.count[i])
- HRETURN(-1);
- if (ds1->h.count[i] > ds2->h.count[i])
- HRETURN(1);
- if (ds1->h.stride[i] < ds2->h.stride[i])
- HRETURN(-1);
- if (ds1->h.stride[i] > ds2->h.stride[i])
- HRETURN(1);
- }
- } else {
- if(ds1->hslab_def!=ds2->hslab_def)
- HRETURN(ds1->hslab_def==TRUE ? 1 : -1);
- }
-
- break;
-
- default:
- assert("not implemented yet" && 0);
+ if (ds1->extent.type < ds2->extent.type)
+ HRETURN(-1);
+ if (ds1->extent.type > ds2->extent.type)
+ HRETURN(1);
+
+ switch (ds1->extent.type) {
+ case H5S_SIMPLE:
+ if (ds1->extent.u.simple.rank < ds2->extent.u.simple.rank)
+ HRETURN(-1);
+ if (ds1->extent.u.simple.rank > ds2->extent.u.simple.rank)
+ HRETURN(1);
+
+ for (i = 0; i < ds1->extent.u.simple.rank; i++) {
+ if (ds1->extent.u.simple.size[i] < ds2->extent.u.simple.size[i])
+ HRETURN(-1);
+ if (ds1->extent.u.simple.size[i] > ds2->extent.u.simple.size[i])
+ HRETURN(1);
+ }
+
+ /* don't compare max dimensions */
+
+#ifdef LATER
+ for (i = 0; i < ds1->extent.u.simple.rank; i++) {
+ if ((ds1->extent.u.simple.perm ? ds1->extent.u.simple.perm[i] : i) <
+ (ds2->extent.u.simple.perm ? ds2->extent.u.simple.perm[i] : i))
+ HRETURN(-1);
+ if ((ds1->extent.u.simple.perm ? ds2->extent.u.simple.perm[i] : i) >
+ (ds2->extent.u.simple.perm ? ds2->extent.u.simple.perm[i] : i))
+ HRETURN(1);
+ }
+#endif
+
+ break;
+
+ default:
+ assert("not implemented yet" && 0);
}
FUNC_LEAVE(0);
@@ -988,7 +951,7 @@ H5S_is_simple(const H5S_t *sdim)
/* Check args and all the boring stuff. */
assert(sdim);
- ret_value = sdim->type == H5S_SIMPLE ? TRUE : FALSE; /* Currently all dataspaces are simple, but check anyway */
+ ret_value = sdim->extent.type == H5S_SIMPLE ? TRUE : FALSE;
FUNC_LEAVE(ret_value);
}
@@ -1034,310 +997,108 @@ H5Sis_simple (hid_t sid)
/*--------------------------------------------------------------------------
NAME
- H5Sset_space
+ H5Sset_extent_simple
PURPOSE
- Determine the size of a dataspace
+ Sets the size of a simple dataspace
USAGE
- herr_t H5Sset_space(sid, rank, dims)
- hid_t sid; IN: Dataspace object to query
- intn rank; IN: # of dimensions for the dataspace
- const size_t *dims; IN: Size of each dimension for the dataspace
+ herr_t H5Sset_extent_simple(sid, rank, dims, max)
+ hid_t sid; IN: Dataspace object to query
+ intn rank; IN: # of dimensions for the dataspace
+ const size_t *dims; IN: Size of each dimension for the dataspace
+ const size_t *max; IN: Maximum size of each dimension for the dataspace
RETURNS
SUCCEED/FAIL
DESCRIPTION
This function sets the number and size of each dimension in the
- dataspace. Setting RANK to a value of zero allows scalar objects to be
- created. Dimensions are specified from slowest to fastest changing in the
- DIMS array (i.e. 'C' order). Setting the size of a dimension to zero
- indicates that the dimension is of unlimited size and should be allowed to
- expand. Currently, only the first dimension in the array (the slowest) may
- be unlimited in size.
+ dataspace. Setting RANK to a value of zero converts the dataspace to a
+ scalar dataspace. Dimensions are specified from slowest to fastest changing
+ in the DIMS array (i.e. 'C' order). Setting the size of a dimension in the
+ MAX array to zero indicates that the dimension is of unlimited size and
+ should be allowed to expand. If MAX is NULL, the dimensions in the DIMS
+ array are used as the maximum dimensions. Currently, only the first
+ dimension in the array (the slowest) may be unlimited in size.
--------------------------------------------------------------------------*/
herr_t
-H5Sset_space (hid_t sid, int rank, const hsize_t *dims)
+H5Sset_extent_simple (hid_t sid, int rank, const hsize_t *dims, const hsize_t *max)
{
H5S_t *space = NULL; /* dataspace to modify */
intn u; /* local counting variable */
herr_t ret_value = SUCCEED;
- FUNC_ENTER(H5Sset_space, FAIL);
- H5TRACE3("e","iIs*h",sid,rank,dims);
+ FUNC_ENTER(H5Sset_extent_simple, FAIL);
/* Check args */
if ((space = H5I_object(sid)) == NULL) {
- HRETURN_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "not a data space");
+ HRETURN_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "not a data space");
}
if (rank > 0 && dims == NULL) {
- HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no dimensions specified");
+ HRETURN_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no dimensions specified");
}
if (rank<0) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid rank");
+ HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "invalid rank");
}
if (dims) {
- for (u=0; u<rank; u++) {
- if (dims[u]<=0) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
- "invalid dimension size");
- }
- }
+ for (u=0; u<rank; u++) {
+ if (((max!=NULL && max[u]!=H5S_UNLIMITED) || max==NULL) && dims[u]==0) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
+ "invalid dimension size");
+ }
+ }
+ }
+ if (max!=NULL) {
+ if(dims==NULL)
+ HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
+ "maximum dimension specified, but no current dimensions specified");
+ for (u=0; u<rank; u++) {
+ if (max[u]!=H5S_UNLIMITED && max[u]<dims[u]) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
+ "invalid maximum dimension size");
+ }
+ }
}
/* shift out of the previous state to a "simple" dataspace */
- switch (space->type) {
- case H5S_SCALAR:
- case H5S_SIMPLE:
- /* do nothing */
- break;
-
- case H5S_COMPLEX:
- /*
- * eventually this will destroy whatever "complex" dataspace info
- * is retained, right now it's an error
- */
- /* Fall through to report error */
-
- default:
- HRETURN_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL,
- "unknown data space class");
- }
- space->type = H5S_SIMPLE;
-
- /* Reset hyperslab definition, if one is defined */
- if(space->hslab_def==TRUE) {
- H5MM_xfree(space->h.start);
- H5MM_xfree(space->h.count);
- H5MM_xfree(space->h.stride);
- space->hslab_def=FALSE;
+ switch (space->extent.type) {
+ case H5S_SCALAR:
+ /* do nothing */
+ break;
+
+ case H5S_SIMPLE:
+ H5S_release_simple(&(space->extent.u.simple));
+ break;
+
+ case H5S_COMPLEX:
+ /*
+ * eventually this will destroy whatever "complex" dataspace info
+ * is retained, right now it's an error
+ */
+ /* Fall through to report error */
+
+ default:
+ HRETURN_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL,
+ "unknown data space class");
}
- /* Free the old space for now */
- if (space->u.simple.size != NULL)
- space->u.simple.size = H5MM_xfree(space->u.simple.size);
- if (space->u.simple.max != NULL)
- space->u.simple.max = H5MM_xfree(space->u.simple.max);
- if (space->u.simple.perm != NULL)
- space->u.simple.max = H5MM_xfree(space->u.simple.perm);
-
if (rank == 0) { /* scalar variable */
- space->type = H5S_SCALAR;
- space->u.simple.rank = 0; /* set to scalar rank */
+ space->extent.type = H5S_SCALAR;
+ space->extent.u.simple.rank = 0; /* set to scalar rank */
} else {
- /* Set the rank and copy the dims */
- space->u.simple.rank = rank;
- if (NULL==(space->u.simple.size=H5MM_calloc(rank*sizeof(hsize_t)))) {
- HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
- }
- HDmemcpy(space->u.simple.size, dims, sizeof(hsize_t) * rank);
+ space->extent.type = H5S_SIMPLE;
+
+ /* Set the rank and copy the dims */
+ space->extent.u.simple.rank = rank;
+ space->extent.u.simple.size = H5MM_malloc(rank*sizeof(hsize_t));
+ HDmemcpy(space->extent.u.simple.size, dims, sizeof(hsize_t) * rank);
+
+ /* Copy the maximum dimensions if specified */
+ if(max!=NULL) {
+ space->extent.u.simple.max = H5MM_malloc(rank*sizeof(hsize_t));
+ HDmemcpy(space->extent.u.simple.max, max, sizeof(hsize_t) * rank);
+ } /* end if */
}
FUNC_LEAVE(ret_value);
}
-/*--------------------------------------------------------------------------
- NAME
- H5Sset_hyperslab
- PURPOSE
- Select a hyperslab from a simple dataspace
- USAGE
- herr_t H5Sset_hyperslab(sid, start, count, stride)
- hid_t sid; IN: Dataspace object to select hyperslab from
- const int *start; IN: Starting location for hyperslab to select
- const size_t *count; IN: Number of elements in hyperslab
- const size_t *stride; IN: Packing of elements in hyperslab
- RETURNS
- SUCCEED/FAIL
- DESCRIPTION
- This function selects a hyperslab from a simple dataspace. The stride
- array may be used to sub-sample the hyperslab chosen, a value of 1 in each
- position of the stride array selects contiguous elements in the array,
- a value of 2 selects every other element, etc. If the stride parameter is
- set to NULL, a contiguous hyperslab is chosen. The values in the start and
- count arrays may be negative, to allow for selecting hyperslabs in chunked
- datasets which extend in arbitrary directions.
---------------------------------------------------------------------------*/
-herr_t
-H5Sset_hyperslab (hid_t sid, const hssize_t *start, const hsize_t *count,
- const hsize_t *stride)
-{
- H5S_t *space = NULL; /* dataspace to modify */
- hsize_t *tmp_stride=NULL; /* temp. copy of stride */
- intn u; /* local counting variable */
- herr_t ret_value = SUCCEED;
-
- FUNC_ENTER(H5Sset_hyperslab, FAIL);
- H5TRACE4("e","i*Hs*h*h",sid,start,count,stride);
-
- /* Get the object */
- if (H5_DATASPACE != H5I_group(sid) || (space = H5I_object(sid)) == NULL) {
- HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "not a data space");
- }
- if (start == NULL || count==NULL) {
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
- "invalid hyperslab selected");
- }
-
- /* We can't modify other types of dataspaces currently, so error out */
- if (space->type!=H5S_SIMPLE) {
- HGOTO_ERROR(H5E_DATASPACE, H5E_BADVALUE, FAIL,
- "unknown dataspace type");
- }
-
- /* Set up stride values for later use */
- tmp_stride=H5MM_malloc(space->u.simple.rank*sizeof(tmp_stride[0]));
- if (NULL==tmp_stride) {
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
- }
- for (u=0; u<space->u.simple.rank; u++) {
- tmp_stride[u] = stride ? stride[u] : 1;
- }
-
- /* Range check arguments */
- for (u=0; u<space->u.simple.rank; u++) {
- if (start[u]<0 || (hsize_t)(start[u])>=space->u.simple.size[u]) {
- HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL,
- "hyperslab bounds out of range");
- }
- if (start[u]<0 ||
- start[u]+(count[u]*tmp_stride[u])>space->u.simple.size[u]) {
- HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL,
- "hyperslab bounds out of range");
- }
- }
-
- /* Allocate space for the hyperslab information */
- if (NULL==space->h.start) {
- space->h.start=H5MM_calloc(space->u.simple.rank*sizeof(hsize_t));
- space->h.count=H5MM_calloc(space->u.simple.rank*sizeof(hsize_t));
- space->h.stride=H5MM_calloc(space->u.simple.rank*sizeof(hsize_t));
- if (NULL==space->h.start ||
- NULL==space->h.count ||
- NULL==space->h.stride) {
- HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "memory allocation failed");
- }
- }
-
- /* Build hyperslab */
- for(u=0; u<space->u.simple.rank; u++) {
- space->h.start[u] = start[u];
- space->h.count[u] = count[u];
- space->h.stride[u] = tmp_stride[u];
- }
- space->hslab_def=TRUE;
-
-done:
- if (ret_value == FAIL) { /* Error condition cleanup */
-
- } /* end if */
-
- /* Normal function cleanup */
- H5MM_xfree(tmp_stride);
- FUNC_LEAVE(ret_value);
-}
-
-/*-------------------------------------------------------------------------
- * Function: H5Sget_hyperslab
- *
- * Purpose: Retrieves information about the hyperslab from a simple data
- * space. If no hyperslab has been defined then the hyperslab
- * is the same as the entire array.
- *
- * Return: Success: Hyperslab dimensionality.
- *
- * Failure: FAIL
- *
- * Programmer: Robb Matzke
- * Wednesday, January 28, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-int
-H5Sget_hyperslab (hid_t sid, hssize_t offset[]/*out*/, hsize_t size[]/*out*/,
- hsize_t stride[]/*out*/)
-{
- const H5S_t *ds = NULL;
- intn ret_value = FAIL;
-
- FUNC_ENTER (H5Sget_hyperslab, FAIL);
- H5TRACE1("Is","i",sid);
-
- /* Check args */
- if (H5_DATASPACE!=H5I_group (sid) || NULL==(ds=H5I_object (sid))) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space");
- }
-
- /* Get hyperslab info */
- if ((ret_value=H5S_get_hyperslab (ds, offset, size, stride))<0) {
- HRETURN_ERROR (H5E_DATASPACE, H5E_CANTINIT, FAIL,
- "unable to retrieve hyperslab information");
- }
-
- FUNC_LEAVE (ret_value);
-}
-
-/*-------------------------------------------------------------------------
- * Function: H5S_get_hyperslab
- *
- * Purpose: Retrieves information about the hyperslab from a simple data
- * space. If no hyperslab has been defined then the hyperslab
- * is the same as the entire array.
- *
- * Return: Success: Hyperslab dimensionality.
- *
- * Failure: FAIL
- *
- * Programmer: Robb Matzke
- * Wednesday, January 28, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-intn
-H5S_get_hyperslab (const H5S_t *ds, hssize_t offset[]/*out*/,
- hsize_t size[]/*out*/, hsize_t stride[]/*out*/)
-{
- intn i;
- intn ret_value = FAIL;
-
- FUNC_ENTER (H5S_get_hyperslab, FAIL);
-
- /* Check args */
- assert (ds);
- switch (ds->type) {
- case H5S_SCALAR:
- break;
-
- case H5S_SIMPLE:
- if (ds->hslab_def) {
- for (i=0; i<ds->u.simple.rank; i++) {
- if (offset) offset[i] = ds->h.start[i];
- if (size) size[i] = ds->h.count[i];
- if (stride) stride[i] = ds->h.stride[i];
- }
- } else {
- for (i=0; i<ds->u.simple.rank; i++) {
- if (offset) offset[i] = 0;
- if (size) size[i] = ds->u.simple.size[i];
- if (stride) stride[i] = 1;
- }
- }
- ret_value = ds->u.simple.rank;
- break;
-
- case H5S_COMPLEX: /*fall through*/
- default:
- HRETURN_ERROR (H5E_DATASPACE, H5E_UNSUPPORTED, FAIL,
- "hyperslabs not supported for this type of space");
- }
-
- FUNC_LEAVE (ret_value);
-}
-
-
/*-------------------------------------------------------------------------
* Function: H5S_find
*
@@ -1358,44 +1119,138 @@ H5S_get_hyperslab (const H5S_t *ds, hssize_t offset[]/*out*/,
*
*-------------------------------------------------------------------------
*/
-const H5S_conv_t *
-H5S_find (const H5S_t *mem_space, const H5S_t *file_space)
+herr_t
+H5S_find (H5S_conv_t *conv, const H5S_t *mem_space, const H5S_t *file_space)
{
- static H5S_conv_t _conv;
- static const H5S_conv_t *conv = NULL;
-
- FUNC_ENTER (H5S_find, NULL);
+ FUNC_ENTER (H5S_find, FAIL);
/* Check args */
- assert (mem_space && (H5S_SIMPLE==mem_space->type || H5S_SCALAR==mem_space->type));
- assert (file_space && (H5S_SIMPLE==file_space->type || H5S_SCALAR==mem_space->type));
+ assert (conv);
+ assert (mem_space && (H5S_SIMPLE==mem_space->extent.type || H5S_SCALAR==mem_space->extent.type));
+ assert (file_space && (H5S_SIMPLE==file_space->extent.type || H5S_SCALAR==mem_space->extent.type));
/*
* We can't do conversion if the source and destination select a
* different number of data points.
*/
- if (H5S_get_npoints (mem_space) != H5S_get_npoints (file_space)) {
- HRETURN_ERROR (H5E_DATASPACE, H5E_BADRANGE, NULL,
+ if (H5S_select_npoints (mem_space) != H5S_select_npoints (file_space)) {
+ HRETURN_ERROR (H5E_DATASPACE, H5E_BADRANGE, FAIL,
"memory and file data spaces are different sizes");
}
+#ifdef OLD_WAY
/*
* Initialize pointers. This will eventually be a table lookup based
* on the source and destination data spaces, similar to H5T_find(), but
* for now we only support simple data spaces.
*/
if (!conv) {
- _conv.init = H5S_simp_init;
- _conv.fgath = H5S_simp_fgath;
- _conv.mscat = H5S_simp_mscat;
- _conv.mgath = H5S_simp_mgath;
- _conv.fscat = H5S_simp_fscat;
- _conv.read = H5S_simp_read;
- _conv.write = H5S_simp_write;
- conv = &_conv;
+ _conv.init = H5S_simp_init;
+ _conv.fgath = H5S_simp_fgath;
+ _conv.mscat = H5S_simp_mscat;
+ _conv.mgath = H5S_simp_mgath;
+ _conv.fscat = H5S_simp_fscat;
+ _conv.read = H5S_simp_read;
+ _conv.write = H5S_simp_write;
+ conv = &_conv;
}
+#else
+ /* Set up the function pointers for file transfers */
+ switch(file_space->select.type) {
+ case H5S_SEL_POINTS:
+#ifdef QAK
+printf("%s: file space has point selection\n",FUNC);
+#endif /* QAK */
+ conv->finit = H5S_point_init;
+ conv->favail = H5S_point_favail;
+ conv->fgath = H5S_point_fgath;
+ conv->fscat = H5S_point_fscat;
+ conv->read = NULL;
+ conv->write = NULL;
+ break;
+
+ case H5S_SEL_ALL:
+#ifdef QAK
+printf("%s: file space has all selection\n",FUNC);
+#endif /* QAK */
+ conv->finit = H5S_all_init;
+ conv->favail = H5S_all_favail;
+ conv->fgath = H5S_all_fgath;
+ conv->fscat = H5S_all_fscat;
+ conv->read = NULL;
+ conv->write = NULL;
+ break;
+
+ case H5S_SEL_HYPERSLABS:
+#ifdef QAK
+printf("%s: file space has hyperslab selection\n",FUNC);
+#endif /* QAK */
+ conv->finit = H5S_hyper_init;
+ conv->favail = H5S_hyper_favail;
+ conv->fgath = H5S_hyper_fgath;
+ conv->fscat = H5S_hyper_fscat;
+ conv->read = NULL;
+ conv->write = NULL;
+ break;
+
+ case H5S_SEL_NONE:
+ default:
+#ifdef QAK
+printf("%s: file space has unknown selection\n",FUNC);
+#endif /* QAK */
+ HRETURN_ERROR (H5E_DATASPACE, H5E_BADVALUE, FAIL,
+ "invalid file dataspace selection type");
+ } /* end switch */
+
+ /* Set up the function pointers for background & memory transfers */
+ switch(mem_space->select.type) {
+ case H5S_SEL_POINTS:
+#ifdef QAK
+printf("%s: memory space has point selection\n",FUNC);
+#endif /* QAK */
+ conv->minit = H5S_point_init;
+ conv->binit = H5S_point_init;
+ conv->mgath = H5S_point_mgath;
+ conv->mscat = H5S_point_mscat;
+ conv->read = NULL;
+ conv->write = NULL;
+ break;
+
+ case H5S_SEL_ALL:
+#ifdef QAK
+printf("%s: memory space has all selection\n",FUNC);
+#endif /* QAK */
+ conv->minit = H5S_all_init;
+ conv->binit = H5S_all_init;
+ conv->mgath = H5S_all_mgath;
+ conv->mscat = H5S_all_mscat;
+ conv->read = NULL;
+ conv->write = NULL;
+ break;
+
+ case H5S_SEL_HYPERSLABS:
+#ifdef QAK
+printf("%s: memory space has hyperslab selection\n",FUNC);
+#endif /* QAK */
+ conv->minit = H5S_hyper_init;
+ conv->binit = H5S_hyper_init;
+ conv->mgath = H5S_hyper_mgath;
+ conv->mscat = H5S_hyper_mscat;
+ conv->read = NULL;
+ conv->write = NULL;
+ break;
+
+ case H5S_SEL_NONE:
+ default:
+#ifdef QAK
+printf("%s: memory space has unknown selection\n",FUNC);
+#endif /* QAK */
+ HRETURN_ERROR (H5E_DATASPACE, H5E_BADVALUE, FAIL,
+ "invalid file dataspace selection type");
+ } /* end switch */
+#endif /* OLD_WAY */
- FUNC_LEAVE (conv);
+ FUNC_LEAVE (SUCCEED);
}
/*-------------------------------------------------------------------------
@@ -1422,30 +1277,97 @@ H5S_extend (H5S_t *space, const hsize_t *size)
FUNC_ENTER (H5S_extend, FAIL);
/* Check args */
- assert (space && H5S_SIMPLE==space->type);
+ assert (space && H5S_SIMPLE==space->extent.type);
assert (size);
- for (i=0; i<space->u.simple.rank; i++) {
- if (space->u.simple.size[i]<size[i]) {
- if (space->u.simple.max &&
- H5S_UNLIMITED!=space->u.simple.max[i] &&
- space->u.simple.max[i]<size[i]) {
- HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
- "dimension cannot be increased");
- }
- ret_value++;
- }
+ for (i=0; i<space->extent.u.simple.rank; i++) {
+ if (space->extent.u.simple.size[i]<size[i]) {
+ if (space->extent.u.simple.max &&
+ H5S_UNLIMITED!=space->extent.u.simple.max[i] &&
+ space->extent.u.simple.max[i]<size[i]) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
+ "dimension cannot be increased");
+ }
+ ret_value++;
+ }
}
/* Update */
if (ret_value) {
- for (i=0; i<space->u.simple.rank; i++) {
- if (space->u.simple.size[i]<size[i]) {
- space->u.simple.size[i] = size[i];
- }
- }
+ for (i=0; i<space->extent.u.simple.rank; i++) {
+ if (space->extent.u.simple.size[i]<size[i]) {
+ space->extent.u.simple.size[i] = size[i];
+ }
+ }
}
FUNC_LEAVE (ret_value);
}
+
+/*-------------------------------------------------------------------------
+ * Function: H5Screate_simple
+ *
+ * Purpose: Creates a new simple data space object and opens it for
+ * access. The DIMS argument is the size of the simple dataset
+ * and the MAXDIMS argument is the upper limit on the size of
+ * the dataset. MAXDIMS may be the null pointer in which case
+ * the upper limit is the same as DIMS. If an element of
+ * MAXDIMS is H5S_UNLIMITED then the corresponding dimension is
+ * unlimited, otherwise no element of MAXDIMS should be smaller
+ * than the corresponding element of DIMS.
+ *
+ * Return: Success: The ID for the new simple data space object.
+ *
+ * Failure: FAIL
+ *
+ * Errors:
+ *
+ * Programmer: Quincey Koziol
+ * Tuesday, January 27, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+hid_t
+H5Screate_simple (int rank, const hsize_t *dims, const hsize_t *maxdims)
+{
+ hid_t ret_value = FAIL;
+ int i;
+
+ FUNC_ENTER(H5Screate, FAIL);
+
+ /* Check arguments */
+ if (rank<0) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
+ "dimensionality cannot be negative");
+ }
+ if (!dims && dims!=0) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
+ "no dimensions specified");
+ }
+ if (maxdims) {
+ for (i=0; i<rank; i++) {
+ if (H5S_UNLIMITED!=maxdims[i] && maxdims[i]<dims[i]) {
+ HRETURN_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL,
+ "maxdims is smaller than dims");
+ }
+ }
+ }
+
+ if((ret_value=H5Screate(H5S_SIMPLE))==FAIL)
+ HRETURN_ERROR (H5E_DATASPACE, H5E_CANTCREATE, FAIL,
+ "can't create simple dataspace");
+
+ if(H5Sset_extent_simple(ret_value,rank,dims,maxdims)<0) {
+ H5Sclose(ret_value);
+ HRETURN_ERROR (H5E_DATASPACE, H5E_CANTINIT, FAIL,
+ "can't set dimensions");
+ } /* end if */
+
+done:
+ if (ret_value < 0) {
+ }
+ FUNC_LEAVE(ret_value);
+}