From 174cc7b19e078a41d97ed42e396127f1f76b889f Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Sat, 15 May 2010 00:40:00 -0500 Subject: [svn-r18821] Packed bits codes tidy up. Removed codes that are not needed any more. Changed algorithm of creating mask which now sits at the least significant bits. Display data by down shift first and then mask it for display. Changed the variable names to reflect the new purpose better. Tested: AlbertPax (linux) --- tools/h5dump/h5dump.c | 25 +++++++------------------ tools/lib/h5tools.c | 4 ++-- tools/lib/h5tools.h | 4 ++-- tools/lib/h5tools_str.c | 16 ++++++++-------- 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;i1) { - 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<>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 index 3db1883..ad7333f 100644 Binary files a/tools/testfiles/packedbits.h5 and b/tools/testfiles/packedbits.h5 differ -- cgit v0.12