diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2011-05-12 17:23:43 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2011-05-12 17:23:43 (GMT) |
commit | a56750c9b597a737de208d9dba0133cafe0a0a68 (patch) | |
tree | c1c679fd82c811693d0452f2178600729c9551c0 /tools | |
parent | 83703a978470d7e25a1b3ea17b2b03a8615a60e9 (diff) | |
download | hdf5-a56750c9b597a737de208d9dba0133cafe0a0a68.zip hdf5-a56750c9b597a737de208d9dba0133cafe0a0a68.tar.gz hdf5-a56750c9b597a737de208d9dba0133cafe0a0a68.tar.bz2 |
[svn-r20802] Bring trunk revision 20798 to 1.8. Trunk changes passed overnight.
Tested: local linux
Diffstat (limited to 'tools')
-rw-r--r-- | tools/h5dump/CMakeLists.txt | 27 | ||||
-rw-r--r-- | tools/h5dump/h5dump.c | 10 | ||||
-rw-r--r-- | tools/h5jam/CMakeLists.txt | 35 | ||||
-rw-r--r-- | tools/h5jam/h5jam.c | 440 | ||||
-rw-r--r-- | tools/h5jam/h5unjam.c | 179 | ||||
-rw-r--r-- | tools/h5jam/testfiles/h5jam-help.txt | 9 | ||||
-rw-r--r-- | tools/h5jam/testfiles/h5unjam-help.txt | 7 | ||||
-rw-r--r-- | tools/h5stat/CMakeLists.txt | 6 | ||||
-rw-r--r-- | tools/h5stat/h5stat.c | 102 | ||||
-rw-r--r-- | tools/lib/h5tools.c | 136 | ||||
-rw-r--r-- | tools/lib/h5tools_str.c | 8 | ||||
-rw-r--r-- | tools/testfiles/h5dump-help.txt | 94 |
12 files changed, 688 insertions, 365 deletions
diff --git a/tools/h5dump/CMakeLists.txt b/tools/h5dump/CMakeLists.txt index 9da1203..a176ba0 100644 --- a/tools/h5dump/CMakeLists.txt +++ b/tools/h5dump/CMakeLists.txt @@ -216,6 +216,7 @@ IF (BUILD_TESTING) tvlstr.h5.xml ) SET (HDF5_REFERENCE_TEST_FILES + h5dump-help.txt tbin1.ddl tbin1.ddl tbin2.ddl @@ -475,6 +476,29 @@ IF (BUILD_TESTING) ############################################################################## ############################################################################## + MACRO (ADD_HELP_TEST testname resultcode) + # If using memchecker add tests without using scripts + IF (HDF5_ENABLE_USING_MEMCHECKER) + ADD_TEST (NAME H5DUMP-${testname} COMMAND $<TARGET_FILE:h5dump> ${ARGN}) + ELSE (HDF5_ENABLE_USING_MEMCHECKER) + ADD_TEST ( + NAME H5DUMP-${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:h5dump>" + -D "TEST_ARGS:STRING=${ARGN}" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_OUTPUT=h5dump-${testname}.out" + -D "TEST_EXPECT=${resultcode}" + -D "TEST_REFERENCE=h5dump-${testname}.txt" + -P "${HDF5_RESOURCES_DIR}/runTest.cmake" + ) + ENDIF (HDF5_ENABLE_USING_MEMCHECKER) + IF (NOT "${last_test}" STREQUAL "") + SET_TESTS_PROPERTIES (H5DUMP-${testname} PROPERTIES DEPENDS ${last_test}) + ENDIF (NOT "${last_test}" STREQUAL "") + SET (last_test "H5DUMP-${testname}") + ENDMACRO (ADD_HELP_TEST) + MACRO (ADD_SKIP_H5_TEST skipresultfile skipresultcode testtype) IF (${testtype} STREQUAL "SKIP") IF (NOT HDF5_ENABLE_USING_MEMCHECKER) @@ -616,6 +640,7 @@ IF (BUILD_TESTING) NAME H5DUMP-clearall-objects COMMAND ${CMAKE_COMMAND} -E remove + h5dump-help.out filter_fail.out filter_fail.out.err packedbits.out @@ -854,6 +879,8 @@ IF (BUILD_TESTING) ENDIF (NOT "${last_test}" STREQUAL "") SET (last_test "H5DUMP-clearall-objects") + ADD_HELP_TEST(help 0 -h) + # test for signed/unsigned datasets ADD_H5_TEST (packedbits 0 packedbits.h5) # test for displaying groups diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index 41a0bcc..d4d9543 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -4635,7 +4635,6 @@ main(int argc, const char *argv[]) /* Initialize h5tools lib */ h5tools_init(); if((hand = parse_command_line(argc, argv))==NULL) { - h5tools_setstatus(EXIT_FAILURE); goto done; } @@ -4844,13 +4843,16 @@ main(int argc, const char *argv[]) /* Free tables for objects */ table_list_free(); + if(hand) + free_handler(hand, argc); + + if(fid >=0) if (H5Fclose(fid) < 0) h5tools_setstatus(EXIT_FAILURE); - if(hand) - free_handler(hand, argc); - + if(prefix) HDfree(prefix); + if(fname) HDfree(fname); /* To Do: clean up XML table */ diff --git a/tools/h5jam/CMakeLists.txt b/tools/h5jam/CMakeLists.txt index 979a1f3..d83c24e 100644 --- a/tools/h5jam/CMakeLists.txt +++ b/tools/h5jam/CMakeLists.txt @@ -56,6 +56,8 @@ IF (BUILD_TESTING) u511.txt u512.txt u513.txt + h5jam-help.txt + h5unjam-help.txt ) SET (HDF5_REFERENCE_TEST_FILES tall.h5 @@ -92,6 +94,37 @@ IF (BUILD_TESTING) ############################################################################## ############################################################################## + MACRO (ADD_HELP_TEST testname resultcode) + # If using memchecker add tests without using scripts + IF (HDF5_ENABLE_USING_MEMCHECKER) + ADD_TEST (NAME H5JAM-${testname} COMMAND $<TARGET_FILE:h5jam> ${ARGN}) + ADD_TEST (NAME H5JAM-UNJAM-${testname} COMMAND $<TARGET_FILE:h5unjam> ${ARGN}) + ELSE (HDF5_ENABLE_USING_MEMCHECKER) + ADD_TEST ( + NAME H5JAM-${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:h5jam>" + -D "TEST_ARGS=${ARGN}" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_OUTPUT=h5jam-${testname}.out" + -D "TEST_EXPECT=${resultcode}" + -D "TEST_REFERENCE=h5jam-${testname}.txt" + -P "${HDF5_RESOURCES_DIR}/runTest.cmake" + ) + ADD_TEST ( + NAME H5JAM-UNJAM-${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:h5unjam>" + -D "TEST_ARGS=${ARGN}" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_OUTPUT=h5unjam-${testname}.out" + -D "TEST_EXPECT=${resultcode}" + -D "TEST_REFERENCE=h5unjam-${testname}.txt" + -P "${HDF5_RESOURCES_DIR}/runTest.cmake" + ) + ENDIF (HDF5_ENABLE_USING_MEMCHECKER) + ENDMACRO (ADD_HELP_TEST) + MACRO (CLEANUP testname) ADD_TEST ( NAME H5JAM-CLEANUP-${testname}-clear-objects @@ -309,6 +342,8 @@ IF (BUILD_TESTING) ############################################################################## ############################################################################## + ADD_HELP_TEST(help 0 -h) + JAMTEST (tall_u10 u10.txt tall.h5 ta2.h5) CHECKFILE (tall_u10 tall.h5 ta2.h5) # CLEANUP (tall_u10 ta2.h5) diff --git a/tools/h5jam/h5jam.c b/tools/h5jam/h5jam.c index 5eaa26a..b300583 100644 --- a/tools/h5jam/h5jam.c +++ b/tools/h5jam/h5jam.c @@ -38,14 +38,14 @@ char *ub_file = NULL; * parameters. The long-named ones can be partially spelled. When * adding more, make sure that they don't clash with each other. */ -static const char *s_opts = "hi:u:o:c:V"; /* add more later ? */ +static const char *s_opts = "hi:u:o:c:V"; /* add more later ? */ static struct long_options l_opts[] = { {"help", no_arg, 'h'}, {"hel", no_arg, 'h'}, - {"i", require_arg, 'i'}, /* input file */ - {"u", require_arg, 'u'}, /* user block file */ - {"o", require_arg, 'o'}, /* output file */ - {"clobber", no_arg, 'c'}, /* clobber existing UB */ + {"i", require_arg, 'i'}, /* input file */ + {"u", require_arg, 'u'}, /* user block file */ + {"o", require_arg, 'o'}, /* output file */ + {"clobber", no_arg, 'c'}, /* clobber existing UB */ {"clobbe", no_arg, 'c'}, {"clobb", no_arg, 'c'}, {"clob", no_arg, 'c'}, @@ -72,11 +72,11 @@ usage (const char *prog) { fflush (stdout); fprintf (stdout, - "usage: %s -u user_block_file -i h5_file [-o ofile | --clobber] \n", - prog); + "usage: %s -u user_block_file -i h5_file [-o ofile | --clobber] \n", + prog); fprintf (stdout, " Add 'user_block_file' to front of \n"); fprintf (stdout, - " 'h5_file', pad so 'h5_file' starts on proper\n"); + " 'h5_file', pad so 'h5_file' starts on proper\n"); fprintf (stdout, " byte.\n"); fprintf (stdout, "\n"); fprintf (stdout, " %s -h \n", prog); @@ -86,6 +86,31 @@ usage (const char *prog) } + +/*------------------------------------------------------------------------- + * Function: leave + * + * Purpose: Shutdown and call exit() + * + * Return: Does not return + * + *------------------------------------------------------------------------- + */ +static void +leave(int ret) +{ + if (ub_file) + HDfree (ub_file); + if (input_file) + HDfree (input_file); + if (output_file) + HDfree (output_file); + + h5tools_close(); + + exit(ret); +} + /*------------------------------------------------------------------------- * Function: parse_command_line * @@ -111,30 +136,30 @@ parse_command_line (int argc, const char *argv[]) while ((opt = get_option (argc, argv, s_opts, l_opts)) != EOF) { switch ((char) opt) - { - case 'o': - output_file = HDstrdup (opt_arg); - break; - case 'i': - input_file = HDstrdup (opt_arg); - break; - case 'u': - ub_file = HDstrdup (opt_arg); - break; - case 'c': - do_clobber = TRUE; - break; - case 'h': - usage (h5tools_getprogname()); - exit (EXIT_SUCCESS); - case 'V': - print_version (h5tools_getprogname()); - exit (EXIT_SUCCESS); - case '?': - default: - usage (h5tools_getprogname()); - exit (EXIT_FAILURE); - } + { + case 'o': + output_file = HDstrdup (opt_arg); + break; + case 'i': + input_file = HDstrdup (opt_arg); + break; + case 'u': + ub_file = HDstrdup (opt_arg); + break; + case 'c': + do_clobber = TRUE; + break; + case 'h': + usage (h5tools_getprogname()); + leave (EXIT_SUCCESS); + case 'V': + print_version (h5tools_getprogname()); + leave (EXIT_SUCCESS); + case '?': + default: + usage (h5tools_getprogname()); + leave (EXIT_FAILURE); + } } } @@ -155,204 +180,197 @@ parse_command_line (int argc, const char *argv[]) int main (int argc, const char *argv[]) { - int ufid; - int h5fid; - int ofid; - void *edata; - H5E_auto2_t func; - hid_t ifile; - hid_t plist; - herr_t status; - htri_t testval; - hsize_t usize; - hsize_t h5fsize; - hsize_t startub; - hsize_t where; - hsize_t newubsize; - off_t fsize; - h5_stat_t sbuf; - h5_stat_t sbuf2; - int res; - - h5tools_setprogname(PROGRAMNAME); - h5tools_setstatus(EXIT_SUCCESS); - - /* Disable error reporting */ - H5Eget_auto2(H5E_DEFAULT, &func, &edata); - H5Eset_auto2(H5E_DEFAULT, NULL, NULL); - - parse_command_line (argc, argv); - - if (ub_file == NULL) - { - /* no user block */ - error_msg("no user block file name\n"); - usage (h5tools_getprogname()); - exit (EXIT_FAILURE); + int ufid = -1; + int h5fid = -1; + int ofid = -1; + void *edata; + H5E_auto2_t func; + hid_t ifile = -1; + hid_t plist = -1; + herr_t status; + htri_t testval; + hsize_t usize; + hsize_t h5fsize; + hsize_t startub; + hsize_t where; + hsize_t newubsize; + off_t fsize; + h5_stat_t sbuf; + h5_stat_t sbuf2; + int res; + + h5tools_setprogname(PROGRAMNAME); + h5tools_setstatus(EXIT_SUCCESS); + + /* Disable error reporting */ + H5Eget_auto2(H5E_DEFAULT, &func, &edata); + H5Eset_auto2(H5E_DEFAULT, NULL, NULL); + + parse_command_line (argc, argv); + + if (ub_file == NULL) { + /* no user block */ + error_msg("no user block file name\n"); + usage (h5tools_getprogname()); + leave (EXIT_FAILURE); } - if (input_file == NULL) - { - /* no user block */ - error_msg("no HDF5 file\n"); - usage (h5tools_getprogname()); - exit (EXIT_FAILURE); + if (input_file == NULL) { + /* no user block */ + error_msg("no HDF5 file\n"); + usage (h5tools_getprogname()); + leave (EXIT_FAILURE); } - testval = H5Fis_hdf5 (input_file); + testval = H5Fis_hdf5 (input_file); - if (testval <= 0) - { - error_msg("Input HDF5 file is not HDF \"%s\"\n", input_file); - exit (EXIT_FAILURE); + if (testval <= 0) { + error_msg("Input HDF5 file is not HDF \"%s\"\n", input_file); + leave (EXIT_FAILURE); } - ifile = H5Fopen (input_file, H5F_ACC_RDONLY, H5P_DEFAULT); + ifile = H5Fopen (input_file, H5F_ACC_RDONLY, H5P_DEFAULT); - if (ifile < 0) - { - error_msg("Can't open input HDF5 file \"%s\"\n", input_file); - exit (EXIT_FAILURE); + if (ifile < 0) { + error_msg("Can't open input HDF5 file \"%s\"\n", input_file); + leave (EXIT_FAILURE); } - plist = H5Fget_create_plist (ifile); - if (plist < 0) - { - error_msg("Can't get file creation plist for file \"%s\"\n", - input_file); - exit (EXIT_FAILURE); + plist = H5Fget_create_plist (ifile); + if (plist < 0) { + error_msg("Can't get file creation plist for file \"%s\"\n", input_file); + H5Fclose(ifile); + leave (EXIT_FAILURE); } - status = H5Pget_userblock (plist, &usize); - if (status < 0) - { - error_msg("Can't get user block for file \"%s\"\n", - input_file); - exit (EXIT_FAILURE); + status = H5Pget_userblock (plist, &usize); + if (status < 0) { + error_msg("Can't get user block for file \"%s\"\n", input_file); + H5Pclose(plist); + H5Fclose(ifile); + leave (EXIT_FAILURE); } - H5Pclose(plist); - H5Fclose(ifile); + H5Pclose(plist); + H5Fclose(ifile); - ufid = HDopen(ub_file, O_RDONLY, 0); - if(ufid < 0) { - error_msg("unable to open user block file \"%s\"\n", - ub_file); - exit (EXIT_FAILURE); + ufid = HDopen(ub_file, O_RDONLY, 0); + if(ufid < 0) { + error_msg("unable to open user block file \"%s\"\n", ub_file); + leave (EXIT_FAILURE); } - res = HDfstat(ufid, &sbuf); - if(res < 0) { - error_msg("Can't stat file \"%s\"\n", ub_file); - exit (EXIT_FAILURE); + res = HDfstat(ufid, &sbuf); + if(res < 0) { + error_msg("Can't stat file \"%s\"\n", ub_file); + HDclose (ufid); + leave (EXIT_FAILURE); } - fsize = sbuf.st_size; + fsize = sbuf.st_size; - h5fid = HDopen(input_file, O_RDONLY, 0); - if(h5fid < 0) { - error_msg("unable to open HDF5 file for read \"%s\"\n", - input_file); - exit (EXIT_FAILURE); + h5fid = HDopen(input_file, O_RDONLY, 0); + if(h5fid < 0) { + error_msg("unable to open HDF5 file for read \"%s\"\n", input_file); + HDclose (ufid); + leave (EXIT_FAILURE); } - res = HDfstat(h5fid, &sbuf2); - if(res < 0) { - error_msg("Can't stat file \"%s\"\n", input_file); - exit (EXIT_FAILURE); + res = HDfstat(h5fid, &sbuf2); + if(res < 0) { + error_msg("Can't stat file \"%s\"\n", input_file); + HDclose (h5fid); + HDclose (ufid); + leave (EXIT_FAILURE); } - h5fsize = sbuf2.st_size; + h5fsize = sbuf2.st_size; - if (output_file == NULL) - { - ofid = HDopen (input_file, O_WRONLY, 0); - - if (ofid < 0) - { - error_msg("unable to open output file \"%s\"\n", - output_file); - exit (EXIT_FAILURE); - } + if (output_file == NULL) { + ofid = HDopen (input_file, O_WRONLY, 0); + + if (ofid < 0) { + error_msg("unable to open output file \"%s\"\n", output_file); + HDclose (h5fid); + HDclose (ufid); + leave (EXIT_FAILURE); + } } - else - { - ofid = HDopen (output_file, O_WRONLY | O_CREAT | O_TRUNC, 0644); - - if (ofid < 0) - { - error_msg("unable to create output file \"%s\"\n", - output_file); - exit (EXIT_FAILURE); - } + else { + ofid = HDopen (output_file, O_WRONLY | O_CREAT | O_TRUNC, 0644); + + if (ofid < 0) { + error_msg("unable to create output file \"%s\"\n", output_file); + HDclose (h5fid); + HDclose (ufid); + leave (EXIT_FAILURE); + } } - newubsize = compute_user_block_size ((hsize_t) fsize); - - startub = usize; - - if (usize > 0) - { - if (do_clobber == TRUE) - { - /* where is max of the current size or the new UB */ - if (usize > newubsize) - { - newubsize = usize; - } - startub = 0; /*blast the old */ - } - else - { - /* add new ub to current ublock, pad to new offset */ - newubsize += usize; - newubsize = compute_user_block_size ((hsize_t) newubsize); - } + newubsize = compute_user_block_size ((hsize_t) fsize); + + startub = usize; + + if (usize > 0) { + if (do_clobber == TRUE) { + /* where is max of the current size or the new UB */ + if (usize > newubsize) { + newubsize = usize; + } + startub = 0; /*blast the old */ + } + else { + /* add new ub to current ublock, pad to new offset */ + newubsize += usize; + newubsize = compute_user_block_size ((hsize_t) newubsize); + } } - /* copy the HDF5 from starting at usize to starting at newubsize: - * makes room at 'from' for new ub */ - /* if no current ub, usize is 0 */ - copy_some_to_file (h5fid, ofid, usize, newubsize, - (ssize_t) (h5fsize - usize)); + /* copy the HDF5 from starting at usize to starting at newubsize: + * makes room at 'from' for new ub */ + /* if no current ub, usize is 0 */ + copy_some_to_file (h5fid, ofid, usize, newubsize, (ssize_t) (h5fsize - usize)); - /* copy the old ub to the beginning of the new file */ - if (!do_clobber) - { - where = - copy_some_to_file (h5fid, ofid, (hsize_t) 0, (hsize_t) 0, - (ssize_t) usize); + /* copy the old ub to the beginning of the new file */ + if (!do_clobber) { + where = copy_some_to_file (h5fid, ofid, (hsize_t) 0, (hsize_t) 0, (ssize_t) usize); } - /* copy the new ub to the end of the ub */ - where = copy_some_to_file (ufid, ofid, (hsize_t) 0, startub, (ssize_t) - 1); - - /* pad the ub */ - where = write_pad (ofid, where); + /* copy the new ub to the end of the ub */ + where = copy_some_to_file (ufid, ofid, (hsize_t) 0, startub, (ssize_t) - 1); + /* pad the ub */ + where = write_pad (ofid, where); - HDclose (ufid); - HDclose (h5fid); - HDclose (ofid); + if (ub_file) + HDfree (ub_file); + if (input_file) + HDfree (input_file); + if (output_file) + HDfree (output_file); + + if (ufid >= 0) HDclose (ufid); + if (h5fid >= 0) HDclose (h5fid); + if (ofid >= 0) HDclose (ofid); - return h5tools_getstatus(); + return h5tools_getstatus(); } /*------------------------------------------------------------------------- * Function: copy_some_to_file * * Purpose: Copy part of the input file to output. - * infid: fd of file to read - * outfid: fd of file to write - * startin: offset of where to read from infid - * startout: offset of where to write to outfid - * limit: bytes to read/write + * infid: fd of file to read + * outfid: fd of file to write + * startin: offset of where to read from infid + * startout: offset of where to write to outfid + * limit: bytes to read/write * - * If limit is < 0, the entire input file is copied. + * If limit is < 0, the entire input file is copied. * - * Note: this routine can be used to copy within - * the same file, i.e., infid and outfid can be the - * same file. + * Note: this routine can be used to copy within + * the same file, i.e., infid and outfid can be the + * same file. * * Return: Success: last byte written in the output. * Failure: Exits program with EXIT_FAILURE value. @@ -365,7 +383,7 @@ main (int argc, const char *argv[]) */ hsize_t copy_some_to_file (int infid, int outfid, hsize_t startin, hsize_t startout, - ssize_t limit) + ssize_t limit) { char buf[1024]; h5_stat_t sbuf; @@ -390,9 +408,9 @@ copy_some_to_file (int infid, int outfid, hsize_t startin, hsize_t startout, if(limit < 0) { res = HDfstat(infid, &sbuf); if(res < 0) { - error_msg("Can't stat file \n"); - exit (EXIT_FAILURE); - } + error_msg("Can't stat file \n"); + exit (EXIT_FAILURE); + } howmuch = sbuf.st_size; } @@ -424,19 +442,19 @@ copy_some_to_file (int infid, int outfid, hsize_t startin, hsize_t startout, HDlseek (infid, (off_t) from, SEEK_SET); if (howmuch > 512) - { - nchars = HDread (infid, buf, (unsigned) 512); - } + { + nchars = HDread (infid, buf, (unsigned) 512); + } else - { - nchars = HDread (infid, buf, (unsigned)howmuch); - } + { + nchars = HDread (infid, buf, (unsigned)howmuch); + } if (nchars <= 0) - { - printf ("huh? \n"); - exit (EXIT_FAILURE); - } + { + printf ("huh? \n"); + exit (EXIT_FAILURE); + } /*ncw = */ HDwrite (outfid, buf, (unsigned) nchars); /* assert (ncw == nchars) */ @@ -444,15 +462,15 @@ copy_some_to_file (int infid, int outfid, hsize_t startin, hsize_t startout, tot += nchars; howmuch -= nchars; if (howmuch > 512) - { - to -= nchars; - from -= nchars; - } + { + to -= nchars; + from -= nchars; + } else - { - to -= howmuch; - from -= howmuch; - } + { + to -= howmuch; + from -= howmuch; + } } /* assert howmuch == 0 */ @@ -467,10 +485,10 @@ copy_some_to_file (int infid, int outfid, hsize_t startin, hsize_t startout, * * Purpose: Find the offset of the HDF5 header after the user block: * align at 0, 512, 1024, etc. - * ublock_size: the size of the user block (bytes). + * ublock_size: the size of the user block (bytes). * * Return: Success: the location of the header == the size of the - * padded user block. + * padded user block. * Failure: none * * Return: Success: last byte written in the output. @@ -520,6 +538,6 @@ write_pad(int ofile, hsize_t where) for(i = 0; i < psize; i++) HDwrite (ofile, buf, 1); - return(where + psize); /* the new size of the file. */ + return(where + psize); /* the new size of the file. */ } diff --git a/tools/h5jam/h5unjam.c b/tools/h5jam/h5unjam.c index bfebc6c..d3b36a9 100644 --- a/tools/h5jam/h5unjam.c +++ b/tools/h5jam/h5unjam.c @@ -42,10 +42,10 @@ static const char *s_opts = "hu:i:o:d:V"; static struct long_options l_opts[] = { { "help", no_arg, 'h' }, { "hel", no_arg, 'h' }, - {"i", require_arg, 'i'}, /* input file */ - {"u", require_arg, 'u'}, /* user block file */ - {"o", require_arg, 'o'}, /* output file */ - {"delete", no_arg, 'd'}, /* delete ub */ + {"i", require_arg, 'i'}, /* input file */ + {"u", require_arg, 'u'}, /* user block file */ + {"o", require_arg, 'o'}, /* output file */ + {"delete", no_arg, 'd'}, /* delete ub */ {"delet", no_arg, 'd'}, {"dele", no_arg, 'd'}, {"del", no_arg, 'd'}, @@ -81,6 +81,30 @@ usage(const char *prog) } /*------------------------------------------------------------------------- + * Function: leave + * + * Purpose: Shutdown and call exit() + * + * Return: Does not return + * + *------------------------------------------------------------------------- + */ +static void +leave(int ret) +{ + if (ub_file) + HDfree (ub_file); + if (input_file) + HDfree (input_file); + if (output_file) + HDfree (output_file); + + h5tools_close(); + + exit(ret); +} + +/*------------------------------------------------------------------------- * Function: parse_command_line * * Purpose: Parse the command line for the h5dumper. @@ -99,33 +123,33 @@ usage(const char *prog) static void parse_command_line(int argc, const char *argv[]) { - int opt = FALSE; + int opt = FALSE; /* parse command line options */ while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) { - switch ((char)opt) { - case 'o': - output_file = HDstrdup (opt_arg); - break; - case 'i': - input_file = HDstrdup (opt_arg); - break; - case 'u': - ub_file = HDstrdup (opt_arg); - break; - case 'd': - do_delete = TRUE; - break; - case 'h': - usage(h5tools_getprogname()); - exit(EXIT_SUCCESS); - case 'V': - print_version (h5tools_getprogname()); - exit (EXIT_SUCCESS); - case '?': - default: - usage(h5tools_getprogname()); - exit(EXIT_FAILURE); + switch ((char) opt) { + case 'o': + output_file = HDstrdup (opt_arg); + break; + case 'i': + input_file = HDstrdup (opt_arg); + break; + case 'u': + ub_file = HDstrdup (opt_arg); + break; + case 'd': + do_delete = TRUE; + break; + case 'h': + usage(h5tools_getprogname()); + leave(EXIT_SUCCESS); + case 'V': + print_version(h5tools_getprogname()); + leave(EXIT_SUCCESS); + case '?': + default: + usage(h5tools_getprogname()); + leave(EXIT_FAILURE); } } @@ -156,19 +180,19 @@ parse_command_line(int argc, const char *argv[]) int main(int argc, const char *argv[]) { - int ifid; - int ufid; - int h5fid; + int ifid = -1; + int ufid = -1; + int h5fid = -1; void *edata; - H5E_auto2_t func; - hid_t ifile; - off_t fsize; - hsize_t usize; - htri_t testval; - herr_t status; - hid_t plist; - int res; - h5_stat_t sbuf; + H5E_auto2_t func; + hid_t ifile = -1; + hid_t plist = -1; + off_t fsize; + hsize_t usize; + htri_t testval; + herr_t status; + int res; + h5_stat_t sbuf; h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); @@ -183,63 +207,75 @@ main(int argc, const char *argv[]) if (testval <= 0) { error_msg("Input HDF5 file is not HDF \"%s\"\n", input_file); - exit(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto done; } ifile = H5Fopen(input_file, H5F_ACC_RDONLY , H5P_DEFAULT); if (ifile < 0) { error_msg("Can't open input HDF5 file \"%s\"\n", input_file); - exit(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto done; } plist = H5Fget_create_plist(ifile); if (plist < 0) { error_msg("Can't get file creation plist for file \"%s\"\n", input_file); - exit(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto done; } - status = H5Pget_userblock(plist, & usize ); + status = H5Pget_userblock(plist, & usize); if (status < 0) { error_msg("Can't get user block for file \"%s\"\n", input_file); - exit(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto done; } + H5Pclose(plist); + H5Fclose(ifile); + if (usize == 0) { - /* no user block to remove: message? */ + /* no user block to remove: message? */ error_msg("\"%s\" has no user block: no change to file\n", input_file); - exit(EXIT_SUCCESS); - + h5tools_setstatus(EXIT_SUCCESS); + goto done; } ifid = HDopen(input_file,O_RDONLY,0); if(ifid < 0) { error_msg("unable to open input HDF5 file \"%s\"\n", input_file); - exit(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto done; } res = HDfstat(ifid, &sbuf); if(res < 0) { error_msg("Can't stat file \"%s\"\n", input_file); - exit(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto done; } fsize = sbuf.st_size; if (do_delete && (ub_file != NULL)) { - error_msg("??\"%s\"\n", ub_file); - exit(EXIT_FAILURE); + error_msg("??\"%s\"\n", ub_file); + h5tools_setstatus(EXIT_FAILURE); + goto done; } if (ub_file == NULL) { - /* write to sdtout */ - ufid = HDdup(1); - } else { + /* write to sdtout */ + ufid = HDdup(1); + } + else { ufid = HDopen(ub_file,O_WRONLY|O_CREAT|O_TRUNC, 0644 ); if (ufid < 0) { error_msg("unable to open user block file for output\"%s\"\n", ub_file); - exit(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto done; } } @@ -248,23 +284,27 @@ main(int argc, const char *argv[]) if (h5fid < 0) { error_msg("unable to open output HDF5 file \"%s\"\n", input_file); - exit(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto done; } - } else { + } + else { h5fid = HDopen(output_file,O_WRONLY|O_CREAT|O_TRUNC, 0644 ); if (h5fid < 0) { error_msg("unable to open output HDF5 file \"%s\"\n", output_file); - exit(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto done; } } /* copy from 0 to 'usize - 1' into ufid */ if (!do_delete) { - if(copy_to_file(ifid, ufid, 0, (ssize_t) usize) < 0) { + if(copy_to_file(ifid, ufid, 0, (ssize_t) usize) < 0) { error_msg("unable to copy user block to output file \"%s\"\n", ub_file); - exit(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto done; } } @@ -273,13 +313,22 @@ main(int argc, const char *argv[]) */ if(copy_to_file(ifid, h5fid, (ssize_t) usize, (ssize_t)(fsize - (ssize_t)usize)) < 0) { error_msg("unable to copy hdf5 data to output file \"%s\"\n", output_file); - exit(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto done; } +done: + if (ub_file) { + HDfree (ub_file); + if (ufid >= 0) HDclose(ufid); + } + if (input_file) + HDfree (input_file); + if (output_file) + HDfree (output_file); - HDclose(ufid); - HDclose(h5fid); - HDclose(ifid); + if (h5fid >= 0) HDclose(h5fid); + if (ifid >= 0) HDclose(ifid); return h5tools_getstatus(); } diff --git a/tools/h5jam/testfiles/h5jam-help.txt b/tools/h5jam/testfiles/h5jam-help.txt new file mode 100644 index 0000000..f5d1f19 --- /dev/null +++ b/tools/h5jam/testfiles/h5jam-help.txt @@ -0,0 +1,9 @@ +usage: h5jam -u user_block_file -i h5_file [-o ofile | --clobber] + Add 'user_block_file' to front of + 'h5_file', pad so 'h5_file' starts on proper + byte. + + h5jam -h + Print a usage message and exit + h5jam -V + Print HDF5 library version and exit diff --git a/tools/h5jam/testfiles/h5unjam-help.txt b/tools/h5jam/testfiles/h5unjam-help.txt new file mode 100644 index 0000000..3eb73c5 --- /dev/null +++ b/tools/h5jam/testfiles/h5unjam-help.txt @@ -0,0 +1,7 @@ +usage: h5unjam -i h5_file -o user_block_file_out -o h5_file_out [-d | --delete] + Extract user block from 'h5_file' into 'user_block_file' + and HDF5 file into 'h5_file_out' + h5unjam -h + Print a usage message and exit + h5unjam -V + Print HDF5 library version and exit diff --git a/tools/h5stat/CMakeLists.txt b/tools/h5stat/CMakeLists.txt index 86ad3ad..89f2ba0 100644 --- a/tools/h5stat/CMakeLists.txt +++ b/tools/h5stat/CMakeLists.txt @@ -155,12 +155,6 @@ IF (BUILD_TESTING) ENDIF (NOT "${last_test}" STREQUAL "") SET (last_test "H5STAT-clearall-objects") - # If using memchecker add tests without using scripts - IF (HDF5_ENABLE_USING_MEMCHECKER) - ADD_TEST (NAME H5STAT-help COMMAND h5stat -h) - ADD_TEST (NAME H5STAT-filters COMMAND h5stat h5stat_filters.h5) - ENDIF (HDF5_ENABLE_USING_MEMCHECKER) - # Test for help flag ADD_H5_TEST (h5stat_help1 0 -h) ADD_H5_TEST (h5stat_help2 0 --help) diff --git a/tools/h5stat/h5stat.c b/tools/h5stat/h5stat.c index 57b1ce0..c58a9ef 100644 --- a/tools/h5stat/h5stat.c +++ b/tools/h5stat/h5stat.c @@ -716,21 +716,47 @@ static struct handler_t * parse_command_line(int argc, const char *argv[]) { int opt, i; - struct handler_t *hand; + struct handler_t *hand = NULL; /* Allocate space to hold the command line info */ - hand = (struct handler_t *)calloc((size_t)argc, sizeof(struct handler_t)); + if((hand = (struct handler_t *)calloc((size_t)argc, sizeof(struct handler_t)))==NULL) { + error_msg("unable to parse command line arguments \n"); + goto error; + } /* parse command line options */ while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) { switch ((char)opt) { case 'h': usage(h5tools_getprogname()); - leave(EXIT_SUCCESS); + h5tools_setstatus(EXIT_SUCCESS); + if (hand) { + for (i = 0; i < argc; i++) + if(hand[i].obj) { + free(hand[i].obj); + hand[i].obj=NULL; + } + + free(hand); + hand = NULL; + } + goto done; + break; case 'V': print_version(h5tools_getprogname()); - leave(EXIT_SUCCESS); + h5tools_setstatus(EXIT_SUCCESS); + if (hand) { + for (i = 0; i < argc; i++) + if(hand[i].obj) { + free(hand[i].obj); + hand[i].obj=NULL; + } + + free(hand); + hand = NULL; + } + goto done; break; case 'F': @@ -784,7 +810,8 @@ parse_command_line(int argc, const char *argv[]) default: usage(h5tools_getprogname()); - leave(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto error; } /* end switch */ } /* end while */ @@ -792,11 +819,28 @@ parse_command_line(int argc, const char *argv[]) if (argc <= opt_ind) { error_msg("missing file name\n"); usage(h5tools_getprogname()); - leave(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto error; } /* end if */ +done: + return hand; + +error: + if (hand) { + for (i = 0; i < argc; i++) + if(hand[i].obj) { + free(hand[i].obj); + hand[i].obj=NULL; + } + + free(hand); + hand = NULL; + } + h5tools_setstatus(EXIT_FAILURE); + return hand; -} /* parse_command_line() */ +} /*------------------------------------------------------------------------- @@ -1326,9 +1370,10 @@ main(int argc, const char *argv[]) iter_t iter; const char *fname = NULL; hid_t fid; - hid_t fcpl; /* file creation property id */ - struct handler_t *hand; + hid_t fcpl; + struct handler_t *hand = NULL; H5F_info_t finfo; + int i; h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); @@ -1338,11 +1383,9 @@ main(int argc, const char *argv[]) /* Initialize h5tools lib */ h5tools_init(); - hand = parse_command_line (argc, argv); - if(!hand) { - error_msg("unable to parse command line arguments \n"); - leave(EXIT_FAILURE); - } /* end if */ + if((hand = parse_command_line(argc, argv))==NULL) { + goto done; + } fname = argv[opt_ind]; @@ -1351,7 +1394,8 @@ main(int argc, const char *argv[]) fid = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT); if(fid < 0) { error_msg("unable to open file \"%s\"\n", fname); - leave(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + goto done; } /* end if */ /* Initialize iter structure */ @@ -1359,12 +1403,12 @@ main(int argc, const char *argv[]) /* Get storge info for SOHM's btree/list/heap and superblock extension */ if(H5Fget_info(fid, &finfo) < 0) - warn_msg("Unable to retrieve SOHM info\n"); + warn_msg("Unable to retrieve SOHM info\n"); else { - iter.super_ext_size = finfo.super_ext_size; - iter.SM_hdr_storage_size = finfo.sohm.hdr_size; - iter.SM_index_storage_size = finfo.sohm.msgs_info.index_size; - iter.SM_heap_storage_size = finfo.sohm.msgs_info.heap_size; + iter.super_ext_size = finfo.super_ext_size; + iter.SM_hdr_storage_size = finfo.sohm.hdr_size; + iter.SM_index_storage_size = finfo.sohm.msgs_info.index_size; + iter.SM_heap_storage_size = finfo.sohm.msgs_info.heap_size; } /* end else */ if((fcpl = H5Fget_create_plist(fid)) < 0) @@ -1393,13 +1437,23 @@ main(int argc, const char *argv[]) print_statistics("/", &iter); } /* end else */ - if (hand) free(hand); +done: + if(hand) { + for (i = 0; i < argc; i++) + if(hand[i].obj) { + free(hand[i].obj); + hand[i].obj=NULL; + } + + free(hand); + hand = NULL; if(H5Fclose(fid) < 0) { error_msg("unable to close file \"%s\"\n", fname); - leave(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); + } } - leave(EXIT_SUCCESS); -} /* main() */ + leave(h5tools_getstatus()); +} diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index bb951a0..2ed13d0 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -226,7 +226,7 @@ hbool_t h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, hsize_t elmt_counter); static int h5tools_print_region_data_blocks(hid_t region_id, - FILE *stream, const h5tool_format_t *info, h5tools_context_t ctx, + FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx, h5tools_str_t *buffer/*string into which to render */, size_t ncols, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata); @@ -239,7 +239,7 @@ hbool_t h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, hsize_t elmt_counter); int h5tools_print_region_data_points(hid_t region_space, hid_t region_id, - FILE *stream, const h5tool_format_t *info, h5tools_context_t ctx, + 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); @@ -851,8 +851,7 @@ h5tools_region_simple_prefix(FILE *stream, const h5tool_format_t *info, } /* Calculate new prefix */ - h5tools_str_region_prefix(&prefix, info, elmtno, ptdata, ctx->ndims, - ctx->p_max_idx, ctx); + 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) { @@ -1388,7 +1387,7 @@ h5tools_render_region_element(FILE *stream, const h5tool_format_t *info, */ static int h5tools_print_region_data_blocks(hid_t region_id, - FILE *stream, const h5tool_format_t *info, h5tools_context_t ctx, + FILE *stream, const h5tool_format_t *info, h5tools_context_t *cur_ctx, h5tools_str_t *buffer/*string into which to render */, size_t ncols, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata) { @@ -1401,15 +1400,22 @@ h5tools_print_region_data_blocks(hid_t region_id, hsize_t elmtno; /* elemnt index */ unsigned int region_flags; /* buffer extent flags */ hsize_t curr_pos; - int jndx; - size_t indx; + size_t jndx; + int indx; int type_size; hid_t mem_space = -1; void *region_buf = NULL; - int blkndx; + hsize_t blkndx; hid_t sid1 = -1; int ret_value = SUCCEED; + h5tools_context_t ctx; + assert(info); + assert(cur_ctx); + assert(buffer); + assert(ptdata); + + memset(&ctx, 0, sizeof(ctx)); /* Get the dataspace of the dataset */ if((sid1 = H5Dget_space(region_id)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dget_space failed"); @@ -1444,13 +1450,16 @@ h5tools_print_region_data_blocks(hid_t region_id, HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for count"); curr_pos = 0; + ctx.indent_level = cur_ctx->indent_level; + ctx.cur_column = cur_ctx->cur_column; + ctx.prev_multiline = cur_ctx->prev_multiline; + ctx.ndims = ndims; for (blkndx = 0; blkndx < nblocks; blkndx++) { - ctx.ndims = ndims; ctx.need_prefix = TRUE; ctx.cur_elmt = 0; - for (jndx = 0; jndx < ndims; jndx++) { - start[jndx] = ptdata[jndx + blkndx * ndims * 2]; - count[jndx] = dims1[jndx]; + for (indx = 0; indx < ndims; indx++) { + start[indx] = ptdata[indx + blkndx * ndims * 2]; + count[indx] = dims1[indx]; } if(H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) < 0) @@ -1483,24 +1492,24 @@ h5tools_print_region_data_blocks(hid_t region_id, h5tools_region_simple_prefix(stream, info, &ctx, curr_pos, ptdata, 0); elmtno = 0; - for (indx = 0; indx < numelem; indx++, elmtno++, ctx.cur_elmt++) { + for (jndx = 0; jndx < numelem; jndx++, elmtno++, ctx.cur_elmt++) { /* Render the region data element begin */ h5tools_str_reset(buffer); - h5tools_str_append(buffer, "%s", indx ? OPTIONAL_LINE_BREAK "" : ""); + h5tools_str_append(buffer, "%s", jndx ? OPTIONAL_LINE_BREAK "" : ""); h5tools_str_sprint(buffer, info, region_id, type_id, - ((char*)region_buf + indx * type_size), &ctx); + ((char*)region_buf + jndx * type_size), &ctx); - if (indx + 1 < numelem || (region_flags & END_OF_DATA) == 0) + if (jndx + 1 < numelem || (region_flags & END_OF_DATA) == 0) h5tools_str_append(buffer, "%s", OPT(info->elmt_suf1, ",")); dimension_break = h5tools_render_region_element(stream, info, &ctx, buffer, &curr_pos, - ncols, ptdata, indx, elmtno); + ncols, ptdata, jndx, elmtno); /* Render the region data element end */ if(FALSE == dimension_break) elmtno = 0; - } /* end for (indx = 0; indx < numelem; indx++, region_elmtno++, ctx.cur_elmt++) */ + } /* end for (jndx = 0; jndx < numelem; jndx++, region_elmtno++, ctx.cur_elmt++) */ ctx.indent_level--; } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */ @@ -1561,6 +1570,10 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, hid_t type_id; int i; + assert(info); + assert(ctx); + assert(buffer); + if((nblocks = H5Sget_select_hyper_nblocks(region_space)) <= 0) H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_hyper_nblocks failed"); @@ -1673,7 +1686,7 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, ctx->need_prefix = TRUE; - h5tools_print_region_data_blocks(region_id, rawdatastream, info, *ctx, + h5tools_print_region_data_blocks(region_id, rawdatastream, info, ctx, buffer, ncols, ndims, type_id, nblocks, ptdata); done: @@ -1732,7 +1745,7 @@ h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, */ int h5tools_print_region_data_points(hid_t region_space, hid_t region_id, - FILE *stream, const h5tool_format_t *info, h5tools_context_t ctx, + 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) { @@ -1741,82 +1754,96 @@ h5tools_print_region_data_points(hid_t region_space, hid_t region_id, hsize_t elmtno; /* elemnt index */ unsigned int region_flags; /* buffer extent flags */ hsize_t curr_pos; - size_t indx; - int jndx; + hsize_t total_size[H5S_MAX_RANK]; + int indx; + size_t jndx; int type_size; hid_t mem_space = -1; void *region_buf = NULL; int ret_value = SUCCEED; + h5tools_context_t ctx; - if((type_size = H5Tget_size(type_id)) == 0) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); - - if((region_buf = HDmalloc(type_size * npoints)) == NULL) - HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for region"); + assert(info); + assert(cur_ctx); + assert(buffer); + assert(ptdata); + memset(&ctx, 0, sizeof(ctx)); /* Allocate space for the dimension array */ 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; + + /* Create dataspace for reading buffer */ if((mem_space = H5Screate_simple(1, dims1, NULL)) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed"); + if((type_size = H5Tget_size(type_id)) == 0) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed"); + + if((region_buf = HDmalloc(type_size * npoints)) == NULL) + HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for region"); + + curr_pos = 0; + ctx.indent_level = cur_ctx->indent_level; + ctx.cur_column = cur_ctx->cur_column; + ctx.prev_multiline = cur_ctx->prev_multiline; + ctx.ndims = ndims; + if(H5Dread(region_id, type_id, mem_space, region_space, H5P_DEFAULT, region_buf) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed"); elmtno = 0; - curr_pos = 0; for (jndx = 0; jndx < npoints; jndx++, elmtno++) { - ctx.ndims = ndims; ctx.need_prefix = TRUE; ctx.cur_elmt = 0; /* points are always 0 */ - /* Render the point element begin */ - h5tools_str_reset(buffer); - ctx.indent_level++; + if(H5Sget_simple_extent_dims(mem_space, total_size, NULL) < 0) + 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++) ctx.p_min_idx[indx] = 0; - if(H5Sget_simple_extent_dims(region_space, ctx.p_max_idx, NULL) < 0) - HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); - - if (ctx.ndims > 0) { - ctx.size_last_dim = (int) (ctx.p_max_idx[ctx.ndims - 1]); - } - else - ctx.size_last_dim = 0; - - if (ctx.ndims > 0) - init_acc_pos(&ctx, ctx.p_max_idx); + init_acc_pos(&ctx, total_size); /* print the data */ region_flags = START_OF_DATA; if (jndx == npoints - 1) region_flags |= END_OF_DATA; - curr_pos = 0; /* points requires constant 0 */ + for (indx = 0; indx < (size_t)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]); + } + else + ctx.size_last_dim = 0; + curr_pos = 0; /* points requires constant 0 */ h5tools_region_simple_prefix(stream, info, &ctx, curr_pos, ptdata, 0); + /* Render the point element begin */ + h5tools_str_reset(buffer); + + h5tools_str_append(buffer, "%s", jndx ? OPTIONAL_LINE_BREAK "" : ""); h5tools_str_sprint(buffer, info, region_id, type_id, ((char*)region_buf + jndx * type_size), &ctx); if (jndx + 1 < npoints || (region_flags & END_OF_DATA) == 0) h5tools_str_append(buffer, "%s", OPT(info->elmt_suf1, ",")); - dimension_break = - h5tools_render_region_element(stream, info, &ctx, buffer, &curr_pos, - ncols, ptdata, (hsize_t)0, elmtno); + dimension_break = h5tools_render_region_element(stream, info, &ctx, buffer, &curr_pos, + ncols, ptdata, (hsize_t)0, elmtno); /* Render the point element end */ - - ctx.indent_level--; if(FALSE == dimension_break) elmtno = 0; - } /* end for (jndx = 0; jndx < npoints; jndx++, region_elmtno++) */ + + ctx.indent_level--; + } /* end for (jndx = 0; jndx < npoints; jndx++, elmtno++) */ done: HDfree(region_buf); @@ -1866,6 +1893,10 @@ h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, hid_t dtype; hid_t type_id; + assert(info); + assert(ctx); + assert(buffer); + if((npoints = H5Sget_select_elem_npoints(region_space)) <= 0) H5E_THROW(dimension_break, H5E_tools_min_id_g, "H5Sget_select_elem_npoints failed"); @@ -1975,7 +2006,7 @@ h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, ctx->need_prefix = TRUE; h5tools_print_region_data_points(region_space, region_id, - rawdatastream, info, *ctx, buffer, ncols, ndims, type_id, npoints, ptdata); + rawdatastream, info, ctx, buffer, ncols, ndims, type_id, npoints, ptdata); done: free(ptdata); @@ -4233,8 +4264,7 @@ render_bin_output_region_data_points(hid_t region_space, hid_t region_id, if(H5Sget_simple_extent_dims(region_space, dims1, NULL) < 0) HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed"); - render_bin_output(stream, container, type_id, - ((char*)region_buf + jndx * type_size)); + render_bin_output(stream, container, type_id, ((char*)region_buf + jndx * type_size)); } /* end for (jndx = 0; jndx < npoints; jndx++) */ done: diff --git a/tools/lib/h5tools_str.c b/tools/lib/h5tools_str.c index 9b7e8f2..54e2584 100644 --- a/tools/lib/h5tools_str.c +++ b/tools/lib/h5tools_str.c @@ -390,8 +390,12 @@ h5tools_str_region_prefix(h5tools_str_t *str, const h5tool_format_t *info, p_prod[i - 1] = (max_idx[i]) * p_prod[i]; for (i = 0; i < (size_t) ndims; i++) { - ctx->pos[i] = curr_pos / p_prod[i]; - curr_pos -= p_prod[i] * ctx->pos[i]; + if(curr_pos > 0) { + ctx->pos[i] = curr_pos / p_prod[i]; + curr_pos -= p_prod[i] * ctx->pos[i]; + } + else + ctx->pos[i] = 0; ctx->pos[i] += (unsigned long) ptdata[ctx->sm_pos+i]; } diff --git a/tools/testfiles/h5dump-help.txt b/tools/testfiles/h5dump-help.txt new file mode 100644 index 0000000..9083782 --- /dev/null +++ b/tools/testfiles/h5dump-help.txt @@ -0,0 +1,94 @@ +usage: h5dump [OPTIONS] file + OPTIONS + -h, --help Print a usage message and exit + -n, --contents Print a list of the file contents and exit + -B, --superblock Print the content of the super block + -H, --header Print the header only; no data is displayed + -A, --onlyattr Print the header and value of attributes + -i, --object-ids Print the object ids + -r, --string Print 1-byte integer datasets as ASCII + -e, --escape Escape non printing characters + -V, --version Print version number and exit + -a P, --attribute=P Print the specified attribute + -d P, --dataset=P Print the specified dataset + -y, --noindex Do not print array indices with the data + -p, --properties Print dataset filters, storage layout and fill value + -f D, --filedriver=D Specify which driver to open the file with + -g P, --group=P Print the specified group and all members + -l P, --soft-link=P Print the value(s) of the specified soft link + -o F, --output=F Output raw data into file F + -b B, --binary=B Binary file output, of form B + -t P, --datatype=P Print the specified named datatype + -w N, --width=N Set the number of columns of output. A value of 0 (zero) + sets the number of columns to the maximum (65535). + Default width is 80 columns. + -m T, --format=T Set the floating point output format + -q Q, --sort_by=Q Sort groups and attributes by index Q + -z Z, --sort_order=Z Sort groups and attributes by order Z + -M L, --packedbits=L Print packed bits as unsigned integers, using mask + format L for an integer dataset specified with + option -d. L is a list of offset,length values, + separated by commas. Offset is the beginning bit in + the data value and length is the number of bits of + the mask. + -R, --region Print dataset pointed by region references + -x, --xml Output in XML using Schema + -u, --use-dtd Output in XML using DTD + -D U, --xml-dtd=U Use the DTD or schema at U + -X S, --xml-ns=S (XML Schema) Use qualified names n the XML + ":": no namespace, default: "hdf5:" + E.g., to dump a file called `-f', use h5dump -- -f + --enable-error-stack Prints messages from the HDF5 error stack as they + occur. + + Subsetting is available by using the following options with a dataset + attribute. Subsetting is done by selecting a hyperslab from the data. + Thus, the options mirror those for performing a hyperslab selection. + One of the START, COUNT, STRIDE, or BLOCK parameters are mandatory if you do subsetting. + The STRIDE, COUNT, and BLOCK parameters are optional and will default to 1 in + each dimension. START is optional and will default to 0 in each dimension. + + -s START, --start=START Offset of start of subsetting selection + -S STRIDE, --stride=STRIDE Hyperslab stride + -c COUNT, --count=COUNT Number of blocks to include in selection + -k BLOCK, --block=BLOCK Size of block in hyperslab + START, COUNT, STRIDE, and BLOCK - is a list of integers the number of which are equal to the + number of dimensions in the dataspace being queried + + D - is the file driver to use in opening the file. Acceptable values + are "sec2", "family", "split", "multi", "direct", and "stream". Without + the file driver flag, the file will be opened with each driver in + turn and in the order specified above until one driver succeeds + in opening the file. + F - is a filename. + P - is the full path from the root group to the object. + N - is an integer greater than 1. + T - is a string containing the floating point format, e.g '%.3f' + U - is a URI reference (as defined in [IETF RFC 2396], + updated by [IETF RFC 2732]) + B - is the form of binary output: NATIVE for a memory type, FILE for the + file type, LE or BE for pre-existing little or big endian types. + Must be used with -o (output file) and it is recommended that + -d (dataset) is used. B is an optional argument, defaults to NATIVE + Q - is the sort index type. It can be "creation_order" or "name" (default) + Z - is the sort order type. It can be "descending" or "ascending" (default) + + Examples: + + 1) Attribute foo of the group /bar_none in file quux.h5 + + h5dump -a /bar_none/foo quux.h5 + + 2) Selecting a subset from dataset /foo in file quux.h5 + + h5dump -d /foo -s "0,1" -S "1,1" -c "2,3" -k "2,2" quux.h5 + + 3) Saving dataset 'dset' in file quux.h5 to binary file 'out.bin' + using a little-endian type + + h5dump -d /dset -b LE -o out.bin quux.h5 + + 4) Display two packed bits (bits 0-1 and bits 4-6) in the dataset /dset + + h5dump -d /dset -M 0,1,4,3 quux.h5 + |