diff options
-rw-r--r-- | tools/h5dump.c | 758 | ||||
-rw-r--r-- | tools/h5dump.h | 11 | ||||
-rw-r--r-- | tools/h5dumputil.c | 50 | ||||
-rwxr-xr-x | tools/testh5dump.sh | 11 |
4 files changed, 699 insertions, 131 deletions
diff --git a/tools/h5dump.c b/tools/h5dump.c index 9d77d63..d29696d 100644 --- a/tools/h5dump.c +++ b/tools/h5dump.c @@ -2,14 +2,33 @@ #include <stdio.h> #include "H5private.h" -static int indent = 0; +int indent = 0; +int ischar=0; static int display_data = 1; static int 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; +} 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 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 *); /*------------------------------------------------------------------------- * Function: usage @@ -29,15 +48,17 @@ usage(void) fprintf(stderr, "\nUsage of HDF5 Dumper:\n\n \ h5dump [-h] [-bb] [-header] [-a <names>] [-d <names>] [-g <names>]\n \ - [-l <names>] <file>\n\n\ + [-l <names>] [-t <names>] <file>\n\n\ -h Print information on this command.\n\ - -bb Display the conent of boot block. The default is not to display.\n\ - -header Display header only; that is, no data displayed.\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\ -a <names> Display the specified attribute(s).\n\ -d <names> Display the specified dataset(s).\n\ - -g <names> Display all the objects within the specified group(s).\n\ - -l <names> Display the specified link value(s).\n\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\ + \n\ + <names> is one or more appropriate object names.\n\n"); } @@ -55,18 +76,15 @@ h5dump [-h] [-bb] [-header] [-a <names>] [-d <names>] [-g <names>]\n \ *-----------------------------------------------------------------------*/ static void indentation(int x) { - while (x>0) { - printf(" "); - x--; - } + while (x>0) { printf(" "); x--; } } /*------------------------------------------------------------------------- - * Function: datatype_name + * Function: print_datatype * - * Purpose: Prints the name of data type. + * Purpose: print the data type. * * Return: void * @@ -76,7 +94,13 @@ static void indentation(int x) { * *-----------------------------------------------------------------------*/ static void -datatype_name(hid_t type) { +print_datatype(hid_t type) { +char *fname ; +hid_t nmembers, mtype; +int i, j, ndims, perm[H5DUMP_MAX_NDIMS]; +size_t dims[H5DUMP_MAX_NDIMS]; + +H5G_stat_t statbuf; switch (H5Tget_class(type)) { @@ -134,7 +158,10 @@ datatype_name(hid_t type) { printf( "H5T_NATIVE_LLONG"); else if (H5Tequal(type, H5T_NATIVE_ULLONG)) printf( "H5T_NATIVE_ULLONG"); - else printf( "unknown integer"); + else { + printf( "undefined integer"); + status = 1; + } break; case H5T_FLOAT: @@ -152,11 +179,14 @@ datatype_name(hid_t type) { printf( "H5T_NATIVE_DOUBLE"); else if (H5Tequal(type, H5T_NATIVE_LDOUBLE)) printf( "H5T_NATIVE_LDOUBLE"); - else printf( "unknown float"); + else { + printf( "undefined float"); + status = 1; + } break; case H5T_TIME: - printf( "time: not yet implemented"); + printf( "H5T_TIME: not yet implemented"); case H5T_STRING: @@ -164,7 +194,10 @@ datatype_name(hid_t type) { printf( "H5T_C_S1"); else if (H5Tequal(type,H5T_FORTRAN_S1)) printf( "H5T_FORTRAN_S1"); - else printf( "unknown string"); + else { + printf( "undefined string"); + status = 1; + } break; case H5T_BITFIELD: @@ -185,20 +218,70 @@ datatype_name(hid_t type) { printf( "H5T_STD_B64BE"); else if (H5Tequal(type, H5T_STD_B64LE)) printf( "H5T_STD_B64LE"); - else printf( "unknown bitfield"); + else { + printf( "undefined bitfield"); + status = 1; + } break; case H5T_OPAQUE: - printf( "opaque: not yet implemented"); + printf( "H5T_OPAQUE: not yet implemented"); break; case H5T_COMPOUND: - printf( "compound: not yet implemented"); + if (H5Tcommitted(type) > 0) { + H5Gget_objinfo(type, ".", TRUE, &statbuf); + + i = search_obj (type_table, statbuf.objno); + + indentation (indent+col); + if (i >= 0) { + if (!type_table.objs[i].displayed) /* unamed data type */ + printf("%s %s \"#%lu:%lu\" %s\n", HARDLINK, BEGIN, + type_table.objs[i].objno[0], + type_table.objs[i].objno[1], END); + else + printf("%s %s \"%s\" %s\n", HARDLINK, BEGIN,type_table.objs[i].objname, END); + } else { + printf("h5dump error: unknown committed type.\n"); + status = 1; + } + + } else { + + 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); + + indentation (indent+col); + + print_datatype(mtype); + + printf (" %s", fname); + + if (ndims != 1 || dims[0] != 1) { + for (j = 0; j < ndims; j++) + printf("[%d]",dims[j]); + } + + printf (";\n"); + + free (fname); + } + } + break; default: printf( "unknown data type"); + status = 1; break; } @@ -229,7 +312,7 @@ dump_bb(void) { * Function: dump_datatype * * Purpose: Dump the data type. Data type can be HDF5 predefined - * atomic data type, named data type or compound data type. + * atomic data type or committed/transient data type. * * Return: void * @@ -241,10 +324,19 @@ dump_bb(void) { static void dump_datatype (hid_t type) { - indentation (indent+col); - printf ("%s %s \"", DATATYPE, BEGIN); - datatype_name(type); - printf ("\" %s\n", END); + indent += col; + indentation (indent); + if (H5Tget_class(type) == H5T_COMPOUND) { + printf ("%s %s\n", DATATYPE, BEGIN); + print_datatype(type); + indentation (indent); + printf ("%s\n", END); + } else { + printf ("%s %s \"", DATATYPE, BEGIN); + print_datatype(type); + printf ("\" %s\n", END); + } + indent -= col; } @@ -264,8 +356,8 @@ dump_datatype (hid_t type) { static void dump_dataspace (hid_t space) { - hsize_t size[64]; - hsize_t maxsize[64]; /* check max dims size */ + hsize_t size[H5DUMP_MAX_NDIMS]; + hsize_t maxsize[H5DUMP_MAX_NDIMS]; int ndims = H5Sget_simple_extent_dims(space, size, maxsize); int i; @@ -275,26 +367,29 @@ dump_dataspace (hid_t space) if (H5Sis_simple(space)) { - HDfprintf (stdout, "%s %s ( %Hu",BEGIN, ARRAY, size[0]); - for (i = 1; i < ndims; i++) - HDfprintf (stdout, ", %Hu", size[i]); - printf(" ) "); + if (ndims == 0) /* scalar space */ + HDfprintf (stdout, "%s %s ( 0 ) ( 0 ) %s\n",BEGIN, ARRAY, END); + else { + HDfprintf (stdout, "%s %s ( %Hu",BEGIN, ARRAY, size[0]); + for (i = 1; i < ndims; i++) + HDfprintf (stdout, ", %Hu", size[i]); + printf(" ) "); - if (maxsize[0]==H5S_UNLIMITED) - HDfprintf (stdout, "( %s", "H5S_UNLIMITED"); - else - HDfprintf (stdout, "( %Hu", maxsize[0]); - - for (i = 1; i < ndims; i++) - if (maxsize[i]==H5S_UNLIMITED) - HDfprintf (stdout, ", %s", "H5S_UNLIMITED"); - else - HDfprintf (stdout, ", %Hu", maxsize[i]); - - printf(" ) %s\n", END); + if (maxsize[0]==H5S_UNLIMITED) + HDfprintf (stdout, "( %s", "H5S_UNLIMITED"); + else + HDfprintf (stdout, "( %Hu", maxsize[0]); + + for (i = 1; i < ndims; i++) + if (maxsize[i]==H5S_UNLIMITED) + HDfprintf (stdout, ", %s", "H5S_UNLIMITED"); + else + HDfprintf (stdout, ", %Hu", maxsize[i]); + + printf(" ) %s\n", END); + } } else - printf("%s not yet implemented %s\n", BEGIN, END); } @@ -372,9 +467,9 @@ hid_t oid, attr_id, type, space; H5G_stat_t statbuf; - j = strlen(name)-1; obj_name = malloc ((j+2) * sizeof(char)); + /* find the last / */ while (name[j] != '/' && j >=0) j--; /* object name */ @@ -472,6 +567,7 @@ H5G_stat_t statbuf; return SUCCEED; } + /*------------------------------------------------------------------------- * Function: dump all * @@ -489,14 +585,16 @@ H5G_stat_t statbuf; static herr_t dump_all (hid_t group, const char *name, void __unused__ *op_data) { - hid_t obj; - char *buf; - H5G_stat_t statbuf; - +hid_t obj; +char *buf, *tmp; +H5G_stat_t statbuf; +int i; H5Gget_objinfo(group, name, FALSE, &statbuf); + tmp = (char *) malloc ((strlen(prefix)+strlen(name)+2) * sizeof(char)); + strcpy(tmp, prefix); switch (statbuf.type) { case H5G_LINK: @@ -507,7 +605,7 @@ dump_all (hid_t group, const char *name, void __unused__ *op_data) begin_obj(SOFTLINK, name); indentation (indent+col); if (H5Gget_linkval (group, name, statbuf.linklen, buf)>=0) - printf ("linktarget \"%s\"\n", buf); + printf ("LINKTARGET \"%s\"\n", buf); else { printf ("h5dump error: unable to get link value.\n"); status = 1; @@ -520,7 +618,9 @@ dump_all (hid_t group, const char *name, void __unused__ *op_data) case H5G_GROUP: if ((obj=H5Gopen (group, name))>=0) { + strcat(strcat(prefix,"/"), name); dump_group (obj, name); + strcpy(prefix, tmp); H5Gclose (obj); } else { printf ("h5dump error: unable to dump group %s\n",name); @@ -532,6 +632,36 @@ dump_all (hid_t group, const char *name, void __unused__ *op_data) case H5G_DATASET: if ((obj=H5Dopen (group, name))>=0) { + + /* hard link */ + H5Gget_objinfo(obj, ".", TRUE, &statbuf); + if (statbuf.nlink > 1) { + i = search_obj (dset_table, statbuf.objno); + if (i < 0) { + indentation (indent); + begin_obj(DATASET, name); + indentation (indent+col); + printf("h5dump error: internal error\n"); + indentation (indent); + end_obj(); + status = 1; + goto done; + } else if (dset_table.objs[i].displayed) { + indentation (indent); + begin_obj(DATASET, name); + indentation (indent+col); + printf("%s %s \"%s\" %s\n",HARDLINK, BEGIN, + dset_table.objs[i].objname,END); + indentation (indent); + end_obj(); + goto done; + } else { + dset_table.objs[i].displayed = 1; + strcat(tmp,"/"); + strcat(tmp,name); + strcpy(dset_table.objs[i].objname, tmp); + } + } dump_dataset (obj, name); H5Dclose (obj); } else { @@ -542,20 +672,24 @@ dump_all (hid_t group, const char *name, void __unused__ *op_data) break; case H5G_TYPE: - dump_named_datatype (obj, name); - H5Tclose(obj); + 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; default: - printf ("Unknown Object %s\n", name); + printf ("h5dump error: unknown object %s\n", name); status = 1; return FAIL; - break; } - - +done: + free(tmp); return SUCCEED; } @@ -574,25 +708,43 @@ dump_all (hid_t group, const char *name, void __unused__ *op_data) * *-----------------------------------------------------------------------*/ static void -dump_named_datatype (hid_t type_id, const char *name) { -hid_t id; -/* +dump_named_datatype (hid_t type, const char *name) { char *fname ; hid_t nmembers, mtype; -int i, ndims, perm[512]; -*/ - -id = type_id; /*doesn't like warning message */ +int i, j, ndims, perm[H5DUMP_MAX_NDIMS]; +size_t dims[H5DUMP_MAX_NDIMS]; indentation (indent); begin_obj(DATATYPE, name); - indentation(indent+col); - printf("named data type: not yet implemented.\n"); + 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); + + indentation (indent+col); + + print_datatype(mtype); + + printf (" %s", fname); + + if (ndims != 1 || dims[0] != 1) { + for (j = 0; j < ndims; j++) + printf("[%d]",dims[j]); + } + printf (";\n"); + + free (fname); + } + indentation (indent); end_obj(); - } @@ -611,25 +763,67 @@ id = type_id; /*doesn't like warning message */ static void dump_group (hid_t gid, const char *name) { H5G_stat_t statbuf; +hid_t dset, type; +char typename[1024], *tmp; +int i; + + tmp = (char *) malloc ((strlen(prefix)+strlen(name)+2) * sizeof(char)); + strcpy(tmp, prefix); + indentation (indent); begin_obj(GROUP, name); indent += col; - /* hard link */ + if (!strcmp(name,"/") && unamedtype) { /* dump unamed type in root group */ + for (i = 0; i < type_table.nobjs; i++) + if (!type_table.objs[i].displayed) { + 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]); + dump_named_datatype (type, typename); + H5Tclose(type); + H5Dclose(dset); + } + } + H5Gget_objinfo(gid, ".", TRUE, &statbuf); if (statbuf.nlink > 1) { - indentation (indent); - printf("%s %s (%s %u) (%s %lu %lu) (%s %lu %lu ) %s\n", - HARDLINK, BEGIN, NLINK, statbuf.nlink, FILENO, statbuf.fileno[0], - statbuf.fileno[1], OBJNO, statbuf.objno[0], statbuf.objno[1], END); + + i = search_obj (group_table, statbuf.objno); + if (i < 0) { + + indentation (indent); + printf("h5dump error: internal error\n"); + status = 1; + + } else if (group_table.objs[i].displayed) { + + indentation (indent); + printf("%s %s \"%s\" %s\n",HARDLINK, BEGIN, group_table.objs[i].objname,END); + + } else { + + 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); + + } + + } else { + + H5Aiterate (gid, NULL, dump_attr, NULL); + H5Giterate (gid, ".", NULL, dump_all, NULL); + } - H5Aiterate (gid, NULL, dump_attr, NULL); - H5Giterate (gid, ".", NULL, dump_all, NULL); indent -= col; indentation (indent); end_obj(); + + free(tmp); } @@ -649,20 +843,10 @@ H5G_stat_t statbuf; static void dump_dataset (hid_t did, const char *name) { hid_t type, space; -H5G_stat_t statbuf; indentation (indent); begin_obj(DATASET, name); - /* hard link */ - H5Gget_objinfo(did, ".", TRUE, &statbuf); - if (statbuf.nlink > 1) { - indentation (indent+col); - printf("%s %s (%s %u) (%s %lu %lu) (%s %lu %lu ) %s\n", - HARDLINK, BEGIN, NLINK, statbuf.nlink, FILENO, statbuf.fileno[0], - statbuf.fileno[1], OBJNO, statbuf.objno[0], statbuf.objno[1], END); - } - type = H5Dget_type (did); space = H5Dget_space (did); dump_datatype(type); @@ -701,10 +885,7 @@ H5G_stat_t statbuf; printf("DATA{ not yet implemented.}\n"); break; case H5T_COMPOUND: - indent += col; - indentation (indent); - indent -= col; - printf("DATA{ not yet implemented.}\n"); + dump_data(did, DATASET_DATA); break; default: break; } @@ -715,6 +896,7 @@ H5G_stat_t statbuf; H5Tclose(type); H5Sclose(space); + indentation (indent); end_obj(); @@ -722,6 +904,256 @@ H5G_stat_t statbuf; /*------------------------------------------------------------------------- + * 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; + } + + 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; + } + + for (i = 0; i < type_table.size; i++) { + dset_table.objs[i].objno[0] = dset_table.objs[i].objno[1] = 0; + dset_table.objs[i].displayed = 0; + } + + prefix = (char *) malloc(prefix_len * sizeof (char)); + strcpy(prefix, ""); +} + + +/*------------------------------------------------------------------------- + * 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; + } + } + + i = table->nobjs++; + table->objs[i].objno[0] = *objno; + table->objs[i].objno[1] = *(objno+1); + strcpy (table->objs[i].objname, objname); + +} + + +/*------------------------------------------------------------------------- + * Function: dump_tables + * + * Purpose: display the contents of tables for debugging purposes + * + * Return: void + * + * Programmer: Ruey-Hsia Li + * + * 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", group_table.objs[i].objno[0], + group_table.objs[i].objno[1], + group_table.objs[i].objname, + group_table.objs[i].displayed); + + printf("\ndset_table: # of entries = %d\n", dset_table.nobjs); + for ( i = 0; i < dset_table.nobjs; i++) + printf ("%ul %ul %s %d\n", dset_table.objs[i].objno[0], + dset_table.objs[i].objno[1], + dset_table.objs[i].objname, + dset_table.objs[i].displayed); + + printf("\ntype_table: # of entries = %d\n", type_table.nobjs); + for ( i = 0; i < type_table.nobjs; i++) + printf ("%ul %ul %s %d\n", type_table.objs[i].objno[0], + type_table.objs[i].objno[1], + type_table.objs[i].objname, + type_table.objs[i].displayed); +} +*/ + + +/*------------------------------------------------------------------------- + * Function: Find_shared_objs + * + * Purpose: Find shared objects, committed types and store them in tables + * + * Return: Success: SUCCEED + * + * Failure: FAIL + * + * 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); + + strcpy(prefix, tmp); + H5Gclose (obj); + + } else + status = 1; + + break; + + case H5G_DATASET: + + 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) ; + type_table.objs[type_table.nobjs-1].displayed = 0; + } + } + H5Tclose(type); + H5Dclose (obj); + } else + status = 1; + + break; + + 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].displayed = 1; /* named data type */ + } else { + strcpy (type_table.objs[i].objname, tmp); + type_table.objs[i].displayed = 1; /* named data type */ + } + break; + + default: + break; + } + + free (tmp); + + return SUCCEED; +} + + +/*------------------------------------------------------------------------- * Function: dump_data * * Purpose: Dump attribute or dataset data @@ -742,7 +1174,7 @@ dump_data (hid_t obj_id, int obj_data) { indent += col; indentation (indent); - printf("%s %s", DATA, BEGIN); + printf("%s %s\n", DATA, BEGIN); if (obj_data == DATASET_DATA) f_type = H5Dget_type(obj_id); @@ -754,7 +1186,7 @@ dump_data (hid_t obj_id, int obj_data) { /* Set to all default values and then override */ memset(&info, 0, sizeof info); info.idx_fmt = " (%s) "; - info.line_ncols = 80; + info.line_ncols = 70 - indent; /* * If the dataset is a 1-byte integer type then format it as an ASCI @@ -764,8 +1196,11 @@ dump_data (hid_t obj_id, int obj_data) { info.elmt_suf1 = ""; info.elmt_suf2 = ""; info.idx_fmt = " (%s) \""; +/* info.line_suf = "\""; - printf("\""); +*/ + info.line_suf = ""; + ischar = 1; } @@ -774,12 +1209,14 @@ dump_data (hid_t obj_id, int obj_data) { */ if (h5dump1(stdout, &info, obj_id, -1, obj_data)<0) { - printf("Unable to print data."); + indentation(indent+col); + printf("Unable to print data.\n"); } if (1==size && H5T_INTEGER==H5Tget_class(f_type)) - printf("\""); + ischar = 0; + indentation(indent); printf("%s\n", END); indent -= col; @@ -789,7 +1226,7 @@ dump_data (hid_t obj_id, int obj_data) { /*------------------------------------------------------------------------- - * Function: + * Function: main * * Purpose: HDF5 dumper * @@ -803,19 +1240,20 @@ dump_data (hid_t obj_id, int obj_data) { *-----------------------------------------------------------------------*/ int main(int argc, char *argv[]) { -hid_t fid, gid, dsetid; +hid_t fid, gid, dsetid, typeid; hid_t plist=H5P_DEFAULT; const char *fname = NULL; -int i, curr_arg, display_bb=0, display_all=1; +int i, index, curr_arg, display_bb=0, display_all=1; int nopts=0, *opts; -char *buf; +char *buf, name[128], name1[128]; H5G_stat_t statbuf; void __unused__ *op_data; - hid_t (*func)(void*); - void *edata; - /* Disable error reporting */ - H5Eget_auto (&func, &edata); - H5Eset_auto (NULL, NULL); +void *edata; +hid_t (*func)(void*); + +/* Disable error reporting */ +H5Eget_auto (&func, &edata); +H5Eset_auto (NULL, NULL); if (argc < 2 ) { usage(); @@ -832,8 +1270,8 @@ void __unused__ *op_data; opts[nopts++] = curr_arg; if (!strcmp(argv[curr_arg],"-h")) { - usage(); + free(opts); exit(0); } else if (!strcmp(argv[curr_arg],"-bb")) @@ -847,11 +1285,13 @@ void __unused__ *op_data; else if (strcmp(argv[curr_arg],"-a") && strcmp(argv[curr_arg],"-d") && strcmp(argv[curr_arg],"-g") && - strcmp(argv[curr_arg],"-l")) { + strcmp(argv[curr_arg],"-l") && + strcmp(argv[curr_arg],"-t")) { fprintf(stderr, "h5dump error: illegal option %s \n", argv[curr_arg]); usage(); + free(opts); exit(1); } else display_all = 0; } @@ -861,6 +1301,7 @@ void __unused__ *op_data; if (opts[0] == 1) { /* argv[1] is an option */ fprintf(stderr, "h5dump error: no <names> or no <file>\n"); usage(); + free(opts); exit(1); } } else { @@ -871,6 +1312,7 @@ void __unused__ *op_data; fprintf(stderr,"h5dump error: no <names> after option %s\n", argv[opts[i]]); usage(); + free(opts); exit(1); } } @@ -878,6 +1320,7 @@ void __unused__ *op_data; if (argc - opts[nopts-1] == 1) { fprintf(stderr,"h5dump error: no <file>\n"); usage(); + free(opts); exit(1); } if (argc - opts[nopts-1] == 2) { @@ -885,6 +1328,7 @@ void __unused__ *op_data; strcmp(argv[opts[i]], "-header") ) { fprintf (stderr, "h5dump error: no <file> or no <names> after option %s\n", argv[opts[i]]); usage(); + free(opts); exit(1); } } @@ -896,9 +1340,32 @@ void __unused__ *op_data; if ((fid = H5Fopen (fname, H5F_ACC_RDONLY, plist)) < 0) { fprintf (stderr, "h5dump error: unable to open file %s \n", fname); + free(opts); exit(1); } + /* allocate and initialize internal data structure */ + init_table(); + + /* find all shared objects */ + H5Giterate (fid, "/", NULL, find_shared_objs, NULL); + strcpy(prefix, ""); + + /* assign names to unamed shared data type */ + for ( i = 0; i < type_table.nobjs; i++) + if (type_table.objs[i].displayed == 0) unamedtype = 1; + +/* + #ifdef H5DUMP_DEBUG + dump_tables(); + #endif +*/ + + if (status) { + printf("internal error! \n"); + goto done; + } + begin_obj("HDF5", fname); if (display_bb) dump_bb(); @@ -908,7 +1375,7 @@ void __unused__ *op_data; if ((gid = H5Gopen (fid, "/")) < 0 ) { fprintf(stdout, "h5dump error: unable to open root group\n"); status = 1; - } else + } else dump_group(gid, "/"); if (H5Gclose (gid) < 0) { @@ -940,12 +1407,32 @@ void __unused__ *op_data; end_obj(); status = 1; } else { - dump_dataset(dsetid, argv[curr_arg]); + 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]); + indentation (indent+col); + printf("%s %s \"%s\" %s\n",HARDLINK, BEGIN, + dset_table.objs[index].objname,END); + indentation (indent); + end_obj(); + } else { + 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 + dump_dataset(dsetid, argv[curr_arg]); if (H5Dclose(dsetid)<1) status = 1; } } + + } else if (!strcmp(argv[opts[i]],"-g")) { for (curr_arg = opts[i]+1; @@ -959,6 +1446,8 @@ void __unused__ *op_data; end_obj(); 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; } @@ -984,7 +1473,7 @@ void __unused__ *op_data; begin_obj(SOFTLINK, argv[curr_arg]); indentation (col); if (H5Gget_linkval (fid, argv[curr_arg], statbuf.linklen, buf)>=0) - printf ("linktarget \"%s\"\n", buf); + printf ("LINKTARGET \"%s\"\n", buf); else { fprintf (stdout, "h5dump error: unable to get link value\n"); status = 1; @@ -1002,16 +1491,65 @@ void __unused__ *op_data; } + } else if (!strcmp(argv[opts[i]],"-t")) { + + + for (curr_arg = opts[i]+1; + curr_arg < ((i+1)==nopts?(argc-1):opts[i+1]); + curr_arg++) { + + if ((typeid=H5Topen (fid, argv[curr_arg])) < 0) { + + /* check if argv[curr_arg] is unamed data type */ + index = 0; + while (index < type_table.nobjs ) { + if (!type_table.objs[index].displayed) { /* 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; + } + } + index++; + } + if (index == type_table.nobjs) { /* unknown type */ + begin_obj (DATATYPE, argv[curr_arg]); + indentation (col); + fprintf (stdout, "h5dump error: unable to open %s\n", + argv[curr_arg]); + end_obj(); + status = 1; + } else { + dsetid = H5Dopen (fid, type_table.objs[index].objname) ; + typeid = H5Dget_type (dsetid); + dump_named_datatype (typeid, argv[curr_arg]); + H5Tclose(typeid); + H5Dclose(dsetid); + } + + } else { + dump_named_datatype (typeid, argv[curr_arg]); + if (H5Tclose(typeid) < 0) status = 1; + } + } } } end_obj(); - free(opts); +done: - /* Restore error reporting */ H5Eset_auto (func, edata); - if (H5Fclose (fid) < 0) exit(1); + free(opts); + if (H5Fclose (fid) < 0) status = 1; + + free (group_table.objs); + free (dset_table.objs); + free (type_table.objs); + free (prefix); return status; diff --git a/tools/h5dump.h b/tools/h5dump.h index aa1d296..2af2d04 100644 --- a/tools/h5dump.h +++ b/tools/h5dump.h @@ -27,22 +27,13 @@ #define ATTRIBUTE_DATA 0 #define DATASET_DATA 1 +#define H5DUMP_MAX_NDIMS 64 #define begin_obj(obj,name) printf("%s \"%s\" %s\n", obj, name, BEGIN) #define end_obj() printf("%s\n", END); #define col 3 - -/* -typedef enum - { - h, bb, header, a, d, g, l - } -command_t; -*/ - - #endif diff --git a/tools/h5dumputil.c b/tools/h5dumputil.c index 63e1f71..b23251b 100644 --- a/tools/h5dumputil.c +++ b/tools/h5dumputil.c @@ -33,6 +33,8 @@ #define NELMTS(X) (sizeof(X)/sizeof(*X)) #define ALIGN(A,Z) ((((A)+(Z)-1)/(Z))*(Z)) +extern int indent; +extern int ischar; /*------------------------------------------------------------------------- @@ -231,7 +233,7 @@ h5dump_simple(FILE *stream, const h5dump_t *info, hid_t dset, hid_t p_type, int hsize_t elmtno, i; /*counters */ int carry; /*counter carry value */ hssize_t zero[8]; /*vector of zeros */ - /* int need_prefix=1;*/ /*indices need printing */ + int need_prefix=1; /*indices need printing */ /* Print info */ hsize_t p_min_idx[8]; /*min selected index */ @@ -239,9 +241,9 @@ h5dump_simple(FILE *stream, const h5dump_t *info, hid_t dset, hid_t p_type, int size_t p_type_nbytes; /*size of memory type */ hsize_t p_nelmts; /*total selected elmts */ char p_buf[256]; /*output string */ - /* size_t p_column=0;*/ /*output column */ + size_t p_column=0; /*output column */ size_t p_ncolumns=80; /*default num columns */ - /* char p_prefix[1024];*/ /*line prefix string */ + char p_prefix[1024]; /*line prefix string */ /* Stripmine info */ hsize_t sm_size[8]; /*stripmine size */ @@ -254,7 +256,7 @@ h5dump_simple(FILE *stream, const h5dump_t *info, hid_t dset, hid_t p_type, int hssize_t hs_offset[8]; /*starting offset */ hsize_t hs_size[8]; /*size this pass */ hsize_t hs_nelmts; /*elements in request */ - +int j, print_once=1; /* * Check that everything looks okay. The dimensionality must not be too * great and the dimensionality of the items selected for printing must @@ -331,7 +333,6 @@ h5dump_simple(FILE *stream, const h5dump_t *info, hid_t dset, hid_t p_type, int } /* Print the prefix */ -/* if ((p_column + strlen(p_buf) + strlen(OPT(info->elmt_suf2, " ")) + @@ -339,26 +340,34 @@ h5dump_simple(FILE *stream, const h5dump_t *info, hid_t dset, hid_t p_type, int need_prefix = 1; } if (need_prefix) { +/* h5dump_prefix(p_prefix, info, elmtno+i, ndims, p_min_idx, p_max_idx); +*/ + if (p_column) { fputs(OPT(info->line_suf, ""), stream); putc('\n', stream); fputs(OPT(info->line_sep, ""), stream); + } + for (j=0;j<indent+col;j++) putc(' ', stream); + if (ischar && print_once) { + putc('"', stream); + print_once=0; + } +/* fputs(p_prefix, stream); +*/ p_column = strlen(p_prefix); need_prefix = 0; } else { fputs(OPT(info->elmt_suf2, " "), stream); p_column += strlen(OPT(info->elmt_suf2, " ")); } -*/ fputs(p_buf, stream); -/* p_column += strlen(p_buf); -*/ } @@ -373,13 +382,17 @@ h5dump_simple(FILE *stream, const h5dump_t *info, hid_t dset, hid_t p_type, int } } -/* if (p_column) { +/* fputs(OPT(info->line_suf, ""), stream); +*/ + if (ischar) + putc('"',stream); putc('\n', stream); +/* fputs(OPT(info->line_sep, ""), stream); - } */ + } H5Sclose(sm_space); H5Sclose(f_space); return 0; @@ -559,6 +572,9 @@ h5dump1(FILE *stream, const h5dump_t *info, hid_t dset, hid_t _p_type, int data_ int status; h5dump_t info_dflt; + char p_buf[256], sm_buf[256]; /*tmp for scala */ + int j; + /* Use default values */ if (!stream) stream = stdout; if (!info) { @@ -584,10 +600,24 @@ h5dump1(FILE *stream, const h5dump_t *info, hid_t dset, hid_t _p_type, int data_ f_space = H5Aget_space(dset); if (H5Sis_simple(f_space)<=0) return -1; + + + if ( H5Sget_simple_extent_ndims(f_space) == 0){ + if (data_flag == ATTRIBUTE_DATA) { + if (H5Aread(dset, p_type, sm_buf) < 0) + return -1; + } else return -1; + h5dump_sprint(p_buf, info, p_type, sm_buf); + for (j=0;j<indent+col;j++) putc(' ', stream); + fputs(p_buf, stream); + putc('\n', stream); + H5Sclose(f_space); + } else { H5Sclose(f_space); /* Print the data */ status = h5dump_simple(stream, info, dset, p_type, data_flag); + } if (p_type!=_p_type) H5Tclose(p_type); return status; } diff --git a/tools/testh5dump.sh b/tools/testh5dump.sh index b55bafb..ea607d9 100755 --- a/tools/testh5dump.sh +++ b/tools/testh5dump.sh @@ -190,7 +190,16 @@ TEST tattr-4.ddl -a attr4 tattr.h5 TEST tslink-1.ddl tslink.h5 TEST tslink-2.ddl -l slink2 tslink.h5 -#TEST thlink-1.ddl thlink.h5 +TEST thlink-1.ddl thlink.h5 +TEST thlink-2.ddl -d /g1/link2 /dset /g1/link1/link3 thlink.h5 +TEST thlink-3.ddl -d /dset /g1/link1/link3 /g1/link2 thlink.h5 +TEST thlink-4.ddl -g /g1 thlink.h5 +TEST thlink-5.ddl -d /dset -g /g2 -d /g1/link2 thlink.h5 + +TEST tcomp-1.ddl tcompound.h5 +TEST tcomp-2.ddl -t /type1 /type2 /group1/type3 tcompound.h5 +TEST tcomp-3.ddl -d /group2/dset5 -g /group1 tcompound.h5 +TEST tcomp-4.ddl -t /#3432:0 -g /group2 tcompound.h5 TEST tall-1.ddl tall.h5 TEST tall-2.ddl -header -g /g1/g1.1 -a attr2 tall.h5 |