summaryrefslogtreecommitdiffstats
path: root/tools/h5repack/h5repacktst.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2013-09-26 22:10:54 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2013-09-26 22:10:54 (GMT)
commitdeddc7f9558d76a4cebc417af8d426877d5aee7d (patch)
treee2e43dea685c798debbbe6ae14f7297738c0bfbd /tools/h5repack/h5repacktst.c
parente2dfb53df72ca884cb9225e738aef77135f92e68 (diff)
downloadhdf5-deddc7f9558d76a4cebc417af8d426877d5aee7d.zip
hdf5-deddc7f9558d76a4cebc417af8d426877d5aee7d.tar.gz
hdf5-deddc7f9558d76a4cebc417af8d426877d5aee7d.tar.bz2
[svn-r24205] Merge HDFFV-8513/8522 from trunk (via cmake branch), h5repack UD plugins.
Also warning session fixes. Tested: CMake local linux
Diffstat (limited to 'tools/h5repack/h5repacktst.c')
-rw-r--r--tools/h5repack/h5repacktst.c479
1 files changed, 463 insertions, 16 deletions
diff --git a/tools/h5repack/h5repacktst.c b/tools/h5repack/h5repacktst.c
index a22b0fe..4510bd5 100644
--- a/tools/h5repack/h5repacktst.c
+++ b/tools/h5repack/h5repacktst.c
@@ -84,6 +84,9 @@
/* obj and region references */
#define FNAME_REF "h5repack_refs.h5"
+/* obj and region references in attr of compound and vlen type */
+#define FNAME_ATTR_REF "h5repack_attr_refs.h5"
+
const char *H5REPACK_FILENAMES[] = {
"h5repack_big_out",
NULL
@@ -146,6 +149,7 @@ static int verify_userblock( const char* filename);
static int make_userblock_file(void);
static int make_named_dtype(hid_t loc_id);
static int make_references(hid_t loc_id);
+static int make_complex_attr_references(hid_t loc_id);
/*-------------------------------------------------------------------------
@@ -1857,6 +1861,17 @@ int make_testfiles(void)
if(H5Fclose(fid) < 0)
return -1;
+ /*-------------------------------------------------------------------------
+ * create a file with obj and region references in attribute of compound and
+ * vlen datatype
+ *-------------------------------------------------------------------------*/
+ if((fid = H5Fcreate(FNAME_ATTR_REF,H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT)) < 0)
+ return -1;
+ if (make_complex_attr_references(fid) < 0)
+ goto out;
+ if(H5Fclose(fid) < 0)
+ return -1;
+
return 0;
out:
@@ -2995,31 +3010,31 @@ out:
*
* Purpose: create datasets with contiguous and chunked layouts:
*
- * contig_small: < 1k, fixed dims datspace
- * chunked_small_fixed: < 1k, fixed dims dataspace
+ * contig_small: < 1k, fixed dims datspace
+ * chunked_small_fixed: < 1k, fixed dims dataspace
*
*-------------------------------------------------------------------------
*/
-#define S_DIM1 4
-#define S_DIM2 10
-#define CONTIG_S "contig_small"
-#define CHUNKED_S_FIX "chunked_small_fixed"
+#define S_DIM1 4
+#define S_DIM2 10
+#define CONTIG_S "contig_small"
+#define CHUNKED_S_FIX "chunked_small_fixed"
static
int make_layout2(hid_t loc_id)
{
- hid_t contig_dcpl = -1; /* dataset creation property list */
+ hid_t contig_dcpl = -1; /* dataset creation property list */
hid_t chunked_dcpl = -1; /* dataset creation property list */
- int i, j, n; /* Local index variables */
- int ret_value = -1; /* Return value */
- hid_t s_sid = -1; /* dataspace ID */
+ int i, j, n; /* Local index variables */
+ int ret_value = -1; /* Return value */
+ hid_t s_sid = -1; /* dataspace ID */
- hsize_t s_dims[RANK] = {S_DIM1,S_DIM2}; /* Dataspace (< 1 k) */
- hsize_t chunk_dims[RANK] = {S_DIM1/2, S_DIM2/2}; /* Dimension sizes for chunks */
+ hsize_t s_dims[RANK] = {S_DIM1,S_DIM2}; /* Dataspace (< 1 k) */
+ hsize_t chunk_dims[RANK] = {S_DIM1/2, S_DIM2/2}; /* Dimension sizes for chunks */
- int s_buf[S_DIM1][S_DIM2]; /* Temporary buffer */
+ int s_buf[S_DIM1][S_DIM2]; /* Temporary buffer */
for(i = n = 0; i < S_DIM1; i++) {
for (j = 0; j < S_DIM2; j++) {
@@ -3355,8 +3370,8 @@ int make_external(hid_t loc_id)
hid_t sid=-1;
hid_t dcpl;
int buf[2]={1,2};
- hsize_t cur_size[1]; /* data space current size */
- hsize_t max_size[1]; /* data space maximum size */
+ hsize_t cur_size[1]; /* data space current size */
+ hsize_t max_size[1]; /* data space maximum size */
hsize_t size;
cur_size[0] = max_size[0] = 2;
@@ -5916,7 +5931,6 @@ static herr_t add_attr_with_objref(hid_t file_id, hid_t obj_id)
{
int ret = SUCCEED;
int status;
- int data_attr_int[2] = {10,20};
/* attr obj ref */
hsize_t dim_attr_objref[1]={3};
hobj_ref_t data_attr_objref[3];
@@ -6460,3 +6474,436 @@ static herr_t make_references(hid_t loc_id)
return ret;
}
+/*-------------------------------------------------------------------------
+* Function: make_complex_attr_references
+*
+* Purpose:
+* create a file with :
+* 1. obj ref in attribute of compound type
+* 2. region ref in attribute of compound type
+* 3. obj ref in attribute of vlen type
+* 4. region ref in attribute of vlen type
+*
+* Programmer: Jonathan (March 25, 2010)
+*-------------------------------------------------------------------------
+*/
+/* obj dset */
+#define RANK_OBJ 2
+#define DIM0_OBJ 6
+#define DIM1_OBJ 10
+/* container dset */
+#define RANK_DSET 1
+#define DIM_DSET 4
+/* 1. obj references in compound attr */
+#define RANK_COMP_OBJREF 1
+#define DIM_COMP_OBJREF 3 /* for dataset, group, datatype */
+/* 2. region references in compound attr */
+#define RANK_COMP_REGREF 1
+#define DIM_COMP_REGREF 1 /* for element region */
+/* 3. obj references in vlen attr */
+#define RANK_VLEN_OBJREF 1
+#define DIM_VLEN_OBJREF 3 /* for dataset, group, datatype */
+#define LEN0_VLEN_OBJREF 1 /* dataset */
+#define LEN1_VLEN_OBJREF 1 /* group */
+#define LEN2_VLEN_OBJREF 1 /* datatype */
+/* 4. region references in vlen attr */
+#define RANK_VLEN_REGREF 1
+#define DIM_VLEN_REGREF 1 /* for element region */
+#define LEN0_VLEN_REGREF 1 /* element region */
+
+static herr_t make_complex_attr_references(hid_t loc_id)
+{
+ herr_t ret = SUCCEED;
+ herr_t status;
+ /*
+ * for objects
+ */
+ hid_t objgid=0, objdid=0, objtid=0, objsid=0;
+ hsize_t obj_dims[RANK_OBJ] = {DIM0_OBJ, DIM1_OBJ};
+ int obj_data[DIM0_OBJ][DIM1_OBJ]=
+ {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
+ {10,11,12,13,14,15,16,17,18,19},
+ {20,21,22,23,24,25,26,27,28,29},
+ {30,31,32,33,34,35,36,37,38,39},
+ {40,41,42,43,44,45,46,47,48,49},
+ {50,51,52,53,54,55,56,57,58,59}};
+
+ /*
+ * group main
+ */
+ hid_t main_gid=0;
+ /*
+ * dataset which the attribute will be attached to
+ */
+ hsize_t main_dset_dims[RANK_DSET] = {DIM_DSET};
+ hid_t main_sid=0, main_did=0;
+ /*
+ * 1. obj references in compound attr
+ */
+ hid_t comp_objref_tid=0, comp_objref_aid=0;
+ typedef struct comp_objref_t {
+ hobj_ref_t val_objref;
+ int val_int;
+ } comp_objref_t;
+ comp_objref_t comp_objref_data[DIM_COMP_OBJREF];
+ hid_t comp_objref_attr_sid=0;
+ hsize_t comp_objref_dim[RANK_COMP_OBJREF] = {DIM_COMP_OBJREF};
+
+ /*
+ * 2. region references in compound attr
+ */
+ hid_t comp_regref_tid=0, comp_regref_aid=0;
+ typedef struct comp_regref_t {
+ hdset_reg_ref_t val_regref;
+ int val_int;
+ } comp_regref_t;
+ comp_regref_t comp_regref_data[DIM_COMP_REGREF];
+ hid_t comp_regref_attr_sid=0;
+ hsize_t comp_regref_dim[RANK_COMP_REGREF] = {DIM_COMP_REGREF};
+ hsize_t coords[4][2] = { {0,1}, {2,3}, {3,4}, {4,5} };
+
+ /*
+ * 3. obj references in vlen attr
+ */
+ hid_t vlen_objref_attr_tid=0, vlen_objref_attr_sid=0;
+ hid_t vlen_objref_attr_id=0;
+ hvl_t vlen_objref_data[DIM_VLEN_OBJREF];
+ hsize_t vlen_objref_dims[RANK_VLEN_OBJREF] = {DIM_VLEN_OBJREF};
+
+ /*
+ * 4. region references in vlen attr
+ */
+ hid_t vlen_regref_attr_tid=0, vlen_regref_attr_sid=0;
+ hid_t vlen_regref_attr_id=0;
+ hvl_t vlen_regref_data[DIM_VLEN_REGREF];
+ hsize_t vlen_regref_dim[RANK_VLEN_REGREF] = {DIM_VLEN_REGREF};
+
+
+ /* ---------------------------------------
+ * create objects which to be referenced
+ */
+ /* object1 group */
+ objgid = H5Gcreate2(loc_id, NAME_OBJ_GRP, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+
+ /* object2 dataset */
+ objsid = H5Screate_simple(RANK_OBJ, obj_dims, NULL);
+ objdid = H5Dcreate2(loc_id, NAME_OBJ_DS1, H5T_NATIVE_INT, objsid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ status = H5Dwrite(objdid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, obj_data[0]);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Dwrite failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /* object3 named datatype */
+ objtid = H5Tcopy(H5T_NATIVE_INT);
+ status = H5Tcommit2(loc_id, NAME_OBJ_NDTYPE, objtid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Tcommit2 failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+
+ /* ---------------------------------------------
+ * Put testing objs in this group
+ * create group contain dataset with attribute and the attribute has
+ * compound type which contain obj and region reference */
+ main_gid = H5Gcreate2(loc_id, "group_main", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ if (main_gid < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Gcreate2 failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /*----------------------------------------------------------
+ * create dataset which the attribute will be attached to
+ */
+ main_sid = H5Screate_simple(RANK_DSET, main_dset_dims, NULL);
+
+ main_did = H5Dcreate2(main_gid, "dset_main", H5T_NATIVE_INT, main_sid, H5P_DEFAULT,H5P_DEFAULT, H5P_DEFAULT);
+
+ status = H5Dwrite(main_did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, obj_data[0]);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Dwrite failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /*-------------------------------------------------------------------
+ * 1. create obj references in a attribute of compound type
+ */
+
+ /*
+ * create compound type for attribute
+ */
+ comp_objref_tid = H5Tcreate (H5T_COMPOUND, sizeof(comp_objref_t));
+
+ H5Tinsert(comp_objref_tid, "value_objref", HOFFSET(comp_objref_t, val_objref), H5T_STD_REF_OBJ);
+ H5Tinsert(comp_objref_tid, "value_int", HOFFSET(comp_objref_t, val_int), H5T_NATIVE_INT);
+
+ /*
+ * Create the object references into compound type
+ */
+ /* references to dataset */
+ status = H5Rcreate (&(comp_objref_data[0].val_objref), loc_id, NAME_OBJ_DS1, H5R_OBJECT,-1);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+ comp_objref_data[0].val_int = 0;
+
+ /* references to group */
+ status = H5Rcreate (&(comp_objref_data[1].val_objref), loc_id, NAME_OBJ_GRP, H5R_OBJECT,-1);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+ comp_objref_data[1].val_int = 10;
+
+ /* references to datatype */
+ status = H5Rcreate (&(comp_objref_data[2].val_objref), loc_id, NAME_OBJ_NDTYPE, H5R_OBJECT,-1);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+ comp_objref_data[2].val_int = 20;
+
+ /*
+ * create attribute and write the object ref
+ */
+ comp_objref_attr_sid = H5Screate_simple (RANK_COMP_OBJREF, comp_objref_dim, NULL);
+ comp_objref_aid = H5Acreate2 (main_did, "Comp_OBJREF", comp_objref_tid, comp_objref_attr_sid, H5P_DEFAULT, H5P_DEFAULT);
+ status = H5Awrite (comp_objref_aid, comp_objref_tid, comp_objref_data);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Awrite failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /*-------------------------------------------------------------------
+ * 2. create region references in attribute of compound type
+ */
+ /*
+ * create compound type for attribute
+ */
+ comp_regref_tid = H5Tcreate (H5T_COMPOUND, sizeof(comp_regref_t));
+
+ H5Tinsert(comp_regref_tid, "value_regref", HOFFSET(comp_regref_t, val_regref), H5T_STD_REF_DSETREG);
+ H5Tinsert(comp_regref_tid, "value_int", HOFFSET(comp_regref_t, val_int), H5T_NATIVE_INT);
+
+ /*
+ * create the region reference
+ */
+ status = H5Sselect_elements (objsid, H5S_SELECT_SET, (size_t)4, coords[0]);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Sselect_elements failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+ status = H5Rcreate (&(comp_regref_data[0].val_regref), loc_id, NAME_OBJ_DS1, H5R_DATASET_REGION, objsid);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+ comp_regref_data[0].val_int = 10;
+
+ /*
+ * create attribute and write the region ref
+ */
+ comp_regref_attr_sid = H5Screate_simple (RANK_COMP_REGREF, comp_regref_dim, NULL);
+ comp_regref_aid = H5Acreate2 (main_did, "Comp_REGREF", comp_regref_tid, comp_regref_attr_sid, H5P_DEFAULT, H5P_DEFAULT);
+ status = H5Awrite (comp_regref_aid, comp_regref_tid, comp_regref_data);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Awrite failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+
+ /*-------------------------------------------------------------------
+ * 3. create obj references in attribute of vlen type
+ */
+ /*
+ * prepare vlen data
+ */
+ vlen_objref_data[0].len = LEN0_VLEN_OBJREF;
+ vlen_objref_data[0].p = malloc (vlen_objref_data[0].len * sizeof(hobj_ref_t));
+ vlen_objref_data[1].len = LEN1_VLEN_OBJREF;
+ vlen_objref_data[1].p = malloc (vlen_objref_data[1].len * sizeof(hobj_ref_t));
+ vlen_objref_data[2].len = LEN2_VLEN_OBJREF;
+ vlen_objref_data[2].p = malloc (vlen_objref_data[2].len * sizeof(hobj_ref_t));
+
+ /*
+ * create obj references
+ */
+ /* reference to dataset */
+ status = H5Rcreate (&((hobj_ref_t*)vlen_objref_data[0].p)[0], loc_id, NAME_OBJ_DS1, H5R_OBJECT, -1);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+ /* reference to group */
+ status = H5Rcreate (&((hobj_ref_t*)vlen_objref_data[1].p)[0], loc_id, NAME_OBJ_GRP, H5R_OBJECT, -1);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+ /* reference to datatype */
+ status = H5Rcreate (&((hobj_ref_t*)vlen_objref_data[2].p)[0], loc_id, NAME_OBJ_NDTYPE, H5R_OBJECT, -1);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /*
+ * create vlen type with obj reference
+ */
+ vlen_objref_attr_tid = H5Tvlen_create (H5T_STD_REF_OBJ);
+ vlen_objref_attr_sid = H5Screate_simple (RANK_VLEN_OBJREF, vlen_objref_dims, NULL);
+
+ /*
+ * create attribute and write the object reference
+ */
+ vlen_objref_attr_id = H5Acreate2(main_did, "Vlen_OBJREF", vlen_objref_attr_tid, vlen_objref_attr_sid, H5P_DEFAULT, H5P_DEFAULT);
+ status = H5Awrite (vlen_objref_attr_id, vlen_objref_attr_tid, vlen_objref_data);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Awrite failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /* close resource for vlen data */
+ status = H5Dvlen_reclaim (vlen_objref_attr_tid, vlen_objref_attr_sid, H5P_DEFAULT, vlen_objref_data);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Dvlen_reclaim failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /*-------------------------------------------------------------------
+ * 4. create region references in a attribute of vlen type
+ */
+
+ /*
+ * prepare vlen data
+ */
+ vlen_regref_data[0].len = LEN0_VLEN_REGREF;
+ vlen_regref_data[0].p = malloc (vlen_regref_data[0].len * sizeof(hdset_reg_ref_t));
+
+ /*
+ * create region reference
+ */
+ status = H5Sselect_elements(objsid, H5S_SELECT_SET, (size_t)4, coords[0]);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Sselect_elements failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+ status = H5Rcreate (&((hdset_reg_ref_t*)vlen_regref_data[0].p)[0], loc_id, NAME_OBJ_DS1, H5R_DATASET_REGION, objsid);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Rcreate failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /*
+ * create vlen type with region reference
+ */
+ vlen_regref_attr_tid = H5Tvlen_create(H5T_STD_REF_DSETREG);
+ vlen_regref_attr_sid = H5Screate_simple(RANK_VLEN_REGREF, vlen_regref_dim, NULL);
+
+ /*
+ * create attribute and write the region reference
+ */
+ vlen_regref_attr_id = H5Acreate2(main_did, "Vlen_REGREF", vlen_regref_attr_tid, vlen_regref_attr_sid, H5P_DEFAULT, H5P_DEFAULT);
+ status = H5Awrite(vlen_regref_attr_id, vlen_regref_attr_tid, vlen_regref_data);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Awrite failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+ /* close resource for vlen data */
+ status = H5Dvlen_reclaim (vlen_regref_attr_tid, vlen_regref_attr_sid, H5P_DEFAULT, vlen_regref_data);
+ if (status < 0)
+ {
+ fprintf(stderr, "Error: %s %d> H5Dvlen_reclaim failed.\n", FUNC, __LINE__);
+ ret = FAIL;
+ goto out;
+ }
+
+out:
+ /* release resources */
+ if (objgid > 0)
+ H5Gclose(objgid);
+ if (objsid > 0)
+ H5Sclose(objsid);
+ if (objdid > 0)
+ H5Dclose(objdid);
+ if (objtid > 0)
+ H5Tclose(objtid);
+
+ if (main_gid > 0)
+ H5Gclose(main_gid);
+ if (main_sid > 0)
+ H5Sclose(main_sid);
+ if (main_did > 0)
+ H5Dclose(main_did);
+ /* comp obj ref */
+ if (comp_objref_tid > 0)
+ H5Tclose(comp_objref_tid);
+ if (comp_objref_aid > 0)
+ H5Aclose(comp_objref_aid);
+ if (comp_objref_attr_sid > 0)
+ H5Sclose(comp_objref_attr_sid);
+ /* comp region ref */
+ if (comp_regref_tid > 0)
+ H5Tclose(comp_regref_tid);
+ if (comp_regref_aid > 0)
+ H5Aclose(comp_regref_aid);
+ if (comp_regref_attr_sid > 0)
+ H5Sclose(comp_regref_attr_sid);
+ /* vlen obj ref */
+ if (vlen_objref_attr_id > 0)
+ H5Aclose(vlen_objref_attr_id);
+ if (vlen_objref_attr_sid > 0)
+ H5Sclose(vlen_objref_attr_sid);
+ if (vlen_objref_attr_tid > 0)
+ H5Tclose(vlen_objref_attr_tid);
+ /* vlen region ref */
+ if (vlen_regref_attr_id > 0)
+ H5Aclose(vlen_regref_attr_id);
+ if (vlen_regref_attr_sid > 0)
+ H5Sclose(vlen_regref_attr_sid);
+ if (vlen_regref_attr_tid > 0)
+ H5Tclose(vlen_regref_attr_tid);
+
+ return ret;
+}