diff options
-rw-r--r-- | tools/h5dump/h5dump.c | 25 | ||||
-rw-r--r-- | tools/lib/h5tools.c | 4 | ||||
-rw-r--r-- | tools/lib/h5tools.h | 4 | ||||
-rw-r--r-- | tools/lib/h5tools_str.c | 16 | ||||
-rw-r--r-- | tools/testfiles/packedbits.h5 | bin | 7776 -> 7776 bytes |
5 files changed, 19 insertions, 30 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index a9adeb5..5fe4315 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -2287,8 +2287,8 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset) for(i=0;i<data_loop;i++) { if(display_packed_bits) { dump_packed_bits(i); - packed_counter = packed_mask[i]; - packed_normalize = packed_offset[i]; + packed_data_mask = packed_mask[i]; + packed_data_offset = packed_offset[i]; } #endif @@ -3604,18 +3604,13 @@ static int parse_mask_list(const char *h_list) { const char *ptr; - int offset_value = 0, length_value = 0; + int offset_value, length_value; /* sanity check */ HDassert(h_list); - packed_counter = 0; HDmemset(packed_mask,0,sizeof(packed_mask)); - HDmemset(packed_offset,0,sizeof(packed_offset)); - HDmemset(packed_length,0,sizeof(packed_length)); - offset_value = -1; - length_value = -1; packed_bits_num = 0; /* scan in pair of offset,length separated by commas. */ ptr = h_list; @@ -3671,16 +3666,11 @@ parse_mask_list(const char *h_list) } packed_offset[packed_bits_num] = offset_value; packed_length[packed_bits_num] = length_value; - - packed_mask[packed_bits_num] = 1 << offset_value; - while(length_value>1) { - packed_mask[packed_bits_num] = packed_mask[packed_bits_num] << 1; - packed_mask[packed_bits_num] |= 1 << offset_value; - length_value--; - } + /* create the bit mask by left shift 1's by length, then negate it. */ + /* After packed_mask is calculated, packed_length is not needed but */ + /* keep it for debug purpose. */ + packed_mask[packed_bits_num] = ~(~0<<length_value); packed_bits_num++; - offset_value = -1; - length_value = -1; /* skip a possible comma separator */ if (*ptr == ','){ @@ -3697,7 +3687,6 @@ parse_mask_list(const char *h_list) error_msg(h5tools_getprogname(), "Bad mask list(%s)\n", h_list); return FAIL; } - packed_counter = packed_mask[0]; return SUCCEED; } diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index cce7d47..e8657e1 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -44,8 +44,8 @@ int bin_form; /* binary form */ int region_output; /* region output */ #ifdef H5_HAVE_H5DUMP_PACKED_BITS int packed_bits_num; /* number of packed bits to display */ -int packed_normalize; /* number of bits to shift right to display normalized */ -unsigned int packed_counter; /* counter for which packed bits to display */ +int packed_data_offset; /* offset of packed bits to display */ +unsigned int packed_data_mask; /* mask in which packed bits to display */ #endif static h5tool_format_t h5tools_dataformat = { diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index b44948a..2c8ec96 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -527,8 +527,8 @@ extern "C" { #ifdef H5_HAVE_H5DUMP_PACKED_BITS H5TOOLS_DLLVAR int packed_bits_num; /* number of packed bits to display */ -H5TOOLS_DLLVAR int packed_normalize; /* number of bits to shift right to display normalized */ -H5TOOLS_DLLVAR unsigned int packed_counter; /* counter for which packed bits to display */ +H5TOOLS_DLLVAR int packed_data_offset; /* offset of packed bits to display */ +H5TOOLS_DLLVAR unsigned int packed_data_mask; /* mask in which packed bits to display */ #endif H5TOOLS_DLLVAR FILE *rawdatastream; /* output stream for raw data */ diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index b1c017a..da9218f 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -785,7 +785,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai HDmemcpy(&tempint, vp, sizeof(int)); #ifdef H5_HAVE_H5DUMP_PACKED_BITS if(packed_bits_num) - tempint = (tempint & packed_counter)>>packed_normalize; + tempint = (tempint >> packed_data_offset) & packed_data_mask; #endif h5tools_str_append(str, OPT(info->fmt_int, "%d"), tempint); } @@ -793,7 +793,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai HDmemcpy(&tempuint, vp, sizeof(unsigned int)); #ifdef H5_HAVE_H5DUMP_PACKED_BITS if(packed_bits_num) - tempuint = (tempuint & packed_counter)>>packed_normalize; + tempuint = (tempuint >> packed_data_offset) & packed_data_mask; #endif h5tools_str_append(str, OPT(info->fmt_uint, "%u"), tempuint); } @@ -802,7 +802,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai HDmemcpy(&tempchar, cp_vp, sizeof(char)); #ifdef H5_HAVE_H5DUMP_PACKED_BITS if(packed_bits_num) - tempchar = (tempchar & packed_counter)>>packed_normalize; + tempchar = (tempchar >> packed_data_offset) & packed_data_mask; #endif h5tools_str_append(str, OPT(info->fmt_schar, "%d"), tempchar); } @@ -811,7 +811,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai HDmemcpy(&tempuchar, ucp_vp, sizeof(unsigned char)); #ifdef H5_HAVE_H5DUMP_PACKED_BITS if(packed_bits_num) - tempuchar = (tempuchar & packed_counter)>>packed_normalize; + tempuchar = (tempuchar >> packed_data_offset) & packed_data_mask; #endif h5tools_str_append(str, OPT(info->fmt_uchar, "%u"), tempuchar); } @@ -821,7 +821,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai HDmemcpy(&tempshort, vp, sizeof(short)); #ifdef H5_HAVE_H5DUMP_PACKED_BITS if(packed_bits_num) - tempshort = (tempshort & packed_counter)>>packed_normalize; + tempshort = (tempshort >> packed_data_offset) & packed_data_mask; #endif h5tools_str_append(str, OPT(info->fmt_short, "%d"), tempshort); } @@ -831,7 +831,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai HDmemcpy(&tempushort, vp, sizeof(unsigned short)); #ifdef H5_HAVE_H5DUMP_PACKED_BITS if(packed_bits_num) - tempushort = (tempushort & packed_counter)>>packed_normalize; + tempushort = (tempushort >> packed_data_offset) & packed_data_mask; #endif h5tools_str_append(str, OPT(info->fmt_ushort, "%u"), tempushort); } @@ -839,7 +839,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai HDmemcpy(&templong, vp, sizeof(long)); #ifdef H5_HAVE_H5DUMP_PACKED_BITS if(packed_bits_num) - templong = (templong & packed_counter)>>packed_normalize; + templong = (templong >> packed_data_offset) & packed_data_mask; #endif h5tools_str_append(str, OPT(info->fmt_long, "%ld"), templong); } @@ -847,7 +847,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai HDmemcpy(&tempulong, vp, sizeof(unsigned long)); #ifdef H5_HAVE_H5DUMP_PACKED_BITS if(packed_bits_num) - tempulong = (tempulong & packed_counter)>>packed_normalize; + tempulong = (tempulong >> packed_data_offset) & packed_data_mask; #endif h5tools_str_append(str, OPT(info->fmt_ulong, "%lu"), tempulong); } diff --git a/tools/testfiles/packedbits.h5 b/tools/testfiles/packedbits.h5 Binary files differindex 3db1883..ad7333f 100644 --- a/tools/testfiles/packedbits.h5 +++ b/tools/testfiles/packedbits.h5 |