diff options
Diffstat (limited to 'tools/h5repack')
-rw-r--r-- | tools/h5repack/CMakeTests.cmake | 41 | ||||
-rw-r--r-- | tools/h5repack/h5repack.c | 512 | ||||
-rw-r--r-- | tools/h5repack/h5repack.h | 16 | ||||
-rw-r--r-- | tools/h5repack/h5repack_filters.c | 17 | ||||
-rw-r--r-- | tools/h5repack/h5repack_main.c | 60 | ||||
-rw-r--r-- | tools/h5repack/h5repack_opttable.c | 306 | ||||
-rw-r--r-- | tools/h5repack/h5repack_parse.c | 776 | ||||
-rw-r--r-- | tools/h5repack/h5repack_plugin.sh.in | 2 | ||||
-rw-r--r-- | tools/h5repack/h5repacktst.c | 194 | ||||
-rw-r--r-- | tools/h5repack/testfiles/h5repack_layout.h5-plugin_zero.tst | 9 |
10 files changed, 908 insertions, 1025 deletions
diff --git a/tools/h5repack/CMakeTests.cmake b/tools/h5repack/CMakeTests.cmake index d5379a4..d0aa6c8 100644 --- a/tools/h5repack/CMakeTests.cmake +++ b/tools/h5repack/CMakeTests.cmake @@ -121,19 +121,14 @@ ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/3_1_vds.h5-vds_chunk2x5x8-v.ddl ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/4_vds.h5-vds_compa-v.ddl ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/4_vds.h5-vds_conti-v.ddl + ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/h5repack_layout.h5-plugin_zero.tst ) foreach (h5_file ${LIST_HDF5_TEST_FILES} ${LIST_OTHER_TEST_FILES}) get_filename_component(fname "${h5_file}" NAME) - set (dest "${PROJECT_BINARY_DIR}/testfiles/${fname}") - #message (STATUS " Copying ${h5_file}") - add_custom_command ( - TARGET h5repack - POST_BUILD - COMMAND ${CMAKE_COMMAND} - ARGS -E copy_if_different ${h5_file} ${dest} - ) + HDFTEST_COPY_FILE("${h5_file}" "${PROJECT_BINARY_DIR}/testfiles/${fname}" "h5repack_files") endforeach (h5_file ${LIST_HDF5_TEST_FILES} ${LIST_OTHER_TEST_FILES}) + add_custom_target(h5repack_files ALL COMMENT "Copying files needed by h5repack tests" DEPENDS ${h5repack_files_list}) ############################################################################## ############################################################################## @@ -148,7 +143,7 @@ set_tests_properties (H5REPACK-${testname} PROPERTIES WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/testfiles") if (NOT "${last_test}" STREQUAL "") set_tests_properties (H5REPACK-${testname} PROPERTIES DEPENDS ${last_test}) - endif (NOT "${last_test}" STREQUAL "") + endif () set (last_test "H5REPACK-${testname}") else (HDF5_ENABLE_USING_MEMCHECKER) add_test ( @@ -187,7 +182,7 @@ ) if (NOT "${last_test}" STREQUAL "") set_tests_properties (H5REPACK_OLD-${testname} PROPERTIES DEPENDS ${last_test}) - endif (NOT "${last_test}" STREQUAL "") + endif () add_test ( NAME H5REPACK_OLD-${testname}_DFF COMMAND $<TARGET_FILE:h5diff> ${PROJECT_BINARY_DIR}/testfiles/${testfile} ${PROJECT_BINARY_DIR}/testfiles/out-${testname}.${testfile} @@ -211,7 +206,7 @@ ) if (NOT "${last_test}" STREQUAL "") set_tests_properties (H5REPACK-${testname} PROPERTIES DEPENDS ${last_test}) - endif (NOT "${last_test}" STREQUAL "") + endif () add_test ( NAME H5REPACK-${testname}_DFF COMMAND $<TARGET_FILE:h5diff> ${PROJECT_BINARY_DIR}/testfiles/${testfile} ${PROJECT_BINARY_DIR}/testfiles/out-${testname}.${testfile} @@ -250,7 +245,7 @@ endif (HDF5_ENABLE_USING_MEMCHECKER) if (NOT "${last_test}" STREQUAL "") set_tests_properties (H5REPACK_CMP-${testname} PROPERTIES DEPENDS ${last_test}) - endif (NOT "${last_test}" STREQUAL "") + endif () endif ("${testtype}" STREQUAL "SKIP") ENDMACRO (ADD_H5_CMP_TEST) @@ -284,7 +279,7 @@ endif (HDF5_ENABLE_USING_MEMCHECKER) if (NOT "${last_test}" STREQUAL "") set_tests_properties (H5REPACK_MASK-${testname} PROPERTIES DEPENDS ${last_test}) - endif (NOT "${last_test}" STREQUAL "") + endif () endif ("${testtype}" STREQUAL "SKIP") ENDMACRO (ADD_H5_MASK_TEST) @@ -303,7 +298,7 @@ COMMAND $<TARGET_FILE:h5repack> ${ARGN} ${PROJECT_BINARY_DIR}/testfiles/${resultfile} ${PROJECT_BINARY_DIR}/testfiles/out-${testname}.${resultfile}) if (NOT "${last_test}" STREQUAL "") set_tests_properties (H5REPACK_DMP-${testname} PROPERTIES DEPENDS ${last_test}) - endif (NOT "${last_test}" STREQUAL "") + endif () if (NOT HDF5_ENABLE_USING_MEMCHECKER) add_test ( NAME H5REPACK_DMP-h5dump-${testname} @@ -337,7 +332,7 @@ ) if (NOT "${last_test}" STREQUAL "") set_tests_properties (H5REPACK_VERIFY_LAYOUT-${testname} PROPERTIES DEPENDS ${last_test}) - endif (NOT "${last_test}" STREQUAL "") + endif () add_test ( NAME H5REPACK_VERIFY_LAYOUT-${testname}_DFF COMMAND $<TARGET_FILE:h5diff> ${PROJECT_BINARY_DIR}/testfiles/${testfile} ${PROJECT_BINARY_DIR}/testfiles/out-${testname}.${testfile} @@ -360,13 +355,13 @@ else ("${resultcode}" STREQUAL "0") if ("${testfilter}" STREQUAL "CHUNKED") set (nottestfilter "(CONTIGUOUS|COMPACT)") - endif ("${testfilter}" STREQUAL "CHUNKED") + endif () if ("${testfilter}" STREQUAL "CONTIGUOUS") set (nottestfilter "(CHUNK|COMPACT)") - endif ("${testfilter}" STREQUAL "CONTIGUOUS") + endif () if ("${testfilter}" STREQUAL "COMPACT") set (nottestfilter "(CONTIGUOUS|CHUNK)") - endif ("${testfilter}" STREQUAL "COMPACT") + endif () add_test ( NAME H5REPACK_VERIFY_LAYOUT-${testname}_DMP COMMAND "${CMAKE_COMMAND}" @@ -402,7 +397,7 @@ set_tests_properties (H5REPACK_VERIFY_LAYOUT_VDS-${testname} PROPERTIES WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/testfiles") if (NOT "${last_test}" STREQUAL "") set_tests_properties (H5REPACK_VERIFY_LAYOUT_VDS-${testname} PROPERTIES DEPENDS ${last_test}) - endif (NOT "${last_test}" STREQUAL "") + endif () add_test ( NAME H5REPACK_VERIFY_LAYOUT_VDS-${testname}_DMP COMMAND "${CMAKE_COMMAND}" @@ -427,7 +422,7 @@ ) if (NOT "${last_test}" STREQUAL "") set_tests_properties (H5REPACK_META-${testname}_N PROPERTIES DEPENDS ${last_test}) - endif (NOT "${last_test}" STREQUAL "") + endif () add_test ( NAME H5REPACK_META-${testname}_M COMMAND $<TARGET_FILE:h5repack> ${ARGN} ${PROJECT_BINARY_DIR}/testfiles/${testfile} ${PROJECT_BINARY_DIR}/testfiles/out-${testname}_M.${testname}.h5 @@ -1151,6 +1146,12 @@ ############################################################################## ADD_H5_UD_TEST (plugin_test 0 h5repack_layout.h5 -v -f UD=257,1,9) ADD_H5_UD_TEST (plugin_none 0 h5repack_layout.UD.h5 -v -f NONE) + # check for no parameters + set (TESTRETVAL 255) + if (WIN32) + set (TESTRETVAL -1) + endif() + ADD_H5_CMP_TEST (plugin_zero "" "TEST" ${TESTRETVAL} h5repack_layout.h5 -v -f UD=250,0) if (HDF5_TEST_VFD) # Run test with different Virtual File Driver diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c index cf30b2b..ef2085c 100644 --- a/tools/h5repack/h5repack.c +++ b/tools/h5repack/h5repack.c @@ -122,35 +122,36 @@ int h5repack_end(pack_opt_t *options) { * *------------------------------------------------------------------------- */ -int h5repack_addfilter(const char* str, pack_opt_t *options) { - obj_list_t *obj_list = NULL; /* one object list for the -f and -l option entry */ - filter_info_t filter; /* filter info for the current -f option entry */ - int n_objs; /* number of objects in the current -f or -l option entry */ - int is_glb; /* is the filter global */ - - /* parse the -f option */ - if (NULL == (obj_list = parse_filter(str, &n_objs, &filter, options, &is_glb))) - return -1; - - /* if it applies to all objects */ - if (is_glb) { - int n; - - n = options->n_filter_g++; /* increase # of global filters */ - - if (options->n_filter_g > H5_REPACK_MAX_NFILTERS) { - error_msg("maximum number of filters exceeded for <%s>\n", str); - HDfree(obj_list); - return -1; - } - - options->filter_g[n] = filter; - } - else - options_add_filter(obj_list, n_objs, filter, options->op_tbl); - - HDfree(obj_list); - return 0; +int +h5repack_addfilter(const char* str, pack_opt_t *options) +{ + obj_list_t *obj_list = NULL; /* one object list for the -f and -l option entry */ + filter_info_t filter; /* filter info for the current -f option entry */ + unsigned n_objs; /* number of objects in the current -f or -l option entry */ + int is_glb; /* is the filter global */ + + /* parse the -f option */ + if (NULL == (obj_list = parse_filter(str, &n_objs, &filter, options, &is_glb))) + return -1; + + /* if it applies to all objects */ + if (is_glb) { + int n; + + n = options->n_filter_g++; /* increase # of global filters */ + if (options->n_filter_g > H5_REPACK_MAX_NFILTERS) { + error_msg("maximum number of filters exceeded for <%s>\n", str); + HDfree(obj_list); + return -1; + } + + options->filter_g[n] = filter; + } + else + options_add_filter(obj_list, n_objs, filter, options->op_tbl); + + HDfree(obj_list); + return 0; } /*------------------------------------------------------------------------- @@ -162,59 +163,53 @@ int h5repack_addfilter(const char* str, pack_opt_t *options) { * *------------------------------------------------------------------------- */ - -int h5repack_addlayout(const char* str, pack_opt_t *options) { - - obj_list_t *obj_list = NULL; /*one object list for the -t and -c option entry */ - int n_objs; /*number of objects in the current -t or -c option entry */ - pack_info_t pack; /*info about layout to extract from parse */ - int j; - int ret_value = -1; - - init_packobject(&pack); - - if (options->all_layout == 1) { - error_msg( - "invalid layout input: 'all' option \ - is present with other objects <%s>\n", - str); - return ret_value; - } - - /* parse the layout option */ - obj_list = parse_layout(str, &n_objs, &pack, options); - if (obj_list) { - - /* set layout option */ - options->layout_g = pack.layout; - - /* no individual dataset specified */ - if (options->all_layout == 1) { - if (pack.layout == H5D_CHUNKED) { - /* -2 means the NONE option, remove chunking - and set the global layout to contiguous */ - if (pack.chunk.rank == -2) { - options->layout_g = H5D_CONTIGUOUS; - } - /* otherwise set the global chunking type */ - else { - options->chunk_g.rank = pack.chunk.rank; - for (j = 0; j < pack.chunk.rank; j++) - options->chunk_g.chunk_lengths[j] = - pack.chunk.chunk_lengths[j]; - } - } - } - - /* individual dataset specified */ - if (options->all_layout == 0) - ret_value = options_add_layout(obj_list, n_objs, &pack, options->op_tbl); - - HDfree(obj_list); - ret_value = 0; - } - - return ret_value; +int +h5repack_addlayout(const char* str, pack_opt_t *options) +{ + obj_list_t *obj_list = NULL; /*one object list for the -t and -c option entry */ + unsigned n_objs; /*number of objects in the current -t or -c option entry */ + pack_info_t pack; /*info about layout to extract from parse */ + int j; + int ret_value = -1; + + init_packobject(&pack); + + if (options->all_layout == 1) { + error_msg( "invalid layout input: 'all' option is present with other objects <%s>\n", str); + return ret_value; + } + + /* parse the layout option */ + obj_list = parse_layout(str, &n_objs, &pack, options); + if (obj_list) { + /* set layout option */ + options->layout_g = pack.layout; + + /* no individual dataset specified */ + if (options->all_layout == 1) { + if (pack.layout == H5D_CHUNKED) { + /* -2 means the NONE option, remove chunking + and set the global layout to contiguous */ + if (pack.chunk.rank == -2) + options->layout_g = H5D_CONTIGUOUS; + /* otherwise set the global chunking type */ + else { + options->chunk_g.rank = pack.chunk.rank; + for (j = 0; j < pack.chunk.rank; j++) + options->chunk_g.chunk_lengths[j] = pack.chunk.chunk_lengths[j]; + } + } + } + + /* individual dataset specified */ + if (options->all_layout == 0) + ret_value = options_add_layout(obj_list, n_objs, &pack, options->op_tbl); + + HDfree(obj_list); + ret_value = 0; + } + + return ret_value; } /* Note: The below copy_named_datatype(), named_datatype_free(), copy_attr() @@ -370,201 +365,201 @@ done: * *------------------------------------------------------------------------- */ -int copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, - trav_table_t *travt, pack_opt_t *options) { - int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ +int +copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, + trav_table_t *travt, pack_opt_t *options) +{ + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ hid_t attr_id = -1; /* attr ID */ - hid_t attr_out = -1; /* attr ID */ - hid_t space_id = -1; /* space ID */ - hid_t ftype_id = -1; /* file type ID */ - hid_t wtype_id = -1; /* read/write type ID */ - size_t msize; /* size of type */ - void *buf = NULL; /* data buffer */ - hsize_t nelmts; /* number of elements in dataset */ - int rank; /* rank of dataset */ - htri_t is_named; /* Whether the datatype is named */ - hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */ - char name[255]; - H5O_info_t oinfo; /* object info */ - int j; - unsigned u; - hbool_t is_ref = 0; - H5T_class_t type_class = -1; - - if (H5Oget_info(loc_in, &oinfo) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Oget_info failed"); - - /*------------------------------------------------------------------------- - * copy all attributes - *------------------------------------------------------------------------- - */ - for (u = 0; u < (unsigned) oinfo.num_attrs; u++) { - /* open attribute */ - if ((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, - H5_ITER_INC, (hsize_t) u, H5P_DEFAULT, H5P_DEFAULT)) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Aopen_by_idx failed"); - - /* get name */ - if (H5Aget_name(attr_id, (size_t) 255, name) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); - - /* get the file datatype */ - if ((ftype_id = H5Aget_type(attr_id)) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Aget_type failed"); - - /* Check if the datatype is committed */ - if ((is_named = H5Tcommitted(ftype_id)) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tcommitted failed"); + hid_t attr_out = -1; /* attr ID */ + hid_t space_id = -1; /* space ID */ + hid_t ftype_id = -1; /* file type ID */ + hid_t wtype_id = -1; /* read/write type ID */ + size_t msize; /* size of type */ + void *buf = NULL; /* data buffer */ + hsize_t nelmts; /* number of elements in dataset */ + int rank; /* rank of dataset */ + htri_t is_named; /* Whether the datatype is named */ + hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */ + char name[255]; + H5O_info_t oinfo; /* object info */ + int j; + unsigned u; + hbool_t is_ref = 0; + H5T_class_t type_class = -1; + + if (H5Oget_info(loc_in, &oinfo) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Oget_info failed"); + + /*------------------------------------------------------------------------- + * copy all attributes + *------------------------------------------------------------------------- + */ + for (u = 0; u < (unsigned) oinfo.num_attrs; u++) { + /* open attribute */ + if ((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t) u, H5P_DEFAULT, H5P_DEFAULT)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aopen_by_idx failed"); + + /* get name */ + if (H5Aget_name(attr_id, (size_t) 255, name) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + + /* get the file datatype */ + if ((ftype_id = H5Aget_type(attr_id)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type failed"); + + /* Check if the datatype is committed */ + if ((is_named = H5Tcommitted(ftype_id)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tcommitted failed"); if (is_named && travt) { - hid_t fidout; + hid_t fidout; - /* Create out file id */ - if ((fidout = H5Iget_file_id(loc_out)) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Iget_file_id failed"); + /* Create out file id */ + if ((fidout = H5Iget_file_id(loc_out)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Iget_file_id failed"); - /* Copy named dt */ - if ((wtype_id = copy_named_datatype(ftype_id, fidout, - named_dt_head_p, travt, options)) < 0) { - H5Fclose(fidout); - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "copy_named_datatype failed"); + /* Copy named dt */ + if ((wtype_id = copy_named_datatype(ftype_id, fidout, named_dt_head_p, travt, options)) < 0) { + H5Fclose(fidout); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_named_datatype failed"); } /* end if */ - if (H5Fclose(fidout) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Fclose failed"); + if (H5Fclose(fidout) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Fclose failed"); } /* end if */ - else { - if (options->use_native == 1) - wtype_id = h5tools_get_native_type(ftype_id); - else - wtype_id = H5Tcopy(ftype_id); - } /* end else */ - - /* get the dataspace handle */ - if ((space_id = H5Aget_space(attr_id)) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Aget_space failed"); - - /* get dimensions */ - if ((rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); - - nelmts = 1; - for (j = 0; j < rank; j++) - nelmts *= dims[j]; - - if ((msize = H5Tget_size(wtype_id)) == 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tget_size failed"); - - /*------------------------------------------------------------------------- - * object references are a special case. We cannot just copy the buffers, - * but instead we recreate the reference. - * This is done on a second sweep of the file that just copies the referenced - * objects at copy_refs_attr() - *------------------------------------------------------------------------- - */ - type_class = H5Tget_class(wtype_id); - is_ref = (type_class == H5T_REFERENCE); - if (type_class == H5T_VLEN || type_class == H5T_ARRAY) { - hid_t base_type = -1; - base_type = H5Tget_super(ftype_id); - is_ref = (is_ref || (H5Tget_class(base_type) == H5T_REFERENCE)); - H5Tclose(base_type); - } - - if (type_class == H5T_COMPOUND) { - int nmembers = H5Tget_nmembers(wtype_id); - for (j = 0; j < nmembers; j++) { - hid_t mtid = H5Tget_member_type(wtype_id, (unsigned) j); - H5T_class_t mtclass = H5Tget_class(mtid); - H5Tclose(mtid); - - if (mtclass == H5T_REFERENCE) { - is_ref = 1; - break; - } - } /* for (j=0; i<nmembers; j++) */ - } /* if (type_class == H5T_COMPOUND) */ - - if (is_ref) { - ; /* handled by copy_refs_attr() */ - } - else { - /*------------------------------------------------------------------------- - * read to memory - *------------------------------------------------------------------------- - */ - - buf = (void *) HDmalloc((size_t)(nelmts * msize)); - if (buf == NULL) { - error_msg("h5repack", "cannot read into memory\n"); - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "HDmalloc failed"); + else { + if (options->use_native == 1) + wtype_id = h5tools_get_native_type(ftype_id); + else + wtype_id = H5Tcopy(ftype_id); + } /* end else */ + + /* get the dataspace handle */ + if ((space_id = H5Aget_space(attr_id)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_space failed"); + + /* get dimensions */ + if ((rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); + + nelmts = 1; + for (j = 0; j < rank; j++) + nelmts *= dims[j]; + + if ((msize = H5Tget_size(wtype_id)) == 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); + + /*------------------------------------------------------------------------- + * object references are a special case. We cannot just copy the buffers, + * but instead we recreate the reference. + * This is done on a second sweep of the file that just copies the referenced + * objects at copy_refs_attr() + *------------------------------------------------------------------------- + */ + type_class = H5Tget_class(wtype_id); + is_ref = (type_class == H5T_REFERENCE); + if (type_class == H5T_VLEN || type_class == H5T_ARRAY) { + hid_t base_type = -1; + + base_type = H5Tget_super(ftype_id); + is_ref = (is_ref || (H5Tget_class(base_type) == H5T_REFERENCE)); + H5Tclose(base_type); + } + + if (type_class == H5T_COMPOUND) { + int nmembers = H5Tget_nmembers(wtype_id); + + for (j = 0; j < nmembers; j++) { + hid_t mtid = H5Tget_member_type(wtype_id, (unsigned) j); + H5T_class_t mtclass = H5Tget_class(mtid); + H5Tclose(mtid); + + if (mtclass == H5T_REFERENCE) { + is_ref = 1; + break; + } + } /* for (j=0; i<nmembers; j++) */ + } /* if (type_class == H5T_COMPOUND) */ + + if (is_ref) { + ; /* handled by copy_refs_attr() */ + } + else { + /*------------------------------------------------------------------------- + * read to memory + *------------------------------------------------------------------------- + */ + + buf = (void *) HDmalloc((size_t)(nelmts * msize)); + if (buf == NULL) { + error_msg("h5repack", "cannot read into memory\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ - if (H5Aread(attr_id, wtype_id, buf) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Aread failed"); + if (H5Aread(attr_id, wtype_id, buf) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed"); - /*------------------------------------------------------------------------- - * copy - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * copy + *------------------------------------------------------------------------- + */ - if ((attr_out = H5Acreate2(loc_out, name, wtype_id, space_id, - H5P_DEFAULT, H5P_DEFAULT)) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Acreate2 failed"); + if ((attr_out = H5Acreate2(loc_out, name, wtype_id, space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Acreate2 failed"); if (H5Awrite(attr_out, wtype_id, buf) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Awrite failed"); - - /*close*/ - if (H5Aclose(attr_out) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Aclose failed"); - - /* Check if we have VL data and string in the attribute's datatype that must - * be reclaimed */ - if (TRUE == h5tools_detect_vlen(wtype_id)) - H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf); - HDfree(buf); - buf = NULL; - } /*H5T_REFERENCE*/ - - if (options->verbose) - printf(FORMAT_OBJ_ATTR, "attr", name); - - /*------------------------------------------------------------------------- - * close - *------------------------------------------------------------------------- - */ - - if (H5Tclose(ftype_id) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Awrite failed"); + + /*close*/ + if (H5Aclose(attr_out) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed"); + + /* Check if we have VL data and string in the attribute's datatype that must + * be reclaimed */ + if (TRUE == h5tools_detect_vlen(wtype_id)) + H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf); + HDfree(buf); + buf = NULL; + } /*H5T_REFERENCE*/ + + if (options->verbose) + printf(FORMAT_OBJ_ATTR, "attr", name); + + /*------------------------------------------------------------------------- + * close + *------------------------------------------------------------------------- + */ + + if (H5Tclose(ftype_id) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); if (H5Tclose(wtype_id) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Tclose failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); if (H5Sclose(space_id) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if (H5Aclose(attr_id) < 0) - HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Aclose failed"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed"); } /* u */ - return 0; + return 0; done: - H5E_BEGIN_TRY - { - if (buf) { - /* Check if we have VL data and string in the attribute's datatype that must - * be reclaimed */ - if (TRUE == h5tools_detect_vlen(wtype_id)) - H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf); - - /* Free buf */ - HDfree(buf); - } /* end if */ + H5E_BEGIN_TRY { + if (buf) { + /* Check if we have VL data and string in the attribute's datatype that must + * be reclaimed */ + if (TRUE == h5tools_detect_vlen(wtype_id)) + H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf); + + /* Free buf */ + HDfree(buf); + } /* end if */ - H5Tclose(ftype_id); - H5Tclose(wtype_id); - H5Sclose(space_id); - H5Aclose(attr_id); - H5Aclose(attr_out); - } H5E_END_TRY; + H5Tclose(ftype_id); + H5Tclose(wtype_id); + H5Sclose(space_id); + H5Aclose(attr_id); + H5Aclose(attr_out); + } H5E_END_TRY; - return -1; + return ret_value; } /* end copy_attr() */ /*------------------------------------------------------------------------- @@ -606,6 +601,9 @@ static int check_options(pack_opt_t *options) { case H5D_CHUNKED: strcpy(slayout, "chunked"); break; + case H5D_VIRTUAL: + strcpy(slayout, "virtual"); + break; case H5D_LAYOUT_ERROR: case H5D_NLAYOUTS: error_msg("invalid layout\n"); diff --git a/tools/h5repack/h5repack.h b/tools/h5repack/h5repack.h index 329be1f..d2ab923 100644 --- a/tools/h5repack/h5repack.h +++ b/tools/h5repack/h5repack.h @@ -82,9 +82,9 @@ typedef struct { /* store a table of all objects */ typedef struct { - unsigned int size; - unsigned int nelems; - pack_info_t *objs; + unsigned int size; + unsigned int nelems; + pack_info_t *objs; } pack_opttbl_t; @@ -114,7 +114,7 @@ typedef struct { hsize_t ublock_size; /* user block size */ hsize_t meta_block_size; /* metadata aggregation block size (for H5Pset_meta_block_size) */ hsize_t threshold; /* alignment threshold for H5Pset_alignment */ - hsize_t alignment ; /* alignment for H5Pset_alignment */ + hsize_t alignment; /* alignment for H5Pset_alignment */ H5F_file_space_type_t fs_strategy; /* File space handling strategy */ hsize_t fs_threshold; /* Free space section threshold */ } pack_opt_t; @@ -210,11 +210,11 @@ int apply_filters(const char* name, /* object name from traverse list */ int options_table_init( pack_opttbl_t **tbl ); int options_table_free( pack_opttbl_t *table ); int options_add_layout( obj_list_t *obj_list, - int n_objs, + unsigned n_objs, pack_info_t *pack, pack_opttbl_t *table ); int options_add_filter ( obj_list_t *obj_list, - int n_objs, + unsigned n_objs, filter_info_t filt, pack_opttbl_t *table ); pack_info_t* options_get_object( const char *path, @@ -226,13 +226,13 @@ pack_info_t* options_get_object( const char *path, */ obj_list_t* parse_filter(const char *str, - int *n_objs, + unsigned *n_objs, filter_info_t *filt, pack_opt_t *options, int *is_glb); obj_list_t* parse_layout(const char *str, - int *n_objs, + unsigned *n_objs, pack_info_t *pack, /* info about object */ pack_opt_t *options); diff --git a/tools/h5repack/h5repack_filters.c b/tools/h5repack/h5repack_filters.c index 56e08ef..e21b829 100644 --- a/tools/h5repack/h5repack_filters.c +++ b/tools/h5repack/h5repack_filters.c @@ -34,8 +34,8 @@ * *------------------------------------------------------------------------- */ -static -int aux_find_obj(const char* name, /* object name from traverse list */ +static int +aux_find_obj(const char* name, /* object name from traverse list */ pack_opt_t *options, /* repack options */ pack_info_t *obj /*OUT*/) /* info about object to filter */ { @@ -48,7 +48,7 @@ int aux_find_obj(const char* name, /* object name from traverse list */ if (HDstrcmp(options->op_tbl->objs[i].path,name)==0) { *obj = options->op_tbl->objs[i]; - return i; + return (int)i; } pdest = HDstrstr(name,options->op_tbl->objs[i].path); @@ -58,7 +58,7 @@ int aux_find_obj(const char* name, /* object name from traverse list */ if( pdest != NULL && result==1 ) { *obj = options->op_tbl->objs[i]; - return i; + return (int)i; } }/*i*/ @@ -76,8 +76,8 @@ int aux_find_obj(const char* name, /* object name from traverse list */ * *------------------------------------------------------------------------- */ -static -int aux_assign_obj(const char* name, /* object name from traverse list */ +static int +aux_assign_obj(const char* name, /* object name from traverse list */ pack_opt_t *options, /* repack options */ pack_info_t *obj /*OUT*/) /* info about object to filter */ { @@ -109,6 +109,7 @@ int aux_assign_obj(const char* name, /* object name from traverse lis case H5D_LAYOUT_ERROR: case H5D_COMPACT: case H5D_CONTIGUOUS: + case H5D_VIRTUAL: case H5D_NLAYOUTS: break; default: @@ -128,6 +129,7 @@ int aux_assign_obj(const char* name, /* object name from traverse lis case H5D_LAYOUT_ERROR: case H5D_COMPACT: case H5D_CONTIGUOUS: + case H5D_VIRTUAL: case H5D_NLAYOUTS: break; default: @@ -184,6 +186,7 @@ int aux_assign_obj(const char* name, /* object name from traverse lis case H5D_LAYOUT_ERROR: case H5D_COMPACT: case H5D_CONTIGUOUS: + case H5D_VIRTUAL: case H5D_NLAYOUTS: break; default: @@ -433,7 +436,7 @@ int apply_filters(const char* name, /* object name from traverse list */ int scale_factor; scale_type = (H5Z_SO_scale_type_t)obj.filter[i].cd_values[0]; - scale_factor = obj.filter[i].cd_values[1]; + scale_factor = (int)obj.filter[i].cd_values[1]; if(H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths)<0) return -1; diff --git a/tools/h5repack/h5repack_main.c b/tools/h5repack/h5repack_main.c index e903435..2d48a04 100644 --- a/tools/h5repack/h5repack_main.c +++ b/tools/h5repack/h5repack_main.c @@ -265,11 +265,11 @@ int read_info(const char *filename, pack_opt_t *options) { 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 */ + error_msg("fscanf error\n"); + h5tools_setstatus(EXIT_FAILURE); + ret_value = EXIT_FAILURE; + goto done; + } /* end if */ if (HDfeof(fp)) break; } @@ -277,11 +277,11 @@ int read_info(const char *filename, pack_opt_t *options) { /* 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 */ + 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)) @@ -292,10 +292,10 @@ int read_info(const char *filename, pack_opt_t *options) { comp_info[i - 1] = '\0'; /*cut the last " */ 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; + error_msg("could not add compression option\n"); + h5tools_setstatus(EXIT_FAILURE); + ret_value = EXIT_FAILURE; + goto done; } } /*------------------------------------------------------------------------- @@ -309,11 +309,11 @@ int read_info(const char *filename, pack_opt_t *options) { 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 */ + error_msg("fscanf error\n"); + h5tools_setstatus(EXIT_FAILURE); + ret_value = EXIT_FAILURE; + goto done; + } /* end if */ if (HDfeof(fp)) break; } @@ -321,11 +321,11 @@ int read_info(const char *filename, pack_opt_t *options) { /* 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 */ + 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)) @@ -336,10 +336,10 @@ int read_info(const char *filename, pack_opt_t *options) { comp_info[i - 1] = '\0'; /*cut the last " */ if (h5repack_addlayout(comp_info, options) == -1) { - error_msg("could not add chunck option\n"); - h5tools_setstatus(EXIT_FAILURE); - ret_value = EXIT_FAILURE; - goto done; + error_msg("could not add chunck option\n"); + h5tools_setstatus(EXIT_FAILURE); + ret_value = EXIT_FAILURE; + goto done; } } /*------------------------------------------------------------------------- @@ -428,7 +428,7 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) { break; case 'm': - options->min_comp = HDatoi( opt_arg ); + options->min_comp = HDstrtoull(opt_arg , NULL, 0); if ((int) options->min_comp <= 0) { error_msg("invalid minimum compress size <%s>\n", opt_arg); h5tools_setstatus(EXIT_FAILURE); @@ -515,7 +515,7 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) { break; case 'a': - options->alignment = HDatol( opt_arg ); + options->alignment = HDstrtoull(opt_arg , NULL, 0); if (options->alignment < 1) { error_msg("invalid alignment size\n", opt_arg); h5tools_setstatus(EXIT_FAILURE); diff --git a/tools/h5repack/h5repack_opttable.c b/tools/h5repack/h5repack_opttable.c index b54e887..8c98b76 100644 --- a/tools/h5repack/h5repack_opttable.c +++ b/tools/h5repack/h5repack_opttable.c @@ -105,21 +105,22 @@ static void aux_tblinsert_layout(pack_opttbl_t *table, unsigned int I, * *------------------------------------------------------------------------- */ - -static int aux_inctable(pack_opttbl_t *table, int n_objs) { - unsigned int i; - - table->size += n_objs; - table->objs = - (pack_info_t*) HDrealloc(table->objs, table->size * sizeof(pack_info_t)); - if (table->objs == NULL) { - error_msg("not enough memory for options table\n"); - return -1; - } - for (i = table->nelems; i < table->size; i++) { - init_packobject(&table->objs[i]); - } - return 0; +static int +aux_inctable(pack_opttbl_t *table, unsigned n_objs) +{ + unsigned u; + + table->size += n_objs; + table->objs = (pack_info_t*) HDrealloc(table->objs, table->size * sizeof(pack_info_t)); + if (table->objs == NULL) { + error_msg("not enough memory for options table\n"); + return -1; + } + + for (u = table->nelems; u < table->size; u++) + init_packobject(&table->objs[u]); + + return 0; } @@ -183,80 +184,77 @@ int options_table_free(pack_opttbl_t *table) { * *------------------------------------------------------------------------- */ - -int options_add_layout(obj_list_t *obj_list, int n_objs, pack_info_t *pack, - pack_opttbl_t *table) { - unsigned int i, I; - int j, added = 0, found = 0; - - /* increase the size of the collection by N_OBJS if necessary */ - if (table->nelems + n_objs >= table->size) { - if (aux_inctable(table, n_objs) < 0) - return -1; - } - - /* search if this object is already in the table; "path" is the key */ - if (table->nelems > 0) { - /* go tru the supplied list of names */ - for (j = 0; j < n_objs; j++) { - /* linear table search */ - for (i = 0; i < table->nelems; i++) { - /*already on the table */ - if (HDstrcmp(obj_list[j].obj,table->objs[i].path) == 0) { - /* already chunk info inserted for this one; exit */ - if (table->objs[i].chunk.rank > 0) { - error_msg( - "chunk information already inserted for <%s>\n", - obj_list[j].obj); - HDexit(EXIT_FAILURE); - } - /* insert the layout info */ - else { - aux_tblinsert_layout(table, i, pack); - found = 1; - break; - } - } /* if */ - } /* i */ - - if (found == 0) { - /* keep the grow in a temp var */ - I = table->nelems + added; - added++; - HDstrcpy(table->objs[I].path, obj_list[j].obj); - aux_tblinsert_layout(table, I, pack); - } - /* cases where we have an already inserted name but there is a new name also - example: - -f dset1:GZIP=1 -l dset1,dset2:CHUNK=20x20 - dset1 is already inserted, but dset2 must also be - */ - else if (found == 1 - && HDstrcmp(obj_list[j].obj,table->objs[i].path) != 0) { - /* keep the grow in a temp var */ - I = table->nelems + added; - added++; - HDstrcpy(table->objs[I].path, obj_list[j].obj); - aux_tblinsert_layout(table, I, pack); - } - } /* j */ - } - - /* first time insertion */ - else { - /* go tru the supplied list of names */ - for (j = 0; j < n_objs; j++) { - I = table->nelems + added; - added++; - HDstrcpy(table->objs[I].path, obj_list[j].obj); - aux_tblinsert_layout(table, I, pack); - - } - } - - table->nelems += added; - - return 0; +int +options_add_layout(obj_list_t *obj_list, unsigned n_objs, pack_info_t *pack, + pack_opttbl_t *table) +{ + unsigned i, j, I; + unsigned added = 0; + hbool_t found = FALSE; + + /* increase the size of the collection by N_OBJS if necessary */ + if (table->nelems + n_objs >= table->size) + if (aux_inctable(table, n_objs) < 0) + return -1; + + /* search if this object is already in the table; "path" is the key */ + if (table->nelems > 0) { + /* go tru the supplied list of names */ + for (j = 0; j < n_objs; j++) { + /* linear table search */ + for (i = 0; i < table->nelems; i++) { + /*already on the table */ + if (HDstrcmp(obj_list[j].obj,table->objs[i].path) == 0) { + /* already chunk info inserted for this one; exit */ + if (table->objs[i].chunk.rank > 0) { + error_msg("chunk information already inserted for <%s>\n", obj_list[j].obj); + HDexit(EXIT_FAILURE); + } + /* insert the layout info */ + else { + aux_tblinsert_layout(table, i, pack); + found = TRUE; + break; + } + } /* if */ + } /* i */ + + if (!found) { + /* keep the grow in a temp var */ + I = table->nelems + added; + added++; + HDstrcpy(table->objs[I].path, obj_list[j].obj); + aux_tblinsert_layout(table, I, pack); + } + /* cases where we have an already inserted name but there is a new name also + example: + -f dset1:GZIP=1 -l dset1,dset2:CHUNK=20x20 + dset1 is already inserted, but dset2 must also be + */ + else + if(found && HDstrcmp(obj_list[j].obj,table->objs[i].path) != 0) { + /* keep the grow in a temp var */ + I = table->nelems + added; + added++; + HDstrcpy(table->objs[I].path, obj_list[j].obj); + aux_tblinsert_layout(table, I, pack); + } + } /* j */ + } + /* first time insertion */ + else { + /* go tru the supplied list of names */ + for (j = 0; j < n_objs; j++) { + I = table->nelems + added; + added++; + HDstrcpy(table->objs[I].path, obj_list[j].obj); + aux_tblinsert_layout(table, I, pack); + } + } + + table->nelems += added; + + return 0; } /*------------------------------------------------------------------------- @@ -268,71 +266,71 @@ int options_add_layout(obj_list_t *obj_list, int n_objs, pack_info_t *pack, * *------------------------------------------------------------------------- */ - -int options_add_filter(obj_list_t *obj_list, int n_objs, filter_info_t filt, - pack_opttbl_t *table) { - - unsigned int i, I; - int j, added = 0, found = 0; - - /* increase the size of the collection by N_OBJS if necessary */ - if (table->nelems + n_objs >= table->size) { - if (aux_inctable(table, n_objs) < 0) - return -1; - } - - /* search if this object is already in the table; "path" is the key */ - if (table->nelems > 0) { - /* go tru the supplied list of names */ - for (j = 0; j < n_objs; j++) { - /* linear table search */ - for (i = 0; i < table->nelems; i++) { - /*already on the table */ - if (HDstrcmp(obj_list[j].obj,table->objs[i].path) == 0) { - /* insert */ - aux_tblinsert_filter(table, i, filt); - found = 1; - break; - } /* if */ - } /* i */ - - if (found == 0) { - /* keep the grow in a temp var */ - I = table->nelems + added; - added++; - HDstrcpy(table->objs[I].path, obj_list[j].obj); - aux_tblinsert_filter(table, I, filt); - } - /* cases where we have an already inserted name but there is a new name also - example: - -l dset1:CHUNK=20x20 -f dset1,dset2:GZIP=1 - dset1 is already inserted, but dset2 must also be - */ - else if (found == 1 - && HDstrcmp(obj_list[j].obj,table->objs[i].path) != 0) { - /* keep the grow in a temp var */ - I = table->nelems + added; - added++; - HDstrcpy(table->objs[I].path, obj_list[j].obj); - aux_tblinsert_filter(table, I, filt); - } - } /* j */ - } - - /* first time insertion */ - else { - /* go tru the supplied list of names */ - for (j = 0; j < n_objs; j++) { - I = table->nelems + added; - added++; - HDstrcpy(table->objs[I].path, obj_list[j].obj); - aux_tblinsert_filter(table, I, filt); - } - } - - table->nelems += added; - - return 0; +int +options_add_filter(obj_list_t *obj_list, unsigned n_objs, filter_info_t filt, + pack_opttbl_t *table) +{ + unsigned int i, j, I; + unsigned added = 0; + hbool_t found = FALSE; + + /* increase the size of the collection by N_OBJS if necessary */ + if (table->nelems + n_objs >= table->size) + if (aux_inctable(table, n_objs) < 0) + return -1; + + /* search if this object is already in the table; "path" is the key */ + if (table->nelems > 0) { + /* go tru the supplied list of names */ + for (j = 0; j < n_objs; j++) { + /* linear table search */ + for (i = 0; i < table->nelems; i++) { + /*already on the table */ + if (HDstrcmp(obj_list[j].obj, table->objs[i].path) == 0) { + /* insert */ + aux_tblinsert_filter(table, i, filt); + found = TRUE; + break; + } /* if */ + } /* i */ + + if (!found) { + /* keep the grow in a temp var */ + I = table->nelems + added; + added++; + HDstrcpy(table->objs[I].path, obj_list[j].obj); + aux_tblinsert_filter(table, I, filt); + } + /* cases where we have an already inserted name but there is a new name also + example: + -l dset1:CHUNK=20x20 -f dset1,dset2:GZIP=1 + dset1 is already inserted, but dset2 must also be + */ + else + if(found && HDstrcmp(obj_list[j].obj,table->objs[i].path) != 0) { + /* keep the grow in a temp var */ + I = table->nelems + added; + added++; + HDstrcpy(table->objs[I].path, obj_list[j].obj); + aux_tblinsert_filter(table, I, filt); + } + } /* j */ + } + + /* first time insertion */ + else { + /* go tru the supplied list of names */ + for (j = 0; j < n_objs; j++) { + I = table->nelems + added; + added++; + HDstrcpy(table->objs[I].path, obj_list[j].obj); + aux_tblinsert_filter(table, I, filt); + } + } + + table->nelems += added; + + return 0; } /*------------------------------------------------------------------------- diff --git a/tools/h5repack/h5repack_parse.c b/tools/h5repack/h5repack_parse.c index 1d71c13..004b9e4 100644 --- a/tools/h5repack/h5repack_parse.c +++ b/tools/h5repack/h5repack_parse.c @@ -31,493 +31,425 @@ * FLET, to apply the HDF5 checksum filter * NBIT, to apply the HDF5 NBIT filter (NBIT compression) * SOFF, to apply the HDF5 scale+offset filter (compression) - * UD, to apply a User Defined filter k, m, n1[,…,nm] + * UD, to apply a User Defined filter k,m,n1[,…,nm] * NONE, to remove the filter * * Examples: * "GZIP=6" * "A,B:NONE" - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September, 23, 2003 - * *------------------------------------------------------------------------- */ - - -obj_list_t* parse_filter(const char *str, - int *n_objs, - filter_info_t *filt, - pack_opt_t *options, - int *is_glb) -{ - unsigned i, u; +obj_list_t* parse_filter(const char *str, unsigned *n_objs, filter_info_t *filt, + pack_opt_t *options, int *is_glb) { + size_t i, m, u; char c; - size_t len=HDstrlen(str); - int j, m, n, k, l, p, r, q, end_obj=-1, no_param=0; + size_t len = HDstrlen(str); + int k, l, p, q, end_obj = -1, no_param = 0; + unsigned j, n; char sobj[MAX_NC_NAME]; char scomp[10]; char stype[6]; char smask[3]; - obj_list_t* obj_list=NULL; + obj_list_t* obj_list = NULL; unsigned pixels_per_block; - /* initialize compression info */ - HDmemset(filt,0,sizeof(filter_info_t)); + HDmemset(filt, 0, sizeof(filter_info_t)); *is_glb = 0; /* check for the end of object list and number of objects */ - for ( i = 0, n = 0; i < len; i++) - { + for (i = 0, n = 0; i < len; i++) { c = str[i]; - if ( c==':' ) - { - end_obj=i; - } - if ( c==',' ) - { + if (c == ':') + end_obj = (int) i; + if (c == ',') n++; - } } - if (end_obj==-1) /* missing : */ - { + /* Check for missing : */ + if (end_obj == -1) { /* apply to all objects */ - options->all_filter=1; + options->all_filter = 1; *is_glb = 1; } n++; - obj_list = (obj_list_t*) HDmalloc(n*sizeof(obj_list_t)); - if (obj_list==NULL) - { + obj_list = (obj_list_t *) HDmalloc(n * sizeof(obj_list_t)); + if (obj_list == NULL) { error_msg("could not allocate object list\n"); return NULL; } - *n_objs=n; + *n_objs = n; /* get object list */ - for ( j = 0, k = 0, n = 0; j < end_obj; j++, k++) - { - c = str[j]; - sobj[k] = c; - if ( c==',' || j==end_obj-1) - { - if ( c==',') sobj[k]='\0'; else sobj[k+1]='\0'; - HDstrcpy(obj_list[n].obj,sobj); - HDmemset(sobj,0,sizeof(sobj)); - n++; - k=-1; + if (end_obj > 0) + for (j = 0, k = 0, n = 0; j < (unsigned) end_obj; j++, k++) { + c = str[j]; + sobj[k] = c; + if (c == ',' || j == (unsigned) (end_obj - 1)) { + if (c == ',') + sobj[k] = '\0'; + else + sobj[k + 1] = '\0'; + HDstrcpy(obj_list[n].obj, sobj); + HDmemset(sobj, 0, sizeof(sobj)); + n++; + k = -1; + } } - } /* nothing after : */ - if (end_obj+1==(int)len) - { - if (obj_list) HDfree(obj_list); - error_msg("input Error: Invalid compression type in <%s>\n",str); + if (end_obj + 1 == (int) len) { + if (obj_list) + HDfree(obj_list); + error_msg("input Error: Invalid compression type in <%s>\n", str); HDexit(EXIT_FAILURE); } - /* get filter additional parameters */ - m=0; - for ( i=end_obj+1, k=0, j=0; i<len; i++,k++) - { + m = 0; + for (i = (size_t)(end_obj + 1), k = 0, j = 0; i < len; i++, k++) { c = str[i]; - scomp[k]=c; - if ( c=='=' || i==len-1) - { - if ( c=='=') /*one more parameter */ - { - scomp[k]='\0'; /*cut space */ + scomp[k] = c; + if (c == '=' || i == len - 1) { + if (c == '=') { /*one more parameter */ + scomp[k] = '\0'; /*cut space */ /*------------------------------------------------------------------------- - * H5Z_FILTER_SZIP - * szip has the format SZIP=<pixels per block,coding> - * pixels per block is a even number in 2-32 and coding method is 'EC' or 'NN' - * example SZIP=8,NN - *------------------------------------------------------------------------- - */ - if (HDstrcmp(scomp,"SZIP")==0) - { - l=-1; /* mask index check */ - for ( m=0,u=i+1; u<len; u++,m++) - { - if (str[u]==',') - { - stype[m]='\0'; /* end digit of szip */ - l=0; /* start EC or NN search */ - u++; /* skip ',' */ + * H5Z_FILTER_SZIP + * szip has the format SZIP=<pixels per block,coding> + * pixels per block is a even number in 2-32 and coding method is 'EC' or 'NN' + * example SZIP=8,NN + *------------------------------------------------------------------------- + */ + if (HDstrcmp(scomp, "SZIP") == 0) { + l = -1; /* mask index check */ + for (m = 0, u = i + 1; u < len; u++, m++) { + if (str[u] == ',') { + stype[m] = '\0'; /* end digit of szip */ + l = 0; /* start EC or NN search */ + u++; /* skip ',' */ } c = str[u]; - if (!isdigit(c) && l==-1) - { - if (obj_list) HDfree(obj_list); - error_msg("compression parameter not digit in <%s>\n",str); + if (!HDisdigit(c) && l == -1) { + if (obj_list) + HDfree(obj_list); + error_msg("compression parameter not digit in <%s>\n", str); HDexit(EXIT_FAILURE); } - if (l==-1) - stype[m]=c; - else - { - smask[l]=c; + if (l == -1) + stype[m] = c; + else { + smask[l] = c; l++; - if (l==2) - { - smask[l]='\0'; - i=len-1; /* end */ + if (l == 2) { + smask[l] = '\0'; + i = len - 1; /* end */ (*n_objs)--; /* we counted an extra ',' */ - if (HDstrcmp(smask,"NN")==0) - filt->cd_values[j++]=H5_SZIP_NN_OPTION_MASK; - else if (HDstrcmp(smask,"EC")==0) - filt->cd_values[j++]=H5_SZIP_EC_OPTION_MASK; - else - { + if (HDstrcmp(smask,"NN") == 0) + filt->cd_values[j++] = H5_SZIP_NN_OPTION_MASK; + else if (HDstrcmp(smask,"EC") == 0) + filt->cd_values[j++] = H5_SZIP_EC_OPTION_MASK; + else { error_msg("szip mask must be 'NN' or 'EC' \n"); HDexit(EXIT_FAILURE); } - - } } - - } /* u */ + } /* u */ } /*if */ /*------------------------------------------------------------------------- - * H5Z_FILTER_SCALEOFFSET - * scaleoffset has the format SOFF=<scale_factor,scale_type> - * scale_type can be - * integer datatype, H5Z_SO_INT (IN) - * float datatype using D-scaling method, H5Z_SO_FLOAT_DSCALE (DS) - * float datatype using E-scaling method, H5Z_SO_FLOAT_ESCALE (ES) , not yet implemented - * for integer datatypes, scale_factor denotes Minimum Bits - * for float datatypes, scale_factor denotes decimal scale factor - * examples - * SOFF=31,IN - * SOFF=3,DF - *------------------------------------------------------------------------- - */ - - else if (HDstrcmp(scomp,"SOFF")==0) - { - l=-1; /* mask index check */ - for ( m=0,u=i+1; u<len; u++,m++) - { - if (str[u]==',') - { - stype[m]='\0'; /* end digit */ - l=0; /* start 'IN' , 'DS', or 'ES' search */ - u++; /* skip ',' */ + * H5Z_FILTER_SCALEOFFSET + * scaleoffset has the format SOFF=<scale_factor,scale_type> + * scale_type can be + * integer datatype, H5Z_SO_INT (IN) + * float datatype using D-scaling method, H5Z_SO_FLOAT_DSCALE (DS) + * float datatype using E-scaling method, H5Z_SO_FLOAT_ESCALE (ES) , not yet implemented + * for integer datatypes, scale_factor denotes Minimum Bits + * for float datatypes, scale_factor denotes decimal scale factor + * examples + * SOFF=31,IN + * SOFF=3,DF + *------------------------------------------------------------------------- + */ + else if (HDstrcmp(scomp, "SOFF") == 0) { + l = -1; /* mask index check */ + for (m = 0, u = i + 1; u < len; u++, m++) { + if (str[u] == ',') { + stype[m] = '\0'; /* end digit */ + l = 0; /* start 'IN' , 'DS', or 'ES' search */ + u++; /* skip ',' */ } c = str[u]; - if (!isdigit(c) && l==-1) - { - if (obj_list) HDfree(obj_list); - error_msg("compression parameter is not a digit in <%s>\n",str); + if (!HDisdigit(c) && l == -1) { + if (obj_list) + HDfree(obj_list); + error_msg("compression parameter is not a digit in <%s>\n", str); HDexit(EXIT_FAILURE); } - if (l==-1) - stype[m]=c; - else - { - smask[l]=c; + if (l == -1) + stype[m] = c; + else { + smask[l] = c; l++; - if (l==2) - { - smask[l]='\0'; - i=len-1; /* end */ + if (l == 2) { + smask[l] = '\0'; + i = len - 1; /* end */ (*n_objs)--; /* we counted an extra ',' */ - if (HDstrcmp(smask,"IN")==0) - filt->cd_values[j++]=H5Z_SO_INT; - else if (HDstrcmp(smask,"DS")==H5Z_SO_FLOAT_DSCALE) - filt->cd_values[j++]=H5Z_SO_FLOAT_DSCALE; - else - { + if (HDstrcmp(smask,"IN") == 0) + filt->cd_values[j++] = H5Z_SO_INT; + else if (HDstrcmp(smask, "DS") == H5Z_SO_FLOAT_DSCALE) + filt->cd_values[j++] = H5Z_SO_FLOAT_DSCALE; + else { error_msg("scale type must be 'IN' or 'DS' \n"); HDexit(EXIT_FAILURE); } - } } - - } /* u */ + } /* u */ } /*if */ + /*------------------------------------------------------------------------- - * User Defined - * has the format UD=<filter_number,cd_value_count,value_1[,value_2,...,value_N]> - * BZIP2 example - * UD=307,1,9 - *------------------------------------------------------------------------- - */ - - else if (HDstrcmp(scomp,"UD")==0) - { - l=-1; /* filter number index check */ - p=-1; /* CD_VAL count check */ - r=-1; /* CD_VAL check */ - for ( m=0,q=0,u=i+1; u<len; u++,m++,q++) - { - if (str[u]==',') - { - stype[q]='\0'; /* end digit */ - if (l==-1) - { - filt->filtn=atoi(stype); - l=0; + * User Defined + * has the format UD=<filter_number,cd_value_count,value_1[,value_2,...,value_N]> + * BZIP2 example + * UD=307,1,9 + *------------------------------------------------------------------------- + */ + else if (HDstrcmp(scomp, "UD") == 0) { + l = -1; /* filter number index check */ + p = -1; /* CD_VAL count check */ + for (m = 0, q = 0, u = i + 1; u < len; u++, m++, q++) { + if (str[u] == ',') { + stype[q] = '\0'; /* end digit */ + if (l == -1) { + filt->filtn = HDatoi(stype); + l = 0; } - else if (p==-1) - { - filt->cd_nelmts=atoi(stype); - p=0; + else if (p == -1) { + filt->cd_nelmts = HDstrtoull(stype, NULL, 0); + p = 0; } else - r=0; - q=0; - u++; /* skip ',' */ + filt->cd_values[j++] = (unsigned)HDstrtoul(stype, NULL, 0); + q = 0; + u++; /* skip ',' */ } c = str[u]; - if (!isdigit(c) && l==-1) - { - if (obj_list) HDfree(obj_list); - error_msg("filter number parameter is not a digit in <%s>\n",str); + if (!HDisdigit(c) && l == -1) { + if (obj_list) + HDfree(obj_list); + error_msg("filter number parameter is not a digit in <%s>\n", str); HDexit(EXIT_FAILURE); } - stype[q]=c; - if (l==0 && p==0) - { - if (r==0) - filt->cd_values[j++]=atoi(stype); - } - - } /* u */ - - stype[q]='\0'; + stype[q] = c; + } /* for u */ + stype[q] = '\0'; } /*if */ - /*------------------------------------------------------------------------- - * all other filters - *------------------------------------------------------------------------- - */ - - else - { + * all other filters + *------------------------------------------------------------------------- + */ + else { /* here we could have 1 or 2 digits */ - for ( m=0,u=i+1; u<len; u++,m++) - { + for (m = 0, u = i + 1; u < len; u++, m++) { c = str[u]; - if (!isdigit(c)){ - if (obj_list) HDfree(obj_list); - error_msg("compression parameter is not a digit in <%s>\n",str); + if (!HDisdigit(c)) { + if (obj_list) + HDfree(obj_list); + error_msg("compression parameter is not a digit in <%s>\n", str); HDexit(EXIT_FAILURE); } - stype[m]=c; + stype[m] = c; } /* u */ - stype[m]='\0'; + stype[m] = '\0'; } /*if */ - - - filt->cd_values[j++]=atoi(stype); - i+=m; /* jump */ + filt->cd_values[j++] = (unsigned) HDstrtoul(stype, NULL, 0); + if(filt->cd_nelmts == 0) + j = 0; + i += m; /* jump */ } - else if (i==len-1) - { /*no more parameters */ - scomp[k+1]='\0'; - no_param=1; + else if (i == len - 1) { /*no more parameters */ + scomp[k + 1] = '\0'; + no_param = 1; } /*------------------------------------------------------------------------- - * translate from string to filter symbol - *------------------------------------------------------------------------- - */ + * translate from string to filter symbol + *------------------------------------------------------------------------- + */ /*------------------------------------------------------------------------- - * H5Z_FILTER_NONE - *------------------------------------------------------------------------- - */ - if (HDstrcmp(scomp,"NONE")==0) - { - filt->filtn=H5Z_FILTER_NONE; + * H5Z_FILTER_NONE + *------------------------------------------------------------------------- + */ + if (HDstrcmp(scomp, "NONE") == 0) { + filt->filtn = H5Z_FILTER_NONE; filt->cd_nelmts = 0; } /*------------------------------------------------------------------------- - * H5Z_FILTER_DEFLATE - *------------------------------------------------------------------------- - */ - else if (HDstrcmp(scomp,"GZIP")==0) - { - filt->filtn=H5Z_FILTER_DEFLATE; + * H5Z_FILTER_DEFLATE + *------------------------------------------------------------------------- + */ + else if (HDstrcmp(scomp, "GZIP") == 0) { + filt->filtn = H5Z_FILTER_DEFLATE; filt->cd_nelmts = 1; - if (no_param) - { /*no more parameters, GZIP must have parameter */ - if (obj_list) HDfree(obj_list); - error_msg("missing compression parameter in <%s>\n",str); + if (no_param) { /*no more parameters, GZIP must have parameter */ + if (obj_list) + HDfree(obj_list); + error_msg("missing compression parameter in <%s>\n", str); HDexit(EXIT_FAILURE); } } /*------------------------------------------------------------------------- - * H5Z_FILTER_SZIP - *------------------------------------------------------------------------- - */ - else if (HDstrcmp(scomp,"SZIP")==0) - { - filt->filtn=H5Z_FILTER_SZIP; + * H5Z_FILTER_SZIP + *------------------------------------------------------------------------- + */ + else if (HDstrcmp(scomp, "SZIP") == 0) { + filt->filtn = H5Z_FILTER_SZIP; filt->cd_nelmts = 2; - if (no_param) - { /*no more parameters, SZIP must have parameter */ - if (obj_list) HDfree(obj_list); - error_msg("missing compression parameter in <%s>\n",str); + if (no_param) { /*no more parameters, SZIP must have parameter */ + if (obj_list) + HDfree(obj_list); + error_msg("missing compression parameter in <%s>\n", str); HDexit(EXIT_FAILURE); } } /*------------------------------------------------------------------------- - * H5Z_FILTER_SHUFFLE - *------------------------------------------------------------------------- - */ - else if (HDstrcmp(scomp,"SHUF")==0) - { - filt->filtn=H5Z_FILTER_SHUFFLE; + * H5Z_FILTER_SHUFFLE + *------------------------------------------------------------------------- + */ + else if (HDstrcmp(scomp, "SHUF") == 0) { + filt->filtn = H5Z_FILTER_SHUFFLE; filt->cd_nelmts = 0; - if (m>0) - { /*shuffle does not have parameter */ - if (obj_list) HDfree(obj_list); - error_msg("extra parameter in SHUF <%s>\n",str); + if (m > 0) { /*shuffle does not have parameter */ + if (obj_list) + HDfree(obj_list); + error_msg("extra parameter in SHUF <%s>\n", str); HDexit(EXIT_FAILURE); } } /*------------------------------------------------------------------------- - * H5Z_FILTER_FLETCHER32 - *------------------------------------------------------------------------- - */ - else if (HDstrcmp(scomp,"FLET")==0) - { - filt->filtn=H5Z_FILTER_FLETCHER32; + * H5Z_FILTER_FLETCHER32 + *------------------------------------------------------------------------- + */ + else if (HDstrcmp(scomp, "FLET") == 0) { + filt->filtn = H5Z_FILTER_FLETCHER32; filt->cd_nelmts = 0; - if (m>0) - { /*shuffle does not have parameter */ - if (obj_list) HDfree(obj_list); - error_msg("extra parameter in FLET <%s>\n",str); + if (m > 0) { /*shuffle does not have parameter */ + if (obj_list) + HDfree(obj_list); + error_msg("extra parameter in FLET <%s>\n", str); HDexit(EXIT_FAILURE); } } /*------------------------------------------------------------------------- - * H5Z_FILTER_NBIT - *------------------------------------------------------------------------- - */ - else if (HDstrcmp(scomp,"NBIT")==0) - { - filt->filtn=H5Z_FILTER_NBIT; + * H5Z_FILTER_NBIT + *------------------------------------------------------------------------- + */ + else if (HDstrcmp(scomp, "NBIT") == 0) { + filt->filtn = H5Z_FILTER_NBIT; filt->cd_nelmts = 0; - if (m>0) - { /*nbit does not have parameter */ - if (obj_list) HDfree(obj_list); - error_msg("extra parameter in NBIT <%s>\n",str); + if (m > 0) { /*nbit does not have parameter */ + if (obj_list) + HDfree(obj_list); + error_msg("extra parameter in NBIT <%s>\n", str); HDexit(EXIT_FAILURE); } } /*------------------------------------------------------------------------- - * H5Z_FILTER_SCALEOFFSET - *------------------------------------------------------------------------- - */ - else if (HDstrcmp(scomp,"SOFF")==0) - { - filt->filtn=H5Z_FILTER_SCALEOFFSET; + * H5Z_FILTER_SCALEOFFSET + *------------------------------------------------------------------------- + */ + else if (HDstrcmp(scomp, "SOFF") == 0) { + filt->filtn = H5Z_FILTER_SCALEOFFSET; filt->cd_nelmts = 2; - if (no_param) - { /*no more parameters, SOFF must have parameter */ - if (obj_list) HDfree(obj_list); - error_msg("missing compression parameter in <%s>\n",str); + if (no_param) { /*no more parameters, SOFF must have parameter */ + if (obj_list) + HDfree(obj_list); + error_msg("missing compression parameter in <%s>\n", str); HDexit(EXIT_FAILURE); } } /*------------------------------------------------------------------------- - * User Defined Filter - *------------------------------------------------------------------------- - */ - else if (HDstrcmp(scomp,"UD")==0) - { - if (filt->cd_nelmts != j) - { /* parameters does not match count */ - if (obj_list) HDfree(obj_list); - error_msg("incorrect number of compression parameters in <%s>\n",str); + * User Defined Filter + *------------------------------------------------------------------------- + */ + else if (HDstrcmp(scomp, "UD") == 0) { + /* parameters does not match count */ + if (filt->cd_nelmts != j) { + if (obj_list) + HDfree(obj_list); + error_msg("incorrect number of compression parameters in <%s>\n", str); HDexit(EXIT_FAILURE); } } else { - if (obj_list) HDfree(obj_list); - error_msg("invalid filter type in <%s>\n",str); + if (obj_list) + HDfree(obj_list); + error_msg("invalid filter type in <%s>\n", str); HDexit(EXIT_FAILURE); } } } /*i*/ /*------------------------------------------------------------------------- - * check valid parameters - *------------------------------------------------------------------------- - */ - - switch (filt->filtn) - { + * check valid parameters + *------------------------------------------------------------------------- + */ + switch (filt->filtn) { /*------------------------------------------------------------------------- - * H5Z_FILTER_DEFLATE - *------------------------------------------------------------------------- - */ - + * H5Z_FILTER_DEFLATE + *------------------------------------------------------------------------- + */ case H5Z_FILTER_DEFLATE: - if (filt->cd_values[0]>9 ) - { - if (obj_list) HDfree(obj_list); - error_msg("invalid compression parameter in <%s>\n",str); + if (filt->cd_values[0] > 9) { + if (obj_list) + HDfree(obj_list); + error_msg("invalid compression parameter in <%s>\n", str); HDexit(EXIT_FAILURE); } break; - /*------------------------------------------------------------------------- - * H5Z_FILTER_SZIP - *------------------------------------------------------------------------- - */ - + * H5Z_FILTER_SZIP + *------------------------------------------------------------------------- + */ case H5Z_FILTER_SZIP: - pixels_per_block=filt->cd_values[0]; - if ((pixels_per_block%2)==1) - { - if (obj_list) HDfree(obj_list); - error_msg("pixels_per_block is not even in <%s>\n",str); + pixels_per_block = filt->cd_values[0]; + if ((pixels_per_block % 2) == 1) { + if (obj_list) + HDfree(obj_list); + error_msg("pixels_per_block is not even in <%s>\n", str); HDexit(EXIT_FAILURE); } - if (pixels_per_block>H5_SZIP_MAX_PIXELS_PER_BLOCK) - { - if (obj_list) HDfree(obj_list); - error_msg("pixels_per_block is too large in <%s>\n",str); + if (pixels_per_block > H5_SZIP_MAX_PIXELS_PER_BLOCK) { + if (obj_list) + HDfree(obj_list); + error_msg("pixels_per_block is too large in <%s>\n", str); HDexit(EXIT_FAILURE); } - if ( (HDstrcmp(smask,"NN")!=0) && (HDstrcmp(smask,"EC")!=0) ) - { - if (obj_list) HDfree(obj_list); + if ((HDstrcmp(smask,"NN") != 0) && (HDstrcmp(smask,"EC") != 0)) { + if (obj_list) + HDfree(obj_list); error_msg("szip mask must be 'NN' or 'EC' \n"); HDexit(EXIT_FAILURE); } break; default: break; - - }; return obj_list; } - - + /*------------------------------------------------------------------------- * Function: parse_layout * @@ -539,176 +471,146 @@ obj_list_t* parse_filter(const char *str, * *------------------------------------------------------------------------- */ -obj_list_t* parse_layout(const char *str, - int *n_objs, - pack_info_t *pack, /* info about layout needed */ - pack_opt_t *options) -{ - obj_list_t* obj_list=NULL; - unsigned i; +obj_list_t* parse_layout(const char *str, unsigned *n_objs, pack_info_t *pack, /* info about layout needed */ +pack_opt_t *options) { + obj_list_t* obj_list = NULL; + unsigned i, j, n; char c; - size_t len=HDstrlen(str); - int j, n, k, end_obj=-1, c_index; + size_t len = HDstrlen(str); + int k, end_obj = -1, c_index; char sobj[MAX_NC_NAME]; char sdim[10]; char slayout[10]; - HDmemset(sdim, '\0', sizeof(sdim)); HDmemset(sobj, '\0', sizeof(sobj)); HDmemset(slayout, '\0', sizeof(slayout)); /* check for the end of object list and number of objects */ - for ( i=0, n=0; i<len; i++) - { + for (i = 0, n = 0; i < len; i++) { c = str[i]; - if ( c==':' ) - { - end_obj=i; - } - if ( c==',' ) - { + if (c == ':') + end_obj = (int) i; + if (c == ',') n++; - } } - if (end_obj==-1) { /* missing : chunk all */ - options->all_layout=1; + if (end_obj == -1) { /* missing : chunk all */ + options->all_layout = 1; } n++; - obj_list = (obj_list_t*) HDmalloc(n*sizeof(obj_list_t)); - if (obj_list==NULL) - { + obj_list = (obj_list_t*) HDmalloc(n * sizeof(obj_list_t)); + if (obj_list == NULL) { error_msg("could not allocate object list\n"); return NULL; } - *n_objs=n; + *n_objs = n; /* get object list */ - for ( j=0, k=0, n=0; j<end_obj; j++,k++) - { - c = str[j]; - sobj[k]=c; - if ( c==',' || j==end_obj-1) - { - if ( c==',') sobj[k]='\0'; else sobj[k+1]='\0'; - HDstrcpy(obj_list[n].obj,sobj); - HDmemset(sobj,0,sizeof(sobj)); - n++; - k=-1; + if (end_obj > 0) + for (j = 0, k = 0, n = 0; j < (unsigned) end_obj; j++, k++) { + c = str[j]; + sobj[k] = c; + if (c == ',' || j == (unsigned) (end_obj - 1)) { + if (c == ',') + sobj[k] = '\0'; + else + sobj[k + 1] = '\0'; + HDstrcpy(obj_list[n].obj, sobj); + HDmemset(sobj, 0, sizeof(sobj)); + n++; + k = -1; + } } - } /* nothing after : */ - if (end_obj+1==(int)len) - { - if (obj_list) HDfree(obj_list); - error_msg("in parse layout, no characters after : in <%s>\n",str); + if (end_obj + 1 == (int) len) { + if (obj_list) + HDfree(obj_list); + error_msg("in parse layout, no characters after : in <%s>\n", str); HDexit(EXIT_FAILURE); } /* get layout info */ - for ( j=end_obj+1, n=0; n<=5; j++,n++) - { - if (n==5) - { - slayout[n]='\0'; /*cut string */ - if (HDstrcmp(slayout,"COMPA")==0) - pack->layout=H5D_COMPACT; - else if (HDstrcmp(slayout,"CONTI")==0) - pack->layout=H5D_CONTIGUOUS; - else if (HDstrcmp(slayout,"CHUNK")==0) - pack->layout=H5D_CHUNKED; + for (j = (unsigned) (end_obj + 1), n = 0; n <= 5; j++, n++) { + if (n == 5) { + slayout[n] = '\0'; /*cut string */ + if (HDstrcmp(slayout, "COMPA") == 0) + pack->layout = H5D_COMPACT; + else if (HDstrcmp(slayout, "CONTI") == 0) + pack->layout = H5D_CONTIGUOUS; + else if (HDstrcmp(slayout, "CHUNK") == 0) + pack->layout = H5D_CHUNKED; else { - error_msg("in parse layout, not a valid layout in <%s>\n",str); + error_msg("in parse layout, not a valid layout in <%s>\n", str); HDexit(EXIT_FAILURE); } } - else - { + else { c = str[j]; - slayout[n]=c; + slayout[n] = c; } } /* j */ - - if ( pack->layout==H5D_CHUNKED ) - { - + if (pack->layout == H5D_CHUNKED) { /*------------------------------------------------------------------------- - * get chunk info - *------------------------------------------------------------------------- - */ - k=0; - - if (j>(int)len) - { - if (obj_list) HDfree(obj_list); - error_msg("in parse layout, <%s> Chunk dimensions missing\n",str); + * get chunk info + *------------------------------------------------------------------------- + */ + k = 0; + if (j > len) { + if (obj_list) + HDfree(obj_list); + error_msg("in parse layout, <%s> Chunk dimensions missing\n", str); HDexit(EXIT_FAILURE); } - for ( i=j, c_index=0; i<len; i++) - { + for (i = j, c_index = 0; i < len; i++) { c = str[i]; - sdim[k]=c; + sdim[k] = c; k++; /*increment sdim index */ - if (!isdigit(c) && c!='x' - && c!='N' && c!='O' && c!='N' && c!='E' - ){ - if (obj_list) HDfree(obj_list); - error_msg("in parse layout, <%s> Not a valid character in <%s>\n", - sdim,str); + if (!HDisdigit(c) && c != 'x' && c != 'N' && c != 'O' && c != 'N' && c != 'E') { + if (obj_list) + HDfree(obj_list); + error_msg("in parse layout, <%s> Not a valid character in <%s>\n", sdim, str); HDexit(EXIT_FAILURE); } - if ( c=='x' || i==len-1) - { - if ( c=='x') { - sdim[k-1]='\0'; - k=0; - pack->chunk.chunk_lengths[c_index]=atoi(sdim); - if (pack->chunk.chunk_lengths[c_index]==0) { - if (obj_list) HDfree(obj_list); - error_msg("in parse layout, <%s> conversion to number in <%s>\n", - sdim,str); + if (c == 'x' || i == len - 1) { + if (c == 'x') { + sdim[k - 1] = '\0'; + k = 0; + pack->chunk.chunk_lengths[c_index] = HDstrtoull(sdim, NULL, 0); + if (pack->chunk.chunk_lengths[c_index] == 0) { + if (obj_list) + HDfree(obj_list); + error_msg("in parse layout, <%s> conversion to number in <%s>\n", sdim, str); HDexit(EXIT_FAILURE); } c_index++; } - else if (i==len-1) { /*no more parameters */ - sdim[k]='\0'; - k=0; - if (HDstrcmp(sdim,"NONE")==0) - { - pack->chunk.rank=-2; + else if (i == len - 1) { /*no more parameters */ + sdim[k] = '\0'; + k = 0; + if (HDstrcmp(sdim,"NONE") == 0) { + pack->chunk.rank = -2; } - else - { - pack->chunk.chunk_lengths[c_index]=atoi(sdim); - if (pack->chunk.chunk_lengths[c_index]==0){ - if (obj_list) HDfree(obj_list); - error_msg("in parse layout, <%s> conversion to number in <%s>\n", - sdim,str); + else { + pack->chunk.chunk_lengths[c_index] = HDstrtoull(sdim, NULL, 0); + if (pack->chunk.chunk_lengths[c_index] == 0) { + if (obj_list) + HDfree(obj_list); + error_msg("in parse layout, <%s> conversion to number in <%s>\n", sdim, str); HDexit(EXIT_FAILURE); } - pack->chunk.rank=c_index+1; + pack->chunk.rank = c_index + 1; } } /*if */ } /*if c=='x' || i==len-1 */ } /*i*/ - - } /*H5D_CHUNKED*/ - return obj_list; } - - - - - - diff --git a/tools/h5repack/h5repack_plugin.sh.in b/tools/h5repack/h5repack_plugin.sh.in index 7502397..a064db6 100644 --- a/tools/h5repack/h5repack_plugin.sh.in +++ b/tools/h5repack/h5repack_plugin.sh.in @@ -127,7 +127,7 @@ CLEAN_TESTFILES_AND_TESTDIR() # skip rm if srcdir is same as destdir # this occurs when build/test performed in source dir and # make cp fail - SDIR=`$DIRNAME $tstfile` + SDIR=$SRC_H5REPACK_TESTFILES INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'` if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then diff --git a/tools/h5repack/h5repacktst.c b/tools/h5repack/h5repacktst.c index 07ea676..82b45fc 100644 --- a/tools/h5repack/h5repacktst.c +++ b/tools/h5repack/h5repacktst.c @@ -3421,7 +3421,7 @@ make_userblock(void) /* Initialize userblock data */ for(u = 0; u < USERBLOCK_SIZE; u++) - ub[u] = 'a' + (char)(u % 26); + ub[u] = (char)('a' + (char)(u % 26)); /* Re-open HDF5 file, as "plain" file */ if((fd = HDopen(FNAME16, O_WRONLY, 0644)) < 0) @@ -3534,7 +3534,7 @@ make_userblock_file(void) /* initialize userblock data */ for(u = 0; u < USERBLOCK_SIZE; u++) - ub[u] = 'a' + (char)(u % 26); + ub[u] = (char)('a' + (char)(u % 26)); /* open file */ if((fd = HDopen(FNAME_UB,O_WRONLY|O_CREAT|O_TRUNC, 0644 )) < 0) @@ -3591,7 +3591,8 @@ int write_dset_in(hid_t loc_id, hid_t sid=-1; hid_t tid=-1; hid_t pid=-1; - int val, i, j, k, n; + unsigned i, j; + int val, k, n; float f; /* create 1D attributes with dimension [2], 2 elements */ @@ -3646,13 +3647,10 @@ int write_dset_in(hid_t loc_id, */ - if (make_diffs) - { - for (i=0; i<2; i++) - for (j=0; j<2; j++) - { - buf1[i][j]='z'; - } + if(make_diffs) { + for(i = 0; i < 2; i++) + for(j = 0; j < 2; j++) + buf1[i][j] = 'z'; } @@ -3675,10 +3673,9 @@ int write_dset_in(hid_t loc_id, *------------------------------------------------------------------------- */ - if (make_diffs) - { - for (i=0; i<2; i++) - buf2[i]=buf2[1]=0; + if(make_diffs) { + for(i = 0; i < 2; i++) + buf2[i] = buf2[1] = 0; } if ((tid = H5Tcopy(H5T_STD_B8LE)) < 0) @@ -3693,11 +3690,10 @@ int write_dset_in(hid_t loc_id, *------------------------------------------------------------------------- */ - if (make_diffs) - { - for (i=0; i<2; i++) - { - buf3[i].a=0; buf3[i].b=0; + if(make_diffs) { + for(i = 0; i < 2; i++) { + buf3[i].a = 0; + buf3[i].b = 0; } } @@ -3716,12 +3712,9 @@ int write_dset_in(hid_t loc_id, */ - if (make_diffs) - { - for (i=0; i<2; i++) - { - buf45[i]=GREEN; - } + if(make_diffs) { + for(i = 0; i < 2; i++) + buf45[i] = GREEN; } if ((tid = H5Tcreate (H5T_COMPOUND, sizeof(s_t))) < 0) @@ -3813,13 +3806,10 @@ int write_dset_in(hid_t loc_id, *------------------------------------------------------------------------- */ - if (make_diffs) - { - for (i=0; i<2; i++) - for (j=0; j<3; j++) - { - buf6[i][j]=0; - } + if(make_diffs) { + for(i = 0; i < 2; i++) + for(j = 0; j < 3; j++) + buf6[i][j] = 0; } if ((tid = H5Tarray_create2(H5T_NATIVE_INT, 1, dimarray)) < 0) @@ -3880,12 +3870,10 @@ int write_dset_in(hid_t loc_id, *------------------------------------------------------------------------- */ - if (make_diffs) - { - for (i=0; i<2; i++) - { - buf7[i]=0; - buf8[i]=0; + if(make_diffs) { + for(i = 0; i < 2; i++) { + buf7[i] = 0; + buf8[i] = 0; } } @@ -4008,16 +3996,13 @@ int write_dset_in(hid_t loc_id, /* Allocate and initialize VL dataset to write */ n = 0; - for(i = 0; i < 3; i++) - { - for(j = 0; j < 2; j++) - { - int l; + for(i = 0; i < 3; i++) { + for(j = 0; j < 2; j++) { + unsigned l; buf52[i][j].p = HDmalloc((i + 1) * sizeof(int)); buf52[i][j].len = (size_t)(i + 1); - for(l = 0; l < i + 1; l++) - { + for(l = 0; l < i + 1; l++) { if(make_diffs) ((int *)buf52[i][j].p)[l] = 0; else @@ -4128,11 +4113,13 @@ int write_dset_in(hid_t loc_id, n=1; - for (i = 0; i < 4; i++) { - for (j = 0; j < 3; j++) { - for (k = 0; k < 2; k++) { - if (make_diffs) buf23[i][j][k]=0; - else buf23[i][j][k]=n++; + for(i = 0; i < 4; i++) { + for(j = 0; j < 3; j++) { + for(k = 0; k < 2; k++) { + if(make_diffs) + buf23[i][j][k] = 0; + else + buf23[i][j][k] = (char)(n++); } } } @@ -4164,16 +4151,16 @@ int write_dset_in(hid_t loc_id, */ n=1; - for (i = 0; i < 4; i++) { - for (j = 0; j < 3; j++) { - for (k = 0; k < 2; k++) { - if (make_diffs) { - buf33[i][j][k].a=0; - buf33[i][j][k].b=0; + for(i = 0; i < 4; i++) { + for(j = 0; j < 3; j++) { + for(k = 0; k < 2; k++) { + if(make_diffs) { + buf33[i][j][k].a = 0; + buf33[i][j][k].b = 0; } else { - buf33[i][j][k].a=n++; - buf33[i][j][k].b=n++; + buf33[i][j][k].a = (char)(n++); + buf33[i][j][k].b = n++; } } } @@ -4227,18 +4214,14 @@ int write_dset_in(hid_t loc_id, /* Allocate and initialize VL dataset to write */ n = 0; - for(i = 0; i < 4; i++) - { - for(j = 0; j < 3; j++) - { - for(k = 0; k < 2; k++) - { - int l; + for(i = 0; i < 4; i++) { + for(j = 0; j < 3; j++) { + for(k = 0; k < 2; k++) { + unsigned l; buf53[i][j][k].p = HDmalloc((i + 1) * sizeof(int)); buf53[i][j][k].len = (size_t)(i + 1); - for(l = 0; l < i + 1; l++) - { + for(l = 0; l < i + 1; l++) { if(make_diffs) ((int *)buf53[i][j][k].p)[l] = 0; else @@ -4274,10 +4257,8 @@ int write_dset_in(hid_t loc_id, n = 1; - for(i = 0; i < 24; i++) - { - for(j = 0; j < (int)dimarray[0]; j++) - { + for(i = 0; i < 24; i++) { + for(j = 0; j < dimarray[0]; j++) { if(make_diffs) buf63[i][j] = 0; else @@ -4316,13 +4297,10 @@ int write_dset_in(hid_t loc_id, if (write_dset(loc_id,3,dims3,"float3D",H5T_NATIVE_FLOAT,buf83) < 0) goto out; - return 0; - out: - H5E_BEGIN_TRY - { + H5E_BEGIN_TRY { H5Pclose(pid); H5Sclose(sid); H5Dclose(did); @@ -4471,7 +4449,8 @@ int write_attr_in(hid_t loc_id, hid_t aid = -1; hid_t sid = -1; hid_t tid = -1; - int val, i, j, k, n; + int val, j, k, n; + unsigned i; float f; /* create 1D attributes with dimension [2], 2 elements */ @@ -5021,16 +5000,17 @@ int write_attr_in(hid_t loc_id, /* Allocate and initialize VL dataset to write */ n=0; - for (i = 0; i < 3; i++) - { - for (j = 0; j < 2; j++) - { - int l; + for(i = 0; i < 3; i++) { + for(j = 0; j < 2; j++) { + unsigned l; + buf52[i][j].p = HDmalloc((i + 1) * sizeof(int)); buf52[i][j].len = (size_t)(i + 1); - for (l = 0; l < i + 1; l++) - if (make_diffs)((int *)buf52[i][j].p)[l] = 0; - else ((int *)buf52[i][j].p)[l] = n++; + for(l = 0; l < i + 1; l++) + if(make_diffs) + ((int *)buf52[i][j].p)[l] = 0; + else + ((int *)buf52[i][j].p)[l] = n++; } } @@ -5239,14 +5219,13 @@ int write_attr_in(hid_t loc_id, */ n=1; - for (i = 0; i < 4; i++) - { - for (j = 0; j < 3; j++) - { - for (k = 0; k < 2; k++) - { - if (make_diffs) buf23[i][j][k]=0; - else buf23[i][j][k]=n++; + for(i = 0; i < 4; i++) { + for(j = 0; j < 3; j++) { + for(k = 0; k < 2; k++) { + if(make_diffs) + buf23[i][j][k] = 0; + else + buf23[i][j][k] = (char)(n++); } } } @@ -5308,21 +5287,16 @@ int write_attr_in(hid_t loc_id, */ n=1; - for (i = 0; i < 4; i++) - { - for (j = 0; j < 3; j++) - { - for (k = 0; k < 2; k++) - { - if (make_diffs) - { - buf33[i][j][k].a=0; - buf33[i][j][k].b=0; + for(i = 0; i < 4; i++) { + for(j = 0; j < 3; j++) { + for(k = 0; k < 2; k++) { + if(make_diffs) { + buf33[i][j][k].a = 0; + buf33[i][j][k].b = 0; } - else - { - buf33[i][j][k].a=n++; - buf33[i][j][k].b=n++; + else { + buf33[i][j][k].a = (char)(n++); + buf33[i][j][k].b = n++; } } } @@ -5491,14 +5465,13 @@ int write_attr_in(hid_t loc_id, { for (k = 0; k < 2; k++) { - int l; + unsigned l; + buf53[i][j][k].p = HDmalloc((i + 1) * sizeof(int)); buf53[i][j][k].len = (size_t)i + 1; for (l = 0; l < i + 1; l++) if (make_diffs) - { ((int *)buf53[i][j][k].p)[l] = 0; - } else ((int *)buf53[i][j][k].p)[l] = n++; } @@ -5622,8 +5595,7 @@ int write_attr_in(hid_t loc_id, return 0; out: - H5E_BEGIN_TRY - { + H5E_BEGIN_TRY { H5Aclose(aid); H5Sclose(sid); H5Tclose(tid); diff --git a/tools/h5repack/testfiles/h5repack_layout.h5-plugin_zero.tst b/tools/h5repack/testfiles/h5repack_layout.h5-plugin_zero.tst new file mode 100644 index 0000000..0993d5b --- /dev/null +++ b/tools/h5repack/testfiles/h5repack_layout.h5-plugin_zero.tst @@ -0,0 +1,9 @@ +Objects to modify layout are... +Objects to apply filter are... + User Defined 250 +Making file <out-plugin_zero.h5repack_layout.h5>... +----------------------------------------- + Type Filter (Compression) Name +----------------------------------------- + group / +h5repack error: <h5repack_layout.h5>: Could not copy data to: out-plugin_zero.h5repack_layout.h5 |