summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2011-05-11 20:45:54 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2011-05-11 20:45:54 (GMT)
commitf49dc381271ac53a508628856787463668789772 (patch)
treed424cac8fb50120d9080086d54fd8d98a0977d03 /tools/lib/h5tools.c
parent2e7d42a43c60753d99d3bed37d121ca30ac5db1c (diff)
downloadhdf5-f49dc381271ac53a508628856787463668789772.zip
hdf5-f49dc381271ac53a508628856787463668789772.tar.gz
hdf5-f49dc381271ac53a508628856787463668789772.tar.bz2
[svn-r20796] Refactor print_data_region_blocks/ponts to remove context passed in by value. The print functions needed an independent context with only the current indent level passed in by argument. Also synched the two routines logical flows and corrected a mem_space error.
h5dump (and h5stat, h5jam/h5unjam) help option not tested. Added h5dump parse_command_line technique for h5stat and h5jam/unjam and created testfiles. Tested: local linux
Diffstat (limited to 'tools/lib/h5tools.c')
-rw-r--r--tools/lib/h5tools.c136
1 files changed, 83 insertions, 53 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index bb951a0..2ed13d0 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -226,7 +226,7 @@ hbool_t h5tools_render_region_element(FILE *stream, const h5tool_format_t *info,
hsize_t elmt_counter);
static int h5tools_print_region_data_blocks(hid_t region_id,
- FILE *stream, const h5tool_format_t *info, h5tools_context_t ctx,
+ FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx,
h5tools_str_t *buffer/*string into which to render */, size_t ncols,
int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata);
@@ -239,7 +239,7 @@ hbool_t h5tools_dump_region_data_points(hid_t region_space, hid_t region_id,
hsize_t elmt_counter);
int h5tools_print_region_data_points(hid_t region_space, hid_t region_id,
- FILE *stream, const h5tool_format_t *info, h5tools_context_t ctx,
+ FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx,
h5tools_str_t *buffer, size_t ncols,
int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata);
@@ -851,8 +851,7 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info,
}
/* Calculate new prefix */
- h5tools_str_region_prefix(&prefix, info, elmtno, ptdata, ctx->ndims,
- ctx->p_max_idx, ctx);
+ h5tools_str_region_prefix(&prefix, info, elmtno, ptdata, ctx->ndims, ctx->p_max_idx, ctx);
/* Write new prefix to output */
if (ctx->indent_level >= 0) {
@@ -1388,7 +1387,7 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info,
*/
static int
h5tools_print_region_data_blocks(hid_t region_id,
- FILE *stream, const h5tool_format_t *info, h5tools_context_t ctx,
+ FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx,
h5tools_str_t *buffer/*string into which to render */, size_t ncols,
int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata)
{
@@ -1401,15 +1400,22 @@ h5tools_print_region_data_blocks(hid_t region_id,
hsize_t elmtno; /* elemnt index */
unsigned int region_flags; /* buffer extent flags */
hsize_t curr_pos;
- int jndx;
- size_t indx;
+ size_t jndx;
+ int indx;
int type_size;
hid_t mem_space = -1;
void *region_buf = NULL;
- int blkndx;
+ hsize_t blkndx;
hid_t sid1 = -1;
int ret_value = SUCCEED;
+ h5tools_context_t ctx;
+ assert(info);
+ assert(cur_ctx);
+ assert(buffer);
+ assert(ptdata);
+
+ memset(&ctx, 0, sizeof(ctx));
/* Get the dataspace of the dataset */
if((sid1 = H5Dget_space(region_id)) < 0)
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed");
@@ -1444,13 +1450,16 @@ h5tools_print_region_data_blocks(hid_t region_id,
HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for count");
curr_pos = 0;
+ ctx.indent_level = cur_ctx->indent_level;
+ ctx.cur_column = cur_ctx->cur_column;
+ ctx.prev_multiline = cur_ctx->prev_multiline;
+ ctx.ndims = ndims;
for (blkndx = 0; blkndx < nblocks; blkndx++) {
- ctx.ndims = ndims;
ctx.need_prefix = TRUE;
ctx.cur_elmt = 0;
- for (jndx = 0; jndx < ndims; jndx++) {
- start[jndx] = ptdata[jndx + blkndx * ndims * 2];
- count[jndx] = dims1[jndx];
+ for (indx = 0; indx < ndims; indx++) {
+ start[indx] = ptdata[indx + blkndx * ndims * 2];
+ count[indx] = dims1[indx];
}
if(H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
@@ -1483,24 +1492,24 @@ h5tools_print_region_data_blocks(hid_t region_id,
h5tools_region_simple_prefix(stream, info, &ctx, curr_pos, ptdata, 0);
elmtno = 0;
- for (indx = 0; indx < numelem; indx++, elmtno++, ctx.cur_elmt++) {
+ for (jndx = 0; jndx < numelem; jndx++, elmtno++, ctx.cur_elmt++) {
/* Render the region data element begin */
h5tools_str_reset(buffer);
- h5tools_str_append(buffer, "%s", indx ? OPTIONAL_LINE_BREAK "" : "");
+ h5tools_str_append(buffer, "%s", jndx ? OPTIONAL_LINE_BREAK "" : "");
h5tools_str_sprint(buffer, info, region_id, type_id,
- ((char*)region_buf + indx * type_size), &ctx);
+ ((char*)region_buf + jndx * type_size), &ctx);
- if (indx + 1 < numelem || (region_flags & END_OF_DATA) == 0)
+ if (jndx + 1 < numelem || (region_flags & END_OF_DATA) == 0)
h5tools_str_append(buffer, "%s", OPT(info->elmt_suf1, ","));
dimension_break = h5tools_render_region_element(stream, info, &ctx, buffer, &curr_pos,
- ncols, ptdata, indx, elmtno);
+ ncols, ptdata, jndx, elmtno);
/* Render the region data element end */
if(FALSE == dimension_break)
elmtno = 0;
- } /* end for (indx = 0; indx < numelem; indx++, region_elmtno++, ctx.cur_elmt++) */
+ } /* end for (jndx = 0; jndx < numelem; jndx++, region_elmtno++, ctx.cur_elmt++) */
ctx.indent_level--;
} /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */
@@ -1561,6 +1570,10 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id,
hid_t type_id;
int i;
+ assert(info);
+ assert(ctx);
+ assert(buffer);
+
if((nblocks = H5Sget_select_hyper_nblocks(region_space)) <= 0)
H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_hyper_nblocks failed");
@@ -1673,7 +1686,7 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id,
ctx->need_prefix = TRUE;
- h5tools_print_region_data_blocks(region_id, rawdatastream, info, *ctx,
+ h5tools_print_region_data_blocks(region_id, rawdatastream, info, ctx,
buffer, ncols, ndims, type_id, nblocks, ptdata);
done:
@@ -1732,7 +1745,7 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id,
*/
int
h5tools_print_region_data_points(hid_t region_space, hid_t region_id,
- FILE *stream, const h5tool_format_t *info, h5tools_context_t ctx,
+ FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx,
h5tools_str_t *buffer, size_t ncols,
int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata)
{
@@ -1741,82 +1754,96 @@ h5tools_print_region_data_points(hid_t region_space, hid_t region_id,
hsize_t elmtno; /* elemnt index */
unsigned int region_flags; /* buffer extent flags */
hsize_t curr_pos;
- size_t indx;
- int jndx;
+ hsize_t total_size[H5S_MAX_RANK];
+ int indx;
+ size_t jndx;
int type_size;
hid_t mem_space = -1;
void *region_buf = NULL;
int ret_value = SUCCEED;
+ h5tools_context_t ctx;
- 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");
+ assert(info);
+ assert(cur_ctx);
+ assert(buffer);
+ assert(ptdata);
+ memset(&ctx, 0, sizeof(ctx));
/* 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;
+
+ /* Create dataspace for reading buffer */
if((mem_space = H5Screate_simple(1, 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 * npoints)) == NULL)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for region");
+
+ curr_pos = 0;
+ ctx.indent_level = cur_ctx->indent_level;
+ ctx.cur_column = cur_ctx->cur_column;
+ ctx.prev_multiline = cur_ctx->prev_multiline;
+ ctx.ndims = ndims;
+
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");
elmtno = 0;
- curr_pos = 0;
for (jndx = 0; jndx < npoints; jndx++, elmtno++) {
- ctx.ndims = ndims;
ctx.need_prefix = TRUE;
ctx.cur_elmt = 0; /* points are always 0 */
- /* Render the point element begin */
- h5tools_str_reset(buffer);
-
ctx.indent_level++;
+ 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");
/* assume entire data space to be printed */
for (indx = 0; indx < (size_t) ctx.ndims; indx++)
ctx.p_min_idx[indx] = 0;
- if(H5Sget_simple_extent_dims(region_space, ctx.p_max_idx, NULL) < 0)
- HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed");
-
- if (ctx.ndims > 0) {
- ctx.size_last_dim = (int) (ctx.p_max_idx[ctx.ndims - 1]);
- }
- else
- ctx.size_last_dim = 0;
-
- if (ctx.ndims > 0)
- init_acc_pos(&ctx, ctx.p_max_idx);
+ init_acc_pos(&ctx, total_size);
/* print the data */
region_flags = START_OF_DATA;
if (jndx == npoints - 1)
region_flags |= END_OF_DATA;
- curr_pos = 0; /* points requires constant 0 */
+ for (indx = 0; indx < (size_t)ctx.ndims; indx++)
+ ctx.p_max_idx[indx] = cur_ctx->p_max_idx[indx];
+
ctx.sm_pos = jndx * ndims;
+ if (ctx.ndims > 0) {
+ ctx.size_last_dim = (int) (ctx.p_max_idx[ctx.ndims - 1]);
+ }
+ else
+ ctx.size_last_dim = 0;
+ curr_pos = 0; /* points requires constant 0 */
h5tools_region_simple_prefix(stream, info, &ctx, curr_pos, ptdata, 0);
+ /* Render the point element begin */
+ h5tools_str_reset(buffer);
+
+ h5tools_str_append(buffer, "%s", jndx ? OPTIONAL_LINE_BREAK "" : "");
h5tools_str_sprint(buffer, info, region_id, type_id,
((char*)region_buf + jndx * type_size), &ctx);
if (jndx + 1 < npoints || (region_flags & END_OF_DATA) == 0)
h5tools_str_append(buffer, "%s", OPT(info->elmt_suf1, ","));
- dimension_break =
- h5tools_render_region_element(stream, info, &ctx, buffer, &curr_pos,
- ncols, ptdata, (hsize_t)0, elmtno);
+ dimension_break = h5tools_render_region_element(stream, info, &ctx, buffer, &curr_pos,
+ ncols, ptdata, (hsize_t)0, elmtno);
/* Render the point element end */
-
- ctx.indent_level--;
if(FALSE == dimension_break)
elmtno = 0;
- } /* end for (jndx = 0; jndx < npoints; jndx++, region_elmtno++) */
+
+ ctx.indent_level--;
+ } /* end for (jndx = 0; jndx < npoints; jndx++, elmtno++) */
done:
HDfree(region_buf);
@@ -1866,6 +1893,10 @@ h5tools_dump_region_data_points(hid_t region_space, hid_t region_id,
hid_t dtype;
hid_t type_id;
+ assert(info);
+ assert(ctx);
+ assert(buffer);
+
if((npoints = H5Sget_select_elem_npoints(region_space)) <= 0)
H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_elem_npoints failed");
@@ -1975,7 +2006,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,
- rawdatastream, info, *ctx, buffer, ncols, ndims, type_id, npoints, ptdata);
+ rawdatastream, info, ctx, buffer, ncols, ndims, type_id, npoints, ptdata);
done:
free(ptdata);
@@ -4233,8 +4264,7 @@ render_bin_output_region_data_points(hid_t region_space, hid_t region_id,
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));
+ render_bin_output(stream, container, type_id, ((char*)region_buf + jndx * type_size));
} /* end for (jndx = 0; jndx < npoints; jndx++) */
done: