diff options
author | Dana Robinson <derobins@hdfgroup.org> | 2020-04-23 00:07:48 (GMT) |
---|---|---|
committer | Dana Robinson <derobins@hdfgroup.org> | 2020-04-23 00:07:48 (GMT) |
commit | 1db039d1beee05d7349e153cef4cf642c907cc1e (patch) | |
tree | 6b10d3ed6382ce8e678c49e90a605ca601efcfed /tools/src | |
parent | 729ad25bdff45c98e7a71acd118ee1332f0cc8bc (diff) | |
parent | 785bd0975ba13c3033820d0fc809da963fcd54ca (diff) | |
download | hdf5-1db039d1beee05d7349e153cef4cf642c907cc1e.zip hdf5-1db039d1beee05d7349e153cef4cf642c907cc1e.tar.gz hdf5-1db039d1beee05d7349e153cef4cf642c907cc1e.tar.bz2 |
Merge pull request #2532 in HDFFV/hdf5 from ~DEROBINS/hdf5_der:develop_minor to develop
* commit '785bd0975ba13c3033820d0fc809da963fcd54ca':
Fixed h5diff command-line parameters to use 1 and 2 instead of src and dst.
Added VOL command-line options to (p)h5diff, h5ls, h5dump, and h5mkgrp.
Diffstat (limited to 'tools/src')
-rw-r--r-- | tools/src/h5diff/h5diff_common.c | 78 | ||||
-rw-r--r-- | tools/src/h5dump/h5dump.c | 128 | ||||
-rw-r--r-- | tools/src/h5dump/h5dump.h | 1 | ||||
-rw-r--r-- | tools/src/h5ls/h5ls.c | 32 | ||||
-rw-r--r-- | tools/src/h5repack/h5repack_main.c | 1 | ||||
-rw-r--r-- | tools/src/misc/h5mkgrp.c | 234 |
6 files changed, 318 insertions, 156 deletions
diff --git a/tools/src/h5diff/h5diff_common.c b/tools/src/h5diff/h5diff_common.c index e05a8e3..771b20f 100644 --- a/tools/src/h5diff/h5diff_common.c +++ b/tools/src/h5diff/h5diff_common.c @@ -27,21 +27,27 @@ static int check_d_input(const char*); */ static const char *s_opts = "hVrv:qn:d:p:NcelxE:S"; static struct long_options l_opts[] = { - { "help", no_arg, 'h' }, - { "version", no_arg, 'V' }, - { "report", no_arg, 'r' }, - { "verbose", optional_arg, 'v' }, - { "quiet", no_arg, 'q' }, - { "count", require_arg, 'n' }, - { "delta", require_arg, 'd' }, - { "relative", require_arg, 'p' }, - { "nan", no_arg, 'N' }, - { "compare", no_arg, 'c' }, + { "help", no_arg, 'h' }, + { "version", no_arg, 'V' }, + { "report", no_arg, 'r' }, + { "verbose", optional_arg, 'v' }, + { "quiet", no_arg, 'q' }, + { "count", require_arg, 'n' }, + { "delta", require_arg, 'd' }, + { "relative", require_arg, 'p' }, + { "nan", no_arg, 'N' }, + { "compare", no_arg, 'c' }, { "use-system-epsilon", no_arg, 'e' }, - { "follow-symlinks", no_arg, 'l' }, - { "no-dangling-links", no_arg, 'x' }, - { "exclude-path", require_arg, 'E' }, + { "follow-symlinks", no_arg, 'l' }, + { "no-dangling-links", no_arg, 'x' }, + { "exclude-path", require_arg, 'E' }, { "enable-error-stack", no_arg, 'S' }, + { "vol-value-1", require_arg, '1' }, + { "vol-name-1", require_arg, '2' }, + { "vol-info-1", require_arg, '3' }, + { "vol-value-2", require_arg, '4' }, + { "vol-name-2", require_arg, '5' }, + { "vol-info-2", require_arg, '6' }, { NULL, 0, '\0' } }; @@ -91,7 +97,7 @@ void parse_command_line(int argc, struct exclude_path_list *exclude_head, *exclude_prev, *exclude_node; /* process the command-line */ - memset(opts, 0, sizeof (diff_opt_t)); + HDmemset(opts, 0, sizeof (diff_opt_t)); /* assume equal contents initially */ opts->contents = 1; @@ -258,6 +264,38 @@ void parse_command_line(int argc, case 'e': opts->use_system_epsilon = 1; break; + + case '1': + opts->vol_info_1.type = VOL_BY_VALUE; + opts->vol_info_1.u.value = (H5VL_class_value_t)HDatoi(opt_arg); + opts->custom_vol_1 = TRUE; + break; + + case '2': + opts->vol_info_1.type = VOL_BY_NAME; + opts->vol_info_1.u.name = opt_arg; + opts->custom_vol_1 = TRUE; + break; + + case '3': + opts->vol_info_1.info_string = opt_arg; + break; + + case '4': + opts->vol_info_2.type = VOL_BY_VALUE; + opts->vol_info_2.u.value = (H5VL_class_value_t)HDatoi(opt_arg); + opts->custom_vol_2 = TRUE; + break; + + case '5': + opts->vol_info_2.type = VOL_BY_NAME; + opts->vol_info_2.u.name = opt_arg; + opts->custom_vol_2 = TRUE; + break; + + case '6': + opts->vol_info_2.info_string = opt_arg; + break; } } @@ -469,6 +507,18 @@ void usage(void) PRINTVALSTREAM(rawoutstream, " Quiet mode. Do not produce output.\n"); PRINTVALSTREAM(rawoutstream, " --enable-error-stack\n"); PRINTVALSTREAM(rawoutstream, " Prints messages from the HDF5 error stack as they occur.\n"); + PRINTVALSTREAM(rawoutstream, " --vol-value-1 Value (ID) of the VOL connector to use for opening the\n"); + PRINTVALSTREAM(rawoutstream, " first HDF5 file specified\n"); + PRINTVALSTREAM(rawoutstream, " --vol-name-1 Name of the VOL connector to use for opening the first\n"); + PRINTVALSTREAM(rawoutstream, " HDF5 file specified\n"); + PRINTVALSTREAM(rawoutstream, " --vol-info-1 VOL-specific info to pass to the VOL connector used for\n"); + PRINTVALSTREAM(rawoutstream, " opening the first HDF5 file specified\n"); + PRINTVALSTREAM(rawoutstream, " --vol-value-2 Value (ID) of the VOL connector to use for opening the\n"); + PRINTVALSTREAM(rawoutstream, " second HDF5 file specified\n"); + PRINTVALSTREAM(rawoutstream, " --vol-name-2 Name of the VOL connector to use for opening the second\n"); + PRINTVALSTREAM(rawoutstream, " HDF5 file specified\n"); + PRINTVALSTREAM(rawoutstream, " --vol-info-2 VOL-specific info to pass to the VOL connector used for\n"); + PRINTVALSTREAM(rawoutstream, " opening the second HDF5 file specified\n"); PRINTVALSTREAM(rawoutstream, " --follow-symlinks\n"); PRINTVALSTREAM(rawoutstream, " Follow symbolic links (soft links and external links and compare the)\n"); PRINTVALSTREAM(rawoutstream, " links' target objects.\n"); diff --git a/tools/src/h5dump/h5dump.c b/tools/src/h5dump/h5dump.c index d292b75..dfaff17 100644 --- a/tools/src/h5dump/h5dump.c +++ b/tools/src/h5dump/h5dump.c @@ -18,15 +18,18 @@ /* Name of tool */ #define PROGRAMNAME "h5dump" -static const char *driver = NULL; /* The driver to open the file with. */ -const char *outfname=NULL; -static int doxml = 0; -static int useschema = 1; -static const char *xml_dtd_uri = NULL; +static const char *driver_name_g = NULL; /* The driver to open the file with. */ +const char *outfname_g = NULL; +static hbool_t doxml_g = FALSE; +static hbool_t useschema_g = TRUE; +static const char *xml_dtd_uri_g = NULL; + +static hbool_t use_custom_vol_g = FALSE; +static h5tools_vol_info_t vol_info_g; #ifdef H5_HAVE_ROS3_VFD /* Default "anonymous" S3 configuration */ -static H5FD_ros3_fapl_t ros3_fa = { +static H5FD_ros3_fapl_t ros3_fa_g = { 1, /* Structure Version */ false, /* Authenticate? */ "", /* AWS Region */ @@ -37,7 +40,7 @@ static H5FD_ros3_fapl_t ros3_fa = { #ifdef H5_HAVE_LIBHDFS /* "Default" HDFS configuration */ -static H5FD_hdfs_fapl_t hdfs_fa = { +static H5FD_hdfs_fapl_t hdfs_fa_g = { 1, /* Structure Version */ "localhost", /* Namenode Name */ 0, /* Namenode Port */ @@ -213,6 +216,9 @@ static struct long_options l_opts[] = { { "vds-gap-size", require_arg, 'G' }, { "s3-cred", require_arg, '$' }, { "hdfs-attrs", require_arg, '#' }, + { "vol-value", require_arg, '1' }, + { "vol-name", require_arg, '2' }, + { "vol-info", require_arg, '3' }, { NULL, 0, '\0' } }; @@ -270,6 +276,12 @@ usage(const char *prog) PRINTVALSTREAM(rawoutstream, " <kerberos cache path>,<username>,\n"); PRINTVALSTREAM(rawoutstream, " <buffer size>)\n"); PRINTVALSTREAM(rawoutstream, " Any absent attribute will use a default value.\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, "--------------- Object Options ---------------\n"); PRINTVALSTREAM(rawoutstream, " -a P, --attribute=P Print the specified attribute\n"); PRINTVALSTREAM(rawoutstream, " If an attribute name contains a slash (/), escape the\n"); @@ -863,7 +875,7 @@ parse_command_line(int argc, const char *argv[]) int opt; int last_was_dset = FALSE; - /* no arguments */ + /* no arguments */ if (argc == 1) { usage(h5tools_getprogname()); goto error; @@ -981,7 +993,7 @@ parse_start: last_was_dset = TRUE; break; case 'f': - driver = opt_arg; + driver_name_g = opt_arg; break; case 'g': display_all = 0; @@ -1051,7 +1063,7 @@ parse_start: usingdasho = TRUE; last_was_dset = FALSE; - outfname = opt_arg; + outfname_g = opt_arg; break; case 'b': @@ -1063,8 +1075,8 @@ parse_start: } } bin_output = TRUE; - if (outfname!=NULL) { - if (h5tools_set_data_output_file(outfname, 1) < 0) { + if (outfname_g != NULL) { + if (h5tools_set_data_output_file(outfname_g, 1) < 0) { /* failed to set output file */ usage(h5tools_getprogname()); goto error; @@ -1115,15 +1127,15 @@ parse_start: /** begin XML parameters **/ case 'x': /* select XML output */ - doxml = TRUE; - useschema = TRUE; + doxml_g = TRUE; + useschema_g = TRUE; h5tools_dump_header_format = NULL; dump_function_table = &xml_function_table; h5tools_nCols = 0; break; case 'u': - doxml = TRUE; - useschema = FALSE; + doxml_g = TRUE; + useschema_g = FALSE; xmlnsprefix = ""; h5tools_dump_header_format = NULL; dump_function_table = &xml_function_table; @@ -1132,7 +1144,7 @@ parse_start: case 'D': /* specify alternative XML DTD or schema */ /* To Do: check format of this value? */ - xml_dtd_uri = opt_arg; + xml_dtd_uri_g = opt_arg; h5tools_nCols = 0; break; @@ -1145,7 +1157,7 @@ parse_start: case 'X': /* specify XML namespace (default="hdf5:"), or none */ /* To Do: check format of this value? */ - if (!useschema) { + if (!useschema_g) { usage(h5tools_getprogname()); goto error; } @@ -1254,7 +1266,7 @@ end_collect: case '$': #ifdef H5_HAVE_ROS3_VFD - if (h5tools_parse_ros3_fapl_tuple(opt_arg, ',', &ros3_fa) < 0) { + if (h5tools_parse_ros3_fapl_tuple(opt_arg, ',', &ros3_fa_g) < 0) { error_msg("failed to parse S3 VFD credential info\n"); usage(h5tools_getprogname()); free_handler(hand, argc); @@ -1271,7 +1283,7 @@ end_collect: case '#': #ifdef H5_HAVE_LIBHDFS - if (h5tools_parse_hdfs_fapl_tuple(opt_arg, ',', &hdfs_fa) < 0) { + if (h5tools_parse_hdfs_fapl_tuple(opt_arg, ',', &hdfs_fa_g) < 0) { error_msg("failed to parse HDFS VFD configuration info\n"); usage(h5tools_getprogname()); free_handler(hand, argc); @@ -1286,6 +1298,22 @@ end_collect: #endif break; + case '1': + vol_info_g.type = VOL_BY_VALUE; + vol_info_g.u.value = (H5VL_class_value_t)HDatoi(opt_arg); + use_custom_vol_g = TRUE; + break; + + case '2': + vol_info_g.type = VOL_BY_NAME; + vol_info_g.u.name = opt_arg; + use_custom_vol_g = TRUE; + break; + + case '3': + vol_info_g.info_string = opt_arg; + break; + case '?': default: usage(h5tools_getprogname()); @@ -1360,7 +1388,7 @@ main(int argc, const char *argv[]) goto done; } - if (bin_output && outfname == NULL) { + if (bin_output && outfname_g == NULL) { error_msg("binary output requires a file name, use -o <filename>\n"); h5tools_setstatus(EXIT_FAILURE); goto done; @@ -1372,7 +1400,7 @@ main(int argc, const char *argv[]) } /* Check for conflicting options */ - if (doxml) { + if (doxml_g) { if (!display_all) { error_msg("option \"%s\" not available for XML\n", "to display selected objects"); h5tools_setstatus(EXIT_FAILURE); @@ -1400,8 +1428,8 @@ main(int argc, const char *argv[]) } } else { - if (xml_dtd_uri) { - warn_msg("option \"%s\" only applies with XML: %s\n", "--xml-dtd", xml_dtd_uri); + if (xml_dtd_uri_g) { + warn_msg("option \"%s\" only applies with XML: %s\n", "--xml-dtd", xml_dtd_uri_g); } } @@ -1414,24 +1442,24 @@ main(int argc, const char *argv[]) /* Initialize indexing options */ h5trav_set_index(sort_by, sort_order); - if (driver != NULL) { + if (driver_name_g != NULL) { h5tools_vfd_info_t vfd_info; vfd_info.info = NULL; - vfd_info.name = driver; + vfd_info.name = driver_name_g; - if (!HDstrcmp(driver, drivernames[ROS3_VFD_IDX])) { + if (!HDstrcmp(driver_name_g, drivernames[ROS3_VFD_IDX])) { #ifdef H5_HAVE_ROS3_VFD - vfd_info.info = (void *)&ros3_fa; + vfd_info.info = (void *)&ros3_fa_g; #else error_msg("Read-Only S3 VFD not enabled.\n"); h5tools_setstatus(EXIT_FAILURE); goto done; #endif } - else if (!HDstrcmp(driver, drivernames[HDFS_VFD_IDX])) { + else if (!HDstrcmp(driver_name_g, drivernames[HDFS_VFD_IDX])) { #ifdef H5_HAVE_LIBHDFS - vfd_info.info = (void *)&hdfs_fa; + vfd_info.info = (void *)&hdfs_fa_g; #else error_msg("The HDFS VFD is not enabled.\n"); h5tools_setstatus(EXIT_FAILURE); @@ -1444,7 +1472,15 @@ main(int argc, const char *argv[]) h5tools_setstatus(EXIT_FAILURE); goto done; } - } /* driver defined */ + } /* driver name defined */ + + if (use_custom_vol_g) { + if ((fapl_id = h5tools_get_fapl(H5P_DEFAULT, &vol_info_g, NULL)) < 0) { + error_msg("unable to create FAPL for file access\n"); + h5tools_setstatus(EXIT_FAILURE); + goto done; + } + } while(opt_ind < argc) { fname = HDstrdup(argv[opt_ind++]); @@ -1464,23 +1500,23 @@ main(int argc, const char *argv[]) /* Prepare to find objects that might be targets of a reference */ fill_ref_path_table(fid); - if(doxml) { + if(doxml_g) { /* initialize XML */ /* reset prefix! */ HDstrcpy(prefix, ""); /* make sure the URI is initialized to something */ - if (xml_dtd_uri == NULL) { - if (useschema) { - xml_dtd_uri = DEFAULT_XSD; + if (xml_dtd_uri_g == NULL) { + if (useschema_g) { + xml_dtd_uri_g = DEFAULT_XSD; } else { - xml_dtd_uri = DEFAULT_DTD; + xml_dtd_uri_g = DEFAULT_DTD; xmlnsprefix = ""; } } else { - if (useschema && HDstrcmp(xmlnsprefix,"")) { + if (useschema_g && HDstrcmp(xmlnsprefix,"")) { error_msg("Cannot set Schema URL for a qualified namespace--use -X or -U option with -D \n"); h5tools_setstatus(EXIT_FAILURE); goto done; @@ -1513,16 +1549,16 @@ main(int argc, const char *argv[]) } /* end if */ /* start to dump - display file header information */ - if (!doxml) { + if (!doxml_g) { begin_obj(h5tools_dump_header_format->filebegin, fname, h5tools_dump_header_format->fileblockbegin); } else { PRINTVALSTREAM(rawoutstream, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); /* alternative first element, depending on schema or DTD. */ - if (useschema) { + if (useschema_g) { if (HDstrcmp(xmlnsprefix,"") == 0) { - PRINTSTREAM(rawoutstream, "<HDF5-File xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"%s\">\n", xml_dtd_uri); + PRINTSTREAM(rawoutstream, "<HDF5-File xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"%s\">\n", xml_dtd_uri_g); } else { /* TO DO: make -url option work in this case (may need new option) */ @@ -1542,12 +1578,12 @@ main(int argc, const char *argv[]) } } else { - PRINTSTREAM(rawoutstream, "<!DOCTYPE HDF5-File PUBLIC \"HDF5-File.dtd\" \"%s\">\n", xml_dtd_uri); + PRINTSTREAM(rawoutstream, "<!DOCTYPE HDF5-File PUBLIC \"HDF5-File.dtd\" \"%s\">\n", xml_dtd_uri_g); PRINTVALSTREAM(rawoutstream, "<HDF5-File>\n"); } } - if (!doxml) { + if (!doxml_g) { if (display_fi) { PRINTVALSTREAM(rawoutstream, "\n"); dump_fcontents(fid); @@ -1566,10 +1602,10 @@ main(int argc, const char *argv[]) h5tools_setstatus(EXIT_FAILURE); } else { - if (!doxml) + if (!doxml_g) dump_indent += COL; dump_function_table->dump_group_function(gid, "/" ); - if (!doxml) + if (!doxml_g) dump_indent -= COL; PRINTVALSTREAM(rawoutstream, "\n"); } @@ -1582,7 +1618,7 @@ main(int argc, const char *argv[]) } else { /* Note: this option is not supported for XML */ - if(doxml) { + if(doxml_g) { error_msg("internal error (file %s:line %d)\n", __FILE__, __LINE__); h5tools_setstatus(EXIT_FAILURE); goto done; @@ -1596,7 +1632,7 @@ main(int argc, const char *argv[]) PRINTVALSTREAM(rawoutstream, "\n"); } - if (!doxml) { + if (!doxml_g) { end_obj(h5tools_dump_header_format->fileend, h5tools_dump_header_format->fileblockend); PRINTVALSTREAM(rawoutstream, "\n"); } diff --git a/tools/src/h5dump/h5dump.h b/tools/src/h5dump/h5dump.h index 801f60d..ca1fef6 100644 --- a/tools/src/h5dump/h5dump.h +++ b/tools/src/h5dump/h5dump.h @@ -43,6 +43,7 @@ typedef struct h5dump_table_items_t { table_t *dset_table; /* Table of datasets */ table_t *type_table; /* Table of datatypes */ } h5dump_table_items_t; + typedef struct h5dump_table_list_t { size_t nalloc; size_t nused; diff --git a/tools/src/h5ls/h5ls.c b/tools/src/h5ls/h5ls.c index 3036ae9..765ab63 100644 --- a/tools/src/h5ls/h5ls.c +++ b/tools/src/h5ls/h5ls.c @@ -218,6 +218,12 @@ usage (void) PRINTVALSTREAM(rawoutstream, " ...<kerberos cache path>,<username>,<buffer size>)\n"); PRINTVALSTREAM(rawoutstream, " If absent or A == '(,,,,)', all default values are used.\n"); PRINTVALSTREAM(rawoutstream, " Has no effect if vfd flag is not 'hdfs'.\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"); PRINTVALSTREAM(rawoutstream, " file/OBJECT\n"); PRINTVALSTREAM(rawoutstream, " Each object consists of an HDF5 file name optionally followed by a\n"); @@ -2854,6 +2860,8 @@ main(int argc, const char *argv[]) H5E_auto2_t tools_func; void *edata; void *tools_edata; + hbool_t custom_vol_fapl = FALSE; + h5tools_vol_info_t vol_info; #ifdef H5_HAVE_ROS3_VFD /* Default "anonymous" S3 configuration */ @@ -2892,6 +2900,9 @@ main(int argc, const char *argv[]) H5Eget_auto2(H5tools_ERR_STACK_g, &tools_func, &tools_edata); H5Eset_auto2(H5tools_ERR_STACK_g, NULL, NULL); + /* Initialize fapl info struct */ + HDmemset(&vol_info, 0, sizeof(h5tools_vol_info_t)); + /* Build object display table */ DISPATCH(H5O_TYPE_GROUP, "Group", NULL, NULL); DISPATCH(H5O_TYPE_DATASET, "Dataset", dataset_list1, dataset_list2); @@ -2955,6 +2966,19 @@ main(int argc, const char *argv[]) else if (!HDstrncmp(argv[argno], "--vfd=", (size_t)6)) { preferred_driver = argv[argno]+6; } + else if (!HDstrncmp(argv[argno], "--vol-value=", (size_t)12)) { + vol_info.type = VOL_BY_VALUE; + vol_info.u.value = (H5VL_class_value_t)HDatoi(argv[argno]+12); + custom_vol_fapl = TRUE; + } + else if (!HDstrncmp(argv[argno], "--vol-name=", (size_t)11)) { + vol_info.type = VOL_BY_NAME; + vol_info.u.name = argv[argno]+11; + custom_vol_fapl = TRUE; + } + else if (!HDstrncmp(argv[argno], "--vol-info=", (size_t)11)) { + vol_info.info_string = argv[argno]+11; + } else if (!HDstrncmp(argv[argno], "--width=", (size_t)8)) { width_g = (int)HDstrtol(argv[argno]+8, &rest, 0); @@ -3147,6 +3171,14 @@ main(int argc, const char *argv[]) leave(EXIT_FAILURE); } + /* Setup a custom fapl for file accesses */ + if (custom_vol_fapl) { + if ((fapl_id = h5tools_get_fapl(H5P_DEFAULT, &vol_info, NULL)) < 0) { + error_msg("failed to setup file access property list (fapl) for file\n"); + leave(EXIT_FAILURE); + } + } + if (preferred_driver) { h5tools_vfd_info_t vfd_info; diff --git a/tools/src/h5repack/h5repack_main.c b/tools/src/h5repack/h5repack_main.c index d54827f..f7822ca 100644 --- a/tools/src/h5repack/h5repack_main.c +++ b/tools/src/h5repack/h5repack_main.c @@ -440,6 +440,7 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) int bound, opt; int ret_value = 0; + /* Initialize fapl info structs */ HDmemset(&in_vol_info, 0, sizeof(h5tools_vol_info_t)); HDmemset(&out_vol_info, 0, sizeof(h5tools_vol_info_t)); 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(¶ms, 0, sizeof(params)); - if(parse_command_line(argc, argv, ¶ms) < 0) { - error_msg("unable to parse command line arguments\n"); - leave(EXIT_FAILURE); - } /* end if */ + /* Initialize the parameters */ + HDmemset(¶ms_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, ¶ms_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() */ |