diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2011-05-09 20:06:43 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2011-05-09 20:06:43 (GMT) |
commit | 040d210f5c5f3f5f46daae8c86c155941c89f58e (patch) | |
tree | 869119da5335613c3d6b521471dfa0e8caa91996 /tools/lib | |
parent | bcde54c0031d29a56bea731303e0bd10d37b8bd7 (diff) | |
download | hdf5-040d210f5c5f3f5f46daae8c86c155941c89f58e.zip hdf5-040d210f5c5f3f5f46daae8c86c155941c89f58e.tar.gz hdf5-040d210f5c5f3f5f46daae8c86c155941c89f58e.tar.bz2 |
[svn-r20777] 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.
Tested: local linux
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/h5tools.c | 98 |
1 files changed, 54 insertions, 44 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index bb951a0..99bd683 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, int cur_indent_level, 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, int cur_indent_level, h5tools_str_t *buffer, size_t ncols, int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata); @@ -1388,7 +1388,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, int cur_indent_level, h5tools_str_t *buffer/*string into which to render */, size_t ncols, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata) { @@ -1409,6 +1409,7 @@ h5tools_print_region_data_blocks(hid_t region_id, int blkndx; hid_t sid1 = -1; int ret_value = SUCCEED; + h5tools_context_t ctx; /* Get the dataspace of the dataset */ if((sid1 = H5Dget_space(region_id)) < 0) @@ -1444,13 +1445,14 @@ 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_indent_level; + 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,19 +1485,19 @@ 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) @@ -1673,7 +1675,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->indent_level, buffer, ncols, ndims, type_id, nblocks, ptdata); done: @@ -1732,91 +1734,99 @@ 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, int cur_indent_level, h5tools_str_t *buffer, size_t ncols, int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata) { hbool_t dimension_break = TRUE; hsize_t *dims1 = NULL; + size_t numelem; hsize_t elmtno; /* elemnt index */ unsigned int region_flags; /* buffer extent flags */ hsize_t curr_pos; + hsize_t total_size[H5S_MAX_RANK]; size_t indx; int jndx; int type_size; hid_t mem_space = -1; void *region_buf = NULL; int ret_value = SUCCEED; - - 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"); + h5tools_context_t 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; + numelem = 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 * numelem)) == NULL) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for region"); + + curr_pos = 0; + ctx.indent_level = cur_indent_level; + 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; + for (indx = 0; indx < (size_t)ctx.ndims; indx++) + ctx.p_max_idx[indx] = dims1[indx]; + curr_pos = 0; /* points requires constant 0 */ 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; 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) + 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, (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); @@ -1975,7 +1985,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->indent_level, buffer, ncols, ndims, type_id, npoints, ptdata); done: free(ptdata); |