summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlbert Cheng <acheng@hdfgroup.org>2000-05-11 17:17:14 (GMT)
committerAlbert Cheng <acheng@hdfgroup.org>2000-05-11 17:17:14 (GMT)
commit18ed617aa9685952cc654ee00edeadc1567fb7f9 (patch)
tree8d3ab2444ef3e5c067353029ca9247c6dfc6d2f3
parent89c69c103620a4e77cce7f0c5aa8e5ab3807cf28 (diff)
downloadhdf5-18ed617aa9685952cc654ee00edeadc1567fb7f9.zip
hdf5-18ed617aa9685952cc654ee00edeadc1567fb7f9.tar.gz
hdf5-18ed617aa9685952cc654ee00edeadc1567fb7f9.tar.bz2
[svn-r2239] Folded all the changes done in version 1.3 into this 1.2 branch
so that all the added features and bug fixes are included in the release branch. (Patrick did most of the work.)
-rw-r--r--tools/Makefile.in2
-rw-r--r--tools/h5dump.c973
-rw-r--r--tools/h5dump.h4
-rw-r--r--tools/h5dumptst.c215
-rw-r--r--tools/h5dumputil.c4
-rw-r--r--tools/h5ls.c173
-rw-r--r--tools/h5toh4.c95
-rw-r--r--tools/h5toh4.h2
-rw-r--r--tools/h5tools.c1625
-rw-r--r--tools/h5tools.h161
-rwxr-xr-xtools/testh5dump.sh3
11 files changed, 1654 insertions, 1603 deletions
diff --git a/tools/Makefile.in b/tools/Makefile.in
index 6dab9e9..7b55744 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -27,7 +27,7 @@ LIBHDF5=../src/libhdf5.la
PROGS=h5debug h5import h5ls h5repart h5dump h5dumptst @H5TOH4@
# Source and object files for the library; do not install
-LIB_SRC=h5tools.c h5findshd.c
+LIB_SRC=h5tools.c
LIB_OBJ=$(LIB_SRC:.c=.lo)
PUB_LIB=
diff --git a/tools/h5dump.c b/tools/h5dump.c
index 34ff725..efbbf11 100644
--- a/tools/h5dump.c
+++ b/tools/h5dump.c
@@ -3,36 +3,195 @@
#include "H5private.h"
#include "h5tools.h"
+static int display_oid = 0;
static int display_data = 1;
-static int status = 0;
+static int d_status = 0;
static int unamedtype = 0; /* shared data type with no name */
-typedef struct shared_obj_t{
-unsigned long objno[2];
-char objname[1024];
-int displayed;
-int recorded;
-} shared_obj_t;
-
-typedef struct table_t{
-int size;
-int nobjs;
-shared_obj_t *objs;
-} table_t;
-
static int prefix_len = 1024;
static char *prefix;
-static table_t group_table, dset_table, type_table;
+static table_t *group_table = NULL, *dset_table = NULL, *type_table = NULL;
+static const dump_header *dump_header_format;
+
static void dump_group (hid_t , const char* );
static void dump_dataset (hid_t, const char*);
static void dump_data (hid_t, int);
static void dump_named_datatype (hid_t , const char *);
-static int search_obj (table_t, unsigned long *);
+
void indentation(int);
static void print_enum(hid_t type);
extern int print_data(hid_t, hid_t, int);
+static void dump_oid(hid_t oid);
+
+
+static h5dump_t dataformat = {
+
+ 0,/*raw*/
+
+ "", /*fmt_raw*/
+ "%d", /*fmt_int*/
+ "%u", /*fmt_uint*/
+ "%d", /*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*/
+ "{\n",/*cmpd_pre*/
+ "}",/*cmpd_suf*/
+ "\n",/*cmpd_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*/
+ " %lu:%lu", /*obj_format*/
+
+ 1, /*dset_hidefileno*/
+ "DATASET %lu:%lu ",/*dset_format*/
+ "%s",/*dset_blockformat_pre*/
+ "%s",/*dset_ptformat_pre*/
+ "%s",/*dset_ptformat*/
+
+
+};
+static const dump_header standardformat = {
+ "standardformat", /*name*/
+ "HDF5", /*fileebgin*/
+ "", /*fileend*/
+ BOOT_BLOCK, /*bootblockbegin*/
+ "", /*bootblockend*/
+ GROUPNAME, /*groupbegin*/
+ "", /*groupend*/
+ DATASET, /*datasetbegin*/
+ "", /*datasetend*/
+ ATTRIBUTE, /*attributebegin*/
+ "", /*attributeend*/
+ DATATYPE, /*datatypebegin*/
+ "", /*datatypeend*/
+ DATASPACE, /*dataspacebegin*/
+ "", /*dataspaceend*/
+ DATA, /*databegin*/
+ "", /*dataend*/
+ SOFTLINK, /*softlinkbegin*/
+ "", /*softlinkend*/
+
+
+ "{", /*fileblockbegin*/
+ "}", /*fileblockend*/
+ "{", /*bootblockblockbegin*/
+ "}", /*bootblockblockend*/
+ "{", /*groupblockbegin*/
+ "}", /*groupblockend*/
+ "{", /*datasetblockbegin*/
+ "}", /*datasetblockend*/
+ "{", /*attributeblockbegin*/
+ "}", /*attributeblockend*/
+ "{", /*datatypeblockbegin*/
+ "}", /*datatypeblockend*/
+ "{", /*dataspaceblockbegin*/
+ "}", /*dataspaceblockend*/
+ "{", /*datablockbegin*/
+ "}", /*datablockend*/
+ "{", /*softlinkblockbegin*/
+ "}", /*softlinkblockend*/
+ "{", /*strblockbegin*/
+ "}", /*strblockend*/
+ "{", /*enumblockbegin*/
+ "}", /*enumblockend*/
+
+ "{", /*dataspacedescriptionbegin*/
+ "}", /*dataspacedescriptionend*/
+ "(", /*dataspacedimbegin*/
+ ")", /*dataspacedimend*/
+};
+
+static const dump_header xmlformat = {
+ "xml", /*name*/
+ "<FILE>", /*filebegin*/
+ "</FILE>", /*fileend*/
+ "<BOOTBLOCK>", /*bootblockbegin*/
+ "</BOOTBLOCK>", /*bootblockend*/
+ "<GROUP>", /*groupbegin*/
+ "</GROUP>", /*groupend*/
+ "<DATASET>", /*datasetbegin*/
+ "</DATASET>", /*datasetend*/
+ "<ATTRIBUTE>", /*attributebegin*/
+ "</ATTRIBUTE>", /*attributeend*/
+ "<DATATYPE>", /*datatypeend*/
+ "</DATATYPE>", /*datatypeend*/
+ "<DATASPACE>", /*dataspacebegin*/
+ "</DATASPACE>", /*dataspaceend*/
+ "<DATA>", /*databegin*/
+ "</DATA>", /*dataend*/
+ "<SOFTLINK>", /*softlinkbegin*/
+ "</SOFTLINK>", /*softlinkend*/
+
+ "", /*fileblockbegin*/
+ "", /*fileblockend*/
+ "", /*bootblockblockbegin*/
+ "", /*bootblockblockend*/
+ "", /*groupblockbegin*/
+ "", /*groupblockend*/
+ "", /*datasetblockbegin*/
+ "", /*datasetblockend*/
+ "", /*attributeblockbegin*/
+ "", /*attributeblockend*/
+ "", /*datatypeblockbegin*/
+ "", /*datatypeblockend*/
+ "", /*dataspaceblockbegin*/
+ "", /*dataspaceblockend*/
+ "", /*datablockbegin*/
+ "", /*datablockend*/
+ "", /*softlinkblockbegin*/
+ "", /*softlinkblockend*/
+ "", /*strblockbegin*/
+ "", /*strblockend*/
+ "", /*enumblockbegin*/
+ "", /*enumblockend*/
+
+ "", /*dataspacedescriptionbegin*/
+ "", /*dataspacedescriptionend*/
+ "(", /*dataspacedimbegin*/
+ ")", /*dataspacedimend*/
+
+};
/*-------------------------------------------------------------------------
* Function: usage
@@ -52,18 +211,22 @@ usage(void)
fprintf(stderr,
"\nUsage of HDF5 Dumper:\n\n \
h5dump [-h] [-bb] [-header] [-a <names>] [-d <names>] [-g <names>]\n \
- [-l <names>] [-t <names>] <file>\n\n\
+ [-l <names>] [-t <names>] [-w <number>] <file>\n\n\
-h Print information on this command and exit.\n\
-bb Display the conent of the boot block. The default is not to display.\n\
-header Display header only; no data is displayed.\n\
+ -v Display the object ids\n\
-V Display version information and exit.\n\
+ -xml Display the output in XML format.\n\
-a <names> Display the specified attribute(s).\n\
-d <names> Display the specified dataset(s).\n\
-g <names> Display the specified group(s) and all the members.\n\
-l <names> Displays the value(s) of the specified soft link(s).\n\
-t <names> Display the specified named data type(s).\n\
+ -w <number> Display the information with the specified maximum number of columns.\n\
\n\
- <names> is one or more appropriate object names.\n\n");
+ <names> is one or more appropriate object names.\n\
+ <number> is an integer greater than 1.\n\n");
}
@@ -151,7 +314,7 @@ H5G_stat_t statbuf;
printf( "H5T_NATIVE_ULLONG");
else {
printf( "undefined integer");
- status = 1;
+ d_status = 1;
}
break;
@@ -172,7 +335,7 @@ H5G_stat_t statbuf;
printf( "H5T_NATIVE_LDOUBLE");
else {
printf( "undefined float");
- status = 1;
+ d_status = 1;
}
break;
@@ -187,7 +350,7 @@ H5G_stat_t statbuf;
cset = H5Tget_cset(type);
indentation (indent+COL);
- printf("%s %s %d;\n", BEGIN, STRSIZE, size);
+ printf("%s %s %d;\n", dump_header_format->strblockbegin, STRSIZE, (int)size);
indentation (indent+COL);
printf(" %s ", STRPAD);
@@ -234,12 +397,12 @@ H5G_stat_t statbuf;
printf( "H5T_FORTRAN_S1;\n");
else {
printf("unknown_one_character_type;\n ");
- status = 1;
+ d_status = 1;
}
H5Tclose(str_type);
}
indentation (indent+COL);
- printf("%s", END);
+ printf("%s", dump_header_format->strblockend);
break;
@@ -263,12 +426,17 @@ H5G_stat_t statbuf;
printf( "H5T_STD_B64LE");
else {
printf( "undefined bitfield");
- status = 1;
+ d_status = 1;
}
break;
case H5T_OPAQUE:
- printf( "H5T_OPAQUE: not yet implemented");
+ printf( "\n");
+ indentation (indent+COL);
+ printf("H5T_OPAQUE\n");
+ indentation (indent+COL);
+ printf("OPAQUE_TAG \"%s\"\n", H5Tget_tag(type));
+ indentation (indent);
break;
case H5T_COMPOUND:
@@ -280,14 +448,14 @@ H5G_stat_t statbuf;
indentation (indent+COL);
if (i >= 0) {
- if (!type_table.objs[i].recorded) /* unamed data type */
- printf("\"/#%lu:%lu\"\n", type_table.objs[i].objno[0],
- type_table.objs[i].objno[1]);
+ if (!type_table->objs[i].recorded)
+ printf("\"/#%lu:%lu\"\n", type_table->objs[i].objno[0],
+ type_table->objs[i].objno[1]);
else
- printf("\"%s\"\n", type_table.objs[i].objname);
+ printf("\"%s\"\n", type_table->objs[i].objname);
} else {
printf("h5dump error: unknown committed type.\n");
- status = 1;
+ d_status = 1;
}
} else {
@@ -295,23 +463,29 @@ H5G_stat_t statbuf;
nmembers = H5Tget_nmembers(type);
for (i = 0; i < nmembers; i++) {
-
fname = H5Tget_member_name(type, i);
mtype = H5Tget_member_type(type, i);
ndims = H5Tget_member_dims(type, i, dims, perm);
- if (H5Tget_class(mtype) != H5T_STRING)
+ if (H5Tget_class(mtype) != H5T_STRING)/* && (H5Tget_class(mtype) != H5T_COMPOUND))*/
indentation (indent+COL);
-
+ if (H5Tget_class(mtype) == H5T_COMPOUND) {
+ indent += COL;
+ printf("{\n");
+ }
print_datatype(mtype);
-
+ if (H5Tget_class(mtype) == H5T_COMPOUND) {
+ indent -= COL;
+ indentation (indent+COL);
+ printf("}");
+ }
printf (" \"%s\"", fname);
if (ndims != 1 || dims[0] != 1) {
for (j = 0; j < ndims; j++)
- printf("[%d]",dims[j]);
+ printf("[%d]",(int)dims[j]);
}
printf (";\n");
@@ -326,19 +500,19 @@ H5G_stat_t statbuf;
break;
case H5T_ENUM:
printf("H5T_ENUM\n");
- indentation(indent + 3);
- printf("{ ");
+ indentation(indent + COL);
+ printf("%s ", dump_header_format->enumblockbegin);
super = H5Tget_super(type);
print_datatype(super);
printf(";");
print_enum(type);
printf("\n");
- indentation (indent + 3);
- printf("}\n");
+ indentation (indent + COL);
+ printf("%s", dump_header_format->enumblockend);
break;
default:
printf( "unknown data type");
- status = 1;
+ d_status = 1;
break;
}
@@ -384,20 +558,21 @@ dump_datatype (hid_t type) {
indent += COL;
indentation (indent);
if (H5Tget_class(type) == H5T_COMPOUND) {
- printf ("%s %s\n", DATATYPE, BEGIN);
+ printf ("%s %s\n", dump_header_format->datatypebegin , dump_header_format->datatypeblockbegin);
print_datatype(type);
indentation (indent);
- printf ("%s\n", END);
+ printf ("%s %s\n", dump_header_format->datatypeblockend, dump_header_format->datatypeend);
+
} else if (H5Tget_class(type) == H5T_STRING) {
- printf ("%s %s\n", DATATYPE, BEGIN);
+ printf ("%s %s\n", dump_header_format->datatypebegin, dump_header_format->datatypeblockbegin);
print_datatype(type);
printf("\n");
indentation (indent);
- printf ("%s\n", END);
+ printf ("%s %s\n", dump_header_format->datatypeblockend, dump_header_format->datatypeend);
} else {
- printf ("%s %s ", DATATYPE, BEGIN);
+ printf ("%s %s ", dump_header_format->datatypebegin, dump_header_format->datatypeblockbegin);
print_datatype(type);
- printf (" %s\n", END);
+ printf (" %s %s\n", dump_header_format->datatypeblockend, dump_header_format->datatypeend);
}
indent -= COL;
}
@@ -426,22 +601,23 @@ dump_dataspace (hid_t space)
indentation (indent+COL);
- printf("%s ", DATASPACE);
+ printf("%s ", dump_header_format->dataspacebegin);
if (H5Sis_simple(space)) {
if (ndims == 0) /* scalar dataspace */
- HDfprintf (stdout, "%s %s %s\n", BEGIN, SCALAR, END);
+ HDfprintf (stdout, "%s %s ", dump_header_format->dataspacedescriptionbegin, SCALAR);
else { /* simple dataspace */
- HDfprintf (stdout, "%s %s ( %Hu",BEGIN, SIMPLE, size[0]);
+ HDfprintf (stdout, "%s %s %s %Hu",dump_header_format->dataspacedescriptionbegin, SIMPLE,
+ dump_header_format->dataspacedimbegin,size[0]);
for (i = 1; i < ndims; i++)
HDfprintf (stdout, ", %Hu", size[i]);
- printf(" ) / ");
+ printf(" %s / ",dump_header_format->dataspacedimend);
if (maxsize[0]==H5S_UNLIMITED)
- HDfprintf (stdout, "( %s", "H5S_UNLIMITED");
+ HDfprintf (stdout, "%s %s", dump_header_format->dataspacedimbegin,"H5S_UNLIMITED");
else
- HDfprintf (stdout, "( %Hu", maxsize[0]);
+ HDfprintf (stdout, "%s %Hu", dump_header_format->dataspacedimbegin,maxsize[0]);
for (i = 1; i < ndims; i++)
if (maxsize[i]==H5S_UNLIMITED)
@@ -449,12 +625,14 @@ dump_dataspace (hid_t space)
else
HDfprintf (stdout, ", %Hu", maxsize[i]);
- printf(" ) %s\n", END);
+ printf(" %s ", dump_header_format->dataspacedimend);
}
} else
printf("%s not yet implemented %s\n", BEGIN, END);
+ end_obj(dump_header_format->dataspaceend, dump_header_format->dataspaceblockend);
+
}
@@ -478,7 +656,7 @@ dump_attr (hid_t attr, const char *attr_name, void UNUSED *op_data)
hid_t attr_id, type, space;
indentation(indent);
- begin_obj (ATTRIBUTE, attr_name);
+ begin_obj (dump_header_format->attributebegin, attr_name, dump_header_format->attributeblockbegin);
if ((attr_id = H5Aopen_name (attr, attr_name))>= 0) {
@@ -486,19 +664,22 @@ hid_t attr_id, type, space;
space = H5Aget_space(attr_id);
dump_datatype(type);
dump_dataspace(space);
+ if (display_oid){
+ dump_oid(attr_id);
+ }
if (display_data) dump_data(attr_id, ATTRIBUTE_DATA);
H5Tclose(type);
H5Sclose(space);
H5Aclose (attr_id);
indentation (indent);
- end_obj();
+ end_obj(dump_header_format->attributeend,dump_header_format->attributeblockend );
} else {
indentation (indent+COL);
printf("h5dump error: unable to open attribute.\n");
indentation (indent);
- end_obj();
- status = 1;
+ end_obj(dump_header_format->attributeend,dump_header_format->attributeblockend);
+ d_status = 1;
return FAIL;
}
@@ -529,7 +710,7 @@ char *obj_name, *attr_name;
hid_t oid, attr_id, type, space;
H5G_stat_t statbuf;
- j = strlen(name)-1;
+ j = (int)strlen(name)-1;
obj_name = malloc ((j+2)* sizeof(char));
/* find the last / */
@@ -543,7 +724,7 @@ H5G_stat_t statbuf;
}
attr_name = name+j+1;
- begin_obj (ATTRIBUTE, name);
+ begin_obj (dump_header_format->attributebegin, name, dump_header_format->attributeblockbegin);
H5Gget_objinfo(loc_id, obj_name, FALSE , &statbuf);
switch (statbuf.type) {
@@ -551,8 +732,8 @@ H5G_stat_t statbuf;
if ((oid = H5Gopen (loc_id, obj_name))<0) {
indentation (COL);
fprintf (stdout, "h5dump error: unable to open %s\n", obj_name);
- end_obj();
- status = 1;
+ end_obj(dump_header_format->attributeend, dump_header_format->attributeblockend);
+ d_status = 1;
return FAIL;
}
break;
@@ -560,8 +741,8 @@ H5G_stat_t statbuf;
if ((oid = H5Dopen (loc_id, obj_name))<0) {
indentation (COL);
fprintf (stdout, "h5dump error: unable to open %s\n", obj_name);
- end_obj();
- status = 1;
+ end_obj(dump_header_format->attributeend, dump_header_format->attributeblockend);
+ d_status = 1;
return FAIL;
}
break;
@@ -569,16 +750,16 @@ H5G_stat_t statbuf;
if ((oid = H5Topen(loc_id, obj_name)) < 0 ) {
indentation (COL);
fprintf (stdout, "h5dump error: unable to open %s\n", obj_name);
- end_obj();
- status = 1;
+ end_obj(dump_header_format->attributeend, dump_header_format->attributeblockend);
+ d_status = 1;
return FAIL;
}
break;
default:
indentation (COL);
fprintf (stdout, "h5dump error: unable to open %s\n", obj_name);
- end_obj();
- status = 1;
+ end_obj(dump_header_format->attributeend, dump_header_format->attributeblockend);
+ d_status = 1;
return FAIL;
}
@@ -588,42 +769,45 @@ H5G_stat_t statbuf;
space = H5Aget_space(attr_id);
dump_datatype(type);
dump_dataspace(space);
+ if (display_oid){
+ dump_oid(attr_id);
+ }
if (display_data) dump_data(attr_id, ATTRIBUTE_DATA);
H5Tclose(type);
H5Sclose(space);
- H5Aclose (attr_id);
- end_obj();
+ H5Aclose (attr_id);
+ end_obj(dump_header_format->attributeend, dump_header_format->attributeblockend);
} else {
indentation (COL);
printf("h5dump error: unable to open attribute.\n");
- end_obj();
- status = 1;
+ end_obj(dump_header_format->attributeend, dump_header_format->attributeblockend);
+ d_status = 1;
}
switch (statbuf.type) {
case H5G_GROUP:
if (H5Gclose (oid) < 0) {
- status = 1;
+ d_status = 1;
return FAIL;
}
break;
case H5G_DATASET:
if (H5Dclose (oid) < 0 ) {
- status = 1;
+ d_status = 1;
return FAIL;
}
break;
case H5G_TYPE:
if (H5Tclose(oid) < 0 ) {
- status = 1;
+ d_status = 1;
return FAIL;
}
break;
default:
- status = 1;
+ d_status = 1;
return FAIL;
}
@@ -666,17 +850,17 @@ int i;
buf = malloc (statbuf.linklen*sizeof(char));
- begin_obj(SOFTLINK, name);
+ begin_obj(dump_header_format->softlinkbegin, name, dump_header_format->softlinkblockbegin);
indentation (indent+COL);
if (H5Gget_linkval (group, name, statbuf.linklen, buf)>=0)
printf ("LINKTARGET \"%s\"\n", buf);
else {
printf ("h5dump error: unable to get link value.\n");
- status = 1;
+ d_status = 1;
}
indentation (indent);
- end_obj();
+ end_obj(dump_header_format->softlinkend, dump_header_format->softlinkblockend);
free (buf);
break;
@@ -688,7 +872,7 @@ int i;
H5Gclose (obj);
} else {
printf ("h5dump error: unable to dump group %s\n",name);
- status = 1;
+ d_status = 1;
}
break;
@@ -703,50 +887,50 @@ int i;
i = search_obj (dset_table, statbuf.objno);
if (i < 0) {
indentation (indent);
- begin_obj(DATASET, name);
+ begin_obj(dump_header_format->datasetbegin, name, dump_header_format->datasetblockbegin);
indentation (indent+COL);
printf("h5dump error: internal error\n");
indentation (indent);
- end_obj();
- status = 1;
+ end_obj(dump_header_format->datasetend, dump_header_format->datasetblockend);
+ d_status = 1;
goto done;
- } else if (dset_table.objs[i].displayed) {
+ } else if (dset_table->objs[i].displayed) {
indentation (indent);
- begin_obj(DATASET, name);
+ begin_obj(dump_header_format->datasetbegin, name, dump_header_format->datasetblockbegin);
indentation (indent+COL);
- printf("%s \"%s\"\n", HARDLINK, dset_table.objs[i].objname);
+ printf("%s \"%s\"\n", HARDLINK, dset_table->objs[i].objname);
indentation (indent);
- end_obj();
+ end_obj(dump_header_format->datasetend, dump_header_format->datasetblockend);
goto done;
} else {
- dset_table.objs[i].displayed = 1;
+ dset_table->objs[i].displayed = 1;
strcat(tmp,"/");
strcat(tmp,name);
- strcpy(dset_table.objs[i].objname, tmp);
+ strcpy(dset_table->objs[i].objname, tmp);
}
}
dump_dataset (obj, name);
H5Dclose (obj);
} else {
printf ("h5dump error: unable to dump dataset %s\n",name);
- status = 1;
+ d_status = 1;
}
break;
case H5G_TYPE:
- if ((obj=H5Topen (group, name)) >= 0) {
- dump_named_datatype (obj, name);
- H5Tclose(obj);
- } else {
- printf ("h5dump error: unable to dump data type %s\n",name);
- status = 1;
- }
- break;
+ if ((obj=H5Topen (group, name)) >= 0) {
+ dump_named_datatype (obj, name);
+ H5Tclose(obj);
+ } else {
+ printf ("h5dump error: unable to dump data type %s\n",name);
+ d_status = 1;
+ }
+ break;
default:
printf ("h5dump error: unknown object %s\n", name);
- status = 1;
+ d_status = 1;
return FAIL;
}
@@ -772,16 +956,15 @@ done:
*-----------------------------------------------------------------------*/
static void
dump_named_datatype (hid_t type, const char *name) {
-
int nmembers = 1, x,j;
hid_t comptype;
char *compname;
int ndims, perm[H5DUMP_MAX_RANK];
- size_t dims[H5DUMP_MAX_RANK];
+size_t dims[H5DUMP_MAX_RANK];
indentation (indent);
- begin_obj(DATATYPE, name);
+ begin_obj(dump_header_format->datatypebegin, name, dump_header_format->datatypeblockbegin);
if (H5Tget_class(type) == H5T_COMPOUND){
nmembers = H5Tget_nmembers(type);
@@ -803,13 +986,11 @@ dump_named_datatype (hid_t type, const char *name) {
indentation (indent+COL);
print_datatype(type);
printf(";\n");
- }
-
+ }
indentation (indent);
- end_obj();
+ end_obj(dump_header_format->datatypeend, dump_header_format->datatypeblockend);
}
-
/*-------------------------------------------------------------------------
* Function: dump_group
*
@@ -834,16 +1015,18 @@ int i;
indentation (indent);
- begin_obj(GROUPNAME, name);
+ begin_obj(dump_header_format->groupbegin, name, dump_header_format->groupblockbegin);
indent += COL;
-
+ if (display_oid) {
+ dump_oid(gid);
+ }
if (!strcmp(name,"/") && unamedtype) { /* dump unamed type in root group */
- for (i = 0; i < type_table.nobjs; i++)
- if (!type_table.objs[i].recorded) {
- dset = H5Dopen (gid, type_table.objs[i].objname);
+ for (i = 0; i < type_table->nobjs; i++)
+ if (!type_table->objs[i].recorded) {
+ dset = H5Dopen (gid, type_table->objs[i].objname);
type = H5Dget_type (dset);
- sprintf(typename,"#%lu:%lu", type_table.objs[i].objno[0],
- type_table.objs[i].objno[1]);
+ sprintf(typename,"#%lu:%lu", type_table->objs[i].objno[0],
+ type_table->objs[i].objno[1]);
dump_named_datatype (type, typename);
H5Tclose(type);
H5Dclose(dset);
@@ -858,17 +1041,17 @@ int i;
indentation (indent);
printf("h5dump error: internal error\n");
- status = 1;
+ d_status = 1;
- } else if (group_table.objs[i].displayed) {
+ } else if (group_table->objs[i].displayed) {
indentation (indent);
- printf("%s \"%s\"\n",HARDLINK, group_table.objs[i].objname);
+ printf("%s \"%s\"\n",HARDLINK, group_table->objs[i].objname);
} else {
- strcpy(group_table.objs[i].objname, prefix);
- group_table.objs[i].displayed = 1;
+ strcpy(group_table->objs[i].objname, prefix);
+ group_table->objs[i].displayed = 1;
H5Aiterate (gid, NULL, dump_attr, NULL);
H5Giterate (gid, ".", NULL, dump_all, NULL);
@@ -883,7 +1066,7 @@ int i;
indent -= COL;
indentation (indent);
- end_obj();
+ end_obj(dump_header_format->groupend, dump_header_format->groupblockend);
free(tmp);
@@ -907,12 +1090,15 @@ dump_dataset (hid_t did, const char *name) {
hid_t type, space;
indentation (indent);
- begin_obj(DATASET, name);
+ begin_obj(dump_header_format->datasetbegin, name, dump_header_format->datasetblockbegin);
type = H5Dget_type (did);
space = H5Dget_space (did);
dump_datatype(type);
dump_dataspace(space);
+ if (display_oid){
+ dump_oid(did);
+ }
if (display_data)
switch (H5Tget_class(type)) {
@@ -938,10 +1124,10 @@ hid_t type, space;
printf("DATA{ not yet implemented.}\n");
break;
case H5T_OPAQUE:
- indent += COL;
+ /* indent += COL;
indentation (indent);
- indent -= COL;
- printf("DATA{ not yet implemented.}\n");
+ indent -= COL;*/
+ dump_data(did, DATASET_DATA);
break;
case H5T_COMPOUND:
dump_data(did, DATASET_DATA);
@@ -964,122 +1150,13 @@ hid_t type, space;
H5Sclose(space);
indentation (indent);
- end_obj();
+ end_obj(dump_header_format->datasetend, dump_header_format->datasetblockend);
}
-/*-------------------------------------------------------------------------
- * Function: init_table
- *
- * Purpose: allocate and initialize tables for shared groups, datasets,
- * and committed types
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-static void
-init_table (void){
-int i;
-
- group_table.size = dset_table.size = type_table.size = 20;
- group_table.nobjs = dset_table.nobjs = type_table.nobjs = 0;
-
- group_table.objs = (shared_obj_t*) malloc(group_table.size*sizeof(shared_obj_t));
- dset_table.objs = (shared_obj_t*) malloc(dset_table.size*sizeof(shared_obj_t));
- type_table.objs = (shared_obj_t*) malloc(type_table.size*sizeof(shared_obj_t));
-
- for (i = 0; i < group_table.size; i++) {
- group_table.objs[i].objno[0] = group_table.objs[i].objno[1] = 0;
- group_table.objs[i].displayed = 0;
- group_table.objs[i].recorded = 0;
- }
-
- for (i = 0; i < dset_table.size; i++) {
- dset_table.objs[i].objno[0] = dset_table.objs[i].objno[1] = 0;
- dset_table.objs[i].displayed = 0;
- dset_table.objs[i].recorded = 0;
- }
-
- for (i = 0; i < type_table.size; i++) {
- type_table.objs[i].objno[0] = type_table.objs[i].objno[1] = 0;
- type_table.objs[i].displayed = 0;
- type_table.objs[i].recorded = 0;
- }
-
- prefix = (char *) malloc(prefix_len * sizeof (char));
- *prefix = '\0';
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: search_obj
- *
- * Purpose: search the object specified by objno in the table
- *
- * Return: an integer, the location of the object
- * -1 if object is not found
- *
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-static int
-search_obj (table_t table, unsigned long *objno) {
-int i=0, found=0;
-
- while (i < table.nobjs && !found)
- if (table.objs[i].objno[0] == *(objno) &&
- table.objs[i].objno[1] == *(objno+1) ) found = 1;
- else i++;
-
- if (!found) return -1;
- else return i;
-
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: add_obj
- *
- * Purpose: add a shared object to the table
- * realloc the table if necessary
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-static void
-add_obj (table_t *table, unsigned long *objno, char *objname) {
-int i;
-
- if (table->nobjs == table->size) {
- table->size *= 2;
- table->objs = realloc (table->objs, table->size*sizeof(shared_obj_t));
- for (i = table->nobjs; i < table->size; i++) {
- table->objs[i].objno[0] = table->objs[i].objno[1] = 0;
- table->objs[i].displayed = 0;
- table->objs[i].recorded = 0;
- }
- }
-
- i = table->nobjs++;
- table->objs[i].objno[0] = *objno;
- table->objs[i].objno[1] = *(objno+1);
- strcpy (table->objs[i].objname, objname);
-
-}
-
+#if H5DUMP_DEBUG
/*-------------------------------------------------------------------------
* Function: dump_tables
*
@@ -1092,170 +1169,131 @@ int i;
* Modifications:
*
*-----------------------------------------------------------------------*/
-/*
+
static void
dump_tables(void) {
int i;
- printf("group_table: # of entries = %d\n", group_table.nobjs);
- for ( i = 0; i < group_table.nobjs; i++)
- printf ("%ul %ul %s\n %d %d", group_table.objs[i].objno[0],
- group_table.objs[i].objno[1],
- group_table.objs[i].objname,
- group_table.objs[i].displayed,
- group_table.objs[i].recorded);
-
- printf("\ndset_table: # of entries = %d\n", dset_table.nobjs);
- for ( i = 0; i < dset_table.nobjs; i++)
- printf ("%ul %ul %s %d %d\n", dset_table.objs[i].objno[0],
- dset_table.objs[i].objno[1],
- dset_table.objs[i].objname,
- dset_table.objs[i].displayed,
- dset_table.objs[i].recorded);
+ printf("group_table: # of entries = %d\n", group_table->nobjs);
+ for ( i = 0; i < group_table->nobjs; i++)
+ printf ("%ul %ul %s %d %d\n", group_table->objs[i].objno[0],
+ group_table->objs[i].objno[1],
+ group_table->objs[i].objname,
+ group_table->objs[i].displayed,
+ group_table->objs[i].recorded);
+
+ printf("\ndset_table: # of entries = %d\n", dset_table->nobjs);
+ for ( i = 0; i < dset_table->nobjs; i++)
+ printf ("%ul %ul %s %d %d\n", dset_table->objs[i].objno[0],
+ dset_table->objs[i].objno[1],
+ dset_table->objs[i].objname,
+ dset_table->objs[i].displayed,
+ dset_table->objs[i].recorded);
- printf("\ntype_table: # of entries = %d\n", type_table.nobjs);
- for ( i = 0; i < type_table.nobjs; i++)
- printf ("%ul %ul %s %d %d\n", type_table.objs[i].objno[0],
- type_table.objs[i].objno[1],
- type_table.objs[i].objname,
- type_table.objs[i].displayed,
- type_table.objs[i].recorded);
+ printf("\ntype_table: # of entries = %d\n", type_table->nobjs);
+ for ( i = 0; i < type_table->nobjs; i++)
+ printf ("%ul %ul %s %d %d\n", type_table->objs[i].objno[0],
+ type_table->objs[i].objno[1],
+ type_table->objs[i].objname,
+ type_table->objs[i].displayed,
+ type_table->objs[i].recorded);
}
-*/
+
+#endif
+
/*-------------------------------------------------------------------------
- * Function: Find_shared_objs
- *
- * Purpose: Find shared objects, committed types and store them in tables
+ * Function: dump_data
*
- * Return: Success: SUCCEED
+ * Purpose: Dump attribute or dataset data
*
- * Failure: FAIL
+ * Return: void
*
* Programmer: Ruey-Hsia Li
*
* Modifications:
*
- *-----------------------------------------------------------------------*/
-static herr_t
-find_shared_objs(hid_t group, const char *name, void UNUSED *op_data)
-{
-hid_t obj, type;
-H5G_stat_t statbuf;
-char *tmp;
-int i;
-
- H5Gget_objinfo(group, name, TRUE, &statbuf);
-
- tmp = (char *) malloc ((strlen(prefix)+strlen(name)+2) * sizeof(char));
-
- strcpy(tmp, prefix);
-
- switch (statbuf.type) {
-
- case H5G_GROUP:
- if ((obj=H5Gopen (group, name))>=0) {
-
- if (prefix_len < (int)(strlen(prefix) + strlen(name) + 2)) {
- prefix_len *= 2;
- prefix = realloc (prefix, prefix_len * sizeof(char));
- }
- strcat(strcat(prefix,"/"), name);
-
- if (statbuf.nlink > 1) {
- if (search_obj (group_table, statbuf.objno) < 0) {
- add_obj (&group_table, statbuf.objno, prefix);
- H5Giterate (obj, ".", NULL, find_shared_objs, NULL);
- }
- } else
- H5Giterate (obj, ".", NULL, find_shared_objs, NULL);
+ *-----------------------------------------------------------------------
+ */
+static void
+dump_data (hid_t obj_id, int obj_data) {
+ h5dump_t *outputformat = &dataformat;
+ int d_status = -1;
+ void *buf;
+ char *attr_name = malloc(sizeof(char)*80);
+ hid_t space, type, p_type;
+ int ndims, i;
+ hsize_t size[64], nelmts = 1;
+ int depth;
+ int stdindent = COL; /* should be 3*/
- strcpy(prefix, tmp);
- H5Gclose (obj);
- } else
- status = 1;
+ outputformat->line_ncols = nCols;
- break;
+ indent += COL;
+ /*the depth will tell us how far we need to indent extra. we use to just
+ use indent but with the merging of the tools lib we have to do something different
+ for the lib funtions... the normal indentation is 6 so when we dont need any extra
+ indentation, depth will be 0.*/
+depth = indent/stdindent+1;
+ indentation (indent);
+ /* printf("%s %s\n", dump_header_format->databegin, BEGIN);*/
+ begin_obj(dump_header_format->databegin, NULL, dump_header_format->datablockbegin);
- case H5G_DATASET:
+ /* Print all the values. */
+ if (obj_data == DATASET_DATA){
+ d_status = h5dump_dset(stdout, outputformat, obj_id, -1,depth);
+ }
+ else { /* need to call h5dump_mem for the attribute data */
- strcat(tmp,"/");
- strcat(tmp,name); /* absolute name of the data set */
- if (statbuf.nlink > 1 &&
- search_obj (dset_table, statbuf.objno) < 0)
- add_obj (&dset_table, statbuf.objno, tmp);
-
- if ((obj=H5Dopen (group, name))>=0) {
- type = H5Dget_type (obj);
- if (H5Tcommitted(type) > 0 ) {
- H5Gget_objinfo(type, ".", TRUE, &statbuf);
- if (search_obj (type_table, statbuf.objno) < 0)
- add_obj (&type_table, statbuf.objno, tmp) ;
- }
- H5Tclose(type);
- H5Dclose (obj);
- } else
- status = 1;
-
- break;
+ type = H5Aget_type(obj_id);
+ /* if (type < 0) {
+ return (d_status);
+ }*/
+ p_type = h5dump_fixtype(type);
+ H5Tclose(type);
- case H5G_TYPE:
- strcat(tmp,"/");
- strcat(tmp,name); /* absolute name of the type */
- i = search_obj (type_table, statbuf.objno);
- if (i < 0) {
- add_obj (&type_table, statbuf.objno, tmp) ;
- type_table.objs[type_table.nobjs-1].recorded = 1; /* named data type */
- } else {
- strcpy (type_table.objs[i].objname, tmp);
- type_table.objs[i].recorded = 1;
- }
- break;
+ /* if (p_type < 0) return d_status;*/
- default:
- break;
- }
+ space = H5Aget_space(obj_id);
- free (tmp);
+/* if (space < 0) return d_status;
+*/
- return SUCCEED;
-}
+ ndims = H5Sget_simple_extent_dims(space, size, NULL);
+ for (i=0; i<ndims; i++) {
+ nelmts *= size[i];
+ }
-/*-------------------------------------------------------------------------
- * Function: dump_data
- *
- * Purpose: Dump attribute or dataset data
- *
- * Return: void
- *
- * Programmer: Ruey-Hsia Li
- *
- * Modifications:
- *
- *-----------------------------------------------------------------------*/
-static void
-dump_data (hid_t obj_id, int obj_data) {
- indent += COL;
- indentation (indent);
- printf("%s %s\n", DATA, BEGIN);
+ buf = malloc(nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type)));
+ assert(buf);
+ if (H5Aread(obj_id, p_type, buf)>=0) {
+ d_status = h5dump_mem(stdout, outputformat, p_type, space, buf, depth);
+ }
+ free(buf);
+ H5Tclose(p_type);
+ H5Sclose(space);
+ H5Tclose(type);
+ }
- /* Print all the values. */
- if (print_data(obj_id, -1, obj_data) < 0) {
+
+ if (d_status < 0) {
indentation(indent+COL);
printf("Unable to print data.\n");
- status = 1;
+ d_status = 1;
}
-
indentation(indent);
- printf("%s\n", END);
+ /* printf("%s\n", END);*/
+ end_obj(dump_header_format->dataend, dump_header_format->datablockend);
indent -= COL;
}
+
+
/*-------------------------------------------------------------------------
* Function: main
*
@@ -1270,30 +1308,30 @@ dump_data (hid_t obj_id, int obj_data) {
*
*-----------------------------------------------------------------------*/
int
-main(int argc, char *argv[]) {
-hid_t fid, gid, dsetid, typeid;
-hid_t plist=H5P_DEFAULT;
-const char *fname = NULL;
-int i, index, curr_arg, display_bb=0, display_all=1;
-int nopts=0, *opts;
-char *buf, name[128], name1[128];
-H5G_stat_t statbuf;
-void UNUSED *op_data;
-void *edata;
-hid_t (*func)(void*);
-
-/* Disable error reporting */
-H5Eget_auto (&func, &edata);
-H5Eset_auto (NULL, NULL);
+main(int argc, char *argv[])
+{
+ hid_t fid, gid, dsetid, typeid;
+ hid_t plist=H5P_DEFAULT;
+ const char *fname = NULL;
+ int i, index, curr_arg, display_bb=0, display_all=1, newwidth= 0;
+ int nopts=0, *opts;
+ char *buf, name[128], name1[128];
+ H5G_stat_t statbuf;
+ void *edata;
+ hid_t (*func)(void*);
+ find_objs_t *info = malloc(sizeof(find_objs_t));
+
+ dump_header_format = &standardformat;
+
+ /* Disable error reporting */
+ H5Eget_auto (&func, &edata);
+ H5Eset_auto (NULL, NULL);
if (argc < 2 ) {
usage();
exit(1);
}
-/*init the programtype var fromt he tools lib*/
- programtype = H5DUMP;
-
opts = malloc((argc/2) * sizeof (int));
opts[0] = -1;
/* parse command line options */
@@ -1314,7 +1352,7 @@ H5Eset_auto (NULL, NULL);
exit(0);
}
- else if (!strcmp(argv[curr_arg],"-bb"))
+ else if (!strcmp(argv[curr_arg],"-bb"))
display_bb = 1;
@@ -1322,6 +1360,20 @@ H5Eset_auto (NULL, NULL);
display_data=0;
+ else if (!strcmp(argv[curr_arg],"-v"))
+
+ display_oid = 1;
+
+ else if (!strcmp(argv[curr_arg],"-w")){
+ /*
+ this way we know which arg was the -w
+ we know it won't be 0 since curr_arg starts at 1
+ */
+ newwidth = curr_arg;
+ }
+ else if (!strcmp(argv[curr_arg], "-xml")){
+ dump_header_format = &xmlformat;
+ }
else if (strcmp(argv[curr_arg],"-a") &&
strcmp(argv[curr_arg],"-d") &&
strcmp(argv[curr_arg],"-g") &&
@@ -1348,7 +1400,9 @@ H5Eset_auto (NULL, NULL);
for (i = 0; i < nopts-1; i++) {
if (opts[i+1]-opts[i] == 1) {
if (strcmp(argv[opts[i]], "-bb") &&
- strcmp(argv[opts[i]], "-header") ) {
+ strcmp(argv[opts[i]], "-header") &&
+ strcmp(argv[opts[i]], "-xml") &&
+ strcmp(argv[opts[i]], "-v")) {
fprintf(stderr,"h5dump error: no <names> after option %s\n",
argv[opts[i]]);
usage();
@@ -1365,8 +1419,10 @@ H5Eset_auto (NULL, NULL);
}
if (argc - opts[nopts-1] == 2) {
if (strcmp(argv[opts[i]], "-bb") &&
- strcmp(argv[opts[i]], "-header") ) {
- fprintf (stderr, "h5dump error: no <file> or no <names> after option %s\n", argv[opts[i]]);
+ strcmp(argv[opts[i]], "-header") &&
+ strcmp(argv[opts[i]], "-xml") &&
+ strcmp(argv[opts[i]], "-v")) {
+ fprintf (stderr, "h5dump error: no <file> or no <names> or no <number> after option %s\n", argv[opts[i]]);
usage();
free(opts);
exit(1);
@@ -1385,43 +1441,63 @@ H5Eset_auto (NULL, NULL);
}
/* allocate and initialize internal data structure */
- init_table();
+ init_table(&group_table);
+ init_table(&type_table);
+ init_table(&dset_table);
+ init_prefix(&prefix, prefix_len);
+
+ /*init the find_objs_t*/
+ info->threshold = 0;
+ info->prefix_len = 1024;
+ info->prefix = malloc(sizeof(char)*info->prefix_len);
+ *(info->prefix) = '\0';
+ info->group_table = group_table;
+ info->type_table = type_table;
+ info->dset_table = dset_table;
+ info->status = d_status;
+
+
/* find all shared objects */
- H5Giterate (fid, "/", NULL, find_shared_objs, NULL);
+ H5Giterate (fid, "/", NULL, find_objs, (void*)info);
strcpy(prefix, "");
/* does there exist unamed committed data type */
- for ( i = 0; i < type_table.nobjs; i++)
- if (type_table.objs[i].recorded == 0) unamedtype = 1;
+ for ( i = 0; i < type_table->nobjs; i++)
+ if (type_table->objs[i].recorded == 0) unamedtype = 1;
+
-/*
#ifdef H5DUMP_DEBUG
dump_tables();
#endif
-*/
- if (status) {
+
+ if (info->status) {
printf("internal error! \n");
goto done;
}
/* start to dump */
- begin_obj("HDF5", fname);
+ begin_obj(dump_header_format->filebegin, fname, dump_header_format->fileblockbegin);
+
if (display_bb) dump_bb();
-
+
+ if (newwidth) {
+ sscanf(argv[newwidth + 1], "%d", &nCols);
+ }
+
if (display_all) {
if ((gid = H5Gopen (fid, "/")) < 0 ) {
fprintf(stdout, "h5dump error: unable to open root group\n");
- status = 1;
+ d_status = 1;
} else
dump_group(gid, "/");
if (H5Gclose (gid) < 0) {
fprintf(stdout, "h5dump error: unable to close root group\n");
- status = 1;
+ d_status = 1;
}
} else
@@ -1440,33 +1516,33 @@ H5Eset_auto (NULL, NULL);
curr_arg++) {
if ((dsetid = H5Dopen (fid, argv[curr_arg]))<0) {
- begin_obj (DATASET, argv[curr_arg]);
+ begin_obj (dump_header_format->datasetbegin, argv[curr_arg], dump_header_format->datasetblockbegin);
indentation (COL);
fprintf (stdout, "h5dump error: unable to open %s\n",
argv[curr_arg]);
- end_obj();
- status = 1;
+ end_obj(dump_header_format->datasetend, dump_header_format->datasetblockend);
+ d_status = 1;
} else {
H5Gget_objinfo(dsetid, ".", TRUE, &statbuf);
if (statbuf.nlink > 1) {
index = search_obj (dset_table, statbuf.objno);
if (index >= 0) {
- if (dset_table.objs[index].displayed) {
- begin_obj(DATASET, argv[curr_arg]);
+ if (dset_table->objs[index].displayed) {
+ begin_obj(dump_header_format->datasetbegin, argv[curr_arg], dump_header_format->datasetblockbegin);
indentation (indent+COL);
printf("%s \"%s\"\n", HARDLINK,
- dset_table.objs[index].objname);
+ dset_table->objs[index].objname);
indentation (indent);
- end_obj();
+ end_obj(dump_header_format->datasetend, dump_header_format->datasetblockend);
} else {
- strcpy(dset_table.objs[index].objname, argv[curr_arg]);
- dset_table.objs[index].displayed = 1;
+ strcpy(dset_table->objs[index].objname, argv[curr_arg]);
+ dset_table->objs[index].displayed = 1;
dump_dataset(dsetid, argv[curr_arg]);
}
- } else status = 1;
+ } else d_status = 1;
} else
dump_dataset(dsetid, argv[curr_arg]);
- if (H5Dclose(dsetid)<1) status = 1;
+ if (H5Dclose(dsetid)<1) d_status = 1;
}
}
@@ -1479,17 +1555,17 @@ H5Eset_auto (NULL, NULL);
curr_arg < ((i+1)==nopts?(argc-1):opts[i+1]);
curr_arg++) {
if ((gid = H5Gopen (fid, argv[curr_arg])) < 0) {
- begin_obj (GROUPNAME, argv[curr_arg]);
+ begin_obj (dump_header_format->groupbegin, argv[curr_arg], dump_header_format->groupblockbegin);
indentation (COL);
fprintf (stdout, "h5dump error: unable to open %s\n",
argv[curr_arg]);
- end_obj();
- status = 1;
+ end_obj(dump_header_format->groupend, dump_header_format->groupblockend);
+ d_status = 1;
} else {
H5Gget_objinfo(gid, ".", TRUE, &statbuf);
strcpy(prefix, argv[curr_arg]);
dump_group(gid, argv[curr_arg]);
- if (H5Gclose (gid) < 0) status = 1;
+ if (H5Gclose (gid) < 0) d_status = 1;
}
}
@@ -1501,32 +1577,32 @@ H5Eset_auto (NULL, NULL);
if (H5Gget_objinfo(fid, argv[curr_arg], FALSE, &statbuf) < 0) {
- begin_obj(SOFTLINK, argv[curr_arg]);
+ begin_obj(dump_header_format->softlinkbegin, argv[curr_arg], dump_header_format->softlinkblockbegin);
indentation (COL);
fprintf(stdout, "h5dump error: unable to get obj info from %s\n", argv[curr_arg]);
- end_obj();
- status = 1;
+ end_obj(dump_header_format->softlinkend, dump_header_format->softlinkblockend);
+ d_status = 1;
} else if (statbuf.type == H5G_LINK) {
buf = malloc(statbuf.linklen*sizeof(char));
- begin_obj(SOFTLINK, argv[curr_arg]);
+ begin_obj(dump_header_format->softlinkbegin, argv[curr_arg], dump_header_format->softlinkblockbegin);
indentation (COL);
if (H5Gget_linkval (fid, argv[curr_arg], statbuf.linklen, buf)>=0)
printf ("LINKTARGET \"%s\"\n", buf);
else {
fprintf (stdout, "h5dump error: unable to get link value\n");
- status = 1;
+ d_status = 1;
}
- end_obj();
+ end_obj(dump_header_format->softlinkend, dump_header_format->softlinkblockend);
free(buf);
} else {
- begin_obj(SOFTLINK, argv[curr_arg]);
+ begin_obj(dump_header_format->softlinkbegin, argv[curr_arg], dump_header_format->softlinkblockbegin);
indentation (COL);
fprintf(stdout, "h5dump error: %s is not a link\n", argv[curr_arg]);
- end_obj();
- status = 1;
+ end_obj(dump_header_format->softlinkend, dump_header_format->softlinkblockend);
+ d_status = 1;
}
}
@@ -1542,12 +1618,12 @@ H5Eset_auto (NULL, NULL);
/* check if argv[curr_arg] is unamed data type */
index = 0;
- while (index < type_table.nobjs ) {
- if (!type_table.objs[index].recorded) { /* unamed data type */
- sprintf(name,"#%lu:%lu\n", type_table.objs[index].objno[0],
- type_table.objs[index].objno[1]);
- sprintf(name1,"/#%lu:%lu\n", type_table.objs[index].objno[0],
- type_table.objs[index].objno[1]);
+ while (index < type_table->nobjs ) {
+ if (!type_table->objs[index].recorded) { /* unamed data type */
+ sprintf(name,"#%lu:%lu\n", type_table->objs[index].objno[0],
+ type_table->objs[index].objno[1]);
+ sprintf(name1,"/#%lu:%lu\n", type_table->objs[index].objno[0],
+ type_table->objs[index].objno[1]);
if (!strncmp(name, argv[curr_arg], strlen(argv[curr_arg])) ||
!strncmp(name1, argv[curr_arg], strlen(argv[curr_arg]))) {
break;
@@ -1555,15 +1631,15 @@ H5Eset_auto (NULL, NULL);
}
index++;
}
- if (index == type_table.nobjs) { /* unknown type */
- begin_obj (DATATYPE, argv[curr_arg]);
+ if (index == type_table->nobjs) { /* unknown type */
+ begin_obj (dump_header_format->datatypebegin, argv[curr_arg], dump_header_format->datatypeblockbegin);
indentation (COL);
fprintf (stdout, "h5dump error: unable to open %s\n",
argv[curr_arg]);
- end_obj();
- status = 1;
+ end_obj(dump_header_format->datatypeend, dump_header_format->datatypeblockend);
+ d_status = 1;
} else {
- dsetid = H5Dopen (fid, type_table.objs[index].objname) ;
+ dsetid = H5Dopen (fid, type_table->objs[index].objname) ;
typeid = H5Dget_type (dsetid);
dump_named_datatype (typeid, argv[curr_arg]);
H5Tclose(typeid);
@@ -1572,26 +1648,27 @@ H5Eset_auto (NULL, NULL);
} else {
dump_named_datatype (typeid, argv[curr_arg]);
- if (H5Tclose(typeid) < 0) status = 1;
+ if (H5Tclose(typeid) < 0) d_status = 1;
}
}
- }
+ }
}
- end_obj();
+ end_obj(dump_header_format->fileend, dump_header_format->fileblockend);
done:
H5Eset_auto (func, edata);
free(opts);
- if (H5Fclose (fid) < 0) status = 1;
+ if (H5Fclose (fid) < 0) d_status = 1;
- free (group_table.objs);
- free (dset_table.objs);
- free (type_table.objs);
+ free (group_table->objs);
+ free (dset_table->objs);
+ free (type_table->objs);
free (prefix);
-
- return status;
+ free (info->prefix);
+ free (info);
+ return d_status;
}
@@ -1687,5 +1764,27 @@ static void print_enum(hid_t type){
/* return TRUE;*/
}
+/*-------------------------------------------------------------------------
+ * Function: dump_oid
+ *
+ * Purpose: Prints the object ids
+ *
+ * Return: void
+ *
+ * Programmer: Patrick Lu
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+static void
+dump_oid(hid_t oid){
+
+ indent += COL;
+ indentation (indent);
+ printf ("%s %s ", OBJID, BEGIN);
+ printf("%d", oid);
+ printf (" %s\n", END);
+ indent -= COL;
+}
diff --git a/tools/h5dump.h b/tools/h5dump.h
index 1b872de..083ac39 100644
--- a/tools/h5dump.h
+++ b/tools/h5dump.h
@@ -9,8 +9,8 @@
#define H5DUMP_MAX_RANK H5S_MAX_RANK
-#define begin_obj(obj,name) printf("%s \"%s\" %s\n", obj, name, BEGIN)
-#define end_obj() printf("%s\n", END);
+#define begin_obj(obj,name, begin) if (name) printf("%s \"%s\" %s\n", obj, name, begin); else printf("%s %s\n",obj,begin);
+#define end_obj(obj, end) printf("%s %s\n", end,obj);
#endif
diff --git a/tools/h5dumptst.c b/tools/h5dumptst.c
index c6f7312..b90974a 100644
--- a/tools/h5dumptst.c
+++ b/tools/h5dumptst.c
@@ -22,6 +22,9 @@
#define FILE15 "tenum.h5"
#define FILE16 "tobjref.h5"
#define FILE17 "tdatareg.h5"
+#define FILE18 "tnestedcomp.h5"
+#define FILE19 "topaque.h5"
+
#define LENSTR 50
#define LENSTR2 11
@@ -56,6 +59,7 @@ typedef struct s1_t {
void test_enum(void);
void test_objref(void);
void test_datareg(void);
+void test_nestcomp(void);
@@ -248,15 +252,14 @@ int point = 100;
static void test_softlink(void) {
hid_t fid, root;
-herr_t status;
fid = H5Fcreate(FILE4, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
root = H5Gopen (fid, "/");
- status = H5Glink (root, H5G_LINK_SOFT, "somevalue", "slink1");
+ H5Glink (root, H5G_LINK_SOFT, "somevalue", "slink1");
- status = H5Glink (root, H5G_LINK_SOFT, "linkvalue", "slink2");
+ H5Glink (root, H5G_LINK_SOFT, "linkvalue", "slink2");
H5Gclose(root);
@@ -365,7 +368,7 @@ hsize_t dset3_dim[2];
dset2[i].b = i+ i*0.1;
dset4[i].a = i;
- dset4[i].b = i*1.0;
+ dset4[i].b = i+3;
dset5[i].a = i;
dset5[i].b = i*0.1;
@@ -426,10 +429,10 @@ hsize_t dset3_dim[2];
for (i = 0; i < (int)dset3_dim[0]; i++) {
for (j = 0; j < (int)dset3_dim[1]; j++) {
for (k = 0; k < 4; k++)
- dset3[i][j].a[k] = k;
+ dset3[i][j].a[k] = k+j+i;
for (k = 0; k < 5; k++)
for (l = 0; l < 6; l++)
- dset3[i][j].b[k][l] = 0.1* (k+1);
+ dset3[i][j].b[k][l] = (k+1)+l+j+i;
}
}
H5Dwrite(dataset, type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset3);
@@ -720,7 +723,7 @@ float dset2_1[10], dset2_2[3][5];
dataset = H5Dcreate(group, "dset1.1.1", H5T_STD_I32BE, space, H5P_DEFAULT);
for (i = 0; i < 10; i++)
for (j = 0; j < 10; j++)
- dset1[i][j] = j;
+ dset1[i][j] = j*i;
H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset1);
H5Sclose(space);
@@ -778,7 +781,7 @@ float dset2_1[10], dset2_2[3][5];
dataset = H5Dcreate(group, "dset2.2", H5T_IEEE_F32BE, space, H5P_DEFAULT);
for (i = 0; i < 3; i++)
for (j = 0; j < 5; j++)
- dset2_2[i][j] = i*0.1;
+ dset2_2[i][j] = (i+1)*j*0.1;
H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2_2);
H5Sclose(space);
H5Dclose(dataset);
@@ -1018,7 +1021,7 @@ const int perm[4] = {0,1,2,3}; /* the 0'th and the 3'rd indices are permuted */
H5Fclose(fid);
}
-static hid_t mkstr(int size, int pad) {
+static hid_t mkstr(int size, H5T_str_t pad) {
hid_t type;
if ((type=H5Tcopy(H5T_C_S1))<0) return -1;
@@ -1160,7 +1163,8 @@ size_t mdims[2];
static void test_str2(void) {
hid_t fid, group, attr, dataset, space, space2, mem_space, hyper_space;
hid_t fxdlenstr, fxdlenstr2, memtype;
-hsize_t dims[1], size[1], start[1], stride[1], count[1], block[1];
+hsize_t dims[1], size[1], stride[1], count[1], block[1];
+hssize_t start[1];
int i;
@@ -1362,8 +1366,6 @@ void test_objref(void){
uint32_t *tu32; /* Temporary pointer to uint32 data */
intn i; /* counting variables */
const char *write_comment="Foo!"; /* Comments for group */
- herr_t ret; /* Generic return value */
-
/* Allocate write & read buffers */
wbuf=malloc(sizeof(hobj_ref_t)*SPACE1_DIM1);
@@ -1380,7 +1382,7 @@ void test_objref(void){
group=H5Gcreate(fid1,"Group1",-1);
/* Set group's comment */
- ret=H5Gset_comment(group,".",write_comment);
+ H5Gset_comment(group,".",write_comment);
/* Create a dataset (inside Group1) */
dataset=H5Dcreate(group,"Dataset1",H5T_STD_U32BE,sid1,H5P_DEFAULT);
@@ -1389,72 +1391,72 @@ void test_objref(void){
*tu32++=i*3;
/* Write selection to disk */
- ret=H5Dwrite(dataset,H5T_NATIVE_UINT,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
+ H5Dwrite(dataset,H5T_NATIVE_UINT,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
/* Close Dataset */
- ret = H5Dclose(dataset);
+ H5Dclose(dataset);
/* Create another dataset (inside Group1) */
dataset=H5Dcreate(group,"Dataset2",H5T_STD_U8BE,sid1,H5P_DEFAULT);
/* Close Dataset */
- ret = H5Dclose(dataset);
+ H5Dclose(dataset);
/* Create a datatype to refer to */
tid1 = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
/* Insert fields */
- ret=H5Tinsert (tid1, "a", HOFFSET(s1_t,a), H5T_STD_I32BE);
+ H5Tinsert (tid1, "a", HOFFSET(s1_t,a), H5T_STD_I32BE);
- ret=H5Tinsert (tid1, "b", HOFFSET(s1_t,b), H5T_IEEE_F32BE);
+ H5Tinsert (tid1, "b", HOFFSET(s1_t,b), H5T_IEEE_F32BE);
- ret=H5Tinsert (tid1, "c", HOFFSET(s1_t,c), H5T_IEEE_F32BE);
+ H5Tinsert (tid1, "c", HOFFSET(s1_t,c), H5T_IEEE_F32BE);
/* Save datatype for later */
- ret=H5Tcommit (group, "Datatype1", tid1);
+ H5Tcommit (group, "Datatype1", tid1);
/* Close datatype */
- ret = H5Tclose(tid1);
+ H5Tclose(tid1);
/* Close group */
- ret = H5Gclose(group);
+ H5Gclose(group);
/* Create a dataset */
dataset=H5Dcreate(fid1,"Dataset3",H5T_STD_REF_OBJ,sid1,H5P_DEFAULT);
/* Create reference to dataset */
- ret = H5Rcreate(&wbuf[0],fid1,"/Group1/Dataset1",H5R_OBJECT,-1);
- ret = H5Rget_object_type(dataset,&wbuf[0]);
+ H5Rcreate(&wbuf[0],fid1,"/Group1/Dataset1",H5R_OBJECT,-1);
+ H5Rget_object_type(dataset,&wbuf[0]);
/* Create reference to dataset */
- ret = H5Rcreate(&wbuf[1],fid1,"/Group1/Dataset2",H5R_OBJECT,-1);
+ H5Rcreate(&wbuf[1],fid1,"/Group1/Dataset2",H5R_OBJECT,-1);
- ret = H5Rget_object_type(dataset,&wbuf[1]);
+ H5Rget_object_type(dataset,&wbuf[1]);
/* Create reference to group */
- ret = H5Rcreate(&wbuf[2],fid1,"/Group1",H5R_OBJECT,-1);
+ H5Rcreate(&wbuf[2],fid1,"/Group1",H5R_OBJECT,-1);
- ret = H5Rget_object_type(dataset,&wbuf[2]);
+ H5Rget_object_type(dataset,&wbuf[2]);
/* Create reference to named datatype */
- ret = H5Rcreate(&wbuf[3],fid1,"/Group1/Datatype1",H5R_OBJECT,-1);
+ H5Rcreate(&wbuf[3],fid1,"/Group1/Datatype1",H5R_OBJECT,-1);
- ret = H5Rget_object_type(dataset,&wbuf[3]);
+ H5Rget_object_type(dataset,&wbuf[3]);
/* Write selection to disk */
- ret=H5Dwrite(dataset,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
+ H5Dwrite(dataset,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
/* Close disk dataspace */
- ret = H5Sclose(sid1);
+ H5Sclose(sid1);
/* Close Dataset */
- ret = H5Dclose(dataset);
+ H5Dclose(dataset);
/* Close file */
- ret = H5Fclose(fid1);
+ H5Fclose(fid1);
/* Free memory buffers */
free(wbuf);
@@ -1486,7 +1488,6 @@ void test_datareg(void){
*drbuf; /* Buffer for reading numeric data from disk */
uint8_t *tu8; /* Temporary pointer to uint8 data */
intn i; /* counting variables */
- herr_t ret; /* Generic return value */
/* Allocate write & read buffers */
wbuf=calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1);
@@ -1507,10 +1508,10 @@ void test_datareg(void){
*tu8++=i*3;
/* Write selection to disk */
- ret=H5Dwrite(dset2,H5T_NATIVE_UCHAR,H5S_ALL,H5S_ALL,H5P_DEFAULT,dwbuf);
+ H5Dwrite(dset2,H5T_NATIVE_UCHAR,H5S_ALL,H5S_ALL,H5P_DEFAULT,dwbuf);
/* Close Dataset */
- ret = H5Dclose(dset2);
+ H5Dclose(dset2);
/* Create dataspace for the reference dataset */
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
@@ -1525,12 +1526,12 @@ void test_datareg(void){
stride[0]=1; stride[1]=1;
count[0]=6; count[1]=6;
block[0]=1; block[1]=1;
- ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block);
+ H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block);
- ret = H5Sget_select_npoints(sid2);
+ H5Sget_select_npoints(sid2);
/* Store first dataset region */
- ret = H5Rcreate(&wbuf[0],fid1,"/Dataset2",H5R_DATASET_REGION,sid2);
+ H5Rcreate(&wbuf[0],fid1,"/Dataset2",H5R_DATASET_REGION,sid2);
/* Select sequence of ten points for second reference */
coord1[0][0]=6; coord1[0][1]=9;
@@ -1543,27 +1544,27 @@ void test_datareg(void){
coord1[7][0]=9; coord1[7][1]=0;
coord1[8][0]=7; coord1[8][1]=1;
coord1[9][0]=3; coord1[9][1]=3;
- ret = H5Sselect_elements(sid2,H5S_SELECT_SET,POINT1_NPOINTS,(const hssize_t **)coord1);
+ H5Sselect_elements(sid2,H5S_SELECT_SET,POINT1_NPOINTS,(const hssize_t **)coord1);
- ret = H5Sget_select_npoints(sid2);
+ H5Sget_select_npoints(sid2);
/* Store second dataset region */
- ret = H5Rcreate(&wbuf[1],fid1,"/Dataset2",H5R_DATASET_REGION,sid2);
+ H5Rcreate(&wbuf[1],fid1,"/Dataset2",H5R_DATASET_REGION,sid2);
/* Write selection to disk */
- ret=H5Dwrite(dset1,H5T_STD_REF_DSETREG,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
+ H5Dwrite(dset1,H5T_STD_REF_DSETREG,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
/* Close disk dataspace */
- ret = H5Sclose(sid1);
+ H5Sclose(sid1);
/* Close Dataset */
- ret = H5Dclose(dset1);
+ H5Dclose(dset1);
/* Close uint8 dataset dataspace */
- ret = H5Sclose(sid2);
+ H5Sclose(sid2);
/* Close file */
- ret = H5Fclose(fid1);
+ H5Fclose(fid1);
/* Free memory buffers */
free(wbuf);
@@ -1572,6 +1573,120 @@ void test_datareg(void){
free(drbuf);
}
+void test_nestcomp(void){
+
+ hid_t file,space,type,type2,dataset;
+ int i, maxdim = 5;
+ hsize_t dim = 5;
+ int y = 1;
+
+ typedef struct {
+ double re; /*real part*/
+ double im; /*imaginary part*/
+ } complex_t;
+
+ typedef struct {
+ complex_t x;
+ complex_t y;
+ } surf_t;
+ surf_t surft[5];
+ /*
+ * Initialize the data
+ */
+
+ for (i = 0; i< dim; i++) {
+ surft[i].x.re = i;
+ surft[i].x.im = i+y;
+ y++;
+ surft[i].y.re = i+y;
+ surft[i].y.im = i+2*y;
+ }
+
+ /*
+ * Create the data space.
+ */
+ space = H5Screate_simple(1, &dim, NULL);
+
+ /*
+ * Create the file.
+ */
+ file = H5Fcreate(FILE18, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+
+ /*
+ * Create the memory datatype.
+ */
+ type = H5Tcreate (H5T_COMPOUND, sizeof(complex_t));
+
+ H5Tinsert(type, "re", HOFFSET(complex_t, re), H5T_NATIVE_DOUBLE);
+ H5Tinsert(type, "im", HOFFSET(complex_t, im), H5T_NATIVE_DOUBLE);
+
+ type2 = H5Tcreate (H5T_COMPOUND, sizeof(surf_t));
+
+ H5Tinsert(type2, "x", HOFFSET(surf_t, x), type);
+ H5Tinsert(type2, "y", HOFFSET(surf_t, y), type);
+
+ /*
+ * Create the dataset.
+ */
+ dataset = H5Dcreate(file, "/nested compound", type2, space, H5P_DEFAULT);
+
+ /*
+ * Wtite data to the dataset;
+ */
+ H5Dwrite(dataset, type2, H5S_ALL, H5S_ALL, H5P_DEFAULT, surft);
+
+ /*
+ * Release resources
+ */
+ H5Tclose(type2);
+ H5Tclose(type);
+ H5Sclose(space);
+ H5Dclose(dataset);
+ H5Fclose(file);
+
+}
+
+void test_opaque(){
+ hid_t file, type, dataset, space;
+ char test[100][2];
+ int x;
+ hsize_t dim = 2;
+
+ for (x = 0; x < 100; x++){
+ test[x][0] = x;
+ test[x][1] = 99 - x;
+ }
+
+ /*
+ * Create the data space.
+ */
+ space = H5Screate_simple(1, &dim, NULL);
+ /*
+ * Create the file.
+ */
+ file = H5Fcreate(FILE19, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ /*
+ * Create the memory datatype.
+ */
+ type = H5Tcreate (H5T_OPAQUE, sizeof(char)*100*2);
+ H5Tset_tag(type, "test opaque type");
+
+ /*
+ * Create the dataset.
+ */
+ dataset = H5Dcreate(file, "opaque test", type, space, H5P_DEFAULT);
+ /*
+ * Wtite data to the dataset;
+ */
+ H5Dwrite(dataset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, test);
+
+ H5Tclose(type);
+ H5Sclose(space);
+ H5Dclose(dataset);
+ H5Fclose(file);
+
+}
+
int main(void){
@@ -1596,6 +1711,10 @@ test_enum();
test_objref();
test_datareg();
+
+test_nestcomp();
+
+test_opaque();
return 0;
}
diff --git a/tools/h5dumputil.c b/tools/h5dumputil.c
index 1393db0..a88f4b2 100644
--- a/tools/h5dumputil.c
+++ b/tools/h5dumputil.c
@@ -25,8 +25,12 @@
#define H5DUMP_BUFSIZE (1024)
#endif
+#ifndef MIN
#define MIN(X,Y) ((X)<(Y)?(X):(Y))
+#endif
+#ifndef NELMTS
#define NELMTS(X) (sizeof(X)/sizeof(*X))
+#endif
#define ALIGN(A,Z) ((((A)+(Z)-1)/(Z))*(Z))
diff --git a/tools/h5ls.c b/tools/h5ls.c
index 5ba09eb..1cad442 100644
--- a/tools/h5ls.c
+++ b/tools/h5ls.c
@@ -16,6 +16,18 @@
#include <h5tools.h>
/*
+ * File drivers
+ */
+#if defined VERSION13
+#include <H5FDsec2.h>
+#include <H5FDmulti.h>
+#include <H5FDfamily.h>
+#elif defined VERSION12
+#include <H5Fpublic.h>
+#endif
+
+#define NDRIVERS 10
+/*
* If defined then include the file name as part of the object name when
* printing full object names. Otherwise leave the file name off.
*/
@@ -32,6 +44,8 @@ static hbool_t fullname_g = FALSE; /*print full path names */
static hbool_t recursive_g = FALSE; /*recursive descent listing */
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 */
/* Info to pass to the iteration functions */
typedef struct iter_t {
@@ -93,11 +107,13 @@ usage: %s [OPTIONS] [OBJECTS...]\n\
-h, -?, --help Print a usage message and exit\n\
-a, --address Print addresses for raw data\n\
-d, --data Print the values of datasets\n\
+ -e, --errors Show all HDF5 error reporting\n\
-f, --full Print full path names instead of base names\n\
-g, --group Show information about a group, not its contents\n\
-l, --label Label members of compound datasets\n\
-r, --recursive List all groups recursively, avoiding cycles\n\
-s, --string Print 1-byte integer datasets as ASCII\n\
+ -S, --simple Use a machine-readable output format\n\
-wN, --width=N Set the number of columns of output\n\
-v, --verbose Generate more verbose output\n\
-V, --version Print version number and exit\n\
@@ -1088,7 +1104,9 @@ display_type(hid_t type, int ind)
* Tuesday, July 21, 1998
*
* Modifications:
- *
+ * Robb Matzke, 1999-09-27
+ * Understands the simple_output_g switch which causes data to
+ * be displayed in a more machine-readable format.
*-------------------------------------------------------------------------
*/
static void
@@ -1097,21 +1115,53 @@ dump_dataset_values(hid_t dset)
hid_t f_type = H5Dget_type(dset);
size_t size = H5Tget_size(f_type);
h5dump_t info;
-
+ char string_prefix[64];
+
/* Set to all default values and then override */
memset(&info, 0, sizeof info);
- info.idx_fmt = "(%s)";
- 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 (simple_output_g) {
+ info.idx_fmt = "";
+ info.line_ncols = 65535; /*something big*/
+ info.line_per_line = 1;
+ info.line_multi_new = 0;
+ info.line_pre = " ";
+ info.line_cont = " ";
+
+ info.arr_pre = "";
+ info.arr_suf = "";
+ info.arr_sep = " ";
+
+ info.cmpd_pre = "";
+ info.cmpd_suf = "";
+ info.cmpd_sep = " ";
+
+ if (label_g) info.cmpd_name = "%s=";
+
+ info.elmt_suf1 = " ";
+ info.str_locale = ESCAPE_HTML;
+
+ } else {
+ info.idx_fmt = "(%s)";
+ info.line_ncols = width_g;
+ info.line_multi_new = 1;
+ if (label_g) info.cmpd_name = "%s=";
+ info.line_pre = " %s ";
+ info.line_cont = " %s ";
+ info.str_repeat = 8;
+ }
+
+ info.dset_format = "DSET-%lu:%lu:%lu:%lu-";
+ info.dset_hidefileno = 0;
+
+ info.obj_format = "-%lu:%lu:%lu:%lu";
+ info.obj_hidefileno = 0;
+
+ info.dset_blockformat_pre = "%sBlk%lu: ";
+ info.dset_ptformat_pre = "%sPt%lu: ";
+
+ info.line_indent = "";
+
if (hexdump_g) {
/*
* Print all data in hexadecimal format if the `-x' or `--hexdump'
@@ -1126,7 +1176,9 @@ dump_dataset_values(hid_t dset)
info.ascii = TRUE;
info.elmt_suf1 = "";
info.elmt_suf2 = "";
- info.line_pre =" %s \"";
+ strcpy(string_prefix, info.line_pre);
+ strcat(string_prefix, "\"");
+ info.line_pre = string_prefix;
info.line_suf = "\"";
}
@@ -1134,7 +1186,7 @@ dump_dataset_values(hid_t dset)
* Print all the values.
*/
printf(" Data:\n");
- if (h5dump_dset(stdout, &info, dset, -1)<0) {
+ if (h5dump_dset(stdout, &info, dset, -1, -1)<0) {
printf(" Unable to print data.\n");
}
@@ -1201,12 +1253,14 @@ list_attr (hid_t obj, const char *attr_name, void UNUSED *op_data)
info.line_1st = " Data: ";
info.line_pre = " ";
info.line_cont = " ";
+ info.str_repeat = 8;
} else {
printf(" Data:\n");
info.idx_fmt = "(%s)";
info.line_pre = " %s ";
info.line_cont = " %s ";
+ info.str_repeat = 8;
}
info.line_ncols = width_g;
if (label_g) info.cmpd_name = "%s=";
@@ -1229,7 +1283,7 @@ list_attr (hid_t obj, const char *attr_name, void UNUSED *op_data)
buf = malloc(need);
assert(buf);
if (H5Aread(attr, p_type, buf)>=0) {
- h5dump_mem(stdout, &info, p_type, space, buf);
+ h5dump_mem(stdout, &info, p_type, space, buf,-1);
}
free(buf);
H5Tclose(p_type);
@@ -1851,18 +1905,23 @@ get_width(void)
int
main (int argc, char *argv[])
{
- hid_t file=-1, plist=-1, root=-1;
+ hid_t file=-1, root=-1, fapl=-1;
char *fname=NULL, *oname=NULL, *x;
const char *progname;
const char *s = NULL;
char *rest, *container=NULL;
- int argno;
+ int argno, dno;
H5G_stat_t sb;
iter_t iter;
static char root_name[] = "/";
- /* Turn off HDF5's automatic error printing unless you're debugging h5ls */
- H5Eset_auto(NULL, NULL);
+ int ndrivers=0;
+
+ struct {
+ const char *name;
+ hid_t fapl;
+ } driver[NDRIVERS];
+
/* Build display table */
DISPATCH(H5G_DATASET, "Dataset", H5Dopen, H5Dclose,
@@ -1876,9 +1935,6 @@ main (int argc, char *argv[])
DISPATCH(H5G_RAGGED, "Ragged Array", H5Gopen, H5Gclose,
NULL, ragged_list2);
- /* Init the program type for the tools lib*/
- programtype = H5LS; /*global*/
-
/* Name of this program without the path */
if ((progname=strrchr(argv[0], '/'))) progname++;
else progname = argv[0];
@@ -1897,17 +1953,21 @@ main (int argc, char *argv[])
exit(0);
} else if (!strcmp(argv[argno], "--address")) {
address_g = TRUE;
- } else if (!strcmp(argv[argno], "--group")) {
- grp_literal_g = TRUE;
} else if (!strcmp(argv[argno], "--data")) {
data_g = TRUE;
+ } else if (!strcmp(argv[argno], "--errors")) {
+ show_errors_g = TRUE;
} else if (!strcmp(argv[argno], "--full")) {
fullname_g = TRUE;
+ } else if (!strcmp(argv[argno], "--group")) {
+ grp_literal_g = TRUE;
} else if (!strcmp(argv[argno], "--label")) {
label_g = TRUE;
} else if (!strcmp(argv[argno], "--recursive")) {
recursive_g = TRUE;
fullname_g = TRUE;
+ } else if (!strcmp(argv[argno], "--simple")) {
+ simple_output_g = TRUE;
} else if (!strcmp(argv[argno], "--string")) {
string_g = TRUE;
} else if (!strncmp(argv[argno], "--width=", 8)) {
@@ -1963,6 +2023,9 @@ main (int argc, char *argv[])
case 'd': /* --data */
data_g = TRUE;
break;
+ case 'e': /* --errors */
+ show_errors_g = TRUE;
+ break;
case 'f': /* --full */
fullname_g = TRUE;
break;
@@ -1976,6 +2039,9 @@ main (int argc, char *argv[])
recursive_g = TRUE;
fullname_g = TRUE;
break;
+ case 'S': /* --simple */
+ simple_output_g = TRUE;
+ break;
case 's': /* --string */
string_g = TRUE;
break;
@@ -2007,7 +2073,35 @@ main (int argc, char *argv[])
usage(progname);
exit(1);
}
-
+
+ /* Turn off HDF5's automatic error printing unless you're debugging h5ls */
+ if (!show_errors_g) H5Eset_auto(NULL, NULL);
+
+ /*
+ * Build a list of file access property lists which we should try when
+ * opening the file. Eventually we'd like some way for the user to
+ * augment/replace this list interactively.
+ */
+
+ driver[ndrivers].name = "sec2";
+ driver[ndrivers].fapl = H5P_DEFAULT;
+ ndrivers++;
+#if defined VERSION13
+ driver[ndrivers].name = "family";
+ driver[ndrivers].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS);
+ H5Pset_fapl_family(fapl, 0, H5P_DEFAULT);
+ ndrivers++;
+
+ driver[ndrivers].name = "split";
+ driver[ndrivers].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS);
+ H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT);
+ ndrivers++;
+
+ driver[ndrivers].name = "multi";
+ driver[ndrivers].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS);
+ H5Pset_fapl_multi(fapl, NULL, NULL, NULL, NULL, TRUE);
+ ndrivers++;
+#endif
/*
* Each remaining argument is an hdf5 file followed by an optional slash
* and object name.
@@ -2028,19 +2122,20 @@ main (int argc, char *argv[])
file = -1;
while (fname && *fname) {
- /* Choose a file driver*/
- plist = H5Pcreate(H5P_FILE_ACCESS);
- if (strchr(fname, '%')) {
- H5Pset_family(plist, 0, H5P_DEFAULT);
+ for (dno=0; dno<ndrivers; dno++) {
+ H5E_BEGIN_TRY {
+ file = H5Fopen(fname, H5F_ACC_RDONLY, driver[dno].fapl);
+ } H5E_END_TRY;
+ if (file>=0) break;
}
-
- /* Try to open the file */
- H5E_BEGIN_TRY {
- file = H5Fopen(fname, H5F_ACC_RDONLY, plist);
- } H5E_END_TRY;
- H5Pclose(plist);
- if (file>=0) break; /*success*/
-
+ if (file>=0) {
+ if (verbose_g) {
+ printf("Opened \"%s\" with %s driver.\n",
+ fname, driver[dno].name);
+ }
+ break; /*success*/
+ }
+
/* Shorten the file name; lengthen the object name */
x = oname;
oname = strrchr(fname, '/');
@@ -2049,7 +2144,7 @@ main (int argc, char *argv[])
*oname = '\0';
}
if (file<0) {
- fprintf(stderr, "%s: unable to open file\n", fname);
+ fprintf(stderr, "%s: unable to open file\n", argv[argno-1]);
}
if (oname) oname++;
if (!oname || !*oname) oname = root_name;
diff --git a/tools/h5toh4.c b/tools/h5toh4.c
index 8e6b591..228c33c 100644
--- a/tools/h5toh4.c
+++ b/tools/h5toh4.c
@@ -11,13 +11,20 @@
*****************************************************************************/
-#include <stdio.h>
+#include "h5toh4.h"
#include <errno.h>
#include <string.h>
#include <fcntl.h>
-#include <sys/stat.h>
-#include <h5toh4.h>
+#include <h5tools.h>
+
+#if WIN32
+typedef unsigned int mode_t;
+#endif
+
+#ifndef S_ISDIR
+#define S_ISDIR(mode) (((mode)&0xF000) == S_IFDIR)
+#endif
extern void PrintOptions_h5toh4(void);
extern char *BuildFilename(char *h5_filename, char *h4_extension);
extern int test_file(char *filename, int oflag, mode_t mode);
@@ -34,17 +41,23 @@ extern herr_t convert_dataset_string(hid_t, char *, op_data_t *);
extern int32 h5type_to_h4type(hid_t);
extern hid_t h4type_to_memtype(int32);
-extern void init_table(void);
-extern void free_table(void);
-extern void dump_tables(void);
-extern herr_t H5findobj_once(hid_t , char *, void *);
-extern int get_table_idx(int, unsigned long *);
-extern int get_tableflag(int, int);
-extern int set_tableflag(int, int);
-extern char* get_objectname(int, int);
+extern void init_table(table_t **temp);
+extern void free_table(table_t **temp);
+extern void init_prefix(char **prefix, int length);
+extern void dump_tables(char* name, table_t* table);
+extern herr_t find_objs(hid_t , const char *, void *);
+extern int get_table_idx(table_t*, unsigned long *);
+extern int get_tableflag(table_t*, int);
+extern int set_tableflag(table_t*, int);
+extern char* get_objectname(table_t*, int);
typedef herr_t (*H5G_operator_t)(hid_t, const char*, void*);
+static int prefix_len = 1024;
+static char *prefix;
+static table_t *group_table, *dset_table, *type_table;
+
+
/*****************************************************************************
@@ -256,6 +269,7 @@ main(int argc, char *argv[])
return status;
}
+
/*****************************************************************************
@@ -304,6 +318,11 @@ int h5toh4(char *h5_filename, char *h4_filename)
void *edata;
hid_t (*func)(void*);
+
+ find_objs_t *info = malloc(sizeof(find_objs_t));
+
+
+
/* open hdf5 file */
if ((fid = H5Fopen (h5_filename, H5F_ACC_RDONLY, plist)) <= 0) {
fprintf(stderr,"Error: Unable to open file %s\n",h5_filename);
@@ -339,14 +358,28 @@ int h5toh4(char *h5_filename, char *h4_filename)
}
/* allocate and initialize internal data structure */
- init_table();
+ init_table(&group_table);
+ init_table(&type_table);
+ init_table(&dset_table);
+ init_prefix(&prefix, prefix_len);
+
+ /* init the find_objs_t*/
+ info->threshold = 0;
+ info->prefix_len = prefix_len;
+ info->prefix = prefix;
+ info->group_table = group_table;
+ info->type_table = type_table;
+ info->dset_table = dset_table;
+ info->status = status;
+
+
/* Disable error reporting */
H5Eget_auto (&func, &edata);
H5Eset_auto (NULL, NULL);
/* find all objects one time */
- if ((status = H5Giterate(fid, "/", NULL, (H5G_operator_t)H5findobj_once, NULL)) != SUCCEED ) {
+ if ((status = H5Giterate(fid, "/", NULL, (H5G_operator_t)find_objs, (void*)info)) != SUCCEED ) {
fprintf(stderr,"Error: Unable to iterate over all of the groups\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "h5toh4", __FILE__, __LINE__);
}
@@ -413,7 +446,9 @@ int h5toh4(char *h5_filename, char *h4_filename)
}
done:
- free_table();
+ free_table(&group_table);
+ free_table(&dset_table);
+ free_table(&type_table);
return status;
@@ -499,13 +534,13 @@ H5G_stat_t statbuf;
} else {
- if ((idx = get_table_idx(H5G_GROUP, statbuf.objno)) < 0 ) {
+ if ((idx = get_table_idx(group_table, statbuf.objno)) < 0 ) {
fprintf(stderr,"Error: object not found, %s\n",name);
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
status = FAIL;
- } else if((flag = get_tableflag(H5G_GROUP,idx)) < 0 ) {
+ } else if((flag = get_tableflag(group_table,idx)) < 0 ) {
fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
@@ -522,7 +557,7 @@ H5G_stat_t statbuf;
} else { /* flag == FALSE */
/* this is now being converted */
- if ((status = set_tableflag(H5G_GROUP,idx)) < 0 ) {
+ if ((status = set_tableflag(group_table,idx)) < 0 ) {
fprintf(stderr,"Error: set_tableflag should never return < 0\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_group", __FILE__, __LINE__);
return(status);
@@ -1357,13 +1392,13 @@ convert_all (hid_t group, char *name, op_data_t *op_data)
if (statbuf.type==H5G_DATASET ) {
- if ((idx = get_table_idx(H5G_DATASET, statbuf.objno)) < 0 ) {
+ if ((idx = get_table_idx(dset_table, statbuf.objno)) < 0 ) {
fprintf(stderr,"Error: object not found\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
status = FAIL;
- } else if((flag = get_tableflag(H5G_DATASET,idx)) < 0 ) {
+ } else if((flag = get_tableflag(dset_table,idx)) < 0 ) {
fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
@@ -1407,7 +1442,7 @@ convert_all (hid_t group, char *name, op_data_t *op_data)
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
status = FAIL;
}
- if(( status = set_tableflag(H5G_DATASET,idx)) != SUCCEED ) {
+ if(( status = set_tableflag(dset_table,idx)) != SUCCEED ) {
fprintf(stderr,"Error: set_tableflag() did not work for %s\n", name);
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
break;
@@ -1424,13 +1459,13 @@ convert_all (hid_t group, char *name, op_data_t *op_data)
} else if (statbuf.type==H5G_GROUP ) {
- if ((idx = get_table_idx(H5G_GROUP, statbuf.objno)) < 0 ) {
+ if ((idx = get_table_idx(group_table, statbuf.objno)) < 0 ) {
fprintf(stderr,"Error: object not found\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
status = FAIL;
- } else if((flag = get_tableflag(H5G_GROUP,idx)) < 0 ) {
+ } else if((flag = get_tableflag(group_table,idx)) < 0 ) {
fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
@@ -1474,13 +1509,13 @@ convert_all (hid_t group, char *name, op_data_t *op_data)
case H5G_GROUP:
- if ((idx = get_table_idx(H5G_GROUP, statbuf.objno)) < 0 ) {
+ if ((idx = get_table_idx(group_table, statbuf.objno)) < 0 ) {
fprintf(stderr,"Error: object not found\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
status = FAIL;
- } else if((flag = get_tableflag(H5G_GROUP,idx)) < 0 ) {
+ } else if((flag = get_tableflag(group_table,idx)) < 0 ) {
fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
@@ -1522,13 +1557,13 @@ convert_all (hid_t group, char *name, op_data_t *op_data)
case H5G_DATASET:
- if ((idx = get_table_idx(H5G_DATASET, statbuf.objno)) < 0 ) {
+ if ((idx = get_table_idx(dset_table, statbuf.objno)) < 0 ) {
fprintf(stderr,"Error: object not found\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
status = FAIL;
- } else if((flag = get_tableflag(H5G_DATASET,idx)) < 0 ) {
+ } else if((flag = get_tableflag(dset_table,idx)) < 0 ) {
fprintf(stderr,"Error: get_tableflag() should never return < 0\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
@@ -1572,7 +1607,7 @@ convert_all (hid_t group, char *name, op_data_t *op_data)
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
status = FAIL;
}
- if(( status = set_tableflag(H5G_DATASET,idx)) != SUCCEED ) {
+ if(( status = set_tableflag(dset_table,idx)) != SUCCEED ) {
fprintf(stderr,"Error: set_tableflag() did not work for %s\n", name);
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_all", __FILE__, __LINE__);
break;
@@ -1641,7 +1676,7 @@ convert_shared_dataset(hid_t did, int idx, op_data_t *op_data)
vgroup_id = op_data->vgroup_id;
- if ((dataset_name = get_objectname(H5G_DATASET, idx)) == NULL ) {
+ if ((dataset_name = get_objectname(dset_table, idx)) == NULL ) {
fprintf(stderr,"Error: get_objectname() did not work\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_dataset", __FILE__, __LINE__);
return (status);
@@ -1804,7 +1839,7 @@ convert_shared_group (hid_t group, int idx, op_data_t *op_data) {
group2 = group;
hfile_id = op_data->hfile_id;
- if ((group_name = get_objectname(H5G_GROUP, idx)) == NULL ) {
+ if ((group_name = get_objectname(group_table, idx)) == NULL ) {
fprintf(stderr,"Error: get_objectname() did not work\n");
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_shared_group", __FILE__, __LINE__);
status = FAIL;
@@ -2340,7 +2375,7 @@ hid_t h4type_to_memtype(int32 h4_datatype)
case DFNT_INT32:
case DFNT_NINT32:
case DFNT_LINT32:
- mem_datatype = H5T_NATIVE_INT; break;
+ mem_datatype = H5T_NATIVE_INT; break;
case DFNT_UINT32:
case DFNT_NUINT32:
case DFNT_LUINT32:
diff --git a/tools/h5toh4.h b/tools/h5toh4.h
index 4436288..edc4b52 100644
--- a/tools/h5toh4.h
+++ b/tools/h5toh4.h
@@ -1,8 +1,8 @@
#ifndef _H5TOH4_H
#define _H5TOH4_H
-#include <hdf5.h>
#include <mfhdf.h>
+#include <hdf5.h>
/*
* Copyright © 1998 NCSA
diff --git a/tools/h5tools.c b/tools/h5tools.c
index 5095bf2..a71116b 100644
--- a/tools/h5tools.c
+++ b/tools/h5tools.c
@@ -25,25 +25,9 @@
int indent = 0;
int compound_data=0;
int nCols = 80;
-ProgType programtype = UNKNOWN;
-static void display_numeric_data(hsize_t hs_nelmts, hid_t p_type,
- unsigned char *sm_buf, size_t p_type_nbytes,
- hsize_t p_nelmts, hsize_t dim_n_size,
- hsize_t elmtno, hid_t container);
-static void display_string(hsize_t hs_nelmts, hid_t p_type,
- unsigned char *sm_buf, size_t p_type_nbytes,
- hsize_t p_nelmts, hsize_t dim_n_size,
- hsize_t elmtno);
-static void display_compound_data(hsize_t hs_nelmts, hid_t p_type,
- unsigned char *sm_buf, size_t p_type_nbytes,
- hsize_t p_nelmts, hsize_t elmtno);
-#if 0
-static void display_reference_data(hsize_t hs_nelmts, hid_t p_type,
- unsigned char *sm_buf, size_t p_type_nbytes,
- hsize_t p_nelmts, hsize_t dim_n_size,
- hsize_t elmtno, hid_t container);
-#endif
-int h5dump_attr(hid_t oid, hid_t ptype);
+
+
+
int print_data(hid_t oid, hid_t _p_type, int obj_data);
@@ -61,12 +45,6 @@ int print_data(hid_t oid, hid_t _p_type, int obj_data);
#define REPEAT_VERBOSE
/*
- * This is the original value of the repeat_threshold in the h5dump_sprint
- * function.
- */
-#define H5DEFAULT_REPEAT_THRESHOLD 8
-
-/*
* 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
@@ -83,6 +61,9 @@ int print_data(hid_t oid, hid_t _p_type, int obj_data);
#define START_OF_DATA 0x0001
#define END_OF_DATA 0x0002
+/* Special strings embedded in the output */
+#define OPTIONAL_LINE_BREAK "\001"
+
/* Variable length string datatype */
#define STR_INIT_LEN 4096 /*initial length */
typedef struct h5dump_str_t {
@@ -91,12 +72,10 @@ typedef struct h5dump_str_t {
size_t nalloc; /*allocated size of string */
} h5dump_str_t;
-/* Special strings embedded in the output */
-#define OPTIONAL_LINE_BREAK "\001"
-
/* Output variables */
typedef struct h5dump_context_t {
size_t cur_column; /*current column for output */
+ size_t cur_elmt; /*current element/output line */
int need_prefix; /*is line prefix needed? */
int ndims; /*dimensionality */
hsize_t p_min_idx[H5S_MAX_RANK]; /*min selected index */
@@ -104,8 +83,29 @@ typedef struct h5dump_context_t {
int prev_multiline; /*was prev datum multiline? */
size_t prev_prefix_len;/*length of previous prefix */
int continuation; /*continuation of previous data?*/
+ int size_last_dim; /*the size of the last dimension,
+ *needed so we can break after each
+ *row */
+ int indent_level; /*the number of times we need some
+ extra indentation */
+ int default_indent_level; /*this is used when the indent level gets changed*/
} h5dump_context_t;
-
+
+typedef herr_t (*H5G_operator_t)(hid_t, const char*, void*);
+
+
+
+extern void init_prefix(char **temp, int length);
+extern void init_table(table_t **table);
+extern void free_table(table_t **table);
+extern void dump_table(char *name, table_t* table);
+extern herr_t find_objs(hid_t group, const char *name, void *op_data);
+extern int search_obj (table_t *temp, unsigned long *);
+extern int get_table_idx(table_t *table, unsigned long *);
+extern int get_tableflag(table_t*, int);
+extern int set_tableflag(table_t*, int);
+extern char* get_objectname(table_t*, int);
+
/*-------------------------------------------------------------------------
* Function: h5dump_str_close
@@ -500,7 +500,7 @@ h5dump_is_zero(const void *_mem, size_t size)
*-------------------------------------------------------------------------
*/
static int
-h5dump_region(hid_t region, h5dump_str_t *str/*in,out*/)
+h5dump_region(hid_t region, h5dump_str_t *str/*in,out*/, const h5dump_t *info)
{
hssize_t nblocks, npoints, i;
hsize_t *ptdata;
@@ -523,16 +523,11 @@ h5dump_region(hid_t region, h5dump_str_t *str/*in,out*/)
ptdata = malloc(nblocks*ndims*2*sizeof(ptdata[0]));
H5Sget_select_hyper_blocklist(region, 0, nblocks, ptdata);
for (i=0; i<nblocks; i++) {
- if (programtype == H5DUMP) {
- h5dump_str_append(str, "%s",
- i?","OPTIONAL_LINE_BREAK" ":"",
- (unsigned long)i);
- }
- else {
- h5dump_str_append(str, "%sBlk%lu: ",
+
+ h5dump_str_append(str, info->dset_blockformat_pre,
i?","OPTIONAL_LINE_BREAK" ":"",
(unsigned long)i);
- }
+
/* Start coordinates and opposite corner */
for (j=0; j<ndims; j++) {
h5dump_str_append(str, "%s%lu", j?",":"(",
@@ -552,16 +547,11 @@ h5dump_region(hid_t region, h5dump_str_t *str/*in,out*/)
ptdata = malloc(npoints*ndims*sizeof(ptdata[0]));
H5Sget_select_elem_pointlist(region, 0, npoints, ptdata);
for (i=0; i<npoints; i++) {
- if (programtype == H5DUMP){
- h5dump_str_append(str, "%s",
- i?","OPTIONAL_LINE_BREAK" ":"",
- (unsigned long)i);
- }
- else {
- h5dump_str_append(str, "%sPt%lu: ",
+
+ h5dump_str_append(str, info->dset_ptformat_pre ,
i?","OPTIONAL_LINE_BREAK" ":"",
(unsigned long)i);
- }
+
for (j=0; j<ndims; j++) {
h5dump_str_append(str, "%s%lu", j?",":"(",
(unsigned long)(ptdata[i*ndims+j]));
@@ -604,16 +594,15 @@ h5dump_region(hid_t region, h5dump_str_t *str/*in,out*/)
*/
static char *
h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
- hid_t container, hid_t type, void *vp)
+ hid_t container, hid_t type, void *vp, h5dump_context_t *ctx)
{
size_t i, n, offset, size, dims[H5S_MAX_RANK], nelmts, start;
char *name, quote='\0';
hid_t memb, obj, region;
- int nmembs, j, k, ndims, otype;
+ int nmembs, x, j, k, ndims, otype;
static char fmt_llong[8], fmt_ullong[8];
H5T_str_t pad;
H5G_stat_t sb;
- int repeat_threshold = H5DEFAULT_REPEAT_THRESHOLD;
/*some tempvars to store the value before we append it to the string
to get rid of the memory alignment problem*/
@@ -627,11 +616,7 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
unsigned long tempulong;
unsigned long_long tempullong;
long_long templlong;
-
- if (programtype == H5DUMP){
- repeat_threshold = -1; /*-1 means any amount of repeat allowed*/
- }
-
+
/* Build default formats for long long types */
if (!fmt_llong[0]) {
sprintf(fmt_llong, "%%%sd", PRINTF_LL_WIDTH);
@@ -652,75 +637,81 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
} else if (H5Tequal(type, H5T_NATIVE_DOUBLE)) {
memcpy(&tempdouble,vp,sizeof(double));
h5dump_str_append(str, OPT(info->fmt_double, "%g"), tempdouble);
-
} else if (H5Tequal(type, H5T_NATIVE_FLOAT)) {
memcpy(&tempfloat,vp,sizeof(float));
h5dump_str_append(str, OPT(info->fmt_double, "%g"), tempfloat);
-
-
+
} else if (info->ascii &&
(H5Tequal(type, H5T_NATIVE_SCHAR) ||
H5Tequal(type, H5T_NATIVE_UCHAR))) {
- switch (*((char*)vp)) {
- case '"':
- h5dump_str_append(str, "\\\"");
- break;
- case '\\':
- h5dump_str_append(str, "\\\\");
- break;
- case '\b':
- h5dump_str_append(str, "\\b");
- break;
- case '\f':
- h5dump_str_append(str, "\\f");
- break;
- case '\n':
- h5dump_str_append(str, "\\n");
- break;
- case '\r':
- h5dump_str_append(str, "\\r");
- break;
- case '\t':
- h5dump_str_append(str, "\\t");
- break;
- default:
- if (isprint((int)(*((char*)vp)))) {
- h5dump_str_append(str, "%c", *((char*)vp));
+ if (ESCAPE_HTML==info->str_locale) {
+ if (*((char*)vp)<=' ' || *((char*)vp)>'~') {
+ h5dump_str_append(str, "%%%02X", *((unsigned char*)vp));
} else {
- h5dump_str_append(str, "\\%03o", *((unsigned char*)vp));
+ h5dump_str_append(str, "%c", *((char*)vp));
+ }
+ } else {
+ switch (*((char*)vp)) {
+ case '"':
+ h5dump_str_append(str, "\\\"");
+ break;
+ case '\\':
+ h5dump_str_append(str, "\\\\");
+ break;
+ case '\b':
+ h5dump_str_append(str, "\\b");
+ break;
+ case '\f':
+ h5dump_str_append(str, "\\f");
+ break;
+ case '\n':
+ h5dump_str_append(str, "\\n");
+ break;
+ case '\r':
+ h5dump_str_append(str, "\\r");
+ break;
+ case '\t':
+ h5dump_str_append(str, "\\t");
+ break;
+ default:
+ if (isprint(*((char*)vp))) {
+ h5dump_str_append(str, "%c", *((char*)vp));
+ } else {
+ h5dump_str_append(str, "\\%03o", *((unsigned char*)vp));
+ }
+ break;
}
- break;
}
-
+
} else if (H5T_STRING==H5Tget_class(type)) {
size = H5Tget_size(type);
quote = '\0';
pad = H5Tget_strpad(type);
-
+
for (i=0;
i<size && ((pad == H5T_STR_NULLPAD)?1:(((char*)vp)[i] != '\0'));
i++) {
-
+
+
/*
* Count how many times the next character repeats. If the
- * threshold is negative then that means it can repeat any number
+ * threshold is zero then that means it can repeat any number
* of times.
*/
- if (repeat_threshold >= 0) {
- j=1;
+ j=1;
+ if (info->str_repeat>0) {
while (i+j<size && ((char*)vp)[i]==((char*)vp)[i+j]) j++;
- } else {
- j = repeat_threshold - 1;
}
+
/*
* 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 (j>repeat_threshold) {
+ if (info->str_repeat>0 && j>info->str_repeat) {
if (quote) h5dump_str_append(str, "%c", quote);
quote = '\'';
h5dump_str_append(str, "%s%c", i?" ":"", quote);
@@ -730,39 +721,48 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
}
/* Print the character */
- switch (((char*)vp)[i]) {
- case '"':
- h5dump_str_append(str, "\\\"");
- break;
- case '\\':
- h5dump_str_append(str, "\\\\");
- break;
- case '\b':
- h5dump_str_append(str, "\\b");
- break;
- case '\f':
- h5dump_str_append(str, "\\f");
- break;
- case '\n':
- h5dump_str_append(str, "\\n");
- break;
- case '\r':
- h5dump_str_append(str, "\\r");
- break;
- case '\t':
- h5dump_str_append(str, "\\t");
- break;
- default:
- if (isprint((int)((char*)vp)[i])) {
- h5dump_str_append(str, "%c", ((char*)vp)[i]);
+ if (ESCAPE_HTML==info->str_locale) {
+ if (((char*)vp)[i]<=' ' || ((char*)vp)[i]>'~') {
+ h5dump_str_append(str, "%%%02X", ((unsigned char*)vp)[i]);
} else {
- h5dump_str_append(str, "\\%03o", ((unsigned char*)vp)[i]);
+ h5dump_str_append(str, "%c", ((char*)vp)[i]);
+ }
+ } else {
+ switch (((char*)vp)[i]) {
+ case '"':
+ h5dump_str_append(str, "\\\"");
+ break;
+ case '\\':
+ h5dump_str_append(str, "\\\\");
+ break;
+ case '\b':
+ h5dump_str_append(str, "\\b");
+ break;
+ case '\f':
+ h5dump_str_append(str, "\\f");
+ break;
+ case '\n':
+ h5dump_str_append(str, "\\n");
+ break;
+ case '\r':
+ h5dump_str_append(str, "\\r");
+ break;
+ case '\t':
+ h5dump_str_append(str, "\\t");
+ break;
+ default:
+ if (isprint(((char*)vp)[i])) {
+ h5dump_str_append(str, "%c", ((char*)vp)[i]);
+ } else {
+ h5dump_str_append(str, "\\%03o",
+ ((unsigned char*)vp)[i]);
+ }
+ break;
}
- break;
}
-
+
/* Print the repeat count */
- if (j>repeat_threshold) {
+ if (info->str_repeat && j>info->str_repeat) {
#ifdef REPEAT_VERBOSE
h5dump_str_append(str, "%c repeats %d times", quote, j-1);
#else
@@ -771,8 +771,14 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
quote = '\0';
i += j-1;
}
+
}
if (quote) h5dump_str_append(str, "%c", quote);
+
+ if (0==i) {
+ h5dump_str_append(str, "\"\""); /*empty string*/
+ }
+
} else if (H5Tequal(type, H5T_NATIVE_INT)) {
memcpy(&tempint, vp, sizeof(int));
@@ -782,7 +788,7 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
} else if (H5Tequal(type, H5T_NATIVE_UINT)) {
memcpy(&tempuint, vp, sizeof(unsigned int));
h5dump_str_append(str, OPT(info->fmt_uint, "%u"),
- tempuint);
+ tempuint);
} else if (H5Tequal(type, H5T_NATIVE_SCHAR)) {
h5dump_str_append(str, OPT(info->fmt_schar, "%d"),
@@ -802,7 +808,6 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
h5dump_str_append(str, OPT(info->fmt_ushort, "%u"),
tempushort);
-
} else if (H5Tequal(type, H5T_NATIVE_LONG)) {
memcpy(&templong, vp, sizeof(long));
h5dump_str_append(str, OPT(info->fmt_long, "%ld"),
@@ -812,7 +817,7 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
memcpy(&tempulong, vp, sizeof(unsigned long));
h5dump_str_append(str, OPT(info->fmt_ulong, "%lu"),
tempulong);
-
+
} else if (H5Tequal(type, H5T_NATIVE_LLONG)) {
memcpy(&templlong, vp, sizeof(long_long));
h5dump_str_append(str, OPT(info->fmt_llong, fmt_llong),
@@ -827,7 +832,7 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
if (sizeof(hssize_t)==sizeof(int)) {
memcpy(&tempint, vp, sizeof(int));
h5dump_str_append(str, OPT(info->fmt_int, "%d"),
- tempint);
+ tempint);
} else if (sizeof(hssize_t)==sizeof(long)) {
memcpy(&templong, vp, sizeof(long));
h5dump_str_append(str, OPT(info->fmt_long, "%ld"),
@@ -846,7 +851,7 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
} else if (sizeof(hsize_t)==sizeof(long)) {
memcpy(&tempulong, vp, sizeof(long));
h5dump_str_append(str, OPT(info->fmt_ulong, "%lu"),
- tempulong);
+ tempulong);
} else {
memcpy(&tempullong, vp, sizeof(unsigned long_long));
h5dump_str_append(str, OPT(info->fmt_ullong, fmt_ullong),
@@ -856,11 +861,20 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
} else if (H5T_COMPOUND==H5Tget_class(type)) {
nmembs = H5Tget_nmembers(type);
h5dump_str_append(str, "%s", OPT(info->cmpd_pre, "{"));
+
+
for (j=0; j<nmembs; j++) {
if (j) h5dump_str_append(str, "%s",
OPT(info->cmpd_sep,
", " OPTIONAL_LINE_BREAK));
-
+
+ /*put code to indent compound type elemnts here*/
+ if (ctx->indent_level >= 0) {
+ h5dump_str_append(str, "%s", OPT(info->line_pre, ""));
+ }
+ for (x=0; x < ctx->indent_level + 1; x++){
+ h5dump_str_append(str,"%s",OPT(info->line_indent,""));
+ }
/* The name */
name = H5Tget_member_name(type, j);
h5dump_str_append(str, OPT(info->cmpd_name, ""), name);
@@ -883,20 +897,44 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
OPT(info->arr_sep,
"," OPTIONAL_LINE_BREAK));
}
+
+ if (ndims>0 && info->arr_linebreak &&
+ i && 0==i%dims[ndims-1]) {
+ h5dump_str_append(str, "%s", "\n");
+ /*need to indent some more here*/
+ if (ctx->indent_level >= 0) {
+ h5dump_str_append(str, "%s", OPT(info->line_pre, ""));
+ }
+ for (x=0; x < ctx->indent_level+1; x++){
+ h5dump_str_append(str,"%s",OPT(info->line_indent,""));
+ }
+ }
h5dump_sprint(str, info, container, memb,
- (char*)vp+offset+i*size);
+ (char*)vp+offset+i*size, ctx);
}
if (nelmts>1) {
h5dump_str_append(str, "%s", OPT(info->arr_suf, "]"));
}
H5Tclose(memb);
}
+
+ h5dump_str_append(str, "%s", OPT(info->cmpd_end, ""));
+
+ /*put code to indent compound type elemnts here*/
+ if (ctx->indent_level >= 0) {
+ h5dump_str_append(str, "%s", OPT(info->line_pre, ""));
+ }
+ for (x=0; x < ctx->indent_level; x++){
+ h5dump_str_append(str,"%s",OPT(info->line_indent,""));
+ }
+
h5dump_str_append(str, "%s", OPT(info->cmpd_suf, "}"));
} else if (H5T_ENUM==H5Tget_class(type)) {
char enum_name[1024];
if (H5Tenum_nameof(type, vp, enum_name, sizeof enum_name)>=0) {
- h5dump_str_append(str, h5dump_escape(enum_name, sizeof enum_name, TRUE));
+ h5dump_str_append(str, h5dump_escape(enum_name, sizeof enum_name,
+ TRUE));
} else {
h5dump_str_append(str, "0x");
n = H5Tget_size(type);
@@ -917,15 +955,15 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
obj = H5Rdereference(container, H5R_DATASET_REGION, vp);
region = H5Rget_region(container, H5R_DATASET_REGION, vp);
H5Gget_objinfo(obj, ".", FALSE, &sb);
- if (programtype == H5DUMP) {
- h5dump_str_append(str, "%s %lu:%lu ",DATASET,sb.objno[1], sb.objno[0]);
- }
- else {
- h5dump_str_append(str, "DSET-%lu:%lu:%lu:%lu-",
- sb.fileno[1], sb.fileno[0],
- sb.objno[1], sb.objno[0]);
- }
- h5dump_region(region, str);
+ if (info->dset_hidefileno){
+ h5dump_str_append(str, info->dset_format,
+ sb.objno[1], sb.objno[0]);
+ } else {
+ h5dump_str_append(str, info->dset_format,
+ sb.fileno[1], sb.fileno[0],
+ sb.objno[1], sb.objno[0]);
+ }
+ h5dump_region(region, str, info);
H5Sclose(region);
H5Dclose(obj);
}
@@ -957,26 +995,19 @@ h5dump_sprint(h5dump_str_t *str/*in,out*/, const h5dump_t *info,
H5Tclose(obj);
break;
default:
- if (programtype == H5LS) {
- h5dump_str_append(str, "%u-", otype);
- }
- else if (programtype == H5DUMP) {
- h5dump_str_append(str, "unknown object reference type");
- }
- /* unable to close `obj' since we don't know the type */
- break;
+ h5dump_str_append(str, "%u-", otype);
+ break;
}
/* Print OID */
- if (programtype == H5DUMP) {
- h5dump_str_append(str, " %lu:%lu",
- sb.objno[1], sb.objno[0]);
- }
- else {
- h5dump_str_append(str, "-%lu:%lu:%lu:%lu",
- sb.fileno[1], sb.fileno[0],
- sb.objno[1], sb.objno[0]);
- }
+ if (info->obj_hidefileno){
+ h5dump_str_append(str, info->obj_format,
+ sb.objno[1], sb.objno[0]);
+ } else {
+ h5dump_str_append(str, info->obj_format,
+ sb.fileno[1], sb.fileno[0],
+ sb.objno[1], sb.objno[0]);
+ }
}
} else {
@@ -1033,7 +1064,9 @@ h5dump_ncols(const char *s)
* Monday, April 26, 1999
*
* Modifications:
- *
+ * Robb Matzke, 1999-09-29
+ * If a new prefix is printed then the current element number is
+ * set back to zero.
*-------------------------------------------------------------------------
*/
static void
@@ -1041,14 +1074,21 @@ h5dump_simple_prefix(FILE *stream, const h5dump_t *info,
h5dump_context_t *ctx, hsize_t elmtno, int secnum)
{
h5dump_str_t prefix;
-
+ int i, templength = 0;
+ int indentlevel = 0;
+
memset(&prefix, 0, sizeof(h5dump_str_t));
if (!ctx->need_prefix) return;
/* Terminate previous line, if any */
if (ctx->cur_column) {
fputs(OPT(info->line_suf, ""), stream);
- putc('\n', stream);
+#if 0 /*why?*/
+ if (info->line_ncols != ctx->cur_column) {
+ putc('\n', stream);
+ }
+#endif
+ putc('\n',stream);
fputs(OPT(info->line_sep, ""), stream);
}
@@ -1057,17 +1097,35 @@ h5dump_simple_prefix(FILE *stream, const h5dump_t *info,
ctx->p_min_idx, ctx->p_max_idx);
/* Write new prefix to output */
- if (0==elmtno && 0==secnum && info->line_1st) {
- fputs(h5dump_str_fmt(&prefix, 0, info->line_1st),
- stream);
- } else if (secnum && info->line_cont) {
- fputs(h5dump_str_fmt(&prefix, 0, info->line_cont),
- stream);
+ if (ctx->indent_level >= 0) {
+ indentlevel = ctx->indent_level;
} else {
- fputs(h5dump_str_fmt(&prefix, 0, info->line_pre),
- stream);
+ /* this is because sometimes we dont print out all the header
+ * info for the data(like the tattr-2.ddl example. if that happens
+ * the ctx->indent_level a negative so we need to skip the above
+ * and just print out the default indent levels. */
+ indentlevel = ctx->default_indent_level;
}
- ctx->cur_column = ctx->prev_prefix_len = h5dump_str_len(&prefix);
+
+ if (0==elmtno && 0==secnum && info->line_1st) {
+ fputs(h5dump_str_fmt(&prefix, 0, info->line_1st), stream);
+ } else if (secnum && info->line_cont) {
+ fputs(h5dump_str_fmt(&prefix, 0, info->line_cont),
+ stream);
+ } else {
+ fputs(h5dump_str_fmt(&prefix, 0, info->line_pre), stream);
+ }
+ templength = h5dump_str_len(&prefix);
+ for (i = 0; i < indentlevel; i++){
+ fputs(h5dump_str_fmt(&prefix, 0, info->line_indent), stream);
+ templength += h5dump_str_len(&prefix);
+ }
+
+
+
+ ctx->cur_column = ctx->prev_prefix_len = templength;
+
+ ctx->cur_elmt = 0;
ctx->need_prefix = 0;
/* Free string */
@@ -1097,6 +1155,10 @@ h5dump_simple_prefix(FILE *stream, const h5dump_t *info,
* 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.
+ *
*-------------------------------------------------------------------------
*/
static void
@@ -1112,18 +1174,24 @@ h5dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container,
size_t ncols=80; /*available output width */
h5dump_str_t buffer; /*string into which to render */
int multiline; /*datum was multiline */
-
+ int elmt_counter=0; /*counts the # elements printed.
+ * I (ptl?) needed something that
+ * isnt 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. */
+
/* Setup */
memset(&buffer, 0, sizeof(h5dump_str_t));
size = H5Tget_size(type);
if (info->line_ncols>0) ncols = info->line_ncols;
h5dump_simple_prefix(stream, info, ctx, 0, 0);
- for (i=0; i<nelmts; i++) {
-
+ for (i=0; i<nelmts; i++, ctx->cur_elmt++, elmt_counter++){
/* Render the element */
h5dump_str_reset(&buffer);
- h5dump_sprint(&buffer, info, container, type, mem+i*size);
+ h5dump_sprint(&buffer, info, container, type, mem+i*size, ctx);
if (i+1<nelmts || 0==(flags & END_OF_DATA)) {
h5dump_str_append(&buffer, "%s", OPT(info->elmt_suf1, ","));
}
@@ -1155,6 +1223,21 @@ h5dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container,
}
}
+ /* we need to break after each row of a dimension---> we should
+ * break at the end of the each last dimension well that is the
+ * way the dumper did it before */
+ if (info->arr_linebreak && ctx->cur_elmt){
+ if ((ctx->cur_elmt%ctx->size_last_dim) == 0){
+ ctx->need_prefix = TRUE;
+ }
+
+ if (elmt_counter==ctx->size_last_dim){
+ ctx->need_prefix = TRUE;
+ elmt_counter = 0;
+ }
+ }
+
+
/*
* If the previous element occupied multiple lines and this element
* is too long to fit on a line then start this element at the
@@ -1167,6 +1250,14 @@ h5dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container,
strlen(OPT(info->line_suf, ""))) > ncols) {
ctx->need_prefix = TRUE;
}
+
+ /*
+ * If too many elements have already been printed then we need to
+ * start a new line.
+ */
+ if (info->line_per_line>0 && ctx->cur_elmt>=info->line_per_line) {
+ ctx->need_prefix = TRUE;
+ }
/*
* Each OPTIONAL_LINE_BREAK embedded in the rendered string can cause
@@ -1181,7 +1272,10 @@ h5dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container,
* information would cause the output to wrap then we need to
* start a new line.
*/
- if ((ctx->cur_column + strlen(section) +
+ /* added the info->skip_first because the dumper does not want
+ * this check to happen for the first line */
+ if ((!info->skip_first || i) &&
+ (ctx->cur_column + strlen(section) +
strlen(OPT(info->elmt_suf2, " ")) +
strlen(OPT(info->line_suf, ""))) > ncols) {
ctx->need_prefix = 1;
@@ -1202,6 +1296,7 @@ h5dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container,
/* Print the section */
fputs(section, stream);
ctx->cur_column += strlen(section);
+
}
ctx->prev_multiline = multiline;
}
@@ -1233,7 +1328,7 @@ h5dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container,
*/
static int
h5dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset,
- hid_t p_type)
+ hid_t p_type, int indentlevel)
{
hid_t f_space; /*file data space */
hsize_t elmtno, i; /*counters */
@@ -1259,7 +1354,9 @@ h5dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset,
hsize_t hs_size[H5S_MAX_RANK]; /*size this pass */
hsize_t hs_nelmts; /*elements in request */
+#if 0
hsize_t dim_n_size;
+#endif
/*
* Check that everything looks okay. The dimensionality must not be too
@@ -1267,6 +1364,8 @@ h5dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset,
* match the dimensionality of the dataset.
*/
memset(&ctx, 0, sizeof ctx);
+ ctx.indent_level = indentlevel;
+ ctx.indent_level = indentlevel;
ctx.need_prefix = 1;
f_space = H5Dget_space(dset);
ctx.ndims = H5Sget_simple_extent_ndims(f_space);
@@ -1280,6 +1379,7 @@ h5dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset,
}
if (0==p_nelmts) return 0; /*nothing to print*/
+ ctx.size_last_dim = total_size[ctx.ndims-1];
/*
* Determine the strip mine size and allocate a buffer. The strip mine is
* a hyperslab whose size is manageable.
@@ -1310,12 +1410,16 @@ h5dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset,
hs_size, NULL);
H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL,
&hs_nelmts, NULL);
+#if 0
dim_n_size = total_size[ctx.ndims-1];
+#endif
} else {
H5Sselect_all(f_space);
H5Sselect_all(sm_space);
hs_nelmts = 1;
+#if 0
dim_n_size = 1;
+#endif
}
/* Read the data */
@@ -1324,67 +1428,12 @@ h5dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset,
}
/* Print the data */
- flags = ((0==elmtno?START_OF_DATA:0) |
- (elmtno+hs_nelmts>=p_nelmts?END_OF_DATA:0));
- if (programtype == UNKNOWN){
- return FAIL;
- } else if (programtype == H5LS){
- h5dump_simple_data(stream, info, dset, &ctx, flags, hs_nelmts,
- p_type, sm_buf);
- } else if (programtype == H5DUMP){
- switch (H5Tget_class(p_type)) {
- case H5T_INTEGER:
- display_numeric_data (hs_nelmts, p_type, sm_buf, p_type_nbytes,
- p_nelmts, dim_n_size, elmtno, dset);
- break;
-
- case H5T_FLOAT:
- display_numeric_data (hs_nelmts, p_type, sm_buf, p_type_nbytes,
- p_nelmts, dim_n_size, elmtno, dset);
- break;
-
- case H5T_TIME:
- break;
-
- case H5T_STRING:
- display_string (hs_nelmts, p_type, sm_buf, p_type_nbytes,
- p_nelmts, dim_n_size, elmtno);
- break;
-
- case H5T_BITFIELD:
- break;
-
- case H5T_OPAQUE:
- break;
-
- case H5T_COMPOUND:
- compound_data = 1;
- display_compound_data (hs_nelmts, p_type, sm_buf,
- p_type_nbytes, p_nelmts, elmtno);
- compound_data = 0;
- break;
-
- case H5T_REFERENCE:
- display_numeric_data(hs_nelmts, p_type, sm_buf, p_type_nbytes,
- p_nelmts, dim_n_size, elmtno, dset);
- break;
-#if 0
- display_reference_data(hs_nelmts, p_type, sm_buf,
- p_type_nbytes, p_nelmts, dim_n_size,
- elmtno, dset);
-#endif
- case H5T_ENUM:
- display_numeric_data(hs_nelmts, p_type, sm_buf,
- p_type_nbytes, p_nelmts, dim_n_size,
- elmtno, dset);
- break;
+ flags = ((0==elmtno ? START_OF_DATA : 0) |
+ (elmtno+hs_nelmts>=p_nelmts ? END_OF_DATA : 0));
+ h5dump_simple_data(stream, info, dset, &ctx, flags, hs_nelmts,
+ p_type, sm_buf);
+
- default:
- break;
- }
-
- }
-
/* 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];
@@ -1430,12 +1479,11 @@ h5dump_simple_dset(FILE *stream, const h5dump_t *info, hid_t dset,
*/
static int
h5dump_simple_mem(FILE *stream, const h5dump_t *info, hid_t type,
- hid_t space, void *mem)
+ hid_t space, void *mem, int indentlevel)
{
hsize_t i; /*counters */
- size_t size; /*size of each element */
hsize_t nelmts; /*total selected elmts */
- h5dump_context_t ctx; /*printing context */
+ h5dump_context_t ctx; /*printing context */
/*
* Check that everything looks okay. The dimensionality must not be too
@@ -1443,6 +1491,7 @@ h5dump_simple_mem(FILE *stream, const h5dump_t *info, hid_t type,
* match the dimensionality of the dataset.
*/
memset(&ctx, 0, sizeof ctx);
+ ctx.indent_level = indentlevel;
ctx.need_prefix = 1;
ctx.ndims = H5Sget_simple_extent_ndims(space);
if ((size_t)(ctx.ndims)>NELMTS(ctx.p_min_idx)) return -1;
@@ -1450,11 +1499,15 @@ h5dump_simple_mem(FILE *stream, const h5dump_t *info, hid_t type,
/* Assume entire data space to be printed */
for (i=0; i<(hsize_t)(ctx.ndims); i++) ctx.p_min_idx[i] = 0;
H5Sget_simple_extent_dims(space, ctx.p_max_idx, NULL);
+
+
for (i=0, nelmts=1; i<(hsize_t)(ctx.ndims); i++) {
nelmts *= ctx.p_max_idx[i] - ctx.p_min_idx[i];
}
if (0==nelmts) return 0; /*nothing to print*/
- size = H5Tget_size(type);
+
+ ctx.size_last_dim = ctx.p_max_idx[ctx.ndims-1];
+ ctx.indent_level = indentlevel;
/* Print it */
h5dump_simple_data(stream, info, -1/*no dataset*/, &ctx,
@@ -1546,26 +1599,8 @@ h5dump_fixtype(hid_t f_type)
* strDUAction == TRUE. if it is false we will do the original action
* here.
*/
- if (programtype == H5DUMP) {
- m_type = H5Tcopy(H5T_C_S1);
- H5Tset_size(m_type, size);
- strpad = H5Tget_strpad(f_type) ;
- H5Tset_strpad(m_type, strpad);
-
- if (H5Tequal(m_type,f_type) < 0) {
- H5Tclose(m_type);
- m_type = H5Tcopy(H5T_FORTRAN_S1);
- H5Tset_size(m_type, size);
- H5Tset_strpad(m_type, strpad);
- if (H5Tequal(m_type,f_type) < 0)
- m_type = -1;
- }
- } else if (programtype == H5LS) {
m_type = H5Tcopy(f_type);
H5Tset_cset(m_type, H5T_CSET_ASCII);
- } else if (programtype == UNKNOWN){
- return FAIL;
- }
break;
case H5T_COMPOUND:
@@ -1691,7 +1726,7 @@ h5dump_fixtype(hid_t f_type)
*-------------------------------------------------------------------------
*/
int
-h5dump_dset(FILE *stream, const h5dump_t *info, hid_t dset, hid_t _p_type)
+h5dump_dset(FILE *stream, const h5dump_t *info, hid_t dset, hid_t _p_type, int indentlevel)
{
hid_t f_space;
hid_t p_type = _p_type;
@@ -1722,7 +1757,7 @@ h5dump_dset(FILE *stream, const h5dump_t *info, hid_t dset, hid_t _p_type)
H5Sclose(f_space);
/* Print the data */
- status = h5dump_simple_dset(stream, info, dset, p_type);
+ status = h5dump_simple_dset(stream, info, dset, p_type, indentlevel);
if (p_type!=_p_type) H5Tclose(p_type);
return status;
}
@@ -1748,7 +1783,7 @@ h5dump_dset(FILE *stream, const h5dump_t *info, hid_t dset, hid_t _p_type)
*/
int
h5dump_mem(FILE *stream, const h5dump_t *info, hid_t type, hid_t space,
- void *mem)
+ void *mem,int indentlevel)
{
h5dump_t info_dflt;
@@ -1761,7 +1796,7 @@ h5dump_mem(FILE *stream, const h5dump_t *info, hid_t type, hid_t space,
/* Check the data space */
if (H5Sis_simple(space)<=0) return -1;
- return h5dump_simple_mem(stream, info, type, space, mem);
+ return h5dump_simple_mem(stream, info, type, space, mem, indentlevel);
}
@@ -1784,889 +1819,419 @@ h5dump_mem(FILE *stream, const h5dump_t *info, hid_t type, hid_t space,
/*************************************************************************/
/*************************************************************************/
-/*-------------------------------------------------------------------------
- * Function: display_numeric_data
- *
- * Purpose: Display numeric data in ddl format.
- *
- * Return: void
- *
- * Comment: hs_nelmts number of elements to be printed
- * p_type memory data type
- * sm_buf data buffer
- * p_type_nbytes size of p_type
- * p_nelmts total number of elements
- * dim_n_size size of dimemsion n
- * elmtno element index
- *
- *-------------------------------------------------------------------------
- */
-static void display_numeric_data
-(hsize_t hs_nelmts, hid_t p_type, unsigned char *sm_buf, size_t p_type_nbytes,
- hsize_t p_nelmts, hsize_t dim_n_size, hsize_t elmtno, hid_t container) {
-
-hsize_t i;
-/*char p_buf[256]; */
-char* out_buf = malloc(sizeof(char) * nCols);
-struct h5dump_str_t tempstr;
-hsize_t x;
-hbool_t isref = FALSE;
-hsize_t totalspace;
-hbool_t done;
-int temp;
-
-
-/******************************************************************************************/
- h5dump_t info;
-
- /* Set to all default values and then override */
- memset(&info, 0, sizeof info);
- info.idx_fmt = "(%s)";
- info.line_ncols = nCols;
- info.line_multi_new = 1;
-
- /*
- * 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 ";
-/*********************************************************************************************/
- /* i added this too*/
- if (H5Tequal(p_type, H5T_STD_REF_DSETREG)) {
- isref = TRUE;
- }
-
-
- out_buf[0] = '\0';
- if ((indent+COL) > nCols) indent = 0;
- memset(&tempstr, 0, sizeof(h5dump_str_t));
-
- for (i=0; i<hs_nelmts && (elmtno+i) < p_nelmts; i++) {
- h5dump_str_reset(&tempstr);
- h5dump_sprint(&tempstr, &info, container, p_type, sm_buf+i*p_type_nbytes);
- if (isref) {
- for (x = 0; x <tempstr.len; x++){
- /* removes the strange characters */
- if (tempstr.s[x] == 1){
- memmove(tempstr.s+x, tempstr.s+(x+1), strlen(tempstr.s+x));
- tempstr.len --;
- }
-
- }
- }
- totalspace = nCols - indent - COL;
-
- if ((int)(strlen(out_buf)+tempstr.len+1) > (nCols-indent-COL)) {
- if (isref){
- /* i added this */
- temp = strlen(out_buf);
- if ((strlen(out_buf) + 7) < (totalspace)){ /* 7 for the word dataset */
- memcpy(out_buf+strlen(out_buf), tempstr.s, totalspace - strlen(out_buf));
- out_buf[totalspace] = '\0';
- memmove(tempstr.s, tempstr.s+(totalspace - temp), tempstr.len - (totalspace - temp));
- tempstr.s[tempstr.len - totalspace + temp] = '\0';
- tempstr.len = strlen(tempstr.s);
- }
- }
- /* first row of member */
- if (compound_data && (elmtno+i+1) == dim_n_size)
- printf("%s\n", out_buf);
- else {
- indentation(indent+COL);
- printf("%s\n", out_buf);
- }
- strcpy(out_buf, tempstr.s);
-
- /* i added this too*/
- if (isref) {
- done = FALSE;
- while (!done) {
- if (tempstr.len > totalspace) {
- /* keep printing until we can fit in the totalspace */
- memmove(out_buf,tempstr.s, totalspace);
- out_buf[totalspace] = '\0';
- memmove(tempstr.s,tempstr.s+totalspace, strlen(tempstr.s + totalspace));
- tempstr.s[tempstr.len - totalspace] = '\0';
- tempstr.len = strlen(tempstr.s);
- indentation(indent+COL);
- printf(out_buf);
-
- } else {
- strcpy(out_buf, tempstr.s);
- done = TRUE;
- }
- }
- }
-
- if ((elmtno+i+1) % dim_n_size)
- strcat(out_buf, ", ");
- else { /* end of a row, flush out_buf */
- indentation(indent+COL);
- printf("%s", out_buf);
- if ((elmtno+i+1) != p_nelmts) /* not last element */
- printf(",\n");
- else if (compound_data) { /* last element of member data*/
- if ((nCols-strlen(out_buf)-indent-COL) < 2) {
- /* 2 for space and ] */
- printf("\n");
- indentation(indent+COL-3);
- }
- } else
- printf("\n"); /* last row */
- *out_buf = '\0';
- }
- } else {
- strcat(out_buf, tempstr.s);
- if ((elmtno+i+1) % dim_n_size) {
- if ((nCols-strlen(out_buf)-indent-COL-1) > 0)
- strcat(out_buf, ", ");
- else
- strcat(out_buf, ",");
- } else { /* end of a row */
- /* 1st row of member data */
- if (compound_data && (elmtno+i+1) == dim_n_size)
- printf("%s", out_buf);
- else {
- indentation(indent+COL);
- printf("%s", out_buf);
- }
-
- /* if it's the last element */
- if ((elmtno+i+1) != p_nelmts)
- printf(",\n");
- else if (compound_data) { /* last row of member data*/
- /* 2 for space and ] */
- if ((nCols-strlen(out_buf)-indent-COL) < 2) {
- printf("\n");
- indentation(indent+COL-3);
- }
- } else
- printf("\n"); /* last row */
- *out_buf = '\0';
- }
- }
- }
-#if !defined (WIN32) && !defined (_DEBUG)
- free(out_buf);
-#endif
-}
/*-------------------------------------------------------------------------
- * Function: display_string
+ * Function: indentation
*
- * Purpose: Display string in ddl format
+ * Purpose: Print spaces for indentation
*
- * Return: void
+ * Return: void
*
- * Comment: concatenator operator : '//'
- * separator between elements: ','
+ * Programmer: Ruey-Hsia Li
*
* Modifications:
*
- *-------------------------------------------------------------------------
- */
-static void display_string
-(hsize_t hs_nelmts, hid_t p_type, unsigned char *sm_buf, size_t p_type_nbytes,
- hsize_t p_nelmts, hsize_t dim_n_size, hsize_t elmtno) {
- hsize_t i, row_size=0;
- int j, m, x, y, z, first_row=1;
- int free_space, long_string = 0;
- char* out_buf = malloc(sizeof(char) * nCols);
- struct h5dump_str_t tempstr;
- int temp;
-
-/******************************************************************************************/
- h5dump_t info;
-
- /* Set to all default values and then override */
- memset(&info, 0, sizeof info);
- info.idx_fmt = "(%s)";
- info.line_ncols = nCols;
- info.line_multi_new = 1;
-
- /*
- * 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 ";
-/*********************************************************************************************/
- out_buf[0] = '\0';
-
- memset(&tempstr, 0, sizeof(h5dump_str_t));
-
-
- h5dump_str_reset(&tempstr);
- for (i=0; i<hs_nelmts && (elmtno+i) < p_nelmts; i++) {
- row_size++;
-
- h5dump_str_reset(&tempstr);
- h5dump_sprint(&tempstr, &info, -1/*no container*/, p_type,
- sm_buf+i*p_type_nbytes);
-
- memmove(tempstr.s, tempstr.s + 1, tempstr.len -1);
- tempstr.s[tempstr.len - 2] = '\0';
- tempstr.len = tempstr.len - 2;
-
- free_space = nCols - indent - COL - strlen(out_buf);
-
- if ((elmtno+i+1) == p_nelmts) { /* last element */
- /* 2 for double quotes */
- if (((int)tempstr.len + 2) > free_space) long_string = 1;
- } else
- /* 3 for double quotes and one comma */
- if (((int)tempstr.len + 3) > free_space) long_string = 1;
-
- if (long_string) {
-
- if (free_space < 5) { /* 5 for double quotes, one space and two '/'s */
- /* flush out_buf */
- if (compound_data && first_row) {
- printf("%s\n", out_buf);
- first_row = 0;
- } else {
- indentation(indent+COL);
- printf("%s\n", out_buf);
- }
- out_buf[0] = '\0';
- x = 0 ;
- } else {
- x = free_space - 5;
- if (compound_data && first_row) {
- printf("%s\"", out_buf);
- strncpy(out_buf, tempstr.s, x);
- out_buf[x] = '\0';
- printf("%s\" %s\n", out_buf,CONCATENATOR);
- first_row = 0;
- out_buf[0] = '\0';
- } else {
- indentation(indent+COL);
- printf("%s\"", out_buf);
- memset(out_buf, '\0', nCols);
- temp = copy_atomic_char(out_buf,tempstr.s,tempstr.len,x);
- out_buf[x] = '\0';
- printf("%s\" %s\n",out_buf,CONCATENATOR);
- x = temp;
- }
- }
-
- y = nCols - indent -COL - 5;
-
- m = (tempstr.len - x)/y;
-
- z = (tempstr.len - x) % y;
+ *-----------------------------------------------------------------------*/
+void indentation(int x) {
+ if(x < nCols) {
+ while (x>0) { printf(" "); x--; }
+ }
+ else {
+ printf("The indentation exceeds the number of cols. Exiting....\n");
+ exit(1);
+ }
+}
- for (j = 0; j < m - 1 ; j++) {
- indentation(indent+COL);
- strncpy(out_buf, tempstr.s+x+j*y, y);
- out_buf[y] = '\0';
- printf("\"%s\" %s\n", out_buf,CONCATENATOR);
- }
+/* Print the program name and the version information which is */
+/* defined the same as the HDF5 library version. */
+void
+print_version(const char *program_name)
+{
+ printf("%s: Version %u.%u.%u%s%s\n",
+ program_name, H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE,
+ H5_VERS_SUBRELEASE[0]?"-":"", H5_VERS_SUBRELEASE);
+}
- if ((elmtno+i+1) == p_nelmts) { /* last element */
- if ((int)strlen(tempstr.s+x+j*y) > (nCols - indent - COL -2)) { /* 2 for double quotes */
- indentation(indent+COL);
- strncpy(out_buf, tempstr.s+x+j*y, y);
- out_buf[y] = '\0';
- printf("\"%s\" %s\n", out_buf, CONCATENATOR);
- indentation(indent+COL);
- printf("\"%s\"", tempstr.s+x+m*y);
- if (compound_data) {
- if ((nCols-strlen(out_buf)-indent-COL) < 2) {
- printf("\n");
- indentation(indent+COL-3);
- }
- } else
- printf("\n");
-
- } else {
- indentation(indent+COL);
- printf("\"%s\"", tempstr.s+x+j*y);
- if (compound_data) {
- if ((nCols-strlen(out_buf)-indent-COL) < 2) {
- printf("\n");
- indentation(indent+COL-3);
- }
-
- } else
- printf("\n");
- }
- out_buf[0] = '\0';
- } else if ( row_size == dim_n_size) {
- if ((int)strlen(tempstr.s+x+j*y) > (nCols - indent - COL -3)) { /* 3 for 2 "'s and 1 , */
- indentation(indent+COL);
- strncpy(out_buf, tempstr.s+x+j*y, y);
- out_buf[y] = '\0';
- printf("\"%s\" %s\n", out_buf, CONCATENATOR);
- indentation(indent+COL);
- printf("\"%s\",\n", tempstr.s+x+m*y);
- } else {
- indentation(indent+COL);
- printf("\"%s\",\n", tempstr.s+x+j*y);
-
- }
- out_buf[0] = '\0';
- row_size = 0;
-
- } else {
- if ((int)strlen(tempstr.s+x+j*y) > (nCols - indent - COL -3)) { /* 3 for 2 "'s and 1 , */
- indentation(indent+COL);
- strncpy(out_buf, tempstr.s+x+j*y, y);
- out_buf[y] = '\0';
- printf("\"%s\" %s\n", out_buf, CONCATENATOR);
- strcpy(out_buf, "\"");
- strcat(out_buf, tempstr.s+x+m*y);
- strcat(out_buf, "\",");
- if ((int)strlen(out_buf) < (nCols-indent-COL)) strcat(out_buf, " ");
- } else {
- strcpy(out_buf, "\"");
- strcat (out_buf, tempstr.s+x+j*y);
- strcat(out_buf, "\",");
- if ((int)strlen(out_buf) < (nCols-indent-COL)) strcat(out_buf, " ");
- }
- }
- long_string = 0;
- } else {
- /* flush out_buf if it's end of a row */
- if (row_size == dim_n_size) {
- if (compound_data && (elmtno+i+1) == dim_n_size) { /* 1st row */
- printf("%s\"%s\"", out_buf, tempstr.s);
- first_row = 0;
- } else {
- indentation(indent+COL);
- printf("%s\"%s\"", out_buf, tempstr.s);
- }
- if ((elmtno+i+1) != p_nelmts)
- printf(",\n");
- else if (compound_data) {
- if ((nCols-strlen(out_buf)-tempstr.len-indent-COL) < 2) {
- /* 2 for space and ] */
- printf("\n");
- indentation(indent+COL-3);
- }
- } else
- printf("\n");
-
- out_buf[0] = '\0';
- row_size = 0;
- } else {
- strcat(out_buf, "\"");
- strcat(out_buf, tempstr.s);
- strcat(out_buf, "\",");
- if ((int)strlen(out_buf) < (nCols-indent-COL)) strcat(out_buf, " ");
- }
+/*
- }
- }
- free(out_buf);
-}
+THE FUNCTIONS BELOW ARE FROM THE H5FINSHD.C FILE
+*/
/*-------------------------------------------------------------------------
- * Function: display_compound_data
+ * Function: init_table
*
- * Purpose: Display compound data in ddl format
+ * Purpose: allocate and initialize tables for shared groups, datasets,
+ * and committed types
*
- * Return: void
+ * Return: void
+ *
+ * Programmer: Ruey-Hsia Li
*
* Modifications:
*
- *-------------------------------------------------------------------------
- */
-static void display_compound_data
-(hsize_t hs_nelmts, hid_t p_type, unsigned char *sm_buf, size_t p_type_nbytes,
- hsize_t p_nelmts, hsize_t elmtno) {
-size_t offset, size, dims[4];
-hsize_t nelmts, dim_n_size=0;
-hid_t memb;
-int nmembs, i, j, k, ndims, perm[4];
-
- if ((indent+COL) > nCols) indent = 0;
-
- for (i=0; i<(int)hs_nelmts && (elmtno+i) < p_nelmts; i++) {
+ *-----------------------------------------------------------------------*/
+void init_table (table_t** temp){
- nmembs = H5Tget_nmembers(p_type);
+ int i;
+ table_t *table = malloc(sizeof(table_t));
- indentation(indent+COL);
- printf("{\n");
+ table->size = 20;
+ table->nobjs = 0;
- indent+= COL;
- for (j=0; j<nmembs; j++) {
+ table->objs = (obj_t*) malloc(table->size*sizeof(obj_t));
+
- offset = H5Tget_member_offset(p_type, j);
- memb = H5Tget_member_type(p_type, j);
- size = H5Tget_size(memb);
- ndims = H5Tget_member_dims(p_type, j, dims, perm);
- if (ndims > 0) dim_n_size = dims[ndims-1];
- else dim_n_size = 1;
- for (k=0, nelmts=1; k<ndims; k++) nelmts *= dims[k];
+ for (i = 0; i < table->size; i++) {
+ table->objs[i].objno[0] = table->objs[i].objno[1] = 0;
+ table->objs[i].displayed = 0;
+ table->objs[i].recorded = 0;
+ table->objs[i].objflag = 0;
+ }
+ *temp = table;
- indentation(indent+COL);
- printf("[ ");
+}
- indent+=2;
- switch (H5Tget_class(memb)) {
- case H5T_INTEGER:
- display_numeric_data
- (nelmts, memb, sm_buf+offset+i*p_type_nbytes, size, nelmts, dim_n_size, 0, -1) ;
- break;
- case H5T_FLOAT:
- display_numeric_data
- (nelmts, memb, sm_buf+offset+i*p_type_nbytes, size, nelmts, dim_n_size, 0, -1) ;
- break;
+/*-------------------------------------------------------------------------
+ * Function: init_prefix
+ *
+ * Purpose: allocate and initialize prefix
+ *
+ * Return: void
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+void init_prefix(char **prefix, int prefix_len){
+ char *temp;
+ temp = (char *) malloc(prefix_len * sizeof (char));
+ *temp = '\0';
+ *prefix = temp;
+}
- case H5T_TIME:
- break;
- case H5T_STRING:
- display_string
- (nelmts, memb, sm_buf+offset+i*p_type_nbytes, size, nelmts, dim_n_size, 0 ) ;
- break;
- case H5T_BITFIELD:
- break;
+/*-------------------------------------------------------------------------
+ * Function: free_table
+ *
+ * Purpose: free tables for shared groups, datasets,
+ * and committed types
+ *
+ * Return: void
+ *
+ * Programmer: Paul Harten
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+void
+free_table (table_t **table){
- case H5T_OPAQUE:
- break;
+ table_t *temp = *table;
+ if (temp->objs != NULL) {
+ HDfree(temp->objs);
+ }
+ *table = temp;
+}
- default: break;
- }
- indent-=2;
+/*-------------------------------------------------------------------------
+ * Function: search_obj
+ *
+ * Purpose: search the object specified by objno in the table
+ *
+ * Return: an integer, the location of the object
+ * -1 if object is not found
+ *
+ *
+ * Programmer: Ruey-Hsia Li
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+int
+search_obj (table_t *table, unsigned long *objno) {
+int i=0, found=0;
+
+ while (i < table->nobjs && !found)
+ if (table->objs[i].objno[0] == *(objno) &&
+ table->objs[i].objno[1] == *(objno+1) ) found = 1;
+ else i++;
+
+ if (!found) return -1;
+ else return i;
- if ( j == nmembs-1) printf(" ]\n");
- else printf(" ],\n");
+}
- H5Tclose(memb);
- }
- indent-= COL;
- indentation(indent+COL);
- if ((elmtno+i+1) == p_nelmts) printf("}\n");
- else printf("},\n");
+/*-------------------------------------------------------------------------
+ * Function: add_obj
+ *
+ * Purpose: add a shared object to the table
+ * realloc the table if necessary
+ *
+ * Return: void
+ *
+ * Programmer: Ruey-Hsia Li
+ *
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+void
+add_obj (table_t *table, unsigned long *objno, char *objname) {
+int i;
+
+ if (table->nobjs == table->size) {
+ table->size *= 2;
+ table->objs = realloc (table->objs, table->size*sizeof(obj_t));
+ for (i = table->nobjs; i < table->size; i++) {
+ table->objs[i].objno[0] = table->objs[i].objno[1] = 0;
+ table->objs[i].displayed = 0;
+ table->objs[i].recorded = 0;
+ table->objs[i].objflag = 0;
+ }
}
+ i = table->nobjs++;
+ table->objs[i].objno[0] = *objno;
+ table->objs[i].objno[1] = *(objno+1);
+ strcpy (table->objs[i].objname, objname);
+
}
-#if 0
/*-------------------------------------------------------------------------
- * Function: h5dump_simple
+ * Function: Find_objs
*
- * Purpose: Print some values from a dataset or an attribute with a
- * simple data space.
+ * Purpose: Find objects, committed types and store them in tables
*
- * Return: Success: 0
+ * Return: Success: SUCCEED
*
- * Failure: -1
+ * Failure: FAIL
*
- * Modifications:
+ * Programmer: Ruey-Hsia Li
*
- *-------------------------------------------------------------------------
- */
-static int
-h5dump_simple(hid_t oid, hid_t p_type, int obj_data)
+ * Modifications:
+ *
+ *-----------------------------------------------------------------------*/
+herr_t find_objs(hid_t group, const char *name, void *op_data)
{
- hid_t f_space; /*file data space */
- int ndims; /*dimensionality */
- hsize_t elmtno, i; /*counters */
- int carry; /*counter carry value */
- hssize_t zero[8]; /*vector of zeros */
+ hid_t obj, type;
+ H5G_stat_t statbuf;
+ char *tmp;
+ int i;
+ find_objs_t *info = (find_objs_t*)op_data;
+
+ if (info->threshold > 1) { /*will get an infinite loop if greater than 1*/
+ return(FAIL);
+ }
- /* Print info */
- hsize_t p_min_idx[8]; /*min selected index */
- hsize_t p_max_idx[8]; /*max selected index */
- size_t p_type_nbytes; /*size of memory type */
- hsize_t p_nelmts; /*total selected elmts */
+ H5Gget_objinfo(group, name, TRUE, &statbuf);
- /* Stripmine info */
- hsize_t sm_size[8]; /*stripmine size */
- hsize_t sm_nbytes; /*bytes per stripmine */
- hsize_t sm_nelmts; /*elements per stripmine*/
- unsigned char *sm_buf; /*buffer for raw data */
- hid_t sm_space; /*stripmine data space */
+ tmp = (char *) malloc ((strlen(info->prefix)+strlen(name)+2) * sizeof(char));
- /* Hyperslab info */
- hssize_t hs_offset[8]; /*starting offset */
- hsize_t hs_size[8]; /*size this pass */
- hsize_t hs_nelmts; /*elements in request */
- hsize_t dim_n_size;
+ strcpy(tmp, info->prefix);
+ switch (statbuf.type) {
- if (obj_data == DATASET_DATA)
- f_space = H5Dget_space(oid);
- else
- f_space = H5Aget_space(oid);
+ case H5G_GROUP:
+ if ((obj=H5Gopen (group, name))>=0) {
- /*
- * 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.
- */
+ if (info->prefix_len < (int)(strlen(info->prefix) + strlen(name) + 2)) {
+ info->prefix_len *= 2;
+ info->prefix = realloc (info->prefix, info->prefix_len * sizeof(char));
+ }
+ strcat(strcat(info->prefix,"/"), name);
- ndims = H5Sget_simple_extent_ndims(f_space);
+ if (statbuf.nlink > info->threshold) {
+ if (search_obj (info->group_table, statbuf.objno) < 0) {
+ add_obj (info->group_table, statbuf.objno, info->prefix);
+ H5Giterate (obj, ".", NULL, find_objs, (void*)info);
+ }
+ } else
+ H5Giterate (obj, ".", NULL, find_objs, (void*)info);
- if ((size_t)ndims>NELMTS(sm_size)) return -1;
+ strcpy(info->prefix, tmp);
+ H5Gclose (obj);
- /* Assume entire data space to be printed */
- for (i=0; i<(hsize_t)ndims; i++) p_min_idx[i] = 0;
- H5Sget_simple_extent_dims(f_space, p_max_idx, NULL);
- for (i=0, p_nelmts=1; i<(hsize_t)ndims; i++) {
- p_nelmts *= p_max_idx[i]-p_min_idx[i];
- }
- if (0==p_nelmts) return 0; /*nothing to print*/
+ } else
+ info->status = 1;
- /*
- * Determine the strip mine size and allocate a buffer. The strip mine is
- * a hyperslab whose size is manageable.
- */
- p_type_nbytes = H5Tget_size(p_type);
- for (i=ndims, sm_nbytes=p_type_nbytes; i>0; --i) {
- sm_size[i-1] = MIN (p_max_idx[i-1]-p_min_idx[i-1],
- H5DUMP_BUFSIZE/sm_nbytes);
- sm_nbytes *= sm_size[i-1];
- assert(sm_nbytes>0);
- }
- sm_buf = malloc(sm_nbytes);
- sm_nelmts = sm_nbytes/p_type_nbytes;
- sm_space = H5Screate_simple(1, &sm_nelmts, NULL);
+ break;
- /* The stripmine loop */
- memset(hs_offset, 0, sizeof hs_offset);
- memset(zero, 0, sizeof zero);
+ case H5G_DATASET:
+ strcat(tmp,"/");
+ strcat(tmp,name); /* absolute name of the data set */
+ if (statbuf.nlink > info->threshold &&
+ search_obj (info->dset_table, statbuf.objno) < 0)
+ add_obj (info->dset_table, statbuf.objno, tmp);
- for (elmtno=0; elmtno<p_nelmts; elmtno+=hs_nelmts) {
+ if ((obj=H5Dopen (group, name))>=0) {
+ type = H5Dget_type (obj);
+ if (H5Tcommitted(type) > 0 ) {
+ H5Gget_objinfo(type, ".", TRUE, &statbuf);
+ if (search_obj (info->type_table, statbuf.objno) < 0) {
+ add_obj (info->type_table, statbuf.objno, tmp) ;
+ info->type_table->objs[info->type_table->nobjs - 1].objflag = 0;
+ }
+ }
+ H5Tclose(type);
+ H5Dclose (obj);
+ } else
+ info->status = 1;
+
+ break;
+
+ case H5G_TYPE:
+ strcat(tmp,"/");
+ strcat(tmp,name); /* absolute name of the type */
+ i = search_obj (info->type_table, statbuf.objno);
+ if (i < 0) {
+ add_obj (info->type_table, statbuf.objno, tmp) ;
+ info->type_table->objs[info->type_table->nobjs-1].recorded = 1; /* named data type */
+ info->type_table->objs[info->type_table->nobjs-1].objflag = 1; /* named data type */
+ } else {
+ strcpy (info->type_table->objs[i].objname, tmp);
+ info->type_table->objs[i].recorded = 1;
+ info->type_table->objs[info->type_table->nobjs-1].objflag = 1; /* named data type */
+ }
+ break;
+ default:
+ break;
+ }
- /* Calculate the hyperslab size */
- if (ndims > 0) {
- for (i=0, hs_nelmts=1; i<(hsize_t)ndims; i++) {
- hs_size[i] = MIN(sm_size[i], p_max_idx[i]-hs_offset[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);
- dim_n_size = p_max_idx[ndims-1];
- } else {
- H5Sselect_all(f_space);
- H5Sselect_all(sm_space);
- hs_nelmts = 1;
- dim_n_size = 1;
- }
+ free (tmp);
- if (obj_data == DATASET_DATA) {
- if (H5Dread(oid, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) <0)
- return -1;
- } else {
- if (H5Aread(oid, p_type, sm_buf) < 0)
- return -1;
- }
+ return SUCCEED;
+}
- /* Print the data */
- switch (H5Tget_class(p_type)) {
- case H5T_INTEGER:
- display_numeric_data (hs_nelmts, p_type, sm_buf, p_type_nbytes,
- p_nelmts, dim_n_size, elmtno, -1);
- break;
-
- case H5T_FLOAT:
- display_numeric_data (hs_nelmts, p_type, sm_buf, p_type_nbytes,
- p_nelmts, dim_n_size, elmtno, -1);
- break;
-
- case H5T_TIME:
- break;
-
- case H5T_STRING:
- display_string (hs_nelmts, p_type, sm_buf, p_type_nbytes,
- p_nelmts, dim_n_size, elmtno);
- break;
-
- case H5T_BITFIELD:
- break;
-
- case H5T_OPAQUE:
- break;
-
- case H5T_COMPOUND:
- compound_data = 1;
- display_compound_data (hs_nelmts, p_type, sm_buf, p_type_nbytes, p_nelmts, elmtno);
- compound_data = 0;
- break;
-
- default: break;
- }
-
- /* Calculate the next hyperslab offset */
- for (i=ndims, carry=1; i>0 && carry; --i) {
- hs_offset[i-1] += hs_size[i-1];
- if (hs_offset[i-1]==(hssize_t)p_max_idx[i-1]) {
- hs_offset[i-1] = p_min_idx[i-1];
- } else {
- carry = 0;
- }
- }
- }
- H5Sclose(sm_space);
- H5Sclose(f_space);
- return 0;
-}
-#endif
/*-------------------------------------------------------------------------
- * Function: print_data
+ * Function: dump_tables
*
- * Purpose: Print some values from a dataset or an attribute 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/attribute type
- * using only native types.
+ * Purpose: display the contents of tables for debugging purposes
*
- * Return: Success: 0
+ * Return: void
*
- * Failure: -1
+ * Programmer: Ruey-Hsia Li
*
* Modifications:
*
- *-------------------------------------------------------------------------
- */
-int
-print_data(hid_t oid, hid_t _p_type, int obj_data)
-{
- hid_t f_space;
- hid_t p_type = _p_type;
- hid_t f_type;
- int status = -1;
-
- if (p_type < 0) {
-
- if (obj_data == DATASET_DATA)
- f_type = H5Dget_type(oid);
- else
- f_type = H5Aget_type(oid);
-
- if (f_type < 0) return status;
+ *-----------------------------------------------------------------------*/
+void
+dump_table(char* tablename, table_t *table) {
+int i;
- p_type = h5dump_fixtype(f_type);
+ printf("%s: # of entries = %d\n", tablename,table->nobjs);
+ for ( i = 0; i < table->nobjs; i++)
+ printf ("%lu %lu %s %d\n", table->objs[i].objno[0],
+ table->objs[i].objno[1],
+ table->objs[i].objname,
+ table->objs[i].objflag);
- H5Tclose(f_type);
+}
- if (p_type < 0) return status;
- }
- /* Check the data space */
- if (obj_data == DATASET_DATA)
- f_space = H5Dget_space(oid);
- else
- f_space = H5Aget_space(oid);
- if (f_space < 0) return status;
-
- if (H5Sis_simple(f_space) >= 0) {
- if (obj_data == DATASET_DATA) {
- status = h5dump_simple_dset(NULL,NULL, oid,p_type);
- }
- else { /*attribute data*/
- status = h5dump_attr(oid,p_type);
- }
- }
- H5Sclose(f_space);
+/*-------------------------------------------------------------------------
+ * Function: get_table_idx
+ *
+ * Purpose: Determine if objects are in a link loop
+ *
+ * Return: Success: table index of object detected to be in loop
+ *
+ * Failure: FAIL
+ *
+ * Programmer: Paul Harten
+ *
+ *-----------------------------------------------------------------------*/
+int
+get_table_idx(table_t *table, unsigned long *objno)
+{
+int idx = -1;
- if (p_type != _p_type) H5Tclose(p_type);
+ idx = search_obj(table, objno);
+ return idx;
- return status;
}
-
/*-------------------------------------------------------------------------
- * Function: indentation
+ * Function: Get table flag setting
*
- * Purpose: Print spaces for indentation
+ * Purpose: Keep the structures and variables used private to
+ * this file.
*
- * Return: void
+ * Return: Success: Boolean setting of the i'th element of the
+ * object table flag
*
- * Programmer: Ruey-Hsia Li
+ * Failure: FAIL
*
- * Modifications:
+ * Programmer: Paul Harten
*
*-----------------------------------------------------------------------*/
-void indentation(int x) {
+int
+get_tableflag(table_t *table, int idx)
+{
+
+ return(table->objs[idx].objflag);
+
- if(x < nCols) {
- while (x>0) { printf(" "); x--; }
- }
- else {
- printf("The indentation exceeds the number of cols. Exiting....\n");
- exit(1);
- }
}
-
-
-
/*-------------------------------------------------------------------------
- * Function: copy_atomic_char
+ * Function: Set table flag setting
*
- * Purpose: copies the atomic characters from 1 string to another
- * assumes there will be enough room in output for the input string
+ * Purpose: Keep the structures and variables used private to
+ * this file.
*
- * Return: returns the number of actual characters copied
+ * Return: Success: Boolean setting of the i'th element of the
+ * object table flag
*
- * Programmer: Patrick Lu
+ * Failure: FAIL
*
- * Modifications:
+ * Programmer: Paul Harten
*
*-----------------------------------------------------------------------*/
-int copy_atomic_char(char* output, char* input, int numchar, int freespace){
-
- int x = 0;
-
- while (freespace || (x == numchar)){
- if (input[x] == '\\'){
- if (freespace == 1){
- break;
- }
- else {
- if ((input[x+1] == '"') || (input[x+1] == '\\') ||
- (input[x+1] == 'b') || (input[x+1] == 'f') ||
- (input[x+1] == 'n') || (input[x+1] == 'r') ||
- (input[x+1] == 't')){ /*escape characters*/
- strncat(output,input,2);
- x += 2;
- freespace = freespace - 2;
- }
- else { /* octal number */
- if (freespace < 4){
- break;
- }
- else {
- strncat(output,input,4);
- x += 4;
- freespace = freespace - 4;
- }
- }
- }
- }
- else {
- strncat(output,input+x,1);
- freespace = freespace - 1;
- x++;
- }
- }
+int
+set_tableflag(table_t *table, int idx)
+{
- if (x == 0) x = FAIL;
- return(x);
-}
+ table->objs[idx].objflag = TRUE;
+ return(SUCCEED);
+
+}
/*-------------------------------------------------------------------------
- * Function: h5dump_attr
+ * Function: Get name of i'th object in table
*
- * Purpose: dumps an attribute
+ * Purpose:
*
- * Return: 0 = succeed or -1 for fail
+ * Return: Success: strdup() of object name character string
*
- * Programmer: Patrick Lu
+ * Failure: NULL
*
- * Modifications:
+ * Programmer: Paul Harten
*
*-----------------------------------------------------------------------*/
+char *
+get_objectname(table_t* table, int idx)
+{
-int h5dump_attr(hid_t oid, hid_t p_type){
-
- hid_t f_space;
- void *sm_buf;
- hid_t type;
- hsize_t size[64], nelmts = 1, dim_n_size;
- size_t p_type_nbytes, need;
- int ndims, i;
- int status = -1;
-
- f_space = H5Aget_space(oid);
-
- /* get the size of the attribute and allocate enough mem*/
- type = H5Aget_type(oid);
- ndims = H5Sget_simple_extent_dims(f_space, size, NULL);
- if (ndims){
- for (i = 0; i < ndims; i++){
- nelmts *= size[i];
- }
- dim_n_size = size[ndims - 1];
- }
- else {
- dim_n_size = 1;
- }
- need = nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type));
- sm_buf = malloc(need);
- p_type_nbytes = H5Tget_size(p_type);
-
- /*read the attr*/
- if (H5Aread(oid, p_type, sm_buf) < 0){
- return (status);
- }
- status = 0;
- /*print it*/
- switch (H5Tget_class(p_type)) {
- case H5T_INTEGER:
- display_numeric_data (nelmts, p_type, sm_buf, p_type_nbytes,
- nelmts, dim_n_size, 0, oid);
- break;
-
- case H5T_FLOAT:
- display_numeric_data (nelmts, p_type, sm_buf, p_type_nbytes,
- nelmts, dim_n_size, 0, oid);
- break;
-
- case H5T_TIME:
- break;
-
- case H5T_STRING:
- display_string (nelmts, p_type, sm_buf, p_type_nbytes,
- nelmts, dim_n_size, 0);
- break;
-
- case H5T_BITFIELD:
- break;
-
- case H5T_OPAQUE:
- break;
-
- case H5T_COMPOUND:
- compound_data = 1;
- display_compound_data (nelmts, p_type, sm_buf, p_type_nbytes, nelmts, 0);
- compound_data = 0;
- break;
- case H5T_REFERENCE:
- display_numeric_data(nelmts, p_type, sm_buf, p_type_nbytes,
- nelmts, dim_n_size, 0, oid);
- case H5T_ENUM:
- display_numeric_data(nelmts, p_type, sm_buf, p_type_nbytes,
- nelmts, dim_n_size, 0, oid);
-/* display_reference_data(nelmts, p_type, sm_buf, p_type_nbytes,
- nelmts, dim_n_size, 0, oid);*/
- break;
- default: break;
- }
- free(sm_buf);
- return (status);
+ return(strdup(table->objs[idx].objname));
}
-/* Print the program name and the version information which is */
-/* defined the same as the HDF5 library version. */
-void
-print_version(char *program_name)
-{
- printf("%s: Version %u.%u.%u%s%s\n",
- program_name, H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE,
- H5_VERS_SUBRELEASE[0]?"-":"", H5_VERS_SUBRELEASE);
-}
+
+
+
+
+
+
diff --git a/tools/h5tools.h b/tools/h5tools.h
index 95aeea8..22ab2d3 100644
--- a/tools/h5tools.h
+++ b/tools/h5tools.h
@@ -12,6 +12,15 @@
#include <hdf5.h>
#include <stdio.h>
+#if H5_VERS_MAJOR == 1
+#if H5_VERS_MINOR == 2
+#define VERSION12
+#elif H5_VERS_MINOR == 3
+#define VERSION13
+#endif
+#endif
+#define ESCAPE_HTML 1
+
/*
* Information about how to format output.
@@ -77,6 +86,15 @@ typedef struct h5dump_t {
* escape. If `ascii' is zero then then 1-byte integers are
* printed as numeric values. The default is zero.
*
+ * str_locale: Determines how strings are printed. If zero then strings
+ * are printed like in C except. If set to ESCAPE_HTML then
+ * strings are printed using HTML encoding where each
+ * character not in the class [a-zA-Z0-9] is substituted
+ * with `%XX' where `X' is a hexadecimal digit.
+ *
+ * str_repeat: If set to non-zero then any character value repeated N
+ * or more times is printed as 'C'*N
+ *
* Numeric data is also subject to the formats for individual elements.
*/
hbool_t raw;
@@ -94,7 +112,8 @@ typedef struct h5dump_t {
const char *fmt_double;
const char *fmt_float;
int ascii;
-
+ int str_locale;
+ int str_repeat;
/*
* Fields associated with compound array members.
*
@@ -107,10 +126,14 @@ typedef struct h5dump_t {
*
* suf: A string to print at the end of each array. The default
* value is a right square bracket `]'.
- */
+ *
+ * linebreaks: a boolean value to determine if we want to break the line
+ * after each row of an array
+ */
const char *arr_pre;
const char *arr_sep;
const char *arr_suf;
+ int arr_linebreak;
/*
* Fields associated with compound data types.
@@ -129,12 +152,16 @@ typedef struct h5dump_t {
* The default is a left curly brace.
*
* suf: A string to print at the end of each compound type. The
- * default is a right curly brace.
+ * default is right curly brace.
+ *
+ * end: a string to print after we reach the last element of
+ * each compound type. prints out before the suf.
*/
const char *cmpd_name;
const char *cmpd_sep;
const char *cmpd_pre;
const char *cmpd_suf;
+ const char *cmpd_end;
/*
* Fields associated with the individual elements.
@@ -178,7 +205,10 @@ typedef struct h5dump_t {
/*
* Fields associated with entire lines.
*
- * ncols: Number of columns per line defaults to 80.
+ * ncols: Number of columns per line defaults to 80.
+ *
+ * per_line: If this field has a positive value then every Nth element
+ * will be printed at the beginning of a line.
*
* pre: Each line of output contains an optional prefix area
* before the data. This area can contain the index for the
@@ -222,22 +252,92 @@ typedef struct h5dump_t {
* should the following element begin on the next line? The
* default is to start the next element on the same line
* unless it wouldn't fit.
+ *
+ * indentlevel: a string that shows how far to indent if extra spacing
+ * is needed. dumper uses it.
*/
int line_ncols; /*columns of output */
+ size_t line_per_line; /*max elements per line */
const char *line_pre; /*prefix at front of each line */
const char *line_1st; /*alternate pre. on first line */
const char *line_cont; /*alternate pre. on continuation*/
const char *line_suf; /*string to append to each line */
const char *line_sep; /*separates lines */
int line_multi_new; /*split multi-line outputs? */
+ const char *line_indent; /*for extra identation if we need it*/
+
+ int skip_first; /*used to skip the first set of checks for line length*/
+
+ int obj_hidefileno; /*flag used to hide or show the file number for obj refs*/
+ const char *obj_format; /*string used to format the output for the obje refs*/
+
+ int dset_hidefileno;/*flag used to hide or show the file number for dataset regions*/
+ const char *dset_format; /*string used to format the output for the dataset regions*/
+
+ const char *dset_blockformat_pre;
+ const char *dset_ptformat_pre;
+ const char *dset_ptformat;
+
+
+
} h5dump_t;
+typedef struct dump_header{
+ const char *name;
+ const char *filebegin;
+ const char *fileend;
+ const char *bootblockbegin;
+ const char *bootblockend;
+ const char *groupbegin;
+ const char *groupend;
+ const char *datasetbegin;
+ const char *datasetend;
+ const char *attributebegin;
+ const char *attributeend;
+ const char *datatypebegin;
+ const char *datatypeend;
+ const char *dataspacebegin;
+ const char *dataspaceend;
+ const char *databegin;
+ const char *dataend;
+ const char *softlinkbegin;
+ const char *softlinkend;
+
+ const char *fileblockbegin;
+ const char *fileblockend;
+ const char *bootblockblockbegin;
+ const char *bootblockblockend;
+ const char *groupblockbegin;
+ const char *groupblockend;
+ const char *datasetblockbegin;
+ const char *datasetblockend;
+ const char *attributeblockbegin;
+ const char *attributeblockend;
+ const char *datatypeblockbegin;
+ const char *datatypeblockend;
+ const char *dataspaceblockbegin;
+ const char *dataspaceblockend;
+ const char *datablockbegin;
+ const char *datablockend;
+ const char *softlinkblockbegin;
+ const char *softlinkblockend;
+ const char *strblockbegin;
+ const char *strblockend;
+ const char *enumblockbegin;
+ const char *enumblockend;
+
+ const char *dataspacedescriptionbegin;
+ const char *dataspacedescriptionend;
+ const char *dataspacedimbegin;
+ const char *dataspacedimend;
+
+} dump_header;
+
hid_t h5dump_fixtype(hid_t f_type);
-int h5dump_dset(FILE *stream, const h5dump_t *info, hid_t dset, hid_t p_type);
+int h5dump_dset(FILE *stream, const h5dump_t *info, hid_t dset, hid_t p_typ,int indentlevel);
int h5dump_mem(FILE *stream, const h5dump_t *info, hid_t type, hid_t space,
- void *mem);
-int copy_atomic_char(char* output, char* input, int numchar, int freespace);
+ void *mem, int indentlevel);
/*if we get a new program that needs to use the library add its name here*/
@@ -248,6 +348,43 @@ typedef enum {
} ProgType;
+
+/*struct taken from the dumper. needed in table struct*/
+typedef struct obj_t{
+unsigned long objno[2];
+char objname[1024];
+int displayed;
+int recorded;
+int objflag;
+} obj_t;
+
+
+/*struct for the tables that the find_objs function uses*/
+
+typedef struct table_t{
+int size;
+int nobjs;
+obj_t *objs;
+} table_t;
+
+
+
+/*this struct stores the information that is passed to the find_objs function*/
+typedef struct find_objs_t {
+ int prefix_len;
+ char *prefix;
+ int threshold; /* should be 0 or 1 */
+ table_t *group_table;
+ table_t *type_table;
+ table_t *dset_table;
+ int status;
+} find_objs_t;
+
+herr_t find_objs(hid_t group, const char *name, void *op_data);
+int search_obj (table_t *temp, unsigned long *);
+void init_table(table_t **temp);
+void init_prefix(char **temp, int);
+
/*
taken from h5dump.h
*/
@@ -261,13 +398,6 @@ typedef enum {
extern int indent;
extern void indentation(int);
extern int nCols;
-/*
- used to determine what action to take in certain cases
- this variable should be set at the beginning of all programs
- that use the lib
- */
-extern ProgType programtype;
-
/* taken from h5dump.h*/
@@ -295,11 +425,12 @@ extern ProgType programtype;
#define CTYPE "CTYPE"
#define CONCATENATOR "//"
#define DATASET "DATASET"
+#define OBJID "OBJECTID"
#define BEGIN "{"
#define END "}"
#endif
/* Definitions of useful routines */
-void print_version(char *program_name);
+void print_version(const char *program_name);
diff --git a/tools/testh5dump.sh b/tools/testh5dump.sh
index dcb1922..627933f 100755
--- a/tools/testh5dump.sh
+++ b/tools/testh5dump.sh
@@ -104,6 +104,9 @@ DUMP tcomp-2.ddl -t /type1 /type2 /group1/type3 tcompound.h5
# test for unamed type
DUMP tcomp-3.ddl -t /#5992:0 -g /group2 tcompound.h5
+#test for the nested compound type
+DUMP tnestcomp-1.ddl tnestedcomp.h5
+
# test for options
DUMP tall-1.ddl tall.h5
DUMP tall-2.ddl -header -g /g1/g1.1 -a attr2 tall.h5