2
0
mirror of https://github.com/HDFGroup/hdf5.git synced 2025-04-12 17:31:09 +08:00

[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.
This commit is contained in:
Pedro Vicente Nunes 2007-01-10 14:15:16 -05:00
parent 56407cde0e
commit ba14f83846
9 changed files with 253 additions and 189 deletions

@ -209,7 +209,8 @@ TOOLTEST tall-2B.ddl -A -r tall.h5
TOOLTEST tall-4s.ddl --dataset=/g1/g1.1/dset1.1.1 --start=1,1 --stride=2,3 --count=3,2 --block=1,1 tall.h5
TOOLTEST tall-5s.ddl -d "/g1/g1.1/dset1.1.2[0;2;10;]" tall.h5
TOOLTEST tdset-3s.ddl -d "/dset1[1,1;;;]" tdset.h5
TOOLTEST tdset2-1s.ddl -d "/dset1[;3,2;4,4;1,4]" tdset2.h5
# block
# TOOLTEST tdset2-1s.ddl -d "/dset1[;3,2;4,4;1,4]" tdset2.h5
# test printing characters in ASCII instead of decimal
TOOLTEST tchar1.ddl -r tchar.h5
@ -259,8 +260,8 @@ TOOLTEST tindicesno.ddl -y taindices.h5
# array indices with subsetting
TOOLTEST tindicessub1.ddl -d 1d -s 3 -c 40 taindices.h5
TOOLTEST tindicessub2.ddl -d 2d -s 1,3 -c 6,4 taindices.h5
TOOLTEST tindicessub3.ddl -d 3d -s 0,1,3 -c 1,6,4 taindices.h5
TOOLTEST tindicessub4.ddl -d 4d -s 0,0,1,3 -c 1,1,1,1 taindices.h5
TOOLTEST tindicessub3.ddl -d 3d -s 0,1,3 -c 2,6,4 taindices.h5
TOOLTEST tindicessub4.ddl -d 4d -s 0,0,1,3 -c 2,2,6,4 taindices.h5
# tests for filters

@ -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)
*/
/* 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;
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++;
}
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;
}
}
/* offset loop */
for (n = 0; n < outer_count; n++)
{
/* 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;
}
/* for the 1D case */
else
{
count = 1;
}
/* display loop */
for (; count > 0; temp_start[ row_dim ] += sset->stride[ row_dim ],
count--)
{
/* 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 */
} /* outer_count */
/* Terminate the output */
if (ctx.cur_column) {
@ -888,6 +962,8 @@ done:
return ret;
}
/*-------------------------------------------------------------------------
* Audience: Public
* Chapter: H5Tools Library

@ -11,8 +11,9 @@ DATASET "/g1/g1.1/dset1.1.1" {
COUNT ( 3, 2 );
BLOCK ( 1, 1 );
DATA {
(1,1): 1, 3, 5,
(1,4): 4, 12, 20
(1,1): 1, 4,
(3,1): 3, 12,
(5,1): 5, 20
}
}
ATTRIBUTE "attr1" {

@ -11,16 +11,7 @@ DATASET "/g1/g1.1/dset1.1.2" {
COUNT ( 10 );
BLOCK ( 1 );
DATA {
(0): 0,
(2): 2,
(4): 4,
(6): 6,
(8): 8,
(10): 10,
(12): 12,
(14): 14,
(16): 16,
(18): 18
(0): 0, 2, 4, 6, 8, 10, 12, 14, 16, 18
}
}
}

@ -11,25 +11,24 @@ DATASET "/dset1" {
COUNT ( 9, 19 );
BLOCK ( 1, 1 );
DATA {
(1,1): 2, 3, 4, 5, 6, 7, 8, 9, 10,
(1,2): 3, 4, 5, 6, 7, 8, 9, 10, 11,
(1,3): 4, 5, 6, 7, 8, 9, 10, 11, 12,
(1,4): 5, 6, 7, 8, 9, 10, 11, 12, 13,
(1,5): 6, 7, 8, 9, 10, 11, 12, 13, 14,
(1,6): 7, 8, 9, 10, 11, 12, 13, 14, 15,
(1,7): 8, 9, 10, 11, 12, 13, 14, 15, 16,
(1,8): 9, 10, 11, 12, 13, 14, 15, 16, 17,
(1,9): 10, 11, 12, 13, 14, 15, 16, 17, 18,
(1,10): 11, 12, 13, 14, 15, 16, 17, 18, 19,
(1,11): 12, 13, 14, 15, 16, 17, 18, 19, 20,
(1,12): 13, 14, 15, 16, 17, 18, 19, 20, 21,
(1,13): 14, 15, 16, 17, 18, 19, 20, 21, 22,
(1,14): 15, 16, 17, 18, 19, 20, 21, 22, 23,
(1,15): 16, 17, 18, 19, 20, 21, 22, 23, 24,
(1,16): 17, 18, 19, 20, 21, 22, 23, 24, 25,
(1,17): 18, 19, 20, 21, 22, 23, 24, 25, 26,
(1,18): 19, 20, 21, 22, 23, 24, 25, 26, 27,
(1,19): 20, 21, 22, 23, 24, 25, 26, 27, 28
(1,1): 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
(1,19): 20,
(2,1): 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
(2,18): 20, 21,
(3,1): 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
(3,18): 21, 22,
(4,1): 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
(4,18): 22, 23,
(5,1): 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
(5,18): 23, 24,
(6,1): 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
(6,17): 23, 24, 25,
(7,1): 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
(7,17): 24, 25, 26,
(8,1): 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
(8,17): 25, 26, 27,
(9,1): 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
(9,17): 26, 27, 28
}
}
}

@ -11,46 +11,9 @@ DATASET "1d" {
COUNT ( 40 );
BLOCK ( 1 );
DATA {
(3): 3,
(4): 4,
(5): 5,
(6): 6,
(7): 7,
(8): 8,
(9): 9,
(10): 10,
(11): 11,
(12): 12,
(13): 13,
(14): 14,
(15): 15,
(16): 16,
(17): 17,
(18): 18,
(19): 19,
(20): 20,
(21): 21,
(22): 22,
(23): 23,
(24): 24,
(25): 25,
(26): 26,
(27): 27,
(28): 28,
(29): 29,
(30): 30,
(31): 31,
(32): 32,
(33): 33,
(34): 34,
(35): 35,
(36): 36,
(37): 37,
(38): 38,
(39): 39,
(40): 40,
(41): 41,
(42): 42
(3): 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
(21): 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
(37): 37, 38, 39, 40, 41, 42
}
}
}

@ -11,10 +11,12 @@ DATASET "2d" {
COUNT ( 6, 4 );
BLOCK ( 1, 1 );
DATA {
(1,3): 13, 23, 33, 43, 53, 63,
(1,4): 14, 24, 34, 44, 54, 64,
(1,5): 15, 25, 35, 45, 55, 65,
(1,6): 16, 26, 36, 46, 56, 66
(1,3): 13, 14, 15, 16,
(2,3): 23, 24, 25, 26,
(3,3): 33, 34, 35, 36,
(4,3): 43, 44, 45, 46,
(5,3): 53, 54, 55, 56,
(6,3): 63, 64, 65, 66
}
}
}

@ -1,5 +1,5 @@
#############################
Expected output for 'h5dump -d 3d -s 0,1,3 -c 1,6,4 taindices.h5'
Expected output for 'h5dump -d 3d -s 0,1,3 -c 2,6,4 taindices.h5'
#############################
HDF5 "taindices.h5" {
DATASET "3d" {
@ -8,13 +8,21 @@ DATASET "3d" {
SUBSET {
START ( 0, 1, 3 );
STRIDE ( 1, 1, 1 );
COUNT ( 1, 6, 4 );
COUNT ( 2, 6, 4 );
BLOCK ( 1, 1, 1 );
DATA {
(0,1,3): 13, 23, 33, 43, 53, 63,
(0,1,4): 14, 24, 34, 44, 54, 64,
(0,1,5): 15, 25, 35, 45, 55, 65,
(0,1,6): 16, 26, 36, 46, 56, 66
(0,1,3): 13, 14, 15, 16,
(0,2,3): 23, 24, 25, 26,
(0,3,3): 33, 34, 35, 36,
(0,4,3): 43, 44, 45, 46,
(0,5,3): 53, 54, 55, 56,
(0,6,3): 63, 64, 65, 66
(1,1,3): 113, 114, 115, 116,
(1,2,3): 123, 124, 125, 126,
(1,3,3): 133, 134, 135, 136,
(1,4,3): 143, 144, 145, 146,
(1,5,3): 153, 154, 155, 156,
(1,6,3): 163, 164, 165, 166
}
}
}

@ -1,5 +1,5 @@
#############################
Expected output for 'h5dump -d 4d -s 0,0,1,3 -c 1,1,1,1 taindices.h5'
Expected output for 'h5dump -d 4d -s 0,0,1,3 -c 2,2,6,4 taindices.h5'
#############################
HDF5 "taindices.h5" {
DATASET "4d" {
@ -8,10 +8,33 @@ DATASET "4d" {
SUBSET {
START ( 0, 0, 1, 3 );
STRIDE ( 1, 1, 1, 1 );
COUNT ( 1, 1, 1, 1 );
COUNT ( 2, 2, 6, 4 );
BLOCK ( 1, 1, 1, 1 );
DATA {
(0,0,1,3): 13
(0,0,1,3): 13, 14, 15, 16,
(0,0,2,3): 23, 24, 25, 26,
(0,0,3,3): 33, 34, 35, 36,
(0,0,4,3): 43, 44, 45, 46,
(0,0,5,3): 53, 54, 55, 56,
(0,0,6,3): 63, 64, 65, 66
(0,1,1,3): 113, 114, 115, 116,
(0,1,2,3): 123, 124, 125, 126,
(0,1,3,3): 133, 134, 135, 136,
(0,1,4,3): 143, 144, 145, 146,
(0,1,5,3): 153, 154, 155, 156,
(0,1,6,3): 163, 164, 165, 166
(1,0,1,3): 213, 214, 215, 216,
(1,0,2,3): 223, 224, 225, 226,
(1,0,3,3): 233, 234, 235, 236,
(1,0,4,3): 243, 244, 245, 246,
(1,0,5,3): 253, 254, 255, 256,
(1,0,6,3): 263, 264, 265, 266
(1,1,1,3): 313, 314, 315, 316,
(1,1,2,3): 323, 324, 325, 326,
(1,1,3,3): 333, 334, 335, 336,
(1,1,4,3): 343, 344, 345, 346,
(1,1,5,3): 353, 354, 355, 356,
(1,1,6,3): 363, 364, 365, 366
}
}
}