summaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2007-01-10 19:15:16 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2007-01-10 19:15:16 (GMT)
commitba14f838467f787fd4d42185a7e65fc529f84af8 (patch)
tree126171e83360b5c261472e66125551edfa1177d7 /tools/lib
parent56407cde0eb97b44d2e2fccf1c67ea585811f7f1 (diff)
downloadhdf5-ba14f838467f787fd4d42185a7e65fc529f84af8.zip
hdf5-ba14f838467f787fd4d42185a7e65fc529f84af8.tar.gz
hdf5-ba14f838467f787fd4d42185a7e65fc529f84af8.tar.bz2
[svn-r13134]
New version of the function h5tools_dump_simple_subset, to display subsetting. The new algorithm is: Introduced an outer loop for cases where dimensionality is greater than 2D. In each iteration a 2D block is displayed by rows in a inner loop. The remainning slower dimensions above the first 2 are incremented one at a time in the outer loop Note: when blocks are introduced, the display is not correct. This is a bug that requires an improvement of the algorithm.
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/h5tools.c268
1 files changed, 172 insertions, 96 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index 804f83a..8d6180f 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -697,6 +697,7 @@ h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t contai
}
+
/*-------------------------------------------------------------------------
* Audience: Public
* Chapter: H5Tools Library
@@ -710,13 +711,20 @@ h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t contai
* Bill Wendling, Wednesday, 07. March 2001
* Modifications:
* Pedro Vicente, 12 December 2006
- * Add information to print array indices from the element position
- * The algorythm used is
- * Given an index I(z,y,x) its position from the beginning of an array
- * of sizes A(size_z, size_y,size_x) is given by
- * Position of I(z,y,x) = index_z * size_y * size_x
+ * Add information to print array indices from the element position
+ * The algorythm used is
+ * Given an index I(z,y,x) its position from the beginning of an array
+ * of sizes A(size_z, size_y,size_x) is given by
+ * Position of I(z,y,x) = index_z * size_y * size_x
* + index_y * size_x
* + index_x
+ *
+ * Pedro Vicente, Quincey Koziol, 4 January 2007
+ * Introduced an outer loop for cases where dimensionality is greater
+ * than 2D. In each iteration a 2D block is displayed by rows in a inner
+ * loop. The remainning slower dimensions above the first 2 are incremented
+ * one at a time in the outer loop
+ *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -726,7 +734,7 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset
{
herr_t ret; /* the value to return */
hid_t f_space; /* file data space */
- hsize_t i, j; /* counters */
+ hsize_t i, j, n; /* counters */
hsize_t zero = 0; /* vector of zeros */
unsigned int flags; /* buffer extent flags */
hsize_t total_size[H5S_MAX_RANK];/* total size of dataset*/
@@ -741,6 +749,14 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset
unsigned char *sm_buf = NULL; /* buffer for raw data */
hid_t sm_space; /* stripmine data space */
hsize_t count; /* hyperslab count */
+ hsize_t outer_count; /* offset count */
+ unsigned int row_dim; /* index of row dimension */
+ int current_outer_dim; /* dimension for start */
+ hsize_t temp_start[H5S_MAX_RANK];/* temporary start inside offset count loop */
+ hsize_t max_start[H5S_MAX_RANK]; /* maximum start inside offset count loop */
+ hsize_t temp_count[H5S_MAX_RANK];/* temporary count inside offset count loop */
+
+ int reset_dim;
ret = FAIL; /* be pessimistic */
f_space = H5Dget_space(dset);
@@ -769,109 +785,167 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset
H5Sget_simple_extent_dims(f_space, total_size, NULL);
ctx.size_last_dim = total_size[ctx.ndims - 1];
- count = sset->count[ctx.ndims - 1];
- sset->count[ctx.ndims - 1] = 1;
+ if (ctx.ndims == 1)
+ row_dim = 0;
+ else
+ row_dim = ctx.ndims - 2;
+
+ /* get the offset count */
+ outer_count = 1;
+ if (ctx.ndims > 2)
+ for (i = 0; i < ctx.ndims - 2; i++)
+ outer_count *= sset->count[ i ];
if(ctx.ndims>0)
init_acc_pos(&ctx,total_size);
-
- for (; count > 0; sset->start[ctx.ndims - 1] += sset->stride[ctx.ndims - 1],
- count--) {
- /* calculate the potential number of elements we're going to print */
- H5Sselect_hyperslab(f_space, H5S_SELECT_SET,
- sset->start,
- sset->stride,
- sset->count,
- sset->block);
- sm_nelmts = H5Sget_select_npoints(f_space);
-
-
- /*
- * start (0, 0)
- * block (2, 2)
- * stride (15, 5)
- * count (4, 3)
- *
- * make:
- *
- * for up to "count" times.
- *
- * start (0, += stride[last_dim])
- * block (2, 2)
- * stride (15, 5)
- * count (4, 1)
- */
-
- if (sm_nelmts == 0) {
- /* nothing to print */
- ret = SUCCEED;
- goto done_close;
- }
- /*
- * determine the strip mine size and allocate a buffer. the strip mine is
- * a hyperslab whose size is manageable.
- */
- sm_nbytes = p_type_nbytes = H5Tget_size(p_type);
-
- if (ctx.ndims > 0)
- for (i = ctx.ndims; i > 0; --i) {
- sm_size[i - 1] = MIN(total_size[i - 1], H5TOOLS_BUFSIZE / sm_nbytes);
- sm_nbytes *= sm_size[i - 1];
- assert(sm_nbytes > 0);
- }
+ /* initialize temporary start, count and maximum start */
+ for (i = 0; i < ctx.ndims; i++)
+ {
+ temp_start[ i ] = sset->start[ i ];
+ temp_count[ i ] = sset->count[ i ];
+ max_start[ i ] = 0;
- assert(sm_nbytes == (hsize_t)((size_t)sm_nbytes)); /*check for overflow*/
- sm_buf = malloc((size_t)sm_nelmts * p_type_nbytes);
- sm_space = H5Screate_simple(1, &sm_nelmts, NULL);
+ }
+ if (ctx.ndims > 2)
+ {
+ for (i = 0; i < ctx.ndims - 2; i++)
+ {
+ max_start[ i ] = temp_start[ i ] + sset->count[ i ];
+ temp_count[ i ] = 1;
+
+ }
+ }
- H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, &zero, NULL, &sm_nelmts, NULL);
+
+ /* offset loop */
+ for (n = 0; n < outer_count; n++)
+ {
- /* Read the data */
- if (H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) < 0) {
- H5Sclose(f_space);
- H5Sclose(sm_space);
- free(sm_buf);
- return FAIL;
+ /* number of read iterations in inner loop, read by rows, to match 2D display */
+ if (ctx.ndims > 1)
+ {
+ count = sset->count[ row_dim ];
+ temp_count[ row_dim ] = 1;
}
-
- /* Print the data */
- flags = START_OF_DATA;
-
- if (count == 1)
- flags |= END_OF_DATA;
-
- for (i = 0; i < ctx.ndims; i++) {
- ctx.p_max_idx[i] = ctx.p_min_idx[i] + MIN(total_size[i], sm_size[i]);
+ /* for the 1D case */
+ else
+ {
+ count = 1;
}
- /* print array indices. get the lower bound of the hyperslab and calulate
- the element position at the start of hyperslab */
- H5Sget_select_bounds(f_space,low,high);
- elmtno=0;
- for (i = 0; i < ctx.ndims-1; i++)
+
+ /* display loop */
+ for (; count > 0; temp_start[ row_dim ] += sset->stride[ row_dim ],
+ count--)
{
- hsize_t offset = 1; /* accumulation of the previous dimensions */
- for (j = i+1; j < ctx.ndims; j++)
- offset *= total_size[j];
- elmtno+= low[i] * offset;
- }
- elmtno+= low[ctx.ndims - 1];
+ /* calculate the potential number of elements we're going to print */
+ H5Sselect_hyperslab(f_space, H5S_SELECT_SET,
+ temp_start,
+ sset->stride,
+ temp_count,
+ sset->block);
+ sm_nelmts = H5Sget_select_npoints(f_space);
+
+ if (sm_nelmts == 0) {
+ /* nothing to print */
+ ret = SUCCEED;
+ goto done_close;
+ }
+
+ /*
+ * determine the strip mine size and allocate a buffer. the strip mine is
+ * a hyperslab whose size is manageable.
+ */
+ sm_nbytes = p_type_nbytes = H5Tget_size(p_type);
+
+ if (ctx.ndims > 0)
+ for (i = ctx.ndims; i > 0; --i) {
+ sm_size[i - 1] = MIN(total_size[i - 1], H5TOOLS_BUFSIZE / sm_nbytes);
+ sm_nbytes *= sm_size[i - 1];
+ assert(sm_nbytes > 0);
+ }
+
+ assert(sm_nbytes == (hsize_t)((size_t)sm_nbytes)); /*check for overflow*/
+ sm_buf = malloc((size_t)sm_nelmts * p_type_nbytes);
+ sm_space = H5Screate_simple(1, &sm_nelmts, NULL);
+
+ H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, &zero, NULL, &sm_nelmts, NULL);
+
+ /* read the data */
+ if (H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) < 0) {
+ H5Sclose(f_space);
+ H5Sclose(sm_space);
+ free(sm_buf);
+ return FAIL;
+ }
+
+ /* print the data */
+ flags = START_OF_DATA;
+
+ if (count == 1)
+ flags |= END_OF_DATA;
+
+ for (i = 0; i < ctx.ndims; i++) {
+ ctx.p_max_idx[i] = ctx.p_min_idx[i] + MIN(total_size[i], sm_size[i]);
+ }
+
+ /* print array indices. get the lower bound of the hyperslab and calulate
+ the element position at the start of hyperslab */
+ H5Sget_select_bounds(f_space,low,high);
+ elmtno=0;
+ for (i = 0; i < ctx.ndims-1; i++)
+ {
+ hsize_t offset = 1; /* accumulation of the previous dimensions */
+ for (j = i+1; j < ctx.ndims; j++)
+ offset *= total_size[j];
+ elmtno+= low[i] * offset;
+ }
+ elmtno+= low[ctx.ndims - 1];
+
+ /* initialize the current stripmine position; this is necessary to print the array
+ indices */
+ ctx.sm_pos = elmtno;
+
+ h5tools_dump_simple_data(stream, info, dset, &ctx, flags, sm_nelmts,
+ p_type, sm_buf);
+ free(sm_buf);
+
+ /* we need to jump to next line and update the index */
+ ctx.need_prefix = 1;
+
+ ctx.continuation++;
+ } /* count */
+
+ if (ctx.ndims > 2)
+ {
+ /* dimension for start */
+ current_outer_dim = (ctx.ndims - 2) -1;
+
+ /* set start to original from current_outer_dim up */
+ for (i = current_outer_dim + 1; i < ctx.ndims; i++)
+ {
+ temp_start[ i ] = sset->start[ i ];
+ }
+
+ /* increment start dimension */
+ do
+ {
+ reset_dim = 0;
+ temp_start[ current_outer_dim ]++;
+ if (temp_start[ current_outer_dim ] >= max_start[ current_outer_dim ])
+ {
+ temp_start[ current_outer_dim ] = sset->start[ current_outer_dim ];
+ current_outer_dim--;
+ reset_dim = 1;
+ }
+ }
+ while (current_outer_dim >= 0 && reset_dim);
+
+ } /* ctx.ndims > 1 */
- /* initialize the current stripmine position; this is necessary to print the array
- indices */
- ctx.sm_pos = elmtno;
-
- h5tools_dump_simple_data(stream, info, dset, &ctx, flags, sm_nelmts,
- p_type, sm_buf);
- free(sm_buf);
-
- /* we need to jump to next line and update the index */
- ctx.need_prefix = 1;
-
- ctx.continuation++;
- }
+ } /* outer_count */
/* Terminate the output */
if (ctx.cur_column) {
@@ -888,6 +962,8 @@ done:
return ret;
}
+
+
/*-------------------------------------------------------------------------
* Audience: Public
* Chapter: H5Tools Library