From defe612ab21a22b9d54e19fa332d45f8489a6da5 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Wed, 6 Oct 2004 11:11:18 -0500 Subject: [svn-r9370] Purpose: Refactor code Description: Refactor common code for determining the native type for using in the tools into separate routine. Also, reduce diffs between the two branches and bring back some fixes from the development branch to the release branch. Platforms tested: FreeBSD 4.10 (sleipnir) too minor to require h5committest --- tools/h5dump/h5dump.c | 156 ++++++++++++++++++----------------------- tools/h5dump/h5dumpgentest.c | 2 +- tools/h5ls/h5ls.c | 146 ++++++++++++++++++-------------------- tools/h5repack/h5repack_copy.c | 24 ++----- tools/h5repack/h5repack_refs.c | 36 +++------- tools/lib/Makefile.in | 2 +- tools/lib/h5diff.c | 2 +- tools/lib/h5diff.h | 5 +- tools/lib/h5diff_array.c | 8 +-- tools/lib/h5diff_attr.c | 24 ++----- tools/lib/h5diff_dset.c | 45 +++--------- tools/lib/h5tools.c | 14 +--- tools/lib/h5tools.h | 6 +- tools/lib/h5tools_filters.c | 2 - tools/lib/h5tools_str.c | 3 - tools/lib/h5tools_type.c | 47 +++++++++++++ tools/lib/h5trav.c | 6 +- tools/lib/h5trav.h | 6 +- tools/lib/talign.c | 7 +- 19 files changed, 228 insertions(+), 313 deletions(-) create mode 100644 tools/lib/h5tools_type.c diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index eabbd61..6ff89d5 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -47,7 +47,7 @@ static int display_all = TRUE; static int display_oid = FALSE; static int display_data = TRUE; static int display_attr_data = TRUE; -static int display_char = FALSE; /*print 1-byte numbers as ASCII? */ +static int display_char = FALSE; /*print 1-byte numbers as ASCII */ static int usingdasho = FALSE; static int display_bb = FALSE; /*superblock */ static int display_dcpl = FALSE; /*dcpl */ @@ -65,9 +65,9 @@ static int display_escape = FALSE; /*escape non printable characters static int doxml = 0; static int useschema = 1; -static const char *xml_dtd_uri = NULL; -static const char *xmlnsprefix="hdf5:"; -hid_t thefile = -1; +static const char *xml_dtd_uri = NULL; +static const char *xmlnsprefix="hdf5:"; +hid_t thefile = -1; /** end XML **/ @@ -79,12 +79,7 @@ static herr_t dump_all(hid_t group, const char *name, void *op_data); #ifdef LATER static void check_compression(hid_t); #endif /* LATER */ -static int xml_name_to_XID(const char *, char *, int , int ); - - - -/* external functions */ -extern int print_data(hid_t, hid_t, int); +static int xml_name_to_XID(const char *, char *, int , int ); static h5dump_t dataformat = { 0, /*raw */ @@ -151,9 +146,8 @@ static h5dump_t dataformat = { "%s", /*dset_blockformat_pre */ "%s", /*dset_ptformat_pre */ "%s", /*dset_ptformat */ - 1 , /*array indices */ - 1 /*escape non printable characters */ - + 1, /*array indices */ + 1 /*escape non printable characters */ }; /** @@ -236,8 +230,8 @@ static h5dump_t xml_dataformat = { "%s", /*dset_blockformat_pre */ "%s", /*dset_ptformat_pre */ "%s", /*dset_ptformat */ - 0 , /*array indices */ - 0 /*escape non printable characters */ + 0, /*array indices */ + 0 /*escape non printable characters */ }; /** XML **/ @@ -1604,7 +1598,7 @@ dump_group(hid_t gid, const char *name) if (!type_table->objs[i].recorded) { dset = H5Dopen(gid, type_table->objs[i].objname); type = H5Dget_type(dset); - sprintf(type_name, "#"H5_PRINTF_HADDR_FMT, type_table->objs[i].objno); + sprintf(type_name, "#"H5_PRINTF_HADDR_FMT, type_table->objs[i].objno); dump_named_datatype(type, type_name); H5Tclose(type); H5Dclose(dset); @@ -1649,7 +1643,7 @@ dump_group(hid_t gid, const char *name) * * Programmer: Ruey-Hsia Li * - * Modifications: + * Modifications: pvn, 2004, added dcpl dump * *------------------------------------------------------------------------- */ @@ -1851,7 +1845,7 @@ dump_subsetting_header(struct subset_t *sset, int dims) * * Programmer: Ruey-Hsia Li * - * Modifications: + * Modifications: pvn, print the matrix indices * *------------------------------------------------------------------------- */ @@ -1868,7 +1862,6 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int pindex) int depth; int stdindent = COL; /* should be 3 */ - outputformat->line_ncols = nCols; outputformat->do_escape=display_escape; /* print the matrix indices */ @@ -1948,14 +1941,8 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int pindex) if(space_type == H5S_NULL || space_type == H5S_NO_CLASS || space_type == H5S_COMPLEX) { status = SUCCEED; } else { - H5T_class_t type_class; - type = H5Aget_type(obj_id); - type_class = H5Tget_class(type); - if(type_class==H5T_BITFIELD) - p_type=H5Tcopy(type); - else - p_type = H5Tget_native_type(type,H5T_DIR_DEFAULT); + p_type = h5tools_get_native_type(type); ndims = H5Sget_simple_extent_dims(space, size, NULL); @@ -2062,35 +2049,29 @@ static void dump_comment(hid_t obj_id) static void dump_fill_value(hid_t dcpl,hid_t type_id, hid_t obj_id) { - h5tools_context_t ctx; /*print context */ - size_t size; - void *buf=NULL; - int nelmts=1; - h5dump_t *outputformat = &dataformat; - hid_t n_type; - H5T_class_t type_class; - - memset(&ctx, 0, sizeof(ctx)); - ctx.indent_level=2; - - type_class = H5Tget_class(type_id); - if(type_class==H5T_BITFIELD) - n_type=H5Tcopy(type_id); - else - n_type = H5Tget_native_type(type_id,H5T_DIR_DEFAULT); - - size = H5Tget_size(n_type); - buf = malloc(size); - - H5Pget_fill_value(dcpl, n_type, buf); - - h5tools_dump_simple_data(stdout, outputformat, obj_id, &ctx, - START_OF_DATA | END_OF_DATA, nelmts, n_type, buf); + h5tools_context_t ctx; /*print context */ + size_t size; + void *buf=NULL; + hsize_t nelmts=1; + h5dump_t *outputformat = &dataformat; + hid_t n_type; + + memset(&ctx, 0, sizeof(ctx)); + ctx.indent_level=2; - H5Tclose(n_type); + n_type = h5tools_get_native_type(type_id); - if (buf) - free (buf); + size = H5Tget_size(n_type); + buf = malloc(size); + + H5Pget_fill_value(dcpl, n_type, buf); + + h5tools_dump_simple_data(stdout, outputformat, obj_id, &ctx, START_OF_DATA | END_OF_DATA, nelmts, n_type, buf); + + H5Tclose(n_type); + + if (buf) + free (buf); } @@ -2189,8 +2170,8 @@ dump_dcpl(hid_t dcpl_id,hid_t type_id, hid_t obj_id) printf("%s %s\n", EXTERNAL, BEGIN); /*start indent */ indent += COL; - for ( i=0; idatasetend, dump_header_format->datasetblockend); } else { - dset_table->objs[idx].displayed = 1; dump_dataset(dsetid, dset, sset); } @@ -3458,7 +3444,6 @@ main(int argc, const char *argv[]) info.dset_table = dset_table; info.status = d_status; - thefile = fid; /* find all objects that might be targets of a refernce */ if ((gid = H5Gopen(fid, "/")) < 0) { @@ -3542,7 +3527,7 @@ main(int argc, const char *argv[]) } } - if (!doxml) + if (!doxml) { if (display_fi) { @@ -3626,7 +3611,7 @@ done: /*------------------------------------------------------------------------- * Function: print_enum * - * Purpose: prints the enum data - + * Purpose: prints the enum data * * Return: void * @@ -4849,13 +4834,7 @@ xml_dump_data(hid_t obj_id, int obj_data, struct subset_t UNUSED * sset, int UNU status = xml_print_strs(obj_id, ATTRIBUTE_DATA); } else { /* all other data */ - H5T_class_t type_class; - - type_class = H5Tget_class(type); - if(type_class==H5T_BITFIELD) - p_type=H5Tcopy(type); - else - p_type = H5Tget_native_type(type,H5T_DIR_DEFAULT); + p_type = h5tools_get_native_type(type); H5Tclose(type); @@ -5676,7 +5655,7 @@ check_filters(hid_t dcpl) } } -static void xml_dump_fill_value(hid_t type) +static void xml_dump_fill_value(hid_t dcpl, hid_t type) { size_t sz; size_t i; @@ -5692,6 +5671,8 @@ char * name; space = H5Tget_size(type); buf = malloc((size_t)space); + H5Pget_fill_value(dcpl, type, buf); + if (H5Tget_class(type) == H5T_REFERENCE) { path = lookup_ref_path(*(hobj_ref_t *)buf); @@ -5968,7 +5949,7 @@ xml_dump_dataset(hid_t did, const char *name, struct subset_t UNUSED * sset) indentation(indent + COL); printf("<%sNoFill/>\n",xmlnsprefix); } else { - xml_dump_fill_value(type); + xml_dump_fill_value(dcpl,type); } indent -= COL; @@ -6204,8 +6185,7 @@ xml_print_enum(hid_t type) static hid_t h5_fileaccess(void) { - static const char *multi_letters = "msbrglo"; - + static const char *multi_letters = "msbrglo"; const char *val = NULL; const char *name; char s[1024]; diff --git a/tools/h5dump/h5dumpgentest.c b/tools/h5dump/h5dumpgentest.c index bc84d08..51ca97f 100644 --- a/tools/h5dump/h5dumpgentest.c +++ b/tools/h5dump/h5dumpgentest.c @@ -5098,7 +5098,7 @@ static void gent_string(void) hid_t str_tid; /* datatype ID */ hid_t did; /* dataset ID */ char buf1[]={"quote \" backspace\b form feed\f new line\n tab\t new line\n carriage return\r"}; - char *buf2[SPACE1_DIM1]= { + const char *buf2[SPACE1_DIM1]= { "Four score and seven\n years ago our forefathers brought forth on this continent a new nation,", "conceived in liberty\n and dedicated to the proposition that all men are created equal.", "Now we are engaged\n in a great civil war,", diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c index 6066812..5d1c6b2 100644 --- a/tools/h5ls/h5ls.c +++ b/tools/h5ls/h5ls.c @@ -78,7 +78,6 @@ static herr_t list (hid_t group, const char *name, void *cd); static void display_type(hid_t type, int ind); static char *fix_name(const char *path, const char *base); - hid_t thefile; char *prefix; char *progname; @@ -1333,13 +1332,13 @@ list_attr (hid_t obj, const char *attr_name, void UNUSED *op_data) printf("%*s", MAX(0, 9-n), ""); if ((attr = H5Aopen_name(obj, attr_name))) { - space = H5Aget_space(attr); - type = H5Aget_type(attr); + space = H5Aget_space(attr); + type = H5Aget_type(attr); - /* Data space */ - ndims = H5Sget_simple_extent_dims(space, size, NULL); - space_type = H5Sget_simple_extent_type(space); - switch (space_type) { + /* Data space */ + ndims = H5Sget_simple_extent_dims(space, size, NULL); + space_type = H5Sget_simple_extent_type(space); + switch (space_type) { case H5S_SCALAR: /* scalar dataspace */ puts(" scalar"); @@ -1357,76 +1356,68 @@ list_attr (hid_t obj, const char *attr_name, void UNUSED *op_data) /* null dataspace */ puts(" null"); break; - } - - /* Data type */ - printf(" Type: "); - display_type(type, 15); - putchar('\n'); - - /* Data */ - memset(&info, 0, sizeof info); - info.line_multi_new = 1; - if (nelmts<5) { - info.idx_fmt = ""; - 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="; - if (string_g && 1==H5Tget_size(type) && - H5T_INTEGER==H5Tget_class(type)) { - info.ascii = TRUE; - info.elmt_suf1 = ""; - info.elmt_suf2 = ""; - info.idx_fmt = "(%s)"; - info.line_pre = " %s \""; - info.line_suf = "\""; - } - - /* values of type reference */ - info.obj_format = "-%lu:"H5_PRINTF_HADDR_FMT; - info.obj_hidefileno = 0; - if (hexdump_g) { - p_type = H5Tcopy(type); - } else { - H5T_class_t type_class; - - type_class = H5Tget_class(type); - if(type_class==H5T_BITFIELD) - p_type=H5Tcopy(type); - else - p_type = H5Tget_native_type(type,H5T_DIR_DEFAULT); - } - - if (p_type>=0) { - temp_need= nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type)); - assert(temp_need==(hsize_t)((size_t)temp_need)); - need = (size_t)temp_need; - buf = malloc(need); - assert(buf); - if (H5Aread(attr, p_type, buf)>=0) { - h5tools_dump_mem(stdout, &info, attr, p_type, space, buf, -1); - } - free(buf); - H5Tclose(p_type); - } - - H5Sclose(space); - H5Tclose(type); - H5Aclose(attr); + } + + /* Data type */ + printf(" Type: "); + display_type(type, 15); + putchar('\n'); + + /* Data */ + memset(&info, 0, sizeof info); + info.line_multi_new = 1; + if (nelmts<5) { + info.idx_fmt = ""; + 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="; + if (string_g && 1==H5Tget_size(type) && + H5T_INTEGER==H5Tget_class(type)) { + info.ascii = TRUE; + info.elmt_suf1 = ""; + info.elmt_suf2 = ""; + info.idx_fmt = "(%s)"; + info.line_pre = " %s \""; + info.line_suf = "\""; + } + + /* values of type reference */ + info.obj_format = "-%lu:"H5_PRINTF_HADDR_FMT; + info.obj_hidefileno = 0; + if (hexdump_g) + p_type = H5Tcopy(type); + else + p_type = h5tools_get_native_type(type); + + if (p_type>=0) { + temp_need= nelmts * MAX(H5Tget_size(type), H5Tget_size(p_type)); + assert(temp_need==(hsize_t)((size_t)temp_need)); + need = (size_t)temp_need; + buf = malloc(need); + assert(buf); + if (H5Aread(attr, p_type, buf)>=0) + h5tools_dump_mem(stdout, &info, attr, p_type, space, buf, -1); + free(buf); + H5Tclose(p_type); + } + + H5Sclose(space); + H5Tclose(type); + H5Aclose(attr); } else { - putchar('\n'); + putchar('\n'); } return 0; @@ -2272,6 +2263,3 @@ main (int argc, const char *argv[]) } leave(0); } - - - diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c index 5908809..a5b6a3f 100644 --- a/tools/h5repack/h5repack_copy.c +++ b/tools/h5repack/h5repack_copy.c @@ -259,7 +259,6 @@ int do_copy_objects(hid_t fidin, #endif /* LATER */ int i, j; int wrote=0; - H5T_class_t type_class; /* datatype class */ /*------------------------------------------------------------------------- * copy the suppplied object list @@ -323,15 +322,8 @@ int do_copy_objects(hid_t fidin, for (j=0; jraw) p_type = H5Tcopy(f_type); - else { - H5T_class_t type_class; - - type_class = H5Tget_class(f_type); - if(type_class==H5T_BITFIELD) - p_type=H5Tcopy(f_type); - else - p_type = H5Tget_native_type(f_type,H5T_DIR_DEFAULT); - } + else + p_type = h5tools_get_native_type(f_type); H5Tclose(f_type); @@ -1219,3 +1210,4 @@ h5tools_dump_mem(FILE *stream, const h5dump_t *info, hid_t obj_id, hid_t type, return h5tools_dump_simple_mem(stream, info, obj_id, type, space, mem, indentlevel); } + diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index 7837a5e..f5731a0 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -315,10 +315,10 @@ typedef struct h5dump_t { const char *dset_ptformat_pre; const char *dset_ptformat; - /*print array indices in output matrix */ + /*print array indices in output matrix */ int pindex; - /*escape non printable characters */ + /*escape non printable characters */ int do_escape; } h5dump_t; @@ -473,7 +473,6 @@ extern FILE *rawdatastream; /*output stream for raw data */ #define STRSIZE "STRSIZE" #define STRPAD "STRPAD" #define SUBSET "SUBSET" - #define FILTERS "FILTERS" #define DEFLATE "COMPRESSION DEFLATE" #define DEFLATE_LEVEL "LEVEL" @@ -502,6 +501,7 @@ extern int h5tools_dump_dset(FILE *stream, const h5dump_t *info, hid_t dset hid_t p_typ, struct subset_t *sset, int indentlevel); extern int h5tools_dump_mem(FILE *stream, const h5dump_t *info, hid_t obj_id, hid_t type, hid_t space, void *mem, int indentlevel); +extern hid_t h5tools_get_native_type(hid_t type); extern void h5tools_dump_simple_data(FILE *stream, const h5dump_t *info, hid_t container, h5tools_context_t *ctx/*in,out*/, unsigned flags, diff --git a/tools/lib/h5tools_filters.c b/tools/lib/h5tools_filters.c index 5315fd4..368283f 100644 --- a/tools/lib/h5tools_filters.c +++ b/tools/lib/h5tools_filters.c @@ -1,5 +1,3 @@ - - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright by the Board of Trustees of the University of Illinois. * * All rights reserved. * diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index 3350f51..f5a1690 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -28,8 +28,6 @@ #include "h5tools_str.h" /*function prototypes */ #include "h5tools_ref.h" - - /* * If REPEAT_VERBOSE is defined then character strings will be printed so * that repeated character sequences like "AAAAAAAAAA" are displayed as @@ -931,7 +929,6 @@ h5tools_str_sprint(h5tools_str_t *str, const h5dump_t *info, hid_t container, h5tools_str_append(str, "%s", OPT(info->line_pre, "")); } - for (x = 0; x < ctx->indent_level + 1; x++) h5tools_str_append(str,"%s",OPT(info->line_indent,"")); } /* end if */ diff --git a/tools/lib/h5tools_type.c b/tools/lib/h5tools_type.c new file mode 100644 index 0000000..53a3505 --- /dev/null +++ b/tools/lib/h5tools_type.c @@ -0,0 +1,47 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "h5tools.h" + +/*------------------------------------------------------------------------- + * Function: h5tools_get_native_type + * + * Purpose: Wrapper around H5Tget_native_type() to work around + * Problems with bitfields. + * + * Return: Success: datatype ID + * + * Failure: FAIL + * + * Programmer: Quincey Koziol + * Tuesday, October 5, 2004 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +hid_t +h5tools_get_native_type(hid_t type) +{ + hid_t p_type; + H5T_class_t type_class; + + type_class = H5Tget_class(type); + if(type_class==H5T_BITFIELD) + p_type=H5Tcopy(type); + else + p_type = H5Tget_native_type(type,H5T_DIR_DEFAULT); + + return(p_type); +} diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c index 93211c5..8094c33 100644 --- a/tools/lib/h5trav.c +++ b/tools/lib/h5trav.c @@ -25,7 +25,7 @@ int traverse( hid_t loc_id, int print); herr_t get_nnames( hid_t loc_id, - const char *group_name ); + const char *group_name ); herr_t get_name_type( hid_t loc_id, const char *group_name, @@ -322,14 +322,12 @@ int traverse( hid_t loc_id, int inserted_objs=0; int i, j; - /* get the number of names */ if (( n_names = get_nnames( loc_id, group_name )) < 0 ) return -1; for ( i = 0; i < n_names; i++) { - if (get_name_type( loc_id, group_name, i, &name, &type ) < 0 ) return -1; @@ -407,7 +405,6 @@ int traverse( hid_t loc_id, } - break; /*------------------------------------------------------------------------- @@ -512,7 +509,6 @@ int traverse( hid_t loc_id, break; - default: break; diff --git a/tools/lib/h5trav.h b/tools/lib/h5trav.h index 671e17c..e8e8a3f 100644 --- a/tools/lib/h5trav.h +++ b/tools/lib/h5trav.h @@ -27,9 +27,9 @@ * the TYPE can be: * H5G_UNKNOWN = -1, * H5G_LINK, Object is a symbolic link - * H5G_GROUP, Object is a group - * H5G_DATASET, Object is a dataset - * H5G_TYPE, Object is a named data type + * H5G_GROUP, Object is a group + * H5G_DATASET, Object is a dataset + * H5G_TYPE, Object is a named data type *------------------------------------------------------------------------- */ diff --git a/tools/lib/talign.c b/tools/lib/talign.c index 082e37e..bb9f96e 100644 --- a/tools/lib/talign.c +++ b/tools/lib/talign.c @@ -29,7 +29,6 @@ int main(void) hsize_t dim[2]; hsize_t cdim[4]; - H5T_class_t type_class; char string5[5]; float fok[2] = {1234., 2341.}; @@ -73,11 +72,7 @@ int main(void) H5Tinsert(cmp, "Not Ok", sizeof(fok) + sizeof(string5), array_dt); H5Tclose(array_dt); - type_class = H5Tget_class(cmp); - if(type_class==H5T_BITFIELD) - fix=H5Tcopy(cmp); - else - fix=H5Tget_native_type(cmp, H5T_DIR_DEFAULT); + fix=h5tools_get_native_type(cmp); cmp1 = H5Tcreate(H5T_COMPOUND, sizeof(fok)); -- cgit v0.12