summaryrefslogtreecommitdiffstats
path: root/tools/src/h5format_convert
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-07-15 16:20:16 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-07-15 16:20:16 (GMT)
commitbac0fc6309aaf777d4b6d093cf027dce3ecfb58c (patch)
tree1b944edb35a01a5bb8bb72445f82afb52317f06e /tools/src/h5format_convert
parent900e75544e214a82de3b7fcdbc083ee71d484892 (diff)
downloadhdf5-bac0fc6309aaf777d4b6d093cf027dce3ecfb58c.zip
hdf5-bac0fc6309aaf777d4b6d093cf027dce3ecfb58c.tar.gz
hdf5-bac0fc6309aaf777d4b6d093cf027dce3ecfb58c.tar.bz2
Tools refactor
Move error_stack setup to tools library Add structure for h5dump properties Eliminate duplicated h5diff functions Use properties structure in place of argument lists.
Diffstat (limited to 'tools/src/h5format_convert')
-rw-r--r--tools/src/h5format_convert/h5format_convert.c178
1 files changed, 89 insertions, 89 deletions
diff --git a/tools/src/h5format_convert/h5format_convert.c b/tools/src/h5format_convert/h5format_convert.c
index 2c4cf41..d63f36f 100644
--- a/tools/src/h5format_convert/h5format_convert.c
+++ b/tools/src/h5format_convert/h5format_convert.c
@@ -64,7 +64,7 @@ static struct long_options l_opts[] = {
{ NULL, 0, '\0' }
};
-
+
/*-------------------------------------------------------------------------
* Function: usage
*
@@ -109,7 +109,7 @@ static void usage(const char *prog)
* Purpose: parse command line input
*
* Return: Success: 0
- * Failure: 1
+ * Failure: 1
*
*-------------------------------------------------------------------------
*/
@@ -127,47 +127,47 @@ parse_command_line(int argc, const char **argv)
/* parse command line options */
while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) {
- switch((char) opt) {
- case 'h':
- usage(h5tools_getprogname());
- h5tools_setstatus(EXIT_SUCCESS);
- goto error;
-
- case 'V':
- print_version(h5tools_getprogname());
- h5tools_setstatus(EXIT_SUCCESS);
- goto error;
-
- case 'v':
- verbose_g = TRUE;
- break;
-
- case 'd': /* -d dname */
- if(opt_arg != NULL && *opt_arg)
- dname_g = HDstrdup(opt_arg);
- if(dname_g == NULL) {
- h5tools_setstatus(EXIT_FAILURE);
- error_msg("No dataset name\n", opt_arg);
- usage(h5tools_getprogname());
- goto error;
- }
- dset_g = TRUE;
- break;
-
- case 'n': /* -n */
- noop_g = TRUE;
- break;
-
- case 'E':
- enable_error_stack = 1;
- break;
-
- default:
- h5tools_setstatus(EXIT_FAILURE);
- usage(h5tools_getprogname());
- goto error;
- break;
- } /* switch */
+ switch((char) opt) {
+ case 'h':
+ usage(h5tools_getprogname());
+ h5tools_setstatus(EXIT_SUCCESS);
+ goto error;
+
+ case 'V':
+ print_version(h5tools_getprogname());
+ h5tools_setstatus(EXIT_SUCCESS);
+ goto error;
+
+ case 'v':
+ verbose_g = TRUE;
+ break;
+
+ case 'd': /* -d dname */
+ if(opt_arg != NULL && *opt_arg)
+ dname_g = HDstrdup(opt_arg);
+ if(dname_g == NULL) {
+ h5tools_setstatus(EXIT_FAILURE);
+ error_msg("No dataset name\n", opt_arg);
+ usage(h5tools_getprogname());
+ goto error;
+ }
+ dset_g = TRUE;
+ break;
+
+ case 'n': /* -n */
+ noop_g = TRUE;
+ break;
+
+ case 'E':
+ enable_error_stack = 1;
+ break;
+
+ default:
+ h5tools_setstatus(EXIT_FAILURE);
+ usage(h5tools_getprogname());
+ goto error;
+ break;
+ } /* switch */
} /* while */
if (argc <= opt_ind) {
@@ -185,7 +185,7 @@ error:
return(-1); ;
} /* parse_command_line() */
-
+
/*-------------------------------------------------------------------------
* Function: leave
*
@@ -207,17 +207,17 @@ leave(int ret)
* Function: convert()
*
* Purpose: To downgrade a dataset's indexing type or layout version:
- * For chunked:
- * Downgrade the chunk indexing type to version 1 B-tree
- * If type is already version 1 B-tree, no further action
- * For compact/contiguous:
- * Downgrade the layout version from 4 to 3
- * If version is already <= 3, no further action
- * For virtual:
- * No further action
+ * For chunked:
+ * Downgrade the chunk indexing type to version 1 B-tree
+ * If type is already version 1 B-tree, no further action
+ * For compact/contiguous:
+ * Downgrade the layout version from 4 to 3
+ * If version is already <= 3, no further action
+ * For virtual:
+ * No further action
*
* Return: Success: 0
- * Failure: 1
+ * Failure: 1
*
*-------------------------------------------------------------------------
*/
@@ -312,7 +312,7 @@ convert(hid_t fid, const char *dname)
}
if(verbose_g)
- HDfprintf(stdout, "Converting the dataset...\n");
+ HDfprintf(stdout, "Converting the dataset...\n");
/* Downgrade the dataset */
if(H5Dformat_convert(did) < 0) {
@@ -377,7 +377,7 @@ convert_dsets_cb(const char *path, const H5O_info2_t *oi, const char *already_vi
if(verbose_g)
HDfprintf(stdout, "Going to process dataset:%s...\n", path);
if(convert(fid, path) < 0)
- goto error;
+ goto error;
} /* end if */
} /* end if */
@@ -387,62 +387,61 @@ error:
return -1;
} /* end convert_dsets_cb() */
-
+
/*-------------------------------------------------------------------------
* Function: main
*
* Purpose: To convert the chunk indexing type of a dataset in a file to
- * version 1 B-tree.
+ * version 1 B-tree.
*
* Return: Success: 0
- * Failure: 1
+ * Failure: 1
*
*-------------------------------------------------------------------------
*/
int
main(int argc, const char *argv[])
{
- H5E_auto2_t func;
- void *edata;
hid_t fid = H5I_INVALID_HID;
h5tools_setprogname(PROGRAMNAME);
h5tools_setstatus(EXIT_SUCCESS);
- /* Disable error reporting */
- H5Eget_auto2(H5E_DEFAULT, &func, &edata);
- H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
-
/* Initialize h5tools lib */
h5tools_init();
/* Parse command line options */
if(parse_command_line(argc, argv) < 0)
- goto done;
+ goto done;
else if(verbose_g)
- HDfprintf(stdout, "Process command line options\n");
+ HDfprintf(stdout, "Process command line options\n");
if(noop_g && verbose_g)
- HDfprintf(stdout, "It is noop...\n");
+ HDfprintf(stdout, "It is noop...\n");
+
+ /* enable error reporting if command line option */
+ h5tools_error_report();
/* Open the HDF5 file */
if((fid = h5tools_fopen(fname_g, H5F_ACC_RDWR, H5P_DEFAULT, FALSE, NULL, 0)) < 0) {
- error_msg("unable to open file \"%s\"\n", fname_g);
- h5tools_setstatus(EXIT_FAILURE);
- goto done;
- } else if(verbose_g)
- HDfprintf(stdout, "Open the file %s\n", fname_g);
+ error_msg("unable to open file \"%s\"\n", fname_g);
+ h5tools_setstatus(EXIT_FAILURE);
+ goto done;
+ }
+ else if(verbose_g)
+ HDfprintf(stdout, "Open the file %s\n", fname_g);
if(dset_g) { /* Convert a specified dataset in the file */
- if(verbose_g)
- HDfprintf(stdout, "Going to process dataset: %s...\n", dname_g);
- if(convert(fid, dname_g) < 0)
- goto done;
- } else { /* Convert all datasets in the file */
- if(verbose_g)
- HDfprintf(stdout, "Processing all datasets in the file...\n");
- if(h5trav_visit(fid, "/", TRUE, TRUE, convert_dsets_cb, NULL, &fid, H5O_INFO_BASIC) < 0)
- goto done;
+ if(verbose_g)
+ HDfprintf(stdout, "Going to process dataset: %s...\n", dname_g);
+ if(convert(fid, dname_g) < 0)
+ goto done;
+ }
+ else { /* Convert all datasets in the file */
+ if(verbose_g)
+ HDfprintf(stdout, "Processing all datasets in the file...\n");
+ if(h5trav_visit(fid, "/", TRUE, TRUE, convert_dsets_cb, NULL, &fid, H5O_INFO_BASIC) < 0)
+ goto done;
} /* end else */
if(verbose_g) {
@@ -464,19 +463,20 @@ main(int argc, const char *argv[])
done:
/* Close the file */
if(fid >= 0) {
- if(H5Fclose(fid) < 0) {
- error_msg("unable to close file \"%s\"\n", fname_g);
- h5tools_setstatus(EXIT_FAILURE);
- } else if(verbose_g)
- HDfprintf(stdout, "Close the file\n");
+ if(H5Fclose(fid) < 0) {
+ error_msg("unable to close file \"%s\"\n", fname_g);
+ h5tools_setstatus(EXIT_FAILURE);
+ }
+ else if(verbose_g) {
+ HDfprintf(stdout, "Close the file\n");
+ }
} /* end if */
if(fname_g)
- HDfree(fname_g);
+ HDfree(fname_g);
if(dname_g)
- HDfree(dname_g);
+ HDfree(dname_g);
- H5Eset_auto2(H5E_DEFAULT, func, edata);
leave(h5tools_getstatus());
} /* end main() */