diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2019-10-02 17:43:56 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2019-10-02 17:43:56 (GMT) |
commit | e2c5f6dd2bed3a0fce3eed401a2762ef9033d816 (patch) | |
tree | ab384216bc22be13026036745cb4197f38fd0111 /tools/src/h5repack | |
parent | 322a347ac84d4c4a12c965802d87d162d6db99fd (diff) | |
download | hdf5-e2c5f6dd2bed3a0fce3eed401a2762ef9033d816.zip hdf5-e2c5f6dd2bed3a0fce3eed401a2762ef9033d816.tar.gz hdf5-e2c5f6dd2bed3a0fce3eed401a2762ef9033d816.tar.bz2 |
Whitespace and benign synchro changes
Diffstat (limited to 'tools/src/h5repack')
-rw-r--r-- | tools/src/h5repack/h5repack.c | 323 | ||||
-rw-r--r-- | tools/src/h5repack/h5repack_copy.c | 221 | ||||
-rw-r--r-- | tools/src/h5repack/h5repack_main.c | 372 |
3 files changed, 509 insertions, 407 deletions
diff --git a/tools/src/h5repack/h5repack.c b/tools/src/h5repack/h5repack.c index c18df6c..24f4e6c 100644 --- a/tools/src/h5repack/h5repack.c +++ b/tools/src/h5repack/h5repack.c @@ -41,7 +41,9 @@ static int have_request(pack_opt_t *options); * Return: 0, ok, -1, fail *------------------------------------------------------------------------- */ -int h5repack(const char* infile, const char* outfile, pack_opt_t *options) { +int +h5repack(const char* infile, const char* outfile, pack_opt_t *options) +{ /* check input */ if (check_options(options) < 0) return -1; @@ -55,7 +57,7 @@ int h5repack(const char* infile, const char* outfile, pack_opt_t *options) { return -1; return 0; -} +} /* end h5repack() */ /*------------------------------------------------------------------------- * Function: h5repack_init @@ -86,7 +88,7 @@ h5repack_init(pack_opt_t *options, int verbose, hbool_t latest) } return (options_table_init(&(options->op_tbl))); -} +} /* end h5repack_init() */ /*------------------------------------------------------------------------- * Function: h5repack_end @@ -95,9 +97,11 @@ h5repack_init(pack_opt_t *options, int verbose, hbool_t latest) *------------------------------------------------------------------------- */ -int h5repack_end(pack_opt_t *options) { +int +h5repack_end(pack_opt_t *options) +{ return options_table_free(options->op_tbl); -} +} /* end h5repack_end() */ /*------------------------------------------------------------------------- * Function: h5repack_addfilter @@ -138,7 +142,7 @@ h5repack_addfilter(const char *str, pack_opt_t *options) HDfree(obj_list); return 0; -} +} /* end h5repack_addfilter() */ /*------------------------------------------------------------------------- * Function: h5repack_addlayout @@ -175,7 +179,7 @@ h5repack_addlayout(const char *str, pack_opt_t *options) if (pack.layout == H5D_CHUNKED) { /* -2 means the NONE option, remove chunking and set the global layout to contiguous */ - if (pack.chunk.rank == -2) + if (pack.chunk.rank == -2) /* TODO: fix 'magic number' */ options->layout_g = H5D_CONTIGUOUS; /* otherwise set the global chunking type */ else { @@ -192,10 +196,10 @@ h5repack_addlayout(const char *str, pack_opt_t *options) HDfree(obj_list); ret_value = 0; - } + } /* end if obj_list exists */ return ret_value; -} +} /* end h5repack_addlayout() */ /* Note: The below copy_named_datatype(), named_datatype_free(), copy_attr() * were located in h5repack_copy.c as static prior to bugfix1726. @@ -215,8 +219,13 @@ h5repack_addlayout(const char *str, pack_opt_t *options) * to free the stack. *------------------------------------------------------------------------- */ -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) { +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) +{ named_dt_t *dt = *named_dt_head_p; /* Stack pointer */ named_dt_t *dt_ret = NULL; /* Datatype to return */ H5O_info_t oinfo; /* Object info of input dtype */ @@ -239,7 +248,8 @@ hid_t copy_named_datatype(hid_t type_in, hid_t fidout, if (travt->objs[i].type == H5TRAV_TYPE_NAMED_DATATYPE) { /* Push onto the stack */ if (NULL == (dt = (named_dt_t *)HDmalloc(sizeof(named_dt_t)))) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "buffer allocation failed failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "buffer allocation failed failed"); dt->next = *named_dt_head_p; *named_dt_head_p = dt; @@ -250,13 +260,14 @@ hid_t copy_named_datatype(hid_t type_in, hid_t fidout, /* Check if this type is the one requested */ if (oinfo.addr == dt->addr_in) { dt_ret = dt; - } /* end if */ - } /* end if */ - } /* end for */ - } /* end else */ + } + } /* end if named datatype */ + } /* 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. */ + * possible if the datatype was committed anonymously in the input file. + */ if (!dt_ret) { /* Push the new datatype onto the stack */ if (NULL == (dt_ret = (named_dt_t *)HDmalloc(sizeof(named_dt_t)))) @@ -267,31 +278,35 @@ hid_t copy_named_datatype(hid_t type_in, hid_t fidout, /* Update the address and id */ dt_ret->addr_in = oinfo.addr; dt_ret->id_out = -1; - } /* end if */ + } /* end if requested datatype not found */ /* If the requested datatype does not yet exist in the output file, copy it - * anonymously */ + * anonymously + */ if (dt_ret->id_out < 0) { if (options->use_native == 1) dt_ret->id_out = H5Tget_native_type(type_in, H5T_DIR_DEFAULT); else dt_ret->id_out = H5Tcopy(type_in); if (dt_ret->id_out < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_native_type-H5Tcopy failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "H5Tget_native_type-H5Tcopy failed"); if (H5Tcommit_anon(fidout, dt_ret->id_out, H5P_DEFAULT, H5P_DEFAULT) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tcommit_anon failed"); - } /* end if */ + } /* end if named datatype not yet in output file */ /* Set return value */ ret_value = dt_ret->id_out; - /* Increment the ref count on id_out, because the calling function will try to close it */ - if(H5Iinc_ref(ret_value) < 0) + /* Increment the ref count on id_out, because the calling function will try + * to close it. (TODO: fix scope envy) + */ + if (H5Iinc_ref(ret_value) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Iinc_ref failed"); done: return ret_value; -} /* end copy_named_datatype */ +} /* end copy_named_datatype() */ /*------------------------------------------------------------------------- * Function: named_datatype_free @@ -299,7 +314,9 @@ done: * Purpose: Frees the stack of named datatypes. *------------------------------------------------------------------------- */ -int named_datatype_free(named_dt_t **named_dt_head_p, int ignore_err) { +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; @@ -310,13 +327,13 @@ int named_datatype_free(named_dt_t **named_dt_head_p, int ignore_err) { dt = dt->next; HDfree(*named_dt_head_p); *named_dt_head_p = dt; - } /* end while */ + } ret_value = 0; done: return (ret_value); -} /* end named_datatype_free */ +} /* end named_datatype_free() */ /*------------------------------------------------------------------------- * Function: copy_attr @@ -330,8 +347,12 @@ 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) +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; hid_t attr_id = -1; /* attr ID */ @@ -361,14 +382,13 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, */ 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) + attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t) u, H5P_DEFAULT, H5P_DEFAULT); + if (attr_id < 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"); @@ -385,18 +405,19 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, /* 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 */ + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "copy_named_datatype failed"); + } if (H5Fclose(fidout) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Fclose failed"); - } /* end if */ + } /* end if datatype is committed and we have a traversal table */ else { if (options->use_native == 1) wtype_id = H5Tget_native_type(ftype_id, H5T_DIR_DEFAULT); else wtype_id = H5Tcopy(ftype_id); - } /* end else */ + } /* end else: uncommitted datatype and/or no traversal table */ /* get the dataspace handle */ if ((space_id = H5Aget_space(attr_id)) < 0) @@ -404,7 +425,8 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, /* 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"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "H5Sget_simple_extent_dims failed"); nelmts = 1; for (j = 0; j < rank; j++) @@ -413,12 +435,12 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, 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() - *------------------------------------------------------------------------- + /*--------------------------------------------------------------------- + * 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); @@ -429,7 +451,7 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, is_ref = (is_ref || (H5Tget_class(base_type) == H5T_REFERENCE)); if (H5Tclose(base_type) < 0) H5TOOLS_INFO(H5E_tools_min_id_g, "H5Tclose base_type failed"); - } + } /* end if type_class is variable length or array */ if (type_class == H5T_COMPOUND) { int nmembers = H5Tget_nmembers(wtype_id); @@ -444,13 +466,13 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, is_ref = 1; break; } - } /* for (j=0; i<nmembers; j++) */ - } /* if (type_class == H5T_COMPOUND) */ + } /* end for each member */ + } /* end if type_class is H5T_COMPOUND */ if (!is_ref) { - /*------------------------------------------------------------------------- + /*----------------------------------------------------------------- * read to memory - *------------------------------------------------------------------------- + *----------------------------------------------------------------- */ buf = (void *)HDmalloc((size_t)(nelmts * msize)); @@ -460,9 +482,9 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, 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) @@ -485,9 +507,9 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, if (options->verbose) HDprintf(FORMAT_OBJ_ATTR, "attr", name); - /*------------------------------------------------------------------------- + /*--------------------------------------------------------------------- * close - *------------------------------------------------------------------------- + *--------------------------------------------------------------------- */ if (H5Sclose(space_id) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); @@ -501,19 +523,18 @@ copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, if (H5Aclose(attr_id) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed"); attr_id = -1; - } /* for u */ + } /* for u (each attribute) */ done: H5E_BEGIN_TRY { if (buf) { - /* Check if we have VL data and string in the attribute's datatype that must - * be reclaimed */ + /* 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 */ + } H5Aclose(attr_out); H5Sclose(space_id); @@ -525,25 +546,27 @@ done: return ret_value; } /* end copy_attr() */ -/*------------------------------------------------------------------------- +/*----------------------------------------------------------------------------- * Function: check_options * * Purpose: print options, checks for invalid options * * Return: void, return -1 on error - *------------------------------------------------------------------------- + *----------------------------------------------------------------------------- */ -static int check_options(pack_opt_t *options) { +static int +check_options(pack_opt_t *options) +{ int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ unsigned int i; int k, j, has_cp = 0, has_ck = 0; char slayout[30]; /*------------------------------------------------------------------------- - * objects to layout - *------------------------------------------------------------------------- - */ - if (options->verbose && have_request(options) /* only print if requested */) { + * Objects to layout + *------------------------------------------------------------------------- + */ + if (options->verbose && have_request(options)) { if (options->all_layout == 1) { HDprintf("All objects to modify layout are...\n"); switch (options->layout_g) { @@ -577,7 +600,7 @@ static int check_options(pack_opt_t *options) { } else HDprintf("No all objects to modify layout\n"); - }/* verbose */ + } /* end if verbose */ for (i = 0; i < options->op_tbl->nelems; i++) { char* name = options->op_tbl->objs[i].path; @@ -591,22 +614,23 @@ static int check_options(pack_opt_t *options) { } has_ck = 1; } - else if (options->op_tbl->objs[i].chunk.rank == -2) { + else if (options->op_tbl->objs[i].chunk.rank == -2) { /* TODO: replace 'magic number' */ if (options->verbose) HDprintf(" <%s> %s\n", name, "NONE (contiguous)"); has_ck = 1; } - } + } /* end for each object in options */ if (options->all_layout == 1 && has_ck) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "invalid chunking input: 'all' option is present with other objects"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "invalid chunking input: 'all' option is present with other objects"); /*------------------------------------------------------------------------- - * objects to filter - *------------------------------------------------------------------------- - */ + * Objects to filter + *------------------------------------------------------------------------- + */ - if (options->verbose && have_request(options) /* only print if requested */) { + if (options->verbose && have_request(options)) { if (options->all_filter == 1) { HDprintf("All objects to apply filter are...\n"); for (k = 0; k < options->n_filter_g; k++) { @@ -630,12 +654,12 @@ static int check_options(pack_opt_t *options) { default: HDprintf(" User Defined %d\n", filtn); break; - } /* k */ - }; - } + } /* end switch */ + } /* end for each filter */ + } /* end if options->all_filter == 1 (TODO: meaning) */ else HDprintf("No all objects to apply filter\n"); - } /* verbose */ + } /* end if verbose */ for (i = 0; i < options->op_tbl->nelems; i++) { pack_info_t pack = options->op_tbl->objs[i]; @@ -643,39 +667,51 @@ static int check_options(pack_opt_t *options) { 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); - else - HDprintf(" <%s> with %s filter\n", name, get_sfilter(pack.filter[j].filtn)); + 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); + } + else { + HDprintf(" <%s> with %s filter\n", + name, + get_sfilter(pack.filter[j].filtn)); + } } } has_cp = 1; - } /* j */ - } /* i */ + } /* end for each filter */ + } /* end for each object in options table */ if (options->all_filter == 1 && has_cp) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "invalid compression input: 'all' option is present with other objects"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "invalid compression input: 'all' option is present with " \ + "other objects"); /*------------------------------------------------------------------------- - * check options for the latest format - *------------------------------------------------------------------------- - */ + * Check options for the latest format + *------------------------------------------------------------------------- + */ if (options->grp_compact < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "invalid maximum number of links to store as header messages"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "invalid maximum number of links to store as header messages"); if (options->grp_indexed < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "invalid minimum number of links to store in the indexed format"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "invalid minimum number of links to store in indexed format"); if (options->grp_indexed > options->grp_compact) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "minimum indexed size is greater than the maximum compact size"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "minimum indexed size is greater than maximum compact size"); for (i = 0; i < 8; i++) if (options->msg_size[i] < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "invalid shared message size"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "invalid shared message size"); - /*-------------------------------------------------------------------------------- - * verify new user userblock options; file name must be present - *--------------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------ + * Verify new user userblock options; file name must be present + *------------------------------------------------------------------------ + */ 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); @@ -684,37 +720,41 @@ static int check_options(pack_opt_t *options) { } if (options->ublock_filename == NULL && options->ublock_size != 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "file name missing for user block", options->ublock_filename); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "file name missing for user block", options->ublock_filename); - /*-------------------------------------------------------------------------------- - * verify alignment options; threshold is zero default but alignment not - *--------------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------ + * Verify alignment options; threshold is zero default but alignment not + *------------------------------------------------------------------------ + */ if (options->alignment == 0 && options->threshold != 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "alignment for H5Pset_alignment missing"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "alignment for H5Pset_alignment missing"); done: return ret_value; -} +} /* end check_options() */ /*------------------------------------------------------------------------- * Function: check_objects * - * Purpose: locate all HDF5 objects in the file and compare with user - * supplied list + * Purpose: Locate all HDF5 objects in the file and compare with user-supplied + * list. * * Return: 0, ok, -1 no *------------------------------------------------------------------------- */ -static int check_objects(const char* fname, pack_opt_t *options) { - int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ +static int +check_objects(const char* fname, pack_opt_t *options) +{ hid_t fid = -1; hid_t did = -1; hid_t sid = -1; unsigned int i; int ifil; trav_table_t *travt = NULL; + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ /* nothing to do */ if (options->op_tbl->nelems == 0) @@ -725,7 +765,8 @@ static int check_objects(const char* fname, pack_opt_t *options) { *------------------------------------------------------------------------- */ if ((fid = h5tools_fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT, NULL, NULL, 0)) < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "h5tools_fopen failed <%s>: %s", fname, H5FOPENERROR); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "h5tools_fopen failed <%s>: %s", fname, H5FOPENERROR); /*------------------------------------------------------------------------- * get the list of objects in the file @@ -734,7 +775,6 @@ static int check_objects(const char* fname, pack_opt_t *options) { /* Initialize indexing options */ h5trav_set_index(sort_by, sort_order); - /* init table */ trav_table_init(&travt); /* get the list of objects in the file */ @@ -750,65 +790,74 @@ static int 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++) { - char* name = options->op_tbl->objs[i].path; + pack_info_t obj = options->op_tbl->objs[i]; + char* name = obj.path; + if (options->verbose) HDprintf(" <%s>", name); /* the input object names are present in the file and are valid */ if (h5trav_getindext(name, travt) < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "%s Could not find <%s> in file <%s>. Exiting...\n", + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "%s Could not find <%s> in file <%s>. Exiting...\n", (options->verbose ? "\n" : ""), name, fname); if (options->verbose) HDprintf("...Found\n"); - for (ifil = 0; ifil < options->op_tbl->objs[i].nfilters; ifil++) { - if (options->op_tbl->objs[i].filter[ifil].filtn < 0) + for (ifil = 0; ifil < obj.nfilters; ifil++) { + if (obj.filter[ifil].filtn < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "invalid filter"); /* check for extra filter conditions */ - switch (options->op_tbl->objs[i].filter[ifil].filtn) { + 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 = options->op_tbl->objs[i].filter[ifil].cd_values[0]; + unsigned ppb = obj.filter[ifil].cd_values[0]; hsize_t dims[H5S_MAX_RANK]; int rank; - if (options->op_tbl->objs[i].chunk.rank > 0) { - rank = options->op_tbl->objs[i].chunk.rank; + if (obj.chunk.rank > 0) { + rank = obj.chunk.rank; for (j = 0; j < rank; j++) - csize *= options->op_tbl->objs[i].chunk.chunk_lengths[j]; + csize *= obj.chunk.chunk_lengths[j]; } else { if ((did = H5Dopen2(fid, name, H5P_DEFAULT)) < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "H5Dopen2 failed"); if ((sid = H5Dget_space(did)) < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "H5Dget_space failed"); if ((rank = H5Sget_simple_extent_ndims(sid)) < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "H5Sget_simple_extent_ndims failed"); HDmemset(dims, 0, sizeof dims); if (H5Sget_simple_extent_dims(sid, dims, NULL) < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "H5Sget_simple_extent_dims failed"); for (j = 0; j < rank; j++) csize *= dims[j]; if (H5Sclose(sid) < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "H5Sclose failed"); if (H5Dclose(did) < 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); - } + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, + "H5Dclose failed"); + } /* end else (chunk rank is 0) */ if (csize < ppb) { HDprintf(" <warning: SZIP settings, chunk size is smaller than pixels per block>\n"); HGOTO_DONE(0); } - } + } /* end case SZIP */ break; default: break; - } - } /* for ifil */ - } /* for i */ + } /* end switch */ + } /* for ifil (each user-defined filter) */ + } /* for i (each object in options traversal table) */ done: H5E_BEGIN_TRY { @@ -819,7 +868,7 @@ done: if (travt) trav_table_free(travt); return ret_value; -} +} /* end check_objects() */ /*------------------------------------------------------------------------- * Function: have_request @@ -829,14 +878,15 @@ done: * Return: 1 yes, 0 no *------------------------------------------------------------------------- */ -static int have_request(pack_opt_t *options) { +static int +have_request(pack_opt_t *options) +{ if (options->all_filter || options->all_layout || options->op_tbl->nelems) return 1; return 0; - -} +} /* end have_request() */ /*------------------------------------------------------------------------- * Function: get_sfilter @@ -846,8 +896,9 @@ static int have_request(pack_opt_t *options) { * Return: name of filter, exit on error *------------------------------------------------------------------------- */ - -static const char* get_sfilter(H5Z_filter_t filtn) { +static const char * +get_sfilter(H5Z_filter_t filtn) +{ if (filtn < 0) return NULL; else if (filtn == H5Z_FILTER_NONE) @@ -866,5 +917,5 @@ static const char* get_sfilter(H5Z_filter_t filtn) { return "SOFF"; else return "UD"; -} +} /* end get_sfilter() */ diff --git a/tools/src/h5repack/h5repack_copy.c b/tools/src/h5repack/h5repack_copy.c index 13adb7c..398d632 100644 --- a/tools/src/h5repack/h5repack_copy.c +++ b/tools/src/h5repack/h5repack_copy.c @@ -58,8 +58,8 @@ static void print_user_block(const char *filename, hid_t fid); * -1 no *------------------------------------------------------------------------- */ - -int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) +int +copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) { int ret_value = 0; hid_t fidin = -1; @@ -365,7 +365,7 @@ done: trav_table_free(travt); return ret_value; -} +} /* end copy_objects() */ /*------------------------------------------------------------------------- * Function: Get_hyperslab @@ -521,7 +521,7 @@ Get_hyperslab(hid_t dcpl_id, int rank_dset, hsize_t dims_dset[], done: return ret_value; -} +} /* end Get_hyperslab() */ /*------------------------------------------------------------------------- * Function: do_copy_objects @@ -577,7 +577,8 @@ done: *------------------------------------------------------------------------- */ -int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, +int +do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, pack_opt_t *options) /* repack options */ { int ret_value = 0; @@ -677,7 +678,11 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, } 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) + 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) @@ -777,8 +782,6 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, 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); @@ -787,6 +790,20 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, if (H5Dget_space_status(dset_in, &space_status) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space_status failed"); + /* If the input dataset has external storage, it must be contiguous. + * Accordingly, there would be no filter or chunk properties to preserve, + * so create a new DCPL. + * Otherwise, copy dcpl_in. + */ + if (H5Pget_external_count(dcpl_in)) { + if ((dcpl_out = H5Pcreate(H5P_DATASET_CREATE)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pcreate failed"); + } + else + if ((dcpl_out = H5Pcopy(dcpl_in)) < 0) { + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pcopy failed"); + } + nelmts = 1; for (j = 0; j < rank; j++) nelmts *= dims[j]; @@ -797,7 +814,7 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, wtype_id = H5Tget_native_type(ftype_id, H5T_DIR_DEFAULT); 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"); @@ -830,18 +847,29 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, * 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) + 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) + 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) + 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 @@ -861,14 +889,14 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, /* 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); - } + } /* end if not chunked */ + } /* end if layout change requested for entire file or individual object */ /*------------------------------------------------------------------------- * create the output dataset; @@ -876,16 +904,39 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, * 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) - HDprintf(" 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) + dset_out = H5Dcreate2(fidout, + travt->objs[i].name, + wtype_id, + f_space_id, + H5P_DEFAULT, + dcpl_out, + H5P_DEFAULT); + /* if unable to create, retry with original DCPL */ + if (dset_out < 0) { + 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) { + HDprintf(" warning: could not create dataset <%s>. Applying original settings\n", + travt->objs[i].name); + } + dset_out = H5Dcreate2( + fidout, + travt->objs[i].name, + wtype_id, + f_space_id, + H5P_DEFAULT, + dcpl_in, + H5P_DEFAULT); + if (dset_out < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dcreate2 failed"); apply_f = 0; - } + } /* end if retry dataset create */ /*------------------------------------------------------------------------- * read/write @@ -909,8 +960,8 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, 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"); - /* free */ - if (buf != NULL) { + + if (buf != NULL) { /* TODO: is buf potentially released by H5Dvlen_reclaim()? */ HDfree(buf); buf = NULL; } @@ -946,17 +997,25 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, dset_layout = H5Pget_layout(dcpl_out); if (dset_layout == H5D_CHUNKED) dcpl_tmp = dcpl_out; /* writing dataset */ - else { /* if reading dataset is chunked */ + else { 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) + 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); + if (hslab_buf == NULL) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "can't allocate space for hyperslab"); hslab_nelmts = hslab_nbytes / p_type_nbytes; hslab_space = H5Screate_simple(1, &hslab_nelmts, NULL); @@ -974,28 +1033,57 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, */ 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.*/ + * "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) + 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) + 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"); - } + } /* end if rank > 0 */ else { H5Sselect_all(f_space_id); H5Sselect_all(hslab_space); hs_select_nelmts = 1; - } /* rank */ - - if(H5Dread(dset_in, wtype_id, hslab_space, f_space_id, H5P_DEFAULT, hslab_buf) < 0) + } /* end (else) rank == 0 */ + + if (H5Dread( + dset_in, + wtype_id, + hslab_space, + f_space_id, + H5P_DEFAULT, + hslab_buf) + < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed"); - if(H5Dwrite(dset_out, wtype_id, hslab_space, f_space_id, H5P_DEFAULT, hslab_buf) < 0) + if (H5Dwrite( + dset_out, + wtype_id, + hslab_space, + f_space_id, + H5P_DEFAULT, + hslab_buf) + < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dwrite failed"); - /* reclaim any VL memory, if necessary */ if (vl_data) H5Dvlen_reclaim(wtype_id, hslab_space, H5P_DEFAULT, hslab_buf); @@ -1007,20 +1095,19 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, hs_sel_offset[k - 1] = 0; else carry = 0; - } /* k */ - } /* elmtno */ + } + } /* end for (hyperslab selection loop) */ 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) */ + } /* end if reading/writing by hyperslab */ + } /* end if (nelmts > 0 && space_status != H5D_SPACE_STATUS_NOT_ALLOCATED) */ /*------------------------------------------------------------------------- - * amount of compression used + * print amount of compression used *------------------------------------------------------------------------- */ if (options->verbose) { @@ -1040,14 +1127,17 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, 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) + * (in case there was a filter) */ - if (has_filter && apply_s == 0) - HDprintf(" <warning: filter not applied to %s. dataset smaller than %d bytes>\n", travt->objs[i].name, (int) options->min_comp); + if (has_filter && apply_s == 0) { + HDprintf(" <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) HDprintf(" <warning: could not apply the filter to %s>\n", travt->objs[i].name); - } /* verbose */ + } /* end if verbose (print compression) */ /*------------------------------------------------------------------------- * copy attrs @@ -1056,14 +1146,13 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, 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*/ + } /* end if not a reference */ + } /* end if h5tools_canreadf (filter availability check) */ /*------------------------------------------------------------------------- - * close + * Close *------------------------------------------------------------------------- */ if (H5Tclose(ftype_id) < 0) @@ -1080,7 +1169,7 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); } /*------------------------------------------------------------------------- - * we do not have request for filter/chunking use H5Ocopy instead + * We do not have request for filter/chunking; use H5Ocopy instead *------------------------------------------------------------------------- */ else { @@ -1094,11 +1183,6 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, 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 */ @@ -1107,12 +1191,11 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, 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 + * Copy attrs manually *------------------------------------------------------------------------- */ if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) @@ -1129,7 +1212,7 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, if (options->verbose) HDprintf(FORMAT_OBJ, "dset", travt->objs[i].name); - } /* end do we have request for filter/chunking */ + } /* end whether we have request for filter/chunking */ break; /*------------------------------------------------------------------------- @@ -1189,8 +1272,8 @@ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, default: HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Object type not found"); } /* switch */ - } /* end for */ - } /* end if */ + } /* end for each object to traverse */ + } /* end if there are objects */ done: @@ -1228,7 +1311,7 @@ done: HDfree(hslab_buf); return ret_value; -} +} /* end do_copy_objects() */ /*------------------------------------------------------------------------- * Function: print_dataset_info @@ -1322,8 +1405,8 @@ print_dataset_info(hid_t dcpl_id, char *objname, double ratio, int pr) default: HDstrcat(strfilter, "UD "); break; - } /* switch */ - }/*i*/ + } /* end switch */ + } /* end for each filter */ if (!pr) HDprintf(FORMAT_OBJ, "dset", objname); @@ -1336,7 +1419,7 @@ print_dataset_info(hid_t dcpl_id, char *objname, double ratio, int pr) HDstrcat(str, temp); HDprintf(FORMAT_OBJ, str, objname); } -} +} /* end print_dataset_info() */ /*------------------------------------------------------------------------- * Function: copy_user_block @@ -1406,7 +1489,7 @@ done: HDclose(outfid); return ret_value; -} +} /* end copy_user_block() */ /*------------------------------------------------------------------------- * Function: print_user_block @@ -1479,6 +1562,6 @@ done: HDclose(fh); return; -} +} /* end print_user_block() */ #endif diff --git a/tools/src/h5repack/h5repack_main.c b/tools/src/h5repack/h5repack_main.c index dec25f9..8c887a2 100644 --- a/tools/src/h5repack/h5repack_main.c +++ b/tools/src/h5repack/h5repack_main.c @@ -23,7 +23,8 @@ static void leave(int ret) H5_ATTR_NORETURN; /* module-scoped variables */ -static int has_i_o = 0; +static int has_i = 0; +static int has_o = 0; const char *infile = NULL; const char *outfile = NULL; @@ -33,34 +34,34 @@ const char *outfile = NULL; */ static const char *s_opts = "hVvf:l:m:e:nLj:k:c:d:s:u:b:M:t:a:i:o:S:P:T:G:q:z: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' }, - { "low", require_arg, 'j' }, - { "high", require_arg, 'k' }, - { "compact", require_arg, 'c' }, - { "indexed", require_arg, 'd' }, - { "ssize", require_arg, 's' }, - { "ublock", require_arg, 'u' }, - { "block", require_arg, 'b' }, + { "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' }, + { "low", require_arg, 'j' }, + { "high", require_arg, 'k' }, + { "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 */ - { "fs_strategy", require_arg, 'S' }, - { "fs_persist", require_arg, 'P' }, - { "fs_threshold", require_arg, 'T' }, - { "fs_pagesize", require_arg, 'G' }, - { "sort_by", require_arg, 'q' }, - { "sort_order", require_arg, 'z' }, - { "enable-error-stack", no_arg, 'E' }, + { "threshold", require_arg, 't' }, + { "alignment", require_arg, 'a' }, + { "infile", require_arg, 'i' }, /* for backward compability */ + { "outfile", require_arg, 'o' }, /* for backward compability */ + { "fs_strategy", require_arg, 'S' }, + { "fs_persist", require_arg, 'P' }, + { "fs_threshold", require_arg, 'T' }, + { "fs_pagesize", require_arg, 'G' }, + { "sort_by", require_arg, 'q' }, + { "sort_order", require_arg, 'z' }, + { "enable-error-stack", no_arg, 'E' }, { NULL, 0, '\0' } }; @@ -83,13 +84,17 @@ static void usage(const char *prog) { 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, " --enable-error-stack Prints messages from the HDF5 error stack as they occur\n"); + PRINTVALSTREAM(rawoutstream, " --enable-error-stack Prints messages from the HDF5 error stack as they\n"); + PRINTVALSTREAM(rawoutstream, " occur\n"); PRINTVALSTREAM(rawoutstream, " -L, --latest Use latest version of file format\n"); - PRINTVALSTREAM(rawoutstream, " This option will take precedence over the -j and -k options\n"); - PRINTVALSTREAM(rawoutstream, " --low=BOUND The low bound for library release versions to use when creating\n"); - PRINTVALSTREAM(rawoutstream, " objects in the file (default is H5F_LIBVER_EARLIEST)\n"); - PRINTVALSTREAM(rawoutstream, " --high=BOUND The high bound for library release versions to use when creating\n"); - PRINTVALSTREAM(rawoutstream, " objects in the file (default is H5F_LIBVER_LATEST)\n"); + PRINTVALSTREAM(rawoutstream, " This option will take precedence over the options\n"); + PRINTVALSTREAM(rawoutstream, " --low and --high\n"); + PRINTVALSTREAM(rawoutstream, " --low=BOUND The low bound for library release versions to use\n"); + PRINTVALSTREAM(rawoutstream, " when creating objects in the file\n"); + PRINTVALSTREAM(rawoutstream, " (default is H5F_LIBVER_EARLIEST)\n"); + PRINTVALSTREAM(rawoutstream, " --high=BOUND The high bound for library release versions to use\n"); + PRINTVALSTREAM(rawoutstream, " when creating objects in the file\n"); + PRINTVALSTREAM(rawoutstream, " (default is H5F_LIBVER_LATEST)\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"); @@ -104,10 +109,14 @@ static void usage(const char *prog) { PRINTVALSTREAM(rawoutstream, " -z Z, --sort_order=Z Sort groups and attributes by order Z\n"); PRINTVALSTREAM(rawoutstream, " -f FILT, --filter=FILT Filter type\n"); PRINTVALSTREAM(rawoutstream, " -l LAYT, --layout=LAYT Layout type\n"); - PRINTVALSTREAM(rawoutstream, " -S FS_STRATEGY, --fs_strategy=FS_STRATEGY File space management strategy for H5Pset_file_space_strategy\n"); - PRINTVALSTREAM(rawoutstream, " -P FS_PERSIST, --fs_persist=FS_PERSIST Persisting or not persisting free-space for H5Pset_file_space_strategy\n"); - PRINTVALSTREAM(rawoutstream, " -T FS_THRESHOLD, --fs_threshold=FS_THRESHOLD Free-space section threshold for H5Pset_file_space_strategy\n"); - PRINTVALSTREAM(rawoutstream, " -G FS_PAGESIZE, --fs_pagesize=FS_PAGESIZE File space page size for H5Pset_file_space_page_size\n"); + PRINTVALSTREAM(rawoutstream, " -S FS_STRATEGY, --fs_strategy=FS_STRATEGY File space management strategy for\n"); + PRINTVALSTREAM(rawoutstream, " H5Pset_file_space_strategy\n"); + PRINTVALSTREAM(rawoutstream, " -P FS_PERSIST, --fs_persist=FS_PERSIST Persisting or not persisting free-\n"); + PRINTVALSTREAM(rawoutstream, " space for H5Pset_file_space_strategy\n"); + PRINTVALSTREAM(rawoutstream, " -T FS_THRESHOLD, --fs_threshold=FS_THRESHOLD Free-space section threshold\n"); + PRINTVALSTREAM(rawoutstream, " for H5Pset_file_space_strategy\n"); + PRINTVALSTREAM(rawoutstream, " -G FS_PAGESIZE, --fs_pagesize=FS_PAGESIZE File space page size for\n"); + PRINTVALSTREAM(rawoutstream, " H5Pset_file_space_page_size\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"); @@ -115,40 +124,50 @@ static void usage(const char *prog) { 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, " Q - is the sort index type for the input file. It can be \"name\" or \"creation_order\" (default)\n"); - PRINTVALSTREAM(rawoutstream, " Z - is the sort order type for the input file. It can be \"descending\" or \"ascending\" (default)\n"); + PRINTVALSTREAM(rawoutstream, " Q - is the sort index type for the input file. It can be \"name\" or\n"); + PRINTVALSTREAM(rawoutstream, " \"creation_order\" (default)\n"); + PRINTVALSTREAM(rawoutstream, " Z - is the sort order type for the input file. It can be \"descending\" or\n"); + PRINTVALSTREAM(rawoutstream, " \"ascending\" (default)\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, " BOUND is an integer indicating the library release versions to use when creating\n"); - PRINTVALSTREAM(rawoutstream, " objects in the file (see H5Pset_libver_bounds()):\n"); + PRINTVALSTREAM(rawoutstream, " BOUND is an integer indicating the library release versions to use when\n"); + PRINTVALSTREAM(rawoutstream, " creating objects in the file (see H5Pset_libver_bounds()):\n"); PRINTVALSTREAM(rawoutstream, " 0: This is H5F_LIBVER_EARLIEST in H5F_libver_t struct\n"); PRINTVALSTREAM(rawoutstream, " 1: This is H5F_LIBVER_V18 in H5F_libver_t struct\n"); PRINTVALSTREAM(rawoutstream, " 2: This is H5F_LIBVER_V110 in H5F_libver_t struct\n"); - PRINTVALSTREAM(rawoutstream, " (H5F_LIBVER_LATEST is aliased to H5F_LIBVER_V110 for this release\n"); + PRINTVALSTREAM(rawoutstream, " 3: This is H5F_LIBVER_V112 in H5F_libver_t struct\n"); + PRINTVALSTREAM(rawoutstream, " (H5F_LIBVER_LATEST is aliased to H5F_LIBVER_V112 for this release\n"); PRINTVALSTREAM(rawoutstream, "\n"); PRINTVALSTREAM(rawoutstream, " FS_STRATEGY is a string indicating the file space strategy used:\n"); PRINTVALSTREAM(rawoutstream, " FSM_AGGR:\n"); - PRINTVALSTREAM(rawoutstream, " The mechanisms used in managing file space are free-space managers, aggregators and virtual file driver.\n"); + PRINTVALSTREAM(rawoutstream, " The mechanisms used in managing file space are free-space\n"); + PRINTVALSTREAM(rawoutstream, " managers, aggregators and virtual file driver.\n"); PRINTVALSTREAM(rawoutstream, " PAGE:\n"); - PRINTVALSTREAM(rawoutstream, " The mechanisms used in managing file space are free-space managers with embedded paged aggregation and virtual file driver.\n"); + PRINTVALSTREAM(rawoutstream, " The mechanisms used in managing file space are free-space\n"); + PRINTVALSTREAM(rawoutstream, " managers with embedded paged aggregation and virtual file driver.\n"); PRINTVALSTREAM(rawoutstream, " AGGR:\n"); - PRINTVALSTREAM(rawoutstream, " The mechanisms used in managing file space are aggregators and virtual file driver.\n"); + PRINTVALSTREAM(rawoutstream, " The mechanisms used in managing file space are aggregators and\n"); + PRINTVALSTREAM(rawoutstream, " virtual file driver.\n"); PRINTVALSTREAM(rawoutstream, " NONE:\n"); - PRINTVALSTREAM(rawoutstream, " The mechanisms used in managing file space are virtual file driver.\n"); - PRINTVALSTREAM(rawoutstream, " The default strategy when not set is FSM_AGGR without persisting free-space.\n"); + PRINTVALSTREAM(rawoutstream, " The mechanisms used in managing file space are virtual file\n"); + PRINTVALSTREAM(rawoutstream, " driver.\n"); + PRINTVALSTREAM(rawoutstream, " The default strategy when not set is FSM_AGGR without persisting free-\n"); + PRINTVALSTREAM(rawoutstream, " space.\n"); PRINTVALSTREAM(rawoutstream, "\n"); PRINTVALSTREAM(rawoutstream, " FS_PERSIST is 1 to persisting free-space or 0 to not persisting free-space.\n"); PRINTVALSTREAM(rawoutstream, " The default when not set is not persisting free-space.\n"); PRINTVALSTREAM(rawoutstream, " The value is ignored for AGGR and NONE strategies.\n"); PRINTVALSTREAM(rawoutstream, "\n"); - PRINTVALSTREAM(rawoutstream, " FS_THRESHOLD is the minimum size (in bytes) of free-space sections to be tracked by the library.\n"); + PRINTVALSTREAM(rawoutstream, " FS_THRESHOLD is the minimum size (in bytes) of free-space sections to be\n"); + PRINTVALSTREAM(rawoutstream, " tracked by the library.\n"); PRINTVALSTREAM(rawoutstream, " The default when not set is 1.\n"); PRINTVALSTREAM(rawoutstream, " The value is ignored for AGGR and NONE strategies.\n"); PRINTVALSTREAM(rawoutstream, "\n"); - PRINTVALSTREAM(rawoutstream, " FS_PAGESIZE is the size (in bytes) >=512 that is used by the library when the file space strategy PAGE is used.\n"); + PRINTVALSTREAM(rawoutstream, " FS_PAGESIZE is the size (in bytes) >=512 that is used by the library when\n"); + PRINTVALSTREAM(rawoutstream, " the file space strategy PAGE is used.\n"); PRINTVALSTREAM(rawoutstream, " The default when not set is 4096.\n"); PRINTVALSTREAM(rawoutstream, "\n"); PRINTVALSTREAM(rawoutstream, " FILT - is a string with the format:\n"); @@ -176,9 +195,9 @@ static void usage(const char *prog) { 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,filter_flag,cd_value_count,value_1[,value_2,...,value_N]>\n"); - PRINTVALSTREAM(rawoutstream, " required values for filter_number,filter_flag,cd_value_count,value_1\n"); - PRINTVALSTREAM(rawoutstream, " optional values for value_2 to value_N\n"); + PRINTVALSTREAM(rawoutstream, " UD=<filter_number,filter_flag,cd_value_count,value1[,value2,...,valueN]>\n"); + PRINTVALSTREAM(rawoutstream, " Required values: filter_number, filter_flag, cd_value_count, value1\n"); + PRINTVALSTREAM(rawoutstream, " Optional values: value2 to valueN\n"); PRINTVALSTREAM(rawoutstream, " NONE (no parameter)\n"); PRINTVALSTREAM(rawoutstream, "\n"); PRINTVALSTREAM(rawoutstream, " LAYT - is a string with the format:\n"); @@ -215,12 +234,12 @@ static void usage(const char *prog) { 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, " minimum shared datatype size of 20\n"); PRINTVALSTREAM(rawoutstream, "\n"); PRINTVALSTREAM(rawoutstream, "5) h5repack --low=0 --high=1 file1 file2\n"); PRINTVALSTREAM(rawoutstream, "\n"); - PRINTVALSTREAM(rawoutstream, " Set low=H5F_LIBVER_EARLIEST and high=H5F_LIBVER_V18 via H5Pset_libver_bounds() when\n"); - PRINTVALSTREAM(rawoutstream, " creating the repacked file: file2\n"); + PRINTVALSTREAM(rawoutstream, " Set low=H5F_LIBVER_EARLIEST and high=H5F_LIBVER_V18 via\n"); + PRINTVALSTREAM(rawoutstream, " H5Pset_libver_bounds() when creating the repacked file, file2\n"); PRINTVALSTREAM(rawoutstream, "\n"); PRINTVALSTREAM(rawoutstream, "5) h5repack -f SHUF -f GZIP=1 file1 file2\n"); PRINTVALSTREAM(rawoutstream, "\n"); @@ -264,7 +283,7 @@ int read_info(const char *filename, pack_opt_t *options) int i, rc = 1; int ret_value = EXIT_SUCCESS; - if ((fp = HDfopen(filename, "r")) == (FILE *) NULL) { + if (NULL == (fp = HDfopen(filename, "r"))) { error_msg("cannot open options file %s\n", filename); h5tools_setstatus(EXIT_FAILURE); ret_value = EXIT_FAILURE; @@ -273,90 +292,46 @@ int read_info(const char *filename, pack_opt_t *options) /* cycle until end of file reached */ while (1) { - rc = fscanf(fp, "%s", stype); - if (rc == -1) - break; - - /*------------------------------------------------------------------------- - * filter - *------------------------------------------------------------------------- - */ - if (HDstrcmp(stype,"-f") == 0) { - /* find begining of info */ - i = 0; - c = '0'; - while (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 != ' ') { - 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)) - break; - if (c == 10 /*eol*/) - break; - } - comp_info[i - 1] = '\0'; /*cut the last " */ - if (h5repack_addfilter(comp_info, options) == -1) { - error_msg("could not add compression option\n"); + /* Info indicator must be for layout or filter */ + if (HDstrcmp(stype,"-l") && HDstrcmp(stype, "-f")) { + error_msg("bad file format for %s", filename); + h5tools_setstatus(EXIT_FAILURE); + ret_value = EXIT_FAILURE; + goto done; + } + + /* find begining of info */ + i = 0; + c = '0'; + while (c != ' ') { + if (fscanf(fp, "%c", &c) < 0 && HDferror(fp)) { + error_msg("fscanf error\n"); h5tools_setstatus(EXIT_FAILURE); ret_value = EXIT_FAILURE; goto done; } + if (HDfeof(fp)) + break; } - /*------------------------------------------------------------------------- - * layout - *------------------------------------------------------------------------- - */ - else if (HDstrcmp(stype,"-l") == 0) { - - /* find begining of info */ - i = 0; - c = '0'; - while (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 != ' ') { - 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)) - break; - if (c == 10 /*eol*/) - break; + c = '0'; + /* go until end */ + while (c != ' ') { + if (fscanf(fp, "%c", &c) < 0 && HDferror(fp)) { + error_msg("fscanf error\n"); + h5tools_setstatus(EXIT_FAILURE); + ret_value = EXIT_FAILURE; + goto done; } - comp_info[i - 1] = '\0'; /*cut the last " */ + comp_info[i++] = c; + if (HDfeof(fp)) + break; + if (c == 10 /*eol*/) + break; + } + comp_info[i - 1] = '\0'; /*cut the last " */ + if (!HDstrcmp(stype, "-l")) { if (h5repack_addlayout(comp_info, options) == -1) { error_msg("could not add chunck option\n"); h5tools_setstatus(EXIT_FAILURE); @@ -364,17 +339,15 @@ int read_info(const char *filename, pack_opt_t *options) goto done; } } - /*------------------------------------------------------------------------- - * not valid - *------------------------------------------------------------------------- - */ else { - error_msg("bad file format for %s", filename); - h5tools_setstatus(EXIT_FAILURE); - ret_value = EXIT_FAILURE; - goto done; + if (h5repack_addfilter(comp_info, options) == -1) { + error_msg("could not add compression option\n"); + h5tools_setstatus(EXIT_FAILURE); + ret_value = EXIT_FAILURE; + goto done; + } } - } + } /* end while info-read cycling */ done: if (fp) @@ -398,9 +371,9 @@ set_sort_by(const char *form) { H5_index_t idx_type = H5_INDEX_UNKNOWN; - if (HDstrcmp(form,"name")==0) /* H5_INDEX_NAME */ + if (!HDstrcmp(form, "name")) idx_type = H5_INDEX_NAME; - else if (HDstrcmp(form,"creation_order")==0) /* H5_INDEX_CRT_ORDER */ + else if (!HDstrcmp(form, "creation_order")) idx_type = H5_INDEX_CRT_ORDER; return idx_type; @@ -421,9 +394,9 @@ set_sort_order(const char *form) { H5_iter_order_t iter_order = H5_ITER_UNKNOWN; - if (HDstrcmp(form,"ascending")==0) /* H5_ITER_INC */ + if (!HDstrcmp(form, "ascending")) iter_order = H5_ITER_INC; - else if (HDstrcmp(form,"descending")==0) /* H5_ITER_DEC */ + else if (!HDstrcmp(form, "descending")) iter_order = H5_ITER_DEC; return iter_order; @@ -442,19 +415,19 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) int ret_value = 0; /* parse command line options */ - while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) { + while (EOF != (opt = get_option(argc, argv, s_opts, l_opts))) { switch ((char) opt) { /* -i for backward compatibility */ case 'i': infile = opt_arg; - has_i_o = 1; + has_i++; break; /* -o for backward compatibility */ case 'o': outfile = opt_arg; - has_i_o = 1; + has_o++; break; case 'h': @@ -519,7 +492,7 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) case 'j': options->low_bound = (H5F_libver_t)HDatoi(opt_arg); - if(options->low_bound < H5F_LIBVER_EARLIEST || options->low_bound > H5F_LIBVER_LATEST) { + if (options->low_bound < H5F_LIBVER_EARLIEST || options->low_bound > H5F_LIBVER_LATEST) { error_msg("in parsing low bound\n"); goto done; } @@ -527,7 +500,7 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) case 'k': options->high_bound = (H5F_libver_t)HDatoi(opt_arg); - if(options->high_bound < H5F_LIBVER_EARLIEST || options->high_bound > H5F_LIBVER_LATEST) { + if (options->high_bound < H5F_LIBVER_EARLIEST || options->high_bound > H5F_LIBVER_LATEST) { error_msg("in parsing high bound\n"); goto done; } @@ -549,10 +522,10 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) { int idx = 0; int ssize = 0; - char *msgPtr = HDstrchr( opt_arg, ':'); + char *msgPtr = HDstrchr(opt_arg, ':'); options->latest = TRUE; /* must use latest format */ if (msgPtr == NULL) { - ssize = HDatoi( opt_arg ); + ssize = HDatoi(opt_arg); for (idx = 0; idx < 5; idx++) options->msg_size[idx] = ssize; } @@ -562,15 +535,15 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) HDstrcpy(msgType, msgPtr + 1); msgPtr[0] = '\0'; ssize = HDatoi( opt_arg ); - if (HDstrncmp(msgType, "dspace",6) == 0) + if (!HDstrncmp(msgType, "dspace", 6)) options->msg_size[0] = ssize; - else if (HDstrncmp(msgType, "dtype", 5) == 0) + else if (!HDstrncmp(msgType, "dtype", 5)) options->msg_size[1] = ssize; - else if (HDstrncmp(msgType, "fill", 4) == 0) + else if (!HDstrncmp(msgType, "fill", 4)) options->msg_size[2] = ssize; - else if (HDstrncmp(msgType, "pline", 5) == 0) + else if (!HDstrncmp(msgType, "pline", 5)) options->msg_size[3] = ssize; - else if (HDstrncmp(msgType, "attr", 4) == 0) + else if (!HDstrncmp(msgType, "attr", 4)) options->msg_size[4] = ssize; } } @@ -607,13 +580,13 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) char strategy[MAX_NC_NAME]; HDstrcpy(strategy, opt_arg); - if(!HDstrcmp(strategy, "FSM_AGGR")) + if (!HDstrcmp(strategy, "FSM_AGGR")) options->fs_strategy = H5F_FSPACE_STRATEGY_FSM_AGGR; - else if(!HDstrcmp(strategy, "PAGE")) + else if (!HDstrcmp(strategy, "PAGE")) options->fs_strategy = H5F_FSPACE_STRATEGY_PAGE; - else if(!HDstrcmp(strategy, "AGGR")) + else if (!HDstrcmp(strategy, "AGGR")) options->fs_strategy = H5F_FSPACE_STRATEGY_AGGR; - else if(!HDstrcmp(strategy, "NONE")) + else if (!HDstrcmp(strategy, "NONE")) options->fs_strategy = H5F_FSPACE_STRATEGY_NONE; else { error_msg("invalid file space management strategy\n", opt_arg); @@ -621,7 +594,7 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) ret_value = -1; goto done; } - if(options->fs_strategy == (H5F_fspace_strategy_t)0) + if (options->fs_strategy == (H5F_fspace_strategy_t)0) /* To distinguish the "specified" zero value */ options->fs_strategy = (H5F_fspace_strategy_t)-1; } @@ -629,27 +602,27 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) case 'P': options->fs_persist = HDatoi(opt_arg); - if(options->fs_persist == 0) + if (options->fs_persist == 0) /* To distinguish the "specified" zero value */ options->fs_persist = -1; break; case 'T': options->fs_threshold = HDatol(opt_arg); - if(options->fs_threshold == 0) + if (options->fs_threshold == 0) /* To distinguish the "specified" zero value */ options->fs_threshold = -1; break; case 'G': options->fs_pagesize = HDstrtoll(opt_arg, NULL, 0); - if(options->fs_pagesize == 0) + if (options->fs_pagesize == 0) /* To distinguish the "specified" zero value */ options->fs_pagesize = -1; break; case 'q': - if((sort_by = set_sort_by(opt_arg)) < 0) { + if (H5_INDEX_UNKNOWN == set_sort_by(opt_arg)) { error_msg(" failed to set sort by form <%s>\n", opt_arg); h5tools_setstatus(EXIT_FAILURE); ret_value = -1; @@ -658,7 +631,7 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) break; case 'z': - if((sort_order = set_sort_order(opt_arg)) < 0) { + if (set_sort_order(opt_arg) == H5_ITER_UNKNOWN) { error_msg(" failed to set sort order form <%s>\n", opt_arg); h5tools_setstatus(EXIT_FAILURE); ret_value = -1; @@ -672,18 +645,35 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) default: break; - } /* switch */ - } /* while */ - - 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"); - usage(h5tools_getprogname()); - h5tools_setstatus(EXIT_FAILURE); - ret_value = -1; - } - } + } /* end switch */ + } /* end while there are more options to parse */ + + /* If neither -i nor -o given, get in and out files positionally */ + if (0 == (has_i + has_o)) { + if (argv[opt_ind] != NULL && argv[opt_ind + 1] != NULL) { + infile = argv[opt_ind]; + outfile = argv[opt_ind + 1]; + + if (!HDstrcmp(infile, outfile)) { + error_msg("file names cannot be the same\n"); + usage(h5tools_getprogname()); + h5tools_setstatus(EXIT_FAILURE); + ret_value = -1; + } + } + else { + error_msg("file names missing\n"); + usage(h5tools_getprogname()); + h5tools_setstatus(EXIT_FAILURE); + ret_value = -1; + } + } + else if (has_i != 1 || has_o != 1) { + error_msg("filenames must be either both -i -o or both positional\n"); + usage(h5tools_getprogname()); + h5tools_setstatus(EXIT_FAILURE); + ret_value = -1; + } done: return ret_value; @@ -740,28 +730,6 @@ int main(int argc, const char **argv) 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 > 0) { H5Eset_auto2(H5E_DEFAULT, func, edata); H5Eset_auto2(H5tools_ERR_STACK_g, tools_func, tools_edata); |