diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2007-02-14 13:54:11 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2007-02-14 13:54:11 (GMT) |
commit | bb392083b2a81aa942678e06a537a3c0ab5c08aa (patch) | |
tree | 9243c5965897315e4cbeef983f71b224498718c0 /tools/lib/h5tools.c | |
parent | df075c5b9266b3b7a038fb1377d130ed315aa15c (diff) | |
download | hdf5-bb392083b2a81aa942678e06a537a3c0ab5c08aa.zip hdf5-bb392083b2a81aa942678e06a537a3c0ab5c08aa.tar.gz hdf5-bb392083b2a81aa942678e06a537a3c0ab5c08aa.tar.bz2 |
[svn-r13297] Description:
Add small 'h5mkgrp' tool to create groups in an HDF5 file from the command
line, allowing the group structure for a file to be created in a script. This
tool closely follows the 'mkdir' command line tool in UNIX/Linux.
Allow tool library applications to pass a FAPL to the h5tool_fopen() call,
giving some additional flexibility to tools which are adding objects to an
existing HDF5 file (like h5copy & h5mkgrp).
Fix missing files in MANIFEST from previous checkin(s).
Tested on:
Linux/32 2.6 (chicago)
Linux/64 2.6 (chicago2)
Diffstat (limited to 'tools/lib/h5tools.c')
-rw-r--r-- | tools/lib/h5tools.c | 128 |
1 files changed, 64 insertions, 64 deletions
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index 429898a..a713092 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -161,67 +161,67 @@ h5tools_close(void) *------------------------------------------------------------------------- */ static hid_t -h5tools_get_fapl(const char *driver, unsigned *drivernum) +h5tools_get_fapl(hid_t fapl, const char *driver, unsigned *drivernum) { - hid_t fapl = H5P_DEFAULT; + hid_t new_fapl; /* Copy of file access property list passed in, or new property list */ + + /* Make a copy of the FAPL, for the file open call to use, eventually */ + if(fapl == H5P_DEFAULT) { + if((new_fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) + goto error; + } /* end if */ + else { + if((new_fapl = H5Pcopy(fapl)) < 0) + goto error; + } /* end else */ /* 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, drivernames[SEC2_IDX])) { + if(!strcmp(driver, drivernames[SEC2_IDX])) { if(drivernum) *drivernum = SEC2_IDX; - } else if (!strcmp(driver, drivernames[FAMILY_IDX])) { + } else if(!strcmp(driver, drivernames[FAMILY_IDX])) { /* FAMILY Driver */ - if((fapl = H5Pcreate(H5P_FILE_ACCESS))>=0) { - /* Set member size to be 0 to indicate the current first member size - * is the member size. - */ - if (H5Pset_fapl_family(fapl, (hsize_t)0, H5P_DEFAULT)<0) - goto error; - if(drivernum) - *drivernum = FAMILY_IDX; - } /* end if */ - } else if (!strcmp(driver, drivernames[SPLIT_IDX])) { + /* Set member size to be 0 to indicate the current first member size + * is the member size. + */ + if(H5Pset_fapl_family(new_fapl, (hsize_t)0, H5P_DEFAULT) < 0) + goto error; + + if(drivernum) + *drivernum = FAMILY_IDX; + } else if(!strcmp(driver, drivernames[SPLIT_IDX])) { /* SPLIT Driver */ - if((fapl = H5Pcreate(H5P_FILE_ACCESS))>=0) { - - if (H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT)<0) - goto error; + if(H5Pset_fapl_split(new_fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT) < 0) + goto error; - if(drivernum) - *drivernum = SPLIT_IDX; - } /* end if */ - } else if (!strcmp(driver, drivernames[MULTI_IDX])) { + if(drivernum) + *drivernum = SPLIT_IDX; + } else if(!strcmp(driver, drivernames[MULTI_IDX])) { /* MULTI Driver */ - if((fapl = H5Pcreate(H5P_FILE_ACCESS))>=0) { - - if (H5Pset_fapl_multi(fapl, NULL, NULL, NULL, NULL, TRUE)<0) - goto error; + if(H5Pset_fapl_multi(new_fapl, NULL, NULL, NULL, NULL, TRUE) < 0) + goto error; - if(drivernum) - *drivernum = MULTI_IDX; - } /* end if */ + if(drivernum) + *drivernum = MULTI_IDX; #ifdef H5_HAVE_STREAM - } else if (!strcmp(driver, drivernames[STREAM_IDX])) { + } else if(!strcmp(driver, drivernames[STREAM_IDX])) { /* STREAM Driver */ - if((fapl = H5Pcreate(H5P_FILE_ACCESS))>=0) { - - if (H5Pset_fapl_stream(fapl, NULL)<0) - goto error; + if(H5Pset_fapl_stream(new_fapl, NULL) < 0) + goto error; - if(drivernum) - *drivernum = STREAM_IDX; - } /* end if */ + if(drivernum) + *drivernum = STREAM_IDX; #endif /* H5_HAVE_STREAM */ #ifdef H5_HAVE_PARALLEL - } else if (!strcmp(driver, drivernames[MPIO_IDX])) { + } else if(!strcmp(driver, drivernames[MPIO_IDX])) { /* MPI-I/O Driver */ /* check if MPI has been initialized. */ - if (!h5tools_mpi_init_g) + if(!h5tools_mpi_init_g) MPI_Initialized(&h5tools_mpi_init_g); - if (h5tools_mpi_init_g && ((fapl = H5Pcreate(H5P_FILE_ACCESS))>=0)) { - if (H5Pset_fapl_mpio(fapl, MPI_COMM_WORLD, MPI_INFO_NULL)<0) + if(h5tools_mpi_init_g) { + if(H5Pset_fapl_mpio(new_fapl, MPI_COMM_WORLD, MPI_INFO_NULL) < 0) goto error; if(drivernum) @@ -230,10 +230,10 @@ h5tools_get_fapl(const char *driver, unsigned *drivernum) } else if (!strcmp(driver, drivernames[MPIPOSIX_IDX])) { /* MPI-I/O Driver */ /* check if MPI has been initialized. */ - if (!h5tools_mpi_init_g) + if(!h5tools_mpi_init_g) MPI_Initialized(&h5tools_mpi_init_g); - if (h5tools_mpi_init_g && ((fapl = H5Pcreate(H5P_FILE_ACCESS))>=0)) { - if (H5Pset_fapl_mpiposix(fapl, MPI_COMM_WORLD, TRUE)<0) + if(h5tools_mpi_init_g) { + if(H5Pset_fapl_mpiposix(new_fapl, MPI_COMM_WORLD, TRUE) < 0) goto error; if(drivernum) @@ -241,14 +241,14 @@ h5tools_get_fapl(const char *driver, unsigned *drivernum) } /* end if */ #endif /* H5_HAVE_PARALLEL */ } else { - fapl=(-1); + goto error; } - return(fapl); + return(new_fapl); error: - if(fapl!=H5P_DEFAULT) - H5Pclose(fapl); + if(new_fapl != H5P_DEFAULT) + H5Pclose(new_fapl); return -1; } @@ -308,49 +308,49 @@ error: *------------------------------------------------------------------------- */ hid_t -h5tools_fopen(const char *fname, unsigned flags, const char *driver, +h5tools_fopen(const char *fname, unsigned flags, hid_t fapl, const char *driver, char *drivername, size_t drivername_size) { unsigned drivernum; hid_t fid = FAIL; - hid_t fapl = H5P_DEFAULT; + hid_t my_fapl = H5P_DEFAULT; - if (driver && *driver) { + if(driver && *driver) { /* Get the correct FAPL for the given driver */ - if((fapl=h5tools_get_fapl(driver,&drivernum))<0) + if((my_fapl = h5tools_get_fapl(fapl, driver, &drivernum)) < 0) goto done; H5E_BEGIN_TRY { - fid = H5Fopen(fname, flags, fapl); + fid = H5Fopen(fname, flags, my_fapl); } H5E_END_TRY; - if (fid == FAIL) + if(fid == FAIL) goto done; } else { /* Try to open the file using each of the drivers */ - for (drivernum = 0; drivernum < NUM_DRIVERS; drivernum++) { + for(drivernum = 0; drivernum < NUM_DRIVERS; drivernum++) { /* Get the correct FAPL for the given driver */ - if((fapl=h5tools_get_fapl(drivernames[drivernum],NULL))<0) + if((my_fapl = h5tools_get_fapl(fapl, drivernames[drivernum], NULL)) < 0) goto done; H5E_BEGIN_TRY { - fid = H5Fopen(fname, flags, fapl); + fid = H5Fopen(fname, flags, my_fapl); } H5E_END_TRY; - if (fid != FAIL) + if(fid != FAIL) break; else { /* Close the FAPL */ - H5Pclose(fapl); - fapl=H5P_DEFAULT; + H5Pclose(my_fapl); + my_fapl = H5P_DEFAULT; } /* end else */ } } /* Save the driver name */ - if (drivername && drivername_size) { - if (fid != FAIL) { + if(drivername && drivername_size) { + if(fid != FAIL) { strncpy(drivername, drivernames[drivernum], drivername_size); drivername[drivername_size - 1] = '\0'; } else { @@ -360,8 +360,8 @@ h5tools_fopen(const char *fname, unsigned flags, const char *driver, } done: - if(fapl!=H5P_DEFAULT) - H5Pclose(fapl); + if(my_fapl != H5P_DEFAULT) + H5Pclose(my_fapl); return fid; } |