summaryrefslogtreecommitdiffstats
path: root/tools/h5repack/testh5repack_dset.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/h5repack/testh5repack_dset.c')
-rw-r--r--tools/h5repack/testh5repack_dset.c222
1 files changed, 217 insertions, 5 deletions
diff --git a/tools/h5repack/testh5repack_dset.c b/tools/h5repack/testh5repack_dset.c
index 42ad644..d74c214 100644
--- a/tools/h5repack/testh5repack_dset.c
+++ b/tools/h5repack/testh5repack_dset.c
@@ -16,7 +16,8 @@
#include "h5test.h"
#include "h5repack.h"
-
+static void make_dset_reg_ref(hid_t loc_id);
+static void read_dset_reg_ref(hid_t loc_id);
/*-------------------------------------------------------------------------
@@ -232,14 +233,20 @@ void write_dset_in(hid_t loc_id,
* H5T_REFERENCE
*-------------------------------------------------------------------------
*/
- /* Create references to dataset */
+ /* object references ( H5R_OBJECT ) */
if (dset_name)
{
status=H5Rcreate(&buf4[0],file_id,dset_name,H5R_OBJECT,-1);
status=H5Rcreate(&buf4[1],file_id,dset_name,H5R_OBJECT,-1);
- write_dset(loc_id,1,dims,"reference",H5T_STD_REF_OBJ,buf4);
+ write_dset(loc_id,1,dims,"reference to object ",H5T_STD_REF_OBJ,buf4);
}
+ /* Dataset region reference ( H5R_DATASET_REGION ) */
+ make_dset_reg_ref(loc_id);
+#if defined(H5_REPACK_DEBUG)
+ read_dset_reg_ref(loc_id);
+#endif
+
/*-------------------------------------------------------------------------
* H5T_ENUM
*-------------------------------------------------------------------------
@@ -392,7 +399,7 @@ void write_dset_in(hid_t loc_id,
status=H5Rcreate(&buf42[i][j],file_id,dset_name,H5R_OBJECT,-1);
}
}
- write_dset(loc_id,2,dims2,"reference2D",H5T_STD_REF_OBJ,buf42);
+ write_dset(loc_id,2,dims2,"reference to object 2D",H5T_STD_REF_OBJ,buf42);
}
/*-------------------------------------------------------------------------
@@ -578,7 +585,7 @@ void write_dset_in(hid_t loc_id,
status=H5Rcreate(&buf43[i][j][k],file_id,dset_name,H5R_OBJECT,-1);
}
}
- write_dset(loc_id,3,dims3,"reference3D",H5T_STD_REF_OBJ,buf43);
+ write_dset(loc_id,3,dims3,"reference to object 3D",H5T_STD_REF_OBJ,buf43);
}
/*-------------------------------------------------------------------------
@@ -673,3 +680,208 @@ void write_dset_in(hid_t loc_id,
write_dset(loc_id,3,dims3,"float3D",H5T_NATIVE_FLOAT,buf83);
}
+
+
+/*-------------------------------------------------------------------------
+ * Function: make_dset_reg_ref
+ *
+ * Purpose: write dataset region references
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#define SPACE1_RANK 1
+#define SPACE1_DIM1 4
+#define SPACE2_RANK 2
+#define SPACE2_DIM1 10
+#define SPACE2_DIM2 10
+#define NPOINTS 10
+
+static void make_dset_reg_ref(hid_t loc_id)
+{
+ hid_t dset1; /* Dataset ID */
+ hid_t dset2; /* Dereferenced dataset ID */
+ hid_t sid1; /* Dataspace ID #1 */
+ hid_t sid2; /* Dataspace ID #2 */
+ hsize_t dims1[] = {SPACE1_DIM1};
+ hsize_t dims2[] = {SPACE2_DIM1, SPACE2_DIM2};
+ hssize_t start[SPACE2_RANK]; /* Starting location of hyperslab */
+ hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */
+ hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */
+ hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */
+ hssize_t coord1[NPOINTS][SPACE2_RANK]; /* Coordinates for point selection */
+ hdset_reg_ref_t *wbuf; /* buffer to write to disk */
+ int *dwbuf; /* Buffer for writing numeric data to disk */
+ int i; /* counting variables */
+ herr_t ret; /* Generic return value */
+
+ /* Allocate write & read buffers */
+ wbuf=calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1);
+ dwbuf=malloc(sizeof(int)*SPACE2_DIM1*SPACE2_DIM2);
+
+ /* Create dataspace for datasets */
+ sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL);
+
+ /* Create a dataset */
+ dset2=H5Dcreate(loc_id,"dset referenced region",H5T_STD_U8LE,sid2,H5P_DEFAULT);
+
+ for(i=0; i<SPACE2_DIM1*SPACE2_DIM2; i++)
+ dwbuf[i]=i*3;
+
+ /* Write selection to disk */
+ ret=H5Dwrite(dset2,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,dwbuf);
+
+ /* Close Dataset */
+ ret = H5Dclose(dset2);
+
+ /* Create dataspace for the reference dataset */
+ sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
+
+ /* Create a dataset */
+ dset1=H5Dcreate(loc_id,"region reference",H5T_STD_REF_DSETREG,sid1,H5P_DEFAULT);
+
+ /* Create references */
+
+ /* Select 6x6 hyperslab for first reference */
+ start[0]=2; start[1]=2;
+ stride[0]=1; stride[1]=1;
+ count[0]=6; count[1]=6;
+ block[0]=1; block[1]=1;
+ ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block);
+
+ /* Store first dataset region */
+ ret = H5Rcreate(&wbuf[0],loc_id,"dset referenced region",H5R_DATASET_REGION,sid2);
+
+ /* Select sequence of ten points for second reference */
+ coord1[0][0]=6; coord1[0][1]=9;
+ coord1[1][0]=2; coord1[1][1]=2;
+ coord1[2][0]=8; coord1[2][1]=4;
+ coord1[3][0]=1; coord1[3][1]=6;
+ coord1[4][0]=2; coord1[4][1]=8;
+ coord1[5][0]=3; coord1[5][1]=2;
+ coord1[6][0]=0; coord1[6][1]=4;
+ coord1[7][0]=9; coord1[7][1]=0;
+ coord1[8][0]=7; coord1[8][1]=1;
+ coord1[9][0]=3; coord1[9][1]=3;
+ ret = H5Sselect_elements(sid2,H5S_SELECT_SET,NPOINTS,(const hssize_t **)coord1);
+
+ /* Store second dataset region */
+ ret = H5Rcreate(&wbuf[1],loc_id,"dset referenced region",H5R_DATASET_REGION,sid2);
+
+ /* Write selection to disk */
+ ret=H5Dwrite(dset1,H5T_STD_REF_DSETREG,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
+
+ /* Close all objects */
+ ret = H5Sclose(sid1);
+ ret = H5Dclose(dset1);
+ ret = H5Sclose(sid2);
+
+ free(wbuf);
+ free(dwbuf);
+}
+
+/*-------------------------------------------------------------------------
+ * Function: read_dset_reg_ref
+ *
+ * Purpose: read dataset region references
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static void read_dset_reg_ref(hid_t loc_id)
+{
+ hid_t dset1; /* Dataset ID */
+ hid_t dset2; /* Dereferenced dataset ID */
+ hid_t sid1; /* Dataspace ID #1 */
+ hid_t sid2; /* Dataspace ID #2 */
+ hsize_t *coords; /* Coordinate buffer */
+ hssize_t low[SPACE2_RANK]; /* Selection bounds */
+ hssize_t high[SPACE2_RANK]; /* Selection bounds */
+ hdset_reg_ref_t *rbuf; /* buffer to read from disk */
+ int *drbuf; /* Buffer for reading numeric data from disk */
+ int i, j; /* counting variables */
+ herr_t ret; /* Generic return value */
+
+ /* Allocate write & read buffers */
+ rbuf=malloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1);
+ drbuf=calloc(sizeof(int),SPACE2_DIM1*SPACE2_DIM2);
+
+ /* Open the dataset */
+ dset1=H5Dopen(loc_id,"region reference");
+
+ /* Read selection from disk */
+ ret=H5Dread(dset1,H5T_STD_REF_DSETREG,H5S_ALL,H5S_ALL,H5P_DEFAULT,rbuf);
+
+ /* Try to open objects */
+ dset2 = H5Rdereference(dset1,H5R_DATASET_REGION,&rbuf[0]);
+
+ /* Check information in referenced dataset */
+ sid1 = H5Dget_space(dset2);
+
+ ret=(herr_t)H5Sget_simple_extent_npoints(sid1);
+ printf(" Number of elements in the dataset is : %d\n",ret);
+
+ /* Read from disk */
+ ret=H5Dread(dset2,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,drbuf);
+
+ for(i=0; i<SPACE2_DIM1; i++) {
+ for (j=0; j<SPACE2_DIM2; j++) printf (" %d ", drbuf[i*SPACE2_DIM2+j]);
+ printf("\n"); }
+
+ /* Get the hyperslab selection */
+ sid2=H5Rget_region(dset1,H5R_DATASET_REGION,&rbuf[0]);
+
+ /* Verify correct hyperslab selected */
+ ret = (herr_t)H5Sget_select_npoints(sid2);
+ printf(" Number of elements in the hyperslab is : %d \n", ret);
+ ret = (herr_t)H5Sget_select_hyper_nblocks(sid2);
+ /* allocate space for the hyperslab blocks */
+ coords=malloc((size_t)ret*SPACE2_RANK*sizeof(hsize_t)*2);
+ ret = H5Sget_select_hyper_blocklist(sid2,0,ret,coords);
+ printf(" Hyperslab coordinates are : \n");
+ printf (" ( %lu , %lu ) ( %lu , %lu ) \n",
+ (unsigned long)coords[0],
+ (unsigned long)coords[1],
+ (unsigned long)coords[2],
+ (unsigned long)coords[3]);
+ free(coords);
+ ret = H5Sget_select_bounds(sid2,low,high);
+
+ /* Close region space */
+ ret = H5Sclose(sid2);
+
+ /* Get the element selection */
+ sid2=H5Rget_region(dset1,H5R_DATASET_REGION,&rbuf[1]);
+
+ /* Verify correct elements selected */
+ ret = (herr_t)H5Sget_select_elem_npoints(sid2);
+ printf(" Number of selected elements is : %d\n", ret);
+
+ /* Allocate space for the element points */
+ coords= malloc(ret*SPACE2_RANK*sizeof(hsize_t));
+ ret = H5Sget_select_elem_pointlist(sid2,0,ret,coords);
+ printf(" Coordinates of selected elements are : \n");
+ for (i=0; i<2*NPOINTS; i=i+2)
+ printf(" ( %lu , %lu ) \n",
+ (unsigned long)coords[i],
+ (unsigned long)coords[i+1]);
+
+ free(coords);
+ ret = H5Sget_select_bounds(sid2,low,high);
+
+ /* Close region space */
+ ret = H5Sclose(sid2);
+
+ /* Close first space */
+ ret = H5Sclose(sid1);
+
+ /* Close dereferenced Dataset */
+ ret = H5Dclose(dset2);
+
+ /* Close Dataset */
+ ret = H5Dclose(dset1);
+
+ /* Free memory buffers */
+ free(rbuf);
+ free(drbuf);
+}