summaryrefslogtreecommitdiffstats
path: root/tools/src/h5repack/h5repack.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-09-30 14:27:10 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-09-30 14:27:10 (GMT)
commitb2d661b508a7fc7a2592c13bc6bdc175551f075d (patch)
tree13baeb0d83a7c2a4c6299993c182b1227c2f6114 /tools/src/h5repack/h5repack.c
parent29ab58b58dce556639ea3154e262895773a8a8df (diff)
downloadhdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.zip
hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.gz
hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.bz2
Clang-format of source files
Diffstat (limited to 'tools/src/h5repack/h5repack.c')
-rw-r--r--tools/src/h5repack/h5repack.c225
1 files changed, 116 insertions, 109 deletions
diff --git a/tools/src/h5repack/h5repack.c b/tools/src/h5repack/h5repack.c
index 4fd163c..a1764df 100644
--- a/tools/src/h5repack/h5repack.c
+++ b/tools/src/h5repack/h5repack.c
@@ -22,10 +22,10 @@
*-------------------------------------------------------------------------
*/
-static int check_options(pack_opt_t *options);
-static int check_objects(const char* fname, pack_opt_t *options);
-static const char* get_sfilter(H5Z_filter_t filtn);
-static int have_request(pack_opt_t *options);
+static int check_options(pack_opt_t *options);
+static int check_objects(const char *fname, pack_opt_t *options);
+static const char *get_sfilter(H5Z_filter_t filtn);
+static int have_request(pack_opt_t *options);
/*-------------------------------------------------------------------------
* Function: h5repack
@@ -42,7 +42,7 @@ static int have_request(pack_opt_t *options);
*-------------------------------------------------------------------------
*/
int
-h5repack(const char* infile, const char* outfile, pack_opt_t *options)
+h5repack(const char *infile, const char *outfile, pack_opt_t *options)
{
/* check input */
if (check_options(options) < 0)
@@ -73,17 +73,17 @@ h5repack_init(pack_opt_t *options, int verbose, hbool_t latest)
int k, n;
HDmemset(options, 0, sizeof(pack_opt_t));
- options->min_comp = 0;
- options->verbose = verbose;
- options->latest = latest;
- options->layout_g = H5D_LAYOUT_ERROR;
- options->low_bound = H5F_LIBVER_EARLIEST;
+ options->min_comp = 0;
+ options->verbose = verbose;
+ options->latest = latest;
+ options->layout_g = H5D_LAYOUT_ERROR;
+ options->low_bound = H5F_LIBVER_EARLIEST;
options->high_bound = H5F_LIBVER_LATEST;
- options->fin_fapl = H5P_DEFAULT;
- options->fout_fapl = H5P_DEFAULT;
+ options->fin_fapl = H5P_DEFAULT;
+ options->fout_fapl = H5P_DEFAULT;
for (n = 0; n < H5_REPACK_MAX_NFILTERS; n++) {
- options->filter_g[n].filtn = -1;
+ options->filter_g[n].filtn = -1;
options->filter_g[n].cd_nelmts = 0;
for (k = 0; k < CD_VALUES; k++)
options->filter_g[n].cd_values[k] = 0;
@@ -117,7 +117,7 @@ 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 */
+ 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 */
@@ -166,7 +166,7 @@ h5repack_addlayout(const char *str, pack_opt_t *options)
init_packobject(&pack);
if (options->all_layout == 1) {
- error_msg( "invalid layout input: 'all' option is present with other objects <%s>\n", str);
+ error_msg("invalid layout input: 'all' option is present with other objects <%s>\n", str);
return ret_value;
}
@@ -222,13 +222,14 @@ h5repack_addlayout(const char *str, pack_opt_t *options)
*-------------------------------------------------------------------------
*/
hid_t
-copy_named_datatype(hid_t type_in, hid_t fidout, named_dt_t **named_dt_head_p, trav_table_t *travt, pack_opt_t *options)
+copy_named_datatype(hid_t type_in, hid_t fidout, named_dt_t **named_dt_head_p, trav_table_t *travt,
+ pack_opt_t *options)
{
- named_dt_t *dt = *named_dt_head_p; /* Stack pointer */
- named_dt_t *dt_ret = NULL; /* Datatype to return */
- H5O_info2_t oinfo; /* Object info of input dtype */
- int token_cmp;
- hid_t ret_value = H5I_INVALID_HID;
+ named_dt_t *dt = *named_dt_head_p; /* Stack pointer */
+ named_dt_t *dt_ret = NULL; /* Datatype to return */
+ H5O_info2_t oinfo; /* Object info of input dtype */
+ int token_cmp;
+ hid_t ret_value = H5I_INVALID_HID;
if (H5Oget_info3(type_in, &oinfo, H5O_INFO_BASIC) < 0)
H5TOOLS_GOTO_ERROR(H5I_INVALID_HID, "H5Oget_info failed");
@@ -256,7 +257,7 @@ copy_named_datatype(hid_t type_in, hid_t fidout, named_dt_t **named_dt_head_p, t
/* Push onto the stack */
if (NULL == (dt = (named_dt_t *)HDmalloc(sizeof(named_dt_t))))
H5TOOLS_GOTO_ERROR(H5I_INVALID_HID, "buffer allocation failed failed");
- dt->next = *named_dt_head_p;
+ dt->next = *named_dt_head_p;
*named_dt_head_p = dt;
/* Update the token/address and id */
@@ -269,8 +270,8 @@ copy_named_datatype(hid_t type_in, hid_t fidout, named_dt_t **named_dt_head_p, t
if (!token_cmp)
dt_ret = dt;
} /* end if named datatype */
- } /* end for each object in traversal table */
- } /* end else (create the stack) */
+ } /* end for each object in traversal table */
+ } /* end else (create the stack) */
/* Handle the case that the requested datatype was not found. This is
* possible if the datatype was committed anonymously in the input file.
@@ -279,7 +280,7 @@ copy_named_datatype(hid_t type_in, hid_t fidout, named_dt_t **named_dt_head_p, t
/* Push the new datatype onto the stack */
if (NULL == (dt_ret = (named_dt_t *)HDmalloc(sizeof(named_dt_t))))
H5TOOLS_GOTO_ERROR(H5I_INVALID_HID, "buffer allocation failed failed");
- dt_ret->next = *named_dt_head_p;
+ dt_ret->next = *named_dt_head_p;
*named_dt_head_p = dt_ret;
/* Update the token/address and id */
@@ -323,8 +324,8 @@ done:
int
named_datatype_free(named_dt_t **named_dt_head_p, int ignore_err)
{
- named_dt_t *dt = *named_dt_head_p;
- int ret_value = -1;
+ named_dt_t *dt = *named_dt_head_p;
+ int ret_value = -1;
while (dt) {
/* Pop the datatype off the stack and free it */
@@ -355,24 +356,24 @@ 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 = H5I_INVALID_HID; /* attr ID */
+ hid_t attr_id = H5I_INVALID_HID; /* attr ID */
hid_t attr_out = H5I_INVALID_HID; /* attr ID */
hid_t space_id = H5I_INVALID_HID; /* space ID */
hid_t ftype_id = H5I_INVALID_HID; /* file type ID */
hid_t wtype_id = H5I_INVALID_HID; /* 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 */
+ 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_info2_t oinfo; /* object info */
+ H5O_info2_t oinfo; /* object info */
int j;
unsigned u;
- hbool_t is_ref = 0;
+ hbool_t is_ref = 0;
H5T_class_t type_class = -1;
- int ret_value = 0;
+ int ret_value = 0;
if (H5Oget_info3(loc_in, &oinfo, H5O_INFO_NUM_ATTRS) < 0)
H5TOOLS_GOTO_ERROR((-1), "H5Oget_info failed");
@@ -381,12 +382,13 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, trav_table_
* copy all attributes
*-------------------------------------------------------------------------
*/
- for (u = 0; u < (unsigned) oinfo.num_attrs; u++) {
+ 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)
+ if ((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, H5P_DEFAULT,
+ H5P_DEFAULT)) < 0)
H5TOOLS_GOTO_ERROR((-1), "H5Aopen_by_idx failed");
- if (H5Aget_name(attr_id, (size_t) 255, name) < 0)
+ if (H5Aget_name(attr_id, (size_t)255, name) < 0)
H5TOOLS_GOTO_ERROR((-1), "H5Pclose failed");
/* get the file datatype */
@@ -442,12 +444,12 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, trav_table_
*---------------------------------------------------------------------
*/
type_class = H5Tget_class(wtype_id);
- is_ref = (type_class == H5T_REFERENCE);
+ is_ref = (type_class == H5T_REFERENCE);
if (type_class == H5T_VLEN || type_class == H5T_ARRAY) {
hid_t base_type = H5I_INVALID_HID;
base_type = H5Tget_super(ftype_id);
- is_ref = (is_ref || (H5Tget_class(base_type) == H5T_REFERENCE));
+ is_ref = (is_ref || (H5Tget_class(base_type) == H5T_REFERENCE));
if (H5Tclose(base_type) < 0)
H5TOOLS_ERROR((-1), "H5Tclose base_type failed");
} /* end if type_class is variable length or array */
@@ -456,7 +458,7 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, trav_table_
int nmembers = H5Tget_nmembers(wtype_id);
for (j = 0; j < nmembers; j++) {
- hid_t mtid = H5Tget_member_type(wtype_id, (unsigned)j);
+ hid_t mtid = H5Tget_member_type(wtype_id, (unsigned)j);
H5T_class_t mtclass = H5Tget_class(mtid);
if (H5Tclose(mtid) < 0)
H5TOOLS_ERROR((-1), "H5Tclose mtid failed");
@@ -466,7 +468,7 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, trav_table_
break;
}
} /* end for each member */
- } /* end if type_class is H5T_COMPOUND */
+ } /* end if type_class is H5T_COMPOUND */
if (!is_ref) {
/*-----------------------------------------------------------------
@@ -525,7 +527,8 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, trav_table_
} /* for u (each attribute) */
done:
- H5E_BEGIN_TRY {
+ H5E_BEGIN_TRY
+ {
if (buf) {
/* Check if we have VL data and string in the attribute's
* datatype that must be reclaimed
@@ -542,7 +545,8 @@ done:
H5Tclose(wtype_id);
H5Tclose(ftype_id);
H5Aclose(attr_id);
- } H5E_END_TRY;
+ }
+ H5E_END_TRY;
return ret_value;
} /* end copy_attr() */
@@ -571,31 +575,31 @@ check_options(pack_opt_t *options)
if (options->all_layout == 1) {
HDprintf("All objects to modify layout are...\n");
switch (options->layout_g) {
- case H5D_COMPACT:
- strcpy(slayout, "compact");
- break;
- case H5D_CONTIGUOUS:
- strcpy(slayout, "contiguous");
- break;
- case H5D_CHUNKED:
- strcpy(slayout, "chunked");
- break;
- case H5D_VIRTUAL:
- strcpy(slayout, "virtual");
- break;
- case H5D_LAYOUT_ERROR:
- case H5D_NLAYOUTS:
- H5TOOLS_GOTO_ERROR((-1), "invalid layout");
- break;
- default:
- strcpy(slayout, "invalid layout\n");
- H5TOOLS_GOTO_DONE((-1));
+ case H5D_COMPACT:
+ strcpy(slayout, "compact");
+ break;
+ case H5D_CONTIGUOUS:
+ strcpy(slayout, "contiguous");
+ break;
+ case H5D_CHUNKED:
+ strcpy(slayout, "chunked");
+ break;
+ case H5D_VIRTUAL:
+ strcpy(slayout, "virtual");
+ break;
+ case H5D_LAYOUT_ERROR:
+ case H5D_NLAYOUTS:
+ H5TOOLS_GOTO_ERROR((-1), "invalid layout");
+ break;
+ default:
+ strcpy(slayout, "invalid layout\n");
+ H5TOOLS_GOTO_DONE((-1));
}
HDprintf(" Apply %s layout to all", slayout);
if (H5D_CHUNKED == options->layout_g) {
HDprintf("with dimension [ ");
for (j = 0; j < options->chunk_g.rank; j++)
- HDprintf("%d ", (int) options->chunk_g.chunk_lengths[j]);
+ HDprintf("%d ", (int)options->chunk_g.chunk_lengths[j]);
HDprintf("]");
}
HDprintf("\n");
@@ -605,13 +609,13 @@ check_options(pack_opt_t *options)
} /* end if verbose */
for (i = 0; i < options->op_tbl->nelems; i++) {
- char* name = options->op_tbl->objs[i].path;
+ char *name = options->op_tbl->objs[i].path;
if (options->op_tbl->objs[i].chunk.rank > 0) {
if (options->verbose) {
HDprintf(" <%s> with chunk size ", name);
for (k = 0; k < options->op_tbl->objs[i].chunk.rank; k++)
- HDprintf("%d ", (int) options->op_tbl->objs[i].chunk.chunk_lengths[k]);
+ HDprintf("%d ", (int)options->op_tbl->objs[i].chunk.chunk_lengths[k]);
HDprintf("\n");
}
has_ck = 1;
@@ -641,36 +645,38 @@ check_options(pack_opt_t *options)
continue;
}
switch (filtn) {
- case H5Z_FILTER_NONE:
- HDprintf(" Uncompress all\n");
- break;
- case H5Z_FILTER_SHUFFLE:
- case H5Z_FILTER_FLETCHER32:
- HDprintf(" All with %s\n", get_sfilter(filtn));
- break;
- case H5Z_FILTER_SZIP:
- case H5Z_FILTER_DEFLATE:
- HDprintf(" All with %s, parameter %d\n", get_sfilter(filtn), options->filter_g[k].cd_values[0]);
- break;
- default:
- HDprintf(" User Defined %d\n", filtn);
- break;
+ case H5Z_FILTER_NONE:
+ HDprintf(" Uncompress all\n");
+ break;
+ case H5Z_FILTER_SHUFFLE:
+ case H5Z_FILTER_FLETCHER32:
+ HDprintf(" All with %s\n", get_sfilter(filtn));
+ break;
+ case H5Z_FILTER_SZIP:
+ case H5Z_FILTER_DEFLATE:
+ HDprintf(" All with %s, parameter %d\n", get_sfilter(filtn),
+ options->filter_g[k].cd_values[0]);
+ break;
+ default:
+ HDprintf(" User Defined %d\n", filtn);
+ break;
} /* end switch */
- } /* end for each filter */
- } /* end if options->all_filter == 1 (TODO: meaning) */
+ } /* end for each filter */
+ } /* end if options->all_filter == 1 (TODO: meaning) */
else
HDprintf("No all objects to apply filter\n");
} /* end if verbose */
for (i = 0; i < options->op_tbl->nelems; i++) {
pack_info_t pack = options->op_tbl->objs[i];
- char* name = pack.path;
+ char * name = pack.path;
for (j = 0; j < pack.nfilters; j++) {
if (options->verbose) {
if (pack.filter[j].filtn >= 0) {
if (pack.filter[j].filtn > H5Z_FILTER_SCALEOFFSET) {
- HDprintf(" <%s> with %s filter %d\n", name, get_sfilter(pack.filter[j].filtn), pack.filter[j].filtn);
+ HDprintf(" <%s> with %s filter %d\n", name, get_sfilter(pack.filter[j].filtn),
+ pack.filter[j].filtn);
}
else {
HDprintf(" <%s> with %s filter\n", name, get_sfilter(pack.filter[j].filtn));
@@ -679,7 +685,7 @@ check_options(pack_opt_t *options)
}
has_cp = 1;
} /* end for each filter */
- } /* end for each object in options table */
+ } /* end for each object in options table */
if (options->all_filter == 1 && has_cp)
H5TOOLS_GOTO_ERROR((-1), "invalid compression input: 'all' option is present with other objects");
@@ -705,7 +711,8 @@ check_options(pack_opt_t *options)
*/
if (options->ublock_filename != NULL && options->ublock_size == 0) {
if (options->verbose) {
- HDprintf("Warning: user block size missing for file %s. Assigning a default size of 1024...\n", options->ublock_filename);
+ HDprintf("Warning: user block size missing for file %s. Assigning a default size of 1024...\n",
+ options->ublock_filename);
options->ublock_size = 1024;
}
}
@@ -735,14 +742,14 @@ done:
*-------------------------------------------------------------------------
*/
static int
-check_objects(const char* fname, pack_opt_t *options)
+check_objects(const char *fname, pack_opt_t *options)
{
hid_t fid = H5I_INVALID_HID;
hid_t did = H5I_INVALID_HID;
hid_t sid = H5I_INVALID_HID;
unsigned int i;
int ifil;
- trav_table_t *travt = NULL;
+ trav_table_t *travt = NULL;
int ret_value = 0;
/* nothing to do */
@@ -754,7 +761,7 @@ check_objects(const char* fname, pack_opt_t *options)
*-------------------------------------------------------------------------
*/
if ((fid = h5tools_fopen(fname, H5F_ACC_RDONLY, options->fin_fapl,
- (options->fin_fapl == H5P_DEFAULT) ? FALSE : TRUE, NULL, 0)) < 0)
+ (options->fin_fapl == H5P_DEFAULT) ? FALSE : TRUE, NULL, 0)) < 0)
H5TOOLS_GOTO_ERROR((-1), "h5tools_fopen failed <%s>: %s", fname, H5FOPENERROR);
/*-------------------------------------------------------------------------
@@ -780,8 +787,8 @@ check_objects(const char* fname, pack_opt_t *options)
HDprintf("Opening file. Searching %zu objects to modify ...\n", travt->nobjs);
for (i = 0; i < options->op_tbl->nelems; i++) {
- pack_info_t obj = options->op_tbl->objs[i];
- char* name = obj.path;
+ pack_info_t obj = options->op_tbl->objs[i];
+ char * name = obj.path;
if (options->verbose)
HDprintf(" <%s>", name);
@@ -789,7 +796,7 @@ check_objects(const char* fname, pack_opt_t *options)
/* the input object names are present in the file and are valid */
if (h5trav_getindext(name, travt) < 0)
H5TOOLS_GOTO_ERROR((-1), "%s Could not find <%s> in file <%s>. Exiting...\n",
- (options->verbose ? "\n" : ""), name, fname);
+ (options->verbose ? "\n" : ""), name, fname);
if (options->verbose)
HDprintf("...Found\n");
@@ -798,14 +805,13 @@ check_objects(const char* fname, pack_opt_t *options)
H5TOOLS_GOTO_ERROR((-1), "invalid filter");
/* check for extra filter conditions */
switch (obj.filter[ifil].filtn) {
- /* chunk size must be smaller than pixels per block */
- case H5Z_FILTER_SZIP:
- {
- int j;
- hsize_t csize = 1;
- unsigned ppb = obj.filter[ifil].cd_values[0];
- hsize_t dims[H5S_MAX_RANK];
- int rank;
+ /* chunk size must be smaller than pixels per block */
+ case H5Z_FILTER_SZIP: {
+ int j;
+ hsize_t csize = 1;
+ unsigned ppb = obj.filter[ifil].cd_values[0];
+ hsize_t dims[H5S_MAX_RANK];
+ int rank;
if (obj.chunk.rank > 0) {
rank = obj.chunk.rank;
@@ -836,18 +842,20 @@ check_objects(const char* fname, pack_opt_t *options)
}
} /* end case SZIP */
break;
- default:
- break;
+ default:
+ break;
} /* end switch */
- } /* for ifil (each user-defined filter) */
- } /* for i (each object in options traversal table) */
+ } /* for ifil (each user-defined filter) */
+ } /* for i (each object in options traversal table) */
done:
- H5E_BEGIN_TRY {
+ H5E_BEGIN_TRY
+ {
H5Sclose(sid);
H5Dclose(did);
H5Fclose(fid);
- } H5E_END_TRY;
+ }
+ H5E_END_TRY;
if (travt)
trav_table_free(travt);
return ret_value;
@@ -901,4 +909,3 @@ get_sfilter(H5Z_filter_t filtn)
else
return "UD";
} /* end get_sfilter() */
-