diff options
author | Patrick Lu <ptlu@hawkwind.ncsa.uiuc.edu> | 2000-06-06 18:07:20 (GMT) |
---|---|---|
committer | Patrick Lu <ptlu@hawkwind.ncsa.uiuc.edu> | 2000-06-06 18:07:20 (GMT) |
commit | 4d16bcfecbf51574e3f8bb8cd0e50373892fa462 (patch) | |
tree | 44e97bf287bc7fae2540e6c10211da44ee9517d8 /tools | |
parent | 6ef640cb9934e6e6fd7b89e902ed974797b91b79 (diff) | |
download | hdf5-4d16bcfecbf51574e3f8bb8cd0e50373892fa462.zip hdf5-4d16bcfecbf51574e3f8bb8cd0e50373892fa462.tar.gz hdf5-4d16bcfecbf51574e3f8bb8cd0e50373892fa462.tar.bz2 |
[svn-r2341] took the code out of h5ls to open files using different drivers and created a function in the tools
library for it(H5ToolsFopen-takes a filename and a char ptr if you want the name of the driver)
added the function to h5tools.c, a header to h5tools.h and changed h5ls.c and h5dump.c to use the new
functions
Diffstat (limited to 'tools')
-rw-r--r-- | tools/h5dump.c | 10 | ||||
-rw-r--r-- | tools/h5ls.c | 52 | ||||
-rw-r--r-- | tools/h5tools.c | 58 | ||||
-rw-r--r-- | tools/h5tools.h | 5 |
4 files changed, 74 insertions, 51 deletions
diff --git a/tools/h5dump.c b/tools/h5dump.c index b6cd255..07c4335 100644 --- a/tools/h5dump.c +++ b/tools/h5dump.c @@ -1307,8 +1307,8 @@ int main(int argc, char *argv[]) { hid_t fid, gid, dsetid, typeid; - hid_t plist=H5P_DEFAULT; - const char *fname = NULL; + + char *fname = NULL; int i, index, curr_arg, display_bb=0, display_all=1, newwidth= 0; int nopts=0, *opts; char *buf, name[128], name1[128]; @@ -1317,6 +1317,7 @@ main(int argc, char *argv[]) hid_t (*func)(void*); find_objs_t *info = malloc(sizeof(find_objs_t)); + dump_header_format = &standardformat; /* Disable error reporting */ @@ -1430,11 +1431,12 @@ main(int argc, char *argv[]) if (argv[argc-1][0] == '\\') fname = &argv[argc-1][1]; else fname = argv[argc-1]; - if ((fid = H5Fopen (fname, H5F_ACC_RDONLY, plist)) < 0) { + fid = H5ToolsFopen(fname, NULL); + if (fid < 0) { fprintf (stderr, "h5dump error: unable to open file %s \n", fname); free(opts); exit(1); - } + } /* allocate and initialize internal data structure */ init_table(&group_table); diff --git a/tools/h5ls.c b/tools/h5ls.c index 1cad442..9ef01e5 100644 --- a/tools/h5ls.c +++ b/tools/h5ls.c @@ -26,7 +26,7 @@ #include <H5Fpublic.h> #endif -#define NDRIVERS 10 + /* * If defined then include the file name as part of the object name when * printing full object names. Otherwise leave the file name off. @@ -1905,24 +1905,19 @@ get_width(void) int main (int argc, char *argv[]) { - hid_t file=-1, root=-1, fapl=-1; + hid_t file=-1, root=-1; char *fname=NULL, *oname=NULL, *x; const char *progname; const char *s = NULL; char *rest, *container=NULL; - int argno, dno; + int argno; H5G_stat_t sb; iter_t iter; static char root_name[] = "/"; - - int ndrivers=0; - - struct { - const char *name; - hid_t fapl; - } driver[NDRIVERS]; + char drivername[50]; + memset(drivername, '\0',50); /* Build display table */ DISPATCH(H5G_DATASET, "Dataset", H5Dopen, H5Dclose, dataset_list1, dataset_list2); @@ -1960,7 +1955,7 @@ main (int argc, char *argv[]) } else if (!strcmp(argv[argno], "--full")) { fullname_g = TRUE; } else if (!strcmp(argv[argno], "--group")) { - grp_literal_g = TRUE; + grp_literal_g = TRUE; } else if (!strcmp(argv[argno], "--label")) { label_g = TRUE; } else if (!strcmp(argv[argno], "--recursive")) { @@ -2077,31 +2072,7 @@ main (int argc, char *argv[]) /* Turn off HDF5's automatic error printing unless you're debugging h5ls */ if (!show_errors_g) H5Eset_auto(NULL, NULL); - /* - * 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++; -#if defined VERSION13 - driver[ndrivers].name = "family"; - driver[ndrivers].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); - H5Pset_fapl_family(fapl, 0, H5P_DEFAULT); - ndrivers++; - - driver[ndrivers].name = "split"; - driver[ndrivers].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); - H5Pset_fapl_multi(fapl, NULL, NULL, NULL, NULL, TRUE); - ndrivers++; -#endif /* * Each remaining argument is an hdf5 file followed by an optional slash * and object name. @@ -2122,16 +2093,13 @@ main (int argc, char *argv[]) file = -1; while (fname && *fname) { - for (dno=0; dno<ndrivers; dno++) { - H5E_BEGIN_TRY { - file = H5Fopen(fname, H5F_ACC_RDONLY, driver[dno].fapl); - } H5E_END_TRY; - if (file>=0) break; - } + + file = H5ToolsFopen(fname, drivername); + if (file>=0) { if (verbose_g) { printf("Opened \"%s\" with %s driver.\n", - fname, driver[dno].name); + fname, drivername); } break; /*success*/ } diff --git a/tools/h5tools.c b/tools/h5tools.c index 0fd8925..9011a6e 100644 --- a/tools/h5tools.c +++ b/tools/h5tools.c @@ -105,7 +105,7 @@ extern int get_table_idx(table_t *table, unsigned long *); extern int get_tableflag(table_t*, int); extern int set_tableflag(table_t*, int); extern char* get_objectname(table_t*, int); - +extern hid_t H5ToolsFopen(char* fname, char* drivername); /*------------------------------------------------------------------------- * Function: h5dump_str_close @@ -2230,10 +2230,58 @@ get_objectname(table_t* table, int idx) return(strdup(table->objs[idx].objname)); } +/*------------------------------------------------------------------------- + * Function: opens a file using the list of drivers + * + * Purpose: + * + * Return: Success: a file id for the opened file + * + * Failure: -1; + * + *-----------------------------------------------------------------------*/ - - - - +hid_t H5ToolsFopen(char* fname, char* drivername){ + + typedef struct driver_t { + const char *name; + hid_t fapl; + } driver_t; + + hid_t fid, fapl = H5P_DEFAULT; + int ndrivers = 0, drivernum; + driver_t driver[NDRIVERS]; + + /*taken from h5ls*/ + driver[ndrivers].name = "sec2"; + driver[ndrivers].fapl = H5P_DEFAULT; + ndrivers++; +#if defined VERSION13 + driver[ndrivers].name = "family"; + driver[ndrivers].fapl = fapl = H5Pcreate(H5P_FILE_ACCESS); + H5Pset_fapl_family(fapl, 0, H5P_DEFAULT); + ndrivers++; + + driver[ndrivers].name = "split"; + driver[ndrivers].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); + H5Pset_fapl_multi(fapl, NULL, NULL, NULL, NULL, TRUE); + ndrivers++; +#endif + for (drivernum = 0; drivernum<ndrivers;drivernum++){ + H5E_BEGIN_TRY { + fid = H5Fopen(fname, H5F_ACC_RDONLY, driver[drivernum].fapl); + } H5E_END_TRY; + if (fid >= 0) break; + } + if (drivername){ + memcpy(drivername,driver[drivernum].name,strlen(driver[drivernum].name)); + } + return (fid); +} diff --git a/tools/h5tools.h b/tools/h5tools.h index 22ab2d3..44432b4 100644 --- a/tools/h5tools.h +++ b/tools/h5tools.h @@ -434,3 +434,8 @@ extern int nCols; /* Definitions of useful routines */ void print_version(const char *program_name); +/*used to open files so we can use different drivers*/ +hid_t H5ToolsFopen(char* fname, char* drivername); + +#define NDRIVERS 10 + |