summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--release_docs/RELEASE.txt4
-rw-r--r--src/H5FLprivate.h2
-rw-r--r--src/H5MPprivate.h2
-rw-r--r--src/H5O.c54
-rw-r--r--src/H5Oprivate.h2
-rw-r--r--src/H5Osdspace.c6
-rw-r--r--src/H5S.c233
-rw-r--r--src/H5Sprivate.h2
-rw-r--r--src/H5Spublic.h2
-rw-r--r--src/H5T.c19
-rw-r--r--test/th5s.c168
11 files changed, 467 insertions, 27 deletions
diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt
index 8d2a74d..0959c77 100644
--- a/release_docs/RELEASE.txt
+++ b/release_docs/RELEASE.txt
@@ -44,6 +44,10 @@ New Features
Library:
--------
+ - 4 new API functions, H5Tencode, H5Tdecode, H5Sencode, H5Sdecode were
+ added to the library. Given object ID, these functions encode and
+ decode HDF5 objects(data type and space) information into and from
+ binary buffer. SLU - 2004/07/21
- Modified the way how HDF5 calculates 'pixels_per_scanline' parameter for
SZIP compression. Now there is no restriction on the size and shape of the
chunk except that the total number of elements in the chunk cannot be
diff --git a/src/H5FLprivate.h b/src/H5FLprivate.h
index c1fbfae..0bac0cf 100644
--- a/src/H5FLprivate.h
+++ b/src/H5FLprivate.h
@@ -35,7 +35,7 @@
/* Private headers needed by this file */
/* Macros for turning off free lists in the library */
-/* #define H5_NO_FREE_LISTS */
+#define H5_NO_FREE_LISTS
#ifdef H5_NO_FREE_LISTS
#define H5_NO_REG_FREE_LISTS
#define H5_NO_ARR_FREE_LISTS
diff --git a/src/H5MPprivate.h b/src/H5MPprivate.h
index 771c836..a47a6fe 100644
--- a/src/H5MPprivate.h
+++ b/src/H5MPprivate.h
@@ -389,6 +389,8 @@
#define color_H5Sset_extent_simple "red"
#define color_H5Scopy "red"
#define color_H5Sclose "red"
+#define color_H5Sencode "red"
+#define color_H5Sdecode "red"
#define color_H5Sget_simple_extent_npoints "red"
#define color_H5Sget_simple_extent_ndims "red"
#define color_H5Sget_simple_extent_dims "red"
diff --git a/src/H5O.c b/src/H5O.c
index 1515500..03336f7 100644
--- a/src/H5O.c
+++ b/src/H5O.c
@@ -3444,10 +3444,11 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5O_encode(unsigned char *buf, void *obj, size_t *nalloc, unsigned type_id)
+H5O_encode(unsigned char *buf, void *obj, hid_t type_id)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
- size_t size; /* size of the message*/
+ size_t extent_size; /* size of the message*/
+ H5F_t f; /* fake file structure*/
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5O_encode,FAIL);
@@ -3457,19 +3458,23 @@ H5O_encode(unsigned char *buf, void *obj, size_t *nalloc, unsigned type_id)
type=message_type_g[type_id]; /* map the type ID to the actual type object */
assert(type);
- /* check buffer size */
- if ((size=(type->raw_size)(NULL, obj))<=0)
+ if(type_id == H5O_SDSPACE_ID) {
+ /* Fake file structure, needed for space encoding and decoding. */
+ f.shared = (H5F_file_t*)H5MM_calloc(sizeof(H5F_file_t));
+ f.shared->sizeof_size = H5F_CRT_OBJ_BYTE_NUM_DEF;
+
+ /* Encode this "size of size" */
+ *buf = H5F_CRT_OBJ_BYTE_NUM_DEF;
+ buf++;
+ }
+
+ /* Encode */
+ if ((type->encode)(&f, buf, obj)<0)
HGOTO_ERROR (H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message");
- /* Don't encode if buffer size isn't big enough */
- if(!buf || *nalloc<size)
- *nalloc = size;
- else {
- /* Encode */
- if ((type->encode)(NULL, buf, obj)<0)
- HGOTO_ERROR (H5E_OHDR, H5E_CANTENCODE, FAIL, "unable to encode message");
- } /* end else */
-
+ if(type_id == H5O_SDSPACE_ID)
+ H5MM_free(f.shared);
+
done:
FUNC_LEAVE_NOAPI(ret_value);
}
@@ -3481,9 +3486,9 @@ done:
* Purpose: Decode a binary object(data type and data space only)
* description and return a new object handle.
*
- * Return: Success: Object ID(non-negative)
+ * Return: Success: Pointer to object(data type or space)
*
- * Failure: Negative
+ * Failure: NULL
*
* Programmer: Raymond Lu
* slu@ncsa.uiuc.edu
@@ -3497,7 +3502,8 @@ void*
H5O_decode(unsigned char *buf, unsigned type_id)
{
const H5O_class_t *type; /* Actual H5O class type for the ID */
- void *ret_value; /* Return value */
+ H5F_t f; /* fake file structure*/
+ void *ret_value=NULL; /* Return value */
FUNC_ENTER_NOAPI(H5O_decode,NULL);
@@ -3506,8 +3512,22 @@ H5O_decode(unsigned char *buf, unsigned type_id)
type=message_type_g[type_id]; /* map the type ID to the actual type object */
assert(type);
+ if(type_id == H5O_SDSPACE_ID) {
+ /* Fake file structure, needed for space encoding and decoding. */
+ f.shared = (H5F_file_t*)H5MM_calloc(sizeof(H5F_file_t));
+
+ /* Decode the "size of size", needed for space encoding and decoding */
+ f.shared->sizeof_size = *buf;
+ buf++;
+ }
+
/* decode */
- ret_value = (type->decode)(NULL, 0, buf, NULL);
+ if((ret_value = (type->decode)(&f, 0, buf, NULL))==NULL)
+ HGOTO_ERROR (H5E_OHDR, H5E_CANTDECODE, NULL, "unable to decode message");
+
+ if(type_id == H5O_SDSPACE_ID) {
+ H5MM_free(f.shared);
+ }
done:
FUNC_LEAVE_NOAPI(ret_value);
diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h
index a18820a..4eb3a3c 100644
--- a/src/H5Oprivate.h
+++ b/src/H5Oprivate.h
@@ -249,7 +249,7 @@ H5_DLL herr_t H5O_remove(H5G_entry_t *ent, unsigned type_id, int sequence,
hid_t dxpl_id);
H5_DLL herr_t H5O_reset(unsigned type_id, void *native);
H5_DLL void *H5O_free(unsigned type_id, void *mesg);
-H5_DLL herr_t H5O_encode(unsigned char *buf, void *obj, size_t *nalloc, unsigned type_id);
+H5_DLL herr_t H5O_encode(unsigned char *buf, void *obj, hid_t type_id);
H5_DLL void* H5O_decode(unsigned char *buf, unsigned type_id);
H5_DLL void *H5O_copy(unsigned type_id, const void *mesg, void *dst);
H5_DLL size_t H5O_raw_size(unsigned type_id, H5F_t *f, const void *mesg);
diff --git a/src/H5Osdspace.c b/src/H5Osdspace.c
index 7c4bb80..8fff4b0 100644
--- a/src/H5Osdspace.c
+++ b/src/H5Osdspace.c
@@ -108,7 +108,7 @@ H5O_sdspace_decode(H5F_t *f, hid_t UNUSED dxpl_id, const uint8_t *p, H5O_shared_
FUNC_ENTER_NOAPI_NOINIT(H5O_sdspace_decode);
/* check args */
- assert(f);
+ /*assert(f);*/
assert(p);
assert (!sh);
@@ -210,7 +210,7 @@ done:
--------------------------------------------------------------------------*/
static herr_t
-H5O_sdspace_encode(H5F_t UNUSED *f, uint8_t *p, const void *mesg)
+H5O_sdspace_encode(H5F_t *f, uint8_t *p, const void *mesg)
{
const H5S_extent_t *sdim = (const H5S_extent_t *) mesg;
unsigned u; /* Local counting variable */
@@ -219,7 +219,7 @@ H5O_sdspace_encode(H5F_t UNUSED *f, uint8_t *p, const void *mesg)
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_sdspace_encode);
/* check args */
- /*assert(f);*/
+ assert(f);
assert(p);
assert(sdim);
diff --git a/src/H5S.c b/src/H5S.c
index f6b95fb..678dadc 100644
--- a/src/H5S.c
+++ b/src/H5S.c
@@ -13,6 +13,7 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#define H5S_PACKAGE /*suppress error about including H5Spkg */
+#define H5F_PACKAGE /*suppress error about including H5Fpkg */
/* Interface initialization */
#define H5_INTERFACE_INIT_FUNC H5S_init_interface
@@ -26,6 +27,7 @@
#include "H5Eprivate.h" /* Error handling */
#include "H5Iprivate.h" /* ID Functions */
#include "H5FLprivate.h" /* Free Lists */
+#include "H5Fpkg.h" /* Dataspace functions */
#include "H5MMprivate.h" /* Memory Management functions */
#include "H5Oprivate.h" /* object headers */
#include "H5Spkg.h" /* Dataspace functions */
@@ -1743,6 +1745,237 @@ done:
/*-------------------------------------------------------------------------
+ * Function: H5Sencode
+ *
+ * Purpose: Given a dataspace ID, converts the object description
+ * (including selection) into binary in a buffer.
+ *
+ * Return: Success: non-negative
+ *
+ * Failure: negative
+ *
+ * Programmer: Raymond Lu
+ * slu@ncsa.uiuc.edu
+ * July 14, 2004
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5Sencode(hid_t obj_id, unsigned char* buf, size_t* nalloc)
+{
+ H5S_t *dspace;
+ herr_t ret_value;
+
+ FUNC_ENTER_API (H5Sencode, FAIL);
+
+ /* Check argument and retrieve object */
+ if (NULL==(dspace=H5I_object_verify(obj_id, H5I_DATASPACE)))
+ HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace")
+
+ ret_value = H5S_encode(dspace, buf, nalloc);
+
+done:
+ FUNC_LEAVE_API(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5S_encode
+ *
+ * Purpose: Private function for H5Sencode. Converts an object
+ * description for data space and its selection into binary
+ * in a buffer.
+ *
+ * Return: Success: non-negative
+ *
+ * Failure: negative
+ *
+ * Programmer: Raymond Lu
+ * slu@ncsa.uiuc.edu
+ * July 14, 2004
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5S_encode(H5S_t *obj, unsigned char *buf, size_t *nalloc)
+{
+ size_t extent_size = 0;
+ hssize_t select_size = 0;
+ H5S_class_t space_type;
+ uint8_t *size_buf;
+ uint8_t *extent_buf;
+ uint8_t *select_buf;
+ H5F_t f; /* fake file structure*/
+ herr_t ret_value = SUCCEED;
+
+ FUNC_ENTER_NOAPI(H5S_encode, FAIL);
+
+ /* Fake file structure, used only for header message operation */
+ f.shared = (H5F_file_t*)H5MM_calloc(sizeof(H5F_file_t));
+ f.shared->sizeof_size = H5F_CRT_OBJ_BYTE_NUM_DEF;
+
+ /* Find out the size of buffer needed for extent */
+ if((extent_size=H5O_raw_size(H5O_SDSPACE_ID, &f, obj))==0)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_BADSIZE, FAIL, "can't find dataspace size");
+
+ H5MM_free(f.shared);
+
+ /* Make it 1 byte bigger to encode the f.shared->sizeof_size(8 bytes). The
+ * actual encoding happens in the level below(H5O_encode). */
+ extent_size++;
+
+ /* Get space type */
+ space_type = H5S_GET_EXTENT_TYPE(obj);
+
+ if((H5S_SIMPLE==space_type) && (select_size=H5S_SELECT_SERIAL_SIZE(obj))<0)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_BADSIZE, FAIL, "can't find dataspace selection size");
+
+ /* Verify the size of buffer. If it's not big enough, simply return the
+ * right size without filling the buffer. */
+ if(!buf || *nalloc<(extent_size+select_size+2)) {
+ *nalloc = extent_size+select_size+2;
+ HGOTO_DONE(ret_value);
+ }
+
+ /* Encode size of extent information. Pointer is actually moved in this macro. */
+ size_buf = buf;
+ UINT16ENCODE(size_buf, (uint8_t)extent_size);
+
+ /* Encode the extent part of dataspace */
+ extent_buf = buf + 2; /* This 2 bytes come from UINT16ENCODE above */
+ if(H5O_encode(extent_buf, obj, H5O_SDSPACE_ID)<0)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTENCODE, FAIL, "can't encode extent space");
+
+ /* Encode the selection part of dataspace. I believe the size is always greater
+ * than 0 */
+ if(space_type==H5S_SIMPLE && select_size>0) {
+ select_buf = buf + 2 + extent_size;
+ if(H5S_SELECT_SERIALIZE(obj, select_buf) <0)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTENCODE, FAIL, "can't encode select space");
+ }
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5Sdecode
+ *
+ * Purpose: Decode a binary object description of data space and
+ * return a new object handle.
+ *
+ * Return: Success: dataspace ID(non-negative)
+ *
+ * Failure: negative
+ *
+ * Programmer: Raymond Lu
+ * slu@ncsa.uiuc.edu
+ * July 14, 2004
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+hid_t
+H5Sdecode(unsigned char* buf)
+{
+ H5S_t *ds;
+ hid_t ret_value;
+
+ FUNC_ENTER_API (H5Sdecode, FAIL);
+
+ if (buf==NULL)
+ HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "empty buffer")
+
+ if((ds = H5S_decode(buf))==NULL)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDECODE, FAIL, "can't decode object");
+
+ /* Register the type and return the ID */
+ if ((ret_value=H5I_register (H5I_DATASPACE, ds))<0)
+ HGOTO_ERROR (H5E_DATASPACE, H5E_CANTREGISTER, FAIL, "unable to register dataspace");
+
+done:
+ FUNC_LEAVE_API(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5S_decode
+ *
+ * Purpose: Private function for H5Sdecode. Reconstructs a binary
+ * description of dataspace and returns a new object handle.
+ *
+ * Return: Success: dataspace ID(non-negative)
+ *
+ * Failure: negative
+ *
+ * Programmer: Raymond Lu
+ * slu@ncsa.uiuc.edu
+ * July 14, 2004
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+H5S_t*
+H5S_decode(unsigned char *buf)
+{
+ H5S_t *ds;
+ H5S_extent_t *extent;
+ size_t extent_size; /* size of the extent message*/
+ uint8_t *size_buf;
+ uint8_t *extent_buf;
+ uint8_t *select_buf;
+ H5S_t *ret_value;
+
+ FUNC_ENTER_NOAPI(H5S_decode, NULL);
+
+ /* Decode size of extent information */
+ size_buf = buf;
+ UINT16DECODE(size_buf, extent_size);
+
+ /* Decode the extent part of dataspace */
+ extent_buf = buf+2; /*2 bytes are from the UINT16DECODE above*/
+
+ if((extent = H5O_decode(extent_buf, H5O_SDSPACE_ID))==NULL)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDECODE, NULL, "can't decode object");
+
+ /* Copy the extent into dataspace structure */
+ ds = H5FL_CALLOC(H5S_t);
+ if(H5O_copy(H5O_SDSPACE_ID, extent, &(ds->extent))==NULL)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy object");
+
+ H5S_extent_release(extent);
+ H5FL_FREE(H5S_extent_t,extent);
+
+ /* Initialize to "all" selection. Deserialization seems relying on it. */
+ if(H5S_select_all(ds,0)<0)
+ HGOTO_ERROR (H5E_DATASPACE, H5E_CANTSET, NULL, "unable to set all selection");
+
+ /* Reset common selection info pointer */
+ ds->select.sel_info.hslab=NULL;
+
+ /* Decode the select part of dataspace. I believe this part always exists. */
+ if(ds->extent.type == H5S_SIMPLE) {
+ select_buf = buf + 2 + extent_size;
+ if(H5S_SELECT_DESERIALIZE(ds, select_buf)<0)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDECODE, NULL, "can't decode space selection");
+ }
+
+ /* Set return value */
+ ret_value=ds;
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value);
+}
+
+
+/*-------------------------------------------------------------------------
* Function: H5S_get_simple_extent_type
*
* Purpose: Internal function for retrieving the type of extent for a dataspace object
diff --git a/src/H5Sprivate.h b/src/H5Sprivate.h
index dc42b05..9e4028b 100644
--- a/src/H5Sprivate.h
+++ b/src/H5Sprivate.h
@@ -206,6 +206,8 @@ typedef struct H5S_conv_t {
/* Operations on dataspaces */
H5_DLL H5S_t *H5S_copy(const H5S_t *src, hbool_t share_selection);
H5_DLL herr_t H5S_close(H5S_t *ds);
+H5_DLL herr_t H5S_encode(H5S_t *obj, unsigned char *buf, size_t *nalloc);
+H5_DLL H5S_t *H5S_decode(unsigned char *buf);
H5_DLL H5S_conv_t *H5S_find(const H5F_t *file,const H5S_t *mem_space, const H5S_t *file_space,
unsigned flags, hbool_t *use_par_opt_io,const H5O_layout_t *layout );
H5_DLL H5S_class_t H5S_get_simple_extent_type(const H5S_t *ds);
diff --git a/src/H5Spublic.h b/src/H5Spublic.h
index 70958c9..2017727 100644
--- a/src/H5Spublic.h
+++ b/src/H5Spublic.h
@@ -100,6 +100,8 @@ H5_DLL herr_t H5Sset_extent_simple(hid_t space_id, int rank,
const hsize_t max[]);
H5_DLL hid_t H5Scopy(hid_t space_id);
H5_DLL herr_t H5Sclose(hid_t space_id);
+H5_DLL herr_t H5Sencode(hid_t obj_id, unsigned char* buf, size_t* nalloc);
+H5_DLL hid_t H5Sdecode(unsigned char* buf);
H5_DLL hssize_t H5Sget_simple_extent_npoints(hid_t space_id);
H5_DLL int H5Sget_simple_extent_ndims(hid_t space_id);
H5_DLL int H5Sget_simple_extent_dims(hid_t space_id, hsize_t dims[],
diff --git a/src/H5T.c b/src/H5T.c
index 4d9b032..095d449 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -20,6 +20,7 @@
*/
#define H5T_PACKAGE /*suppress error about including H5Tpkg */
+#define H5F_PACKAGE /*suppress error about including H5Fpkg */
/* Interface initialization */
#define H5_INTERFACE_INIT_FUNC H5T_init_interface
@@ -32,10 +33,12 @@
#include "H5Dprivate.h" /*datasets (for H5Tcopy) */
#include "H5Eprivate.h" /*error handling */
#include "H5FLprivate.h" /* Free Lists */
+#include "H5Fprivate.h" /* File */
#include "H5Gprivate.h" /*groups */
#include "H5Iprivate.h" /*ID functions */
#include "H5MMprivate.h" /*memory management */
#include "H5Pprivate.h" /* Property Lists */
+#include "H5Fpkg.h" /*file functions */
#include "H5Tpkg.h" /*data-type functions */
/* Check for header needed for SGI floating-point code */
@@ -2618,7 +2621,7 @@ H5Tdecode(unsigned char* buf)
FUNC_ENTER_API (H5Tdecode, FAIL);
if (buf==NULL)
- HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "NULL pointer for buffer")
+ HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "empty buffer")
if((dt = H5T_decode(buf))==NULL)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTDECODE, FAIL, "can't decode object");
@@ -2658,11 +2661,23 @@ done:
herr_t
H5T_encode(H5T_t *obj, unsigned char *buf, size_t *nalloc)
{
+ size_t buf_size = 0;
+ H5F_t f;
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(H5T_encode, FAIL);
+
+ /* Find out the size of buffer needed */
+ if((buf_size=H5O_raw_size(H5O_DTYPE_ID, &f, obj))==0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_BADSIZE, FAIL, "can't find datatype size");
+
+ /* Don't encode if buffer size isn't big enough or buffer is empty */
+ if(!buf || *nalloc<buf_size) {
+ *nalloc = buf_size;
+ HGOTO_DONE(ret_value);
+ }
- if(H5O_encode(buf, obj, nalloc, H5O_DTYPE_ID)<0)
+ if(H5O_encode(buf, obj, H5O_DTYPE_ID)<0)
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTENCODE, FAIL, "can't encode object");
done:
diff --git a/test/th5s.c b/test/th5s.c
index a7f5296..1029bc0 100644
--- a/test/th5s.c
+++ b/test/th5s.c
@@ -425,7 +425,168 @@ test_h5s_null(void)
/* Close the file */
ret = H5Fclose(fid);
CHECK(ret, FAIL, "H5Fclose");
-} /* end test_misc20() */
+} /* end test_h5s_null() */
+
+/****************************************************************
+**
+** test_h5s_encode(): Test H5S (dataspace) encoding and decoding.
+**
+****************************************************************/
+static void
+test_h5s_encode(void)
+{
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t sid1, sid2, sid3; /* Dataspace ID */
+ hid_t decoded_sid1, decoded_sid2, decoded_sid3;
+ int rank; /* Logical rank of dataspace */
+ hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
+ size_t sbuf_size=0, null_size=0, scalar_size=0;
+ unsigned char *sbuf=NULL, *null_sbuf=NULL, *scalar_buf=NULL;
+ hsize_t tdims[4]; /* Dimension array to test with */
+ hsize_t tmax[4];
+ hssize_t n; /* Number of dataspace elements */
+ hssize_t start[] = {0, 0, 0};
+ hsize_t stride[] = {2, 5, 3};
+ hsize_t count[] = {2, 2, 2};
+ hsize_t block[] = {1, 3, 1};
+ H5S_sel_type sel_type;
+ H5S_class_t space_type;
+ hssize_t nblocks;
+ herr_t ret; /* Generic return value */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing Dataspace Encoding and Decoding\n"));
+
+ H5open();
+
+ /*-------------------------------------------------------------------------
+ * Test encoding and decoding of simple dataspace and hyperslab selection.
+ *-------------------------------------------------------------------------
+ */
+ sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
+ CHECK(sid1, FAIL, "H5Screate_simple");
+
+ ret = H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, stride, count, block);
+ CHECK(ret, FAIL, "H5Sselect_hyperslab");
+
+ /* Encode simple data space in a buffer */
+ ret = H5Sencode(sid1, NULL, &sbuf_size);
+ CHECK(ret, FAIL, "H5Sencode");
+
+ if(sbuf_size>0)
+ sbuf = (unsigned char*)calloc(1, sbuf_size);
+
+ ret = H5Sencode(sid1, sbuf, &sbuf_size);
+ CHECK(ret, FAIL, "H5Sencode");
+
+ /* Decode from the dataspace buffer and return an object handle */
+ decoded_sid1=H5Sdecode(sbuf);
+ CHECK(decoded_sid1, FAIL, "H5Sdecode");
+
+ /* Verify the decoded dataspace */
+ n = H5Sget_simple_extent_npoints(decoded_sid1);
+ CHECK(n, FAIL, "H5Sget_simple_extent_npoints");
+ VERIFY(n, SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3,
+ "H5Sget_simple_extent_npoints");
+
+ rank = H5Sget_simple_extent_ndims(decoded_sid1);
+ CHECK(rank, FAIL, "H5Sget_simple_extent_ndims");
+ VERIFY(rank, SPACE1_RANK, "H5Sget_simple_extent_ndims");
+
+ rank = H5Sget_simple_extent_dims(decoded_sid1, tdims, NULL);
+ CHECK(rank, FAIL, "H5Sget_simple_extent_dims");
+ VERIFY(HDmemcmp(tdims, dims1, SPACE1_RANK * sizeof(hsize_t)), 0,
+ "H5Sget_simple_extent_dims");
+
+ /* Verify hyperslabe selection */
+ sel_type = H5Sget_select_type(decoded_sid1);
+ VERIFY(sel_type, H5S_SEL_HYPERSLABS, "H5Sget_select_type");
+
+ nblocks = H5Sget_select_hyper_nblocks(decoded_sid1);
+ VERIFY(nblocks, 2*2*2, "H5Sget_select_hyper_nblocks");
+
+ ret = H5Sclose(sid1);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ ret = H5Sclose(decoded_sid1);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ /*-------------------------------------------------------------------------
+ * Test encoding and decoding of null dataspace.
+ *-------------------------------------------------------------------------
+ */
+ sid2 = H5Screate(H5S_NULL);
+ CHECK(sid2, FAIL, "H5Screate");
+
+ /* Encode null data space in a buffer */
+ ret = H5Sencode(sid2, NULL, &null_size);
+ CHECK(ret, FAIL, "H5Sencode");
+
+ if(null_size>0)
+ null_sbuf = (unsigned char*)calloc(1, null_size);
+
+ ret = H5Sencode(sid2, null_sbuf, &null_size);
+ CHECK(ret, FAIL, "H5Sencode");
+
+ /* Decode from the dataspace buffer and return an object handle */
+ decoded_sid2=H5Sdecode(null_sbuf);
+ CHECK(decoded_sid2, FAIL, "H5Sdecode");
+
+ /* Verify decoded dataspace */
+ space_type = H5Sget_simple_extent_type(decoded_sid2);
+ VERIFY(space_type, H5S_NULL, "H5Sget_simple_extent_type");
+
+ ret = H5Sclose(sid2);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ ret = H5Sclose(decoded_sid2);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ /*-------------------------------------------------------------------------
+ * Test encoding and decoding of scalar dataspace.
+ *-------------------------------------------------------------------------
+ */
+ /* Create scalar dataspace */
+ sid3 = H5Screate(H5S_SCALAR);
+ CHECK(sid3, FAIL, "H5Screate_simple");
+
+ /* Encode scalar data space in a buffer */
+ ret = H5Sencode(sid3, NULL, &scalar_size);
+ CHECK(ret, FAIL, "H5Sencode");
+
+ if(scalar_size>0)
+ scalar_buf = (unsigned char*)calloc(1, scalar_size);
+
+ ret = H5Sencode(sid3, scalar_buf, &scalar_size);
+ CHECK(ret, FAIL, "H5Sencode");
+
+ /* Decode from the dataspace buffer and return an object handle */
+ decoded_sid3=H5Sdecode(scalar_buf);
+ CHECK(decoded_sid3, FAIL, "H5Sdecode");
+
+ /* Verify extent type */
+ space_type = H5Sget_simple_extent_type(decoded_sid3);
+ VERIFY(space_type, H5S_SCALAR, "H5Sget_simple_extent_type");
+
+ /* Verify decoded dataspace */
+ n = H5Sget_simple_extent_npoints(decoded_sid3);
+ CHECK(n, FAIL, "H5Sget_simple_extent_npoints");
+ VERIFY(n, 1, "H5Sget_simple_extent_npoints");
+
+ rank = H5Sget_simple_extent_ndims(decoded_sid3);
+ CHECK(rank, FAIL, "H5Sget_simple_extent_ndims");
+ VERIFY(rank, 0, "H5Sget_simple_extent_ndims");
+
+ ret = H5Sclose(sid3);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ ret = H5Sclose(decoded_sid3);
+ CHECK(ret, FAIL, "H5Sclose");
+
+ free(sbuf);
+ free(null_sbuf);
+ free(scalar_buf);
+} /* test_h5s_encode() */
/****************************************************************
**
@@ -802,8 +963,10 @@ test_h5s(void)
test_h5s_basic(); /* Test basic H5S code */
test_h5s_null(); /* Test Null dataspace H5S code */
+ test_h5s_encode(); /* Test encoding and decoding */
test_h5s_scalar_write(); /* Test scalar H5S writing code */
- test_h5s_scalar_read(); /* Test scalar H5S reading code */
+ test_h5s_scalar_read(); /* Test scalar H5S reading code */
+
test_h5s_compound_scalar_write(); /* Test compound datatype scalar H5S writing code */
test_h5s_compound_scalar_read(); /* Test compound datatype scalar H5S reading code */
@@ -831,4 +994,3 @@ cleanup_h5s(void)
{
remove(DATAFILE);
}
-