diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2012-03-02 14:21:13 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2012-03-02 14:21:13 (GMT) |
commit | 68d93b7f4e458ace2ac255c1c7d9dd8873132b51 (patch) | |
tree | 5e8429affabf4e90eee15cc85119820b3afc36a8 /tools/lib | |
parent | c714d9ef43e8b442bd271867c7afab0487fc0c0a (diff) | |
download | hdf5-68d93b7f4e458ace2ac255c1c7d9dd8873132b51.zip hdf5-68d93b7f4e458ace2ac255c1c7d9dd8873132b51.tar.gz hdf5-68d93b7f4e458ace2ac255c1c7d9dd8873132b51.tar.bz2 |
[svn-r22013] HDFFV-7560:
Merge 1.8 and h5dump/tools and tests based on tools library from trunk.
Reduced warnings.
HDFFV-7949:
Remove duplicated functions in h5ls
Tested: local linux,h5committest
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tools/lib/Makefile.am | 2 | ||||
-rw-r--r-- | tools/lib/Makefile.in | 11 | ||||
-rw-r--r-- | tools/lib/h5diff.c | 80 | ||||
-rw-r--r-- | tools/lib/h5diff_array.c | 338 | ||||
-rw-r--r-- | tools/lib/h5diff_dset.c | 42 | ||||
-rw-r--r-- | tools/lib/h5diff_util.c | 2 | ||||
-rw-r--r-- | tools/lib/h5tools.c | 2963 | ||||
-rw-r--r-- | tools/lib/h5tools.h | 108 | ||||
-rw-r--r-- | tools/lib/h5tools_dump.c | 3921 | ||||
-rw-r--r-- | tools/lib/h5tools_dump.h | 85 | ||||
-rw-r--r-- | tools/lib/h5tools_str.c | 201 | ||||
-rw-r--r-- | tools/lib/h5tools_str.h | 24 | ||||
-rw-r--r-- | tools/lib/h5tools_type.c | 226 | ||||
-rw-r--r-- | tools/lib/h5tools_utils.c | 218 | ||||
-rw-r--r-- | tools/lib/h5tools_utils.h | 12 | ||||
-rw-r--r-- | tools/lib/h5trav.c | 6 |
17 files changed, 4853 insertions, 3388 deletions
diff --git a/tools/lib/CMakeLists.txt b/tools/lib/CMakeLists.txt index 2337985..a75596d 100644 --- a/tools/lib/CMakeLists.txt +++ b/tools/lib/CMakeLists.txt @@ -14,6 +14,7 @@ SET (H5_TOOLS_LIB_SRCS ${HDF5_TOOLS_LIB_SOURCE_DIR}/h5diff_dset.c ${HDF5_TOOLS_LIB_SOURCE_DIR}/h5diff_util.c ${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools.c + ${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_dump.c ${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_filters.c ${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_ref.c ${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_str.c @@ -25,6 +26,7 @@ SET (H5_TOOLS_LIB_SRCS SET (H5_TOOLS_LIB_HDRS ${HDF5_TOOLS_LIB_SOURCE_DIR}/h5trav.h ${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools.h + ${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_dump.h ${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_utils.h ${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_str.h ${HDF5_TOOLS_LIB_SOURCE_DIR}/h5tools_ref.h diff --git a/tools/lib/Makefile.am b/tools/lib/Makefile.am index 43ee863..e364b47 100644 --- a/tools/lib/Makefile.am +++ b/tools/lib/Makefile.am @@ -26,7 +26,7 @@ INCLUDES=-I$(top_srcdir)/src # This is our main target, the h5tools library. noinst_LTLIBRARIES=libh5tools.la -libh5tools_la_SOURCES=h5tools.c h5tools_str.c h5tools_utils.c h5diff.c \ +libh5tools_la_SOURCES=h5tools.c h5tools_dump.c h5tools_str.c h5tools_utils.c h5diff.c \ h5diff_array.c h5diff_attr.c h5diff_dset.c h5diff_util.c h5trav.c \ h5tools_filters.c h5tools_ref.c h5tools_type.c diff --git a/tools/lib/Makefile.in b/tools/lib/Makefile.in index 0ecf276..beeb42f 100644 --- a/tools/lib/Makefile.in +++ b/tools/lib/Makefile.in @@ -67,10 +67,10 @@ CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libh5tools_la_LIBADD = -am_libh5tools_la_OBJECTS = h5tools.lo h5tools_str.lo h5tools_utils.lo \ - h5diff.lo h5diff_array.lo h5diff_attr.lo h5diff_dset.lo \ - h5diff_util.lo h5trav.lo h5tools_filters.lo h5tools_ref.lo \ - h5tools_type.lo +am_libh5tools_la_OBJECTS = h5tools.lo h5tools_dump.lo h5tools_str.lo \ + h5tools_utils.lo h5diff.lo h5diff_array.lo h5diff_attr.lo \ + h5diff_dset.lo h5diff_util.lo h5trav.lo h5tools_filters.lo \ + h5tools_ref.lo h5tools_type.lo libh5tools_la_OBJECTS = $(am_libh5tools_la_OBJECTS) AM_V_lt = $(am__v_lt_$(V)) am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) @@ -396,7 +396,7 @@ INCLUDES = -I$(top_srcdir)/src # This is our main target, the h5tools library. noinst_LTLIBRARIES = libh5tools.la -libh5tools_la_SOURCES = h5tools.c h5tools_str.c h5tools_utils.c h5diff.c \ +libh5tools_la_SOURCES = h5tools.c h5tools_dump.c h5tools_str.c h5tools_utils.c h5diff.c \ h5diff_array.c h5diff_attr.c h5diff_dset.c h5diff_util.c h5trav.c \ h5tools_filters.c h5tools_ref.c h5tools_type.c @@ -490,6 +490,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5diff_dset.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5diff_util.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5tools.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5tools_dump.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5tools_filters.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5tools_ref.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5tools_str.Plo@am__quote@ diff --git a/tools/lib/h5diff.c b/tools/lib/h5diff.c index be20ed4..bc8acd5 100644 --- a/tools/lib/h5diff.c +++ b/tools/lib/h5diff.c @@ -25,11 +25,11 @@ * Debug printf macros. The prefix allows output filtering by test scripts. */ #ifdef H5DIFF_DEBUG -#define h5diffdebug(x) fprintf(stderr, "h5diff debug: " x) -#define h5diffdebug2(x1, x2) fprintf(stderr, "h5diff debug: " x1, x2) -#define h5diffdebug3(x1, x2, x3) fprintf(stderr, "h5diff debug: " x1, x2, x3) -#define h5diffdebug4(x1, x2, x3, x4) fprintf(stderr, "h5diff debug: " x1, x2, x3, x4) -#define h5diffdebug5(x1, x2, x3, x4, x5) fprintf(stderr, "h5diff debug: " x1, x2, x3, x4, x5) +#define h5diffdebug(x) HDfprintf(stderr, "h5diff debug: " x) +#define h5diffdebug2(x1, x2) HDfprintf(stderr, "h5diff debug: " x1, x2) +#define h5diffdebug3(x1, x2, x3) HDfprintf(stderr, "h5diff debug: " x1, x2, x3) +#define h5diffdebug4(x1, x2, x3, x4) HDfprintf(stderr, "h5diff debug: " x1, x2, x3, x4) +#define h5diffdebug5(x1, x2, x3, x4, x5) HDfprintf(stderr, "h5diff debug: " x1, x2, x3, x4, x5) #else #define h5diffdebug(x) #define h5diffdebug2(x1, x2) @@ -153,13 +153,13 @@ void print_manager_output(void) overflow_file = NULL; } - fflush(stdout); - memset(outBuff, 0, OUTBUFF_SIZE); + HDfflush(stdout); + HDmemset(outBuff, 0, OUTBUFF_SIZE); outBuffOffset = 0; } else if( (outBuffOffset>0) && !g_Parallel) { - fprintf(stderr, "h5diff error: outBuffOffset>0, but we're not in parallel!\n"); + HDfprintf(stderr, "h5diff error: outBuffOffset>0, but we're not in parallel!\n"); } } @@ -189,7 +189,7 @@ static void print_incoming_data(void) MPI_Iprobe(MPI_ANY_SOURCE, MPI_TAG_PRINT_DATA, MPI_COMM_WORLD, &incomingMessage, &Status); if(incomingMessage) { - memset(data, 0, PRINT_DATA_MAX_SIZE+1); + HDmemset(data, 0, PRINT_DATA_MAX_SIZE+1); MPI_Recv(data, PRINT_DATA_MAX_SIZE, MPI_CHAR, Status.MPI_SOURCE, MPI_TAG_PRINT_DATA, MPI_COMM_WORLD, &Status); printf("%s", data); @@ -274,7 +274,7 @@ static int is_exclude_path (char * path, h5trav_type_t type, diff_opt_t *options if (exclude_path_ptr->obj_type == H5TRAV_TYPE_GROUP) { ret_cmp = HDstrncmp(exclude_path_ptr->obj_path, path, - strlen(exclude_path_ptr->obj_path)); + HDstrlen(exclude_path_ptr->obj_path)); if (ret_cmp == 0) { /* check if given path belong to an excluding group, if so @@ -531,7 +531,7 @@ static herr_t trav_grp_symlinks(const char *path, const H5L_info_t *linfo, const char *ext_path; /* init linkinfo struct */ - memset(&lnk_info, 0, sizeof(h5tool_link_info_t)); + HDmemset(&lnk_info, 0, sizeof(h5tool_link_info_t)); if (!opts->follow_links) { @@ -614,7 +614,7 @@ static herr_t trav_grp_symlinks(const char *path, const H5L_info_t *linfo, done: if (lnk_info.trg_path) - HDfree(lnk_info.trg_path); + HDfree((char *)lnk_info.trg_path); return 0; } @@ -728,25 +728,25 @@ hsize_t h5diff(const char *fname1, /* make the given object1 fullpath, start with "/" */ if (HDstrncmp(objname1, "/", 1)) { - HDstrcpy(obj1fullname, "/"); - HDstrcat(obj1fullname, objname1); + HDstrcpy((char *)obj1fullname, "/"); + HDstrcat((char *)obj1fullname, objname1); } else - HDstrcpy(obj1fullname, objname1); + HDstrcpy((char *)obj1fullname, objname1); /* make the given object2 fullpath, start with "/" */ if (HDstrncmp(objname2, "/", 1)) { - HDstrcpy(obj2fullname, "/"); - HDstrcat(obj2fullname, objname2); + HDstrcpy((char *)obj2fullname, "/"); + HDstrcat((char *)obj2fullname, objname2); } else - HDstrcpy(obj2fullname, objname2); + HDstrcpy((char *)obj2fullname, objname2); /*---------------------------------------------------------- * check if obj1 is root, group, single object or symlink */ - if(!HDstrcmp(obj1fullname, "/")) + if(!HDstrcmp((char *)obj1fullname, "/")) { obj1type = H5TRAV_TYPE_GROUP; } @@ -856,9 +856,9 @@ hsize_t h5diff(const char *fname1, { /* set root group */ obj1fullname = (char*)HDcalloc(2, sizeof(char)); - HDstrcat(obj1fullname, "/"); + HDstrcat((char *)obj1fullname, "/"); obj2fullname = (char*)HDcalloc(2, sizeof(char)); - HDstrcat(obj2fullname, "/"); + HDstrcat((char *)obj2fullname, "/"); } @@ -995,7 +995,7 @@ hsize_t h5diff(const char *fname1, if((HDstrlen(fname1) > MAX_FILENAME) || (HDstrlen(fname2) > MAX_FILENAME)) { - fprintf(stderr, "The parallel diff only supports path names up to %d characters\n", MAX_FILENAME); + HDfprintf(stderr, "The parallel diff only supports path names up to %d characters\n", MAX_FILENAME); MPI_Abort(MPI_COMM_WORLD, 0); } /* end if */ @@ -1045,15 +1045,15 @@ out: /* free buffers */ if (obj1fullname) - HDfree(obj1fullname); + HDfree((char *)obj1fullname); if (obj2fullname) - HDfree(obj2fullname); + HDfree((char *)obj2fullname); /* free link info buffer */ if (trg_linfo1.trg_path) - HDfree(trg_linfo1.trg_path); + HDfree((char *)trg_linfo1.trg_path); if (trg_linfo2.trg_path) - HDfree(trg_linfo2.trg_path); + HDfree((char *)trg_linfo2.trg_path); /* close */ H5E_BEGIN_TRY @@ -1112,9 +1112,9 @@ hsize_t diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, * make full path */ if (HDstrcmp (grp1, "/")) - grp1_path = grp1; + grp1_path = (char *)grp1; if (HDstrcmp (grp2, "/")) - grp2_path = grp2; + grp2_path = (char *)grp2; /*------------------------------------------------------------------------- * regarding the return value of h5diff (0, no difference in files, 1 difference ) @@ -1180,12 +1180,12 @@ hsize_t diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, { objtype = table->objs[i].type; /* make full path for obj1 */ - obj1_fullpath = (char*)HDcalloc (strlen(grp1_path) + strlen (table->objs[i].name) + 1, sizeof (char)); + obj1_fullpath = (char*)HDcalloc (HDstrlen(grp1_path) + strlen (table->objs[i].name) + 1, sizeof (char)); HDstrcpy(obj1_fullpath, grp1_path); HDstrcat(obj1_fullpath, table->objs[i].name); /* make full path for obj2 */ - obj2_fullpath = (char*)HDcalloc (strlen(grp2_path) + strlen (table->objs[i].name) + 1, sizeof (char)); + obj2_fullpath = (char*)HDcalloc (HDstrlen(grp2_path) + strlen (table->objs[i].name) + 1, sizeof (char)); HDstrcpy(obj2_fullpath, grp2_path); HDstrcat(obj2_fullpath, table->objs[i].name); @@ -1474,7 +1474,7 @@ hsize_t diff_match(hid_t file1_id, const char *grp1, trav_info_t *info1, } /* end if */ h5diffdebug("done with if block\n"); - free(workerTasks); + HDfree(workerTasks); } #endif /* H5_HAVE_PARALLEL */ @@ -1769,9 +1769,9 @@ out: /* free link info buffer */ if (linkinfo1.trg_path) - HDfree(linkinfo1.trg_path); + HDfree((char *)linkinfo1.trg_path); if (linkinfo2.trg_path) - HDfree(linkinfo2.trg_path); + HDfree((char *)linkinfo2.trg_path); return nfound; } @@ -1938,7 +1938,7 @@ hsize_t diff(hid_t file1_id, *---------------------------------------------------------------------- */ case H5TRAV_TYPE_DATASET: - /* verbose (-v) and report (-r) mode */ + /* verbose (-v) and report (-r) mode */ if(options->m_verbose || options->m_report) { do_print_objname("dataset", path1, path2, options); @@ -1950,7 +1950,7 @@ hsize_t diff(hid_t file1_id, { nfound = diff_dataset(file1_id, file2_id, path1, path2, options); } - /* the rest (-c, none, ...) */ + /* the rest (-c, none, ...) */ else { nfound = diff_dataset(file1_id, file2_id, path1, path2, options); @@ -1958,7 +1958,7 @@ hsize_t diff(hid_t file1_id, if (nfound) { do_print_objname("dataset", path1, path2, options); - print_found(nfound); + print_found(nfound); } } break; @@ -2163,9 +2163,9 @@ hsize_t diff(hid_t file1_id, /* free link info buffer */ if (linkinfo1.trg_path) - HDfree(linkinfo1.trg_path); + HDfree((char *)linkinfo1.trg_path); if (linkinfo2.trg_path) - HDfree(linkinfo2.trg_path); + HDfree((char *)linkinfo2.trg_path); return nfound; @@ -2206,9 +2206,9 @@ out2: /* free link info buffer */ if (linkinfo1.trg_path) - HDfree(linkinfo1.trg_path); + HDfree((char *)linkinfo1.trg_path); if (linkinfo2.trg_path) - HDfree(linkinfo2.trg_path); + HDfree((char *)linkinfo2.trg_path); /* close */ /* disable error reporting */ diff --git a/tools/lib/h5diff_array.c b/tools/lib/h5diff_array.c index e6a9d05..57a5599 100644 --- a/tools/lib/h5diff_array.c +++ b/tools/lib/h5diff_array.c @@ -137,7 +137,7 @@ static int not_comparable; is_zero=1; \ } -# define PDIFF(a,b) ( (b>a) ? (b-a) : (a-b)) +# define PDIFF(a,b) ( (b>a) ? (b-a) : (a-b)) /*------------------------------------------------------------------------- * local prototypes @@ -260,7 +260,7 @@ hsize_t diff_array( void *_mem1, switch (type_class) { default: - assert(0); + HDassert(0); break; /*------------------------------------------------------------------------- @@ -440,10 +440,10 @@ hsize_t diff_datum(void *_mem1, switch (H5Tget_class(m_type)) { default: - assert(0); + HDassert(0); break; case H5T_TIME: - assert(0); + HDassert(0); break; /*------------------------------------------------------------------------- @@ -705,7 +705,7 @@ hsize_t diff_datum(void *_mem1, size = H5Tget_size(memb_type); ndims = H5Tget_array_ndims(m_type); H5Tget_array_dims2(m_type, adims); - assert(ndims >= 1 && ndims <= H5S_MAX_RANK); + HDassert(ndims >= 1 && ndims <= H5S_MAX_RANK); /* calculate the number of array elements */ for (u = 0, nelmts = 1; u <ndims; u++) @@ -897,9 +897,9 @@ hsize_t diff_datum(void *_mem1, { char temp1_char; char temp2_char; - assert(type_size==sizeof(char)); - memcpy(&temp1_char, mem1, sizeof(char)); - memcpy(&temp2_char, mem2, sizeof(char)); + HDassert(type_size==sizeof(char)); + HDmemcpy(&temp1_char, mem1, sizeof(char)); + HDmemcpy(&temp2_char, mem2, sizeof(char)); /* -d and !-p */ if (options->d && !options->p) { @@ -993,10 +993,10 @@ hsize_t diff_datum(void *_mem1, { unsigned char temp1_uchar; unsigned char temp2_uchar; - assert(type_size==sizeof(unsigned char)); + HDassert(type_size==sizeof(unsigned char)); - memcpy(&temp1_uchar, mem1, sizeof(unsigned char)); - memcpy(&temp2_uchar, mem2, sizeof(unsigned char)); + HDmemcpy(&temp1_uchar, mem1, sizeof(unsigned char)); + HDmemcpy(&temp2_uchar, mem2, sizeof(unsigned char)); /* -d and !-p */ if (options->d && !options->p) { @@ -1092,10 +1092,10 @@ hsize_t diff_datum(void *_mem1, { short temp1_short; short temp2_short; - assert(type_size==sizeof(short)); + HDassert(type_size==sizeof(short)); - memcpy(&temp1_short, mem1, sizeof(short)); - memcpy(&temp2_short, mem2, sizeof(short)); + HDmemcpy(&temp1_short, mem1, sizeof(short)); + HDmemcpy(&temp2_short, mem2, sizeof(short)); /* -d and !-p */ if (options->d && !options->p) { @@ -1191,10 +1191,10 @@ hsize_t diff_datum(void *_mem1, { unsigned short temp1_ushort; unsigned short temp2_ushort; - assert(type_size==sizeof(short)); + HDassert(type_size==sizeof(short)); - memcpy(&temp1_ushort, mem1, sizeof(unsigned short)); - memcpy(&temp2_ushort, mem2, sizeof(unsigned short)); + HDmemcpy(&temp1_ushort, mem1, sizeof(unsigned short)); + HDmemcpy(&temp2_ushort, mem2, sizeof(unsigned short)); /* -d and !-p */ if (options->d && !options->p) { @@ -1291,10 +1291,10 @@ hsize_t diff_datum(void *_mem1, { int temp1_int; int temp2_int; - assert(type_size==sizeof(int)); + HDassert(type_size==sizeof(int)); - memcpy(&temp1_int, mem1, sizeof(int)); - memcpy(&temp2_int, mem2, sizeof(int)); + HDmemcpy(&temp1_int, mem1, sizeof(int)); + HDmemcpy(&temp2_int, mem2, sizeof(int)); /* -d and !-p */ if (options->d && !options->p) { @@ -1389,10 +1389,10 @@ hsize_t diff_datum(void *_mem1, { unsigned int temp1_uint; unsigned int temp2_uint; - assert(type_size==sizeof(int)); + HDassert(type_size==sizeof(int)); - memcpy(&temp1_uint, mem1, sizeof(unsigned int)); - memcpy(&temp2_uint, mem2, sizeof(unsigned int)); + HDmemcpy(&temp1_uint, mem1, sizeof(unsigned int)); + HDmemcpy(&temp2_uint, mem2, sizeof(unsigned int)); /* -d and !-p */ if (options->d && !options->p) { @@ -1487,10 +1487,10 @@ hsize_t diff_datum(void *_mem1, { long temp1_long; long temp2_long; - assert(type_size==sizeof(long)); + HDassert(type_size==sizeof(long)); - memcpy(&temp1_long, mem1, sizeof(long)); - memcpy(&temp2_long, mem2, sizeof(long)); + HDmemcpy(&temp1_long, mem1, sizeof(long)); + HDmemcpy(&temp2_long, mem2, sizeof(long)); /* -d and !-p */ if (options->d && !options->p) { @@ -1587,10 +1587,10 @@ hsize_t diff_datum(void *_mem1, { unsigned long temp1_ulong; unsigned long temp2_ulong; - assert(type_size==sizeof(unsigned long)); + HDassert(type_size==sizeof(unsigned long)); - memcpy(&temp1_ulong, mem1, sizeof(unsigned long)); - memcpy(&temp2_ulong, mem2, sizeof(unsigned long)); + HDmemcpy(&temp1_ulong, mem1, sizeof(unsigned long)); + HDmemcpy(&temp2_ulong, mem2, sizeof(unsigned long)); /* -d and !-p */ if (options->d && !options->p) { @@ -1686,10 +1686,10 @@ hsize_t diff_datum(void *_mem1, { long long temp1_llong; long long temp2_llong; - assert(type_size==sizeof(long long)); + HDassert(type_size==sizeof(long long)); - memcpy(&temp1_llong, mem1, sizeof(long long)); - memcpy(&temp2_llong, mem2, sizeof(long long)); + HDmemcpy(&temp1_llong, mem1, sizeof(long long)); + HDmemcpy(&temp2_llong, mem2, sizeof(long long)); /* -d and !-p */ if (options->d && !options->p) { @@ -1784,10 +1784,10 @@ hsize_t diff_datum(void *_mem1, { unsigned long long temp1_ullong; unsigned long long temp2_ullong; - assert(type_size==sizeof(unsigned long long)); + HDassert(type_size==sizeof(unsigned long long)); - memcpy(&temp1_ullong, mem1, sizeof(unsigned long long)); - memcpy(&temp2_ullong, mem2, sizeof(unsigned long long)); + HDmemcpy(&temp1_ullong, mem1, sizeof(unsigned long long)); + HDmemcpy(&temp2_ullong, mem2, sizeof(unsigned long long)); /* -d and !-p */ if (options->d && !options->p) { @@ -1904,10 +1904,10 @@ hsize_t diff_datum(void *_mem1, int isnan1=0; int isnan2=0; - assert(type_size==sizeof(float)); + HDassert(type_size==sizeof(float)); - memcpy(&temp1_float, mem1, sizeof(float)); - memcpy(&temp2_float, mem2, sizeof(float)); + HDmemcpy(&temp1_float, mem1, sizeof(float)); + HDmemcpy(&temp2_float, mem2, sizeof(float)); /* logic for detecting NaNs is different with options -d, -p and no options */ @@ -2117,10 +2117,10 @@ hsize_t diff_datum(void *_mem1, int isnan1=0; int isnan2=0; - assert(type_size==sizeof(double)); + HDassert(type_size==sizeof(double)); - memcpy(&temp1_double, mem1, sizeof(double)); - memcpy(&temp2_double, mem2, sizeof(double)); + HDmemcpy(&temp1_double, mem1, sizeof(double)); + HDmemcpy(&temp2_double, mem2, sizeof(double)); /* logic for detecting NaNs is different with options -d, -p and no options */ @@ -2332,10 +2332,10 @@ hsize_t diff_datum(void *_mem1, int isnan2=0; - assert(type_size==sizeof(long double)); + HDassert(type_size==sizeof(long double)); - memcpy(&temp1_double, mem1, sizeof(long double)); - memcpy(&temp2_double, mem2, sizeof(long double)); + HDmemcpy(&temp1_double, mem1, sizeof(long double)); + HDmemcpy(&temp2_double, mem2, sizeof(long double)); /* logic for detecting NaNs is different with options -d, -p and no options */ @@ -2668,13 +2668,13 @@ hsize_t diff_region(hid_t obj1_id, */ if(nblocks1 > 0) { alloc_size = nblocks1 * ndims1 * 2 * sizeof(ptdata1[0]); - assert(alloc_size == (hsize_t)((size_t)alloc_size)); /*check for overflow*/ + HDassert(alloc_size == (hsize_t)((size_t)alloc_size)); /*check for overflow*/ - ptdata1 = malloc((size_t)alloc_size); + ptdata1 = HDmalloc((size_t)alloc_size); H5_CHECK_OVERFLOW(nblocks1, hssize_t, hsize_t); H5Sget_select_hyper_blocklist(region1_id, (hsize_t)0, (hsize_t)nblocks1, ptdata1); - ptdata2 = malloc((size_t)alloc_size); + ptdata2 = HDmalloc((size_t)alloc_size); H5_CHECK_OVERFLOW(nblocks2, hssize_t, hsize_t); H5Sget_select_hyper_blocklist(region2_id, (hsize_t)0, (hsize_t)nblocks2, ptdata2); @@ -2723,13 +2723,13 @@ hsize_t diff_region(hid_t obj1_id, */ if(npoints1 > 0) { alloc_size = npoints1 * ndims1 * sizeof(ptdata1[0]); - assert(alloc_size == (hsize_t)((size_t)alloc_size)); /*check for overflow*/ + HDassert(alloc_size == (hsize_t)((size_t)alloc_size)); /*check for overflow*/ - ptdata1 = malloc((size_t)alloc_size); + ptdata1 = HDmalloc((size_t)alloc_size); H5_CHECK_OVERFLOW(npoints1,hssize_t,hsize_t); H5Sget_select_elem_pointlist(region1_id, (hsize_t)0, (hsize_t)npoints1, ptdata1); - ptdata2 = malloc((size_t)alloc_size); + ptdata2 = HDmalloc((size_t)alloc_size); H5_CHECK_OVERFLOW(npoints1,hssize_t,hsize_t); H5Sget_select_elem_pointlist(region2_id, (hsize_t)0, (hsize_t)npoints2, ptdata2); @@ -2820,8 +2820,8 @@ hsize_t character_compare(unsigned char *mem1, unsigned char temp1_uchar; unsigned char temp2_uchar; - memcpy(&temp1_uchar, mem1, sizeof(unsigned char)); - memcpy(&temp2_uchar, mem2, sizeof(unsigned char)); + HDmemcpy(&temp1_uchar, mem1, sizeof(unsigned char)); + HDmemcpy(&temp2_uchar, mem2, sizeof(unsigned char)); if (temp1_uchar != temp2_uchar) { @@ -2869,8 +2869,8 @@ hsize_t character_compare_opt(unsigned char *mem1, double per; int both_zero; - memcpy(&temp1_uchar, mem1, sizeof(unsigned char)); - memcpy(&temp2_uchar, mem2, sizeof(unsigned char)); + HDmemcpy(&temp1_uchar, mem1, sizeof(unsigned char)); + HDmemcpy(&temp2_uchar, mem2, sizeof(unsigned char)); /* -d and !-p */ @@ -2975,8 +2975,8 @@ hsize_t diff_float(unsigned char *mem1, { for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_float, mem1, sizeof(float)); - memcpy(&temp2_float, mem2, sizeof(float)); + HDmemcpy(&temp1_float, mem1, sizeof(float)); + HDmemcpy(&temp2_float, mem2, sizeof(float)); /*------------------------------------------------------------------------- * detect NaNs @@ -3029,8 +3029,8 @@ hsize_t diff_float(unsigned char *mem1, { for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_float, mem1, sizeof(float)); - memcpy(&temp2_float, mem2, sizeof(float)); + HDmemcpy(&temp1_float, mem1, sizeof(float)); + HDmemcpy(&temp2_float, mem2, sizeof(float)); /*------------------------------------------------------------------------- * detect NaNs @@ -3102,8 +3102,8 @@ hsize_t diff_float(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_float, mem1, sizeof(float)); - memcpy(&temp2_float, mem2, sizeof(float)); + HDmemcpy(&temp1_float, mem1, sizeof(float)); + HDmemcpy(&temp2_float, mem2, sizeof(float)); /*------------------------------------------------------------------------- * detect NaNs @@ -3176,8 +3176,8 @@ hsize_t diff_float(unsigned char *mem1, { for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_float, mem1, sizeof(float)); - memcpy(&temp2_float, mem2, sizeof(float)); + HDmemcpy(&temp1_float, mem1, sizeof(float)); + HDmemcpy(&temp2_float, mem2, sizeof(float)); if (equal_float(temp1_float,temp2_float,options)==FALSE) { @@ -3248,8 +3248,8 @@ hsize_t diff_double(unsigned char *mem1, { for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_double, mem1, sizeof(double)); - memcpy(&temp2_double, mem2, sizeof(double)); + HDmemcpy(&temp1_double, mem1, sizeof(double)); + HDmemcpy(&temp2_double, mem2, sizeof(double)); /*------------------------------------------------------------------------- * detect NaNs @@ -3302,8 +3302,8 @@ hsize_t diff_double(unsigned char *mem1, { for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_double, mem1, sizeof(double)); - memcpy(&temp2_double, mem2, sizeof(double)); + HDmemcpy(&temp1_double, mem1, sizeof(double)); + HDmemcpy(&temp2_double, mem2, sizeof(double)); /*------------------------------------------------------------------------- * detect NaNs @@ -3375,8 +3375,8 @@ hsize_t diff_double(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_double, mem1, sizeof(double)); - memcpy(&temp2_double, mem2, sizeof(double)); + HDmemcpy(&temp1_double, mem1, sizeof(double)); + HDmemcpy(&temp2_double, mem2, sizeof(double)); /*------------------------------------------------------------------------- * detect NaNs @@ -3452,8 +3452,8 @@ hsize_t diff_double(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_double, mem1, sizeof(double)); - memcpy(&temp2_double, mem2, sizeof(double)); + HDmemcpy(&temp1_double, mem1, sizeof(double)); + HDmemcpy(&temp2_double, mem2, sizeof(double)); if (equal_double(temp1_double,temp2_double,options)==FALSE) @@ -3531,8 +3531,8 @@ hsize_t diff_ldouble(unsigned char *mem1, { for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_double, mem1, sizeof(long double)); - memcpy(&temp2_double, mem2, sizeof(long double)); + HDmemcpy(&temp1_double, mem1, sizeof(long double)); + HDmemcpy(&temp2_double, mem2, sizeof(long double)); /*------------------------------------------------------------------------- * detect NaNs @@ -3585,8 +3585,8 @@ hsize_t diff_ldouble(unsigned char *mem1, { for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_double, mem1, sizeof(long double)); - memcpy(&temp2_double, mem2, sizeof(long double)); + HDmemcpy(&temp1_double, mem1, sizeof(long double)); + HDmemcpy(&temp2_double, mem2, sizeof(long double)); /*------------------------------------------------------------------------- * detect NaNs @@ -3658,8 +3658,8 @@ hsize_t diff_ldouble(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_double, mem1, sizeof(long double)); - memcpy(&temp2_double, mem2, sizeof(long double)); + HDmemcpy(&temp1_double, mem1, sizeof(long double)); + HDmemcpy(&temp2_double, mem2, sizeof(long double)); /*------------------------------------------------------------------------- * detect NaNs @@ -3735,8 +3735,8 @@ hsize_t diff_ldouble(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_double, mem1, sizeof(long double)); - memcpy(&temp2_double, mem2, sizeof(long double)); + HDmemcpy(&temp1_double, mem1, sizeof(long double)); + HDmemcpy(&temp2_double, mem2, sizeof(long double)); if (equal_ldouble(temp1_double,temp2_double,options)==FALSE) @@ -3809,8 +3809,8 @@ hsize_t diff_schar(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_char, mem1, sizeof(char)); - memcpy(&temp2_char, mem2, sizeof(char)); + HDmemcpy(&temp1_char, mem1, sizeof(char)); + HDmemcpy(&temp2_char, mem2, sizeof(char)); if (ABS(temp1_char-temp2_char) > options->delta) { @@ -3835,8 +3835,8 @@ hsize_t diff_schar(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_char, mem1, sizeof(char)); - memcpy(&temp2_char, mem2, sizeof(char)); + HDmemcpy(&temp1_char, mem1, sizeof(char)); + HDmemcpy(&temp2_char, mem2, sizeof(char)); PER(temp1_char,temp2_char); @@ -3879,8 +3879,8 @@ hsize_t diff_schar(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_char, mem1, sizeof(char)); - memcpy(&temp2_char, mem2, sizeof(char)); + HDmemcpy(&temp1_char, mem1, sizeof(char)); + HDmemcpy(&temp2_char, mem2, sizeof(char)); PER(temp1_char,temp2_char); @@ -3922,8 +3922,8 @@ hsize_t diff_schar(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_char, mem1, sizeof(char)); - memcpy(&temp2_char, mem2, sizeof(char)); + HDmemcpy(&temp1_char, mem1, sizeof(char)); + HDmemcpy(&temp2_char, mem2, sizeof(char)); if (temp1_char != temp2_char) { @@ -3986,8 +3986,8 @@ hsize_t diff_uchar(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_uchar, mem1, sizeof(unsigned char)); - memcpy(&temp2_uchar, mem2, sizeof(unsigned char)); + HDmemcpy(&temp1_uchar, mem1, sizeof(unsigned char)); + HDmemcpy(&temp2_uchar, mem2, sizeof(unsigned char)); if ( PDIFF(temp1_uchar,temp2_uchar) > options->delta) { @@ -4013,8 +4013,8 @@ hsize_t diff_uchar(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_uchar, mem1, sizeof(unsigned char)); - memcpy(&temp2_uchar, mem2, sizeof(unsigned char)); + HDmemcpy(&temp1_uchar, mem1, sizeof(unsigned char)); + HDmemcpy(&temp2_uchar, mem2, sizeof(unsigned char)); PER_UNSIGN(signed char,temp1_uchar,temp2_uchar); @@ -4057,8 +4057,8 @@ hsize_t diff_uchar(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_uchar, mem1, sizeof(unsigned char)); - memcpy(&temp2_uchar, mem2, sizeof(unsigned char)); + HDmemcpy(&temp1_uchar, mem1, sizeof(unsigned char)); + HDmemcpy(&temp2_uchar, mem2, sizeof(unsigned char)); PER_UNSIGN(signed char,temp1_uchar,temp2_uchar); @@ -4100,8 +4100,8 @@ hsize_t diff_uchar(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_uchar, mem1, sizeof(unsigned char)); - memcpy(&temp2_uchar, mem2, sizeof(unsigned char)); + HDmemcpy(&temp1_uchar, mem1, sizeof(unsigned char)); + HDmemcpy(&temp2_uchar, mem2, sizeof(unsigned char)); if (temp1_uchar != temp2_uchar) { @@ -4161,8 +4161,8 @@ hsize_t diff_short(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_short, mem1, sizeof(short)); - memcpy(&temp2_short, mem2, sizeof(short)); + HDmemcpy(&temp1_short, mem1, sizeof(short)); + HDmemcpy(&temp2_short, mem2, sizeof(short)); if (ABS(temp1_short-temp2_short) > options->delta) { @@ -4188,8 +4188,8 @@ hsize_t diff_short(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_short, mem1, sizeof(short)); - memcpy(&temp2_short, mem2, sizeof(short)); + HDmemcpy(&temp1_short, mem1, sizeof(short)); + HDmemcpy(&temp2_short, mem2, sizeof(short)); PER(temp1_short,temp2_short); @@ -4234,8 +4234,8 @@ hsize_t diff_short(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_short, mem1, sizeof(short)); - memcpy(&temp2_short, mem2, sizeof(short)); + HDmemcpy(&temp1_short, mem1, sizeof(short)); + HDmemcpy(&temp2_short, mem2, sizeof(short)); PER(temp1_short,temp2_short); @@ -4277,8 +4277,8 @@ hsize_t diff_short(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_short, mem1, sizeof(short)); - memcpy(&temp2_short, mem2, sizeof(short)); + HDmemcpy(&temp1_short, mem1, sizeof(short)); + HDmemcpy(&temp2_short, mem2, sizeof(short)); if (temp1_short != temp2_short) { @@ -4339,8 +4339,8 @@ hsize_t diff_ushort(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_ushort, mem1, sizeof(unsigned short)); - memcpy(&temp2_ushort, mem2, sizeof(unsigned short)); + HDmemcpy(&temp1_ushort, mem1, sizeof(unsigned short)); + HDmemcpy(&temp2_ushort, mem2, sizeof(unsigned short)); if ( PDIFF(temp1_ushort,temp2_ushort) > options->delta) { @@ -4366,8 +4366,8 @@ hsize_t diff_ushort(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_ushort, mem1, sizeof(unsigned short)); - memcpy(&temp2_ushort, mem2, sizeof(unsigned short)); + HDmemcpy(&temp1_ushort, mem1, sizeof(unsigned short)); + HDmemcpy(&temp2_ushort, mem2, sizeof(unsigned short)); PER_UNSIGN(signed short,temp1_ushort,temp2_ushort); @@ -4412,8 +4412,8 @@ hsize_t diff_ushort(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_ushort, mem1, sizeof(unsigned short)); - memcpy(&temp2_ushort, mem2, sizeof(unsigned short)); + HDmemcpy(&temp1_ushort, mem1, sizeof(unsigned short)); + HDmemcpy(&temp2_ushort, mem2, sizeof(unsigned short)); PER_UNSIGN(signed short,temp1_ushort,temp2_ushort); @@ -4455,8 +4455,8 @@ hsize_t diff_ushort(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_ushort, mem1, sizeof(unsigned short)); - memcpy(&temp2_ushort, mem2, sizeof(unsigned short)); + HDmemcpy(&temp1_ushort, mem1, sizeof(unsigned short)); + HDmemcpy(&temp2_ushort, mem2, sizeof(unsigned short)); if (temp1_ushort != temp2_ushort) { @@ -4518,8 +4518,8 @@ hsize_t diff_int(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_int, mem1, sizeof(int)); - memcpy(&temp2_int, mem2, sizeof(int)); + HDmemcpy(&temp1_int, mem1, sizeof(int)); + HDmemcpy(&temp2_int, mem2, sizeof(int)); if (ABS(temp1_int-temp2_int) > options->delta) { @@ -4545,8 +4545,8 @@ hsize_t diff_int(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_int, mem1, sizeof(int)); - memcpy(&temp2_int, mem2, sizeof(int)); + HDmemcpy(&temp1_int, mem1, sizeof(int)); + HDmemcpy(&temp2_int, mem2, sizeof(int)); PER(temp1_int,temp2_int); @@ -4591,8 +4591,8 @@ hsize_t diff_int(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_int, mem1, sizeof(int)); - memcpy(&temp2_int, mem2, sizeof(int)); + HDmemcpy(&temp1_int, mem1, sizeof(int)); + HDmemcpy(&temp2_int, mem2, sizeof(int)); PER(temp1_int,temp2_int); @@ -4634,8 +4634,8 @@ hsize_t diff_int(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_int, mem1, sizeof(int)); - memcpy(&temp2_int, mem2, sizeof(int)); + HDmemcpy(&temp1_int, mem1, sizeof(int)); + HDmemcpy(&temp2_int, mem2, sizeof(int)); if (temp1_int != temp2_int) { @@ -4697,8 +4697,8 @@ hsize_t diff_uint(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_uint, mem1, sizeof(unsigned int)); - memcpy(&temp2_uint, mem2, sizeof(unsigned int)); + HDmemcpy(&temp1_uint, mem1, sizeof(unsigned int)); + HDmemcpy(&temp2_uint, mem2, sizeof(unsigned int)); if ( PDIFF(temp1_uint,temp2_uint) > options->delta) { @@ -4724,8 +4724,8 @@ hsize_t diff_uint(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_uint, mem1, sizeof(unsigned int)); - memcpy(&temp2_uint, mem2, sizeof(unsigned int)); + HDmemcpy(&temp1_uint, mem1, sizeof(unsigned int)); + HDmemcpy(&temp2_uint, mem2, sizeof(unsigned int)); PER_UNSIGN(signed int,temp1_uint,temp2_uint); @@ -4769,8 +4769,8 @@ hsize_t diff_uint(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_uint, mem1, sizeof(unsigned int)); - memcpy(&temp2_uint, mem2, sizeof(unsigned int)); + HDmemcpy(&temp1_uint, mem1, sizeof(unsigned int)); + HDmemcpy(&temp2_uint, mem2, sizeof(unsigned int)); PER_UNSIGN(signed int,temp1_uint,temp2_uint); @@ -4811,8 +4811,8 @@ hsize_t diff_uint(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_uint, mem1, sizeof(unsigned int)); - memcpy(&temp2_uint, mem2, sizeof(unsigned int)); + HDmemcpy(&temp1_uint, mem1, sizeof(unsigned int)); + HDmemcpy(&temp2_uint, mem2, sizeof(unsigned int)); if (temp1_uint != temp2_uint) { @@ -4877,8 +4877,8 @@ hsize_t diff_long(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_long, mem1, sizeof(long)); - memcpy(&temp2_long, mem2, sizeof(long)); + HDmemcpy(&temp1_long, mem1, sizeof(long)); + HDmemcpy(&temp2_long, mem2, sizeof(long)); if (ABS(temp1_long-temp2_long) > options->delta) { @@ -4904,8 +4904,8 @@ hsize_t diff_long(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_long, mem1, sizeof(long)); - memcpy(&temp2_long, mem2, sizeof(long)); + HDmemcpy(&temp1_long, mem1, sizeof(long)); + HDmemcpy(&temp2_long, mem2, sizeof(long)); PER(temp1_long,temp2_long); @@ -4950,8 +4950,8 @@ hsize_t diff_long(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_long, mem1, sizeof(long)); - memcpy(&temp2_long, mem2, sizeof(long)); + HDmemcpy(&temp1_long, mem1, sizeof(long)); + HDmemcpy(&temp2_long, mem2, sizeof(long)); PER(temp1_long,temp2_long); @@ -4993,8 +4993,8 @@ hsize_t diff_long(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_long, mem1, sizeof(long)); - memcpy(&temp2_long, mem2, sizeof(long)); + HDmemcpy(&temp1_long, mem1, sizeof(long)); + HDmemcpy(&temp2_long, mem2, sizeof(long)); if (temp1_long != temp2_long) { @@ -5061,8 +5061,8 @@ hsize_t diff_ulong(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_ulong, mem1, sizeof(unsigned long)); - memcpy(&temp2_ulong, mem2, sizeof(unsigned long)); + HDmemcpy(&temp1_ulong, mem1, sizeof(unsigned long)); + HDmemcpy(&temp2_ulong, mem2, sizeof(unsigned long)); if ( PDIFF(temp1_ulong,temp2_ulong) > options->delta) { @@ -5090,8 +5090,8 @@ hsize_t diff_ulong(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_ulong, mem1, sizeof(unsigned long)); - memcpy(&temp2_ulong, mem2, sizeof(unsigned long)); + HDmemcpy(&temp1_ulong, mem1, sizeof(unsigned long)); + HDmemcpy(&temp2_ulong, mem2, sizeof(unsigned long)); PER_UNSIGN(signed long,temp1_ulong,temp2_ulong); @@ -5135,8 +5135,8 @@ hsize_t diff_ulong(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_ulong, mem1, sizeof(unsigned long)); - memcpy(&temp2_ulong, mem2, sizeof(unsigned long)); + HDmemcpy(&temp1_ulong, mem1, sizeof(unsigned long)); + HDmemcpy(&temp2_ulong, mem2, sizeof(unsigned long)); PER_UNSIGN(signed long,temp1_ulong,temp2_ulong); @@ -5177,8 +5177,8 @@ hsize_t diff_ulong(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_ulong, mem1, sizeof(unsigned long)); - memcpy(&temp2_ulong, mem2, sizeof(unsigned long)); + HDmemcpy(&temp1_ulong, mem1, sizeof(unsigned long)); + HDmemcpy(&temp2_ulong, mem2, sizeof(unsigned long)); if (temp1_ulong != temp2_ulong) { @@ -5240,8 +5240,8 @@ hsize_t diff_llong(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_llong, mem1, sizeof(long long)); - memcpy(&temp2_llong, mem2, sizeof(long long)); + HDmemcpy(&temp1_llong, mem1, sizeof(long long)); + HDmemcpy(&temp2_llong, mem2, sizeof(long long)); if (ABS( temp1_llong-temp2_llong) > options->delta) { @@ -5267,8 +5267,8 @@ hsize_t diff_llong(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_llong, mem1, sizeof(long long)); - memcpy(&temp2_llong, mem2, sizeof(long long)); + HDmemcpy(&temp1_llong, mem1, sizeof(long long)); + HDmemcpy(&temp2_llong, mem2, sizeof(long long)); PER(temp1_llong,temp2_llong); @@ -5310,8 +5310,8 @@ hsize_t diff_llong(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_llong, mem1, sizeof(long long)); - memcpy(&temp2_llong, mem2, sizeof(long long)); + HDmemcpy(&temp1_llong, mem1, sizeof(long long)); + HDmemcpy(&temp2_llong, mem2, sizeof(long long)); PER(temp1_llong,temp2_llong); @@ -5350,8 +5350,8 @@ hsize_t diff_llong(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_llong, mem1, sizeof(long long)); - memcpy(&temp2_llong, mem2, sizeof(long long)); + HDmemcpy(&temp1_llong, mem1, sizeof(long long)); + HDmemcpy(&temp2_llong, mem2, sizeof(long long)); if (temp1_llong != temp2_llong) { @@ -5414,8 +5414,8 @@ hsize_t diff_ullong(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_ullong, mem1, sizeof(unsigned long long)); - memcpy(&temp2_ullong, mem2, sizeof(unsigned long long)); + HDmemcpy(&temp1_ullong, mem1, sizeof(unsigned long long)); + HDmemcpy(&temp2_ullong, mem2, sizeof(unsigned long long)); if ( PDIFF(temp1_ullong,temp2_ullong) > (unsigned long long) options->delta) { @@ -5441,8 +5441,8 @@ hsize_t diff_ullong(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_ullong, mem1, sizeof(unsigned long long)); - memcpy(&temp2_ullong, mem2, sizeof(unsigned long long)); + HDmemcpy(&temp1_ullong, mem1, sizeof(unsigned long long)); + HDmemcpy(&temp2_ullong, mem2, sizeof(unsigned long long)); ull2float(temp1_ullong,&f1); ull2float(temp2_ullong,&f2); @@ -5486,8 +5486,8 @@ hsize_t diff_ullong(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_ullong, mem1, sizeof(unsigned long long)); - memcpy(&temp2_ullong, mem2, sizeof(unsigned long long)); + HDmemcpy(&temp1_ullong, mem1, sizeof(unsigned long long)); + HDmemcpy(&temp2_ullong, mem2, sizeof(unsigned long long)); ull2float(temp1_ullong,&f1); ull2float(temp2_ullong,&f2); @@ -5528,8 +5528,8 @@ hsize_t diff_ullong(unsigned char *mem1, for ( i = 0; i < nelmts; i++) { - memcpy(&temp1_ullong, mem1, sizeof(unsigned long long)); - memcpy(&temp2_ullong, mem2, sizeof(unsigned long long)); + HDmemcpy(&temp1_ullong, mem1, sizeof(unsigned long long)); + HDmemcpy(&temp2_ullong, mem2, sizeof(unsigned long long)); if (temp1_ullong != temp2_ullong) { @@ -5580,18 +5580,18 @@ int ull2float(unsigned long long ull_value, float *f_value) src_size = H5Tget_size(H5T_NATIVE_ULLONG); dst_size = H5Tget_size(H5T_NATIVE_FLOAT); - buf = (unsigned char*)calloc(1, MAX(src_size, dst_size)); + buf = (unsigned char*)HDcalloc(1, MAX(src_size, dst_size)); - memcpy(buf, &ull_value, src_size); + HDmemcpy(buf, &ull_value, src_size); /* do conversion */ if(H5Tconvert(H5T_NATIVE_ULLONG, H5T_NATIVE_FLOAT, 1, buf, NULL, dxpl_id)<0) goto error; - memcpy(f_value, buf, dst_size); + HDmemcpy(f_value, buf, dst_size); if(buf) - free(buf); + HDfree(buf); return 0; @@ -5600,7 +5600,7 @@ error: H5Pclose(dxpl_id); } H5E_END_TRY; if(buf) - free(buf); + HDfree(buf); return -1; } @@ -5774,13 +5774,13 @@ hbool_t equal_float(float value, float expected, diff_opt_t *options) /*------------------------------------------------------------------------- - * Function: my_isnan + * Function: my_isnan * - * Purpose: Determines whether VAL points to NaN. + * Purpose: Determines whether VAL points to NaN. * - * Return: TRUE or FALSE + * Return: TRUE or FALSE * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Monday, July 6, 1998 * * Modifications: @@ -5995,7 +5995,7 @@ void print_pos( int *ph, /* print header */ pos[i] = curr_pos/acc[i]; curr_pos -= acc[i]*pos[i]; } - assert( curr_pos == 0 ); + HDassert( curr_pos == 0 ); if ( rank > 0 ) { @@ -6048,7 +6048,7 @@ void print_char_pos( int *ph, /* print header */ pos[i] = curr_pos/acc[i]; curr_pos -= acc[i]*pos[i]; } - assert( curr_pos == 0 ); + HDassert( curr_pos == 0 ); parallel_print("[ " ); if ( rank > 0 ) diff --git a/tools/lib/h5diff_dset.c b/tools/lib/h5diff_dset.c index 03ec067..c1ed429 100644 --- a/tools/lib/h5diff_dset.c +++ b/tools/lib/h5diff_dset.c @@ -409,7 +409,7 @@ hsize_t diff_datasetid( hid_t did1, options, name1, name2, m_tid1, did1, did2); /* reclaim any VL memory, if necessary */ - if(vl_data) { + if(vl_data) { H5Dvlen_reclaim(m_tid1, sid1, H5P_DEFAULT, buf1); H5Dvlen_reclaim(m_tid2, sid2, H5P_DEFAULT, buf2); } /* end if */ @@ -445,27 +445,27 @@ hsize_t diff_datasetid( hid_t did1, size = 1; sm_size[i - 1] = MIN(dims1[i - 1], size); sm_nbytes *= sm_size[i - 1]; - assert(sm_nbytes > 0); + HDassert(sm_nbytes > 0); } /* end for */ - /* malloc return code should be verified. + /* malloc return code should be verified. * If fail, need to handle the error. * This else branch should be recoded as a separate function. * Note that there are many "goto error" within this branch * that fails to address freeing other objects created here. - * E.g., sm_space. - */ - sm_buf1 = malloc((size_t)sm_nbytes); - assert(sm_buf1); - sm_buf2 = malloc((size_t)sm_nbytes); - assert(sm_buf2); + * E.g., sm_space. + */ + sm_buf1 = HDmalloc((size_t)sm_nbytes); + HDassert(sm_buf1); + sm_buf2 = HDmalloc((size_t)sm_nbytes); + HDassert(sm_buf2); sm_nelmts = sm_nbytes / p_type_nbytes; sm_space = H5Screate_simple(1, &sm_nelmts, NULL); /* the stripmine loop */ - memset(hs_offset, 0, sizeof hs_offset); - memset(zero, 0, sizeof zero); + HDmemset(hs_offset, 0, sizeof hs_offset); + HDmemset(zero, 0, sizeof zero); for(elmtno = 0; elmtno < p_nelmts; elmtno += hs_nelmts) { /* calculate the hyperslab size */ @@ -529,19 +529,19 @@ hsize_t diff_datasetid( hid_t did1, /* free */ if(buf1 != NULL) { - free(buf1); + HDfree(buf1); buf1 = NULL; } /* end if */ if(buf2 != NULL) { - free(buf2); + HDfree(buf2); buf2 = NULL; } /* end if */ if(sm_buf1 != NULL) { - free(sm_buf1); + HDfree(sm_buf1); sm_buf1 = NULL; } /* end if */ if(sm_buf2 != NULL) { - free(sm_buf2); + HDfree(sm_buf2); sm_buf2 = NULL; } /* end if */ @@ -565,7 +565,7 @@ error: /* reclaim any VL memory, if necessary */ if(vl_data) H5Dvlen_reclaim(m_tid1, sid1, H5P_DEFAULT, buf1); - free(buf1); + HDfree(buf1); buf1=NULL; } if (buf2!=NULL) @@ -573,7 +573,7 @@ error: /* reclaim any VL memory, if necessary */ if(vl_data) H5Dvlen_reclaim(m_tid2, sid2, H5P_DEFAULT, buf2); - free(buf2); + HDfree(buf2); buf2=NULL; } if (sm_buf1!=NULL) @@ -581,7 +581,7 @@ error: /* reclaim any VL memory, if necessary */ if(vl_data) H5Dvlen_reclaim(m_tid1, sm_space, H5P_DEFAULT, sm_buf1); - free(sm_buf1); + HDfree(sm_buf1); sm_buf1=NULL; } if (sm_buf2!=NULL) @@ -589,7 +589,7 @@ error: /* reclaim any VL memory, if necessary */ if(vl_data) H5Dvlen_reclaim(m_tid1, sm_space, H5P_DEFAULT, sm_buf2); - free(sm_buf2); + HDfree(sm_buf2); sm_buf2=NULL; } @@ -695,7 +695,7 @@ int diff_can_type( hid_t f_tid1, /* file data type */ *------------------------------------------------------------------------- */ - assert(tclass1==tclass2); + HDassert(tclass1==tclass2); switch (tclass1) { case H5T_INTEGER: @@ -784,7 +784,7 @@ int diff_can_type( hid_t f_tid1, /* file data type */ *------------------------------------------------------------------------- */ - assert(rank1==rank2); + HDassert(rank1==rank2); for ( i=0; i<rank1; i++) { if (maxdim1 && maxdim2) diff --git a/tools/lib/h5diff_util.c b/tools/lib/h5diff_util.c index dfdc8b3..0d476b6 100644 --- a/tools/lib/h5diff_util.c +++ b/tools/lib/h5diff_util.c @@ -183,7 +183,7 @@ diff_basename(const char *name) return NULL; /* Find the end of the base name */ - i = strlen(name); + i = HDstrlen(name); while (i>0 && '/'==name[i-1]) --i; diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index db81496..0d29686 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -25,6 +25,7 @@ #include <stdlib.h> #include "h5tools.h" +#include "h5tools_dump.h" #include "h5tools_ref.h" #include "h5tools_utils.h" #include "H5private.h" @@ -38,223 +39,20 @@ hid_t H5tools_ERR_CLS_g = -1; hid_t H5E_tools_g = -1; hid_t H5E_tools_min_id_g = -1; int compound_data; -FILE *rawdatastream; /* should initialize to stdout but gcc moans about it */ -int bin_output; /* binary output */ -int bin_form; /* binary form */ -int region_output; /* region output */ -int packed_bits_num; /* number of packed bits to display */ +FILE *rawdatastream; /* should initialize to stdout but gcc moans about it */ +FILE *rawoutstream; /* should initialize to stdout but gcc moans about it */ +FILE *rawerrorstream; /* should initialize to stderr but gcc moans about it */ +int bin_output; /* binary output */ +int bin_form; /* binary form */ +int region_output; /* region output */ +int oid_output; /* oid output */ +int data_output; /* data output */ +int attr_data_output; /* attribute data output */ +int packed_bits_num; /* number of packed bits to display */ int packed_data_offset; /* offset of packed bits to display */ +int packed_data_length; /* lengtht of packed bits to display */ unsigned long long packed_data_mask; /* mask in which packed bits to display */ -static h5tool_format_t h5tools_dataformat = { -0, /*raw */ - -"", /*fmt_raw */ -"%d", /*fmt_int */ -"%u", /*fmt_uint */ -#ifdef H5_VMS -"%hd",/*fmt_schar */ -#else -"%hhd",/*fmt_schar */ -#endif -"%u", /*fmt_uchar */ -"%d", /*fmt_short */ -"%u", /*fmt_ushort */ -"%ld", /*fmt_long */ -"%lu", /*fmt_ulong */ -NULL, /*fmt_llong */ -NULL, /*fmt_ullong */ -"%g", /*fmt_double */ -"%g", /*fmt_float */ - -0, /*ascii */ -0, /*str_locale */ -0, /*str_repeat */ - -"[ ", /*arr_pre */ -",", /*arr_sep */ -" ]", /*arr_suf */ -1, /*arr_linebreak */ - -"", /*cmpd_name */ -",\n", /*cmpd_sep */ -"{\n", /*cmpd_pre */ -"}", /*cmpd_suf */ -"\n", /*cmpd_end */ - -", ", /*vlen_sep */ -"(", /*vlen_pre */ -")", /*vlen_suf */ -"", /*vlen_end */ - -"%s", /*elmt_fmt */ -",", /*elmt_suf1 */ -" ", /*elmt_suf2 */ - -"", /*idx_n_fmt */ -"", /*idx_sep */ -"", /*idx_fmt */ - -80, /*line_ncols *//*standard default columns */ -0, /*line_per_line */ -"", /*line_pre */ -"%s", /*line_1st */ -"%s", /*line_cont */ -"", /*line_suf */ -"", /*line_sep */ -1, /*line_multi_new */ -" ", /*line_indent */ - -1, /*skip_first */ - -1, /*obj_hidefileno */ -" "H5_PRINTF_HADDR_FMT, /*obj_format */ - -1, /*dset_hidefileno */ -"DATASET %s ", /*dset_format */ -"%s", /*dset_blockformat_pre */ -"%s", /*dset_ptformat_pre */ -"%s", /*dset_ptformat */ -1, /*array indices */ -1 /*escape non printable characters */ -}; - -static const h5tools_dump_header_t h5tools_standardformat = { -"standardformat", /*name */ -"HDF5", /*fileebgin */ -"", /*fileend */ -SUPER_BLOCK, /*bootblockbegin */ -"", /*bootblockend */ -H5_TOOLS_GROUP, /*groupbegin */ -"", /*groupend */ -H5_TOOLS_DATASET, /*datasetbegin */ -"", /*datasetend */ -ATTRIBUTE, /*attributebegin */ -"", /*attributeend */ -H5_TOOLS_DATATYPE, /*datatypebegin */ -"", /*datatypeend */ -DATASPACE, /*dataspacebegin */ -"", /*dataspaceend */ -DATA, /*databegin */ -"", /*dataend */ -SOFTLINK, /*softlinkbegin */ -"", /*softlinkend */ -EXTLINK, /*extlinkbegin */ -"", /*extlinkend */ -UDLINK, /*udlinkbegin */ -"", /*udlinkend */ -SUBSET, /*subsettingbegin */ -"", /*subsettingend */ -START, /*startbegin */ -"", /*startend */ -STRIDE, /*stridebegin */ -"", /*strideend */ -COUNT, /*countbegin */ -"", /*countend */ -BLOCK, /*blockbegin */ -"", /*blockend */ - -"{", /*fileblockbegin */ -"}", /*fileblockend */ -"{", /*bootblockblockbegin */ -"}", /*bootblockblockend */ -"{", /*groupblockbegin */ -"}", /*groupblockend */ -"{", /*datasetblockbegin */ -"}", /*datasetblockend */ -"{", /*attributeblockbegin */ -"}", /*attributeblockend */ -"", /*datatypeblockbegin */ -"", /*datatypeblockend */ -"", /*dataspaceblockbegin */ -"", /*dataspaceblockend */ -"{", /*datablockbegin */ -"}", /*datablockend */ -"{", /*softlinkblockbegin */ -"}", /*softlinkblockend */ -"{", /*extlinkblockbegin */ -"}", /*extlinkblockend */ -"{", /*udlinkblockbegin */ -"}", /*udlinkblockend */ -"{", /*strblockbegin */ -"}", /*strblockend */ -"{", /*enumblockbegin */ -"}", /*enumblockend */ -"{", /*structblockbegin */ -"}", /*structblockend */ -"{", /*vlenblockbegin */ -"}", /*vlenblockend */ -"{", /*subsettingblockbegin */ -"}", /*subsettingblockend */ -"(", /*startblockbegin */ -");", /*startblockend */ -"(", /*strideblockbegin */ -");", /*strideblockend */ -"(", /*countblockbegin */ -");", /*countblockend */ -"(", /*blockblockbegin */ -");", /*blockblockend */ - -"", /*dataspacedescriptionbegin */ -"", /*dataspacedescriptionend */ -"(", /*dataspacedimbegin */ -")", /*dataspacedimend */ -}; - -static const h5tools_dump_header_t * h5tools_dump_header_format; - -/* local prototypes */ -static int do_bin_output(FILE *stream, hid_t container, hsize_t nelmts, hid_t tid, void *_mem); -static int render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem); -static int render_bin_output_region_data_blocks(hid_t region_id, FILE *stream, - hid_t container, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata); -static hbool_t render_bin_output_region_blocks(hid_t region_space, hid_t region_id, - FILE *stream, hid_t container); -static hbool_t render_bin_output_region_points(hid_t region_space, hid_t region_id, - FILE *stream, hid_t container); -static hbool_t h5tools_is_zero(const void *_mem, size_t size); - -hbool_t h5tools_render_element(FILE *stream, const h5tool_format_t *info, - h5tools_context_t *ctx/*in,out*/, - h5tools_str_t *buffer/*string into which to render */, - hsize_t *curr_pos/*total data element position*/, - size_t ncols, hsize_t local_elmt_counter/*element counter*/, - hsize_t elmt_counter); - -hbool_t h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, - h5tools_context_t *ctx/*in,out*/, - h5tools_str_t *buffer/*string into which to render */, - hsize_t *curr_pos/*total data element position*/, - size_t ncols, hsize_t *ptdata, - hsize_t local_elmt_counter/*element counter*/, - hsize_t elmt_counter); - -static int h5tools_print_region_data_blocks(hid_t region_id, - FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx, - h5tools_str_t *buffer/*string into which to render */, size_t ncols, - int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata); - -hbool_t h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, - FILE *stream, const h5tool_format_t *info, - h5tools_context_t *ctx/*in,out*/, - h5tools_str_t *buffer/*string into which to render */, - hsize_t *curr_pos/*total data element position*/, - size_t ncols, hsize_t region_elmt_counter/*element counter*/, - hsize_t elmt_counter); - -int h5tools_print_region_data_points(hid_t region_space, hid_t region_id, - FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx, - h5tools_str_t *buffer, size_t ncols, - int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata); - -hbool_t h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, - FILE *stream, const h5tool_format_t *info, - h5tools_context_t *ctx/*in,out*/, - h5tools_str_t *buffer/*string into which to render */, - hsize_t *curr_pos/*total data element position*/, - size_t ncols, hsize_t region_elmt_counter/*element counter*/, - hsize_t elmt_counter); - /* module-scoped variables */ static int h5tools_init_g; /* if h5tools lib has been initialized */ #ifdef H5_HAVE_PARALLEL @@ -321,8 +119,12 @@ h5tools_init(void) if (!rawdatastream) rawdatastream = stdout; + if (!rawoutstream) + rawoutstream = stdout; + if (!rawerrorstream) + rawerrorstream = stderr; - h5tools_dump_header_format = &h5tools_standardformat; + h5tools_dump_init(); h5tools_init_g++; } @@ -354,6 +156,18 @@ h5tools_close(void) else rawdatastream = NULL; } + if (rawoutstream && rawoutstream != stdout) { + if (fclose(rawoutstream)) + perror("closing rawoutstream"); + else + rawoutstream = NULL; + } + if (rawerrorstream && rawerrorstream != stderr) { + if (fclose(rawerrorstream)) + perror("closing rawerrorstream"); + else + rawerrorstream = NULL; + } /* Clean up the reference path table, if it's been used */ term_ref_path_table(); @@ -399,7 +213,7 @@ h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) /* Determine which driver the user wants to open the file with. Try * that driver. If it can't open it, then fail. */ - if (!strcmp(driver, drivernames[SEC2_IDX])) { + if (!HDstrcmp(driver, drivernames[SEC2_IDX])) { /* SEC2 driver */ if (H5Pset_fapl_sec2(new_fapl) < 0) goto error; @@ -407,7 +221,7 @@ h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) if (drivernum) *drivernum = SEC2_IDX; } - else if (!strcmp(driver, drivernames[FAMILY_IDX])) { + else if (!HDstrcmp(driver, drivernames[FAMILY_IDX])) { /* FAMILY Driver */ /* Set member size to be 0 to indicate the current first member size @@ -419,7 +233,7 @@ h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) if (drivernum) *drivernum = FAMILY_IDX; } - else if (!strcmp(driver, drivernames[SPLIT_IDX])) { + else if (!HDstrcmp(driver, drivernames[SPLIT_IDX])) { /* SPLIT Driver */ if (H5Pset_fapl_split(new_fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT) < 0) goto error; @@ -427,7 +241,7 @@ h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) if (drivernum) *drivernum = SPLIT_IDX; } - else if (!strcmp(driver, drivernames[MULTI_IDX])) { + else if (!HDstrcmp(driver, drivernames[MULTI_IDX])) { /* MULTI Driver */ if (H5Pset_fapl_multi(new_fapl, NULL, NULL, NULL, NULL, TRUE) < 0) goto error; @@ -436,7 +250,7 @@ h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) *drivernum = MULTI_IDX; #ifdef H5_HAVE_STREAM } - else if(!strcmp(driver, drivernames[STREAM_IDX])) { + else if(!HDstrcmp(driver, drivernames[STREAM_IDX])) { /* STREAM Driver */ if(H5Pset_fapl_stream(new_fapl, NULL) < 0) goto error; @@ -446,7 +260,7 @@ h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) #endif /* H5_HAVE_STREAM */ #ifdef H5_HAVE_PARALLEL } - else if(!strcmp(driver, drivernames[MPIO_IDX])) { + else if(!HDstrcmp(driver, drivernames[MPIO_IDX])) { /* MPI-I/O Driver */ /* check if MPI has been initialized. */ if(!h5tools_mpi_init_g) @@ -459,7 +273,7 @@ h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) *drivernum = MPIO_IDX; } /* end if */ } - else if (!strcmp(driver, drivernames[MPIPOSIX_IDX])) { + else if (!HDstrcmp(driver, drivernames[MPIPOSIX_IDX])) { /* MPI-I/O Driver */ /* check if MPI has been initialized. */ if(!h5tools_mpi_init_g) @@ -585,7 +399,7 @@ h5tools_fopen(const char *fname, unsigned flags, hid_t fapl, const char *driver, /* Save the driver name */ if (drivername && drivername_size) { if (fid != FAIL) { - strncpy(drivername, drivernames[drivernum], drivername_size); + HDstrncpy(drivername, drivernames[drivernum], drivername_size); drivername[drivername_size - 1] = '\0'; } else { @@ -617,7 +431,7 @@ done: *------------------------------------------------------------------------- */ static size_t -h5tools_ncols(const char *s) +h5tools_count_ncols(const char *s) { register size_t i; @@ -743,7 +557,7 @@ done: * level before) *------------------------------------------------------------------------- */ -static void +void h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hsize_t elmtno, int secnum) { @@ -755,14 +569,14 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, if (!ctx->need_prefix) return; - memset(&prefix, 0, sizeof(h5tools_str_t)); - memset(&str, 0, sizeof(h5tools_str_t)); + HDmemset(&prefix, 0, sizeof(h5tools_str_t)); + HDmemset(&str, 0, sizeof(h5tools_str_t)); /* Terminate previous line, if any */ if (ctx->cur_column) { - fputs(OPT(info->line_suf, ""), stream); - putc('\n', stream); - fputs(OPT(info->line_sep, ""), stream); + HDfputs(OPT(info->line_suf, ""), stream); + HDputc('\n', stream); + HDfputs(OPT(info->line_sep, ""), stream); } /* Calculate new prefix */ @@ -786,23 +600,23 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, the prefix is printed one indentation level before */ if (info->pindex) { for (i = 0; i < indentlevel - 1; i++) { - fputs(h5tools_str_fmt(&str, 0, info->line_indent), stream); + HDfputs(h5tools_str_fmt(&str, 0, info->line_indent), stream); } } if (elmtno == 0 && secnum == 0 && info->line_1st) - fputs(h5tools_str_fmt(&prefix, 0, info->line_1st), stream); + HDfputs(h5tools_str_fmt(&prefix, 0, info->line_1st), stream); else if (secnum && info->line_cont) - fputs(h5tools_str_fmt(&prefix, 0, info->line_cont), stream); + HDfputs(h5tools_str_fmt(&prefix, 0, info->line_cont), stream); else - fputs(h5tools_str_fmt(&prefix, 0, info->line_pre), stream); + HDfputs(h5tools_str_fmt(&prefix, 0, info->line_pre), stream); templength = h5tools_str_len(&prefix); for (i = 0; i < indentlevel; i++) { /*we already made the indent for the array indices case */ if (!info->pindex) { - fputs(h5tools_str_fmt(&prefix, 0, info->line_indent), stream); + HDfputs(h5tools_str_fmt(&prefix, 0, info->line_indent), stream); templength += h5tools_str_len(&prefix); } else { @@ -832,7 +646,7 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, * None *------------------------------------------------------------------------- */ -static void +void h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hsize_t elmtno, hsize_t *ptdata, int secnum) { @@ -844,14 +658,14 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, if (!ctx->need_prefix) return; - memset(&prefix, 0, sizeof(h5tools_str_t)); - memset(&str, 0, sizeof(h5tools_str_t)); + HDmemset(&prefix, 0, sizeof(h5tools_str_t)); + HDmemset(&str, 0, sizeof(h5tools_str_t)); /* Terminate previous line, if any */ if (ctx->cur_column) { - fputs(OPT(info->line_suf, ""), stream); - putc('\n', stream); - fputs(OPT(info->line_sep, ""), stream); + HDfputs(OPT(info->line_suf, ""), stream); + HDputc('\n', stream); + HDfputs(OPT(info->line_sep, ""), stream); } /* Calculate new prefix */ @@ -875,23 +689,23 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, the prefix is printed one indentation level before */ if (info->pindex) { for (i = 0; i < indentlevel - 1; i++) { - fputs(h5tools_str_fmt(&str, 0, info->line_indent), stream); + HDfputs(h5tools_str_fmt(&str, 0, info->line_indent), stream); } } if (elmtno == 0 && secnum == 0 && info->line_1st) - fputs(h5tools_str_fmt(&prefix, 0, info->line_1st), stream); + HDfputs(h5tools_str_fmt(&prefix, 0, info->line_1st), stream); else if (secnum && info->line_cont) - fputs(h5tools_str_fmt(&prefix, 0, info->line_cont), stream); + HDfputs(h5tools_str_fmt(&prefix, 0, info->line_cont), stream); else - fputs(h5tools_str_fmt(&prefix, 0, info->line_pre), stream); + HDfputs(h5tools_str_fmt(&prefix, 0, info->line_pre), stream); templength = h5tools_str_len(&prefix); for (i = 0; i < indentlevel; i++) { /*we already made the indent for the array indices case */ if (!info->pindex) { - fputs(h5tools_str_fmt(&prefix, 0, info->line_indent), stream); + HDfputs(h5tools_str_fmt(&prefix, 0, info->line_indent), stream); templength += h5tools_str_len(&prefix); } else { @@ -912,159 +726,6 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, /*------------------------------------------------------------------------- * Audience: Public * Chapter: H5Tools Library - * Purpose: Prints NELMTS data elements to output STREAM. - * Description: - * Prints some (NELMTS) data elements to output STREAM. The elements are - * stored in _MEM as type TYPE and are printed according to the format - * described in INFO. The CTX struct contains context information shared - * between calls to this function. The FLAGS is a bit field that - * indicates whether the data supplied in this call falls at the - * beginning or end of the total data to be printed (START_OF_DATA and - * END_OF_DATA). - * Return: - * None - * Programmer: - * Robb Matzke, Monday, April 26, 1999 - * Modifications: - * Robb Matzke, 1999-06-04 - * The `container' argument is the optional dataset for reference types. - * - * Robb Matzke, 1999-09-29 - * Understands the `per_line' property which indicates that every Nth - * element should begin a new line. - * - * Robb Matzke, LLNL, 2003-06-05 - * Do not dereference the memory for a variable-length string here. - * Deref in h5tools_str_sprint() instead so recursive types are - * handled correctly. - * - * Pedro Vicente Nunes, The HDF Group, 2005-10-19 - * pass to the prefix in h5tools_simple_prefix the total position - * instead of the current stripmine position i; this is necessary - * to print the array indices - * new field sm_pos in h5tools_context_t, the current stripmine element position - *------------------------------------------------------------------------- - */ -void -h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t container, - h5tools_context_t *ctx/*in,out*/, unsigned flags, - hsize_t nelmts, hid_t type, void *_mem) -{ - unsigned char *mem = (unsigned char*) _mem; - hsize_t i; /*element counter */ - size_t size; /*size of each datum */ - hid_t region_space; - hid_t region_id; - hbool_t dimension_break = TRUE; - H5S_sel_type region_type; - size_t ncols = 80; /*available output width */ - h5tools_str_t buffer; /*string into which to render */ - hsize_t curr_pos; /* total data element position */ - hsize_t elmt_counter = 0;/*counts the # elements printed. - *I (ptl?) needed something that - *isn't going to get reset when a new - *line is formed. I'm going to use - *this var to count elements and - *break after we see a number equal - *to the ctx->size_last_dim. */ - - /* binary dump */ - if (bin_output) { - do_bin_output(rawdatastream, container, nelmts, type, _mem); - } /* end if */ - else { - /* setup */ - HDmemset(&buffer, 0, sizeof(h5tools_str_t)); - size = H5Tget_size(type); - - if (info->line_ncols > 0) - ncols = info->line_ncols; - - /* pass to the prefix in h5tools_simple_prefix the total position - * instead of the current stripmine position i; this is necessary - * to print the array indices - */ - curr_pos = ctx->sm_pos; - - for (i = 0; i < nelmts; i++, ctx->cur_elmt++, elmt_counter++) { - void* memref = mem + i * size; - if (region_output && H5Tequal(type, H5T_STD_REF_DSETREG)) { - char ref_name[1024]; - - /* region data */ - region_id = H5Rdereference(container, H5R_DATASET_REGION, memref); - if (region_id >= 0) { - region_space = H5Rget_region(container, H5R_DATASET_REGION, memref); - if (region_space >= 0) { - if (h5tools_is_zero(memref, H5Tget_size(type))) { - h5tools_str_append(&buffer, "NULL"); - } - else { - if(H5Rget_name(region_id, H5R_DATASET_REGION, memref, (char*) ref_name, 1024)<0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Rget_name failed"); - - /* Render the region element begin */ - h5tools_str_reset(&buffer); - - h5tools_str_append(&buffer, info->dset_format, ref_name); - - dimension_break = h5tools_render_element(stdout, info, - ctx, &buffer, &curr_pos, ncols, i, elmt_counter); - - region_type = H5Sget_select_type(region_space); - if(region_type==H5S_SEL_POINTS) - /* Print point information */ - dimension_break = h5tools_dump_region_data_points( - region_space, region_id, stdout, info, ctx, - &buffer, &curr_pos, ncols, i, elmt_counter); - else if(region_type==H5S_SEL_HYPERSLABS) - /* Print block information */ - dimension_break = h5tools_dump_region_data_blocks( - region_space, region_id, stdout, info, ctx, - &buffer, &curr_pos, ncols, i, elmt_counter); - else - HERROR(H5E_tools_g, H5E_tools_min_id_g, "invalid region type"); - /* Render the region element end */ - - } /* end else to if (h5tools_is_zero(... */ - if(H5Sclose(region_space) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); - } /* end if (region_space >= 0) */ - else - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Rget_region failed"); - if(H5Dclose(region_id) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dclose failed"); - - } /* if (region_id >= 0) */ - else - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Rdereference failed"); - - ctx->need_prefix = TRUE; - } /* end if (region_output... */ - else { - /* Render the data element begin*/ - h5tools_str_reset(&buffer); - h5tools_str_sprint(&buffer, info, container, type, memref, ctx); - - if (i + 1 < nelmts || (flags & END_OF_DATA) == 0) - h5tools_str_append(&buffer, "%s", OPT(info->elmt_suf1, ",")); - - dimension_break = h5tools_render_element(stream, info, ctx, &buffer, - &curr_pos, ncols, i, elmt_counter); - /* Render the data element end*/ - - } - if(FALSE==dimension_break) - elmt_counter = 0; - } /* end for (i = 0; i < nelmts... */ - - h5tools_str_close(&buffer); - }/* else bin */ -} - -/*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library * Purpose: Render an element to output STREAM. * Description: * Prints the string buffer to the output STREAM. The string is @@ -1105,9 +766,9 @@ h5tools_render_element(FILE *stream, const h5tool_format_t *info, * current location... */ if (info->line_multi_new == 1 && - (ctx->cur_column + h5tools_ncols(s) + - strlen(OPT(info->elmt_suf2, " ")) + - strlen(OPT(info->line_suf, ""))) > ncols) { + (ctx->cur_column + h5tools_count_ncols(s) + + HDstrlen(OPT(info->elmt_suf2, " ")) + + HDstrlen(OPT(info->line_suf, ""))) > ncols) { if (ctx->prev_multiline) { /* * ... and the previous element also occupied more than one @@ -1115,9 +776,9 @@ h5tools_render_element(FILE *stream, const h5tool_format_t *info, */ ctx->need_prefix = TRUE; } - else if ((ctx->prev_prefix_len + h5tools_ncols(s) + - strlen(OPT(info->elmt_suf2, " ")) + - strlen(OPT(info->line_suf, ""))) <= ncols) { + else if ((ctx->prev_prefix_len + h5tools_count_ncols(s) + + HDstrlen(OPT(info->elmt_suf2, " ")) + + HDstrlen(OPT(info->line_suf, ""))) <= ncols) { /* * ...but *could* fit on one line otherwise, then we * should end the current line and start this element on its @@ -1150,9 +811,9 @@ h5tools_render_element(FILE *stream, const h5tool_format_t *info, if (info->line_multi_new == 1 && ctx->prev_multiline && (ctx->cur_column + - h5tools_ncols(s) + - strlen(OPT(info->elmt_suf2, " ")) + - strlen(OPT(info->line_suf, ""))) > ncols) + h5tools_count_ncols(s) + + HDstrlen(OPT(info->elmt_suf2, " ")) + + HDstrlen(OPT(info->line_suf, ""))) > ncols) ctx->need_prefix = TRUE; /* @@ -1169,7 +830,7 @@ h5tools_render_element(FILE *stream, const h5tool_format_t *info, */ multiline = 0; for (secnum = 0, multiline = 0; - (section = strtok(secnum ? NULL : s, OPTIONAL_LINE_BREAK)); + (section = HDstrtok(secnum ? NULL : s, OPTIONAL_LINE_BREAK)); secnum++) { /* * If the current section plus possible suffix and end-of-line @@ -1180,9 +841,9 @@ h5tools_render_element(FILE *stream, const h5tool_format_t *info, /* * check for displaying prefix for each section */ - if ( (ctx->cur_column + strlen(section) + - strlen(OPT(info->elmt_suf2, " ")) + - strlen(OPT(info->line_suf, ""))) > ncols) + if ( (ctx->cur_column + HDstrlen(section) + + HDstrlen(OPT(info->elmt_suf2, " ")) + + HDstrlen(OPT(info->line_suf, ""))) > ncols) ctx->need_prefix = 1; /* @@ -1202,13 +863,13 @@ h5tools_render_element(FILE *stream, const h5tool_format_t *info, h5tools_simple_prefix(stream, info, ctx, *curr_pos, secnum); } else if ((local_elmt_counter || ctx->continuation) && secnum == 0) { - fputs(OPT(info->elmt_suf2, " "), stream); - ctx->cur_column += strlen(OPT(info->elmt_suf2, " ")); + HDfputs(OPT(info->elmt_suf2, " "), stream); + ctx->cur_column += HDstrlen(OPT(info->elmt_suf2, " ")); } /* Print the section */ - fputs(section, stream); - ctx->cur_column += strlen(section); + HDfputs(section, stream); + ctx->cur_column += HDstrlen(section); } ctx->prev_multiline = multiline; @@ -1259,9 +920,9 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, * current location... */ if (info->line_multi_new == 1 && - (ctx->cur_column + h5tools_ncols(s) + - strlen(OPT(info->elmt_suf2, " ")) + - strlen(OPT(info->line_suf, ""))) > ncols) { + (ctx->cur_column + h5tools_count_ncols(s) + + HDstrlen(OPT(info->elmt_suf2, " ")) + + HDstrlen(OPT(info->line_suf, ""))) > ncols) { if (ctx->prev_multiline) { /* * ... and the previous element also occupied more than one @@ -1269,9 +930,9 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, */ ctx->need_prefix = TRUE; } - else if ((ctx->prev_prefix_len + h5tools_ncols(s) + - strlen(OPT(info->elmt_suf2, " ")) + - strlen(OPT(info->line_suf, ""))) <= ncols) { + else if ((ctx->prev_prefix_len + h5tools_count_ncols(s) + + HDstrlen(OPT(info->elmt_suf2, " ")) + + HDstrlen(OPT(info->line_suf, ""))) <= ncols) { /* * ...but *could* fit on one line otherwise, then we * should end the current line and start this element on its @@ -1304,9 +965,9 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, if (info->line_multi_new == 1 && ctx->prev_multiline && (ctx->cur_column + - h5tools_ncols(s) + - strlen(OPT(info->elmt_suf2, " ")) + - strlen(OPT(info->line_suf, ""))) > ncols) + h5tools_count_ncols(s) + + HDstrlen(OPT(info->elmt_suf2, " ")) + + HDstrlen(OPT(info->line_suf, ""))) > ncols) ctx->need_prefix = TRUE; /* @@ -1322,7 +983,7 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, * one-at a time. */ multiline = 0; - for (secnum = 0, multiline = 0; (section = strtok(secnum ? NULL : s, + for (secnum = 0, multiline = 0; (section = HDstrtok(secnum ? NULL : s, OPTIONAL_LINE_BREAK)); secnum++) { /* * If the current section plus possible suffix and end-of-line @@ -1336,9 +997,9 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, */ if ((!info->skip_first || local_elmt_counter) && (ctx->cur_column + - strlen(section) + - strlen(OPT(info->elmt_suf2, " ")) + - strlen(OPT(info->line_suf, ""))) > ncols) + HDstrlen(section) + + HDstrlen(OPT(info->elmt_suf2, " ")) + + HDstrlen(OPT(info->line_suf, ""))) > ncols) ctx->need_prefix = 1; /* @@ -1358,13 +1019,13 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, h5tools_region_simple_prefix(stream, info, ctx, local_elmt_counter, ptdata, secnum); } else if ((local_elmt_counter || ctx->continuation) && secnum == 0) { - fputs(OPT(info->elmt_suf2, " "), stream); - ctx->cur_column += strlen(OPT(info->elmt_suf2, " ")); + HDfputs(OPT(info->elmt_suf2, " "), stream); + ctx->cur_column += HDstrlen(OPT(info->elmt_suf2, " ")); } /* Print the section */ - fputs(section, stream); - ctx->cur_column += strlen(section); + HDfputs(section, stream); + ctx->cur_column += HDstrlen(section); } ctx->prev_multiline = multiline; @@ -1372,2256 +1033,6 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, } /*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Print the data values from a dataset referenced by region blocks. - * - * Description: - * This is a special case subfunction to print the data in a region reference of type blocks. - * - * Return: - * The function returns FAIL if there was an error, otherwise SUCEED - * - * Parameters Description: - * h5tools_str_t *buffer is the string into which to render - * size_t ncols - * int ndims is the number of dimensions of the region element - * hssize_t nblocks is the number of blocks in the region - *------------------------------------------------------------------------- - */ -static int -h5tools_print_region_data_blocks(hid_t region_id, - FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx, - h5tools_str_t *buffer/*string into which to render */, size_t ncols, - int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata) -{ - hbool_t dimension_break = TRUE; - hsize_t *dims1 = NULL; - hsize_t *start = NULL; - hsize_t *count = NULL; - size_t numelem; - hsize_t total_size[H5S_MAX_RANK]; - hsize_t elmtno; /* elemnt index */ - unsigned int region_flags; /* buffer extent flags */ - hsize_t curr_pos; - size_t jndx; - int indx; - int type_size; - hid_t mem_space = -1; - void *region_buf = NULL; - hsize_t blkndx; - hid_t sid1 = -1; - int ret_value = SUCCEED; - h5tools_context_t ctx; - - assert(info); - assert(cur_ctx); - assert(buffer); - assert(ptdata); - - memset(&ctx, 0, sizeof(ctx)); - /* Get the dataspace of the dataset */ - if((sid1 = H5Dget_space(region_id)) < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); - - /* Allocate space for the dimension array */ - if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for dims"); - - /* find the dimensions of each data space from the block coordinates */ - numelem = 1; - for (jndx = 0; jndx < ndims; jndx++) { - dims1[jndx] = ptdata[jndx + ndims] - ptdata[jndx] + 1; - numelem = dims1[jndx] * numelem; - } - - /* Create dataspace for reading buffer */ - if((mem_space = H5Screate_simple(ndims, dims1, NULL)) < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed"); - - if((type_size = H5Tget_size(type_id)) == 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); - - if((region_buf = HDmalloc(type_size * numelem)) == NULL) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate region buffer"); - - /* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reading memory dataset */ - /* 1 2 n 1 2 n */ - if((start = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for start"); - - if((count = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for count"); - - curr_pos = 0; - ctx.indent_level = cur_ctx->indent_level; - ctx.cur_column = cur_ctx->cur_column; - ctx.prev_multiline = cur_ctx->prev_multiline; - ctx.ndims = ndims; - for (blkndx = 0; blkndx < nblocks; blkndx++) { - ctx.need_prefix = TRUE; - ctx.cur_elmt = 0; - for (indx = 0; indx < ndims; indx++) { - start[indx] = ptdata[indx + blkndx * ndims * 2]; - count[indx] = dims1[indx]; - } - - if(H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sselect_hyperslab failed"); - - if(H5Dread(region_id, type_id, mem_space, sid1, H5P_DEFAULT, region_buf) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dread failed"); - - ctx.indent_level++; - if(H5Sget_simple_extent_dims(mem_space, total_size, NULL) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); - - /* assume entire data space to be printed */ - for (indx = 0; indx < (size_t) ctx.ndims; indx++) - ctx.p_min_idx[indx] = start[indx]; - init_acc_pos(&ctx, total_size); - - /* print the data */ - region_flags = START_OF_DATA; - if (blkndx == nblocks - 1) - region_flags |= END_OF_DATA; - - for (indx = 0; indx < (size_t)ctx.ndims; indx++) - ctx.p_max_idx[indx] = dims1[indx]; - - curr_pos = 0; - ctx.sm_pos = blkndx*2*ndims; - ctx.size_last_dim = dims1[ndims-1]; - - h5tools_region_simple_prefix(stream, info, &ctx, curr_pos, ptdata, 0); - - elmtno = 0; - for (jndx = 0; jndx < numelem; jndx++, elmtno++, ctx.cur_elmt++) { - /* Render the region data element begin */ - h5tools_str_reset(buffer); - - h5tools_str_append(buffer, "%s", jndx ? OPTIONAL_LINE_BREAK "" : ""); - h5tools_str_sprint(buffer, info, region_id, type_id, - ((char*)region_buf + jndx * type_size), &ctx); - - if (jndx + 1 < numelem || (region_flags & END_OF_DATA) == 0) - h5tools_str_append(buffer, "%s", OPT(info->elmt_suf1, ",")); - - dimension_break = h5tools_render_region_element(stream, info, &ctx, buffer, &curr_pos, - ncols, ptdata, jndx, elmtno); - /* Render the region data element end */ - - if(FALSE == dimension_break) - elmtno = 0; - } /* end for (jndx = 0; jndx < numelem; jndx++, region_elmtno++, ctx.cur_elmt++) */ - - ctx.indent_level--; - } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */ - - done: - HDfree(start); - HDfree(count); - HDfree(region_buf); - HDfree(dims1); - - if(H5Sclose(mem_space) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); - if(H5Sclose(sid1) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); - - return ret_value; -} - -/*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Print some values from a dataset referenced by region blocks. - * - * Description: - * This is a special case subfunction to dump a region reference using blocks. - * - * Return: - * The function returns False if the last dimension has been reached, otherwise True - * - * In/Out: - * h5tools_context_t *ctx - * hsize_t *curr_pos - * - * Parameters Description: - * h5tools_str_t *buffer is the string into which to render - * hsize_t curr_pos is the total data element position - * size_t ncols - * hsize_t region_elmt_counter is the region element loop counter - * hsize_t elmt_count is the data element loop counter - *------------------------------------------------------------------------- - */ -hbool_t -h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, - FILE *stream, const h5tool_format_t *info, - h5tools_context_t *ctx/*in,out*/, - h5tools_str_t *buffer/*string into which to render */, - hsize_t *curr_pos/*total data element position*/, - size_t ncols, hsize_t region_elmt_counter/*element counter*/, - hsize_t elmt_counter) -{ - HERR_INIT(hbool_t, TRUE) - hbool_t dimension_break = TRUE; - hssize_t nblocks; - hsize_t alloc_size; - hsize_t *ptdata = NULL; - int ndims; - hid_t dtype; - hid_t type_id; - int i; - - assert(info); - assert(ctx); - assert(buffer); - - if((nblocks = H5Sget_select_hyper_nblocks(region_space)) <= 0) - H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_hyper_nblocks failed"); - - /* Print block information */ - if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0) - H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); - - /* Render the region { element begin */ - h5tools_str_reset(buffer); - - h5tools_str_append(buffer, "{"); - dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); - /* Render the region { element end */ - - /* Render the region datatype info and indices element begin */ - h5tools_str_reset(buffer); - - ctx->indent_level++; - ctx->need_prefix = TRUE; - h5tools_str_append(buffer, "REGION_TYPE BLOCK "); - - alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]); - assert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ - if((ptdata = (hsize_t*) malloc((size_t) alloc_size)) == NULL) - HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); - - H5_CHECK_OVERFLOW(nblocks, hssize_t, hsize_t); - if(H5Sget_select_hyper_blocklist(region_space, (hsize_t) 0, (hsize_t) nblocks, ptdata) < 0) - HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Rget_select_hyper_blocklist failed"); - - for (i = 0; i < nblocks; i++) { - int j; - - h5tools_str_append(buffer, info->dset_blockformat_pre, - i ? "," OPTIONAL_LINE_BREAK " " : "", (unsigned long) i); - - /* Start coordinates and opposite corner */ - for (j = 0; j < ndims; j++) - h5tools_str_append(buffer, "%s%lu", j ? "," : "(", - (unsigned long) ptdata[i * 2 * ndims + j]); - - for (j = 0; j < ndims; j++) - h5tools_str_append(buffer, "%s%lu", j ? "," : ")-(", - (unsigned long) ptdata[i * 2 * ndims + j + ndims]); - - h5tools_str_append(buffer, ")"); - } /* end for (i = 0; i < nblocks; i++) */ - - dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); - /* Render the region datatype info and indices element end */ - - ctx->need_prefix = TRUE; - - if((dtype = H5Dget_type(region_id)) < 0) - HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Dget_type failed"); - if((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0) - HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Tget_native_type failed"); - - /* Render the datatype element begin */ - h5tools_str_reset(buffer); - h5tools_str_append(buffer, "%s %s ", - h5tools_dump_header_format->datatypebegin, - h5tools_dump_header_format->datatypeblockbegin); - - h5tools_print_datatype(buffer, info, ctx, dtype); - - if (HDstrlen(h5tools_dump_header_format->datatypeblockend)) { - h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datatypeblockend); - if (HDstrlen(h5tools_dump_header_format->datatypeend)) - h5tools_str_append(buffer, " "); - } - if (HDstrlen(h5tools_dump_header_format->datatypeend)) - h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datatypeend); - - dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); - /* Render the datatype element end */ - - ctx->need_prefix = TRUE; - - /* Render the dataspace element begin */ - h5tools_str_reset(buffer); - - ctx->need_prefix = TRUE; - h5tools_str_append(buffer, "%s ", h5tools_dump_header_format->dataspacebegin); - - h5tools_print_dataspace(buffer, region_space); - - if (HDstrlen(h5tools_dump_header_format->dataspaceblockend)) { - h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend); - if (HDstrlen(h5tools_dump_header_format->dataspaceend)) - h5tools_str_append(buffer, " "); - } - if (HDstrlen(h5tools_dump_header_format->dataspaceend)) - h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend); - - dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); - /* Render the dataspace element end */ - - ctx->need_prefix = TRUE; - - /* Render the databegin element begin */ - h5tools_str_reset(buffer); - - h5tools_str_append(buffer, "%s %s ", - h5tools_dump_header_format->databegin, - h5tools_dump_header_format->datablockbegin); - - dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); - /* Render the databegin element end */ - - ctx->need_prefix = TRUE; - - h5tools_print_region_data_blocks(region_id, rawdatastream, info, ctx, - buffer, ncols, ndims, type_id, nblocks, ptdata); - - done: - free(ptdata); - - if(H5Tclose(type_id) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); - - if(H5Tclose(dtype) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); - - ctx->need_prefix = TRUE; - - /* Render the dataend element begin */ - h5tools_str_reset(buffer); - h5tools_str_append(buffer, "%s %s ", - h5tools_dump_header_format->dataend, - h5tools_dump_header_format->datablockend); - dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, - ncols, region_elmt_counter, elmt_counter); - /* Render the dataend element end */ - - ctx->indent_level--; - ctx->need_prefix = TRUE; - - /* Render the region } element begin */ - h5tools_str_reset(buffer); - h5tools_str_append(buffer, "}"); - dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, - ncols, region_elmt_counter, elmt_counter); - /* Render the region } element end */ - - H5_LEAVE(dimension_break) - - CATCH - return ret_value; -} - -/*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Print the data values from a dataset referenced by region points. - * - * Description: - * This is a special case subfunction to print the data in a region reference of type points. - * - * Return: - * The function returns FAIL on error, otherwise SUCCEED - * - * Parameters Description: - * h5tools_str_t *buffer is the string into which to render - * size_t ncols - * int ndims is the number of dimensions of the region element - * hssize_t npoints is the number of points in the region - *------------------------------------------------------------------------- - */ -int -h5tools_print_region_data_points(hid_t region_space, hid_t region_id, - FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx, - h5tools_str_t *buffer, size_t ncols, - int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata) -{ - hbool_t dimension_break = TRUE; - hsize_t *dims1 = NULL; - hsize_t elmtno; /* elemnt index */ - unsigned int region_flags; /* buffer extent flags */ - hsize_t curr_pos; - hsize_t total_size[H5S_MAX_RANK]; - int indx; - size_t jndx; - int type_size; - hid_t mem_space = -1; - void *region_buf = NULL; - int ret_value = SUCCEED; - h5tools_context_t ctx; - - assert(info); - assert(cur_ctx); - assert(buffer); - assert(ptdata); - - memset(&ctx, 0, sizeof(ctx)); - /* Allocate space for the dimension array */ - if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for dims"); - - dims1[0] = npoints; - - /* Create dataspace for reading buffer */ - if((mem_space = H5Screate_simple(1, dims1, NULL)) < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed"); - - if((type_size = H5Tget_size(type_id)) == 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); - - if((region_buf = HDmalloc(type_size * npoints)) == NULL) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for region"); - - curr_pos = 0; - ctx.indent_level = cur_ctx->indent_level; - ctx.cur_column = cur_ctx->cur_column; - ctx.prev_multiline = cur_ctx->prev_multiline; - ctx.ndims = ndims; - - if(H5Dread(region_id, type_id, mem_space, region_space, H5P_DEFAULT, region_buf) < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed"); - - elmtno = 0; - for (jndx = 0; jndx < npoints; jndx++, elmtno++) { - ctx.need_prefix = TRUE; - ctx.cur_elmt = 0; /* points are always 0 */ - - ctx.indent_level++; - if(H5Sget_simple_extent_dims(mem_space, total_size, NULL) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); - - /* assume entire data space to be printed */ - for (indx = 0; indx < (size_t) ctx.ndims; indx++) - ctx.p_min_idx[indx] = 0; - init_acc_pos(&ctx, total_size); - - /* print the data */ - region_flags = START_OF_DATA; - if (jndx == npoints - 1) - region_flags |= END_OF_DATA; - - for (indx = 0; indx < (size_t)ctx.ndims; indx++) - ctx.p_max_idx[indx] = cur_ctx->p_max_idx[indx]; - - ctx.sm_pos = jndx * ndims; - if (ctx.ndims > 0) { - ctx.size_last_dim = (int) (ctx.p_max_idx[ctx.ndims - 1]); - } - else - ctx.size_last_dim = 0; - - curr_pos = 0; /* points requires constant 0 */ - h5tools_region_simple_prefix(stream, info, &ctx, curr_pos, ptdata, 0); - - /* Render the point element begin */ - h5tools_str_reset(buffer); - - h5tools_str_append(buffer, "%s", jndx ? OPTIONAL_LINE_BREAK "" : ""); - h5tools_str_sprint(buffer, info, region_id, type_id, - ((char*)region_buf + jndx * type_size), &ctx); - - if (jndx + 1 < npoints || (region_flags & END_OF_DATA) == 0) - h5tools_str_append(buffer, "%s", OPT(info->elmt_suf1, ",")); - - dimension_break = h5tools_render_region_element(stream, info, &ctx, buffer, &curr_pos, - ncols, ptdata, (hsize_t)0, elmtno); - /* Render the point element end */ - if(FALSE == dimension_break) - elmtno = 0; - - ctx.indent_level--; - } /* end for (jndx = 0; jndx < npoints; jndx++, elmtno++) */ - - done: - HDfree(region_buf); - HDfree(dims1); - - if(H5Sclose(mem_space) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); - - return ret_value; -} - -/*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Print some values from a dataset referenced by region points. - * - * Description: - * This is a special case subfunction to dump a region reference using points. - * - * Return: - * The function returns False if the last dimension has been reached, otherwise True - * - * In/Out: - * h5tools_context_t *ctx - * hsize_t *curr_pos - * - * Parameters Description: - * h5tools_str_t *buffer is the string into which to render - * hsize_t curr_pos is the total data element position - * size_t ncols - * hsize_t region_elmt_counter is the region element loop counter - * hsize_t elmt_count is the data element loop counter - *------------------------------------------------------------------------- - */ -hbool_t -h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, - FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, - h5tools_str_t *buffer, hsize_t *curr_pos, size_t ncols, hsize_t region_elmt_counter, - hsize_t elmt_counter) { - HERR_INIT(hbool_t, TRUE) - hbool_t dimension_break = TRUE; - hssize_t npoints; - hsize_t alloc_size; - hsize_t *ptdata; - int ndims; - hssize_t indx; - hid_t dtype; - hid_t type_id; - - assert(info); - assert(ctx); - assert(buffer); - - if((npoints = H5Sget_select_elem_npoints(region_space)) <= 0) - H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_elem_npoints failed"); - - /* Allocate space for the dimension array */ - if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0) - H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); - - /* Render the region { element begin */ - h5tools_str_reset(buffer); - - h5tools_str_append(buffer, "{"); - dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); - /* Render the region { element end */ - - /* Render the region datatype info and indices element begin */ - h5tools_str_reset(buffer); - - ctx->indent_level++; - ctx->need_prefix = TRUE; - h5tools_str_append(buffer, "REGION_TYPE POINT "); - - alloc_size = npoints * ndims * sizeof(ptdata[0]); - assert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ - if(NULL == (ptdata = (hsize_t *)HDmalloc((size_t) alloc_size))) - HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); - - H5_CHECK_OVERFLOW(npoints, hssize_t, hsize_t); - if(H5Sget_select_elem_pointlist(region_space, (hsize_t) 0, (hsize_t) npoints, ptdata) < 0) - HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Sget_select_elem_pointlist failed"); - - for (indx = 0; indx < npoints; indx++) { - int loop_indx; - - h5tools_str_append(buffer, info->dset_ptformat_pre, - indx ? "," OPTIONAL_LINE_BREAK " " : "", (unsigned long) indx); - - for (loop_indx = 0; loop_indx < ndims; loop_indx++) - h5tools_str_append(buffer, "%s%lu", loop_indx ? "," : "(", - (unsigned long) (ptdata[indx * ndims + loop_indx])); - - h5tools_str_append(buffer, ")"); - } /* end for (indx = 0; indx < npoints; indx++) */ - - dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); - /* Render the region datatype info and indices element end */ - - ctx->need_prefix = TRUE; - - if((dtype = H5Dget_type(region_id)) < 0) - HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Dget_type failed"); - - if((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0) - HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Tget_native_type failed"); - - /* Render the datatype element begin */ - h5tools_str_reset(buffer); - h5tools_str_append(buffer, "%s %s ", - h5tools_dump_header_format->datatypebegin, - h5tools_dump_header_format->datatypeblockbegin); - - h5tools_print_datatype(buffer, info, ctx, dtype); - - if (HDstrlen(h5tools_dump_header_format->datatypeblockend)) { - h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datatypeblockend); - if (HDstrlen(h5tools_dump_header_format->datatypeend)) - h5tools_str_append(buffer, " "); - } - if (HDstrlen(h5tools_dump_header_format->datatypeend)) - h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datatypeend); - - dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); - /* Render the datatype element end */ - - ctx->need_prefix = TRUE; - - /* Render the dataspace element begin */ - h5tools_str_reset(buffer); - - ctx->need_prefix = TRUE; - h5tools_str_append(buffer, "%s ", h5tools_dump_header_format->dataspacebegin); - - h5tools_print_dataspace(buffer, region_space); - - if (HDstrlen(h5tools_dump_header_format->dataspaceblockend)) { - h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend); - if (HDstrlen(h5tools_dump_header_format->dataspaceend)) - h5tools_str_append(buffer, " "); - } - if (HDstrlen(h5tools_dump_header_format->dataspaceend)) - h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend); - - dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); - /* Render the dataspace element end */ - - ctx->need_prefix = TRUE; - - /* Render the databegin element begin */ - h5tools_str_reset(buffer); - - h5tools_str_append(buffer, "%s %s ", - h5tools_dump_header_format->databegin, - h5tools_dump_header_format->datablockbegin); - - dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); - /* Render the databegin element end */ - - ctx->need_prefix = TRUE; - - h5tools_print_region_data_points(region_space, region_id, - rawdatastream, info, ctx, buffer, ncols, ndims, type_id, npoints, ptdata); - - done: - free(ptdata); - - if(H5Tclose(type_id) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); - - if(H5Tclose(dtype) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); - - ctx->need_prefix = TRUE; - - /* Render the dataend element begin */ - h5tools_str_reset(buffer); - h5tools_str_append(buffer, "%s %s ", - h5tools_dump_header_format->dataend, - h5tools_dump_header_format->datablockend); - dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, - ncols, region_elmt_counter, elmt_counter); - /* Render the dataend element end*/ - - ctx->indent_level--; - ctx->need_prefix = TRUE; - - /* Render the region } element begin */ - h5tools_str_reset(buffer); - h5tools_str_append(buffer, "}"); - dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, - ncols, region_elmt_counter, elmt_counter); - /* Render the region } element end */ - - H5_LEAVE(dimension_break) -CATCH - return ret_value; -} - -/*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: print out the data for a subset of a dataset. - * Description: - * - * Select a hyperslab from the dataset DSET using the parameters - * specified in SSET. Dump this out to STREAM. - * - * Hyperslabs select "count" blocks of size "block", spaced "stride" elements - * from each other, starting at coordinate "start". - * - * Return: - * On success, return SUCCEED. Otherwise, the function returns FAIL. - * - * Algorithm - * - * The parameters from SSET are translated into temporary - * variables so that 1 row is printed at a time (getting the coordinate indices - * at each row). - * We define the stride, count and block to be 1 in the row dimension to achieve - * this and advance until all points are printed. - * - * The element position is obtained from the matrix according to: - * 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 - * - *------------------------------------------------------------------------- - */ -static herr_t -h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, - hid_t dset, hid_t p_type, struct subset_t *sset, - hid_t f_space, hsize_t hyperslab_count, - hsize_t *temp_start,/* start inside offset count loop */ - hsize_t *temp_count,/* count inside offset count loop */ - hsize_t *temp_block,/* block size used in loop */ - hsize_t *temp_stride,/* stride size used in loop */ - hsize_t *total_size,/* total size of dataset */ - unsigned int row_dim/* index of row_counter dimension */) -{ - HERR_INIT(herr_t, SUCCEED) - size_t i; /* counters */ - size_t j; /* counters */ - hsize_t zero[1] = {0}; /* vector of zeros */ - unsigned int flags; /* buffer extent flags */ - hsize_t elmtno; /* elemnt index */ - hsize_t low[H5S_MAX_RANK]; /* low bound of hyperslab */ - hsize_t high[H5S_MAX_RANK]; /* higher bound of hyperslab */ - size_t p_type_nbytes; /* size of memory type */ - hsize_t sm_size[H5S_MAX_RANK]; /* stripmine size */ - hsize_t sm_nbytes; /* bytes per stripmine */ - hssize_t ssm_nelmts; /* elements per stripmine*/ - hsize_t sm_nelmts; /* elements per stripmine*/ - unsigned char *sm_buf = NULL; /* buffer for raw data */ - hid_t sm_space = -1; /* stripmine data space */ - hsize_t size_row_block; /* size for blocks along rows */ - hsize_t row_counter = 0; - - /* VL data special information */ - unsigned int vl_data = 0; /* contains VL datatypes */ - - if ((size_t) ctx->ndims > NELMTS(sm_size)) - H5E_THROW(FAIL, H5E_tools_min_id_g, "ndims and sm_size comparision failed"); - - if (ctx->ndims > 0) - init_acc_pos(ctx, total_size); - - size_row_block = sset->block.data[row_dim]; - - /* Check if we have VL data in the dataset's datatype */ - if (h5tools_detect_vlen_str(p_type) == TRUE) - vl_data = TRUE; - if (H5Tdetect_class(p_type, H5T_VLEN) == TRUE) - vl_data = TRUE; - - /* display loop */ - for (; hyperslab_count > 0; temp_start[row_dim] += temp_stride[row_dim], hyperslab_count--) { - /* jump rows if size of block exceeded - cases where block > 1 only and stride > block */ - if (size_row_block > 1 - && row_counter == size_row_block - && sset->stride.data[row_dim] > sset->block.data[row_dim]) { - - hsize_t increase_rows = sset->stride.data[row_dim] - sset->block.data[row_dim]; - temp_start[row_dim] += increase_rows; - row_counter = 0; - } - - row_counter++; - - /* calculate the potential number of elements we're going to print */ - if(H5Sselect_hyperslab(f_space, H5S_SELECT_SET, temp_start, temp_stride, temp_count, temp_block) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed"); - - if((ssm_nelmts = H5Sget_select_npoints(f_space)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_select_npoints failed"); - sm_nelmts = (hsize_t)ssm_nelmts; - - if (sm_nelmts > 0) { - /* - * determine the strip mine size and allocate a buffer. the strip mine is - * a hyperslab whose size is manageable. - */ - if((sm_nbytes = p_type_nbytes = H5Tget_size(p_type)) == 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); - - if (ctx->ndims > 0) - for (i = ctx->ndims; i > 0; --i) { - hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes; - if (size == 0) /* datum size > H5TOOLS_BUFSIZE */ - size = 1; - sm_size[i - 1] = MIN(total_size[i - 1], size); - sm_nbytes *= sm_size[i - 1]; - assert(sm_nbytes > 0); - } - - assert(sm_nbytes == (hsize_t) ((size_t) sm_nbytes)); /*check for overflow*/ - if(NULL == (sm_buf = (unsigned char *)HDmalloc((size_t) sm_nelmts * p_type_nbytes))) - H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for strip-mine"); - - if((sm_space = H5Screate_simple(1, &sm_nelmts, NULL)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed"); - - if(H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &sm_nelmts, NULL) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed"); - - /* read the data */ - if(H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dread failed"); - - /* print the data */ - flags = START_OF_DATA; - - if (hyperslab_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 */ - if(H5Sget_select_bounds(f_space, low, high) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_select_bounds failed"); - - elmtno = 0; - for (i = 0; i < (size_t) ctx->ndims - 1; i++) { - hsize_t offset = 1; /* accumulation of the previous dimensions */ - for (j = i + 1; j < (size_t) 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); - - /* Reclaim any VL memory, if necessary */ - if (vl_data) - H5Dvlen_reclaim(p_type, sm_space, H5P_DEFAULT, sm_buf); - - if(H5Sclose(sm_space) < 0) - H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); - if(sm_buf) - HDfree(sm_buf); - sm_buf = NULL; - } - else - H5E_THROW(SUCCEED, H5E_tools_min_id_g, "nothing to print"); - /* we need to jump to next line and update the index */ - ctx->need_prefix = 1; - - ctx->continuation++; - - } /* hyperslab_count loop */ - -CATCH - if(sm_buf) - HDfree(sm_buf); - - return ret_value; -} - -/*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: print out the data for a subset of a dataset. - * Description: - * - * Select a hyperslab from the dataset DSET using the parameters - * specified in SSET. Dump this out to STREAM. - * - * Hyperslabs select "count" blocks of size "block", spaced "stride" elements - * from each other, starting at coordinate "start". - * - * Return: - * On success, return SUCCEED. Otherwise, the function returns FAIL. - * - * Algorithm - * - * The parameters from SSET are translated into temporary - * variables so that 1 row is printed at a time (getting the coordinate indices - * at each row). - * We define the stride, count and block to be 1 in the row dimension to achieve - * this and advance until all points are printed. - * - * The element position is obtained from the matrix according to: - * 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 - * - *------------------------------------------------------------------------- - */ -static herr_t -h5tools_display_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, - hid_t dset, hid_t p_type, struct subset_t *sset, - hid_t f_space, hsize_t *total_size) -{ - size_t i; /* counters */ - hsize_t n; /* counters */ - hsize_t count; /* hyperslab count */ - hsize_t outer_count; /* offset count */ - unsigned int row_dim; /* index of row_counter 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 */ - hsize_t temp_block[H5S_MAX_RANK];/* temporary block size used in loop */ - hsize_t temp_stride[H5S_MAX_RANK];/* temporary stride size used in loop */ - int reset_dim; - herr_t ret_value = SUCCEED; - - 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 < (size_t) ctx->ndims - 2; i++) { - /* consider block size */ - outer_count = outer_count * sset->count.data[i] * sset->block.data[i]; - - } - - /* initialize temporary start, count and maximum start */ - for (i = 0; i < (size_t) ctx->ndims; i++) { - temp_start[i] = sset->start.data[i]; - temp_count[i] = sset->count.data[i]; - temp_block[i] = sset->block.data[i]; - temp_stride[i] = sset->stride.data[i]; - max_start[i] = 0; - } - - if (ctx->ndims > 2) { - for (i = 0; i < (size_t) ctx->ndims - 2; i++) { - max_start[i] = temp_start[i] + sset->count.data[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 is the number of iterations to display all the rows, - the block size count times */ - count = sset->count.data[row_dim] * sset->block.data[row_dim]; - - /* always 1 row_counter at a time, that is a block of size 1, 1 time */ - temp_count[row_dim] = 1; - temp_block[row_dim] = 1; - - /* advance 1 row_counter at a time */ - if (sset->block.data[row_dim] > 1) - temp_stride[row_dim] = 1; - - } - /* for the 1D case */ - else { - count = 1; - } - - h5tools_print_simple_subset(stream, info, ctx, dset, p_type, sset, - f_space, count, temp_start, temp_count, - temp_block, temp_stride, total_size, row_dim); - - 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.data[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.data[current_outer_dim]; - - /* consider block */ - if (sset->block.data[current_outer_dim] > 1) - temp_start[current_outer_dim]++; - - current_outer_dim--; - reset_dim = 1; - } - } while (current_outer_dim >= 0 && reset_dim); - - } /* ctx.ndims > 1 */ - - } /* outer_count */ - - return ret_value; -} - -/*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Dump out a subset of a dataset. - * Description: - * - * Select a hyperslab from the dataset DSET using the parameters - * specified in SSET. Dump this out to STREAM. - * - * Hyperslabs select "count" blocks of size "block", spaced "stride" elements - * from each other, starting at coordinate "start". - * - * Return: - * On success, return SUCCEED. Otherwise, the function returns FAIL. - * - * Original programmer: - * Bill Wendling, Wednesday, March 07, 2001 - * - * Rewritten with modified algorithm by: - * Pedro Vicente, Wednesday, January 16, 2008, contributions from Quincey Koziol - * - * Algorithm - * - * In a inner loop, the parameters from SSET are translated into temporary - * variables so that 1 row is printed at a time (getting the coordinate indices - * at each row). - * We define the stride, count and block to be 1 in the row dimension to achieve - * this and advance until all points are printed. - * An outer loop for cases where dimensionality is greater than 2D is made. - * In each iteration, the 2D block is displayed in the inner loop. The remaining - * slower dimensions above the first 2 are incremented one at a time in the outer loop - * - * The element position is obtained from the matrix according to: - * 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 - * - *------------------------------------------------------------------------- - */ -static herr_t -h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset, - hid_t p_type, struct subset_t *sset, int indentlevel) -{ - HERR_INIT(herr_t, SUCCEED) - int sndims; - hid_t f_space = -1; /* file data space */ - size_t i; /* counters */ - hsize_t total_size[H5S_MAX_RANK];/* total size of dataset*/ - h5tools_context_t ctx; /* print context */ - - if((f_space = H5Dget_space(dset)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); - - /* - * check that everything looks okay. the dimensionality must not be too - * great and the dimensionality of the items selected for printing must - * match the dimensionality of the dataset. - */ - memset(&ctx, 0, sizeof(ctx)); - ctx.indent_level = indentlevel; - ctx.need_prefix = 1; - if((sndims = H5Sget_simple_extent_ndims(f_space)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); - ctx.ndims = (unsigned)sndims; - - /* assume entire data space to be printed */ - if (ctx.ndims > 0) - for (i = 0; i < (size_t) ctx.ndims; i++) - ctx.p_min_idx[i] = 0; - - if(H5Sget_simple_extent_dims(f_space, total_size, NULL) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); - ctx.size_last_dim = total_size[ctx.ndims - 1]; - - h5tools_display_simple_subset(stream, info, &ctx, dset, p_type, sset, f_space, total_size); - - /* Terminate the output */ - if (ctx.cur_column) { - fputs(OPT(info->line_suf, ""), stdout); - putc('\n', stdout); - fputs(OPT(info->line_sep, ""), stdout); - } - -CATCH - if(f_space >= 0 && H5Sclose(f_space) < 0) - H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); - - return ret_value; -} - -/*------------------------------------------------------------------------- - * Audience: Public - * Chapter: H5Tools Library - * Purpose: Print some values from a dataset with a simple data space. - * Description: - * This is a special case of h5tools_dump_dset(). This function only - * intended for dumping datasets -- it does strip mining and some other - * things which are unnecessary for smaller objects such as attributes - * (to print small objects like attributes simply read the attribute and - * call h5tools_dump_simple_mem()). - * Return: - * On success, the function returns SUCCEED. Otherwise, the function - * returns FAIL. - *------------------------------------------------------------------------- - */ -static int -h5tools_dump_simple_dset(FILE *stream, const h5tool_format_t *info, - hid_t dset, hid_t p_type, int indentlevel) -{ - hid_t f_space; /* file data space */ - hsize_t elmtno; /* counter */ - size_t i; /* counter */ - int carry; /* counter carry value */ - hsize_t zero[8]; /* vector of zeros */ - unsigned int flags; /* buffer extent flags */ - hsize_t total_size[H5S_MAX_RANK]; /* total size of dataset*/ - - /* Print info */ - h5tools_context_t ctx; /* print context */ - size_t p_type_nbytes; /* size of memory type */ - hsize_t p_nelmts; /* total selected elmts */ - - /* Stripmine info */ - hsize_t sm_size[H5S_MAX_RANK]; /* stripmine size */ - hsize_t sm_nbytes; /* bytes per stripmine */ - hsize_t sm_nelmts; /* elements per stripmine*/ - unsigned char *sm_buf = NULL; /* buffer for raw data */ - hid_t sm_space; /* stripmine data space */ - - /* Hyperslab info */ - hsize_t hs_offset[H5S_MAX_RANK]; /* starting offset */ - hsize_t hs_size[H5S_MAX_RANK]; /* size this pass */ - hsize_t hs_nelmts; /* elements in request */ - - /* VL data special information */ - unsigned int vl_data = 0; /* contains VL datatypes */ - - f_space = H5Dget_space(dset); - - if (f_space == FAIL) - return FAIL; - - /* - * Check that everything looks okay. The dimensionality must not be too - * great and the dimensionality of the items selected for printing must - * match the dimensionality of the dataset. - */ - memset(&ctx, 0, sizeof(ctx)); - ctx.ndims = H5Sget_simple_extent_ndims(f_space); - - if ((size_t)ctx.ndims > NELMTS(sm_size)) { - H5Sclose(f_space); - return FAIL; - } - - ctx.indent_level = indentlevel; - ctx.need_prefix = 1; - - /* Assume entire data space to be printed */ - if (ctx.ndims > 0) - for (i = 0; i < (size_t)ctx.ndims; i++) - ctx.p_min_idx[i] = 0; - - H5Sget_simple_extent_dims(f_space, total_size, NULL); - - /* calculate the number of elements we're going to print */ - p_nelmts = 1; - - if (ctx.ndims > 0) { - for (i = 0; i < ctx.ndims; i++) - p_nelmts *= total_size[i]; - ctx.size_last_dim = (total_size[ctx.ndims - 1]); - } /* end if */ - else - ctx.size_last_dim = 0; - - if (p_nelmts == 0) { - /* nothing to print */ - H5Sclose(f_space); - return SUCCEED; - } - - /* Check if we have VL data in the dataset's datatype */ - if (h5tools_detect_vlen_str(p_type) == TRUE) - vl_data = TRUE; - if (H5Tdetect_class(p_type, H5T_VLEN) == TRUE) - vl_data = TRUE; - - /* - * 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) { - hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes; - if ( size == 0) /* datum size > H5TOOLS_BUFSIZE */ - size = 1; - sm_size[i - 1] = MIN(total_size[i - 1], size); - sm_nbytes *= sm_size[i - 1]; - assert(sm_nbytes > 0); - } - } - - if(!sm_nbytes) - goto done; - - assert(sm_nbytes == (hsize_t)((size_t)sm_nbytes)); /*check for overflow*/ - sm_buf = (unsigned char *)HDmalloc((size_t)sm_nbytes); - - 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); - - for (elmtno = 0; elmtno < p_nelmts; elmtno += hs_nelmts) { - /* Calculate the hyperslab size */ - if (ctx.ndims > 0) { - for (i = 0, hs_nelmts = 1; i < ctx.ndims; i++) { - hs_size[i] = MIN(total_size[i] - hs_offset[i], sm_size[i]); - ctx.p_max_idx[i] = ctx.p_min_idx[i] + hs_size[i]; - hs_nelmts *= hs_size[i]; - } - - H5Sselect_hyperslab(f_space, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL); - H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &hs_nelmts, NULL); - } - else { - H5Sselect_all(f_space); - H5Sselect_all(sm_space); - hs_nelmts = 1; - } - - /* 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 = (elmtno == 0) ? START_OF_DATA : 0; - flags |= ((elmtno + hs_nelmts) >= p_nelmts) ? END_OF_DATA : 0; - - /* 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, hs_nelmts, p_type, sm_buf); - - /* Reclaim any VL memory, if necessary */ - if (vl_data) - H5Dvlen_reclaim(p_type, sm_space, H5P_DEFAULT, sm_buf); - - /* Calculate the next hyperslab offset */ - for (i = ctx.ndims, carry = 1; i > 0 && carry; --i) { - ctx.p_min_idx[i - 1] = ctx.p_max_idx[i - 1]; - hs_offset[i - 1] += hs_size[i - 1]; - - if (hs_offset[i - 1] == total_size[i - 1]) - hs_offset[i - 1] = 0; - else - carry = 0; - } - - ctx.continuation++; - } - - /* Terminate the output */ - if (ctx.cur_column) { - fputs(OPT(info->line_suf, ""), stream); - putc('\n', stream); - fputs(OPT(info->line_sep, ""), stream); - } - - HDfree(sm_buf); - -done: - H5Sclose(sm_space); - H5Sclose(f_space); - - return SUCCEED; -} - -/*------------------------------------------------------------------------- - * Function: h5tools_dump_simple_mem - * - * Purpose: Print some values from memory with a simple data space. - * This is a special case of h5tools_dump_mem(). - * - * Return: Success: SUCCEED - * Failure: FAIL - * - *------------------------------------------------------------------------- - */ -static int -h5tools_dump_simple_mem(FILE *stream, const h5tool_format_t *info, hid_t obj_id, - hid_t type, hid_t space, void *mem, int indentlevel) -{ - int i; /*counters */ - hsize_t nelmts; /*total selected elmts */ - h5tools_context_t ctx; /*printing context */ - - /* - * Check that everything looks okay. The dimensionality must not be too - * great and the dimensionality of the items selected for printing must - * match the dimensionality of the dataset. - */ - memset(&ctx, 0, sizeof(ctx)); - ctx.ndims = H5Sget_simple_extent_ndims(space); - - if ((size_t) ctx.ndims > NELMTS(ctx.p_min_idx)) - return FAIL; - - ctx.indent_level = indentlevel; - ctx.need_prefix = 1; - - /* Assume entire data space to be printed */ - for (i = 0; i < ctx.ndims; i++) - ctx.p_min_idx[i] = 0; - - H5Sget_simple_extent_dims(space, ctx.p_max_idx, NULL); - - for (i = 0, nelmts = 1; ctx.ndims != 0 && i < ctx.ndims; i++) - nelmts *= ctx.p_max_idx[i] - ctx.p_min_idx[i]; - - if (nelmts == 0) - return SUCCEED; /*nothing to print*/ - if (ctx.ndims > 0) { - assert(ctx.p_max_idx[ctx.ndims - 1] == (hsize_t) ((int) ctx.p_max_idx[ctx.ndims - 1])); - ctx.size_last_dim = (int) (ctx.p_max_idx[ctx.ndims - 1]); - } /* end if */ - 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); - - /* Terminate the output */ - if (ctx.cur_column) { - fputs(OPT(info->line_suf, ""), stream); - putc('\n', stream); - fputs(OPT(info->line_sep, ""), stream); - } - - return SUCCEED; -} - -/*------------------------------------------------------------------------- - * Function: h5tools_dump_dset - * - * Purpose: Print some values from a dataset DSET to the file STREAM - * after converting all types to P_TYPE (which should be a - * native type). If P_TYPE is a negative value then it will be - * computed from the dataset type using only native types. - * - * Note: This function is intended only for datasets since it does - * some things like strip mining which are unnecessary for - * smaller objects such as attributes. The easiest way to print - * small objects is to read the object into memory and call - * h5tools_dump_mem(). - * - * Return: Success: SUCCEED - * Failure: FAIL - * - * Modifications: - * Robb Matzke, 1999-06-07 - * If info->raw is set then the memory datatype will be the same - * as the file datatype. - * - * Bill Wendling, 2001-02-27 - * Renamed to ``h5tools_dump_dset'' and added the subsetting - * parameter. - * - *------------------------------------------------------------------------- - */ -int -h5tools_dump_dset(FILE *stream, const h5tool_format_t *info, hid_t dset, - hid_t _p_type, struct subset_t *sset, int indentlevel) -{ - hid_t f_space; - hid_t p_type = _p_type; - hid_t f_type; - H5S_class_t space_type; - int status = FAIL; - h5tool_format_t info_dflt; - /* Use default values */ - if (!stream) - stream = stdout; - - if (!info) { - memset(&info_dflt, 0, sizeof info_dflt); - info = &info_dflt; - } - - if (p_type < 0) { - f_type = H5Dget_type(dset); - - if (info->raw || bin_form == 1) - p_type = H5Tcopy(f_type); - else if (bin_form == 2) - p_type = h5tools_get_little_endian_type(f_type); - else if (bin_form == 3) - p_type = h5tools_get_big_endian_type(f_type); - else - p_type = h5tools_get_native_type(f_type); - - H5Tclose(f_type); - - if (p_type < 0) - goto done; - } - - /* Check the data space */ - f_space = H5Dget_space(dset); - - space_type = H5Sget_simple_extent_type(f_space); - - /* Print the data */ - if (space_type == H5S_SIMPLE || space_type == H5S_SCALAR) { - if(!sset) - status = h5tools_dump_simple_dset(rawdatastream, info, dset, p_type, indentlevel); - else - status = h5tools_dump_simple_subset(rawdatastream, info, dset, p_type, sset, indentlevel); - } - else - /* space is H5S_NULL */ - status = SUCCEED; - - /* Close the dataspace */ - H5Sclose(f_space); - -done: - if (p_type != _p_type) - H5Tclose(p_type); - - return status; -} - -/*------------------------------------------------------------------------- - * Function: h5tools_dump_mem - * - * Purpose: Displays the data contained in MEM. MEM must have the - * specified data TYPE and SPACE. Currently only simple data - * spaces are allowed and only the `all' selection. - * - * Return: Success: SUCCEED - * Failure: FAIL - * - *------------------------------------------------------------------------- - */ -int -h5tools_dump_mem(FILE *stream, const h5tool_format_t *info, hid_t obj_id, hid_t type, - hid_t space, void *mem, int indentlevel) -{ - HERR_INIT(int, SUCCEED) - h5tool_format_t info_dflt; - - /* Use default values */ - if (!stream) - stream = stdout; - - if (!info) { - memset(&info_dflt, 0, sizeof(info_dflt)); - info = &info_dflt; - } - - /* Check the data space */ - if (H5Sis_simple(space) <= 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sis_simple failed") - - H5_LEAVE(h5tools_dump_simple_mem(stream, info, obj_id, type, space, mem, indentlevel)) - -CATCH - return ret_value; -} - -/*------------------------------------------------------------------------- - * Function: print_datatype - * - * Purpose: print the datatype. - * - * Return: void - * - * In/Out: h5tools_str_t *buffer - * h5tools_context_t *ctx - * - *------------------------------------------------------------------------- - */ -int -h5tools_print_datatype(h5tools_str_t *buffer, const h5tool_format_t *info, - h5tools_context_t *ctx, hid_t type) -{ - HERR_INIT(int, SUCCEED) - char *mname; - hid_t mtype, str_type; - int snmembers; - unsigned nmembers; - int sndims; - unsigned i; - size_t size = 0; - hsize_t dims[H5TOOLS_DUMP_MAX_RANK]; - H5T_str_t str_pad; - H5T_cset_t cset; - H5T_order_t order; - H5T_class_t type_class; - hid_t super; - hid_t tmp_type; - htri_t is_vlstr = FALSE; - const char *order_s = NULL; /* byte order string */ - H5T_sign_t sign; /* sign scheme value */ - const char *sign_s = NULL; /* sign scheme string */ - - if((type_class = H5Tget_class(type)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_class failed"); - switch (type_class) { - case H5T_INTEGER: - if (H5Tequal(type, H5T_STD_I8BE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_I8BE"); - } - else if (H5Tequal(type, H5T_STD_I8LE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_I8LE"); - } - else if (H5Tequal(type, H5T_STD_I16BE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_I16BE"); - } - else if (H5Tequal(type, H5T_STD_I16LE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_I16LE"); - } - else if (H5Tequal(type, H5T_STD_I32BE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_I32BE"); - } - else if (H5Tequal(type, H5T_STD_I32LE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_I32LE"); - } - else if (H5Tequal(type, H5T_STD_I64BE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_I64BE"); - } - else if (H5Tequal(type, H5T_STD_I64LE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_I64LE"); - } - else if (H5Tequal(type, H5T_STD_U8BE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_U8BE"); - } - else if (H5Tequal(type, H5T_STD_U8LE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_U8LE"); - } - else if (H5Tequal(type, H5T_STD_U16BE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_U16BE"); - } - else if (H5Tequal(type, H5T_STD_U16LE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_U16LE"); - } - else if (H5Tequal(type, H5T_STD_U32BE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_U32BE"); - } - else if (H5Tequal(type, H5T_STD_U32LE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_U32LE"); - } - else if (H5Tequal(type, H5T_STD_U64BE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_U64BE"); - } - else if (H5Tequal(type, H5T_STD_U64LE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_U64LE"); - } - else if (H5Tequal(type, H5T_NATIVE_SCHAR) == TRUE) { - h5tools_str_append(buffer, "H5T_NATIVE_SCHAR"); - } - else if (H5Tequal(type, H5T_NATIVE_UCHAR) == TRUE) { - h5tools_str_append(buffer, "H5T_NATIVE_UCHAR"); - } - else if (H5Tequal(type, H5T_NATIVE_SHORT) == TRUE) { - h5tools_str_append(buffer, "H5T_NATIVE_SHORT"); - } - else if (H5Tequal(type, H5T_NATIVE_USHORT) == TRUE) { - h5tools_str_append(buffer, "H5T_NATIVE_USHORT"); - } - else if (H5Tequal(type, H5T_NATIVE_INT) == TRUE) { - h5tools_str_append(buffer, "H5T_NATIVE_INT"); - } - else if (H5Tequal(type, H5T_NATIVE_UINT) == TRUE) { - h5tools_str_append(buffer, "H5T_NATIVE_UINT"); - } - else if (H5Tequal(type, H5T_NATIVE_LONG) == TRUE) { - h5tools_str_append(buffer, "H5T_NATIVE_LONG"); - } - else if (H5Tequal(type, H5T_NATIVE_ULONG) == TRUE) { - h5tools_str_append(buffer, "H5T_NATIVE_ULONG"); - } - else if (H5Tequal(type, H5T_NATIVE_LLONG) == TRUE) { - h5tools_str_append(buffer, "H5T_NATIVE_LLONG"); - } - else if (H5Tequal(type, H5T_NATIVE_ULLONG) == TRUE) { - h5tools_str_append(buffer, "H5T_NATIVE_ULLONG"); - } - else { - - /* byte order */ - if (H5Tget_size(type) > 1) { - order = H5Tget_order(type); - if (H5T_ORDER_LE == order) { - order_s = " little-endian"; - } - else if (H5T_ORDER_BE == order) { - order_s = " big-endian"; - } - else if (H5T_ORDER_VAX == order) { - order_s = " mixed-endian"; - } - else { - order_s = " unknown-byte-order"; - } - } - else { - order_s = ""; - } - - /* sign */ - if ((sign = H5Tget_sign(type)) >= 0) { - if (H5T_SGN_NONE == sign) { - sign_s = " unsigned"; - } - else if (H5T_SGN_2 == sign) { - sign_s = ""; - } - else { - sign_s = " unknown-sign"; - } - } - else { - sign_s = " unknown-sign"; - } - - /* print size, order, and sign */ - h5tools_str_append(buffer, "%lu-bit%s%s integer", - (unsigned long) (8 * H5Tget_size(type)), order_s, sign_s); - } - break; - - case H5T_FLOAT: - if (H5Tequal(type, H5T_IEEE_F32BE) == TRUE) { - h5tools_str_append(buffer, "H5T_IEEE_F32BE"); - } - else if (H5Tequal(type, H5T_IEEE_F32LE) == TRUE) { - h5tools_str_append(buffer, "H5T_IEEE_F32LE"); - } - else if (H5Tequal(type, H5T_IEEE_F64BE) == TRUE) { - h5tools_str_append(buffer, "H5T_IEEE_F64BE"); - } - else if (H5Tequal(type, H5T_IEEE_F64LE) == TRUE) { - h5tools_str_append(buffer, "H5T_IEEE_F64LE"); - } - else if (H5Tequal(type, H5T_VAX_F32) == TRUE) { - h5tools_str_append(buffer, "H5T_VAX_F32"); - } - else if (H5Tequal(type, H5T_VAX_F64) == TRUE) { - h5tools_str_append(buffer, "H5T_VAX_F64"); - } - else if (H5Tequal(type, H5T_NATIVE_FLOAT) == TRUE) { - h5tools_str_append(buffer, "H5T_NATIVE_FLOAT"); - } - else if (H5Tequal(type, H5T_NATIVE_DOUBLE) == TRUE) { - h5tools_str_append(buffer, "H5T_NATIVE_DOUBLE"); -#if H5_SIZEOF_LONG_DOUBLE !=0 - } - else if (H5Tequal(type, H5T_NATIVE_LDOUBLE) == TRUE) { - h5tools_str_append(buffer, "H5T_NATIVE_LDOUBLE"); -#endif - } - else { - - /* byte order */ - if (H5Tget_size(type) > 1) { - order = H5Tget_order(type); - if (H5T_ORDER_LE == order) { - order_s = " little-endian"; - } - else if (H5T_ORDER_BE == order) { - order_s = " big-endian"; - } - else if (H5T_ORDER_VAX == order) { - order_s = " mixed-endian"; - } - else { - order_s = " unknown-byte-order"; - } - } - else { - order_s = ""; - } - - /* print size and byte order */ - h5tools_str_append(buffer, "%lu-bit%s floating-point", - (unsigned long) (8 * H5Tget_size(type)), order_s); - - } - break; - - case H5T_TIME: - h5tools_str_append(buffer, "H5T_TIME: not yet implemented"); - break; - - case H5T_STRING: - /* Make a copy of type in memory in case when TYPE is on disk, the size - * will be bigger than in memory. This makes it easier to compare - * types in memory. */ - tmp_type = H5Tcopy(type); - size = H5Tget_size(tmp_type); - str_pad = H5Tget_strpad(tmp_type); - cset = H5Tget_cset(tmp_type); - is_vlstr = H5Tis_variable_str(tmp_type); - - h5tools_str_append(buffer, "H5T_STRING %s\n", h5tools_dump_header_format->strblockbegin); - ctx->indent_level++; - - if (is_vlstr) - h5tools_str_append(buffer, "%s H5T_VARIABLE;\n", STRSIZE); - else - h5tools_str_append(buffer, "%s %d;\n", STRSIZE, (int) size); - - h5tools_str_append(buffer, "%s ", STRPAD); - if (str_pad == H5T_STR_NULLTERM) - h5tools_str_append(buffer, "H5T_STR_NULLTERM;\n"); - else if (str_pad == H5T_STR_NULLPAD) - h5tools_str_append(buffer, "H5T_STR_NULLPAD;\n"); - else if (str_pad == H5T_STR_SPACEPAD) - h5tools_str_append(buffer, "H5T_STR_SPACEPAD;\n"); - else - h5tools_str_append(buffer, "H5T_STR_ERROR;\n"); - - h5tools_str_append(buffer, "%s ", CSET); - - if (cset == H5T_CSET_ASCII) - h5tools_str_append(buffer, "H5T_CSET_ASCII;\n"); - else - h5tools_str_append(buffer, "unknown_cset;\n"); - - str_type = H5Tcopy(H5T_C_S1); - if (is_vlstr) - H5Tset_size(str_type, H5T_VARIABLE); - else - H5Tset_size(str_type, size); - H5Tset_cset(str_type, cset); - H5Tset_strpad(str_type, str_pad); - - h5tools_str_append(buffer, "%s ", CTYPE); - - /* Check C variable-length string first. Are the two types equal? */ - if (H5Tequal(tmp_type, str_type)) { - h5tools_str_append(buffer, "H5T_C_S1;\n"); - goto done; - } - - /* Change the endianness and see if they're equal. */ - order = H5Tget_order(tmp_type); - if (order == H5T_ORDER_LE) - H5Tset_order(str_type, H5T_ORDER_LE); - else if (order == H5T_ORDER_BE) - H5Tset_order(str_type, H5T_ORDER_BE); - - if (H5Tequal(tmp_type, str_type)) { - h5tools_str_append(buffer, "H5T_C_S1;\n"); - goto done; - } - - /* If not equal to C variable-length string, check Fortran type. */ - if(H5Tclose(str_type) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); - str_type = H5Tcopy(H5T_FORTRAN_S1); - - H5Tset_cset(str_type, cset); - H5Tset_size(str_type, size); - H5Tset_strpad(str_type, str_pad); - - /* Are the two types equal? */ - if (H5Tequal(tmp_type, str_type)) { - h5tools_str_append(buffer, "H5T_FORTRAN_S1;\n"); - goto done; - } - - /* Change the endianness and see if they're equal. */ - order = H5Tget_order(tmp_type); - if (order == H5T_ORDER_LE) - H5Tset_order(str_type, H5T_ORDER_LE); - else if (order == H5T_ORDER_BE) - H5Tset_order(str_type, H5T_ORDER_BE); - - if (H5Tequal(tmp_type, str_type)) { - h5tools_str_append(buffer, "H5T_FORTRAN_S1;\n"); - goto done; - } - - /* Type doesn't match any of above. */ - h5tools_str_append(buffer, "unknown_one_character_type;\n "); - - done: - if(H5Tclose(str_type) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); - if(H5Tclose(tmp_type) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); - - ctx->indent_level--; - h5tools_str_append(buffer, "%s", h5tools_dump_header_format->strblockend); - break; - - case H5T_BITFIELD: - if (H5Tequal(type, H5T_STD_B8BE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_B8BE"); - } - else if (H5Tequal(type, H5T_STD_B8LE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_B8LE"); - } - else if (H5Tequal(type, H5T_STD_B16BE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_B16BE"); - } - else if (H5Tequal(type, H5T_STD_B16LE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_B16LE"); - } - else if (H5Tequal(type, H5T_STD_B32BE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_B32BE"); - } - else if (H5Tequal(type, H5T_STD_B32LE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_B32LE"); - } - else if (H5Tequal(type, H5T_STD_B64BE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_B64BE"); - } - else if (H5Tequal(type, H5T_STD_B64LE) == TRUE) { - h5tools_str_append(buffer, "H5T_STD_B64LE"); - } - else { - h5tools_str_append(buffer, "undefined bitfield"); - } - break; - - case H5T_OPAQUE: - h5tools_str_append(buffer, "\n"); - h5tools_str_append(buffer, "H5T_OPAQUE;\n"); - { - char *ttag = H5Tget_tag(type); - h5tools_str_append(buffer, "OPAQUE_TAG \"%s\";\n", ttag); - if (ttag) - HDfree(ttag); - } - break; - - case H5T_COMPOUND: - if((snmembers = H5Tget_nmembers(type)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed"); - nmembers = (unsigned)snmembers; - - h5tools_str_append(buffer, "H5T_COMPOUND %s\n", h5tools_dump_header_format->structblockbegin); - - for (i = 0; i < nmembers; i++) { - mname = H5Tget_member_name(type, i); - if((mtype = H5Tget_member_type(type, i))>=0) { - if (H5Tget_class(mtype) == H5T_COMPOUND) - ctx->indent_level++; - - h5tools_print_datatype(buffer, info, ctx, mtype); - - if (H5Tget_class(mtype) == H5T_COMPOUND) - ctx->indent_level--; - - h5tools_str_append(buffer, " \"%s\";\n", mname); - if(H5Tclose(mtype) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); - } - else - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tget_member_type failed"); - free(mname); - } - - h5tools_str_append(buffer, "%s", h5tools_dump_header_format->structblockend); - break; - - case H5T_REFERENCE: - h5tools_str_append(buffer, "H5T_REFERENCE"); - if(region_output) { - if (H5Tequal(type, H5T_STD_REF_DSETREG) == TRUE) { - h5tools_str_append(buffer, " { H5T_STD_REF_DSETREG }"); - } - else { - h5tools_str_append(buffer, " { H5T_STD_REF_OBJECT }"); - } - } - break; - - case H5T_ENUM: - if((super = H5Tget_super(type)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed"); - - h5tools_str_append(buffer, "H5T_ENUM %s\n", h5tools_dump_header_format->enumblockbegin); - ctx->indent_level++; - - h5tools_print_datatype(buffer, info, ctx, super); - if(H5Tclose(super) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); - - h5tools_str_append(buffer, ";\n"); - h5tools_print_enum(buffer, type); - - ctx->indent_level--; - h5tools_str_append(buffer, "%s", h5tools_dump_header_format->enumblockend); - - break; - - case H5T_VLEN: - if((super = H5Tget_super(type)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed"); - - h5tools_str_append(buffer, "H5T_VLEN %s ", h5tools_dump_header_format->vlenblockbegin); - - h5tools_print_datatype(buffer, info, ctx, super); - if(H5Tclose(super) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); - - h5tools_str_append(buffer, "%s", h5tools_dump_header_format->vlenblockend); - - break; - - case H5T_ARRAY: - h5tools_str_append(buffer, "H5T_ARRAY { "); - - /* Get array information */ - if((sndims = H5Tget_array_ndims(type)) >= 0) { - unsigned ndims = (unsigned)sndims; - - if(H5Tget_array_dims2(type, dims) >= 0) { - /* Print array dimensions */ - for (i = 0; i < ndims; i++) - h5tools_str_append(buffer, "[%d]", (int) dims[i]); - - h5tools_str_append(buffer, " "); - } - else - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tget_array_dims2 failed"); - } - else - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tget_array_ndims failed"); - - /* Get array base type */ - if((super = H5Tget_super(type)) >= 0) { - /* Print base type */ - h5tools_print_datatype(buffer, info, ctx, super); - /* Close array base type */ - if(H5Tclose(super) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); - } - else - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tget_super failed"); - - h5tools_str_append(buffer, " }"); - - break; - - default: - h5tools_str_append(buffer, "unknown datatype"); - break; - } - -CATCH - return ret_value; -} - -/*------------------------------------------------------------------------- - * Function: print_dataspace - * - * Purpose: print the dataspace. - * - * Return: void - * - * In/Out: h5tools_str_t *buffer - * h5tools_context_t *ctx - * - *------------------------------------------------------------------------- - */ -int -h5tools_print_dataspace(h5tools_str_t *buffer, hid_t space) -{ - HERR_INIT(int, SUCCEED) - hsize_t size[H5TOOLS_DUMP_MAX_RANK]; - hsize_t maxsize[H5TOOLS_DUMP_MAX_RANK]; - int ndims = -1; - H5S_class_t space_type = -1; - int i; - - if((ndims = H5Sget_simple_extent_dims(space, size, maxsize)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); - - if((space_type = H5Sget_simple_extent_type(space)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_type failed"); - - switch(space_type) { - case H5S_SCALAR: - /* scalar dataspace */ - h5tools_str_append(buffer, "%s %s", h5tools_dump_header_format->dataspacedescriptionbegin, S_SCALAR); - break; - - case H5S_SIMPLE: - /* simple dataspace */ - h5tools_str_append(buffer, "%s %s { %s %" H5_PRINTF_LL_WIDTH "u", - h5tools_dump_header_format->dataspacedescriptionbegin, S_SIMPLE, - h5tools_dump_header_format->dataspacedimbegin, size[0]); - - for(i = 1; i < ndims; i++) - h5tools_str_append(buffer, ", %" H5_PRINTF_LL_WIDTH "u", size[i]); - - h5tools_str_append(buffer, " %s / ", h5tools_dump_header_format->dataspacedimend); - - if(maxsize[0] == H5S_UNLIMITED) - h5tools_str_append(buffer, "%s %s", - h5tools_dump_header_format->dataspacedimbegin, "H5S_UNLIMITED"); - else - h5tools_str_append(buffer, "%s %" H5_PRINTF_LL_WIDTH "u", - h5tools_dump_header_format->dataspacedimbegin, maxsize[0]); - - for(i = 1; i < ndims; i++) - if(maxsize[i] == H5S_UNLIMITED) - h5tools_str_append(buffer, ", %s", "H5S_UNLIMITED"); - else - h5tools_str_append(buffer, ", %" H5_PRINTF_LL_WIDTH "u", maxsize[i]); - - h5tools_str_append(buffer, " %s }", h5tools_dump_header_format->dataspacedimend); - break; - - case H5S_NULL: - /* null dataspace */ - h5tools_str_append(buffer, "%s %s", h5tools_dump_header_format->dataspacedescriptionbegin, S_NULL); - break; - - case H5S_NO_CLASS: - default: - h5tools_str_append(buffer, "%s unknown dataspace %s\n", BEGIN, END); - break; - } /* end switch */ - -CATCH - return ret_value; -} - - -/*------------------------------------------------------------------------- - * Function: print_enum - * - * Purpose: prints the enum data - * - * Return: void - * - * In/Out: h5tools_str_t *buffer - * h5tools_context_t *ctx - * - *-----------------------------------------------------------------------*/ -int -h5tools_print_enum(h5tools_str_t *buffer, hid_t type) -{ - HERR_INIT(int, SUCCEED) - char **name = NULL; /*member names */ - unsigned char *value = NULL; /*value array */ - unsigned char *copy = NULL; /*a pointer to value array */ - unsigned nmembs = 0; /*number of members */ - int nchars; /*number of output characters */ - hid_t super = -1; /*enum base integer type */ - hid_t native = -1; /*native integer datatype */ - H5T_sign_t sign_type; /*sign of value type */ - size_t type_size; /*value type size */ - size_t dst_size; /*destination value type size */ - int snmembs; - unsigned i; - - if((snmembs = H5Tget_nmembers(type)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed"); - nmembs = (unsigned)snmembs; - assert(nmembs > 0); - - if((super = H5Tget_super(type)) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_super failed"); - - if((type_size = H5Tget_size(type)) <= 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size(type) failed"); - - /* - * Determine what datatype to use for the native values. To simplify - * things we entertain three possibilities: - * 1. long long -- the largest native signed integer - * 2. unsigned long long -- the largest native unsigned integer - * 3. raw format - */ - if(type_size <= sizeof(long long)) { - dst_size = sizeof(long long); - - if((sign_type = H5Tget_sign(type))<0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_sign failed"); - if(H5T_SGN_NONE == sign_type) - native = H5T_NATIVE_ULLONG; - else - native = H5T_NATIVE_LLONG; - } /* end if */ - else - dst_size = type_size; - - /* Get the names and raw values of all members */ - if(NULL == (name = (char **)HDcalloc(nmembs, sizeof(char *)))) - H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for member name"); - if(NULL == (value = (unsigned char *)HDcalloc(nmembs, MAX(type_size, dst_size)))) - H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for member value"); - - for (i = 0; i < nmembs; i++) { - name[i] = H5Tget_member_name(type, i); - if(H5Tget_member_value(type, i, value + i * type_size) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_member_value failed"); - } - - /* Convert values to native datatype */ - if (native > 0) - if(H5Tconvert(super, native, nmembs, value, NULL, H5P_DEFAULT) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tconvert failed"); - - /* - * Sort members by increasing value - * ***not implemented yet*** - */ - - /* Print members */ - for (i = 0; i < nmembs; i++) { - h5tools_str_append(buffer, "\"%s\"", name[i]); - nchars = strlen(name[i]); - h5tools_str_append(buffer, "%*s ", MAX(0, 16 - nchars), ""); - - if (native < 0) { - size_t j; - - h5tools_str_append(buffer, "0x"); - - for (j = 0; j < dst_size; j++) - h5tools_str_append(buffer, "%02x", value[i * dst_size + j]); - } - else if (H5T_SGN_NONE == H5Tget_sign(native)) { - /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size" - *strangely, unless use another pointer "copy".*/ - copy = value + i * dst_size; - h5tools_str_append(buffer, "%" H5_PRINTF_LL_WIDTH "u", *((unsigned long long *) ((void *) copy))); - } - else { - /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size" - *strangely, unless use another pointer "copy".*/ - copy = value + i * dst_size; - h5tools_str_append(buffer, "%" H5_PRINTF_LL_WIDTH "d", *((long long *) ((void *) copy))); - } - - h5tools_str_append(buffer, ";\n"); - } - -CATCH - if(name) { - /* Release resources */ - for(i = 0; i < nmembs; i++) - if(name[i]) - free(name[i]); - free(name); - } /* end if */ - - if(value) - free(value); - - if(super >= 0 && H5Tclose(super) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not close datatype's super class"); - - if(0 == nmembs) - h5tools_str_append(buffer, "\n<empty>"); - - return ret_value; -} - -/*------------------------------------------------------------------------- - * Function: dump_datatype - * - * Purpose: Dump the datatype. Datatype can be HDF5 predefined - * atomic datatype or committed/transient datatype. - * - * Return: void - * - * In/Out: h5tools_context_t *ctx - *------------------------------------------------------------------------- - */ -void -h5tools_dump_datatype(FILE *stream, const h5tool_format_t *info, - h5tools_context_t *ctx, hid_t type) -{ - size_t ncols = 80; /* available output width */ - h5tools_str_t buffer; /* string into which to render */ - hsize_t curr_pos; /* total data element position */ - hsize_t elmt_counter = 0;/* counts the # elements printed.*/ - - /* setup */ - HDmemset(&buffer, 0, sizeof(h5tools_str_t)); - - if (info->line_ncols > 0) - ncols = info->line_ncols; - - /* pass to the prefix in h5tools_simple_prefix the total position - * instead of the current stripmine position i; this is necessary - * to print the array indices - */ - curr_pos = ctx->sm_pos; - - h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); - /* Render the element */ - h5tools_str_reset(&buffer); - - ctx->indent_level++; - h5tools_str_append(&buffer, "%s %s ", - h5tools_dump_header_format->datatypebegin, - h5tools_dump_header_format->datatypeblockbegin); - - h5tools_print_datatype(&buffer, info, ctx, type); - - if (HDstrlen(h5tools_dump_header_format->datatypeblockend)) { - h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->datatypeblockend); - if (HDstrlen(h5tools_dump_header_format->datatypeend)) - h5tools_str_append(&buffer, " "); - } - if (HDstrlen(h5tools_dump_header_format->datatypeend)) - h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->datatypeend); - h5tools_str_append(&buffer, "\n"); - - curr_pos = h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, - ncols, elmt_counter, 0); - - ctx->need_prefix = TRUE; - ctx->indent_level--; -} - -/*------------------------------------------------------------------------- * Function: init_acc_pos * * Purpose: initialize accumulator and matrix position @@ -3634,7 +1045,7 @@ init_acc_pos(h5tools_context_t *ctx, hsize_t *dims) { int i; - assert(ctx->ndims); + HDassert(ctx->ndims); ctx->acc[ctx->ndims - 1] = 1; for (i = (ctx->ndims - 2); i >= 0; i--) { @@ -3653,8 +1064,8 @@ init_acc_pos(h5tools_context_t *ctx, hsize_t *dims) * Failure: FAIL *------------------------------------------------------------------------- */ -static -int do_bin_output(FILE *stream, hid_t container, hsize_t nelmts, hid_t tid, void *_mem) +int +do_bin_output(FILE *stream, FILE *err_stream, hid_t container, hsize_t nelmts, hid_t tid, void *_mem) { HERR_INIT(int, SUCCEED) unsigned char *mem = (unsigned char*)_mem; @@ -3666,7 +1077,7 @@ int do_bin_output(FILE *stream, hid_t container, hsize_t nelmts, hid_t tid, void for (i = 0; i < nelmts; i++) { if (render_bin_output(stream, container, tid, mem + i * size) < 0) { - printf("\nError in writing binary stream\n"); + HDfprintf(err_stream,"\nError in writing binary stream\n"); return FAIL; } } @@ -3684,7 +1095,7 @@ CATCH * Failure: FAIL *------------------------------------------------------------------------- */ -static int +int render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem) { HERR_INIT(int, SUCCEED) @@ -3708,8 +1119,8 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem) #ifdef DEBUG_H5DUMP_BIN static char fmt_llong[8], fmt_ullong[8]; if (!fmt_llong[0]) { - sprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH); - sprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH); + HDsprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH); + HDsprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH); } #endif @@ -3717,30 +1128,30 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem) H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); if (H5Tequal(tid, H5T_NATIVE_FLOAT)) { - memcpy(&tempfloat, mem, sizeof(float)); + HDmemcpy(&tempfloat, mem, sizeof(float)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%g ", tempfloat); + HDfprintf(stream, "%g ", tempfloat); #else - if (1 != fwrite(&tempfloat, size, 1, stream)) + if (1 != HDfwrite(&tempfloat, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else if (H5Tequal(tid, H5T_NATIVE_DOUBLE)) { - memcpy(&tempdouble, mem, sizeof(double)); + HDmemcpy(&tempdouble, mem, sizeof(double)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%g ", tempdouble); + HDfprintf(stream, "%g ", tempdouble); #else - if (1 != fwrite(&tempdouble, size, 1, stream)) + if (1 != HDfwrite(&tempdouble, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } #if H5_SIZEOF_LONG_DOUBLE !=0 else if (H5Tequal(tid, H5T_NATIVE_LDOUBLE)) { - memcpy(&templdouble, mem, sizeof(long double)); + HDmemcpy(&templdouble, mem, sizeof(long double)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%Lf ", templdouble); + HDfprintf(stream, "%Lf ", templdouble); #else - if (1 != fwrite(&templdouble, size, 1, stream)) + if (1 != HDfwrite(&templdouble, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } @@ -3763,159 +1174,159 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem) H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); } for (i = 0; i < size && (s[i] || pad != H5T_STR_NULLTERM); i++) { - memcpy(&tempuchar, &s[i], sizeof(unsigned char)); + HDmemcpy(&tempuchar, &s[i], sizeof(unsigned char)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%d", tempuchar); + HDfprintf(stream, "%d", tempuchar); #else - if (1 != fwrite(&tempuchar, size, 1, stream)) + if (1 != HDfwrite(&tempuchar, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } /* i */ } else if (H5Tequal(tid, H5T_NATIVE_INT)) { - memcpy(&tempint, mem, sizeof(int)); + HDmemcpy(&tempint, mem, sizeof(int)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%d ", tempint); + HDfprintf(stream, "%d ", tempint); #else - if (1 != fwrite(&tempint, size, 1, stream)) + if (1 != HDfwrite(&tempint, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else if (H5Tequal(tid, H5T_NATIVE_UINT)) { - memcpy(&tempuint, mem, sizeof(unsigned int)); + HDmemcpy(&tempuint, mem, sizeof(unsigned int)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%u ", tempuint); + HDfprintf(stream, "%u ", tempuint); #else - if (1 != fwrite(&tempuint, size, 1, stream)) + if (1 != HDfwrite(&tempuint, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else if (H5Tequal(tid, H5T_NATIVE_SCHAR)) { - memcpy(&tempschar, mem, sizeof(char)); + HDmemcpy(&tempschar, mem, sizeof(char)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%d ", tempschar); + HDfprintf(stream, "%d ", tempschar); #else - if (1 != fwrite(&tempschar, size, 1, stream)) + if (1 != HDfwrite(&tempschar, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else if (H5Tequal(tid, H5T_NATIVE_UCHAR)) { - memcpy(&tempuchar, mem, sizeof(unsigned char)); + HDmemcpy(&tempuchar, mem, sizeof(unsigned char)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%u ", tempuchar); + HDfprintf(stream, "%u ", tempuchar); #else - if (1 != fwrite(&tempuchar, size, 1, stream)) + if (1 != HDfwrite(&tempuchar, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else if (H5Tequal(tid, H5T_NATIVE_SHORT)) { - memcpy(&tempshort, mem, sizeof(short)); + HDmemcpy(&tempshort, mem, sizeof(short)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%d ", tempshort); + HDfprintf(stream, "%d ", tempshort); #else - if (1 != fwrite(&tempshort, size, 1, stream)) + if (1 != HDfwrite(&tempshort, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else if (H5Tequal(tid, H5T_NATIVE_USHORT)) { - memcpy(&tempushort, mem, sizeof(unsigned short)); + HDmemcpy(&tempushort, mem, sizeof(unsigned short)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%u ", tempushort); + HDfprintf(stream, "%u ", tempushort); #else - if (1 != fwrite(&tempushort, size, 1, stream)) + if (1 != HDfwrite(&tempushort, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else if (H5Tequal(tid, H5T_NATIVE_LONG)) { - memcpy(&templong, mem, sizeof(long)); + HDmemcpy(&templong, mem, sizeof(long)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%ld ", templong); + HDfprintf(stream, "%ld ", templong); #else - if (1 != fwrite(&templong, size, 1, stream)) + if (1 != HDfwrite(&templong, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else if (H5Tequal(tid, H5T_NATIVE_ULONG)) { - memcpy(&tempulong, mem, sizeof(unsigned long)); + HDmemcpy(&tempulong, mem, sizeof(unsigned long)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%lu ", tempulong); + HDfprintf(stream, "%lu ", tempulong); #else - if (1 != fwrite(&tempulong, size, 1, stream)) + if (1 != HDfwrite(&tempulong, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else if (H5Tequal(tid, H5T_NATIVE_LLONG)) { - memcpy(&templlong, mem, sizeof(long long)); + HDmemcpy(&templlong, mem, sizeof(long long)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, fmt_llong, templlong); + HDfprintf(stream, fmt_llong, templlong); #else - if (1 != fwrite(&templlong, size, 1, stream)) + if (1 != HDfwrite(&templlong, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else if (H5Tequal(tid, H5T_NATIVE_ULLONG)) { - memcpy(&tempullong, mem, sizeof(unsigned long long)); + HDmemcpy(&tempullong, mem, sizeof(unsigned long long)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, fmt_ullong, tempullong); + HDfprintf(stream, fmt_ullong, tempullong); #else - if (1 != fwrite(&tempullong, size, 1, stream)) + if (1 != HDfwrite(&tempullong, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else if (H5Tequal(tid, H5T_NATIVE_HSSIZE)) { if (sizeof(hssize_t) == sizeof(int)) { - memcpy(&tempint, mem, sizeof(int)); + HDmemcpy(&tempint, mem, sizeof(int)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%d ", tempint); + HDfprintf(stream, "%d ", tempint); #else - if (1 != fwrite(&tempint, size, 1, stream)) + if (1 != HDfwrite(&tempint, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else if (sizeof(hssize_t) == sizeof(long)) { - memcpy(&templong, mem, sizeof(long)); + HDmemcpy(&templong, mem, sizeof(long)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%ld ", templong); + HDfprintf(stream, "%ld ", templong); #else - if (1 != fwrite(&templong, size, 1, stream)) + if (1 != HDfwrite(&templong, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else { - memcpy(&templlong, mem, sizeof(long long)); + HDmemcpy(&templlong, mem, sizeof(long long)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, fmt_llong, templlong); + HDfprintf(stream, fmt_llong, templlong); #else - if (1 != fwrite(&templlong, size, 1, stream)) + if (1 != HDfwrite(&templlong, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } } else if (H5Tequal(tid, H5T_NATIVE_HSIZE)) { if (sizeof(hsize_t) == sizeof(int)) { - memcpy(&tempuint, mem, sizeof(unsigned int)); + HDmemcpy(&tempuint, mem, sizeof(unsigned int)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%u ", tempuint); + HDfprintf(stream, "%u ", tempuint); #else - if (1 != fwrite(&tempuint, size, 1, stream)) + if (1 != HDfwrite(&tempuint, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else if (sizeof(hsize_t) == sizeof(long)) { - memcpy(&tempulong, mem, sizeof(unsigned long)); + HDmemcpy(&tempulong, mem, sizeof(unsigned long)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%lu ", tempulong); + HDfprintf(stream, "%lu ", tempulong); #else - if (1 != fwrite(&tempulong, size, 1, stream)) + if (1 != HDfwrite(&tempulong, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else { - memcpy(&tempullong, mem, sizeof(unsigned long long)); + HDmemcpy(&tempullong, mem, sizeof(unsigned long long)); #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, fmt_ullong, tempullong); + HDfprintf(stream, fmt_ullong, tempullong); #else - if (1 != fwrite(&tempullong, size, 1, stream)) + if (1 != HDfwrite(&tempullong, size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } @@ -3942,18 +1353,18 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem) unsigned int i; if (1 == size) { #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "0x%02x", mem[0]); + HDfprintf(stream, "0x%02x", mem[0]); #else - if (1 != fwrite(&mem[0], size, 1, stream)) + if (1 != HDfwrite(&mem[0], size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else { for (i = 0; i < size; i++) { #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%s%02x", i?":":"", mem[i]); + HDfprintf(stream, "%s%02x", i?":":"", mem[i]); #else - if (1 != fwrite(&mem[i], sizeof(char), 1, stream)) + if (1 != HDfwrite(&mem[i], sizeof(char), 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } /*i*/ @@ -3969,7 +1380,7 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem) size = H5Tget_size(memb); ndims = H5Tget_array_ndims(tid); H5Tget_array_dims2(tid, dims); - assert(ndims >= 1 && ndims <= H5S_MAX_RANK); + HDassert(ndims >= 1 && ndims <= H5S_MAX_RANK); /* calculate the number of array elements */ for (k = 0, nelmts = 1; k < ndims; k++) { @@ -4032,18 +1443,18 @@ render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem) size_t i; if (1 == size) { #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "0x%02x", mem[0]); + HDfprintf(stream, "0x%02x", mem[0]); #else - if (1 != fwrite(&mem[0], size, 1, stream)) + if (1 != HDfwrite(&mem[0], size, 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } else { for (i = 0; i < size; i++) { #ifdef DEBUG_H5DUMP_BIN - fprintf(stream, "%s%02x", i?":":"", mem[i]); + HDfprintf(stream, "%s%02x", i?":":"", mem[i]); #else - if (1 != fwrite(&mem[i], sizeof(char), 1, stream)) + if (1 != HDfwrite(&mem[i], sizeof(char), 1, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); #endif } /*i*/ @@ -4067,14 +1478,15 @@ CATCH * *------------------------------------------------------------------------- */ -static int +int render_bin_output_region_data_blocks(hid_t region_id, FILE *stream, hid_t container, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata) { hsize_t *dims1 = NULL; hsize_t *start = NULL; hsize_t *count = NULL; - size_t numelem; + hsize_t numelem; + hsize_t numindex; hsize_t total_size[H5S_MAX_RANK]; int jndx; int type_size; @@ -4132,10 +1544,10 @@ render_bin_output_region_data_blocks(hid_t region_id, FILE *stream, if(H5Sget_simple_extent_dims(mem_space, total_size, NULL) < 0) HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); - for (jndx = 0; jndx < numelem; jndx++) { + for (numindex = 0; numindex < numelem; numindex++) { render_bin_output(stream, container, type_id, - ((char*)region_buf + jndx * type_size)); + ((char*)region_buf + numindex * type_size)); /* Render the region data element end */ } /* end for (jndx = 0; jndx < numelem; jndx++) */ } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */ @@ -4167,7 +1579,7 @@ render_bin_output_region_data_blocks(hid_t region_id, FILE *stream, * *------------------------------------------------------------------------- */ -static hbool_t +hbool_t render_bin_output_region_blocks(hid_t region_space, hid_t region_id, FILE *stream, hid_t container) { @@ -4187,8 +1599,8 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id, H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]); - assert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ - if((ptdata = (hsize_t*) malloc((size_t) alloc_size)) == NULL) + HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ + if((ptdata = (hsize_t*) HDmalloc((size_t) alloc_size)) == NULL) HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); H5_CHECK_OVERFLOW(nblocks, hssize_t, hsize_t); @@ -4204,7 +1616,7 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id, type_id, nblocks, ptdata); done: - free(ptdata); + HDfree(ptdata); if(H5Tclose(type_id) < 0) HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); @@ -4294,7 +1706,7 @@ render_bin_output_region_data_points(hid_t region_space, hid_t region_id, * *------------------------------------------------------------------------- */ -static hbool_t +hbool_t render_bin_output_region_points(hid_t region_space, hid_t region_id, FILE *stream, hid_t container) { @@ -4314,7 +1726,7 @@ render_bin_output_region_points(hid_t region_space, hid_t region_id, H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); alloc_size = npoints * ndims * sizeof(ptdata[0]); - assert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ + HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ if(NULL == (ptdata = (hsize_t *)HDmalloc((size_t) alloc_size))) HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); @@ -4332,7 +1744,7 @@ render_bin_output_region_points(hid_t region_space, hid_t region_id, stream, container, ndims, type_id, npoints, ptdata); done: - free(ptdata); + HDfree(ptdata); if(H5Tclose(type_id) < 0) HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); @@ -4353,8 +1765,8 @@ CATCH * Return: TRUE if all bytes are zero; FALSE otherwise *------------------------------------------------------------------------- */ -static -hbool_t h5tools_is_zero(const void *_mem, size_t size) +hbool_t +h5tools_is_zero(const void *_mem, size_t size) { const unsigned char *mem = (const unsigned char *) _mem; @@ -4385,18 +1797,19 @@ hbool_t h5tools_is_zero(const void *_mem, size_t size) * *------------------------------------------------------------------------- */ -hbool_t h5tools_is_obj_same(hid_t loc_id1, const char *name1, +hbool_t +h5tools_is_obj_same(hid_t loc_id1, const char *name1, hid_t loc_id2, const char *name2) { H5O_info_t oinfo1, oinfo2; hbool_t ret_val = 0; - if ( name1 && strcmp(name1, ".")) + if ( name1 && HDstrcmp(name1, ".")) H5Oget_info_by_name(loc_id1, name1, &oinfo1, H5P_DEFAULT); else H5Oget_info(loc_id1, &oinfo1); - if ( name2 && strcmp(name2, ".")) + if ( name2 && HDstrcmp(name2, ".")) H5Oget_info_by_name(loc_id2, name2, &oinfo2, H5P_DEFAULT); else H5Oget_info(loc_id2, &oinfo2); diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index 1b2014a..0f4b271 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -31,23 +31,6 @@ #define START_OF_DATA 0x0001 #define END_OF_DATA 0x0002 -/* - * The output functions need a temporary buffer to hold a piece of the - * dataset while it's being printed. This constant sets the limit on the - * size of that temporary buffer in bytes. For efficiency's sake, choose the - * largest value suitable for your machine (for testing use a small value). - */ -#if 1 -#define H5TOOLS_BUFSIZE (1024 * 1024) -#else -#define H5TOOLS_BUFSIZE (1024) -#endif - -/* - * Maximum size used in a call to malloc - */ -#define H5TOOLS_MALLOCSIZE (128 * 1024 * 1024) - /* format for hsize_t */ #define HSIZE_T_FORMAT "%"H5_PRINTF_LL_WIDTH"u" @@ -101,6 +84,9 @@ #define EXTERNAL_FILE "EXTERNAL_FILE" #define FILLVALUE "FILLVALUE" #define FILE_CONTENTS "FILE_CONTENTS" +#define PACKED_BITS "PACKED_BITS" +#define PACKED_OFFSET "OFFSET" +#define PACKED_LENGTH "LENGTH" #define BEGIN "{" #define END "}" @@ -526,17 +512,27 @@ struct subset_t { #include "h5tools_str.h" +H5TOOLS_DLLVAR h5tool_format_t h5tools_dataformat; +H5TOOLS_DLLVAR const h5tools_dump_header_t h5tools_standardformat; +H5TOOLS_DLLVAR const h5tools_dump_header_t* h5tools_dump_header_format; + #ifdef __cplusplus extern "C" { #endif -H5TOOLS_DLLVAR int packed_bits_num; /* number of packed bits to display */ -H5TOOLS_DLLVAR int packed_data_offset; /* offset of packed bits to display */ +H5TOOLS_DLLVAR int packed_bits_num; /* number of packed bits to display */ +H5TOOLS_DLLVAR int packed_data_offset; /* offset of packed bits to display */ +H5TOOLS_DLLVAR int packed_data_length; /* lengtht of packed bits to display */ H5TOOLS_DLLVAR unsigned long long packed_data_mask; /* mask in which packed bits to display */ H5TOOLS_DLLVAR FILE *rawdatastream; /* output stream for raw data */ +H5TOOLS_DLLVAR FILE *rawoutstream; /* output stream for raw output */ +H5TOOLS_DLLVAR FILE *rawerrorstream; /* output stream for raw error */ H5TOOLS_DLLVAR int bin_output; /* binary output */ H5TOOLS_DLLVAR int bin_form; /* binary form */ H5TOOLS_DLLVAR int region_output; /* region output */ +H5TOOLS_DLLVAR int oid_output; /* oid output */ +H5TOOLS_DLLVAR int data_output; /* data output */ +H5TOOLS_DLLVAR int attr_data_output; /* attribute data output */ /* Strings for output */ #define H5_TOOLS_GROUP "GROUP" @@ -544,41 +540,45 @@ H5TOOLS_DLLVAR int region_output; /* region output */ #define H5_TOOLS_DATATYPE "DATATYPE" /* Definitions of useful routines */ -H5TOOLS_DLL void h5tools_init(void); -H5TOOLS_DLL void h5tools_close(void); -H5TOOLS_DLL hid_t h5tools_fopen(const char *fname, unsigned flags, hid_t fapl, - const char *driver, char *drivername, size_t drivername_len); -H5TOOLS_DLL int h5tools_dump_dset(FILE *stream, const h5tool_format_t *info, hid_t dset, - hid_t p_typ, struct subset_t *sset, int indentlevel); -H5TOOLS_DLL int h5tools_dump_mem(FILE *stream, const h5tool_format_t *info, hid_t obj_id, - hid_t type, hid_t space, void *mem, int indentlevel); -H5TOOLS_DLL hid_t h5tools_get_native_type(hid_t type); -H5TOOLS_DLL hid_t h5tools_get_little_endian_type(hid_t type); -H5TOOLS_DLL hid_t h5tools_get_big_endian_type(hid_t type); - -H5TOOLS_DLL htri_t h5tools_detect_vlen(hid_t tid); -H5TOOLS_DLL htri_t h5tools_detect_vlen_str(hid_t tid); -H5TOOLS_DLL hbool_t h5tools_is_obj_same(hid_t loc_id1, const char *name1, hid_t loc_id2, const char *name2); - -H5TOOLS_DLL void h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t container, - h5tools_context_t *ctx/*in,out*/, unsigned flags, - hsize_t nelmts, hid_t type, void *_mem); - -H5TOOLS_DLL int h5tools_canreadf(const char* name, - hid_t dcpl_id); -H5TOOLS_DLL int h5tools_can_encode(H5Z_filter_t filtn); - -void init_acc_pos(h5tools_context_t *ctx, hsize_t *dims); -/* - * new functions needed to display region reference data - */ -void h5tools_dump_datatype(FILE *stream, const h5tool_format_t *info, - h5tools_context_t *ctx/*in,out*/, hid_t type); -int h5tools_print_dataspace(h5tools_str_t *buffer/*in,out*/, hid_t space); -int h5tools_print_datatype(h5tools_str_t *buffer/*in,out*/, - const h5tool_format_t *info, h5tools_context_t *ctx/*in,out*/, - hid_t type); -int h5tools_print_enum(h5tools_str_t *buffer/*in,out*/, hid_t type); +H5TOOLS_DLL void h5tools_init(void); +H5TOOLS_DLL void h5tools_close(void); +H5TOOLS_DLL hid_t h5tools_fopen(const char *fname, unsigned flags, hid_t fapl, + const char *driver, char *drivername, size_t drivername_len); +H5TOOLS_DLL hid_t h5tools_get_native_type(hid_t type); +H5TOOLS_DLL hid_t h5tools_get_little_endian_type(hid_t type); +H5TOOLS_DLL hid_t h5tools_get_big_endian_type(hid_t type); +H5TOOLS_DLL htri_t h5tools_detect_vlen(hid_t tid); +H5TOOLS_DLL htri_t h5tools_detect_vlen_str(hid_t tid); +H5TOOLS_DLL hbool_t h5tools_is_obj_same(hid_t loc_id1, const char *name1, hid_t loc_id2, const char *name2); +H5TOOLS_DLL void init_acc_pos(h5tools_context_t *ctx, hsize_t *dims); +H5TOOLS_DLL hbool_t h5tools_is_zero(const void *_mem, size_t size); +H5TOOLS_DLL int h5tools_canreadf(const char* name, hid_t dcpl_id); +H5TOOLS_DLL int h5tools_can_encode(H5Z_filter_t filtn); + +H5TOOLS_DLL void h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx, hsize_t elmtno, int secnum); +H5TOOLS_DLL void h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx, hsize_t elmtno, hsize_t *ptdata, int secnum); + +H5TOOLS_DLL int do_bin_output(FILE *stream, FILE *err_stream, hid_t container, hsize_t nelmts, hid_t tid, void *_mem); +H5TOOLS_DLL int render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem); +H5TOOLS_DLL int render_bin_output_region_data_blocks(hid_t region_id, FILE *stream, + hid_t container, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata); +H5TOOLS_DLL hbool_t render_bin_output_region_blocks(hid_t region_space, hid_t region_id, + FILE *stream, hid_t container); +H5TOOLS_DLL hbool_t render_bin_output_region_points(hid_t region_space, hid_t region_id, + FILE *stream, hid_t container); + +H5TOOLS_DLL hbool_t h5tools_render_element(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx, h5tools_str_t *buffer, hsize_t *curr_pos, + size_t ncols, hsize_t local_elmt_counter, hsize_t elmt_counter); +H5TOOLS_DLL hbool_t h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx/*in,out*/, + h5tools_str_t *buffer/*string into which to render */, + hsize_t *curr_pos/*total data element position*/, + size_t ncols, hsize_t *ptdata, + hsize_t local_elmt_counter/*element counter*/, + hsize_t elmt_counter); #ifdef __cplusplus } diff --git a/tools/lib/h5tools_dump.c b/tools/lib/h5tools_dump.c new file mode 100644 index 0000000..15cb679 --- /dev/null +++ b/tools/lib/h5tools_dump.c @@ -0,0 +1,3921 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * Programmer: Robb Matzke <matzke@llnl.gov> + * Thursday, July 23, 1998 + * + * Purpose: A library for displaying the values of a dataset in a human + * readable format. + */ + +#include <stdio.h> +#include <stdlib.h> + +#include "h5tools.h" +#include "h5tools_dump.h" +#include "h5tools_ref.h" +#include "h5tools_utils.h" +#include "H5private.h" + +#define SANITY_CHECK + +#define ALIGN(A,Z) ((((A) + (Z) - 1) / (Z)) * (Z)) + +h5tool_format_t h5tools_dataformat = { +0, /*raw */ + +"", /*fmt_raw */ +"%d", /*fmt_int */ +"%u", /*fmt_uint */ +"%hhd", /*fmt_schar */ +"%u", /*fmt_uchar */ +"%d", /*fmt_short */ +"%u", /*fmt_ushort */ +"%ld", /*fmt_long */ +"%lu", /*fmt_ulong */ +NULL, /*fmt_llong */ +NULL, /*fmt_ullong */ +"%g", /*fmt_double */ +"%g", /*fmt_float */ + +0, /*ascii */ +0, /*str_locale */ +0, /*str_repeat */ + +"[ ", /*arr_pre */ +",", /*arr_sep */ +" ]", /*arr_suf */ +1, /*arr_linebreak */ + +"", /*cmpd_name */ +",\n", /*cmpd_sep */ +"{", /*cmpd_pre */ +"}", /*cmpd_suf */ +"\n", /*cmpd_end */ + +", ", /*vlen_sep */ +"(", /*vlen_pre */ +")", /*vlen_suf */ +"", /*vlen_end */ + +"%s", /*elmt_fmt */ +",", /*elmt_suf1 */ +" ", /*elmt_suf2 */ + +"", /*idx_n_fmt */ +"", /*idx_sep */ +"", /*idx_fmt */ + +80, /*line_ncols *//*standard default columns */ +0, /*line_per_line */ +"", /*line_pre */ +"%s", /*line_1st */ +"%s", /*line_cont */ +"", /*line_suf */ +"", /*line_sep */ +1, /*line_multi_new */ +" ", /*line_indent */ + +1, /*skip_first */ + +1, /*obj_hidefileno */ +" "H5_PRINTF_HADDR_FMT, /*obj_format */ + +1, /*dset_hidefileno */ +"DATASET %s ", /*dset_format */ +"%s", /*dset_blockformat_pre */ +"%s", /*dset_ptformat_pre */ +"%s", /*dset_ptformat */ +1, /*array indices */ +1 /*escape non printable characters */ +}; + +const h5tools_dump_header_t h5tools_standardformat = { +"standardformat", /*name */ +"HDF5", /*fileebgin */ +"", /*fileend */ +SUPER_BLOCK, /*bootblockbegin */ +"", /*bootblockend */ +H5_TOOLS_GROUP, /*groupbegin */ +"", /*groupend */ +H5_TOOLS_DATASET, /*datasetbegin */ +"", /*datasetend */ +ATTRIBUTE, /*attributebegin */ +"", /*attributeend */ +H5_TOOLS_DATATYPE, /*datatypebegin */ +"", /*datatypeend */ +DATASPACE, /*dataspacebegin */ +"", /*dataspaceend */ +DATA, /*databegin */ +"", /*dataend */ +SOFTLINK, /*softlinkbegin */ +"", /*softlinkend */ +EXTLINK, /*extlinkbegin */ +"", /*extlinkend */ +UDLINK, /*udlinkbegin */ +"", /*udlinkend */ +SUBSET, /*subsettingbegin */ +"", /*subsettingend */ +START, /*startbegin */ +"", /*startend */ +STRIDE, /*stridebegin */ +"", /*strideend */ +COUNT, /*countbegin */ +"", /*countend */ +BLOCK, /*blockbegin */ +"", /*blockend */ + +"{", /*fileblockbegin */ +"}", /*fileblockend */ +"{", /*bootblockblockbegin */ +"}", /*bootblockblockend */ +"{", /*groupblockbegin */ +"}", /*groupblockend */ +"{", /*datasetblockbegin */ +"}", /*datasetblockend */ +"{", /*attributeblockbegin */ +"}", /*attributeblockend */ +"", /*datatypeblockbegin */ +"", /*datatypeblockend */ +"", /*dataspaceblockbegin */ +"", /*dataspaceblockend */ +"{", /*datablockbegin */ +"}", /*datablockend */ +"{", /*softlinkblockbegin */ +"}", /*softlinkblockend */ +"{", /*extlinkblockbegin */ +"}", /*extlinkblockend */ +"{", /*udlinkblockbegin */ +"}", /*udlinkblockend */ +"{", /*strblockbegin */ +"}", /*strblockend */ +"{", /*enumblockbegin */ +"}", /*enumblockend */ +"{", /*structblockbegin */ +"}", /*structblockend */ +"{", /*vlenblockbegin */ +"}", /*vlenblockend */ +"{", /*subsettingblockbegin */ +"}", /*subsettingblockend */ +"(", /*startblockbegin */ +");", /*startblockend */ +"(", /*strideblockbegin */ +");", /*strideblockend */ +"(", /*countblockbegin */ +");", /*countblockend */ +"(", /*blockblockbegin */ +");", /*blockblockend */ + +"", /*dataspacedescriptionbegin */ +"", /*dataspacedescriptionend */ +"(", /*dataspacedimbegin */ +")", /*dataspacedimend */ +}; + +const h5tools_dump_header_t* h5tools_dump_header_format; +table_t *h5dump_type_table = NULL; /*type table reference for datatype dump */ + +/* local prototypes */ + +hbool_t h5tools_render_element(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx/*in,out*/, + h5tools_str_t *buffer/*string into which to render */, + hsize_t *curr_pos/*total data element position*/, + size_t ncols, hsize_t local_elmt_counter/*element counter*/, + hsize_t elmt_counter); + +hbool_t h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx/*in,out*/, + h5tools_str_t *buffer/*string into which to render */, + hsize_t *curr_pos/*total data element position*/, + size_t ncols, hsize_t *ptdata, + hsize_t local_elmt_counter/*element counter*/, + hsize_t elmt_counter); + +static int h5tools_print_region_data_blocks(hid_t region_id, + FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx, + h5tools_str_t *buffer/*string into which to render */, size_t ncols, + int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata); + +hbool_t h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, + FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx/*in,out*/, + h5tools_str_t *buffer/*string into which to render */, + hsize_t *curr_pos/*total data element position*/, + size_t ncols, hsize_t region_elmt_counter/*element counter*/, + hsize_t elmt_counter); + +int h5tools_print_region_data_points(hid_t region_space, hid_t region_id, + FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx, + h5tools_str_t *buffer, size_t ncols, + int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata); + +hbool_t h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, + FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx/*in,out*/, + h5tools_str_t *buffer/*string into which to render */, + hsize_t *curr_pos/*total data element position*/, + size_t ncols, hsize_t region_elmt_counter/*element counter*/, + hsize_t elmt_counter); +void +h5tools_dump_init(void) +{ + h5tools_dump_header_format = &h5tools_standardformat; +} + +/*------------------------------------------------------------------------- + * Audience: Public + * Chapter: H5Tools Library + * Purpose: Prints NELMTS data elements to output STREAM. + * Description: + * Prints some (NELMTS) data elements to output STREAM. The elements are + * stored in _MEM as type TYPE and are printed according to the format + * described in INFO. The CTX struct contains context information shared + * between calls to this function. The FLAGS is a bit field that + * indicates whether the data supplied in this call falls at the + * beginning or end of the total data to be printed (START_OF_DATA and + * END_OF_DATA). + * Return: + * None + * Programmer: + * Robb Matzke, Monday, April 26, 1999 + * Modifications: + * Robb Matzke, 1999-06-04 + * The `container' argument is the optional dataset for reference types. + * + * Robb Matzke, 1999-09-29 + * Understands the `per_line' property which indicates that every Nth + * element should begin a new line. + * + * Robb Matzke, LLNL, 2003-06-05 + * Do not dereference the memory for a variable-length string here. + * Deref in h5tools_str_sprint() instead so recursive types are + * handled correctly. + * + * Pedro Vicente Nunes, The HDF Group, 2005-10-19 + * pass to the prefix in h5tools_simple_prefix the total position + * instead of the current stripmine position i; this is necessary + * to print the array indices + * new field sm_pos in h5tools_context_t, the current stripmine element position + *------------------------------------------------------------------------- + */ +void +h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t container, + h5tools_context_t *ctx/*in,out*/, unsigned flags, + hsize_t nelmts, hid_t type, void *_mem) +{ + unsigned char *mem = (unsigned char*) _mem; + hsize_t i; /*element counter */ + size_t size; /*size of each datum */ + hid_t region_space = -1; + hid_t region_id = -1; + hbool_t dimension_break = TRUE; + H5S_sel_type region_type; + size_t ncols = 80; /*available output width */ + h5tools_str_t buffer; /*string into which to render */ + hsize_t curr_pos = 0; /* total data element position */ + hsize_t elmt_counter = 0;/*counts the # elements printed. + *I (ptl?) needed something that + *isn't going to get reset when a new + *line is formed. I'm going to use + *this var to count elements and + *break after we see a number equal + *to the ctx->size_last_dim. */ + + /* binary dump */ + if (bin_output) { + do_bin_output(rawdatastream, rawoutstream, container, nelmts, type, _mem); + } /* end if */ + else { + /* setup */ + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + size = H5Tget_size(type); + + if (info->line_ncols > 0) + ncols = info->line_ncols; + + /* pass to the prefix in h5tools_simple_prefix the total position + * instead of the current stripmine position i; this is necessary + * to print the array indices + */ + curr_pos = ctx->sm_pos; + + if (region_output && H5Tequal(type, H5T_STD_REF_DSETREG)) { + for (i = 0; i < nelmts; i++, ctx->cur_elmt++, elmt_counter++) { + void* memref = mem + i * size; + char ref_name[1024]; + + /* region data */ + region_id = H5Rdereference(container, H5R_DATASET_REGION, memref); + if (region_id >= 0) { + region_space = H5Rget_region(container, H5R_DATASET_REGION, memref); + if (region_space >= 0) { + if (h5tools_is_zero(memref, H5Tget_size(type))) { + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + /* Render the region element begin */ + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "NULL"); + + dimension_break = h5tools_render_element(stream, info, + ctx, &buffer, &curr_pos, ncols, i, elmt_counter); + } + else { + if(H5Rget_name(region_id, H5R_DATASET_REGION, memref, (char*) ref_name, 1024)<0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Rget_name failed"); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos+i, 0); + + /* Render the region element begin */ + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, info->dset_format, ref_name); + + dimension_break = h5tools_render_element(stream, info, + ctx, &buffer, &curr_pos, ncols, i, elmt_counter); + + region_type = H5Sget_select_type(region_space); + if(region_type == H5S_SEL_POINTS) + /* Print point information */ + dimension_break = h5tools_dump_region_data_points( + region_space, region_id, stream, info, ctx, + &buffer, &curr_pos, ncols, i, elmt_counter); + else if(region_type == H5S_SEL_HYPERSLABS) + /* Print block information */ + dimension_break = h5tools_dump_region_data_blocks( + region_space, region_id, stream, info, ctx, + &buffer, &curr_pos, ncols, i, elmt_counter); + else + HERROR(H5E_tools_g, H5E_tools_min_id_g, "invalid region type"); + /* Render the region element end */ + + } /* end else to if (h5tools_is_zero(... */ + if(H5Sclose(region_space) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + } /* end if (region_space >= 0) */ + else + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Rget_region failed"); + if(H5Dclose(region_id) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dclose failed"); + + } /* if (region_id >= 0) */ + else + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Rdereference failed"); + + ctx->need_prefix = TRUE; + + if(FALSE == dimension_break) + elmt_counter = 0; + } /* end for (i = 0; i < nelmts... */ + } /* end if (region_output... */ + else { + for (i = 0; i < nelmts; i++, ctx->cur_elmt++, elmt_counter++) { + void* memref = mem + i * size; + /* Render the data element begin*/ + h5tools_str_reset(&buffer); + h5tools_str_sprint(&buffer, info, container, type, memref, ctx); + + if (i + 1 < nelmts || (flags & END_OF_DATA) == 0) + h5tools_str_append(&buffer, "%s", OPT(info->elmt_suf1, ",")); + + dimension_break = h5tools_render_element(stream, info, ctx, &buffer, + &curr_pos, ncols, i, elmt_counter); + /* Render the data element end*/ + if(FALSE == dimension_break) + elmt_counter = 0; + } /* end for (i = 0; i < nelmts... */ + } + + h5tools_str_close(&buffer); + }/* else bin */ +} + +/*------------------------------------------------------------------------- + * Audience: Public + * Chapter: H5Tools Library + * Purpose: Print the data values from a dataset referenced by region blocks. + * + * Description: + * This is a special case subfunction to print the data in a region reference of type blocks. + * + * Return: + * The function returns FAIL if there was an error, otherwise SUCEED + * + * Parameters Description: + * h5tools_str_t *buffer is the string into which to render + * size_t ncols + * int ndims is the number of dimensions of the region element + * hssize_t nblocks is the number of blocks in the region + *------------------------------------------------------------------------- + */ +static int +h5tools_print_region_data_blocks(hid_t region_id, + FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx, + h5tools_str_t *buffer/*string into which to render */, size_t ncols, + int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata) +{ + hbool_t dimension_break = TRUE; + hsize_t *dims1 = NULL; + hsize_t *start = NULL; + hsize_t *count = NULL; + hsize_t blkndx; + hsize_t total_size[H5S_MAX_RANK]; + hsize_t elmtno; /* elemnt index */ + hsize_t curr_pos = 0; + unsigned int region_flags; /* buffer extent flags */ + hsize_t numelem; + hsize_t numindex; + size_t jndx; + int indx; + int type_size; + int ret_value = SUCCEED; + hid_t mem_space = -1; + hid_t sid1 = -1; + h5tools_context_t ctx; + void *region_buf = NULL; + + HDassert(info); + HDassert(cur_ctx); + HDassert(buffer); + HDassert(ptdata); + + HDmemset(&ctx, 0, sizeof(ctx)); + /* Get the dataspace of the dataset */ + if((sid1 = H5Dget_space(region_id)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); + + /* Allocate space for the dimension array */ + if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for dims"); + + /* find the dimensions of each data space from the block coordinates */ + numelem = 1; + for (jndx = 0; jndx < ndims; jndx++) { + dims1[jndx] = ptdata[jndx + ndims] - ptdata[jndx] + 1; + numelem = dims1[jndx] * numelem; + } + + /* Create dataspace for reading buffer */ + if((mem_space = H5Screate_simple(ndims, dims1, NULL)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed"); + + if((type_size = H5Tget_size(type_id)) == 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); + + if((region_buf = HDmalloc(type_size * numelem)) == NULL) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate region buffer"); + + /* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reading memory dataset */ + /* 1 2 n 1 2 n */ + if((start = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for start"); + + if((count = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for count"); + + curr_pos = 0; + ctx.indent_level = cur_ctx->indent_level; + ctx.cur_column = cur_ctx->cur_column; + ctx.prev_multiline = cur_ctx->prev_multiline; + ctx.ndims = ndims; + for (blkndx = 0; blkndx < nblocks; blkndx++) { + ctx.need_prefix = TRUE; + ctx.cur_elmt = 0; + for (indx = 0; indx < ndims; indx++) { + start[indx] = ptdata[indx + blkndx * ndims * 2]; + count[indx] = dims1[indx]; + } + + if(H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sselect_hyperslab failed"); + + if(H5Dread(region_id, type_id, mem_space, sid1, H5P_DEFAULT, region_buf) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dread failed"); + + ctx.indent_level++; + if(H5Sget_simple_extent_dims(mem_space, total_size, NULL) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); + + /* assume entire data space to be printed */ + for (indx = 0; indx < (size_t) ctx.ndims; indx++) + ctx.p_min_idx[indx] = start[indx]; + init_acc_pos(&ctx, total_size); + + /* print the data */ + region_flags = START_OF_DATA; + if (blkndx == nblocks - 1) + region_flags |= END_OF_DATA; + + for (indx = 0; indx < (size_t)ctx.ndims; indx++) + ctx.p_max_idx[indx] = dims1[indx]; + + curr_pos = 0; + ctx.sm_pos = blkndx*2*ndims; + ctx.size_last_dim = dims1[ndims-1]; + + h5tools_region_simple_prefix(stream, info, &ctx, curr_pos, ptdata, 0); + + elmtno = 0; + for (numindex = 0; numindex < numelem; numindex++, elmtno++, ctx.cur_elmt++) { + /* Render the region data element begin */ + h5tools_str_reset(buffer); + + h5tools_str_append(buffer, "%s", numindex ? OPTIONAL_LINE_BREAK "" : ""); + h5tools_str_sprint(buffer, info, region_id, type_id, + ((char*)region_buf + numindex * type_size), &ctx); + + if (numindex + 1 < numelem || (region_flags & END_OF_DATA) == 0) + h5tools_str_append(buffer, "%s", OPT(info->elmt_suf1, ",")); + + dimension_break = h5tools_render_region_element(stream, info, &ctx, buffer, &curr_pos, + ncols, ptdata, numindex, elmtno); + /* Render the region data element end */ + + if(FALSE == dimension_break) + elmtno = 0; + } /* end for (jndx = 0; jndx < numelem; jndx++, region_elmtno++, ctx.cur_elmt++) */ + + ctx.indent_level--; + } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */ + + done: + HDfree(start); + HDfree(count); + HDfree(region_buf); + HDfree(dims1); + + if(H5Sclose(mem_space) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + if(H5Sclose(sid1) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + + return ret_value; +} + +/*------------------------------------------------------------------------- + * Audience: Public + * Chapter: H5Tools Library + * Purpose: Print some values from a dataset referenced by region blocks. + * + * Description: + * This is a special case subfunction to dump a region reference using blocks. + * + * Return: + * The function returns False if the last dimension has been reached, otherwise True + * + * In/Out: + * h5tools_context_t *ctx + * hsize_t *curr_pos + * + * Parameters Description: + * h5tools_str_t *buffer is the string into which to render + * hsize_t curr_pos is the total data element position + * size_t ncols + * hsize_t region_elmt_counter is the region element loop counter + * hsize_t elmt_count is the data element loop counter + *------------------------------------------------------------------------- + */ +hbool_t +h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, + FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx/*in,out*/, + h5tools_str_t *buffer/*string into which to render */, + hsize_t *curr_pos/*total data element position*/, + size_t ncols, hsize_t region_elmt_counter/*element counter*/, + hsize_t elmt_counter) +{ + HERR_INIT(hbool_t, TRUE) + hbool_t dimension_break = TRUE; + hssize_t nblocks; + hsize_t alloc_size; + hsize_t *ptdata = NULL; + int ndims; + hid_t dtype = -1; + hid_t type_id = -1; + int i; + + HDassert(info); + HDassert(ctx); + HDassert(buffer); + + if((nblocks = H5Sget_select_hyper_nblocks(region_space)) <= 0) + H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_hyper_nblocks failed"); + + /* Print block information */ + if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0) + H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + + /* Render the region { element begin */ + h5tools_str_reset(buffer); + + h5tools_str_append(buffer, "{"); + dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); + /* Render the region { element end */ + + ctx->indent_level++; + ctx->need_prefix = TRUE; + + /* Render the region datatype info and indices element begin */ + h5tools_str_reset(buffer); + h5tools_str_append(buffer, "REGION_TYPE BLOCK "); + + alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]); + HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ + if((ptdata = (hsize_t*) HDmalloc((size_t) alloc_size)) == NULL) + HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); + + H5_CHECK_OVERFLOW(nblocks, hssize_t, hsize_t); + if(H5Sget_select_hyper_blocklist(region_space, (hsize_t) 0, (hsize_t) nblocks, ptdata) < 0) + HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Rget_select_hyper_blocklist failed"); + + for (i = 0; i < nblocks; i++) { + int j; + + h5tools_str_append(buffer, info->dset_blockformat_pre, + i ? "," OPTIONAL_LINE_BREAK " " : "", (unsigned long) i); + + /* Start coordinates and opposite corner */ + for (j = 0; j < ndims; j++) + h5tools_str_append(buffer, "%s" HSIZE_T_FORMAT, j ? "," : "(", + ptdata[i * 2 * ndims + j]); + + for (j = 0; j < ndims; j++) + h5tools_str_append(buffer, "%s" HSIZE_T_FORMAT, j ? "," : ")-(", + ptdata[i * 2 * ndims + j + ndims]); + + h5tools_str_append(buffer, ")"); + } /* end for (i = 0; i < nblocks; i++) */ + + dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); + /* Render the region datatype info and indices element end */ + + ctx->need_prefix = TRUE; + + if((dtype = H5Dget_type(region_id)) < 0) + HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Dget_type failed"); + if((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0) + HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Tget_native_type failed"); + + /* Render the datatype element begin */ + h5tools_str_reset(buffer); + h5tools_str_append(buffer, "%s %s ", + h5tools_dump_header_format->datatypebegin, + h5tools_dump_header_format->datatypeblockbegin); + + ctx->indent_level++; + h5tools_print_datatype(stream, buffer, info, ctx, dtype, TRUE); + ctx->indent_level--; + + if (HDstrlen(h5tools_dump_header_format->datatypeblockend)) { + h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datatypeblockend); + if (HDstrlen(h5tools_dump_header_format->datatypeend)) + h5tools_str_append(buffer, " "); + } + if (HDstrlen(h5tools_dump_header_format->datatypeend)) + h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datatypeend); + + dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); + /* Render the datatype element end */ + + ctx->need_prefix = TRUE; + + /* Render the dataspace element begin */ + h5tools_str_reset(buffer); + h5tools_str_append(buffer, "%s ", h5tools_dump_header_format->dataspacebegin); + + h5tools_print_dataspace(stream, buffer, info, ctx, region_space); + + if (HDstrlen(h5tools_dump_header_format->dataspaceblockend)) { + h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend); + if (HDstrlen(h5tools_dump_header_format->dataspaceend)) + h5tools_str_append(buffer, " "); + } + if (HDstrlen(h5tools_dump_header_format->dataspaceend)) + h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend); + + dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); + /* Render the dataspace element end */ + + ctx->need_prefix = TRUE; + + /* Render the databegin element begin */ + h5tools_str_reset(buffer); + h5tools_str_append(buffer, "%s %s ", + h5tools_dump_header_format->databegin, + h5tools_dump_header_format->datablockbegin); + dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); + /* Render the databegin element end */ + + ctx->need_prefix = TRUE; + + h5tools_print_region_data_blocks(region_id, rawdatastream, info, ctx, + buffer, ncols, ndims, type_id, nblocks, ptdata); + + done: + HDfree(ptdata); + + if(H5Tclose(type_id) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + + if(H5Tclose(dtype) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + + ctx->need_prefix = TRUE; + + /* Render the dataend element begin */ + h5tools_str_reset(buffer); + h5tools_str_append(buffer, "%s %s ", + h5tools_dump_header_format->dataend, + h5tools_dump_header_format->datablockend); + dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, + ncols, region_elmt_counter, elmt_counter); + /* Render the dataend element end */ + + ctx->indent_level--; + ctx->need_prefix = TRUE; + + /* Render the region } element begin */ + h5tools_str_reset(buffer); + h5tools_str_append(buffer, "}"); + dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, + ncols, region_elmt_counter, elmt_counter); + /* Render the region } element end */ + + H5_LEAVE(dimension_break) + + CATCH + return ret_value; +} + +/*------------------------------------------------------------------------- + * Audience: Public + * Chapter: H5Tools Library + * Purpose: Print the data values from a dataset referenced by region points. + * + * Description: + * This is a special case subfunction to print the data in a region reference of type points. + * + * Return: + * The function returns FAIL on error, otherwise SUCCEED + * + * Parameters Description: + * h5tools_str_t *buffer is the string into which to render + * size_t ncols + * int ndims is the number of dimensions of the region element + * hssize_t npoints is the number of points in the region + *------------------------------------------------------------------------- + */ +int +h5tools_print_region_data_points(hid_t region_space, hid_t region_id, + FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx, + h5tools_str_t *buffer, size_t ncols, + int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata) +{ + hbool_t dimension_break = TRUE; + hsize_t *dims1 = NULL; + hsize_t elmtno; /* elemnt index */ + hsize_t curr_pos = 0; + hsize_t total_size[H5S_MAX_RANK]; + size_t jndx; + int indx; + int type_size; + int ret_value = SUCCEED; + unsigned int region_flags; /* buffer extent flags */ + hid_t mem_space = -1; + void *region_buf = NULL; + h5tools_context_t ctx; + + HDassert(info); + HDassert(cur_ctx); + HDassert(buffer); + HDassert(ptdata); + + HDmemset(&ctx, 0, sizeof(ctx)); + /* Allocate space for the dimension array */ + if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for dims"); + + dims1[0] = npoints; + + /* Create dataspace for reading buffer */ + if((mem_space = H5Screate_simple(1, dims1, NULL)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed"); + + if((type_size = H5Tget_size(type_id)) == 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); + + if((region_buf = HDmalloc(type_size * npoints)) == NULL) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for region"); + + curr_pos = 0; + ctx.indent_level = cur_ctx->indent_level; + ctx.cur_column = cur_ctx->cur_column; + ctx.prev_multiline = cur_ctx->prev_multiline; + ctx.ndims = ndims; + + if(H5Dread(region_id, type_id, mem_space, region_space, H5P_DEFAULT, region_buf) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed"); + + elmtno = 0; + for (jndx = 0; jndx < npoints; jndx++, elmtno++) { + ctx.need_prefix = TRUE; + ctx.cur_elmt = 0; /* points are always 0 */ + + ctx.indent_level++; + if(H5Sget_simple_extent_dims(mem_space, total_size, NULL) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); + + /* assume entire data space to be printed */ + for (indx = 0; indx < (size_t) ctx.ndims; indx++) + ctx.p_min_idx[indx] = 0; + init_acc_pos(&ctx, total_size); + + /* print the data */ + region_flags = START_OF_DATA; + if (jndx == npoints - 1) + region_flags |= END_OF_DATA; + + for (indx = 0; indx < (size_t)ctx.ndims; indx++) + ctx.p_max_idx[indx] = cur_ctx->p_max_idx[indx]; + + ctx.sm_pos = jndx * ndims; + if (ctx.ndims > 0) { + ctx.size_last_dim = (int) (ctx.p_max_idx[ctx.ndims - 1]); + } + else + ctx.size_last_dim = 0; + + curr_pos = 0; /* points requires constant 0 */ + h5tools_region_simple_prefix(stream, info, &ctx, curr_pos, ptdata, 0); + + /* Render the point element begin */ + h5tools_str_reset(buffer); + + h5tools_str_append(buffer, "%s", jndx ? OPTIONAL_LINE_BREAK "" : ""); + h5tools_str_sprint(buffer, info, region_id, type_id, + ((char*)region_buf + jndx * type_size), &ctx); + + if (jndx + 1 < npoints || (region_flags & END_OF_DATA) == 0) + h5tools_str_append(buffer, "%s", OPT(info->elmt_suf1, ",")); + + dimension_break = h5tools_render_region_element(stream, info, &ctx, buffer, &curr_pos, + ncols, ptdata, (hsize_t)0, elmtno); + /* Render the point element end */ + if(FALSE == dimension_break) + elmtno = 0; + + ctx.indent_level--; + } /* end for (jndx = 0; jndx < npoints; jndx++, elmtno++) */ + + done: + HDfree(region_buf); + HDfree(dims1); + + if(H5Sclose(mem_space) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + + return ret_value; +} + +/*------------------------------------------------------------------------- + * Audience: Public + * Chapter: H5Tools Library + * Purpose: Print some values from a dataset referenced by region points. + * + * Description: + * This is a special case subfunction to dump a region reference using points. + * + * Return: + * The function returns False if the last dimension has been reached, otherwise True + * + * In/Out: + * h5tools_context_t *ctx + * hsize_t *curr_pos + * + * Parameters Description: + * h5tools_str_t *buffer is the string into which to render + * hsize_t curr_pos is the total data element position + * size_t ncols + * hsize_t region_elmt_counter is the region element loop counter + * hsize_t elmt_count is the data element loop counter + *------------------------------------------------------------------------- + */ +hbool_t +h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, + FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, + h5tools_str_t *buffer, hsize_t *curr_pos, size_t ncols, hsize_t region_elmt_counter, + hsize_t elmt_counter) { + HERR_INIT(hbool_t, TRUE) + hbool_t dimension_break = TRUE; + hssize_t npoints; + hsize_t alloc_size; + hsize_t *ptdata; + int ndims; + hssize_t indx; + hid_t dtype; + hid_t type_id; + + HDassert(info); + HDassert(ctx); + HDassert(buffer); + + if((npoints = H5Sget_select_elem_npoints(region_space)) <= 0) + H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_elem_npoints failed"); + + /* Allocate space for the dimension array */ + if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0) + H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + + /* Render the region { element begin */ + h5tools_str_reset(buffer); + + h5tools_str_append(buffer, "{"); + dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); + /* Render the region { element end */ + + /* Render the region datatype info and indices element begin */ + h5tools_str_reset(buffer); + + ctx->indent_level++; + ctx->need_prefix = TRUE; + h5tools_str_append(buffer, "REGION_TYPE POINT "); + + alloc_size = npoints * ndims * sizeof(ptdata[0]); + HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ + if(NULL == (ptdata = (hsize_t *)HDmalloc((size_t) alloc_size))) + HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); + + H5_CHECK_OVERFLOW(npoints, hssize_t, hsize_t); + if(H5Sget_select_elem_pointlist(region_space, (hsize_t) 0, (hsize_t) npoints, ptdata) < 0) + HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Sget_select_elem_pointlist failed"); + + for (indx = 0; indx < npoints; indx++) { + int loop_indx; + + h5tools_str_append(buffer, info->dset_ptformat_pre, + indx ? "," OPTIONAL_LINE_BREAK " " : "", (unsigned long) indx); + + for (loop_indx = 0; loop_indx < ndims; loop_indx++) + h5tools_str_append(buffer, "%s" HSIZE_T_FORMAT, loop_indx ? "," : "(", + ptdata[indx * ndims + loop_indx]); + + h5tools_str_append(buffer, ")"); + } /* end for (indx = 0; indx < npoints; indx++) */ + + dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); + /* Render the region datatype info and indices element end */ + + ctx->need_prefix = TRUE; + + if((dtype = H5Dget_type(region_id)) < 0) + HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Dget_type failed"); + + if((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0) + HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Tget_native_type failed"); + + /* Render the datatype element begin */ + h5tools_str_reset(buffer); + h5tools_str_append(buffer, "%s %s ", + h5tools_dump_header_format->datatypebegin, + h5tools_dump_header_format->datatypeblockbegin); + + ctx->indent_level++; + h5tools_print_datatype(stream, buffer, info, ctx, dtype, TRUE); + ctx->indent_level--; + + if (HDstrlen(h5tools_dump_header_format->datatypeblockend)) { + h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datatypeblockend); + if (HDstrlen(h5tools_dump_header_format->datatypeend)) + h5tools_str_append(buffer, " "); + } + if (HDstrlen(h5tools_dump_header_format->datatypeend)) + h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datatypeend); + + dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); + /* Render the datatype element end */ + + ctx->need_prefix = TRUE; + + /* Render the dataspace element begin */ + h5tools_str_reset(buffer); + + ctx->need_prefix = TRUE; + h5tools_str_append(buffer, "%s ", h5tools_dump_header_format->dataspacebegin); + + h5tools_print_dataspace(stream, buffer, info, ctx, region_space); + + if (HDstrlen(h5tools_dump_header_format->dataspaceblockend)) { + h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend); + if (HDstrlen(h5tools_dump_header_format->dataspaceend)) + h5tools_str_append(buffer, " "); + } + if (HDstrlen(h5tools_dump_header_format->dataspaceend)) + h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend); + + dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); + /* Render the dataspace element end */ + + ctx->need_prefix = TRUE; + + /* Render the databegin element begin */ + h5tools_str_reset(buffer); + + h5tools_str_append(buffer, "%s %s ", + h5tools_dump_header_format->databegin, + h5tools_dump_header_format->datablockbegin); + + dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter); + + ctx->need_prefix = TRUE; + + h5tools_print_region_data_points(region_space, region_id, + rawdatastream, info, ctx, buffer, ncols, ndims, type_id, npoints, ptdata); + + done: + HDfree(ptdata); + + if(H5Tclose(type_id) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + + if(H5Tclose(dtype) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + + ctx->need_prefix = TRUE; + + /* Render the dataend element begin */ + h5tools_str_reset(buffer); + h5tools_str_append(buffer, "%s %s ", + h5tools_dump_header_format->dataend, + h5tools_dump_header_format->datablockend); + dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, + ncols, region_elmt_counter, elmt_counter); + /* Render the dataend element end*/ + + ctx->indent_level--; + ctx->need_prefix = TRUE; + + /* Render the region } element begin */ + h5tools_str_reset(buffer); + h5tools_str_append(buffer, "}"); + dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, + ncols, region_elmt_counter, elmt_counter); + /* Render the region } element end */ + + H5_LEAVE(dimension_break) +CATCH + return ret_value; +} + +/*------------------------------------------------------------------------- + * Audience: Public + * Chapter: H5Tools Library + * Purpose: print out the data for a subset of a dataset. + * Description: + * + * Select a hyperslab from the dataset DSET using the parameters + * specified in SSET. Dump this out to STREAM. + * + * Hyperslabs select "count" blocks of size "block", spaced "stride" elements + * from each other, starting at coordinate "start". + * + * Return: + * On success, return SUCCEED. Otherwise, the function returns FAIL. + * + * Algorithm + * + * The parameters from SSET are translated into temporary + * variables so that 1 row is printed at a time (getting the coordinate indices + * at each row). + * We define the stride, count and block to be 1 in the row dimension to achieve + * this and advance until all points are printed. + * + * The element position is obtained from the matrix according to: + * 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 + * + *------------------------------------------------------------------------- + */ +static herr_t +h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, + hid_t dset, hid_t p_type, struct subset_t *sset, + hid_t f_space, hsize_t hyperslab_count, + hsize_t *temp_start,/* start inside offset count loop */ + hsize_t *temp_count,/* count inside offset count loop */ + hsize_t *temp_block,/* block size used in loop */ + hsize_t *temp_stride,/* stride size used in loop */ + hsize_t *total_size,/* total size of dataset */ + unsigned int row_dim/* index of row_counter dimension */) +{ + HERR_INIT(herr_t, SUCCEED) + size_t i; /* counters */ + size_t j; /* counters */ + hsize_t zero[1] = {0}; /* vector of zeros */ + unsigned int flags; /* buffer extent flags */ + hsize_t elmtno; /* elemnt index */ + hsize_t low[H5S_MAX_RANK]; /* low bound of hyperslab */ + hsize_t high[H5S_MAX_RANK]; /* higher bound of hyperslab */ + size_t p_type_nbytes; /* size of memory type */ + hsize_t sm_size[H5S_MAX_RANK]; /* stripmine size */ + hsize_t sm_nbytes; /* bytes per stripmine */ + hssize_t ssm_nelmts; /* elements per stripmine*/ + hsize_t sm_nelmts; /* elements per stripmine*/ + unsigned char *sm_buf = NULL; /* buffer for raw data */ + hid_t sm_space = -1; /* stripmine data space */ + hsize_t size_row_block; /* size for blocks along rows */ + hsize_t row_counter = 0; + + /* VL data special information */ + unsigned int vl_data = 0; /* contains VL datatypes */ + + if ((size_t) ctx->ndims > NELMTS(sm_size)) + H5E_THROW(FAIL, H5E_tools_min_id_g, "ndims and sm_size comparision failed"); + + if (ctx->ndims > 0) + init_acc_pos(ctx, total_size); + + size_row_block = sset->block.data[row_dim]; + + /* Check if we have VL data in the dataset's datatype */ + if (h5tools_detect_vlen_str(p_type) == TRUE) + vl_data = TRUE; + if (H5Tdetect_class(p_type, H5T_VLEN) == TRUE) + vl_data = TRUE; + + /* display loop */ + for (; hyperslab_count > 0; temp_start[row_dim] += temp_stride[row_dim], hyperslab_count--) { + /* jump rows if size of block exceeded + cases where block > 1 only and stride > block */ + if (size_row_block > 1 + && row_counter == size_row_block + && sset->stride.data[row_dim] > sset->block.data[row_dim]) { + + hsize_t increase_rows = sset->stride.data[row_dim] - sset->block.data[row_dim]; + temp_start[row_dim] += increase_rows; + row_counter = 0; + } + + row_counter++; + + /* calculate the potential number of elements we're going to print */ + if(H5Sselect_hyperslab(f_space, H5S_SELECT_SET, temp_start, temp_stride, temp_count, temp_block) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed"); + + if((ssm_nelmts = H5Sget_select_npoints(f_space)) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_select_npoints failed"); + sm_nelmts = (hsize_t)ssm_nelmts; + + if (sm_nelmts > 0) { + /* + * determine the strip mine size and allocate a buffer. the strip mine is + * a hyperslab whose size is manageable. + */ + if((sm_nbytes = p_type_nbytes = H5Tget_size(p_type)) == 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); + + if (ctx->ndims > 0) + for (i = ctx->ndims; i > 0; --i) { + hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes; + if (size == 0) /* datum size > H5TOOLS_BUFSIZE */ + size = 1; + sm_size[i - 1] = MIN(total_size[i - 1], size); + sm_nbytes *= sm_size[i - 1]; + HDassert(sm_nbytes > 0); + } + + HDassert(sm_nbytes == (hsize_t) ((size_t) sm_nbytes)); /*check for overflow*/ + if(NULL == (sm_buf = (unsigned char *)HDmalloc((size_t) sm_nelmts * p_type_nbytes))) + H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for strip-mine"); + + if((sm_space = H5Screate_simple(1, &sm_nelmts, NULL)) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed"); + + if(H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &sm_nelmts, NULL) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed"); + + /* read the data */ + if(H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dread failed"); + + /* print the data */ + flags = START_OF_DATA; + + if (hyperslab_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 */ + if(H5Sget_select_bounds(f_space, low, high) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_select_bounds failed"); + + elmtno = 0; + for (i = 0; i < (size_t) ctx->ndims - 1; i++) { + hsize_t offset = 1; /* accumulation of the previous dimensions */ + for (j = i + 1; j < (size_t) 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; + + ctx->need_prefix = TRUE; + + h5tools_dump_simple_data(stream, info, dset, ctx, flags, sm_nelmts, p_type, sm_buf); + + /* Reclaim any VL memory, if necessary */ + if (vl_data) + H5Dvlen_reclaim(p_type, sm_space, H5P_DEFAULT, sm_buf); + + if(H5Sclose(sm_space) < 0) + H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + if(sm_buf) + HDfree(sm_buf); + sm_buf = NULL; + } + else + H5E_THROW(SUCCEED, H5E_tools_min_id_g, "nothing to print"); + + ctx->continuation++; + + } /* hyperslab_count loop */ + +CATCH + if(sm_buf) + HDfree(sm_buf); + + return ret_value; +} + +/*------------------------------------------------------------------------- + * Audience: Public + * Chapter: H5Tools Library + * Purpose: print out the data for a subset of a dataset. + * Description: + * + * Select a hyperslab from the dataset DSET using the parameters + * specified in SSET. Dump this out to STREAM. + * + * Hyperslabs select "count" blocks of size "block", spaced "stride" elements + * from each other, starting at coordinate "start". + * + * Return: + * On success, return SUCCEED. Otherwise, the function returns FAIL. + * + * Algorithm + * + * The parameters from SSET are translated into temporary + * variables so that 1 row is printed at a time (getting the coordinate indices + * at each row). + * We define the stride, count and block to be 1 in the row dimension to achieve + * this and advance until all points are printed. + * + * The element position is obtained from the matrix according to: + * 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 + * + *------------------------------------------------------------------------- + */ +static herr_t +h5tools_display_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, + hid_t dset, hid_t p_type, struct subset_t *sset, + hid_t f_space, hsize_t *total_size) +{ + size_t i; /* counters */ + hsize_t n; /* counters */ + hsize_t count; /* hyperslab count */ + hsize_t outer_count; /* offset count */ + unsigned int row_dim; /* index of row_counter 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 */ + hsize_t temp_block[H5S_MAX_RANK];/* temporary block size used in loop */ + hsize_t temp_stride[H5S_MAX_RANK];/* temporary stride size used in loop */ + int reset_dim; + herr_t ret_value = SUCCEED; + + 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 < (size_t) ctx->ndims - 2; i++) { + /* block size is handled by containing h5tools_print_simple_subset call */ + outer_count = outer_count * sset->count.data[i]; + } + + /* initialize temporary start, count and maximum start */ + for (i = 0; i < (size_t) ctx->ndims; i++) { + temp_start[i] = sset->start.data[i]; + temp_count[i] = sset->count.data[i]; + temp_block[i] = sset->block.data[i]; + temp_stride[i] = sset->stride.data[i]; + max_start[i] = 0; + } + + if (ctx->ndims > 2) { + for (i = 0; i < (size_t) ctx->ndims - 2; i++) { + max_start[i] = temp_start[i] + sset->count.data[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 is the number of iterations to display all the rows, + the block size count times */ + count = sset->count.data[row_dim] * sset->block.data[row_dim]; + + /* always 1 row_counter at a time, that is a block of size 1, 1 time */ + temp_count[row_dim] = 1; + temp_block[row_dim] = 1; + + /* advance 1 row_counter at a time */ + if (sset->block.data[row_dim] > 1) + temp_stride[row_dim] = 1; + } + /* for the 1D case */ + else { + count = 1; + } + + h5tools_print_simple_subset(stream, info, ctx, dset, p_type, sset, + f_space, count, temp_start, temp_count, + temp_block, temp_stride, total_size, row_dim); + + 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.data[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.data[current_outer_dim]; + + /* consider block */ + if (sset->block.data[current_outer_dim] > 1) + temp_start[current_outer_dim]++; + + current_outer_dim--; + reset_dim = 1; + } + } while (current_outer_dim >= 0 && reset_dim); + + } /* ctx.ndims > 1 */ + + } /* outer_count */ + + return ret_value; +} + +/*------------------------------------------------------------------------- + * Audience: Public + * Chapter: H5Tools Library + * Purpose: Dump out a subset of a dataset. + * Description: + * + * Select a hyperslab from the dataset DSET using the parameters + * specified in SSET. Dump this out to STREAM. + * + * Hyperslabs select "count" blocks of size "block", spaced "stride" elements + * from each other, starting at coordinate "start". + * + * Return: + * On success, return SUCCEED. Otherwise, the function returns FAIL. + * + * Original programmer: + * Bill Wendling, Wednesday, March 07, 2001 + * + * Rewritten with modified algorithm by: + * Pedro Vicente, Wednesday, January 16, 2008, contributions from Quincey Koziol + * + * Algorithm + * + * In a inner loop, the parameters from SSET are translated into temporary + * variables so that 1 row is printed at a time (getting the coordinate indices + * at each row). + * We define the stride, count and block to be 1 in the row dimension to achieve + * this and advance until all points are printed. + * An outer loop for cases where dimensionality is greater than 2D is made. + * In each iteration, the 2D block is displayed in the inner loop. The remaining + * slower dimensions above the first 2 are incremented one at a time in the outer loop + * + * The element position is obtained from the matrix according to: + * 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 + * + *------------------------------------------------------------------------- + */ +static herr_t +h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t dset, + hid_t p_type, struct subset_t *sset) +{ + HERR_INIT(herr_t, SUCCEED) + int sndims; + hid_t f_space = -1; /* file data space */ + size_t i; /* counters */ + hsize_t total_size[H5S_MAX_RANK];/* total size of dataset*/ + + if((f_space = H5Dget_space(dset)) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); + + if((sndims = H5Sget_simple_extent_ndims(f_space)) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + ctx->ndims = (unsigned)sndims; + + /* assume entire data space to be printed */ + if (ctx->ndims > 0) + for (i = 0; i < (size_t) ctx->ndims; i++) + ctx->p_min_idx[i] = 0; + + if(H5Sget_simple_extent_dims(f_space, total_size, NULL) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); + ctx->size_last_dim = total_size[ctx->ndims - 1]; + + h5tools_display_simple_subset(stream, info, ctx, dset, p_type, sset, f_space, total_size); + +CATCH + if(f_space >= 0 && H5Sclose(f_space) < 0) + H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + + return ret_value; +} + +/*------------------------------------------------------------------------- + * Audience: Public + * Chapter: H5Tools Library + * Purpose: Print some values from a dataset with a simple data space. + * Description: + * This is a special case of h5tools_dump_dset(). This function only + * intended for dumping datasets -- it does strip mining and some other + * things which are unnecessary for smaller objects such as attributes + * (to print small objects like attributes simply read the attribute and + * call h5tools_dump_simple_mem()). + * Return: + * On success, the function returns SUCCEED. Otherwise, the function + * returns FAIL. + *------------------------------------------------------------------------- + */ +static int +h5tools_dump_simple_dset(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, + hid_t dset, hid_t p_type) +{ + hid_t f_space; /* file data space */ + hsize_t elmtno; /* counter */ + size_t i; /* counter */ + int carry; /* counter carry value */ + hsize_t zero[8]; /* vector of zeros */ + unsigned int flags; /* buffer extent flags */ + hsize_t total_size[H5S_MAX_RANK]; /* total size of dataset*/ + + /* Print info */ + size_t p_type_nbytes; /* size of memory type */ + hsize_t p_nelmts; /* total selected elmts */ + + /* Stripmine info */ + hsize_t sm_size[H5S_MAX_RANK]; /* stripmine size */ + hsize_t sm_nbytes; /* bytes per stripmine */ + hsize_t sm_nelmts; /* elements per stripmine*/ + unsigned char *sm_buf = NULL; /* buffer for raw data */ + hid_t sm_space; /* stripmine data space */ + + /* Hyperslab info */ + hsize_t hs_offset[H5S_MAX_RANK]; /* starting offset */ + hsize_t hs_size[H5S_MAX_RANK]; /* size this pass */ + hsize_t hs_nelmts; /* elements in request */ + + /* VL data special information */ + unsigned int vl_data = 0; /* contains VL datatypes */ + + f_space = H5Dget_space(dset); + + if (f_space == FAIL) + return FAIL; + + ctx->ndims = H5Sget_simple_extent_ndims(f_space); + + if ((size_t)ctx->ndims > NELMTS(sm_size)) { + H5Sclose(f_space); + return FAIL; + } + + /* Assume entire data space to be printed */ + if (ctx->ndims > 0) + for (i = 0; i < (size_t)ctx->ndims; i++) + ctx->p_min_idx[i] = 0; + + H5Sget_simple_extent_dims(f_space, total_size, NULL); + + /* calculate the number of elements we're going to print */ + p_nelmts = 1; + + if (ctx->ndims > 0) { + for (i = 0; i < ctx->ndims; i++) + p_nelmts *= total_size[i]; + ctx->size_last_dim = (total_size[ctx->ndims - 1]); + } /* end if */ + else + ctx->size_last_dim = 0; + + if (p_nelmts == 0) { + /* nothing to print */ + H5Sclose(f_space); + return SUCCEED; + } + + /* Check if we have VL data in the dataset's datatype */ + if (h5tools_detect_vlen_str(p_type) == TRUE) + vl_data = TRUE; + if (H5Tdetect_class(p_type, H5T_VLEN) == TRUE) + vl_data = TRUE; + + /* + * 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) { + hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes; + if ( size == 0) /* datum size > H5TOOLS_BUFSIZE */ + size = 1; + sm_size[i - 1] = MIN(total_size[i - 1], size); + sm_nbytes *= sm_size[i - 1]; + HDassert(sm_nbytes > 0); + } + } + + if(!sm_nbytes) + goto done; + + HDassert(sm_nbytes == (hsize_t)((size_t)sm_nbytes)); /*check for overflow*/ + sm_buf = (unsigned char *)HDmalloc((size_t)sm_nbytes); + + 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 */ + HDmemset(hs_offset, 0, sizeof hs_offset); + HDmemset(zero, 0, sizeof zero); + + for (elmtno = 0; elmtno < p_nelmts; elmtno += hs_nelmts) { + /* Calculate the hyperslab size */ + if (ctx->ndims > 0) { + for (i = 0, hs_nelmts = 1; i < ctx->ndims; i++) { + hs_size[i] = MIN(total_size[i] - hs_offset[i], sm_size[i]); + ctx->p_max_idx[i] = ctx->p_min_idx[i] + hs_size[i]; + hs_nelmts *= hs_size[i]; + } + + H5Sselect_hyperslab(f_space, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL); + H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &hs_nelmts, NULL); + } + else { + H5Sselect_all(f_space); + H5Sselect_all(sm_space); + hs_nelmts = 1; + } + + /* Read the data */ + if (H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) < 0) { + H5Sclose(f_space); + H5Sclose(sm_space); + HDfree(sm_buf); + return FAIL; + } + + /* Print the data */ + flags = (elmtno == 0) ? START_OF_DATA : 0; + flags |= ((elmtno + hs_nelmts) >= p_nelmts) ? END_OF_DATA : 0; + + /* 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, hs_nelmts, p_type, sm_buf); + + /* Reclaim any VL memory, if necessary */ + if (vl_data) + H5Dvlen_reclaim(p_type, sm_space, H5P_DEFAULT, sm_buf); + + /* Calculate the next hyperslab offset */ + for (i = ctx->ndims, carry = 1; i > 0 && carry; --i) { + ctx->p_min_idx[i - 1] = ctx->p_max_idx[i - 1]; + hs_offset[i - 1] += hs_size[i - 1]; + + if (hs_offset[i - 1] == total_size[i - 1]) + hs_offset[i - 1] = 0; + else + carry = 0; + } + + ctx->continuation++; + } + + HDfree(sm_buf); + +done: + H5Sclose(sm_space); + H5Sclose(f_space); + + return SUCCEED; +} + +/*------------------------------------------------------------------------- + * Function: h5tools_dump_simple_mem + * + * Purpose: Print some values from memory with a simple data space. + * This is a special case of h5tools_dump_mem(). + * + * Return: Success: SUCCEED + * Failure: FAIL + * + *------------------------------------------------------------------------- + */ +static int +h5tools_dump_simple_mem(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t obj_id, + hid_t type, hid_t space, void *mem) +{ + int i; /*counters */ + hsize_t nelmts; /*total selected elmts */ + + ctx->ndims = H5Sget_simple_extent_ndims(space); + + if ((size_t) ctx->ndims > NELMTS(ctx->p_min_idx)) + return FAIL; + + /* Assume entire data space to be printed */ + for (i = 0; i < ctx->ndims; i++) + ctx->p_min_idx[i] = 0; + + H5Sget_simple_extent_dims(space, ctx->p_max_idx, NULL); + + for (i = 0, nelmts = 1; ctx->ndims != 0 && i < ctx->ndims; i++) + nelmts *= ctx->p_max_idx[i] - ctx->p_min_idx[i]; + + if (nelmts == 0) + return SUCCEED; /*nothing to print*/ + if (ctx->ndims > 0) { + HDassert(ctx->p_max_idx[ctx->ndims - 1] == (hsize_t) ((int) ctx->p_max_idx[ctx->ndims - 1])); + ctx->size_last_dim = (int) (ctx->p_max_idx[ctx->ndims - 1]); + } /* end if */ + else + ctx->size_last_dim = 0; + + if (ctx->ndims > 0) + init_acc_pos(ctx, ctx->p_max_idx); + + h5tools_dump_simple_data(stream, info, obj_id, ctx, START_OF_DATA | END_OF_DATA, nelmts, type, mem); + + return SUCCEED; +} + +/*------------------------------------------------------------------------- + * Function: h5tools_dump_dset + * + * Purpose: Print some values from a dataset DSET to the file STREAM + * after converting all types to P_TYPE (which should be a + * native type). If P_TYPE is a negative value then it will be + * computed from the dataset type using only native types. + * + * Note: This function is intended only for datasets since it does + * some things like strip mining which are unnecessary for + * smaller objects such as attributes. The easiest way to print + * small objects is to read the object into memory and call + * h5tools_dump_mem(). + * + * Return: Success: SUCCEED + * Failure: FAIL + * + * Modifications: + * Robb Matzke, 1999-06-07 + * If info->raw is set then the memory datatype will be the same + * as the file datatype. + * + * Bill Wendling, 2001-02-27 + * Renamed to ``h5tools_dump_dset'' and added the subsetting + * parameter. + * + *------------------------------------------------------------------------- + */ +int +h5tools_dump_dset(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, + hid_t dset, hid_t _p_type, struct subset_t *sset) +{ + hid_t f_space; + hid_t p_type = _p_type; + hid_t f_type; + H5S_class_t space_type; + int status = FAIL; + h5tool_format_t info_dflt; + /* Use default values */ + if (!stream) + stream = rawoutstream; + + if (!info) { + HDmemset(&info_dflt, 0, sizeof info_dflt); + info = &info_dflt; + } + + if (p_type < 0) { + f_type = H5Dget_type(dset); + + if (info->raw || bin_form == 1) + p_type = H5Tcopy(f_type); + else if (bin_form == 2) + p_type = h5tools_get_little_endian_type(f_type); + else if (bin_form == 3) + p_type = h5tools_get_big_endian_type(f_type); + else + p_type = h5tools_get_native_type(f_type); + + H5Tclose(f_type); + + if (p_type < 0) + goto done; + } + + /* Check the data space */ + f_space = H5Dget_space(dset); + + space_type = H5Sget_simple_extent_type(f_space); + + /* Print the data */ + if (space_type == H5S_SIMPLE || space_type == H5S_SCALAR) { + if(!sset) + status = h5tools_dump_simple_dset(rawdatastream, info, ctx, dset, p_type); + else + status = h5tools_dump_simple_subset(stream, info, ctx, dset, p_type, sset); + } + else + /* space is H5S_NULL */ + status = SUCCEED; + + /* Close the dataspace */ + H5Sclose(f_space); + +done: + if (p_type != _p_type) + H5Tclose(p_type); + + return status; +} + +/*------------------------------------------------------------------------- + * Function: h5tools_dump_mem + * + * Purpose: Displays the data contained in MEM. MEM must have the + * specified data TYPE and SPACE. Currently only simple data + * spaces are allowed and only the `all' selection. + * + * Return: Success: SUCCEED + * Failure: FAIL + * + *------------------------------------------------------------------------- + */ +int +h5tools_dump_mem(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, + hid_t obj_id, hid_t type, hid_t space, void *mem) +{ + HERR_INIT(int, SUCCEED) + h5tool_format_t info_dflt; + + /* Use default values */ + if (!stream) + stream = rawoutstream; + + if (!info) { + HDmemset(&info_dflt, 0, sizeof(info_dflt)); + info = &info_dflt; + } + + /* Check the data space */ + if (H5Sis_simple(space) <= 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sis_simple failed") + + H5_LEAVE(h5tools_dump_simple_mem(stream, info, ctx, obj_id, type, space, mem)) + +CATCH + return ret_value; +} + +/*------------------------------------------------------------------------- + * Function: print_datatype + * + * Purpose: print the datatype - do not prefix. + * + * Return: void + * + * In/Out: h5tools_str_t *buffer + * h5tools_context_t *ctx + * + *------------------------------------------------------------------------- + */ +int +h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_t *info, + h5tools_context_t *ctx, hid_t type, int object_search) +{ + HERR_INIT(int, SUCCEED) + char *mname; + hid_t mtype = -1; + hid_t str_type = -1; + hid_t super = -1; + hid_t tmp_type = -1; + int snmembers; + int sndims; + unsigned nmembers; + unsigned i; + size_t size = 0; + size_t ncols = 80; /*available output width */ + hsize_t dims[H5TOOLS_DUMP_MAX_RANK]; + hsize_t curr_pos = 0; /* total data element position */ + H5T_str_t str_pad; + H5T_cset_t cset; + H5T_order_t order; + H5T_class_t type_class; + H5T_sign_t sign; /* sign scheme value */ + htri_t is_vlstr = FALSE; + const char *sign_s = NULL; /* sign scheme string */ + const char *order_s = NULL; /* byte order string */ + + if((type_class = H5Tget_class(type)) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_class failed"); + if (object_search && H5Tcommitted(type) > 0) { + H5O_info_t oinfo; + obj_t *obj = NULL; /* Found object */ + + H5Oget_info(type, &oinfo); + obj = search_obj(h5dump_type_table, oinfo.addr); + + if(obj) { + if(!obj->recorded) { + h5tools_str_append(buffer,"\"/#"H5_PRINTF_HADDR_FMT"\"", obj->objno); + } + else + h5tools_str_append(buffer, "\"%s\"", obj->objname); + } + else { + error_msg("unknown committed type.\n"); + h5tools_setstatus(EXIT_FAILURE); + } + + return ret_value; + } + + if (info->line_ncols > 0) + ncols = info->line_ncols; + + switch (type_class) { + case H5T_INTEGER: + if (H5Tequal(type, H5T_STD_I8BE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_I8BE"); + } + else if (H5Tequal(type, H5T_STD_I8LE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_I8LE"); + } + else if (H5Tequal(type, H5T_STD_I16BE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_I16BE"); + } + else if (H5Tequal(type, H5T_STD_I16LE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_I16LE"); + } + else if (H5Tequal(type, H5T_STD_I32BE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_I32BE"); + } + else if (H5Tequal(type, H5T_STD_I32LE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_I32LE"); + } + else if (H5Tequal(type, H5T_STD_I64BE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_I64BE"); + } + else if (H5Tequal(type, H5T_STD_I64LE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_I64LE"); + } + else if (H5Tequal(type, H5T_STD_U8BE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_U8BE"); + } + else if (H5Tequal(type, H5T_STD_U8LE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_U8LE"); + } + else if (H5Tequal(type, H5T_STD_U16BE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_U16BE"); + } + else if (H5Tequal(type, H5T_STD_U16LE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_U16LE"); + } + else if (H5Tequal(type, H5T_STD_U32BE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_U32BE"); + } + else if (H5Tequal(type, H5T_STD_U32LE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_U32LE"); + } + else if (H5Tequal(type, H5T_STD_U64BE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_U64BE"); + } + else if (H5Tequal(type, H5T_STD_U64LE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_U64LE"); + } + else if (H5Tequal(type, H5T_NATIVE_SCHAR) == TRUE) { + h5tools_str_append(buffer, "H5T_NATIVE_SCHAR"); + } + else if (H5Tequal(type, H5T_NATIVE_UCHAR) == TRUE) { + h5tools_str_append(buffer, "H5T_NATIVE_UCHAR"); + } + else if (H5Tequal(type, H5T_NATIVE_SHORT) == TRUE) { + h5tools_str_append(buffer, "H5T_NATIVE_SHORT"); + } + else if (H5Tequal(type, H5T_NATIVE_USHORT) == TRUE) { + h5tools_str_append(buffer, "H5T_NATIVE_USHORT"); + } + else if (H5Tequal(type, H5T_NATIVE_INT) == TRUE) { + h5tools_str_append(buffer, "H5T_NATIVE_INT"); + } + else if (H5Tequal(type, H5T_NATIVE_UINT) == TRUE) { + h5tools_str_append(buffer, "H5T_NATIVE_UINT"); + } + else if (H5Tequal(type, H5T_NATIVE_LONG) == TRUE) { + h5tools_str_append(buffer, "H5T_NATIVE_LONG"); + } + else if (H5Tequal(type, H5T_NATIVE_ULONG) == TRUE) { + h5tools_str_append(buffer, "H5T_NATIVE_ULONG"); + } + else if (H5Tequal(type, H5T_NATIVE_LLONG) == TRUE) { + h5tools_str_append(buffer, "H5T_NATIVE_LLONG"); + } + else if (H5Tequal(type, H5T_NATIVE_ULLONG) == TRUE) { + h5tools_str_append(buffer, "H5T_NATIVE_ULLONG"); + } + else { + + /* byte order */ + if (H5Tget_size(type) > 1) { + order = H5Tget_order(type); + if (H5T_ORDER_LE == order) { + order_s = " little-endian"; + } + else if (H5T_ORDER_BE == order) { + order_s = " big-endian"; + } + else if (H5T_ORDER_VAX == order) { + order_s = " mixed-endian"; + } + else { + order_s = " unknown-byte-order"; + } + } + else { + order_s = ""; + } + + /* sign */ + if ((sign = H5Tget_sign(type)) >= 0) { + if (H5T_SGN_NONE == sign) { + sign_s = " unsigned"; + } + else if (H5T_SGN_2 == sign) { + sign_s = ""; + } + else { + sign_s = " unknown-sign"; + } + } + else { + sign_s = " unknown-sign"; + } + + /* print size, order, and sign */ + h5tools_str_append(buffer, "%lu-bit%s%s integer", + (unsigned long) (8 * H5Tget_size(type)), order_s, sign_s); + } + break; + + case H5T_FLOAT: + if (H5Tequal(type, H5T_IEEE_F32BE) == TRUE) { + h5tools_str_append(buffer, "H5T_IEEE_F32BE"); + } + else if (H5Tequal(type, H5T_IEEE_F32LE) == TRUE) { + h5tools_str_append(buffer, "H5T_IEEE_F32LE"); + } + else if (H5Tequal(type, H5T_IEEE_F64BE) == TRUE) { + h5tools_str_append(buffer, "H5T_IEEE_F64BE"); + } + else if (H5Tequal(type, H5T_IEEE_F64LE) == TRUE) { + h5tools_str_append(buffer, "H5T_IEEE_F64LE"); + } + else if (H5Tequal(type, H5T_VAX_F32) == TRUE) { + h5tools_str_append(buffer, "H5T_VAX_F32"); + } + else if (H5Tequal(type, H5T_VAX_F64) == TRUE) { + h5tools_str_append(buffer, "H5T_VAX_F64"); + } + else if (H5Tequal(type, H5T_NATIVE_FLOAT) == TRUE) { + h5tools_str_append(buffer, "H5T_NATIVE_FLOAT"); + } + else if (H5Tequal(type, H5T_NATIVE_DOUBLE) == TRUE) { + h5tools_str_append(buffer, "H5T_NATIVE_DOUBLE"); +#if H5_SIZEOF_LONG_DOUBLE !=0 + } + else if (H5Tequal(type, H5T_NATIVE_LDOUBLE) == TRUE) { + h5tools_str_append(buffer, "H5T_NATIVE_LDOUBLE"); +#endif + } + else { + + /* byte order */ + if (H5Tget_size(type) > 1) { + order = H5Tget_order(type); + if (H5T_ORDER_LE == order) { + order_s = " little-endian"; + } + else if (H5T_ORDER_BE == order) { + order_s = " big-endian"; + } + else if (H5T_ORDER_VAX == order) { + order_s = " mixed-endian"; + } + else { + order_s = " unknown-byte-order"; + } + } + else { + order_s = ""; + } + + /* print size and byte order */ + h5tools_str_append(buffer, "%lu-bit%s floating-point", + (unsigned long) (8 * H5Tget_size(type)), order_s); + + } + break; + + case H5T_TIME: + h5tools_str_append(buffer, "H5T_TIME: not yet implemented"); + break; + + case H5T_STRING: + /* Make a copy of type in memory in case when TYPE is on disk, the size + * will be bigger than in memory. This makes it easier to compare + * types in memory. */ + tmp_type = H5Tcopy(type); + size = H5Tget_size(tmp_type); + str_pad = H5Tget_strpad(tmp_type); + cset = H5Tget_cset(tmp_type); + is_vlstr = H5Tis_variable_str(tmp_type); + + curr_pos = ctx->cur_column; + h5tools_str_append(buffer, "H5T_STRING %s", h5tools_dump_header_format->strblockbegin); + h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level++; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(buffer); + + if (is_vlstr) + h5tools_str_append(buffer, "%s H5T_VARIABLE;", STRSIZE); + else + h5tools_str_append(buffer, "%s %d;", STRSIZE, (int) size); + h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(buffer); + + h5tools_str_append(buffer, "%s ", STRPAD); + if (str_pad == H5T_STR_NULLTERM) + h5tools_str_append(buffer, "H5T_STR_NULLTERM;"); + else if (str_pad == H5T_STR_NULLPAD) + h5tools_str_append(buffer, "H5T_STR_NULLPAD;"); + else if (str_pad == H5T_STR_SPACEPAD) + h5tools_str_append(buffer, "H5T_STR_SPACEPAD;"); + else + h5tools_str_append(buffer, "H5T_STR_ERROR;"); + h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(buffer); + + h5tools_str_append(buffer, "%s ", CSET); + + if (cset == H5T_CSET_ASCII) + h5tools_str_append(buffer, "H5T_CSET_ASCII;"); + else + h5tools_str_append(buffer, "unknown_cset;"); + h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(buffer); + + str_type = H5Tcopy(H5T_C_S1); + if (is_vlstr) + H5Tset_size(str_type, H5T_VARIABLE); + else + H5Tset_size(str_type, size); + H5Tset_cset(str_type, cset); + H5Tset_strpad(str_type, str_pad); + + h5tools_str_append(buffer, "%s ", CTYPE); + + /* Check C variable-length string first. Are the two types equal? */ + if (H5Tequal(tmp_type, str_type)) { + h5tools_str_append(buffer, "H5T_C_S1;"); + goto done; + } + + /* Change the endianness and see if they're equal. */ + order = H5Tget_order(tmp_type); + if (order == H5T_ORDER_LE) + H5Tset_order(str_type, H5T_ORDER_LE); + else if (order == H5T_ORDER_BE) + H5Tset_order(str_type, H5T_ORDER_BE); + + if (H5Tequal(tmp_type, str_type)) { + h5tools_str_append(buffer, "H5T_C_S1;"); + goto done; + } + + /* If not equal to C variable-length string, check Fortran type. */ + if(H5Tclose(str_type) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + str_type = H5Tcopy(H5T_FORTRAN_S1); + + H5Tset_cset(str_type, cset); + H5Tset_size(str_type, size); + H5Tset_strpad(str_type, str_pad); + + /* Are the two types equal? */ + if (H5Tequal(tmp_type, str_type)) { + h5tools_str_append(buffer, "H5T_FORTRAN_S1;"); + goto done; + } + + /* Change the endianness and see if they're equal. */ + order = H5Tget_order(tmp_type); + if (order == H5T_ORDER_LE) + H5Tset_order(str_type, H5T_ORDER_LE); + else if (order == H5T_ORDER_BE) + H5Tset_order(str_type, H5T_ORDER_BE); + + if (H5Tequal(tmp_type, str_type)) { + h5tools_str_append(buffer, "H5T_FORTRAN_S1;"); + goto done; + } + + /* Type doesn't match any of above. */ + h5tools_str_append(buffer, "unknown_one_character_type;"); + + done: + h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(buffer); + if(H5Tclose(str_type) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + if(H5Tclose(tmp_type) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + + h5tools_str_append(buffer, "%s", h5tools_dump_header_format->strblockend); + break; + + case H5T_BITFIELD: + if (H5Tequal(type, H5T_STD_B8BE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_B8BE"); + } + else if (H5Tequal(type, H5T_STD_B8LE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_B8LE"); + } + else if (H5Tequal(type, H5T_STD_B16BE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_B16BE"); + } + else if (H5Tequal(type, H5T_STD_B16LE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_B16LE"); + } + else if (H5Tequal(type, H5T_STD_B32BE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_B32BE"); + } + else if (H5Tequal(type, H5T_STD_B32LE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_B32LE"); + } + else if (H5Tequal(type, H5T_STD_B64BE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_B64BE"); + } + else if (H5Tequal(type, H5T_STD_B64LE) == TRUE) { + h5tools_str_append(buffer, "H5T_STD_B64LE"); + } + else { + h5tools_str_append(buffer, "undefined bitfield"); + } + break; + + case H5T_OPAQUE: + h5tools_str_append(buffer, "H5T_OPAQUE %s", h5tools_dump_header_format->structblockbegin); + h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); + ctx->indent_level++; + { + char *ttag = H5Tget_tag(type); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(buffer); + h5tools_str_append(buffer, "OPAQUE_TAG \"%s\";", ttag); + h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); + + if (ttag) + HDfree(ttag); + } + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(buffer); + h5tools_str_append(buffer, "%s", h5tools_dump_header_format->structblockend); + break; + + case H5T_COMPOUND: + if((snmembers = H5Tget_nmembers(type)) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed"); + nmembers = (unsigned)snmembers; + + h5tools_str_append(buffer, "H5T_COMPOUND %s", h5tools_dump_header_format->structblockbegin); + h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level++; + for (i = 0; i < nmembers; i++) { + mname = H5Tget_member_name(type, i); + if((mtype = H5Tget_member_type(type, i))>=0) { + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(buffer); + h5tools_print_datatype(stream, buffer, info, ctx, mtype, TRUE); + + h5tools_str_append(buffer, " \"%s\";", mname); + h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); + if(H5Tclose(mtype) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + } + else + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tget_member_type failed"); + HDfree(mname); + } + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(buffer); + h5tools_str_append(buffer, "%s", h5tools_dump_header_format->structblockend); + break; + + case H5T_REFERENCE: + h5tools_str_append(buffer, "H5T_REFERENCE"); + if (H5Tequal(type, H5T_STD_REF_DSETREG) == TRUE) { + h5tools_str_append(buffer, " { H5T_STD_REF_DSETREG }"); + } + else { + h5tools_str_append(buffer, " { H5T_STD_REF_OBJECT }"); + } + break; + + case H5T_ENUM: + if((super = H5Tget_super(type)) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed"); + + h5tools_str_append(buffer, "H5T_ENUM %s", h5tools_dump_header_format->enumblockbegin); + h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); + ctx->indent_level++; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(buffer); + h5tools_print_datatype(stream, buffer, info, ctx, super, TRUE); + + if(H5Tclose(super) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + + h5tools_str_append(buffer, ";"); + h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); + + h5tools_print_enum(stream, buffer, info, ctx, type); + + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(buffer); + h5tools_str_append(buffer, "%s", h5tools_dump_header_format->enumblockend); + + break; + + case H5T_VLEN: + if((super = H5Tget_super(type)) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed"); + + h5tools_str_append(buffer, "H5T_VLEN %s ", h5tools_dump_header_format->vlenblockbegin); + + h5tools_print_datatype(stream, buffer, info, ctx, super, TRUE); + + if(H5Tclose(super) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + + h5tools_str_append(buffer, "%s", h5tools_dump_header_format->vlenblockend); + + break; + + case H5T_ARRAY: + h5tools_str_append(buffer, "H5T_ARRAY { "); + + /* Get array information */ + if((sndims = H5Tget_array_ndims(type)) >= 0) { + unsigned ndims = (unsigned)sndims; + + if(H5Tget_array_dims2(type, dims) >= 0) { + /* Print array dimensions */ + for (i = 0; i < ndims; i++) + h5tools_str_append(buffer, "[" HSIZE_T_FORMAT "]", dims[i]); + + h5tools_str_append(buffer, " "); + } + else + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tget_array_dims2 failed"); + } + else + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tget_array_ndims failed"); + + /* Get array base type */ + if((super = H5Tget_super(type)) >= 0) { + /* Print base type */ + h5tools_print_datatype(stream, buffer, info, ctx, super, TRUE); + /* Close array base type */ + if(H5Tclose(super) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + } + else + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tget_super failed"); + + h5tools_str_append(buffer, " }"); + + break; + + default: + h5tools_str_append(buffer, "unknown datatype"); + break; + } + +CATCH + return ret_value; +} + +/*------------------------------------------------------------------------- + * Function: print_dataspace + * + * Purpose: print the dataspace. + * + * Return: void + * + * In/Out: h5tools_str_t *buffer + * h5tools_context_t *ctx + * + *------------------------------------------------------------------------- + */ +int +h5tools_print_dataspace(FILE *stream, h5tools_str_t *buffer, const h5tool_format_t *info, + h5tools_context_t *ctx, hid_t space) +{ + HERR_INIT(int, SUCCEED) + hsize_t size[H5TOOLS_DUMP_MAX_RANK]; + hsize_t maxsize[H5TOOLS_DUMP_MAX_RANK]; + int ndims = -1; + H5S_class_t space_type = -1; + int i; + + if((ndims = H5Sget_simple_extent_dims(space, size, maxsize)) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); + + if((space_type = H5Sget_simple_extent_type(space)) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_type failed"); + + switch(space_type) { + case H5S_SCALAR: + /* scalar dataspace */ + h5tools_str_append(buffer, "%s %s", h5tools_dump_header_format->dataspacedescriptionbegin, S_SCALAR); + break; + + case H5S_SIMPLE: + /* simple dataspace */ + h5tools_str_append(buffer, "%s %s { %s " HSIZE_T_FORMAT, + h5tools_dump_header_format->dataspacedescriptionbegin, S_SIMPLE, + h5tools_dump_header_format->dataspacedimbegin, size[0]); + + for(i = 1; i < ndims; i++) + h5tools_str_append(buffer, ", " HSIZE_T_FORMAT, size[i]); + + h5tools_str_append(buffer, " %s / ", h5tools_dump_header_format->dataspacedimend); + + if(maxsize[0] == H5S_UNLIMITED) + h5tools_str_append(buffer, "%s %s", + h5tools_dump_header_format->dataspacedimbegin, "H5S_UNLIMITED"); + else + h5tools_str_append(buffer, "%s " HSIZE_T_FORMAT, + h5tools_dump_header_format->dataspacedimbegin, maxsize[0]); + + for(i = 1; i < ndims; i++) + if(maxsize[i] == H5S_UNLIMITED) + h5tools_str_append(buffer, ", %s", "H5S_UNLIMITED"); + else + h5tools_str_append(buffer, ", " HSIZE_T_FORMAT, maxsize[i]); + + h5tools_str_append(buffer, " %s }", h5tools_dump_header_format->dataspacedimend); + break; + + case H5S_NULL: + /* null dataspace */ + h5tools_str_append(buffer, "%s %s", h5tools_dump_header_format->dataspacedescriptionbegin, S_NULL); + break; + + case H5S_NO_CLASS: + default: + h5tools_str_append(buffer, "%s unknown dataspace %s\n", BEGIN, END); + break; + } /* end switch */ + +CATCH + return ret_value; +} + + +/*------------------------------------------------------------------------- + * Function: print_enum + * + * Purpose: prints the enum data + * + * Return: void + * + * In/Out: h5tools_str_t *buffer + * h5tools_context_t *ctx + * + *-----------------------------------------------------------------------*/ +int +h5tools_print_enum(FILE *stream, h5tools_str_t *buffer, const h5tool_format_t *info, + h5tools_context_t *ctx, hid_t type) +{ + HERR_INIT(int, SUCCEED) + char **name = NULL; /*member names */ + unsigned char *value = NULL; /*value array */ + unsigned char *copy = NULL; /*a pointer to value array */ + unsigned i; + unsigned nmembs = 0; /*number of members */ + int snmembs; + int nchars; /*number of output characters */ + hid_t super = -1; /*enum base integer type */ + hid_t native = -1; /*native integer datatype */ + H5T_sign_t sign_type; /*sign of value type */ + size_t type_size; /*value type size */ + size_t dst_size; /*destination value type size */ + size_t ncols = 80; /*available output width */ + hsize_t curr_pos = 0; /* total data element position */ + + if (info->line_ncols > 0) + ncols = info->line_ncols; + + if((snmembs = H5Tget_nmembers(type)) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed"); + nmembs = (unsigned)snmembs; + HDassert(nmembs > 0); + + if((super = H5Tget_super(type)) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_super failed"); + + if((type_size = H5Tget_size(type)) <= 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size(type) failed"); + + /* + * Determine what datatype to use for the native values. To simplify + * things we entertain three possibilities: + * 1. long long -- the largest native signed integer + * 2. unsigned long long -- the largest native unsigned integer + * 3. raw format + */ + if(type_size <= sizeof(long long)) { + dst_size = sizeof(long long); + + if((sign_type = H5Tget_sign(type))<0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_sign failed"); + if(H5T_SGN_NONE == sign_type) + native = H5T_NATIVE_ULLONG; + else + native = H5T_NATIVE_LLONG; + } /* end if */ + else + dst_size = type_size; + + /* Get the names and raw values of all members */ + if(NULL == (name = (char **)HDcalloc(nmembs, sizeof(char *)))) + H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for member name"); + if(NULL == (value = (unsigned char *)HDcalloc(nmembs, MAX(type_size, dst_size)))) + H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for member value"); + + for (i = 0; i < nmembs; i++) { + name[i] = H5Tget_member_name(type, i); + if(H5Tget_member_value(type, i, value + i * type_size) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_member_value failed"); + } + + /* Convert values to native datatype */ + if (native > 0) + if(H5Tconvert(super, native, nmembs, value, NULL, H5P_DEFAULT) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tconvert failed"); + + /* + * Sort members by increasing value + * ***not implemented yet*** + */ + + /* Print members */ + for (i = 0; i < nmembs; i++) { + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(buffer); + h5tools_str_append(buffer, "\"%s\"", name[i]); + nchars = HDstrlen(name[i]); + h5tools_str_append(buffer, "%*s ", MAX(0, 16 - nchars), ""); + + if (native < 0) { + size_t j; + + h5tools_str_append(buffer, "0x"); + + for (j = 0; j < dst_size; j++) + h5tools_str_append(buffer, "%02x", value[i * dst_size + j]); + } + else if (H5T_SGN_NONE == H5Tget_sign(native)) { + /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size" + *strangely, unless use another pointer "copy".*/ + copy = value + i * dst_size; + h5tools_str_append(buffer, HSIZE_T_FORMAT, *((unsigned long long *) ((void *) copy))); + } + else { + /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size" + *strangely, unless use another pointer "copy".*/ + copy = value + i * dst_size; + h5tools_str_append(buffer, "%" H5_PRINTF_LL_WIDTH "d", *((long long *) ((void *) copy))); + } + + h5tools_str_append(buffer, ";"); + h5tools_render_element(stream, info, ctx, buffer, &curr_pos, ncols, 0, 0); + } + +CATCH + if(name) { + /* Release resources */ + for(i = 0; i < nmembs; i++) + if(name[i]) + HDfree(name[i]); + HDfree(name); + } /* end if */ + + if(value) + HDfree(value); + + if(super >= 0 && H5Tclose(super) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not close datatype's super class"); + + if(0 == nmembs) + h5tools_str_append(buffer, "\n<empty>"); + + return ret_value; +} + +/*------------------------------------------------------------------------- + * Function: dump_datatype + * + * Purpose: Dump the datatype. Datatype can be HDF5 predefined + * atomic datatype or committed/transient datatype. + * + * Return: void + * + * In/Out: h5tools_context_t *ctx + *------------------------------------------------------------------------- + */ +void +h5tools_dump_datatype(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx, hid_t type) +{ + h5tools_str_t buffer; /* string into which to render */ + size_t ncols = 80; /* available output width */ + hsize_t curr_pos = ctx->sm_pos; /* total data element position */ + /* pass to the prefix in h5tools_simple_prefix the total position + * instead of the current stripmine position i; this is necessary + * to print the array indices + */ + + /* setup */ + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + + if (info->line_ncols > 0) + ncols = info->line_ncols; + + ctx->need_prefix = TRUE; + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s %s ", + h5tools_dump_header_format->datatypebegin, + h5tools_dump_header_format->datatypeblockbegin); + h5tools_print_datatype(stream, &buffer, info, ctx, type, TRUE); + if (HDstrlen(h5tools_dump_header_format->datatypeblockend)) { + h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->datatypeblockend); + if (HDstrlen(h5tools_dump_header_format->datatypeend)) + h5tools_str_append(&buffer, " "); + } + if (HDstrlen(h5tools_dump_header_format->datatypeend)) + h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->datatypeend); + + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + h5tools_str_close(&buffer); +} + +/*------------------------------------------------------------------------- + * Function: dump_dataspace + * + * Purpose: Dump the dataspace. + * + * Return: void + * + * In/Out: h5tools_context_t *ctx + *------------------------------------------------------------------------- + */ +void +h5tools_dump_dataspace(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx, hid_t type) +{ + h5tools_str_t buffer; /* string into which to render */ + size_t ncols = 80; /* available output width */ + hsize_t curr_pos = ctx->sm_pos; /* total data element position */ + /* pass to the prefix in h5tools_simple_prefix the total position + * instead of the current stripmine position i; this is necessary + * to print the array indices + */ + + /* setup */ + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + + if (info->line_ncols > 0) + ncols = info->line_ncols; + + ctx->need_prefix = TRUE; + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s ", + h5tools_dump_header_format->dataspacebegin); + + h5tools_print_dataspace(stream, &buffer, info, ctx, type); + + if (HDstrlen(h5tools_dump_header_format->dataspaceblockend)) { + h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->dataspaceblockend); + if (HDstrlen(h5tools_dump_header_format->dataspaceend)) + h5tools_str_append(&buffer, " "); + } + if (HDstrlen(h5tools_dump_header_format->dataspaceend)) + h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->dataspaceend); + + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + h5tools_str_close(&buffer); +} + +/*------------------------------------------------------------------------- + * Function: dump_oid + * + * Purpose: Dump the oid. + * + * Return: void + * + * In/Out: h5tools_context_t *ctx + *------------------------------------------------------------------------- + */ +void +h5tools_dump_oid(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx, hid_t oid) +{ + h5tools_str_t buffer; /* string into which to render */ + size_t ncols = 80; /* available output width */ + hsize_t curr_pos = ctx->sm_pos; /* total data element position */ + /* pass to the prefix in h5tools_simple_prefix the total position + * instead of the current stripmine position i; this is necessary + * to print the array indices + */ + + /* setup */ + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + + if (info->line_ncols > 0) + ncols = info->line_ncols; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s %s %d %s", OBJID, BEGIN, oid, END); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + h5tools_str_close(&buffer); +} + + +/*------------------------------------------------------------------------- + * Function: dump_fill_value + * + * Purpose: prints the fill value + * + * Return: void + * + * Programmer: pvn + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +void +h5tools_print_fill_value(h5tools_str_t *buffer/*in,out*/, const h5tool_format_t *info, h5tools_context_t *ctx/*in,out*/, hid_t dcpl, hid_t type_id, hid_t obj_id) +{ + size_t size; + hid_t n_type; + hsize_t nelmts = 1; + void *buf = NULL; + + n_type = h5tools_get_native_type(type_id); + + size = H5Tget_size(n_type); + buf = HDmalloc(size); + + H5Pget_fill_value(dcpl, n_type, buf); + + h5tools_str_sprint(buffer, info, obj_id, n_type, buf, ctx); + + H5Tclose(n_type); + + if (buf) + HDfree (buf); +} + +/*------------------------------------------------------------------------- + * Function: dump_dcpl + * + * Purpose: prints several dataset create property list properties + * + * Return: void + * + * Modifications: pvn, March 28, 2008 + * Add a COMPRESSION ratio information for cases when filters are present + * + *------------------------------------------------------------------------- + */ +void +h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx, hid_t dcpl_id,hid_t type_id, hid_t obj_id) +{ + int nfilters; /* number of filters */ + int rank; /* rank */ + int i; + unsigned j; + unsigned filt_flags; /* filter flags */ + unsigned cd_values[20]; /* filter client data values */ + unsigned szip_options_mask; + unsigned szip_pixels_per_block; + H5Z_filter_t filtn; /* filter identification number */ + H5D_fill_value_t fvstatus; + H5D_alloc_time_t at; + H5D_fill_time_t ft; + size_t ncols = 80; /* available output width */ + size_t cd_nelmts; /* filter client number of values */ + off_t offset; /* offset of external file */ + char f_name[256]; /* filter name */ + char name[256]; /* external file name */ + hsize_t chsize[64]; /* chunk size in elements */ + hsize_t size; /* size of external file */ + hsize_t storage_size; + hsize_t curr_pos = 0; /* total data element position */ + hsize_t elmt_counter = 0;/* counts the # elements printed.*/ + haddr_t ioffset; + h5tools_str_t buffer; /* string into which to render */ + + /* setup */ + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + if (info->line_ncols > 0) + ncols = info->line_ncols; + + storage_size = H5Dget_storage_size(obj_id); + nfilters = H5Pget_nfilters(dcpl_id); + ioffset = H5Dget_offset(obj_id); + HDstrcpy(f_name,"\0"); + + /*------------------------------------------------------------------------- + * STORAGE_LAYOUT + *------------------------------------------------------------------------- + */ + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s %s", STORAGE_LAYOUT, BEGIN); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + if(H5D_CHUNKED == H5Pget_layout(dcpl_id)) { + ctx->indent_level++; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s ", CHUNKED); + + rank = H5Pget_chunk(dcpl_id,NELMTS(chsize),chsize); + h5tools_str_append(&buffer, "%s " HSIZE_T_FORMAT, h5tools_dump_header_format->dataspacedimbegin, chsize[0]); + for(i = 1; i < rank; i++) + h5tools_str_append(&buffer, ", " HSIZE_T_FORMAT, chsize[i]); + h5tools_str_append(&buffer, " %s", h5tools_dump_header_format->dataspacedimend); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + + /* if there are filters, print a compression ratio */ + if(nfilters) { + hsize_t dims[H5S_MAX_RANK]; + hsize_t nelmts = 1; + double ratio = 0; + int ok = 0; + + hid_t tid = H5Dget_type(obj_id); + hid_t sid = H5Dget_space(obj_id); + size_t datum_size = H5Tget_size(tid); + int ndims = H5Sget_simple_extent_dims(sid, dims, NULL); + + /* only print the compression ratio for these filters */ + for(i = 0; i < nfilters; i++) { + cd_nelmts = NELMTS(cd_values); + filtn = H5Pget_filter2(dcpl_id, (unsigned)i, &filt_flags, &cd_nelmts, + cd_values, sizeof(f_name), f_name, NULL); + + switch(filtn) { + case H5Z_FILTER_DEFLATE: + case H5Z_FILTER_SZIP: + case H5Z_FILTER_NBIT: + case H5Z_FILTER_SCALEOFFSET: + ok = 1; + break; + } + } + + if(ndims && ok) { + hsize_t uncomp_size; + + for(i = 0; i < ndims; i++) { + nelmts *= dims[i]; + } + uncomp_size = nelmts * datum_size; + + /* compression ratio = uncompressed size / compressed size */ + + if(storage_size != 0) + ratio = (double) uncomp_size / (double) storage_size; + + h5tools_str_append(&buffer, "SIZE " HSIZE_T_FORMAT" (%.3f:1 COMPRESSION)", storage_size, ratio); + + } + else + h5tools_str_append(&buffer, "SIZE " HSIZE_T_FORMAT, storage_size); + + H5Sclose(sid); + H5Tclose(tid); + + } + else { + h5tools_str_append(&buffer, "SIZE " HSIZE_T_FORMAT, storage_size); + } + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s",END); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + } + else if(H5D_COMPACT == H5Pget_layout(dcpl_id)) { + ctx->indent_level++; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s", COMPACT); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "SIZE " HSIZE_T_FORMAT, storage_size); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s",END); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + } + else if(H5D_CONTIGUOUS == H5Pget_layout(dcpl_id)) { + int next; + + next = H5Pget_external_count(dcpl_id); + + /*------------------------------------------------------------------------- + * EXTERNAL_FILE + *------------------------------------------------------------------------- + */ + if(next) { + ctx->indent_level++; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s", CONTIGUOUS); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s %s", EXTERNAL, BEGIN); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level++; + for(j = 0; j < (unsigned)next; j++) { + H5Pget_external(dcpl_id, j, sizeof(name), name, &offset, &size); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "FILENAME %s SIZE " HSIZE_T_FORMAT, name, size); + h5tools_str_append(&buffer, " OFFSET %ld", offset); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + } + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s",END); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s",END); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + } + else { + ctx->indent_level++; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s", CONTIGUOUS); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer,"SIZE " HSIZE_T_FORMAT, storage_size); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer,"OFFSET "H5_PRINTF_HADDR_FMT, ioffset); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s",END); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + } + } + /*------------------------------------------------------------------------- + * FILTERS + *------------------------------------------------------------------------- + */ + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s %s", FILTERS, BEGIN); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level++; + + if(nfilters) { + for(i = 0; i < nfilters; i++) { + cd_nelmts = NELMTS(cd_values); + filtn = H5Pget_filter2(dcpl_id, (unsigned)i, &filt_flags, &cd_nelmts, + cd_values, sizeof(f_name), f_name, NULL); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + switch(filtn) { + case H5Z_FILTER_DEFLATE: + h5tools_str_append(&buffer, "%s %s %s %d %s", DEFLATE, BEGIN, DEFLATE_LEVEL, cd_values[0], END); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + break; + case H5Z_FILTER_SHUFFLE: + h5tools_str_append(&buffer, "%s", SHUFFLE); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + break; + case H5Z_FILTER_FLETCHER32: + h5tools_str_append(&buffer, "%s", FLETCHER32); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + break; + case H5Z_FILTER_SZIP: + { + szip_options_mask = cd_values[0];; + szip_pixels_per_block = cd_values[1]; + + h5tools_str_append(&buffer, "%s %s",SZIP, BEGIN); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level++; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "PIXELS_PER_BLOCK %d", szip_pixels_per_block); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + if(szip_options_mask & H5_SZIP_CHIP_OPTION_MASK) + h5tools_str_append(&buffer, "MODE %s", "HARDWARE"); + else if(szip_options_mask & H5_SZIP_ALLOW_K13_OPTION_MASK) + h5tools_str_append(&buffer, "MODE %s", "K13"); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + if(szip_options_mask & H5_SZIP_EC_OPTION_MASK) + h5tools_str_append(&buffer, "CODING %s", "ENTROPY"); + else if(szip_options_mask & H5_SZIP_NN_OPTION_MASK) + h5tools_str_append(&buffer, "CODING %s", "NEAREST NEIGHBOUR"); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + if(szip_options_mask & H5_SZIP_LSB_OPTION_MASK) + h5tools_str_append(&buffer, "BYTE_ORDER %s", "LSB"); + else if(szip_options_mask & H5_SZIP_MSB_OPTION_MASK) + h5tools_str_append(&buffer, "BYTE_ORDER %s", "MSB"); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + if(szip_options_mask & H5_SZIP_RAW_OPTION_MASK) { + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "HEADER %s", "RAW"); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + } + + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s",END); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + } + break; + case H5Z_FILTER_NBIT: + h5tools_str_append(&buffer, "%s", NBIT); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + break; + case H5Z_FILTER_SCALEOFFSET: + h5tools_str_append(&buffer, "%s %s %s %d %s", SCALEOFFSET, BEGIN, SCALEOFFSET_MINBIT, cd_values[0], END); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + break; + default: + if(H5Zfilter_avail(filtn)) + h5tools_str_append(&buffer, "%s %s", "USER_REGISTERED_FILTER", BEGIN); + else + h5tools_str_append(&buffer, "%s %s", "UNKNOWN_FILTER", BEGIN); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level++; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "FILTER_ID %d", filtn); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + if(f_name[0] != '\0') { + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "COMMENT %s", f_name); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + } + if (cd_nelmts) { + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s %s ","PARAMS", BEGIN); + for (j=0; j<cd_nelmts; j++) + h5tools_str_append(&buffer, "%d ", cd_values[j]); + h5tools_str_append(&buffer, "%s", END); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + } + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s",END); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + break; + }/*switch*/ + } /*i*/ + }/*nfilters*/ + else { + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "NONE"); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + } + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s",END); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + /*------------------------------------------------------------------------- + * FILLVALUE + *------------------------------------------------------------------------- + */ + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s %s", FILLVALUE, BEGIN); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level++; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "FILL_TIME "); + + H5Pget_fill_time(dcpl_id, &ft); + switch(ft) { + case H5D_FILL_TIME_ALLOC: + h5tools_str_append(&buffer, "%s", "H5D_FILL_TIME_ALLOC"); + break; + case H5D_FILL_TIME_NEVER: + h5tools_str_append(&buffer, "%s", "H5D_FILL_TIME_NEVER"); + break; + case H5D_FILL_TIME_IFSET: + h5tools_str_append(&buffer, "%s", "H5D_FILL_TIME_IFSET"); + break; + default: + HDassert(0); + break; + } + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s ", "VALUE "); + H5Pfill_value_defined(dcpl_id, &fvstatus); + if(fvstatus == H5D_FILL_VALUE_UNDEFINED) + h5tools_str_append(&buffer, "%s", "H5D_FILL_VALUE_UNDEFINED"); + else { + ctx->indent_level--; + h5tools_print_fill_value(&buffer, info, ctx, dcpl_id, type_id, obj_id); + ctx->indent_level++; + } + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s", END); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + /*------------------------------------------------------------------------- + * ALLOCATION_TIME + *------------------------------------------------------------------------- + */ + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "ALLOCATION_TIME %s", BEGIN); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level++; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + H5Pget_alloc_time(dcpl_id, &at); + switch(at) { + case H5D_ALLOC_TIME_EARLY: + h5tools_str_append(&buffer, "%s", "H5D_ALLOC_TIME_EARLY"); + break; + case H5D_ALLOC_TIME_INCR: + h5tools_str_append(&buffer, "%s", "H5D_ALLOC_TIME_INCR"); + break; + case H5D_ALLOC_TIME_LATE: + h5tools_str_append(&buffer, "%s", "H5D_ALLOC_TIME_LATE"); + break; + default: + HDassert(0); + break; + } + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s", END); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + h5tools_str_close(&buffer); +} + +/*------------------------------------------------------------------------- + * Function: dump_comment + * + * Purpose: prints the comment for the the object name + * + * Return: void + * + *------------------------------------------------------------------------- + */ +void +h5tools_dump_comment(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx, hid_t obj_id) +{ + char *comment = NULL; + ssize_t cmt_bufsize = -1; + size_t buf_size = 0; + size_t ncols = 80; /* available output width */ + h5tools_str_t buffer; /* string into which to render */ + hsize_t elmt_counter = 0;/* counts the # elements printed.*/ + hsize_t curr_pos = ctx->sm_pos; /* total data element position */ + /* pass to the prefix in h5tools_simple_prefix the total position + * instead of the current stripmine position i; this is necessary + * to print the array indices + */ + + /* setup */ + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + + if (info->line_ncols > 0) + ncols = info->line_ncols; + + cmt_bufsize = H5Oget_comment(obj_id, comment, buf_size); + + /* call H5Oget_comment again with the correct value. + * If the call to H5Oget_comment returned an error, skip this block */ + if (cmt_bufsize > 0) { + comment = (char *)HDmalloc((size_t)(cmt_bufsize+1)); /* new_size including null terminator */ + if(comment) { + cmt_bufsize = H5Oget_comment(obj_id, comment, cmt_bufsize); + if(cmt_bufsize > 0) { + comment[cmt_bufsize] = '\0'; /* necessary because null char is not returned */ + + ctx->need_prefix = TRUE; + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "COMMENT \"%s\"", comment); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + h5tools_str_close(&buffer); + } /* end if */ + HDfree(comment); + } + } +} /* end dump_comment() */ + +/*------------------------------------------------------------------------- + * Function: dump_attribute + * + * Purpose: Dump the attribute. + * + * Return: void + * + * In/Out: h5tools_context_t *ctx + *------------------------------------------------------------------------- + */ +void +h5tools_dump_attribute(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx, hid_t oid, const char *attr_name, hid_t attr_id, + int display_index, int display_char) +{ + h5tools_str_t buffer; /* string into which to render */ + size_t ncols = 80; /* available output width */ + hsize_t elmt_counter = 0;/* counts the # elements printed.*/ + hsize_t curr_pos = ctx->sm_pos; /* total data element position */ + /* pass to the prefix in h5tools_simple_prefix the total position + * instead of the current stripmine position i; this is necessary + * to print the array indices + */ + + /* setup */ + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + + if (info->line_ncols > 0) + ncols = info->line_ncols; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s \"%s\" %s", + h5tools_dump_header_format->attributebegin, attr_name, + h5tools_dump_header_format->attributeblockbegin); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + if(attr_id < 0) { + error_msg("unable to open attribute \"%s\"\n", attr_name); + } + else { + hid_t type, space; + + ctx->indent_level++; + + type = H5Aget_type(attr_id); + h5tools_dump_datatype(stream, info, ctx, type); + + space = H5Aget_space(attr_id); + h5tools_dump_dataspace(stream, info, ctx, space); + + if(oid_output) + h5tools_dump_oid(stream, info, ctx, attr_id); + + if(data_output || attr_data_output) + h5tools_dump_data(stream, info, ctx, attr_id, FALSE, NULL, display_index, display_char); + + ctx->indent_level--; + + H5Tclose(type); + H5Sclose(space); + H5Aclose(attr_id); + } + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(&buffer); + + if (HDstrlen(h5tools_dump_header_format->attributeblockend)) { + h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->attributeblockend); + if (HDstrlen(h5tools_dump_header_format->attributeend)) + h5tools_str_append(&buffer, " "); + } + if (HDstrlen(h5tools_dump_header_format->attributeend)) + h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->attributeend); + + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + h5tools_str_close(&buffer); +} + +/*------------------------------------------------------------------------- + * Function: dump_dims + * + * Purpose: Dump the dimensions handed to it in a comma separated list + * + * Return: void + * + * Programmer: Bill Wendling + * Tuesday, 27. February 2001 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +void +h5tools_print_dims(h5tools_str_t *buffer, hsize_t *s, int dims) +{ + int i; + + for (i = 0; i < dims; i++) { + h5tools_str_append(buffer, HSIZE_T_FORMAT, s[i]); + + if (i + 1 != dims) h5tools_str_append(buffer, ", "); + } +} + +/*------------------------------------------------------------------------- + * Function: print_packed_bits + * + * Purpose: Prints the packed bits offset and length + * + * Return: void + * + *------------------------------------------------------------------------- + */ +void +h5tools_print_packed_bits(h5tools_str_t *buffer, 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"); + } + + if ((packed_bits_size>0) && (packed_data_offset + packed_data_length) > packed_bits_size) { + error_msg("Packed Bit offset+length value(%d) too large. Max is %d\n", packed_data_offset+packed_data_length, packed_bits_size); + packed_data_mask = 0; + }; + h5tools_str_append(buffer, "%s %s=%d %s=%d", PACKED_BITS, PACKED_OFFSET, packed_data_offset, PACKED_LENGTH, packed_data_length); +} + +/*------------------------------------------------------------------------- + * Function: dump_subsetting_header + * + * Purpose: Dump the subsetting header like specified in the DDL. + * + * Return: void + * + * Programmer: Bill Wendling + * Tuesday, 27. February 2001 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +void +h5tools_dump_subsetting_header(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx, struct subset_t *sset, int dims) +{ + h5tools_str_t buffer; /* string into which to render */ + hsize_t curr_pos = 0; /* total data element position */ + size_t ncols = 80; /* available output width */ + + /* setup */ + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + if (info->line_ncols > 0) + ncols = info->line_ncols; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s %s", h5tools_dump_header_format->subsettingbegin, h5tools_dump_header_format->subsettingblockbegin); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level++; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s %s ", h5tools_dump_header_format->startbegin, h5tools_dump_header_format->startblockbegin); + h5tools_print_dims(&buffer, sset->start.data, dims); + h5tools_str_append(&buffer, "%s %s", h5tools_dump_header_format->startend, h5tools_dump_header_format->startblockend); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s %s ", h5tools_dump_header_format->stridebegin, h5tools_dump_header_format->strideblockbegin); + h5tools_print_dims(&buffer, sset->stride.data, dims); + h5tools_str_append(&buffer, "%s %s", h5tools_dump_header_format->strideend, h5tools_dump_header_format->strideblockend); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s %s ", h5tools_dump_header_format->countbegin, h5tools_dump_header_format->countblockbegin); + + if(sset->count.data) + h5tools_print_dims(&buffer, sset->count.data, dims); + else + h5tools_str_append(&buffer, "DEFAULT"); + + h5tools_str_append(&buffer, "%s %s", h5tools_dump_header_format->countend, h5tools_dump_header_format->countblockend); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, info, ctx, 0, 0); + + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s %s ", h5tools_dump_header_format->blockbegin, h5tools_dump_header_format->blockblockbegin); + + if(sset->block.data) + h5tools_print_dims(&buffer, sset->block.data, dims); + else + h5tools_str_append(&buffer, "DEFAULT"); + + h5tools_str_append(&buffer, "%s %s", h5tools_dump_header_format->blockend, h5tools_dump_header_format->blockblockend); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, 0, 0); + + ctx->indent_level--; + + h5tools_str_close(&buffer); +} + +/*------------------------------------------------------------------------- + * Function: dump_data + * + * Purpose: Dump attribute or dataset data + * + * Return: void + * + *------------------------------------------------------------------------- + */ +void +h5tools_dump_data(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx, hid_t obj_id, int obj_data, struct subset_t *sset, + int display_index, int display_char) +{ + H5S_class_t space_type; + int ndims; + int i; + hid_t space; + hid_t type; + hid_t p_type; + hsize_t size[64]; + hsize_t alloc_size; + hsize_t nelmts = 1; + int status = -1; + void *buf = NULL; + h5tools_str_t buffer; /* string into which to render */ + hsize_t curr_pos = 0; /* total data element position */ + size_t ncols = 80; /* available output width */ + h5tool_format_t string_dataformat; + h5tool_format_t outputformat; + + /* setup */ + HDmemset(&buffer, 0, sizeof(h5tools_str_t)); + if (info->line_ncols > 0) + ncols = info->line_ncols; + + outputformat = *info; + string_dataformat = *info; + /* print the matrix indices */ + string_dataformat.pindex = display_index; + + /* do not print indices for regions */ + if(obj_data) { + hid_t f_type = H5Dget_type(obj_id); + + if (H5Tequal(f_type, H5T_STD_REF_DSETREG)) { + /* For the region option, correct the display of indices */ + if (region_output) { + if (!string_dataformat.pindex) { + string_dataformat.idx_fmt = ""; + string_dataformat.idx_n_fmt = ""; + string_dataformat.idx_sep = ""; + string_dataformat.line_pre = ""; + } + } + else + string_dataformat.pindex = 0; + } + H5Tclose(f_type); + } + + if (string_dataformat.pindex) { + string_dataformat.idx_fmt = "(%s): "; + string_dataformat.idx_n_fmt = HSIZE_T_FORMAT; + string_dataformat.idx_sep = ","; + string_dataformat.line_pre = "%s"; + } + info = &string_dataformat; + + if (sset && obj_data) { + hid_t f_space = H5Dget_space(obj_id); + + h5tools_dump_subsetting_header(stream, &outputformat, ctx, sset, H5Sget_simple_extent_ndims(f_space)); + H5Sclose(f_space); + + ctx->indent_level++; + } + + ctx->need_prefix = TRUE; + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "%s %s", h5tools_dump_header_format->databegin, h5tools_dump_header_format->datablockbegin); + h5tools_render_element(stream, &outputformat, ctx, &buffer, &curr_pos, ncols, 0, 0); + + /* Print all the values. */ + if(obj_data) { + h5tools_context_t datactx = *ctx; /* print context */ + hid_t f_type = H5Dget_type(obj_id); + + if((display_char && H5Tget_size(f_type) == 1) && (H5Tget_class(f_type) == H5T_INTEGER)) { + /* + * Print 1-byte integer data as an ASCII character string + * instead of integers if the `-r' or `--string' command-line + * option was given. + * + * We don't want to modify the global dataformat, so make a + * copy of it instead. + */ + string_dataformat = *info; + string_dataformat.idx_fmt = "\""; + info = &string_dataformat; + datactx.indent_level++; + datactx.need_prefix = TRUE; + h5tools_simple_prefix(stream, info, &datactx, 0, 0); + + string_dataformat = *info; + string_dataformat.idx_fmt = "\""; + string_dataformat.line_multi_new = 1; + string_dataformat.str_repeat = 8; + string_dataformat.ascii = TRUE; + string_dataformat.elmt_suf1 = ""; + string_dataformat.elmt_suf2 = ""; + string_dataformat.line_suf = "\""; + info = &string_dataformat; + } + else + datactx.need_prefix = TRUE; + status = h5tools_dump_dset(stream, info, &datactx, obj_id, -1, sset); + if((display_char && H5Tget_size(f_type) == 1) && (H5Tget_class(f_type) == H5T_INTEGER)) { + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "\""); + h5tools_render_element(stream, &outputformat, ctx, &buffer, &curr_pos, ncols, 0, 0); + } + H5Tclose(f_type); + } + else { + h5tools_context_t datactx = *ctx; /* print context */ + /* need to call h5tools_dump_mem for the attribute data */ + space = H5Aget_space(obj_id); + space_type = H5Sget_simple_extent_type(space); + if(space_type == H5S_NULL || space_type == H5S_NO_CLASS) { + status = SUCCEED; + } + else { + /* VL data special information */ + unsigned int vl_data = 0; /* contains VL datatypes */ + + type = H5Aget_type(obj_id); + p_type = h5tools_get_native_type(type); + + ndims = H5Sget_simple_extent_dims(space, size, NULL); + + /* Check if we have VL data in the dataset's datatype */ + if (h5tools_detect_vlen_str(p_type) == TRUE) + vl_data = TRUE; + if (H5Tdetect_class(p_type, H5T_VLEN) == TRUE) + vl_data = TRUE; + + for (i = 0; i < ndims; i++) + nelmts *= size[i]; + + alloc_size = nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type)); + HDassert(alloc_size == (hsize_t)((size_t)alloc_size)); /*check for overflow*/ + + if(alloc_size) { + buf = HDmalloc((size_t)alloc_size); + HDassert(buf); + + if (H5Aread(obj_id, p_type, buf) >= 0) + if (display_char && H5Tget_size(type) == 1 && H5Tget_class(type) == H5T_INTEGER) { + /* + * Print 1-byte integer data as an ASCII character string + * instead of integers if the `-r' or `--string' command-line + * option was given. + * + * We don't want to modify the global dataformat, so make a + * copy of it instead. + */ + string_dataformat = *info; + string_dataformat.idx_fmt = "\""; + info = &string_dataformat; + datactx.indent_level++; + datactx.need_prefix = TRUE; + h5tools_simple_prefix(stream, info, &datactx, 0, 0); + + string_dataformat = *info; + string_dataformat.idx_fmt = "\""; + string_dataformat.line_multi_new = 1; + string_dataformat.str_repeat = 8; + string_dataformat.ascii = TRUE; + string_dataformat.elmt_suf1 = ""; + string_dataformat.elmt_suf2 = ""; + string_dataformat.line_suf = "\""; + info = &string_dataformat; + } + else + datactx.need_prefix = TRUE; + + status = h5tools_dump_mem(stream, info, &datactx, obj_id, p_type, space, buf); + if (display_char && H5Tget_size(type) == 1 && H5Tget_class(type) == H5T_INTEGER) { + h5tools_str_reset(&buffer); + h5tools_str_append(&buffer, "\""); + h5tools_render_element(stream, &outputformat, ctx, &buffer, &curr_pos, ncols, 0, 0); + } + + /* Reclaim any VL memory, if necessary */ + if (vl_data) + H5Dvlen_reclaim(p_type, space, H5P_DEFAULT, buf); + + HDfree(buf); + } + else + status = SUCCEED; + + H5Tclose(p_type); + H5Tclose(type); + } + H5Sclose(space); + } + + if (status == FAIL) { + error_msg("unable to print data\n"); + h5tools_setstatus(EXIT_FAILURE); + } + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, &outputformat, ctx, 0, 0); + + h5tools_str_reset(&buffer); + if(HDstrlen(h5tools_dump_header_format->datablockend)) { + h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->datablockend); + if(HDstrlen(h5tools_dump_header_format->dataend)) + h5tools_str_append(&buffer, " "); + } + if(HDstrlen(h5tools_dump_header_format->dataend)) + h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->dataend); + h5tools_render_element(stream, &outputformat, ctx, &buffer, &curr_pos, ncols, 0, 0); + + if (sset && obj_data) { + ctx->indent_level--; + + ctx->need_prefix = TRUE; + h5tools_simple_prefix(stream, &outputformat, ctx, 0, 0); + + h5tools_str_reset(&buffer); + if(HDstrlen(h5tools_dump_header_format->subsettingblockend)) { + h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->subsettingblockend); + if(HDstrlen(h5tools_dump_header_format->subsettingend)) + h5tools_str_append(&buffer, " "); + } + if(HDstrlen(h5tools_dump_header_format->subsettingend)) + h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->subsettingend); + h5tools_render_element(stream, &outputformat, ctx, &buffer, &curr_pos, ncols, 0, 0); + } + + h5tools_str_close(&buffer); +} + diff --git a/tools/lib/h5tools_dump.h b/tools/lib/h5tools_dump.h new file mode 100644 index 0000000..c94d0e1 --- /dev/null +++ b/tools/lib/h5tools_dump.h @@ -0,0 +1,85 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +/* + * Purpose: Support h5dump functions for the various tools. + */ +#ifndef H5TOOLS_DUMP_H__ +#define H5TOOLS_DUMP_H__ + +#include "h5tools_utils.h" + +/* 3 private values: can't be set, but can be read. + Note: these are defined in H5Zprivate, they are + duplicated here. + */ +#define H5_SZIP_LSB_OPTION_MASK 8 +#define H5_SZIP_MSB_OPTION_MASK 16 +#define H5_SZIP_RAW_OPTION_MASK 128 + +#ifdef __cplusplus +extern "C" { +#endif + +H5TOOLS_DLLVAR table_t *h5dump_type_table; /*type table reference for datatype dump */ + +/* Definitions of useful routines */ +H5TOOLS_DLL void h5tools_dump_init(void); + +H5TOOLS_DLL int h5tools_dump_dset(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx/*in,out*/, hid_t dset, + hid_t p_typ, struct subset_t *sset); +H5TOOLS_DLL int h5tools_dump_mem(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx/*in,out*/, hid_t obj_id, + hid_t type, hid_t space, void *mem); +H5TOOLS_DLL void h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t container, + h5tools_context_t *ctx/*in,out*/, unsigned flags, + hsize_t nelmts, hid_t type, void *_mem); +H5TOOLS_DLL void h5tools_dump_datatype(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx/*in,out*/, hid_t type); +H5TOOLS_DLL void h5tools_dump_dataspace(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx/*in,out*/, hid_t space); +H5TOOLS_DLL void h5tools_dump_attribute(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx/*in,out*/, hid_t oid, const char *attr_name, + hid_t attr_id, int display_index, int display_char); +H5TOOLS_DLL void h5tools_dump_oid(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx/*in,out*/, hid_t oid); +H5TOOLS_DLL void h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx/*in,out*/, hid_t dcpl, hid_t type_id, hid_t obj_id); +H5TOOLS_DLL void h5tools_dump_comment(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx/*in,out*/, hid_t obj_id); +H5TOOLS_DLL void h5tools_dump_data(FILE *stream, const h5tool_format_t *info, + h5tools_context_t *ctx, hid_t obj_id, + int obj_data, struct subset_t *sset, int display_index, int display_char); + +H5TOOLS_DLL int h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer/*in,out*/, + const h5tool_format_t *info, h5tools_context_t *ctx/*in,out*/, + hid_t type, int object_search); +H5TOOLS_DLL int h5tools_print_dataspace(FILE *stream, h5tools_str_t *buffer/*in,out*/, + const h5tool_format_t *info, h5tools_context_t *ctx/*in,out*/, + hid_t space); +H5TOOLS_DLL int h5tools_print_enum(FILE *stream, h5tools_str_t *buffer/*in,out*/, + const h5tool_format_t *info, h5tools_context_t *ctx/*in,out*/, + hid_t type); +H5TOOLS_DLL void h5tools_print_fill_value(h5tools_str_t *buffer/*in,out*/, + const h5tool_format_t *info, h5tools_context_t *ctx/*in,out*/, + hid_t dcpl, hid_t type_id, hid_t obj_id); +H5TOOLS_DLL void h5tools_print_packed_bits(h5tools_str_t *buffer/*in,out*/, hid_t type); +#ifdef __cplusplus +} +#endif + +#endif /* H5TOOLS_DUMP_H__ */ + diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index e7d920c..1d99490 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -68,8 +68,8 @@ void h5tools_str_close(h5tools_str_t *str) { if (str && str->nalloc) { - free(str->s); - memset(str, 0, sizeof(h5tools_str_t)); + HDfree(str->s); + HDmemset(str, 0, sizeof(h5tools_str_t)); } } @@ -123,18 +123,13 @@ char * h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) { va_list ap; - hbool_t isReallocated = FALSE; /* Make sure we have some memory into which to print */ if (!str->s || str->nalloc <= 0) { - str->nalloc = STR_INIT_LEN; - str->s = malloc(str->nalloc); - assert(str->s); - str->s[0] = '\0'; - str->len = 0; + h5tools_str_reset(str); } - if (strlen(fmt) == 0) { + if (HDstrlen(fmt) == 0) { /* nothing to print */ return str->s; } @@ -145,9 +140,9 @@ h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) size_t avail = str->nalloc - str->len; int nchars = -1; - va_start(ap, fmt); + HDva_start(ap, fmt); nchars = HDvsnprintf(str->s + str->len, avail, fmt, ap); - va_end(ap); + HDva_end(ap); /* Note: HDvsnprintf() behaves differently on Windows as Unix, when * buffer is smaller than source string. On Unix, this function @@ -155,17 +150,21 @@ h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) * buffer size with NULL at the end of the buffer. However on * Windows with the same condition, this function returns -1 and * doesn't add NULL at the end of the buffer. - * Because of this different return results, isReallocated variable + * Because of this different return results, the strlen of the new string * is used to handle when HDvsnprintf() returns -1 on Windows due * to lack of buffer size, so try one more time after realloc more * buffer size before return NULL. */ - if (nchars < 0 && isReallocated == TRUE) { + if (nchars < 0 +#ifndef H5_VSNPRINTF_WORKS + && (HDstrlen(str->s) < str->nalloc) +#endif + ) { /* failure, such as bad format */ return NULL; } - if (nchars < 0 || (size_t) nchars >= avail || (0 == nchars && (strcmp(fmt, "%s")))) { + if (nchars < 0 || (size_t) nchars >= avail || (0 == nchars && (HDstrcmp(fmt, "%s")))) { /* Truncation return value as documented by C99, or zero return value with either of the * following conditions, each of which indicates that the proper C99 return value probably * should have been positive when the format string is @@ -173,11 +172,10 @@ h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) * Alocate at least twice as much space and try again. */ size_t newsize = MAX(str->len + nchars + 1, 2 * str->nalloc); - assert(newsize > str->nalloc); /*overflow*/ - str->s = realloc(str->s, newsize); - assert(str->s); + HDassert(newsize > str->nalloc); /*overflow*/ + str->s = HDrealloc(str->s, newsize); + HDassert(str->s); str->nalloc = newsize; - isReallocated = TRUE; } else { /* Success */ @@ -211,8 +209,8 @@ h5tools_str_reset(h5tools_str_t *str/*in,out*/) { if (!str->s || str->nalloc <= 0) { str->nalloc = STR_INIT_LEN; - str->s = malloc(str->nalloc); - assert(str->s); + str->s = HDmalloc(str->nalloc); + HDassert(str->s); } str->s[0] = '\0'; @@ -273,19 +271,19 @@ h5tools_str_fmt(h5tools_str_t *str/*in,out*/, size_t start, const char *fmt) char _temp[1024], *temp = _temp; /* If the format string is simply "%s" then don't bother doing anything */ - if (!strcmp(fmt, "%s")) + if (!HDstrcmp(fmt, "%s")) return str->s; /* * Save the input value if there is a `%' anywhere in FMT. Otherwise * don't bother because we don't need a temporary copy. */ - if (strchr(fmt, '%')) { + if (HDstrchr(fmt, '%')) { size_t n = sizeof(_temp); if (str->len - start + 1 > n) { n = str->len - start + 1; - temp = malloc(n); - assert(temp); + temp = HDmalloc(n); + HDassert(temp); } HDstrncpy(temp, str->s + start, n); @@ -297,7 +295,7 @@ h5tools_str_fmt(h5tools_str_t *str/*in,out*/, size_t start, const char *fmt) /* Free the temp buffer if we allocated one */ if (temp != _temp) - free(temp); + HDfree(temp); return str->s; } @@ -336,7 +334,7 @@ h5tools_str_prefix(h5tools_str_t *str/*in,out*/, const h5tool_format_t *info, ctx->pos[i] = curr_pos / ctx->acc[i]; curr_pos -= ctx->acc[i] * ctx->pos[i]; } - assert(curr_pos == 0); + HDassert(curr_pos == 0); /* Print the index values */ for (i = 0; i < (size_t) ndims; i++) { @@ -451,8 +449,8 @@ h5tools_str_dump_region_blocks(h5tools_str_t *str, hid_t region, int i; alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]); - assert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ - ptdata = (hsize_t *)malloc((size_t) alloc_size); + HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ + ptdata = (hsize_t *)HDmalloc((size_t) alloc_size); H5_CHECK_OVERFLOW(nblocks, hssize_t, hsize_t); H5Sget_select_hyper_blocklist(region, (hsize_t)0, (hsize_t)nblocks, ptdata); @@ -464,17 +462,17 @@ h5tools_str_dump_region_blocks(h5tools_str_t *str, hid_t region, /* Start coordinates and opposite corner */ for (j = 0; j < ndims; j++) - h5tools_str_append(str, "%s%lu", j ? "," : "(", - (unsigned long) ptdata[i * 2 * ndims + j]); + h5tools_str_append(str, "%s" HSIZE_T_FORMAT, j ? "," : "(", + ptdata[i * 2 * ndims + j]); for (j = 0; j < ndims; j++) - h5tools_str_append(str, "%s%lu", j ? "," : ")-(", - (unsigned long) ptdata[i * 2 * ndims + j + ndims]); + h5tools_str_append(str, "%s" HSIZE_T_FORMAT, j ? "," : ")-(", + ptdata[i * 2 * ndims + j + ndims]); h5tools_str_append(str, ")"); } - free(ptdata); + HDfree(ptdata); } /* end if (nblocks > 0) */ } @@ -512,8 +510,8 @@ h5tools_str_dump_region_points(h5tools_str_t *str, hid_t region, int i; alloc_size = npoints * ndims * sizeof(ptdata[0]); - assert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ - ptdata = (hsize_t *)malloc((size_t) alloc_size); + HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ + ptdata = (hsize_t *)HDmalloc((size_t) alloc_size); H5_CHECK_OVERFLOW(npoints, hssize_t, hsize_t); H5Sget_select_elem_pointlist(region, (hsize_t)0, (hsize_t)npoints, ptdata); @@ -524,13 +522,13 @@ h5tools_str_dump_region_points(h5tools_str_t *str, hid_t region, (unsigned long)i); for (j = 0; j < ndims; j++) - h5tools_str_append(str, "%s%lu", j ? "," : "(", - (unsigned long) (ptdata[i * ndims + j])); + h5tools_str_append(str, "%s" HSIZE_T_FORMAT, j ? "," : "(", + (ptdata[i * ndims + j])); h5tools_str_append(str, ")"); } - free(ptdata); + HDfree(ptdata); } /* end if (npoints > 0) */ } @@ -610,6 +608,32 @@ h5tools_print_char(h5tools_str_t *str, const h5tool_format_t *info, char ch) } } } +void +h5tools_str_indent(h5tools_str_t *str, const h5tool_format_t *info, + h5tools_context_t *ctx) +{ + int i, indentlevel = 0; + + /* Write new prefix */ + if (ctx->indent_level >= 0) { + indentlevel = ctx->indent_level; + } + else { + /* + * This is because sometimes we don't print out all the header + * info for the data (like the tattr-2.ddl example). If that happens + * the ctx->indent_level is negative so we need to skip the above and + * just print out the default indent levels. + */ + indentlevel = ctx->default_indent_level; + } + + for (i = 0; i < indentlevel; i++) { + h5tools_str_append(str, "%s", OPT(info->line_indent, "")); + } + +// ctx->need_prefix = 0; +} /*------------------------------------------------------------------------- * Function: h5tools_str_sprint @@ -650,7 +674,7 @@ h5tools_print_char(h5tools_str_t *str, const h5tool_format_t *info, char ch) * * Raymond Lu, 2011-09-01 * CLANG compiler complained about the line (about 800): - * tempint = (tempint >> packed_data_offset) & packed_data_mask; + * tempint = (tempint >> packed_data_offset) & packed_data_mask; * The right shift may cause undefined behavior if PACKED_DATA_OFFSET is * 32-bit or more. For every kind of native integers, I changed the code * to make it zero if PACKED_DATA_OFFSET is greater than or equal to the @@ -840,7 +864,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai h5tools_str_append(str, OPT(info->fmt_schar, "%hd"), tempchar); #else h5tools_str_append(str, OPT(info->fmt_schar, "%hhd"), tempchar); -#endif +#endif } else if (H5Tequal(type, H5T_NATIVE_UCHAR)) { unsigned char tempuchar; @@ -919,29 +943,29 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai } else if (H5Tequal(type, H5T_NATIVE_HSSIZE)) { if (sizeof(hssize_t) == sizeof(int)) { - memcpy(&tempint, vp, sizeof(int)); + HDmemcpy(&tempint, vp, sizeof(int)); h5tools_str_append(str, OPT(info->fmt_int, "%d"), tempint); } else if (sizeof(hssize_t) == sizeof(long)) { - memcpy(&templong, vp, sizeof(long)); + HDmemcpy(&templong, vp, sizeof(long)); h5tools_str_append(str, OPT(info->fmt_long, "%ld"), templong); } else { - memcpy(&templlong, vp, sizeof(long long)); + HDmemcpy(&templlong, vp, sizeof(long long)); h5tools_str_append(str, OPT(info->fmt_llong, fmt_llong), templlong); } } else if (H5Tequal(type, H5T_NATIVE_HSIZE)) { if (sizeof(hsize_t) == sizeof(int)) { - memcpy(&tempuint, vp, sizeof(unsigned int)); + HDmemcpy(&tempuint, vp, sizeof(unsigned int)); h5tools_str_append(str, OPT(info->fmt_uint, "%u"), tempuint); } else if (sizeof(hsize_t) == sizeof(long)) { - memcpy(&tempulong, vp, sizeof(long)); + HDmemcpy(&tempulong, vp, sizeof(long)); h5tools_str_append(str, OPT(info->fmt_ulong, "%lu"), tempulong); } else { - memcpy(&tempullong, vp, sizeof(unsigned long long)); + HDmemcpy(&tempullong, vp, sizeof(unsigned long long)); h5tools_str_append(str, OPT(info->fmt_ullong, fmt_ullong), tempullong); } } @@ -951,59 +975,39 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai nmembs = H5Tget_nmembers(type); h5tools_str_append(str, "%s", OPT(info->cmpd_pre, "{")); + ctx->indent_level++; + for (j = 0; j < nmembs; j++) { if (j) - h5tools_str_append(str, "%s", OPT(info->cmpd_sep, ", " OPTIONAL_LINE_BREAK)); - - /* RPM 2000-10-31 - * If the previous character is a line-feed (which is true when - * h5dump is running) then insert some white space for - * indentation. Be warned that column number calculations will be - * incorrect and that object indices at the beginning of the line - * will be missing (h5dump doesn't display them anyway). */ - if (ctx->indent_level >= 0 && str->len && str->s[str->len - 1] == '\n') { - int x; - - h5tools_str_append(str, OPT(info->line_pre, ""), ""); - - for (x = 0; x < ctx->indent_level + 1; x++) - h5tools_str_append(str, "%s", OPT(info->line_indent, "")); - } + h5tools_str_append(str, "%s", OPT(info->cmpd_sep, ", "OPTIONAL_LINE_BREAK)); + else + h5tools_str_append(str, "%s", OPT(info->cmpd_end, "")); + if(info->arr_linebreak) + h5tools_str_indent(str, info, ctx); + /* The name */ name = H5Tget_member_name(type, j); h5tools_str_append(str, OPT(info->cmpd_name, ""), name); - free(name); + HDfree(name); /* The value */ offset = H5Tget_member_offset(type, j); memb = H5Tget_member_type(type, j); - ctx->indent_level++; h5tools_str_sprint(str, info, container, memb, cp_vp + offset, ctx); - ctx->indent_level--; H5Tclose(memb); } + ctx->indent_level--; - /* RPM 2000-10-31 - * If the previous character is a line feed (which is true when - * h5dump is running) then insert some white space for indentation. - * Be warned that column number calculations will be incorrect and - * that object indices at the beginning of the line will be missing - * (h5dump doesn't display them anyway). */ - h5tools_str_append(str, "%s", OPT(info->cmpd_end, "")); - - if (ctx->indent_level >= 0 && str->len && str->s[str->len - 1] == '\n') { - int x; - h5tools_str_append(str, OPT(info->line_pre, ""), ""); - - for (x = 0; x < ctx->indent_level; x++) - h5tools_str_append(str, "%s", OPT(info->line_indent, "")); + if(info->arr_linebreak) { + h5tools_str_append(str, "%s", OPT(info->cmpd_end, "")); + h5tools_str_indent(str, info, ctx); } - h5tools_str_append(str, "%s", OPT(info->cmpd_suf, "}")); + } else if (H5Tget_class(type) == H5T_ENUM) { char enum_name[1024]; @@ -1084,25 +1088,27 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai else if (H5Tget_class(type) == H5T_ARRAY) { int k, ndims; hsize_t i, dims[H5S_MAX_RANK], temp_nelmts; - static int is_next_arry_elmt=0; + static int is_next_arry_elmt = 0; /* Get the array's base datatype for each element */ memb = H5Tget_super(type); size = H5Tget_size(memb); ndims = H5Tget_array_ndims(type); H5Tget_array_dims2(type, dims); - assert(ndims >= 1 && ndims <= H5S_MAX_RANK); + HDassert(ndims >= 1 && ndims <= H5S_MAX_RANK); /* Calculate the number of array elements */ for (k = 0, nelmts = 1; k < ndims; k++) { temp_nelmts = nelmts; temp_nelmts *= dims[k]; - assert(temp_nelmts == (hsize_t) ((size_t) temp_nelmts)); + HDassert(temp_nelmts == (hsize_t) ((size_t) temp_nelmts)); nelmts = (size_t) temp_nelmts; } /* Print the opening bracket */ h5tools_str_append(str, "%s", OPT(info->arr_pre, "[")); + ctx->indent_level++; + for (i = 0; i < nelmts; i++) { if (i) h5tools_str_append(str, "%s", OPT(info->arr_sep, "," OPTIONAL_LINE_BREAK)); @@ -1111,14 +1117,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai int x; h5tools_str_append(str, "%s", "\n"); + h5tools_str_indent(str, info, ctx); - /* need to indent some more here*/ - if (ctx->indent_level >= 0) - if (!info->pindex) - h5tools_str_append(str, "%s", OPT(info->line_pre, "")); - - for (x = 0; x < ctx->indent_level + 1; x++) - h5tools_str_append(str, "%s", OPT(info->line_indent, "")); } /* end if */ else if (i && info->arr_sep) { /* if next element begin, add next line with indent */ @@ -1127,13 +1127,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai is_next_arry_elmt = 0; h5tools_str_append(str, "%s", "\n "); + h5tools_str_indent(str, info, ctx); - if (ctx->indent_level >= 0) - if (!info->pindex) - h5tools_str_append(str, "%s", OPT(info->line_pre, "")); - - for (x = 0; x < ctx->indent_level + 1; x++) - h5tools_str_append(str, "%s", OPT(info->line_indent, "")); } /* otherwise just add space */ else @@ -1141,15 +1136,13 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai } /* end else if */ - ctx->indent_level++; - /* Dump values in an array element */ is_next_arry_elmt = 0; /* dump all values in the array element, so turn it off */ h5tools_str_sprint(str, info, container, memb, cp_vp + i * size, ctx); - - ctx->indent_level--; } /* end for */ + ctx->indent_level--; + /* Print the closing bracket */ h5tools_str_append(str, "%s", OPT(info->arr_suf, "]")); is_next_arry_elmt = 1; /* set for begining of next array element */ @@ -1280,7 +1273,7 @@ static char * h5tools_escape(char *s/*in,out*/, size_t size) { register size_t i; - size_t n = strlen(s); + size_t n = HDstrlen(s); const char *escape; char octal[8]; @@ -1332,14 +1325,14 @@ h5tools_escape(char *s/*in,out*/, size_t size) } if (escape) { - size_t esc_size = strlen(escape); + size_t esc_size = HDstrlen(escape); if (n + esc_size + 1 > size) /*would overflow*/ return NULL; - memmove(s + i + esc_size, s + i + 1, n - i); /*make room*/ - memcpy(s + i, escape, esc_size); /*insert*/ + HDmemmove(s + i + esc_size, s + i + 1, n - i); /*make room*/ + HDmemcpy(s + i, escape, esc_size); /*insert*/ n += esc_size - 1; /* adjust total string size */ i += esc_size; /* adjust string position */ } diff --git a/tools/lib/h5tools_str.h b/tools/lib/h5tools_str.h index 599c7d1..9527a56 100644 --- a/tools/lib/h5tools_str.h +++ b/tools/lib/h5tools_str.h @@ -26,25 +26,25 @@ typedef struct h5tools_str_t { size_t nalloc; /*allocated size of string */ } h5tools_str_t; -extern void h5tools_str_close(h5tools_str_t *str); -extern size_t h5tools_str_len(h5tools_str_t *str); -extern char *h5tools_str_append(h5tools_str_t *str, const char *fmt, ...); -extern char *h5tools_str_reset(h5tools_str_t *str); -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 h5tool_format_t *info, +H5TOOLS_DLL void h5tools_str_close(h5tools_str_t *str); +H5TOOLS_DLL size_t h5tools_str_len(h5tools_str_t *str); +H5TOOLS_DLL char *h5tools_str_append(h5tools_str_t *str, const char *fmt, ...); +H5TOOLS_DLL char *h5tools_str_reset(h5tools_str_t *str); +H5TOOLS_DLL char *h5tools_str_trunc(h5tools_str_t *str, size_t size); +H5TOOLS_DLL char *h5tools_str_fmt(h5tools_str_t *str, size_t start, const char *fmt); +H5TOOLS_DLL char *h5tools_str_prefix(h5tools_str_t *str, const h5tool_format_t *info, hsize_t elmtno, unsigned ndims, h5tools_context_t *ctx); /* * new functions needed to display region reference data */ -extern char *h5tools_str_region_prefix(h5tools_str_t *str, const h5tool_format_t *info, +H5TOOLS_DLL char *h5tools_str_region_prefix(h5tools_str_t *str, const h5tool_format_t *info, hsize_t elmtno, hsize_t *ptdata, unsigned ndims, hsize_t max_idx[], h5tools_context_t *ctx); -extern void h5tools_str_dump_region_blocks(h5tools_str_t *, hid_t, const h5tool_format_t *); -extern void h5tools_str_dump_region_points(h5tools_str_t *, hid_t, const h5tool_format_t *); -extern void h5tools_str_sprint_region(h5tools_str_t *str, const h5tool_format_t *info, hid_t container, +H5TOOLS_DLL void h5tools_str_dump_region_blocks(h5tools_str_t *, hid_t, const h5tool_format_t *); +H5TOOLS_DLL void h5tools_str_dump_region_points(h5tools_str_t *, hid_t, const h5tool_format_t *); +H5TOOLS_DLL void h5tools_str_sprint_region(h5tools_str_t *str, const h5tool_format_t *info, hid_t container, void *vp); -extern char *h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, +H5TOOLS_DLL char *h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t container, hid_t type, void *vp, h5tools_context_t *ctx); diff --git a/tools/lib/h5tools_type.c b/tools/lib/h5tools_type.c index bbd1b8d..d68d3c5 100644 --- a/tools/lib/h5tools_type.c +++ b/tools/lib/h5tools_type.c @@ -66,62 +66,62 @@ h5tools_get_native_type(hid_t type) hid_t h5tools_get_little_endian_type(hid_t tid) { - hid_t p_type=-1; - H5T_class_t type_class; - size_t size; - H5T_sign_t sign; - - type_class = H5Tget_class(tid); - size = H5Tget_size(tid); - sign = H5Tget_sign(tid); - - switch( type_class ) - { - case H5T_INTEGER: - { - if ( size == 1 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I8LE); - else if ( size == 2 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I16LE); - else if ( size == 4 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I32LE); - else if ( size == 8 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I64LE); - else if ( size == 1 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U8LE); - else if ( size == 2 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U16LE); - else if ( size == 4 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U32LE); - else if ( size == 8 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U64LE); - } - break; - - case H5T_FLOAT: - if ( size == 4) - p_type=H5Tcopy(H5T_IEEE_F32LE); - else if ( size == 8) - p_type=H5Tcopy(H5T_IEEE_F64LE); - break; - - case H5T_TIME: - case H5T_BITFIELD: - case H5T_OPAQUE: - case H5T_STRING: - case H5T_COMPOUND: - case H5T_REFERENCE: - case H5T_ENUM: - case H5T_VLEN: - case H5T_ARRAY: - break; - - default: - break; - - } - - return(p_type); + hid_t p_type=-1; + H5T_class_t type_class; + size_t size; + H5T_sign_t sign; + + type_class = H5Tget_class(tid); + size = H5Tget_size(tid); + sign = H5Tget_sign(tid); + + switch( type_class ) + { + case H5T_INTEGER: + { + if ( size == 1 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I8LE); + else if ( size == 2 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I16LE); + else if ( size == 4 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I32LE); + else if ( size == 8 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I64LE); + else if ( size == 1 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U8LE); + else if ( size == 2 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U16LE); + else if ( size == 4 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U32LE); + else if ( size == 8 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U64LE); + } + break; + + case H5T_FLOAT: + if ( size == 4) + p_type=H5Tcopy(H5T_IEEE_F32LE); + else if ( size == 8) + p_type=H5Tcopy(H5T_IEEE_F64LE); + break; + + case H5T_TIME: + case H5T_BITFIELD: + case H5T_OPAQUE: + case H5T_STRING: + case H5T_COMPOUND: + case H5T_REFERENCE: + case H5T_ENUM: + case H5T_VLEN: + case H5T_ARRAY: + break; + + default: + break; + + } + + return(p_type); } @@ -143,62 +143,62 @@ h5tools_get_little_endian_type(hid_t tid) hid_t h5tools_get_big_endian_type(hid_t tid) { - hid_t p_type=-1; - H5T_class_t type_class; - size_t size; - H5T_sign_t sign; - - type_class = H5Tget_class(tid); - size = H5Tget_size(tid); - sign = H5Tget_sign(tid); - - switch( type_class ) - { - case H5T_INTEGER: - { - if ( size == 1 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I8BE); - else if ( size == 2 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I16BE); - else if ( size == 4 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I32BE); - else if ( size == 8 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I64BE); - else if ( size == 1 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U8BE); - else if ( size == 2 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U16BE); - else if ( size == 4 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U32BE); - else if ( size == 8 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U64BE); - } - break; - - case H5T_FLOAT: - if ( size == 4) - p_type=H5Tcopy(H5T_IEEE_F32BE); - else if ( size == 8) - p_type=H5Tcopy(H5T_IEEE_F64BE); - break; - - case H5T_TIME: - case H5T_BITFIELD: - case H5T_OPAQUE: - case H5T_STRING: - case H5T_COMPOUND: - case H5T_REFERENCE: - case H5T_ENUM: - case H5T_VLEN: - case H5T_ARRAY: - break; - - default: - break; - - } - - - return(p_type); + hid_t p_type=-1; + H5T_class_t type_class; + size_t size; + H5T_sign_t sign; + + type_class = H5Tget_class(tid); + size = H5Tget_size(tid); + sign = H5Tget_sign(tid); + + switch( type_class ) + { + case H5T_INTEGER: + { + if ( size == 1 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I8BE); + else if ( size == 2 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I16BE); + else if ( size == 4 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I32BE); + else if ( size == 8 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I64BE); + else if ( size == 1 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U8BE); + else if ( size == 2 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U16BE); + else if ( size == 4 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U32BE); + else if ( size == 8 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U64BE); + } + break; + + case H5T_FLOAT: + if ( size == 4) + p_type=H5Tcopy(H5T_IEEE_F32BE); + else if ( size == 8) + p_type=H5Tcopy(H5T_IEEE_F64BE); + break; + + case H5T_TIME: + case H5T_BITFIELD: + case H5T_OPAQUE: + case H5T_STRING: + case H5T_COMPOUND: + case H5T_REFERENCE: + case H5T_ENUM: + case H5T_VLEN: + case H5T_ARRAY: + break; + + default: + break; + + } + + + return(p_type); } diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c index ab8536f..4505609 100644 --- a/tools/lib/h5tools_utils.c +++ b/tools/lib/h5tools_utils.c @@ -28,13 +28,13 @@ #include <stdio.h> #include <stdlib.h> +#include "h5tools.h" #include "h5tools_utils.h" #include "H5private.h" #include "h5trav.h" /* global variables */ -int nCols = 80; - +int h5tools_nCols = 80; /* ``get_option'' variables */ int opt_err = 1; /*get_option prints errors if this is on */ int opt_ind = 1; /*token pointer */ @@ -42,6 +42,18 @@ const char *opt_arg; /*flag argument (or value) */ static int h5tools_d_status = 0; static const char *h5tools_progname = "h5tools"; +/* + * The output functions need a temporary buffer to hold a piece of the + * dataset while it's being printed. This constant sets the limit on the + * size of that temporary buffer in bytes. For efficiency's sake, choose the + * largest value suitable for your machine (for testing use a small value). + */ +/* Maximum size used in a call to malloc for a dataset */ +hsize_t H5TOOLS_MALLOCSIZE = (128 * 1024 * 1024); +/* size of hyperslab buffer when a dataset is bigger than H5TOOLS_MALLOCSIZE */ +hsize_t H5TOOLS_BUFSIZE = (1024 * 1024); + + /* ``parallel_print'' variables */ unsigned char g_Parallel = 0; /*0 for serial, 1 for parallel */ char outBuff[OUTBUFF_SIZE]; @@ -68,57 +80,54 @@ static void add_obj(table_t *table, haddr_t objno, const char *objname, hbool_t */ void parallel_print(const char* format, ...) { - int bytes_written; - va_list ap; - - va_start(ap, format); + int bytes_written; + va_list ap; - if(!g_Parallel) - vprintf(format, ap); - else - { + HDva_start(ap, format); - if(overflow_file == NULL) /*no overflow has occurred yet */ - { + if(!g_Parallel) + HDvprintf(format, ap); + else { + if(overflow_file == NULL) /*no overflow has occurred yet */ { #if 0 - printf("calling HDvsnprintf: OUTBUFF_SIZE=%ld, outBuffOffset=%ld, ", (long)OUTBUFF_SIZE, (long)outBuffOffset); + printf("calling HDvsnprintf: OUTBUFF_SIZE=%ld, outBuffOffset=%ld, ", (long)OUTBUFF_SIZE, (long)outBuffOffset); #endif - bytes_written = HDvsnprintf(outBuff+outBuffOffset, OUTBUFF_SIZE-outBuffOffset, format, ap); + bytes_written = HDvsnprintf(outBuff+outBuffOffset, OUTBUFF_SIZE-outBuffOffset, format, ap); #if 0 - printf("bytes_written=%ld\n", (long)bytes_written); + printf("bytes_written=%ld\n", (long)bytes_written); #endif - va_end(ap); - va_start(ap, format); + HDva_end(ap); + HDva_start(ap, format); #if 0 - printf("Result: bytes_written=%ld, OUTBUFF_SIZE-outBuffOffset=%ld\n", (long)bytes_written, (long)OUTBUFF_SIZE-outBuffOffset); + printf("Result: bytes_written=%ld, OUTBUFF_SIZE-outBuffOffset=%ld\n", (long)bytes_written, (long)OUTBUFF_SIZE-outBuffOffset); #endif - if ((bytes_written < 0) || + if ((bytes_written < 0) || #ifdef H5_VSNPRINTF_WORKS - (bytes_written >= (OUTBUFF_SIZE-outBuffOffset)) + (bytes_written >= (OUTBUFF_SIZE-outBuffOffset)) #else - ((bytes_written+1) == (OUTBUFF_SIZE-outBuffOffset)) + ((bytes_written+1) == (OUTBUFF_SIZE-outBuffOffset)) #endif - ) - { - /* Terminate the outbuff at the end of the previous output */ - outBuff[outBuffOffset] = '\0'; - - overflow_file = HDtmpfile(); - if(overflow_file == NULL) - fprintf(stderr, "warning: could not create overflow file. Output may be truncated.\n"); - else - bytes_written = HDvfprintf(overflow_file, format, ap); - } - else - outBuffOffset += bytes_written; - } - else - bytes_written = HDvfprintf(overflow_file, format, ap); - - } - va_end(ap); + ) + { + /* Terminate the outbuff at the end of the previous output */ + outBuff[outBuffOffset] = '\0'; + + overflow_file = HDtmpfile(); + if(overflow_file == NULL) + HDfprintf(rawerrorstream, "warning: could not create overflow file. Output may be truncated.\n"); + else + bytes_written = HDvfprintf(overflow_file, format, ap); + } + else + outBuffOffset += bytes_written; + } + else + bytes_written = HDvfprintf(overflow_file, format, ap); + + } + HDva_end(ap); } @@ -142,12 +151,13 @@ error_msg(const char *fmt, ...) { va_list ap; - va_start(ap, fmt); - HDfflush(stdout); - HDfprintf(stderr, "%s error: ", h5tools_getprogname()); - HDvfprintf(stderr, fmt, ap); + HDva_start(ap, fmt); + HDfflush(rawdatastream); + HDfflush(rawoutstream); + HDfprintf(rawerrorstream, "%s error: ", h5tools_getprogname()); + HDvfprintf(rawerrorstream, fmt, ap); - va_end(ap); + HDva_end(ap); } @@ -171,11 +181,12 @@ warn_msg(const char *fmt, ...) { va_list ap; - va_start(ap, fmt); - HDfflush(stdout); - HDfprintf(stderr, "%s warning: ", h5tools_getprogname()); - HDvfprintf(stderr, fmt, ap); - va_end(ap); + HDva_start(ap, fmt); + HDfflush(rawdatastream); + HDfflush(rawoutstream); + HDfprintf(rawerrorstream, "%s warning: ", h5tools_getprogname()); + HDvfprintf(rawerrorstream, fmt, ap); + HDva_end(ap); } /*------------------------------------------------------------------------- @@ -228,7 +239,8 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti /* check for more flag-like tokens */ if (opt_ind >= argc || argv[opt_ind][0] != '-' || argv[opt_ind][1] == '\0') { return EOF; - } else if (HDstrcmp(argv[opt_ind], "--") == 0) { + } + else if (HDstrcmp(argv[opt_ind], "--") == 0) { opt_ind++; return EOF; } @@ -254,27 +266,27 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti if (opt_ind < (argc - 1)) if (argv[opt_ind + 1][0] != '-') opt_arg = argv[++opt_ind]; - } else if (l_opts[i].has_arg == require_arg) { + } + else if (l_opts[i].has_arg == require_arg) { if (opt_err) - HDfprintf(stderr, + HDfprintf(rawerrorstream, "%s: option required for \"--%s\" flag\n", argv[0], arg); opt_opt = '?'; } - } else { + } + else { if (arg[len] == '=') { if (opt_err) - HDfprintf(stderr, + HDfprintf(rawerrorstream, "%s: no option required for \"%s\" flag\n", argv[0], arg); opt_opt = '?'; } - opt_arg = NULL; } - break; } } @@ -282,22 +294,23 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti if (l_opts[i].name == NULL) { /* exhausted all of the l_opts we have and still didn't match */ if (opt_err) - HDfprintf(stderr, "%s: unknown option \"%s\"\n", argv[0], arg); + HDfprintf(rawerrorstream, "%s: unknown option \"%s\"\n", argv[0], arg); opt_opt = '?'; } opt_ind++; sp = 1; - } else { + } + else { register char *cp; /* pointer into current token */ /* short command line option */ opt_opt = argv[opt_ind][sp]; - if (opt_opt == ':' || (cp = strchr(opts, opt_opt)) == 0) { + if (opt_opt == ':' || (cp = HDstrchr(opts, opt_opt)) == 0) { if (opt_err) - HDfprintf(stderr, "%s: unknown option \"%c\"\n", + HDfprintf(rawerrorstream, "%s: unknown option \"%c\"\n", argv[0], opt_opt); /* if no chars left in this token, move to next token */ @@ -305,7 +318,6 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti opt_ind++; sp = 1; } - return '?'; } @@ -314,48 +326,41 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti if (argv[opt_ind][sp + 1] != '\0') { /* flag value is rest of current token */ opt_arg = &argv[opt_ind++][sp + 1]; - } else if (++opt_ind >= argc) { + } + else if (++opt_ind >= argc) { if (opt_err) - HDfprintf(stderr, + HDfprintf(rawerrorstream, "%s: value expected for option \"%c\"\n", argv[0], opt_opt); opt_opt = '?'; - } else { + } + else { /* flag value is next token */ opt_arg = argv[opt_ind++]; } sp = 1; } - /* wildcard argument */ - else if (*cp == '*') - { + else if (*cp == '*') { /* check the next argument */ opt_ind++; /* we do have an extra argument, check if not last */ - if ( argv[opt_ind][0] != '-' && (opt_ind+1) < argc ) - { + if ( argv[opt_ind][0] != '-' && (opt_ind+1) < argc ) { opt_arg = argv[opt_ind++]; } - else - { + else { opt_arg = NULL; } } - - else - { + else { /* set up to look at next char in token, next time */ if (argv[opt_ind][++sp] == '\0') { /* no more in current token, so setup next token */ opt_ind++; sp = 1; - - } - opt_arg = NULL; } } @@ -381,12 +386,13 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti void indentation(int x) { - if (x < nCols) { + if (x < h5tools_nCols) { while (x-- > 0) - printf(" "); - } else { - HDfprintf(stderr, "error: the indentation exceeds the number of cols.\n"); - exit(1); + HDfprintf(rawoutstream, " "); + } + else { + HDfprintf(rawerrorstream, "error: the indentation exceeds the number of cols.\n"); + HDexit(1); } } @@ -408,7 +414,7 @@ indentation(int x) void print_version(const char *progname) { - printf("%s: Version %u.%u.%u%s%s\n", + HDfprintf(rawoutstream, "%s: Version %u.%u.%u%s%s\n", progname, H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE, ((char *)H5_VERS_SUBRELEASE)[0] ? "-" : "", H5_VERS_SUBRELEASE); } @@ -488,9 +494,9 @@ dump_table(char* tablename, table_t *table) { unsigned u; - printf("%s: # of entries = %d\n", tablename,table->nobjs); + HDfprintf(rawoutstream,"%s: # of entries = %d\n", tablename,table->nobjs); for (u = 0; u < table->nobjs; u++) - HDfprintf(stdout,"%a %s %d %d\n", table->objs[u].objno, + HDfprintf(rawoutstream,"%a %s %d %d\n", table->objs[u].objno, table->objs[u].objname, table->objs[u].displayed, table->objs[u].recorded); } @@ -889,3 +895,43 @@ int h5tools_getstatus(void) { return h5tools_d_status; } + +/*----------------------------------------------------------- + * PURPOSE : + * if environment variable H5TOOLS_BUFSIZE is set, + * update H5TOOLS_BUFSIZE and H5TOOLS_MALLOCSIZE from the env + * This can be called from each tools main() as part of initial act. + * Note: this is more of debugging purpose for now. + */ +int h5tools_getenv_update_hyperslab_bufsize(void) +{ + const char *env_str = NULL; + long hyperslab_bufsize_mb; + + /* check if environment variable is set for the hyperslab buffer size */ + if (NULL != (env_str = HDgetenv ("H5TOOLS_BUFSIZE"))) + { + errno = 0; + hyperslab_bufsize_mb = HDstrtol(env_str, (char**)NULL, 10); + if (errno != 0 || hyperslab_bufsize_mb <= 0) + { + + /* TODO: later when pubilshed + HDfprintf(rawerrorstream,"Error: Invalid environment variable \"H5TOOLS_BUFSIZE\" : %s\n", env_str); + */ + + goto error; + } + + + /* convert MB to byte */ + H5TOOLS_BUFSIZE = hyperslab_bufsize_mb * 1024 * 1024; + + H5TOOLS_MALLOCSIZE = MAX(H5TOOLS_BUFSIZE, H5TOOLS_MALLOCSIZE); + } + + + return (1); +error: + return (-1); +} diff --git a/tools/lib/h5tools_utils.h b/tools/lib/h5tools_utils.h index 4d356c7..f30974a 100644 --- a/tools/lib/h5tools_utils.h +++ b/tools/lib/h5tools_utils.h @@ -29,8 +29,8 @@ extern "C" { #endif /* ``parallel_print'' information */ -#define PRINT_DATA_MAX_SIZE 512 -#define OUTBUFF_SIZE (PRINT_DATA_MAX_SIZE*4) +#define PRINT_DATA_MAX_SIZE 512 +#define OUTBUFF_SIZE (PRINT_DATA_MAX_SIZE*4) H5TOOLS_DLLVAR int g_nTasks; H5TOOLS_DLLVAR unsigned char g_Parallel; @@ -38,6 +38,10 @@ H5TOOLS_DLLVAR char outBuff[]; H5TOOLS_DLLVAR int outBuffOffset; H5TOOLS_DLLVAR FILE * overflow_file; +/* Maximum size used in a call to malloc for a dataset */ +H5TOOLS_DLLVAR hsize_t H5TOOLS_MALLOCSIZE; +/* size of hyperslab buffer when a dataset is bigger than H5TOOLS_MALLOCSIZE */ +H5TOOLS_DLLVAR hsize_t H5TOOLS_BUFSIZE; /* * begin get_option section */ @@ -115,7 +119,7 @@ typedef struct find_objs_t { table_t *dset_table; } find_objs_t; -H5TOOLS_DLLVAR int nCols; /*max number of columns for outputting */ +H5TOOLS_DLLVAR int h5tools_nCols; /*max number of columns for outputting */ /* Definitions of useful routines */ H5TOOLS_DLL void indentation(int); @@ -169,7 +173,7 @@ H5TOOLS_DLL const char *h5tools_getprogname(void); H5TOOLS_DLL void h5tools_setprogname(const char*progname); H5TOOLS_DLL int h5tools_getstatus(void); H5TOOLS_DLL void h5tools_setstatus(int d_status); - +H5TOOLS_DLL int h5tools_getenv_update_hyperslab_bufsize(void); #ifdef __cplusplus } #endif diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c index c3cfddf..3bb8b3f 100644 --- a/tools/lib/h5trav.c +++ b/tools/lib/h5trav.c @@ -900,7 +900,7 @@ trav_print_visit_lnk(const char *path, const H5L_info_t *linfo, void *udata) H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT); printf(" %-10s %s -> %s\n", "link", path, targbuf); - free(targbuf); + HDfree(targbuf); } /* end if */ else printf(" %-10s %s ->\n", "link", path); @@ -913,12 +913,12 @@ trav_print_visit_lnk(const char *path, const H5L_info_t *linfo, void *udata) const char *objname; targbuf = HDmalloc(linfo->u.val_size + 1); - assert(targbuf); + HDassert(targbuf); H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT); H5Lunpack_elink_val(targbuf, linfo->u.val_size, NULL, &filename, &objname); printf(" %-10s %s -> %s %s\n", "ext link", path, filename, objname); - free(targbuf); + HDfree(targbuf); } /* end if */ else printf(" %-10s %s ->\n", "ext link", path); |