summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/h5repack/h5repack.c546
-rw-r--r--tools/h5repack/h5repack_copy.c2513
-rw-r--r--tools/h5repack/h5repack_filters.c14
-rw-r--r--tools/h5repack/h5repack_main.c402
-rw-r--r--tools/h5repack/h5repack_plugin.sh.in2
-rw-r--r--tools/h5repack/h5repack_refs.c256
-rw-r--r--tools/h5repack/h5repack_verify.c247
-rw-r--r--tools/h5repack/h5repacktst.c200
-rw-r--r--tools/h5repack/testfiles/h5repack_filters.h5-gzip_verbose_filters.tst13
9 files changed, 2064 insertions, 2129 deletions
diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c
index 8a9090a..3f99374 100644
--- a/tools/h5repack/h5repack.c
+++ b/tools/h5repack/h5repack.c
@@ -118,35 +118,36 @@ int h5repack_end(pack_opt_t *options) {
*
*-------------------------------------------------------------------------
*/
-int h5repack_addfilter(const char* str, pack_opt_t *options) {
- obj_list_t *obj_list = NULL; /* one object list for the -f and -l option entry */
- filter_info_t filter; /* filter info for the current -f option entry */
- int n_objs; /* number of objects in the current -f or -l option entry */
- int is_glb; /* is the filter global */
-
- /* parse the -f option */
- if (NULL == (obj_list = parse_filter(str, &n_objs, &filter, options, &is_glb)))
- return -1;
-
- /* if it applies to all objects */
- if (is_glb) {
- int n;
-
- n = options->n_filter_g++; /* increase # of global filters */
-
- if (options->n_filter_g > H5_REPACK_MAX_NFILTERS) {
- error_msg("maximum number of filters exceeded for <%s>\n", str);
- HDfree(obj_list);
- return -1;
- }
-
- options->filter_g[n] = filter;
- }
- else
- options_add_filter(obj_list, n_objs, filter, options->op_tbl);
-
- HDfree(obj_list);
- return 0;
+int
+h5repack_addfilter(const char* str, pack_opt_t *options)
+{
+ obj_list_t *obj_list = NULL; /* one object list for the -f and -l option entry */
+ filter_info_t filter; /* filter info for the current -f option entry */
+ unsigned n_objs; /* number of objects in the current -f or -l option entry */
+ int is_glb; /* is the filter global */
+
+ /* parse the -f option */
+ if (NULL == (obj_list = parse_filter(str, &n_objs, &filter, options, &is_glb)))
+ return -1;
+
+ /* if it applies to all objects */
+ if (is_glb) {
+ int n;
+
+ n = options->n_filter_g++; /* increase # of global filters */
+ if (options->n_filter_g > H5_REPACK_MAX_NFILTERS) {
+ error_msg("maximum number of filters exceeded for <%s>\n", str);
+ HDfree(obj_list);
+ return -1;
+ }
+
+ options->filter_g[n] = filter;
+ }
+ else
+ options_add_filter(obj_list, n_objs, filter, options->op_tbl);
+
+ HDfree(obj_list);
+ return 0;
}
/*-------------------------------------------------------------------------
@@ -158,59 +159,53 @@ int h5repack_addfilter(const char* str, pack_opt_t *options) {
*
*-------------------------------------------------------------------------
*/
-
-int h5repack_addlayout(const char* str, pack_opt_t *options) {
-
- obj_list_t *obj_list = NULL; /*one object list for the -t and -c option entry */
- int n_objs; /*number of objects in the current -t or -c option entry */
- pack_info_t pack; /*info about layout to extract from parse */
- int j;
- int ret_value = -1;
-
- init_packobject(&pack);
-
- if (options->all_layout == 1) {
- error_msg(
- "invalid layout input: 'all' option \
- is present with other objects <%s>\n",
- str);
- return ret_value;
- }
-
- /* parse the layout option */
- obj_list = parse_layout(str, &n_objs, &pack, options);
- if (obj_list) {
-
- /* set layout option */
- options->layout_g = pack.layout;
-
- /* no individual dataset specified */
- if (options->all_layout == 1) {
- if (pack.layout == H5D_CHUNKED) {
- /* -2 means the NONE option, remove chunking
- and set the global layout to contiguous */
- if (pack.chunk.rank == -2) {
- options->layout_g = H5D_CONTIGUOUS;
- }
- /* otherwise set the global chunking type */
- else {
- options->chunk_g.rank = pack.chunk.rank;
- for (j = 0; j < pack.chunk.rank; j++)
- options->chunk_g.chunk_lengths[j] =
- pack.chunk.chunk_lengths[j];
- }
- }
- }
-
- /* individual dataset specified */
- if (options->all_layout == 0)
- ret_value = options_add_layout(obj_list, n_objs, &pack, options->op_tbl);
-
- HDfree(obj_list);
- ret_value = 0;
- }
-
- return ret_value;
+int
+h5repack_addlayout(const char* str, pack_opt_t *options)
+{
+ obj_list_t *obj_list = NULL; /*one object list for the -t and -c option entry */
+ unsigned n_objs; /*number of objects in the current -t or -c option entry */
+ pack_info_t pack; /*info about layout to extract from parse */
+ int j;
+ int ret_value = -1;
+
+ init_packobject(&pack);
+
+ if (options->all_layout == 1) {
+ error_msg( "invalid layout input: 'all' option is present with other objects <%s>\n", str);
+ return ret_value;
+ }
+
+ /* parse the layout option */
+ obj_list = parse_layout(str, &n_objs, &pack, options);
+ if (obj_list) {
+ /* set layout option */
+ options->layout_g = pack.layout;
+
+ /* no individual dataset specified */
+ if (options->all_layout == 1) {
+ if (pack.layout == H5D_CHUNKED) {
+ /* -2 means the NONE option, remove chunking
+ and set the global layout to contiguous */
+ if (pack.chunk.rank == -2)
+ options->layout_g = H5D_CONTIGUOUS;
+ /* otherwise set the global chunking type */
+ else {
+ options->chunk_g.rank = pack.chunk.rank;
+ for (j = 0; j < pack.chunk.rank; j++)
+ options->chunk_g.chunk_lengths[j] = pack.chunk.chunk_lengths[j];
+ }
+ }
+ }
+
+ /* individual dataset specified */
+ if (options->all_layout == 0)
+ ret_value = options_add_layout(obj_list, n_objs, &pack, options->op_tbl);
+
+ HDfree(obj_list);
+ ret_value = 0;
+ }
+
+ return ret_value;
}
/* Note: The below copy_named_datatype(), named_datatype_free(), copy_attr()
@@ -366,200 +361,201 @@ done:
*
*-------------------------------------------------------------------------
*/
-int copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p,
- trav_table_t *travt, pack_opt_t *options) {
- hid_t attr_id = -1; /* attr ID */
- hid_t attr_out = -1; /* attr ID */
- hid_t space_id = -1; /* space ID */
- hid_t ftype_id = -1; /* file type ID */
- hid_t wtype_id = -1; /* read/write type ID */
- size_t msize; /* size of type */
- void *buf = NULL; /* data buffer */
- hsize_t nelmts; /* number of elements in dataset */
- int rank; /* rank of dataset */
- htri_t is_named; /* Whether the datatype is named */
- hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */
- char name[255];
- H5O_info_t oinfo; /* object info */
- int j;
- unsigned u;
- hbool_t is_ref = 0;
- H5T_class_t type_class = -1;
-
- if (H5Oget_info(loc_in, &oinfo) < 0)
- goto error;
-
- /*-------------------------------------------------------------------------
- * copy all attributes
- *-------------------------------------------------------------------------
- */
- for (u = 0; u < (unsigned) oinfo.num_attrs; u++) {
- /* open attribute */
- if ((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER,
- H5_ITER_INC, (hsize_t) u, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto error;
-
- /* get name */
- if (H5Aget_name(attr_id, (size_t) 255, name) < 0)
- goto error;
-
- /* get the file datatype */
- if ((ftype_id = H5Aget_type(attr_id)) < 0)
- goto error;
-
- /* Check if the datatype is committed */
- if ((is_named = H5Tcommitted(ftype_id)) < 0)
- goto error;
- if (is_named && travt) {
- hid_t fidout;
-
- /* Create out file id */
- if ((fidout = H5Iget_file_id(loc_out)) < 0)
- goto error;
-
- /* Copy named dt */
- if ((wtype_id = copy_named_datatype(ftype_id, fidout,
- named_dt_head_p, travt, options)) < 0) {
- H5Fclose(fidout);
- goto error;
- } /* end if */
-
- if (H5Fclose(fidout) < 0)
- goto error;
- } /* end if */
- else {
- if (options->use_native == 1)
- wtype_id = h5tools_get_native_type(ftype_id);
- else
- wtype_id = H5Tcopy(ftype_id);
- } /* end else */
-
- /* get the dataspace handle */
- if ((space_id = H5Aget_space(attr_id)) < 0)
- goto error;
-
- /* get dimensions */
- if ((rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0)
- goto error;
-
- nelmts = 1;
- for (j = 0; j < rank; j++)
- nelmts *= dims[j];
-
- if ((msize = H5Tget_size(wtype_id)) == 0)
- goto error;
-
- /*-------------------------------------------------------------------------
- * object references are a special case. We cannot just copy the buffers,
- * but instead we recreate the reference.
- * This is done on a second sweep of the file that just copies the referenced
- * objects at copy_refs_attr()
- *-------------------------------------------------------------------------
- */
- type_class = H5Tget_class(wtype_id);
- is_ref = (type_class == H5T_REFERENCE);
- if (type_class == H5T_VLEN || type_class == H5T_ARRAY) {
- hid_t base_type = -1;
- base_type = H5Tget_super(ftype_id);
- is_ref = (is_ref || (H5Tget_class(base_type) == H5T_REFERENCE));
- H5Tclose(base_type);
- }
+int
+copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p,
+ trav_table_t *travt, pack_opt_t *options)
+{
+ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
+ hid_t attr_id = -1; /* attr ID */
+ hid_t attr_out = -1; /* attr ID */
+ hid_t space_id = -1; /* space ID */
+ hid_t ftype_id = -1; /* file type ID */
+ hid_t wtype_id = -1; /* read/write type ID */
+ size_t msize; /* size of type */
+ void *buf = NULL; /* data buffer */
+ hsize_t nelmts; /* number of elements in dataset */
+ int rank; /* rank of dataset */
+ htri_t is_named; /* Whether the datatype is named */
+ hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */
+ char name[255];
+ H5O_info_t oinfo; /* object info */
+ int j;
+ unsigned u;
+ hbool_t is_ref = 0;
+ H5T_class_t type_class = -1;
+
+ if (H5Oget_info(loc_in, &oinfo) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Oget_info failed");
+
+ /*-------------------------------------------------------------------------
+ * copy all attributes
+ *-------------------------------------------------------------------------
+ */
+ for (u = 0; u < (unsigned) oinfo.num_attrs; u++) {
+ /* open attribute */
+ if ((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t) u, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aopen_by_idx failed");
+
+ /* get name */
+ if (H5Aget_name(attr_id, (size_t) 255, name) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+
+ /* get the file datatype */
+ if ((ftype_id = H5Aget_type(attr_id)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type failed");
+
+ /* Check if the datatype is committed */
+ if ((is_named = H5Tcommitted(ftype_id)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tcommitted failed");
+ if (is_named && travt) {
+ hid_t fidout;
+
+ /* Create out file id */
+ if ((fidout = H5Iget_file_id(loc_out)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Iget_file_id failed");
+
+ /* Copy named dt */
+ if ((wtype_id = copy_named_datatype(ftype_id, fidout, named_dt_head_p, travt, options)) < 0) {
+ H5Fclose(fidout);
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_named_datatype failed");
+ } /* end if */
+
+ if (H5Fclose(fidout) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Fclose failed");
+ } /* end if */
+ else {
+ if (options->use_native == 1)
+ wtype_id = h5tools_get_native_type(ftype_id);
+ else
+ wtype_id = H5Tcopy(ftype_id);
+ } /* end else */
+
+ /* get the dataspace handle */
+ if ((space_id = H5Aget_space(attr_id)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_space failed");
+
+ /* get dimensions */
+ if ((rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed");
+
+ nelmts = 1;
+ for (j = 0; j < rank; j++)
+ nelmts *= dims[j];
+
+ if ((msize = H5Tget_size(wtype_id)) == 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed");
+
+ /*-------------------------------------------------------------------------
+ * object references are a special case. We cannot just copy the buffers,
+ * but instead we recreate the reference.
+ * This is done on a second sweep of the file that just copies the referenced
+ * objects at copy_refs_attr()
+ *-------------------------------------------------------------------------
+ */
+ type_class = H5Tget_class(wtype_id);
+ is_ref = (type_class == H5T_REFERENCE);
+ if (type_class == H5T_VLEN || type_class == H5T_ARRAY) {
+ hid_t base_type = -1;
+
+ base_type = H5Tget_super(ftype_id);
+ is_ref = (is_ref || (H5Tget_class(base_type) == H5T_REFERENCE));
+ H5Tclose(base_type);
+ }
+
+ if (type_class == H5T_COMPOUND) {
+ int nmembers = H5Tget_nmembers(wtype_id);
+
+ for (j = 0; j < nmembers; j++) {
+ hid_t mtid = H5Tget_member_type(wtype_id, (unsigned) j);
+ H5T_class_t mtclass = H5Tget_class(mtid);
+ H5Tclose(mtid);
+
+ if (mtclass == H5T_REFERENCE) {
+ is_ref = 1;
+ break;
+ }
+ } /* for (j=0; i<nmembers; j++) */
+ } /* if (type_class == H5T_COMPOUND) */
+
+ if (is_ref) {
+ ; /* handled by copy_refs_attr() */
+ }
+ else {
+ /*-------------------------------------------------------------------------
+ * read to memory
+ *-------------------------------------------------------------------------
+ */
+
+ buf = (void *) HDmalloc((size_t)(nelmts * msize));
+ if (buf == NULL) {
+ error_msg("h5repack", "cannot read into memory\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed");
+ } /* end if */
+ if (H5Aread(attr_id, wtype_id, buf) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed");
+
+ /*-------------------------------------------------------------------------
+ * copy
+ *-------------------------------------------------------------------------
+ */
+
+ if ((attr_out = H5Acreate2(loc_out, name, wtype_id, space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Acreate2 failed");
+ if (H5Awrite(attr_out, wtype_id, buf) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Awrite failed");
+
+ /*close*/
+ if (H5Aclose(attr_out) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed");
+
+ /* Check if we have VL data and string in the attribute's datatype that must
+ * be reclaimed */
+ if (TRUE == h5tools_detect_vlen(wtype_id))
+ H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf);
+ HDfree(buf);
+ buf = NULL;
+ } /*H5T_REFERENCE*/
+
+ if (options->verbose)
+ printf(FORMAT_OBJ_ATTR, "attr", name);
+
+ /*-------------------------------------------------------------------------
+ * close
+ *-------------------------------------------------------------------------
+ */
+
+ if (H5Tclose(ftype_id) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
+ if (H5Tclose(wtype_id) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
+ if (H5Sclose(space_id) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed");
+ if (H5Aclose(attr_id) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed");
+ } /* u */
+
+ return 0;
- if (type_class == H5T_COMPOUND) {
- int nmembers = H5Tget_nmembers(wtype_id);
- for (j = 0; j < nmembers; j++) {
- hid_t mtid = H5Tget_member_type(wtype_id, (unsigned) j);
- H5T_class_t mtclass = H5Tget_class(mtid);
- H5Tclose(mtid);
-
- if (mtclass == H5T_REFERENCE) {
- is_ref = 1;
- break;
- }
- } /* for (j=0; i<nmembers; j++) */
- } /* if (type_class == H5T_COMPOUND) */
-
- if (is_ref) {
- ; /* handled by copy_refs_attr() */
- }
- else {
- /*-------------------------------------------------------------------------
- * read to memory
- *-------------------------------------------------------------------------
- */
-
- buf = (void *) HDmalloc((size_t)(nelmts * msize));
- if (buf == NULL) {
- error_msg("h5repack", "cannot read into memory\n");
- goto error;
- } /* end if */
- if (H5Aread(attr_id, wtype_id, buf) < 0)
- goto error;
-
- /*-------------------------------------------------------------------------
- * copy
- *-------------------------------------------------------------------------
- */
-
- if ((attr_out = H5Acreate2(loc_out, name, wtype_id, space_id,
- H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto error;
- if (H5Awrite(attr_out, wtype_id, buf) < 0)
- goto error;
-
- /*close*/
- if (H5Aclose(attr_out) < 0)
- goto error;
-
- /* Check if we have VL data and string in the attribute's datatype that must
- * be reclaimed */
- if (TRUE == h5tools_detect_vlen(wtype_id))
- H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf);
- HDfree(buf);
- buf = NULL;
- } /*H5T_REFERENCE*/
-
- if (options->verbose)
- printf(FORMAT_OBJ_ATTR, "attr", name);
-
- /*-------------------------------------------------------------------------
- * close
- *-------------------------------------------------------------------------
- */
-
- if (H5Tclose(ftype_id) < 0)
- goto error;
- if (H5Tclose(wtype_id) < 0)
- goto error;
- if (H5Sclose(space_id) < 0)
- goto error;
- if (H5Aclose(attr_id) < 0)
- goto error;
- } /* u */
-
- return 0;
-
-error:
- H5E_BEGIN_TRY
- {
- if (buf) {
- /* Check if we have VL data and string in the attribute's datatype that must
- * be reclaimed */
- if (TRUE == h5tools_detect_vlen(wtype_id))
- H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf);
-
- /* Free buf */
- HDfree(buf);
- } /* end if */
-
- H5Tclose(ftype_id);
- H5Tclose(wtype_id);
- H5Sclose(space_id);
- H5Aclose(attr_id);
- H5Aclose(attr_out);
- } H5E_END_TRY;
-
- return -1;
+done:
+ H5E_BEGIN_TRY {
+ if (buf) {
+ /* Check if we have VL data and string in the attribute's datatype that must
+ * be reclaimed */
+ if (TRUE == h5tools_detect_vlen(wtype_id))
+ H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf);
+
+ /* Free buf */
+ HDfree(buf);
+ } /* end if */
+
+ H5Tclose(ftype_id);
+ H5Tclose(wtype_id);
+ H5Sclose(space_id);
+ H5Aclose(attr_id);
+ H5Aclose(attr_out);
+ } H5E_END_TRY;
+
+ return ret_value;
} /* end copy_attr() */
/*-------------------------------------------------------------------------
diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c
index 1963750..547f61a 100644
--- a/tools/h5repack/h5repack_copy.c
+++ b/tools/h5repack/h5repack_copy.c
@@ -36,7 +36,7 @@
#define USERBLOCK_XFER_SIZE 512
/* check H5Dread()/H5Dwrite() error, e.g. memory allocation error inside the library. */
-#define CHECK_H5DRW_ERROR(_fun, _did, _mtid, _msid, _fsid, _pid, _buf) { \
+#define CHECK_H5DRW_ERROR(_fun, _fail, _did, _mtid, _msid, _fsid, _pid, _buf) { \
H5E_BEGIN_TRY { \
if(_fun(_did, _mtid, _msid, _fsid, _pid, _buf) < 0) { \
hid_t _err_num = 0; \
@@ -44,7 +44,7 @@
H5Ewalk2(H5E_DEFAULT, H5E_WALK_DOWNWARD, walk_error_callback, &_err_num); \
H5Eget_msg(_err_num, NULL, _msg, (size_t)80); \
error_msg("%s %s -- %s\n", #_fun, "failed", _msg); \
- goto error; \
+ HGOTO_DONE(_fail) \
} \
} H5E_END_TRY; \
}
@@ -68,7 +68,7 @@ static herr_t walk_error_callback(unsigned n, const H5E_error2_t *err_desc, void
/* get the major number from the error stack. */
static herr_t walk_error_callback(H5_ATTR_UNUSED unsigned n, const H5E_error2_t *err_desc, void *udata) {
if (err_desc)
- *((int *) udata) = err_desc->maj_num;
+ *((hid_t *) udata) = err_desc->maj_num;
return 0;
}
@@ -97,306 +97,331 @@ static herr_t walk_error_callback(H5_ATTR_UNUSED unsigned n, const H5E_error2_t
*-------------------------------------------------------------------------
*/
-int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) {
- hid_t fidin;
- hid_t fidout = -1;
- trav_table_t *travt = NULL;
- hsize_t ub_size = 0; /* size of user block */
- hid_t fcpl = H5P_DEFAULT; /* file creation property list ID */
- hid_t fapl = H5P_DEFAULT; /* file access property list ID */
-
- /*-------------------------------------------------------------------------
- * open input file
- *-------------------------------------------------------------------------
- */
- if ((fidin = h5tools_fopen(fnamein, H5F_ACC_RDONLY, H5P_DEFAULT, NULL, NULL,
- (size_t) 0)) < 0) {
- error_msg("<%s>: %s\n", fnamein, H5FOPENERROR);
- goto out;
- }
-
- /* get user block size and file space strategy/threshold */
- {
- hid_t fcpl_in; /* file creation property list ID for input file */
-
- if ((fcpl_in = H5Fget_create_plist(fidin)) < 0) {
- error_msg("failed to retrieve file creation property list\n");
- goto out;
- }
-
- if (H5Pget_userblock(fcpl_in, &ub_size) < 0) {
- error_msg("failed to retrieve userblock size\n");
- goto out;
- }
-
- if (H5Pclose(fcpl_in) < 0) {
- error_msg("failed to close property list\n");
- goto out;
- }
- }
-
- /* Check if we need to create a non-default file creation property list */
- if (options->latest || ub_size > 0) {
- /* Create file creation property list */
- if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) {
- error_msg("fail to create a file creation property list\n");
- goto out;
- }
-
- if (ub_size > 0) {
- if (H5Pset_userblock(fcpl, ub_size) < 0) {
- error_msg("failed to set non-default userblock size\n");
- goto out;
- }
- }
-
- if (options->latest) {
- unsigned i = 0, nindex = 0, mesg_type_flags[5], min_mesg_sizes[5];
-
- /* Adjust group creation parameters for root group */
- /* (So that it is created in "dense storage" form) */
- if (H5Pset_link_phase_change(fcpl, (unsigned) options->grp_compact,
- (unsigned) options->grp_indexed) < 0) {
- error_msg(
- "fail to adjust group creation parameters for root group\n");
- goto out;
- }
-
- for (i = 0; i < 5; i++) {
- if (options->msg_size[i] > 0) {
- switch (i) {
- case 0:
- mesg_type_flags[nindex] = H5O_SHMESG_SDSPACE_FLAG;
- break;
-
- case 1:
- mesg_type_flags[nindex] = H5O_SHMESG_DTYPE_FLAG;
- break;
-
- case 2:
- mesg_type_flags[nindex] = H5O_SHMESG_FILL_FLAG;
- break;
-
- case 3:
- mesg_type_flags[nindex] = H5O_SHMESG_PLINE_FLAG;
- break;
-
- case 4:
- mesg_type_flags[nindex] = H5O_SHMESG_ATTR_FLAG;
- break;
- default:
- break;
- } /* end switch */
- min_mesg_sizes[nindex] = (unsigned) options->msg_size[i];
-
- nindex++;
- } /* end if */
- } /* end for */
-
- if (nindex > 0) {
- if (H5Pset_shared_mesg_nindexes(fcpl, nindex) < 0) {
- error_msg(
- "fail to set the number of shared object header message indexes\n");
- goto out;
- }
-
- /* msg_size[0]=dataspace, 1=datatype, 2=file value, 3=filter pipleline, 4=attribute */
- for (i = 0; i < (nindex - 1); i++) {
- if (H5Pset_shared_mesg_index(fcpl, i, mesg_type_flags[i],
- min_mesg_sizes[i]) < 0) {
- error_msg(
- "fail to configure the specified shared object header message index\n");
- goto out;
- } /* end if */
- } /* end for */
- } /* if (nindex>0) */
-
- /* Create file access property list */
- if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) {
- error_msg("Could not create file access property list\n");
- goto out;
- } /* end if */
-
- if (H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) {
- error_msg(
- "Could not set property for using latest version of the format\n");
- goto out;
- } /* end if */
- } /* end if */
- } /* end if */
+int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options)
+{
+ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
+ hid_t fidin;
+ hid_t fidout = -1;
+ trav_table_t *travt = NULL;
+ hsize_t ub_size = 0; /* size of user block */
+ hid_t fcpl = H5P_DEFAULT; /* file creation property list ID */
+ hid_t fapl = H5P_DEFAULT; /* file access property list ID */
+
+ /*-------------------------------------------------------------------------
+ * open input file
+ *-------------------------------------------------------------------------
+ */
+ if ((fidin = h5tools_fopen(fnamein, H5F_ACC_RDONLY, H5P_DEFAULT, NULL, NULL, (size_t) 0)) < 0) {
+ error_msg("<%s>: %s\n", fnamein, H5FOPENERROR);
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+
+ /* get user block size and file space strategy/threshold */
+ {
+ hid_t fcpl_in; /* file creation property list ID for input file */
+
+ if ((fcpl_in = H5Fget_create_plist(fidin)) < 0) {
+ error_msg("failed to retrieve file creation property list\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+
+ if (H5Pget_userblock(fcpl_in, &ub_size) < 0) {
+ error_msg("failed to retrieve userblock size\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+
+ if (!options->fs_strategy) {
+ if (H5Pget_file_space(fcpl_in, &options->fs_strategy, NULL) < 0) {
+ error_msg("failed to retrieve file space strategy\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+
+ if (!options->fs_threshold) {
+ if (H5Pget_file_space(fcpl_in, NULL, &options->fs_threshold) < 0) {
+ error_msg("failed to retrieve file space threshold\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+
+ if (H5Pclose(fcpl_in) < 0) {
+ error_msg("failed to close property list\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+
+ /* Check if we need to create a non-default file creation property list */
+ if (options->latest || ub_size > 0) {
+ /* Create file creation property list */
+ if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) {
+ error_msg("fail to create a file creation property list\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+
+ if (ub_size > 0) {
+ if (H5Pset_userblock(fcpl, ub_size) < 0) {
+ error_msg("failed to set non-default userblock size\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+
+ if (options->latest) {
+ unsigned i = 0, nindex = 0, mesg_type_flags[5], min_mesg_sizes[5];
+
+ /* Adjust group creation parameters for root group */
+ /* (So that it is created in "dense storage" form) */
+ if (H5Pset_link_phase_change(fcpl, (unsigned) options->grp_compact,
+ (unsigned) options->grp_indexed) < 0) {
+ error_msg("fail to adjust group creation parameters for root group\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+
+ for (i = 0; i < 5; i++) {
+ if (options->msg_size[i] > 0) {
+ switch (i) {
+ case 0:
+ mesg_type_flags[nindex] = H5O_SHMESG_SDSPACE_FLAG;
+ break;
+
+ case 1:
+ mesg_type_flags[nindex] = H5O_SHMESG_DTYPE_FLAG;
+ break;
+
+ case 2:
+ mesg_type_flags[nindex] = H5O_SHMESG_FILL_FLAG;
+ break;
+
+ case 3:
+ mesg_type_flags[nindex] = H5O_SHMESG_PLINE_FLAG;
+ break;
+
+ case 4:
+ mesg_type_flags[nindex] = H5O_SHMESG_ATTR_FLAG;
+ break;
+
+ default:
+ break;
+ } /* end switch */
+ min_mesg_sizes[nindex] = (unsigned) options->msg_size[i];
+
+ nindex++;
+ } /* end if */
+ } /* end for */
+
+ if (nindex > 0) {
+ if (H5Pset_shared_mesg_nindexes(fcpl, nindex) < 0) {
+ error_msg("fail to set the number of shared object header message indexes\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+
+ /* msg_size[0]=dataspace, 1=datatype, 2=file value, 3=filter pipleline, 4=attribute */
+ for (i = 0; i < (nindex - 1); i++) {
+ if (H5Pset_shared_mesg_index(fcpl, i, mesg_type_flags[i], min_mesg_sizes[i]) < 0) {
+ error_msg("fail to configure the specified shared object header message index\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ } /* end if */
+ } /* end for */
+ } /* if (nindex>0) */
+
+ /* Create file access property list */
+ if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) {
+ error_msg("Could not create file access property list\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ } /* end if */
+
+ if (H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) {
+ error_msg("Could not set property for using latest version of the format\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ } /* end if */
+ } /* end if */
+ } /* end if */
#if defined (H5REPACK_DEBUG_USER_BLOCK)
- print_user_block(fnamein, fidin);
+print_user_block(fnamein, fidin);
#endif
- /*-------------------------------------------------------------------------
- * set the new user userblock options in the FCPL (before H5Fcreate )
- *-------------------------------------------------------------------------
- */
- if (options->ublock_size > 0) {
- /* either use the FCPL already created or create a new one */
- if (fcpl == H5P_DEFAULT) {
- /* create a file creation property list */
- if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) {
- error_msg("fail to create a file creation property list\n");
- goto out;
- }
- }
-
- /* set user block size */
- if (H5Pset_userblock(fcpl, options->ublock_size) < 0) {
- error_msg("failed to set userblock size\n");
- goto out;
- }
- }
-
- /*-------------------------------------------------------------------------
- * set alignment options
- *-------------------------------------------------------------------------
- */
- if (options->alignment > 0) {
- /* either use the FAPL already created or create a new one */
- if (fapl == H5P_DEFAULT) {
- /* create a file access property list */
- if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) {
- error_msg("Could not create file access property list\n");
- goto out;
- }
- }
-
- if (H5Pset_alignment(fapl, options->threshold, options->alignment) < 0) {
- error_msg("failed to set alignment\n");
- goto out;
- }
- }
-
- /*-------------------------------------------------------------------------
- * set metadata block size option
- *-------------------------------------------------------------------------
- */
- if (options->meta_block_size > 0) {
- /* either use the FAPL already created or create a new one */
- if (fapl == H5P_DEFAULT) {
- /* create a file access property list */
- if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) {
- error_msg("Could not create file access property list\n");
- goto out;
- }
- }
-
- if (H5Pset_meta_block_size(fapl, options->meta_block_size) < 0) {
- error_msg("failed to set metadata block size\n");
- goto out;
- }
- }
-
-
- /*-------------------------------------------------------------------------
- * create the output file
- *-------------------------------------------------------------------------
- */
- if (options->verbose)
- printf("Making file <%s>...\n", fnameout);
-
- if ((fidout = H5Fcreate(fnameout, H5F_ACC_TRUNC, fcpl, fapl)) < 0) {
- error_msg("<%s>: Could not create file\n", fnameout);
- goto out;
- }
-
- /*-------------------------------------------------------------------------
- * write a new user block if requested
- *-------------------------------------------------------------------------
- */
- if (options->ublock_size > 0) {
- if (copy_user_block(options->ublock_filename, fnameout,
- options->ublock_size) < 0) {
- error_msg("Could not copy user block. Exiting...\n");
- goto out;
-
- }
- }
-
- /*-------------------------------------------------------------------------
- * get list of objects
- *-------------------------------------------------------------------------
- */
-
- /* init table */
- trav_table_init(&travt);
-
- /* get the list of objects in the file */
- if (h5trav_gettable(fidin, travt) < 0)
- goto out;
-
- /*-------------------------------------------------------------------------
- * do the copy
- *-------------------------------------------------------------------------
- */
- if (do_copy_objects(fidin, fidout, travt, options) < 0) {
- error_msg("<%s>: Could not copy data to: %s\n", fnamein, fnameout);
- goto out;
- } /* end if */
-
- /*-------------------------------------------------------------------------
- * do the copy of referenced objects
- * and create hard links
- *-------------------------------------------------------------------------
- */
- if (do_copy_refobjs(fidin, fidout, travt, options) < 0) {
- printf("h5repack: <%s>: Could not copy data to: %s\n", fnamein,
- fnameout);
- goto out;
- }
-
- /*-------------------------------------------------------------------------
- * close
- *-------------------------------------------------------------------------
- */
-
- if (fapl > 0)
- H5Pclose(fapl);
-
- if (fcpl > 0)
- H5Pclose(fcpl);
-
- H5Fclose(fidin);
- H5Fclose(fidout);
-
- /* free table */
- trav_table_free(travt);
- travt = NULL;
-
- /*-------------------------------------------------------------------------
- * write only the input file user block if there is no user block file input
- *-------------------------------------------------------------------------
- */
-
- if (ub_size > 0 && options->ublock_size == 0) {
- if (copy_user_block(fnamein, fnameout, ub_size) < 0) {
- error_msg("Could not copy user block. Exiting...\n");
- goto out;
-
- }
- }
-
- return 0;
+ /*-------------------------------------------------------------------------
+ * set the new user userblock options in the FCPL (before H5Fcreate )
+ *-------------------------------------------------------------------------
+ */
+ if (options->ublock_size > 0) {
+ /* either use the FCPL already created or create a new one */
+ if (fcpl == H5P_DEFAULT) {
+ /* create a file creation property list */
+ if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) {
+ error_msg("fail to create a file creation property list\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+
+ /* set user block size */
+ if (H5Pset_userblock(fcpl, options->ublock_size) < 0) {
+ error_msg("failed to set userblock size\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+
+ /*-------------------------------------------------------------------------
+ * set alignment options
+ *-------------------------------------------------------------------------
+ */
+ if (options->alignment > 0) {
+ /* either use the FAPL already created or create a new one */
+ if (fapl == H5P_DEFAULT) {
+ /* create a file access property list */
+ if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) {
+ error_msg("Could not create file access property list\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+
+ if (H5Pset_alignment(fapl, options->threshold, options->alignment) < 0) {
+ error_msg("failed to set alignment\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+
+ /*-------------------------------------------------------------------------
+ * set metadata block size option
+ *-------------------------------------------------------------------------
+ */
+ if (options->meta_block_size > 0) {
+ /* either use the FAPL already created or create a new one */
+ if (fapl == H5P_DEFAULT) {
+ /* create a file access property list */
+ if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) {
+ error_msg("Could not create file access property list\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+
+ if (H5Pset_meta_block_size(fapl, options->meta_block_size) < 0) {
+ error_msg("failed to set metadata block size\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+
+ /*-------------------------------------------------------------------------
+ * set free-space strategy options
+ *-------------------------------------------------------------------------
+ */
+
+ /* either use the FCPL already created or create a new one */
+ if (fcpl == H5P_DEFAULT) {
+ /* create a file creation property list */
+ if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) {
+ error_msg("fail to create a file creation property list\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+
+ /* set file space strategy and free space threshold */
+ if (H5Pset_file_space(fcpl, options->fs_strategy, options->fs_threshold) < 0) {
+ error_msg("failed to set file space strategy & threshold \n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+
+ /*-------------------------------------------------------------------------
+ * create the output file
+ *-------------------------------------------------------------------------
+ */
+ if (options->verbose)
+ printf("Making file <%s>...\n", fnameout);
+
+ if ((fidout = H5Fcreate(fnameout, H5F_ACC_TRUNC, fcpl, fapl)) < 0) {
+ error_msg("<%s>: Could not create file\n", fnameout);
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+
+ /*-------------------------------------------------------------------------
+ * write a new user block if requested
+ *-------------------------------------------------------------------------
+ */
+ if (options->ublock_size > 0) {
+ if (copy_user_block(options->ublock_filename, fnameout, options->ublock_size) < 0) {
+ error_msg("Could not copy user block. Exiting...\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+
+ /*-------------------------------------------------------------------------
+ * get list of objects
+ *-------------------------------------------------------------------------
+ */
+
+ /* init table */
+ trav_table_init(&travt);
+
+ /* get the list of objects in the file */
+ if (h5trav_gettable(fidin, travt) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+
+ /*-------------------------------------------------------------------------
+ * do the copy
+ *-------------------------------------------------------------------------
+ */
+ if (do_copy_objects(fidin, fidout, travt, options) < 0) {
+ error_msg("<%s>: Could not copy data to: %s\n", fnamein, fnameout);
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ } /* end if */
+
+ /*-------------------------------------------------------------------------
+ * do the copy of referenced objects
+ * and create hard links
+ *-------------------------------------------------------------------------
+ */
+ if (do_copy_refobjs(fidin, fidout, travt, options) < 0) {
+ printf("h5repack: <%s>: Could not copy data to: %s\n", fnamein, fnameout);
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+
+ /*-------------------------------------------------------------------------
+ * close
+ *-------------------------------------------------------------------------
+ */
+
+ if (fapl > 0)
+ H5Pclose(fapl);
+
+ if (fcpl > 0)
+ H5Pclose(fcpl);
+
+ H5Fclose(fidin);
+ H5Fclose(fidout);
+
+ /* free table */
+ trav_table_free(travt);
+ travt = NULL;
+
+ /*-------------------------------------------------------------------------
+ * write only the input file user block if there is no user block file input
+ *-------------------------------------------------------------------------
+ */
+
+ if (ub_size > 0 && options->ublock_size == 0) {
+ if (copy_user_block(fnamein, fnameout, ub_size) < 0) {
+ error_msg("Could not copy user block. Exiting...\n");
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+
+ return 0;
+
+ /*-------------------------------------------------------------------------
+ * out
+ *-------------------------------------------------------------------------
+ */
- /*-------------------------------------------------------------------------
- * out
- *-------------------------------------------------------------------------
- */
-
-out:
- H5E_BEGIN_TRY
- {
- H5Pclose(fapl);
- H5Pclose(fcpl);
- H5Fclose(fidin);
- H5Fclose(fidout);
- }H5E_END_TRY;
- if (travt)
- trav_table_free(travt);
-
- return -1;
+done:
+ H5E_BEGIN_TRY {
+ H5Pclose(fapl);
+ H5Pclose(fcpl);
+ H5Fclose(fidin);
+ H5Fclose(fidout);
+ } H5E_END_TRY;
+ if (travt)
+ trav_table_free(travt);
+
+ return ret_value;
}
/*-------------------------------------------------------------------------
@@ -437,132 +462,126 @@ out:
*-----------------------------------------*/
int Get_hyperslab(hid_t dcpl_id, int rank_dset, hsize_t dims_dset[],
- size_t size_datum, hsize_t dims_hslab[], hsize_t * hslab_nbytes_p) {
- int status = 0;
- int k;
- H5D_layout_t dset_layout;
- int rank_chunk;
- hsize_t dims_chunk[H5S_MAX_RANK];
- hsize_t size_chunk = 1;
- hsize_t nchunk_fit; /* number of chunks that fits in hyperslab buffer (H5TOOLS_BUFSIZE) */
- hsize_t ndatum_fit; /* number of dataum that fits in hyperslab buffer (H5TOOLS_BUFSIZE) */
- hsize_t chunk_dims_map[H5S_MAX_RANK]; /* mapped chunk dimentions */
- hsize_t hs_dims_map[H5S_MAX_RANK]; /* mapped hyperslab dimentions */
- hsize_t hslab_nbytes; /* size of hyperslab in byte */
-
- /* init to set as size of a data element */
- hslab_nbytes = size_datum;
-
- /* get layout of dataset */
- dset_layout = H5Pget_layout(dcpl_id);
-
- /* if dataset is chunked */
- if (dset_layout == H5D_CHUNKED) {
- /* get chunk dims */
- rank_chunk = H5Pget_chunk(dcpl_id, rank_dset, dims_chunk);
- if (rank_chunk < 0) {
- status = -1;
- goto out;
- }
-
- for (k = rank_dset; k > 0; --k)
- size_chunk *= dims_chunk[k - 1];
-
- /* figure out how many chunks can fit in the hyperslab buffer */
- nchunk_fit = (H5TOOLS_BUFSIZE / size_datum) / size_chunk;
-
- /* 1. if a chunk fit in hyperslab buffer */
- if (nchunk_fit >= 1) {
- /* Calulate a hyperslab that contains as many chunks that can fit
- * in hyperslab buffer. Hyperslab will be increased starting from
- * the last dimention of the dataset (see h5dump's dims output).
- * The calculation boundary is dataset dims.
- * In the loop, used mapping from a datum to a chunk to figure out
- * chunk based hyperslab.
- */
- for (k = rank_dset; k > 0; --k) {
- /* map dataset dimentions with a chunk dims */
- chunk_dims_map[k - 1] = dims_dset[k - 1] / dims_chunk[k - 1];
-
- /* if reminder exist, increse by 1 to cover partial edge chunks */
- if (dims_dset[k - 1] % dims_chunk[k - 1] > 0)
- chunk_dims_map[k - 1]++;
-
- /* get mapped hyperslab dims */
- hs_dims_map[k - 1] = MIN (nchunk_fit, chunk_dims_map[k-1]);
-
- /* prepare next round */
- nchunk_fit = nchunk_fit / chunk_dims_map[k - 1];
- /* if a chunk is bigger than the rest of buffer */
- if (nchunk_fit == 0)
- nchunk_fit = 1;
-
- /* get hyperslab dimentions as unmapping to actual size */
- dims_hslab[k - 1] =
- MIN( (hs_dims_map[k-1] * dims_chunk[k-1]), dims_dset[k-1]);
-
- /* calculate total size for the hyperslab */
- hslab_nbytes *= dims_hslab[k - 1];
- }
- }
- /* 2. if a chunk is bigger than hyperslab buffer */
- else {
- /* Calulate a hyperslab that contains as many data elements that
- * can fit in hyperslab buffer. Hyperslab will be increased
- * starting from the last dimention of the chunk (see h5dump's dims
- * output).
- * The calculation boundary is a chunk dims.
- */
- for (k = rank_dset; k > 0; --k) {
- ndatum_fit = H5TOOLS_BUFSIZE / hslab_nbytes;
-
- /* if a datum is bigger than rest of buffer */
- if (ndatum_fit == 0)
- ndatum_fit = 1;
- /* get hyperslab dimentions within a chunk boundary */
- dims_hslab[k - 1] = MIN (dims_chunk[k-1], ndatum_fit);
-
- /* calculate total size for the hyperslab */
- hslab_nbytes *= dims_hslab[k - 1];
-
- if (hslab_nbytes <= 0) {
- status = -1;
- goto out;
- }
- }
- }
- }
- /* 3. if dataset is not chunked */
- else {
- /* Calulate a hyperslab that contains as many data elements that can
- * fit in hyperslab buffer. Hyperslab will be increased starting from
- * the last dimention of the dataset (see h5dump's dims output).
- * The calculation boundary is dataset dims.
- */
- for (k = rank_dset; k > 0; --k) {
- ndatum_fit = H5TOOLS_BUFSIZE / hslab_nbytes;
-
- /* if a datum is bigger than rest of buffer */
- if (ndatum_fit == 0)
- ndatum_fit = 1;
- /* get hyperslab dimentions within dataset boundary */
- dims_hslab[k - 1] = MIN(dims_dset[k - 1], ndatum_fit);
-
- /* calculate total size for the hyperslab */
- hslab_nbytes *= dims_hslab[k - 1];
-
- if (hslab_nbytes <= 0) {
- status = -1;
- goto out;
- }
- }
- }
-
- /* pass out the hyperslab size*/
- *hslab_nbytes_p = hslab_nbytes;
+ size_t size_datum, hsize_t dims_hslab[], hsize_t * hslab_nbytes_p)
+{
+ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
+ int k;
+ H5D_layout_t dset_layout;
+ int rank_chunk;
+ hsize_t dims_chunk[H5S_MAX_RANK];
+ hsize_t size_chunk = 1;
+ hsize_t nchunk_fit; /* number of chunks that fits in hyperslab buffer (H5TOOLS_BUFSIZE) */
+ hsize_t ndatum_fit; /* number of dataum that fits in hyperslab buffer (H5TOOLS_BUFSIZE) */
+ hsize_t chunk_dims_map[H5S_MAX_RANK]; /* mapped chunk dimentions */
+ hsize_t hs_dims_map[H5S_MAX_RANK]; /* mapped hyperslab dimentions */
+ hsize_t hslab_nbytes; /* size of hyperslab in byte */
+
+ /* init to set as size of a data element */
+ hslab_nbytes = size_datum;
+
+ /* get layout of dataset */
+ dset_layout = H5Pget_layout(dcpl_id);
+
+ /* if dataset is chunked */
+ if (dset_layout == H5D_CHUNKED) {
+ /* get chunk dims */
+ rank_chunk = H5Pget_chunk(dcpl_id, rank_dset, dims_chunk);
+ if (rank_chunk < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+
+ for (k = rank_dset; k > 0; --k)
+ size_chunk *= dims_chunk[k - 1];
+
+ /* figure out how many chunks can fit in the hyperslab buffer */
+ nchunk_fit = (H5TOOLS_BUFSIZE / size_datum) / size_chunk;
+
+ /* 1. if a chunk fit in hyperslab buffer */
+ if (nchunk_fit >= 1) {
+ /* Calulate a hyperslab that contains as many chunks that can fit
+ * in hyperslab buffer. Hyperslab will be increased starting from
+ * the last dimention of the dataset (see h5dump's dims output).
+ * The calculation boundary is dataset dims.
+ * In the loop, used mapping from a datum to a chunk to figure out
+ * chunk based hyperslab.
+ */
+ for (k = rank_dset; k > 0; --k) {
+ /* map dataset dimentions with a chunk dims */
+ chunk_dims_map[k - 1] = dims_dset[k - 1] / dims_chunk[k - 1];
+
+ /* if reminder exist, increse by 1 to cover partial edge chunks */
+ if (dims_dset[k - 1] % dims_chunk[k - 1] > 0)
+ chunk_dims_map[k - 1]++;
+
+ /* get mapped hyperslab dims */
+ hs_dims_map[k - 1] = MIN (nchunk_fit, chunk_dims_map[k-1]);
+
+ /* prepare next round */
+ nchunk_fit = nchunk_fit / chunk_dims_map[k - 1];
+ /* if a chunk is bigger than the rest of buffer */
+ if (nchunk_fit == 0)
+ nchunk_fit = 1;
+
+ /* get hyperslab dimentions as unmapping to actual size */
+ dims_hslab[k - 1] = MIN( (hs_dims_map[k-1] * dims_chunk[k-1]), dims_dset[k-1]);
+
+ /* calculate total size for the hyperslab */
+ hslab_nbytes *= dims_hslab[k - 1];
+ }
+ }
+ /* 2. if a chunk is bigger than hyperslab buffer */
+ else {
+ /* Calulate a hyperslab that contains as many data elements that
+ * can fit in hyperslab buffer. Hyperslab will be increased
+ * starting from the last dimention of the chunk (see h5dump's dims
+ * output).
+ * The calculation boundary is a chunk dims.
+ */
+ for (k = rank_dset; k > 0; --k) {
+ ndatum_fit = H5TOOLS_BUFSIZE / hslab_nbytes;
+
+ /* if a datum is bigger than rest of buffer */
+ if (ndatum_fit == 0)
+ ndatum_fit = 1;
+ /* get hyperslab dimentions within a chunk boundary */
+ dims_hslab[k - 1] = MIN (dims_chunk[k-1], ndatum_fit);
+
+ /* calculate total size for the hyperslab */
+ hslab_nbytes *= dims_hslab[k - 1];
+
+ if (hslab_nbytes <= 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+ }
+ /* 3. if dataset is not chunked */
+ else {
+ /* Calulate a hyperslab that contains as many data elements that can
+ * fit in hyperslab buffer. Hyperslab will be increased starting from
+ * the last dimention of the dataset (see h5dump's dims output).
+ * The calculation boundary is dataset dims.
+ */
+ for (k = rank_dset; k > 0; --k) {
+ ndatum_fit = H5TOOLS_BUFSIZE / hslab_nbytes;
+
+ /* if a datum is bigger than rest of buffer */
+ if (ndatum_fit == 0)
+ ndatum_fit = 1;
+ /* get hyperslab dimentions within dataset boundary */
+ dims_hslab[k - 1] = MIN(dims_dset[k - 1], ndatum_fit);
+
+ /* calculate total size for the hyperslab */
+ hslab_nbytes *= dims_hslab[k - 1];
+
+ if (hslab_nbytes <= 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ }
+ }
+
+ /* pass out the hyperslab size*/
+ *hslab_nbytes_p = hslab_nbytes;
-out:
- return status;
+done:
+ return ret_value;
}
/*-------------------------------------------------------------------------
@@ -662,716 +681,639 @@ out:
int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt,
pack_opt_t *options) /* repack options */
{
- hid_t grp_in = -1; /* group ID */
- hid_t grp_out = -1; /* group ID */
- hid_t dset_in = -1; /* read dataset ID */
- hid_t dset_out = -1; /* write dataset ID */
- hid_t gcpl_in = -1; /* group creation property list */
- hid_t gcpl_out = -1; /* group creation property list */
- hid_t type_in = -1; /* named type ID */
- hid_t type_out = -1; /* named type ID */
- hid_t dcpl_in = -1; /* dataset creation property list ID */
- hid_t dcpl_out = -1; /* dataset creation property list ID */
- hid_t f_space_id = -1; /* file space ID */
- hid_t ftype_id = -1; /* file type ID */
- hid_t wtype_id = -1; /* read/write type ID */
- named_dt_t *named_dt_head = NULL; /* Pointer to the stack of named datatypes copied */
- size_t msize; /* size of type */
- hsize_t nelmts; /* number of elements in dataset */
- H5D_space_status_t space_status; /* determines whether space has been allocated for the dataset */
- int rank; /* rank of dataset */
- hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */
- hsize_t dsize_in; /* input dataset size before filter */
- hsize_t dsize_out; /* output dataset size after filter */
- int apply_s; /* flag for apply filter to small dataset sizes */
- int apply_f; /* flag for apply filter to return error on H5Dcreate */
- void *buf = NULL; /* buffer for raw data */
- void *hslab_buf = NULL; /* hyperslab buffer for raw data */
- int has_filter; /* current object has a filter */
- int req_filter; /* there was a request for a filter */
- int req_obj_layout = 0; /* request layout to current object */
- unsigned crt_order_flags; /* group creation order flag */
- unsigned i;
- unsigned u;
- int is_ref = 0;
- htri_t is_named;
- hbool_t limit_maxdims;
- hsize_t size_dset;
-
- /*-------------------------------------------------------------------------
- * copy the suppplied object list
- *-------------------------------------------------------------------------
- */
-
- if (options->verbose) {
- printf("-----------------------------------------\n");
- printf(" Type Filter (Compression) Name\n");
- printf("-----------------------------------------\n");
- }
-
- for (i = 0; i < travt->nobjs; i++) {
- /* init variables per obj */
- buf = NULL;
- limit_maxdims = FALSE;
-
- switch (travt->objs[i].type) {
-
- case H5TRAV_TYPE_UNKNOWN:
- HDassert(0);
- break;
- /*-------------------------------------------------------------------------
- * H5TRAV_TYPE_GROUP
- *-------------------------------------------------------------------------
- */
- case H5TRAV_TYPE_GROUP:
-
- if (options->verbose) {
- printf(FORMAT_OBJ, "group", travt->objs[i].name);
- }
-
- /* open input group */
- if ((grp_in = H5Gopen2(fidin, travt->objs[i].name, H5P_DEFAULT))
- < 0)
- goto error;
-
- /* get input group creation property list */
- if ((gcpl_in = H5Gget_create_plist(grp_in)) < 0)
- goto error;
-
- /* query and set the group creation properties */
- if (H5Pget_link_creation_order(gcpl_in, &crt_order_flags) < 0)
- goto error;
-
- /* set up group creation property list */
- if ((gcpl_out = H5Pcreate(H5P_GROUP_CREATE)) < 0)
- goto error;
-
- if (H5Pset_link_creation_order(gcpl_out, crt_order_flags) < 0)
- goto error;
-
- /*-------------------------------------------------------------------------
- * the root is a special case, we get an ID for the root group
- * and copy its attributes using that ID
- *-------------------------------------------------------------------------
- */
- if (HDstrcmp(travt->objs[i].name, "/") == 0) {
- if ((grp_out = H5Gopen2(fidout, "/", H5P_DEFAULT)) < 0)
- goto error;
- }
- else {
-
- if (options->grp_compact > 0 || options->grp_indexed > 0) {
- if (H5Pset_link_phase_change(gcpl_out,
- (unsigned) options->grp_compact,
- (unsigned) options->grp_indexed) < 0)
- goto error;
- }
-
- if ((grp_out = H5Gcreate2(fidout, travt->objs[i].name,
- H5P_DEFAULT, gcpl_out, H5P_DEFAULT)) < 0)
- goto error;
-
- }
-
- /*-------------------------------------------------------------------------
- * copy attrs
- *-------------------------------------------------------------------------
- */
- if (copy_attr(grp_in, grp_out, &named_dt_head, travt, options) < 0)
- goto error;
-
- if (H5Pclose(gcpl_out) < 0)
- goto error;
- if (H5Pclose(gcpl_in) < 0)
- goto error;
- if (H5Gclose(grp_out) < 0)
- goto error;
- if (H5Gclose(grp_in) < 0)
- goto error;
-
- break;
-
- /*-------------------------------------------------------------------------
- * H5TRAV_TYPE_DATASET
- *-------------------------------------------------------------------------
- */
- case H5TRAV_TYPE_DATASET:
-
- has_filter = 0;
- req_filter = 0;
-
- /* check if global filters were requested */
- if (options->n_filter_g)
- req_filter = 1;
-
- /* check if filters were requested for individual objects */
- for (u = 0; u < options->op_tbl->nelems; u++) {
-
- if (HDstrcmp(travt->objs[i].name, options->op_tbl->objs[u].path) == 0) {
- if (options->op_tbl->objs[u].filter->filtn > 0) {
- req_filter = 1;
- }
- }
- }
-
- /* check if layout change requested individual object */
- if (options->layout_g != H5D_LAYOUT_ERROR) {
- pack_info_t *pckinfo;
- /* any dataset is specified */
- if (options->op_tbl->nelems > 0) {
- /* check if object exist */
- pckinfo = options_get_object(travt->objs[i].name,
- options->op_tbl);
- if (pckinfo) {
- req_obj_layout = 1;
- }
- }
- }
-
- /* early detection of references */
- if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT))
- < 0)
- goto error;
- if ((ftype_id = H5Dget_type(dset_in)) < 0)
- goto error;
- if (H5T_REFERENCE == H5Tget_class(ftype_id))
- is_ref = 1;
-
- /* Check if the datatype is committed */
- if ((is_named = H5Tcommitted(ftype_id)) < 0)
- goto error;
- if (is_named)
- if ((wtype_id = copy_named_datatype(ftype_id, fidout,
- &named_dt_head, travt, options)) < 0)
- goto error;
-
- if (H5Tclose(ftype_id) < 0)
- goto error;
- if (H5Dclose(dset_in) < 0)
- goto error;
-
- /*-------------------------------------------------------------------------
- * check if we should use H5Ocopy or not
- * if there is a request for filters/layout, we read/write the object
- * otherwise we do a copy using H5Ocopy
- *-------------------------------------------------------------------------
- */
- if (options->op_tbl->nelems || options->all_filter == 1
- || options->all_layout == 1 || is_ref || is_named) {
-
- int j;
-
- if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
- if ((f_space_id = H5Dget_space(dset_in)) < 0)
- goto error;
- if ((ftype_id = H5Dget_type(dset_in)) < 0)
- goto error;
- if ((dcpl_in = H5Dget_create_plist(dset_in)) < 0)
- goto error;
- if ((dcpl_out = H5Pcopy(dcpl_in)) < 0)
- goto error;
- if ((rank = H5Sget_simple_extent_ndims(f_space_id)) < 0)
- goto error;
- HDmemset(dims, 0, sizeof dims);
- if (H5Sget_simple_extent_dims(f_space_id, dims, NULL) < 0)
- goto error;
-
- if (H5Dget_space_status(dset_in, &space_status) < 0)
- goto error;
-
- nelmts = 1;
- for (j = 0; j < rank; j++)
- nelmts *= dims[j];
-
- /* wtype_id will have already been set if using a named dtype */
- if (!is_named) {
- if (options->use_native == 1)
- wtype_id = h5tools_get_native_type(ftype_id);
- else
- wtype_id = H5Tcopy(ftype_id);
- } /* end if */
-
- if ((msize = H5Tget_size(wtype_id)) == 0)
- goto error;
-
- /* size of current dset */
- size_dset = nelmts * msize;
-
- /*-------------------------------------------------------------------------
- * check if the dataset creation property list has filters that
- * are not registered in the current configuration
- * 1) the external filters GZIP and SZIP might not be available
- * 2) the internal filters might be turned off
- *-------------------------------------------------------------------------
- */
- if (h5tools_canreadf((travt->objs[i].name), dcpl_in) == 1) {
- apply_s = 1;
- apply_f = 1;
-
- /*-------------------------------------------------------------------------
- * references are a special case
- * we cannot just copy the buffers, but instead we recreate the reference
- * in a second traversal of the output file
- *-------------------------------------------------------------------------
- */
- if (H5T_REFERENCE != H5Tget_class(wtype_id)) {
- /* get the storage size of the input dataset */
- dsize_in = H5Dget_storage_size(dset_in);
-
- /* check for small size datasets (less than 1k) except
- * changing to COMPACT. For the reference, COMPACT is limited
- * by size 64K by library.
- */
- if (options->layout_g != H5D_COMPACT) {
- if (size_dset < options->min_comp)
- apply_s = 0;
- }
-
- /* apply the filter */
- if (apply_s) {
- if (apply_filters(travt->objs[i].name, rank, dims,
- msize, dcpl_out, options, &has_filter) < 0)
- goto error;
- }
-
- /* only if layout change requested for entire file or
- * individual obj */
- if (options->all_layout > 0 || req_obj_layout == 1)
- /*-------------------------------------------------
- * Unset the unlimited max dims if convert to other
- * than chunk layouts, because unlimited max dims
- * only can be applied to chunk layout.
- * Also perform only for targeted dataset
- * Also check for size limit to convert to compact
- *-------------------------------------------------*/
- if (options->layout_g != H5D_CHUNKED) {
- /* any dataset is specified */
- if (options->op_tbl->nelems > 0) {
- /* if current obj match specified obj */
- if (options_get_object(travt->objs[i].name,
- options->op_tbl))
- limit_maxdims = TRUE;
- }
- else { /* no dataset is specified */
- limit_maxdims = TRUE;
- }
-
- /* if convert to COMPACT */
- if (options->layout_g == H5D_COMPACT) {
- /* should be smaller than 64K */
- if (size_dset > MAX_COMPACT_DSIZE)
- limit_maxdims = FALSE;
- }
-
- /* unset unlimited max dims */
- if (limit_maxdims)
- H5Sset_extent_simple(f_space_id, rank, dims,
- NULL);
- }
-
- /*-------------------------------------------------------------------------
- * create the output dataset;
- * disable error checking in case the dataset cannot be created with the
- * modified dcpl; in that case use the original instead
- *-------------------------------------------------------------------------
- */
- H5E_BEGIN_TRY
- {
- dset_out = H5Dcreate2(fidout,
- travt->objs[i].name, wtype_id,
- f_space_id, H5P_DEFAULT, dcpl_out,
- H5P_DEFAULT);
- }H5E_END_TRY;
-
- if (dset_out == FAIL) {
- if (options->verbose)
- printf(
- " warning: could not create dataset <%s>. Applying original settings\n",
- travt->objs[i].name);
-
- if ((dset_out = H5Dcreate2(fidout,
- travt->objs[i].name, wtype_id, f_space_id,
- H5P_DEFAULT, dcpl_in, H5P_DEFAULT)) < 0)
- goto error;
- apply_f = 0;
- }
-
- /*-------------------------------------------------------------------------
- * read/write
- *-------------------------------------------------------------------------
- */
- if (nelmts > 0 && space_status != H5D_SPACE_STATUS_NOT_ALLOCATED) {
- size_t need = (size_t)(nelmts * msize); /* bytes needed */
-
- /* have to read the whole dataset if there is only one element in the dataset */
- if (need < H5TOOLS_MALLOCSIZE)
- buf = HDmalloc(need);
-
- if (buf != NULL) {
- /* read/write: use the macro to check error, e.g. memory allocation error inside the library. */
- CHECK_H5DRW_ERROR(H5Dread, dset_in, wtype_id,
- H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
- CHECK_H5DRW_ERROR(H5Dwrite, dset_out, wtype_id,
- H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
-
- /* Check if we have VL data in the dataset's
- * datatype that must be reclaimed */
- if (TRUE == H5Tdetect_class(wtype_id, H5T_VLEN))
- if (H5Dvlen_reclaim(wtype_id, f_space_id,
- H5P_DEFAULT, buf) < 0)
- goto error;
- }
- else { /* possibly not enough memory, read/write by hyperslabs */
- size_t p_type_nbytes = msize; /*size of memory type */
- hsize_t p_nelmts = nelmts; /*total elements */
- hsize_t elmtno; /*counter */
- int carry; /*counter carry value */
- unsigned int vl_data = 0; /*contains VL datatypes */
-
- /* hyperslab info */
- hsize_t hslab_dims[H5S_MAX_RANK]; /*hyperslab dims */
- hsize_t hslab_nbytes; /*bytes per hyperslab */
- hsize_t hslab_nelmts; /*elements per hyperslab*/
- hid_t hslab_space; /*hyperslab data space */
-
- /* hyperslab selection info */
- hsize_t hs_sel_offset[H5S_MAX_RANK];/* selection offset */
- hsize_t hs_sel_count[H5S_MAX_RANK]; /* selection count */
- hsize_t hs_select_nelmts; /* selected elements */
- hsize_t zero[8]; /*vector of zeros */
- int k;
- H5D_layout_t dset_layout;
- hid_t dcpl_tmp = -1; /* dataset creation property list ID */
-
- /* check if we have VL data in the dataset's datatype */
- if (H5Tdetect_class(wtype_id, H5T_VLEN) == TRUE)
- vl_data = TRUE;
-
- /* check first if writing dataset is chunked,
- * if so use its chunk layout for better performance. */
- dset_layout = H5Pget_layout(dcpl_out);
- if (dset_layout == H5D_CHUNKED)
- dcpl_tmp = dcpl_out; /* writing dataset */
- else { /* if reading dataset is chunked */
- dset_layout = H5Pget_layout(dcpl_in);
- if (dset_layout == H5D_CHUNKED)
- dcpl_tmp = dcpl_in; /* reading dataset */
- }
-
- /* get hyperslab dims and size in byte */
- if (Get_hyperslab(dcpl_tmp, rank, dims,
- p_type_nbytes, hslab_dims,
- &hslab_nbytes) < 0)
- goto error;
-
- hslab_buf = HDmalloc((size_t)hslab_nbytes);
-
- hslab_nelmts = hslab_nbytes / p_type_nbytes;
- hslab_space = H5Screate_simple(1, &hslab_nelmts,
- NULL);
-
- /* the hyperslab selection loop */
- HDmemset(hs_sel_offset, 0,
- sizeof hs_sel_offset);
- HDmemset(zero, 0, sizeof zero);
-
- for (elmtno = 0; elmtno < p_nelmts; elmtno +=
- hs_select_nelmts) {
- if (rank > 0) {
- /* calculate the hyperslab selections. The selection would be same as the hyperslab except for remaining edge portion of the dataset which is smaller then the hyperslab.
- */
- for (k = 0, hs_select_nelmts = 1;
- k < rank; k++) {
- /* MIN() is used to get the remaining edge portion if exist.
- * "dims[k] - hs_sel_offset[k]" is remaining edge portion that is smaller then the hyperslab.*/
- hs_sel_count[k] =
- MIN(dims[k] - hs_sel_offset[k], hslab_dims[k]);
- hs_select_nelmts *= hs_sel_count[k];
- }
-
- if (H5Sselect_hyperslab(f_space_id,
- H5S_SELECT_SET, hs_sel_offset,
- NULL, hs_sel_count, NULL) < 0)
- goto error;
- if (H5Sselect_hyperslab(hslab_space,
- H5S_SELECT_SET, zero, NULL,
- &hs_select_nelmts, NULL) < 0)
- goto error;
- }
- else {
- H5Sselect_all(f_space_id);
- H5Sselect_all(hslab_space);
- hs_select_nelmts = 1;
- } /* rank */
-
- /* read/write: use the macro to check error, e.g. memory allocation error inside the library. */
- CHECK_H5DRW_ERROR(H5Dread, dset_in,
- wtype_id, hslab_space, f_space_id,
- H5P_DEFAULT, hslab_buf);
- CHECK_H5DRW_ERROR(H5Dwrite, dset_out,
- wtype_id, hslab_space, f_space_id,
- H5P_DEFAULT, hslab_buf);
-
- /* reclaim any VL memory, if necessary */
- if (vl_data)
- H5Dvlen_reclaim(wtype_id, hslab_space,
- H5P_DEFAULT, hslab_buf);
-
- /* calculate the next hyperslab offset */
- for (k = rank, carry = 1; k > 0 && carry;
- --k) {
- hs_sel_offset[k - 1] += hs_sel_count[k
- - 1];
- /* if reached the end of a dim */
- if (hs_sel_offset[k - 1] == dims[k - 1])
- hs_sel_offset[k - 1] = 0;
- else
- carry = 0;
- } /* k */
- } /* elmtno */
-
- H5Sclose(hslab_space);
- /* free */
- if (hslab_buf != NULL) {
- HDfree(hslab_buf);
- hslab_buf = NULL;
- }
- } /* hyperslab read */
- } /* if (nelmts>0 && space_status==H5D_SPACE_STATUS_NOT_ALLOCATED) */
-
- /*-------------------------------------------------------------------------
- * amount of compression used
- *-------------------------------------------------------------------------
- */
- if (options->verbose) {
- double ratio = 0;
-
- /* only print the compression ration if there was a filter request */
- if (apply_s && apply_f && req_filter) {
- /* get the storage size of the output dataset */
- dsize_out = H5Dget_storage_size(dset_out);
-
- /* compression ratio = uncompressed size / compressed size */
- if (dsize_out != 0)
- ratio = (double) dsize_in
- / (double) dsize_out;
-
- print_dataset_info(dcpl_out,
- travt->objs[i].name, ratio, 1);
- }
- else
- print_dataset_info(dcpl_in, travt->objs[i].name,
- ratio, 0);
-
- /* print a message that the filter was not applied
- (in case there was a filter)
- */
- if (has_filter && apply_s == 0)
- printf(
- " <warning: filter not applied to %s. dataset smaller than %d bytes>\n",
- travt->objs[i].name,
- (int) options->min_comp);
-
- if (has_filter && apply_f == 0)
- printf(
- " <warning: could not apply the filter to %s>\n",
- travt->objs[i].name);
-
- } /* verbose */
-
- /*-------------------------------------------------------------------------
- * copy attrs
- *-------------------------------------------------------------------------
- */
- if (copy_attr(dset_in, dset_out, &named_dt_head, travt,
- options) < 0)
- goto error;
- /*close */
- if (H5Dclose(dset_out) < 0)
- goto error;
-
- }/*!H5T_REFERENCE*/
- }/*h5tools_canreadf*/
-
- /*-------------------------------------------------------------------------
- * close
- *-------------------------------------------------------------------------
- */
- if (H5Tclose(ftype_id) < 0)
- goto error;
- if (H5Tclose(wtype_id) < 0)
- goto error;
- if (H5Pclose(dcpl_in) < 0)
- goto error;
- if (H5Pclose(dcpl_out) < 0)
- goto error;
- if (H5Sclose(f_space_id) < 0)
- goto error;
- if (H5Dclose(dset_in) < 0)
- goto error;
-
- }
- /*-------------------------------------------------------------------------
- * we do not have request for filter/chunking use H5Ocopy instead
- *-------------------------------------------------------------------------
- */
- else {
- hid_t pid;
-
- /* create property to pass copy options */
- if ((pid = H5Pcreate(H5P_OBJECT_COPY)) < 0)
- goto error;
-
- /* set options for object copy */
- if (H5Pset_copy_object(pid, H5O_COPY_WITHOUT_ATTR_FLAG) < 0)
- goto error;
-
- /*-------------------------------------------------------------------------
- * do the copy
- *-------------------------------------------------------------------------
- */
-
- if (H5Ocopy(fidin, /* Source file or group identifier */
- travt->objs[i].name, /* Name of the source object to be copied */
- fidout, /* Destination file or group identifier */
- travt->objs[i].name, /* Name of the destination object */
- pid, /* Properties which apply to the copy */
- H5P_DEFAULT) < 0) /* Properties which apply to the new hard link */
- goto error;
-
- /* close property */
- if (H5Pclose(pid) < 0)
- goto error;
-
- /*-------------------------------------------------------------------------
- * copy attrs manually
- *-------------------------------------------------------------------------
- */
- if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT))
- < 0)
- goto error;
- if ((dset_out = H5Dopen2(fidout, travt->objs[i].name,
- H5P_DEFAULT)) < 0)
- goto error;
- if (copy_attr(dset_in, dset_out, &named_dt_head, travt, options)
- < 0)
- goto error;
- if (H5Dclose(dset_in) < 0)
- goto error;
- if (H5Dclose(dset_out) < 0)
- goto error;
-
- if (options->verbose)
- printf(FORMAT_OBJ, "dset", travt->objs[i].name);
-
- } /* end do we have request for filter/chunking */
-
- break;
-
- /*-------------------------------------------------------------------------
- * H5TRAV_TYPE_NAMED_DATATYPE
- *-------------------------------------------------------------------------
- */
- case H5TRAV_TYPE_NAMED_DATATYPE:
-
- if (options->verbose)
- printf(FORMAT_OBJ, "type", travt->objs[i].name);
-
- if ((type_in = H5Topen2(fidin, travt->objs[i].name, H5P_DEFAULT))
- < 0)
- goto error;
-
- /* Copy the datatype anonymously */
- if ((type_out = copy_named_datatype(type_in, fidout, &named_dt_head,
- travt, options)) < 0)
- goto error;
-
- /* Link in to group structure */
- if (H5Lcreate_hard(type_out, ".", fidout, travt->objs[i].name,
- H5P_DEFAULT, H5P_DEFAULT) < 0)
- goto error;
-
- /*-------------------------------------------------------------------------
- * copy attrs
- *-------------------------------------------------------------------------
- */
- if (copy_attr(type_in, type_out, &named_dt_head, travt, options)
- < 0)
- goto error;
-
- if (H5Tclose(type_in) < 0)
- goto error;
- if (H5Tclose(type_out) < 0)
- goto error;
-
- break;
-
- /*-------------------------------------------------------------------------
- * H5TRAV_TYPE_LINK
- * H5TRAV_TYPE_UDLINK
- *
- * Only handles external links; H5Lcopy will fail for other UD link types
- * since we don't have creation or copy callbacks for them.
- *-------------------------------------------------------------------------
- */
-
- case H5TRAV_TYPE_LINK:
- case H5TRAV_TYPE_UDLINK: {
-
- if (options->verbose)
- printf(FORMAT_OBJ, "link", travt->objs[i].name);
-
- if (H5Lcopy(fidin, travt->objs[i].name, fidout, travt->objs[i].name,
- H5P_DEFAULT, H5P_DEFAULT) < 0)
- goto error;
-
- if (options->verbose)
- printf(FORMAT_OBJ, "link", travt->objs[i].name);
-
- }
- break;
-
- default:
- goto error;
- } /* switch */
-
- /* free */
- if (buf != NULL) {
- HDfree(buf);
- buf = NULL;
- }
-
- } /* i */
-
- /* Finalize (link) the stack of named datatypes (if any) */
- named_datatype_free(&named_dt_head, 0);
+ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
+ hid_t grp_in = -1; /* group ID */
+ hid_t grp_out = -1; /* group ID */
+ hid_t dset_in = -1; /* read dataset ID */
+ hid_t dset_out = -1; /* write dataset ID */
+ hid_t gcpl_in = -1; /* group creation property list */
+ hid_t gcpl_out = -1; /* group creation property list */
+ hid_t type_in = -1; /* named type ID */
+ hid_t type_out = -1; /* named type ID */
+ hid_t dcpl_in = -1; /* dataset creation property list ID */
+ hid_t dcpl_out = -1; /* dataset creation property list ID */
+ hid_t f_space_id = -1; /* file space ID */
+ hid_t ftype_id = -1; /* file type ID */
+ hid_t wtype_id = -1; /* read/write type ID */
+ named_dt_t *named_dt_head = NULL; /* Pointer to the stack of named datatypes copied */
+ size_t msize; /* size of type */
+ hsize_t nelmts; /* number of elements in dataset */
+ H5D_space_status_t space_status; /* determines whether space has been allocated for the dataset */
+ int rank; /* rank of dataset */
+ hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */
+ hsize_t dsize_in; /* input dataset size before filter */
+ hsize_t dsize_out; /* output dataset size after filter */
+ int apply_s; /* flag for apply filter to small dataset sizes */
+ int apply_f; /* flag for apply filter to return error on H5Dcreate */
+ void *buf = NULL; /* buffer for raw data */
+ void *hslab_buf = NULL; /* hyperslab buffer for raw data */
+ int has_filter; /* current object has a filter */
+ int req_filter; /* there was a request for a filter */
+ int req_obj_layout = 0; /* request layout to current object */
+ unsigned crt_order_flags; /* group creation order flag */
+ unsigned i;
+ unsigned u;
+ int is_ref = 0;
+ htri_t is_named;
+ hbool_t limit_maxdims;
+ hsize_t size_dset;
+
+ /*-------------------------------------------------------------------------
+ * copy the suppplied object list
+ *-------------------------------------------------------------------------
+ */
+
+ if (options->verbose) {
+ printf("-----------------------------------------\n");
+ printf(" Type Filter (Compression) Name\n");
+ printf("-----------------------------------------\n");
+ }
+
+ for (i = 0; i < travt->nobjs; i++) {
+ /* init variables per obj */
+ buf = NULL;
+ limit_maxdims = FALSE;
+
+ switch (travt->objs[i].type) {
+ case H5TRAV_TYPE_UNKNOWN:
+ HDassert(0);
+ break;
+
+ /*-------------------------------------------------------------------------
+ * H5TRAV_TYPE_GROUP
+ *-------------------------------------------------------------------------
+ */
+ case H5TRAV_TYPE_GROUP:
+ if (options->verbose)
+ printf(FORMAT_OBJ, "group", travt->objs[i].name);
+
+ /* open input group */
+ if ((grp_in = H5Gopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed");
+
+ /* get input group creation property list */
+ if ((gcpl_in = H5Gget_create_plist(grp_in)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gget_create_plist failed");
+
+ /* query and set the group creation properties */
+ if (H5Pget_link_creation_order(gcpl_in, &crt_order_flags) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pget_link_creation_order failed");
+
+ /* set up group creation property list */
+ if ((gcpl_out = H5Pcreate(H5P_GROUP_CREATE)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pcreate failed");
+
+ if (H5Pset_link_creation_order(gcpl_out, crt_order_flags) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pset_link_creation_order failed");
+
+ /*-------------------------------------------------------------------------
+ * the root is a special case, we get an ID for the root group
+ * and copy its attributes using that ID
+ *-------------------------------------------------------------------------
+ */
+ if (HDstrcmp(travt->objs[i].name, "/") == 0) {
+ if ((grp_out = H5Gopen2(fidout, "/", H5P_DEFAULT)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed");
+ }
+ else {
+ if (options->grp_compact > 0 || options->grp_indexed > 0)
+ if (H5Pset_link_phase_change(gcpl_out, (unsigned) options->grp_compact, (unsigned) options->grp_indexed) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pset_link_phase_change failed");
+
+ if ((grp_out = H5Gcreate2(fidout, travt->objs[i].name, H5P_DEFAULT, gcpl_out, H5P_DEFAULT)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gcreate2 failed");
+ }
+
+ /*-------------------------------------------------------------------------
+ * copy attrs
+ *-------------------------------------------------------------------------
+ */
+ if (copy_attr(grp_in, grp_out, &named_dt_head, travt, options) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_attr failed");
+
+ if (H5Pclose(gcpl_out) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ if (H5Pclose(gcpl_in) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ if (H5Gclose(grp_out) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed");
+ if (H5Gclose(grp_in) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed");
+
+ break;
+
+ /*-------------------------------------------------------------------------
+ * H5TRAV_TYPE_DATASET
+ *-------------------------------------------------------------------------
+ */
+ case H5TRAV_TYPE_DATASET:
+ has_filter = 0;
+ req_filter = 0;
+
+ /* check if global filters were requested */
+ if (options->n_filter_g)
+ req_filter = 1;
+
+ /* check if filters were requested for individual objects */
+ for (u = 0; u < options->op_tbl->nelems; u++)
+ if (HDstrcmp(travt->objs[i].name, options->op_tbl->objs[u].path) == 0)
+ if (options->op_tbl->objs[u].filter->filtn > 0)
+ req_filter = 1;
+
+ /* check if layout change requested individual object */
+ if (options->layout_g != H5D_LAYOUT_ERROR) {
+ pack_info_t *pckinfo;
+
+ /* any dataset is specified */
+ if (options->op_tbl->nelems > 0) {
+ /* check if object exist */
+ pckinfo = options_get_object(travt->objs[i].name, options->op_tbl);
+ if (pckinfo)
+ req_obj_layout = 1;
+ }
+ }
+
+ /* early detection of references */
+ if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed");
+ if ((ftype_id = H5Dget_type(dset_in)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_type failed");
+ if (H5T_REFERENCE == H5Tget_class(ftype_id))
+ is_ref = 1;
+
+ /* Check if the datatype is committed */
+ if ((is_named = H5Tcommitted(ftype_id)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tcommitted failed");
+ if (is_named)
+ if ((wtype_id = copy_named_datatype(ftype_id, fidout, &named_dt_head, travt, options)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_named_datatype failed");
+
+ if (H5Tclose(ftype_id) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
+ if (H5Dclose(dset_in) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed");
+
+ /*-------------------------------------------------------------------------
+ * check if we should use H5Ocopy or not
+ * if there is a request for filters/layout, we read/write the object
+ * otherwise we do a copy using H5Ocopy
+ *-------------------------------------------------------------------------
+ */
+ if (options->op_tbl->nelems || options->all_filter == 1
+ || options->all_layout == 1 || is_ref || is_named) {
+
+ int j;
+
+ if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed");
+ if ((f_space_id = H5Dget_space(dset_in)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed");
+ if ((ftype_id = H5Dget_type(dset_in)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_type failed");
+ if ((dcpl_in = H5Dget_create_plist(dset_in)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed");
+ if ((dcpl_out = H5Pcopy(dcpl_in)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pcopy failed");
+ if ((rank = H5Sget_simple_extent_ndims(f_space_id)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed");
+ HDmemset(dims, 0, sizeof dims);
+ if (H5Sget_simple_extent_dims(f_space_id, dims, NULL) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed");
+ if (H5Dget_space_status(dset_in, &space_status) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space_status failed");
+
+ nelmts = 1;
+ for (j = 0; j < rank; j++)
+ nelmts *= dims[j];
+
+ /* wtype_id will have already been set if using a named dtype */
+ if (!is_named) {
+ if (options->use_native == 1)
+ wtype_id = h5tools_get_native_type(ftype_id);
+ else
+ wtype_id = H5Tcopy(ftype_id);
+ } /* end if */
+
+ if ((msize = H5Tget_size(wtype_id)) == 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed");
+
+ /* size of current dset */
+ size_dset = nelmts * msize;
+
+ /*-------------------------------------------------------------------------
+ * check if the dataset creation property list has filters that
+ * are not registered in the current configuration
+ * 1) the external filters GZIP and SZIP might not be available
+ * 2) the internal filters might be turned off
+ *-------------------------------------------------------------------------
+ */
+ if (h5tools_canreadf((travt->objs[i].name), dcpl_in) == 1) {
+ apply_s = 1;
+ apply_f = 1;
+
+ /*-------------------------------------------------------------------------
+ * references are a special case
+ * we cannot just copy the buffers, but instead we recreate the reference
+ * in a second traversal of the output file
+ *-------------------------------------------------------------------------
+ */
+ if (H5T_REFERENCE != H5Tget_class(wtype_id)) {
+ /* get the storage size of the input dataset */
+ dsize_in = H5Dget_storage_size(dset_in);
+
+ /* check for small size datasets (less than 1k) except
+ * changing to COMPACT. For the reference, COMPACT is limited
+ * by size 64K by library.
+ */
+ if (options->layout_g != H5D_COMPACT)
+ if (size_dset < options->min_comp)
+ apply_s = 0;
+
+ /* apply the filter */
+ if (apply_s)
+ if (apply_filters(travt->objs[i].name, rank, dims, msize, dcpl_out, options, &has_filter) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "apply_filters failed");
+
+ /* only if layout change requested for entire file or
+ * individual obj */
+ if (options->all_layout > 0 || req_obj_layout == 1)
+ /*-------------------------------------------------
+ * Unset the unlimited max dims if convert to other
+ * than chunk layouts, because unlimited max dims
+ * only can be applied to chunk layout.
+ * Also perform only for targeted dataset
+ * Also check for size limit to convert to compact
+ *-------------------------------------------------*/
+ if (options->layout_g != H5D_CHUNKED) {
+ /* any dataset is specified */
+ if (options->op_tbl->nelems > 0) {
+ /* if current obj match specified obj */
+ if (options_get_object(travt->objs[i].name, options->op_tbl))
+ limit_maxdims = TRUE;
+ }
+ else /* no dataset is specified */
+ limit_maxdims = TRUE;
+
+ /* if convert to COMPACT */
+ if (options->layout_g == H5D_COMPACT)
+ /* should be smaller than 64K */
+ if (size_dset > MAX_COMPACT_DSIZE)
+ limit_maxdims = FALSE;
+
+ /* unset unlimited max dims */
+ if (limit_maxdims)
+ H5Sset_extent_simple(f_space_id, rank, dims, NULL);
+ }
+
+ /*-------------------------------------------------------------------------
+ * create the output dataset;
+ * disable error checking in case the dataset cannot be created with the
+ * modified dcpl; in that case use the original instead
+ *-------------------------------------------------------------------------
+ */
+ dset_out = H5Dcreate2(fidout, travt->objs[i].name, wtype_id, f_space_id, H5P_DEFAULT, dcpl_out, H5P_DEFAULT);
+ if (dset_out == FAIL) {
+ H5Epush2(H5tools_ERR_STACK_g, __FILE__, FUNC, __LINE__, H5tools_ERR_CLS_g, H5E_tools_g, H5E_tools_min_id_g, "H5Dcreate2 failed");
+ if (options->verbose)
+ printf(" warning: could not create dataset <%s>. Applying original settings\n", travt->objs[i].name);
+
+ if ((dset_out = H5Dcreate2(fidout, travt->objs[i].name, wtype_id, f_space_id, H5P_DEFAULT, dcpl_in, H5P_DEFAULT)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dcreate2 failed");
+ apply_f = 0;
+ }
+
+ /*-------------------------------------------------------------------------
+ * read/write
+ *-------------------------------------------------------------------------
+ */
+ if (nelmts > 0 && space_status != H5D_SPACE_STATUS_NOT_ALLOCATED) {
+ size_t need = (size_t)(nelmts * msize); /* bytes needed */
+
+ /* have to read the whole dataset if there is only one element in the dataset */
+ if (need < H5TOOLS_MALLOCSIZE)
+ buf = HDmalloc(need);
+
+ if (buf != NULL) {
+ /* read/write: use the macro to check error, e.g. memory allocation error inside the library. */
+ CHECK_H5DRW_ERROR(H5Dread, FAIL, dset_in, wtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
+ CHECK_H5DRW_ERROR(H5Dwrite, FAIL, dset_out, wtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
+
+ /* Check if we have VL data in the dataset's
+ * datatype that must be reclaimed */
+ if (TRUE == H5Tdetect_class(wtype_id, H5T_VLEN))
+ if (H5Dvlen_reclaim(wtype_id, f_space_id, H5P_DEFAULT, buf) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dvlen_reclaim failed");
+ }
+ else { /* possibly not enough memory, read/write by hyperslabs */
+ size_t p_type_nbytes = msize; /*size of memory type */
+ hsize_t p_nelmts = nelmts; /*total elements */
+ hsize_t elmtno; /*counter */
+ int carry; /*counter carry value */
+ unsigned int vl_data = 0; /*contains VL datatypes */
+
+ /* hyperslab info */
+ hsize_t hslab_dims[H5S_MAX_RANK]; /*hyperslab dims */
+ hsize_t hslab_nbytes; /*bytes per hyperslab */
+ hsize_t hslab_nelmts; /*elements per hyperslab*/
+ hid_t hslab_space; /*hyperslab data space */
+
+ /* hyperslab selection info */
+ hsize_t hs_sel_offset[H5S_MAX_RANK];/* selection offset */
+ hsize_t hs_sel_count[H5S_MAX_RANK]; /* selection count */
+ hsize_t hs_select_nelmts; /* selected elements */
+ hsize_t zero[8]; /*vector of zeros */
+ int k;
+ H5D_layout_t dset_layout;
+ hid_t dcpl_tmp = -1; /* dataset creation property list ID */
+
+ /* check if we have VL data in the dataset's datatype */
+ if (H5Tdetect_class(wtype_id, H5T_VLEN) == TRUE)
+ vl_data = TRUE;
+
+ /* check first if writing dataset is chunked,
+ * if so use its chunk layout for better performance. */
+ dset_layout = H5Pget_layout(dcpl_out);
+ if (dset_layout == H5D_CHUNKED)
+ dcpl_tmp = dcpl_out; /* writing dataset */
+ else { /* if reading dataset is chunked */
+ dset_layout = H5Pget_layout(dcpl_in);
+ if (dset_layout == H5D_CHUNKED)
+ dcpl_tmp = dcpl_in; /* reading dataset */
+ }
+
+ /* get hyperslab dims and size in byte */
+ if (Get_hyperslab(dcpl_tmp, rank, dims, p_type_nbytes, hslab_dims, &hslab_nbytes) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Get_hyperslab failed");
+
+ hslab_buf = HDmalloc((size_t)hslab_nbytes);
+
+ hslab_nelmts = hslab_nbytes / p_type_nbytes;
+ hslab_space = H5Screate_simple(1, &hslab_nelmts, NULL);
+
+ /* the hyperslab selection loop */
+ HDmemset(hs_sel_offset, 0, sizeof hs_sel_offset);
+ HDmemset(zero, 0, sizeof zero);
+
+ for (elmtno = 0; elmtno < p_nelmts; elmtno += hs_select_nelmts) {
+ if (rank > 0) {
+ /* calculate the hyperslab selections.
+ * The selection would be same as the hyperslab
+ * except for remaining edge portion of the dataset
+ * which is smaller then the hyperslab.
+ */
+ for (k = 0, hs_select_nelmts = 1; k < rank; k++) {
+ /* MIN() is used to get the remaining edge portion if exist.
+ * "dims[k] - hs_sel_offset[k]" is remaining edge portion that is smaller then the hyperslab.*/
+ hs_sel_count[k] = MIN(dims[k] - hs_sel_offset[k], hslab_dims[k]);
+ hs_select_nelmts *= hs_sel_count[k];
+ }
+
+ if (H5Sselect_hyperslab(f_space_id, H5S_SELECT_SET, hs_sel_offset, NULL, hs_sel_count, NULL) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed");
+ if (H5Sselect_hyperslab(hslab_space, H5S_SELECT_SET, zero, NULL, &hs_select_nelmts, NULL) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed");
+ }
+ else {
+ H5Sselect_all(f_space_id);
+ H5Sselect_all(hslab_space);
+ hs_select_nelmts = 1;
+ } /* rank */
+
+ /* read/write: use the macro to check error, e.g. memory allocation error inside the library. */
+ CHECK_H5DRW_ERROR(H5Dread, FAIL, dset_in, wtype_id, hslab_space, f_space_id, H5P_DEFAULT, hslab_buf);
+ CHECK_H5DRW_ERROR(H5Dwrite, FAIL, dset_out, wtype_id, hslab_space, f_space_id, H5P_DEFAULT, hslab_buf);
+
+ /* reclaim any VL memory, if necessary */
+ if (vl_data)
+ H5Dvlen_reclaim(wtype_id, hslab_space, H5P_DEFAULT, hslab_buf);
+
+ /* calculate the next hyperslab offset */
+ for (k = rank, carry = 1; k > 0 && carry; --k) {
+ hs_sel_offset[k - 1] += hs_sel_count[k - 1];
+ /* if reached the end of a dim */
+ if (hs_sel_offset[k - 1] == dims[k - 1])
+ hs_sel_offset[k - 1] = 0;
+ else
+ carry = 0;
+ } /* k */
+ } /* elmtno */
+
+ H5Sclose(hslab_space);
+ /* free */
+ if (hslab_buf != NULL) {
+ HDfree(hslab_buf);
+ hslab_buf = NULL;
+ }
+ } /* hyperslab read */
+ } /* if (nelmts>0 && space_status==H5D_SPACE_STATUS_NOT_ALLOCATED) */
+
+ /*-------------------------------------------------------------------------
+ * amount of compression used
+ *-------------------------------------------------------------------------
+ */
+ if (options->verbose) {
+ double ratio = 0;
+
+ /* only print the compression ration if there was a filter request */
+ if (apply_s && apply_f && req_filter) {
+ /* get the storage size of the output dataset */
+ dsize_out = H5Dget_storage_size(dset_out);
+
+ /* compression ratio = uncompressed size / compressed size */
+ if (dsize_out != 0)
+ ratio = (double) dsize_in / (double) dsize_out;
+ print_dataset_info(dcpl_out, travt->objs[i].name, ratio, 1);
+ }
+ else
+ print_dataset_info(dcpl_in, travt->objs[i].name, ratio, 0);
+
+ /* print a message that the filter was not applied
+ (in case there was a filter)
+ */
+ if (has_filter && apply_s == 0)
+ printf(" <warning: filter not applied to %s. dataset smaller than %d bytes>\n", travt->objs[i].name, (int) options->min_comp);
+
+ if (has_filter && apply_f == 0)
+ printf(" <warning: could not apply the filter to %s>\n", travt->objs[i].name);
+ } /* verbose */
+
+ /*-------------------------------------------------------------------------
+ * copy attrs
+ *-------------------------------------------------------------------------
+ */
+ if (copy_attr(dset_in, dset_out, &named_dt_head, travt, options) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_attr failed");
+
+ /*close */
+ if (H5Dclose(dset_out) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed");
+ }/*!H5T_REFERENCE*/
+ }/*h5tools_canreadf*/
+
+ /*-------------------------------------------------------------------------
+ * close
+ *-------------------------------------------------------------------------
+ */
+ if (H5Tclose(ftype_id) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
+ if (H5Tclose(wtype_id) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
+ if (H5Pclose(dcpl_in) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ if (H5Pclose(dcpl_out) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+ if (H5Sclose(f_space_id) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed");
+ if (H5Dclose(dset_in) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed");
+ }
+ /*-------------------------------------------------------------------------
+ * we do not have request for filter/chunking use H5Ocopy instead
+ *-------------------------------------------------------------------------
+ */
+ else {
+ hid_t pid;
+
+ /* create property to pass copy options */
+ if ((pid = H5Pcreate(H5P_OBJECT_COPY)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pcreate failed");
+
+ /* set options for object copy */
+ if (H5Pset_copy_object(pid, H5O_COPY_WITHOUT_ATTR_FLAG) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pset_copy_object failed");
+
+ /*-------------------------------------------------------------------------
+ * do the copy
+ *-------------------------------------------------------------------------
+ */
+
+ if (H5Ocopy(fidin, /* Source file or group identifier */
+ travt->objs[i].name, /* Name of the source object to be copied */
+ fidout, /* Destination file or group identifier */
+ travt->objs[i].name, /* Name of the destination object */
+ pid, /* Properties which apply to the copy */
+ H5P_DEFAULT) < 0) /* Properties which apply to the new hard link */
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Ocopy failed");
+
+ /* close property */
+ if (H5Pclose(pid) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
+
+ /*-------------------------------------------------------------------------
+ * copy attrs manually
+ *-------------------------------------------------------------------------
+ */
+ if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed");
+ if ((dset_out = H5Dopen2(fidout, travt->objs[i].name, H5P_DEFAULT)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed");
+ if (copy_attr(dset_in, dset_out, &named_dt_head, travt, options) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_attr failed");
+ if (H5Dclose(dset_in) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed");
+ if (H5Dclose(dset_out) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed");
+
+ if (options->verbose)
+ printf(FORMAT_OBJ, "dset", travt->objs[i].name);
+
+ } /* end do we have request for filter/chunking */
+ break;
+
+ /*-------------------------------------------------------------------------
+ * H5TRAV_TYPE_NAMED_DATATYPE
+ *-------------------------------------------------------------------------
+ */
+ case H5TRAV_TYPE_NAMED_DATATYPE:
+ if (options->verbose)
+ printf(FORMAT_OBJ, "type", travt->objs[i].name);
+
+ if ((type_in = H5Topen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Topen2 failed");
+
+ /* Copy the datatype anonymously */
+ if ((type_out = copy_named_datatype(type_in, fidout, &named_dt_head, travt, options)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_named_datatype failed");
+
+ /* Link in to group structure */
+ if (H5Lcreate_hard(type_out, ".", fidout, travt->objs[i].name, H5P_DEFAULT, H5P_DEFAULT) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Lcreate_hard failed");
+
+ /*-------------------------------------------------------------------------
+ * copy attrs
+ *-------------------------------------------------------------------------
+ */
+ if (copy_attr(type_in, type_out, &named_dt_head, travt, options) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_attr failed");
+
+ if (H5Tclose(type_in) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
+ if (H5Tclose(type_out) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
+
+ break;
+
+ /*-------------------------------------------------------------------------
+ * H5TRAV_TYPE_LINK
+ * H5TRAV_TYPE_UDLINK
+ *
+ * Only handles external links; H5Lcopy will fail for other UD link types
+ * since we don't have creation or copy callbacks for them.
+ *-------------------------------------------------------------------------
+ */
+ case H5TRAV_TYPE_LINK:
+ case H5TRAV_TYPE_UDLINK:
+ if (options->verbose)
+ printf(FORMAT_OBJ, "link", travt->objs[i].name);
+
+ if (H5Lcopy(fidin, travt->objs[i].name, fidout, travt->objs[i].name, H5P_DEFAULT, H5P_DEFAULT) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Lcopy failed");
+
+ if (options->verbose)
+ printf(FORMAT_OBJ, "link", travt->objs[i].name);
+ break;
+
+ default:
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Object type not found");
+ } /* switch */
+
+ /* free */
+ if (buf != NULL) {
+ HDfree(buf);
+ buf = NULL;
+ }
+ } /* i */
+
+ /* Finalize (link) the stack of named datatypes (if any) */
+ named_datatype_free(&named_dt_head, 0);
+
+ return ret_value;
- return 0;
-
-error:
- H5E_BEGIN_TRY
- {
- H5Gclose(grp_in);
- H5Gclose(grp_out);
- H5Pclose(dcpl_in);
- H5Pclose(gcpl_in);
- H5Pclose(gcpl_out);
- H5Sclose(f_space_id);
- H5Dclose(dset_in);
- H5Dclose(dset_out);
- H5Tclose(ftype_id);
- H5Tclose(wtype_id);
- H5Tclose(type_in);
- H5Tclose(type_out);
- named_datatype_free(&named_dt_head, 1);
- }H5E_END_TRY;
- /* free */
- if (buf != NULL)
- HDfree(buf);
- if (hslab_buf != NULL)
- HDfree(hslab_buf);
- return -1;
+done:
+ H5E_BEGIN_TRY
+ {
+ H5Gclose(grp_in);
+ H5Gclose(grp_out);
+ H5Pclose(dcpl_in);
+ H5Pclose(gcpl_in);
+ H5Pclose(gcpl_out);
+ H5Sclose(f_space_id);
+ H5Dclose(dset_in);
+ H5Dclose(dset_out);
+ H5Tclose(ftype_id);
+ H5Tclose(wtype_id);
+ H5Tclose(type_in);
+ H5Tclose(type_out);
+ named_datatype_free(&named_dt_head, 1);
+ }H5E_END_TRY;
+
+ /* free */
+ if (buf != NULL)
+ HDfree(buf);
+ if (hslab_buf != NULL)
+ HDfree(hslab_buf);
+
+ return ret_value;
}
/*-------------------------------------------------------------------------
@@ -1382,101 +1324,102 @@ error:
*-------------------------------------------------------------------------
*/
static void print_dataset_info(hid_t dcpl_id, char *objname, double ratio,
- int pr) {
- char strfilter[255];
+ int pr)
+{
+ char strfilter[255];
#if defined (PRINT_DEBUG )
- char temp[255];
+ char temp[255];
#endif
- int nfilters; /* number of filters */
- unsigned filt_flags; /* filter flags */
- H5Z_filter_t filtn; /* filter identification number */
- unsigned cd_values[20]; /* filter client data values */
- size_t cd_nelmts; /* filter client number of values */
- char f_objname[256]; /* filter objname */
- int i;
-
- HDstrcpy(strfilter, "\0");
+ int nfilters; /* number of filters */
+ unsigned filt_flags; /* filter flags */
+ H5Z_filter_t filtn; /* filter identification number */
+ unsigned cd_values[20]; /* filter client data values */
+ size_t cd_nelmts; /* filter client number of values */
+ char f_objname[256]; /* filter objname */
+ int i;
- /* get information about input filters */
- if ((nfilters = H5Pget_nfilters(dcpl_id)) < 0)
- return;
+ HDstrcpy(strfilter, "\0");
- for (i = 0; i < nfilters; i++) {
- cd_nelmts = NELMTS(cd_values);
+ /* get information about input filters */
+ if ((nfilters = H5Pget_nfilters(dcpl_id)) < 0)
+ return;
- filtn = H5Pget_filter2(dcpl_id, (unsigned) i, &filt_flags, &cd_nelmts,
- cd_values, sizeof(f_objname), f_objname, NULL);
+ for (i = 0; i < nfilters; i++) {
+ cd_nelmts = NELMTS(cd_values);
- switch (filtn) {
+ filtn = H5Pget_filter2(dcpl_id, (unsigned) i, &filt_flags, &cd_nelmts,
+ cd_values, sizeof(f_objname), f_objname, NULL);
- case H5Z_FILTER_NONE:
- HDstrcat(strfilter, "NONE ");
- break;
+ switch (filtn) {
+ case H5Z_FILTER_NONE:
+ HDstrcat(strfilter, "NONE ");
+ break;
- case H5Z_FILTER_DEFLATE:
- HDstrcat(strfilter, "GZIP ");
+ case H5Z_FILTER_DEFLATE:
+ HDstrcat(strfilter, "GZIP ");
#if defined (PRINT_DEBUG)
- {
- unsigned level=cd_values[0];
- sprintf(temp,"(%d)",level);
- HDstrcat(strfilter,temp);
- }
+ {
+ unsigned level = cd_values[0];
+
+ sprintf(temp,"(%d)", level);
+ HDstrcat(strfilter, temp);
+ }
#endif
- break;
+ break;
- case H5Z_FILTER_SZIP:
- HDstrcat(strfilter, "SZIP ");
+ case H5Z_FILTER_SZIP:
+ HDstrcat(strfilter, "SZIP ");
#if defined (PRINT_DEBUG)
- {
- unsigned options_mask=cd_values[0]; /* from dcpl, not filt*/
- unsigned ppb=cd_values[1];
- sprintf(temp,"(%d,",ppb);
- HDstrcat(strfilter,temp);
- if (options_mask & H5_SZIP_EC_OPTION_MASK)
- HDstrcpy(temp,"EC) ");
- else if (options_mask & H5_SZIP_NN_OPTION_MASK)
- HDstrcpy(temp,"NN) ");
- }
- HDstrcat(strfilter,temp);
-
+ {
+ unsigned options_mask = cd_values[0]; /* from dcpl, not filt*/
+ unsigned ppb = cd_values[1];
+
+ sprintf(temp,"(%d,", ppb);
+ HDstrcat(strfilter, temp);
+ if (options_mask & H5_SZIP_EC_OPTION_MASK)
+ HDstrcpy(temp, "EC) ");
+ else if (options_mask & H5_SZIP_NN_OPTION_MASK)
+ HDstrcpy(temp, "NN) ");
+ }
+ HDstrcat(strfilter, temp);
#endif
-
- break;
-
- case H5Z_FILTER_SHUFFLE:
- HDstrcat(strfilter, "SHUF ");
- break;
-
- case H5Z_FILTER_FLETCHER32:
- HDstrcat(strfilter, "FLET ");
- break;
-
- case H5Z_FILTER_NBIT:
- HDstrcat(strfilter, "NBIT ");
- break;
-
- case H5Z_FILTER_SCALEOFFSET:
- HDstrcat(strfilter, "SCALEOFFSET ");
- break;
-
- default:
- HDstrcat(strfilter, "UD ");
- break;
- } /* switch */
- }/*i*/
-
- if (!pr)
- printf(FORMAT_OBJ, "dset", objname);
- else {
- char str[255], temp[28];
- HDstrcpy(str, "dset ");
- HDstrcat(str, strfilter);
- sprintf(temp, " (%.3f:1)", ratio);
- HDstrcat(str, temp);
- printf(FORMAT_OBJ, str, objname);
- }
+ break;
+
+ case H5Z_FILTER_SHUFFLE:
+ HDstrcat(strfilter, "SHUF ");
+ break;
+
+ case H5Z_FILTER_FLETCHER32:
+ HDstrcat(strfilter, "FLET ");
+ break;
+
+ case H5Z_FILTER_NBIT:
+ HDstrcat(strfilter, "NBIT ");
+ break;
+
+ case H5Z_FILTER_SCALEOFFSET:
+ HDstrcat(strfilter, "SCALEOFFSET ");
+ break;
+
+ default:
+ HDstrcat(strfilter, "UD ");
+ break;
+ } /* switch */
+ }/*i*/
+
+ if (!pr)
+ printf(FORMAT_OBJ, "dset", objname);
+ else {
+ char str[255], temp[28];
+
+ HDstrcpy(str, "dset ");
+ HDstrcat(str, strfilter);
+ sprintf(temp, " (%.3f:1)", ratio);
+ HDstrcat(str, temp);
+ printf(FORMAT_OBJ, str, objname);
+ }
}
/*-------------------------------------------------------------------------
@@ -1493,73 +1436,66 @@ static void print_dataset_info(hid_t dcpl_id, char *objname, double ratio,
*-------------------------------------------------------------------------
*/
static int copy_user_block(const char *infile, const char *outfile,
- hsize_t size) {
- int infid = -1, outfid = -1; /* File descriptors */
- int status = 0; /* Return value */
-
- /* User block must be any power of 2 equal to 512 or greater (512, 1024, 2048, etc.) */
- HDassert(size > 0);
-
- /* Open files */
- if ((infid = HDopen(infile, O_RDONLY, 0)) < 0) {
- status = -1;
- goto done;
- }
- if ((outfid = HDopen(outfile, O_WRONLY, 0644)) < 0) {
- status = -1;
- goto done;
- }
-
- /* Copy the userblock from the input file to the output file */
- while (size > 0) {
- ssize_t nread, nbytes; /* # of bytes transfered, etc. */
- char rbuf[USERBLOCK_XFER_SIZE]; /* Buffer for reading */
- const char *wbuf; /* Pointer into buffer, for writing */
-
- /* Read buffer from source file */
- if (size > USERBLOCK_XFER_SIZE)
- nread = HDread(infid, rbuf, (size_t)USERBLOCK_XFER_SIZE);
- else
- nread = HDread(infid, rbuf, (size_t)size);
- if (nread < 0) {
- status = -1;
- goto done;
- } /* end if */
-
- /* Write buffer to destination file */
- /* (compensating for interrupted writes & checking for errors, etc.) */
- nbytes = nread;
- wbuf = rbuf;
- while (nbytes > 0) {
- ssize_t nwritten; /* # of bytes written */
-
- do {
- nwritten = HDwrite(outfid, wbuf, (size_t)nbytes);
- } while (-1 == nwritten && EINTR == errno);
- if (-1 == nwritten) { /* error */
- status = -1;
- goto done;
- } /* end if */
- HDassert(nwritten > 0);
- HDassert(nwritten <= nbytes);
-
- /* Update # of bytes left & offset in buffer */
- nbytes -= nwritten;
- wbuf += nwritten;
- HDassert(nbytes == 0 || wbuf < (rbuf + USERBLOCK_XFER_SIZE));
- } /* end while */
-
- /* Update size of userblock left to transfer */
- size = size - (hsize_t) nread;
- } /* end while */
+ hsize_t size)
+{
+ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
+ int infid = -1, outfid = -1; /* File descriptors */
+
+ /* User block must be any power of 2 equal to 512 or greater (512, 1024, 2048, etc.) */
+ HDassert(size > 0);
+
+ /* Open files */
+ if ((infid = HDopen(infile, O_RDONLY, 0)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDopen failed");
+ if ((outfid = HDopen(outfile, O_WRONLY, 0644)) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDopen failed");
+
+ /* Copy the userblock from the input file to the output file */
+ while (size > 0) {
+ ssize_t nread, nbytes; /* # of bytes transfered, etc. */
+ char rbuf[USERBLOCK_XFER_SIZE]; /* Buffer for reading */
+ const char *wbuf; /* Pointer into buffer, for writing */
+
+ /* Read buffer from source file */
+ if (size > USERBLOCK_XFER_SIZE)
+ nread = HDread(infid, rbuf, (size_t)USERBLOCK_XFER_SIZE);
+ else
+ nread = HDread(infid, rbuf, (size_t)size);
+ if (nread < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDread failed");
+
+ /* Write buffer to destination file */
+ /* (compensating for interrupted writes & checking for errors, etc.) */
+ nbytes = nread;
+ wbuf = rbuf;
+ while (nbytes > 0) {
+ ssize_t nwritten; /* # of bytes written */
+
+ do {
+ nwritten = HDwrite(outfid, wbuf, (size_t)nbytes);
+ } while (-1 == nwritten && EINTR == errno);
+ if (-1 == nwritten) /* error */
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDwrite failed");
+ HDassert(nwritten > 0);
+ HDassert(nwritten <= nbytes);
+
+ /* Update # of bytes left & offset in buffer */
+ nbytes -= nwritten;
+ wbuf += nwritten;
+ HDassert(nbytes == 0 || wbuf < (rbuf + USERBLOCK_XFER_SIZE));
+ } /* end while */
+
+ /* Update size of userblock left to transfer */
+ size = size - (hsize_t) nread;
+ } /* end while */
done:
- if (infid > 0)
- HDclose(infid);
- if (outfid > 0)
- HDclose(outfid);
+ if (infid > 0)
+ HDclose(infid);
+ if (outfid > 0)
+ HDclose(outfid);
- return status;
+ return ret_value;
}
/*-------------------------------------------------------------------------
@@ -1579,7 +1515,8 @@ done:
static
void print_user_block(const char *filename, hid_t fid)
{
- int fh; /* file handle */
+ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
+ int fh; /* file handle */
hsize_t ub_size; /* user block size */
hsize_t size; /* size read */
hid_t fcpl; /* file creation property list ID for HDF5 file */
@@ -1588,23 +1525,23 @@ void print_user_block(const char *filename, hid_t fid)
/* get user block size */
if(( fcpl = H5Fget_create_plist(fid)) < 0) {
error_msg("failed to retrieve file creation property list\n");
- goto done;
- }
+ HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Fget_create_plist failed");
+ }
if(H5Pget_userblock(fcpl, &ub_size) < 0) {
error_msg("failed to retrieve userblock size\n");
- goto done;
- }
+ HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pget_userblock failed");
+ }
if(H5Pclose(fcpl) < 0) {
error_msg("failed to close property list\n");
- goto done;
- }
+ HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed");
+ }
/* open file */
if((fh = HDopen(filename, O_RDONLY, 0)) < 0) {
- goto done;
- }
+ HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "HDopen failed");
+ }
size = ub_size;
@@ -1627,8 +1564,8 @@ void print_user_block(const char *filename, hid_t fid)
printf("\n");
if(nread < 0) {
- goto done;
- }
+ HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "nread < 0");
+ }
/* update size of userblock left to transfer */
size -= nread;
diff --git a/tools/h5repack/h5repack_filters.c b/tools/h5repack/h5repack_filters.c
index 56e08ef..e873a53 100644
--- a/tools/h5repack/h5repack_filters.c
+++ b/tools/h5repack/h5repack_filters.c
@@ -34,8 +34,8 @@
*
*-------------------------------------------------------------------------
*/
-static
-int aux_find_obj(const char* name, /* object name from traverse list */
+static int
+aux_find_obj(const char* name, /* object name from traverse list */
pack_opt_t *options, /* repack options */
pack_info_t *obj /*OUT*/) /* info about object to filter */
{
@@ -48,7 +48,7 @@ int aux_find_obj(const char* name, /* object name from traverse list */
if (HDstrcmp(options->op_tbl->objs[i].path,name)==0)
{
*obj = options->op_tbl->objs[i];
- return i;
+ return (int)i;
}
pdest = HDstrstr(name,options->op_tbl->objs[i].path);
@@ -58,7 +58,7 @@ int aux_find_obj(const char* name, /* object name from traverse list */
if( pdest != NULL && result==1 )
{
*obj = options->op_tbl->objs[i];
- return i;
+ return (int)i;
}
}/*i*/
@@ -76,8 +76,8 @@ int aux_find_obj(const char* name, /* object name from traverse list */
*
*-------------------------------------------------------------------------
*/
-static
-int aux_assign_obj(const char* name, /* object name from traverse list */
+static int
+aux_assign_obj(const char* name, /* object name from traverse list */
pack_opt_t *options, /* repack options */
pack_info_t *obj /*OUT*/) /* info about object to filter */
{
@@ -433,7 +433,7 @@ int apply_filters(const char* name, /* object name from traverse list */
int scale_factor;
scale_type = (H5Z_SO_scale_type_t)obj.filter[i].cd_values[0];
- scale_factor = obj.filter[i].cd_values[1];
+ scale_factor = (int)obj.filter[i].cd_values[1];
if(H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths)<0)
return -1;
diff --git a/tools/h5repack/h5repack_main.c b/tools/h5repack/h5repack_main.c
index f3fd469..7998ae8 100644
--- a/tools/h5repack/h5repack_main.c
+++ b/tools/h5repack/h5repack_main.c
@@ -33,28 +33,29 @@ const char *outfile = NULL;
* Command-line options: The user can specify short or long-named
* parameters.
*/
-static const char *s_opts = "hVvf:l:m:e:nLc:d:s:u:b:M:t:a:i:o:";
+static const char *s_opts = "hVvf:l:m:e:nLc:d:s:u:b:M:t:a:i:o:E";
static struct long_options l_opts[] = {
- { "help", no_arg, 'h' },
- { "version", no_arg, 'V' },
- { "verbose", no_arg, 'v' },
- { "filter", require_arg, 'f' },
- { "layout", require_arg, 'l' },
- { "minimum", require_arg, 'm' },
- { "file", require_arg, 'e' },
- { "native", no_arg, 'n' },
- { "latest", no_arg, 'L' },
- { "compact", require_arg, 'c' },
- { "indexed", require_arg, 'd' },
- { "ssize", require_arg, 's' },
- { "ublock", require_arg, 'u' },
- { "block", require_arg, 'b' },
- { "metadata_block_size", require_arg, 'M' },
- { "threshold", require_arg, 't' },
- { "alignment", require_arg, 'a' },
- { "infile", require_arg, 'i' }, /* -i for backward compability */
- { "outfile", require_arg, 'o' }, /* -o for backward compability */
- { NULL, 0, '\0' }
+ { "help", no_arg, 'h' },
+ { "version", no_arg, 'V' },
+ { "verbose", no_arg, 'v' },
+ { "filter", require_arg, 'f' },
+ { "layout", require_arg, 'l' },
+ { "minimum", require_arg, 'm' },
+ { "file", require_arg, 'e' },
+ { "native", no_arg, 'n' },
+ { "latest", no_arg, 'L' },
+ { "compact", require_arg, 'c' },
+ { "indexed", require_arg, 'd' },
+ { "ssize", require_arg, 's' },
+ { "ublock", require_arg, 'u' },
+ { "block", require_arg, 'b' },
+ { "metadata_block_size", require_arg, 'M' },
+ { "threshold", require_arg, 't' },
+ { "alignment", require_arg, 'a' },
+ { "infile", require_arg, 'i' }, /* -i for backward compability */
+ { "outfile", require_arg, 'o' }, /* -o for backward compability */
+ { "enable-error-stack", no_arg, 'E' },
+ { NULL, 0, '\0' }
};
/*-------------------------------------------------------------------------
@@ -67,113 +68,117 @@ static struct long_options l_opts[] = {
*-------------------------------------------------------------------------
*/
static void usage(const char *prog) {
- printf("usage: %s [OPTIONS] file1 file2\n", prog);
- printf(" file1 Input HDF5 File\n");
- printf(" file2 Output HDF5 File\n");
- printf(" OPTIONS\n");
- printf(" -h, --help Print a usage message and exit\n");
- printf(" -v, --verbose Verbose mode, print object information\n");
- printf(" -V, --version Print version number and exit\n");
- printf(" -n, --native Use a native HDF5 type when repacking\n");
- printf(" -L, --latest Use latest version of file format\n");
- printf(" -c L1, --compact=L1 Maximum number of links in header messages\n");
- printf(" -d L2, --indexed=L2 Minimum number of links in the indexed format\n");
- printf(" -s S[:F], --ssize=S[:F] Shared object header message minimum size\n");
- printf(" -m M, --minimum=M Do not apply the filter to datasets smaller than M\n");
- printf(" -e E, --file=E Name of file E with the -f and -l options\n");
- printf(" -u U, --ublock=U Name of file U with user block data to be added\n");
- printf(" -b B, --block=B Size of user block to be added\n");
- printf(" -M A, --metadata_block_size=A Metadata block size for H5Pset_meta_block_size\n");
- printf(" -t T, --threshold=T Threshold value for H5Pset_alignment\n");
- printf(" -a A, --alignment=A Alignment value for H5Pset_alignment\n");
- printf(" -f FILT, --filter=FILT Filter type\n");
- printf(" -l LAYT, --layout=LAYT Layout type\n");
- printf("\n");
- printf(" M - is an integer greater than 1, size of dataset in bytes (default is 0) \n");
- printf(" E - is a filename.\n");
- printf(" S - is an integer\n");
- printf(" U - is a filename.\n");
- printf(" T - is an integer\n");
- printf(" A - is an integer greater than zero\n");
- printf(" B - is the user block size, any value that is 512 or greater and is\n");
- printf(" a power of 2 (1024 default)\n");
- printf(" F - is the shared object header message type, any of <dspace|dtype|fill|\n");
- printf(" pline|attr>. If F is not specified, S applies to all messages\n");
- printf("\n");
- printf(" FILT - is a string with the format:\n");
- printf("\n");
- printf(" <list of objects>:<name of filter>=<filter parameters>\n");
- printf("\n");
- printf(" <list of objects> is a comma separated list of object names, meaning apply\n");
- printf(" compression only to those objects. If no names are specified, the filter\n");
- printf(" is applied to all objects\n");
- printf(" <name of filter> can be:\n");
- printf(" GZIP, to apply the HDF5 GZIP filter (GZIP compression)\n");
- printf(" SZIP, to apply the HDF5 SZIP filter (SZIP compression)\n");
- printf(" SHUF, to apply the HDF5 shuffle filter\n");
- printf(" FLET, to apply the HDF5 checksum filter\n");
- printf(" NBIT, to apply the HDF5 NBIT filter (NBIT compression)\n");
- printf(" SOFF, to apply the HDF5 Scale/Offset filter\n");
- printf(" UD, to apply a user defined filter\n");
- printf(" NONE, to remove all filters\n");
- printf(" <filter parameters> is optional filter parameter information\n");
- printf(" GZIP=<deflation level> from 1-9\n");
- printf(" SZIP=<pixels per block,coding> pixels per block is a even number in\n");
- printf(" 2-32 and coding method is either EC or NN\n");
- printf(" SHUF (no parameter)\n");
- printf(" FLET (no parameter)\n");
- printf(" NBIT (no parameter)\n");
- printf(" SOFF=<scale_factor,scale_type> scale_factor is an integer and scale_type\n");
- printf(" is either IN or DS\n");
- printf(" UD=<filter_number,cd_value_count,value_1[,value_2,...,value_N]>\n");
- printf(" required values for filter_number,cd_value_count,value_1\n");
- printf(" optional values for value_2 to value_N\n");
- printf(" NONE (no parameter)\n");
- printf("\n");
- printf(" LAYT - is a string with the format:\n");
- printf("\n");
- printf(" <list of objects>:<layout type>=<layout parameters>\n");
- printf("\n");
- printf(" <list of objects> is a comma separated list of object names, meaning that\n");
- printf(" layout information is supplied for those objects. If no names are\n");
- printf(" specified, the layout type is applied to all objects\n");
- printf(" <layout type> can be:\n");
- printf(" CHUNK, to apply chunking layout\n");
- printf(" COMPA, to apply compact layout\n");
- printf(" CONTI, to apply contiguous layout\n");
- printf(" <layout parameters> is optional layout information\n");
- printf(" CHUNK=DIM[xDIM...xDIM], the chunk size of each dimension\n");
- printf(" COMPA (no parameter)\n");
- printf(" CONTI (no parameter)\n");
- printf("\n");
- printf("Examples of use:\n");
- printf("\n");
- printf("1) h5repack -v -f GZIP=1 file1 file2\n");
- printf("\n");
- printf(" GZIP compression with level 1 to all objects\n");
- printf("\n");
- printf("2) h5repack -v -f dset1:SZIP=8,NN file1 file2\n");
- printf("\n");
- printf(" SZIP compression with 8 pixels per block and NN coding method to object dset1\n");
- printf("\n");
- printf("3) h5repack -v -l dset1,dset2:CHUNK=20x10 -f dset3,dset4,dset5:NONE file1 file2\n");
- printf("\n");
- printf(" Chunked layout, with a layout size of 20x10, to objects dset1 and dset2\n");
- printf(" and remove filters to objects dset3, dset4, dset5\n");
- printf("\n");
- printf("4) h5repack -L -c 10 -s 20:dtype file1 file2 \n");
- printf("\n");
- printf(" Using latest file format with maximum compact group size of 10 and\n");
- printf(" and minimum shared datatype size of 20\n");
- printf("\n");
- printf("5) h5repack -f SHUF -f GZIP=1 file1 file2 \n");
- printf("\n");
- printf(" Add both filters SHUF and GZIP in this order to all datasets\n");
- printf("\n");
- printf("6) h5repack -f UD=307,1,9 file1 file2 \n");
- printf("\n");
- printf(" Add bzip2 filter to all datasets\n");
- printf("\n");
+ FLUSHSTREAM(rawoutstream);
+ PRINTSTREAM(rawoutstream, "usage: %s [OPTIONS] file1 file2\n", prog);
+ PRINTVALSTREAM(rawoutstream, " file1 Input HDF5 File\n");
+ PRINTVALSTREAM(rawoutstream, " file2 Output HDF5 File\n");
+ PRINTVALSTREAM(rawoutstream, " OPTIONS\n");
+ PRINTVALSTREAM(rawoutstream, " -h, --help Print a usage message and exit\n");
+ PRINTVALSTREAM(rawoutstream, " -v, --verbose Verbose mode, print object information\n");
+ PRINTVALSTREAM(rawoutstream, " -V, --version Print version number and exit\n");
+ PRINTVALSTREAM(rawoutstream, " -n, --native Use a native HDF5 type when repacking\n");
+ PRINTVALSTREAM(rawoutstream, " -L, --latest Use latest version of file format\n");
+ PRINTVALSTREAM(rawoutstream, " -c L1, --compact=L1 Maximum number of links in header messages\n");
+ PRINTVALSTREAM(rawoutstream, " -d L2, --indexed=L2 Minimum number of links in the indexed format\n");
+ PRINTVALSTREAM(rawoutstream, " -s S[:F], --ssize=S[:F] Shared object header message minimum size\n");
+ PRINTVALSTREAM(rawoutstream, " -m M, --minimum=M Do not apply the filter to datasets smaller than M\n");
+ PRINTVALSTREAM(rawoutstream, " -e E, --file=E Name of file E with the -f and -l options\n");
+ PRINTVALSTREAM(rawoutstream, " -u U, --ublock=U Name of file U with user block data to be added\n");
+ PRINTVALSTREAM(rawoutstream, " -b B, --block=B Size of user block to be added\n");
+ PRINTVALSTREAM(rawoutstream, " -M A, --metadata_block_size=A Metadata block size for H5Pset_meta_block_size\n");
+ PRINTVALSTREAM(rawoutstream, " -t T, --threshold=T Threshold value for H5Pset_alignment\n");
+ PRINTVALSTREAM(rawoutstream, " -a A, --alignment=A Alignment value for H5Pset_alignment\n");
+ PRINTVALSTREAM(rawoutstream, " -f FILT, --filter=FILT Filter type\n");
+ PRINTVALSTREAM(rawoutstream, " -l LAYT, --layout=LAYT Layout type\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, " M - is an integer greater than 1, size of dataset in bytes (default is 0) \n");
+ PRINTVALSTREAM(rawoutstream, " E - is a filename.\n");
+ PRINTVALSTREAM(rawoutstream, " S - is an integer\n");
+ PRINTVALSTREAM(rawoutstream, " U - is a filename.\n");
+ PRINTVALSTREAM(rawoutstream, " T - is an integer\n");
+ PRINTVALSTREAM(rawoutstream, " A - is an integer greater than zero\n");
+ PRINTVALSTREAM(rawoutstream, " B - is the user block size, any value that is 512 or greater and is\n");
+ PRINTVALSTREAM(rawoutstream, " a power of 2 (1024 default)\n");
+ PRINTVALSTREAM(rawoutstream, " F - is the shared object header message type, any of <dspace|dtype|fill|\n");
+ PRINTVALSTREAM(rawoutstream, " pline|attr>. If F is not specified, S applies to all messages\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, " --enable-error-stack Prints messages from the HDF5 error stack as they\n");
+ PRINTVALSTREAM(rawoutstream, " occur.\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, " FILT - is a string with the format:\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, " <list of objects>:<name of filter>=<filter parameters>\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, " <list of objects> is a comma separated list of object names, meaning apply\n");
+ PRINTVALSTREAM(rawoutstream, " compression only to those objects. If no names are specified, the filter\n");
+ PRINTVALSTREAM(rawoutstream, " is applied to all objects\n");
+ PRINTVALSTREAM(rawoutstream, " <name of filter> can be:\n");
+ PRINTVALSTREAM(rawoutstream, " GZIP, to apply the HDF5 GZIP filter (GZIP compression)\n");
+ PRINTVALSTREAM(rawoutstream, " SZIP, to apply the HDF5 SZIP filter (SZIP compression)\n");
+ PRINTVALSTREAM(rawoutstream, " SHUF, to apply the HDF5 shuffle filter\n");
+ PRINTVALSTREAM(rawoutstream, " FLET, to apply the HDF5 checksum filter\n");
+ PRINTVALSTREAM(rawoutstream, " NBIT, to apply the HDF5 NBIT filter (NBIT compression)\n");
+ PRINTVALSTREAM(rawoutstream, " SOFF, to apply the HDF5 Scale/Offset filter\n");
+ PRINTVALSTREAM(rawoutstream, " UD, to apply a user defined filter\n");
+ PRINTVALSTREAM(rawoutstream, " NONE, to remove all filters\n");
+ PRINTVALSTREAM(rawoutstream, " <filter parameters> is optional filter parameter information\n");
+ PRINTVALSTREAM(rawoutstream, " GZIP=<deflation level> from 1-9\n");
+ PRINTVALSTREAM(rawoutstream, " SZIP=<pixels per block,coding> pixels per block is a even number in\n");
+ PRINTVALSTREAM(rawoutstream, " 2-32 and coding method is either EC or NN\n");
+ PRINTVALSTREAM(rawoutstream, " SHUF (no parameter)\n");
+ PRINTVALSTREAM(rawoutstream, " FLET (no parameter)\n");
+ PRINTVALSTREAM(rawoutstream, " NBIT (no parameter)\n");
+ PRINTVALSTREAM(rawoutstream, " SOFF=<scale_factor,scale_type> scale_factor is an integer and scale_type\n");
+ PRINTVALSTREAM(rawoutstream, " is either IN or DS\n");
+ PRINTVALSTREAM(rawoutstream, " UD=<filter_number,cd_value_count,value_1[,value_2,...,value_N]>\n");
+ PRINTVALSTREAM(rawoutstream, " required values for filter_number,cd_value_count,value_1\n");
+ PRINTVALSTREAM(rawoutstream, " optional values for value_2 to value_N\n");
+ PRINTVALSTREAM(rawoutstream, " NONE (no parameter)\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, " LAYT - is a string with the format:\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, " <list of objects>:<layout type>=<layout parameters>\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, " <list of objects> is a comma separated list of object names, meaning that\n");
+ PRINTVALSTREAM(rawoutstream, " layout information is supplied for those objects. If no names are\n");
+ PRINTVALSTREAM(rawoutstream, " specified, the layout type is applied to all objects\n");
+ PRINTVALSTREAM(rawoutstream, " <layout type> can be:\n");
+ PRINTVALSTREAM(rawoutstream, " CHUNK, to apply chunking layout\n");
+ PRINTVALSTREAM(rawoutstream, " COMPA, to apply compact layout\n");
+ PRINTVALSTREAM(rawoutstream, " CONTI, to apply contiguous layout\n");
+ PRINTVALSTREAM(rawoutstream, " <layout parameters> is optional layout information\n");
+ PRINTVALSTREAM(rawoutstream, " CHUNK=DIM[xDIM...xDIM], the chunk size of each dimension\n");
+ PRINTVALSTREAM(rawoutstream, " COMPA (no parameter)\n");
+ PRINTVALSTREAM(rawoutstream, " CONTI (no parameter)\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, "Examples of use:\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, "1) h5repack -v -f GZIP=1 file1 file2\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, " GZIP compression with level 1 to all objects\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, "2) h5repack -v -f dset1:SZIP=8,NN file1 file2\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, " SZIP compression with 8 pixels per block and NN coding method to object dset1\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, "3) h5repack -v -l dset1,dset2:CHUNK=20x10 -f dset3,dset4,dset5:NONE file1 file2\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, " Chunked layout, with a layout size of 20x10, to objects dset1 and dset2\n");
+ PRINTVALSTREAM(rawoutstream, " and remove filters to objects dset3, dset4, dset5\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, "4) h5repack -L -c 10 -s 20:dtype file1 file2 \n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, " Using latest file format with maximum compact group size of 10 and\n");
+ PRINTVALSTREAM(rawoutstream, " and minimum shared datatype size of 20\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, "5) h5repack -f SHUF -f GZIP=1 file1 file2 \n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, " Add both filters SHUF and GZIP in this order to all datasets\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, "6) h5repack -f UD=307,1,9 file1 file2 \n");
+ PRINTVALSTREAM(rawoutstream, "\n");
+ PRINTVALSTREAM(rawoutstream, " Add bzip2 filter to all datasets\n");
+ PRINTVALSTREAM(rawoutstream, "\n");
}
/*-------------------------------------------------------------------------
@@ -242,14 +247,24 @@ int read_info(const char *filename, pack_opt_t *options) {
i = 0;
c = '0';
while (c != ' ') {
- fscanf(fp, "%c", &c);
+ if(fscanf(fp, "%c", &c) < 0 && HDferror(fp)) {
+ error_msg("fscanf error\n");
+ h5tools_setstatus(EXIT_FAILURE);
+ ret_value = EXIT_FAILURE;
+ goto done;
+ } /* end if */
if (HDfeof(fp))
break;
}
c = '0';
/* go until end */
while (c != ' ') {
- fscanf(fp, "%c", &c);
+ if(fscanf(fp, "%c", &c) < 0 && HDferror(fp)) {
+ error_msg("fscanf error\n");
+ h5tools_setstatus(EXIT_FAILURE);
+ ret_value = EXIT_FAILURE;
+ goto done;
+ } /* end if */
comp_info[i] = c;
i++;
if (HDfeof(fp))
@@ -276,14 +291,24 @@ int read_info(const char *filename, pack_opt_t *options) {
i = 0;
c = '0';
while (c != ' ') {
- fscanf(fp, "%c", &c);
+ if(fscanf(fp, "%c", &c) < 0 && HDferror(fp)) {
+ error_msg("fscanf error\n");
+ h5tools_setstatus(EXIT_FAILURE);
+ ret_value = EXIT_FAILURE;
+ goto done;
+ } /* end if */
if (HDfeof(fp))
break;
}
c = '0';
/* go until end */
while (c != ' ') {
- fscanf(fp, "%c", &c);
+ if(fscanf(fp, "%c", &c) < 0 && HDferror(fp)) {
+ error_msg("fscanf error\n");
+ h5tools_setstatus(EXIT_FAILURE);
+ ret_value = EXIT_FAILURE;
+ goto done;
+ } /* end if */
comp_info[i] = c;
i++;
if (HDfeof(fp))
@@ -343,7 +368,7 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) {
has_i_o = 1;
break;
- /* -o for backward compability */
+ /* -o for backward compability */
case 'o':
outfile = opt_arg;
has_i_o = 1;
@@ -386,7 +411,7 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) {
break;
case 'm':
- options->min_comp = HDatoi( opt_arg );
+ options->min_comp = HDstrtoull(opt_arg , NULL, 0);
if ((int) options->min_comp <= 0) {
error_msg("invalid minimum compress size <%s>\n", opt_arg);
h5tools_setstatus(EXIT_FAILURE);
@@ -473,7 +498,7 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) {
break;
case 'a':
- options->alignment = HDatol( opt_arg );
+ options->alignment = HDstrtoull(opt_arg , NULL, 0);
if (options->alignment < 1) {
error_msg("invalid alignment size\n", opt_arg);
h5tools_setstatus(EXIT_FAILURE);
@@ -482,13 +507,17 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) {
}
break;
- default:
- break;
- } /* switch */
+ case 'E':
+ enable_error_stack = TRUE;
+ break;
+
+ default:
+ break;
+ } /* switch */
- } /* while */
+ } /* while */
- if (has_i_o == 0) {
+ if (has_i_o == 0) {
/* check for file names to be processed */
if (argc <= opt_ind || argv[opt_ind + 1] == NULL) {
error_msg("missing file names\n");
@@ -520,50 +549,67 @@ done:
*-------------------------------------------------------------------------
*/
int main(int argc, const char **argv) {
+ H5E_auto2_t func;
+ H5E_auto2_t tools_func;
+ void *edata;
+ void *tools_edata;
pack_opt_t options; /*the global options */
h5tools_setprogname(PROGRAMNAME);
h5tools_setstatus(EXIT_SUCCESS);
- /* Initialize h5tools lib */
- h5tools_init();
-
- /* update hyperslab buffer size from H5TOOLS_BUFSIZE env if exist */
- if (h5tools_getenv_update_hyperslab_bufsize() < 0) {
- h5tools_setstatus(EXIT_FAILURE);
- goto done;
- }
-
- /* initialize options */
- h5repack_init(&options, 0);
-
- if (parse_command_line(argc, argv, &options) < 0)
- goto done;
-
- /* get file names if they were not yet got */
- if (has_i_o == 0) {
-
- if (argv[opt_ind] != NULL && argv[opt_ind + 1] != NULL) {
- infile = argv[opt_ind];
- outfile = argv[opt_ind + 1];
-
- if ( HDstrcmp( infile, outfile ) == 0) {
- error_msg("file names cannot be the same\n");
- usage(h5tools_getprogname());
- h5tools_setstatus(EXIT_FAILURE);
- goto done;
- }
- }
- else {
- error_msg("file names missing\n");
- usage(h5tools_getprogname());
- h5tools_setstatus(EXIT_FAILURE);
- goto done;
- }
- }
-
- /* pack it */
+ /* Disable error reporting */
+ H5Eget_auto2(H5E_DEFAULT, &func, &edata);
+ H5Eset_auto2(H5E_DEFAULT, NULL, NULL);
+
+ /* Initialize h5tools lib */
+ h5tools_init();
+
+ /* Disable tools error reporting */
+ H5Eget_auto2(H5tools_ERR_STACK_g, &tools_func, &tools_edata);
+ H5Eset_auto2(H5tools_ERR_STACK_g, NULL, NULL);
+
+ /* update hyperslab buffer size from H5TOOLS_BUFSIZE env if exist */
+ if (h5tools_getenv_update_hyperslab_bufsize() < 0) {
+ h5tools_setstatus(EXIT_FAILURE);
+ goto done;
+ }
+
+ /* initialize options */
+ h5repack_init(&options, 0);
+
+ if (parse_command_line(argc, argv, &options) < 0)
+ goto done;
+
+ /* get file names if they were not yet got */
+ if (has_i_o == 0) {
+
+ if (argv[opt_ind] != NULL && argv[opt_ind + 1] != NULL) {
+ infile = argv[opt_ind];
+ outfile = argv[opt_ind + 1];
+
+ if ( HDstrcmp( infile, outfile ) == 0) {
+ error_msg("file names cannot be the same\n");
+ usage(h5tools_getprogname());
+ h5tools_setstatus(EXIT_FAILURE);
+ goto done;
+ }
+ }
+ else {
+ error_msg("file names missing\n");
+ usage(h5tools_getprogname());
+ h5tools_setstatus(EXIT_FAILURE);
+ goto done;
+ }
+ }
+
+ if (enable_error_stack) {
+ H5Eset_auto2(H5E_DEFAULT, func, edata);
+ H5Eset_auto2(H5tools_ERR_STACK_g, tools_func, tools_edata);
+ }
+
+ /* pack it */
h5tools_setstatus(h5repack(infile, outfile, &options));
done:
diff --git a/tools/h5repack/h5repack_plugin.sh.in b/tools/h5repack/h5repack_plugin.sh.in
index 7502397..a064db6 100644
--- a/tools/h5repack/h5repack_plugin.sh.in
+++ b/tools/h5repack/h5repack_plugin.sh.in
@@ -127,7 +127,7 @@ CLEAN_TESTFILES_AND_TESTDIR()
# skip rm if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
- SDIR=`$DIRNAME $tstfile`
+ SDIR=$SRC_H5REPACK_TESTFILES
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
diff --git a/tools/h5repack/h5repack_refs.c b/tools/h5repack/h5repack_refs.c
index 2b39249..f0f32c3 100644
--- a/tools/h5repack/h5repack_refs.c
+++ b/tools/h5repack/h5repack_refs.c
@@ -1,4 +1,3 @@
-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
@@ -50,6 +49,7 @@ int do_copy_refobjs(hid_t fidin,
trav_table_t *travt,
pack_opt_t *options) /* repack options */
{
+ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
hid_t grp_in = (-1); /* read group ID */
hid_t grp_out = (-1); /* write group ID */
hid_t dset_in = (-1); /* read dataset ID */
@@ -85,18 +85,18 @@ int do_copy_refobjs(hid_t fidin,
*-------------------------------------------------------------------------
*/
if((grp_out = H5Gopen2(fidout, travt->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed");
if((grp_in = H5Gopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed");
if(copy_refs_attr(grp_in, grp_out, options, travt, fidout) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_refs_attr failed");
if(H5Gclose(grp_out) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed");
if(H5Gclose(grp_in) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed");
/*-------------------------------------------------------------------------
* check for hard links
@@ -113,26 +113,26 @@ int do_copy_refobjs(hid_t fidin,
*/
case H5TRAV_TYPE_DATASET:
if((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed");
if((space_id = H5Dget_space(dset_in)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed");
if((ftype_id = H5Dget_type(dset_in)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_type failed");
if((dcpl_id = H5Dget_create_plist(dset_in)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed");
if((rank = H5Sget_simple_extent_ndims(space_id)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed");
if(H5Sget_simple_extent_dims(space_id, dims, NULL) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed");
nelmts = 1;
for(k = 0; k < rank; k++)
nelmts *= dims[k];
if((mtype_id = h5tools_get_native_type(ftype_id)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "h5tools_get_native_type failed");
if((msize = H5Tget_size(mtype_id)) == 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed");
/*-------------------------------------------------------------------------
* check if the dataset creation property list has filters that
@@ -168,19 +168,19 @@ int do_copy_refobjs(hid_t fidin,
buf = (hobj_ref_t *)HDmalloc((unsigned)(nelmts * msize));
if(buf==NULL) {
printf("cannot read into memory\n" );
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed");
} /* end if */
if(H5Dread(dset_in, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed");
refbuf = (hobj_ref_t*) HDcalloc((unsigned)nelmts, msize);
if(refbuf == NULL){
printf("cannot allocate memory\n" );
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed");
} /* end if */
for(u = 0; u < nelmts; u++) {
H5E_BEGIN_TRY {
- if((refobj_id = H5Rdereference(dset_in, H5R_OBJECT, &buf[u])) < 0)
+ if((refobj_id = H5Rdereference2(dset_in, H5P_DEFAULT, H5R_OBJECT, &buf[u])) < 0)
continue;
} H5E_END_TRY;
@@ -190,7 +190,7 @@ int do_copy_refobjs(hid_t fidin,
if((refname = MapIdToName(refobj_id, travt)) != NULL) {
/* create the reference, -1 parameter for objects */
if(H5Rcreate(&refbuf[u], fidout, refname, H5R_OBJECT, (hid_t)-1) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rcreate failed");
if(options->verbose)
{
printf(FORMAT_OBJ,"dset",travt->objs[i].name );
@@ -208,10 +208,10 @@ int do_copy_refobjs(hid_t fidin,
*-------------------------------------------------------------------------
*/
if((dset_out = H5Dcreate2(fidout, travt->objs[i].name, mtype_id, space_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dcreate2 failed");
if(nelmts)
if(H5Dwrite(dset_out, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, refbuf) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dwrite failed");
if(buf)
HDfree(buf);
@@ -222,7 +222,7 @@ int do_copy_refobjs(hid_t fidin,
* copy attrs
*----------------------------------------------------*/
if(copy_attr(dset_in, dset_out, &named_dt_head, travt, options) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_attr failed");
} /*H5T_STD_REF_OBJ*/
/*-------------------------------------------------------------------------
@@ -245,10 +245,10 @@ int do_copy_refobjs(hid_t fidin,
buf = (hdset_reg_ref_t *)HDmalloc((unsigned)(nelmts * msize));
if(buf == NULL) {
printf("cannot read into memory\n");
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed");
} /* end if */
if(H5Dread(dset_in, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed");
/*-------------------------------------------------------------------------
* create output
@@ -257,12 +257,12 @@ int do_copy_refobjs(hid_t fidin,
refbuf = (hdset_reg_ref_t *)HDcalloc(sizeof(hdset_reg_ref_t), (size_t)nelmts); /*init to zero */
if(refbuf == NULL) {
printf("cannot allocate memory\n");
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed");
} /* end if */
for(u = 0; u < nelmts; u++) {
H5E_BEGIN_TRY {
- if((refobj_id = H5Rdereference(dset_in, H5R_DATASET_REGION, &buf[u])) < 0)
+ if((refobj_id = H5Rdereference2(dset_in, H5P_DEFAULT, H5R_DATASET_REGION, &buf[u])) < 0)
continue;
} H5E_END_TRY;
@@ -273,18 +273,15 @@ int do_copy_refobjs(hid_t fidin,
hid_t region_id; /* region id of the referenced dataset */
if((region_id = H5Rget_region(dset_in, H5R_DATASET_REGION, &buf[u])) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rget_region failed");
/* create the reference, we need the space_id */
if(H5Rcreate(&refbuf[u], fidout, refname, H5R_DATASET_REGION, region_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rcreate failed");
if(H5Sclose(region_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed");
if(options->verbose)
{
-
-
-
printf(FORMAT_OBJ,"dset",travt->objs[i].name );
printf("object <%s> region reference created to <%s>\n",
travt->objs[i].name,
@@ -300,10 +297,10 @@ int do_copy_refobjs(hid_t fidin,
*-------------------------------------------------------------------------
*/
if((dset_out = H5Dcreate2(fidout, travt->objs[i].name, mtype_id, space_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dcreate2 failed");
if(nelmts)
if(H5Dwrite(dset_out, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, refbuf) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dwrite failed");
if(buf)
HDfree(buf);
@@ -314,7 +311,7 @@ int do_copy_refobjs(hid_t fidin,
* copy attrs
*----------------------------------------------------*/
if(copy_attr(dset_in, dset_out, &named_dt_head, travt, options) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_attr failed");
} /* H5T_STD_REF_DSETREG */
/*-------------------------------------------------------------------------
* not references, open previously created object in 1st traversal
@@ -322,7 +319,7 @@ int do_copy_refobjs(hid_t fidin,
*/
else {
if((dset_out = H5Dopen2(fidout, travt->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed");
} /* end else */
HDassert(dset_out != FAIL);
@@ -332,7 +329,7 @@ int do_copy_refobjs(hid_t fidin,
*-------------------------------------------------------------------------
*/
if(copy_refs_attr(dset_in, dset_out, options, travt, fidout) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_refs_attr failed");
/*-------------------------------------------------------------------------
* check for hard links
@@ -343,7 +340,7 @@ int do_copy_refobjs(hid_t fidin,
H5Lcreate_hard(fidout, travt->objs[i].name, H5L_SAME_LOC, travt->objs[i].links[j].new_name, H5P_DEFAULT, H5P_DEFAULT);
if(H5Dclose(dset_out) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed");
} /*can_read*/
/*-------------------------------------------------------------------------
@@ -351,15 +348,15 @@ int do_copy_refobjs(hid_t fidin,
*-------------------------------------------------------------------------
*/
if(H5Tclose(ftype_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
if(H5Tclose(mtype_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
if(H5Pclose(dcpl_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
if(H5Sclose(space_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed");
if(H5Dclose(dset_in) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed");
break;
/*-------------------------------------------------------------------------
@@ -368,9 +365,9 @@ int do_copy_refobjs(hid_t fidin,
*/
case H5TRAV_TYPE_NAMED_DATATYPE:
if((type_in = H5Topen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Topen2 failed");
if(H5Tclose(type_in) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
break;
/*-------------------------------------------------------------------------
@@ -383,7 +380,7 @@ int do_copy_refobjs(hid_t fidin,
case H5TRAV_TYPE_UNKNOWN:
case H5TRAV_TYPE_UDLINK:
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5TRAV invalid type");
default:
break;
@@ -396,9 +393,9 @@ int do_copy_refobjs(hid_t fidin,
*/
named_datatype_free(&named_dt_head, 0);
- return 0;
+ return ret_value;
-error:
+done:
H5E_BEGIN_TRY {
H5Gclose(grp_in);
H5Gclose(grp_out);
@@ -412,7 +409,7 @@ error:
named_datatype_free(&named_dt_head, 0);
} H5E_END_TRY;
- return -1;
+ return ret_value;
}
@@ -450,6 +447,7 @@ static int copy_refs_attr(hid_t loc_in,
hid_t fidout /* for saving references */
)
{
+ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
hid_t attr_id = -1; /* attr ID */
hid_t attr_out = -1; /* attr ID */
hid_t space_id = -1; /* space ID */
@@ -467,32 +465,32 @@ static int copy_refs_attr(hid_t loc_in,
void *refbuf = NULL;
void *buf = NULL;
const char* refname = NULL;
- int *ref_comp_index = NULL;
+ unsigned *ref_comp_index = NULL;
size_t *ref_comp_size = NULL;
int ref_comp_field_n = 0;
if(H5Oget_info(loc_in, &oinfo) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Oget_info failed");
for(u = 0; u < (unsigned)oinfo.num_attrs; u++) {
is_ref = is_ref_vlen = is_ref_array = is_ref_comp = 0;
/* open attribute */
if((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aopen_by_idx failed");
/* get the file datatype */
if((ftype_id = H5Aget_type(attr_id)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type failed");
type_class = H5Tget_class(ftype_id);
if((mtype_id = h5tools_get_native_type(ftype_id)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "h5tools_get_native_type failed");
if((msize = H5Tget_size(mtype_id)) == 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed");
is_ref = (type_class == H5T_REFERENCE);
@@ -516,10 +514,10 @@ static int copy_refs_attr(hid_t loc_in,
int nmembers = H5Tget_nmembers(ftype_id) ;
if (nmembers < 1)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed");
- ref_comp_index = (int *)HDmalloc(nmembers*sizeof (int));
- ref_comp_size = (size_t *)HDmalloc(nmembers*sizeof(ref_comp_size));
+ ref_comp_index = (unsigned *)HDmalloc((size_t)nmembers*sizeof(unsigned));
+ ref_comp_size = (size_t *)HDmalloc((size_t)nmembers*sizeof(ref_comp_size));
ref_comp_field_n = 0;
for (i=0; i<(unsigned)nmembers; i++) {
@@ -560,15 +558,15 @@ static int copy_refs_attr(hid_t loc_in,
/* get name */
if(H5Aget_name(attr_id, 255, name) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_name failed");
/* get the dataspace handle */
if((space_id = H5Aget_space(attr_id)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_space failed");
/* get dimensions */
if((rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed");
/*-------------------------------------------------------------------------
@@ -580,8 +578,8 @@ static int copy_refs_attr(hid_t loc_in,
nelmts *= dims[j];
if (is_ref_array) {
- unsigned array_rank = 0;
- hsize_t array_size = 1;
+ unsigned array_rank = 0;
+ hsize_t array_size = 1;
hsize_t array_dims[H5S_MAX_RANK];
hid_t base_type;
@@ -589,7 +587,7 @@ static int copy_refs_attr(hid_t loc_in,
msize = H5Tget_size(base_type);
H5Tclose(base_type);
- array_rank = H5Tget_array_ndims(mtype_id);
+ array_rank = (unsigned)H5Tget_array_ndims(mtype_id);
H5Tget_array_dims2(mtype_id, array_dims);
for(j = 0; j <array_rank; j++)
array_size *= array_dims[j];
@@ -597,7 +595,7 @@ static int copy_refs_attr(hid_t loc_in,
}
if((attr_out = H5Acreate2(loc_out, name, ftype_id, space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Acreate2 failed");
if (nelmts>0) {
/* handle object references */
@@ -605,15 +603,15 @@ static int copy_refs_attr(hid_t loc_in,
buf = (hobj_ref_t *)HDmalloc((unsigned)(nelmts * msize));
if(buf == NULL) {
printf("cannot read into memory\n");
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed");
} /* end if */
if(H5Aread(attr_id, mtype_id, buf) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed");
refbuf = (hobj_ref_t *)HDcalloc((unsigned)nelmts, msize);
if(refbuf == NULL) {
printf("cannot allocate memory\n");
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed");
} /* end if */
for(i = 0; i < (unsigned)nelmts; i++) {
@@ -629,10 +627,10 @@ static int copy_refs_attr(hid_t loc_in,
if(buf == NULL) {
printf( "cannot read into memory\n" );
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed");
} /* end if */
if(H5Aread(attr_id, mtype_id, buf) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed");
/*-------------------------------------------------------------------------
* create output
@@ -641,7 +639,7 @@ static int copy_refs_attr(hid_t loc_in,
refbuf = (hdset_reg_ref_t *)HDcalloc(sizeof(hdset_reg_ref_t), (size_t)nelmts); /*init to zero */
if(refbuf == NULL) {
printf( "cannot allocate memory\n" );
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed");
} /* end if */
for(i = 0; i < (unsigned)nelmts; i++) {
@@ -659,11 +657,11 @@ static int copy_refs_attr(hid_t loc_in,
if(buf == NULL) {
printf( "cannot read into memory\n" );
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed");
} /* end if */
if(H5Aread(attr_id, mtype_id, buf) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed");
if (H5R_OBJ_REF_BUF_SIZE==msize) {
hobj_ref_t ref_out;
@@ -700,41 +698,43 @@ static int copy_refs_attr(hid_t loc_in,
if(buf == NULL)
{
printf( "cannot read into memory\n" );
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed");
} /* end if */
if(H5Aread(attr_id, mtype_id, buf) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed");
for (i=0; i<(unsigned)nelmts; i++) {
- for (j=0; j<(unsigned)ref_comp_field_n; j++) {
- if (ref_comp_size[j] == H5R_OBJ_REF_BUF_SIZE) {
- int idx = i*msize+H5Tget_member_offset( mtype_id, (unsigned)ref_comp_index[j]);
- hobj_ref_t ref_out;
- if (update_ref_value(attr_id, H5R_OBJECT, (hobj_ref_t *)(((char *)buf)+idx), fidout, &ref_out, travt)<0)
- continue;
- HDmemcpy(((char *)buf)+idx, &ref_out, ref_comp_size[j]);
- } /* if */
- else if (ref_comp_size[j] == H5R_DSET_REG_REF_BUF_SIZE) {
- int idx = i*msize+H5Tget_member_offset( mtype_id, (unsigned)ref_comp_index[j]);
- hdset_reg_ref_t ref_out;
- if (update_ref_value(attr_id, H5R_DATASET_REGION, (hdset_reg_ref_t *)(((char *)buf)+idx), fidout, &ref_out, travt)<0)
- continue;
- HDmemcpy(((char *)buf)+idx, &ref_out, ref_comp_size[j]);
- } /* else if */
- } /* j */
+ for (j=0; j<(unsigned)ref_comp_field_n; j++) {
+ if (ref_comp_size[j] == H5R_OBJ_REF_BUF_SIZE) {
+ size_t idx = (i * msize) + H5Tget_member_offset(mtype_id, ref_comp_index[j]);
+ hobj_ref_t ref_out;
+
+ if (update_ref_value(attr_id, H5R_OBJECT, (hobj_ref_t *)(((char *)buf)+idx), fidout, &ref_out, travt)<0)
+ continue;
+ HDmemcpy(((char *)buf)+idx, &ref_out, ref_comp_size[j]);
+ } /* if */
+ else if (ref_comp_size[j] == H5R_DSET_REG_REF_BUF_SIZE) {
+ size_t idx = i * msize + H5Tget_member_offset(mtype_id, ref_comp_index[j]);
+ hdset_reg_ref_t ref_out;
+
+ if (update_ref_value(attr_id, H5R_DATASET_REGION, (hdset_reg_ref_t *)(((char *)buf)+idx), fidout, &ref_out, travt)<0)
+ continue;
+ HDmemcpy(((char *)buf)+idx, &ref_out, ref_comp_size[j]);
+ } /* else if */
+ } /* j */
} /* i */
} /* else if (is_ref_comp) */
if(H5Awrite(attr_out, mtype_id, refbuf) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Awrite failed");
if (is_ref_vlen && buf)
H5Dvlen_reclaim (mtype_id, space_id, H5P_DEFAULT, buf);
} /* if (nelmts) */
if (refbuf == buf)
- refbuf = NULL; /* set it to NULL to avoid double free since buf and refbuf are the same. */
+ refbuf = NULL; /* set it to NULL to avoid double free since buf and refbuf are the same. */
if(buf) {
HDfree(buf);
@@ -747,39 +747,39 @@ static int copy_refs_attr(hid_t loc_in,
}
if (ref_comp_index) {
- HDfree(ref_comp_index);
- ref_comp_index = NULL;
+ HDfree(ref_comp_index);
+ ref_comp_index = NULL;
}
if (ref_comp_size) {
- HDfree(ref_comp_size);
- ref_comp_size = NULL;
+ HDfree(ref_comp_size);
+ ref_comp_size = NULL;
}
if(H5Aclose(attr_out) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed");
/*-------------------------------------------------------------------------
* close
*-------------------------------------------------------------------------
*/
if(H5Tclose(ftype_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
if(H5Tclose(mtype_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
if(H5Sclose(space_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed");
if(H5Aclose(attr_id) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed");
} /* for(u = 0; u < (unsigned)oinfo.num_attrs; u++) */
- return 0;
+ return ret_value;
-error:
- if(refbuf)
- HDfree(refbuf);
- if(buf)
- HDfree(buf);
+done:
+ if(refbuf)
+ HDfree(refbuf);
+ if(buf)
+ HDfree(buf);
if (ref_comp_index)
HDfree(ref_comp_index);
@@ -795,7 +795,7 @@ error:
H5Aclose(attr_out);
} H5E_END_TRY;
- return -1;
+ return ret_value;
}
/*-------------------------------------------------------------------------
@@ -845,30 +845,26 @@ out:
static herr_t update_ref_value(hid_t obj_id, H5R_type_t ref_type, void *ref_in,
hid_t fid_out, void *ref_out, trav_table_t *travt)
{
- herr_t ret = -1;
- const char* ref_obj_name;
- hid_t space_id=-1, ref_obj_id=-1;
-
- ref_obj_id = H5Rdereference(obj_id, ref_type, ref_in);
- if (ref_obj_id<0)
- goto done;
-
- ref_obj_name = MapIdToName(ref_obj_id, travt);
- if (ref_obj_name == NULL)
- goto done;
+ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
+ const char* ref_obj_name;
+ hid_t space_id=-1, ref_obj_id=-1;
- if (ref_type == H5R_DATASET_REGION) {
- space_id = H5Rget_region(obj_id, H5R_DATASET_REGION, ref_in);
- if (space_id < 0)
- goto done;
- }
+ ref_obj_id = H5Rdereference2(obj_id, H5P_DEFAULT, ref_type, ref_in);
+ if (ref_obj_id < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rdereference2 failed");
- ret = H5Rcreate(ref_out, fid_out, ref_obj_name, ref_type, space_id);
+ ref_obj_name = MapIdToName(ref_obj_id, travt);
+ if (ref_obj_name == NULL)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "MapIdToName failed");
- if (ret < 0)
- goto done;
+ if (ref_type == H5R_DATASET_REGION) {
+ space_id = H5Rget_region(obj_id, H5R_DATASET_REGION, ref_in);
+ if (space_id < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rget_region failed");
+ }
- ret = 0;
+ if(H5Rcreate(ref_out, fid_out, ref_obj_name, ref_type, space_id) < 0)
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rcreate failed");
done:
H5E_BEGIN_TRY {
@@ -876,6 +872,6 @@ done:
H5Oclose(ref_obj_id);
} H5E_END_TRY;
- return ret;
+ return ret_value;
}
diff --git a/tools/h5repack/h5repack_verify.c b/tools/h5repack/h5repack_verify.c
index cec9c86..f393dd1 100644
--- a/tools/h5repack/h5repack_verify.c
+++ b/tools/h5repack/h5repack_verify.c
@@ -51,11 +51,12 @@ static int verify_filters(hid_t pid, hid_t tid, int nfilters, filter_info_t *fil
int
h5repack_verify(const char *out_fname, pack_opt_t *options)
{
- hid_t fidout; /* file ID for output file*/
- hid_t did; /* dataset ID */
- hid_t pid; /* dataset creation property list ID */
- hid_t sid; /* space ID */
- hid_t tid; /* type ID */
+ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
+ hid_t fidout = -1; /* file ID for output file*/
+ hid_t did = -1; /* dataset ID */
+ hid_t pid = -1; /* dataset creation property list ID */
+ hid_t sid = -1; /* space ID */
+ hid_t tid = -1; /* type ID */
unsigned int i;
trav_table_t *travt = NULL;
int ok = 1;
@@ -74,20 +75,20 @@ h5repack_verify(const char *out_fname, pack_opt_t *options)
*-------------------------------------------------------------------------
*/
if((did = H5Dopen2(fidout, name, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed");
if((sid = H5Dget_space(did)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed");
if((pid = H5Dget_create_plist(did)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed");
if((tid = H5Dget_type(did)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_type failed");
/*-------------------------------------------------------------------------
* filter check
*-------------------------------------------------------------------------
*/
if(verify_filters(pid, tid, obj->nfilters, obj->filter) <= 0)
- ok = 0;
+ ok = 0;
/*-------------------------------------------------------------------------
@@ -102,13 +103,13 @@ h5repack_verify(const char *out_fname, pack_opt_t *options)
*-------------------------------------------------------------------------
*/
if(H5Pclose(pid) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
if (H5Sclose(sid) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed");
if (H5Dclose(did) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed");
if (H5Tclose(tid) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
}
@@ -126,7 +127,7 @@ h5repack_verify(const char *out_fname, pack_opt_t *options)
/* get the list of objects in the file */
if(h5trav_gettable(fidout, travt) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "h5trav_gettable failed");
for(i = 0; i < travt->nobjs; i++)
{
@@ -140,13 +141,13 @@ h5repack_verify(const char *out_fname, pack_opt_t *options)
*-------------------------------------------------------------------------
*/
if((did = H5Dopen2(fidout, name, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed");
if((sid = H5Dget_space(did)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed");
if((pid = H5Dget_create_plist(did)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed");
if((tid = H5Dget_type(did)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_type failed");
/*-------------------------------------------------------------------------
* filter check
@@ -154,7 +155,6 @@ h5repack_verify(const char *out_fname, pack_opt_t *options)
*/
if(options->all_filter == 1)
{
-
if(verify_filters(pid, tid, options->n_filter_g, options->filter_g) <= 0)
ok = 0;
}
@@ -166,6 +166,7 @@ h5repack_verify(const char *out_fname, pack_opt_t *options)
if(options->all_layout == 1)
{
pack_info_t pack;
+
init_packobject(&pack);
pack.layout = options->layout_g;
pack.chunk = options->chunk_g;
@@ -179,13 +180,13 @@ h5repack_verify(const char *out_fname, pack_opt_t *options)
*-------------------------------------------------------------------------
*/
if (H5Pclose(pid) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
if (H5Sclose(sid) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed");
if (H5Dclose(did) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed");
if (H5Tclose(tid) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
} /* if */
} /* i */
@@ -200,20 +201,24 @@ h5repack_verify(const char *out_fname, pack_opt_t *options)
*/
if (H5Fclose(fidout) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Fclose failed");
return ok;
-error:
+done:
H5E_BEGIN_TRY {
+ H5Pclose(fcpl_in);
+ H5Pclose(fcpl_out);
H5Pclose(pid);
H5Sclose(sid);
H5Dclose(did);
+ H5Fclose(fidin);
H5Fclose(fidout);
if (travt)
trav_table_free(travt);
} H5E_END_TRY;
- return -1;
+
+ return ret_value;
} /* h5repack_verify() */
@@ -291,6 +296,7 @@ int verify_layout(hid_t pid,
int h5repack_cmp_pl(const char *fname1,
const char *fname2)
{
+ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */
hid_t fid1=-1; /* file ID */
hid_t fid2=-1; /* file ID */
hid_t dset1=-1; /* dataset ID */
@@ -315,12 +321,12 @@ int h5repack_cmp_pl(const char *fname1,
{
/* Open the files */
- if ((fid1=H5Fopen(fname1,H5F_ACC_RDONLY,H5P_DEFAULT)) < 0 )
+ if ((fid1 = H5Fopen(fname1,H5F_ACC_RDONLY,H5P_DEFAULT)) < 0 )
{
error_msg("<%s>: %s\n", fname1, H5FOPENERROR );
return -1;
}
- if ((fid2=H5Fopen(fname2,H5F_ACC_RDONLY,H5P_DEFAULT)) < 0 )
+ if ((fid2 = H5Fopen(fname2,H5F_ACC_RDONLY,H5P_DEFAULT)) < 0 )
{
error_msg("<%s>: %s\n", fname2, H5FOPENERROR );
H5Fclose(fid1);
@@ -335,7 +341,7 @@ int h5repack_cmp_pl(const char *fname1,
*/
trav_table_init(&trav);
if(h5trav_gettable(fid1, trav) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "h5trav_gettable failed");
/*-------------------------------------------------------------------------
* traverse the suppplied object list
@@ -348,31 +354,30 @@ int h5repack_cmp_pl(const char *fname1,
{
if ((gid = H5Gopen2(fid1, trav->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed");
if ((gcplid = H5Gget_create_plist(gid)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gget_create_plist failed");
if (H5Pget_link_creation_order(gcplid, &crt_order_flag1) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pget_link_creation_order failed");
if (H5Pclose(gcplid) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
if (H5Gclose(gid) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed");
if ((gid = H5Gopen2(fid2, trav->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed");
if ((gcplid = H5Gget_create_plist(gid)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gget_create_plist failed");
if (H5Pget_link_creation_order(gcplid, &crt_order_flag2) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pget_link_creation_order failed");
if (H5Pclose(gcplid) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
if (H5Gclose(gid) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed");
- if ( crt_order_flag1 != crt_order_flag2 )
- {
+ if (crt_order_flag1 != crt_order_flag2) {
error_msg("property lists for <%s> are different\n",trav->objs[i].name);
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "property lists failed");
}
}
@@ -382,25 +387,24 @@ int h5repack_cmp_pl(const char *fname1,
else if(trav->objs[i].type == H5TRAV_TYPE_DATASET)
{
if((dset1 = H5Dopen2(fid1, trav->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed");
if((dset2 = H5Dopen2(fid2, trav->objs[i].name, H5P_DEFAULT)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed");
if((dcpl1 = H5Dget_create_plist(dset1)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed");
if((dcpl2 = H5Dget_create_plist(dset2)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed");
/*-------------------------------------------------------------------------
* compare the property lists
*-------------------------------------------------------------------------
*/
if((ret = H5Pequal(dcpl1, dcpl2)) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pequal failed");
- if(ret == 0)
- {
+ if(ret == 0) {
error_msg("property lists for <%s> are different\n",trav->objs[i].name);
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "property lists failed");
}
/*-------------------------------------------------------------------------
@@ -408,13 +412,13 @@ int h5repack_cmp_pl(const char *fname1,
*-------------------------------------------------------------------------
*/
if(H5Pclose(dcpl1) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
if(H5Pclose(dcpl2) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed");
if(H5Dclose(dset1) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed");
if(H5Dclose(dset2) < 0)
- goto error;
+ HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed");
} /*if*/
} /*i*/
@@ -432,14 +436,14 @@ int h5repack_cmp_pl(const char *fname1,
H5Fclose(fid1);
H5Fclose(fid2);
- return ret;
- /*-------------------------------------------------------------------------
- * error
- *-------------------------------------------------------------------------
- */
+ return ret;
-error:
+/*-------------------------------------------------------------------------
+* error
+*-------------------------------------------------------------------------
+*/
+done:
H5E_BEGIN_TRY
{
H5Pclose(dcpl1);
@@ -452,8 +456,8 @@ error:
H5Gclose(gid);
trav_table_free(trav);
} H5E_END_TRY;
- return -1;
+ return ret_value;
}
@@ -522,100 +526,71 @@ int verify_filters(hid_t pid, hid_t tid, int nfilters, filter_info_t *filter)
switch (filtn)
{
- case H5Z_FILTER_NONE:
+ case H5Z_FILTER_NONE:
break;
- case H5Z_FILTER_SHUFFLE:
-
- /* 1 private client value is returned by DCPL */
- if ( cd_nelmts != H5Z_SHUFFLE_TOTAL_NPARMS && filter[i].cd_nelmts != H5Z_SHUFFLE_USER_NPARMS )
- return 0;
-
- /* get dataset's type size */
- if((size = H5Tget_size(tid)) <= 0)
- return -1;
-
- /* the private client value holds the dataset's type size */
- if ( size != cd_values[0] )
- return 0;
-
-
- break;
-
- case H5Z_FILTER_SZIP:
-
- /* 4 private client values are returned by DCPL */
- if ( cd_nelmts != H5Z_SZIP_TOTAL_NPARMS && filter[i].cd_nelmts != H5Z_SZIP_USER_NPARMS )
- return 0;
-
- /* "User" parameter for pixels-per-block (index 1) */
- if ( cd_values[H5Z_SZIP_PARM_PPB] != filter[i].cd_values[H5Z_SZIP_PARM_PPB] )
- return 0;
-
-
- break;
-
- case H5Z_FILTER_NBIT:
-
- /* only client data values number of values checked */
- if ( H5Z_NBIT_USER_NPARMS != filter[i].cd_nelmts)
- return 0;
-
-
-
- break;
+ case H5Z_FILTER_SHUFFLE:
+ /* 1 private client value is returned by DCPL */
+ if ( cd_nelmts != H5Z_SHUFFLE_TOTAL_NPARMS && filter[i].cd_nelmts != H5Z_SHUFFLE_USER_NPARMS )
+ return 0;
- case H5Z_FILTER_SCALEOFFSET:
+ /* get dataset's type size */
+ if((size = H5Tget_size(tid)) <= 0)
+ return -1;
- /* only client data values checked */
- for( j = 0; j < H5Z_SCALEOFFSET_USER_NPARMS; j++)
- {
- if (cd_values[j] != filter[i].cd_values[j])
- {
+ /* the private client value holds the dataset's type size */
+ if ( size != cd_values[0] )
return 0;
- }
-
- }
+ break;
- break;
+ case H5Z_FILTER_SZIP:
+ /* 4 private client values are returned by DCPL */
+ if ( cd_nelmts != H5Z_SZIP_TOTAL_NPARMS && filter[i].cd_nelmts != H5Z_SZIP_USER_NPARMS )
+ return 0;
- /* for these filters values must match, no local values set in DCPL */
- case H5Z_FILTER_FLETCHER32:
- case H5Z_FILTER_DEFLATE:
+ /* "User" parameter for pixels-per-block (index 1) */
+ if ( cd_values[H5Z_SZIP_PARM_PPB] != filter[i].cd_values[H5Z_SZIP_PARM_PPB] )
+ return 0;
- if ( cd_nelmts != filter[i].cd_nelmts)
- return 0;
+ break;
- for( j = 0; j < cd_nelmts; j++)
- {
- if (cd_values[j] != filter[i].cd_values[j])
- {
+ case H5Z_FILTER_NBIT:
+ /* only client data values number of values checked */
+ if ( H5Z_NBIT_USER_NPARMS != filter[i].cd_nelmts)
return 0;
- }
+ break;
- }
+ case H5Z_FILTER_SCALEOFFSET:
+ /* only client data values checked */
+ for( j = 0; j < H5Z_SCALEOFFSET_USER_NPARMS; j++)
+ if (cd_values[j] != filter[i].cd_values[j])
+ return 0;
+ break;
+ /* for these filters values must match, no local values set in DCPL */
+ case H5Z_FILTER_FLETCHER32:
+ case H5Z_FILTER_DEFLATE:
+ if ( cd_nelmts != filter[i].cd_nelmts)
+ return 0;
- break;
+ for( j = 0; j < cd_nelmts; j++)
+ if (cd_values[j] != filter[i].cd_values[j])
+ return 0;
- default:
- if ( cd_nelmts != filter[i].cd_nelmts)
- return 0;
+ break;
- for( j = 0; j < cd_nelmts; j++)
- {
- if (cd_values[j] != filter[i].cd_values[j])
- {
- return 0;
- }
+ default:
+ if ( cd_nelmts != filter[i].cd_nelmts)
+ return 0;
- }
- break;
+ for( j = 0; j < cd_nelmts; j++)
+ if (cd_values[j] != filter[i].cd_values[j])
+ return 0;
+ break;
} /* switch */
-
}
return 1;
diff --git a/tools/h5repack/h5repacktst.c b/tools/h5repack/h5repacktst.c
index f49e587..d0b182c 100644
--- a/tools/h5repack/h5repacktst.c
+++ b/tools/h5repack/h5repacktst.c
@@ -1536,15 +1536,15 @@ int main (void)
{
hid_t fapl;
- /* setup */
- h5_reset();
fapl = h5_fileaccess();
- h5_cleanup(H5REPACK_FILENAMES, fapl);
+ h5_clean_files(H5REPACK_FILENAMES, fapl);
}
puts("All h5repack tests passed.");
+ h5tools_close();
+
return 0;
error:
@@ -3361,7 +3361,7 @@ make_userblock(void)
/* Initialize userblock data */
for(u = 0; u < USERBLOCK_SIZE; u++)
- ub[u] = 'a' + (char)(u % 26);
+ ub[u] = (char)('a' + (char)(u % 26));
/* Re-open HDF5 file, as "plain" file */
if((fd = HDopen(FNAME16, O_WRONLY, 0644)) < 0)
@@ -3474,7 +3474,7 @@ make_userblock_file(void)
/* initialize userblock data */
for(u = 0; u < USERBLOCK_SIZE; u++)
- ub[u] = 'a' + (char)(u % 26);
+ ub[u] = (char)('a' + (char)(u % 26));
/* open file */
if((fd = HDopen(FNAME_UB,O_WRONLY|O_CREAT|O_TRUNC, 0644 )) < 0)
@@ -3531,7 +3531,8 @@ int write_dset_in(hid_t loc_id,
hid_t sid=-1;
hid_t tid=-1;
hid_t pid=-1;
- int val, i, j, k, n;
+ unsigned i, j;
+ int val, k, n;
float f;
/* create 1D attributes with dimension [2], 2 elements */
@@ -3586,13 +3587,10 @@ int write_dset_in(hid_t loc_id,
*/
- if (make_diffs)
- {
- for (i=0; i<2; i++)
- for (j=0; j<2; j++)
- {
- buf1[i][j]='z';
- }
+ if(make_diffs) {
+ for(i = 0; i < 2; i++)
+ for(j = 0; j < 2; j++)
+ buf1[i][j] = 'z';
}
@@ -3615,10 +3613,9 @@ int write_dset_in(hid_t loc_id,
*-------------------------------------------------------------------------
*/
- if (make_diffs)
- {
- for (i=0; i<2; i++)
- buf2[i]=buf2[1]=0;
+ if(make_diffs) {
+ for(i = 0; i < 2; i++)
+ buf2[i] = buf2[1] = 0;
}
if ((tid = H5Tcopy(H5T_STD_B8LE)) < 0)
@@ -3633,11 +3630,10 @@ int write_dset_in(hid_t loc_id,
*-------------------------------------------------------------------------
*/
- if (make_diffs)
- {
- for (i=0; i<2; i++)
- {
- buf3[i].a=0; buf3[i].b=0;
+ if(make_diffs) {
+ for(i = 0; i < 2; i++) {
+ buf3[i].a = 0;
+ buf3[i].b = 0;
}
}
@@ -3656,12 +3652,9 @@ int write_dset_in(hid_t loc_id,
*/
- if (make_diffs)
- {
- for (i=0; i<2; i++)
- {
- buf45[i]=GREEN;
- }
+ if(make_diffs) {
+ for(i = 0; i < 2; i++)
+ buf45[i] = GREEN;
}
if ((tid = H5Tcreate (H5T_COMPOUND, sizeof(s_t))) < 0)
@@ -3753,13 +3746,10 @@ int write_dset_in(hid_t loc_id,
*-------------------------------------------------------------------------
*/
- if (make_diffs)
- {
- for (i=0; i<2; i++)
- for (j=0; j<3; j++)
- {
- buf6[i][j]=0;
- }
+ if(make_diffs) {
+ for(i = 0; i < 2; i++)
+ for(j = 0; j < 3; j++)
+ buf6[i][j] = 0;
}
if ((tid = H5Tarray_create2(H5T_NATIVE_INT, 1, dimarray)) < 0)
@@ -3820,12 +3810,10 @@ int write_dset_in(hid_t loc_id,
*-------------------------------------------------------------------------
*/
- if (make_diffs)
- {
- for (i=0; i<2; i++)
- {
- buf7[i]=0;
- buf8[i]=0;
+ if(make_diffs) {
+ for(i = 0; i < 2; i++) {
+ buf7[i] = 0;
+ buf8[i] = 0;
}
}
@@ -3948,16 +3936,13 @@ int write_dset_in(hid_t loc_id,
/* Allocate and initialize VL dataset to write */
n = 0;
- for(i = 0; i < 3; i++)
- {
- for(j = 0; j < 2; j++)
- {
- int l;
+ for(i = 0; i < 3; i++) {
+ for(j = 0; j < 2; j++) {
+ unsigned l;
buf52[i][j].p = HDmalloc((i + 1) * sizeof(int));
buf52[i][j].len = (size_t)(i + 1);
- for(l = 0; l < i + 1; l++)
- {
+ for(l = 0; l < i + 1; l++) {
if(make_diffs)
((int *)buf52[i][j].p)[l] = 0;
else
@@ -4068,11 +4053,13 @@ int write_dset_in(hid_t loc_id,
n=1;
- for (i = 0; i < 4; i++) {
- for (j = 0; j < 3; j++) {
- for (k = 0; k < 2; k++) {
- if (make_diffs) buf23[i][j][k]=0;
- else buf23[i][j][k]=n++;
+ for(i = 0; i < 4; i++) {
+ for(j = 0; j < 3; j++) {
+ for(k = 0; k < 2; k++) {
+ if(make_diffs)
+ buf23[i][j][k] = 0;
+ else
+ buf23[i][j][k] = (char)(n++);
}
}
}
@@ -4104,16 +4091,16 @@ int write_dset_in(hid_t loc_id,
*/
n=1;
- for (i = 0; i < 4; i++) {
- for (j = 0; j < 3; j++) {
- for (k = 0; k < 2; k++) {
- if (make_diffs) {
- buf33[i][j][k].a=0;
- buf33[i][j][k].b=0;
+ for(i = 0; i < 4; i++) {
+ for(j = 0; j < 3; j++) {
+ for(k = 0; k < 2; k++) {
+ if(make_diffs) {
+ buf33[i][j][k].a = 0;
+ buf33[i][j][k].b = 0;
}
else {
- buf33[i][j][k].a=n++;
- buf33[i][j][k].b=n++;
+ buf33[i][j][k].a = (char)(n++);
+ buf33[i][j][k].b = n++;
}
}
}
@@ -4167,18 +4154,14 @@ int write_dset_in(hid_t loc_id,
/* Allocate and initialize VL dataset to write */
n = 0;
- for(i = 0; i < 4; i++)
- {
- for(j = 0; j < 3; j++)
- {
- for(k = 0; k < 2; k++)
- {
- int l;
+ for(i = 0; i < 4; i++) {
+ for(j = 0; j < 3; j++) {
+ for(k = 0; k < 2; k++) {
+ unsigned l;
buf53[i][j][k].p = HDmalloc((i + 1) * sizeof(int));
buf53[i][j][k].len = (size_t)(i + 1);
- for(l = 0; l < i + 1; l++)
- {
+ for(l = 0; l < i + 1; l++) {
if(make_diffs)
((int *)buf53[i][j][k].p)[l] = 0;
else
@@ -4214,10 +4197,8 @@ int write_dset_in(hid_t loc_id,
n = 1;
- for(i = 0; i < 24; i++)
- {
- for(j = 0; j < (int)dimarray[0]; j++)
- {
+ for(i = 0; i < 24; i++) {
+ for(j = 0; j < dimarray[0]; j++) {
if(make_diffs)
buf63[i][j] = 0;
else
@@ -4256,13 +4237,10 @@ int write_dset_in(hid_t loc_id,
if (write_dset(loc_id,3,dims3,"float3D",H5T_NATIVE_FLOAT,buf83) < 0)
goto out;
-
return 0;
-
out:
- H5E_BEGIN_TRY
- {
+ H5E_BEGIN_TRY {
H5Pclose(pid);
H5Sclose(sid);
H5Dclose(did);
@@ -4411,7 +4389,8 @@ int write_attr_in(hid_t loc_id,
hid_t aid = -1;
hid_t sid = -1;
hid_t tid = -1;
- int val, i, j, k, n;
+ int val, j, k, n;
+ unsigned i;
float f;
/* create 1D attributes with dimension [2], 2 elements */
@@ -4961,16 +4940,17 @@ int write_attr_in(hid_t loc_id,
/* Allocate and initialize VL dataset to write */
n=0;
- for (i = 0; i < 3; i++)
- {
- for (j = 0; j < 2; j++)
- {
- int l;
+ for(i = 0; i < 3; i++) {
+ for(j = 0; j < 2; j++) {
+ unsigned l;
+
buf52[i][j].p = HDmalloc((i + 1) * sizeof(int));
buf52[i][j].len = (size_t)(i + 1);
- for (l = 0; l < i + 1; l++)
- if (make_diffs)((int *)buf52[i][j].p)[l] = 0;
- else ((int *)buf52[i][j].p)[l] = n++;
+ for(l = 0; l < i + 1; l++)
+ if(make_diffs)
+ ((int *)buf52[i][j].p)[l] = 0;
+ else
+ ((int *)buf52[i][j].p)[l] = n++;
}
}
@@ -5179,14 +5159,13 @@ int write_attr_in(hid_t loc_id,
*/
n=1;
- for (i = 0; i < 4; i++)
- {
- for (j = 0; j < 3; j++)
- {
- for (k = 0; k < 2; k++)
- {
- if (make_diffs) buf23[i][j][k]=0;
- else buf23[i][j][k]=n++;
+ for(i = 0; i < 4; i++) {
+ for(j = 0; j < 3; j++) {
+ for(k = 0; k < 2; k++) {
+ if(make_diffs)
+ buf23[i][j][k] = 0;
+ else
+ buf23[i][j][k] = (char)(n++);
}
}
}
@@ -5248,21 +5227,16 @@ int write_attr_in(hid_t loc_id,
*/
n=1;
- for (i = 0; i < 4; i++)
- {
- for (j = 0; j < 3; j++)
- {
- for (k = 0; k < 2; k++)
- {
- if (make_diffs)
- {
- buf33[i][j][k].a=0;
- buf33[i][j][k].b=0;
+ for(i = 0; i < 4; i++) {
+ for(j = 0; j < 3; j++) {
+ for(k = 0; k < 2; k++) {
+ if(make_diffs) {
+ buf33[i][j][k].a = 0;
+ buf33[i][j][k].b = 0;
}
- else
- {
- buf33[i][j][k].a=n++;
- buf33[i][j][k].b=n++;
+ else {
+ buf33[i][j][k].a = (char)(n++);
+ buf33[i][j][k].b = n++;
}
}
}
@@ -5431,14 +5405,13 @@ int write_attr_in(hid_t loc_id,
{
for (k = 0; k < 2; k++)
{
- int l;
+ unsigned l;
+
buf53[i][j][k].p = HDmalloc((i + 1) * sizeof(int));
buf53[i][j][k].len = (size_t)i + 1;
for (l = 0; l < i + 1; l++)
if (make_diffs)
- {
((int *)buf53[i][j][k].p)[l] = 0;
- }
else
((int *)buf53[i][j][k].p)[l] = n++;
}
@@ -5562,8 +5535,7 @@ int write_attr_in(hid_t loc_id,
return 0;
out:
- H5E_BEGIN_TRY
- {
+ H5E_BEGIN_TRY {
H5Aclose(aid);
H5Sclose(sid);
H5Tclose(tid);
diff --git a/tools/h5repack/testfiles/h5repack_filters.h5-gzip_verbose_filters.tst b/tools/h5repack/testfiles/h5repack_filters.h5-gzip_verbose_filters.tst
new file mode 100644
index 0000000..36e65b9
--- /dev/null
+++ b/tools/h5repack/testfiles/h5repack_filters.h5-gzip_verbose_filters.tst
@@ -0,0 +1,13 @@
+Objects to modify layout are...
+Objects to apply filter are...
+ </dset_deflate> with GZIP filter
+ </dset_deflate>...Found
+-----------------------------------------
+ Type Filter (Compression) Name
+-----------------------------------------
+ group /
+ dset /dset_all
+ dset GZIP (0.995:1) /dset_deflate
+ dset /dset_fletcher32
+ dset /dset_nbit
+ dset /dset_shuffle