diff options
Diffstat (limited to 'tools/lib/h5tools.c')
-rw-r--r-- | tools/lib/h5tools.c | 155 |
1 files changed, 123 insertions, 32 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 3d8c871..6fc09d7 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -30,6 +30,7 @@ #include "h5tools_utils.h" #include "H5private.h" +#define SANITY_CHECK #define ALIGN(A,Z) ((((A) + (Z) - 1) / (Z)) * (Z)) @@ -612,7 +613,7 @@ h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t contai } /* - * We need to break after each row of a dimension---> we should + * We need to break after each row_counter of a dimension---> we should * break at the end of the each last dimension well that is the * way the dumper did it before */ @@ -706,28 +707,40 @@ h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t contai * Chapter: H5Tools Library * Purpose: Dump out a subset of a dataset. * Description: - * Select a hyperslab from the dataset DSET using the parameters - * specified in SSET. Dump this out to STREAM. + * + * Select a hyperslab from the dataset DSET using the parameters + * specified in SSET. Dump this out to STREAM. + * + * Hyperslabs select "count" blocks of size "block", spaced "stride" elements + * from each other, starting at coordinate "start". + * * Return: * On success, return SUCCEED. Otherwise, the function returns FAIL. - * Programmer: - * 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 + * + * Original programmer: + * Bill Wendling, Wednesday, March 07, 2001 + * + * Rewritten with modified algorithm by: + * Pedro Vicente, Wednesday, January 16, 2008, contributions from Quincey Koziol + * + * Algorithm + * + * In a inner loop, the parameters from SSET are translated into temporary + * variables so that 1 row is printed at a time (getting the coordinate indices + * at each row). + * We define the stride, count and block to be 1 in the row dimension to achieve + * this and advance until all points are printed. + * An outer loop for cases where dimensionality is greater than 2D is made. + * In each iteration, the 2D block is displayed in the inner loop. The remaining + * slower dimensions above the first 2 are incremented one at a time in the outer loop + * + * The element position is obtained from the matrix according to: * 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 @@ -755,13 +768,21 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset 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 */ + unsigned int row_dim; /* index of row_counter 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; + hsize_t temp_block[H5S_MAX_RANK];/* temporary block size used in loop */ + hsize_t temp_stride[H5S_MAX_RANK];/* temporary stride size used in loop */ + int reset_dim; + hsize_t size_row_block; /* size for blocks along rows */ + +#if defined (SANITY_CHECK) + hsize_t total_points = 1; /* to print */ + hsize_t printed_points = 0; /* printed */ +#endif + ret = FAIL; /* be pessimistic */ f_space = H5Dget_space(dset); @@ -799,17 +820,32 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset outer_count = 1; if (ctx.ndims > 2) for (i = 0; i < (size_t)ctx.ndims - 2; i++) - outer_count *= sset->count[ i ]; + { + /* consider block size */ + outer_count = outer_count * sset->count[ i ] * sset->block[ i ]; + + } if(ctx.ndims>0) init_acc_pos(&ctx,total_size); + /* calculate total number of points to print */ +#if defined (SANITY_CHECK) + for (i = 0; i < (size_t)ctx.ndims; i++) + { + total_points *= sset->count[ i ] * sset->block[ i ];; + } +#endif + + /* initialize temporary start, count and maximum start */ for (i = 0; i < (size_t)ctx.ndims; i++) { temp_start[ i ] = sset->start[ i ]; temp_count[ i ] = sset->count[ i ]; + temp_block[ i ] = sset->block[ i ]; + temp_stride[ i ] = sset->stride[ i ]; max_start[ i ] = 0; } @@ -828,29 +864,69 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset for (n = 0; n < outer_count; n++) { + hsize_t row_counter = 0; + /* 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; + + /* count is the number of iterations to display all the rows, + the block size count times */ + count = sset->count[ row_dim ] * sset->block[ row_dim ]; + + /* always 1 row_counter at a time, that is a block of size 1, 1 time */ + temp_count[ row_dim ] = 1; + temp_block[ row_dim ] = 1; + + /* advance 1 row_counter at a time */ + if (sset->block[ row_dim ] > 1 ) + temp_stride[ row_dim ] = 1; + + } /* for the 1D case */ else { count = 1; } - + + size_row_block = sset->block[ row_dim ]; + + /* display loop */ - for (; count > 0; temp_start[ row_dim ] += sset->stride[ row_dim ], - count--) - { + for (; count > 0; + temp_start[ row_dim ] += temp_stride[ row_dim ], + count--) + { + + + /* jump rows if size of block exceeded + cases where block > 1 only and stride > block */ + if ( size_row_block > 1 && + row_counter == size_row_block && + sset->stride[ row_dim ] > sset->block[ row_dim ] + ) + { + + hsize_t increase_rows = sset->stride[ row_dim ] - + sset->block[ row_dim ]; + + temp_start[ row_dim ] += increase_rows; + + row_counter = 0; + + } + + row_counter++; + + /* calculate the potential number of elements we're going to print */ H5Sselect_hyperslab(f_space, H5S_SELECT_SET, temp_start, - sset->stride, + temp_stride, temp_count, - sset->block); + temp_block); sm_nelmts = H5Sget_select_npoints(f_space); if (sm_nelmts == 0) { @@ -920,6 +996,13 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset ctx.need_prefix = 1; ctx.continuation++; + + +#if defined (SANITY_CHECK) + printed_points += sm_nelmts; +#endif + + } /* count */ if (ctx.ndims > 2) @@ -930,8 +1013,9 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset /* 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 ]; + temp_start[ i ] = sset->start[ i ]; } + /* increment start dimension */ do @@ -941,6 +1025,11 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset if (temp_start[ current_outer_dim ] >= max_start[ current_outer_dim ]) { temp_start[ current_outer_dim ] = sset->start[ current_outer_dim ]; + + /* consider block */ + if ( sset->block[ current_outer_dim ] > 1 ) + temp_start[ current_outer_dim ]++; + current_outer_dim--; reset_dim = 1; } @@ -951,6 +1040,11 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset } /* outer_count */ +#if defined (SANITY_CHECK) + assert( printed_points == total_points ); +#endif + + /* Terminate the output */ if (ctx.cur_column) { fputs(OPT(info->line_suf, ""), stream); @@ -1459,9 +1553,6 @@ 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) { -#if 0 - #define DEBUG_H5DUMP_BIN 1 -#endif unsigned char *mem = (unsigned char*)_mem; size_t size; /* datum size */ float tempfloat; |