summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2010-08-09 17:15:06 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2010-08-09 17:15:06 (GMT)
commit02b5824f57c778aa91f4d78f72a615f2e62a3783 (patch)
tree3326933f473ae2c20a3e6b7c12cebd894877e3fc /tools/lib/h5tools.c
parenta586c760ee217c619fc97f0498c57506fb360a3e (diff)
downloadhdf5-02b5824f57c778aa91f4d78f72a615f2e62a3783.zip
hdf5-02b5824f57c778aa91f4d78f72a615f2e62a3783.tar.gz
hdf5-02b5824f57c778aa91f4d78f72a615f2e62a3783.tar.bz2
[svn-r19198] [BZ1953]implementation for the proposed changes suggested by the "h5dump_output_option" RFC. This required that the region reference code be duplicated and reduced to allow the do_bin_output() function to understand region references. The container type-id also needed to be propagated into the do_bin_output() function and functions referenced (render_bin_output*).
Existing tests tested the binary function, so only one test was added to test the region reference generated file. Tested: local linux
Diffstat (limited to 'tools/lib/h5tools.c')
-rw-r--r--tools/lib/h5tools.c351
1 files changed, 337 insertions, 14 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index e8657e1..f29d6bf 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -202,8 +202,12 @@ BLOCK, /*blockbegin */
static const h5tools_dump_header_t * h5tools_dump_header_format;
/* local prototypes */
-static int do_bin_output(FILE *stream, hsize_t nelmts, hid_t tid, void *_mem);
-static int render_bin_output(FILE *stream, hid_t tid, void *_mem);
+static int do_bin_output(FILE *stream, hid_t container, hsize_t nelmts, hid_t tid, void *_mem);
+static int render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem);
+static hbool_t render_bin_output_region_blocks(hid_t region_space, hid_t region_id,
+ FILE *stream, hid_t container, hid_t tid, void *_mem);
+static hbool_t render_bin_output_region_points(hid_t region_space, hid_t region_id,
+ FILE *stream, hid_t container, hid_t tid, void *_mem);
static hbool_t h5tools_is_zero(const void *_mem, size_t size);
hbool_t h5tools_render_element(FILE *stream, const h5tool_format_t *info,
@@ -871,7 +875,7 @@ h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t contai
/* binary dump */
if (bin_output) {
- do_bin_output(stream, nelmts, type, _mem);
+ do_bin_output(rawdatastream, container, nelmts, type, _mem);
} /* end if */
else {
/* setup */
@@ -952,7 +956,7 @@ h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t contai
if (i + 1 < nelmts || (flags & END_OF_DATA) == 0)
h5tools_str_append(&buffer, "%s", OPT(info->elmt_suf1, ","));
- dimension_break = h5tools_render_element(stream, info, ctx, &buffer,
+ dimension_break = h5tools_render_element(rawdatastream, info, ctx, &buffer,
&curr_pos, ncols, i, elmt_counter);
/* Render the data element end*/
@@ -1581,7 +1585,7 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id,
ctx->need_prefix = TRUE;
h5tools_print_region_data_blocks(region_space, region_id,
- stream, info, *ctx, buffer, ncols, ndims, type_id, nblocks, ptdata);
+ rawdatastream, info, *ctx, buffer, ncols, ndims, type_id, nblocks, ptdata);
done:
free(ptdata);
@@ -1883,7 +1887,7 @@ h5tools_dump_region_data_points(hid_t region_space, hid_t region_id,
ctx->need_prefix = TRUE;
h5tools_print_region_data_points(region_space, region_id,
- stream, info, *ctx, buffer, ncols, ndims, type_id, npoints, ptdata);
+ rawdatastream, info, *ctx, buffer, ncols, ndims, type_id, npoints, ptdata);
done:
free(ptdata);
@@ -2663,10 +2667,10 @@ h5tools_dump_dset(FILE *stream, const h5tool_format_t *info, hid_t dset,
/* Print the data */
if (space_type == H5S_SIMPLE || space_type == H5S_SCALAR) {
if (!sset) {
- status = h5tools_dump_simple_dset(rawdatastream, info, dset, p_type, indentlevel);
+ status = h5tools_dump_simple_dset(stream, info, dset, p_type, indentlevel);
}
else {
- status = h5tools_dump_simple_subset(rawdatastream, info, dset, p_type, sset, indentlevel);
+ status = h5tools_dump_simple_subset(stream, info, dset, p_type, sset, indentlevel);
}
}
else
@@ -3501,7 +3505,7 @@ init_acc_pos(h5tools_context_t *ctx, hsize_t *dims)
*-------------------------------------------------------------------------
*/
static
-int do_bin_output(FILE *stream, hsize_t nelmts, hid_t tid, void *_mem)
+int do_bin_output(FILE *stream, hid_t container, hsize_t nelmts, hid_t tid, void *_mem)
{
HERR_INIT(int, SUCCEED)
unsigned char *mem = (unsigned char*)_mem;
@@ -3512,7 +3516,7 @@ int do_bin_output(FILE *stream, hsize_t nelmts, hid_t tid, void *_mem)
H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size failed");
for (i = 0; i < nelmts; i++) {
- if (render_bin_output(stream, tid, mem + i * size) < 0) {
+ if (render_bin_output(stream, container, tid, mem + i * size) < 0) {
printf("\nError in writing binary stream\n");
return FAIL;
}
@@ -3532,7 +3536,7 @@ CATCH
*-------------------------------------------------------------------------
*/
static int
-render_bin_output(FILE *stream, hid_t tid, void *_mem)
+render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem)
{
HERR_INIT(int, SUCCEED)
unsigned char *mem = (unsigned char*)_mem;
@@ -3779,7 +3783,7 @@ render_bin_output(FILE *stream, hid_t tid, void *_mem)
offset = H5Tget_member_offset(tid, j);
memb = H5Tget_member_type(tid, j);
- if (render_bin_output(stream, memb, mem + offset) < 0)
+ if (render_bin_output(stream, container, memb, mem + offset) < 0)
return FAIL;
H5Tclose(memb);
@@ -3827,7 +3831,7 @@ render_bin_output(FILE *stream, hid_t tid, void *_mem)
/* dump the array element */
for (i = 0; i < nelmts; i++) {
- if (render_bin_output(stream, memb, mem + i * size) < 0)
+ if (render_bin_output(stream, container, memb, mem + i * size) < 0)
H5E_THROW(FAIL, H5E_tools_min_id_g, "render_bin_output failed");
}
@@ -3847,11 +3851,34 @@ render_bin_output(FILE *stream, hid_t tid, void *_mem)
for (i = 0; i < nelmts; i++) {
/* dump the array element */
- if (render_bin_output(stream, memb, ((char *) (((hvl_t *) mem)->p)) + i * size) < 0)
+ if (render_bin_output(stream, container, memb, ((char *) (((hvl_t *) mem)->p)) + i * size) < 0)
H5E_THROW(FAIL, H5E_tools_min_id_g, "render_bin_output failed");
}
H5Tclose(memb);
}
+ else if (H5Tequal(tid, H5T_STD_REF_DSETREG)) {
+ if (region_output) {
+ /* region data */
+ hid_t region_id, region_space;
+ H5S_sel_type region_type;
+
+ region_id = H5Rdereference(container, H5R_DATASET_REGION, mem);
+ if (region_id >= 0) {
+ region_space = H5Rget_region(container, H5R_DATASET_REGION, mem);
+ if (region_space >= 0) {
+ region_type = H5Sget_select_type(region_space);
+ if(region_type==H5S_SEL_POINTS)
+ render_bin_output_region_points(region_space, region_id, stream, container, tid, mem);
+ else
+ render_bin_output_region_blocks(region_space, region_id, stream, container, tid, mem);
+ H5Sclose(region_space);
+ } /* end if (region_space >= 0) */
+ H5Dclose(region_id);
+ } /* end if (region_id >= 0) */
+ } /* end if (region_output... */
+ }
+ else if (H5Tequal(tid, H5T_STD_REF_OBJ)) {
+ }
else {
size_t i;
if (1 == size) {
@@ -3879,6 +3906,302 @@ CATCH
}
/*-------------------------------------------------------------------------
+ * Audience: Public
+ * Chapter: H5Tools Library
+ * Purpose: Print the data values from a dataset referenced by region blocks.
+ *
+ * Description:
+ * This is a special case subfunction to print the data in a region reference of type blocks.
+ *
+ * Return:
+ * The function returns FAIL if there was an error, otherwise SUCEED
+ *
+ *-------------------------------------------------------------------------
+ */
+int
+render_bin_output_region_data_blocks(hid_t region_space, hid_t region_id,
+ FILE *stream, hid_t container,
+ int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata) {
+ HERR_INIT(int, SUCCEED)
+ hsize_t *dims1 = NULL;
+ hsize_t *start = NULL;
+ hsize_t *count = NULL;
+ size_t numelem;
+ hsize_t total_size[H5S_MAX_RANK];
+ unsigned int region_flags; /* buffer extent flags */
+ int jndx;
+ int type_size;
+ hid_t mem_space = -1;
+ void *region_buf = NULL;
+ int blkndx;
+ hid_t sid1 = -1;
+
+ /* Get the dataspace of the dataset */
+ if((sid1 = H5Dget_space(region_id)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed");
+
+ /* Allocate space for the dimension array */
+ if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for dims");
+
+ /* find the dimensions of each data space from the block coordinates */
+ numelem = 1;
+ for (jndx = 0; jndx < ndims; jndx++) {
+ dims1[jndx] = ptdata[jndx + ndims] - ptdata[jndx] + 1;
+ numelem = dims1[jndx] * numelem;
+ }
+
+ /* Create dataspace for reading buffer */
+ if((mem_space = H5Screate_simple(ndims, dims1, NULL)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed");
+
+ if((type_size = H5Tget_size(type_id)) == 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed");
+
+ if((region_buf = HDmalloc(type_size * numelem)) == NULL)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate region buffer");
+
+ /* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reading memory dataset */
+ /* 1 2 n 1 2 n */
+ if((start = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for start");
+
+ if((count = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for count");
+
+ for (blkndx = 0; blkndx < nblocks; blkndx++) {
+ for (jndx = 0; jndx < ndims; jndx++) {
+ start[jndx] = ptdata[jndx + blkndx * ndims * 2];
+ count[jndx] = dims1[jndx];
+ }
+
+ if(H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sselect_hyperslab failed");
+
+ if(H5Dread(region_id, type_id, mem_space, sid1, H5P_DEFAULT, region_buf) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dread failed");
+
+ if(H5Sget_simple_extent_dims(mem_space, total_size, NULL) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed");
+
+ for (jndx = 0; jndx < numelem; jndx++) {
+
+ render_bin_output(stream, container, type_id,
+ ((char*)region_buf + jndx * type_size));
+ /* Render the region data element end */
+ } /* end for (jndx = 0; jndx < numelem; jndx++) */
+ } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */
+
+ done:
+ HDfree(start);
+ HDfree(count);
+ HDfree(region_buf);
+ HDfree(dims1);
+
+ if(H5Sclose(mem_space) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed");
+ if(H5Sclose(sid1) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed");
+
+CATCH
+ return ret_value;
+}
+
+/*-------------------------------------------------------------------------
+ * Audience: Public
+ * Chapter: H5Tools Library
+ * Purpose: Print some values from a dataset referenced by region blocks.
+ *
+ * Description:
+ * This is a special case subfunction to dump a region reference using blocks.
+ *
+ * Return:
+ * The function returns False if ERROR, otherwise True
+ *
+ *-------------------------------------------------------------------------
+ */
+hbool_t
+render_bin_output_region_blocks(hid_t region_space, hid_t region_id,
+ FILE *stream, hid_t container, hid_t tid, void *_mem) {
+ HERR_INIT(hbool_t, TRUE)
+ hssize_t nblocks;
+ hsize_t alloc_size;
+ hsize_t *ptdata = NULL;
+ int ndims;
+ hid_t dtype;
+ hid_t type_id;
+ int i;
+
+ if((nblocks = H5Sget_select_hyper_nblocks(region_space)) <= 0)
+ H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_select_hyper_nblocks failed");
+
+ /* Print block information */
+ if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0)
+ H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed");
+
+ alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]);
+ assert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/
+ if((ptdata = (hsize_t*) malloc((size_t) alloc_size)) == NULL)
+ HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "Could not allocate buffer for ptdata");
+
+ H5_CHECK_OVERFLOW(nblocks, hssize_t, hsize_t);
+ if(H5Sget_select_hyper_blocklist(region_space, (hsize_t) 0, (hsize_t) nblocks, ptdata) < 0)
+ HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Rget_select_hyper_blocklist failed");
+
+ if((dtype = H5Dget_type(region_id)) < 0)
+ HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Dget_type failed");
+ if((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0)
+ HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Tget_native_type failed");
+
+ render_bin_output_region_data_blocks(region_space, region_id,
+ stream, container, ndims, type_id, nblocks, ptdata);
+
+ done:
+ free(ptdata);
+
+ if(H5Tclose(type_id) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed");
+
+ if(H5Tclose(dtype) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed");
+
+ H5_LEAVE(TRUE)
+
+ CATCH
+ return ret_value;
+}
+
+/*-------------------------------------------------------------------------
+ * Audience: Public
+ * Chapter: H5Tools Library
+ * Purpose: Print the data values from a dataset referenced by region points.
+ *
+ * Description:
+ * This is a special case subfunction to print the data in a region reference of type points.
+ *
+ * Return:
+ * The function returns FAIL on error, otherwise SUCCEED
+ *
+ * Parameters Description:
+ * h5tools_str_t *buffer is the string into which to render
+ * size_t ncols
+ * int ndims is the number of dimensions of the region element
+ * hssize_t npoints is the number of points in the region
+ *-------------------------------------------------------------------------
+ */
+int
+render_bin_output_region_data_points(hid_t region_space, hid_t region_id,
+ FILE *stream, hid_t container,
+ int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata) {
+ HERR_INIT(int, SUCCEED)
+ hsize_t alloc_size;
+ hsize_t *dims1 = NULL;
+ unsigned int region_flags; /* buffer extent flags */
+ int indx;
+ int jndx;
+ int type_size;
+ hid_t mem_space = -1;
+ void *region_buf = NULL;
+
+ if((type_size = H5Tget_size(type_id)) == 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed");
+
+ if((region_buf = HDmalloc(type_size * npoints)) == NULL)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for region");
+
+ /* Allocate space for the dimension array */
+ if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for dims");
+
+ dims1[0] = npoints;
+ if((mem_space = H5Screate_simple(1, dims1, NULL)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed");
+
+ if(H5Dread(region_id, type_id, mem_space, region_space, H5P_DEFAULT, region_buf) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed");
+ for (jndx = 0; jndx < npoints; jndx++) {
+ if(H5Sget_simple_extent_dims(region_space, dims1, NULL) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed");
+
+ render_bin_output(stream, container, type_id,
+ ((char*)region_buf + jndx * type_size));
+ } /* end for (jndx = 0; jndx < npoints; jndx++) */
+
+ done:
+ HDfree(region_buf);
+ HDfree(dims1);
+
+ if(H5Sclose(mem_space) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed");
+CATCH
+ return ret_value;
+}
+
+/*-------------------------------------------------------------------------
+ * Audience: Public
+ * Chapter: H5Tools Library
+ * Purpose: Print some values from a dataset referenced by region points.
+ *
+ * Description:
+ * This is a special case subfunction to dump a region reference using points.
+ *
+ * Return:
+ * The function returns False if the last dimension has been reached, otherwise True
+ *
+ *-------------------------------------------------------------------------
+ */
+hbool_t
+render_bin_output_region_points(hid_t region_space, hid_t region_id,
+ FILE *stream, hid_t container, hid_t tid, void *_mem) {
+ HERR_INIT(hbool_t, TRUE)
+ hssize_t npoints;
+ hsize_t alloc_size;
+ hsize_t *ptdata;
+ int ndims;
+ int indx;
+ hid_t dtype;
+ hid_t type_id;
+
+ if((npoints = H5Sget_select_elem_npoints(region_space)) <= 0)
+ H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_select_elem_npoints failed");
+
+ /* Allocate space for the dimension array */
+ if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0)
+ H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed");
+
+ alloc_size = npoints * ndims * sizeof(ptdata[0]);
+ assert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/
+ if((ptdata = malloc((size_t) alloc_size)) == NULL)
+ HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "Could not allocate buffer for ptdata");
+
+ H5_CHECK_OVERFLOW(npoints, hssize_t, hsize_t);
+ if(H5Sget_select_elem_pointlist(region_space, (hsize_t) 0, (hsize_t) npoints, ptdata) < 0)
+ HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Sget_select_elem_pointlist failed");
+
+ if((dtype = H5Dget_type(region_id)) < 0)
+ HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Dget_type failed");
+
+ if((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0)
+ HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Tget_native_type failed");
+
+ render_bin_output_region_data_points(region_space, region_id,
+ stream, container, ndims, type_id, npoints, ptdata);
+
+ done:
+ free(ptdata);
+
+ if(H5Tclose(type_id) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed");
+
+ if(H5Tclose(dtype) < 0)
+ HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed");
+
+ H5_LEAVE(ret_value)
+CATCH
+ return ret_value;
+}
+
+/*-------------------------------------------------------------------------
* Function: h5tools_is_zero
*
* Purpose: Determines if memory is initialized to all zero bytes.