diff options
author | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2005-02-08 20:54:37 (GMT) |
---|---|---|
committer | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2005-02-08 20:54:37 (GMT) |
commit | 99c08dd282650fcf968e37efdba00fa65bd349b7 (patch) | |
tree | ea19fd5354eec5b3b2d46e6658cde99ee066357f /tools/lib | |
parent | 0c81f8682ce92f8c1f440af911de079348cd0832 (diff) | |
download | hdf5-99c08dd282650fcf968e37efdba00fa65bd349b7.zip hdf5-99c08dd282650fcf968e37efdba00fa65bd349b7.tar.gz hdf5-99c08dd282650fcf968e37efdba00fa65bd349b7.tar.bz2 |
[svn-r9960] Purpose:
bug fix, new test file
Description:
h5dump was not properly displaying array indices > 3D
Solution:
added the same algorythm and data structure that h5diff uses to calculate the array index
from a element number position
Platforms tested:
linux
solaris
Misc. update:
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/h5tools.c | 39 | ||||
-rw-r--r-- | tools/lib/h5tools.h | 8 | ||||
-rw-r--r-- | tools/lib/h5tools_str.c | 12 | ||||
-rw-r--r-- | tools/lib/h5tools_str.h | 2 |
4 files changed, 55 insertions, 6 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 60377c0..e47b534 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -445,7 +445,7 @@ h5tools_simple_prefix(FILE *stream, const h5dump_t *info, /* Calculate new prefix */ h5tools_str_prefix(&prefix, info, elmtno, ctx->ndims, ctx->p_min_idx, - ctx->p_max_idx); + ctx->p_max_idx,ctx); /* Write new prefix to output */ if (ctx->indent_level >= 0) { @@ -746,6 +746,9 @@ h5tools_dump_simple_subset(FILE *stream, const h5dump_t *info, hid_t dset, count = sset->count[ctx.ndims - 1]; sset->count[ctx.ndims - 1] = 1; + 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 */ @@ -954,6 +957,9 @@ h5tools_dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset, sm_nelmts = sm_nbytes / p_type_nbytes; sm_space = H5Screate_simple(1, &sm_nelmts, NULL); + if(ctx.ndims>0) + init_acc_pos(&ctx,total_size); + /* The stripmine loop */ memset(hs_offset, 0, sizeof hs_offset); memset(zero, 0, sizeof zero); @@ -1081,6 +1087,9 @@ h5tools_dump_simple_mem(FILE *stream, const h5dump_t *info, hid_t obj_id, else ctx.size_last_dim = 0; + if(ctx.ndims>0) + init_acc_pos(&ctx,ctx.p_max_idx); + /* Print it */ h5tools_dump_simple_data(stream, info, obj_id, &ctx, START_OF_DATA | END_OF_DATA, nelmts, type, mem); @@ -1228,3 +1237,31 @@ h5tools_dump_mem(FILE *stream, const h5dump_t *info, hid_t obj_id, hid_t type, indentlevel); } +/*------------------------------------------------------------------------- + * Function: init_acc_pos + * + * Purpose: initialize accumulator and matrix position + * + * Return: void + * + * Programmer: pvn + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +void init_acc_pos(h5tools_context_t *ctx, hsize_t *dims) +{ + int i; + + assert(ctx->ndims); + + ctx->acc[ctx->ndims-1]=1; + for(i=(ctx->ndims-2); i>=0; i--) + { + ctx->acc[i]=ctx->acc[i+1] * dims[i+1]; + } + for ( i = 0; i < ctx->ndims; i++) + ctx->pos[i]=0; +} + diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index d5603f7..0c3633f 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -413,8 +413,9 @@ typedef struct h5tools_context_t { *row */ int indent_level; /*the number of times we need some *extra indentation */ - int default_indent_level; /*this is used when the indent - *level gets changed */ + int default_indent_level; /*this is used when the indent level gets changed */ + hsize_t acc[H5S_MAX_RANK]; /* accumulator position */ + hsize_t pos[H5S_MAX_RANK]; /* matrix position */ } h5tools_context_t; /* a structure to hold the subsetting particulars for a dataset */ @@ -510,4 +511,7 @@ extern int h5tools_canreadf(const char* name, hid_t dcpl_id); extern int h5tools_can_encode(H5Z_filter_t filtn); +void init_acc_pos(h5tools_context_t *ctx, hsize_t *dims); + + #endif /* H5TOOLS_H__ */ diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index 6e48190..2d34d94 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -310,10 +310,11 @@ h5tools_str_fmt(h5tools_str_t *str/*in,out*/, size_t start, const char *fmt) char * h5tools_str_prefix(h5tools_str_t *str/*in,out*/, const h5dump_t *info, hsize_t elmtno, int ndims, hsize_t min_idx[], - hsize_t max_idx[]) + hsize_t max_idx[],h5tools_context_t *ctx) { hsize_t p_prod[H5S_MAX_RANK], p_idx[H5S_MAX_RANK]; hsize_t n, i = 0; + hsize_t curr_pos=elmtno; h5tools_str_reset(str); @@ -331,13 +332,20 @@ h5tools_str_prefix(h5tools_str_t *str/*in,out*/, const h5dump_t *info, n %= p_prod[i]; } + for ( i = 0; i < (hsize_t)ndims; i++) + { + ctx->pos[i] = curr_pos/ctx->acc[i]; + curr_pos -= ctx->acc[i]*ctx->pos[i]; + } + assert( curr_pos == 0 ); + /* Print the index values */ for (i = 0; i < (hsize_t)ndims; i++) { if (i) h5tools_str_append(str, "%s", OPT(info->idx_sep, ",")); h5tools_str_append(str, OPT(info->idx_n_fmt, "%lu"), - (unsigned long)p_idx[i]); + (unsigned long) ctx->pos[i]); } } else { /* Scalar */ diff --git a/tools/lib/h5tools_str.h b/tools/lib/h5tools_str.h index d0883fd..0b6df60 100644 --- a/tools/lib/h5tools_str.h +++ b/tools/lib/h5tools_str.h @@ -33,7 +33,7 @@ extern char *h5tools_str_trunc(h5tools_str_t *str, size_t size); extern char *h5tools_str_fmt(h5tools_str_t *str, size_t start, const char *fmt); extern char *h5tools_str_prefix(h5tools_str_t *str, const h5dump_t *info, hsize_t elmtno, int ndims, hsize_t min_idx[], - hsize_t max_idx[]); + hsize_t max_idx[],h5tools_context_t *ctx); extern int h5tools_str_dump_region(h5tools_str_t *, hid_t, const h5dump_t *); extern void h5tools_print_char(h5tools_str_t *str, const h5dump_t *info, unsigned char ch); extern char *h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, |