summaryrefslogtreecommitdiffstats
path: root/tools/h5dump
diff options
context:
space:
mode:
Diffstat (limited to 'tools/h5dump')
-rw-r--r--tools/h5dump/CMakeLists.txt271
-rw-r--r--tools/h5dump/h5dump.c250
-rw-r--r--tools/h5dump/h5dump.h5
-rw-r--r--tools/h5dump/testh5dump.sh.in91
4 files changed, 607 insertions, 10 deletions
diff --git a/tools/h5dump/CMakeLists.txt b/tools/h5dump/CMakeLists.txt
index b367acb..a02388a 100644
--- a/tools/h5dump/CMakeLists.txt
+++ b/tools/h5dump/CMakeLists.txt
@@ -398,6 +398,80 @@ IF (BUILD_TESTING)
)
ENDIF (WIN32 AND NOT CYGWIN)
+ # --------------------------------------------------------------------
+ # Special option for Packed Bits
+ # --------------------------------------------------------------------
+ IF (HDF5_USE_H5DUMP_PACKED_BITS)
+ #-- Copy all the HDF5 files from the test directory into the source directory
+ SET (HDF5_REFERENCE_PBITS
+ tnofilename-with-packed-bits.ddl
+ tpbitsArray.ddl
+ tpbitsCompound.ddl
+ tpbitsIncomplete.ddl
+ tpbitsLengthExceeded.ddl
+ tpbitsCharLengthExceeded.ddl
+ tpbitsIntLengthExceeded.ddl
+ tpbitsLongLengthExceeded.ddl
+ tpbitsLengthPositive.ddl
+ tpbitsMax.ddl
+ tpbitsMaxExceeded.ddl
+ tpbitsOffsetExceeded.ddl
+ tpbitsCharOffsetExceeded.ddl
+ tpbitsIntOffsetExceeded.ddl
+ tpbitsLongOffsetExceeded.ddl
+ tpbitsOffsetNegative.ddl
+ tpbitsOverlapped.ddl
+ tpbitsSigned.ddl
+ tpbitsUnsigned.ddl
+ tpbitsSignedInt.ddl
+ tpbitsUnsignedInt.ddl
+ tpbitsSignedLong.ddl
+ tpbitsUnsignedLong.ddl
+ tpbitsSignedLongLong.ddl
+ tpbitsUnsignedLongLong.ddl
+ tpbitsSignedWhole.ddl
+ tpbitsUnsignedWhole.ddl
+ tpbitsSignedIntWhole.ddl
+ tpbitsUnsignedIntWhole.ddl
+ tpbitsSignedLongWhole.ddl
+ tpbitsUnsignedLongWhole.ddl
+ tpbitsSignedLongLongWhole.ddl
+ tpbitsUnsignedLongLongWhole.ddl
+ tpbitsSignedLongLongWhole1.ddl
+ tpbitsUnsignedLongLongWhole1.ddl
+ tpbitsSignedLongLongWhole63.ddl
+ tpbitsUnsignedLongLongWhole63.ddl
+ tpbitsSigned4.ddl
+ tpbitsUnsigned4.ddl
+ tpbitsSignedInt8.ddl
+ tpbitsUnsignedInt8.ddl
+ tpbitsSignedLong16.ddl
+ tpbitsUnsignedLong16.ddl
+ tpbitsSignedLongLong32.ddl
+ tpbitsUnsignedLongLong32.ddl
+ tpbitsSigned2.ddl
+ tpbitsUnsigned2.ddl
+ tpbitsSignedInt4.ddl
+ tpbitsUnsignedInt4.ddl
+ tpbitsSignedLong8.ddl
+ tpbitsUnsignedLong8.ddl
+ tpbitsSignedLongLong16.ddl
+ tpbitsUnsignedLongLong16.ddl
+ )
+
+ FOREACH (ddl_pbits ${HDF5_REFERENCE_PBITS})
+ SET (ddldest "${PROJECT_BINARY_DIR}/${ddl_pbits}")
+ #MESSAGE (STATUS " Translating ${ddl_pbits}")
+ ADD_CUSTOM_COMMAND (
+ TARGET h5dump
+ POST_BUILD
+ COMMAND ${XLATE_UTILITY}
+ ARGS ${HDF5_TOOLS_SRC_DIR}/testfiles/${ddl_pbits} ${ddldest} -l3
+ )
+ ENDFOREACH (ddl_pbits ${HDF5_REFERENCE_PBITS})
+
+ ENDIF (HDF5_USE_H5DUMP_PACKED_BITS)
+
##############################################################################
##############################################################################
### T H E T E S T S M A C R O S ###
@@ -901,8 +975,10 @@ IF (BUILD_TESTING)
ADD_H5_TEST (tchar1 0 -r tchar.h5)
# test failure handling
- # Missing file name
- ADD_H5_TEST (tnofilename 1)
+ IF (NOT HDF5_USE_H5DUMP_PACKED_BITS)
+ # Missing file name
+ ADD_H5_TEST (tnofilename 1)
+ ENDIF (NOT HDF5_USE_H5DUMP_PACKED_BITS)
# rev. 2004
@@ -1130,17 +1206,196 @@ IF (BUILD_TESTING)
NAME H5DUMP_PACKED_BITS-clearall-objects
COMMAND ${CMAKE_COMMAND}
-E remove
- tpackedbits.out
- tpackedbits.out.err
- tpackedbits2.out
- tpackedbits2.out.err
+ tnofilename-with-packed-bits.out
+ tnofilename-with-packed-bits.out.err
+ tpbitsArray.out
+ tpbitsArray.out.err
+ tpbitsCompound.out
+ tpbitsCompound.out.err
+ tpbitsIncomplete.out
+ tpbitsIncomplete.out.err
+ tpbitsLengthExceeded.out
+ tpbitsLengthExceeded.out.err
+ tpbitsCharLengthExceeded.out
+ tpbitsCharLengthExceeded.out.err
+ tpbitsIntLengthExceeded.out
+ tpbitsIntLengthExceeded.out.err
+ tpbitsLongLengthExceeded.out
+ tpbitsLongLengthExceeded.out.err
+ tpbitsLengthPositive.out
+ tpbitsLengthPositive.out.err
+ tpbitsMax.out
+ tpbitsMax.out.err
+ tpbitsMaxExceeded.out
+ tpbitsMaxExceeded.out.err
+ tpbitsOffsetExceeded.out
+ tpbitsOffsetExceeded.out.err
+ tpbitsCharOffsetExceeded.out
+ tpbitsCharOffsetExceeded.out.err
+ tpbitsIntOffsetExceeded.out
+ tpbitsIntOffsetExceeded.out.err
+ tpbitsLongOffsetExceeded.out
+ tpbitsLongOffsetExceeded.out.err
+ tpbitsOffsetNegative.out
+ tpbitsOffsetNegative.out.err
+ tpbitsOverlapped.out
+ tpbitsOverlapped.out.err
+ tpbitsSigned.out
+ tpbitsSigned.out.err
+ tpbitsUnsigned.out
+ tpbitsUnsigned.out.err
+ tpbitsSignedInt.out
+ tpbitsSignedInt.out.err
+ tpbitsUnsignedInt.out
+ tpbitsUnsignedInt.out.err
+ tpbitsSignedLong.out
+ tpbitsSignedLong.out.err
+ tpbitsUnsignedLong.out
+ tpbitsUnsignedLong.out.err
+ tpbitsSignedLongLong.out
+ tpbitsSignedLongLong.out.err
+ tpbitsUnsignedLongLong.out
+ tpbitsUnsignedLongLong.out.err
+ tpbitsSignedWhole.out
+ tpbitsSignedWhole.out.err
+ tpbitsUnsignedWhole.out
+ tpbitsUnsignedWhole.out.err
+ tpbitsSignedIntWhole.out
+ tpbitsSignedIntWhole.out.err
+ tpbitsUnsignedIntWhole.out
+ tpbitsUnsignedIntWhole.out.err
+ tpbitsSignedLongWhole.out
+ tpbitsSignedLongWhole.out.err
+ tpbitsUnsignedLongWhole.out
+ tpbitsUnsignedLongWhole.out.err
+ tpbitsSignedLongLongWhole.out
+ tpbitsSignedLongLongWhole.out.err
+ tpbitsUnsignedLongLongWhole.out
+ tpbitsUnsignedLongLongWhole.out.err
+ tpbitsSignedLongLongWhole1.out
+ tpbitsSignedLongLongWhole1.out.err
+ tpbitsUnsignedLongLongWhole1.out
+ tpbitsUnsignedLongLongWhole1.out.err
+ tpbitsSignedLongLongWhole63.out
+ tpbitsSignedLongLongWhole63.out.err
+ tpbitsUnsignedLongLongWhole63.out
+ tpbitsUnsignedLongLongWhole63.out.err
+ tpbitsSigned4.out
+ tpbitsSigned4.out.err
+ tpbitsUnsigned4.out
+ tpbitsUnsigned4.out.err
+ tpbitsSignedInt8.out
+ tpbitsSignedInt8.out.err
+ tpbitsUnsignedInt8.out
+ tpbitsUnsignedInt8.out.err
+ tpbitsSignedLong16.out
+ tpbitsSignedLong16.out.err
+ tpbitsUnsignedLong16.out
+ tpbitsUnsignedLong16.out.err
+ tpbitsSignedLongLong32.out
+ tpbitsSignedLongLong32.out.err
+ tpbitsUnsignedLongLong32.out
+ tpbitsUnsignedLongLong32.out.err
+ tpbitsSigned2.out
+ tpbitsSigned2.out.err
+ tpbitsUnsigned2.out
+ tpbitsUnsigned2.out.err
+ tpbitsSignedInt4.out
+ tpbitsSignedInt4.out.err
+ tpbitsUnsignedInt4.out
+ tpbitsUnsignedInt4.out.err
+ tpbitsSignedLong8.out
+ tpbitsSignedLong8.out.err
+ tpbitsUnsignedLong8.out
+ tpbitsUnsignedLong8.out.err
+ tpbitsSignedLongLong16.out
+ tpbitsSignedLongLong16.out.err
+ tpbitsUnsignedLongLong16.out
+ tpbitsUnsignedLongLong16.out.err
)
IF (NOT "${last_test}" STREQUAL "")
SET_TESTS_PROPERTIES (H5DUMP_PACKED_BITS-clearall-objects PROPERTIES DEPENDS ${last_test})
ENDIF (NOT "${last_test}" STREQUAL "")
SET (last_test "H5DUMP_PACKED_BITS-clearall-objects")
- ADD_H5_TEST (tpackedbits 0 -d /dset1 -M 0,2 tdset.h5)
- ADD_H5_TEST (tpackedbits2 0 -d /dset1 -M 0,2,2,1 tdset.h5)
+
+ # test failure handling
+ # Missing file name
+ ADD_H5_TEST (tnofilename-with-packed-bits 1)
+ # Limits:
+ # Maximum number of packed bits is 8 (for now).
+ # Maximum integer size is 8*sizeof(long long).
+ # Maximun Offset is Maximum size - 1.
+ # Maximum Offset+Length is Maximum size.
+ # Tests:
+ # Normal operation on both signed and unsigned int datasets.
+ # Sanity check
+ # Their rawdata output should be the same.
+ ADD_H5_TEST (tpbitsSignedWhole 0 -d /DS08BITS -M 0,8 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedWhole 0 -d /DU08BITS -M 0,8 packedbits.h5)
+ ADD_H5_TEST (tpbitsSignedIntWhole 0 -d /DS16BITS -M 0,16 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedIntWhole 0 -d /DU16BITS -M 0,16 packedbits.h5)
+ ADD_H5_TEST (tpbitsSignedLongWhole 0 -d /DS32BITS -M 0,32 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedLongWhole 0 -d /DU32BITS -M 0,32 packedbits.h5)
+ ADD_H5_TEST (tpbitsSignedLongLongWhole 0 -d /DS64BITS -M 0,64 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedLongLongWhole 0 -d /DU64BITS -M 0,64 packedbits.h5)
+ ADD_H5_TEST (tpbitsSignedLongLongWhole63 0 -d /DS64BITS -M 0,63 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedLongLongWhole63 0 -d /DU64BITS -M 0,63 packedbits.h5)
+ ADD_H5_TEST (tpbitsSignedLongLongWhole1 0 -d /DS64BITS -M 1,63 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedLongLongWhole1 0 -d /DU64BITS -M 1,63 packedbits.h5)
+ # Half sections
+ ADD_H5_TEST (tpbitsSigned4 0 -d /DS08BITS -M 0,4,4,4 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsigned4 0 -d /DU08BITS -M 0,4,4,4 packedbits.h5)
+ ADD_H5_TEST (tpbitsSignedInt8 0 -d /DS16BITS -M 0,8,8,8 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedInt8 0 -d /DU16BITS -M 0,8,8,8 packedbits.h5)
+ ADD_H5_TEST (tpbitsSignedLong16 0 -d /DS32BITS -M 0,16,16,16 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedLong16 0 -d /DU32BITS -M 0,16,16,16 packedbits.h5)
+ ADD_H5_TEST (tpbitsSignedLongLong32 0 -d /DS64BITS -M 0,32,32,32 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedLongLong32 0 -d /DU64BITS -M 0,32,32,32 packedbits.h5)
+ # Quarter sections
+ ADD_H5_TEST (tpbitsSigned2 0 -d /DS08BITS -M 0,2,2,2,4,2,6,2 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsigned2 0 -d /DU08BITS -M 0,2,2,2,4,2,6,2 packedbits.h5)
+ ADD_H5_TEST (tpbitsSignedInt4 0 -d /DS16BITS -M 0,4,4,4,8,4,12,4 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedInt4 0 -d /DU16BITS -M 0,4,4,4,8,4,12,4 packedbits.h5)
+ ADD_H5_TEST (tpbitsSignedLong8 0 -d /DS32BITS -M 0,8,8,8,16,8,24,8 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedLong8 0 -d /DU32BITS -M 0,8,8,8,16,8,24,8 packedbits.h5)
+ ADD_H5_TEST (tpbitsSignedLongLong16 0 -d /DS64BITS -M 0,16,16,16,32,16,48,16 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedLongLong16 0 -d /DU64BITS -M 0,16,16,16,32,16,48,16 packedbits.h5)
+ # Begin and End
+ ADD_H5_TEST (tpbitsSigned 0 -d /DS08BITS -M 0,2,2,6 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsigned 0 -d /DU08BITS -M 0,2,2,6 packedbits.h5)
+ ADD_H5_TEST (tpbitsSignedInt 0 -d /DS16BITS -M 0,2,10,6 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedInt 0 -d /DU16BITS -M 0,2,10,6 packedbits.h5)
+ ADD_H5_TEST (tpbitsSignedLong 0 -d /DS32BITS -M 0,2,26,6 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedLong 0 -d /DU32BITS -M 0,2,26,6 packedbits.h5)
+ ADD_H5_TEST (tpbitsSignedLongLong 0 -d /DS64BITS -M 0,2,58,6 packedbits.h5)
+ ADD_H5_TEST (tpbitsUnsignedLongLong 0 -d /DU64BITS -M 0,2,58,6 packedbits.h5)
+ # Overlapped packed bits.
+ ADD_H5_TEST (tpbitsOverlapped 0 -d /DS08BITS -M 0,1,1,1,2,1,0,3 packedbits.h5)
+ # Maximum number of packed bits.
+ ADD_H5_TEST (tpbitsMax 0 -d /DS08BITS -M 0,1,1,1,2,1,3,1,4,1,5,1,6,1,7,1 packedbits.h5)
+ # Compound type.
+ ADD_H5_TEST (tpbitsCompound 0 -d /dset1 -M 0,1,1,1 tcompound.h5)
+ # Array type.
+ ADD_H5_TEST (tpbitsArray 0 -d /Dataset1 -M 0,1,1,1 tarray1.h5)
+ # Test Error handling.
+ # Too many packed bits requested. Max is 8 for now.
+ ADD_H5_TEST (tpbitsMaxExceeded 1 -d /DS08BITS -M 0,1,0,1,1,1,2,1,3,1,4,1,5,1,6,1,7,1 packedbits.h5)
+ # Offset too large. Max is 8*sizeof(long long.
+ ADD_H5_TEST (tpbitsOffsetExceeded 1 -d /DS08BITS -M 64,1 packedbits.h5)
+ ADD_H5_TEST (tpbitsCharOffsetExceeded 0 -d /DS08BITS -M 8,1 packedbits.h5)
+ ADD_H5_TEST (tpbitsIntOffsetExceeded 0 -d /DS16BITS -M 16,1 packedbits.h5)
+ ADD_H5_TEST (tpbitsLongOffsetExceeded 0 -d /DS32BITS -M 32,1 packedbits.h5)
+ # Bad offset, must not be negative.
+ ADD_H5_TEST (tpbitsOffsetNegative 1 -d /DS08BITS -M -1,1 packedbits.h5)
+ # Bad length, must not be positive.
+ ADD_H5_TEST (tpbitsLengthPositive 1 -d /DS08BITS -M 4,0 packedbits.h5)
+ # Offset+Length is too large. Max is 8*sizeof(long long).
+ ADD_H5_TEST (tpbitsLengthExceeded 1 -d /DS08BITS -M 37,28 packedbits.h5)
+ ADD_H5_TEST (tpbitsCharLengthExceeded 0 -d /DS08BITS -M 2,7 packedbits.h5)
+ ADD_H5_TEST (tpbitsIntLengthExceeded 0 -d /DS16BITS -M 10,7 packedbits.h5)
+ ADD_H5_TEST (tpbitsLongLengthExceeded 0 -d /DS32BITS -M 26,7 packedbits.h5)
+ # Incomplete pair of packed bits request.
+ ADD_H5_TEST (tpbitsIncomplete 1 -d /DS08BITS -M 0,2,2,1,0,2,2, packedbits.h5)
ENDIF (HDF5_USE_H5DUMP_PACKED_BITS)
# Remove any output file left over from previous test run
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index 64575c2..da6e806 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -93,11 +93,25 @@ static int display_ai = TRUE; /*array index */
static int display_escape = FALSE; /*escape non printable characters */
static int display_region = FALSE; /*print region reference data */
static int enable_error_stack= FALSE; /* re-enable error stack */
+#ifdef H5_HAVE_H5DUMP_PACKED_BITS
+static int display_packed_bits = FALSE; /*print 1-8 byte numbers as packed bits*/
+#endif
/* sort parameters */
static H5_index_t sort_by = H5_INDEX_NAME; /*sort_by [creation_order | name] */
static H5_iter_order_t sort_order = H5_ITER_INC; /*sort_order [ascending | descending] */
+#ifdef H5_HAVE_H5DUMP_PACKED_BITS
+#define PACKED_BITS_MAX 8 /* Maximum number of packed-bits to display */
+#define PACKED_BITS_SIZE_MAX 8*sizeof(long long) /* Maximum bits size of integer types of packed-bits */
+/* mask list for packed bits */
+static unsigned long long packed_mask[PACKED_BITS_MAX]; /* packed bits are restricted to 8*sizeof(llong) bytes */
+
+/* packed bits display parameters */
+static int packed_offset[PACKED_BITS_MAX];
+static int packed_length[PACKED_BITS_MAX];
+#endif
+
/**
** Added for XML **
**/
@@ -117,6 +131,9 @@ static int indent; /*how far in to indent the line
/* internal functions */
static hid_t h5_fileaccess(void);
static void dump_oid(hid_t oid);
+#ifdef H5_HAVE_H5DUMP_PACKED_BITS
+static void dump_packed_bits(unsigned int packed_index, hid_t type);
+#endif
static void print_enum(hid_t type);
static int xml_name_to_XID(const char *, char *, int , int );
static void init_prefix(char **prfx, size_t prfx_len);
@@ -387,7 +404,14 @@ struct handler_t {
* parameters. The long-named ones can be partially spelled. When
* adding more, make sure that they don't clash with each other.
*/
-static const char *s_opts = "hnpeyBHirVa:c:d:f:g:k:l:t:w:xD:uX:o:b*F:s:S:Aq:z:m:RE";
+/* The following initialization makes use of C language cancatenating */
+/* "xxx" "yyy" into "xxxyyy". */
+static const char *s_opts = "hnpeyBHirVa:c:d:f:g:k:l:t:w:xD:uX:o:b*F:s:S:Aq:z:m:RE"
+#ifdef H5_HAVE_H5DUMP_PACKED_BITS
+"M:"
+#endif
+; /* end of *s_opt initialization */
+
static struct long_options l_opts[] = {
{ "help", no_arg, 'h' },
{ "hel", no_arg, 'h' },
@@ -501,6 +525,9 @@ static struct long_options l_opts[] = {
{ "format", require_arg, 'm' },
{ "region", no_arg, 'R' },
{ "enable-error-stack", no_arg, 'E' },
+#ifdef H5_HAVE_H5DUMP_PACKED_BITS
+ { "packed-bits", require_arg, 'M' },
+#endif
{ NULL, 0, '\0' }
};
@@ -656,6 +683,16 @@ usage(const char *prog)
fprintf(stdout, " -m T, --format=T Set the floating point output format\n");
fprintf(stdout, " -q Q, --sort_by=Q Sort groups and attributes by index Q\n");
fprintf(stdout, " -z Z, --sort_order=Z Sort groups and attributes by order Z\n");
+#ifdef H5_HAVE_H5DUMP_PACKED_BITS
+ fprintf(stdout,
+ " -M L, --packedbits=L Print packed bits as unsigned integers, using mask\n"
+ " format L for an integer dataset specified with\n"
+ " option -d. L is a list of offset,length values,\n"
+ " separated by commas. Offset is the beginning bit in\n"
+ " the data value and length is the number of bits of\n"
+ " the mask.\n"
+ );
+#endif
fprintf(stdout, " -R, --region Print dataset pointed by region references\n");
fprintf(stdout, " -x, --xml Output in XML using Schema\n");
fprintf(stdout, " -u, --use-dtd Output in XML using DTD\n");
@@ -712,6 +749,12 @@ usage(const char *prog)
fprintf(stdout, " using a little-endian type\n");
fprintf(stdout, "\n");
fprintf(stdout, " h5dump -d /dset -b LE -o out.bin quux.h5\n");
+#ifdef H5_HAVE_H5DUMP_PACKED_BITS
+ fprintf(stdout, "\n");
+ fprintf(stdout, " 4) Display two packed bits (bits 0-1 and bits 4-6) in the dataset /dset\n");
+ fprintf(stdout, "\n");
+ fprintf(stdout, " h5dump -d /dset -M 0,1,4,3 quux.h5\n");
+#endif
fprintf(stdout, "\n");
}
@@ -2270,7 +2313,19 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset)
if(display_dcpl)
dump_dcpl(dcpl_id, type, did);
- if(display_data)
+ if(display_data) {
+#ifdef H5_HAVE_H5DUMP_PACKED_BITS
+ int data_loop = 1;
+ int i;
+ if(display_packed_bits)
+ data_loop = packed_bits_num;
+ for(i=0;i<data_loop;i++) {
+ if(display_packed_bits) {
+ dump_packed_bits(i, type);
+ packed_data_mask = packed_mask[i];
+ packed_data_offset = packed_offset[i];
+ }
+#endif
switch(H5Tget_class(type)) {
case H5T_TIME:
indentation(indent + COL);
@@ -2293,6 +2348,10 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset)
default:
break;
} /* end switch */
+#ifdef H5_HAVE_H5DUMP_PACKED_BITS
+ } /* for(i=0;i<data_loop;i++) */
+#endif
+ }
indent += COL;
@@ -2672,6 +2731,64 @@ dump_oid(hid_t oid)
indentation(indent + COL);
printf("%s %s %d %s\n", OBJID, BEGIN, oid, END);
}
+#ifdef H5_HAVE_H5DUMP_PACKED_BITS
+/*-------------------------------------------------------------------------
+ * Function: dump_packed_bits
+ *
+ * Purpose: Prints the packed bits offset and length
+ *
+ * Return: void
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+dump_packed_bits(unsigned int packed_index, hid_t type)
+{
+ int packed_bits_size = 0;
+ hid_t n_type = h5tools_get_native_type(type);
+ if(H5Tget_class(n_type)==H5T_INTEGER) {
+ if(H5Tequal(n_type, H5T_NATIVE_SCHAR) == TRUE) {
+ packed_bits_size = 8 * sizeof(char);
+ }
+ else if(H5Tequal(n_type, H5T_NATIVE_UCHAR) == TRUE) {
+ packed_bits_size = 8 * sizeof(unsigned char);
+ }
+ else if(H5Tequal(n_type, H5T_NATIVE_SHORT) == TRUE) {
+ packed_bits_size = 8 * sizeof(short);
+ }
+ else if(H5Tequal(n_type, H5T_NATIVE_USHORT) == TRUE) {
+ packed_bits_size = 8 * sizeof(unsigned short);
+ }
+ else if(H5Tequal(n_type, H5T_NATIVE_INT) == TRUE) {
+ packed_bits_size = 8 * sizeof(int);
+ }
+ else if(H5Tequal(n_type, H5T_NATIVE_UINT) == TRUE) {
+ packed_bits_size = 8 * sizeof(unsigned int);
+ }
+ else if(H5Tequal(n_type, H5T_NATIVE_LONG) == TRUE) {
+ packed_bits_size = 8 * sizeof(long);
+ }
+ else if(H5Tequal(n_type, H5T_NATIVE_ULONG) == TRUE) {
+ packed_bits_size = 8 * sizeof(unsigned long);
+ }
+ else if(H5Tequal(n_type, H5T_NATIVE_LLONG) == TRUE) {
+ packed_bits_size = 8 * sizeof(long long);
+ }
+ else if(H5Tequal(n_type, H5T_NATIVE_ULLONG) == TRUE) {
+ packed_bits_size = 8 * sizeof(unsigned long long);
+ }
+ else
+ error_msg("Packed Bit not valid for this datatype");
+ }
+ indentation(indent + COL);
+ if ((packed_bits_size>0) && (packed_offset[packed_index] + packed_length[packed_index]) > packed_bits_size) {
+ error_msg("Packed Bit offset+length value(%d) too large. Max is %d\n",
+ packed_offset[packed_index]+packed_length[packed_index], packed_bits_size);
+ packed_mask[packed_index] = 0;
+ };
+ printf("%s %s=%d %s=%d\n", PACKED_BITS, PACKED_OFFSET, packed_offset[packed_index], PACKED_LENGTH, packed_length[packed_index]);
+}
+#endif
/*-------------------------------------------------------------------------
* Function: dump_comment
@@ -3583,6 +3700,120 @@ parse_subset_params(char *dset)
return s;
}
+#ifdef H5_HAVE_H5DUMP_PACKED_BITS
+/*-------------------------------------------------------------------------
+ * Function: parse_mask_list
+ *
+ * Purpose: Parse a list of comma or space separated integers and fill
+ * the packed_bits list and counter. The string being passed into this function
+ * should be at the start of the list you want to parse.
+ *
+ * Return: Success: SUCCEED
+ *
+ * Failure: FAIL
+ *
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+parse_mask_list(const char *h_list)
+{
+ const char *ptr;
+ int offset_value, length_value;
+ unsigned long long temp_mask;
+
+ /* sanity check */
+ HDassert(h_list);
+
+ HDmemset(packed_mask,0,sizeof(packed_mask));
+
+ packed_bits_num = 0;
+ /* scan in pair of offset,length separated by commas. */
+ ptr = h_list;
+ while (*ptr) {
+ /* scan for an offset which is an unsigned int */
+ if (!HDisdigit(*ptr)){
+ error_msg("Bad mask list(%s)\n", h_list);
+ return FAIL;
+ }
+ offset_value = HDatoi(ptr);
+ if (offset_value < 0 || offset_value >= PACKED_BITS_SIZE_MAX){
+ error_msg("Packed Bit offset value(%d) must be between 0 and %d\n",
+ offset_value, PACKED_BITS_SIZE_MAX - 1);
+ return FAIL;
+ }
+
+ /* skip to end of integer */
+ while (HDisdigit(*++ptr))
+ ;
+ /* Look for the common separator */
+ if (*ptr++ != ',') {
+ error_msg("Bad mask list(%s), missing expected comma separator.\n", h_list);
+ return FAIL;
+ }
+
+ /* scan for a length which is a positive int */
+ if (!HDisdigit(*ptr)){
+ error_msg("Bad mask list(%s)\n", h_list);
+ return FAIL;
+ }
+ length_value = HDatoi(ptr);
+ if (length_value <= 0){
+ error_msg("Packed Bit length value(%d) must be positive.\n",
+ length_value);
+ return FAIL;
+ };
+ if ((offset_value + length_value) > PACKED_BITS_SIZE_MAX){
+ error_msg("Packed Bit offset+length value(%d) too large. Max is %d\n",
+ offset_value+length_value, PACKED_BITS_SIZE_MAX);
+ return FAIL;
+ };
+
+ /* skip to end of int */
+ while (HDisdigit(*++ptr))
+ ;
+
+ /* store the offset,length pair */
+ if (packed_bits_num >= PACKED_BITS_MAX){
+ /* too many requests */
+ error_msg("Too many masks requested (max. %d). Mask list(%s)\n",
+ PACKED_BITS_MAX, h_list);
+ return FAIL;
+ }
+ packed_offset[packed_bits_num] = offset_value;
+ packed_length[packed_bits_num] = 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. */
+ temp_mask = ~0L;
+ if(length_value<8*sizeof(unsigned long long)) {
+ temp_mask = temp_mask << length_value;
+ packed_mask[packed_bits_num] = ~temp_mask;
+ }
+ else
+ packed_mask[packed_bits_num] = temp_mask;
+ packed_bits_num++;
+
+ /* skip a possible comma separator */
+ if (*ptr == ','){
+ if (!(*++ptr)){
+ /* unexpected end of string */
+ error_msg("Bad mask list(%s), unexpected end of string.\n", h_list);
+ return FAIL;
+ }
+ }
+ }
+ HDassert(packed_bits_num <= PACKED_BITS_MAX);
+ if (packed_bits_num == 0){
+ /* got no masks! */
+ error_msg("Bad mask list(%s)\n", h_list);
+ return FAIL;
+ }
+ return SUCCEED;
+}
+
+#endif
+
/*-------------------------------------------------------------------------
* Function: handle_datasets
*
@@ -4172,6 +4403,21 @@ parse_start:
}
break;
+#ifdef H5_HAVE_H5DUMP_PACKED_BITS
+ case 'M':
+ if (!last_was_dset) {
+ error_msg("option `-%c' can only be used after --dataset option\n",
+ opt);
+ leave(EXIT_FAILURE);
+ }
+ if (parse_mask_list(opt_arg) != SUCCEED){
+ usage(h5tools_getprogname());
+ leave(EXIT_FAILURE);
+ }
+ display_packed_bits = TRUE;
+ break;
+#endif
+
/** begin XML parameters **/
case 'x':
/* select XML output */
diff --git a/tools/h5dump/h5dump.h b/tools/h5dump/h5dump.h
index e16705c..3e34538 100644
--- a/tools/h5dump/h5dump.h
+++ b/tools/h5dump/h5dump.h
@@ -69,6 +69,11 @@
#define EXTERNAL_FILE "EXTERNAL_FILE"
#define FILLVALUE "FILLVALUE"
#define FILE_CONTENTS "FILE_CONTENTS"
+#ifdef H5_HAVE_H5DUMP_PACKED_BITS
+#define PACKED_BITS "PACKED_BITS"
+#define PACKED_OFFSET "OFFSET"
+#define PACKED_LENGTH "LENGTH"
+#endif
#define BEGIN "{"
#define END "}"
diff --git a/tools/h5dump/testh5dump.sh.in b/tools/h5dump/testh5dump.sh.in
index 9b56f7c..f8da64b 100644
--- a/tools/h5dump/testh5dump.sh.in
+++ b/tools/h5dump/testh5dump.sh.in
@@ -23,6 +23,9 @@ USE_FILTER_FLETCHER32="@USE_FILTER_FLETCHER32@"
USE_FILTER_NBIT="@USE_FILTER_NBIT@"
USE_FILTER_SCALEOFFSET="@USE_FILTER_SCALEOFFSET@"
+# Determine if H5dump packed bits feature is included
+Have_Packed_Bits="@PACKED_BITS@"
+
TESTNAME=h5dump
EXIT_SUCCESS=0
EXIT_FAILURE=1
@@ -433,7 +436,11 @@ TOOLTEST tchar1.ddl -r tchar.h5
# test failure handling
# Missing file name
+if test "$Have_Packed_Bits" = "yes"; then
+ TOOLTEST tnofilename-with-packed-bits.ddl
+else
TOOLTEST tnofilename.ddl
+fi
# rev. 2004
@@ -638,6 +645,90 @@ TOOLTEST3 filter_fail.ddl --enable-error-stack filter_fail.h5
# test for -o -y for dataset with attributes
TOOLTEST1 tall-6.ddl -y -o $TESTDIR/data -d /g1/g1.1/dset1.1.1 tall.h5
+# test for dataset packed bits
+# Set up xCMD to test or skip.
+if test "$Have_Packed_Bits" = "yes"; then
+ xCMD=TOOLTEST
+else
+ xCMD=SKIP
+fi
+# Limits:
+# Maximum number of packed bits is 8 (for now).
+# Maximum integer size is 64 (for now).
+# Maximun Offset is 63 (Maximum size - 1).
+# Maximum Offset+Length is 64 (Maximum size).
+# Tests:
+# Normal operation on both signed and unsigned int datasets.
+# Sanity check
+# Their rawdata output should be the same.
+$xCMD tpbitsSignedWhole.ddl -d /DS08BITS -M 0,8 packedbits.h5
+$xCMD tpbitsUnsignedWhole.ddl -d /DU08BITS -M 0,8 packedbits.h5
+$xCMD tpbitsSignedIntWhole.ddl -d /DS16BITS -M 0,16 packedbits.h5
+$xCMD tpbitsUnsignedIntWhole.ddl -d /DU16BITS -M 0,16 packedbits.h5
+$xCMD tpbitsSignedLongWhole.ddl -d /DS32BITS -M 0,32 packedbits.h5
+$xCMD tpbitsUnsignedLongWhole.ddl -d /DU32BITS -M 0,32 packedbits.h5
+$xCMD tpbitsSignedLongLongWhole.ddl -d /DS64BITS -M 0,64 packedbits.h5
+$xCMD tpbitsUnsignedLongLongWhole.ddl -d /DU64BITS -M 0,64 packedbits.h5
+$xCMD tpbitsSignedLongLongWhole63.ddl -d /DS64BITS -M 0,63 packedbits.h5
+$xCMD tpbitsUnsignedLongLongWhole63.ddl -d /DU64BITS -M 0,63 packedbits.h5
+$xCMD tpbitsSignedLongLongWhole1.ddl -d /DS64BITS -M 1,63 packedbits.h5
+$xCMD tpbitsUnsignedLongLongWhole1.ddl -d /DU64BITS -M 1,63 packedbits.h5
+# Half sections
+$xCMD tpbitsSigned4.ddl -d /DS08BITS -M 0,4,4,4 packedbits.h5
+$xCMD tpbitsUnsigned4.ddl -d /DU08BITS -M 0,4,4,4 packedbits.h5
+$xCMD tpbitsSignedInt8.ddl -d /DS16BITS -M 0,8,8,8 packedbits.h5
+$xCMD tpbitsUnsignedInt8.ddl -d /DU16BITS -M 0,8,8,8 packedbits.h5
+$xCMD tpbitsSignedLong16.ddl -d /DS32BITS -M 0,16,16,16 packedbits.h5
+$xCMD tpbitsUnsignedLong16.ddl -d /DU32BITS -M 0,16,16,16 packedbits.h5
+$xCMD tpbitsSignedLongLong32.ddl -d /DS64BITS -M 0,32,32,32 packedbits.h5
+$xCMD tpbitsUnsignedLongLong32.ddl -d /DU64BITS -M 0,32,32,32 packedbits.h5
+# Quarter sections
+$xCMD tpbitsSigned2.ddl -d /DS08BITS -M 0,2,2,2,4,2,6,2 packedbits.h5
+$xCMD tpbitsUnsigned2.ddl -d /DU08BITS -M 0,2,2,2,4,2,6,2 packedbits.h5
+$xCMD tpbitsSignedInt4.ddl -d /DS16BITS -M 0,4,4,4,8,4,12,4 packedbits.h5
+$xCMD tpbitsUnsignedInt4.ddl -d /DU16BITS -M 0,4,4,4,8,4,12,4 packedbits.h5
+$xCMD tpbitsSignedLong8.ddl -d /DS32BITS -M 0,8,8,8,16,8,24,8 packedbits.h5
+$xCMD tpbitsUnsignedLong8.ddl -d /DU32BITS -M 0,8,8,8,16,8,24,8 packedbits.h5
+$xCMD tpbitsSignedLongLong16.ddl -d /DS64BITS -M 0,16,16,16,32,16,48,16 packedbits.h5
+$xCMD tpbitsUnsignedLongLong16.ddl -d /DU64BITS -M 0,16,16,16,32,16,48,16 packedbits.h5
+# Begin and End
+$xCMD tpbitsSigned.ddl -d /DS08BITS -M 0,2,2,6 packedbits.h5
+$xCMD tpbitsUnsigned.ddl -d /DU08BITS -M 0,2,2,6 packedbits.h5
+$xCMD tpbitsSignedInt.ddl -d /DS16BITS -M 0,2,10,6 packedbits.h5
+$xCMD tpbitsUnsignedInt.ddl -d /DU16BITS -M 0,2,10,6 packedbits.h5
+$xCMD tpbitsSignedLong.ddl -d /DS32BITS -M 0,2,26,6 packedbits.h5
+$xCMD tpbitsUnsignedLong.ddl -d /DU32BITS -M 0,2,26,6 packedbits.h5
+$xCMD tpbitsSignedLongLong.ddl -d /DS64BITS -M 0,2,58,6 packedbits.h5
+$xCMD tpbitsUnsignedLongLong.ddl -d /DU64BITS -M 0,2,58,6 packedbits.h5
+# Overlapped packed bits.
+$xCMD tpbitsOverlapped.ddl -d /DS08BITS -M 0,1,1,1,2,1,0,3 packedbits.h5
+# Maximum number of packed bits.
+$xCMD tpbitsMax.ddl -d /DS08BITS -M 0,1,1,1,2,1,3,1,4,1,5,1,6,1,7,1 packedbits.h5
+# Compound type.
+$xCMD tpbitsCompound.ddl -d /dset1 -M 0,1,1,1 tcompound.h5
+# Array type.
+$xCMD tpbitsArray.ddl -d /Dataset1 -M 0,1,1,1 tarray1.h5
+# Test Error handling.
+# Too many packed bits requested. Max is 8 for now.
+$xCMD tpbitsMaxExceeded.ddl -d /DS08BITS -M 0,1,0,1,1,1,2,1,3,1,4,1,5,1,6,1,7,1 packedbits.h5
+# Offset too large. Max is 7 (8-1) for now.
+$xCMD tpbitsOffsetExceeded.ddl -d /DS08BITS -M 64,1 packedbits.h5
+$xCMD tpbitsCharOffsetExceeded.ddl -d /DS08BITS -M 8,1 packedbits.h5
+$xCMD tpbitsIntOffsetExceeded.ddl -d /DS16BITS -M 16,1 packedbits.h5
+$xCMD tpbitsLongOffsetExceeded.ddl -d /DS32BITS -M 32,1 packedbits.h5
+# Bad offset, must not be negative.
+$xCMD tpbitsOffsetNegative.ddl -d /DS08BITS -M -1,1 packedbits.h5
+# Bad length, must not be positive.
+$xCMD tpbitsLengthPositive.ddl -d /DS08BITS -M 4,0 packedbits.h5
+# Offset+Length is too large. Max is 8 for now.
+$xCMD tpbitsLengthExceeded.ddl -d /DS08BITS -M 37,28 packedbits.h5
+$xCMD tpbitsCharLengthExceeded.ddl -d /DS08BITS -M 2,7 packedbits.h5
+$xCMD tpbitsIntLengthExceeded.ddl -d /DS16BITS -M 10,7 packedbits.h5
+$xCMD tpbitsLongLengthExceeded.ddl -d /DS32BITS -M 26,7 packedbits.h5
+# Incomplete pair of packed bits request.
+$xCMD tpbitsIncomplete.ddl -d /DS08BITS -M 0,2,2,1,0,2,2, packedbits.h5
+
+
# Report test results and exit
if test $nerrors -eq 0 ; then
echo "All $TESTNAME tests passed."