From 6881c423a13ae1e7dbf73f1b6fc02d91c71e5947 Mon Sep 17 00:00:00 2001 From: Robb Matzke Date: Mon, 7 Jun 1999 13:19:30 -0500 Subject: [svn-r1309] Changes since 19990607 ---------------------- ./tools/h5tools.c Finished code which prints references (object and dataset region). Patrick, if you tell me how h5dump should (or might want to) print references I can make some changes to support various formats... You can try it out with: cd test env HDF5_NOCLEANUP=yes ./testhdf5 ../tools/h5ls -dvr trefer1.h5 ../tools/h5ls -dvr trefer2.h5 (run h5ls with no arguments if you forgot what the switches do) ./test/trefer.c Call calloc instead of malloc in one place to prevent uninitialized data from being written into the file. --- test/trefer.c | 2 +- tools/h5ls.c | 15 +++-- tools/h5tools.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 169 insertions(+), 36 deletions(-) diff --git a/test/trefer.c b/test/trefer.c index 651557f..bb27695 100644 --- a/test/trefer.c +++ b/test/trefer.c @@ -316,7 +316,7 @@ test_reference_region(void) MESSAGE(5, ("Testing Dataset Region Reference Functions\n")); /* Allocate write & read buffers */ - wbuf=malloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1); + wbuf=calloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1); rbuf=malloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1); dwbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); drbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); diff --git a/tools/h5ls.c b/tools/h5ls.c index 1dfe647..acd8c9e 100644 --- a/tools/h5ls.c +++ b/tools/h5ls.c @@ -1000,6 +1000,13 @@ dump_dataset_values(hid_t dset) info.line_ncols = width_g; info.line_multi_new = 1; if (label_g) info.cmpd_name = "%s="; + + /* + * If a compound datatype is split across multiple lines then indent + * the continuation line. + */ + info.line_pre = " %s "; + info.line_cont = " %s "; if (hexdump_g) { /* @@ -1018,14 +1025,6 @@ dump_dataset_values(hid_t dset) info.line_pre =" %s \""; info.line_suf = "\""; } - - - /* - * If a compound datatype is split across multiple lines then add an - * ellipsis to the beginning of the continuation line. - */ - info.line_pre = " %s "; - info.line_cont = " %s "; /* * Print all the values. diff --git a/tools/h5tools.c b/tools/h5tools.c index 40cc9f5..226b036 100644 --- a/tools/h5tools.c +++ b/tools/h5tools.c @@ -186,6 +186,7 @@ h5dump_str_append(h5dump_str_t *str/*in,out*/, const char *fmt, ...) str->len += nchars; break; } + /* Try again with twice as much space */ str->nalloc *= 2; str->s = realloc(str->s, str->nalloc); @@ -446,6 +447,112 @@ h5dump_escape(char *s/*in,out*/, size_t size, int escape_spaces) /*------------------------------------------------------------------------- + * Function: h5dump_is_zero + * + * Purpose: Determines if memory is initialized to all zero bytes. + * + * Return: TRUE if all bytes are zero; FALSE otherwise + * + * Programmer: Robb Matzke + * Monday, June 7, 1999 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static hbool_t +h5dump_is_zero(const void *_mem, size_t size) +{ + const unsigned char *mem = (const unsigned char*)_mem; + while (size-- > 0) { + if (mem[size]) return FALSE; + } + return TRUE; +} + + +/*------------------------------------------------------------------------- + * Function: h5dump_region + * + * Purpose: Prints information about a dataspace region by appending + * the information to the specified string. + * + * Return: Success: 0 + * + * Failure: NULL + * + * Programmer: Robb Matzke + * Monday, June 7, 1999 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +h5dump_region(hid_t region, h5dump_str_t *str/*in,out*/) +{ + hssize_t nblocks, npoints, i; + hsize_t *ptdata; + int j; + int ndims = H5Sget_simple_extent_ndims(region); + + /* + * These two functions fail if the region does not have blocks or points, + * respectively. They do not currently know how to translate from one to + * the other. + */ + H5E_BEGIN_TRY { + nblocks = H5Sget_select_hyper_nblocks(region); + npoints = H5Sget_select_elem_npoints(region); + } H5E_END_TRY; + h5dump_str_append(str, "{"); + + /* Print block information */ + if (nblocks>0) { + ptdata = malloc(nblocks*ndims*2*sizeof(ptdata[0])); + H5Sget_select_hyper_blocklist(region, 0, nblocks, ptdata); + for (i=0; i0) { + ptdata = malloc(npoints*ndims*sizeof(ptdata[0])); + H5Sget_select_elem_pointlist(region, 0, npoints, ptdata); + for (i=0; i