From 1070468dac5d0fd5e02b69514d7a0dfacfd28606 Mon Sep 17 00:00:00 2001 From: Jacob Smith Date: Mon, 23 Sep 2019 16:25:25 -0500 Subject: Change print calls to HD-wrapped. Minor formatting tweaks (inc. regressions and in-file style-matching). --- test/external.c | 5 ++- tools/src/h5repack/h5repack.c | 63 ++++++++++++++++++------------------ tools/src/h5repack/h5repack_copy.c | 66 +++++++++++++++++++++----------------- 3 files changed, 70 insertions(+), 64 deletions(-) diff --git a/test/external.c b/test/external.c index 56cc816..50d94ab 100644 --- a/test/external.c +++ b/test/external.c @@ -457,8 +457,7 @@ test_multiple_files(hid_t file) TESTING("multiple external files"); - dcpl = H5Pcreate(H5P_DATASET_CREATE); - if(dcpl < 0) + if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) FAIL_STACK_ERROR max_ext_size = (hsize_t)(sizeof(int) * max_size[0] / n_external_files); @@ -596,7 +595,7 @@ test_overflow(void) TESTING("address overflow in external files"); - if((dcpl = H5Pcreate (H5P_DATASET_CREATE)) < 0) + if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) FAIL_STACK_ERROR if(H5Pset_external(dcpl, "ext1.data", (off_t)0, H5F_UNLIMITED-1) < 0) FAIL_STACK_ERROR diff --git a/tools/src/h5repack/h5repack.c b/tools/src/h5repack/h5repack.c index d49a16b..f12c3b4 100644 --- a/tools/src/h5repack/h5repack.c +++ b/tools/src/h5repack/h5repack.c @@ -382,7 +382,8 @@ copy_attr( */ 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"); if (H5Aget_name(attr_id, (size_t) 255, name) < 0) @@ -504,7 +505,7 @@ copy_attr( } /*H5T_REFERENCE*/ if (options->verbose) - printf(FORMAT_OBJ_ATTR, "attr", name); + HDprintf(FORMAT_OBJ_ATTR, "attr", name); /*--------------------------------------------------------------------- * close @@ -567,7 +568,7 @@ check_options(pack_opt_t *options) */ if (options->verbose && have_request(options)) { if (options->all_layout == 1) { - printf("All objects to modify layout are...\n"); + HDprintf("All objects to modify layout are...\n"); switch (options->layout_g) { case H5D_COMPACT: strcpy(slayout, "compact"); @@ -588,17 +589,17 @@ check_options(pack_opt_t *options) strcpy(slayout, "invalid layout\n"); HGOTO_DONE(FAIL); } - printf(" Apply %s layout to all", slayout); + HDprintf(" Apply %s layout to all", slayout); if (H5D_CHUNKED == options->layout_g) { - printf("with dimension [ "); + HDprintf("with dimension [ "); for (j = 0; j < options->chunk_g.rank; j++) - printf("%d ", (int) options->chunk_g.chunk_lengths[j]); - printf("]"); + HDprintf("%d ", (int) options->chunk_g.chunk_lengths[j]); + HDprintf("]"); } - printf("\n"); + HDprintf("\n"); } else - printf("No all objects to modify layout\n"); + HDprintf("No all objects to modify layout\n"); } /* end if verbose */ for (i = 0; i < options->op_tbl->nelems; i++) { @@ -606,16 +607,16 @@ check_options(pack_opt_t *options) if (options->op_tbl->objs[i].chunk.rank > 0) { if (options->verbose) { - printf(" <%s> with chunk size ", name); + HDprintf(" <%s> with chunk size ", name); for (k = 0; k < options->op_tbl->objs[i].chunk.rank; k++) - printf("%d ", (int)options->op_tbl->objs[i].chunk.chunk_lengths[k]); - printf("\n"); + HDprintf("%d ", (int)options->op_tbl->objs[i].chunk.chunk_lengths[k]); + HDprintf("\n"); } has_ck = 1; } else if (options->op_tbl->objs[i].chunk.rank == -2) { /* TODO: replace 'magic number' */ if (options->verbose) - printf(" <%s> %s\n", name, "NONE (contiguous)"); + HDprintf(" <%s> %s\n", name, "NONE (contiguous)"); has_ck = 1; } } /* end for each object in options */ @@ -631,35 +632,35 @@ check_options(pack_opt_t *options) if (options->verbose && have_request(options)) { if (options->all_filter == 1) { - printf("All objects to apply filter are...\n"); + HDprintf("All objects to apply filter are...\n"); for (k = 0; k < options->n_filter_g; k++) { H5Z_filter_t filtn = options->filter_g[k].filtn; if (filtn < 0) { - printf(" Unknown\n"); + HDprintf(" Unknown\n"); continue; } switch (filtn) { case H5Z_FILTER_NONE: - printf(" Uncompress all\n"); + HDprintf(" Uncompress all\n"); break; case H5Z_FILTER_SHUFFLE: case H5Z_FILTER_FLETCHER32: - printf(" All with %s\n", get_sfilter(filtn)); + HDprintf(" All with %s\n", get_sfilter(filtn)); break; case H5Z_FILTER_SZIP: case H5Z_FILTER_DEFLATE: - printf(" All with %s, parameter %d\n", + HDprintf(" All with %s, parameter %d\n", get_sfilter(filtn), options->filter_g[k].cd_values[0]); break; default: - printf(" User Defined %d\n", filtn); + HDprintf(" User Defined %d\n", filtn); break; } /* end switch */ } /* end for each filter */ } /* end if options->all_filter == 1 (TODO: meaning) */ else - printf("No all objects to apply filter\n"); + HDprintf("No all objects to apply filter\n"); } /* end if verbose */ for (i = 0; i < options->op_tbl->nelems; i++) { @@ -669,15 +670,16 @@ 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) - printf(" <%s> with %s filter %d\n", - name, + 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 - printf(" <%s> with %s filter\n", + } + else { + HDprintf(" <%s> with %s filter\n", name, get_sfilter(pack.filter[j].filtn)); + } } } has_cp = 1; @@ -714,7 +716,7 @@ check_options(pack_opt_t *options) */ if (options->ublock_filename != NULL && options->ublock_size == 0) { if (options->verbose) { - printf("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; } } @@ -787,15 +789,14 @@ check_objects(const char* fname, pack_opt_t *options) */ if (options->verbose) - printf("Opening file. Searching %zu objects to modify ...\n", - travt->nobjs); + 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; if (options->verbose) - printf(" <%s>", name); + HDprintf(" <%s>", name); /* the input object names are present in the file and are valid */ if (h5trav_getindext(name, travt) < 0) @@ -803,7 +804,7 @@ check_objects(const char* fname, pack_opt_t *options) "%s Could not find <%s> in file <%s>. Exiting...\n", (options->verbose ? "\n" : ""), name, fname); if (options->verbose) - printf("...Found\n"); + HDprintf("...Found\n"); for (ifil = 0; ifil < obj.nfilters; ifil++) { if (obj.filter[ifil].filtn < 0) @@ -849,7 +850,7 @@ check_objects(const char* fname, pack_opt_t *options) } /* end else (chunk rank is 0) */ if (csize < ppb) { - printf(" \n"); + HDprintf(" \n"); HGOTO_DONE(0); } } /* end case SZIP */ diff --git a/tools/src/h5repack/h5repack_copy.c b/tools/src/h5repack/h5repack_copy.c index 5939df4..07defa5 100644 --- a/tools/src/h5repack/h5repack_copy.c +++ b/tools/src/h5repack/h5repack_copy.c @@ -296,7 +296,7 @@ print_user_block(fnamein, fidin); *------------------------------------------------------------------------- */ if (options->verbose) - printf("Making new file ...\n"); + HDprintf("Making new file ...\n"); if ((fidout = H5Fcreate(fnameout, H5F_ACC_TRUNC, fcpl, fapl)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Fcreate could not create file <%s>:", fnameout); @@ -625,9 +625,9 @@ do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, */ if (options->verbose) { - printf("-----------------------------------------\n"); - printf(" Type Filter (Compression) Name\n"); - printf("-----------------------------------------\n"); + HDprintf("-----------------------------------------\n"); + HDprintf(" Type Filter (Compression) Name\n"); + HDprintf("-----------------------------------------\n"); } if (travt->objs) { @@ -646,7 +646,7 @@ do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, */ case H5TRAV_TYPE_GROUP: if (options->verbose) - printf(FORMAT_OBJ, "group", travt->objs[i].name); + HDprintf(FORMAT_OBJ, "group", travt->objs[i].name); /* open input group */ if ((grp_in = H5Gopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) @@ -782,17 +782,6 @@ 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 the input dataset has external storage, it must be contiguous. - * Accordingly, there would be no filter or chunk properties to preserve. - */ - 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"); - } 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); @@ -801,6 +790,20 @@ 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]; @@ -844,12 +847,14 @@ 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_s) { if (apply_filters( travt->objs[i].name, rank, @@ -860,6 +865,7 @@ do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, &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 */ @@ -916,7 +922,7 @@ do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, H5E_tools_min_id_g, "H5Dcreate2 failed"); if (options->verbose) - printf(" warning: could not create dataset <%s>. Applying original settings\n", + HDprintf(" warning: could not create dataset <%s>. Applying original settings\n", travt->objs[i].name); dset_out = H5Dcreate2(fidout, travt->objs[i].name, @@ -1122,12 +1128,12 @@ do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, * (in case there was a filter) */ if (has_filter && apply_s == 0) - printf(" \n", + HDprintf(" \n", travt->objs[i].name, (int) options->min_comp); if (has_filter && apply_f == 0) - printf(" \n", travt->objs[i].name); + HDprintf(" \n", travt->objs[i].name); } /* end if verbose (print compression) */ /*------------------------------------------------------------------------- @@ -1201,7 +1207,7 @@ do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); if (options->verbose) - printf(FORMAT_OBJ, "dset", travt->objs[i].name); + HDprintf(FORMAT_OBJ, "dset", travt->objs[i].name); } /* end whether we have request for filter/chunking */ break; @@ -1212,7 +1218,7 @@ do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, */ case H5TRAV_TYPE_NAMED_DATATYPE: if (options->verbose) - printf(FORMAT_OBJ, "type", travt->objs[i].name); + HDprintf(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"); @@ -1251,13 +1257,13 @@ do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, case H5TRAV_TYPE_LINK: case H5TRAV_TYPE_UDLINK: if (options->verbose) - printf(FORMAT_OBJ, "link", travt->objs[i].name); + HDprintf(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); + HDprintf(FORMAT_OBJ, "link", travt->objs[i].name); break; default: @@ -1400,7 +1406,7 @@ print_dataset_info(hid_t dcpl_id, char *objname, double ratio, int pr) } /* end for each filter */ if (!pr) - printf(FORMAT_OBJ, "dset", objname); + HDprintf(FORMAT_OBJ, "dset", objname); else { char str[512], temp[512]; @@ -1408,7 +1414,7 @@ print_dataset_info(hid_t dcpl_id, char *objname, double ratio, int pr) HDstrcat(str, strfilter); sprintf(temp, " (%.3f:1)", ratio); HDstrcat(str, temp); - printf(FORMAT_OBJ, str, objname); + HDprintf(FORMAT_OBJ, str, objname); } } /* end print_dataset_info() */ @@ -1535,10 +1541,10 @@ print_user_block(const char *filename, hid_t fid) for (i = 0; i < nread; i++) { - printf("%c ", rbuf[i]); + HDprintf("%c ", rbuf[i]); } - printf("\n"); + HDprintf("\n"); if (nread < 0) { HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "nread < 0"); -- cgit v0.12