summaryrefslogtreecommitdiffstats
path: root/tools/src/misc/h5mkgrp.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/src/misc/h5mkgrp.c')
-rw-r--r--tools/src/misc/h5mkgrp.c234
1 files changed, 138 insertions, 96 deletions
diff --git a/tools/src/misc/h5mkgrp.c b/tools/src/misc/h5mkgrp.c
index a2cb68b..cbd6e6d 100644
--- a/tools/src/misc/h5mkgrp.c
+++ b/tools/src/misc/h5mkgrp.c
@@ -25,24 +25,29 @@ int d_status = EXIT_SUCCESS;
/* command-line options: short and long-named parameters */
static const char *s_opts = "hlpvV";
static struct long_options l_opts[] = {
- { "help", no_arg, 'h' },
- { "latest", no_arg, 'l' },
- { "parents", no_arg, 'p' },
- { "verbose", no_arg, 'v' },
- { "version", no_arg, 'V' },
+ { "help", no_arg, 'h' },
+ { "latest", no_arg, 'l' },
+ { "parents", no_arg, 'p' },
+ { "verbose", no_arg, 'v' },
+ { "version", no_arg, 'V' },
+ { "vol-value", require_arg, '1' },
+ { "vol-name", require_arg, '2' },
+ { "vol-info", require_arg, '3' },
{ NULL, 0, '\0' }
};
/* Command line parameter settings */
-typedef struct {
+typedef struct mkgrp_opt_t {
char *fname; /* File name to operate on */
hbool_t latest; /* Whether file should use latest format versions */
hbool_t verbose; /* Whether output should be verbose */
hbool_t parents; /* Whether to create intermediate groups */
size_t ngroups; /* Number of groups to create */
char **groups; /* Pointer to array of group names */
-} param_t;
-param_t params; /* Command line parameter settings */
+ hid_t fapl_id; /* fapl to use when opening the file */
+} mkgrp_opt_t;
+
+mkgrp_opt_t params_g; /* Command line parameter settings */
/*-------------------------------------------------------------------------
@@ -61,13 +66,17 @@ leave(int ret)
{
size_t curr_group;
- if (params.fname)
- HDfree (params.fname);
- if (params.ngroups) {
- for(curr_group = 0; curr_group < params.ngroups; curr_group++)
- HDfree (params.groups[curr_group]);
- HDfree (params.groups);
+ if (params_g.fname)
+ HDfree(params_g.fname);
+ if (params_g.ngroups) {
+ for (curr_group = 0; curr_group < params_g.ngroups; curr_group++)
+ HDfree(params_g.groups[curr_group]);
+ HDfree(params_g.groups);
}
+ if (H5I_INVALID_HID != params_g.fapl_id && H5P_DEFAULT != params_g.fapl_id)
+ if (H5Pclose(params_g.fapl_id) < 0)
+ error_msg("Could not close file access property list\n");
+
h5tools_close();
HDexit(ret);
} /* end leave() */
@@ -85,65 +94,79 @@ leave(int ret)
*-------------------------------------------------------------------------
*/
static void
-usage(void)
+usage(const char *prog)
{
- HDfprintf(stdout, "\
-usage: h5mkgrp [OPTIONS] FILE GROUP...\n\
- OPTIONS\n\
- -h, --help Print a usage message and exit\n\
- -l, --latest Use latest version of file format to create groups\n\
- -p, --parents No error if existing, make parent groups as needed\n\
- -v, --verbose Print information about OBJECTS and OPTIONS\n\
- -V, --version Print version number and exit\n");
+ FLUSHSTREAM(rawoutstream);
+ PRINTSTREAM(rawoutstream, "usage: %s [OPTIONS] FILE GROUP...\n", prog);
+ PRINTVALSTREAM(rawoutstream, " OPTIONS\n");
+ PRINTVALSTREAM(rawoutstream, " -h, --help Print a usage message and exit\n");
+ PRINTVALSTREAM(rawoutstream, " -l, --latest Use latest version of file format to create groups\n");
+ PRINTVALSTREAM(rawoutstream, " -p, --parents No error if existing, make parent groups as needed\n");
+ PRINTVALSTREAM(rawoutstream, " -v, --verbose Print information about OBJECTS and OPTIONS\n");
+ PRINTVALSTREAM(rawoutstream, " -V, --version Print version number and exit\n");
+ PRINTVALSTREAM(rawoutstream, " --vol-value Value (ID) of the VOL connector to use for opening the\n");
+ PRINTVALSTREAM(rawoutstream, " HDF5 file specified\n");
+ PRINTVALSTREAM(rawoutstream, " --vol-name Name of the VOL connector to use for opening the\n");
+ PRINTVALSTREAM(rawoutstream, " HDF5 file specified\n");
+ PRINTVALSTREAM(rawoutstream, " --vol-info VOL-specific info to pass to the VOL connector used for\n");
+ PRINTVALSTREAM(rawoutstream, " opening the HDF5 file specified\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
} /* end usage() */
/*-------------------------------------------------------------------------
- * Function: parse_command_line
+ * Function: parse_command_line
*
- * Purpose: Parses command line and sets up global variable to control output
+ * Purpose: Parses command line and sets up global variable to control
+ * output
*
- * Return: Success: 0
- * Failure: -1
+ * Return: Success: 0
+ * Failure: -1
*
* Programmer: Quincey Koziol, 2/13/2007
*
*-------------------------------------------------------------------------
*/
static int
-parse_command_line(int argc, const char *argv[], param_t *parms)
+parse_command_line(int argc, const char *argv[], mkgrp_opt_t *options)
{
int opt; /* Option from command line */
size_t curr_group; /* Current group name to copy */
+ hbool_t custom_fapl = FALSE;
+ h5tools_vol_info_t vol_info;
+ hid_t tmp_fapl_id = H5I_INVALID_HID;
/* Check for empty command line */
if(argc == 1) {
- usage();
+ usage(h5tools_getprogname());
leave(EXIT_SUCCESS);
- } /* end if */
+ }
+
+ /* Initialize fapl info struct */
+ HDmemset(&vol_info, 0, sizeof(h5tools_vol_info_t));
/* Parse command line options */
while((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) {
switch((char)opt) {
/* Display 'help' */
case 'h':
- usage();
+ usage(h5tools_getprogname());
leave(EXIT_SUCCESS);
break;
/* Create objects with the latest version of the format */
case 'l':
- parms->latest = TRUE;
+ options->latest = TRUE;
break;
/* Create parent groups */
case 'p':
- parms->parents = TRUE;
+ options->parents = TRUE;
break;
/* Verbose output */
case 'v':
- parms->verbose = TRUE;
+ options->verbose = TRUE;
break;
/* Display version */
@@ -152,9 +175,25 @@ parse_command_line(int argc, const char *argv[], param_t *parms)
leave(EXIT_SUCCESS);
break;
+ case '1':
+ vol_info.type = VOL_BY_VALUE;
+ vol_info.u.value = (H5VL_class_value_t)HDatoi(opt_arg);
+ custom_fapl = TRUE;
+ break;
+
+ case '2':
+ vol_info.type = VOL_BY_NAME;
+ vol_info.u.name = opt_arg;
+ custom_fapl = TRUE;
+ break;
+
+ case '3':
+ vol_info.info_string = opt_arg;
+ break;
+
/* Bad command line argument */
default:
- usage();
+ usage(h5tools_getprogname());
leave(EXIT_FAILURE);
} /* end switch */
} /* end while */
@@ -162,43 +201,51 @@ parse_command_line(int argc, const char *argv[], param_t *parms)
/* Check for file name to be processed */
if(argc <= opt_ind) {
error_msg("missing file name\n");
- usage();
+ usage(h5tools_getprogname());
leave(EXIT_FAILURE);
- } /* end if */
+ }
/* Retrieve file name */
- parms->fname = HDstrdup(argv[opt_ind]);
+ options->fname = HDstrdup(argv[opt_ind]);
opt_ind++;
/* Check for group(s) to be created */
if(argc <= opt_ind) {
error_msg("missing group name(s)\n");
- usage();
+ usage(h5tools_getprogname());
leave(EXIT_FAILURE);
- } /* end if */
+ }
/* Allocate space for the group name pointers */
- parms->ngroups = (size_t)(argc - opt_ind);
- parms->groups = (char **)HDmalloc(parms->ngroups * sizeof(char *));
+ options->ngroups = (size_t)(argc - opt_ind);
+ options->groups = (char **)HDmalloc(options->ngroups * sizeof(char *));
/* Retrieve the group names */
curr_group = 0;
while(opt_ind < argc) {
- parms->groups[curr_group] = HDstrdup(argv[opt_ind]);
+ options->groups[curr_group] = HDstrdup(argv[opt_ind]);
curr_group++;
opt_ind++;
- } /* end while */
+ }
+
+ /* Setup a custom fapl for file accesses */
+ if (custom_fapl) {
+ if ((tmp_fapl_id = h5tools_get_fapl(options->fapl_id, &vol_info, NULL)) < 0) {
+ error_msg("failed to setup file access property list (fapl) for file\n");
+ leave(EXIT_FAILURE);
+ }
+
+ /* Close the old fapl */
+ if (options->fapl_id != H5P_DEFAULT)
+ if (H5Pclose(options->fapl_id) < 0) {
+ error_msg("failed to close file access property list (fapl)\n");
+ leave(EXIT_FAILURE);
+ }
-#ifdef QAK
-HDfprintf(stderr, "parms->parents = %t\n", parms->parents);
-HDfprintf(stderr, "parms->verbose = %t\n", parms->verbose);
-HDfprintf(stderr, "parms->fname = '%s'\n", parms->fname);
-HDfprintf(stderr, "parms->ngroups = %Zu\n", parms->ngroups);
-for(curr_group = 0; curr_group < parms->ngroups; curr_group++)
- HDfprintf(stderr, "parms->group[%Zu] = '%s'\n", curr_group, parms->groups[curr_group]);
-#endif /* QAK */
+ options->fapl_id = tmp_fapl_id;
+ }
- return(0);
+ return 0;
} /* parse_command_line() */
@@ -214,10 +261,9 @@ for(curr_group = 0; curr_group < parms->ngroups; curr_group++)
int
main(int argc, const char *argv[])
{
- hid_t fid; /* HDF5 file ID */
- hid_t fapl_id; /* File access property list ID */
- hid_t lcpl_id; /* Link creation property list ID */
- size_t curr_group; /* Current group to create */
+ hid_t fid = H5I_INVALID_HID; /* HDF5 file ID */
+ hid_t lcpl_id = H5I_INVALID_HID; /* Link creation property list ID */
+ size_t curr_group; /* Current group to create */
h5tools_setprogname(PROGRAMNAME);
h5tools_setstatus(EXIT_SUCCESS);
@@ -228,103 +274,99 @@ main(int argc, const char *argv[])
/* Initialize h5tools lib */
h5tools_init();
- /* Parse command line */
- HDmemset(&params, 0, sizeof(params));
- if(parse_command_line(argc, argv, &params) < 0) {
- error_msg("unable to parse command line arguments\n");
- leave(EXIT_FAILURE);
- } /* end if */
+ /* Initialize the parameters */
+ HDmemset(&params_g, 0, sizeof(params_g));
/* Create file access property list */
- if((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) {
+ if((params_g.fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) {
error_msg("Could not create file access property list\n");
leave(EXIT_FAILURE);
- } /* end if */
+ }
+
+ /* Parse command line */
+ if(parse_command_line(argc, argv, &params_g) < 0) {
+ error_msg("unable to parse command line arguments\n");
+ leave(EXIT_FAILURE);
+ }
/* Check for creating groups with new format version */
- if(params.latest) {
+ if(params_g.latest) {
/* Set the "use the latest version of the format" bounds */
- if(H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) {
+ if(H5Pset_libver_bounds(params_g.fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) {
error_msg("Could not set property for using latest version of the format\n");
leave(EXIT_FAILURE);
- } /* end if */
+ }
/* Display some output if requested */
- if(params.verbose)
+ if(params_g.verbose)
HDprintf("%s: Creating groups with latest version of the format\n", h5tools_getprogname());
- } /* end if */
+ }
/* Attempt to open an existing HDF5 file first */
- fid = h5tools_fopen(params.fname, H5F_ACC_RDWR, fapl_id, FALSE, NULL, 0);
+ fid = h5tools_fopen(params_g.fname, H5F_ACC_RDWR, params_g.fapl_id, FALSE, NULL, 0);
/* If we couldn't open an existing file, try creating file */
/* (use "EXCL" instead of "TRUNC", so we don't blow away existing non-HDF5 file) */
if(fid < 0)
- fid = H5Fcreate(params.fname, H5F_ACC_EXCL, H5P_DEFAULT, fapl_id);
+ fid = H5Fcreate(params_g.fname, H5F_ACC_EXCL, H5P_DEFAULT, params_g.fapl_id);
/* Test for error in opening file */
if(fid < 0) {
- error_msg("Could not open output file '%s'\n", params.fname);
+ error_msg("Could not open output file '%s'\n", params_g.fname);
leave(EXIT_FAILURE);
- } /* end if */
+ }
/* Create link creation property list */
if((lcpl_id = H5Pcreate(H5P_LINK_CREATE)) < 0) {
error_msg("Could not create link creation property list\n");
leave(EXIT_FAILURE);
- } /* end if */
+ }
/* Check for creating intermediate groups */
- if(params.parents) {
+ if(params_g.parents) {
/* Set the intermediate group creation property */
if(H5Pset_create_intermediate_group(lcpl_id, TRUE) < 0) {
error_msg("Could not set property for creating parent groups\n");
leave(EXIT_FAILURE);
- } /* end if */
+ }
/* Display some output if requested */
- if(params.verbose)
+ if(params_g.verbose)
HDprintf("%s: Creating parent groups\n", h5tools_getprogname());
- } /* end if */
+ }
/* Loop over creating requested groups */
- for(curr_group = 0; curr_group < params.ngroups; curr_group++) {
+ for(curr_group = 0; curr_group < params_g.ngroups; curr_group++) {
hid_t gid; /* Group ID */
/* Attempt to create a group */
- if((gid = H5Gcreate2(fid, params.groups[curr_group], lcpl_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
- error_msg("Could not create group '%s'\n", params.groups[curr_group]);
+ if((gid = H5Gcreate2(fid, params_g.groups[curr_group], lcpl_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
+ error_msg("Could not create group '%s'\n", params_g.groups[curr_group]);
leave(EXIT_FAILURE);
- } /* end if */
+ }
/* Close the group */
if(H5Gclose(gid) < 0) {
- error_msg("Could not close group '%s'??\n", params.groups[curr_group]);
+ error_msg("Could not close group '%s'??\n", params_g.groups[curr_group]);
leave(EXIT_FAILURE);
- } /* end if */
+ }
/* Display some output if requested */
- if(params.verbose)
- HDprintf("%s: created group '%s'\n", h5tools_getprogname(), params.groups[curr_group]);
+ if(params_g.verbose)
+ HDprintf("%s: created group '%s'\n", h5tools_getprogname(), params_g.groups[curr_group]);
} /* end for */
/* Close link creation property list */
if(H5Pclose(lcpl_id) < 0) {
error_msg("Could not close link creation property list\n");
leave(EXIT_FAILURE);
- } /* end if */
+ }
/* Close file */
if(H5Fclose(fid) < 0) {
- error_msg("Could not close output file '%s'??\n", params.fname);
- leave(EXIT_FAILURE);
- } /* end if */
-
- /* Close file access property list */
- if(H5Pclose(fapl_id) < 0) {
- error_msg("Could not close file access property list\n");
+ error_msg("Could not close output file '%s'??\n", params_g.fname);
leave(EXIT_FAILURE);
- } /* end if */
+ }
leave(EXIT_SUCCESS);
} /* end main() */