diff options
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/h5tools.c | 556 | ||||
-rw-r--r-- | tools/lib/h5tools.h | 3 | ||||
-rw-r--r-- | tools/lib/h5tools_dump.c | 4 | ||||
-rw-r--r-- | tools/lib/h5tools_str.c | 873 | ||||
-rw-r--r-- | tools/lib/h5tools_utils.c | 2 | ||||
-rw-r--r-- | tools/lib/h5tools_utils.h | 2 | ||||
-rw-r--r-- | tools/lib/h5trav.c | 25 | ||||
-rw-r--r-- | tools/lib/h5trav.h | 2 |
8 files changed, 645 insertions, 822 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index f308a99..dd72284 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -1064,37 +1064,6 @@ init_acc_pos(h5tools_context_t *ctx, hsize_t *dims) } /*------------------------------------------------------------------------- - * Function: do_bin_output - * - * Purpose: Dump memory buffer to a binary file stream - * - * Return: Success: SUCCEED - * Failure: FAIL - *------------------------------------------------------------------------- - */ -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; - size_t size; /* datum size */ - hsize_t i; /* element counter */ - - if((size = H5Tget_size(tid)) == 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); - - for (i = 0; i < nelmts; i++) { - if (render_bin_output(stream, container, tid, mem + i * size) < 0) { - HDfprintf(err_stream,"\nError in writing binary stream\n"); - return FAIL; - } - } - -CATCH - return ret_value; -} - -/*------------------------------------------------------------------------- * Function: render_bin_output * * Purpose: Write one element of memory buffer to a binary file stream @@ -1104,369 +1073,182 @@ CATCH *------------------------------------------------------------------------- */ int -render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem) +render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t block_nelmts) { HERR_INIT(int, SUCCEED) unsigned char *mem = (unsigned char*)_mem; size_t size; /* datum size */ - float tempfloat; - double tempdouble; - unsigned long long tempullong; - long long templlong; - unsigned long tempulong; - long templong; - unsigned int tempuint; - int tempint; - unsigned short tempushort; - short tempshort; - unsigned char tempuchar; - char tempschar; -#if H5_SIZEOF_LONG_DOUBLE !=0 - long double templdouble; -#endif -#ifdef DEBUG_H5DUMP_BIN - static char fmt_llong[8], fmt_ullong[8]; - if (!fmt_llong[0]) { - HDsprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH); - HDsprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH); - } -#endif + hsize_t block_index; + H5T_class_t type_class; if((size = H5Tget_size(tid)) == 0) H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); - if (H5Tequal(tid, H5T_NATIVE_FLOAT)) { - HDmemcpy(&tempfloat, mem, sizeof(float)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%g ", tempfloat); -#else - 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)) { - HDmemcpy(&tempdouble, mem, sizeof(double)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%g ", tempdouble); -#else - 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)) { - HDmemcpy(&templdouble, mem, sizeof(long double)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%Lf ", templdouble); -#else - if (1 != HDfwrite(&templdouble, size, 1, stream)) - H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); -#endif - } -#endif - else if (H5T_STRING == H5Tget_class(tid)) { - unsigned int i; - H5T_str_t pad; - char *s; - - pad = H5Tget_strpad(tid); - - if (H5Tis_variable_str(tid)) { - s = *(char**) mem; - if (s != NULL) - size = HDstrlen(s); - } - else { - s = (char *) mem; - if((size = H5Tget_size(tid)) == 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); - } - for (i = 0; i < size && (s[i] || pad != H5T_STR_NULLTERM); i++) { - HDmemcpy(&tempuchar, &s[i], sizeof(unsigned char)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%d", tempuchar); -#else - 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)) { - HDmemcpy(&tempint, mem, sizeof(int)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%d ", tempint); -#else - 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)) { - HDmemcpy(&tempuint, mem, sizeof(unsigned int)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%u ", tempuint); -#else - 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)) { - HDmemcpy(&tempschar, mem, sizeof(char)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%d ", tempschar); -#else - 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)) { - HDmemcpy(&tempuchar, mem, sizeof(unsigned char)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%u ", tempuchar); -#else - 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)) { - HDmemcpy(&tempshort, mem, sizeof(short)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%d ", tempshort); -#else - 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)) { - HDmemcpy(&tempushort, mem, sizeof(unsigned short)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%u ", tempushort); -#else - 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)) { - HDmemcpy(&templong, mem, sizeof(long)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%ld ", templong); -#else - 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)) { - HDmemcpy(&tempulong, mem, sizeof(unsigned long)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%lu ", tempulong); -#else - 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)) { - HDmemcpy(&templlong, mem, sizeof(long long)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, fmt_llong, templlong); -#else - 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)) { - HDmemcpy(&tempullong, mem, sizeof(unsigned long long)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, fmt_ullong, tempullong); -#else - 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)) { - HDmemcpy(&tempint, mem, sizeof(int)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%d ", tempint); -#else - 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)) { - HDmemcpy(&templong, mem, sizeof(long)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%ld ", templong); -#else - if (1 != HDfwrite(&templong, size, 1, stream)) - H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); -#endif - } - else { - HDmemcpy(&templlong, mem, sizeof(long long)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, fmt_llong, templlong); -#else - 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)) { - HDmemcpy(&tempuint, mem, sizeof(unsigned int)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%u ", tempuint); -#else - 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)) { - HDmemcpy(&tempulong, mem, sizeof(unsigned long)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "%lu ", tempulong); -#else - if (1 != HDfwrite(&tempulong, size, 1, stream)) - H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); -#endif - } - else { - HDmemcpy(&tempullong, mem, sizeof(unsigned long long)); -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, fmt_ullong, tempullong); -#else - if (1 != HDfwrite(&tempullong, size, 1, stream)) - H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); -#endif - } - } - else if (H5Tget_class(tid) == H5T_COMPOUND) { - unsigned j; - hid_t memb; - unsigned nmembs; - size_t offset; + if((type_class = H5Tget_class(tid)) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_class failed"); - nmembs = H5Tget_nmembers(tid); + switch (type_class) { + case H5T_INTEGER: + case H5T_FLOAT: + case H5T_ENUM: + block_index = block_nelmts * size; + while(block_index > 0) { + size_t bytes_in = 0; /* # of bytes to write */ + size_t bytes_wrote = 0; /* # of bytes written */ + size_t item_size = size; /* size of items in bytes */ - for (j = 0; j < nmembs; j++) { - offset = H5Tget_member_offset(tid, j); - memb = H5Tget_member_type(tid, j); + if(block_index > sizeof(size_t)) + bytes_in = sizeof(size_t); + else + bytes_in = (size_t)block_index; - if (render_bin_output(stream, container, memb, mem + offset) < 0) - return FAIL; + bytes_wrote = HDfwrite(mem, 1, bytes_in, stream); - H5Tclose(memb); - } - } - else if (H5Tget_class(tid) == H5T_ENUM) { - unsigned int i; - if (1 == size) { -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "0x%02x", mem[0]); -#else - 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 - HDfprintf(stream, "%s%02x", i?":":"", mem[i]); -#else - if (1 != HDfwrite(&mem[i], sizeof(char), 1, stream)) + if(bytes_wrote != bytes_in || (0 == bytes_wrote && HDferror(stream))) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); -#endif - } /*i*/ - }/*else 1 */ - } - else if (H5Tget_class(tid) == H5T_ARRAY) { - int k, ndims; - hsize_t i, dims[H5S_MAX_RANK], temp_nelmts, nelmts; - hid_t memb; - - /* get the array's base datatype for each element */ - memb = H5Tget_super(tid); - size = H5Tget_size(memb); - ndims = H5Tget_array_ndims(tid); - H5Tget_array_dims2(tid, dims); - 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]; - nelmts = (size_t) temp_nelmts; - } - - /* dump the array element */ - for (i = 0; i < nelmts; i++) { - if (render_bin_output(stream, container, memb, mem + i * size) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "render_bin_output failed"); - } - H5Tclose(memb); - } - else if (H5Tget_class(tid) == H5T_VLEN) { - unsigned int i; - hsize_t nelmts; - hid_t memb; - - /* get the VL sequences's base datatype for each element */ - memb = H5Tget_super(tid); - size = H5Tget_size(memb); - - /* Get the number of sequence elements */ - nelmts = ((hvl_t *) mem)->len; - - for (i = 0; i < nelmts; i++) { - /* dump the array element */ - if (render_bin_output(stream, container, memb, ((char *) (((hvl_t *) mem)->p)) + i * size) < 0) - H5E_THROW(FAIL, H5E_tools_min_id_g, "render_bin_output failed"); - } - H5Tclose(memb); - } - else if (H5Tequal(tid, H5T_STD_REF_DSETREG)) { - if (region_output) { - /* region data */ - hid_t region_id, region_space; - H5S_sel_type region_type; - - region_id = H5Rdereference(container, H5R_DATASET_REGION, mem); - if (region_id >= 0) { - region_space = H5Rget_region(container, H5R_DATASET_REGION, mem); - if (region_space >= 0) { - region_type = H5Sget_select_type(region_space); - if(region_type == H5S_SEL_POINTS) - render_bin_output_region_points(region_space, region_id, stream, container); - else - render_bin_output_region_blocks(region_space, region_id, stream, container); - H5Sclose(region_space); - } /* end if (region_space >= 0) */ - H5Dclose(region_id); - } /* end if (region_id >= 0) */ - } /* end if (region_output... */ - } - else if (H5Tequal(tid, H5T_STD_REF_OBJ)) { - } - else { - size_t i; - if (1 == size) { -#ifdef DEBUG_H5DUMP_BIN - HDfprintf(stream, "0x%02x", mem[0]); -#else - 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 - HDfprintf(stream, "%s%02x", i?":":"", mem[i]); -#else - if (1 != HDfwrite(&mem[i], sizeof(char), 1, stream)) + block_index -= (hsize_t)bytes_wrote; + mem = mem + bytes_wrote; + } + break; + case H5T_STRING: + { + unsigned int i; + H5T_str_t pad; + char *s; + unsigned char tempuchar; + + pad = H5Tget_strpad(tid); + + for (block_index = 0; block_index < block_nelmts; block_index++) { + mem = ((unsigned char*)_mem) + block_index * size; + + if (H5Tis_variable_str(tid)) { + s = *(char**) mem; + if (s != NULL) + size = HDstrlen(s); + } + else { + s = (char *) mem; + } + for (i = 0; i < size && (s[i] || pad != H5T_STR_NULLTERM); i++) { + HDmemcpy(&tempuchar, &s[i], sizeof(unsigned char)); + if (1 != HDfwrite(&tempuchar, size, 1, stream)) + H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); + } /* i */ + } /* for (block_index = 0; block_index < block_nelmts; block_index++) */ + } + break; + case H5T_COMPOUND: + { + unsigned j; + hid_t memb; + unsigned nmembs; + size_t offset; + + nmembs = H5Tget_nmembers(tid); + + for (block_index = 0; block_index < block_nelmts; block_index++) { + mem = ((unsigned char*)_mem) + block_index * size; + for (j = 0; j < nmembs; j++) { + offset = H5Tget_member_offset(tid, j); + memb = H5Tget_member_type(tid, j); + + if (render_bin_output(stream, container, memb, mem + offset, 1) < 0) + return FAIL; + + H5Tclose(memb); + } + } + } + break; + case H5T_ARRAY: + { + int k, ndims; + hsize_t i, dims[H5S_MAX_RANK], temp_nelmts, nelmts; + hid_t memb; + + /* get the array's base datatype for each element */ + memb = H5Tget_super(tid); + ndims = H5Tget_array_ndims(tid); + H5Tget_array_dims2(tid, dims); + 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]; + nelmts = (size_t) temp_nelmts; + } + + for (block_index = 0; block_index < block_nelmts; block_index++) { + mem = ((unsigned char*)_mem) + block_index * size; + /* dump the array element */ + if (render_bin_output(stream, container, memb, mem, nelmts) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "render_bin_output failed"); + } + H5Tclose(memb); + } + break; + case H5T_VLEN: + { + unsigned int i; + hsize_t nelmts; + hid_t memb; + + /* get the VL sequences's base datatype for each element */ + memb = H5Tget_super(tid); + + for (block_index = 0; block_index < block_nelmts; block_index++) { + mem = ((unsigned char*)_mem) + block_index * size; + /* Get the number of sequence elements */ + nelmts = ((hvl_t *) mem)->len; + + /* dump the array element */ + if (render_bin_output(stream, container, memb, ((char *) (((hvl_t *) mem)->p)), nelmts) < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "render_bin_output failed"); + } + H5Tclose(memb); + } + break; + case H5T_REFERENCE: + { + if (H5Tequal(tid, H5T_STD_REF_DSETREG)) { + if (region_output) { + /* region data */ + hid_t region_id, region_space; + H5S_sel_type region_type; + + for (block_index = 0; block_index < block_nelmts; block_index++) { + mem = ((unsigned char*)_mem) + block_index * size; + region_id = H5Rdereference(container, H5R_DATASET_REGION, mem); + if (region_id >= 0) { + region_space = H5Rget_region(container, H5R_DATASET_REGION, mem); + if (region_space >= 0) { + region_type = H5Sget_select_type(region_space); + if(region_type == H5S_SEL_POINTS) + render_bin_output_region_points(region_space, region_id, stream, container); + else + render_bin_output_region_blocks(region_space, region_id, stream, container); + H5Sclose(region_space); + } /* end if (region_space >= 0) */ + H5Dclose(region_id); + } /* end if (region_id >= 0) */ + } + } /* end if (region_output... */ + } + else if (H5Tequal(tid, H5T_STD_REF_OBJ)) { + ; + } + } + break; + default: + for (block_index = 0; block_index < block_nelmts; block_index++) { + mem = ((unsigned char*)_mem) + block_index * size; + if (size != HDfwrite(mem, sizeof(char), size, stream)) H5E_THROW(FAIL, H5E_tools_min_id_g, "fwrite failed"); -#endif - } /*i*/ - }/*else 1 */ + } + break; } CATCH @@ -1552,12 +1334,8 @@ 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 (numindex = 0; numindex < numelem; numindex++) { - - render_bin_output(stream, container, type_id, - ((char*)region_buf + numindex * type_size)); - /* Render the region data element end */ - } /* end for (jndx = 0; jndx < numelem; jndx++) */ + render_bin_output(stream, container, type_id, (char*)region_buf, numelem); + /* Render the region data element end */ } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */ done: @@ -1684,12 +1462,10 @@ render_bin_output_region_data_points(hid_t region_space, hid_t region_id, 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"); - for (jndx = 0; jndx < npoints; jndx++) { - if(H5Sget_simple_extent_dims(region_space, dims1, NULL) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); + if(H5Sget_simple_extent_dims(region_space, dims1, NULL) < 0) + HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); - render_bin_output(stream, container, type_id, ((char*)region_buf + jndx * type_size)); - } /* end for (jndx = 0; jndx < npoints; jndx++) */ + render_bin_output(stream, container, type_id, (char*)region_buf, npoints); done: HDfree(region_buf); diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index 0f4b271..3e3a4cf 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -560,8 +560,7 @@ H5TOOLS_DLL void h5tools_simple_prefix(FILE *stream, const h5tool_format_t *i 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(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t nelmts); 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, diff --git a/tools/lib/h5tools_dump.c b/tools/lib/h5tools_dump.c index 7ea6f38..7555f03 100644 --- a/tools/lib/h5tools_dump.c +++ b/tools/lib/h5tools_dump.c @@ -282,7 +282,9 @@ h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, hid_t contai /* binary dump */ if (bin_output) { - do_bin_output(rawdatastream, rawoutstream, container, nelmts, type, _mem); + if (render_bin_output(rawdatastream, container, type, _mem, nelmts) < 0) { + HDfprintf(rawoutstream,"\nError in writing binary stream\n"); + } } /* end if */ else { /* setup */ diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index c069ecc..9ce3524 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -693,6 +693,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai unsigned nmembs; static char fmt_llong[8], fmt_ullong[8]; H5T_str_t pad; + H5T_class_t type_class; /* * some tempvars to store the value before we append it to the string to @@ -729,480 +730,494 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai } } } - else if (H5Tequal(type, H5T_NATIVE_FLOAT)) { - float tempfloat; + else { + if((type_class = H5Tget_class(type)) < 0) + return NULL; + switch (type_class) { + case H5T_FLOAT: + if (H5Tequal(type, H5T_NATIVE_FLOAT)) { + float tempfloat; - HDmemcpy(&tempfloat, vp, sizeof(float)); - h5tools_str_append(str, OPT(info->fmt_float, "%g"), tempfloat); - } - else if (H5Tequal(type, H5T_NATIVE_DOUBLE)) { - double tempdouble; + HDmemcpy(&tempfloat, vp, sizeof(float)); + h5tools_str_append(str, OPT(info->fmt_float, "%g"), tempfloat); + } + else if (H5Tequal(type, H5T_NATIVE_DOUBLE)) { + double tempdouble; - HDmemcpy(&tempdouble, vp, sizeof(double)); - h5tools_str_append(str, OPT(info->fmt_double, "%g"), tempdouble); + HDmemcpy(&tempdouble, vp, sizeof(double)); + h5tools_str_append(str, OPT(info->fmt_double, "%g"), tempdouble); #if H5_SIZEOF_LONG_DOUBLE !=0 - } - else if (H5Tequal(type, H5T_NATIVE_LDOUBLE)) { - long double templdouble; + } + else if (H5Tequal(type, H5T_NATIVE_LDOUBLE)) { + long double templdouble; - HDmemcpy(&templdouble, vp, sizeof(long double)); - h5tools_str_append(str, "%Lf", templdouble); + HDmemcpy(&templdouble, vp, sizeof(long double)); + h5tools_str_append(str, "%Lf", templdouble); #endif - } - else if (info->ascii && (H5Tequal(type, H5T_NATIVE_SCHAR) || - H5Tequal(type, H5T_NATIVE_UCHAR))) { - h5tools_print_char(str, info, (char) (*ucp_vp)); - } - else if (H5T_STRING == H5Tget_class(type)) { - unsigned int i; - char quote = '\0'; - char *s; - - quote = '\0'; - if (H5Tis_variable_str(type)) { - /* cp_vp is the pointer into the struct where a `char*' is stored. So we have - * to dereference the pointer to get the `char*' to pass to HDstrlen(). */ - s = *(char**) cp_vp; - if (s != NULL) - size = HDstrlen(s); - } - else { - s = cp_vp; - size = H5Tget_size(type); - } - pad = H5Tget_strpad(type); - - /* Check for NULL pointer for string */ - if (s == NULL) { - h5tools_str_append(str, "NULL"); - } - else { - for (i = 0; i < size && (s[i] || pad != H5T_STR_NULLTERM); i++) { - int j = 1; - - /* - * Count how many times the next character repeats. If the - * threshold is zero then that means it can repeat any number - * of times. - */ - if (info->str_repeat > 0) - while (i + j < size && s[i] == s[i + j]) - j++; - - /* - * Print the opening quote. If the repeat count is high enough to - * warrant printing the number of repeats instead of enumerating - * the characters, then make sure the character to be repeated is - * in it's own quote. - */ - if (info->str_repeat > 0 && j > info->str_repeat) { - if (quote) - h5tools_str_append(str, "%c", quote); - - quote = '\''; - h5tools_str_append(str, "%s%c", i ? " " : "", quote); } - else if (!quote) { - quote = '"'; - h5tools_str_append(str, "%s%c", i ? " " : "", quote); - } - - /* Print the character */ - h5tools_print_char(str, info, s[i]); + break; + case H5T_STRING: + { + unsigned int i; + char quote = '\0'; + char *s; - /* Print the repeat count */ - if (info->str_repeat && j > info->str_repeat) { + quote = '\0'; + if (H5Tis_variable_str(type)) { + /* cp_vp is the pointer into the struct where a `char*' is stored. So we have + * to dereference the pointer to get the `char*' to pass to HDstrlen(). */ + s = *(char**) cp_vp; + if (s != NULL) size = HDstrlen(s); + } + else { + s = cp_vp; + size = H5Tget_size(type); + } + pad = H5Tget_strpad(type); + + /* Check for NULL pointer for string */ + if (s == NULL) { + h5tools_str_append(str, "NULL"); + } + else { + for (i = 0; i < size && (s[i] || pad != H5T_STR_NULLTERM); i++) { + int j = 1; + + /* + * Count how many times the next character repeats. If the + * threshold is zero then that means it can repeat any number + * of times. + */ + if (info->str_repeat > 0) while (i + j < size && s[i] == s[i + j]) + j++; + + /* + * Print the opening quote. If the repeat count is high enough to + * warrant printing the number of repeats instead of enumerating + * the characters, then make sure the character to be repeated is + * in it's own quote. + */ + if (info->str_repeat > 0 && j > info->str_repeat) { + if (quote) h5tools_str_append(str, "%c", quote); + + quote = '\''; + h5tools_str_append(str, "%s%c", i ? " " : "", quote); + } + else if (!quote) { + quote = '"'; + h5tools_str_append(str, "%s%c", i ? " " : "", quote); + } + + /* Print the character */ + h5tools_print_char(str, info, s[i]); + + /* Print the repeat count */ + if (info->str_repeat && j > info->str_repeat) { #ifdef REPEAT_VERBOSE - h5tools_str_append(str, "%c repeats %d times", quote, j - 1); + h5tools_str_append(str, "%c repeats %d times", quote, j - 1); #else - h5tools_str_append(str, "%c*%d", quote, j - 1); + h5tools_str_append(str, "%c*%d", quote, j - 1); #endif /* REPEAT_VERBOSE */ - quote = '\0'; - i += j - 1; - } + quote = '\0'; + i += j - 1; + } - } + } - if (quote) - h5tools_str_append(str, "%c", quote); + if (quote) h5tools_str_append(str, "%c", quote); - if (i == 0) - /*empty string*/ - h5tools_str_append(str, "\"\""); - } /* end else */ - } - else if (H5Tequal(type, H5T_NATIVE_INT)) { - HDmemcpy(&tempint, vp, sizeof(int)); - if(packed_bits_num) { - if(packed_data_offset >= 8*sizeof(int)) - tempint = 0; - else - tempint = (tempint >> packed_data_offset) & packed_data_mask; - } - h5tools_str_append(str, OPT(info->fmt_int, "%d"), tempint); - } - else if (H5Tequal(type, H5T_NATIVE_UINT)) { - HDmemcpy(&tempuint, vp, sizeof(unsigned int)); - if(packed_bits_num) { - if(packed_data_offset >= 8*sizeof(unsigned int)) - tempuint = 0; - else - tempuint = (tempuint >> packed_data_offset) & packed_data_mask; - } - h5tools_str_append(str, OPT(info->fmt_uint, "%u"), tempuint); - } - else if (H5Tequal(type, H5T_NATIVE_SCHAR)) { - signed char tempchar; - HDmemcpy(&tempchar, cp_vp, sizeof(char)); - if(packed_bits_num) { - if(packed_data_offset >= 8*sizeof(char)) - tempchar = 0; - else - tempchar = (tempchar >> packed_data_offset) & packed_data_mask; - } + if (i == 0) + /*empty string*/ + h5tools_str_append(str, "\"\""); + } /* end else */ + } + break; + case H5T_INTEGER: + if (H5Tequal(type, H5T_NATIVE_INT)) { + HDmemcpy(&tempint, vp, sizeof(int)); + if (packed_bits_num) { + if (packed_data_offset >= 8 * sizeof(int)) + tempint = 0; + else + tempint = (tempint >> packed_data_offset) & packed_data_mask; + } + h5tools_str_append(str, OPT(info->fmt_int, "%d"), tempint); + } + else if (H5Tequal(type, H5T_NATIVE_UINT)) { + HDmemcpy(&tempuint, vp, sizeof(unsigned int)); + if (packed_bits_num) { + if (packed_data_offset >= 8 * sizeof(unsigned int)) + tempuint = 0; + else + tempuint = (tempuint >> packed_data_offset) & packed_data_mask; + } + h5tools_str_append(str, OPT(info->fmt_uint, "%u"), tempuint); + } + else if (info->ascii && (H5Tequal(type, H5T_NATIVE_SCHAR) || H5Tequal(type, H5T_NATIVE_UCHAR))) { + h5tools_print_char(str, info, (char) (*ucp_vp)); + } + else if (H5Tequal(type, H5T_NATIVE_SCHAR)) { + signed char tempchar; + HDmemcpy(&tempchar, cp_vp, sizeof(char)); + if (packed_bits_num) { + if (packed_data_offset >= 8 * sizeof(char)) + tempchar = 0; + else + tempchar = (tempchar >> packed_data_offset) & packed_data_mask; + } #ifdef H5_VMS - h5tools_str_append(str, OPT(info->fmt_schar, "%hd"), tempchar); + h5tools_str_append(str, OPT(info->fmt_schar, "%hd"), tempchar); #else - h5tools_str_append(str, OPT(info->fmt_schar, "%hhd"), tempchar); + h5tools_str_append(str, OPT(info->fmt_schar, "%hhd"), tempchar); #endif - } - else if (H5Tequal(type, H5T_NATIVE_UCHAR)) { - unsigned char tempuchar; - HDmemcpy(&tempuchar, ucp_vp, sizeof(unsigned char)); - if(packed_bits_num) { - if(packed_data_offset >= 8*sizeof(unsigned char)) - tempuchar = 0; - else - tempuchar = (tempuchar >> packed_data_offset) & packed_data_mask; - } - h5tools_str_append(str, OPT(info->fmt_uchar, "%u"), tempuchar); - } - else if (H5Tequal(type, H5T_NATIVE_SHORT)) { - short tempshort; - - HDmemcpy(&tempshort, vp, sizeof(short)); - if(packed_bits_num) { - if(packed_data_offset >= 8*sizeof(short)) - tempshort = 0; - else - tempshort = (tempshort >> packed_data_offset) & packed_data_mask; - } - h5tools_str_append(str, OPT(info->fmt_short, "%d"), tempshort); - } - else if (H5Tequal(type, H5T_NATIVE_USHORT)) { - unsigned short tempushort; - - HDmemcpy(&tempushort, vp, sizeof(unsigned short)); - if(packed_bits_num) { - if(packed_data_offset >= 8*sizeof(unsigned short)) - tempushort = 0; - else - tempushort = (tempushort >> packed_data_offset) & packed_data_mask; - } - h5tools_str_append(str, OPT(info->fmt_ushort, "%u"), tempushort); - } - else if (H5Tequal(type, H5T_NATIVE_LONG)) { - HDmemcpy(&templong, vp, sizeof(long)); - if(packed_bits_num) { - if(packed_data_offset >= 8*sizeof(long)) - templong = 0; - else - templong = (templong >> packed_data_offset) & packed_data_mask; - } - h5tools_str_append(str, OPT(info->fmt_long, "%ld"), templong); - } - else if (H5Tequal(type, H5T_NATIVE_ULONG)) { - HDmemcpy(&tempulong, vp, sizeof(unsigned long)); - if(packed_bits_num) { - if(packed_data_offset >= 8*sizeof(unsigned long)) - tempulong = 0; - else - tempulong = (tempulong >> packed_data_offset) & packed_data_mask; - } - h5tools_str_append(str, OPT(info->fmt_ulong, "%lu"), tempulong); - } - else if (H5Tequal(type, H5T_NATIVE_LLONG)) { - HDmemcpy(&templlong, vp, sizeof(long long)); - if(packed_bits_num) { - if(packed_data_offset >= 8*sizeof(long long)) - templlong = 0; - else - templlong = (templlong >> packed_data_offset) & packed_data_mask; - } - h5tools_str_append(str, OPT(info->fmt_llong, fmt_llong), templlong); - } - else if (H5Tequal(type, H5T_NATIVE_ULLONG)) { - HDmemcpy(&tempullong, vp, sizeof(unsigned long long)); - if(packed_bits_num) { - if(packed_data_offset >= 8*sizeof(unsigned long long)) - tempullong = 0; - else - tempullong = (tempullong >> packed_data_offset) & packed_data_mask; - } - h5tools_str_append(str, OPT(info->fmt_ullong, fmt_ullong), tempullong); - } - else if (H5Tequal(type, H5T_NATIVE_HSSIZE)) { - if (sizeof(hssize_t) == sizeof(int)) { - HDmemcpy(&tempint, vp, sizeof(int)); - h5tools_str_append(str, OPT(info->fmt_int, "%d"), tempint); - } - else if (sizeof(hssize_t) == sizeof(long)) { - HDmemcpy(&templong, vp, sizeof(long)); - h5tools_str_append(str, OPT(info->fmt_long, "%ld"), templong); - } - else { - 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)) { - HDmemcpy(&tempuint, vp, sizeof(unsigned int)); - h5tools_str_append(str, OPT(info->fmt_uint, "%u"), tempuint); - } - else if (sizeof(hsize_t) == sizeof(long)) { - HDmemcpy(&tempulong, vp, sizeof(long)); - h5tools_str_append(str, OPT(info->fmt_ulong, "%lu"), tempulong); - } - else { - HDmemcpy(&tempullong, vp, sizeof(unsigned long long)); - h5tools_str_append(str, OPT(info->fmt_ullong, fmt_ullong), tempullong); - } - } - else if (H5Tget_class(type) == H5T_COMPOUND) { - unsigned j; - - nmembs = H5Tget_nmembers(type); - h5tools_str_append(str, "%s", OPT(info->cmpd_pre, "{")); + } + else if (H5Tequal(type, H5T_NATIVE_UCHAR)) { + unsigned char tempuchar; + HDmemcpy(&tempuchar, ucp_vp, sizeof(unsigned char)); + if (packed_bits_num) { + if (packed_data_offset >= 8 * sizeof(unsigned char)) + tempuchar = 0; + else + tempuchar = (tempuchar >> packed_data_offset) & packed_data_mask; + } + h5tools_str_append(str, OPT(info->fmt_uchar, "%u"), tempuchar); + } + else if (H5Tequal(type, H5T_NATIVE_SHORT)) { + short tempshort; + + HDmemcpy(&tempshort, vp, sizeof(short)); + if (packed_bits_num) { + if (packed_data_offset >= 8 * sizeof(short)) + tempshort = 0; + else + tempshort = (tempshort >> packed_data_offset) & packed_data_mask; + } + h5tools_str_append(str, OPT(info->fmt_short, "%d"), tempshort); + } + else if (H5Tequal(type, H5T_NATIVE_USHORT)) { + unsigned short tempushort; + + HDmemcpy(&tempushort, vp, sizeof(unsigned short)); + if (packed_bits_num) { + if (packed_data_offset >= 8 * sizeof(unsigned short)) + tempushort = 0; + else + tempushort = (tempushort >> packed_data_offset) & packed_data_mask; + } + h5tools_str_append(str, OPT(info->fmt_ushort, "%u"), tempushort); + } + else if (H5Tequal(type, H5T_NATIVE_LONG)) { + HDmemcpy(&templong, vp, sizeof(long)); + if (packed_bits_num) { + if (packed_data_offset >= 8 * sizeof(long)) + templong = 0; + else + templong = (templong >> packed_data_offset) & packed_data_mask; + } + h5tools_str_append(str, OPT(info->fmt_long, "%ld"), templong); + } + else if (H5Tequal(type, H5T_NATIVE_ULONG)) { + HDmemcpy(&tempulong, vp, sizeof(unsigned long)); + if (packed_bits_num) { + if (packed_data_offset >= 8 * sizeof(unsigned long)) + tempulong = 0; + else + tempulong = (tempulong >> packed_data_offset) & packed_data_mask; + } + h5tools_str_append(str, OPT(info->fmt_ulong, "%lu"), tempulong); + } + else if (H5Tequal(type, H5T_NATIVE_LLONG)) { + HDmemcpy(&templlong, vp, sizeof(long long)); + if (packed_bits_num) { + if (packed_data_offset >= 8 * sizeof(long long)) + templlong = 0; + else + templlong = (templlong >> packed_data_offset) & packed_data_mask; + } + h5tools_str_append(str, OPT(info->fmt_llong, fmt_llong), templlong); + } + else if (H5Tequal(type, H5T_NATIVE_ULLONG)) { + HDmemcpy(&tempullong, vp, sizeof(unsigned long long)); + if (packed_bits_num) { + if (packed_data_offset >= 8 * sizeof(unsigned long long)) + tempullong = 0; + else + tempullong = (tempullong >> packed_data_offset) & packed_data_mask; + } + h5tools_str_append(str, OPT(info->fmt_ullong, fmt_ullong), tempullong); + } + else if (H5Tequal(type, H5T_NATIVE_HSSIZE)) { + if (sizeof(hssize_t) == sizeof(int)) { + HDmemcpy(&tempint, vp, sizeof(int)); + h5tools_str_append(str, OPT(info->fmt_int, "%d"), tempint); + } + else if (sizeof(hssize_t) == sizeof(long)) { + HDmemcpy(&templong, vp, sizeof(long)); + h5tools_str_append(str, OPT(info->fmt_long, "%ld"), templong); + } + else { + 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)) { + HDmemcpy(&tempuint, vp, sizeof(unsigned int)); + h5tools_str_append(str, OPT(info->fmt_uint, "%u"), tempuint); + } + else if (sizeof(hsize_t) == sizeof(long)) { + HDmemcpy(&tempulong, vp, sizeof(long)); + h5tools_str_append(str, OPT(info->fmt_ulong, "%lu"), tempulong); + } + else { + HDmemcpy(&tempullong, vp, sizeof(unsigned long long)); + h5tools_str_append(str, OPT(info->fmt_ullong, fmt_ullong), tempullong); + } + } + break; + case H5T_COMPOUND: + { + unsigned j; - ctx->indent_level++; + nmembs = H5Tget_nmembers(type); + h5tools_str_append(str, "%s", OPT(info->cmpd_pre, "{")); - for (j = 0; j < nmembs; j++) { - if (j) - h5tools_str_append(str, "%s", OPT(info->cmpd_sep, ", "OPTIONAL_LINE_BREAK)); - else - h5tools_str_append(str, "%s", OPT(info->cmpd_end, "")); + ctx->indent_level++; - 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); - HDfree(name); + for (j = 0; j < nmembs; j++) { + if (j) + h5tools_str_append(str, "%s", OPT(info->cmpd_sep, ", "OPTIONAL_LINE_BREAK)); + else + h5tools_str_append(str, "%s", OPT(info->cmpd_end, "")); - /* The value */ - offset = H5Tget_member_offset(type, j); - memb = H5Tget_member_type(type, j); + if (info->arr_linebreak) h5tools_str_indent(str, info, ctx); - h5tools_str_sprint(str, info, container, memb, cp_vp + offset, ctx); + /* The name */ + name = H5Tget_member_name(type, j); + h5tools_str_append(str, OPT(info->cmpd_name, ""), name); + HDfree(name); - H5Tclose(memb); - } - ctx->indent_level--; + /* The value */ + offset = H5Tget_member_offset(type, j); + memb = H5Tget_member_type(type, j); + h5tools_str_sprint(str, info, container, memb, cp_vp + offset, ctx); - 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, "}")); + H5Tclose(memb); + } + ctx->indent_level--; - } - else if (H5Tget_class(type) == H5T_ENUM) { - char enum_name[1024]; + 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, "}")); - if (H5Tenum_nameof(type, vp, enum_name, sizeof enum_name) >= 0) { - h5tools_str_append(str, h5tools_escape(enum_name, sizeof(enum_name))); - } - else { - size_t i; - n = H5Tget_size(type); - if (1 == n) { - h5tools_str_append(str, "0x%02x", ucp_vp[0]); - } - else { - for (i = 0; i < n; i++) - h5tools_str_append(str, "%s%02x", i ? ":" : "", ucp_vp[i]); - } - } - } - else if (H5Tequal(type, H5T_STD_REF_DSETREG)) { - if (h5tools_str_is_zero(vp, H5Tget_size(type))) { - h5tools_str_append(str, "NULL"); - } - else { - h5tools_str_sprint_region(str, info, container, vp); - } - } - else if (H5Tequal(type, H5T_STD_REF_OBJ)) { - /* - * Object references -- show the type and OID of the referenced - * object. - */ - if (h5tools_str_is_zero(vp, H5Tget_size(type))) { - h5tools_str_append(str, "NULL"); - } - else { - H5O_info_t oi; - const char *path; - - obj = H5Rdereference(container, H5R_OBJECT, vp); - H5Oget_info(obj, &oi); - - /* Print object type and close object */ - switch (oi.type) { - case H5O_TYPE_GROUP: - h5tools_str_append(str, H5_TOOLS_GROUP); - break; - - case H5O_TYPE_DATASET: - h5tools_str_append(str, H5_TOOLS_DATASET); + } break; - - case H5O_TYPE_NAMED_DATATYPE: - h5tools_str_append(str, H5_TOOLS_DATATYPE); + case H5T_ENUM: + { + char enum_name[1024]; + + if (H5Tenum_nameof(type, vp, enum_name, sizeof enum_name) >= 0) { + h5tools_str_append(str, h5tools_escape(enum_name, sizeof(enum_name))); + } + else { + size_t i; + n = H5Tget_size(type); + if (1 == n) { + h5tools_str_append(str, "0x%02x", ucp_vp[0]); + } + else { + for (i = 0; i < n; i++) + h5tools_str_append(str, "%s%02x", i ? ":" : "", ucp_vp[i]); + } + } + } break; - - default: - h5tools_str_append(str, "%u-", (unsigned) oi.type); + case H5T_REFERENCE: + if (H5Tequal(type, H5T_STD_REF_DSETREG)) { + if (h5tools_str_is_zero(vp, H5Tget_size(type))) { + h5tools_str_append(str, "NULL"); + } + else { + h5tools_str_sprint_region(str, info, container, vp); + } + } + else if (H5Tequal(type, H5T_STD_REF_OBJ)) { + /* + * Object references -- show the type and OID of the referenced + * object. + */ + if (h5tools_str_is_zero(vp, H5Tget_size(type))) { + h5tools_str_append(str, "NULL"); + } + else { + H5O_info_t oi; + const char *path; + + obj = H5Rdereference(container, H5R_OBJECT, vp); + H5Oget_info(obj, &oi); + + /* Print object type and close object */ + switch (oi.type) { + case H5O_TYPE_GROUP: + h5tools_str_append(str, H5_TOOLS_GROUP); + break; + + case H5O_TYPE_DATASET: + h5tools_str_append(str, H5_TOOLS_DATASET); + break; + + case H5O_TYPE_NAMED_DATATYPE: + h5tools_str_append(str, H5_TOOLS_DATATYPE); + break; + + default: + h5tools_str_append(str, "%u-", (unsigned) oi.type); + break; + } /* end switch */ + H5Oclose(obj); + + /* Print OID */ + if (info->obj_hidefileno) + h5tools_str_append(str, info->obj_format, oi.addr); + else + h5tools_str_append(str, info->obj_format, oi.fileno, oi.addr); + + /* Print name */ + path = lookup_ref_path(*(haddr_t *) vp); + if (path) { + h5tools_str_append(str, " "); + h5tools_str_append(str, path); + h5tools_str_append(str, " "); + } /* end if */ + } /* end else */ + } break; - } /* end switch */ - H5Oclose(obj); - - /* Print OID */ - if (info->obj_hidefileno) - h5tools_str_append(str, info->obj_format, oi.addr); - else - h5tools_str_append(str, info->obj_format, oi.fileno, oi.addr); - - /* Print name */ - path = lookup_ref_path(*(haddr_t *) vp); - if (path) { - h5tools_str_append(str, " "); - h5tools_str_append(str, path); - h5tools_str_append(str, " "); - } /* end if */ - } /* end else */ - } - 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; - - /* 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); - 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]; - 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)); - - if (info->arr_linebreak && i && i % dims[ndims - 1] == 0) { - h5tools_str_append(str, "%s", "\n"); - h5tools_str_indent(str, info, ctx); - - } /* end if */ - else if (i && info->arr_sep) { - /* if next element begin, add next line with indent */ - if (is_next_arry_elmt) { - is_next_arry_elmt = 0; - - h5tools_str_append(str, "%s", "\n "); - h5tools_str_indent(str, info, ctx); - + case H5T_ARRAY: + { + int k, ndims; + hsize_t i, dims[H5S_MAX_RANK], temp_nelmts; + 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); + 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]; + 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)); + + if (info->arr_linebreak && i && i % dims[ndims - 1] == 0) { + h5tools_str_append(str, "%s", "\n"); + h5tools_str_indent(str, info, ctx); + + } /* end if */ + else if (i && info->arr_sep) { + /* if next element begin, add next line with indent */ + if (is_next_arry_elmt) { + is_next_arry_elmt = 0; + + h5tools_str_append(str, "%s", "\n "); + h5tools_str_indent(str, info, ctx); + + } + /* otherwise just add space */ + else + h5tools_str_append(str, " "); + + } /* end else if */ + + /* 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); + } /* 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 */ + H5Tclose(memb); } - /* otherwise just add space */ - else - h5tools_str_append(str, " "); - - } /* end else if */ - - /* 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); - } /* 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 */ - H5Tclose(memb); - } - else if (H5Tget_class(type) == H5T_VLEN) { - unsigned int i; + break; + case H5T_VLEN: + { + unsigned int i; - /* Get the VL sequences's base datatype for each element */ - memb = H5Tget_super(type); - size = H5Tget_size(memb); + /* Get the VL sequences's base datatype for each element */ + memb = H5Tget_super(type); + size = H5Tget_size(memb); - /* Print the opening bracket */ - h5tools_str_append(str, "%s", OPT(info->vlen_pre, "(")); + /* Print the opening bracket */ + h5tools_str_append(str, "%s", OPT(info->vlen_pre, "(")); - /* Get the number of sequence elements */ - nelmts = ((hvl_t *) cp_vp)->len; + /* Get the number of sequence elements */ + nelmts = ((hvl_t *) cp_vp)->len; - for (i = 0; i < nelmts; i++) { - if (i) - h5tools_str_append(str, "%s", OPT(info->vlen_sep, "," OPTIONAL_LINE_BREAK)); + for (i = 0; i < nelmts; i++) { + if (i) h5tools_str_append(str, "%s", OPT(info->vlen_sep, "," OPTIONAL_LINE_BREAK)); #ifdef LATER - /* Need to fix so VL data breaks at correct location on end of line -QAK */ - if (info->arr_linebreak && h5tools_str_len(str)>=info->line_ncols) { - int x; + /* Need to fix so VL data breaks at correct location on end of line -QAK */ + if (info->arr_linebreak && h5tools_str_len(str)>=info->line_ncols) { + int x; - h5tools_str_append(str, "%s", "\n"); + h5tools_str_append(str, "%s", "\n"); - /* need to indent some more here */ - if (ctx->indent_level >= 0) - h5tools_str_append(str, "%s", OPT(info->line_pre, "")); + /* need to indent some more here */ + if (ctx->indent_level >= 0) + 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 */ + for (x = 0; x < ctx->indent_level + 1; x++) + h5tools_str_append(str,"%s",OPT(info->line_indent,"")); + } /* end if */ #endif /* LATER */ - ctx->indent_level++; + ctx->indent_level++; - /* Dump the array element */ - h5tools_str_sprint(str, info, container, memb, - ((char *) (((hvl_t *) cp_vp)->p)) + i * size, ctx); + /* Dump the array element */ + h5tools_str_sprint(str, info, container, memb, ((char *) (((hvl_t *) cp_vp)->p)) + i * size, ctx); - ctx->indent_level--; - } /* end for */ + ctx->indent_level--; + } /* end for */ - h5tools_str_append(str, "%s", OPT(info->vlen_suf, ")")); - H5Tclose(memb); - } - else { - /* All other types get printed as hexadecimal */ - size_t i; - n = H5Tget_size(type); - if (1 == n) { - h5tools_str_append(str, "0x%02x", ucp_vp[0]); - } - else { - for (i = 0; i < n; i++) - h5tools_str_append(str, "%s%02x", i ? ":" : "", ucp_vp[i]); - } - } + h5tools_str_append(str, "%s", OPT(info->vlen_suf, ")")); + H5Tclose(memb); + } + break; + default: + { + /* All other types get printed as hexadecimal */ + size_t i; + n = H5Tget_size(type); + if (1 == n) { + h5tools_str_append(str, "0x%02x", ucp_vp[0]); + } + else { + for (i = 0; i < n; i++) + h5tools_str_append(str, "%s%02x", i ? ":" : "", ucp_vp[i]); + } + } + break; + } /* end switch */ + } return h5tools_str_fmt(str, start, OPT(info->elmt_fmt, "%s")); } diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c index 11ab5f3..79322bc 100644 --- a/tools/lib/h5tools_utils.c +++ b/tools/lib/h5tools_utils.c @@ -852,6 +852,8 @@ H5tools_get_symlink_info(hid_t file_id, const char * linkpath, h5tool_link_info_ /* set target obj type to return */ link_info->trg_type = trg_oinfo.type; + link_info->objno = trg_oinfo.addr; + link_info->fileno = trg_oinfo.fileno; } /* end if */ else link_info->trg_type = H5O_TYPE_UNKNOWN; diff --git a/tools/lib/h5tools_utils.h b/tools/lib/h5tools_utils.h index f30974a..10c643d 100644 --- a/tools/lib/h5tools_utils.h +++ b/tools/lib/h5tools_utils.h @@ -161,6 +161,8 @@ typedef struct { H5O_type_t trg_type; /* OUT: target type */ const char *trg_path; /* OUT: target obj path. This must be freed * when used with H5tools_get_symlink_info() */ + haddr_t objno; /* OUT: target object address */ + unsigned long fileno; /* OUT: File number that target object is located in */ H5L_info_t linfo; /* OUT: link info */ h5tool_opt_t opt; /* IN: options */ } h5tool_link_info_t; diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c index 0215c46..8455360 100644 --- a/tools/lib/h5trav.c +++ b/tools/lib/h5trav.c @@ -354,6 +354,31 @@ trav_info_add(trav_info_t *info, const char *path, h5trav_type_t obj_type) info->paths[idx].objno = HADDR_UNDEF; } /* end trav_info_add() */ + +/*------------------------------------------------------------------------- + * Function: trav_fileinfo_add + * + * Purpose: Add a file addr & fileno to info struct + * + * Return: void + * + *------------------------------------------------------------------------- + */ +void +trav_fileinfo_add(trav_info_t *info, hid_t loc_id) +{ + H5O_info_t oinfo; + size_t idx = info->nused - 1; + + if ( info->paths[idx].path && HDstrcmp(info->paths[idx].path, ".")) + H5Oget_info_by_name(loc_id, info->paths[idx].path, &oinfo, H5P_DEFAULT); + else + H5Oget_info(loc_id, &oinfo); + + info->paths[idx].objno = oinfo.addr; + info->paths[idx].fileno = oinfo.fileno; +} /* end trav_fileinfo_add() */ + /*------------------------------------------------------------------------- * Function: trav_info_visit_obj diff --git a/tools/lib/h5trav.h b/tools/lib/h5trav.h index c416cf8..3548c6b 100644 --- a/tools/lib/h5trav.h +++ b/tools/lib/h5trav.h @@ -177,6 +177,8 @@ H5TOOLS_DLL void trav_info_free(trav_info_t *info); H5TOOLS_DLL void trav_info_add(trav_info_t *info, const char *path, h5trav_type_t obj_type); +H5TOOLS_DLL void trav_fileinfo_add(trav_info_t *info, hid_t loc_id); + /*------------------------------------------------------------------------- * table private functions *------------------------------------------------------------------------- |