diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2016-09-30 18:27:55 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2016-09-30 18:27:55 (GMT) |
commit | 6bf74ebdf21cd424225e827f55206905ae44ccc1 (patch) | |
tree | 7c11f225e6584b66f27881cc90a34a9d424d989c | |
parent | b2cb046d514861c54bd33a1ac85aa67ded3e240d (diff) | |
parent | f84e746de37c4b9ef11b4bf940208b1374c79e65 (diff) | |
download | hdf5-6bf74ebdf21cd424225e827f55206905ae44ccc1.zip hdf5-6bf74ebdf21cd424225e827f55206905ae44ccc1.tar.gz hdf5-6bf74ebdf21cd424225e827f55206905ae44ccc1.tar.bz2 |
Merge pull request #50 in HDFFV/hdf5 from ~BYRN/hdf5_adb:hdf5_1_8 to hdf5_1_8
* commit 'f84e746de37c4b9ef11b4bf940208b1374c79e65':
Fix error reporting
Update new test file references
revert merge change to cleanup files
Fix incorrect use of H5Rdereference2
remove merge typo
Remove unsupported function
Merge/align from trunk(develop)
Merge/align with trunk
Update functions to align with trunk
Fix function declaration
HDFFV-9974: Correct parsing of UD filter parameters. Verified by user, who reported issue. merge from https://bitbucket.hdfgroup.org/projects/HDFFV/repos/hdf5/commits/b947f7e911e498f5455a78836a6f82a042dd5b33
32 files changed, 3378 insertions, 3487 deletions
@@ -2032,6 +2032,7 @@ ./tools/h5repack/testfiles/h5repack_layout.h5.ddl ./tools/h5repack/testfiles/h5repack_layout.UD.h5-plugin_none.ddl ./tools/h5repack/testfiles/h5repack_layout.h5-plugin_test.ddl +./tools/h5repack/testfiles/h5repack_layout.h5-plugin_zero.tst # jam utility and tests ./tools/h5jam/h5jam.c diff --git a/config/cmake/HDF518_Examples.cmake.in b/config/cmake/HDF518_Examples.cmake.in index 5da1708..e1cb781 100644 --- a/config/cmake/HDF518_Examples.cmake.in +++ b/config/cmake/HDF518_Examples.cmake.in @@ -10,7 +10,7 @@ set(CTEST_DASHBOARD_ROOT ${CTEST_SCRIPT_DIRECTORY}) # handle input parameters to script. #INSTALLDIR - HDF5-1.8 root folder -#CTEST_BUILD_CONFIGURATION - Release, Debug, RelWithDebInfo +#CTEST_CONFIGURATION_TYPE - Release, Debug, RelWithDebInfo #CTEST_SOURCE_NAME - name of source folder; HDF4Examples #STATIC_LIBRARIES - Default is YES #FORTRAN_LIBRARIES - Default is NO @@ -29,8 +29,8 @@ endif() if(NOT DEFINED INSTALLDIR) set(INSTALLDIR "@CMAKE_INSTALL_PREFIX@") endif() -if(NOT DEFINED CTEST_BUILD_CONFIGURATION) - set(CTEST_BUILD_CONFIGURATION "Release") +if(NOT DEFINED CTEST_CONFIGURATION_TYPE) + set(CTEST_CONFIGURATION_TYPE "Release") endif() if(NOT DEFINED CTEST_SOURCE_NAME) set(CTEST_SOURCE_NAME "HDF5Examples") @@ -158,7 +158,7 @@ if(NOT N EQUAL 0) set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N}) endif() set (CTEST_CONFIGURE_COMMAND - "${CTEST_CMAKE_COMMAND} -C \"${CTEST_SOURCE_DIRECTORY}/config/cmake/cacheinit.cmake\" -DCMAKE_BUILD_TYPE:STRING=${CTEST_BUILD_CONFIGURATION} ${BUILD_OPTIONS} \"-G${CTEST_CMAKE_GENERATOR}\" \"${CTEST_SOURCE_DIRECTORY}\"" + "${CTEST_CMAKE_COMMAND} -C \"${CTEST_SOURCE_DIRECTORY}/config/cmake/cacheinit.cmake\" -DCMAKE_BUILD_TYPE:STRING=${CTEST_CONFIGURATION_TYPE} ${BUILD_OPTIONS} \"-G${CTEST_CMAKE_GENERATOR}\" \"${CTEST_SOURCE_DIRECTORY}\"" ) #----------------------------------------------------------------------------- @@ -171,19 +171,28 @@ ctest_read_custom_files ("${CTEST_BINARY_DIRECTORY}") ## NORMAL process ## -------------------------- ctest_start (Experimental) -ctest_configure (BUILD "${CTEST_BINARY_DIRECTORY}") +ctest_configure (BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res) +if(${res} LESS 0 OR ${res} GREATER 0) + file(APPEND ${CTEST_SCRIPT_DIRECTORY}/FailedCTest.txt "Failed Configure: ${res}\n") +endif() if(LOCAL_SUBMIT) ctest_submit (PARTS Configure Notes) endif() -ctest_build (BUILD "${CTEST_BINARY_DIRECTORY}" APPEND) +ctest_build (BUILD "${CTEST_BINARY_DIRECTORY}" APPEND APPEND RETURN_VALUE res NUMBER_ERRORS errval) +if(${res} LESS 0 OR ${res} GREATER 0 OR ${errval} GREATER 0) + file(APPEND ${CTEST_SCRIPT_DIRECTORY}/FailedCTest.txt "Failed ${errval} Build: ${res}\n") +endif() if(LOCAL_SUBMIT) ctest_submit (PARTS Build) endif() ctest_test (BUILD "${CTEST_BINARY_DIRECTORY}" APPEND ${ctest_test_args} RETURN_VALUE res) +if(${res} LESS 0 OR ${res} GREATER 0) + file(APPEND ${CTEST_SCRIPT_DIRECTORY}/FailedCTest.txt "Failed Tests: ${res}\n") +endif() if(LOCAL_SUBMIT) ctest_submit (PARTS Test) endif() -if(res GREATER 0) +if(${res} LESS 0 OR ${res} GREATER 0) message (FATAL_ERROR "tests FAILED") endif() #----------------------------------------------------------------------------- diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index 5b953cb..9efb6db 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -620,10 +620,9 @@ parse_hsize_list(const char *h_list, subset_d *d) size_count++; last_digit = 1; - } - else { - last_digit = 0; } + else + last_digit = 0; if (size_count == 0) /* there aren't any integers to read */ @@ -635,7 +634,7 @@ parse_hsize_list(const char *h_list, subset_d *d) for (ptr = h_list; i < size_count && ptr && *ptr && *ptr != ';' && *ptr != ']'; ptr++) if(HDisdigit(*ptr)) { /* we should have an integer now */ - p_list[i++] = (hsize_t)HDatof(ptr); + p_list[i++] = (hsize_t)HDstrtoull(ptr, NULL, 0); while (HDisdigit(*ptr)) /* scroll to end of integer */ @@ -643,8 +642,6 @@ parse_hsize_list(const char *h_list, subset_d *d) } d->data = p_list; d->len = size_count; - - return; } /*------------------------------------------------------------------------- @@ -667,7 +664,7 @@ static struct subset_t * parse_subset_params(char *dset) { struct subset_t *s = NULL; - register char *brace; + char *brace; if (!disable_compact_subset && ((brace = HDstrrchr(dset, '[')) != NULL)) { *brace++ = '\0'; @@ -705,20 +702,21 @@ parse_subset_params(char *dset) * * Purpose: Parse a list of comma or space separated integers and fill * the packed_bits list and counter. The string being passed into this function - * should be at the start of the list you want to parse. + * should be at the start of the list you want to parse. * * Return: Success: SUCCEED * * Failure: FAIL * - * *------------------------------------------------------------------------- */ static int parse_mask_list(const char *h_list) { - int offset_value; - int length_value; + int soffset_value; + unsigned offset_value; + int slength_value; + unsigned length_value; unsigned long long temp_mask; const char *ptr = NULL; @@ -736,10 +734,11 @@ parse_mask_list(const char *h_list) error_msg("Bad mask list(%s)\n", h_list); return FAIL; } - offset_value = HDatoi(ptr); - if (offset_value < 0 || offset_value >= PACKED_BITS_SIZE_MAX) { - error_msg("Packed Bit offset value(%d) must be between 0 and %d\n", - offset_value, PACKED_BITS_SIZE_MAX - 1); + soffset_value = HDatoi(ptr); + offset_value = (unsigned)soffset_value; + if (soffset_value < 0 || offset_value >= PACKED_BITS_SIZE_MAX) { + error_msg("Packed Bit offset value(%d) must be between 0 and %u\n", + soffset_value, (unsigned)(PACKED_BITS_SIZE_MAX - 1)); return FAIL; } @@ -757,14 +756,15 @@ parse_mask_list(const char *h_list) error_msg("Bad mask list(%s)\n", h_list); return FAIL; } - length_value = HDatoi(ptr); - if (length_value <= 0) { - error_msg("Packed Bit length value(%d) must be positive.\n", length_value); + slength_value = HDatoi(ptr); + if (slength_value <= 0) { + error_msg("Packed Bit length value(%d) must be positive.\n", slength_value); return FAIL; } - if ((offset_value + length_value) > PACKED_BITS_SIZE_MAX){ - error_msg("Packed Bit offset+length value(%d) too large. Max is %d\n", - offset_value+length_value, PACKED_BITS_SIZE_MAX); + length_value = (unsigned)slength_value; + if ((offset_value + length_value) > PACKED_BITS_SIZE_MAX) { + error_msg("Packed Bit offset+length value(%u) too large. Max is %u\n", + offset_value+length_value, (unsigned)PACKED_BITS_SIZE_MAX); return FAIL; } @@ -783,8 +783,8 @@ parse_mask_list(const char *h_list) /* create the bit mask by left shift 1's by length, then negate it. */ /* After packed_mask is calculated, packed_length is not needed but */ /* keep it for debug purpose. */ - temp_mask = ~0L; - if(length_value<8*sizeof(unsigned long long)) { + temp_mask = ~0ULL; + if(length_value < (int)(8 *sizeof(unsigned long long))) { temp_mask = temp_mask << length_value; packed_mask[packed_bits_num] = ~temp_mask; } @@ -831,7 +831,7 @@ static void free_handler(struct handler_t *hand, int len) { int i; - + if(hand) { for (i = 0; i < len; i++) { if(hand[i].obj) { @@ -956,11 +956,15 @@ parse_start: goto done; break; case 'w': - h5tools_nCols = HDatoi(opt_arg); - if (h5tools_nCols <= 0) { - h5tools_nCols = 65535; + { + int sh5tools_nCols = HDatoi(opt_arg); + + if (sh5tools_nCols <= 0) + h5tools_nCols = 65535; + else + h5tools_nCols = (unsigned)sh5tools_nCols; + last_was_dset = FALSE; } - last_was_dset = FALSE; break; case 'N': display_all = 0; @@ -1159,12 +1163,10 @@ parse_start: usage(h5tools_getprogname()); goto error; } - if (HDstrcmp(opt_arg,":") == 0) { + if (HDstrcmp(opt_arg,":") == 0) xmlnsprefix = ""; - } - else { + else xmlnsprefix = opt_arg; - } h5tools_nCols = 0; break; /** end XML parameters **/ @@ -1187,7 +1189,7 @@ parse_start: * the two. */ s = last_dset->subset_info; - } + } else { last_dset->subset_info = s = (struct subset_t *)HDcalloc(1, sizeof(struct subset_t)); } @@ -1358,7 +1360,7 @@ main(int argc, const char *argv[]) /* Disable tools error reporting */ H5Eget_auto2(H5tools_ERR_STACK_g, &tools_func, &tools_edata); H5Eset_auto2(H5tools_ERR_STACK_g, NULL, NULL); - + if((hand = parse_command_line(argc, argv))==NULL) { goto done; } @@ -1444,12 +1446,12 @@ main(int argc, const char *argv[]) if (xml_dtd_uri == NULL) { if (useschema) { xml_dtd_uri = DEFAULT_XSD; - } + } else { xml_dtd_uri = DEFAULT_DTD; xmlnsprefix = ""; } - } + } else { if (useschema && HDstrcmp(xmlnsprefix,"")) { error_msg("Cannot set Schema URL for a qualified namespace--use -X or -U option with -D \n"); @@ -1486,7 +1488,7 @@ main(int argc, const char *argv[]) /* start to dump - display file header information */ if (!doxml) { begin_obj(h5tools_dump_header_format->filebegin, fname, h5tools_dump_header_format->fileblockbegin); - } + } else { PRINTVALSTREAM(rawoutstream, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); @@ -1495,7 +1497,7 @@ main(int argc, const char *argv[]) if (HDstrcmp(xmlnsprefix,"") == 0) { PRINTSTREAM(rawoutstream, "<HDF5-File xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"%s\">\n", xml_dtd_uri); - } + } else { /* TO DO: make -url option work in this case (may need new option) */ char *ns; @@ -1511,7 +1513,7 @@ main(int argc, const char *argv[]) "http://www.hdfgroup.org/HDF5/XML/schema/HDF5-File.xsd\">\n",xmlnsprefix,ns); HDfree(ns); } - } + } else { PRINTSTREAM(rawoutstream, "<!DOCTYPE HDF5-File PUBLIC \"HDF5-File.dtd\" \"%s\">\n", xml_dtd_uri); PRINTVALSTREAM(rawoutstream, "<HDF5-File>\n"); @@ -1570,7 +1572,7 @@ main(int argc, const char *argv[]) if (!doxml) { end_obj(h5tools_dump_header_format->fileend, h5tools_dump_header_format->fileblockend); PRINTVALSTREAM(rawoutstream, "\n"); - } + } else { PRINTSTREAM(rawoutstream, "</%sHDF5-File>\n", xmlnsprefix); } @@ -1591,7 +1593,7 @@ main(int argc, const char *argv[]) } } /* end while */ - if(hand) + if(hand) free_handler(hand, argc); /* To Do: clean up XML table */ @@ -1615,7 +1617,7 @@ done: fname = NULL; } - if(hand) + if(hand) free_handler(hand, argc); /* To Do: clean up XML table */ @@ -1668,20 +1670,20 @@ h5_fileaccess(void) if (!HDstrcmp(name, "sec2")) { /* Unix read() and write() system calls */ if (H5Pset_fapl_sec2(fapl)<0) return -1; - } + } else if (!HDstrcmp(name, "stdio")) { /* Standard C fread() and fwrite() system calls */ if (H5Pset_fapl_stdio(fapl)<0) return -1; - } + } else if (!HDstrcmp(name, "core")) { /* In-core temporary file with 1MB increment */ if (H5Pset_fapl_core(fapl, 1024*1024, FALSE)<0) return -1; - } + } else if (!HDstrcmp(name, "split")) { /* Split meta data and raw data each using default driver */ if (H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT) < 0) return -1; - } + } else if (!HDstrcmp(name, "multi")) { /* Multi-file driver, general case of the split driver */ H5FD_mem_t memb_map[H5FD_MEM_NTYPES]; @@ -1702,12 +1704,12 @@ h5_fileaccess(void) memb_map[mt] = mt; sprintf(sv[mt], "%%s-%c.h5", multi_letters[mt]); memb_name[mt] = sv[mt]; - memb_addr[mt] = MAX(mt-1,0)*(HADDR_MAX/10); + memb_addr[mt] = (haddr_t)MAX(mt - 1, 0) * (HADDR_MAX / 10); } if (H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name, memb_addr, FALSE) < 0) return -1; - } + } else if (!HDstrcmp(name, "family")) { hsize_t fam_size = 100*1024*1024; /*100 MB*/ @@ -1716,7 +1718,7 @@ h5_fileaccess(void) fam_size = (hsize_t)(HDstrtod(val, NULL) * 1024*1024); if (H5Pset_fapl_family(fapl, fam_size, H5P_DEFAULT)<0) return -1; - } + } else if (!HDstrcmp(name, "log")) { long log_flags = H5FD_LOG_LOC_IO; @@ -1726,12 +1728,12 @@ h5_fileaccess(void) if (H5Pset_fapl_log(fapl, NULL, (unsigned)log_flags, 0) < 0) return -1; - } + } else if (!HDstrcmp(name, "direct")) { /* Substitute Direct I/O driver with sec2 driver temporarily because * some output has sec2 driver as the standard. */ if (H5Pset_fapl_sec2(fapl)<0) return -1; - } + } else { /* Unknown driver */ return -1; diff --git a/tools/h5dump/h5dump.h b/tools/h5dump/h5dump.h index a1f5b22..e9b8233 100644 --- a/tools/h5dump/h5dump.h +++ b/tools/h5dump/h5dump.h @@ -39,11 +39,11 @@ typedef struct dump_functions_t { /* List of table structures. There is one table structure for each file */ typedef struct h5dump_table_items_t { - unsigned long fileno; /* File number that these tables refer to */ - hid_t oid; /* ID of an object in this file, held open so fileno is consistent */ - table_t *group_table; /* Table of groups */ - table_t *dset_table; /* Table of datasets */ - table_t *type_table; /* Table of datatypes */ + unsigned long fileno; /* File number that these tables refer to */ + hid_t oid; /* ID of an object in this file, held open so fileno is consistent */ + table_t *group_table; /* Table of groups */ + table_t *dset_table; /* Table of datasets */ + table_t *type_table; /* Table of datatypes */ } h5dump_table_items_t; typedef struct h5dump_table_list_t { size_t nalloc; @@ -53,7 +53,7 @@ typedef struct h5dump_table_list_t { h5dump_table_list_t table_list = {0, 0, NULL}; table_t *group_table = NULL, *dset_table = NULL, *type_table = NULL; -int dump_indent = 0; /*how far in to indent the line */ +unsigned dump_indent = 0; /*how far in to indent the line */ int unamedtype = 0; /* shared datatype with no name */ hbool_t hit_elink = FALSE; /* whether we have traversed an external link */ @@ -74,7 +74,6 @@ int display_fi = FALSE; /*file index */ int display_ai = TRUE; /*array index */ int display_escape = FALSE; /*escape non printable characters */ int display_region = FALSE; /*print region reference data */ -int enable_error_stack= FALSE; /* re-enable error stack */ int disable_compact_subset= FALSE; /* disable compact form of subset notation */ int display_packed_bits = FALSE; /*print 1-8 byte numbers as packed bits*/ int include_attrs = TRUE; /* Display attributes */ @@ -84,13 +83,13 @@ H5_index_t sort_by = H5_INDEX_NAME; /*sort_by [creation_order | name H5_iter_order_t sort_order = H5_ITER_INC; /*sort_order [ascending | descending] */ #define PACKED_BITS_MAX 8 /* Maximum number of packed-bits to display */ -#define PACKED_BITS_SIZE_MAX 8*sizeof(long long) /* Maximum bits size of integer types of packed-bits */ +#define PACKED_BITS_SIZE_MAX (8*sizeof(long long)) /* Maximum bits size of integer types of packed-bits */ /* mask list for packed bits */ unsigned long long packed_mask[PACKED_BITS_MAX]; /* packed bits are restricted to 8*sizeof(llong) bytes */ /* packed bits display parameters */ -int packed_offset[PACKED_BITS_MAX]; -int packed_length[PACKED_BITS_MAX]; +unsigned packed_offset[PACKED_BITS_MAX]; +unsigned packed_length[PACKED_BITS_MAX]; /* * The global table is set to either ddl_function_table or diff --git a/tools/h5dump/h5dump_ddl.c b/tools/h5dump/h5dump_ddl.c index 0324a52..c0b1833 100644 --- a/tools/h5dump/h5dump_ddl.c +++ b/tools/h5dump/h5dump_ddl.c @@ -26,12 +26,12 @@ typedef struct { hid_t fid; /* File ID being traversed */ - char *op_name; /* Object name wanted */ + const char *op_name; /* Object name wanted */ } trav_handle_udata_t; typedef struct { - char *path; /* Path of object being searched */ - char *op_name; /* Object name wanted */ + const char *path; /* Path of object being searched */ + const char *op_name; /* Object name wanted */ } trav_attr_udata_t; /* callback function used by H5Literate() */ @@ -59,7 +59,7 @@ dump_datatype(hid_t type) h5tool_format_t *outputformat = &h5tools_dataformat; HDmemset(&ctx, 0, sizeof(ctx)); - ctx.indent_level = dump_indent/COL; + ctx.indent_level = dump_indent / COL; ctx.cur_column = dump_indent; h5dump_type_table = type_table; @@ -88,9 +88,9 @@ dump_dataspace(hid_t space) h5tool_format_t *outputformat = &h5tools_dataformat; HDmemset(&ctx, 0, sizeof(ctx)); - ctx.indent_level = dump_indent/COL; + ctx.indent_level = dump_indent / COL; ctx.cur_column = dump_indent; - + h5tools_dump_dataspace(rawoutstream, outputformat, &ctx, space); } @@ -117,19 +117,19 @@ dump_attr_cb(hid_t oid, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED * h5tools_context_t ctx; /* print context */ h5tool_format_t *outputformat = &h5tools_dataformat; h5tool_format_t string_dataformat; - + hid_t attr_id; herr_t ret = SUCCEED; HDmemset(&ctx, 0, sizeof(ctx)); - ctx.indent_level = dump_indent/COL; + ctx.indent_level = dump_indent / COL; ctx.cur_column = dump_indent; - + attr_id = H5Aopen(oid, attr_name, H5P_DEFAULT); oid_output = display_oid; data_output = display_data; attr_data_output = display_attr_data; - + string_dataformat = *outputformat; if (fp_format) { @@ -137,7 +137,7 @@ dump_attr_cb(hid_t oid, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED * string_dataformat.fmt_float = fp_format; } - if (h5tools_nCols==0) { + if (h5tools_nCols == 0) { string_dataformat.line_ncols = 65535; string_dataformat.line_per_line = 1; } @@ -155,7 +155,7 @@ dump_attr_cb(hid_t oid, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED * h5tools_setstatus(EXIT_FAILURE); ret = FAIL; } - + return ret; } @@ -197,9 +197,9 @@ dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void H5_ATTR HDmemset(&buffer, 0, sizeof(h5tools_str_t)); HDmemset(&ctx, 0, sizeof(ctx)); - ctx.indent_level = dump_indent/COL; + ctx.indent_level = dump_indent / COL; ctx.cur_column = dump_indent; - + string_dataformat = *outputformat; if (fp_format) { @@ -207,7 +207,7 @@ dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void H5_ATTR string_dataformat.fmt_float = fp_format; } - if (h5tools_nCols==0) { + if (h5tools_nCols == 0) { string_dataformat.line_ncols = 65535; string_dataformat.line_per_line = 1; } @@ -222,8 +222,8 @@ dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void H5_ATTR if(!obj_path) { ret = FAIL; goto done; - } - + } + HDstrcpy(obj_path, prefix); HDstrcat(obj_path, "/"); HDstrcat(obj_path, name); @@ -310,7 +310,7 @@ dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void H5_ATTR ret = FAIL; H5Dclose(obj); goto done; - } + } else if(found_obj->displayed) { ctx.need_prefix = TRUE; h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0); @@ -349,7 +349,7 @@ dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void H5_ATTR H5Dclose(obj); goto done; - } + } else { found_obj->displayed = TRUE; } @@ -357,7 +357,7 @@ dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void H5_ATTR dump_function_table->dump_dataset_function(obj, name, NULL); H5Dclose(obj); - } + } else { error_msg("unable to dump dataset \"%s\"\n", name); h5tools_setstatus(EXIT_FAILURE); @@ -370,7 +370,7 @@ dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void H5_ATTR error_msg("unable to dump datatype \"%s\"\n", name); h5tools_setstatus(EXIT_FAILURE); ret = FAIL; - } + } else { dump_function_table->dump_named_datatype_function(obj, name); H5Tclose(obj); @@ -408,7 +408,7 @@ dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void H5_ATTR error_msg("unable to get link value\n"); h5tools_setstatus(EXIT_FAILURE); ret = FAIL; - } + } else { /* print the value of a soft link */ /* Standard DDL: no modification */ @@ -558,7 +558,7 @@ dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void H5_ATTR done: h5tools_str_close(&buffer); - + if(obj_path) HDfree(obj_path); return ret; @@ -648,9 +648,9 @@ dump_named_datatype(hid_t tid, const char *name) HDmemset(&buffer, 0, sizeof(h5tools_str_t)); HDmemset(&ctx, 0, sizeof(ctx)); - ctx.indent_level = dump_indent/COL; + ctx.indent_level = dump_indent / COL; ctx.cur_column = dump_indent; - + string_dataformat = *outputformat; if (fp_format) { @@ -658,7 +658,7 @@ dump_named_datatype(hid_t tid, const char *name) string_dataformat.fmt_float = fp_format; } - if (h5tools_nCols==0) { + if (h5tools_nCols == 0) { string_dataformat.line_ncols = 65535; string_dataformat.line_per_line = 1; } @@ -685,7 +685,7 @@ dump_named_datatype(hid_t tid, const char *name) } ctx.need_prefix = TRUE; - + /* Render the element */ h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "%s \"%s\" %s", @@ -718,7 +718,7 @@ dump_named_datatype(hid_t tid, const char *name) else found_obj->displayed = TRUE; } /* end if */ - + /* Render the element */ h5tools_str_reset(&buffer); h5tools_print_datatype(rawoutstream, &buffer, outputformat, &ctx, tid, FALSE); @@ -726,7 +726,7 @@ dump_named_datatype(hid_t tid, const char *name) if(H5Tget_class(tid) != H5T_COMPOUND) { h5tools_str_append(&buffer, ";"); } - + h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0); /* print attributes */ @@ -811,9 +811,9 @@ dump_group(hid_t gid, const char *name) HDmemset(&buffer, 0, sizeof(h5tools_str_t)); HDmemset(&ctx, 0, sizeof(ctx)); - ctx.indent_level = dump_indent/COL; + ctx.indent_level = dump_indent / COL; ctx.cur_column = dump_indent; - + string_dataformat = *outputformat; if (fp_format) { @@ -821,7 +821,7 @@ dump_group(hid_t gid, const char *name) string_dataformat.fmt_float = fp_format; } - if (h5tools_nCols==0) { + if (h5tools_nCols == 0) { string_dataformat.line_ncols = 65535; string_dataformat.line_per_line = 1; } @@ -839,7 +839,7 @@ dump_group(hid_t gid, const char *name) h5tools_dump_header_format->groupbegin, name, h5tools_dump_header_format->groupblockbegin); h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0); - + ctx.indent_level++; dump_indent += COL; @@ -858,9 +858,8 @@ dump_group(hid_t gid, const char *name) } } /* end if */ - if(display_oid) { + if(display_oid) h5tools_dump_oid(rawoutstream, outputformat, &ctx, gid); - } h5tools_dump_comment(rawoutstream, outputformat, &ctx, gid); @@ -946,9 +945,9 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset) hsize_t curr_pos = 0; /* total data element position */ HDmemset(&ctx, 0, sizeof(ctx)); - ctx.indent_level = dump_indent/COL; + ctx.indent_level = dump_indent / COL; ctx.cur_column = dump_indent; - + string_dataformat = *outputformat; if (fp_format) { @@ -956,7 +955,7 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset) string_dataformat.fmt_float = fp_format; } - if (h5tools_nCols==0) { + if (h5tools_nCols == 0) { string_dataformat.line_ncols = 65535; string_dataformat.line_per_line = 1; } @@ -982,7 +981,7 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset) ctx.need_prefix = TRUE; h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0); - + /* Render the element */ h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "%s \"%s\" %s", @@ -994,7 +993,7 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset) dump_indent += COL; ctx.indent_level++; - + type = H5Dget_type(did); h5dump_type_table = type_table; h5tools_dump_datatype(rawoutstream, outputformat, &ctx, type); @@ -1016,19 +1015,20 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset) H5Pclose(dcpl_id); if(display_data) { - int data_loop = 1; - int i; + unsigned data_loop = 1; + unsigned u; + if(display_packed_bits) data_loop = packed_bits_num; - for(i=0; i<data_loop; i++) { + for(u = 0; u < data_loop; u++) { if(display_packed_bits) { ctx.need_prefix = TRUE; h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0); /* Render the element */ h5tools_str_reset(&buffer); - packed_data_mask = packed_mask[i]; - packed_data_offset = packed_offset[i]; - packed_data_length = packed_length[i]; + packed_data_mask = packed_mask[u]; + packed_data_offset = packed_offset[u]; + packed_data_length = packed_length[u]; h5tools_print_packed_bits(&buffer, type); h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0); } @@ -1042,7 +1042,7 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset) h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "DATA{ not yet implemented.}"); h5tools_render_element(rawoutstream, outputformat, &ctx, &buffer, &curr_pos, (size_t)outputformat->line_ncols, (hsize_t)0, (hsize_t)0); - + ctx.indent_level--; break; @@ -1067,7 +1067,7 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset) HDassert(0); break; } /* end switch */ - } /* for(i=0;i<data_loop;i++) */ + } /* for(u=0; u<data_loop; u++) */ } H5Tclose(type); @@ -1079,7 +1079,7 @@ dump_dataset(hid_t did, const char *name, struct subset_t *sset) ctx.need_prefix = TRUE; h5tools_simple_prefix(rawoutstream, outputformat, &ctx, (hsize_t)0, 0); - + /* Render the element */ h5tools_str_reset(&buffer); if(HDstrlen(h5tools_dump_header_format->datasetblockend)) { @@ -1124,7 +1124,7 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int display_index) string_dataformat.fmt_float = fp_format; } - if (h5tools_nCols==0) { + if (h5tools_nCols == 0) { string_dataformat.line_ncols = 65535; string_dataformat.line_per_line = 1; } @@ -1135,7 +1135,7 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int display_index) outputformat = &string_dataformat; HDmemset(&ctx, 0, sizeof(ctx)); - ctx.indent_level = dump_indent/COL; + ctx.indent_level = dump_indent / COL; ctx.cur_column = dump_indent; if(obj_data == DATASET_DATA) @@ -1189,7 +1189,7 @@ dump_fcpl(hid_t fid) fdriver=H5Pget_driver(fapl); H5Pclose(fapl); #endif - + /*------------------------------------------------------------------------- * SUPER_BLOCK *------------------------------------------------------------------------- @@ -1279,9 +1279,8 @@ dump_fcontents(hid_t fid) unsigned u; for (u = 0; u < type_table->nobjs; u++) { - if (!type_table->objs[u].recorded) { + if (!type_table->objs[u].recorded) PRINTSTREAM(rawoutstream, " %-10s /#"H5_PRINTF_HADDR_FMT"\n", "datatype", type_table->objs[u].objno); - } } } @@ -1295,54 +1294,54 @@ static herr_t attr_search(hid_t oid, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED *ainfo, void *_op_data) { herr_t ret = SUCCEED; - int i; - int j; - int k; - char *obj_op_name; + int j; + char *obj_op_name; char *obj_name; - trav_attr_udata_t *attr_data = (trav_attr_udata_t*)_op_data; - char *buf = attr_data->path; - char *op_name = attr_data->op_name; + trav_attr_udata_t *attr_data = (trav_attr_udata_t*)_op_data; + const char *buf = attr_data->path; + const char *op_name = attr_data->op_name; j = (int)HDstrlen(op_name) - 1; /* find the last / */ while(j >= 0) { - if (op_name[j] == '/' && (j==0 || (j>0 && op_name[j-1]!='\\'))) - break; - j--; + if(op_name[j] == '/' && (j == 0 || (j > 0 && op_name[j - 1] != '\\'))) + break; + j--; } obj_op_name = h5tools_str_replace(op_name + j + 1, "\\/", "/"); if(obj_op_name == NULL) { - h5tools_setstatus(EXIT_FAILURE); - ret = FAIL; + h5tools_setstatus(EXIT_FAILURE); + ret = FAIL; } else { - if(HDstrcmp(attr_name, obj_op_name)==0) { - /* object name */ - i = (int)HDstrlen(buf); - j = (int)HDstrlen(op_name); - k = (size_t)i + 1 + (size_t)j + 1 + 2; - obj_name = (char *)HDmalloc((size_t)k); - if(obj_name == NULL) { - h5tools_setstatus(EXIT_FAILURE); - ret = FAIL; - } - else { - HDmemset(obj_name, '\0', (size_t)k); - if(op_name[0] != '/') { - HDstrncat(obj_name, buf, (size_t)i + 1); - if(buf[i-1] != '/') - HDstrncat(obj_name, "/", (size_t)2); - } - HDstrncat(obj_name, op_name, (size_t)j + 1); - - handle_attributes(oid, obj_name, NULL, 0, NULL); - HDfree(obj_name); - } - } - HDfree(obj_op_name); + if(HDstrcmp(attr_name, obj_op_name)==0) { + size_t u, v, w; + + /* object name */ + u = HDstrlen(buf); + v = HDstrlen(op_name); + w = u + 1 + v + 1 + 2; + obj_name = (char *)HDmalloc(w); + if(obj_name == NULL) { + h5tools_setstatus(EXIT_FAILURE); + ret = FAIL; + } + else { + HDmemset(obj_name, '\0', w); + if(op_name[0] != '/') { + HDstrncat(obj_name, buf, u + 1); + if(buf[u - 1] != '/') + HDstrncat(obj_name, "/", (size_t)2); + } + HDstrncat(obj_name, op_name, v + 1); + + handle_attributes(oid, obj_name, NULL, 0, NULL); + HDfree(obj_name); + } + } + HDfree(obj_op_name); } return ret; } /* end attr_search() */ @@ -1350,31 +1349,34 @@ attr_search(hid_t oid, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED *a static herr_t obj_search(const char *path, const H5O_info_t *oi, const char H5_ATTR_UNUSED *already_visited, void *_op_data) { - trav_handle_udata_t *handle_data = (trav_handle_udata_t*)_op_data; - char *op_name = (char*)handle_data->op_name; - + trav_handle_udata_t *handle_data = (trav_handle_udata_t*)_op_data; + const char *op_name = handle_data->op_name; trav_attr_udata_t attr_data; - attr_data.path = (char*)path; + + attr_data.path = path; attr_data.op_name = op_name; H5Aiterate_by_name(handle_data->fid, path, H5_INDEX_NAME, H5_ITER_INC, NULL, attr_search, (void*)&attr_data, H5P_DEFAULT); - if(HDstrcmp(path, op_name)==0) { - switch(oi->type) { - case H5O_TYPE_GROUP: - handle_groups(handle_data->fid, path, NULL, 0, NULL); - break; - case H5O_TYPE_DATASET: - handle_datasets(handle_data->fid, path, NULL, 0, NULL); - break; - case H5O_TYPE_NAMED_DATATYPE: - handle_datatypes(handle_data->fid, path, NULL, 0, NULL); - break; - case H5O_TYPE_UNKNOWN: - case H5O_TYPE_NTYPES: - default: - error_msg("unknown object type value\n"); - h5tools_setstatus(EXIT_FAILURE); - } /* end switch */ + if(HDstrcmp(path, op_name) == 0) { + switch(oi->type) { + case H5O_TYPE_GROUP: + handle_groups(handle_data->fid, path, NULL, 0, NULL); + break; + + case H5O_TYPE_DATASET: + handle_datasets(handle_data->fid, path, NULL, 0, NULL); + break; + + case H5O_TYPE_NAMED_DATATYPE: + handle_datatypes(handle_data->fid, path, NULL, 0, NULL); + break; + + case H5O_TYPE_UNKNOWN: + case H5O_TYPE_NTYPES: + default: + error_msg("unknown object type value\n"); + h5tools_setstatus(EXIT_FAILURE); + } /* end switch */ } return 0; @@ -1383,49 +1385,48 @@ obj_search(const char *path, const H5O_info_t *oi, const char H5_ATTR_UNUSED *al static herr_t lnk_search(const char *path, const H5L_info_t *li, void *_op_data) { - int search_len; - int k; + size_t search_len; + size_t k; char *search_name; - trav_handle_udata_t *handle_data = (trav_handle_udata_t*)_op_data; - char *op_name = (char*)handle_data->op_name; + trav_handle_udata_t *handle_data = (trav_handle_udata_t*)_op_data; + const char *op_name = handle_data->op_name; search_len = HDstrlen(op_name); - if(search_len > 0 && op_name[0] != '/') { - k = 2; - } + if(search_len > 0 && op_name[0] != '/') + k = 2; else k = 1; - search_name = (char *)HDmalloc((size_t)(search_len + k)); + search_name = (char *)HDmalloc(search_len + k); if(search_name == NULL) { - error_msg("creating temporary link\n"); - h5tools_setstatus(EXIT_FAILURE); + error_msg("creating temporary link\n"); + h5tools_setstatus(EXIT_FAILURE); } else { - if (k == 2) { - HDstrcpy(search_name, "/"); - HDstrncat(search_name, op_name, (size_t)search_len + 1); - } - else - HDstrncpy(search_name, op_name, (size_t)search_len + 1); - search_name[search_len + k - 1] = '\0'; - - if(HDstrcmp(path, search_name) == 0) { - switch(li->type) { - case H5L_TYPE_SOFT: - case H5L_TYPE_EXTERNAL: - handle_links(handle_data->fid, op_name, NULL, 0, NULL); - break; - - case H5L_TYPE_HARD: - case H5L_TYPE_MAX: - case H5L_TYPE_ERROR: - default: - error_msg("unknown link type value\n"); - h5tools_setstatus(EXIT_FAILURE); - break; - } /* end switch() */ - } - HDfree(search_name); + if (k == 2) { + HDstrcpy(search_name, "/"); + HDstrncat(search_name, op_name, search_len + 1); + } + else + HDstrncpy(search_name, op_name, search_len + 1); + search_name[search_len + k - 1] = '\0'; + + if(HDstrcmp(path, search_name) == 0) { + switch(li->type) { + case H5L_TYPE_SOFT: + case H5L_TYPE_EXTERNAL: + handle_links(handle_data->fid, op_name, NULL, 0, NULL); + break; + + case H5L_TYPE_HARD: + case H5L_TYPE_MAX: + case H5L_TYPE_ERROR: + default: + error_msg("unknown link type value\n"); + h5tools_setstatus(EXIT_FAILURE); + break; + } /* end switch() */ + } + HDfree(search_name); } return 0; } /* end lnk_search() */ @@ -1452,7 +1453,7 @@ handle_paths(hid_t fid, const char *path_name, void H5_ATTR_UNUSED * data, int H hid_t gcpl_id; unsigned crt_order_flags; unsigned attr_crt_order_flags; - trav_handle_udata_t handle_udata; /* User data for traversal */ + trav_handle_udata_t handle_udata; /* User data for traversal */ if ((gcpl_id = H5Gget_create_plist(gid)) < 0) { error_msg("error in getting group creation property list ID\n"); @@ -1476,12 +1477,12 @@ handle_paths(hid_t fid, const char *path_name, void H5_ATTR_UNUSED * data, int H h5tools_setstatus(EXIT_FAILURE); } - handle_udata.fid = fid; - handle_udata.op_name = (char*)path_name; - if(h5trav_visit(fid, "/", TRUE, TRUE, obj_search, lnk_search, &handle_udata) < 0) { - error_msg("error traversing information\n"); - h5tools_setstatus(EXIT_FAILURE); - } + handle_udata.fid = fid; + handle_udata.op_name = path_name; + if(h5trav_visit(fid, "/", TRUE, TRUE, obj_search, lnk_search, &handle_udata) < 0) { + error_msg("error traversing information\n"); + h5tools_setstatus(EXIT_FAILURE); + } } } @@ -1505,8 +1506,8 @@ handle_paths(hid_t fid, const char *path_name, void H5_ATTR_UNUSED * data, int H void handle_attributes(hid_t fid, const char *attr, void H5_ATTR_UNUSED * data, int H5_ATTR_UNUSED pe, const char H5_ATTR_UNUSED *display_name) { - hid_t oid = -1; - hid_t attr_id = -1; + hid_t oid = -1; + hid_t attr_id = -1; char *obj_name = NULL; char *attr_name = NULL; int j; @@ -1523,7 +1524,7 @@ handle_attributes(hid_t fid, const char *attr, void H5_ATTR_UNUSED * data, int H /* find the last / */ while(j >= 0) { - if (attr[j] == '/' && (j==0 || (j>0 && attr[j-1]!='\\'))) + if (attr[j] == '/' && (j==0 || (j>0 && attr[j-1]!='\\'))) break; j--; } @@ -1538,7 +1539,7 @@ handle_attributes(hid_t fid, const char *attr, void H5_ATTR_UNUSED * data, int H dump_indent += COL; HDmemset(&ctx, 0, sizeof(ctx)); - ctx.indent_level = dump_indent/COL; + ctx.indent_level = dump_indent / COL; ctx.cur_column = dump_indent; string_dataformat = *outputformat; @@ -1548,7 +1549,7 @@ handle_attributes(hid_t fid, const char *attr, void H5_ATTR_UNUSED * data, int H string_dataformat.fmt_float = fp_format; } - if (h5tools_nCols==0) { + if (h5tools_nCols == 0) { string_dataformat.line_ncols = 65535; string_dataformat.line_per_line = 1; } @@ -1558,7 +1559,7 @@ handle_attributes(hid_t fid, const char *attr, void H5_ATTR_UNUSED * data, int H string_dataformat.do_escape = display_escape; outputformat = &string_dataformat; - attr_name = h5tools_str_replace(attr + j + 1, "\\/", "/"); + attr_name = h5tools_str_replace(attr + j + 1, "\\/", "/"); /* handle error case: cannot open the object with the attribute */ if((oid = H5Oopen(fid, obj_name, H5P_DEFAULT)) < 0) { @@ -1614,7 +1615,7 @@ handle_attributes(hid_t fid, const char *attr, void H5_ATTR_UNUSED * data, int H } /* end if */ HDfree(obj_name); - HDfree(attr_name); + HDfree(attr_name); dump_indent -= COL; return; @@ -1622,9 +1623,9 @@ error: h5tools_setstatus(EXIT_FAILURE); if(obj_name) HDfree(obj_name); - - if (attr_name) - HDfree(attr_name); + + if (attr_name) + HDfree(attr_name); H5E_BEGIN_TRY { H5Oclose(oid); @@ -1681,8 +1682,7 @@ handle_datasets(hid_t fid, const char *dset, void *data, int pe, const char *dis h5tools_setstatus(EXIT_FAILURE); return; } - else - ndims = ndims_res; + ndims = (unsigned)ndims_res; if(!sset->start.data || !sset->stride.data || !sset->count.data || !sset->block.data) { /* they didn't specify a ``stride'' or ``block''. default to 1 in all @@ -1739,7 +1739,7 @@ handle_datasets(hid_t fid, const char *dset, void *data, int pe, const char *dis h5tools_setstatus(EXIT_FAILURE); return; } - + /*------------------------------------------------------------------------- * check for block overlap *------------------------------------------------------------------------- @@ -1772,7 +1772,7 @@ handle_datasets(hid_t fid, const char *dset, void *data, int pe, const char *dis PRINTSTREAM(rawoutstream, "%s \"%s\"\n", HARDLINK, found_obj->objname); indentation(dump_indent); end_obj(h5tools_dump_header_format->datasetend, h5tools_dump_header_format->datasetblockend); - } + } else { found_obj->displayed = TRUE; dump_indent += COL; @@ -1871,11 +1871,11 @@ handle_links(hid_t fid, const char *links, void H5_ATTR_UNUSED * data, int H5_AT if(H5Lget_info(fid, links, &linfo, H5P_DEFAULT) < 0) { error_msg("unable to get link info from \"%s\"\n", links); h5tools_setstatus(EXIT_FAILURE); - } + } else if(linfo.type == H5L_TYPE_HARD) { error_msg("\"%s\" is a hard link\n", links); h5tools_setstatus(EXIT_FAILURE); - } + } else { char *buf = (char *)HDmalloc(linfo.u.val_size); PRINTVALSTREAM(rawoutstream, "\n"); @@ -1912,12 +1912,12 @@ handle_links(hid_t fid, const char *links, void H5_ATTR_UNUSED * data, int H5_AT PRINTSTREAM(rawoutstream, "TARGETFILE \"%s\"\n", elink_file); indentation(COL); PRINTSTREAM(rawoutstream, "TARGETPATH \"%s\"\n", elink_path); - } + } else { error_msg("h5dump error: unable to unpack external link value for \"%s\"\n", links); h5tools_setstatus(EXIT_FAILURE); } - } + } else { error_msg("h5dump error: unable to get external link value for \"%s\"\n", links); h5tools_setstatus(EXIT_FAILURE); @@ -2091,12 +2091,15 @@ dump_extlink(hid_t group, const char *linkname, const char *objname) case H5O_TYPE_GROUP: handle_groups(group, linkname, NULL, 0, objname); break; + case H5O_TYPE_DATASET: handle_datasets(group, linkname, NULL, 0, objname); break; + case H5O_TYPE_NAMED_DATATYPE: handle_datatypes(group, linkname, NULL, 0, objname); break; + case H5O_TYPE_UNKNOWN: case H5O_TYPE_NTYPES: default: diff --git a/tools/h5repack/CMakeTests.cmake b/tools/h5repack/CMakeTests.cmake index b87de7b..c7171d8 100644 --- a/tools/h5repack/CMakeTests.cmake +++ b/tools/h5repack/CMakeTests.cmake @@ -86,11 +86,13 @@ ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/h5repack.info ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/deflate_limit.h5repack_layout.h5.ddl ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/h5repack_layout.h5.ddl + ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/h5repack_filters.h5-gzip_verbose_filters.tst ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/h5repack_filters.h5.tst ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/h5repack_layout.h5-plugin_test.ddl ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/plugin_test.h5repack_layout.h5.tst ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/h5repack_layout.UD.h5-plugin_none.ddl ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/plugin_none.h5repack_layout.UD.h5.tst + ${HDF5_TOOLS_H5REPACK_SOURCE_DIR}/testfiles/h5repack_layout.h5-plugin_zero.tst ) foreach (h5_file ${LIST_HDF5_TEST_FILES} ${LIST_OTHER_TEST_FILES}) @@ -208,7 +210,7 @@ -D "TEST_OUTPUT=${resultfile}-${testname}.out" -D "TEST_EXPECT=${resultcode}" -D "TEST_FILTER:STRING=${testfilter}" - -D "TEST_REFERENCE=${resultfile}.tst" + -D "TEST_REFERENCE=${resultfile}-${testname}.tst" -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" ) endif (HDF5_ENABLE_USING_MEMCHECKER) @@ -988,6 +990,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 8a9090a..3f99374 100644 --- a/tools/h5repack/h5repack.c +++ b/tools/h5repack/h5repack.c @@ -118,35 +118,36 @@ int h5repack_end(pack_opt_t *options) { * *------------------------------------------------------------------------- */ -int h5repack_addfilter(const char* str, pack_opt_t *options) { - obj_list_t *obj_list = NULL; /* one object list for the -f and -l option entry */ - filter_info_t filter; /* filter info for the current -f option entry */ - int n_objs; /* number of objects in the current -f or -l option entry */ - int is_glb; /* is the filter global */ - - /* parse the -f option */ - if (NULL == (obj_list = parse_filter(str, &n_objs, &filter, options, &is_glb))) - return -1; - - /* if it applies to all objects */ - if (is_glb) { - int n; - - n = options->n_filter_g++; /* increase # of global filters */ - - if (options->n_filter_g > H5_REPACK_MAX_NFILTERS) { - error_msg("maximum number of filters exceeded for <%s>\n", str); - HDfree(obj_list); - return -1; - } - - options->filter_g[n] = filter; - } - else - options_add_filter(obj_list, n_objs, filter, options->op_tbl); - - HDfree(obj_list); - return 0; +int +h5repack_addfilter(const char* str, pack_opt_t *options) +{ + obj_list_t *obj_list = NULL; /* one object list for the -f and -l option entry */ + filter_info_t filter; /* filter info for the current -f option entry */ + unsigned n_objs; /* number of objects in the current -f or -l option entry */ + int is_glb; /* is the filter global */ + + /* parse the -f option */ + if (NULL == (obj_list = parse_filter(str, &n_objs, &filter, options, &is_glb))) + return -1; + + /* if it applies to all objects */ + if (is_glb) { + int n; + + n = options->n_filter_g++; /* increase # of global filters */ + if (options->n_filter_g > H5_REPACK_MAX_NFILTERS) { + error_msg("maximum number of filters exceeded for <%s>\n", str); + HDfree(obj_list); + return -1; + } + + options->filter_g[n] = filter; + } + else + options_add_filter(obj_list, n_objs, filter, options->op_tbl); + + HDfree(obj_list); + return 0; } /*------------------------------------------------------------------------- @@ -158,59 +159,53 @@ int h5repack_addfilter(const char* str, pack_opt_t *options) { * *------------------------------------------------------------------------- */ - -int h5repack_addlayout(const char* str, pack_opt_t *options) { - - obj_list_t *obj_list = NULL; /*one object list for the -t and -c option entry */ - int n_objs; /*number of objects in the current -t or -c option entry */ - pack_info_t pack; /*info about layout to extract from parse */ - int j; - int ret_value = -1; - - init_packobject(&pack); - - if (options->all_layout == 1) { - error_msg( - "invalid layout input: 'all' option \ - is present with other objects <%s>\n", - str); - return ret_value; - } - - /* parse the layout option */ - obj_list = parse_layout(str, &n_objs, &pack, options); - if (obj_list) { - - /* set layout option */ - options->layout_g = pack.layout; - - /* no individual dataset specified */ - if (options->all_layout == 1) { - if (pack.layout == H5D_CHUNKED) { - /* -2 means the NONE option, remove chunking - and set the global layout to contiguous */ - if (pack.chunk.rank == -2) { - options->layout_g = H5D_CONTIGUOUS; - } - /* otherwise set the global chunking type */ - else { - options->chunk_g.rank = pack.chunk.rank; - for (j = 0; j < pack.chunk.rank; j++) - options->chunk_g.chunk_lengths[j] = - pack.chunk.chunk_lengths[j]; - } - } - } - - /* individual dataset specified */ - if (options->all_layout == 0) - ret_value = options_add_layout(obj_list, n_objs, &pack, options->op_tbl); - - HDfree(obj_list); - ret_value = 0; - } - - return ret_value; +int +h5repack_addlayout(const char* str, pack_opt_t *options) +{ + obj_list_t *obj_list = NULL; /*one object list for the -t and -c option entry */ + unsigned n_objs; /*number of objects in the current -t or -c option entry */ + pack_info_t pack; /*info about layout to extract from parse */ + int j; + int ret_value = -1; + + init_packobject(&pack); + + if (options->all_layout == 1) { + error_msg( "invalid layout input: 'all' option is present with other objects <%s>\n", str); + return ret_value; + } + + /* parse the layout option */ + obj_list = parse_layout(str, &n_objs, &pack, options); + if (obj_list) { + /* set layout option */ + options->layout_g = pack.layout; + + /* no individual dataset specified */ + if (options->all_layout == 1) { + if (pack.layout == H5D_CHUNKED) { + /* -2 means the NONE option, remove chunking + and set the global layout to contiguous */ + if (pack.chunk.rank == -2) + options->layout_g = H5D_CONTIGUOUS; + /* otherwise set the global chunking type */ + else { + options->chunk_g.rank = pack.chunk.rank; + for (j = 0; j < pack.chunk.rank; j++) + options->chunk_g.chunk_lengths[j] = pack.chunk.chunk_lengths[j]; + } + } + } + + /* individual dataset specified */ + if (options->all_layout == 0) + ret_value = options_add_layout(obj_list, n_objs, &pack, options->op_tbl); + + HDfree(obj_list); + ret_value = 0; + } + + return ret_value; } /* Note: The below copy_named_datatype(), named_datatype_free(), copy_attr() @@ -366,200 +361,201 @@ done: * *------------------------------------------------------------------------- */ -int copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, - trav_table_t *travt, pack_opt_t *options) { - hid_t attr_id = -1; /* attr ID */ - hid_t attr_out = -1; /* attr ID */ - hid_t space_id = -1; /* space ID */ - hid_t ftype_id = -1; /* file type ID */ - hid_t wtype_id = -1; /* read/write type ID */ - size_t msize; /* size of type */ - void *buf = NULL; /* data buffer */ - hsize_t nelmts; /* number of elements in dataset */ - int rank; /* rank of dataset */ - htri_t is_named; /* Whether the datatype is named */ - hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */ - char name[255]; - H5O_info_t oinfo; /* object info */ - int j; - unsigned u; - hbool_t is_ref = 0; - H5T_class_t type_class = -1; - - if (H5Oget_info(loc_in, &oinfo) < 0) - goto error; - - /*------------------------------------------------------------------------- - * copy all attributes - *------------------------------------------------------------------------- - */ - for (u = 0; u < (unsigned) oinfo.num_attrs; u++) { - /* open attribute */ - if ((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, - H5_ITER_INC, (hsize_t) u, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; - - /* get name */ - if (H5Aget_name(attr_id, (size_t) 255, name) < 0) - goto error; - - /* get the file datatype */ - if ((ftype_id = H5Aget_type(attr_id)) < 0) - goto error; - - /* Check if the datatype is committed */ - if ((is_named = H5Tcommitted(ftype_id)) < 0) - goto error; - if (is_named && travt) { - hid_t fidout; - - /* Create out file id */ - if ((fidout = H5Iget_file_id(loc_out)) < 0) - goto error; - - /* Copy named dt */ - if ((wtype_id = copy_named_datatype(ftype_id, fidout, - named_dt_head_p, travt, options)) < 0) { - H5Fclose(fidout); - goto error; - } /* end if */ - - if (H5Fclose(fidout) < 0) - goto error; - } /* end if */ - else { - if (options->use_native == 1) - wtype_id = h5tools_get_native_type(ftype_id); - else - wtype_id = H5Tcopy(ftype_id); - } /* end else */ - - /* get the dataspace handle */ - if ((space_id = H5Aget_space(attr_id)) < 0) - goto error; - - /* get dimensions */ - if ((rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0) - goto error; - - nelmts = 1; - for (j = 0; j < rank; j++) - nelmts *= dims[j]; - - if ((msize = H5Tget_size(wtype_id)) == 0) - goto error; - - /*------------------------------------------------------------------------- - * object references are a special case. We cannot just copy the buffers, - * but instead we recreate the reference. - * This is done on a second sweep of the file that just copies the referenced - * objects at copy_refs_attr() - *------------------------------------------------------------------------- - */ - type_class = H5Tget_class(wtype_id); - is_ref = (type_class == H5T_REFERENCE); - if (type_class == H5T_VLEN || type_class == H5T_ARRAY) { - hid_t base_type = -1; - base_type = H5Tget_super(ftype_id); - is_ref = (is_ref || (H5Tget_class(base_type) == H5T_REFERENCE)); - H5Tclose(base_type); - } +int +copy_attr(hid_t loc_in, hid_t loc_out, named_dt_t **named_dt_head_p, + trav_table_t *travt, pack_opt_t *options) +{ + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ + hid_t attr_id = -1; /* attr ID */ + hid_t attr_out = -1; /* attr ID */ + hid_t space_id = -1; /* space ID */ + hid_t ftype_id = -1; /* file type ID */ + hid_t wtype_id = -1; /* read/write type ID */ + size_t msize; /* size of type */ + void *buf = NULL; /* data buffer */ + hsize_t nelmts; /* number of elements in dataset */ + int rank; /* rank of dataset */ + htri_t is_named; /* Whether the datatype is named */ + hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */ + char name[255]; + H5O_info_t oinfo; /* object info */ + int j; + unsigned u; + hbool_t is_ref = 0; + H5T_class_t type_class = -1; + + if (H5Oget_info(loc_in, &oinfo) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Oget_info failed"); + + /*------------------------------------------------------------------------- + * copy all attributes + *------------------------------------------------------------------------- + */ + for (u = 0; u < (unsigned) oinfo.num_attrs; u++) { + /* open attribute */ + if ((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t) u, H5P_DEFAULT, H5P_DEFAULT)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aopen_by_idx failed"); + + /* get name */ + if (H5Aget_name(attr_id, (size_t) 255, name) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + + /* get the file datatype */ + if ((ftype_id = H5Aget_type(attr_id)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type failed"); + + /* Check if the datatype is committed */ + if ((is_named = H5Tcommitted(ftype_id)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tcommitted failed"); + if (is_named && travt) { + hid_t fidout; + + /* Create out file id */ + if ((fidout = H5Iget_file_id(loc_out)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Iget_file_id failed"); + + /* Copy named dt */ + if ((wtype_id = copy_named_datatype(ftype_id, fidout, named_dt_head_p, travt, options)) < 0) { + H5Fclose(fidout); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_named_datatype failed"); + } /* end if */ + + if (H5Fclose(fidout) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Fclose failed"); + } /* end if */ + else { + if (options->use_native == 1) + wtype_id = h5tools_get_native_type(ftype_id); + else + wtype_id = H5Tcopy(ftype_id); + } /* end else */ + + /* get the dataspace handle */ + if ((space_id = H5Aget_space(attr_id)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_space failed"); + + /* get dimensions */ + if ((rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); + + nelmts = 1; + for (j = 0; j < rank; j++) + nelmts *= dims[j]; + + if ((msize = H5Tget_size(wtype_id)) == 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); + + /*------------------------------------------------------------------------- + * object references are a special case. We cannot just copy the buffers, + * but instead we recreate the reference. + * This is done on a second sweep of the file that just copies the referenced + * objects at copy_refs_attr() + *------------------------------------------------------------------------- + */ + type_class = H5Tget_class(wtype_id); + is_ref = (type_class == H5T_REFERENCE); + if (type_class == H5T_VLEN || type_class == H5T_ARRAY) { + hid_t base_type = -1; + + base_type = H5Tget_super(ftype_id); + is_ref = (is_ref || (H5Tget_class(base_type) == H5T_REFERENCE)); + H5Tclose(base_type); + } + + if (type_class == H5T_COMPOUND) { + int nmembers = H5Tget_nmembers(wtype_id); + + for (j = 0; j < nmembers; j++) { + hid_t mtid = H5Tget_member_type(wtype_id, (unsigned) j); + H5T_class_t mtclass = H5Tget_class(mtid); + H5Tclose(mtid); + + if (mtclass == H5T_REFERENCE) { + is_ref = 1; + break; + } + } /* for (j=0; i<nmembers; j++) */ + } /* if (type_class == H5T_COMPOUND) */ + + if (is_ref) { + ; /* handled by copy_refs_attr() */ + } + else { + /*------------------------------------------------------------------------- + * read to memory + *------------------------------------------------------------------------- + */ + + buf = (void *) HDmalloc((size_t)(nelmts * msize)); + if (buf == NULL) { + error_msg("h5repack", "cannot read into memory\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); + } /* end if */ + if (H5Aread(attr_id, wtype_id, buf) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed"); + + /*------------------------------------------------------------------------- + * copy + *------------------------------------------------------------------------- + */ + + if ((attr_out = H5Acreate2(loc_out, name, wtype_id, space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Acreate2 failed"); + if (H5Awrite(attr_out, wtype_id, buf) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Awrite failed"); + + /*close*/ + if (H5Aclose(attr_out) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed"); + + /* Check if we have VL data and string in the attribute's datatype that must + * be reclaimed */ + if (TRUE == h5tools_detect_vlen(wtype_id)) + H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf); + HDfree(buf); + buf = NULL; + } /*H5T_REFERENCE*/ + + if (options->verbose) + printf(FORMAT_OBJ_ATTR, "attr", name); + + /*------------------------------------------------------------------------- + * close + *------------------------------------------------------------------------- + */ + + if (H5Tclose(ftype_id) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); + if (H5Tclose(wtype_id) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); + if (H5Sclose(space_id) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); + if (H5Aclose(attr_id) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed"); + } /* u */ + + return 0; - if (type_class == H5T_COMPOUND) { - int nmembers = H5Tget_nmembers(wtype_id); - for (j = 0; j < nmembers; j++) { - hid_t mtid = H5Tget_member_type(wtype_id, (unsigned) j); - H5T_class_t mtclass = H5Tget_class(mtid); - H5Tclose(mtid); - - if (mtclass == H5T_REFERENCE) { - is_ref = 1; - break; - } - } /* for (j=0; i<nmembers; j++) */ - } /* if (type_class == H5T_COMPOUND) */ - - if (is_ref) { - ; /* handled by copy_refs_attr() */ - } - else { - /*------------------------------------------------------------------------- - * read to memory - *------------------------------------------------------------------------- - */ - - buf = (void *) HDmalloc((size_t)(nelmts * msize)); - if (buf == NULL) { - error_msg("h5repack", "cannot read into memory\n"); - goto error; - } /* end if */ - if (H5Aread(attr_id, wtype_id, buf) < 0) - goto error; - - /*------------------------------------------------------------------------- - * copy - *------------------------------------------------------------------------- - */ - - if ((attr_out = H5Acreate2(loc_out, name, wtype_id, space_id, - H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; - if (H5Awrite(attr_out, wtype_id, buf) < 0) - goto error; - - /*close*/ - if (H5Aclose(attr_out) < 0) - goto error; - - /* Check if we have VL data and string in the attribute's datatype that must - * be reclaimed */ - if (TRUE == h5tools_detect_vlen(wtype_id)) - H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf); - HDfree(buf); - buf = NULL; - } /*H5T_REFERENCE*/ - - if (options->verbose) - printf(FORMAT_OBJ_ATTR, "attr", name); - - /*------------------------------------------------------------------------- - * close - *------------------------------------------------------------------------- - */ - - if (H5Tclose(ftype_id) < 0) - goto error; - if (H5Tclose(wtype_id) < 0) - goto error; - if (H5Sclose(space_id) < 0) - goto error; - if (H5Aclose(attr_id) < 0) - goto error; - } /* u */ - - return 0; - -error: - H5E_BEGIN_TRY - { - if (buf) { - /* Check if we have VL data and string in the attribute's datatype that must - * be reclaimed */ - if (TRUE == h5tools_detect_vlen(wtype_id)) - H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf); - - /* Free buf */ - HDfree(buf); - } /* end if */ - - H5Tclose(ftype_id); - H5Tclose(wtype_id); - H5Sclose(space_id); - H5Aclose(attr_id); - H5Aclose(attr_out); - } H5E_END_TRY; - - return -1; +done: + H5E_BEGIN_TRY { + if (buf) { + /* Check if we have VL data and string in the attribute's datatype that must + * be reclaimed */ + if (TRUE == h5tools_detect_vlen(wtype_id)) + H5Dvlen_reclaim(wtype_id, space_id, H5P_DEFAULT, buf); + + /* Free buf */ + HDfree(buf); + } /* end if */ + + H5Tclose(ftype_id); + H5Tclose(wtype_id); + H5Sclose(space_id); + H5Aclose(attr_id); + H5Aclose(attr_out); + } H5E_END_TRY; + + return ret_value; } /* end copy_attr() */ /*------------------------------------------------------------------------- diff --git a/tools/h5repack/h5repack.h b/tools/h5repack/h5repack.h index 250121e..6bed05e 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; @@ -207,11 +207,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, @@ -223,13 +223,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_copy.c b/tools/h5repack/h5repack_copy.c index 1963750..9573ee8 100644 --- a/tools/h5repack/h5repack_copy.c +++ b/tools/h5repack/h5repack_copy.c @@ -33,10 +33,10 @@ */ /* size of buffer/# of bytes to xfer at a time when copying userblock */ -#define USERBLOCK_XFER_SIZE 512 +#define USERBLOCK_XFER_SIZE 512 /* check H5Dread()/H5Dwrite() error, e.g. memory allocation error inside the library. */ -#define CHECK_H5DRW_ERROR(_fun, _did, _mtid, _msid, _fsid, _pid, _buf) { \ +#define CHECK_H5DRW_ERROR(_fun, _fail, _did, _mtid, _msid, _fsid, _pid, _buf) { \ H5E_BEGIN_TRY { \ if(_fun(_did, _mtid, _msid, _fsid, _pid, _buf) < 0) { \ hid_t _err_num = 0; \ @@ -44,7 +44,7 @@ H5Ewalk2(H5E_DEFAULT, H5E_WALK_DOWNWARD, walk_error_callback, &_err_num); \ H5Eget_msg(_err_num, NULL, _msg, (size_t)80); \ error_msg("%s %s -- %s\n", #_fun, "failed", _msg); \ - goto error; \ + HGOTO_DONE(_fail) \ } \ } H5E_END_TRY; \ } @@ -54,12 +54,12 @@ *------------------------------------------------------------------------- */ static int Get_hyperslab(hid_t dcpl_id, int rank_dset, hsize_t dims_dset[], - size_t size_datum, hsize_t dims_hslab[], hsize_t * hslab_nbytes_p); + size_t size_datum, hsize_t dims_hslab[], hsize_t * hslab_nbytes_p); static void print_dataset_info(hid_t dcpl_id, char *objname, double per, int pr); static int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, - pack_opt_t *options); + pack_opt_t *options); static int copy_user_block(const char *infile, const char *outfile, - hsize_t size); + hsize_t size); #if defined (H5REPACK_DEBUG_USER_BLOCK) static void print_user_block(const char *filename, hid_t fid); #endif @@ -67,10 +67,10 @@ static herr_t walk_error_callback(unsigned n, const H5E_error2_t *err_desc, void /* get the major number from the error stack. */ static herr_t walk_error_callback(H5_ATTR_UNUSED unsigned n, const H5E_error2_t *err_desc, void *udata) { - if (err_desc) - *((int *) udata) = err_desc->maj_num; + if (err_desc) + *((hid_t *) udata) = err_desc->maj_num; - return 0; + return 0; } /*------------------------------------------------------------------------- @@ -97,306 +97,311 @@ static herr_t walk_error_callback(H5_ATTR_UNUSED unsigned n, const H5E_error2_t *------------------------------------------------------------------------- */ -int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) { - hid_t fidin; - hid_t fidout = -1; - trav_table_t *travt = NULL; - hsize_t ub_size = 0; /* size of user block */ - hid_t fcpl = H5P_DEFAULT; /* file creation property list ID */ - hid_t fapl = H5P_DEFAULT; /* file access property list ID */ - - /*------------------------------------------------------------------------- - * open input file - *------------------------------------------------------------------------- - */ - if ((fidin = h5tools_fopen(fnamein, H5F_ACC_RDONLY, H5P_DEFAULT, NULL, NULL, - (size_t) 0)) < 0) { - error_msg("<%s>: %s\n", fnamein, H5FOPENERROR); - goto out; - } - - /* get user block size and file space strategy/threshold */ - { - hid_t fcpl_in; /* file creation property list ID for input file */ - - if ((fcpl_in = H5Fget_create_plist(fidin)) < 0) { - error_msg("failed to retrieve file creation property list\n"); - goto out; - } - - if (H5Pget_userblock(fcpl_in, &ub_size) < 0) { - error_msg("failed to retrieve userblock size\n"); - goto out; - } - - if (H5Pclose(fcpl_in) < 0) { - error_msg("failed to close property list\n"); - goto out; - } - } - - /* Check if we need to create a non-default file creation property list */ - if (options->latest || ub_size > 0) { - /* Create file creation property list */ - if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) { - error_msg("fail to create a file creation property list\n"); - goto out; - } - - if (ub_size > 0) { - if (H5Pset_userblock(fcpl, ub_size) < 0) { - error_msg("failed to set non-default userblock size\n"); - goto out; - } - } - - if (options->latest) { - unsigned i = 0, nindex = 0, mesg_type_flags[5], min_mesg_sizes[5]; - - /* Adjust group creation parameters for root group */ - /* (So that it is created in "dense storage" form) */ - if (H5Pset_link_phase_change(fcpl, (unsigned) options->grp_compact, - (unsigned) options->grp_indexed) < 0) { - error_msg( - "fail to adjust group creation parameters for root group\n"); - goto out; - } - - for (i = 0; i < 5; i++) { - if (options->msg_size[i] > 0) { - switch (i) { - case 0: - mesg_type_flags[nindex] = H5O_SHMESG_SDSPACE_FLAG; - break; - - case 1: - mesg_type_flags[nindex] = H5O_SHMESG_DTYPE_FLAG; - break; - - case 2: - mesg_type_flags[nindex] = H5O_SHMESG_FILL_FLAG; - break; - - case 3: - mesg_type_flags[nindex] = H5O_SHMESG_PLINE_FLAG; - break; - - case 4: - mesg_type_flags[nindex] = H5O_SHMESG_ATTR_FLAG; - break; - default: - break; - } /* end switch */ - min_mesg_sizes[nindex] = (unsigned) options->msg_size[i]; - - nindex++; - } /* end if */ - } /* end for */ - - if (nindex > 0) { - if (H5Pset_shared_mesg_nindexes(fcpl, nindex) < 0) { - error_msg( - "fail to set the number of shared object header message indexes\n"); - goto out; - } - - /* msg_size[0]=dataspace, 1=datatype, 2=file value, 3=filter pipleline, 4=attribute */ - for (i = 0; i < (nindex - 1); i++) { - if (H5Pset_shared_mesg_index(fcpl, i, mesg_type_flags[i], - min_mesg_sizes[i]) < 0) { - error_msg( - "fail to configure the specified shared object header message index\n"); - goto out; - } /* end if */ - } /* end for */ - } /* if (nindex>0) */ - - /* Create file access property list */ - if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { - error_msg("Could not create file access property list\n"); - goto out; - } /* end if */ - - if (H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) { - error_msg( - "Could not set property for using latest version of the format\n"); - goto out; - } /* end if */ - } /* end if */ - } /* end if */ +int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options) +{ + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ + hid_t fidin; + hid_t fidout = -1; + trav_table_t *travt = NULL; + hsize_t ub_size = 0; /* size of user block */ + hid_t fcpl = H5P_DEFAULT; /* file creation property list ID */ + hid_t fapl = H5P_DEFAULT; /* file access property list ID */ + + /*------------------------------------------------------------------------- + * open input file + *------------------------------------------------------------------------- + */ + if ((fidin = h5tools_fopen(fnamein, H5F_ACC_RDONLY, H5P_DEFAULT, NULL, NULL, (size_t) 0)) < 0) { + error_msg("<%s>: %s\n", fnamein, H5FOPENERROR); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + + /* get user block size and file space strategy/threshold */ + { + hid_t fcpl_in; /* file creation property list ID for input file */ + + if ((fcpl_in = H5Fget_create_plist(fidin)) < 0) { + error_msg("failed to retrieve file creation property list\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + + if (H5Pget_userblock(fcpl_in, &ub_size) < 0) { + error_msg("failed to retrieve userblock size\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + + if (H5Pclose(fcpl_in) < 0) { + error_msg("failed to close property list\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + /* Check if we need to create a non-default file creation property list */ + if (options->latest || ub_size > 0) { + /* Create file creation property list */ + if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) { + error_msg("fail to create a file creation property list\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + + if (ub_size > 0) { + if (H5Pset_userblock(fcpl, ub_size) < 0) { + error_msg("failed to set non-default userblock size\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + if (options->latest) { + unsigned i = 0, nindex = 0, mesg_type_flags[5], min_mesg_sizes[5]; + + /* Adjust group creation parameters for root group */ + /* (So that it is created in "dense storage" form) */ + if (H5Pset_link_phase_change(fcpl, (unsigned) options->grp_compact, + (unsigned) options->grp_indexed) < 0) { + error_msg("fail to adjust group creation parameters for root group\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + + for (i = 0; i < 5; i++) { + if (options->msg_size[i] > 0) { + switch (i) { + case 0: + mesg_type_flags[nindex] = H5O_SHMESG_SDSPACE_FLAG; + break; + + case 1: + mesg_type_flags[nindex] = H5O_SHMESG_DTYPE_FLAG; + break; + + case 2: + mesg_type_flags[nindex] = H5O_SHMESG_FILL_FLAG; + break; + + case 3: + mesg_type_flags[nindex] = H5O_SHMESG_PLINE_FLAG; + break; + + case 4: + mesg_type_flags[nindex] = H5O_SHMESG_ATTR_FLAG; + break; + + default: + break; + } /* end switch */ + min_mesg_sizes[nindex] = (unsigned) options->msg_size[i]; + + nindex++; + } /* end if */ + } /* end for */ + + if (nindex > 0) { + if (H5Pset_shared_mesg_nindexes(fcpl, nindex) < 0) { + error_msg("fail to set the number of shared object header message indexes\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + + /* msg_size[0]=dataspace, 1=datatype, 2=file value, 3=filter pipleline, 4=attribute */ + for (i = 0; i < (nindex - 1); i++) { + if (H5Pset_shared_mesg_index(fcpl, i, mesg_type_flags[i], min_mesg_sizes[i]) < 0) { + error_msg("fail to configure the specified shared object header message index\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } /* end if */ + } /* end for */ + } /* if (nindex>0) */ + + /* Create file access property list */ + if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { + error_msg("Could not create file access property list\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } /* end if */ + + if (H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) { + error_msg("Could not set property for using latest version of the format\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } /* end if */ + } /* end if */ + } /* end if */ #if defined (H5REPACK_DEBUG_USER_BLOCK) - print_user_block(fnamein, fidin); +print_user_block(fnamein, fidin); #endif - /*------------------------------------------------------------------------- - * set the new user userblock options in the FCPL (before H5Fcreate ) - *------------------------------------------------------------------------- - */ - if (options->ublock_size > 0) { - /* either use the FCPL already created or create a new one */ - if (fcpl == H5P_DEFAULT) { - /* create a file creation property list */ - if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) { - error_msg("fail to create a file creation property list\n"); - goto out; - } - } - - /* set user block size */ - if (H5Pset_userblock(fcpl, options->ublock_size) < 0) { - error_msg("failed to set userblock size\n"); - goto out; - } - } - - /*------------------------------------------------------------------------- - * set alignment options - *------------------------------------------------------------------------- - */ - if (options->alignment > 0) { - /* either use the FAPL already created or create a new one */ - if (fapl == H5P_DEFAULT) { - /* create a file access property list */ - if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { - error_msg("Could not create file access property list\n"); - goto out; - } - } - - if (H5Pset_alignment(fapl, options->threshold, options->alignment) < 0) { - error_msg("failed to set alignment\n"); - goto out; - } - } - - /*------------------------------------------------------------------------- - * set metadata block size option - *------------------------------------------------------------------------- - */ - if (options->meta_block_size > 0) { - /* either use the FAPL already created or create a new one */ - if (fapl == H5P_DEFAULT) { - /* create a file access property list */ - if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { - error_msg("Could not create file access property list\n"); - goto out; - } - } - - if (H5Pset_meta_block_size(fapl, options->meta_block_size) < 0) { - error_msg("failed to set metadata block size\n"); - goto out; - } - } - - - /*------------------------------------------------------------------------- - * create the output file - *------------------------------------------------------------------------- - */ - if (options->verbose) - printf("Making file <%s>...\n", fnameout); - - if ((fidout = H5Fcreate(fnameout, H5F_ACC_TRUNC, fcpl, fapl)) < 0) { - error_msg("<%s>: Could not create file\n", fnameout); - goto out; - } - - /*------------------------------------------------------------------------- - * write a new user block if requested - *------------------------------------------------------------------------- - */ - if (options->ublock_size > 0) { - if (copy_user_block(options->ublock_filename, fnameout, - options->ublock_size) < 0) { - error_msg("Could not copy user block. Exiting...\n"); - goto out; - - } - } - - /*------------------------------------------------------------------------- - * get list of objects - *------------------------------------------------------------------------- - */ - - /* init table */ - trav_table_init(&travt); - - /* get the list of objects in the file */ - if (h5trav_gettable(fidin, travt) < 0) - goto out; - - /*------------------------------------------------------------------------- - * do the copy - *------------------------------------------------------------------------- - */ - if (do_copy_objects(fidin, fidout, travt, options) < 0) { - error_msg("<%s>: Could not copy data to: %s\n", fnamein, fnameout); - goto out; - } /* end if */ - - /*------------------------------------------------------------------------- - * do the copy of referenced objects - * and create hard links - *------------------------------------------------------------------------- - */ - if (do_copy_refobjs(fidin, fidout, travt, options) < 0) { - printf("h5repack: <%s>: Could not copy data to: %s\n", fnamein, - fnameout); - goto out; - } - - /*------------------------------------------------------------------------- - * close - *------------------------------------------------------------------------- - */ - - if (fapl > 0) - H5Pclose(fapl); - - if (fcpl > 0) - H5Pclose(fcpl); - - H5Fclose(fidin); - H5Fclose(fidout); - - /* free table */ - trav_table_free(travt); - travt = NULL; - - /*------------------------------------------------------------------------- - * write only the input file user block if there is no user block file input - *------------------------------------------------------------------------- - */ - - if (ub_size > 0 && options->ublock_size == 0) { - if (copy_user_block(fnamein, fnameout, ub_size) < 0) { - error_msg("Could not copy user block. Exiting...\n"); - goto out; - - } - } - - return 0; - - /*------------------------------------------------------------------------- - * out - *------------------------------------------------------------------------- - */ - -out: - H5E_BEGIN_TRY - { - H5Pclose(fapl); - H5Pclose(fcpl); - H5Fclose(fidin); - H5Fclose(fidout); - }H5E_END_TRY; - if (travt) - trav_table_free(travt); - - return -1; + /*------------------------------------------------------------------------- + * set the new user userblock options in the FCPL (before H5Fcreate ) + *------------------------------------------------------------------------- + */ + if (options->ublock_size > 0) { + /* either use the FCPL already created or create a new one */ + if (fcpl == H5P_DEFAULT) { + /* create a file creation property list */ + if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) { + error_msg("fail to create a file creation property list\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + /* set user block size */ + if (H5Pset_userblock(fcpl, options->ublock_size) < 0) { + error_msg("failed to set userblock size\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + /*------------------------------------------------------------------------- + * set alignment options + *------------------------------------------------------------------------- + */ + if (options->alignment > 0) { + /* either use the FAPL already created or create a new one */ + if (fapl == H5P_DEFAULT) { + /* create a file access property list */ + if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { + error_msg("Could not create file access property list\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + if (H5Pset_alignment(fapl, options->threshold, options->alignment) < 0) { + error_msg("failed to set alignment\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + /*------------------------------------------------------------------------- + * set metadata block size option + *------------------------------------------------------------------------- + */ + if (options->meta_block_size > 0) { + /* either use the FAPL already created or create a new one */ + if (fapl == H5P_DEFAULT) { + /* create a file access property list */ + if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { + error_msg("Could not create file access property list\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + if (H5Pset_meta_block_size(fapl, options->meta_block_size) < 0) { + error_msg("failed to set metadata block size\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + /*------------------------------------------------------------------------- + * set free-space strategy options + *------------------------------------------------------------------------- + */ + + /* either use the FCPL already created or create a new one */ + if (fcpl == H5P_DEFAULT) { + /* create a file creation property list */ + if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) { + error_msg("fail to create a file creation property list\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + /*------------------------------------------------------------------------- + * create the output file + *------------------------------------------------------------------------- + */ + if (options->verbose) + printf("Making file <%s>...\n", fnameout); + + if ((fidout = H5Fcreate(fnameout, H5F_ACC_TRUNC, fcpl, fapl)) < 0) { + error_msg("<%s>: Could not create file\n", fnameout); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + + /*------------------------------------------------------------------------- + * write a new user block if requested + *------------------------------------------------------------------------- + */ + if (options->ublock_size > 0) { + if (copy_user_block(options->ublock_filename, fnameout, options->ublock_size) < 0) { + error_msg("Could not copy user block. Exiting...\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + /*------------------------------------------------------------------------- + * get list of objects + *------------------------------------------------------------------------- + */ + + /* init table */ + trav_table_init(&travt); + + /* get the list of objects in the file */ + if (h5trav_gettable(fidin, travt) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + + /*------------------------------------------------------------------------- + * do the copy + *------------------------------------------------------------------------- + */ + if (do_copy_objects(fidin, fidout, travt, options) < 0) { + error_msg("<%s>: Could not copy data to: %s\n", fnamein, fnameout); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } /* end if */ + + /*------------------------------------------------------------------------- + * do the copy of referenced objects + * and create hard links + *------------------------------------------------------------------------- + */ + if (do_copy_refobjs(fidin, fidout, travt, options) < 0) { + printf("h5repack: <%s>: Could not copy data to: %s\n", fnamein, fnameout); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + + /*------------------------------------------------------------------------- + * close + *------------------------------------------------------------------------- + */ + + if (fapl > 0) + H5Pclose(fapl); + + if (fcpl > 0) + H5Pclose(fcpl); + + H5Fclose(fidin); + H5Fclose(fidout); + + /* free table */ + trav_table_free(travt); + travt = NULL; + + /*------------------------------------------------------------------------- + * write only the input file user block if there is no user block file input + *------------------------------------------------------------------------- + */ + + if (ub_size > 0 && options->ublock_size == 0) { + if (copy_user_block(fnamein, fnameout, ub_size) < 0) { + error_msg("Could not copy user block. Exiting...\n"); + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + return 0; + + /*------------------------------------------------------------------------- + * out + *------------------------------------------------------------------------- + */ + +done: + H5E_BEGIN_TRY { + H5Pclose(fapl); + H5Pclose(fcpl); + H5Fclose(fidin); + H5Fclose(fidout); + } H5E_END_TRY; + if (travt) + trav_table_free(travt); + + return ret_value; } /*------------------------------------------------------------------------- @@ -437,132 +442,126 @@ out: *-----------------------------------------*/ int Get_hyperslab(hid_t dcpl_id, int rank_dset, hsize_t dims_dset[], - size_t size_datum, hsize_t dims_hslab[], hsize_t * hslab_nbytes_p) { - int status = 0; - int k; - H5D_layout_t dset_layout; - int rank_chunk; - hsize_t dims_chunk[H5S_MAX_RANK]; - hsize_t size_chunk = 1; - hsize_t nchunk_fit; /* number of chunks that fits in hyperslab buffer (H5TOOLS_BUFSIZE) */ - hsize_t ndatum_fit; /* number of dataum that fits in hyperslab buffer (H5TOOLS_BUFSIZE) */ - hsize_t chunk_dims_map[H5S_MAX_RANK]; /* mapped chunk dimentions */ - hsize_t hs_dims_map[H5S_MAX_RANK]; /* mapped hyperslab dimentions */ - hsize_t hslab_nbytes; /* size of hyperslab in byte */ - - /* init to set as size of a data element */ - hslab_nbytes = size_datum; - - /* get layout of dataset */ - dset_layout = H5Pget_layout(dcpl_id); - - /* if dataset is chunked */ - if (dset_layout == H5D_CHUNKED) { - /* get chunk dims */ - rank_chunk = H5Pget_chunk(dcpl_id, rank_dset, dims_chunk); - if (rank_chunk < 0) { - status = -1; - goto out; - } - - for (k = rank_dset; k > 0; --k) - size_chunk *= dims_chunk[k - 1]; - - /* figure out how many chunks can fit in the hyperslab buffer */ - nchunk_fit = (H5TOOLS_BUFSIZE / size_datum) / size_chunk; - - /* 1. if a chunk fit in hyperslab buffer */ - if (nchunk_fit >= 1) { - /* Calulate a hyperslab that contains as many chunks that can fit - * in hyperslab buffer. Hyperslab will be increased starting from - * the last dimention of the dataset (see h5dump's dims output). - * The calculation boundary is dataset dims. - * In the loop, used mapping from a datum to a chunk to figure out - * chunk based hyperslab. - */ - for (k = rank_dset; k > 0; --k) { - /* map dataset dimentions with a chunk dims */ - chunk_dims_map[k - 1] = dims_dset[k - 1] / dims_chunk[k - 1]; - - /* if reminder exist, increse by 1 to cover partial edge chunks */ - if (dims_dset[k - 1] % dims_chunk[k - 1] > 0) - chunk_dims_map[k - 1]++; - - /* get mapped hyperslab dims */ - hs_dims_map[k - 1] = MIN (nchunk_fit, chunk_dims_map[k-1]); - - /* prepare next round */ - nchunk_fit = nchunk_fit / chunk_dims_map[k - 1]; - /* if a chunk is bigger than the rest of buffer */ - if (nchunk_fit == 0) - nchunk_fit = 1; - - /* get hyperslab dimentions as unmapping to actual size */ - dims_hslab[k - 1] = - MIN( (hs_dims_map[k-1] * dims_chunk[k-1]), dims_dset[k-1]); - - /* calculate total size for the hyperslab */ - hslab_nbytes *= dims_hslab[k - 1]; - } - } - /* 2. if a chunk is bigger than hyperslab buffer */ - else { - /* Calulate a hyperslab that contains as many data elements that - * can fit in hyperslab buffer. Hyperslab will be increased - * starting from the last dimention of the chunk (see h5dump's dims - * output). - * The calculation boundary is a chunk dims. - */ - for (k = rank_dset; k > 0; --k) { - ndatum_fit = H5TOOLS_BUFSIZE / hslab_nbytes; - - /* if a datum is bigger than rest of buffer */ - if (ndatum_fit == 0) - ndatum_fit = 1; - /* get hyperslab dimentions within a chunk boundary */ - dims_hslab[k - 1] = MIN (dims_chunk[k-1], ndatum_fit); - - /* calculate total size for the hyperslab */ - hslab_nbytes *= dims_hslab[k - 1]; - - if (hslab_nbytes <= 0) { - status = -1; - goto out; - } - } - } - } - /* 3. if dataset is not chunked */ - else { - /* Calulate a hyperslab that contains as many data elements that can - * fit in hyperslab buffer. Hyperslab will be increased starting from - * the last dimention of the dataset (see h5dump's dims output). - * The calculation boundary is dataset dims. - */ - for (k = rank_dset; k > 0; --k) { - ndatum_fit = H5TOOLS_BUFSIZE / hslab_nbytes; - - /* if a datum is bigger than rest of buffer */ - if (ndatum_fit == 0) - ndatum_fit = 1; - /* get hyperslab dimentions within dataset boundary */ - dims_hslab[k - 1] = MIN(dims_dset[k - 1], ndatum_fit); - - /* calculate total size for the hyperslab */ - hslab_nbytes *= dims_hslab[k - 1]; - - if (hslab_nbytes <= 0) { - status = -1; - goto out; - } - } - } - - /* pass out the hyperslab size*/ - *hslab_nbytes_p = hslab_nbytes; - -out: - return status; + size_t size_datum, hsize_t dims_hslab[], hsize_t * hslab_nbytes_p) +{ + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ + int k; + H5D_layout_t dset_layout; + int rank_chunk; + hsize_t dims_chunk[H5S_MAX_RANK]; + hsize_t size_chunk = 1; + hsize_t nchunk_fit; /* number of chunks that fits in hyperslab buffer (H5TOOLS_BUFSIZE) */ + hsize_t ndatum_fit; /* number of dataum that fits in hyperslab buffer (H5TOOLS_BUFSIZE) */ + hsize_t chunk_dims_map[H5S_MAX_RANK]; /* mapped chunk dimentions */ + hsize_t hs_dims_map[H5S_MAX_RANK]; /* mapped hyperslab dimentions */ + hsize_t hslab_nbytes; /* size of hyperslab in byte */ + + /* init to set as size of a data element */ + hslab_nbytes = size_datum; + + /* get layout of dataset */ + dset_layout = H5Pget_layout(dcpl_id); + + /* if dataset is chunked */ + if (dset_layout == H5D_CHUNKED) { + /* get chunk dims */ + rank_chunk = H5Pget_chunk(dcpl_id, rank_dset, dims_chunk); + if (rank_chunk < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + + for (k = rank_dset; k > 0; --k) + size_chunk *= dims_chunk[k - 1]; + + /* figure out how many chunks can fit in the hyperslab buffer */ + nchunk_fit = (H5TOOLS_BUFSIZE / size_datum) / size_chunk; + + /* 1. if a chunk fit in hyperslab buffer */ + if (nchunk_fit >= 1) { + /* Calulate a hyperslab that contains as many chunks that can fit + * in hyperslab buffer. Hyperslab will be increased starting from + * the last dimention of the dataset (see h5dump's dims output). + * The calculation boundary is dataset dims. + * In the loop, used mapping from a datum to a chunk to figure out + * chunk based hyperslab. + */ + for (k = rank_dset; k > 0; --k) { + /* map dataset dimentions with a chunk dims */ + chunk_dims_map[k - 1] = dims_dset[k - 1] / dims_chunk[k - 1]; + + /* if reminder exist, increse by 1 to cover partial edge chunks */ + if (dims_dset[k - 1] % dims_chunk[k - 1] > 0) + chunk_dims_map[k - 1]++; + + /* get mapped hyperslab dims */ + hs_dims_map[k - 1] = MIN (nchunk_fit, chunk_dims_map[k-1]); + + /* prepare next round */ + nchunk_fit = nchunk_fit / chunk_dims_map[k - 1]; + /* if a chunk is bigger than the rest of buffer */ + if (nchunk_fit == 0) + nchunk_fit = 1; + + /* get hyperslab dimentions as unmapping to actual size */ + dims_hslab[k - 1] = MIN( (hs_dims_map[k-1] * dims_chunk[k-1]), dims_dset[k-1]); + + /* calculate total size for the hyperslab */ + hslab_nbytes *= dims_hslab[k - 1]; + } + } + /* 2. if a chunk is bigger than hyperslab buffer */ + else { + /* Calulate a hyperslab that contains as many data elements that + * can fit in hyperslab buffer. Hyperslab will be increased + * starting from the last dimention of the chunk (see h5dump's dims + * output). + * The calculation boundary is a chunk dims. + */ + for (k = rank_dset; k > 0; --k) { + ndatum_fit = H5TOOLS_BUFSIZE / hslab_nbytes; + + /* if a datum is bigger than rest of buffer */ + if (ndatum_fit == 0) + ndatum_fit = 1; + /* get hyperslab dimentions within a chunk boundary */ + dims_hslab[k - 1] = MIN (dims_chunk[k-1], ndatum_fit); + + /* calculate total size for the hyperslab */ + hslab_nbytes *= dims_hslab[k - 1]; + + if (hslab_nbytes <= 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + } + /* 3. if dataset is not chunked */ + else { + /* Calulate a hyperslab that contains as many data elements that can + * fit in hyperslab buffer. Hyperslab will be increased starting from + * the last dimention of the dataset (see h5dump's dims output). + * The calculation boundary is dataset dims. + */ + for (k = rank_dset; k > 0; --k) { + ndatum_fit = H5TOOLS_BUFSIZE / hslab_nbytes; + + /* if a datum is bigger than rest of buffer */ + if (ndatum_fit == 0) + ndatum_fit = 1; + /* get hyperslab dimentions within dataset boundary */ + dims_hslab[k - 1] = MIN(dims_dset[k - 1], ndatum_fit); + + /* calculate total size for the hyperslab */ + hslab_nbytes *= dims_hslab[k - 1]; + + if (hslab_nbytes <= 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + } + } + + /* pass out the hyperslab size*/ + *hslab_nbytes_p = hslab_nbytes; + +done: + return ret_value; } /*------------------------------------------------------------------------- @@ -660,718 +659,641 @@ out: */ int do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, - pack_opt_t *options) /* repack options */ + pack_opt_t *options) /* repack options */ { - hid_t grp_in = -1; /* group ID */ - hid_t grp_out = -1; /* group ID */ - hid_t dset_in = -1; /* read dataset ID */ - hid_t dset_out = -1; /* write dataset ID */ - hid_t gcpl_in = -1; /* group creation property list */ - hid_t gcpl_out = -1; /* group creation property list */ - hid_t type_in = -1; /* named type ID */ - hid_t type_out = -1; /* named type ID */ - hid_t dcpl_in = -1; /* dataset creation property list ID */ - hid_t dcpl_out = -1; /* dataset creation property list ID */ - hid_t f_space_id = -1; /* file space ID */ - hid_t ftype_id = -1; /* file type ID */ - hid_t wtype_id = -1; /* read/write type ID */ - named_dt_t *named_dt_head = NULL; /* Pointer to the stack of named datatypes copied */ - size_t msize; /* size of type */ - hsize_t nelmts; /* number of elements in dataset */ - H5D_space_status_t space_status; /* determines whether space has been allocated for the dataset */ - int rank; /* rank of dataset */ - hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */ - hsize_t dsize_in; /* input dataset size before filter */ - hsize_t dsize_out; /* output dataset size after filter */ - int apply_s; /* flag for apply filter to small dataset sizes */ - int apply_f; /* flag for apply filter to return error on H5Dcreate */ - void *buf = NULL; /* buffer for raw data */ - void *hslab_buf = NULL; /* hyperslab buffer for raw data */ - int has_filter; /* current object has a filter */ - int req_filter; /* there was a request for a filter */ - int req_obj_layout = 0; /* request layout to current object */ - unsigned crt_order_flags; /* group creation order flag */ - unsigned i; - unsigned u; - int is_ref = 0; - htri_t is_named; - hbool_t limit_maxdims; - hsize_t size_dset; - - /*------------------------------------------------------------------------- - * copy the suppplied object list - *------------------------------------------------------------------------- - */ - - if (options->verbose) { - printf("-----------------------------------------\n"); - printf(" Type Filter (Compression) Name\n"); - printf("-----------------------------------------\n"); - } - - for (i = 0; i < travt->nobjs; i++) { - /* init variables per obj */ - buf = NULL; - limit_maxdims = FALSE; - - switch (travt->objs[i].type) { - - case H5TRAV_TYPE_UNKNOWN: - HDassert(0); - break; - /*------------------------------------------------------------------------- - * H5TRAV_TYPE_GROUP - *------------------------------------------------------------------------- - */ - case H5TRAV_TYPE_GROUP: - - if (options->verbose) { - printf(FORMAT_OBJ, "group", travt->objs[i].name); - } - - /* open input group */ - if ((grp_in = H5Gopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) - < 0) - goto error; - - /* get input group creation property list */ - if ((gcpl_in = H5Gget_create_plist(grp_in)) < 0) - goto error; - - /* query and set the group creation properties */ - if (H5Pget_link_creation_order(gcpl_in, &crt_order_flags) < 0) - goto error; - - /* set up group creation property list */ - if ((gcpl_out = H5Pcreate(H5P_GROUP_CREATE)) < 0) - goto error; - - if (H5Pset_link_creation_order(gcpl_out, crt_order_flags) < 0) - goto error; - - /*------------------------------------------------------------------------- - * the root is a special case, we get an ID for the root group - * and copy its attributes using that ID - *------------------------------------------------------------------------- - */ - if (HDstrcmp(travt->objs[i].name, "/") == 0) { - if ((grp_out = H5Gopen2(fidout, "/", H5P_DEFAULT)) < 0) - goto error; - } - else { - - if (options->grp_compact > 0 || options->grp_indexed > 0) { - if (H5Pset_link_phase_change(gcpl_out, - (unsigned) options->grp_compact, - (unsigned) options->grp_indexed) < 0) - goto error; - } - - if ((grp_out = H5Gcreate2(fidout, travt->objs[i].name, - H5P_DEFAULT, gcpl_out, H5P_DEFAULT)) < 0) - goto error; - - } - - /*------------------------------------------------------------------------- - * copy attrs - *------------------------------------------------------------------------- - */ - if (copy_attr(grp_in, grp_out, &named_dt_head, travt, options) < 0) - goto error; - - if (H5Pclose(gcpl_out) < 0) - goto error; - if (H5Pclose(gcpl_in) < 0) - goto error; - if (H5Gclose(grp_out) < 0) - goto error; - if (H5Gclose(grp_in) < 0) - goto error; - - break; - - /*------------------------------------------------------------------------- - * H5TRAV_TYPE_DATASET - *------------------------------------------------------------------------- - */ - case H5TRAV_TYPE_DATASET: - - has_filter = 0; - req_filter = 0; - - /* check if global filters were requested */ - if (options->n_filter_g) - req_filter = 1; - - /* check if filters were requested for individual objects */ - for (u = 0; u < options->op_tbl->nelems; u++) { - - if (HDstrcmp(travt->objs[i].name, options->op_tbl->objs[u].path) == 0) { - if (options->op_tbl->objs[u].filter->filtn > 0) { - req_filter = 1; - } - } - } - - /* check if layout change requested individual object */ - if (options->layout_g != H5D_LAYOUT_ERROR) { - pack_info_t *pckinfo; - /* any dataset is specified */ - if (options->op_tbl->nelems > 0) { - /* check if object exist */ - pckinfo = options_get_object(travt->objs[i].name, - options->op_tbl); - if (pckinfo) { - req_obj_layout = 1; - } - } - } - - /* early detection of references */ - if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) - < 0) - goto error; - if ((ftype_id = H5Dget_type(dset_in)) < 0) - goto error; - if (H5T_REFERENCE == H5Tget_class(ftype_id)) - is_ref = 1; - - /* Check if the datatype is committed */ - if ((is_named = H5Tcommitted(ftype_id)) < 0) - goto error; - if (is_named) - if ((wtype_id = copy_named_datatype(ftype_id, fidout, - &named_dt_head, travt, options)) < 0) - goto error; - - if (H5Tclose(ftype_id) < 0) - goto error; - if (H5Dclose(dset_in) < 0) - goto error; - - /*------------------------------------------------------------------------- - * check if we should use H5Ocopy or not - * if there is a request for filters/layout, we read/write the object - * otherwise we do a copy using H5Ocopy - *------------------------------------------------------------------------- - */ - if (options->op_tbl->nelems || options->all_filter == 1 - || options->all_layout == 1 || is_ref || is_named) { - - int j; - - if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; - if ((f_space_id = H5Dget_space(dset_in)) < 0) - goto error; - if ((ftype_id = H5Dget_type(dset_in)) < 0) - goto error; - if ((dcpl_in = H5Dget_create_plist(dset_in)) < 0) - goto error; - if ((dcpl_out = H5Pcopy(dcpl_in)) < 0) - goto error; - if ((rank = H5Sget_simple_extent_ndims(f_space_id)) < 0) - goto error; - HDmemset(dims, 0, sizeof dims); - if (H5Sget_simple_extent_dims(f_space_id, dims, NULL) < 0) - goto error; - - if (H5Dget_space_status(dset_in, &space_status) < 0) - goto error; - - nelmts = 1; - for (j = 0; j < rank; j++) - nelmts *= dims[j]; - - /* wtype_id will have already been set if using a named dtype */ - if (!is_named) { - if (options->use_native == 1) - wtype_id = h5tools_get_native_type(ftype_id); - else - wtype_id = H5Tcopy(ftype_id); - } /* end if */ - - if ((msize = H5Tget_size(wtype_id)) == 0) - goto error; - - /* size of current dset */ - size_dset = nelmts * msize; - - /*------------------------------------------------------------------------- - * check if the dataset creation property list has filters that - * are not registered in the current configuration - * 1) the external filters GZIP and SZIP might not be available - * 2) the internal filters might be turned off - *------------------------------------------------------------------------- - */ - if (h5tools_canreadf((travt->objs[i].name), dcpl_in) == 1) { - apply_s = 1; - apply_f = 1; - - /*------------------------------------------------------------------------- - * references are a special case - * we cannot just copy the buffers, but instead we recreate the reference - * in a second traversal of the output file - *------------------------------------------------------------------------- - */ - if (H5T_REFERENCE != H5Tget_class(wtype_id)) { - /* get the storage size of the input dataset */ - dsize_in = H5Dget_storage_size(dset_in); - - /* check for small size datasets (less than 1k) except - * changing to COMPACT. For the reference, COMPACT is limited - * by size 64K by library. - */ - if (options->layout_g != H5D_COMPACT) { - if (size_dset < options->min_comp) - apply_s = 0; - } - - /* apply the filter */ - if (apply_s) { - if (apply_filters(travt->objs[i].name, rank, dims, - msize, dcpl_out, options, &has_filter) < 0) - goto error; - } - - /* only if layout change requested for entire file or - * individual obj */ - if (options->all_layout > 0 || req_obj_layout == 1) - /*------------------------------------------------- - * Unset the unlimited max dims if convert to other - * than chunk layouts, because unlimited max dims - * only can be applied to chunk layout. - * Also perform only for targeted dataset - * Also check for size limit to convert to compact - *-------------------------------------------------*/ - if (options->layout_g != H5D_CHUNKED) { - /* any dataset is specified */ - if (options->op_tbl->nelems > 0) { - /* if current obj match specified obj */ - if (options_get_object(travt->objs[i].name, - options->op_tbl)) - limit_maxdims = TRUE; - } - else { /* no dataset is specified */ - limit_maxdims = TRUE; - } - - /* if convert to COMPACT */ - if (options->layout_g == H5D_COMPACT) { - /* should be smaller than 64K */ - if (size_dset > MAX_COMPACT_DSIZE) - limit_maxdims = FALSE; - } - - /* unset unlimited max dims */ - if (limit_maxdims) - H5Sset_extent_simple(f_space_id, rank, dims, - NULL); - } - - /*------------------------------------------------------------------------- - * create the output dataset; - * disable error checking in case the dataset cannot be created with the - * modified dcpl; in that case use the original instead - *------------------------------------------------------------------------- - */ - H5E_BEGIN_TRY - { - dset_out = H5Dcreate2(fidout, - travt->objs[i].name, wtype_id, - f_space_id, H5P_DEFAULT, dcpl_out, - H5P_DEFAULT); - }H5E_END_TRY; - - if (dset_out == FAIL) { - if (options->verbose) - printf( - " warning: could not create dataset <%s>. Applying original settings\n", - travt->objs[i].name); - - if ((dset_out = H5Dcreate2(fidout, - travt->objs[i].name, wtype_id, f_space_id, - H5P_DEFAULT, dcpl_in, H5P_DEFAULT)) < 0) - goto error; - apply_f = 0; - } - - /*------------------------------------------------------------------------- - * read/write - *------------------------------------------------------------------------- - */ - if (nelmts > 0 && space_status != H5D_SPACE_STATUS_NOT_ALLOCATED) { - size_t need = (size_t)(nelmts * msize); /* bytes needed */ - - /* have to read the whole dataset if there is only one element in the dataset */ - if (need < H5TOOLS_MALLOCSIZE) - buf = HDmalloc(need); - - if (buf != NULL) { - /* read/write: use the macro to check error, e.g. memory allocation error inside the library. */ - CHECK_H5DRW_ERROR(H5Dread, dset_in, wtype_id, - H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); - CHECK_H5DRW_ERROR(H5Dwrite, dset_out, wtype_id, - H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); - - /* Check if we have VL data in the dataset's - * datatype that must be reclaimed */ - if (TRUE == H5Tdetect_class(wtype_id, H5T_VLEN)) - if (H5Dvlen_reclaim(wtype_id, f_space_id, - H5P_DEFAULT, buf) < 0) - goto error; - } - else { /* possibly not enough memory, read/write by hyperslabs */ - size_t p_type_nbytes = msize; /*size of memory type */ - hsize_t p_nelmts = nelmts; /*total elements */ - hsize_t elmtno; /*counter */ - int carry; /*counter carry value */ - unsigned int vl_data = 0; /*contains VL datatypes */ - - /* hyperslab info */ - hsize_t hslab_dims[H5S_MAX_RANK]; /*hyperslab dims */ - hsize_t hslab_nbytes; /*bytes per hyperslab */ - hsize_t hslab_nelmts; /*elements per hyperslab*/ - hid_t hslab_space; /*hyperslab data space */ - - /* hyperslab selection info */ - hsize_t hs_sel_offset[H5S_MAX_RANK];/* selection offset */ - hsize_t hs_sel_count[H5S_MAX_RANK]; /* selection count */ - hsize_t hs_select_nelmts; /* selected elements */ - hsize_t zero[8]; /*vector of zeros */ - int k; - H5D_layout_t dset_layout; - hid_t dcpl_tmp = -1; /* dataset creation property list ID */ - - /* check if we have VL data in the dataset's datatype */ - if (H5Tdetect_class(wtype_id, H5T_VLEN) == TRUE) - vl_data = TRUE; - - /* check first if writing dataset is chunked, - * if so use its chunk layout for better performance. */ - dset_layout = H5Pget_layout(dcpl_out); - if (dset_layout == H5D_CHUNKED) - dcpl_tmp = dcpl_out; /* writing dataset */ - else { /* if reading dataset is chunked */ - dset_layout = H5Pget_layout(dcpl_in); - if (dset_layout == H5D_CHUNKED) - dcpl_tmp = dcpl_in; /* reading dataset */ - } - - /* get hyperslab dims and size in byte */ - if (Get_hyperslab(dcpl_tmp, rank, dims, - p_type_nbytes, hslab_dims, - &hslab_nbytes) < 0) - goto error; - - hslab_buf = HDmalloc((size_t)hslab_nbytes); - - hslab_nelmts = hslab_nbytes / p_type_nbytes; - hslab_space = H5Screate_simple(1, &hslab_nelmts, - NULL); - - /* the hyperslab selection loop */ - HDmemset(hs_sel_offset, 0, - sizeof hs_sel_offset); - HDmemset(zero, 0, sizeof zero); - - for (elmtno = 0; elmtno < p_nelmts; elmtno += - hs_select_nelmts) { - if (rank > 0) { - /* calculate the hyperslab selections. The selection would be same as the hyperslab except for remaining edge portion of the dataset which is smaller then the hyperslab. - */ - for (k = 0, hs_select_nelmts = 1; - k < rank; k++) { - /* MIN() is used to get the remaining edge portion if exist. - * "dims[k] - hs_sel_offset[k]" is remaining edge portion that is smaller then the hyperslab.*/ - hs_sel_count[k] = - MIN(dims[k] - hs_sel_offset[k], hslab_dims[k]); - hs_select_nelmts *= hs_sel_count[k]; - } - - if (H5Sselect_hyperslab(f_space_id, - H5S_SELECT_SET, hs_sel_offset, - NULL, hs_sel_count, NULL) < 0) - goto error; - if (H5Sselect_hyperslab(hslab_space, - H5S_SELECT_SET, zero, NULL, - &hs_select_nelmts, NULL) < 0) - goto error; - } - else { - H5Sselect_all(f_space_id); - H5Sselect_all(hslab_space); - hs_select_nelmts = 1; - } /* rank */ - - /* read/write: use the macro to check error, e.g. memory allocation error inside the library. */ - CHECK_H5DRW_ERROR(H5Dread, dset_in, - wtype_id, hslab_space, f_space_id, - H5P_DEFAULT, hslab_buf); - CHECK_H5DRW_ERROR(H5Dwrite, dset_out, - wtype_id, hslab_space, f_space_id, - H5P_DEFAULT, hslab_buf); - - /* reclaim any VL memory, if necessary */ - if (vl_data) - H5Dvlen_reclaim(wtype_id, hslab_space, - H5P_DEFAULT, hslab_buf); - - /* calculate the next hyperslab offset */ - for (k = rank, carry = 1; k > 0 && carry; - --k) { - hs_sel_offset[k - 1] += hs_sel_count[k - - 1]; - /* if reached the end of a dim */ - if (hs_sel_offset[k - 1] == dims[k - 1]) - hs_sel_offset[k - 1] = 0; - else - carry = 0; - } /* k */ - } /* elmtno */ - - H5Sclose(hslab_space); - /* free */ - if (hslab_buf != NULL) { - HDfree(hslab_buf); - hslab_buf = NULL; - } - } /* hyperslab read */ - } /* if (nelmts>0 && space_status==H5D_SPACE_STATUS_NOT_ALLOCATED) */ - - /*------------------------------------------------------------------------- - * amount of compression used - *------------------------------------------------------------------------- - */ - if (options->verbose) { - double ratio = 0; - - /* only print the compression ration if there was a filter request */ - if (apply_s && apply_f && req_filter) { - /* get the storage size of the output dataset */ - dsize_out = H5Dget_storage_size(dset_out); - - /* compression ratio = uncompressed size / compressed size */ - if (dsize_out != 0) - ratio = (double) dsize_in - / (double) dsize_out; - - print_dataset_info(dcpl_out, - travt->objs[i].name, ratio, 1); - } - else - print_dataset_info(dcpl_in, travt->objs[i].name, - ratio, 0); - - /* print a message that the filter was not applied - (in case there was a filter) - */ - if (has_filter && apply_s == 0) - printf( - " <warning: filter not applied to %s. dataset smaller than %d bytes>\n", - travt->objs[i].name, - (int) options->min_comp); - - if (has_filter && apply_f == 0) - printf( - " <warning: could not apply the filter to %s>\n", - travt->objs[i].name); - - } /* verbose */ - - /*------------------------------------------------------------------------- - * copy attrs - *------------------------------------------------------------------------- - */ - if (copy_attr(dset_in, dset_out, &named_dt_head, travt, - options) < 0) - goto error; - /*close */ - if (H5Dclose(dset_out) < 0) - goto error; - - }/*!H5T_REFERENCE*/ - }/*h5tools_canreadf*/ - - /*------------------------------------------------------------------------- - * close - *------------------------------------------------------------------------- - */ - if (H5Tclose(ftype_id) < 0) - goto error; - if (H5Tclose(wtype_id) < 0) - goto error; - if (H5Pclose(dcpl_in) < 0) - goto error; - if (H5Pclose(dcpl_out) < 0) - goto error; - if (H5Sclose(f_space_id) < 0) - goto error; - if (H5Dclose(dset_in) < 0) - goto error; - - } - /*------------------------------------------------------------------------- - * we do not have request for filter/chunking use H5Ocopy instead - *------------------------------------------------------------------------- - */ - else { - hid_t pid; - - /* create property to pass copy options */ - if ((pid = H5Pcreate(H5P_OBJECT_COPY)) < 0) - goto error; - - /* set options for object copy */ - if (H5Pset_copy_object(pid, H5O_COPY_WITHOUT_ATTR_FLAG) < 0) - goto error; - - /*------------------------------------------------------------------------- - * do the copy - *------------------------------------------------------------------------- - */ - - if (H5Ocopy(fidin, /* Source file or group identifier */ - travt->objs[i].name, /* Name of the source object to be copied */ - fidout, /* Destination file or group identifier */ - travt->objs[i].name, /* Name of the destination object */ - pid, /* Properties which apply to the copy */ - H5P_DEFAULT) < 0) /* Properties which apply to the new hard link */ - goto error; - - /* close property */ - if (H5Pclose(pid) < 0) - goto error; - - /*------------------------------------------------------------------------- - * copy attrs manually - *------------------------------------------------------------------------- - */ - if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) - < 0) - goto error; - if ((dset_out = H5Dopen2(fidout, travt->objs[i].name, - H5P_DEFAULT)) < 0) - goto error; - if (copy_attr(dset_in, dset_out, &named_dt_head, travt, options) - < 0) - goto error; - if (H5Dclose(dset_in) < 0) - goto error; - if (H5Dclose(dset_out) < 0) - goto error; - - if (options->verbose) - printf(FORMAT_OBJ, "dset", travt->objs[i].name); - - } /* end do we have request for filter/chunking */ - - break; - - /*------------------------------------------------------------------------- - * H5TRAV_TYPE_NAMED_DATATYPE - *------------------------------------------------------------------------- - */ - case H5TRAV_TYPE_NAMED_DATATYPE: - - if (options->verbose) - printf(FORMAT_OBJ, "type", travt->objs[i].name); - - if ((type_in = H5Topen2(fidin, travt->objs[i].name, H5P_DEFAULT)) - < 0) - goto error; - - /* Copy the datatype anonymously */ - if ((type_out = copy_named_datatype(type_in, fidout, &named_dt_head, - travt, options)) < 0) - goto error; - - /* Link in to group structure */ - if (H5Lcreate_hard(type_out, ".", fidout, travt->objs[i].name, - H5P_DEFAULT, H5P_DEFAULT) < 0) - goto error; - - /*------------------------------------------------------------------------- - * copy attrs - *------------------------------------------------------------------------- - */ - if (copy_attr(type_in, type_out, &named_dt_head, travt, options) - < 0) - goto error; - - if (H5Tclose(type_in) < 0) - goto error; - if (H5Tclose(type_out) < 0) - goto error; - - break; - - /*------------------------------------------------------------------------- - * H5TRAV_TYPE_LINK - * H5TRAV_TYPE_UDLINK - * - * Only handles external links; H5Lcopy will fail for other UD link types - * since we don't have creation or copy callbacks for them. - *------------------------------------------------------------------------- - */ - - case H5TRAV_TYPE_LINK: - case H5TRAV_TYPE_UDLINK: { - - if (options->verbose) - printf(FORMAT_OBJ, "link", travt->objs[i].name); - - if (H5Lcopy(fidin, travt->objs[i].name, fidout, travt->objs[i].name, - H5P_DEFAULT, H5P_DEFAULT) < 0) - goto error; - - if (options->verbose) - printf(FORMAT_OBJ, "link", travt->objs[i].name); - - } - break; - - default: - goto error; - } /* switch */ - - /* free */ - if (buf != NULL) { - HDfree(buf); - buf = NULL; - } - - } /* i */ - - /* Finalize (link) the stack of named datatypes (if any) */ - named_datatype_free(&named_dt_head, 0); - - return 0; - -error: - H5E_BEGIN_TRY - { - H5Gclose(grp_in); - H5Gclose(grp_out); - H5Pclose(dcpl_in); - H5Pclose(gcpl_in); - H5Pclose(gcpl_out); - H5Sclose(f_space_id); - H5Dclose(dset_in); - H5Dclose(dset_out); - H5Tclose(ftype_id); - H5Tclose(wtype_id); - H5Tclose(type_in); - H5Tclose(type_out); - named_datatype_free(&named_dt_head, 1); - }H5E_END_TRY; - /* free */ - if (buf != NULL) - HDfree(buf); - if (hslab_buf != NULL) - HDfree(hslab_buf); - return -1; + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ + hid_t grp_in = -1; /* group ID */ + hid_t grp_out = -1; /* group ID */ + hid_t dset_in = -1; /* read dataset ID */ + hid_t dset_out = -1; /* write dataset ID */ + hid_t gcpl_in = -1; /* group creation property list */ + hid_t gcpl_out = -1; /* group creation property list */ + hid_t type_in = -1; /* named type ID */ + hid_t type_out = -1; /* named type ID */ + hid_t dcpl_in = -1; /* dataset creation property list ID */ + hid_t dcpl_out = -1; /* dataset creation property list ID */ + hid_t f_space_id = -1; /* file space ID */ + hid_t ftype_id = -1; /* file type ID */ + hid_t wtype_id = -1; /* read/write type ID */ + named_dt_t *named_dt_head = NULL; /* Pointer to the stack of named datatypes copied */ + size_t msize; /* size of type */ + hsize_t nelmts; /* number of elements in dataset */ + H5D_space_status_t space_status; /* determines whether space has been allocated for the dataset */ + int rank; /* rank of dataset */ + hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */ + hsize_t dsize_in; /* input dataset size before filter */ + hsize_t dsize_out; /* output dataset size after filter */ + int apply_s; /* flag for apply filter to small dataset sizes */ + int apply_f; /* flag for apply filter to return error on H5Dcreate */ + void *buf = NULL; /* buffer for raw data */ + void *hslab_buf = NULL; /* hyperslab buffer for raw data */ + int has_filter; /* current object has a filter */ + int req_filter; /* there was a request for a filter */ + int req_obj_layout = 0; /* request layout to current object */ + unsigned crt_order_flags; /* group creation order flag */ + unsigned i; + unsigned u; + int is_ref = 0; + htri_t is_named; + hbool_t limit_maxdims; + hsize_t size_dset; + + /*------------------------------------------------------------------------- + * copy the suppplied object list + *------------------------------------------------------------------------- + */ + + if (options->verbose) { + printf("-----------------------------------------\n"); + printf(" Type Filter (Compression) Name\n"); + printf("-----------------------------------------\n"); + } + + for (i = 0; i < travt->nobjs; i++) { + /* init variables per obj */ + buf = NULL; + limit_maxdims = FALSE; + + switch (travt->objs[i].type) { + case H5TRAV_TYPE_UNKNOWN: + HDassert(0); + break; + + /*------------------------------------------------------------------------- + * H5TRAV_TYPE_GROUP + *------------------------------------------------------------------------- + */ + case H5TRAV_TYPE_GROUP: + if (options->verbose) + printf(FORMAT_OBJ, "group", travt->objs[i].name); + + /* open input group */ + if ((grp_in = H5Gopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed"); + + /* get input group creation property list */ + if ((gcpl_in = H5Gget_create_plist(grp_in)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gget_create_plist failed"); + + /* query and set the group creation properties */ + if (H5Pget_link_creation_order(gcpl_in, &crt_order_flags) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pget_link_creation_order failed"); + + /* set up group creation property list */ + if ((gcpl_out = H5Pcreate(H5P_GROUP_CREATE)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pcreate failed"); + + if (H5Pset_link_creation_order(gcpl_out, crt_order_flags) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pset_link_creation_order failed"); + + /*------------------------------------------------------------------------- + * the root is a special case, we get an ID for the root group + * and copy its attributes using that ID + *------------------------------------------------------------------------- + */ + if (HDstrcmp(travt->objs[i].name, "/") == 0) { + if ((grp_out = H5Gopen2(fidout, "/", H5P_DEFAULT)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed"); + } + else { + if (options->grp_compact > 0 || options->grp_indexed > 0) + if (H5Pset_link_phase_change(gcpl_out, (unsigned) options->grp_compact, (unsigned) options->grp_indexed) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pset_link_phase_change failed"); + + if ((grp_out = H5Gcreate2(fidout, travt->objs[i].name, H5P_DEFAULT, gcpl_out, H5P_DEFAULT)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gcreate2 failed"); + } + + /*------------------------------------------------------------------------- + * copy attrs + *------------------------------------------------------------------------- + */ + if (copy_attr(grp_in, grp_out, &named_dt_head, travt, options) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_attr failed"); + + if (H5Pclose(gcpl_out) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + if (H5Pclose(gcpl_in) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + if (H5Gclose(grp_out) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed"); + if (H5Gclose(grp_in) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed"); + + break; + + /*------------------------------------------------------------------------- + * H5TRAV_TYPE_DATASET + *------------------------------------------------------------------------- + */ + case H5TRAV_TYPE_DATASET: + has_filter = 0; + req_filter = 0; + + /* check if global filters were requested */ + if (options->n_filter_g) + req_filter = 1; + + /* check if filters were requested for individual objects */ + for (u = 0; u < options->op_tbl->nelems; u++) + if (HDstrcmp(travt->objs[i].name, options->op_tbl->objs[u].path) == 0) + if (options->op_tbl->objs[u].filter->filtn > 0) + req_filter = 1; + + /* check if layout change requested individual object */ + if (options->layout_g != H5D_LAYOUT_ERROR) { + pack_info_t *pckinfo; + + /* any dataset is specified */ + if (options->op_tbl->nelems > 0) { + /* check if object exist */ + pckinfo = options_get_object(travt->objs[i].name, options->op_tbl); + if (pckinfo) + req_obj_layout = 1; + } + } + + /* early detection of references */ + if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); + if ((ftype_id = H5Dget_type(dset_in)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_type failed"); + if (H5T_REFERENCE == H5Tget_class(ftype_id)) + is_ref = 1; + + /* Check if the datatype is committed */ + if ((is_named = H5Tcommitted(ftype_id)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tcommitted failed"); + if (is_named) + if ((wtype_id = copy_named_datatype(ftype_id, fidout, &named_dt_head, travt, options)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_named_datatype failed"); + + if (H5Tclose(ftype_id) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); + if (H5Dclose(dset_in) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); + + /*------------------------------------------------------------------------- + * check if we should use H5Ocopy or not + * if there is a request for filters/layout, we read/write the object + * otherwise we do a copy using H5Ocopy + *------------------------------------------------------------------------- + */ + if (options->op_tbl->nelems || options->all_filter == 1 + || options->all_layout == 1 || is_ref || is_named) { + + int j; + + if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); + if ((f_space_id = H5Dget_space(dset_in)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); + if ((ftype_id = H5Dget_type(dset_in)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_type failed"); + if ((dcpl_in = H5Dget_create_plist(dset_in)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed"); + if ((dcpl_out = H5Pcopy(dcpl_in)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pcopy failed"); + if ((rank = H5Sget_simple_extent_ndims(f_space_id)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + HDmemset(dims, 0, sizeof dims); + if (H5Sget_simple_extent_dims(f_space_id, dims, NULL) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); + if (H5Dget_space_status(dset_in, &space_status) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space_status failed"); + + nelmts = 1; + for (j = 0; j < rank; j++) + nelmts *= dims[j]; + + /* wtype_id will have already been set if using a named dtype */ + if (!is_named) { + if (options->use_native == 1) + wtype_id = h5tools_get_native_type(ftype_id); + else + wtype_id = H5Tcopy(ftype_id); + } /* end if */ + + if ((msize = H5Tget_size(wtype_id)) == 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); + + /* size of current dset */ + size_dset = nelmts * msize; + + /*------------------------------------------------------------------------- + * check if the dataset creation property list has filters that + * are not registered in the current configuration + * 1) the external filters GZIP and SZIP might not be available + * 2) the internal filters might be turned off + *------------------------------------------------------------------------- + */ + if (h5tools_canreadf((travt->objs[i].name), dcpl_in) == 1) { + apply_s = 1; + apply_f = 1; + + /*------------------------------------------------------------------------- + * references are a special case + * we cannot just copy the buffers, but instead we recreate the reference + * in a second traversal of the output file + *------------------------------------------------------------------------- + */ + if (H5T_REFERENCE != H5Tget_class(wtype_id)) { + /* get the storage size of the input dataset */ + dsize_in = H5Dget_storage_size(dset_in); + + /* check for small size datasets (less than 1k) except + * changing to COMPACT. For the reference, COMPACT is limited + * by size 64K by library. + */ + if (options->layout_g != H5D_COMPACT) + if (size_dset < options->min_comp) + apply_s = 0; + + /* apply the filter */ + if (apply_s) + if (apply_filters(travt->objs[i].name, rank, dims, msize, dcpl_out, options, &has_filter) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "apply_filters failed"); + + /* only if layout change requested for entire file or + * individual obj */ + if (options->all_layout > 0 || req_obj_layout == 1) + /*------------------------------------------------- + * Unset the unlimited max dims if convert to other + * than chunk layouts, because unlimited max dims + * only can be applied to chunk layout. + * Also perform only for targeted dataset + * Also check for size limit to convert to compact + *-------------------------------------------------*/ + if (options->layout_g != H5D_CHUNKED) { + /* any dataset is specified */ + if (options->op_tbl->nelems > 0) { + /* if current obj match specified obj */ + if (options_get_object(travt->objs[i].name, options->op_tbl)) + limit_maxdims = TRUE; + } + else /* no dataset is specified */ + limit_maxdims = TRUE; + + /* if convert to COMPACT */ + if (options->layout_g == H5D_COMPACT) + /* should be smaller than 64K */ + if (size_dset > MAX_COMPACT_DSIZE) + limit_maxdims = FALSE; + + /* unset unlimited max dims */ + if (limit_maxdims) + H5Sset_extent_simple(f_space_id, rank, dims, NULL); + } + + /*------------------------------------------------------------------------- + * create the output dataset; + * disable error checking in case the dataset cannot be created with the + * modified dcpl; in that case use the original instead + *------------------------------------------------------------------------- + */ + dset_out = H5Dcreate2(fidout, travt->objs[i].name, wtype_id, f_space_id, H5P_DEFAULT, dcpl_out, H5P_DEFAULT); + if (dset_out == FAIL) { + H5Epush2(H5tools_ERR_STACK_g, __FILE__, FUNC, __LINE__, H5tools_ERR_CLS_g, H5E_tools_g, H5E_tools_min_id_g, "H5Dcreate2 failed"); + if (options->verbose) + printf(" warning: could not create dataset <%s>. Applying original settings\n", travt->objs[i].name); + + if ((dset_out = H5Dcreate2(fidout, travt->objs[i].name, wtype_id, f_space_id, H5P_DEFAULT, dcpl_in, H5P_DEFAULT)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dcreate2 failed"); + apply_f = 0; + } + + /*------------------------------------------------------------------------- + * read/write + *------------------------------------------------------------------------- + */ + if (nelmts > 0 && space_status != H5D_SPACE_STATUS_NOT_ALLOCATED) { + size_t need = (size_t)(nelmts * msize); /* bytes needed */ + + /* have to read the whole dataset if there is only one element in the dataset */ + if (need < H5TOOLS_MALLOCSIZE) + buf = HDmalloc(need); + + if (buf != NULL) { + /* read/write: use the macro to check error, e.g. memory allocation error inside the library. */ + CHECK_H5DRW_ERROR(H5Dread, FAIL, dset_in, wtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); + CHECK_H5DRW_ERROR(H5Dwrite, FAIL, dset_out, wtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); + + /* Check if we have VL data in the dataset's + * datatype that must be reclaimed */ + if (TRUE == H5Tdetect_class(wtype_id, H5T_VLEN)) + if (H5Dvlen_reclaim(wtype_id, f_space_id, H5P_DEFAULT, buf) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dvlen_reclaim failed"); + } + else { /* possibly not enough memory, read/write by hyperslabs */ + size_t p_type_nbytes = msize; /*size of memory type */ + hsize_t p_nelmts = nelmts; /*total elements */ + hsize_t elmtno; /*counter */ + int carry; /*counter carry value */ + unsigned int vl_data = 0; /*contains VL datatypes */ + + /* hyperslab info */ + hsize_t hslab_dims[H5S_MAX_RANK]; /*hyperslab dims */ + hsize_t hslab_nbytes; /*bytes per hyperslab */ + hsize_t hslab_nelmts; /*elements per hyperslab*/ + hid_t hslab_space; /*hyperslab data space */ + + /* hyperslab selection info */ + hsize_t hs_sel_offset[H5S_MAX_RANK];/* selection offset */ + hsize_t hs_sel_count[H5S_MAX_RANK]; /* selection count */ + hsize_t hs_select_nelmts; /* selected elements */ + hsize_t zero[8]; /*vector of zeros */ + int k; + H5D_layout_t dset_layout; + hid_t dcpl_tmp = -1; /* dataset creation property list ID */ + + /* check if we have VL data in the dataset's datatype */ + if (H5Tdetect_class(wtype_id, H5T_VLEN) == TRUE) + vl_data = TRUE; + + /* check first if writing dataset is chunked, + * if so use its chunk layout for better performance. */ + dset_layout = H5Pget_layout(dcpl_out); + if (dset_layout == H5D_CHUNKED) + dcpl_tmp = dcpl_out; /* writing dataset */ + else { /* if reading dataset is chunked */ + dset_layout = H5Pget_layout(dcpl_in); + if (dset_layout == H5D_CHUNKED) + dcpl_tmp = dcpl_in; /* reading dataset */ + } + + /* get hyperslab dims and size in byte */ + if (Get_hyperslab(dcpl_tmp, rank, dims, p_type_nbytes, hslab_dims, &hslab_nbytes) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Get_hyperslab failed"); + + hslab_buf = HDmalloc((size_t)hslab_nbytes); + + hslab_nelmts = hslab_nbytes / p_type_nbytes; + hslab_space = H5Screate_simple(1, &hslab_nelmts, NULL); + + /* the hyperslab selection loop */ + HDmemset(hs_sel_offset, 0, sizeof hs_sel_offset); + HDmemset(zero, 0, sizeof zero); + + for (elmtno = 0; elmtno < p_nelmts; elmtno += hs_select_nelmts) { + if (rank > 0) { + /* calculate the hyperslab selections. + * The selection would be same as the hyperslab + * except for remaining edge portion of the dataset + * which is smaller then the hyperslab. + */ + for (k = 0, hs_select_nelmts = 1; k < rank; k++) { + /* MIN() is used to get the remaining edge portion if exist. + * "dims[k] - hs_sel_offset[k]" is remaining edge portion that is smaller then the hyperslab.*/ + hs_sel_count[k] = MIN(dims[k] - hs_sel_offset[k], hslab_dims[k]); + hs_select_nelmts *= hs_sel_count[k]; + } + + if (H5Sselect_hyperslab(f_space_id, H5S_SELECT_SET, hs_sel_offset, NULL, hs_sel_count, NULL) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed"); + if (H5Sselect_hyperslab(hslab_space, H5S_SELECT_SET, zero, NULL, &hs_select_nelmts, NULL) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed"); + } + else { + H5Sselect_all(f_space_id); + H5Sselect_all(hslab_space); + hs_select_nelmts = 1; + } /* rank */ + + /* read/write: use the macro to check error, e.g. memory allocation error inside the library. */ + CHECK_H5DRW_ERROR(H5Dread, FAIL, dset_in, wtype_id, hslab_space, f_space_id, H5P_DEFAULT, hslab_buf); + CHECK_H5DRW_ERROR(H5Dwrite, FAIL, dset_out, wtype_id, hslab_space, f_space_id, H5P_DEFAULT, hslab_buf); + + /* reclaim any VL memory, if necessary */ + if (vl_data) + H5Dvlen_reclaim(wtype_id, hslab_space, H5P_DEFAULT, hslab_buf); + + /* calculate the next hyperslab offset */ + for (k = rank, carry = 1; k > 0 && carry; --k) { + hs_sel_offset[k - 1] += hs_sel_count[k - 1]; + /* if reached the end of a dim */ + if (hs_sel_offset[k - 1] == dims[k - 1]) + hs_sel_offset[k - 1] = 0; + else + carry = 0; + } /* k */ + } /* elmtno */ + + H5Sclose(hslab_space); + /* free */ + if (hslab_buf != NULL) { + HDfree(hslab_buf); + hslab_buf = NULL; + } + } /* hyperslab read */ + } /* if (nelmts>0 && space_status==H5D_SPACE_STATUS_NOT_ALLOCATED) */ + + /*------------------------------------------------------------------------- + * amount of compression used + *------------------------------------------------------------------------- + */ + if (options->verbose) { + double ratio = 0; + + /* only print the compression ration if there was a filter request */ + if (apply_s && apply_f && req_filter) { + /* get the storage size of the output dataset */ + dsize_out = H5Dget_storage_size(dset_out); + + /* compression ratio = uncompressed size / compressed size */ + if (dsize_out != 0) + ratio = (double) dsize_in / (double) dsize_out; + print_dataset_info(dcpl_out, travt->objs[i].name, ratio, 1); + } + else + print_dataset_info(dcpl_in, travt->objs[i].name, ratio, 0); + + /* print a message that the filter was not applied + (in case there was a filter) + */ + if (has_filter && apply_s == 0) + printf(" <warning: filter not applied to %s. dataset smaller than %d bytes>\n", travt->objs[i].name, (int) options->min_comp); + + if (has_filter && apply_f == 0) + printf(" <warning: could not apply the filter to %s>\n", travt->objs[i].name); + } /* verbose */ + + /*------------------------------------------------------------------------- + * copy attrs + *------------------------------------------------------------------------- + */ + if (copy_attr(dset_in, dset_out, &named_dt_head, travt, options) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_attr failed"); + + /*close */ + if (H5Dclose(dset_out) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); + }/*!H5T_REFERENCE*/ + }/*h5tools_canreadf*/ + + /*------------------------------------------------------------------------- + * close + *------------------------------------------------------------------------- + */ + if (H5Tclose(ftype_id) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); + if (H5Tclose(wtype_id) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); + if (H5Pclose(dcpl_in) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + if (H5Pclose(dcpl_out) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + if (H5Sclose(f_space_id) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); + if (H5Dclose(dset_in) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); + } + /*------------------------------------------------------------------------- + * we do not have request for filter/chunking use H5Ocopy instead + *------------------------------------------------------------------------- + */ + else { + hid_t pid; + + /* create property to pass copy options */ + if ((pid = H5Pcreate(H5P_OBJECT_COPY)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pcreate failed"); + + /* set options for object copy */ + if (H5Pset_copy_object(pid, H5O_COPY_WITHOUT_ATTR_FLAG) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pset_copy_object failed"); + + /*------------------------------------------------------------------------- + * do the copy + *------------------------------------------------------------------------- + */ + + if (H5Ocopy(fidin, /* Source file or group identifier */ + travt->objs[i].name, /* Name of the source object to be copied */ + fidout, /* Destination file or group identifier */ + travt->objs[i].name, /* Name of the destination object */ + pid, /* Properties which apply to the copy */ + H5P_DEFAULT) < 0) /* Properties which apply to the new hard link */ + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Ocopy failed"); + + /* close property */ + if (H5Pclose(pid) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); + + /*------------------------------------------------------------------------- + * copy attrs manually + *------------------------------------------------------------------------- + */ + if ((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); + if ((dset_out = H5Dopen2(fidout, travt->objs[i].name, H5P_DEFAULT)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); + if (copy_attr(dset_in, dset_out, &named_dt_head, travt, options) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_attr failed"); + if (H5Dclose(dset_in) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); + if (H5Dclose(dset_out) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); + + if (options->verbose) + printf(FORMAT_OBJ, "dset", travt->objs[i].name); + + } /* end do we have request for filter/chunking */ + break; + + /*------------------------------------------------------------------------- + * H5TRAV_TYPE_NAMED_DATATYPE + *------------------------------------------------------------------------- + */ + case H5TRAV_TYPE_NAMED_DATATYPE: + if (options->verbose) + printf(FORMAT_OBJ, "type", travt->objs[i].name); + + if ((type_in = H5Topen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Topen2 failed"); + + /* Copy the datatype anonymously */ + if ((type_out = copy_named_datatype(type_in, fidout, &named_dt_head, travt, options)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_named_datatype failed"); + + /* Link in to group structure */ + if (H5Lcreate_hard(type_out, ".", fidout, travt->objs[i].name, H5P_DEFAULT, H5P_DEFAULT) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Lcreate_hard failed"); + + /*------------------------------------------------------------------------- + * copy attrs + *------------------------------------------------------------------------- + */ + if (copy_attr(type_in, type_out, &named_dt_head, travt, options) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_attr failed"); + + if (H5Tclose(type_in) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); + if (H5Tclose(type_out) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); + + break; + + /*------------------------------------------------------------------------- + * H5TRAV_TYPE_LINK + * H5TRAV_TYPE_UDLINK + * + * Only handles external links; H5Lcopy will fail for other UD link types + * since we don't have creation or copy callbacks for them. + *------------------------------------------------------------------------- + */ + case H5TRAV_TYPE_LINK: + case H5TRAV_TYPE_UDLINK: + if (options->verbose) + printf(FORMAT_OBJ, "link", travt->objs[i].name); + + if (H5Lcopy(fidin, travt->objs[i].name, fidout, travt->objs[i].name, H5P_DEFAULT, H5P_DEFAULT) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Lcopy failed"); + + if (options->verbose) + printf(FORMAT_OBJ, "link", travt->objs[i].name); + break; + + default: + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Object type not found"); + } /* switch */ + + /* free */ + if (buf != NULL) { + HDfree(buf); + buf = NULL; + } + } /* i */ + + /* Finalize (link) the stack of named datatypes (if any) */ + named_datatype_free(&named_dt_head, 0); + + return ret_value; + +done: + H5E_BEGIN_TRY + { + H5Gclose(grp_in); + H5Gclose(grp_out); + H5Pclose(dcpl_in); + H5Pclose(gcpl_in); + H5Pclose(gcpl_out); + H5Sclose(f_space_id); + H5Dclose(dset_in); + H5Dclose(dset_out); + H5Tclose(ftype_id); + H5Tclose(wtype_id); + H5Tclose(type_in); + H5Tclose(type_out); + named_datatype_free(&named_dt_head, 1); + }H5E_END_TRY; + + /* free */ + if (buf != NULL) + HDfree(buf); + if (hslab_buf != NULL) + HDfree(hslab_buf); + + return ret_value; } /*------------------------------------------------------------------------- @@ -1382,101 +1304,102 @@ error: *------------------------------------------------------------------------- */ static void print_dataset_info(hid_t dcpl_id, char *objname, double ratio, - int pr) { - char strfilter[255]; + int pr) +{ + char strfilter[255]; #if defined (PRINT_DEBUG ) - char temp[255]; + char temp[255]; #endif - int nfilters; /* number of filters */ - unsigned filt_flags; /* filter flags */ - H5Z_filter_t filtn; /* filter identification number */ - unsigned cd_values[20]; /* filter client data values */ - size_t cd_nelmts; /* filter client number of values */ - char f_objname[256]; /* filter objname */ - int i; - - HDstrcpy(strfilter, "\0"); + int nfilters; /* number of filters */ + unsigned filt_flags; /* filter flags */ + H5Z_filter_t filtn; /* filter identification number */ + unsigned cd_values[20]; /* filter client data values */ + size_t cd_nelmts; /* filter client number of values */ + char f_objname[256]; /* filter objname */ + int i; - /* get information about input filters */ - if ((nfilters = H5Pget_nfilters(dcpl_id)) < 0) - return; + HDstrcpy(strfilter, "\0"); - for (i = 0; i < nfilters; i++) { - cd_nelmts = NELMTS(cd_values); + /* get information about input filters */ + if ((nfilters = H5Pget_nfilters(dcpl_id)) < 0) + return; - filtn = H5Pget_filter2(dcpl_id, (unsigned) i, &filt_flags, &cd_nelmts, - cd_values, sizeof(f_objname), f_objname, NULL); + for (i = 0; i < nfilters; i++) { + cd_nelmts = NELMTS(cd_values); - switch (filtn) { + filtn = H5Pget_filter2(dcpl_id, (unsigned) i, &filt_flags, &cd_nelmts, + cd_values, sizeof(f_objname), f_objname, NULL); - case H5Z_FILTER_NONE: - HDstrcat(strfilter, "NONE "); - break; + switch (filtn) { + case H5Z_FILTER_NONE: + HDstrcat(strfilter, "NONE "); + break; - case H5Z_FILTER_DEFLATE: - HDstrcat(strfilter, "GZIP "); + case H5Z_FILTER_DEFLATE: + HDstrcat(strfilter, "GZIP "); #if defined (PRINT_DEBUG) - { - unsigned level=cd_values[0]; - sprintf(temp,"(%d)",level); - HDstrcat(strfilter,temp); - } + { + unsigned level = cd_values[0]; + + sprintf(temp,"(%d)", level); + HDstrcat(strfilter, temp); + } #endif - break; + break; - case H5Z_FILTER_SZIP: - HDstrcat(strfilter, "SZIP "); + case H5Z_FILTER_SZIP: + HDstrcat(strfilter, "SZIP "); #if defined (PRINT_DEBUG) - { - unsigned options_mask=cd_values[0]; /* from dcpl, not filt*/ - unsigned ppb=cd_values[1]; - sprintf(temp,"(%d,",ppb); - HDstrcat(strfilter,temp); - if (options_mask & H5_SZIP_EC_OPTION_MASK) - HDstrcpy(temp,"EC) "); - else if (options_mask & H5_SZIP_NN_OPTION_MASK) - HDstrcpy(temp,"NN) "); - } - HDstrcat(strfilter,temp); - + { + unsigned options_mask = cd_values[0]; /* from dcpl, not filt*/ + unsigned ppb = cd_values[1]; + + sprintf(temp,"(%d,", ppb); + HDstrcat(strfilter, temp); + if (options_mask & H5_SZIP_EC_OPTION_MASK) + HDstrcpy(temp, "EC) "); + else if (options_mask & H5_SZIP_NN_OPTION_MASK) + HDstrcpy(temp, "NN) "); + } + HDstrcat(strfilter, temp); #endif - - break; - - case H5Z_FILTER_SHUFFLE: - HDstrcat(strfilter, "SHUF "); - break; - - case H5Z_FILTER_FLETCHER32: - HDstrcat(strfilter, "FLET "); - break; - - case H5Z_FILTER_NBIT: - HDstrcat(strfilter, "NBIT "); - break; - - case H5Z_FILTER_SCALEOFFSET: - HDstrcat(strfilter, "SCALEOFFSET "); - break; - - default: - HDstrcat(strfilter, "UD "); - break; - } /* switch */ - }/*i*/ - - if (!pr) - printf(FORMAT_OBJ, "dset", objname); - else { - char str[255], temp[28]; - HDstrcpy(str, "dset "); - HDstrcat(str, strfilter); - sprintf(temp, " (%.3f:1)", ratio); - HDstrcat(str, temp); - printf(FORMAT_OBJ, str, objname); - } + break; + + case H5Z_FILTER_SHUFFLE: + HDstrcat(strfilter, "SHUF "); + break; + + case H5Z_FILTER_FLETCHER32: + HDstrcat(strfilter, "FLET "); + break; + + case H5Z_FILTER_NBIT: + HDstrcat(strfilter, "NBIT "); + break; + + case H5Z_FILTER_SCALEOFFSET: + HDstrcat(strfilter, "SCALEOFFSET "); + break; + + default: + HDstrcat(strfilter, "UD "); + break; + } /* switch */ + }/*i*/ + + if (!pr) + printf(FORMAT_OBJ, "dset", objname); + else { + char str[255], temp[28]; + + HDstrcpy(str, "dset "); + HDstrcat(str, strfilter); + sprintf(temp, " (%.3f:1)", ratio); + HDstrcat(str, temp); + printf(FORMAT_OBJ, str, objname); + } } /*------------------------------------------------------------------------- @@ -1493,73 +1416,66 @@ static void print_dataset_info(hid_t dcpl_id, char *objname, double ratio, *------------------------------------------------------------------------- */ static int copy_user_block(const char *infile, const char *outfile, - hsize_t size) { - int infid = -1, outfid = -1; /* File descriptors */ - int status = 0; /* Return value */ - - /* User block must be any power of 2 equal to 512 or greater (512, 1024, 2048, etc.) */ - HDassert(size > 0); - - /* Open files */ - if ((infid = HDopen(infile, O_RDONLY, 0)) < 0) { - status = -1; - goto done; - } - if ((outfid = HDopen(outfile, O_WRONLY, 0644)) < 0) { - status = -1; - goto done; - } - - /* Copy the userblock from the input file to the output file */ - while (size > 0) { - ssize_t nread, nbytes; /* # of bytes transfered, etc. */ - char rbuf[USERBLOCK_XFER_SIZE]; /* Buffer for reading */ - const char *wbuf; /* Pointer into buffer, for writing */ - - /* Read buffer from source file */ - if (size > USERBLOCK_XFER_SIZE) - nread = HDread(infid, rbuf, (size_t)USERBLOCK_XFER_SIZE); - else - nread = HDread(infid, rbuf, (size_t)size); - if (nread < 0) { - status = -1; - goto done; - } /* end if */ - - /* Write buffer to destination file */ - /* (compensating for interrupted writes & checking for errors, etc.) */ - nbytes = nread; - wbuf = rbuf; - while (nbytes > 0) { - ssize_t nwritten; /* # of bytes written */ - - do { - nwritten = HDwrite(outfid, wbuf, (size_t)nbytes); - } while (-1 == nwritten && EINTR == errno); - if (-1 == nwritten) { /* error */ - status = -1; - goto done; - } /* end if */ - HDassert(nwritten > 0); - HDassert(nwritten <= nbytes); - - /* Update # of bytes left & offset in buffer */ - nbytes -= nwritten; - wbuf += nwritten; - HDassert(nbytes == 0 || wbuf < (rbuf + USERBLOCK_XFER_SIZE)); - } /* end while */ - - /* Update size of userblock left to transfer */ - size = size - (hsize_t) nread; - } /* end while */ + hsize_t size) +{ + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ + int infid = -1, outfid = -1; /* File descriptors */ + + /* User block must be any power of 2 equal to 512 or greater (512, 1024, 2048, etc.) */ + HDassert(size > 0); + + /* Open files */ + if ((infid = HDopen(infile, O_RDONLY, 0)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDopen failed"); + if ((outfid = HDopen(outfile, O_WRONLY, 0644)) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDopen failed"); + + /* Copy the userblock from the input file to the output file */ + while (size > 0) { + ssize_t nread, nbytes; /* # of bytes transfered, etc. */ + char rbuf[USERBLOCK_XFER_SIZE]; /* Buffer for reading */ + const char *wbuf; /* Pointer into buffer, for writing */ + + /* Read buffer from source file */ + if (size > USERBLOCK_XFER_SIZE) + nread = HDread(infid, rbuf, (size_t)USERBLOCK_XFER_SIZE); + else + nread = HDread(infid, rbuf, (size_t)size); + if (nread < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDread failed"); + + /* Write buffer to destination file */ + /* (compensating for interrupted writes & checking for errors, etc.) */ + nbytes = nread; + wbuf = rbuf; + while (nbytes > 0) { + ssize_t nwritten; /* # of bytes written */ + + do { + nwritten = HDwrite(outfid, wbuf, (size_t)nbytes); + } while (-1 == nwritten && EINTR == errno); + if (-1 == nwritten) /* error */ + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDwrite failed"); + HDassert(nwritten > 0); + HDassert(nwritten <= nbytes); + + /* Update # of bytes left & offset in buffer */ + nbytes -= nwritten; + wbuf += nwritten; + HDassert(nbytes == 0 || wbuf < (rbuf + USERBLOCK_XFER_SIZE)); + } /* end while */ + + /* Update size of userblock left to transfer */ + size = size - (hsize_t) nread; + } /* end while */ done: - if (infid > 0) - HDclose(infid); - if (outfid > 0) - HDclose(outfid); + if (infid > 0) + HDclose(infid); + if (outfid > 0) + HDclose(outfid); - return status; + return ret_value; } /*------------------------------------------------------------------------- @@ -1579,66 +1495,67 @@ done: static void print_user_block(const char *filename, hid_t fid) { - int fh; /* file handle */ - hsize_t ub_size; /* user block size */ - hsize_t size; /* size read */ - hid_t fcpl; /* file creation property list ID for HDF5 file */ - int i; - - /* get user block size */ - if(( fcpl = H5Fget_create_plist(fid)) < 0) { - error_msg("failed to retrieve file creation property list\n"); - goto done; - } - - if(H5Pget_userblock(fcpl, &ub_size) < 0) { - error_msg("failed to retrieve userblock size\n"); - goto done; - } - - if(H5Pclose(fcpl) < 0) { - error_msg("failed to close property list\n"); - goto done; - } - - /* open file */ - if((fh = HDopen(filename, O_RDONLY, 0)) < 0) { - goto done; - } - - size = ub_size; - - /* read file */ - while(size > 0) { - ssize_t nread; /* # of bytes read */ - char rbuf[USERBLOCK_XFER_SIZE]; /* buffer for reading */ - - /* read buffer */ - if(size > USERBLOCK_XFER_SIZE) - nread = HDread(fh, rbuf, (size_t)USERBLOCK_XFER_SIZE); - else - nread = HDread(fh, rbuf, (size_t)size); - - for(i = 0; i < nread; i++) { - - printf("%c ", rbuf[i]); - - } - printf("\n"); - - if(nread < 0) { - goto done; - } - - /* update size of userblock left to transfer */ - size -= nread; - } + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ + int fh; /* file handle */ + hsize_t ub_size; /* user block size */ + hsize_t size; /* size read */ + hid_t fcpl; /* file creation property list ID for HDF5 file */ + int i; + + /* get user block size */ + if(( fcpl = H5Fget_create_plist(fid)) < 0) { + error_msg("failed to retrieve file creation property list\n"); + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Fget_create_plist failed"); + } + + if(H5Pget_userblock(fcpl, &ub_size) < 0) { + error_msg("failed to retrieve userblock size\n"); + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pget_userblock failed"); + } + + if(H5Pclose(fcpl) < 0) { + error_msg("failed to close property list\n"); + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Pclose failed"); + } + + /* open file */ + if((fh = HDopen(filename, O_RDONLY, 0)) < 0) { + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "HDopen failed"); + } + + size = ub_size; + + /* read file */ + while(size > 0) { + ssize_t nread; /* # of bytes read */ + char rbuf[USERBLOCK_XFER_SIZE]; /* buffer for reading */ + + /* read buffer */ + if(size > USERBLOCK_XFER_SIZE) + nread = HDread(fh, rbuf, (size_t)USERBLOCK_XFER_SIZE); + else + nread = HDread(fh, rbuf, (size_t)size); + + for(i = 0; i < nread; i++) { + + printf("%c ", rbuf[i]); + + } + printf("\n"); + + if(nread < 0) { + HGOTO_ERROR(H5E_tools_g, H5E_tools_min_id_g, "nread < 0"); + } + + /* update size of userblock left to transfer */ + size -= nread; + } done: - if(fh > 0) - HDclose(fh); + if(fh > 0) + HDclose(fh); - return; + return; } #endif diff --git a/tools/h5repack/h5repack_filters.c b/tools/h5repack/h5repack_filters.c index 56e08ef..e873a53 100644 --- a/tools/h5repack/h5repack_filters.c +++ b/tools/h5repack/h5repack_filters.c @@ -34,8 +34,8 @@ * *------------------------------------------------------------------------- */ -static -int aux_find_obj(const char* name, /* object name from traverse list */ +static int +aux_find_obj(const char* name, /* object name from traverse list */ pack_opt_t *options, /* repack options */ pack_info_t *obj /*OUT*/) /* info about object to filter */ { @@ -48,7 +48,7 @@ int aux_find_obj(const char* name, /* object name from traverse list */ if (HDstrcmp(options->op_tbl->objs[i].path,name)==0) { *obj = options->op_tbl->objs[i]; - return i; + return (int)i; } pdest = HDstrstr(name,options->op_tbl->objs[i].path); @@ -58,7 +58,7 @@ int aux_find_obj(const char* name, /* object name from traverse list */ if( pdest != NULL && result==1 ) { *obj = options->op_tbl->objs[i]; - return i; + return (int)i; } }/*i*/ @@ -76,8 +76,8 @@ int aux_find_obj(const char* name, /* object name from traverse list */ * *------------------------------------------------------------------------- */ -static -int aux_assign_obj(const char* name, /* object name from traverse list */ +static int +aux_assign_obj(const char* name, /* object name from traverse list */ pack_opt_t *options, /* repack options */ pack_info_t *obj /*OUT*/) /* info about object to filter */ { @@ -433,7 +433,7 @@ int apply_filters(const char* name, /* object name from traverse list */ int scale_factor; scale_type = (H5Z_SO_scale_type_t)obj.filter[i].cd_values[0]; - scale_factor = obj.filter[i].cd_values[1]; + scale_factor = (int)obj.filter[i].cd_values[1]; if(H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths)<0) return -1; diff --git a/tools/h5repack/h5repack_main.c b/tools/h5repack/h5repack_main.c index f3fd469..7998ae8 100644 --- a/tools/h5repack/h5repack_main.c +++ b/tools/h5repack/h5repack_main.c @@ -33,28 +33,29 @@ const char *outfile = NULL; * Command-line options: The user can specify short or long-named * parameters. */ -static const char *s_opts = "hVvf:l:m:e:nLc:d:s:u:b:M:t:a:i:o:"; +static const char *s_opts = "hVvf:l:m:e:nLc:d:s:u:b:M:t:a:i:o:E"; static struct long_options l_opts[] = { - { "help", no_arg, 'h' }, - { "version", no_arg, 'V' }, - { "verbose", no_arg, 'v' }, - { "filter", require_arg, 'f' }, - { "layout", require_arg, 'l' }, - { "minimum", require_arg, 'm' }, - { "file", require_arg, 'e' }, - { "native", no_arg, 'n' }, - { "latest", no_arg, 'L' }, - { "compact", require_arg, 'c' }, - { "indexed", require_arg, 'd' }, - { "ssize", require_arg, 's' }, - { "ublock", require_arg, 'u' }, - { "block", require_arg, 'b' }, - { "metadata_block_size", require_arg, 'M' }, - { "threshold", require_arg, 't' }, - { "alignment", require_arg, 'a' }, - { "infile", require_arg, 'i' }, /* -i for backward compability */ - { "outfile", require_arg, 'o' }, /* -o for backward compability */ - { NULL, 0, '\0' } + { "help", no_arg, 'h' }, + { "version", no_arg, 'V' }, + { "verbose", no_arg, 'v' }, + { "filter", require_arg, 'f' }, + { "layout", require_arg, 'l' }, + { "minimum", require_arg, 'm' }, + { "file", require_arg, 'e' }, + { "native", no_arg, 'n' }, + { "latest", no_arg, 'L' }, + { "compact", require_arg, 'c' }, + { "indexed", require_arg, 'd' }, + { "ssize", require_arg, 's' }, + { "ublock", require_arg, 'u' }, + { "block", require_arg, 'b' }, + { "metadata_block_size", require_arg, 'M' }, + { "threshold", require_arg, 't' }, + { "alignment", require_arg, 'a' }, + { "infile", require_arg, 'i' }, /* -i for backward compability */ + { "outfile", require_arg, 'o' }, /* -o for backward compability */ + { "enable-error-stack", no_arg, 'E' }, + { NULL, 0, '\0' } }; /*------------------------------------------------------------------------- @@ -67,113 +68,117 @@ static struct long_options l_opts[] = { *------------------------------------------------------------------------- */ static void usage(const char *prog) { - printf("usage: %s [OPTIONS] file1 file2\n", prog); - printf(" file1 Input HDF5 File\n"); - printf(" file2 Output HDF5 File\n"); - printf(" OPTIONS\n"); - printf(" -h, --help Print a usage message and exit\n"); - printf(" -v, --verbose Verbose mode, print object information\n"); - printf(" -V, --version Print version number and exit\n"); - printf(" -n, --native Use a native HDF5 type when repacking\n"); - printf(" -L, --latest Use latest version of file format\n"); - printf(" -c L1, --compact=L1 Maximum number of links in header messages\n"); - printf(" -d L2, --indexed=L2 Minimum number of links in the indexed format\n"); - printf(" -s S[:F], --ssize=S[:F] Shared object header message minimum size\n"); - printf(" -m M, --minimum=M Do not apply the filter to datasets smaller than M\n"); - printf(" -e E, --file=E Name of file E with the -f and -l options\n"); - printf(" -u U, --ublock=U Name of file U with user block data to be added\n"); - printf(" -b B, --block=B Size of user block to be added\n"); - printf(" -M A, --metadata_block_size=A Metadata block size for H5Pset_meta_block_size\n"); - printf(" -t T, --threshold=T Threshold value for H5Pset_alignment\n"); - printf(" -a A, --alignment=A Alignment value for H5Pset_alignment\n"); - printf(" -f FILT, --filter=FILT Filter type\n"); - printf(" -l LAYT, --layout=LAYT Layout type\n"); - printf("\n"); - printf(" M - is an integer greater than 1, size of dataset in bytes (default is 0) \n"); - printf(" E - is a filename.\n"); - printf(" S - is an integer\n"); - printf(" U - is a filename.\n"); - printf(" T - is an integer\n"); - printf(" A - is an integer greater than zero\n"); - printf(" B - is the user block size, any value that is 512 or greater and is\n"); - printf(" a power of 2 (1024 default)\n"); - printf(" F - is the shared object header message type, any of <dspace|dtype|fill|\n"); - printf(" pline|attr>. If F is not specified, S applies to all messages\n"); - printf("\n"); - printf(" FILT - is a string with the format:\n"); - printf("\n"); - printf(" <list of objects>:<name of filter>=<filter parameters>\n"); - printf("\n"); - printf(" <list of objects> is a comma separated list of object names, meaning apply\n"); - printf(" compression only to those objects. If no names are specified, the filter\n"); - printf(" is applied to all objects\n"); - printf(" <name of filter> can be:\n"); - printf(" GZIP, to apply the HDF5 GZIP filter (GZIP compression)\n"); - printf(" SZIP, to apply the HDF5 SZIP filter (SZIP compression)\n"); - printf(" SHUF, to apply the HDF5 shuffle filter\n"); - printf(" FLET, to apply the HDF5 checksum filter\n"); - printf(" NBIT, to apply the HDF5 NBIT filter (NBIT compression)\n"); - printf(" SOFF, to apply the HDF5 Scale/Offset filter\n"); - printf(" UD, to apply a user defined filter\n"); - printf(" NONE, to remove all filters\n"); - printf(" <filter parameters> is optional filter parameter information\n"); - printf(" GZIP=<deflation level> from 1-9\n"); - printf(" SZIP=<pixels per block,coding> pixels per block is a even number in\n"); - printf(" 2-32 and coding method is either EC or NN\n"); - printf(" SHUF (no parameter)\n"); - printf(" FLET (no parameter)\n"); - printf(" NBIT (no parameter)\n"); - printf(" SOFF=<scale_factor,scale_type> scale_factor is an integer and scale_type\n"); - printf(" is either IN or DS\n"); - printf(" UD=<filter_number,cd_value_count,value_1[,value_2,...,value_N]>\n"); - printf(" required values for filter_number,cd_value_count,value_1\n"); - printf(" optional values for value_2 to value_N\n"); - printf(" NONE (no parameter)\n"); - printf("\n"); - printf(" LAYT - is a string with the format:\n"); - printf("\n"); - printf(" <list of objects>:<layout type>=<layout parameters>\n"); - printf("\n"); - printf(" <list of objects> is a comma separated list of object names, meaning that\n"); - printf(" layout information is supplied for those objects. If no names are\n"); - printf(" specified, the layout type is applied to all objects\n"); - printf(" <layout type> can be:\n"); - printf(" CHUNK, to apply chunking layout\n"); - printf(" COMPA, to apply compact layout\n"); - printf(" CONTI, to apply contiguous layout\n"); - printf(" <layout parameters> is optional layout information\n"); - printf(" CHUNK=DIM[xDIM...xDIM], the chunk size of each dimension\n"); - printf(" COMPA (no parameter)\n"); - printf(" CONTI (no parameter)\n"); - printf("\n"); - printf("Examples of use:\n"); - printf("\n"); - printf("1) h5repack -v -f GZIP=1 file1 file2\n"); - printf("\n"); - printf(" GZIP compression with level 1 to all objects\n"); - printf("\n"); - printf("2) h5repack -v -f dset1:SZIP=8,NN file1 file2\n"); - printf("\n"); - printf(" SZIP compression with 8 pixels per block and NN coding method to object dset1\n"); - printf("\n"); - printf("3) h5repack -v -l dset1,dset2:CHUNK=20x10 -f dset3,dset4,dset5:NONE file1 file2\n"); - printf("\n"); - printf(" Chunked layout, with a layout size of 20x10, to objects dset1 and dset2\n"); - printf(" and remove filters to objects dset3, dset4, dset5\n"); - printf("\n"); - printf("4) h5repack -L -c 10 -s 20:dtype file1 file2 \n"); - printf("\n"); - printf(" Using latest file format with maximum compact group size of 10 and\n"); - printf(" and minimum shared datatype size of 20\n"); - printf("\n"); - printf("5) h5repack -f SHUF -f GZIP=1 file1 file2 \n"); - printf("\n"); - printf(" Add both filters SHUF and GZIP in this order to all datasets\n"); - printf("\n"); - printf("6) h5repack -f UD=307,1,9 file1 file2 \n"); - printf("\n"); - printf(" Add bzip2 filter to all datasets\n"); - printf("\n"); + FLUSHSTREAM(rawoutstream); + PRINTSTREAM(rawoutstream, "usage: %s [OPTIONS] file1 file2\n", prog); + PRINTVALSTREAM(rawoutstream, " file1 Input HDF5 File\n"); + PRINTVALSTREAM(rawoutstream, " file2 Output HDF5 File\n"); + PRINTVALSTREAM(rawoutstream, " OPTIONS\n"); + PRINTVALSTREAM(rawoutstream, " -h, --help Print a usage message and exit\n"); + PRINTVALSTREAM(rawoutstream, " -v, --verbose Verbose mode, print object information\n"); + PRINTVALSTREAM(rawoutstream, " -V, --version Print version number and exit\n"); + PRINTVALSTREAM(rawoutstream, " -n, --native Use a native HDF5 type when repacking\n"); + PRINTVALSTREAM(rawoutstream, " -L, --latest Use latest version of file format\n"); + PRINTVALSTREAM(rawoutstream, " -c L1, --compact=L1 Maximum number of links in header messages\n"); + PRINTVALSTREAM(rawoutstream, " -d L2, --indexed=L2 Minimum number of links in the indexed format\n"); + PRINTVALSTREAM(rawoutstream, " -s S[:F], --ssize=S[:F] Shared object header message minimum size\n"); + PRINTVALSTREAM(rawoutstream, " -m M, --minimum=M Do not apply the filter to datasets smaller than M\n"); + PRINTVALSTREAM(rawoutstream, " -e E, --file=E Name of file E with the -f and -l options\n"); + PRINTVALSTREAM(rawoutstream, " -u U, --ublock=U Name of file U with user block data to be added\n"); + PRINTVALSTREAM(rawoutstream, " -b B, --block=B Size of user block to be added\n"); + PRINTVALSTREAM(rawoutstream, " -M A, --metadata_block_size=A Metadata block size for H5Pset_meta_block_size\n"); + PRINTVALSTREAM(rawoutstream, " -t T, --threshold=T Threshold value for H5Pset_alignment\n"); + PRINTVALSTREAM(rawoutstream, " -a A, --alignment=A Alignment value for H5Pset_alignment\n"); + PRINTVALSTREAM(rawoutstream, " -f FILT, --filter=FILT Filter type\n"); + PRINTVALSTREAM(rawoutstream, " -l LAYT, --layout=LAYT Layout type\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, " M - is an integer greater than 1, size of dataset in bytes (default is 0) \n"); + PRINTVALSTREAM(rawoutstream, " E - is a filename.\n"); + PRINTVALSTREAM(rawoutstream, " S - is an integer\n"); + PRINTVALSTREAM(rawoutstream, " U - is a filename.\n"); + PRINTVALSTREAM(rawoutstream, " T - is an integer\n"); + PRINTVALSTREAM(rawoutstream, " A - is an integer greater than zero\n"); + PRINTVALSTREAM(rawoutstream, " B - is the user block size, any value that is 512 or greater and is\n"); + PRINTVALSTREAM(rawoutstream, " a power of 2 (1024 default)\n"); + PRINTVALSTREAM(rawoutstream, " F - is the shared object header message type, any of <dspace|dtype|fill|\n"); + PRINTVALSTREAM(rawoutstream, " pline|attr>. If F is not specified, S applies to all messages\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, " --enable-error-stack Prints messages from the HDF5 error stack as they\n"); + PRINTVALSTREAM(rawoutstream, " occur.\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, " FILT - is a string with the format:\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, " <list of objects>:<name of filter>=<filter parameters>\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, " <list of objects> is a comma separated list of object names, meaning apply\n"); + PRINTVALSTREAM(rawoutstream, " compression only to those objects. If no names are specified, the filter\n"); + PRINTVALSTREAM(rawoutstream, " is applied to all objects\n"); + PRINTVALSTREAM(rawoutstream, " <name of filter> can be:\n"); + PRINTVALSTREAM(rawoutstream, " GZIP, to apply the HDF5 GZIP filter (GZIP compression)\n"); + PRINTVALSTREAM(rawoutstream, " SZIP, to apply the HDF5 SZIP filter (SZIP compression)\n"); + PRINTVALSTREAM(rawoutstream, " SHUF, to apply the HDF5 shuffle filter\n"); + PRINTVALSTREAM(rawoutstream, " FLET, to apply the HDF5 checksum filter\n"); + PRINTVALSTREAM(rawoutstream, " NBIT, to apply the HDF5 NBIT filter (NBIT compression)\n"); + PRINTVALSTREAM(rawoutstream, " SOFF, to apply the HDF5 Scale/Offset filter\n"); + PRINTVALSTREAM(rawoutstream, " UD, to apply a user defined filter\n"); + PRINTVALSTREAM(rawoutstream, " NONE, to remove all filters\n"); + PRINTVALSTREAM(rawoutstream, " <filter parameters> is optional filter parameter information\n"); + PRINTVALSTREAM(rawoutstream, " GZIP=<deflation level> from 1-9\n"); + PRINTVALSTREAM(rawoutstream, " SZIP=<pixels per block,coding> pixels per block is a even number in\n"); + PRINTVALSTREAM(rawoutstream, " 2-32 and coding method is either EC or NN\n"); + PRINTVALSTREAM(rawoutstream, " SHUF (no parameter)\n"); + PRINTVALSTREAM(rawoutstream, " FLET (no parameter)\n"); + PRINTVALSTREAM(rawoutstream, " NBIT (no parameter)\n"); + PRINTVALSTREAM(rawoutstream, " SOFF=<scale_factor,scale_type> scale_factor is an integer and scale_type\n"); + PRINTVALSTREAM(rawoutstream, " is either IN or DS\n"); + PRINTVALSTREAM(rawoutstream, " UD=<filter_number,cd_value_count,value_1[,value_2,...,value_N]>\n"); + PRINTVALSTREAM(rawoutstream, " required values for filter_number,cd_value_count,value_1\n"); + PRINTVALSTREAM(rawoutstream, " optional values for value_2 to value_N\n"); + PRINTVALSTREAM(rawoutstream, " NONE (no parameter)\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, " LAYT - is a string with the format:\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, " <list of objects>:<layout type>=<layout parameters>\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, " <list of objects> is a comma separated list of object names, meaning that\n"); + PRINTVALSTREAM(rawoutstream, " layout information is supplied for those objects. If no names are\n"); + PRINTVALSTREAM(rawoutstream, " specified, the layout type is applied to all objects\n"); + PRINTVALSTREAM(rawoutstream, " <layout type> can be:\n"); + PRINTVALSTREAM(rawoutstream, " CHUNK, to apply chunking layout\n"); + PRINTVALSTREAM(rawoutstream, " COMPA, to apply compact layout\n"); + PRINTVALSTREAM(rawoutstream, " CONTI, to apply contiguous layout\n"); + PRINTVALSTREAM(rawoutstream, " <layout parameters> is optional layout information\n"); + PRINTVALSTREAM(rawoutstream, " CHUNK=DIM[xDIM...xDIM], the chunk size of each dimension\n"); + PRINTVALSTREAM(rawoutstream, " COMPA (no parameter)\n"); + PRINTVALSTREAM(rawoutstream, " CONTI (no parameter)\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, "Examples of use:\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, "1) h5repack -v -f GZIP=1 file1 file2\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, " GZIP compression with level 1 to all objects\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, "2) h5repack -v -f dset1:SZIP=8,NN file1 file2\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, " SZIP compression with 8 pixels per block and NN coding method to object dset1\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, "3) h5repack -v -l dset1,dset2:CHUNK=20x10 -f dset3,dset4,dset5:NONE file1 file2\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, " Chunked layout, with a layout size of 20x10, to objects dset1 and dset2\n"); + PRINTVALSTREAM(rawoutstream, " and remove filters to objects dset3, dset4, dset5\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, "4) h5repack -L -c 10 -s 20:dtype file1 file2 \n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, " Using latest file format with maximum compact group size of 10 and\n"); + PRINTVALSTREAM(rawoutstream, " and minimum shared datatype size of 20\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, "5) h5repack -f SHUF -f GZIP=1 file1 file2 \n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, " Add both filters SHUF and GZIP in this order to all datasets\n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, "6) h5repack -f UD=307,1,9 file1 file2 \n"); + PRINTVALSTREAM(rawoutstream, "\n"); + PRINTVALSTREAM(rawoutstream, " Add bzip2 filter to all datasets\n"); + PRINTVALSTREAM(rawoutstream, "\n"); } /*------------------------------------------------------------------------- @@ -242,14 +247,24 @@ int read_info(const char *filename, pack_opt_t *options) { i = 0; c = '0'; while (c != ' ') { - fscanf(fp, "%c", &c); + if(fscanf(fp, "%c", &c) < 0 && HDferror(fp)) { + error_msg("fscanf error\n"); + h5tools_setstatus(EXIT_FAILURE); + ret_value = EXIT_FAILURE; + goto done; + } /* end if */ if (HDfeof(fp)) break; } c = '0'; /* go until end */ while (c != ' ') { - fscanf(fp, "%c", &c); + if(fscanf(fp, "%c", &c) < 0 && HDferror(fp)) { + error_msg("fscanf error\n"); + h5tools_setstatus(EXIT_FAILURE); + ret_value = EXIT_FAILURE; + goto done; + } /* end if */ comp_info[i] = c; i++; if (HDfeof(fp)) @@ -276,14 +291,24 @@ int read_info(const char *filename, pack_opt_t *options) { i = 0; c = '0'; while (c != ' ') { - fscanf(fp, "%c", &c); + if(fscanf(fp, "%c", &c) < 0 && HDferror(fp)) { + error_msg("fscanf error\n"); + h5tools_setstatus(EXIT_FAILURE); + ret_value = EXIT_FAILURE; + goto done; + } /* end if */ if (HDfeof(fp)) break; } c = '0'; /* go until end */ while (c != ' ') { - fscanf(fp, "%c", &c); + if(fscanf(fp, "%c", &c) < 0 && HDferror(fp)) { + error_msg("fscanf error\n"); + h5tools_setstatus(EXIT_FAILURE); + ret_value = EXIT_FAILURE; + goto done; + } /* end if */ comp_info[i] = c; i++; if (HDfeof(fp)) @@ -343,7 +368,7 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) { has_i_o = 1; break; - /* -o for backward compability */ + /* -o for backward compability */ case 'o': outfile = opt_arg; has_i_o = 1; @@ -386,7 +411,7 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) { break; case 'm': - options->min_comp = HDatoi( opt_arg ); + options->min_comp = HDstrtoull(opt_arg , NULL, 0); if ((int) options->min_comp <= 0) { error_msg("invalid minimum compress size <%s>\n", opt_arg); h5tools_setstatus(EXIT_FAILURE); @@ -473,7 +498,7 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) { break; case 'a': - options->alignment = HDatol( opt_arg ); + options->alignment = HDstrtoull(opt_arg , NULL, 0); if (options->alignment < 1) { error_msg("invalid alignment size\n", opt_arg); h5tools_setstatus(EXIT_FAILURE); @@ -482,13 +507,17 @@ int parse_command_line(int argc, const char **argv, pack_opt_t* options) { } break; - default: - break; - } /* switch */ + case 'E': + enable_error_stack = TRUE; + break; + + default: + break; + } /* switch */ - } /* while */ + } /* while */ - if (has_i_o == 0) { + if (has_i_o == 0) { /* check for file names to be processed */ if (argc <= opt_ind || argv[opt_ind + 1] == NULL) { error_msg("missing file names\n"); @@ -520,50 +549,67 @@ done: *------------------------------------------------------------------------- */ int main(int argc, const char **argv) { + H5E_auto2_t func; + H5E_auto2_t tools_func; + void *edata; + void *tools_edata; pack_opt_t options; /*the global options */ h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); - /* Initialize h5tools lib */ - h5tools_init(); - - /* update hyperslab buffer size from H5TOOLS_BUFSIZE env if exist */ - if (h5tools_getenv_update_hyperslab_bufsize() < 0) { - h5tools_setstatus(EXIT_FAILURE); - goto done; - } - - /* initialize options */ - h5repack_init(&options, 0); - - if (parse_command_line(argc, argv, &options) < 0) - goto done; - - /* get file names if they were not yet got */ - if (has_i_o == 0) { - - if (argv[opt_ind] != NULL && argv[opt_ind + 1] != NULL) { - infile = argv[opt_ind]; - outfile = argv[opt_ind + 1]; - - if ( HDstrcmp( infile, outfile ) == 0) { - error_msg("file names cannot be the same\n"); - usage(h5tools_getprogname()); - h5tools_setstatus(EXIT_FAILURE); - goto done; - } - } - else { - error_msg("file names missing\n"); - usage(h5tools_getprogname()); - h5tools_setstatus(EXIT_FAILURE); - goto done; - } - } - - /* pack it */ + /* Disable error reporting */ + H5Eget_auto2(H5E_DEFAULT, &func, &edata); + H5Eset_auto2(H5E_DEFAULT, NULL, NULL); + + /* Initialize h5tools lib */ + h5tools_init(); + + /* Disable tools error reporting */ + H5Eget_auto2(H5tools_ERR_STACK_g, &tools_func, &tools_edata); + H5Eset_auto2(H5tools_ERR_STACK_g, NULL, NULL); + + /* update hyperslab buffer size from H5TOOLS_BUFSIZE env if exist */ + if (h5tools_getenv_update_hyperslab_bufsize() < 0) { + h5tools_setstatus(EXIT_FAILURE); + goto done; + } + + /* initialize options */ + h5repack_init(&options, 0); + + if (parse_command_line(argc, argv, &options) < 0) + goto done; + + /* get file names if they were not yet got */ + if (has_i_o == 0) { + + if (argv[opt_ind] != NULL && argv[opt_ind + 1] != NULL) { + infile = argv[opt_ind]; + outfile = argv[opt_ind + 1]; + + if ( HDstrcmp( infile, outfile ) == 0) { + error_msg("file names cannot be the same\n"); + usage(h5tools_getprogname()); + h5tools_setstatus(EXIT_FAILURE); + goto done; + } + } + else { + error_msg("file names missing\n"); + usage(h5tools_getprogname()); + h5tools_setstatus(EXIT_FAILURE); + goto done; + } + } + + if (enable_error_stack) { + H5Eset_auto2(H5E_DEFAULT, func, edata); + H5Eset_auto2(H5tools_ERR_STACK_g, tools_func, tools_edata); + } + + /* pack it */ h5tools_setstatus(h5repack(infile, outfile, &options)); done: diff --git a/tools/h5repack/h5repack_opttable.c b/tools/h5repack/h5repack_opttable.c index b54e887..dd0a0e9 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; + int 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; + int 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/h5repack_refs.c b/tools/h5repack/h5repack_refs.c index 2b39249..fbaeada 100644 --- a/tools/h5repack/h5repack_refs.c +++ b/tools/h5repack/h5repack_refs.c @@ -1,4 +1,3 @@ - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright by The HDF Group. * * Copyright by the Board of Trustees of the University of Illinois. * @@ -50,6 +49,7 @@ int do_copy_refobjs(hid_t fidin, trav_table_t *travt, pack_opt_t *options) /* repack options */ { + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ hid_t grp_in = (-1); /* read group ID */ hid_t grp_out = (-1); /* write group ID */ hid_t dset_in = (-1); /* read dataset ID */ @@ -85,18 +85,18 @@ int do_copy_refobjs(hid_t fidin, *------------------------------------------------------------------------- */ if((grp_out = H5Gopen2(fidout, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed"); if((grp_in = H5Gopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed"); if(copy_refs_attr(grp_in, grp_out, options, travt, fidout) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_refs_attr failed"); if(H5Gclose(grp_out) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed"); if(H5Gclose(grp_in) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed"); /*------------------------------------------------------------------------- * check for hard links @@ -113,26 +113,26 @@ int do_copy_refobjs(hid_t fidin, */ case H5TRAV_TYPE_DATASET: if((dset_in = H5Dopen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); if((space_id = H5Dget_space(dset_in)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); if((ftype_id = H5Dget_type(dset_in)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_type failed"); if((dcpl_id = H5Dget_create_plist(dset_in)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed"); if((rank = H5Sget_simple_extent_ndims(space_id)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); if(H5Sget_simple_extent_dims(space_id, dims, NULL) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); nelmts = 1; for(k = 0; k < rank; k++) nelmts *= dims[k]; if((mtype_id = h5tools_get_native_type(ftype_id)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "h5tools_get_native_type failed"); if((msize = H5Tget_size(mtype_id)) == 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); /*------------------------------------------------------------------------- * check if the dataset creation property list has filters that @@ -168,15 +168,15 @@ int do_copy_refobjs(hid_t fidin, buf = (hobj_ref_t *)HDmalloc((unsigned)(nelmts * msize)); if(buf==NULL) { printf("cannot read into memory\n" ); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Dread(dset_in, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed"); refbuf = (hobj_ref_t*) HDcalloc((unsigned)nelmts, msize); if(refbuf == NULL){ printf("cannot allocate memory\n" ); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed"); } /* end if */ for(u = 0; u < nelmts; u++) { H5E_BEGIN_TRY { @@ -190,7 +190,7 @@ int do_copy_refobjs(hid_t fidin, if((refname = MapIdToName(refobj_id, travt)) != NULL) { /* create the reference, -1 parameter for objects */ if(H5Rcreate(&refbuf[u], fidout, refname, H5R_OBJECT, (hid_t)-1) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rcreate failed"); if(options->verbose) { printf(FORMAT_OBJ,"dset",travt->objs[i].name ); @@ -208,10 +208,10 @@ int do_copy_refobjs(hid_t fidin, *------------------------------------------------------------------------- */ if((dset_out = H5Dcreate2(fidout, travt->objs[i].name, mtype_id, space_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dcreate2 failed"); if(nelmts) if(H5Dwrite(dset_out, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, refbuf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dwrite failed"); if(buf) HDfree(buf); @@ -222,7 +222,7 @@ int do_copy_refobjs(hid_t fidin, * copy attrs *----------------------------------------------------*/ if(copy_attr(dset_in, dset_out, &named_dt_head, travt, options) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_attr failed"); } /*H5T_STD_REF_OBJ*/ /*------------------------------------------------------------------------- @@ -245,10 +245,10 @@ int do_copy_refobjs(hid_t fidin, buf = (hdset_reg_ref_t *)HDmalloc((unsigned)(nelmts * msize)); if(buf == NULL) { printf("cannot read into memory\n"); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Dread(dset_in, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed"); /*------------------------------------------------------------------------- * create output @@ -257,7 +257,7 @@ int do_copy_refobjs(hid_t fidin, refbuf = (hdset_reg_ref_t *)HDcalloc(sizeof(hdset_reg_ref_t), (size_t)nelmts); /*init to zero */ if(refbuf == NULL) { printf("cannot allocate memory\n"); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed"); } /* end if */ for(u = 0; u < nelmts; u++) { @@ -273,18 +273,15 @@ int do_copy_refobjs(hid_t fidin, hid_t region_id; /* region id of the referenced dataset */ if((region_id = H5Rget_region(dset_in, H5R_DATASET_REGION, &buf[u])) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rget_region failed"); /* create the reference, we need the space_id */ if(H5Rcreate(&refbuf[u], fidout, refname, H5R_DATASET_REGION, region_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rcreate failed"); if(H5Sclose(region_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if(options->verbose) { - - - printf(FORMAT_OBJ,"dset",travt->objs[i].name ); printf("object <%s> region reference created to <%s>\n", travt->objs[i].name, @@ -300,10 +297,10 @@ int do_copy_refobjs(hid_t fidin, *------------------------------------------------------------------------- */ if((dset_out = H5Dcreate2(fidout, travt->objs[i].name, mtype_id, space_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dcreate2 failed"); if(nelmts) if(H5Dwrite(dset_out, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, refbuf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dwrite failed"); if(buf) HDfree(buf); @@ -314,7 +311,7 @@ int do_copy_refobjs(hid_t fidin, * copy attrs *----------------------------------------------------*/ if(copy_attr(dset_in, dset_out, &named_dt_head, travt, options) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_attr failed"); } /* H5T_STD_REF_DSETREG */ /*------------------------------------------------------------------------- * not references, open previously created object in 1st traversal @@ -322,7 +319,7 @@ int do_copy_refobjs(hid_t fidin, */ else { if((dset_out = H5Dopen2(fidout, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); } /* end else */ HDassert(dset_out != FAIL); @@ -332,7 +329,7 @@ int do_copy_refobjs(hid_t fidin, *------------------------------------------------------------------------- */ if(copy_refs_attr(dset_in, dset_out, options, travt, fidout) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "copy_refs_attr failed"); /*------------------------------------------------------------------------- * check for hard links @@ -343,7 +340,7 @@ int do_copy_refobjs(hid_t fidin, H5Lcreate_hard(fidout, travt->objs[i].name, H5L_SAME_LOC, travt->objs[i].links[j].new_name, H5P_DEFAULT, H5P_DEFAULT); if(H5Dclose(dset_out) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); } /*can_read*/ /*------------------------------------------------------------------------- @@ -351,15 +348,15 @@ int do_copy_refobjs(hid_t fidin, *------------------------------------------------------------------------- */ if(H5Tclose(ftype_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); if(H5Tclose(mtype_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); if(H5Pclose(dcpl_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); if(H5Sclose(space_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if(H5Dclose(dset_in) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); break; /*------------------------------------------------------------------------- @@ -368,9 +365,9 @@ int do_copy_refobjs(hid_t fidin, */ case H5TRAV_TYPE_NAMED_DATATYPE: if((type_in = H5Topen2(fidin, travt->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Topen2 failed"); if(H5Tclose(type_in) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); break; /*------------------------------------------------------------------------- @@ -383,7 +380,7 @@ int do_copy_refobjs(hid_t fidin, case H5TRAV_TYPE_UNKNOWN: case H5TRAV_TYPE_UDLINK: - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5TRAV invalid type"); default: break; @@ -396,9 +393,9 @@ int do_copy_refobjs(hid_t fidin, */ named_datatype_free(&named_dt_head, 0); - return 0; + return ret_value; -error: +done: H5E_BEGIN_TRY { H5Gclose(grp_in); H5Gclose(grp_out); @@ -412,7 +409,7 @@ error: named_datatype_free(&named_dt_head, 0); } H5E_END_TRY; - return -1; + return ret_value; } @@ -450,6 +447,7 @@ static int copy_refs_attr(hid_t loc_in, hid_t fidout /* for saving references */ ) { + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ hid_t attr_id = -1; /* attr ID */ hid_t attr_out = -1; /* attr ID */ hid_t space_id = -1; /* space ID */ @@ -467,32 +465,32 @@ static int copy_refs_attr(hid_t loc_in, void *refbuf = NULL; void *buf = NULL; const char* refname = NULL; - int *ref_comp_index = NULL; + unsigned *ref_comp_index = NULL; size_t *ref_comp_size = NULL; int ref_comp_field_n = 0; if(H5Oget_info(loc_in, &oinfo) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Oget_info failed"); for(u = 0; u < (unsigned)oinfo.num_attrs; u++) { is_ref = is_ref_vlen = is_ref_array = is_ref_comp = 0; /* open attribute */ if((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aopen_by_idx failed"); /* get the file datatype */ if((ftype_id = H5Aget_type(attr_id)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_type failed"); type_class = H5Tget_class(ftype_id); if((mtype_id = h5tools_get_native_type(ftype_id)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "h5tools_get_native_type failed"); if((msize = H5Tget_size(mtype_id)) == 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); is_ref = (type_class == H5T_REFERENCE); @@ -516,10 +514,10 @@ static int copy_refs_attr(hid_t loc_in, int nmembers = H5Tget_nmembers(ftype_id) ; if (nmembers < 1) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed"); - ref_comp_index = (int *)HDmalloc(nmembers*sizeof (int)); - ref_comp_size = (size_t *)HDmalloc(nmembers*sizeof(ref_comp_size)); + ref_comp_index = (unsigned *)HDmalloc((size_t)nmembers*sizeof(unsigned)); + ref_comp_size = (size_t *)HDmalloc((size_t)nmembers*sizeof(ref_comp_size)); ref_comp_field_n = 0; for (i=0; i<(unsigned)nmembers; i++) { @@ -560,15 +558,15 @@ static int copy_refs_attr(hid_t loc_in, /* get name */ if(H5Aget_name(attr_id, 255, name) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_name failed"); /* get the dataspace handle */ if((space_id = H5Aget_space(attr_id)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aget_space failed"); /* get dimensions */ if((rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); /*------------------------------------------------------------------------- @@ -580,8 +578,8 @@ static int copy_refs_attr(hid_t loc_in, nelmts *= dims[j]; if (is_ref_array) { - unsigned array_rank = 0; - hsize_t array_size = 1; + unsigned array_rank = 0; + hsize_t array_size = 1; hsize_t array_dims[H5S_MAX_RANK]; hid_t base_type; @@ -589,7 +587,7 @@ static int copy_refs_attr(hid_t loc_in, msize = H5Tget_size(base_type); H5Tclose(base_type); - array_rank = H5Tget_array_ndims(mtype_id); + array_rank = (unsigned)H5Tget_array_ndims(mtype_id); H5Tget_array_dims2(mtype_id, array_dims); for(j = 0; j <array_rank; j++) array_size *= array_dims[j]; @@ -597,7 +595,7 @@ static int copy_refs_attr(hid_t loc_in, } if((attr_out = H5Acreate2(loc_out, name, ftype_id, space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Acreate2 failed"); if (nelmts>0) { /* handle object references */ @@ -605,15 +603,15 @@ static int copy_refs_attr(hid_t loc_in, buf = (hobj_ref_t *)HDmalloc((unsigned)(nelmts * msize)); if(buf == NULL) { printf("cannot read into memory\n"); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Aread(attr_id, mtype_id, buf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed"); refbuf = (hobj_ref_t *)HDcalloc((unsigned)nelmts, msize); if(refbuf == NULL) { printf("cannot allocate memory\n"); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed"); } /* end if */ for(i = 0; i < (unsigned)nelmts; i++) { @@ -629,10 +627,10 @@ static int copy_refs_attr(hid_t loc_in, if(buf == NULL) { printf( "cannot read into memory\n" ); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Aread(attr_id, mtype_id, buf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed"); /*------------------------------------------------------------------------- * create output @@ -641,7 +639,7 @@ static int copy_refs_attr(hid_t loc_in, refbuf = (hdset_reg_ref_t *)HDcalloc(sizeof(hdset_reg_ref_t), (size_t)nelmts); /*init to zero */ if(refbuf == NULL) { printf( "cannot allocate memory\n" ); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed"); } /* end if */ for(i = 0; i < (unsigned)nelmts; i++) { @@ -659,11 +657,11 @@ static int copy_refs_attr(hid_t loc_in, if(buf == NULL) { printf( "cannot read into memory\n" ); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Aread(attr_id, mtype_id, buf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed"); if (H5R_OBJ_REF_BUF_SIZE==msize) { hobj_ref_t ref_out; @@ -700,41 +698,43 @@ static int copy_refs_attr(hid_t loc_in, if(buf == NULL) { printf( "cannot read into memory\n" ); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Aread(attr_id, mtype_id, buf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aread failed"); for (i=0; i<(unsigned)nelmts; i++) { - for (j=0; j<(unsigned)ref_comp_field_n; j++) { - if (ref_comp_size[j] == H5R_OBJ_REF_BUF_SIZE) { - int idx = i*msize+H5Tget_member_offset( mtype_id, (unsigned)ref_comp_index[j]); - hobj_ref_t ref_out; - if (update_ref_value(attr_id, H5R_OBJECT, (hobj_ref_t *)(((char *)buf)+idx), fidout, &ref_out, travt)<0) - continue; - HDmemcpy(((char *)buf)+idx, &ref_out, ref_comp_size[j]); - } /* if */ - else if (ref_comp_size[j] == H5R_DSET_REG_REF_BUF_SIZE) { - int idx = i*msize+H5Tget_member_offset( mtype_id, (unsigned)ref_comp_index[j]); - hdset_reg_ref_t ref_out; - if (update_ref_value(attr_id, H5R_DATASET_REGION, (hdset_reg_ref_t *)(((char *)buf)+idx), fidout, &ref_out, travt)<0) - continue; - HDmemcpy(((char *)buf)+idx, &ref_out, ref_comp_size[j]); - } /* else if */ - } /* j */ + for (j=0; j<(unsigned)ref_comp_field_n; j++) { + if (ref_comp_size[j] == H5R_OBJ_REF_BUF_SIZE) { + size_t idx = (i * msize) + H5Tget_member_offset(mtype_id, ref_comp_index[j]); + hobj_ref_t ref_out; + + if (update_ref_value(attr_id, H5R_OBJECT, (hobj_ref_t *)(((char *)buf)+idx), fidout, &ref_out, travt)<0) + continue; + HDmemcpy(((char *)buf)+idx, &ref_out, ref_comp_size[j]); + } /* if */ + else if (ref_comp_size[j] == H5R_DSET_REG_REF_BUF_SIZE) { + size_t idx = i * msize + H5Tget_member_offset(mtype_id, ref_comp_index[j]); + hdset_reg_ref_t ref_out; + + if (update_ref_value(attr_id, H5R_DATASET_REGION, (hdset_reg_ref_t *)(((char *)buf)+idx), fidout, &ref_out, travt)<0) + continue; + HDmemcpy(((char *)buf)+idx, &ref_out, ref_comp_size[j]); + } /* else if */ + } /* j */ } /* i */ } /* else if (is_ref_comp) */ if(H5Awrite(attr_out, mtype_id, refbuf) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Awrite failed"); if (is_ref_vlen && buf) H5Dvlen_reclaim (mtype_id, space_id, H5P_DEFAULT, buf); } /* if (nelmts) */ if (refbuf == buf) - refbuf = NULL; /* set it to NULL to avoid double free since buf and refbuf are the same. */ + refbuf = NULL; /* set it to NULL to avoid double free since buf and refbuf are the same. */ if(buf) { HDfree(buf); @@ -747,39 +747,39 @@ static int copy_refs_attr(hid_t loc_in, } if (ref_comp_index) { - HDfree(ref_comp_index); - ref_comp_index = NULL; + HDfree(ref_comp_index); + ref_comp_index = NULL; } if (ref_comp_size) { - HDfree(ref_comp_size); - ref_comp_size = NULL; + HDfree(ref_comp_size); + ref_comp_size = NULL; } if(H5Aclose(attr_out) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed"); /*------------------------------------------------------------------------- * close *------------------------------------------------------------------------- */ if(H5Tclose(ftype_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); if(H5Tclose(mtype_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); if(H5Sclose(space_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if(H5Aclose(attr_id) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Aclose failed"); } /* for(u = 0; u < (unsigned)oinfo.num_attrs; u++) */ - return 0; + return ret_value; -error: - if(refbuf) - HDfree(refbuf); - if(buf) - HDfree(buf); +done: + if(refbuf) + HDfree(refbuf); + if(buf) + HDfree(buf); if (ref_comp_index) HDfree(ref_comp_index); @@ -795,7 +795,7 @@ error: H5Aclose(attr_out); } H5E_END_TRY; - return -1; + return ret_value; } /*------------------------------------------------------------------------- @@ -845,30 +845,26 @@ out: static herr_t update_ref_value(hid_t obj_id, H5R_type_t ref_type, void *ref_in, hid_t fid_out, void *ref_out, trav_table_t *travt) { - herr_t ret = -1; - const char* ref_obj_name; - hid_t space_id=-1, ref_obj_id=-1; + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ + const char* ref_obj_name; + hid_t space_id=-1, ref_obj_id=-1; ref_obj_id = H5Rdereference(obj_id, ref_type, ref_in); - if (ref_obj_id<0) - goto done; - - ref_obj_name = MapIdToName(ref_obj_id, travt); - if (ref_obj_name == NULL) - goto done; - - if (ref_type == H5R_DATASET_REGION) { - space_id = H5Rget_region(obj_id, H5R_DATASET_REGION, ref_in); - if (space_id < 0) - goto done; - } + if (ref_obj_id < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rdereference2 failed"); - ret = H5Rcreate(ref_out, fid_out, ref_obj_name, ref_type, space_id); + ref_obj_name = MapIdToName(ref_obj_id, travt); + if (ref_obj_name == NULL) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "MapIdToName failed"); - if (ret < 0) - goto done; + if (ref_type == H5R_DATASET_REGION) { + space_id = H5Rget_region(obj_id, H5R_DATASET_REGION, ref_in); + if (space_id < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rget_region failed"); + } - ret = 0; + if(H5Rcreate(ref_out, fid_out, ref_obj_name, ref_type, space_id) < 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rcreate failed"); done: H5E_BEGIN_TRY { @@ -876,6 +872,6 @@ done: H5Oclose(ref_obj_id); } H5E_END_TRY; - return ret; + return ret_value; } diff --git a/tools/h5repack/h5repack_verify.c b/tools/h5repack/h5repack_verify.c index cec9c86..60962aa 100644 --- a/tools/h5repack/h5repack_verify.c +++ b/tools/h5repack/h5repack_verify.c @@ -51,11 +51,12 @@ static int verify_filters(hid_t pid, hid_t tid, int nfilters, filter_info_t *fil int h5repack_verify(const char *out_fname, pack_opt_t *options) { - hid_t fidout; /* file ID for output file*/ - hid_t did; /* dataset ID */ - hid_t pid; /* dataset creation property list ID */ - hid_t sid; /* space ID */ - hid_t tid; /* type ID */ + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ + hid_t fidout = -1; /* file ID for output file*/ + hid_t did = -1; /* dataset ID */ + hid_t pid = -1; /* dataset creation property list ID */ + hid_t sid = -1; /* space ID */ + hid_t tid = -1; /* type ID */ unsigned int i; trav_table_t *travt = NULL; int ok = 1; @@ -74,20 +75,20 @@ h5repack_verify(const char *out_fname, pack_opt_t *options) *------------------------------------------------------------------------- */ if((did = H5Dopen2(fidout, name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); if((sid = H5Dget_space(did)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); if((pid = H5Dget_create_plist(did)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed"); if((tid = H5Dget_type(did)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_type failed"); /*------------------------------------------------------------------------- * filter check *------------------------------------------------------------------------- */ if(verify_filters(pid, tid, obj->nfilters, obj->filter) <= 0) - ok = 0; + ok = 0; /*------------------------------------------------------------------------- @@ -102,13 +103,13 @@ h5repack_verify(const char *out_fname, pack_opt_t *options) *------------------------------------------------------------------------- */ if(H5Pclose(pid) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); if (H5Sclose(sid) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if (H5Dclose(did) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); if (H5Tclose(tid) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); } @@ -126,7 +127,7 @@ h5repack_verify(const char *out_fname, pack_opt_t *options) /* get the list of objects in the file */ if(h5trav_gettable(fidout, travt) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "h5trav_gettable failed"); for(i = 0; i < travt->nobjs; i++) { @@ -140,13 +141,13 @@ h5repack_verify(const char *out_fname, pack_opt_t *options) *------------------------------------------------------------------------- */ if((did = H5Dopen2(fidout, name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); if((sid = H5Dget_space(did)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); if((pid = H5Dget_create_plist(did)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed"); if((tid = H5Dget_type(did)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_type failed"); /*------------------------------------------------------------------------- * filter check @@ -154,7 +155,6 @@ h5repack_verify(const char *out_fname, pack_opt_t *options) */ if(options->all_filter == 1) { - if(verify_filters(pid, tid, options->n_filter_g, options->filter_g) <= 0) ok = 0; } @@ -166,6 +166,7 @@ h5repack_verify(const char *out_fname, pack_opt_t *options) if(options->all_layout == 1) { pack_info_t pack; + init_packobject(&pack); pack.layout = options->layout_g; pack.chunk = options->chunk_g; @@ -179,13 +180,13 @@ h5repack_verify(const char *out_fname, pack_opt_t *options) *------------------------------------------------------------------------- */ if (H5Pclose(pid) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); if (H5Sclose(sid) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if (H5Dclose(did) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); if (H5Tclose(tid) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tclose failed"); } /* if */ } /* i */ @@ -200,11 +201,11 @@ h5repack_verify(const char *out_fname, pack_opt_t *options) */ if (H5Fclose(fidout) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Fclose failed"); return ok; -error: +done: H5E_BEGIN_TRY { H5Pclose(pid); H5Sclose(sid); @@ -213,7 +214,8 @@ error: if (travt) trav_table_free(travt); } H5E_END_TRY; - return -1; + + return ret_value; } /* h5repack_verify() */ @@ -291,6 +293,7 @@ int verify_layout(hid_t pid, int h5repack_cmp_pl(const char *fname1, const char *fname2) { + int ret_value = 0; /*no need to LEAVE() on ERROR: HERR_INIT(int, SUCCEED) */ hid_t fid1=-1; /* file ID */ hid_t fid2=-1; /* file ID */ hid_t dset1=-1; /* dataset ID */ @@ -315,12 +318,12 @@ int h5repack_cmp_pl(const char *fname1, { /* Open the files */ - if ((fid1=H5Fopen(fname1,H5F_ACC_RDONLY,H5P_DEFAULT)) < 0 ) + if ((fid1 = H5Fopen(fname1,H5F_ACC_RDONLY,H5P_DEFAULT)) < 0 ) { error_msg("<%s>: %s\n", fname1, H5FOPENERROR ); return -1; } - if ((fid2=H5Fopen(fname2,H5F_ACC_RDONLY,H5P_DEFAULT)) < 0 ) + if ((fid2 = H5Fopen(fname2,H5F_ACC_RDONLY,H5P_DEFAULT)) < 0 ) { error_msg("<%s>: %s\n", fname2, H5FOPENERROR ); H5Fclose(fid1); @@ -335,7 +338,7 @@ int h5repack_cmp_pl(const char *fname1, */ trav_table_init(&trav); if(h5trav_gettable(fid1, trav) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "h5trav_gettable failed"); /*------------------------------------------------------------------------- * traverse the suppplied object list @@ -348,31 +351,30 @@ int h5repack_cmp_pl(const char *fname1, { if ((gid = H5Gopen2(fid1, trav->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed"); if ((gcplid = H5Gget_create_plist(gid)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gget_create_plist failed"); if (H5Pget_link_creation_order(gcplid, &crt_order_flag1) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pget_link_creation_order failed"); if (H5Pclose(gcplid) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); if (H5Gclose(gid) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed"); if ((gid = H5Gopen2(fid2, trav->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gopen2 failed"); if ((gcplid = H5Gget_create_plist(gid)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gget_create_plist failed"); if (H5Pget_link_creation_order(gcplid, &crt_order_flag2) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pget_link_creation_order failed"); if (H5Pclose(gcplid) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); if (H5Gclose(gid) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Gclose failed"); - if ( crt_order_flag1 != crt_order_flag2 ) - { + if (crt_order_flag1 != crt_order_flag2) { error_msg("property lists for <%s> are different\n",trav->objs[i].name); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "property lists failed"); } } @@ -382,25 +384,24 @@ int h5repack_cmp_pl(const char *fname1, else if(trav->objs[i].type == H5TRAV_TYPE_DATASET) { if((dset1 = H5Dopen2(fid1, trav->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); if((dset2 = H5Dopen2(fid2, trav->objs[i].name, H5P_DEFAULT)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dopen2 failed"); if((dcpl1 = H5Dget_create_plist(dset1)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed"); if((dcpl2 = H5Dget_create_plist(dset2)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_create_plist failed"); /*------------------------------------------------------------------------- * compare the property lists *------------------------------------------------------------------------- */ if((ret = H5Pequal(dcpl1, dcpl2)) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pequal failed"); - if(ret == 0) - { + if(ret == 0) { error_msg("property lists for <%s> are different\n",trav->objs[i].name); - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "property lists failed"); } /*------------------------------------------------------------------------- @@ -408,13 +409,13 @@ int h5repack_cmp_pl(const char *fname1, *------------------------------------------------------------------------- */ if(H5Pclose(dcpl1) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); if(H5Pclose(dcpl2) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Pclose failed"); if(H5Dclose(dset1) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); if(H5Dclose(dset2) < 0) - goto error; + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dclose failed"); } /*if*/ } /*i*/ @@ -432,14 +433,14 @@ int h5repack_cmp_pl(const char *fname1, H5Fclose(fid1); H5Fclose(fid2); - return ret; - /*------------------------------------------------------------------------- - * error - *------------------------------------------------------------------------- - */ + return ret; -error: +/*------------------------------------------------------------------------- +* error +*------------------------------------------------------------------------- +*/ +done: H5E_BEGIN_TRY { H5Pclose(dcpl1); @@ -452,8 +453,8 @@ error: H5Gclose(gid); trav_table_free(trav); } H5E_END_TRY; - return -1; + return ret_value; } @@ -522,100 +523,71 @@ int verify_filters(hid_t pid, hid_t tid, int nfilters, filter_info_t *filter) switch (filtn) { - case H5Z_FILTER_NONE: - break; - - case H5Z_FILTER_SHUFFLE: - - /* 1 private client value is returned by DCPL */ - if ( cd_nelmts != H5Z_SHUFFLE_TOTAL_NPARMS && filter[i].cd_nelmts != H5Z_SHUFFLE_USER_NPARMS ) - return 0; - - /* get dataset's type size */ - if((size = H5Tget_size(tid)) <= 0) - return -1; - - /* the private client value holds the dataset's type size */ - if ( size != cd_values[0] ) - return 0; - - + case H5Z_FILTER_NONE: break; - case H5Z_FILTER_SZIP: - - /* 4 private client values are returned by DCPL */ - if ( cd_nelmts != H5Z_SZIP_TOTAL_NPARMS && filter[i].cd_nelmts != H5Z_SZIP_USER_NPARMS ) - return 0; - - /* "User" parameter for pixels-per-block (index 1) */ - if ( cd_values[H5Z_SZIP_PARM_PPB] != filter[i].cd_values[H5Z_SZIP_PARM_PPB] ) - return 0; - - - break; - - case H5Z_FILTER_NBIT: - - /* only client data values number of values checked */ - if ( H5Z_NBIT_USER_NPARMS != filter[i].cd_nelmts) - return 0; - - - - break; + case H5Z_FILTER_SHUFFLE: + /* 1 private client value is returned by DCPL */ + if ( cd_nelmts != H5Z_SHUFFLE_TOTAL_NPARMS && filter[i].cd_nelmts != H5Z_SHUFFLE_USER_NPARMS ) + return 0; - case H5Z_FILTER_SCALEOFFSET: + /* get dataset's type size */ + if((size = H5Tget_size(tid)) <= 0) + return -1; - /* only client data values checked */ - for( j = 0; j < H5Z_SCALEOFFSET_USER_NPARMS; j++) - { - if (cd_values[j] != filter[i].cd_values[j]) - { + /* the private client value holds the dataset's type size */ + if ( size != cd_values[0] ) return 0; - } - - } + break; - break; + case H5Z_FILTER_SZIP: + /* 4 private client values are returned by DCPL */ + if ( cd_nelmts != H5Z_SZIP_TOTAL_NPARMS && filter[i].cd_nelmts != H5Z_SZIP_USER_NPARMS ) + return 0; - /* for these filters values must match, no local values set in DCPL */ - case H5Z_FILTER_FLETCHER32: - case H5Z_FILTER_DEFLATE: + /* "User" parameter for pixels-per-block (index 1) */ + if ( cd_values[H5Z_SZIP_PARM_PPB] != filter[i].cd_values[H5Z_SZIP_PARM_PPB] ) + return 0; - if ( cd_nelmts != filter[i].cd_nelmts) - return 0; + break; - for( j = 0; j < cd_nelmts; j++) - { - if (cd_values[j] != filter[i].cd_values[j]) - { + case H5Z_FILTER_NBIT: + /* only client data values number of values checked */ + if ( H5Z_NBIT_USER_NPARMS != filter[i].cd_nelmts) return 0; - } + break; - } + case H5Z_FILTER_SCALEOFFSET: + /* only client data values checked */ + for( j = 0; j < H5Z_SCALEOFFSET_USER_NPARMS; j++) + if (cd_values[j] != filter[i].cd_values[j]) + return 0; + break; + /* for these filters values must match, no local values set in DCPL */ + case H5Z_FILTER_FLETCHER32: + case H5Z_FILTER_DEFLATE: + if ( cd_nelmts != filter[i].cd_nelmts) + return 0; - break; + for( j = 0; j < cd_nelmts; j++) + if (cd_values[j] != filter[i].cd_values[j]) + return 0; - default: - if ( cd_nelmts != filter[i].cd_nelmts) - return 0; + break; - for( j = 0; j < cd_nelmts; j++) - { - if (cd_values[j] != filter[i].cd_values[j]) - { - return 0; - } + default: + if ( cd_nelmts != filter[i].cd_nelmts) + return 0; - } - break; + for( j = 0; j < cd_nelmts; j++) + if (cd_values[j] != filter[i].cd_values[j]) + return 0; + break; } /* switch */ - } return 1; diff --git a/tools/h5repack/h5repacktst.c b/tools/h5repack/h5repacktst.c index f49e587..0d43576 100644 --- a/tools/h5repack/h5repacktst.c +++ b/tools/h5repack/h5repacktst.c @@ -1545,6 +1545,8 @@ int main (void) puts("All h5repack tests passed."); + h5tools_close(); + return 0; error: @@ -3361,7 +3363,7 @@ make_userblock(void) /* Initialize userblock data */ for(u = 0; u < USERBLOCK_SIZE; u++) - ub[u] = 'a' + (char)(u % 26); + ub[u] = (char)('a' + (char)(u % 26)); /* Re-open HDF5 file, as "plain" file */ if((fd = HDopen(FNAME16, O_WRONLY, 0644)) < 0) @@ -3474,7 +3476,7 @@ make_userblock_file(void) /* initialize userblock data */ for(u = 0; u < USERBLOCK_SIZE; u++) - ub[u] = 'a' + (char)(u % 26); + ub[u] = (char)('a' + (char)(u % 26)); /* open file */ if((fd = HDopen(FNAME_UB,O_WRONLY|O_CREAT|O_TRUNC, 0644 )) < 0) @@ -3531,7 +3533,8 @@ int write_dset_in(hid_t loc_id, hid_t sid=-1; hid_t tid=-1; hid_t pid=-1; - int val, i, j, k, n; + unsigned i, j; + int val, k, n; float f; /* create 1D attributes with dimension [2], 2 elements */ @@ -3586,13 +3589,10 @@ int write_dset_in(hid_t loc_id, */ - if (make_diffs) - { - for (i=0; i<2; i++) - for (j=0; j<2; j++) - { - buf1[i][j]='z'; - } + if(make_diffs) { + for(i = 0; i < 2; i++) + for(j = 0; j < 2; j++) + buf1[i][j] = 'z'; } @@ -3615,10 +3615,9 @@ int write_dset_in(hid_t loc_id, *------------------------------------------------------------------------- */ - if (make_diffs) - { - for (i=0; i<2; i++) - buf2[i]=buf2[1]=0; + if(make_diffs) { + for(i = 0; i < 2; i++) + buf2[i] = buf2[1] = 0; } if ((tid = H5Tcopy(H5T_STD_B8LE)) < 0) @@ -3633,11 +3632,10 @@ int write_dset_in(hid_t loc_id, *------------------------------------------------------------------------- */ - if (make_diffs) - { - for (i=0; i<2; i++) - { - buf3[i].a=0; buf3[i].b=0; + if(make_diffs) { + for(i = 0; i < 2; i++) { + buf3[i].a = 0; + buf3[i].b = 0; } } @@ -3656,12 +3654,9 @@ int write_dset_in(hid_t loc_id, */ - if (make_diffs) - { - for (i=0; i<2; i++) - { - buf45[i]=GREEN; - } + if(make_diffs) { + for(i = 0; i < 2; i++) + buf45[i] = GREEN; } if ((tid = H5Tcreate (H5T_COMPOUND, sizeof(s_t))) < 0) @@ -3753,13 +3748,10 @@ int write_dset_in(hid_t loc_id, *------------------------------------------------------------------------- */ - if (make_diffs) - { - for (i=0; i<2; i++) - for (j=0; j<3; j++) - { - buf6[i][j]=0; - } + if(make_diffs) { + for(i = 0; i < 2; i++) + for(j = 0; j < 3; j++) + buf6[i][j] = 0; } if ((tid = H5Tarray_create2(H5T_NATIVE_INT, 1, dimarray)) < 0) @@ -3820,12 +3812,10 @@ int write_dset_in(hid_t loc_id, *------------------------------------------------------------------------- */ - if (make_diffs) - { - for (i=0; i<2; i++) - { - buf7[i]=0; - buf8[i]=0; + if(make_diffs) { + for(i = 0; i < 2; i++) { + buf7[i] = 0; + buf8[i] = 0; } } @@ -3948,16 +3938,13 @@ int write_dset_in(hid_t loc_id, /* Allocate and initialize VL dataset to write */ n = 0; - for(i = 0; i < 3; i++) - { - for(j = 0; j < 2; j++) - { - int l; + for(i = 0; i < 3; i++) { + for(j = 0; j < 2; j++) { + unsigned l; buf52[i][j].p = HDmalloc((i + 1) * sizeof(int)); buf52[i][j].len = (size_t)(i + 1); - for(l = 0; l < i + 1; l++) - { + for(l = 0; l < i + 1; l++) { if(make_diffs) ((int *)buf52[i][j].p)[l] = 0; else @@ -4068,11 +4055,13 @@ int write_dset_in(hid_t loc_id, n=1; - for (i = 0; i < 4; i++) { - for (j = 0; j < 3; j++) { - for (k = 0; k < 2; k++) { - if (make_diffs) buf23[i][j][k]=0; - else buf23[i][j][k]=n++; + for(i = 0; i < 4; i++) { + for(j = 0; j < 3; j++) { + for(k = 0; k < 2; k++) { + if(make_diffs) + buf23[i][j][k] = 0; + else + buf23[i][j][k] = (char)(n++); } } } @@ -4104,16 +4093,16 @@ int write_dset_in(hid_t loc_id, */ n=1; - for (i = 0; i < 4; i++) { - for (j = 0; j < 3; j++) { - for (k = 0; k < 2; k++) { - if (make_diffs) { - buf33[i][j][k].a=0; - buf33[i][j][k].b=0; + for(i = 0; i < 4; i++) { + for(j = 0; j < 3; j++) { + for(k = 0; k < 2; k++) { + if(make_diffs) { + buf33[i][j][k].a = 0; + buf33[i][j][k].b = 0; } else { - buf33[i][j][k].a=n++; - buf33[i][j][k].b=n++; + buf33[i][j][k].a = (char)(n++); + buf33[i][j][k].b = n++; } } } @@ -4167,18 +4156,14 @@ int write_dset_in(hid_t loc_id, /* Allocate and initialize VL dataset to write */ n = 0; - for(i = 0; i < 4; i++) - { - for(j = 0; j < 3; j++) - { - for(k = 0; k < 2; k++) - { - int l; + for(i = 0; i < 4; i++) { + for(j = 0; j < 3; j++) { + for(k = 0; k < 2; k++) { + unsigned l; buf53[i][j][k].p = HDmalloc((i + 1) * sizeof(int)); buf53[i][j][k].len = (size_t)(i + 1); - for(l = 0; l < i + 1; l++) - { + for(l = 0; l < i + 1; l++) { if(make_diffs) ((int *)buf53[i][j][k].p)[l] = 0; else @@ -4214,10 +4199,8 @@ int write_dset_in(hid_t loc_id, n = 1; - for(i = 0; i < 24; i++) - { - for(j = 0; j < (int)dimarray[0]; j++) - { + for(i = 0; i < 24; i++) { + for(j = 0; j < dimarray[0]; j++) { if(make_diffs) buf63[i][j] = 0; else @@ -4256,13 +4239,10 @@ int write_dset_in(hid_t loc_id, if (write_dset(loc_id,3,dims3,"float3D",H5T_NATIVE_FLOAT,buf83) < 0) goto out; - return 0; - out: - H5E_BEGIN_TRY - { + H5E_BEGIN_TRY { H5Pclose(pid); H5Sclose(sid); H5Dclose(did); @@ -4411,7 +4391,8 @@ int write_attr_in(hid_t loc_id, hid_t aid = -1; hid_t sid = -1; hid_t tid = -1; - int val, i, j, k, n; + int val, j, k, n; + unsigned i; float f; /* create 1D attributes with dimension [2], 2 elements */ @@ -4961,16 +4942,17 @@ int write_attr_in(hid_t loc_id, /* Allocate and initialize VL dataset to write */ n=0; - for (i = 0; i < 3; i++) - { - for (j = 0; j < 2; j++) - { - int l; + for(i = 0; i < 3; i++) { + for(j = 0; j < 2; j++) { + unsigned l; + buf52[i][j].p = HDmalloc((i + 1) * sizeof(int)); buf52[i][j].len = (size_t)(i + 1); - for (l = 0; l < i + 1; l++) - if (make_diffs)((int *)buf52[i][j].p)[l] = 0; - else ((int *)buf52[i][j].p)[l] = n++; + for(l = 0; l < i + 1; l++) + if(make_diffs) + ((int *)buf52[i][j].p)[l] = 0; + else + ((int *)buf52[i][j].p)[l] = n++; } } @@ -5179,14 +5161,13 @@ int write_attr_in(hid_t loc_id, */ n=1; - for (i = 0; i < 4; i++) - { - for (j = 0; j < 3; j++) - { - for (k = 0; k < 2; k++) - { - if (make_diffs) buf23[i][j][k]=0; - else buf23[i][j][k]=n++; + for(i = 0; i < 4; i++) { + for(j = 0; j < 3; j++) { + for(k = 0; k < 2; k++) { + if(make_diffs) + buf23[i][j][k] = 0; + else + buf23[i][j][k] = (char)(n++); } } } @@ -5248,21 +5229,16 @@ int write_attr_in(hid_t loc_id, */ n=1; - for (i = 0; i < 4; i++) - { - for (j = 0; j < 3; j++) - { - for (k = 0; k < 2; k++) - { - if (make_diffs) - { - buf33[i][j][k].a=0; - buf33[i][j][k].b=0; + for(i = 0; i < 4; i++) { + for(j = 0; j < 3; j++) { + for(k = 0; k < 2; k++) { + if(make_diffs) { + buf33[i][j][k].a = 0; + buf33[i][j][k].b = 0; } - else - { - buf33[i][j][k].a=n++; - buf33[i][j][k].b=n++; + else { + buf33[i][j][k].a = (char)(n++); + buf33[i][j][k].b = n++; } } } @@ -5431,14 +5407,13 @@ int write_attr_in(hid_t loc_id, { for (k = 0; k < 2; k++) { - int l; + unsigned l; + buf53[i][j][k].p = HDmalloc((i + 1) * sizeof(int)); buf53[i][j][k].len = (size_t)i + 1; for (l = 0; l < i + 1; l++) if (make_diffs) - { ((int *)buf53[i][j][k].p)[l] = 0; - } else ((int *)buf53[i][j][k].p)[l] = n++; } @@ -5562,8 +5537,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-help.txt b/tools/h5repack/testfiles/h5repack-help.txt index ba58bc6..5c30ce8 100644 --- a/tools/h5repack/testfiles/h5repack-help.txt +++ b/tools/h5repack/testfiles/h5repack-help.txt @@ -31,6 +31,9 @@ usage: h5repack [OPTIONS] file1 file2 F - is the shared object header message type, any of <dspace|dtype|fill| pline|attr>. If F is not specified, S applies to all messages + --enable-error-stack Prints messages from the HDF5 error stack as they + occur. + FILT - is a string with the format: <list of objects>:<name of filter>=<filter parameters> diff --git a/tools/h5repack/testfiles/h5repack_filters.h5-gzip_verbose_filters.tst b/tools/h5repack/testfiles/h5repack_filters.h5-gzip_verbose_filters.tst new file mode 100644 index 0000000..36e65b9 --- /dev/null +++ b/tools/h5repack/testfiles/h5repack_filters.h5-gzip_verbose_filters.tst @@ -0,0 +1,13 @@ +Objects to modify layout are... +Objects to apply filter are... + </dset_deflate> with GZIP filter + </dset_deflate>...Found +----------------------------------------- + Type Filter (Compression) Name +----------------------------------------- + group / + dset /dset_all + dset GZIP (0.995:1) /dset_deflate + dset /dset_fletcher32 + dset /dset_nbit + dset /dset_shuffle 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 diff --git a/tools/lib/h5diff_util.c b/tools/lib/h5diff_util.c index aefd641..ab3e1ce 100644 --- a/tools/lib/h5diff_util.c +++ b/tools/lib/h5diff_util.c @@ -78,8 +78,6 @@ void print_type(hid_t type) { switch (H5Tget_class(type)) { - default: - return; case H5T_INTEGER: if (H5Tequal(type, H5T_STD_I8BE)) { parallel_print("H5T_STD_I8BE"); @@ -160,7 +158,21 @@ void print_type(hid_t type) } break; - }/*switch*/ + case H5T_TIME: + case H5T_STRING: + case H5T_BITFIELD: + case H5T_OPAQUE: + case H5T_COMPOUND: + case H5T_REFERENCE: + case H5T_ENUM: + case H5T_VLEN: + case H5T_ARRAY: + case H5T_NO_CLASS: + case H5T_NCLASSES: + default: + return; + + } /* end switch */ } /*------------------------------------------------------------------------- @@ -179,16 +191,16 @@ diff_basename(const char *name) { size_t i; - if (name==NULL) + if (name == NULL) return NULL; /* Find the end of the base name */ i = HDstrlen(name); - while (i>0 && '/'==name[i-1]) + while (i > 0 && '/' == name[i - 1]) --i; /* Skip backward over base name */ - while (i>0 && '/'!=name[i-1]) + while (i > 0 && '/' != name[i - 1]) --i; return(name+i); @@ -211,14 +223,20 @@ get_type(h5trav_type_t type) switch(type) { case H5TRAV_TYPE_DATASET: return("H5G_DATASET"); + case H5TRAV_TYPE_GROUP: return("H5G_GROUP"); + case H5TRAV_TYPE_NAMED_DATATYPE: return("H5G_TYPE"); + case H5TRAV_TYPE_LINK: return("H5G_LINK"); + case H5TRAV_TYPE_UDLINK: return("H5G_UDLINK"); + + case H5TRAV_TYPE_UNKNOWN: default: return("unknown type"); } @@ -242,13 +260,22 @@ get_sign(H5T_sign_t sign) { switch (sign) { - default: - return("H5T_SGN_ERROR"); - case H5T_SGN_NONE: - return("H5T_SGN_NONE"); - case H5T_SGN_2: - return("H5T_SGN_2"); - } + case H5T_SGN_NONE: + return "H5T_SGN_NONE"; + + case H5T_SGN_2: + return "H5T_SGN_2"; + + case H5T_SGN_ERROR: + return "H5T_SGN_ERROR"; + + case H5T_NSGN: + return "H5T_NSGN"; + + default: + HDassert(0); + return "unknown sign value"; + } /* end switch */ } @@ -266,34 +293,47 @@ get_sign(H5T_sign_t sign) const char* get_class(H5T_class_t tclass) { - switch (tclass) - { - default: - return("Invalid class"); - case H5T_TIME: - return("H5T_TIME"); - case H5T_INTEGER: - return("H5T_INTEGER"); - case H5T_FLOAT: - return("H5T_FLOAT"); - case H5T_STRING: - return("H5T_STRING"); - case H5T_BITFIELD: - return("H5T_BITFIELD"); - case H5T_OPAQUE: - return("H5T_OPAQUE"); - case H5T_COMPOUND: - return("H5T_COMPOUND"); - case H5T_REFERENCE: - return("H5T_REFERENCE"); - case H5T_ENUM: - return("H5T_ENUM"); - case H5T_VLEN: - return("H5T_VLEN"); - case H5T_ARRAY: - return("H5T_ARRAY"); - } -} + switch (tclass) { + case H5T_TIME: + return("H5T_TIME"); + + case H5T_INTEGER: + return("H5T_INTEGER"); + + case H5T_FLOAT: + return("H5T_FLOAT"); + + case H5T_STRING: + return("H5T_STRING"); + + case H5T_BITFIELD: + return("H5T_BITFIELD"); + + case H5T_OPAQUE: + return("H5T_OPAQUE"); + + case H5T_COMPOUND: + return("H5T_COMPOUND"); + + case H5T_REFERENCE: + return("H5T_REFERENCE"); + + case H5T_ENUM: + return("H5T_ENUM"); + + case H5T_VLEN: + return("H5T_VLEN"); + + case H5T_ARRAY: + return("H5T_ARRAY"); + + case H5T_NO_CLASS: + case H5T_NCLASSES: + default: + HDassert(0); + return("Invalid class"); + } /* end switch */ +} /* end get_class() */ /*------------------------------------------------------------------------- * Function: print_found @@ -304,10 +344,10 @@ get_class(H5T_class_t tclass) */ void print_found(hsize_t nfound) { - if(g_Parallel) - parallel_print("%"H5_PRINTF_LL_WIDTH"u differences found\n", (unsigned long long)nfound); - else - HDfprintf(stdout,"%Hu differences found\n",nfound); + if(g_Parallel) + parallel_print("%"H5_PRINTF_LL_WIDTH"u differences found\n", (unsigned long long)nfound); + else + HDfprintf(stdout,"%Hu differences found\n",nfound); } @@ -354,3 +394,4 @@ herr_t match_up_memsize (hid_t f_tid1_id, hid_t f_tid2_id, out: return ret; } + diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index a21dea7..f2123fb 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -47,10 +47,11 @@ int region_output; /* region output */ int oid_output; /* oid output */ int data_output; /* data output */ int attr_data_output; /* attribute data output */ -int packed_bits_num; /* number of packed bits to display */ -int packed_data_offset; /* offset of packed bits to display */ -int packed_data_length; /* lengtht of packed bits to display */ +unsigned packed_bits_num; /* number of packed bits to display */ +unsigned packed_data_offset; /* offset of packed bits to display */ +unsigned packed_data_length; /* length of packed bits to display */ unsigned long long packed_data_mask; /* mask in which packed bits to display */ +int enable_error_stack= FALSE; /* re-enable error stack */ /* module-scoped variables */ static int h5tools_init_g; /* if h5tools lib has been initialized */ @@ -805,7 +806,7 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_str_t prefix; h5tools_str_t str; /*temporary for indentation */ size_t templength = 0; - int i, indentlevel = 0; + unsigned u, indentlevel = 0; if (stream == NULL) return; @@ -827,10 +828,9 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_str_prefix(&prefix, info, elmtno, ctx->ndims, ctx); /* Write new prefix to output */ - if (ctx->indent_level >= 0) { + if (ctx->indent_level > 0) indentlevel = ctx->indent_level; - } - else { + else /* * This is because sometimes we don't print out all the header * info for the data (like the tattr-2.ddl example). If that happens @@ -838,29 +838,23 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, * just print out the default indent levels. */ indentlevel = ctx->default_indent_level; - } /* when printing array indices, print the indentation before the prefix the prefix is printed one indentation level before */ - if (info->pindex) { - for (i = 0; i < indentlevel - 1; i++) { + if (info->pindex) + for (u = 0; u < indentlevel - 1; u++) PUTSTREAM(h5tools_str_fmt(&str, (size_t)0, info->line_indent), stream); - } - } - if (elmtno == 0 && secnum == 0 && info->line_1st) { + if (elmtno == 0 && secnum == 0 && info->line_1st) PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_1st), stream); - } - else if (secnum && info->line_cont) { + else if (secnum && info->line_cont) PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_cont), stream); - } - else { + else PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_pre), stream); - } templength = h5tools_str_len(&prefix); - for (i = 0; i < indentlevel; i++) { + for (u = 0; u < indentlevel; u++) /*we already made the indent for the array indices case */ if (!info->pindex) { PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_indent), stream); @@ -870,7 +864,6 @@ h5tools_simple_prefix(FILE *stream, const h5tool_format_t *info, /*we cannot count the prefix for the array indices case */ templength += h5tools_str_len(&str); } - } ctx->cur_column = ctx->prev_prefix_len = templength; ctx->cur_elmt = 0; @@ -900,7 +893,7 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_str_t prefix; h5tools_str_t str; /*temporary for indentation */ size_t templength = 0; - int i, indentlevel = 0; + unsigned u, indentlevel = 0; if (stream == NULL) return; @@ -922,7 +915,7 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, h5tools_str_region_prefix(&prefix, info, elmtno, ptdata, ctx->ndims, ctx->p_max_idx, ctx); /* Write new prefix to output */ - if (ctx->indent_level >= 0) + if (ctx->indent_level > 0) indentlevel = ctx->indent_level; else /* @@ -936,20 +929,19 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, /* when printing array indices, print the indentation before the prefix the prefix is printed one indentation level before */ if (info->pindex) - for (i = 0; i < indentlevel - 1; i++) { + for (u = 0; u < indentlevel - 1; u++) PUTSTREAM(h5tools_str_fmt(&str, (size_t)0, info->line_indent), stream); - } - if (elmtno == 0 && secnum == 0 && info->line_1st) { + if (elmtno == 0 && secnum == 0 && info->line_1st) PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_1st), stream); - } else if (secnum && info->line_cont) { + else if (secnum && info->line_cont) PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_cont), stream); - } else + else PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_pre), stream); templength = h5tools_str_len(&prefix); - for (i = 0; i < indentlevel; i++) { + for (u = 0; u < indentlevel; u++) /*we already made the indent for the array indices case */ if (!info->pindex) { PUTSTREAM(h5tools_str_fmt(&prefix, (size_t)0, info->line_indent), stream); @@ -959,7 +951,6 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, /*we cannot count the prefix for the array indices case */ templength += h5tools_str_len(&str); } - } ctx->cur_column = ctx->prev_prefix_len = templength; ctx->cur_elmt = 0; @@ -1299,9 +1290,8 @@ init_acc_pos(h5tools_context_t *ctx, hsize_t *dims) HDassert(ctx->ndims); ctx->acc[ctx->ndims - 1] = 1; - for (i = (ctx->ndims - 2); i >= 0; i--) { + for (i = ((int)ctx->ndims - 2); i >= 0; i--) ctx->acc[i] = ctx->acc[i + 1] * dims[i + 1]; - } for (j = 0; j < ctx->ndims; j++) ctx->pos[j] = 0; } @@ -1536,18 +1526,18 @@ CATCH */ int render_bin_output_region_data_blocks(hid_t region_id, FILE *stream, - hid_t container, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata) + hid_t container, unsigned ndims, hid_t type_id, hsize_t nblocks, hsize_t *ptdata) { hsize_t *dims1 = NULL; hsize_t *start = NULL; hsize_t *count = NULL; hsize_t numelem; hsize_t total_size[H5S_MAX_RANK]; - int jndx; + unsigned jndx; size_t type_size; hid_t mem_space = -1; void *region_buf = NULL; - int blkndx; + hsize_t blkndx; hid_t sid1 = -1; int ret_value = SUCCEED; @@ -1567,7 +1557,7 @@ render_bin_output_region_data_blocks(hid_t region_id, FILE *stream, } /* Create dataspace for reading buffer */ - if((mem_space = H5Screate_simple(ndims, dims1, NULL)) < 0) + if((mem_space = H5Screate_simple((int)ndims, dims1, NULL)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed"); if((type_size = H5Tget_size(type_id)) == 0) @@ -1640,7 +1630,8 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id, hsize_t nblocks; hsize_t alloc_size; hsize_t *ptdata; - int ndims; + int sndims; + unsigned ndims; hid_t dtype = -1; hid_t type_id = -1; @@ -1649,16 +1640,16 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id, nblocks = (hsize_t)snblocks; /* Print block information */ - if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0) + if((sndims = H5Sget_simple_extent_ndims(region_space)) < 0) H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + ndims = (unsigned)sndims; alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]); HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ if((ptdata = (hsize_t*) HDmalloc((size_t) alloc_size)) == NULL) HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); - H5_CHECK_OVERFLOW(nblocks, hssize_t, hsize_t); - if(H5Sget_select_hyper_blocklist(region_space, (hsize_t) 0, (hsize_t) nblocks, ptdata) < 0) + if(H5Sget_select_hyper_blocklist(region_space, (hsize_t) 0, nblocks, ptdata) < 0) HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Rget_select_hyper_blocklist failed"); if((dtype = H5Dget_type(region_id)) < 0) @@ -1705,10 +1696,10 @@ render_bin_output_region_blocks(hid_t region_space, hid_t region_id, int render_bin_output_region_data_points(hid_t region_space, hid_t region_id, FILE *stream, hid_t container, - int ndims, hid_t type_id, hssize_t npoints) + unsigned ndims, hid_t type_id, hsize_t npoints) { hsize_t *dims1 = NULL; - int type_size; + size_t type_size; hid_t mem_space = -1; void *region_buf = NULL; int ret_value = SUCCEED; @@ -1763,17 +1754,21 @@ render_bin_output_region_points(hid_t region_space, hid_t region_id, FILE *stream, hid_t container) { HERR_INIT(hbool_t, TRUE) - hssize_t npoints; - int ndims; + hssize_t snpoints; + hsize_t npoints; + int sndims; + unsigned ndims; hid_t dtype = -1; hid_t type_id = -1; - if((npoints = H5Sget_select_elem_npoints(region_space)) <= 0) + if((snpoints = H5Sget_select_elem_npoints(region_space)) <= 0) H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_select_elem_npoints failed"); + npoints = (hsize_t)snpoints; /* Allocate space for the dimension array */ - if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0) + if((sndims = H5Sget_simple_extent_ndims(region_space)) < 0) H5E_THROW(FALSE, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + ndims = (unsigned)sndims; if((dtype = H5Dget_type(region_id)) < 0) HGOTO_ERROR(FALSE, H5E_tools_min_id_g, "H5Dget_type failed"); diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index 5c08f33..b548100 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -37,10 +37,10 @@ #define H5TOOLS_DUMP_MAX_RANK H5S_MAX_RANK /* Stream macros */ -#define FLUSHSTREAM(S) {if(S != NULL) HDfflush(S);} -#define PRINTSTREAM(S, F, ...) {if(S != NULL) HDfprintf(S, F, __VA_ARGS__);} -#define PRINTVALSTREAM(S, V) {if(S != NULL) HDfprintf(S, V);} -#define PUTSTREAM(X,S) {if(S != NULL) HDfputs(X, S);} +#define FLUSHSTREAM(S) if(S != NULL) HDfflush(S) +#define PRINTSTREAM(S, F, ...) if(S != NULL) HDfprintf(S, F, __VA_ARGS__) +#define PRINTVALSTREAM(S, V) if(S != NULL) HDfprintf(S, V) +#define PUTSTREAM(X,S) do { if(S != NULL) HDfputs(X, S); } while(0) /* * Strings for output - these were duplicated from the h5dump.h @@ -81,7 +81,7 @@ #define FLETCHER32 "CHECKSUM FLETCHER32" #define SZIP "COMPRESSION SZIP" #define NBIT "COMPRESSION NBIT" -#define SCALEOFFSET "COMPRESSION SCALEOFFSET" +#define SCALEOFFSET "COMPRESSION SCALEOFFSET" #define SCALEOFFSET_MINBIT "MIN BITS" #define STORAGE_LAYOUT "STORAGE_LAYOUT" #define CONTIGUOUS "CONTIGUOUS" @@ -275,7 +275,7 @@ typedef struct h5tool_format_t { const char *fmt_float; int ascii; int str_locale; - int str_repeat; + unsigned str_repeat; /* * Fields associated with compound array members. @@ -491,9 +491,9 @@ typedef struct h5tools_context_t { hsize_t size_last_dim; /*the size of the last dimension, *needed so we can break after each *row */ - int indent_level; /*the number of times we need some + unsigned indent_level; /*the number of times we need some *extra indentation */ - int default_indent_level; /*this is used when the indent level gets changed */ + unsigned default_indent_level; /*this is used when the indent level gets changed */ hsize_t acc[H5S_MAX_RANK]; /* accumulator position */ hsize_t pos[H5S_MAX_RANK]; /* matrix position */ hsize_t sm_pos; /* current stripmine element position */ @@ -526,9 +526,9 @@ H5TOOLS_DLLVAR const h5tools_dump_header_t* h5tools_dump_header_format; extern "C" { #endif -H5TOOLS_DLLVAR int packed_bits_num; /* number of packed bits to display */ -H5TOOLS_DLLVAR int packed_data_offset; /* offset of packed bits to display */ -H5TOOLS_DLLVAR int packed_data_length; /* lengtht of packed bits to display */ +H5TOOLS_DLLVAR unsigned packed_bits_num; /* number of packed bits to display */ +H5TOOLS_DLLVAR unsigned packed_data_offset; /* offset of packed bits to display */ +H5TOOLS_DLLVAR unsigned packed_data_length; /* length of packed bits to display */ H5TOOLS_DLLVAR unsigned long long packed_data_mask; /* mask in which packed bits to display */ H5TOOLS_DLLVAR FILE *rawattrstream; /* output stream for raw attribute data */ H5TOOLS_DLLVAR FILE *rawdatastream; /* output stream for raw data */ @@ -542,6 +542,9 @@ H5TOOLS_DLLVAR int oid_output; /* oid output */ H5TOOLS_DLLVAR int data_output; /* data output */ H5TOOLS_DLLVAR int attr_data_output; /* attribute data output */ +/* things to display or which are set via command line parameters */ +H5TOOLS_DLLVAR int enable_error_stack; /* re-enable error stack */ + /* Strings for output */ #define H5_TOOLS_GROUP "GROUP" #define H5_TOOLS_DATASET "DATASET" @@ -550,11 +553,11 @@ H5TOOLS_DLLVAR int attr_data_output; /* attribute data output */ /* Definitions of useful routines */ H5TOOLS_DLL void h5tools_init(void); H5TOOLS_DLL void h5tools_close(void); -H5TOOLS_DLL int h5tools_set_data_output_file(const char *fname, int is_bin); -H5TOOLS_DLL int h5tools_set_attr_output_file(const char *fname, int is_bin); -H5TOOLS_DLL int h5tools_set_input_file(const char *fname, int is_bin); -H5TOOLS_DLL int h5tools_set_output_file(const char *fname, int is_bin); -H5TOOLS_DLL int h5tools_set_error_file(const char *fname, int is_bin); +H5TOOLS_DLL int h5tools_set_data_output_file(const char *fname, int is_bin); +H5TOOLS_DLL int h5tools_set_attr_output_file(const char *fname, int is_bin); +H5TOOLS_DLL int h5tools_set_input_file(const char *fname, int is_bin); +H5TOOLS_DLL int h5tools_set_output_file(const char *fname, int is_bin); +H5TOOLS_DLL int h5tools_set_error_file(const char *fname, int is_bin); H5TOOLS_DLL hid_t h5tools_fopen(const char *fname, unsigned flags, hid_t fapl, const char *driver, char *drivername, size_t drivername_len); H5TOOLS_DLL hid_t h5tools_get_native_type(hid_t type); @@ -574,8 +577,12 @@ H5TOOLS_DLL void h5tools_region_simple_prefix(FILE *stream, const h5tool_form h5tools_context_t *ctx, hsize_t elmtno, hsize_t *ptdata, int secnum); H5TOOLS_DLL int render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t nelmts); +H5TOOLS_DLL int render_bin_output_region_data_blocks(hid_t region_id, FILE *stream, + hid_t container, unsigned ndims, hid_t type_id, hsize_t nblocks, hsize_t *ptdata); H5TOOLS_DLL hbool_t render_bin_output_region_blocks(hid_t region_space, hid_t region_id, FILE *stream, hid_t container); +H5TOOLS_DLL int render_bin_output_region_data_points(hid_t region_space, hid_t region_id, + FILE* stream, hid_t container, unsigned ndims, hid_t type_id, hsize_t npoints); H5TOOLS_DLL hbool_t render_bin_output_region_points(hid_t region_space, hid_t region_id, FILE *stream, hid_t container); diff --git a/tools/lib/h5tools_dump.c b/tools/lib/h5tools_dump.c index 2c2a06f..3928837 100644 --- a/tools/lib/h5tools_dump.c +++ b/tools/lib/h5tools_dump.c @@ -198,10 +198,10 @@ hbool_t h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, size_t ncols, hsize_t region_elmt_counter/*element counter*/, hsize_t elmt_counter); -int h5tools_print_region_data_points(hid_t region_space, hid_t region_id, +static int h5tools_print_region_data_points(hid_t region_space, hid_t region_id, FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx, h5tools_str_t *buffer, size_t ncols, - int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata); + unsigned ndims, hid_t type_id, hsize_t npoints, hsize_t *ptdata); hbool_t h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, FILE *stream, const h5tool_format_t *info, @@ -634,10 +634,10 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]); HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ if((ptdata = (hsize_t*) HDmalloc((size_t) alloc_size)) == NULL) -{ + { HERROR(H5E_tools_g, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); HGOTO_DONE(dimension_break); -} + } if(H5Sget_select_hyper_blocklist(region_space, (hsize_t)0, nblocks, ptdata) < 0) HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Rget_select_hyper_blocklist failed"); @@ -779,20 +779,20 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, * hssize_t npoints is the number of points in the region *------------------------------------------------------------------------- */ -int +static int h5tools_print_region_data_points(hid_t region_space, hid_t region_id, FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx, h5tools_str_t *buffer, size_t ncols, - int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata) + unsigned ndims, hid_t type_id, hsize_t npoints, hsize_t *ptdata) { hbool_t dimension_break = TRUE; hsize_t *dims1 = NULL; hsize_t elmtno; /* elemnt index */ hsize_t curr_pos = 0; hsize_t total_size[H5S_MAX_RANK]; - size_t jndx; + hsize_t jndx; unsigned indx; - int type_size; + size_t type_size; int ret_value = SUCCEED; unsigned int region_flags; /* buffer extent flags */ hid_t mem_space = -1; @@ -807,7 +807,7 @@ h5tools_print_region_data_points(hid_t region_space, hid_t region_id, HDmemset(&ctx, 0, sizeof(ctx)); /* Allocate space for the dimension array */ - if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims)) == NULL) + if((dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * ndims)) == NULL) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for dims"); dims1[0] = npoints; @@ -841,7 +841,7 @@ h5tools_print_region_data_points(hid_t region_space, hid_t region_id, HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); /* assume entire data space to be printed */ - for (indx = 0; indx < (size_t) ctx.ndims; indx++) + for (indx = 0; indx < ctx.ndims; indx++) ctx.p_min_idx[indx] = 0; init_acc_pos(&ctx, total_size); @@ -850,13 +850,12 @@ h5tools_print_region_data_points(hid_t region_space, hid_t region_id, if (jndx == npoints - 1) region_flags |= END_OF_DATA; - for (indx = 0; indx < (size_t)ctx.ndims; indx++) + for (indx = 0; indx < ctx.ndims; indx++) ctx.p_max_idx[indx] = cur_ctx->p_max_idx[indx]; ctx.sm_pos = jndx * ndims; - if (ctx.ndims > 0) { - ctx.size_last_dim = (int) (ctx.p_max_idx[ctx.ndims - 1]); - } + if (ctx.ndims > 0) + ctx.size_last_dim = ctx.p_max_idx[ctx.ndims - 1]; else ctx.size_last_dim = 0; @@ -922,11 +921,13 @@ h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, hsize_t elmt_counter) { HERR_INIT(hbool_t, TRUE) hbool_t dimension_break = TRUE; - hssize_t npoints; + hssize_t snpoints; + hsize_t npoints; hsize_t alloc_size; hsize_t *ptdata; - int ndims; - hssize_t indx; + int sndims; + unsigned ndims; + hsize_t indx; hid_t dtype = -1; hid_t type_id = -1; @@ -934,12 +935,14 @@ h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, HDassert(ctx); HDassert(buffer); - if((npoints = H5Sget_select_elem_npoints(region_space)) <= 0) + if((snpoints = H5Sget_select_elem_npoints(region_space)) <= 0) H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_elem_npoints failed"); + npoints = (hsize_t)snpoints; /* Allocate space for the dimension array */ - if((ndims = H5Sget_simple_extent_ndims(region_space)) < 0) + if((sndims = H5Sget_simple_extent_ndims(region_space)) < 0) H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed"); + ndims = (unsigned)sndims; /* Render the region { element begin */ h5tools_str_reset(buffer); @@ -960,12 +963,11 @@ h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, if(NULL == (ptdata = (hsize_t *)HDmalloc((size_t) alloc_size))) HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "Could not allocate buffer for ptdata"); - H5_CHECK_OVERFLOW(npoints, hssize_t, hsize_t); - if(H5Sget_select_elem_pointlist(region_space, (hsize_t) 0, (hsize_t) npoints, ptdata) < 0) + if(H5Sget_select_elem_pointlist(region_space, (hsize_t) 0, npoints, ptdata) < 0) HGOTO_ERROR(dimension_break, H5E_tools_min_id_g, "H5Sget_select_elem_pointlist failed"); for (indx = 0; indx < npoints; indx++) { - int loop_indx; + unsigned loop_indx; h5tools_str_append(buffer, info->dset_ptformat_pre, indx ? "," OPTIONAL_LINE_BREAK " " : "", (unsigned long) indx); @@ -1249,7 +1251,7 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c H5Dvlen_reclaim(p_type, sm_space, H5P_DEFAULT, sm_buf); if(H5Sclose(sm_space) < 0) - H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if(sm_buf) HDfree(sm_buf); sm_buf = NULL; @@ -1333,7 +1335,7 @@ h5tools_display_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools } /* initialize temporary start, count and maximum start */ - for (i = 0; i < (size_t) ctx->ndims; i++) { + for (i = 0; i < ctx->ndims; i++) { temp_start[i] = sset->start.data[i]; temp_count[i] = sset->count.data[i]; temp_block[i] = sset->block.data[i]; @@ -1375,12 +1377,11 @@ h5tools_display_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools if (ctx->ndims > 2) { /* dimension for start */ - current_outer_dim = (ctx->ndims - 2) - 1; + current_outer_dim = (int)(ctx->ndims - 2) - 1; /* set start to original from current_outer_dim up */ - for (i = current_outer_dim + 1; i < ctx->ndims; i++) { + for (i = (size_t)(current_outer_dim + 1); i < ctx->ndims; i++) temp_start[i] = sset->start.data[i]; - } /* increment start dimension */ do { @@ -1472,7 +1473,7 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_co CATCH if(f_space >= 0 && H5Sclose(f_space) < 0) - H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); return ret_value; } @@ -1500,6 +1501,7 @@ h5tools_dump_simple_dset(FILE *stream, const h5tool_format_t *info, h5tools_cont hid_t f_space = -1; /* file data space */ hsize_t elmtno; /* counter */ size_t i; /* counter */ + int sndims; /* rank of dataspace */ int carry; /* counter carry value */ hsize_t zero[8]; /* vector of zeros */ unsigned int flags; /* buffer extent flags */ @@ -1529,11 +1531,13 @@ h5tools_dump_simple_dset(FILE *stream, const h5tool_format_t *info, h5tools_cont if (f_space == FAIL) H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); - ctx->ndims = H5Sget_simple_extent_ndims(f_space); + sndims = H5Sget_simple_extent_ndims(f_space); + if(sndims < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_simple_extent_ndims failed"); + ctx->ndims = (unsigned)sndims; - if ((size_t)ctx->ndims > NELMTS(sm_size)) { + if ((size_t)ctx->ndims > NELMTS(sm_size)) H5E_THROW(FAIL, H5E_tools_min_id_g, "ctx->ndims > NELMTS(sm_size) failed"); - } /* Assume entire data space to be printed */ if (ctx->ndims > 0) @@ -1652,9 +1656,9 @@ CATCH done: if(sm_space >= 0 && H5Sclose(sm_space) < 0) - H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if(f_space >= 0 && H5Sclose(f_space) < 0) - H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed"); + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); return ret_value; } @@ -1675,10 +1679,14 @@ h5tools_dump_simple_mem(FILE *stream, const h5tool_format_t *info, h5tools_conte hid_t type, hid_t space, void *mem) { HERR_INIT(herr_t, SUCCEED) + int sndims; /* rank of dataspace */ unsigned i; /*counters */ hsize_t nelmts; /*total selected elmts */ - ctx->ndims = H5Sget_simple_extent_ndims(space); + sndims = H5Sget_simple_extent_ndims(space); + if(sndims < 0) + H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dget_simple_extent_ndims failed"); + ctx->ndims = (unsigned)sndims; if ((size_t) ctx->ndims > NELMTS(ctx->p_min_idx)) H5E_THROW(FAIL, H5E_tools_min_id_g, "ctx->ndims > NELMTS(ctx->p_min_idx) failed"); @@ -1696,7 +1704,7 @@ h5tools_dump_simple_mem(FILE *stream, const h5tool_format_t *info, h5tools_conte H5_LEAVE(SUCCEED); /* nothing to print */ if (ctx->ndims > 0) { HDassert(ctx->p_max_idx[ctx->ndims - 1] == (hsize_t) ((int) ctx->p_max_idx[ctx->ndims - 1])); - ctx->size_last_dim = (int) (ctx->p_max_idx[ctx->ndims - 1]); + ctx->size_last_dim = ctx->p_max_idx[ctx->ndims - 1]; } /* end if */ else ctx->size_last_dim = 0; @@ -2583,7 +2591,6 @@ h5tools_print_enum(FILE *stream, h5tools_str_t *buffer, const h5tool_format_t *i unsigned i; unsigned nmembs = 0; /*number of members */ int snmembs; - int nchars; /*number of output characters */ hid_t super = -1; /*enum base integer type */ hid_t native = -1; /*native integer datatype */ H5T_sign_t sign_type; /*sign of value type */ @@ -2650,12 +2657,14 @@ h5tools_print_enum(FILE *stream, h5tools_str_t *buffer, const h5tool_format_t *i /* Print members */ for (i = 0; i < nmembs; i++) { + int nchars; /*number of output characters */ + ctx->need_prefix = TRUE; h5tools_simple_prefix(stream, info, ctx, (hsize_t)0, 0); h5tools_str_reset(buffer); h5tools_str_append(buffer, "\"%s\"", name[i]); - nchars = HDstrlen(name[i]); + nchars = (int)HDstrlen(name[i]); h5tools_str_append(buffer, "%*s ", MAX(0, 16 - nchars), ""); if (native < 0) { @@ -2900,7 +2909,7 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, size_t cd_nelmts; /* filter client number of values */ off_t offset; /* offset of external file */ char f_name[256]; /* filter name */ - char name[256]; /* external file name */ + char name[256]; /* external or virtual file name */ hsize_t chsize[64]; /* chunk size in elements */ hsize_t size; /* size of external file */ hsize_t storage_size; @@ -2942,7 +2951,7 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, for(i = 1; i < rank; i++) h5tools_str_append(&buffer, ", " HSIZE_T_FORMAT, chsize[i]); h5tools_str_append(&buffer, " %s", h5tools_dump_header_format->dataspacedimend); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->need_prefix = TRUE; h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); @@ -2995,8 +3004,7 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, else { h5tools_str_append(&buffer, "SIZE " HSIZE_T_FORMAT, storage_size); } - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); - + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->indent_level--; break; case H5D_COMPACT: @@ -3006,15 +3014,14 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "%s", COMPACT); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->need_prefix = TRUE; h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "SIZE " HSIZE_T_FORMAT, storage_size); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); - + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->indent_level--; break; case H5D_CONTIGUOUS: @@ -3034,14 +3041,14 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "%s", CONTIGUOUS); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->need_prefix = TRUE; h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "%s %s", EXTERNAL, BEGIN); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->indent_level++; for (j = 0; j < (unsigned) next; j++) { @@ -3053,7 +3060,7 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "FILENAME %s SIZE " HSIZE_T_FORMAT, name, size); h5tools_str_append(&buffer, " OFFSET %ld", offset); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); } ctx->indent_level--; @@ -3072,14 +3079,14 @@ h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "%s", CONTIGUOUS); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->need_prefix = TRUE; h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); h5tools_str_reset(&buffer); h5tools_str_append(&buffer,"SIZE " HSIZE_T_FORMAT, storage_size); - h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0); + h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t) ncols, (hsize_t) 0, (hsize_t) 0); ctx->need_prefix = TRUE; h5tools_simple_prefix(stream, info, ctx, curr_pos, 0); @@ -3437,7 +3444,7 @@ h5tools_dump_comment(FILE *stream, const h5tool_format_t *info, if (cmt_bufsize > 0) { comment = (char *)HDmalloc((size_t)(cmt_bufsize+1)); /* new_size including null terminator */ if(comment) { - cmt_bufsize = H5Oget_comment(obj_id, comment, cmt_bufsize); + cmt_bufsize = H5Oget_comment(obj_id, comment, (size_t)cmt_bufsize); if(cmt_bufsize > 0) { comment[cmt_bufsize] = '\0'; /* necessary because null char is not returned */ @@ -3576,49 +3583,39 @@ h5tools_print_dims(h5tools_str_t *buffer, hsize_t *s, int dims) void h5tools_print_packed_bits(h5tools_str_t *buffer, hid_t type) { - int packed_bits_size = 0; - + unsigned packed_bits_size = 0; hid_t n_type = h5tools_get_native_type(type); - if(H5Tget_class(n_type)==H5T_INTEGER) { - if(H5Tequal(n_type, H5T_NATIVE_SCHAR) == TRUE) { + + if(H5Tget_class(n_type) == H5T_INTEGER) { + if(H5Tequal(n_type, H5T_NATIVE_SCHAR) == TRUE) packed_bits_size = 8 * sizeof(char); - } - else if(H5Tequal(n_type, H5T_NATIVE_UCHAR) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_UCHAR) == TRUE) packed_bits_size = 8 * sizeof(unsigned char); - } - else if(H5Tequal(n_type, H5T_NATIVE_SHORT) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_SHORT) == TRUE) packed_bits_size = 8 * sizeof(short); - } - else if(H5Tequal(n_type, H5T_NATIVE_USHORT) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_USHORT) == TRUE) packed_bits_size = 8 * sizeof(unsigned short); - } - else if(H5Tequal(n_type, H5T_NATIVE_INT) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_INT) == TRUE) packed_bits_size = 8 * sizeof(int); - } - else if(H5Tequal(n_type, H5T_NATIVE_UINT) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_UINT) == TRUE) packed_bits_size = 8 * sizeof(unsigned int); - } - else if(H5Tequal(n_type, H5T_NATIVE_LONG) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_LONG) == TRUE) packed_bits_size = 8 * sizeof(long); - } - else if(H5Tequal(n_type, H5T_NATIVE_ULONG) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_ULONG) == TRUE) packed_bits_size = 8 * sizeof(unsigned long); - } - else if(H5Tequal(n_type, H5T_NATIVE_LLONG) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_LLONG) == TRUE) packed_bits_size = 8 * sizeof(long long); - } - else if(H5Tequal(n_type, H5T_NATIVE_ULLONG) == TRUE) { + else if(H5Tequal(n_type, H5T_NATIVE_ULLONG) == TRUE) packed_bits_size = 8 * sizeof(unsigned long long); - } else error_msg("Packed Bit not valid for this datatype"); } - if ((packed_bits_size>0) && (packed_data_offset + packed_data_length) > packed_bits_size) { - error_msg("Packed Bit offset+length value(%d) too large. Max is %d\n", packed_data_offset+packed_data_length, packed_bits_size); + if((packed_bits_size > 0) && (packed_data_offset + packed_data_length) > packed_bits_size) { + error_msg("Packed Bit offset+length value(%u) too large. Max is %d\n", packed_data_offset + packed_data_length, packed_bits_size); packed_data_mask = 0; }; - h5tools_str_append(buffer, "%s %s=%d %s=%d", PACKED_BITS, PACKED_OFFSET, packed_data_offset, PACKED_LENGTH, packed_data_length); + h5tools_str_append(buffer, "%s %s=%u %s=%u", PACKED_BITS, PACKED_OFFSET, packed_data_offset, PACKED_LENGTH, packed_data_length); } /*------------------------------------------------------------------------- diff --git a/tools/lib/h5tools_error.h b/tools/lib/h5tools_error.h index ae549fd..749157e 100644 --- a/tools/lib/h5tools_error.h +++ b/tools/lib/h5tools_error.h @@ -98,7 +98,7 @@ H5TOOLS_DLLVAR hid_t H5E_tools_min_id_g; * to the `catch_except' label, if we're not already past it. */ #define H5E_THROW(fail_value, min_id, str) { \ - HERROR(H5E_tools_g, min_id, str); \ + H5Epush2(H5tools_ERR_STACK_g, __FILE__, FUNC, __LINE__, H5tools_ERR_CLS_g, H5E_tools_g, min_id, str); \ H5_LEAVE(fail_value) \ } diff --git a/tools/lib/h5tools_filters.c b/tools/lib/h5tools_filters.c index ccdba26..0b42124 100644 --- a/tools/lib/h5tools_filters.c +++ b/tools/lib/h5tools_filters.c @@ -13,7 +13,7 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "hdf5.h" +#include "H5private.h" #include "h5tools.h" /*------------------------------------------------------------------------- @@ -151,54 +151,60 @@ int h5tools_can_encode(H5Z_filter_t filtn) { switch (filtn) { /* user defined filter */ default: - return 0; + return 0; case H5Z_FILTER_DEFLATE: #ifndef H5_HAVE_FILTER_DEFLATE - return 0; + return 0; #endif - break; + break; + case H5Z_FILTER_SZIP: #ifndef H5_HAVE_FILTER_SZIP - return 0; + return 0; #else { - unsigned int filter_config_flags; + unsigned int filter_config_flags; - if (H5Zget_filter_info(filtn, &filter_config_flags) < 0) - return -1; - if ((filter_config_flags - & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) == 0) { - /* filter present but neither encode nor decode is supported (???) */ - return -1; - } - else if ((filter_config_flags - & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) == H5Z_FILTER_CONFIG_DECODE_ENABLED) { - /* decoder only: read but not write */ - return 0; - } - else if ((filter_config_flags - & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) == H5Z_FILTER_CONFIG_ENCODE_ENABLED) { - /* encoder only: write but not read (???) */ - return -1; - } - else if ((filter_config_flags - & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) - == (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) { - return 1; - } + if (H5Zget_filter_info(filtn, &filter_config_flags) < 0) + return -1; + if ((filter_config_flags + & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) == 0) { + /* filter present but neither encode nor decode is supported (???) */ + return -1; + } + else if ((filter_config_flags + & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) == H5Z_FILTER_CONFIG_DECODE_ENABLED) { + /* decoder only: read but not write */ + return 0; + } + else if ((filter_config_flags + & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) == H5Z_FILTER_CONFIG_ENCODE_ENABLED) { + /* encoder only: write but not read (???) */ + return -1; + } + else if ((filter_config_flags + & (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) + == (H5Z_FILTER_CONFIG_ENCODE_ENABLED | H5Z_FILTER_CONFIG_DECODE_ENABLED)) { + return 1; + } } #endif - break; + break; + case H5Z_FILTER_SHUFFLE: - break; + break; + case H5Z_FILTER_FLETCHER32: - break; + break; + case H5Z_FILTER_NBIT: - break; + break; + case H5Z_FILTER_SCALEOFFSET: - break; - }/*switch*/ + break; + }/*switch*/ - return 1; + return 1; } + diff --git a/tools/lib/h5tools_ref.c b/tools/lib/h5tools_ref.c index 3a4183b..8c869c8 100644 --- a/tools/lib/h5tools_ref.c +++ b/tools/lib/h5tools_ref.c @@ -39,7 +39,7 @@ typedef struct { haddr_t objno; /* Object ID (i.e. address) */ - const char *path; /* Object path */ + char *path; /* Object path */ } ref_path_node_t; static H5SL_t *ref_path_table = NULL; /* the "table" (implemented with a skip list) */ @@ -65,7 +65,7 @@ free_ref_path_info(void *item, void H5_ATTR_UNUSED *key, void H5_ATTR_UNUSED *op { ref_path_node_t *node = (ref_path_node_t *)item; - HDfree((void *)node->path); + HDfree(node->path); HDfree(node); return(0); @@ -218,7 +218,7 @@ ref_path_table_put(const char *path, haddr_t objno) HDassert(ref_path_table); HDassert(path); - if((new_node = HDmalloc(sizeof(ref_path_node_t))) == NULL) + if((new_node = (ref_path_node_t *)HDmalloc(sizeof(ref_path_node_t))) == NULL) return(-1); new_node->objno = objno; @@ -300,7 +300,7 @@ lookup_ref_path(haddr_t ref) if(ref_path_table == NULL) init_ref_path_table(); - node = H5SL_search(ref_path_table, &ref); + node = (ref_path_node_t *)H5SL_search(ref_path_table, &ref); return(node ? node->path : NULL); } diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index a92568a..7f65c91 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -126,14 +126,12 @@ h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) va_list ap; /* Make sure we have some memory into which to print */ - if (!str->s || str->nalloc <= 0) { + if (!str->s || str->nalloc <= 0) h5tools_str_reset(str); - } - if (HDstrlen(fmt) == 0) { + if (HDstrlen(fmt) == 0) /* nothing to print */ return str->s; - } /* Format the arguments and append to the value already in `str' */ while (1) { @@ -156,19 +154,18 @@ h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) * to lack of buffer size, so try one more time after realloc more * buffer size before return NULL. */ - if (nchars < 0) { + if (nchars < 0) /* failure, such as bad format */ return NULL; - } - if (nchars < 0 || (size_t) nchars >= avail || (0 == nchars && (HDstrcmp(fmt, "%s")))) { + if ((size_t) nchars >= avail || (0 == nchars && (HDstrcmp(fmt, "%s")))) { /* Truncation return value as documented by C99, or zero return value with either of the * following conditions, each of which indicates that the proper C99 return value probably * should have been positive when the format string is * something other than "%s" * Alocate at least twice as much space and try again. */ - size_t newsize = MAX(str->len + nchars + 1, 2 * str->nalloc); + size_t newsize = MAX(str->len + (size_t)nchars + 1, 2 * str->nalloc); HDassert(newsize > str->nalloc); /*overflow*/ str->s = (char*)HDrealloc(str->s, newsize); HDassert(str->s); @@ -176,7 +173,7 @@ h5tools_str_append(h5tools_str_t *str/*in,out*/, const char *fmt, ...) } else { /* Success */ - str->len += nchars; + str->len += (size_t)nchars; break; } } @@ -267,6 +264,9 @@ h5tools_str_fmt(h5tools_str_t *str/*in,out*/, size_t start, const char *fmt) { char _temp[1024], *temp = _temp; + HDassert(str); + HDassert(fmt); + /* If the format string is simply "%s" then don't bother doing anything */ if (!HDstrcmp(fmt, "%s")) return str->s; @@ -413,58 +413,57 @@ h5tools_str_region_prefix(h5tools_str_t *str, const h5tool_format_t *info, } /*------------------------------------------------------------------------- - * Function: h5tools_str_dump_region_blocks + * Function: h5tools_str_dump_space_blocks * - * Purpose: Prints information about a dataspace region by appending + * Purpose: Prints information about a dataspace selection by appending * the information to the specified string. * * Return: none * * In/Out: - * h5tools_context_t *ctx * h5tools_str_t *str *------------------------------------------------------------------------- */ void -h5tools_str_dump_region_blocks(h5tools_str_t *str, hid_t region, +h5tools_str_dump_space_blocks(h5tools_str_t *str, hid_t rspace, const h5tool_format_t *info) { - hssize_t nblocks; - hsize_t alloc_size; - hsize_t *ptdata; - int ndims = H5Sget_simple_extent_ndims(region); + hssize_t snblocks; /* - * This function fails if the region does not have blocks. + * This function fails if the rspace does not have blocks. */ H5E_BEGIN_TRY { - nblocks = H5Sget_select_hyper_nblocks(region); + snblocks = H5Sget_select_hyper_nblocks(rspace); } H5E_END_TRY; /* Print block information */ - if (nblocks > 0) { - int i; - + if (snblocks > 0) { + hsize_t nblocks; + hsize_t *ptdata; + hsize_t alloc_size; + unsigned ndims = (unsigned)H5Sget_simple_extent_ndims(rspace); + hsize_t u; + + nblocks = (hsize_t)snblocks; alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]); HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ ptdata = (hsize_t *)HDmalloc((size_t) alloc_size); - H5_CHECK_OVERFLOW(nblocks, hssize_t, hsize_t); - H5Sget_select_hyper_blocklist(region, (hsize_t)0, (hsize_t)nblocks, ptdata); + H5Sget_select_hyper_blocklist(rspace, (hsize_t)0, nblocks, ptdata); - for (i = 0; i < nblocks; i++) { - int j; + for (u = 0; u < nblocks; u++) { + unsigned v; - h5tools_str_append(str, info->dset_blockformat_pre, i ? "," OPTIONAL_LINE_BREAK " " : "", - (unsigned long)i); + h5tools_str_append(str, info->dset_blockformat_pre, u ? "," OPTIONAL_LINE_BREAK " " : "", (unsigned long)u); /* Start coordinates and opposite corner */ - for (j = 0; j < ndims; j++) - h5tools_str_append(str, "%s" HSIZE_T_FORMAT, j ? "," : "(", - ptdata[i * 2 * ndims + j]); + for (v = 0; v < ndims; v++) + h5tools_str_append(str, "%s" HSIZE_T_FORMAT, v ? "," : "(", + ptdata[u * 2 * ndims + v]); - for (j = 0; j < ndims; j++) - h5tools_str_append(str, "%s" HSIZE_T_FORMAT, j ? "," : ")-(", - ptdata[i * 2 * ndims + j + ndims]); + for (v = 0; v < ndims; v++) + h5tools_str_append(str, "%s" HSIZE_T_FORMAT, v ? "," : ")-(", + ptdata[u * 2 * ndims + v + ndims]); h5tools_str_append(str, ")"); } @@ -474,53 +473,53 @@ h5tools_str_dump_region_blocks(h5tools_str_t *str, hid_t region, } /*------------------------------------------------------------------------- - * Function: h5tools_str_dump_region_points + * Function: h5tools_str_dump_space_points * - * Purpose: Prints information about a dataspace region by appending + * Purpose: Prints information about a dataspace selection by appending * the information to the specified string. * * Return: none * * In/Out: - * h5tools_context_t *ctx * h5tools_str_t *str *------------------------------------------------------------------------- */ void -h5tools_str_dump_region_points(h5tools_str_t *str, hid_t region, +h5tools_str_dump_space_points(h5tools_str_t *str, hid_t rspace, const h5tool_format_t *info) { - hssize_t npoints; - hsize_t alloc_size; - hsize_t *ptdata; - int ndims = H5Sget_simple_extent_ndims(region); + hssize_t snpoints; /* - * This function fails if the region does not have points. + * This function fails if the rspace does not have points. */ H5E_BEGIN_TRY { - npoints = H5Sget_select_elem_npoints(region); + snpoints = H5Sget_select_elem_npoints(rspace); } H5E_END_TRY; /* Print point information */ - if (npoints > 0) { - int i; - + if (snpoints > 0) { + hsize_t npoints; + hsize_t alloc_size; + hsize_t *ptdata; + unsigned ndims = (unsigned)H5Sget_simple_extent_ndims(rspace); + hsize_t u; + + npoints = (hsize_t)snpoints; alloc_size = npoints * ndims * sizeof(ptdata[0]); HDassert(alloc_size == (hsize_t) ((size_t) alloc_size)); /*check for overflow*/ ptdata = (hsize_t *)HDmalloc((size_t) alloc_size); - H5_CHECK_OVERFLOW(npoints, hssize_t, hsize_t); - H5Sget_select_elem_pointlist(region, (hsize_t)0, (hsize_t)npoints, ptdata); + H5Sget_select_elem_pointlist(rspace, (hsize_t)0, npoints, ptdata); - for (i = 0; i < npoints; i++) { - int j; + for (u = 0; u < npoints; u++) { + unsigned v; - h5tools_str_append(str, info->dset_ptformat_pre, i ? "," OPTIONAL_LINE_BREAK " " : "", - (unsigned long)i); + h5tools_str_append(str, info->dset_ptformat_pre, u ? "," OPTIONAL_LINE_BREAK " " : "", + (unsigned long)u); - for (j = 0; j < ndims; j++) - h5tools_str_append(str, "%s" HSIZE_T_FORMAT, j ? "," : "(", - (ptdata[i * ndims + j])); + for (v = 0; v < ndims; v++) + h5tools_str_append(str, "%s" HSIZE_T_FORMAT, v ? "," : "(", + (ptdata[u * ndims + v])); h5tools_str_append(str, ")"); } @@ -609,13 +608,12 @@ void h5tools_str_indent(h5tools_str_t *str, const h5tool_format_t *info, h5tools_context_t *ctx) { - int i, indentlevel = 0; + unsigned u, indentlevel = 0; /* Write new prefix */ - if (ctx->indent_level >= 0) { + if (ctx->indent_level > 0) indentlevel = ctx->indent_level; - } - else { + else /* * This is because sometimes we don't print out all the header * info for the data (like the tattr-2.ddl example). If that happens @@ -623,11 +621,9 @@ h5tools_str_indent(h5tools_str_t *str, const h5tool_format_t *info, * just print out the default indent levels. */ indentlevel = ctx->default_indent_level; - } - for (i = 0; i < indentlevel; i++) { + for (u = 0; u < indentlevel; u++) h5tools_str_append(str, "%s", OPT(info->line_indent, "")); - } } /*------------------------------------------------------------------------- @@ -686,22 +682,10 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai unsigned char *ucp_vp = (unsigned char *)vp; char *cp_vp = (char *)vp; hid_t memb, obj; - unsigned nmembs; static char fmt_llong[8], fmt_ullong[8]; H5T_str_t pad; H5T_class_t type_class; - /* - * some tempvars to store the value before we append it to the string to - * get rid of the memory alignment problem - */ - unsigned long long tempullong; - long long templlong; - unsigned long tempulong; - long templong; - unsigned int tempuint; - int tempint; - /* Build default formats for long long types */ if (!fmt_llong[0]) { HDsnprintf(fmt_llong, sizeof(fmt_llong), "%%%sd", H5_PRINTF_LL_WIDTH); @@ -737,7 +721,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai float tempfloat; HDmemcpy(&tempfloat, vp, sizeof(float)); - h5tools_str_append(str, OPT(info->fmt_float, "%g"), tempfloat); + h5tools_str_append(str, OPT(info->fmt_float, "%g"), (double)tempfloat); } else if (sizeof(double) == nsize) { /* if (H5Tequal(type, H5T_NATIVE_DOUBLE)) */ @@ -756,6 +740,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai #endif } break; + case H5T_STRING: { unsigned int i; @@ -776,12 +761,11 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai pad = H5Tget_strpad(type); /* Check for NULL pointer for string */ - if (s == NULL) { + if (s == NULL) h5tools_str_append(str, "NULL"); - } else { for (i = 0; i < size && (s[i] || pad != H5T_STR_NULLTERM); i++) { - int j = 1; + unsigned j = 1; /* * Count how many times the next character repeats. If the @@ -798,7 +782,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai * in it's own quote. */ if (info->str_repeat > 0 && j > info->str_repeat) { - if (quote) h5tools_str_append(str, "%c", quote); + if (quote) + h5tools_str_append(str, "%c", quote); quote = '\''; h5tools_str_append(str, "%s%c", i ? " " : "", quote); @@ -821,10 +806,10 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai quote = '\0'; i += j - 1; } - } - if (quote) h5tools_str_append(str, "%c", quote); + if (quote) + h5tools_str_append(str, "%c", quote); if (i == 0) /*empty string*/ @@ -832,64 +817,64 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai } /* end else */ } break; + case H5T_INTEGER: if (sizeof(char) == nsize) { - /* if ((H5Tequal(type, H5T_NATIVE_SCHAR) || H5Tequal(type, H5T_NATIVE_UCHAR))) */ - if (info->ascii) { + if (info->ascii) h5tools_print_char(str, info, (char) (*ucp_vp)); - } else if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(type, H5T_NATIVE_UCHAR)) */ unsigned char tempuchar; + HDmemcpy(&tempuchar, ucp_vp, sizeof(unsigned char)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(unsigned char)) tempuchar = 0; else - tempuchar = (tempuchar >> packed_data_offset) & packed_data_mask; + tempuchar = (unsigned char)((unsigned long long)(tempuchar >> packed_data_offset) & packed_data_mask); } - h5tools_str_append(str, OPT(info->fmt_uchar, "%u"), tempuchar); + h5tools_str_append(str, OPT(info->fmt_uchar, "%hhu"), tempuchar); } else { - /* if (H5Tequal(type, H5T_NATIVE_SCHAR)) */ signed char tempchar; + HDmemcpy(&tempchar, cp_vp, sizeof(char)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(char)) tempchar = 0; else - tempchar = (tempchar >> packed_data_offset) & packed_data_mask; + tempchar = (signed char)((unsigned long long)(tempchar >> packed_data_offset) & packed_data_mask); } h5tools_str_append(str, OPT(info->fmt_schar, "%hhd"), tempchar); } } /* end if (sizeof(char) == nsize) */ else if (sizeof(int) == nsize) { if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(type, H5T_NATIVE_UINT)) */ + unsigned int tempuint; + HDmemcpy(&tempuint, vp, sizeof(unsigned int)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(unsigned int)) tempuint = 0; else - tempuint = (tempuint >> packed_data_offset) & packed_data_mask; + tempuint = (unsigned)((tempuint >> packed_data_offset) & packed_data_mask); } h5tools_str_append(str, OPT(info->fmt_uint, "%u"), tempuint); } else { - /* if (H5Tequal(type, H5T_NATIVE_INT)) */ + int tempint; + HDmemcpy(&tempint, vp, sizeof(int)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(int)) tempint = 0; else - tempint = (tempint >> packed_data_offset) & packed_data_mask; + tempint = (int)((unsigned long long)(tempint >> packed_data_offset) & packed_data_mask); } h5tools_str_append(str, OPT(info->fmt_int, "%d"), tempint); } } /* end if (sizeof(int) == nsize) */ else if (sizeof(short) == nsize) { if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(type, H5T_NATIVE_USHORT)) */ unsigned short tempushort; HDmemcpy(&tempushort, vp, sizeof(unsigned short)); @@ -897,12 +882,11 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai if (packed_data_offset >= 8 * sizeof(unsigned short)) tempushort = 0; else - tempushort = (tempushort >> packed_data_offset) & packed_data_mask; + tempushort = (unsigned short)((unsigned long long)(tempushort >> packed_data_offset) & packed_data_mask); } - h5tools_str_append(str, OPT(info->fmt_ushort, "%u"), tempushort); + h5tools_str_append(str, OPT(info->fmt_ushort, "%hu"), tempushort); } else { - /* if (H5Tequal(type, H5T_NATIVE_SHORT)) */ short tempshort; HDmemcpy(&tempshort, vp, sizeof(short)); @@ -910,14 +894,15 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai if (packed_data_offset >= 8 * sizeof(short)) tempshort = 0; else - tempshort = (tempshort >> packed_data_offset) & packed_data_mask; + tempshort = (short)((unsigned long long)(tempshort >> packed_data_offset) & packed_data_mask); } - h5tools_str_append(str, OPT(info->fmt_short, "%d"), tempshort); + h5tools_str_append(str, OPT(info->fmt_short, "%hd"), tempshort); } } /* end if (sizeof(short) == nsize) */ else if (sizeof(long) == nsize) { if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(type, H5T_NATIVE_ULONG)) */ + unsigned long tempulong; + HDmemcpy(&tempulong, vp, sizeof(unsigned long)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(unsigned long)) @@ -928,20 +913,23 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai h5tools_str_append(str, OPT(info->fmt_ulong, "%lu"), tempulong); } else { - /* if (H5Tequal(type, H5T_NATIVE_LONG)) */ + long templong; + HDmemcpy(&templong, vp, sizeof(long)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(long)) templong = 0; else - templong = (templong >> packed_data_offset) & packed_data_mask; + templong = (long)((unsigned long long)(templong >> packed_data_offset) & packed_data_mask); } h5tools_str_append(str, OPT(info->fmt_long, "%ld"), templong); } } /* end if (sizeof(long) == nsize) */ +#if H5_SIZEOF_LONG != H5_SIZEOF_LONG_LONG else if (sizeof(long long) == nsize) { if(H5T_SGN_NONE == nsign) { - /* if (H5Tequal(type, H5T_NATIVE_ULLONG)) */ + unsigned long long tempullong; + HDmemcpy(&tempullong, vp, sizeof(unsigned long long)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(unsigned long long)) @@ -952,7 +940,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai h5tools_str_append(str, OPT(info->fmt_ullong, fmt_ullong), tempullong); } else { - /* if (H5Tequal(type, H5T_NATIVE_LLONG)) */ + long long templlong; + HDmemcpy(&templlong, vp, sizeof(long long)); if (packed_bits_num) { if (packed_data_offset >= 8 * sizeof(long long)) @@ -963,12 +952,15 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai h5tools_str_append(str, OPT(info->fmt_llong, fmt_llong), templlong); } } /* end if (sizeof(long long) == nsize) */ +#endif /* H5_SIZEOF_LONG != H5_SIZEOF_LONG_LONG */ break; + case H5T_COMPOUND: { + unsigned nmembs; unsigned j; - nmembs = H5Tget_nmembers(type); + nmembs = (unsigned)H5Tget_nmembers(type); h5tools_str_append(str, "%s", OPT(info->cmpd_pre, "{")); ctx->indent_level++; @@ -979,7 +971,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai else h5tools_str_append(str, "%s", OPT(info->cmpd_end, "")); - if (info->arr_linebreak) h5tools_str_indent(str, info, ctx); + if (info->arr_linebreak) + h5tools_str_indent(str, info, ctx); /* The name */ name = H5Tget_member_name(type, j); @@ -1001,9 +994,9 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai h5tools_str_indent(str, info, ctx); } h5tools_str_append(str, "%s", OPT(info->cmpd_suf, "}")); - } break; + case H5T_ENUM: { char enum_name[1024]; @@ -1023,10 +1016,10 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai } } break; + case H5T_REFERENCE: - if (h5tools_str_is_zero(vp, nsize)) { + if (h5tools_str_is_zero(vp, nsize)) h5tools_str_append(str, "NULL"); - } else { if (nsize == H5R_DSET_REG_REF_BUF_SIZE) { /* if (H5Tequal(type, H5T_STD_REF_DSETREG)) */ @@ -1082,6 +1075,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai } /* end else if (H5Tequal(type, H5T_STD_REF_OBJ)) */ } break; + case H5T_ARRAY: { int k, ndims; @@ -1108,7 +1102,8 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai ctx->indent_level++; for (i = 0; i < nelmts; i++) { - if (i) h5tools_str_append(str, "%s", OPT(info->arr_sep, "," OPTIONAL_LINE_BREAK)); + if (i) + h5tools_str_append(str, "%s", OPT(info->arr_sep, "," OPTIONAL_LINE_BREAK)); if (info->arr_linebreak && i && i % dims[ndims - 1] == 0) { h5tools_str_append(str, "%s", "\n"); @@ -1143,6 +1138,7 @@ h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t contai H5Tclose(memb); } break; + case H5T_VLEN: { unsigned int i; @@ -1244,9 +1240,9 @@ h5tools_str_sprint_region(h5tools_str_t *str, const h5tool_format_t *info, region_type = H5Sget_select_type(region); if(region_type==H5S_SEL_POINTS) - h5tools_str_dump_region_points(str, region, info); + h5tools_str_dump_space_points(str, region, info); else - h5tools_str_dump_region_blocks(str, region, info); + h5tools_str_dump_space_blocks(str, region, info); h5tools_str_append(str, "}"); @@ -1392,31 +1388,33 @@ h5tools_str_is_zero(const void *_mem, size_t size) char * h5tools_str_replace ( const char *string, const char *substr, const char *replacement ) { - char *tok = NULL; - char *newstr = NULL; - char *oldstr = NULL; - char *head = NULL; - - if ( substr == NULL || replacement == NULL ) - return HDstrdup (string); - newstr = HDstrdup (string); - head = newstr; - while ( (tok = HDstrstr ( head, substr ))){ - oldstr = newstr; - newstr = (char *)HDmalloc( HDstrlen( oldstr ) - HDstrlen( substr ) + HDstrlen( replacement ) + 1 ); - - if ( newstr == NULL ){ - HDfree (oldstr); - return NULL; + char *tok = NULL; + char *newstr = NULL; + char *head = NULL; + + if(substr == NULL || replacement == NULL) + return HDstrdup(string); + newstr = HDstrdup(string); + head = newstr; + while((tok = HDstrstr(head, substr))) { + char *oldstr; + + oldstr = newstr; + newstr = (char *)HDmalloc(HDstrlen(oldstr) - HDstrlen(substr) + HDstrlen(replacement) + 1); + + if(newstr == NULL) { + HDfree(oldstr); + return NULL; } - HDmemcpy ( newstr, oldstr, tok - oldstr ); - HDmemcpy ( newstr + (tok - oldstr), replacement, HDstrlen ( replacement ) ); - HDmemcpy ( newstr + (tok - oldstr) + HDstrlen( replacement ), tok + HDstrlen ( substr ), HDstrlen ( oldstr ) - HDstrlen ( substr ) - ( tok - oldstr ) ); - HDmemset ( newstr + HDstrlen ( oldstr ) - HDstrlen ( substr ) + HDstrlen ( replacement ) , 0, 1 ); + HDmemcpy(newstr, oldstr, (size_t)(tok - oldstr)); + HDmemcpy(newstr + (tok - oldstr), replacement, HDstrlen(replacement)); + HDmemcpy(newstr + (tok - oldstr) + HDstrlen(replacement), tok + HDstrlen(substr), HDstrlen(oldstr) - HDstrlen(substr) - (size_t)(tok - oldstr)); + HDmemset(newstr + HDstrlen (oldstr) - HDstrlen(substr) + HDstrlen(replacement) , 0, 1); /* move back head right after the last replacement */ - head = newstr + (tok - oldstr) + HDstrlen( replacement ); - HDfree (oldstr); + head = newstr + (tok - oldstr) + HDstrlen(replacement); + HDfree(oldstr); } return newstr; } + diff --git a/tools/lib/h5tools_str.h b/tools/lib/h5tools_str.h index 38697c6..8d4c042 100644 --- a/tools/lib/h5tools_str.h +++ b/tools/lib/h5tools_str.h @@ -40,8 +40,8 @@ H5TOOLS_DLL char *h5tools_str_prefix(h5tools_str_t *str, const h5tool_format_ H5TOOLS_DLL char *h5tools_str_region_prefix(h5tools_str_t *str, const h5tool_format_t *info, hsize_t elmtno, hsize_t *ptdata, unsigned ndims, hsize_t max_idx[], h5tools_context_t *ctx); -H5TOOLS_DLL void h5tools_str_dump_region_blocks(h5tools_str_t *, hid_t, const h5tool_format_t *); -H5TOOLS_DLL void h5tools_str_dump_region_points(h5tools_str_t *, hid_t, const h5tool_format_t *); +H5TOOLS_DLL void h5tools_str_dump_space_blocks(h5tools_str_t *, hid_t, const h5tool_format_t *); +H5TOOLS_DLL void h5tools_str_dump_space_points(h5tools_str_t *, hid_t, const h5tool_format_t *); H5TOOLS_DLL void h5tools_str_sprint_region(h5tools_str_t *str, const h5tool_format_t *info, hid_t container, void *vp); H5TOOLS_DLL char *h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, diff --git a/tools/lib/h5tools_type.c b/tools/lib/h5tools_type.c index d68d3c5..8a56d29 100644 --- a/tools/lib/h5tools_type.c +++ b/tools/lib/h5tools_type.c @@ -13,6 +13,7 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +#include "H5private.h" #include "h5tools.h" /*------------------------------------------------------------------------- @@ -75,54 +76,54 @@ h5tools_get_little_endian_type(hid_t tid) size = H5Tget_size(tid); sign = H5Tget_sign(tid); - switch( type_class ) - { - case H5T_INTEGER: - { - if ( size == 1 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I8LE); - else if ( size == 2 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I16LE); - else if ( size == 4 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I32LE); - else if ( size == 8 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I64LE); - else if ( size == 1 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U8LE); - else if ( size == 2 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U16LE); - else if ( size == 4 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U32LE); - else if ( size == 8 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U64LE); - } - break; - - case H5T_FLOAT: - if ( size == 4) - p_type=H5Tcopy(H5T_IEEE_F32LE); - else if ( size == 8) - p_type=H5Tcopy(H5T_IEEE_F64LE); - break; - - case H5T_TIME: - case H5T_BITFIELD: - case H5T_OPAQUE: - case H5T_STRING: - case H5T_COMPOUND: - case H5T_REFERENCE: - case H5T_ENUM: - case H5T_VLEN: - case H5T_ARRAY: - break; - - default: - break; - - } - - return(p_type); -} + switch(type_class) { + case H5T_INTEGER: + if ( size == 1 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I8LE); + else if ( size == 2 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I16LE); + else if ( size == 4 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I32LE); + else if ( size == 8 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I64LE); + else if ( size == 1 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U8LE); + else if ( size == 2 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U16LE); + else if ( size == 4 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U32LE); + else if ( size == 8 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U64LE); + break; + + case H5T_FLOAT: + if ( size == 4) + p_type=H5Tcopy(H5T_IEEE_F32LE); + else if ( size == 8) + p_type=H5Tcopy(H5T_IEEE_F64LE); + break; + + case H5T_TIME: + case H5T_BITFIELD: + case H5T_OPAQUE: + case H5T_STRING: + case H5T_COMPOUND: + case H5T_REFERENCE: + case H5T_ENUM: + case H5T_VLEN: + case H5T_ARRAY: + break; + + case H5T_NO_CLASS: + case H5T_NCLASSES: + default: + HDassert(0); + break; + + } /* end switch */ + + return p_type; +} /* end h5tools_get_little_endian_type() */ /*------------------------------------------------------------------------- @@ -152,53 +153,51 @@ h5tools_get_big_endian_type(hid_t tid) size = H5Tget_size(tid); sign = H5Tget_sign(tid); - switch( type_class ) - { - case H5T_INTEGER: - { - if ( size == 1 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I8BE); - else if ( size == 2 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I16BE); - else if ( size == 4 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I32BE); - else if ( size == 8 && sign == H5T_SGN_2) - p_type=H5Tcopy(H5T_STD_I64BE); - else if ( size == 1 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U8BE); - else if ( size == 2 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U16BE); - else if ( size == 4 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U32BE); - else if ( size == 8 && sign == H5T_SGN_NONE) - p_type=H5Tcopy(H5T_STD_U64BE); - } - break; - - case H5T_FLOAT: - if ( size == 4) - p_type=H5Tcopy(H5T_IEEE_F32BE); - else if ( size == 8) - p_type=H5Tcopy(H5T_IEEE_F64BE); - break; - - case H5T_TIME: - case H5T_BITFIELD: - case H5T_OPAQUE: - case H5T_STRING: - case H5T_COMPOUND: - case H5T_REFERENCE: - case H5T_ENUM: - case H5T_VLEN: - case H5T_ARRAY: - break; - - default: - break; - - } - - - return(p_type); -} + switch(type_class) { + case H5T_INTEGER: + if ( size == 1 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I8BE); + else if ( size == 2 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I16BE); + else if ( size == 4 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I32BE); + else if ( size == 8 && sign == H5T_SGN_2) + p_type=H5Tcopy(H5T_STD_I64BE); + else if ( size == 1 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U8BE); + else if ( size == 2 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U16BE); + else if ( size == 4 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U32BE); + else if ( size == 8 && sign == H5T_SGN_NONE) + p_type=H5Tcopy(H5T_STD_U64BE); + break; + + case H5T_FLOAT: + if ( size == 4) + p_type=H5Tcopy(H5T_IEEE_F32BE); + else if ( size == 8) + p_type=H5Tcopy(H5T_IEEE_F64BE); + break; + + case H5T_TIME: + case H5T_BITFIELD: + case H5T_OPAQUE: + case H5T_STRING: + case H5T_COMPOUND: + case H5T_REFERENCE: + case H5T_ENUM: + case H5T_VLEN: + case H5T_ARRAY: + break; + + case H5T_NO_CLASS: + case H5T_NCLASSES: + default: + HDassert(0); + break; + } /* end switch */ + + return p_type; +} /* end h5tools_get_big_endian_type() */ diff --git a/tools/lib/h5tools_utils.c b/tools/lib/h5tools_utils.c index b87abf6..e19926b 100644 --- a/tools/lib/h5tools_utils.c +++ b/tools/lib/h5tools_utils.c @@ -34,7 +34,7 @@ #include "h5trav.h" /* global variables */ -int h5tools_nCols = 80; +unsigned h5tools_nCols = 80; /* ``get_option'' variables */ int opt_err = 1; /*get_option prints errors if this is on */ int opt_ind = 1; /*token pointer */ @@ -57,7 +57,7 @@ hsize_t H5TOOLS_BUFSIZE = ( 32 * 1024 * 1024); /* 32 MB */ /* ``parallel_print'' variables */ unsigned char g_Parallel = 0; /*0 for serial, 1 for parallel */ char outBuff[OUTBUFF_SIZE]; -int outBuffOffset; +unsigned outBuffOffset; FILE* overflow_file = NULL; /* local functions */ @@ -89,11 +89,11 @@ void parallel_print(const char* format, ...) HDvprintf(format, ap); else { if(overflow_file == NULL) /*no overflow has occurred yet */ { - bytes_written = HDvsnprintf(outBuff+outBuffOffset, OUTBUFF_SIZE-outBuffOffset, format, ap); + bytes_written = HDvsnprintf(outBuff + outBuffOffset, OUTBUFF_SIZE - outBuffOffset, format, ap); HDva_end(ap); HDva_start(ap, format); - if((bytes_written < 0) || (bytes_written >= (OUTBUFF_SIZE - outBuffOffset))) { + if((bytes_written < 0) || ((unsigned)bytes_written >= (OUTBUFF_SIZE - outBuffOffset))) { /* Terminate the outbuff at the end of the previous output */ outBuff[outBuffOffset] = '\0'; @@ -104,7 +104,7 @@ void parallel_print(const char* format, ...) bytes_written = HDvfprintf(overflow_file, format, ap); } else - outBuffOffset += bytes_written; + outBuffOffset += (unsigned)bytes_written; } else bytes_written = HDvfprintf(overflow_file, format, ap); @@ -376,7 +376,7 @@ get_option(int argc, const char **argv, const char *opts, const struct long_opti *------------------------------------------------------------------------- */ void -indentation(int x) +indentation(unsigned x) { if (x < h5tools_nCols) { while (x-- > 0) @@ -408,7 +408,7 @@ print_version(const char *progname) { PRINTSTREAM(rawoutstream, "%s: Version %u.%u.%u%s%s\n", progname, H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE, - ((char *)H5_VERS_SUBRELEASE)[0] ? "-" : "", H5_VERS_SUBRELEASE); + ((const char *)H5_VERS_SUBRELEASE)[0] ? "-" : "", H5_VERS_SUBRELEASE); } @@ -680,7 +680,7 @@ init_objs(hid_t fid, find_objs_t *info, table_t **group_table, static void add_obj(table_t *table, haddr_t objno, const char *objname, hbool_t record) { - unsigned u; + size_t u; /* See if we need to make table larger */ if(table->nobjs == table->size) { @@ -912,7 +912,6 @@ int h5tools_getenv_update_hyperslab_bufsize(void) hyperslab_bufsize_mb = HDstrtol(env_str, (char**)NULL, 10); if (errno != 0 || hyperslab_bufsize_mb <= 0) { - /* TODO: later when pubilshed HDfprintf(rawerrorstream,"Error: Invalid environment variable \"H5TOOLS_BUFSIZE\" : %s\n", env_str); */ @@ -922,13 +921,14 @@ int h5tools_getenv_update_hyperslab_bufsize(void) /* convert MB to byte */ - H5TOOLS_BUFSIZE = hyperslab_bufsize_mb * 1024 * 1024; + H5TOOLS_BUFSIZE = (hsize_t)hyperslab_bufsize_mb * 1024 * 1024; H5TOOLS_MALLOCSIZE = MAX(H5TOOLS_BUFSIZE, H5TOOLS_MALLOCSIZE); } - return (1); + error: return (-1); } + diff --git a/tools/lib/h5tools_utils.h b/tools/lib/h5tools_utils.h index 3285278..f7ab65b 100644 --- a/tools/lib/h5tools_utils.h +++ b/tools/lib/h5tools_utils.h @@ -35,7 +35,7 @@ extern "C" { H5TOOLS_DLLVAR int g_nTasks; H5TOOLS_DLLVAR unsigned char g_Parallel; H5TOOLS_DLLVAR char outBuff[]; -H5TOOLS_DLLVAR int outBuffOffset; +H5TOOLS_DLLVAR unsigned outBuffOffset; H5TOOLS_DLLVAR FILE * overflow_file; /* Maximum size used in a call to malloc for a dataset */ @@ -119,10 +119,10 @@ typedef struct find_objs_t { table_t *dset_table; } find_objs_t; -H5TOOLS_DLLVAR int h5tools_nCols; /*max number of columns for outputting */ +H5TOOLS_DLLVAR unsigned h5tools_nCols; /*max number of columns for outputting */ /* Definitions of useful routines */ -H5TOOLS_DLL void indentation(int); +H5TOOLS_DLL void indentation(unsigned); H5TOOLS_DLL void print_version(const char *progname); H5TOOLS_DLL void parallel_print(const char* format, ... ); H5TOOLS_DLL void error_msg(const char *fmt, ...); |