summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuey-Hsia Li <rli@ncsa.uiuc.edu>1998-12-21 22:45:01 (GMT)
committerRuey-Hsia Li <rli@ncsa.uiuc.edu>1998-12-21 22:45:01 (GMT)
commitee9cac2af920182455f1985a79ac4745dca9a3c9 (patch)
tree72a02610e8fedfcd00fbd042506291372c3211d1
parent38309fb3f68ad3fd6bb07da6f6d4d1be1a146855 (diff)
downloadhdf5-ee9cac2af920182455f1985a79ac4745dca9a3c9.zip
hdf5-ee9cac2af920182455f1985a79ac4745dca9a3c9.tar.gz
hdf5-ee9cac2af920182455f1985a79ac4745dca9a3c9.tar.bz2
[svn-r983] Added tests in testh5dump.sh.
Features of this version of dumper * loop detection * data type ** atomic type -> H5T_INTEGER (H5T_STD_XXXXX) -> H5T_FLOAT (H5T_IEEE_XXXXX) -> H5T_STRING (H5T_C_S1, H5T_FORTRAN_S1) ** committed/transient/unamed compound type * data space ** scalar space ** simple space * dataset dumper can display dataset's ** attribute ** type ** space ** data * group dumper can display group attributes and group members which include ** named/unamed data type ** group ** dataset ** softlink * attribute dumper can display attribute's ** type ** space ** data * hard link * soft link * format of data ** fit on 80 columns ** end of line after each row (more work will be done on data.)
-rw-r--r--tools/h5dump.c185
-rw-r--r--tools/h5dump.h11
-rw-r--r--tools/h5dumputil.c331
-rwxr-xr-xtools/testh5dump.sh37
4 files changed, 349 insertions, 215 deletions
diff --git a/tools/h5dump.c b/tools/h5dump.c
index b0d19a0..043f70e 100644
--- a/tools/h5dump.c
+++ b/tools/h5dump.c
@@ -12,6 +12,7 @@ typedef struct shared_obj_t{
unsigned long objno[2];
char objname[1024];
int displayed;
+int recorded;
} shared_obj_t;
typedef struct table_t{
@@ -96,10 +97,11 @@ static void indentation(int x) {
static void
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];
-
+hid_t nmembers, mtype, str_type;
+int i, j, ndims, perm[H5DUMP_MAX_RANK];
+size_t dims[H5DUMP_MAX_RANK], size;
+H5T_str_t str_pad;
+H5T_cset_t cset;
H5G_stat_t statbuf;
switch (H5Tget_class(type)) {
@@ -187,17 +189,69 @@ H5G_stat_t statbuf;
case H5T_TIME:
printf( "H5T_TIME: not yet implemented");
+ break;
case H5T_STRING:
- if (H5Tequal(type,H5T_C_S1))
- printf( "H5T_C_S1");
- else if (H5Tequal(type,H5T_FORTRAN_S1))
- printf( "H5T_FORTRAN_S1");
- else {
- printf( "undefined string");
+ size = H5Tget_size(type);
+ str_pad = H5Tget_strpad(type) ;
+ cset = H5Tget_cset(type);
+
+ indentation (indent+col);
+ printf("%s %s %d;\n", BEGIN, STRSIZE, size);
+
+ indentation (indent+col);
+ printf(" %s ", STRPAD);
+ if (str_pad == H5T_STR_NULLTERM )
+
+ printf("H5T_STR_NULLTERM;\n");
+
+ else if (str_pad == H5T_STR_NULLPAD )
+
+ printf("H5T_STR_NULLPAD;\n");
+
+ else if (str_pad == H5T_STR_SPACEPAD )
+
+ printf("H5T_STR_SPACEPAD;\n");
+
+ else
+ printf("H5T_STR_ERROR;\n");
+
+ indentation (indent+col);
+ printf(" %s ", CSET);
+ if (cset == H5T_CSET_ASCII)
+ printf("H5T_CSET_ASCII;\n");
+ else
+ printf("unknown_cset;\n");
+
+ str_type = H5Tcopy(H5T_C_S1);
+ H5Tset_cset(str_type, cset ) ;
+ H5Tset_size(str_type, size);
+ H5Tset_strpad(str_type, str_pad);
+
+ indentation (indent+col);
+ printf(" %s ", CTYPE);
+ if (H5Tequal(type,str_type)) {
+ printf("H5T_C_S1;\n");
+ H5Tclose(str_type);
+ } else {
+
+ H5Tclose(str_type);
+ str_type = H5Tcopy(H5T_FORTRAN_S1);
+ H5Tset_cset(str_type, cset ) ;
+ H5Tset_size(str_type, size);
+ H5Tset_strpad(str_type, str_pad );
+ if (H5Tequal(type,str_type))
+ printf( "H5T_FORTRAN_S1;\n");
+ else {
+ printf("unknown_one_character_type;\n ");
status = 1;
+ }
+ H5Tclose(str_type);
}
+ indentation (indent+col);
+ printf("%s\n", END);
+
break;
case H5T_BITFIELD:
@@ -237,12 +291,11 @@ H5G_stat_t statbuf;
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);
+ 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]);
else
- printf("%s %s \"%s\" %s\n", HARDLINK, BEGIN,type_table.objs[i].objname, END);
+ printf("\"%s\"\n", type_table.objs[i].objname);
} else {
printf("h5dump error: unknown committed type.\n");
status = 1;
@@ -264,7 +317,7 @@ H5G_stat_t statbuf;
print_datatype(mtype);
- printf (" %s", fname);
+ printf (" \"%s\"", fname);
if (ndims != 1 || dims[0] != 1) {
for (j = 0; j < ndims; j++)
@@ -326,15 +379,16 @@ dump_datatype (hid_t type) {
indent += col;
indentation (indent);
- if (H5Tget_class(type) == H5T_COMPOUND) {
+ if (H5Tget_class(type) == H5T_COMPOUND ||
+ H5Tget_class(type) == H5T_STRING ) {
printf ("%s %s\n", DATATYPE, BEGIN);
print_datatype(type);
indentation (indent);
printf ("%s\n", END);
} else {
- printf ("%s %s \"", DATATYPE, BEGIN);
+ printf ("%s %s ", DATATYPE, BEGIN);
print_datatype(type);
- printf ("\" %s\n", END);
+ printf (" %s\n", END);
}
indent -= col;
}
@@ -356,8 +410,8 @@ dump_datatype (hid_t type) {
static void
dump_dataspace (hid_t space)
{
- hsize_t size[H5DUMP_MAX_NDIMS];
- hsize_t maxsize[H5DUMP_MAX_NDIMS];
+ hsize_t size[H5DUMP_MAX_RANK];
+ hsize_t maxsize[H5DUMP_MAX_RANK];
int ndims = H5Sget_simple_extent_dims(space, size, maxsize);
int i;
@@ -367,13 +421,13 @@ dump_dataspace (hid_t space)
if (H5Sis_simple(space)) {
- 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]);
+ if (ndims == 0) /* scalar dataspace */
+ HDfprintf (stdout, "%s %s %s\n", BEGIN, SCALAR, END);
+ else { /* simple dataspace */
+ HDfprintf (stdout, "%s %s ( %Hu",BEGIN, SIMPLE, size[0]);
for (i = 1; i < ndims; i++)
HDfprintf (stdout, ", %Hu", size[i]);
- printf(" ) ");
+ printf(" ) / ");
if (maxsize[0]==H5S_UNLIMITED)
HDfprintf (stdout, "( %s", "H5S_UNLIMITED");
@@ -466,21 +520,23 @@ char *obj_name, *attr_name;
hid_t oid, attr_id, type, space;
H5G_stat_t statbuf;
-
j = strlen(name)-1;
- obj_name = malloc ((j+2) * sizeof(char));
+ obj_name = malloc ((j+2)* sizeof(char));
/* find the last / */
while (name[j] != '/' && j >=0) j--;
+
/* object name */
if (j == -1) strcpy(obj_name, "/");
- else strncpy(obj_name, name, j+1);
-
- attr_name = name+j+1;
+ else {
+ strncpy(obj_name, name, j+1);
+ obj_name[j+1] = '\0';
+ }
+ attr_name = name+j+1;
begin_obj (ATTRIBUTE, name);
- H5Gget_objinfo(loc_id, obj_name, FALSE, &statbuf);
+ H5Gget_objinfo(loc_id, obj_name, FALSE , &statbuf);
switch (statbuf.type) {
case H5G_GROUP:
if ((oid = H5Gopen (loc_id, obj_name))<0) {
@@ -650,8 +706,7 @@ int i;
indentation (indent);
begin_obj(DATASET, name);
indentation (indent+col);
- printf("%s %s \"%s\" %s\n",HARDLINK, BEGIN,
- dset_table.objs[i].objname,END);
+ printf("%s \"%s\"\n", HARDLINK, dset_table.objs[i].objname);
indentation (indent);
end_obj();
goto done;
@@ -711,8 +766,8 @@ static void
dump_named_datatype (hid_t type, const char *name) {
char *fname ;
hid_t nmembers, mtype;
-int i, j, ndims, perm[H5DUMP_MAX_NDIMS];
-size_t dims[H5DUMP_MAX_NDIMS];
+int i, j, ndims, perm[H5DUMP_MAX_RANK];
+size_t dims[H5DUMP_MAX_RANK];
indentation (indent);
begin_obj(DATATYPE, name);
@@ -731,7 +786,7 @@ size_t dims[H5DUMP_MAX_NDIMS];
print_datatype(mtype);
- printf (" %s", fname);
+ printf (" \"%s\"", fname);
if (ndims != 1 || dims[0] != 1) {
for (j = 0; j < ndims; j++)
@@ -777,7 +832,7 @@ int i;
if (!strcmp(name,"/") && unamedtype) { /* dump unamed type in root group */
for (i = 0; i < type_table.nobjs; i++)
- if (!type_table.objs[i].displayed) {
+ 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],
@@ -801,12 +856,12 @@ int i;
} else if (group_table.objs[i].displayed) {
indentation (indent);
- printf("%s %s \"%s\" %s\n",HARDLINK, BEGIN, group_table.objs[i].objname,END);
+ printf("%s \"%s\"\n",HARDLINK, group_table.objs[i].objname);
} else {
strcpy(group_table.objs[i].objname, prefix);
- group_table.objs[i].displayed=1;
+ group_table.objs[i].displayed = 1;
H5Aiterate (gid, NULL, dump_attr, NULL);
H5Giterate (gid, ".", NULL, dump_all, NULL);
@@ -930,20 +985,26 @@ int i;
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++) {
- dset_table.objs[i].objno[0] = dset_table.objs[i].objno[1] = 0;
- dset_table.objs[i].displayed = 0;
+ 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';
+/*
strcpy(prefix, "");
+*/
}
@@ -999,6 +1060,7 @@ int i;
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;
}
}
@@ -1029,24 +1091,27 @@ 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],
+ 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].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\n", dset_table.objs[i].objno[0],
+ 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].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\n", type_table.objs[i].objno[0],
+ 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].displayed,
+ type_table.objs[i].recorded);
}
*/
@@ -1118,10 +1183,8 @@ int i;
type = H5Dget_type (obj);
if (H5Tcommitted(type) > 0 ) {
H5Gget_objinfo(type, ".", TRUE, &statbuf);
- if (search_obj (type_table, statbuf.objno) < 0) {
+ 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);
@@ -1136,10 +1199,10 @@ int i;
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 */
+ type_table.objs[type_table.nobjs-1].recorded = 1; /* named data type */
} else {
strcpy (type_table.objs[i].objname, tmp);
- type_table.objs[i].displayed = 1; /* named data type */
+ type_table.objs[i].recorded = 1;
}
break;
@@ -1192,7 +1255,8 @@ dump_data (hid_t obj_id, int obj_data) {
* If the dataset is a 1-byte integer type then format it as an ASCI
* character string instead of integers.
*/
- if (1==size && H5T_INTEGER==H5Tget_class(f_type)) {
+ if ((1==size && H5T_INTEGER==H5Tget_class(f_type)) ||
+ (H5T_STRING == H5Tget_class(f_type))) {
info.elmt_suf1 = "";
info.elmt_suf2 = "";
info.idx_fmt = " (%s) \"";
@@ -1211,6 +1275,7 @@ dump_data (hid_t obj_id, int obj_data) {
if (h5dump1(stdout, &info, obj_id, -1, obj_data)<0) {
indentation(indent+col);
printf("Unable to print data.\n");
+ status = 1;
}
if (1==size && H5T_INTEGER==H5Tget_class(f_type))
@@ -1351,9 +1416,9 @@ H5Eset_auto (NULL, NULL);
H5Giterate (fid, "/", NULL, find_shared_objs, NULL);
strcpy(prefix, "");
- /* assign names to unamed shared data type */
+ /* does there exist unamed committed data type */
for ( i = 0; i < type_table.nobjs; i++)
- if (type_table.objs[i].displayed == 0) unamedtype = 1;
+ if (type_table.objs[i].recorded == 0) unamedtype = 1;
/*
#ifdef H5DUMP_DEBUG
@@ -1366,6 +1431,7 @@ H5Eset_auto (NULL, NULL);
goto done;
}
+ /* start to dump */
begin_obj("HDF5", fname);
if (display_bb) dump_bb();
@@ -1391,7 +1457,6 @@ H5Eset_auto (NULL, NULL);
for (curr_arg = opts[i]+1;
curr_arg < ((i+1)==nopts?(argc-1):opts[i+1]);
curr_arg++)
-
dump_selected_attr (fid, argv[curr_arg]);
} else if (!strcmp(argv[opts[i]],"-d")) {
@@ -1414,8 +1479,8 @@ H5Eset_auto (NULL, NULL);
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);
+ printf("%s \"%s\"\n", HARDLINK,
+ dset_table.objs[index].objname);
indentation (indent);
end_obj();
} else {
@@ -1503,7 +1568,7 @@ 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].displayed) { /* unamed data type */
+ 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],
diff --git a/tools/h5dump.h b/tools/h5dump.h
index 02b3166..0a55508 100644
--- a/tools/h5dump.h
+++ b/tools/h5dump.h
@@ -10,8 +10,9 @@
#define DATATYPE "DATATYPE"
#define DATASPACE "DATASPACE"
#define DATA "DATA"
-#define ARRAY "ARRAY"
-#define OTHER "OTHER"
+#define SCALAR "SCALAR"
+#define SIMPLE "SIMPLE"
+#define COMPLEX "COMPLEX"
#define STORAGELAYOUT "STORAGELAYOUT"
#define COMPRESSION "COMPRESSION"
#define EXTERNAL "EXTERNAL"
@@ -20,6 +21,10 @@
#define NLINK "NLINK"
#define FILENO "FILENO"
#define OBJNO "OBJNO"
+#define STRSIZE "STRSIZE"
+#define STRPAD "STRPAD"
+#define CSET "CSET"
+#define CTYPE "CTYPE"
#define BEGIN "{"
#define END "}"
@@ -27,7 +32,7 @@
#define ATTRIBUTE_DATA 0
#define DATASET_DATA 1
-#define H5DUMP_MAX_NDIMS 64
+#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);
diff --git a/tools/h5dumputil.c b/tools/h5dumputil.c
index d033092..4ae9012 100644
--- a/tools/h5dumputil.c
+++ b/tools/h5dumputil.c
@@ -36,69 +36,6 @@
extern int indent;
extern int ischar;
-
-/*-------------------------------------------------------------------------
- * Function: h5dump_prefix
- *
- * Purpose: Prints the prefix to show up at the begining of the line.
- *
- * Return: void
- *
- * Programmer: Robb Matzke
- * Thursday, July 23, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-/*
-static void
-h5dump_prefix(char *s, const h5dump_t *info, hsize_t elmtno, int ndims,
- hsize_t min_idx[], hsize_t max_idx[])
-{
- hsize_t p_prod[8], p_idx[8];
- hsize_t n, i;
- char temp[1024];
-
-*/
- /*
- * Calculate the number of elements represented by a unit change in a
- * certain index position.
- */
-/*
- for (i=ndims-1, p_prod[ndims-1]=1; i>0; --i) {
- p_prod[i-1] = (max_idx[i]-min_idx[i]) * p_prod[i];
- }
-*/
- /*
- * Calculate the index values from the element number.
- */
-/*
- for (i=0, n=elmtno; i<(hsize_t)ndims; i++) {
- p_idx[i] = n / p_prod[i] + min_idx[i];
- n %= p_prod[i];
- }
-*/
- /*
- * Print the index values.
- */
-/*
- *temp = '\0';
- for (i=0; i<(hsize_t)ndims; i++) {
- if (i) strcat(temp, OPT(info->idx_sep, ","));
- sprintf(temp+strlen(temp), OPT(info->idx_n_fmt, "%lu"),
- (unsigned long)p_idx[i]);
- }
-*/
-
- /*
- * Add prefix and suffix to the index.
- */
-/*
- sprintf(s, OPT(info->idx_fmt, "%s: "), temp);
-}
-*/
-
/*-------------------------------------------------------------------------
* Function: h5dump_sprint
*
@@ -121,11 +58,23 @@ h5dump_sprint(char *s/*out*/, const h5dump_t *info, hid_t type, void *vp)
char temp[1024], *name;
hid_t memb;
int nmembs, j, k, ndims;
-
+
if (H5Tequal(type, H5T_NATIVE_DOUBLE)) {
sprintf(temp, "%g", *((double*)vp));
} else if (H5Tequal(type, H5T_NATIVE_FLOAT)) {
sprintf(temp, "%g", *((float*)vp));
+ } else if (H5Tequal(type, H5T_NATIVE_SHORT)) {
+ sprintf(temp, "%d", *((short*)vp));
+ } else if (H5Tequal(type, H5T_NATIVE_USHORT)) {
+ sprintf(temp, "%u", *((unsigned short*)vp));
+ } else if (H5Tequal(type, H5T_NATIVE_INT)) {
+ sprintf(temp, "%d", *((int*)vp));
+ } else if (H5Tequal(type, H5T_NATIVE_UINT)) {
+ sprintf(temp, "%u", *((unsigned*)vp));
+ } else if (H5Tequal(type, H5T_NATIVE_LONG)) {
+ sprintf(temp, "%ld", *((long*)vp));
+ } else if (H5Tequal(type, H5T_NATIVE_ULONG)) {
+ sprintf(temp, "%lu", *((unsigned long*)vp));
} else if (H5Tequal(type, H5T_NATIVE_SCHAR) ||
H5Tequal(type, H5T_NATIVE_UCHAR)) {
switch (*((char*)vp)) {
@@ -155,19 +104,7 @@ h5dump_sprint(char *s/*out*/, const h5dump_t *info, hid_t type, void *vp)
else sprintf(temp, "\\%03o", *((unsigned char*)vp));
break;
}
- } else if (H5Tequal(type, H5T_NATIVE_SHORT)) {
- sprintf(temp, "%d", *((short*)vp));
- } else if (H5Tequal(type, H5T_NATIVE_USHORT)) {
- sprintf(temp, "%u", *((unsigned short*)vp));
- } else if (H5Tequal(type, H5T_NATIVE_INT)) {
- sprintf(temp, "%d", *((int*)vp));
- } else if (H5Tequal(type, H5T_NATIVE_UINT)) {
- sprintf(temp, "%u", *((unsigned*)vp));
- } else if (H5Tequal(type, H5T_NATIVE_LONG)) {
- sprintf(temp, "%ld", *((long*)vp));
- } else if (H5Tequal(type, H5T_NATIVE_ULONG)) {
- sprintf(temp, "%lu", *((unsigned long*)vp));
- } else if (H5T_COMPOUND==H5Tget_class(type)) {
+ } else if (H5T_COMPOUND==H5Tget_class(type)) {
nmembs = H5Tget_nmembers(type);
strcpy(temp, OPT(info->cmpd_pre, "{"));
for (j=0; j<nmembs; j++) {
@@ -196,6 +133,10 @@ h5dump_sprint(char *s/*out*/, const h5dump_t *info, hid_t type, void *vp)
H5Tclose(memb);
}
strcat(temp, OPT(info->cmpd_suf, "}"));
+ } else if (H5T_STRING==H5Tget_class(type)) {
+ for (i = 0; i < H5Tget_size(type); i++)
+ h5dump_sprint(s+i, info, H5T_NATIVE_SCHAR, (char*)vp+i);
+ goto done;
} else {
strcpy(temp, "0x");
n = H5Tget_size(type);
@@ -205,8 +146,12 @@ h5dump_sprint(char *s/*out*/, const h5dump_t *info, hid_t type, void *vp)
}
sprintf(s, OPT(info->elmt_fmt, "%s"), temp);
+done:
+ ;
+
}
+
/*-------------------------------------------------------------------------
* Function: h5dump_simple
@@ -226,14 +171,14 @@ h5dump_sprint(char *s/*out*/, const h5dump_t *info, hid_t type, void *vp)
*-------------------------------------------------------------------------
*/
static int
-h5dump_simple(FILE *stream, const h5dump_t *info, hid_t dset, hid_t p_type, int data_flag)
+h5dump_simple(FILE *stream, const h5dump_t *info, hid_t oid, hid_t p_type, int obj_type)
{
hid_t f_space; /*file data space */
int ndims; /*dimensionality */
hsize_t elmtno, i; /*counters */
- int carry; /*counter carry value */
+ /*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 */
@@ -241,9 +186,10 @@ 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 */
@@ -256,19 +202,31 @@ 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;
+int j, row_size, ntokens;
+char out_buf[80], prefix[80];
+
+/*
+ prefix[0] = NULL;
+ out_buf[0] = NULL;
+*/
+ prefix[0] = '\0';
+ out_buf[0] = '\0';
+ if ((indent+col) > 80) indent = 0;
+ for (j=0;j<indent+col;j++) strcat (prefix, " ");
+
+ if (obj_type == DATASET_DATA)
+ f_space = H5Dget_space(oid);
+ else
+ f_space = H5Aget_space(oid);
+
/*
* 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 (data_flag == DATASET_DATA)
- f_space = H5Dget_space(dset);
- else
- f_space = H5Aget_space(dset);
-
ndims = H5Sget_simple_extent_ndims(f_space);
+
if ((size_t)ndims>NELMTS(sm_size)) return -1;
/* Assume entire data space to be printed */
@@ -300,6 +258,40 @@ int j, print_once=1;
/* The stripmine loop */
memset(hs_offset, 0, sizeof hs_offset);
memset(zero, 0, sizeof zero);
+
+ if (ndims == 0) { /* scalar space */
+
+ if (obj_type == 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;
+ }
+
+ if (ischar) {
+
+ for (j = 0; j < (int)p_type_nbytes; j++) {
+ h5dump_sprint(p_buf, info, H5T_NATIVE_SCHAR, sm_buf+j);
+ if ((strlen(out_buf)+strlen(p_buf)+5) > (80-strlen(prefix))) {
+ printf("%s\"%s\" //\n", prefix, out_buf);
+ strcpy(out_buf, p_buf);
+ if ( j+1 == (int)p_type_nbytes )
+ printf("%s\"%s\"\n", prefix, out_buf);
+ } else {
+ strcat(out_buf, p_buf);
+ if ( j+1 == (int)p_type_nbytes )
+ printf("%s\"%s\"\n", prefix, out_buf);
+ }
+ }
+ } else {
+ h5dump_sprint(p_buf, info, p_type, sm_buf);
+ printf("%s%s\n", prefix, p_buf);
+ }
+
+ return 0 ;
+ }
+
+row_size = 0;
for (elmtno=0; elmtno<p_nelmts; elmtno+=hs_nelmts) {
/* Calculate the hyperslab size */
@@ -314,25 +306,81 @@ int j, print_once=1;
H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL,
&hs_nelmts, NULL);
- if (data_flag == DATASET_DATA) {
- if (H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf)<0) {
+ if (obj_type == DATASET_DATA) {
+ if (H5Dread(oid, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf)<0) {
return -1;
}
} else {
- if (H5Aread(dset, p_type, sm_buf) < 0)
+ if (H5Aread(oid, p_type, sm_buf) < 0)
return -1;
}
-
/* Print the data */
+
+ if (ischar)
+ ntokens = 5;
+ else
+ ntokens = 1;
+
for (i=0; i<hs_nelmts; i++) {
- /* Render the element */
+ row_size++;
+ h5dump_sprint(p_buf, info, p_type, sm_buf+i*p_type_nbytes);
+
+ if (H5T_COMPOUND==H5Tget_class(p_type))
+ printf("%s%s\n", prefix, p_buf);
+
+ else {
+ if ((strlen(out_buf)+strlen(p_buf)+ntokens) > (80-strlen(prefix))) {
+ printf("%s", prefix);
+ if (ischar) printf("\"");
+ printf("%s", out_buf);
+ if (ischar) printf("\" //");
+ printf("\n");
+
+ strcpy(out_buf, p_buf);
+ if (row_size == (int)p_max_idx[ndims-1]) {
+ printf("%s", prefix);
+ if (ischar) printf("\"");
+ printf("%s", out_buf);
+ *out_buf = '\0';
+ if (ischar) printf("\"");
+ if ((i+1) != hs_nelmts) {
+ if (ischar) printf(" //");
+ else printf(",");
+ }
+ printf("\n");
+ row_size = 0;
+ } else
+ if (!ischar) strcat(out_buf, ", ");
+ } else {
+ strcat(out_buf, p_buf);
+ if (row_size == (int)p_max_idx[ndims-1]) {
+ printf("%s", prefix);
+ if (ischar) printf("\"");
+ printf("%s", out_buf);
+ if (ischar) printf("\"");
+ if ((i+1) != hs_nelmts) {
+ if (ischar) printf(" //");
+ else printf(",");
+ }
+ printf("\n");
+ *out_buf = '\0';
+ row_size = 0;
+ } else
+ if (!ischar) strcat(out_buf, ", ");
+
+ }
+ }
+
+ }
+/*
+ for (i=0; i<hs_nelmts; i++) {
+ Render the element
h5dump_sprint(p_buf, info, p_type, sm_buf+i*p_type_nbytes);
if (elmtno+i+1<p_nelmts) {
strcat(p_buf, OPT(info->elmt_suf1, ","));
}
- /* Print the prefix */
if ((p_column +
strlen(p_buf) +
strlen(OPT(info->elmt_suf2, " ")) +
@@ -340,10 +388,6 @@ int j, print_once=1;
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);
@@ -356,9 +400,7 @@ int j, print_once=1;
putc('"', stream);
print_once=0;
}
-/*
fputs(p_prefix, stream);
-*/
p_column = strlen(p_prefix);
need_prefix = 0;
} else {
@@ -370,8 +412,10 @@ int j, print_once=1;
p_column += strlen(p_buf);
}
+*/
/* 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]) {
@@ -380,19 +424,18 @@ int j, print_once=1;
carry = 0;
}
}
+*/
}
- if (p_column) {
/*
+ 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;
@@ -422,8 +465,10 @@ h5dump_fixtype(hid_t f_type)
hid_t m_type=-1, f_memb;
hid_t *memb=NULL;
char **name=NULL;
- int nmembs=0, i, j, *ndims=NULL;
+ int nmembs=0, i, j, *ndims=NULL, perm[4];
size_t size, offset, *dims=NULL, nelmts;
+ H5T_str_t strpad;
+
size = H5Tget_size(f_type);
switch (H5Tget_class(f_type)) {
@@ -487,7 +532,7 @@ h5dump_fixtype(hid_t f_type)
if (memb[i]<0) goto done;
/* Get the member dimensions */
- ndims[i] = H5Tget_member_dims(f_type, i, dims+i*4, NULL);
+ ndims[i] = H5Tget_member_dims(f_type, i, dims+i*4, perm);
assert(ndims[i]>=0 && ndims[i]<=4);
for (j=0, nelmts=1; j<ndims[i]; j++) nelmts *= dims[i*4+j];
@@ -506,15 +551,33 @@ h5dump_fixtype(hid_t f_type)
m_type = H5Tcreate(H5T_COMPOUND, size);
for (i=0, offset=0; i<nmembs; i++) {
H5Tinsert_array(m_type, name[i], offset, ndims[i], dims+i*4,
- NULL, memb[i]);
+ perm, memb[i]);
for (j=0, nelmts=1; j<ndims[i]; j++) nelmts *= dims[i*4+j];
offset = ALIGN(offset, H5Tget_size(memb[i])) +
nelmts * H5Tget_size(memb[i]);
}
+/* free name */
break;
case H5T_TIME:
case H5T_STRING:
+
+ 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;
+ }
+
+ break;
+
case H5T_BITFIELD:
case H5T_OPAQUE:
/*
@@ -545,7 +608,7 @@ h5dump_fixtype(hid_t f_type)
/*-------------------------------------------------------------------------
- * Function: h5dump
+ * Function: h5dump1
*
* Purpose: Print some values from a dataset DSET to the file STREAM
* after converting all types to P_TYPE (which should be a
@@ -564,17 +627,14 @@ h5dump_fixtype(hid_t f_type)
*-------------------------------------------------------------------------
*/
int
-h5dump1(FILE *stream, const h5dump_t *info, hid_t dset, hid_t _p_type, int data_flag)
+h5dump1 (FILE *stream, const h5dump_t *info, hid_t oid, hid_t _p_type, int obj_type)
{
hid_t f_space;
hid_t p_type = _p_type;
hid_t f_type;
- int status;
+ int status = -1;
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) {
@@ -582,42 +642,35 @@ h5dump1(FILE *stream, const h5dump_t *info, hid_t dset, hid_t _p_type, int data_
info = &info_dflt;
}
- if (p_type<0) {
- if (data_flag == DATASET_DATA)
- f_type = H5Dget_type(dset);
+ if (p_type < 0) {
+
+ if (obj_type == DATASET_DATA)
+ f_type = H5Dget_type(oid);
else
- f_type = H5Aget_type(dset);
+ f_type = H5Aget_type(oid);
+
+ if (f_type < 0) return status;
p_type = h5dump_fixtype(f_type);
+
H5Tclose(f_type);
- if (p_type<0) return -1;
+
+ if (p_type < 0) return status;
}
/* Check the data space */
- if (data_flag == DATASET_DATA)
- f_space = H5Dget_space(dset);
+ if (obj_type == DATASET_DATA)
+ f_space = H5Dget_space(oid);
else
- f_space = H5Aget_space(dset);
+ f_space = H5Aget_space(oid);
+
+ if (f_space < 0) return status;
- 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 {
+ if (H5Sis_simple(f_space) >= 0)
+ status = h5dump_simple(stream, info, oid, p_type, obj_type);
+
H5Sclose(f_space);
- /* Print the data */
- status = h5dump_simple(stream, info, dset, p_type, data_flag);
- }
- if (p_type!=_p_type) H5Tclose(p_type);
+ if (p_type != _p_type) H5Tclose(p_type);
return status;
}
diff --git a/tools/testh5dump.sh b/tools/testh5dump.sh
index cb68db7..5645d60 100755
--- a/tools/testh5dump.sh
+++ b/tools/testh5dump.sh
@@ -69,35 +69,46 @@ DUMP()
##############################################################################
##############################################################################
+# test for displaying groups
DUMP tgroup-1.ddl tgroup.h5
-DUMP tgroup-2.ddl -g / tgroup.h5
-DUMP tgroup-3.ddl -g /g2 /y tgroup.h5
+# test for displaying the selected groups
+DUMP tgroup-2.ddl -g /g2 / /y tgroup.h5
+# test for displaying simple space datasets
DUMP tdset-1.ddl tdset.h5
-DUMP tdset-2.ddl -d dset1 /dset2 tdset.h5
-DUMP tdset-3.ddl -d /dset1 -header tdset.h5
-DUMP tdset-4.ddl -d dset3 tdset.h5
+# test for displaying selected datasets
+DUMP tdset-2.ddl -header -d dset1 /dset2 dset3 tdset.h5
+# test for displaying attributes
DUMP tattr-1.ddl tattr.h5
-DUMP tattr-2.ddl -a attr1 attr3 tattr.h5
-DUMP tattr-3.ddl -header -a attr2 tattr.h5
-DUMP tattr-4.ddl -a attr4 tattr.h5
+# test for displaying the selected attributes of string type and scalar space
+DUMP tattr-2.ddl -a attr1 attr4 attr5 tattr.h5
+# test for header and error messages
+DUMP tattr-3.ddl -header -a attr2 attr tattr.h5
+# test for displaying soft links
DUMP tslink-1.ddl tslink.h5
+# test for displaying the selected link
DUMP tslink-2.ddl -l slink2 tslink.h5
+# tests for hard links
DUMP thlink-1.ddl thlink.h5
-DUMP thlink-2.ddl -d /g1/link2 /dset /g1/link1/link3 thlink.h5
-DUMP thlink-3.ddl -d /dset /g1/link1/link3 /g1/link2 thlink.h5
+DUMP thlink-2.ddl -d /g1/dset2 /dset1 /g1/g1.1/dset3 thlink.h5
+DUMP thlink-3.ddl -d /g1/g1.1/dset3 /g1/dset2 /dset1 thlink.h5
DUMP thlink-4.ddl -g /g1 thlink.h5
-DUMP thlink-5.ddl -d /dset -g /g2 -d /g1/link2 thlink.h5
+DUMP thlink-5.ddl -d /dset1 -g /g2 -d /g1/dset2 thlink.h5
+# tests for compound data types
DUMP tcomp-1.ddl tcompound.h5
+# test for named data types
DUMP tcomp-2.ddl -t /type1 /type2 /group1/type3 tcompound.h5
-DUMP tcomp-3.ddl -d /group2/dset5 -g /group1 tcompound.h5
-DUMP tcomp-4.ddl -t /#3432:0 -g /group2 tcompound.h5
+# test for unamed type
+DUMP tcomp-3.ddl -t /#5992:0 -g /group2 tcompound.h5
+# test for options
DUMP tall-1.ddl tall.h5
DUMP tall-2.ddl -header -g /g1/g1.1 -a attr2 tall.h5
DUMP tall-3.ddl -d /g2/dset2.1 -l /g1/g1.2/g1.2.1/slink tall.h5
+# test for loop detection
+DUMP tloop-1.ddl tloop.h5