summaryrefslogtreecommitdiffstats
path: root/tools/src/h5ls/h5ls.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/src/h5ls/h5ls.c')
-rw-r--r--tools/src/h5ls/h5ls.c660
1 files changed, 539 insertions, 121 deletions
diff --git a/tools/src/h5ls/h5ls.c b/tools/src/h5ls/h5ls.c
index 5c9c693..6c21782 100644
--- a/tools/src/h5ls/h5ls.c
+++ b/tools/src/h5ls/h5ls.c
@@ -91,7 +91,7 @@ static h5tool_format_t ls_dataformat = {
"", /*line_suf */
"", /*line_sep */
1, /*line_multi_new */
- "", /*line_indent */
+ " ", /*line_indent */
0, /*skip_first */
@@ -132,7 +132,6 @@ static hbool_t no_dangling_link_g = FALSE; /* treat dangling link is error */
static hbool_t follow_elink_g = FALSE; /* follow external links */
static hbool_t grp_literal_g = FALSE; /* list group, not contents */
static hbool_t hexdump_g = FALSE; /* show data as raw hexadecimal */
-static hbool_t show_errors_g = FALSE; /* print HDF5 error messages */
static hbool_t simple_output_g = FALSE; /* make output more machine-readable */
static hbool_t show_file_name_g = FALSE; /* show file name for full names */
static hbool_t no_line_wrap_g = FALSE; /* show data content without line wrap */
@@ -193,7 +192,7 @@ usage (void)
PRINTVALSTREAM(rawoutstream, " --no-dangling-links\n");
PRINTVALSTREAM(rawoutstream, " Must be used with --follow-symlinks option;\n");
PRINTVALSTREAM(rawoutstream, " otherwise, h5ls shows error message and returns an exit\n");
- PRINTVALSTREAM(rawoutstream, " code of 1. \n");
+ PRINTVALSTREAM(rawoutstream, " code of 1.\n");
PRINTVALSTREAM(rawoutstream, " Check for any symbolic links (soft links or external links)\n");
PRINTVALSTREAM(rawoutstream, " that do not resolve to an existing object (dataset, group,\n");
PRINTVALSTREAM(rawoutstream, " or named datatype).\n");
@@ -228,11 +227,8 @@ usage (void)
PRINTVALSTREAM(rawoutstream, " \"%%05d\" to open a file family.\n");
PRINTVALSTREAM(rawoutstream, "\n");
PRINTVALSTREAM(rawoutstream, " Deprecated Options\n");
- PRINTVALSTREAM(rawoutstream, " The following options have been deprecated in HDF5. While they remain\n");
- PRINTVALSTREAM(rawoutstream, " available, they have been superseded as indicated and may be removed\n");
- PRINTVALSTREAM(rawoutstream, " from HDF5 in the future. Use the indicated replacement option in all\n");
- PRINTVALSTREAM(rawoutstream, " new work; where possible, existing scripts, et cetera, should also be\n");
- PRINTVALSTREAM(rawoutstream, " updated to use the replacement option.\n");
+ PRINTVALSTREAM(rawoutstream, " The following options have been removed in HDF5 1.12. Use the indicated\n");
+ PRINTVALSTREAM(rawoutstream, " replacement option in all work.\n");
PRINTVALSTREAM(rawoutstream, "\n");
PRINTVALSTREAM(rawoutstream, " -E or --external Follow external links.\n");
PRINTVALSTREAM(rawoutstream, " Replaced by --follow-symlinks.\n");
@@ -918,6 +914,7 @@ print_enum_type(h5tools_str_t *buffer, hid_t type, int ind)
H5free_memory(name[i]);
HDfree(name);
HDfree(value);
+ H5Tclose(super);
return FALSE;
}
@@ -1082,7 +1079,10 @@ print_reference_type(h5tools_str_t *buffer, hid_t type, int H5_ATTR_UNUSED ind)
if (H5T_REFERENCE != H5Tget_class(type))
return FALSE;
- if (H5Tequal(type, H5T_STD_REF_OBJ) == TRUE) {
+ if (H5Tequal(type, H5T_STD_REF) == TRUE) {
+ h5tools_str_append(buffer, "standard reference");
+ }
+ else if (H5Tequal(type, H5T_STD_REF_OBJ) == TRUE) {
h5tools_str_append(buffer, "object reference");
}
else if (H5Tequal(type, H5T_STD_REF_DSETREG) == TRUE) {
@@ -1285,6 +1285,233 @@ print_type(h5tools_str_t *buffer, hid_t type, int ind)
h5tools_str_append(buffer,"%lu-byte class-%u unknown", (unsigned long)H5Tget_size(type), (unsigned)data_class);
}
+/*
+ *
+ */
+static void
+dump_reference(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t container, H5R_ref_t *ref_buf, int ndims)
+{
+ H5TOOLS_ERR_INIT(int, SUCCEED)
+ hid_t new_obj_id = H5I_INVALID_HID;
+ hid_t new_obj_sid = H5I_INVALID_HID;
+ hsize_t elmt_counter = 0; /*counts the # elements printed. */
+ size_t ncols = 80; /* available output width */
+ size_t i;
+ hsize_t curr_pos = 0; /* total data element position */
+ h5tools_str_t buffer; /* string into which to render */
+ h5tools_context_t datactx; /* print context */
+
+ H5TOOLS_PUSH_STACK();
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "enter");
+
+ datactx = *ctx; /* print context */
+ /* Assume entire data space to be printed */
+ if (datactx.ndims > 0)
+ for (i = 0; i < (size_t)datactx.ndims; i++)
+ datactx.p_min_idx[i] = 0;
+ datactx.need_prefix = TRUE;
+
+ HDmemset(&buffer, 0, sizeof(h5tools_str_t));
+ for(i = 0; i < ndims; i++, datactx.cur_elmt++, elmt_counter++) {
+ H5O_type_t obj_type; /* Object type */
+ H5R_type_t ref_type; /* Reference type */
+
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "reference loop:%d with curr_pos=%ld", i, curr_pos);
+
+ datactx.need_prefix = TRUE;
+ h5tools_str_reset(&buffer);
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "reference loop - h5tools_str_sprint with H5T_STD_REF:%d", i);
+ h5tools_str_sprint(&buffer, info, container, H5T_STD_REF, &ref_buf[i], &datactx);
+ h5tools_render_element(stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)i, (hsize_t)ndims);
+
+ ref_type = H5Rget_type((const H5R_ref_t *)&ref_buf[i]);
+ switch (ref_type) {
+ case H5R_OBJECT1:
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "ref_type is H5R_OBJECT1");
+ if (H5Rget_obj_type3((const H5R_ref_t *)&ref_buf[i], H5P_DEFAULT, &obj_type) >= 0) {
+ switch (obj_type) {
+ case H5O_TYPE_DATASET:
+ if((new_obj_id = H5Ropen_object((const H5R_ref_t *)&ref_buf[i], H5P_DEFAULT, H5P_DEFAULT)) >= 0) {
+ datactx.indent_level++;
+ h5tools_dump_dset(stream, info, &datactx, new_obj_id);
+ datactx.indent_level--;
+ if(H5Dclose(new_obj_id) < 0)
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dclose H5R_OBJECT1:H5O_TYPE_DATASET failed");
+ if(H5Rdestroy(&ref_buf[i]) < 0)
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Rdestroy H5R_OBJECT1:H5O_TYPE_DATASET failed");
+ }
+ else
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Ropen_object H5R_OBJECT1:H5O_TYPE_DATASET failed");
+ break;
+
+ case H5O_TYPE_GROUP:
+ case H5O_TYPE_NAMED_DATATYPE:
+ case H5O_TYPE_MAP:
+ case H5O_TYPE_UNKNOWN:
+ case H5O_TYPE_NTYPES:
+ default:
+ break;
+ } /* end switch */
+ }
+ else
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Rget_obj_type3 H5R_OBJECT1 failed");
+ break;
+ case H5R_DATASET_REGION1:
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "ref_type is H5R_DATASET_REGION1");
+ if((new_obj_id = H5Ropen_object((const H5R_ref_t *)&ref_buf[i], H5P_DEFAULT, H5P_DEFAULT)) >= 0) {
+ datactx.indent_level++;
+ h5tools_dump_dset(stream, info, &datactx, new_obj_id);
+ datactx.indent_level--;
+ if(H5Dclose(new_obj_id) < 0)
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dclose H5R_DATASET_REGION1 failed");
+ if(H5Rdestroy(&ref_buf[i]) < 0)
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Rdestroy H5R_DATASET_REGION1 failed");
+ }
+ else
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Ropen_object H5R_DATASET_REGION1 failed");
+ break;
+ case H5R_OBJECT2:
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "ref_type is H5R_OBJECT2");
+ if (H5Rget_obj_type3((const H5R_ref_t *)&ref_buf[i], H5P_DEFAULT, &obj_type) >= 0) {
+ switch (obj_type) {
+ case H5O_TYPE_GROUP:
+ break;
+
+ case H5O_TYPE_DATASET:
+ if((new_obj_id = H5Ropen_object((const H5R_ref_t *)&ref_buf[i], H5P_DEFAULT, H5P_DEFAULT)) >= 0) {
+ datactx.indent_level++;
+ h5tools_dump_dset(stream, info, &datactx, new_obj_id);
+ datactx.indent_level--;
+ if(H5Oclose(new_obj_id) < 0)
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Oclose H5R_OBJECT2 failed");
+ if(H5Rdestroy(&ref_buf[i]) < 0)
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Rdestroy H5R_OBJECT2 failed");
+ }
+ else
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Ropen_object H5R_OBJECT2 failed");
+ break;
+
+ case H5O_TYPE_NAMED_DATATYPE:
+ break;
+
+ case H5O_TYPE_MAP:
+ case H5O_TYPE_UNKNOWN:
+ case H5O_TYPE_NTYPES:
+ default:
+ break;
+ } /* end switch */
+ }
+ else
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Rget_obj_type3 H5R_OBJECT2 failed");
+ break;
+ case H5R_DATASET_REGION2:
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "ref_type is H5R_DATASET_REGION2");
+
+ if (info->line_ncols > 0)
+ ncols = info->line_ncols;
+
+ /* if (new_obj_id < 0) - could mean that no reference was written do not throw failure */
+ if((new_obj_id = H5Ropen_object((const H5R_ref_t *)&ref_buf[i], H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ H5Epush2(H5tools_ERR_STACK_g, __FILE__, FUNC, __LINE__, H5tools_ERR_CLS_g, H5E_tools_g, H5E_tools_min_id_g,
+ "H5Ropen_object H5R_DATASET_REGION2 failed");
+ else {
+ if((new_obj_sid = H5Ropen_region((const H5R_ref_t *)&ref_buf[i], H5P_DEFAULT, H5P_DEFAULT)) >= 0) {
+ if (h5tools_is_zero(&ref_buf[i], H5Tget_size(H5T_STD_REF))) {
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "NULL H5R_DATASET_REGION2");
+
+ h5tools_str_reset(&buffer);
+ h5tools_str_append(&buffer, " {");
+ h5tools_render_element(stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
+
+ datactx.need_prefix = TRUE;
+ datactx.indent_level++;
+ h5tools_str_reset(&buffer);
+ h5tools_str_append(&buffer, "NULL");
+ h5tools_render_element(stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
+ datactx.indent_level--;
+ datactx.need_prefix = TRUE;
+
+ h5tools_str_reset(&buffer);
+ h5tools_str_append(&buffer, "}");
+ h5tools_render_element(stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
+ }
+ else {
+ H5S_sel_type region_type;
+
+ region_type = H5Sget_select_type(new_obj_sid);
+ if(region_type == H5S_SEL_POINTS) {
+ /* Print point information */
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5S_SEL_POINTS H5R_DATASET_REGION2");
+ h5tools_dump_region_data_points(new_obj_sid, new_obj_id, stream, info, &datactx,
+ &buffer, &curr_pos, ncols, i, elmt_counter);
+ }
+ else if(region_type == H5S_SEL_HYPERSLABS) {
+ /* Print block information */
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5S_SEL_HYPERSLABS H5R_DATASET_REGION2");
+ h5tools_dump_region_data_blocks(new_obj_sid, new_obj_id, stream, info, &datactx,
+ &buffer, &curr_pos, ncols, i, elmt_counter);
+ }
+ else
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "invalid region type");
+ } /* end else to if (h5tools_is_zero(... */
+ if(H5Sclose(new_obj_sid) < 0)
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose H5R_DATASET_REGION2 failed");
+ }
+ else
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Ropen_region H5R_DATASET_REGION2 failed");
+ if(H5Dclose(new_obj_id) < 0)
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Dclose H5R_DATASET_REGION2 failed");
+ if(H5Rdestroy(&ref_buf[i]) < 0)
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Rdestroy H5R_DATASET_REGION2 failed");
+ }
+ break;
+ case H5R_ATTR:
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "ref_type is H5R_ATTR");
+ if((new_obj_id = H5Ropen_attr((const H5R_ref_t *)&ref_buf[i], H5P_DEFAULT, H5P_DEFAULT)) >= 0) {
+ h5tools_dump_region_attribute(new_obj_id, stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
+ if(H5Aclose(new_obj_id) < 0)
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Aclose H5R_ATTR failed");
+ if(H5Rdestroy(&ref_buf[i]) < 0)
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Rdestroy H5R_ATTR failed");
+ }
+ else {
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "NULL H5R_ATTR");
+
+ h5tools_str_reset(&buffer);
+ h5tools_str_append(&buffer, " {");
+ h5tools_render_element(stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
+
+ datactx.need_prefix = TRUE;
+ datactx.indent_level++;
+ h5tools_str_reset(&buffer);
+ h5tools_str_append(&buffer, "NULL");
+ h5tools_render_element(stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
+ datactx.indent_level--;
+ datactx.need_prefix = TRUE;
+
+ h5tools_str_reset(&buffer);
+ h5tools_str_append(&buffer, "}");
+ h5tools_render_element(stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
+
+ H5TOOLS_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Ropen_attr H5R_ATTR failed");
+ }
+ break;
+ case H5R_BADTYPE:
+ case H5R_MAXTYPE:
+ default:
+ break;
+ } /* end switch */
+
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "finished reference loop:%d",i);
+ } /* end for(i = 0; i < ndims; i++, ctx->cur_elmt++, elmt_counter++) */
+done:
+ h5tools_str_close(&buffer);
+
+ PRINTVALSTREAM(stream, "\n");
+
+ H5TOOLS_ENDDEBUG(H5E_tools_min_dbg_id_g, "exit");
+ H5TOOLS_POP_STACK();
+}
/*-------------------------------------------------------------------------
* Function: dump_dataset_values
@@ -1297,6 +1524,12 @@ print_type(h5tools_str_t *buffer, hid_t type, int ind)
static void
dump_dataset_values(hid_t dset)
{
+ H5TOOLS_ERR_INIT(herr_t, SUCCEED)
+ hid_t f_type = H5I_INVALID_HID;
+ hid_t space = H5I_INVALID_HID;
+ hsize_t total_size[H5S_MAX_RANK];
+ int ndims;
+ size_t i;
char string_prefix[64];
static char fmt_double[16];
static char fmt_float[16];
@@ -1305,15 +1538,20 @@ dump_dataset_values(hid_t dset)
h5tools_context_t ctx; /* print context */
h5tool_format_t outputformat;
h5tool_format_t *info = &ls_dataformat;
+ H5R_ref_t *ref_buf = NULL;
- hid_t f_type = H5Dget_type(dset);
- size_t size = H5Tget_size(f_type);
+ H5TOOLS_PUSH_STACK();
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "enter");
+
+ f_type = H5Dget_type(dset);
+ space = H5Dget_space(dset);
HDmemset(&ctx, 0, sizeof(ctx));
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
outputformat = *info;
outputformat.line_1st = NULL;
+ outputformat.idx_fmt = "";
if (simple_output_g) {
outputformat.idx_fmt = "";
outputformat.line_per_line = 1;
@@ -1345,9 +1583,10 @@ dump_dataset_values(hid_t dset)
else {
outputformat.line_ncols = (unsigned)width_g;
}
- if (label_g) outputformat.cmpd_name = "%s=";
+ if (label_g)
+ outputformat.cmpd_name = "%s=";
outputformat.line_pre = " %s ";
- outputformat.line_cont = " %s ";
+ outputformat.line_cont = " %s ";
outputformat.str_repeat = 8;
outputformat.arr_pre = NULL;
@@ -1375,7 +1614,7 @@ dump_dataset_values(hid_t dset)
* command line switch was given. */
outputformat.raw = TRUE;
}
- else if (string_g && 1 == size && H5T_INTEGER == H5Tget_class(f_type)) {
+ else if (string_g && H5Tget_size(f_type) == 1 && (H5Tget_class(f_type) == H5T_INTEGER)) {
/* Print 1-byte integer data as an ASCI character string instead of
* integers if the `-s' or `--string' command-line option was given. */
outputformat.ascii = TRUE;
@@ -1387,29 +1626,244 @@ dump_dataset_values(hid_t dset)
}
info = &outputformat;
- ctx.indent_level = 2;
+ ctx.indent_level = 1;
ctx.cur_column = (size_t)curr_pos;
/* Print all the values. */
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, " Data:\n");
+
h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0);
+
ctx.need_prefix = TRUE;
ctx.cur_column = (size_t)curr_pos;
- if (h5tools_dump_dset(rawoutstream, info, &ctx, dset, NULL) < 0) {
- h5tools_str_reset(&buffer);
- h5tools_str_append(&buffer, " Unable to print data.");
- h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0);
+ if (H5Tget_class(f_type) == H5T_REFERENCE) {
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "reference class type");
+ if (!H5Tequal(f_type, H5T_STD_REF) && !H5Tequal(f_type, H5T_STD_REF_DSETREG) && !H5Tequal(f_type, H5T_STD_REF_OBJ)) {
+ HGOTO_DONE(SUCCEED);
+ }
+
+ ndims = (int)H5Sget_simple_extent_npoints(space);
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "ndims=%d - ctx.ndims=%d", ndims, ctx.ndims);
+
+ /* 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(space, total_size, NULL);
+ if (ctx.ndims > 0)
+ init_acc_pos(&ctx, total_size);
+ ctx.need_prefix = TRUE;
+
+ if (NULL != (ref_buf = (H5R_ref_t *)HDcalloc(MAX(sizeof(unsigned), sizeof(H5R_ref_t)), ndims))) {
+ H5TOOLS_DEBUG(H5E_tools_min_id_g, "H5Dread reference read");
+ if(H5Dread(dset, H5T_STD_REF, H5S_ALL, H5S_ALL, H5P_DEFAULT, ref_buf) < 0) {
+ HDfree(ref_buf);
+ H5TOOLS_GOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread reference failed");
+ }
+ dump_reference(rawoutstream, info, &ctx, dset, ref_buf, ndims);
+ HDfree(ref_buf);
+ }
}
-
+ else {
+ if (h5tools_dump_dset(rawoutstream, info, &ctx, dset) < 0) {
+ h5tools_str_reset(&buffer);
+ h5tools_str_append(&buffer, " Unable to print data.");
+ h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0);
+ }
+ }
+done:
+ H5Sclose(space);
H5Tclose(f_type);
h5tools_str_close(&buffer);
PRINTVALSTREAM(rawoutstream, "\n");
+
+ H5TOOLS_ENDDEBUG(H5E_tools_min_dbg_id_g, "exit");
+ H5TOOLS_POP_STACK();
}
/*-------------------------------------------------------------------------
+ * Function: dump_attribute_values
+ *
+ * Purpose: Prints all values of a attribute.
+ *
+ * Return: void
+ *-------------------------------------------------------------------------
+ */
+static void
+dump_attribute_values(hid_t attr, const char *attr_name)
+{
+ H5TOOLS_ERR_INIT(herr_t, SUCCEED)
+ hid_t f_type = H5I_INVALID_HID;
+ hid_t space = H5I_INVALID_HID;
+ hsize_t total_size[H5S_MAX_RANK];
+ int ndims;
+ size_t i;
+ char string_prefix[64];
+ static char fmt_double[16];
+ static char fmt_float[16];
+ hsize_t curr_pos = 0; /* total data element position */
+ h5tools_str_t buffer; /* string into which to render */
+ h5tools_context_t ctx; /* print context */
+ h5tool_format_t outputformat;
+ h5tool_format_t *info = &ls_dataformat;
+ H5R_ref_t *ref_buf = NULL;
+
+ H5TOOLS_PUSH_STACK();
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "enter");
+
+ f_type = H5Aget_type(attr);
+ space = H5Aget_space(attr);
+
+ HDmemset(&ctx, 0, sizeof(ctx));
+ HDmemset(&buffer, 0, sizeof(h5tools_str_t));
+
+ outputformat = *info;
+ outputformat.line_1st = NULL;
+ outputformat.idx_fmt = "";
+ if (simple_output_g) {
+ outputformat.idx_fmt = "";
+ outputformat.line_per_line = 1;
+ outputformat.line_multi_new = 0;
+ outputformat.line_pre = " ";
+ outputformat.line_cont = " ";
+
+ outputformat.arr_pre = "";
+ outputformat.arr_suf = "";
+ outputformat.arr_sep = " ";
+
+ if (!label_g) {
+ outputformat.cmpd_pre = "";
+ outputformat.cmpd_suf = "";
+ }
+ outputformat.cmpd_sep = " ";
+
+ if (label_g)
+ outputformat.cmpd_name = "%s=";
+
+ outputformat.elmt_suf1 = " ";
+ outputformat.str_locale = ESCAPE_HTML;
+
+ }
+ else {
+ if (no_line_wrap_g) {
+ outputformat.line_per_line = 1;
+ }
+ else {
+ outputformat.line_ncols = (unsigned)width_g;
+ }
+ if (label_g)
+ outputformat.cmpd_name = "%s=";
+ outputformat.line_pre = " %s ";
+ outputformat.line_cont = " %s ";
+ outputformat.str_repeat = 8;
+
+ outputformat.arr_pre = NULL;
+ outputformat.arr_suf = NULL;
+ outputformat.arr_sep = NULL;
+
+ outputformat.cmpd_pre = NULL;
+ outputformat.cmpd_suf = NULL;
+ outputformat.cmpd_sep = NULL;
+
+ outputformat.vlen_sep = NULL;
+ outputformat.vlen_pre = NULL;
+ outputformat.vlen_suf = NULL;
+ outputformat.vlen_end = NULL;
+ }
+ outputformat.arr_linebreak = 0;
+ /* Floating point types should display full precision */
+ HDsnprintf(fmt_float, sizeof(fmt_float), "%%1.%dg", FLT_DIG);
+ outputformat.fmt_float = fmt_float;
+ HDsnprintf(fmt_double, sizeof(fmt_double), "%%1.%dg", DBL_DIG);
+ outputformat.fmt_double = fmt_double;
+
+ if (hexdump_g) {
+ /* Print all data in hexadecimal format if the `-x' or `--hexdump'
+ * command line switch was given. */
+ outputformat.raw = TRUE;
+ }
+ else if (string_g && H5Tget_size(f_type) == 1 && (H5Tget_class(f_type) == H5T_INTEGER)) {
+ /* Print 1-byte integer data as an ASCI character string instead of
+ * integers if the `-s' or `--string' command-line option was given. */
+ outputformat.ascii = TRUE;
+ outputformat.elmt_suf1 = "";
+ outputformat.elmt_suf2 = "";
+ HDsnprintf(string_prefix, sizeof(string_prefix), "%s\"", outputformat.line_pre);
+ outputformat.line_pre = string_prefix;
+ outputformat.line_suf = "\"";
+ }
+ info = &outputformat;
+
+ ctx.indent_level = 2;
+ ctx.cur_column = (size_t)curr_pos;
+
+ /* Print all the values. */
+ h5tools_str_reset(&buffer);
+ h5tools_str_append(&buffer, " Data:\n");
+
+ h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0);
+
+ ctx.need_prefix = TRUE;
+ ctx.cur_column = (size_t)curr_pos;
+ if (H5Tget_class(f_type) == H5T_REFERENCE) {
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "reference class type");
+ if (!H5Tequal(f_type, H5T_STD_REF) && !H5Tequal(f_type, H5T_STD_REF_DSETREG) && !H5Tequal(f_type, H5T_STD_REF_OBJ)) {
+ HGOTO_DONE(SUCCEED);
+ }
+
+ ndims = (int)H5Sget_simple_extent_npoints(space);
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "ndims=%d - ctx.ndims=%d", ndims, ctx.ndims);
+
+ /* 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(space, total_size, NULL);
+ if (ctx.ndims > 0)
+ init_acc_pos(&ctx, total_size);
+ ctx.need_prefix = TRUE;
+
+ if (NULL != (ref_buf = (H5R_ref_t *)HDcalloc(MAX(sizeof(unsigned), sizeof(H5R_ref_t)), ndims))) {
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "H5Aread reference read");
+ if(H5Aread(attr, H5T_STD_REF, ref_buf) < 0) {
+ HDfree(ref_buf);
+ H5TOOLS_GOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread reference failed");
+ }
+ ctx.indent_level++;
+ dump_reference(rawoutstream, info, &ctx, attr, ref_buf, ndims);
+ ctx.indent_level--;
+ HDfree(ref_buf);
+ }
+ }
+ else {
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "Attribute data read");
+ ctx.indent_level++;
+ if (h5tools_dump_mem(rawoutstream, info, &ctx, attr) < 0) {
+ h5tools_str_reset(&buffer);
+ h5tools_str_append(&buffer, " Unable to print data.");
+ h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0);
+ }
+ ctx.indent_level--;
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "Attribute data read complete");
+ }
+done:
+ H5Sclose(space);
+ H5Tclose(f_type);
+
+ h5tools_str_close(&buffer);
+
+ PRINTVALSTREAM(rawoutstream, "\n");
+
+ H5TOOLS_ENDDEBUG(H5E_tools_min_dbg_id_g, "exit");
+ H5TOOLS_POP_STACK();
+}
+
+/*-------------------------------------------------------------------------
* Function: list_attr
*
* Purpose: Prints information about attributes.
@@ -1422,39 +1876,43 @@ static herr_t
list_attr(hid_t obj, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED *ainfo,
void H5_ATTR_UNUSED *op_data)
{
+ H5TOOLS_ERR_INIT(herr_t, SUCCEED)
hid_t attr = H5I_INVALID_HID;
hid_t space = H5I_INVALID_HID;
hid_t type = H5I_INVALID_HID;
- hid_t p_type = H5I_INVALID_HID;
hsize_t size[H5S_MAX_RANK];
hsize_t nelmts = 1;
- hsize_t temp_need;
- size_t need;
int ndims;
int i;
- void *buf;
H5S_class_t space_type;
hsize_t curr_pos = 0; /* total data element position */
h5tools_str_t buffer; /* string into which to render */
h5tools_context_t ctx; /* print context */
h5tool_format_t *info = &ls_dataformat;
- h5tool_format_t outputformat;
+
+ H5TOOLS_PUSH_STACK();
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "enter");
HDmemset(&ctx, 0, sizeof(ctx));
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
+ ctx.indent_level = 2;
+ ctx.cur_column = (size_t)curr_pos;
+
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, " Attribute: ");
print_string(&buffer, attr_name, TRUE);
- if ((attr = H5Aopen(obj, attr_name, H5P_DEFAULT))) {
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "Attribute name:%s", attr_name);
+ if ((attr = H5Aopen(obj, attr_name, H5P_DEFAULT)) >= 0) {
space = H5Aget_space(attr);
type = H5Aget_type(attr);
/* Data space */
ndims = H5Sget_simple_extent_dims(space, size, NULL);
space_type = H5Sget_simple_extent_type(space);
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "Attribute ndims:%d", ndims);
switch(space_type) {
case H5S_SCALAR:
/* scalar dataspace */
@@ -1489,100 +1947,26 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED *ain
/* Data type */
h5tools_str_reset(&buffer);
- h5tools_str_append(&buffer, " Type: ");
+ h5tools_str_append(&buffer, " %-10s ", "Type:");
print_type(&buffer, type, 15);
h5tools_str_append(&buffer, "\n");
h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0);
- /* Data */
- outputformat = *info;
-
- if (nelmts < 5) {
- outputformat.idx_fmt = "";
- outputformat.line_1st = " Data: ";
- outputformat.line_pre = " ";
- outputformat.line_cont = " ";
- outputformat.str_repeat = 8;
-
- }
- else {
- h5tools_str_reset(&buffer);
- h5tools_str_append(&buffer, " Data:\n");
- h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0);
- outputformat.line_1st = NULL;
- outputformat.line_pre = " %s ";
- outputformat.line_cont = " %s ";
- outputformat.str_repeat = 8;
- }
-
- outputformat.line_ncols = (unsigned)width_g;
- if (label_g)
- outputformat.cmpd_name = "%s=";
- if (string_g && 1 == H5Tget_size(type) && H5T_INTEGER == H5Tget_class(type)) {
- outputformat.ascii = TRUE;
- outputformat.elmt_suf1 = "";
- outputformat.elmt_suf2 = "";
- outputformat.line_pre = " %s \"";
- outputformat.line_suf = "\"";
- } /* end if */
-
-
- outputformat.arr_pre = NULL;
- outputformat.arr_suf = NULL;
- outputformat.arr_sep = NULL;
-
- outputformat.cmpd_pre = NULL;
- outputformat.cmpd_suf = NULL;
- outputformat.cmpd_sep = NULL;
-
- outputformat.vlen_sep = NULL;
- outputformat.vlen_pre = NULL;
- outputformat.vlen_suf = NULL;
- outputformat.vlen_end = NULL;
-
- info = &outputformat;
-
- if (space_type != H5S_NULL && space_type != H5S_NO_CLASS) {
- if (hexdump_g)
- p_type = H5Tcopy(type);
- else
- p_type = H5Tget_native_type(type, H5T_DIR_DEFAULT);
-
- if (p_type >= 0) {
- /* VL data special information */
- unsigned int vl_data = 0; /* contains VL datatypes */
-
- /* Check if we have VL data in the dataset's datatype */
- if (h5tools_detect_vlen(p_type) == TRUE)
- vl_data = TRUE;
-
- temp_need = nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type));
- need = (size_t)temp_need;
- if((buf = HDmalloc(need)) != NULL) {
- if(H5Aread(attr, p_type, buf) >= 0) {
- ctx.need_prefix = TRUE;
- ctx.indent_level = 2;
- ctx.cur_column = (size_t)curr_pos;
- h5tools_dump_mem(rawoutstream, info, &ctx, attr, p_type, space, buf);
- }
-
- /* Reclaim any VL memory, if necessary */
- if (vl_data)
- H5Treclaim(p_type, space, H5P_DEFAULT, buf);
-
- HDfree(buf);
- }
- H5Tclose(p_type);
- } /* end if */
- }
-
H5Sclose(space);
H5Tclose(type);
+
+ h5tools_str_close(&buffer);
+
+ if (data_g)
+ dump_attribute_values(attr, attr_name);
H5Aclose(attr);
}
- h5tools_str_close(&buffer);
-
- PRINTVALSTREAM(rawoutstream, "\n");
+ else {
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "Attribute open failed");
+ h5tools_str_close(&buffer);
+ }
+ H5TOOLS_ENDDEBUG(H5E_tools_min_dbg_id_g, "exit");
+ H5TOOLS_POP_STACK();
return 0;
}
@@ -1796,7 +2180,10 @@ dataset_list2(hid_t dset, const char H5_ATTR_UNUSED *name)
break;
case H5T_REFERENCE:
- if (H5Tequal(type, H5T_STD_REF_DSETREG)) {
+ if (H5Tequal(dset, H5T_STD_REF)) {
+ h5tools_str_append(&buffer, "reference information not available");
+ }
+ else if (H5Tequal(dset, H5T_STD_REF_DSETREG)) {
h5tools_str_append(&buffer, "information not available");
}
break;
@@ -1835,8 +2222,10 @@ dataset_list2(hid_t dset, const char H5_ATTR_UNUSED *name)
h5tools_str_append(&buffer, "}\n");
} /* end for */
} /* end if */
+ h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0);
/* Print data type */
+ h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, " %-10s ", "Type:");
print_type(&buffer, type, 15);
h5tools_str_append(&buffer, "\n");
@@ -1908,6 +2297,7 @@ datatype_list2(hid_t type, const char H5_ATTR_UNUSED *name)
static herr_t
list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void *_iter)
{
+ H5TOOLS_ERR_INIT(herr_t, SUCCEED)
H5O_type_t obj_type = oinfo->type; /* Type of the object */
iter_t *iter = (iter_t*)_iter;
hsize_t curr_pos = 0; /* total data element position */
@@ -1915,11 +2305,15 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void
h5tools_context_t ctx; /* print context */
h5tool_format_t *info = &ls_dataformat;
+ H5TOOLS_PUSH_STACK();
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "enter");
+
HDmemset(&ctx, 0, sizeof(ctx));
HDmemset(&buffer, 0, sizeof(h5tools_str_t));
h5tools_str_reset(&buffer);
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "Object name:%s", name);
/* Print the link's name, either full name or base name */
if (!iter->symlink_target)
print_obj_name(&buffer, iter, name, "");
@@ -1951,6 +2345,7 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void
/* Open the object. Not all objects can be opened. If this is the case
* then return right away.
*/
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "Open object name=%s", name);
if (obj_type >= 0 && (obj = H5Oopen(iter->fid, name, H5P_DEFAULT)) < 0) {
h5tools_str_reset(&buffer);
h5tools_str_append(&buffer, " *ERROR*\n");
@@ -1959,6 +2354,7 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void
} /* end if */
/* List the first line of information for the object. */
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "Object type:%d", obj_type);
if (obj_type >= 0 && dispatch_g[obj_type].list1)
(dispatch_g[obj_type].list1)(obj);
if (!iter->symlink_target || (verbose_g > 0)) {
@@ -1975,6 +2371,7 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void
ssize_t cmt_bufsize = -1;
/* Display attributes */
+ H5TOOLS_DEBUG(H5E_tools_min_dbg_id_g, "Display attributes");
if (obj_type >= 0)
H5Aiterate2(obj, H5_INDEX_NAME, H5_ITER_INC, NULL, list_attr, NULL);
@@ -2042,6 +2439,9 @@ done:
}
h5tools_str_close(&buffer);
+ H5TOOLS_ENDDEBUG(H5E_tools_min_dbg_id_g, "exit");
+ H5TOOLS_POP_STACK();
+
return 0;
} /* end list_obj() */
@@ -2445,6 +2845,10 @@ main(int argc, const char *argv[])
const char *preferred_driver = NULL;
int err_exit = 0;
hid_t fapl_id = H5P_DEFAULT;
+ H5E_auto2_t func;
+ H5E_auto2_t tools_func;
+ void *edata;
+ void *tools_edata;
#ifdef H5_HAVE_ROS3_VFD
/* default "anonymous" s3 configuration */
@@ -2472,9 +2876,17 @@ main(int argc, const char *argv[])
h5tools_setprogname(PROGRAMNAME);
h5tools_setstatus(EXIT_SUCCESS);
+ /* Disable error reporting */
+ H5Eget_auto2(H5E_DEFAULT, &func, &edata);
+ H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
+
/* Initialize h5tools lib */
h5tools_init();
+ /* Disable tools error reporting */
+ H5Eget_auto2(H5tools_ERR_STACK_g, &tools_func, &tools_edata);
+ H5Eset_auto2(H5tools_ERR_STACK_g, NULL, NULL);
+
/* Build object display table */
DISPATCH(H5O_TYPE_GROUP, "Group", NULL, NULL);
DISPATCH(H5O_TYPE_DATASET, "Dataset", dataset_list1, dataset_list2);
@@ -2501,11 +2913,11 @@ main(int argc, const char *argv[])
data_g = TRUE;
}
else if (!HDstrcmp(argv[argno], "--enable-error-stack")) {
- show_errors_g = TRUE;
+ enable_error_stack = 1;
/* deprecated --errors */
}
else if (!HDstrcmp(argv[argno], "--errors")) {
- show_errors_g = TRUE;
+ enable_error_stack = 1;
}
else if (!HDstrcmp(argv[argno], "--follow-symlinks")) {
follow_symlink_g = TRUE;
@@ -2754,7 +3166,7 @@ main(int argc, const char *argv[])
/* deprecated -e */
case 'e': /* --errors */
- show_errors_g = TRUE;
+ enable_error_stack = 1;
break;
case 'E': /* --external */
@@ -2862,10 +3274,10 @@ main(int argc, const char *argv[])
}
} /* preferred_driver defined */
- /* Turn off HDF5's automatic error printing unless you're debugging h5ls */
- if(!show_errors_g)
- H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
-
+ if (enable_error_stack > 0) {
+ H5Eset_auto2(H5E_DEFAULT, func, edata);
+ H5Eset_auto2(H5tools_ERR_STACK_g, tools_func, tools_edata);
+ }
/* Each remaining argument is an hdf5 file followed by an optional slash
* and object name.
@@ -2929,6 +3341,7 @@ main(int argc, const char *argv[])
x = oname;
if (NULL == (oname = HDstrdup(oname))) {
HDfprintf(rawerrorstream, "memory allocation failed\n");
+ H5Eset_auto2(H5E_DEFAULT, func, edata);
leave(EXIT_FAILURE);
}
*x = '\0';
@@ -2973,6 +3386,7 @@ main(int argc, const char *argv[])
h5tools_str_reset(&buffer);
print_obj_name(&buffer, &iter, oname, "**NOT FOUND**");
h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0);
+ H5Eset_auto2(H5E_DEFAULT, func, edata);
leave(EXIT_FAILURE);
} /* end if */
} /* end if */
@@ -2981,8 +3395,10 @@ main(int argc, const char *argv[])
/* Open the object and display it's information */
if (li.type == H5L_TYPE_HARD) {
- if (visit_obj(file, oname, &iter) < 0)
+ if (visit_obj(file, oname, &iter) < 0) {
+ H5Eset_auto2(H5E_DEFAULT, func, edata);
leave(EXIT_FAILURE);
+ }
} /* end if(li.type == H5L_TYPE_HARD) */
else {
/* Specified name is not for object -- list that link */
@@ -3011,10 +3427,12 @@ main(int argc, const char *argv[])
if (fapl_id != H5P_DEFAULT) {
if (0 < H5Pclose(fapl_id)) {
HDfprintf(rawerrorstream, "Error: Unable to set close fapl entry\n\n");
+ H5Eset_auto2(H5E_DEFAULT, func, edata);
leave(EXIT_FAILURE);
}
}
+ H5Eset_auto2(H5E_DEFAULT, func, edata);
if (err_exit)
leave(EXIT_FAILURE);
else