summaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2011-05-12 17:23:43 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2011-05-12 17:23:43 (GMT)
commita56750c9b597a737de208d9dba0133cafe0a0a68 (patch)
treec1c679fd82c811693d0452f2178600729c9551c0 /tools/lib
parent83703a978470d7e25a1b3ea17b2b03a8615a60e9 (diff)
downloadhdf5-a56750c9b597a737de208d9dba0133cafe0a0a68.zip
hdf5-a56750c9b597a737de208d9dba0133cafe0a0a68.tar.gz
hdf5-a56750c9b597a737de208d9dba0133cafe0a0a68.tar.bz2
[svn-r20802] Bring trunk revision 20798 to 1.8. Trunk changes passed overnight.
Tested: local linux
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/h5tools.c136
-rw-r--r--tools/lib/h5tools_str.c8
2 files changed, 89 insertions, 55 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:
diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c
index 9b7e8f2..54e2584 100644
--- a/tools/lib/h5tools_str.c
+++ b/tools/lib/h5tools_str.c
@@ -390,8 +390,12 @@ h5tools_str_region_prefix(h5tools_str_t *str, const h5tool_format_t *info,
p_prod[i - 1] = (max_idx[i]) * p_prod[i];
for (i = 0; i < (size_t) ndims; i++) {
- ctx->pos[i] = curr_pos / p_prod[i];
- curr_pos -= p_prod[i] * ctx->pos[i];
+ if(curr_pos > 0) {
+ ctx->pos[i] = curr_pos / p_prod[i];
+ curr_pos -= p_prod[i] * ctx->pos[i];
+ }
+ else
+ ctx->pos[i] = 0;
ctx->pos[i] += (unsigned long) ptdata[ctx->sm_pos+i];
}