diff options
author | Ruey-Hsia Li <rli@ncsa.uiuc.edu> | 1998-12-21 22:45:01 (GMT) |
---|---|---|
committer | Ruey-Hsia Li <rli@ncsa.uiuc.edu> | 1998-12-21 22:45:01 (GMT) |
commit | ee9cac2af920182455f1985a79ac4745dca9a3c9 (patch) | |
tree | 72a02610e8fedfcd00fbd042506291372c3211d1 /tools/h5dump.c | |
parent | 38309fb3f68ad3fd6bb07da6f6d4d1be1a146855 (diff) | |
download | hdf5-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.)
Diffstat (limited to 'tools/h5dump.c')
-rw-r--r-- | tools/h5dump.c | 185 |
1 files changed, 125 insertions, 60 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], |