diff options
author | Bill Wendling <wendling@ncsa.uiuc.edu> | 2001-08-02 17:54:38 (GMT) |
---|---|---|
committer | Bill Wendling <wendling@ncsa.uiuc.edu> | 2001-08-02 17:54:38 (GMT) |
commit | f303405aee3efd78f68c82d8b6cc540a05d34184 (patch) | |
tree | da0b5aca9b86d005c0c6fd09fe1ff35c03209875 | |
parent | 0b850332e9ee4ff638e8468ed8267e93ce325408 (diff) | |
download | hdf5-f303405aee3efd78f68c82d8b6cc540a05d34184.zip hdf5-f303405aee3efd78f68c82d8b6cc540a05d34184.tar.gz hdf5-f303405aee3efd78f68c82d8b6cc540a05d34184.tar.bz2 |
[svn-r4306]
Purpose:
Back port of Feature Add
Description:
Added the feature to specify which driver you want for the H5dumper
using the command-line flag "-f D or --filedriver=D".
Platforms tested:
Linux
-rw-r--r-- | tools/h5dump/h5dump.c | 111 | ||||
-rw-r--r-- | tools/lib/h5tools.c | 162 | ||||
-rw-r--r-- | tools/lib/h5tools.h | 10 |
3 files changed, 196 insertions, 87 deletions
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index eea5913..4a99794 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -1,12 +1,12 @@ /* - * Copyright (C) 1998-2001 National Center for Supercomputing Applications - * All rights reserved. + * Copyright (C) 1998, 1999, 2000, 2001 + * National Center for Supercomputing Applications + * All rights reserved. * */ #include <stdio.h> #include <stdlib.h> - #include "h5dump.h" #include "H5private.h" #include "h5tools.h" @@ -16,10 +16,11 @@ static const char *progname = "h5dump"; static int d_status = EXIT_SUCCESS; -static int unamedtype = 0; /* shared data type with no name */ +static int unamedtype = 0; /* shared data type with no name */ static int prefix_len = 1024; static table_t *group_table = NULL, *dset_table = NULL, *type_table = NULL; static char *prefix; +static const char *driver = NULL; /* The driver to open the file with. */ static const dump_header *dump_header_format; @@ -391,9 +392,9 @@ struct handler_t { */ #if 0 /* binary: not implemented yet */ -static const char *s_opts = "hbBHvVa:d:g:l:t:w:xD:o:s:S:c:k:"; +static const char *s_opts = "hbBHvVa:d:f:g:l:t:w:xD:o:s:S:c:k:"; #else -static const char *s_opts = "hBHvVa:d:g:l:t:w:xD:o:s:S:c:k:"; +static const char *s_opts = "hBHvVa:d:f:g:l:t:w:xD:o:s:S:c:k:"; #endif /* 0 */ static struct long_options l_opts[] = { { "help", no_arg, 'h' }, @@ -455,6 +456,15 @@ static struct long_options l_opts[] = { { "datatyp", require_arg, 't' }, { "dataty", require_arg, 't' }, { "datat", require_arg, 't' }, + { "filedriver", require_arg, 'f' }, + { "filedrive", require_arg, 'f' }, + { "filedriv", require_arg, 'f' }, + { "filedri", require_arg, 'f' }, + { "filedr", require_arg, 'f' }, + { "filed", require_arg, 'f' }, + { "file", require_arg, 'f' }, + { "fil", require_arg, 'f' }, + { "fi", require_arg, 'f' }, { "group", require_arg, 'g' }, { "grou", require_arg, 'g' }, { "gro", require_arg, 'g' }, @@ -586,21 +596,22 @@ usage(const char *prog) fflush(stdout); fprintf(stdout, "\ usage: %s [OPTIONS] file\n\ - OPTIONS\n\ - -h, --help Print a usage message and exit\n\ - -B, --bootblock Print the content of the boot block\n\ - -H, --header Print the header only; no data is displayed\n\ - -i, --object-ids Print the object ids\n\ - -V, --version Print version number and exit\n\ - -a P, --attribute=P Print the specified attribute\n\ - -d P, --dataset=P Print the specified dataset\n\ - -g P, --group=P Print the specified group and all members\n\ - -l P, --soft-link=P Print the value(s) of the specified soft link\n\ - -o F, --output=F Output raw data into file F\n\ - -t P, --datatype=P Print the specified named data type\n\ - -w N, --width=N Set the number of columns of output\n\ - -x, --xml Output in XML\n\ - -D U, --xml-dtd=U Use the DTD at U\n\ + OPTIONS\n\ + -h, --help Print a usage message and exit\n\ + -B, --bootblock Print the content of the boot block\n\ + -H, --header Print the header only; no data is displayed\n\ + -i, --object-ids Print the object ids\n\ + -V, --version Print version number and exit\n\ + -a P, --attribute=P Print the specified attribute\n\ + -d P, --dataset=P Print the specified dataset\n\ + -f D, --filedriver=D Specify which driver to open the file with\n\ + -g P, --group=P Print the specified group and all members\n\ + -l P, --soft-link=P Print the value(s) of the specified soft link\n\ + -o F, --output=F Output raw data into file F\n\ + -t P, --datatype=P Print the specified named data type\n\ + -w N, --width=N Set the number of columns of output\n\ + -x, --xml Output in XML\n\ + -D U, --xml-dtd=U Use the DTD at U\n\ \n\ Subsetting is available by using the following options with a dataset\n\ attribute. Subsetting is done by selecting a hyperslab from the data.\n\ @@ -614,8 +625,11 @@ usage: %s [OPTIONS] file\n\ -c L, --count=L Number of blocks to include in selection\n\ -k L, --block=L Size of block in hyperslab\n\ \n\ - P - is the full path from the root group to the object.\n\ + D - is a driver name either: \"sec2\", \"family\", \"split\", \"multi\", or \"stream\".\n\ + By default, the file will be opened in the same order as specified\n\ + above until one driver succeeds in opening the file.\n\ F - is a filename.\n\ + P - is the full path from the root group to the object.\n\ N - is an integer greater than 1.\n\ L - is a list of integers the number of which are equal to the\n\ number of dimensions in the dataspace being queried\n\ @@ -1768,7 +1782,7 @@ dump_subsetting_header(struct subset_t *sset, int dims) indentation(indent); printf("%s %s ", dump_header_format->startbegin, dump_header_format->startblockbegin); - dump_dims(sset->start, dims); + dump_dims((hsize_t *)sset->start, dims); printf("%s %s\n", dump_header_format->startend, dump_header_format->startblockend); @@ -2063,7 +2077,7 @@ parse_subset_params(char *dset) *brace++ = '\0'; s = calloc(1, sizeof(struct subset_t)); - s->start = parse_hsize_list(brace); + s->start = (hssize_t *)parse_hsize_list(brace); while (*brace && *brace != ';') brace++; @@ -2180,21 +2194,21 @@ handle_datasets(hid_t fid, char *dset, void *data) H5Gget_objinfo(dsetid, ".", TRUE, &statbuf); if (statbuf.nlink > 1) { - int index = search_obj(dset_table, statbuf.objno); + int idx = search_obj(dset_table, statbuf.objno); - if (index >= 0) { - if (dset_table->objs[index].displayed) { + if (idx >= 0) { + if (dset_table->objs[idx].displayed) { begin_obj(dump_header_format->datasetbegin, dset, dump_header_format->datasetblockbegin); indentation(indent + COL); printf("%s \"%s\"\n", HARDLINK, - dset_table->objs[index].objname); + dset_table->objs[idx].objname); indentation(indent); end_obj(dump_header_format->datasetend, dump_header_format->datasetblockend); } else { - strcpy(dset_table->objs[index].objname, dset); - dset_table->objs[index].displayed = 1; + strcpy(dset_table->objs[idx].objname, dset); + dset_table->objs[idx].displayed = 1; dump_dataset(dsetid, dset, sset); } } else { @@ -2323,29 +2337,29 @@ handle_datatypes(hid_t fid, char *type, void UNUSED *data) if ((typeid = H5Topen(fid, type)) < 0) { /* check if type is unamed data type */ - int index = 0; + int idx = 0; - while (index < type_table->nobjs ) { + while (idx < type_table->nobjs ) { char name[128], name1[128]; - if (!type_table->objs[index].recorded) { + if (!type_table->objs[idx].recorded) { /* unamed data type */ sprintf(name, "#%lu:%lu\n", - type_table->objs[index].objno[0], - type_table->objs[index].objno[1]); + type_table->objs[idx].objno[0], + type_table->objs[idx].objno[1]); sprintf(name1, "/#%lu:%lu\n", - type_table->objs[index].objno[0], - type_table->objs[index].objno[1]); + type_table->objs[idx].objno[0], + type_table->objs[idx].objno[1]); if (!strncmp(name, type, strlen(type)) || !strncmp(name1, type, strlen(type))) break; } - index++; + idx++; } - if (index == type_table->nobjs) { + if (idx == type_table->nobjs) { /* unknown type */ begin_obj(dump_header_format->datatypebegin, type, dump_header_format->datatypeblockbegin); @@ -2355,7 +2369,7 @@ handle_datatypes(hid_t fid, char *type, void UNUSED *data) dump_header_format->datatypeblockend); d_status = EXIT_FAILURE; } else { - hid_t dsetid = H5Dopen(fid, type_table->objs[index].objname); + hid_t dsetid = H5Dopen(fid, type_table->objs[idx].objname); typeid = H5Dget_type(dsetid); dump_named_datatype(typeid, type); H5Tclose(typeid); @@ -2457,6 +2471,9 @@ parse_start: last_was_dset = TRUE; break; + case 'f': + driver = opt_arg; + break; case 'g': display_all = 0; @@ -2554,8 +2571,8 @@ parse_start: */ do { switch ((char)opt) { - case 's': free(s->start); s->start = parse_hsize_list(opt_arg); break; - case 'T': free(s->stride); s->stride = parse_hsize_list(opt_arg); break; + case 's': free(s->start); s->start = (hssize_t *)parse_hsize_list(opt_arg); break; + case 'S': free(s->stride); s->stride = parse_hsize_list(opt_arg); break; case 'c': free(s->count); s->count = parse_hsize_list(opt_arg); break; case 'k': free(s->block); s->block = parse_hsize_list(opt_arg); break; default: goto end_collect; @@ -2716,7 +2733,7 @@ main(int argc, const char *argv[]) else fname = argv[opt_ind]; - fid = h5tools_fopen(fname, NULL, 0); + fid = h5tools_fopen(fname, driver, NULL, 0); if (fid < 0) { error_msg(progname, "unable to open file \"%s\"\n", fname); @@ -2925,10 +2942,10 @@ print_enum(hid_t type) for (j = 0; j < dst_size; j++) printf("%02x", value[i * dst_size + j]); } else if (H5T_SGN_NONE == H5Tget_sign(native)) { - printf("%" PRINTF_LL_WIDTH "u", *((unsigned long_long *) + HDfprintf(stdout,"%" PRINTF_LL_WIDTH "u", *((unsigned long_long *) ((void *) (value + i * dst_size)))); } else { - printf("%" PRINTF_LL_WIDTH "d", + HDfprintf(stdout,"%" PRINTF_LL_WIDTH "d", *((long_long *) ((void *) (value + i * dst_size)))); } @@ -4954,10 +4971,10 @@ xml_print_enum(hid_t type) for (j = 0; j < dst_size; j++) printf("%02x", value[i * dst_size + j]); } else if (H5T_SGN_NONE == H5Tget_sign(native)) { - printf("%" PRINTF_LL_WIDTH "u", *((unsigned long_long *) + HDfprintf(stdout,"%" PRINTF_LL_WIDTH "u", *((unsigned long_long *) ((void *) (value + i * dst_size)))); } else { - printf("%" PRINTF_LL_WIDTH "d", + HDfprintf(stdout,"%" PRINTF_LL_WIDTH "d", *((long_long *) ((void *) (value + i * dst_size)))); } printf("\n"); diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index ca3c8a6..972aa59 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -1,6 +1,7 @@ /* - * Copyright (c) 1998-2001 National Center for Supercomputing Applications - * All rights reserved. + * Copyright (c) 1998, 1999, 2000, 2001 + * National Center for Supercomputing Applications + * All rights reserved. * * Programmer: Robb Matzke <matzke@llnl.gov> * Thursday, July 23, 1998 @@ -18,9 +19,6 @@ #include "hdf5.h" #include "H5private.h" - - - /* * The output functions need a temporary buffer to hold a piece of the * dataset while it's being printed. This constant sets the limit on the @@ -113,6 +111,10 @@ h5tools_close(void) * driver to try out. If the HDF5 library is greater than version 1.2, * then we have the FAMILY, SPLIT, and MULTI drivers to play with (and * the STREAM driver if H5_HAVE_STREAM is defined, that is). + * + * If DRIVER is non-NULL, then it will try to open the file with that + * driver first. We assume that the user knows what they are doing so, if + * we fail, then we won't try other file drivers. * Return: * On success, returns a file id for the opened file. If DRIVERNAME is * non-null then the first DRIVERNAME_SIZE-1 characters of the driver @@ -145,69 +147,156 @@ h5tools_close(void) * Bill Wendling, 2001-01-10 * Changed macro behavior so that if we have a version other than 1.2.x * (i.e., > 1.2), then we do the drivers check. + * + * Bill Wendling, 2001-07-30 + * Added DRIVER parameter so that the user can specify "try this driver" + * instead of the default behaviour. If it fails to open the file with + * that driver, this will fail completely (i.e., we won't try the other + * drivers). We're assuming the user knows what they're doing. How UNIX + * of us. *------------------------------------------------------------------------- */ hid_t -h5tools_fopen(const char *fname, char *drivername, size_t drivername_size) +h5tools_fopen(const char *fname, const char *driver, char *drivername, + size_t drivername_size) { - static struct { + static struct d_list { const char *name; hid_t fapl; - } driver[16]; - static int ndrivers = 0; + } drivers_list[] = { + { "sec2", FAIL }, + { "family", FAIL }, + { "split", FAIL }, + { "multi", FAIL }, +#ifdef H5_HAVE_STREAM + { "stream", FAIL }, +#endif /* H5_HAVE_STREAM */ + }; + /* This enum should match the entries in the above drivers_list since they + * are indexes into the drivers_list array. */ + enum { + SEC2_IDX = 0, + FAMILY_IDX, + SPLIT_IDX, + MULTI_IDX, +#ifdef H5_HAVE_STREAM + STREAM_IDX, +#endif /* H5_HAVE_STREAM */ + }; +#define NUM_DRIVERS (sizeof(drivers_list) / sizeof(struct d_list)) + + static int initialized = 0; register int drivernum; - hid_t fid = -1; + hid_t fid = FAIL; #ifndef VERSION12 hid_t fapl = H5P_DEFAULT; #endif /* !VERSION12 */ - if (!ndrivers) { + if (!initialized) { /* Build a list of file access property lists which we should try * when opening the file. Eventually we'd like some way for the * user to augment/replace this list interactively. */ - driver[ndrivers].name = "sec2"; - driver[ndrivers].fapl = H5P_DEFAULT; - ndrivers++; - + ++initialized; + + /* SEC2 Driver */ + drivers_list[SEC2_IDX].fapl = H5P_DEFAULT; + #ifndef VERSION12 - driver[ndrivers].name = "family"; - driver[ndrivers].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); + /* FAMILY Driver */ + drivers_list[FAMILY_IDX].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); H5Pset_fapl_family(fapl, (hsize_t)0, H5P_DEFAULT); - ndrivers++; - driver[ndrivers].name = "split"; - driver[ndrivers].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); + /* SPLIT Driver */ + drivers_list[SPLIT_IDX].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT); - ndrivers++; - driver[ndrivers].name = "multi"; - driver[ndrivers].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); + /* MULTI Driver */ + drivers_list[MULTI_IDX].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); H5Pset_fapl_multi(fapl, NULL, NULL, NULL, NULL, TRUE); - ndrivers++; #ifdef H5_HAVE_STREAM - driver[ndrivers].name = "stream"; - driver[ndrivers].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); + /* STREAM Driver */ + drivers_list[STREAM_IDX].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); H5Pset_fapl_stream(fapl, NULL); - ndrivers++; #endif /* H5_HAVE_STREAM */ #endif /* !VERSION12 */ } - /* Try to open the file using each of the drivers */ - for (drivernum = 0; drivernum < ndrivers; drivernum++) { - H5E_BEGIN_TRY { - fid = H5Fopen(fname, H5F_ACC_RDONLY, driver[drivernum].fapl); - } H5E_END_TRY; + if (driver && *driver) { + /* Determine which driver the user wants to open the file with. Try + * that driver. If it can't open it, then fail. */ + if (!strcmp(driver, drivers_list[SEC2_IDX].name)) { + H5E_BEGIN_TRY { + fid = H5Fopen(fname, H5F_ACC_RDONLY, + drivers_list[SEC2_IDX].fapl); + } H5E_END_TRY; + + if (fid == FAIL) + goto done; + + drivernum = SEC2_IDX; + } else if (!strcmp(driver, drivers_list[FAMILY_IDX].name)) { + H5E_BEGIN_TRY { + fid = H5Fopen(fname, H5F_ACC_RDONLY, + drivers_list[FAMILY_IDX].fapl); + } H5E_END_TRY; + + if (fid == FAIL) + goto done; - if (fid >= 0) - break; + drivernum = FAMILY_IDX; + } else if (!strcmp(driver, drivers_list[SPLIT_IDX].name)) { + H5E_BEGIN_TRY { + fid = H5Fopen(fname, H5F_ACC_RDONLY, + drivers_list[SPLIT_IDX].fapl); + } H5E_END_TRY; + + if (fid == FAIL) + goto done; + + drivernum = SPLIT_IDX; + } else if (!strcmp(driver, drivers_list[MULTI_IDX].name)) { + H5E_BEGIN_TRY { + fid = H5Fopen(fname, H5F_ACC_RDONLY, + drivers_list[MULTI_IDX].fapl); + } H5E_END_TRY; + + if (fid == FAIL) + goto done; + + drivernum = MULTI_IDX; +#ifdef H5_HAVE_STREAM + } else if (!strcmp(driver, drivers_list[STREAM_IDX].name)) { + H5E_BEGIN_TRY { + fid = H5Fopen(fname, H5F_ACC_RDONLY, + drivers_list[STREAM_IDX].fapl); + } H5E_END_TRY; + + if (fid == FAIL) + goto done; + + drivernum = STREAM_IDX; +#endif /* H5_HAVE_STREAM */ + } else { + goto done; + } + } else { + /* Try to open the file using each of the drivers */ + for (drivernum = 0; drivernum < NUM_DRIVERS; drivernum++) { + H5E_BEGIN_TRY { + fid = H5Fopen(fname, H5F_ACC_RDONLY, + drivers_list[drivernum].fapl); + } H5E_END_TRY; + + if (fid != FAIL) + break; + } } /* Save the driver name */ if (drivername && drivername_size) { - if (fid >= 0) { - strncpy(drivername, driver[drivernum].name, drivername_size); + if (fid != FAIL) { + strncpy(drivername, drivers_list[drivernum].name, drivername_size); drivername[drivername_size - 1] = '\0'; } else { /*no file opened*/ @@ -215,6 +304,7 @@ h5tools_fopen(const char *fname, char *drivername, size_t drivername_size) } } +done: return fid; } diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index 6a6f859..eda4a39 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -1,6 +1,7 @@ /* - * Copyright (c) 1998-2001 National Center for Supercomputing Applications - * All rights reserved. + * Copyright (c) 1998, 1999, 2000, 2001 + * National Center for Supercomputing Applications + * All rights reserved. * * Programmer: Robb Matzke <matzke@llnl.gov> * Thursday, July 23, 1998 @@ -404,7 +405,7 @@ typedef struct h5tools_context_t { /* a structure to hold the subsetting particulars for a dataset */ struct subset_t { - hsize_t *start; + hssize_t *start; hsize_t *stride; hsize_t *count; hsize_t *block; @@ -464,7 +465,8 @@ extern FILE *rawdatastream; /*output stream for raw data */ /* Definitions of useful routines */ extern void h5tools_init(void); extern void h5tools_close(void); -extern hid_t h5tools_fopen(const char *fname, char *drivername, size_t drivername_len); +extern hid_t h5tools_fopen(const char *fname, const char *driver, + char *drivername, size_t drivername_len); extern hid_t h5tools_fixtype(hid_t f_type); extern int h5tools_dump_dset(FILE *stream, const h5dump_t *info, hid_t dset, hid_t p_typ, struct subset_t *sset, int indentlevel); |