summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2011-05-11 20:45:54 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2011-05-11 20:45:54 (GMT)
commitf49dc381271ac53a508628856787463668789772 (patch)
treed424cac8fb50120d9080086d54fd8d98a0977d03
parent2e7d42a43c60753d99d3bed37d121ca30ac5db1c (diff)
downloadhdf5-f49dc381271ac53a508628856787463668789772.zip
hdf5-f49dc381271ac53a508628856787463668789772.tar.gz
hdf5-f49dc381271ac53a508628856787463668789772.tar.bz2
[svn-r20796] Refactor print_data_region_blocks/ponts to remove context passed in by value. The print functions needed an independent context with only the current indent level passed in by argument. Also synched the two routines logical flows and corrected a mem_space error.
h5dump (and h5stat, h5jam/h5unjam) help option not tested. Added h5dump parse_command_line technique for h5stat and h5jam/unjam and created testfiles. Tested: local linux
-rw-r--r--MANIFEST5
-rw-r--r--tools/h5dump/CMakeLists.txt27
-rw-r--r--tools/h5dump/h5dump.c20
-rw-r--r--tools/h5jam/CMakeLists.txt35
-rw-r--r--tools/h5jam/h5jam.c440
-rw-r--r--tools/h5jam/h5unjam.c179
-rw-r--r--tools/h5jam/testfiles/h5jam-help.txt9
-rw-r--r--tools/h5jam/testfiles/h5unjam-help.txt7
-rw-r--r--tools/h5stat/CMakeLists.txt6
-rw-r--r--tools/h5stat/h5stat.c507
-rw-r--r--tools/lib/h5tools.c136
-rw-r--r--tools/lib/h5tools_str.c8
-rw-r--r--tools/testfiles/h5dump-help.txt94
13 files changed, 899 insertions, 574 deletions
diff --git a/MANIFEST b/MANIFEST
index d2a7b12..1be085e 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1173,6 +1173,7 @@
./tools/testfiles/packedbits.ddl
./tools/testfiles/file_space.h5
./tools/testfiles/file_space.ddl
+./tools/testfiles/h5dump-help.txt
./tools/testfiles/tall-1.ddl
./tools/testfiles/tall-2.ddl
./tools/testfiles/tall-3.ddl
@@ -1803,11 +1804,13 @@
# test files for jam
./tools/h5jam/testfiles/twithub.h5
+./tools/h5jam/testfiles/twithub513.h5
+./tools/h5jam/testfiles/h5jam-help.txt
+./tools/h5jam/testfiles/h5unjam-help.txt
./tools/h5jam/testfiles/u10.txt
./tools/h5jam/testfiles/tall.h5
./tools/h5jam/testfiles/u511.txt
./tools/h5jam/testfiles/u512.txt
-./tools/h5jam/testfiles/twithub513.h5
./tools/h5jam/testfiles/u513.txt
# test files for h5copy
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 05ec369..cfeaaef 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -4560,7 +4560,7 @@ error:
if (hand) {
free_handler(hand, argc);
hand = NULL;
-}
+ }
h5tools_setstatus(EXIT_FAILURE);
return hand;
@@ -4630,7 +4630,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;
}
@@ -4834,14 +4833,17 @@ done:
/* Free tables for objects */
table_list_free();
- if (H5Fclose(fid) < 0)
- h5tools_setstatus(EXIT_FAILURE);
-
- if(hand)
- free_handler(hand, argc);
+ if(hand)
+ free_handler(hand, argc);
- HDfree(prefix);
- HDfree(fname);
+ if(fid >=0)
+ if (H5Fclose(fid) < 0)
+ h5tools_setstatus(EXIT_FAILURE);
+
+ 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..0f63234 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=jam-${testname}.out"
+ -D "TEST_EXPECT=${resultcode}"
+ -D "TEST_REFERENCE=jam-${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=unjam-${testname}.out"
+ -D "TEST_EXPECT=${resultcode}"
+ -D "TEST_REFERENCE=unjam-${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 fd21266..b7026cc 100644
--- a/tools/h5stat/h5stat.c
+++ b/tools/h5stat/h5stat.c
@@ -15,7 +15,7 @@
#include <stdlib.h>
#include <string.h>
-#include "H5private.h" /* Generic Functions */
+#include "H5private.h" /* Generic Functions */
#include "h5tools.h"
#include "h5tools_utils.h"
#include "h5tools_ref.h"
@@ -27,7 +27,7 @@
/* Parameters to control statistics gathered */
#define SIZE_SMALL_GROUPS 10
-#define SIZE_SMALL_ATTRS 10
+#define SIZE_SMALL_ATTRS 10
#define SIZE_SMALL_DSETS 10
#define SIZE_SMALL_SECTS 10
@@ -60,7 +60,7 @@ typedef struct ohdr_info_t {
/* Info to pass to the iteration functions */
typedef struct iter_t {
hid_t fid; /* File ID */
- hsize_t filesize; /* Size of the file */
+ hsize_t filesize; /* Size of the file */
unsigned long uniq_groups; /* Number of unique groups */
unsigned long uniq_dsets; /* Number of unique datasets */
unsigned long uniq_dtypes; /* Number of unique named datatypes */
@@ -74,7 +74,7 @@ typedef struct iter_t {
unsigned long *group_bins; /* Pointer to array of bins for group counts */
ohdr_info_t group_ohdr_info; /* Object header information for groups */
- hsize_t max_attrs; /* Maximum attributes from a group */
+ hsize_t max_attrs; /* Maximum attributes from a group */
unsigned long num_small_attrs[SIZE_SMALL_ATTRS]; /* Size of small attributes tracked */
unsigned attr_nbins; /* Number of bins for attribute counts */
unsigned long *attr_bins; /* Pointer to array of bins for attribute counts */
@@ -99,14 +99,14 @@ typedef struct iter_t {
hsize_t attrs_heap_storage_size; /* fractal heap size for attributes (1.8) */
hsize_t SM_hdr_storage_size; /* header size for SOHM table (1.8) */
hsize_t SM_index_storage_size; /* index (btree & list) size for SOHM table (1.8) */
- hsize_t SM_heap_storage_size; /* fractal heap size for SOHM table (1.8) */
- hsize_t super_size; /* superblock size */
- hsize_t super_ext_size; /* superblock extension size */
- hsize_t ublk_size; /* user block size (if exists) */
- H5F_file_space_type_t fs_strategy; /* File space management strategy */
- hsize_t fs_threshold; /* Free-space section threshold */
- hsize_t free_space; /* amount of freespace in the file */
- hsize_t free_hdr; /* size of free space manager metadata in the file */
+ hsize_t SM_heap_storage_size; /* fractal heap size for SOHM table (1.8) */
+ hsize_t super_size; /* superblock size */
+ hsize_t super_ext_size; /* superblock extension size */
+ hsize_t ublk_size; /* user block size (if exists) */
+ H5F_file_space_type_t fs_strategy; /* File space management strategy */
+ hsize_t fs_threshold; /* Free-space section threshold */
+ hsize_t free_space; /* amount of freespace in the file */
+ hsize_t free_hdr; /* size of free space manager metadata in the file */
unsigned long num_small_sects[SIZE_SMALL_SECTS]; /* Size of small free-space sections */
unsigned sect_nbins; /* Number of bins for free-space section sizes */
unsigned long *sect_bins; /* Pointer to array of bins for free-space section sizes */
@@ -120,19 +120,19 @@ typedef struct iter_t {
static int display_all = TRUE;
/* Enable the printing of selected statistics */
-static int display_file = FALSE; /* display file information */
-static int display_group = FALSE; /* display groups information */
-static int display_dset = FALSE; /* display datasets information */
+static int display_file = FALSE; /* display file information */
+static int display_group = FALSE; /* display groups information */
+static int display_dset = FALSE; /* display datasets information */
static int display_dset_dtype_meta = FALSE; /* display datasets' datatype information */
-static int display_attr = FALSE; /* display attributes information */
+static int display_attr = FALSE; /* display attributes information */
static int display_free_sections = FALSE; /* display free space information */
-static int display_summary = FALSE; /* display summary of file space information */
+static int display_summary = FALSE; /* display summary of file space information */
static int display_file_metadata = FALSE; /* display file space info for file's metadata */
static int display_group_metadata = FALSE; /* display file space info for groups' metadata */
static int display_dset_metadata = FALSE; /* display file space info for datasets' metadata */
-static int display_object = FALSE; /* not implemented yet */
+static int display_object = FALSE; /* not implemented yet */
/* a structure for handling the order command-line parameters come in */
struct handler_t {
@@ -303,7 +303,7 @@ ceil_log10(unsigned long x)
static herr_t
attribute_stats(iter_t *iter, const H5O_info_t *oi)
{
- unsigned bin; /* "bin" the number of objects falls in */
+ unsigned bin; /* "bin" the number of objects falls in */
/* Update dataset & attribute metadata info */
iter->attrs_btree_storage_size += oi->meta_size.attr.index_size;
@@ -318,12 +318,12 @@ attribute_stats(iter_t *iter, const H5O_info_t *oi)
/* Add attribute count to proper bin */
bin = ceil_log10((unsigned long)oi->num_attrs);
if((bin + 1) > iter->attr_nbins) {
- iter->attr_bins = (unsigned long *)realloc(iter->attr_bins, (bin + 1) * sizeof(unsigned long));
+ iter->attr_bins = (unsigned long *)realloc(iter->attr_bins, (bin + 1) * sizeof(unsigned long));
assert(iter->attr_bins);
- /* Initialize counts for intermediate bins */
+ /* Initialize counts for intermediate bins */
while(iter->attr_nbins < bin)
- iter->attr_bins[iter->attr_nbins++] = 0;
+ iter->attr_bins[iter->attr_nbins++] = 0;
iter->attr_nbins++;
/* Initialize count for new bin */
@@ -351,23 +351,23 @@ attribute_stats(iter_t *iter, const H5O_info_t *oi)
* Modifications: Refactored code from the walk_function
* EIP, Wednesday, August 16, 2006
*
- * Vailin Choi 12 July 2007
- * 1. Gathered storage info for btree and heap
- * (groups and attributes)
- * 2. Gathered info for attributes
+ * Vailin Choi 12 July 2007
+ * 1. Gathered storage info for btree and heap
+ * (groups and attributes)
+ * 2. Gathered info for attributes
*
- * Vailin Choi 14 July 2007
- * Cast "num_objs" and "num_attrs" to size_t
- * Due to the -Mbounds problem for the pgi-32 bit compiler on indexing
+ * Vailin Choi 14 July 2007
+ * Cast "num_objs" and "num_attrs" to size_t
+ * Due to the -Mbounds problem for the pgi-32 bit compiler on indexing
*
*-------------------------------------------------------------------------
*/
static herr_t
group_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
{
- H5G_info_t ginfo; /* Group information */
- unsigned bin; /* "bin" the number of objects falls in */
- herr_t ret;
+ H5G_info_t ginfo; /* Group information */
+ unsigned bin; /* "bin" the number of objects falls in */
+ herr_t ret;
/* Gather statistics about this type of object */
iter->uniq_groups++;
@@ -393,7 +393,7 @@ group_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
iter->group_bins = (unsigned long *)realloc(iter->group_bins, (bin + 1) * sizeof(unsigned long));
assert(iter->group_bins);
- /* Initialize counts for intermediate bins */
+ /* Initialize counts for intermediate bins */
while(iter->group_nbins < bin)
iter->group_bins[iter->group_nbins++] = 0;
iter->group_nbins++;
@@ -433,22 +433,22 @@ group_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
static herr_t
dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
{
- unsigned bin; /* "bin" the number of objects falls in */
- hid_t did; /* Dataset ID */
- hid_t sid; /* Dataspace ID */
- hid_t tid; /* Datatype ID */
- hid_t dcpl; /* Dataset creation property list ID */
- hsize_t dims[H5S_MAX_RANK];/* Dimensions of dataset */
- H5D_layout_t lout; /* Layout of dataset */
- unsigned type_found; /* Whether the dataset's datatype was */
- /* already found */
- int ndims; /* Number of dimensions of dataset */
- hsize_t storage; /* Size of dataset storage */
- unsigned u; /* Local index variable */
- int num_ext; /* Number of external files for a dataset */
- int nfltr; /* Number of filters for a dataset */
- H5Z_filter_t fltr; /* Filter identifier */
- herr_t ret;
+ unsigned bin; /* "bin" the number of objects falls in */
+ hid_t did; /* Dataset ID */
+ hid_t sid; /* Dataspace ID */
+ hid_t tid; /* Datatype ID */
+ hid_t dcpl; /* Dataset creation property list ID */
+ hsize_t dims[H5S_MAX_RANK];/* Dimensions of dataset */
+ H5D_layout_t lout; /* Layout of dataset */
+ unsigned type_found; /* Whether the dataset's datatype was */
+ /* already found */
+ int ndims; /* Number of dimensions of dataset */
+ hsize_t storage; /* Size of dataset storage */
+ unsigned u; /* Local index variable */
+ int num_ext; /* Number of external files for a dataset */
+ int nfltr; /* Number of filters for a dataset */
+ H5Z_filter_t fltr; /* Filter identifier */
+ herr_t ret;
/* Gather statistics about this type of object */
iter->uniq_dsets++;
@@ -481,7 +481,7 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
/* Object header's total size for H5D_COMPACT layout includes raw data size */
/* "storage" also includes H5D_COMPACT raw data size */
if(lout == H5D_COMPACT)
- iter->dset_ohdr_info.total_size -= storage;
+ iter->dset_ohdr_info.total_size -= storage;
/* Track the layout type for dataset */
(iter->dset_layouts[lout])++;
@@ -495,7 +495,7 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
iter->nexternal += (unsigned long)num_ext;
iter->dset_external_storage_size += (unsigned long)storage;
} else
- iter->dset_storage_size += storage;
+ iter->dset_storage_size += storage;
/* Gather dataspace statistics */
sid = H5Dget_space(did);
@@ -640,7 +640,7 @@ datatype_stats(iter_t *iter, const H5O_info_t *oi)
* Purpose: Gather statistics about an object
*
* Return: Success: 0
- * Failure: -1
+ * Failure: -1
*
* Programmer: Quincey Koziol
* Tuesday, November 6, 2007
@@ -669,7 +669,7 @@ obj_stats(const char *path, const H5O_info_t *oi, const char *already_visited,
break;
case H5O_TYPE_NAMED_DATATYPE:
- datatype_stats(iter, oi);
+ datatype_stats(iter, oi);
break;
default:
@@ -724,7 +724,7 @@ lnk_stats(const char UNUSED *path, const H5L_info_t *li, void *_iter)
* Purpose: Gather statistics for free space sections in the file
*
* Return: Success: 0
- * Failure: -1
+ * Failure: -1
*
* Programmer: Vailin Choi; July 7th, 2009
*
@@ -734,24 +734,24 @@ static herr_t
freespace_stats(hid_t fid, iter_t *iter)
{
H5F_sect_info_t *sect_info = NULL; /* Free space sections */
- ssize_t nsects; /* Number of free space sections */
- size_t u; /* Local index variable */
+ ssize_t nsects; /* Number of free space sections */
+ size_t u; /* Local index variable */
/* Query section information */
if((nsects = H5Fget_free_sections(fid, H5FD_MEM_DEFAULT, 0, NULL)) < 0)
- return(FAIL);
+ return(FAIL);
else if(nsects) {
- if(NULL == (sect_info = (H5F_sect_info_t *)calloc((size_t)nsects, sizeof(H5F_sect_info_t))))
- return(FAIL);
- nsects = H5Fget_free_sections(fid, H5FD_MEM_DEFAULT, (size_t)nsects, sect_info);
- assert(nsects);
+ if(NULL == (sect_info = (H5F_sect_info_t *)calloc((size_t)nsects, sizeof(H5F_sect_info_t))))
+ return(FAIL);
+ nsects = H5Fget_free_sections(fid, H5FD_MEM_DEFAULT, (size_t)nsects, sect_info);
+ assert(nsects);
} /* end else-if */
for(u = 0; u < (size_t)nsects; u++) {
- unsigned bin; /* "bin" the number of objects falls in */
+ unsigned bin; /* "bin" the number of objects falls in */
- if(sect_info[u].size < SIZE_SMALL_SECTS)
- (iter->num_small_sects[(size_t)sect_info[u].size])++;
+ if(sect_info[u].size < SIZE_SMALL_SECTS)
+ (iter->num_small_sects[(size_t)sect_info[u].size])++;
/* Add section size to proper bin */
bin = ceil_log10((unsigned long)sect_info[u].size);
@@ -792,9 +792,9 @@ freespace_stats(hid_t fid, iter_t *iter)
* Saturday, August 12, 2006
*
* Modifications:
- * Vailin Choi; October 2009
- * Turn on display_group_metadata, display_dset_metadata
- * Add 'S' & 's' for printing free space info (previous checkin)
+ * Vailin Choi; October 2009
+ * Turn on display_group_metadata, display_dset_metadata
+ * Add 'S' & 's' for printing free space info (previous checkin)
*
*-------------------------------------------------------------------------
*/
@@ -802,86 +802,113 @@ 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);
-
- case 'V':
- print_version(h5tools_getprogname());
- leave(EXIT_SUCCESS);
- break;
+ switch ((char) opt) {
+ case 'h':
+ usage(h5tools_getprogname());
+ 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':
- display_all = FALSE;
- display_file_metadata = TRUE;
- break;
+ case 'V':
+ print_version(h5tools_getprogname());
+ 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':
- display_all = FALSE;
- display_file = TRUE;
- break;
+ case 'F':
+ display_all = FALSE;
+ display_file_metadata = TRUE;
+ break;
- case 'G':
- display_all = FALSE;
- display_group_metadata = TRUE;
- break;
+ case 'f':
+ display_all = FALSE;
+ display_file = TRUE;
+ break;
- case 'g':
- display_all = FALSE;
- display_group = TRUE;
- break;
+ case 'G':
+ display_all = FALSE;
+ display_group_metadata = TRUE;
+ break;
- case 'D':
- display_all = FALSE;
- display_dset_metadata = TRUE;
- break;
+ case 'g':
+ display_all = FALSE;
+ display_group = TRUE;
+ break;
- case 'd':
- display_all = FALSE;
- display_dset = TRUE;
- break;
+ case 'D':
+ display_all = FALSE;
+ display_dset_metadata = TRUE;
+ break;
- case 'T':
- display_all = FALSE;
- display_dset_dtype_meta = TRUE;
- break;
+ case 'd':
+ display_all = FALSE;
+ display_dset = TRUE;
+ break;
- case 'A':
- display_all = FALSE;
- display_attr = TRUE;
- break;
+ case 'T':
+ display_all = FALSE;
+ display_dset_dtype_meta = TRUE;
+ break;
- case 's':
- display_all = FALSE;
- display_free_sections = TRUE;
- break;
+ case 'A':
+ display_all = FALSE;
+ display_attr = TRUE;
+ break;
- case 'S':
- display_all = FALSE;
- display_summary = TRUE;
- break;
+ case 's':
+ display_all = FALSE;
+ display_free_sections = TRUE;
+ break;
- case 'O':
- display_all = FALSE;
- display_object = TRUE;
- for(i = 0; i < argc; i++)
- if(!hand[i].obj) {
- hand[i].obj = HDstrdup(opt_arg);
- break;
- } /* end if */
- break;
+ case 'S':
+ display_all = FALSE;
+ display_summary = TRUE;
+ break;
- default:
- usage(h5tools_getprogname());
- leave(EXIT_FAILURE);
+ case 'O':
+ display_all = FALSE;
+ display_object = TRUE;
+ for (i = 0; i < argc; i++)
+ if (!hand[i].obj) {
+ hand[i].obj = HDstrdup(opt_arg);
+ break;
+ } /* end if */
+ break;
+
+ default:
+ usage(h5tools_getprogname());
+ h5tools_setstatus(EXIT_FAILURE);
+ goto error;
} /* end switch */
} /* end while */
@@ -889,9 +916,26 @@ 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;
}
@@ -968,9 +1012,9 @@ print_file_info(const iter_t *iter)
* Saturday, August 12, 2006
*
* Modifications:
- * bug #1253; Oct 6th 2008; Vailin Choi
- * Fixed segmentation fault: print iter->group_bins[0] when
- * there is iter->group_nbins
+ * bug #1253; Oct 6th 2008; Vailin Choi
+ * Fixed segmentation fault: print iter->group_bins[0] when
+ * there is iter->group_nbins
*
*-------------------------------------------------------------------------
*/
@@ -1165,8 +1209,8 @@ print_dataset_info(const iter_t *iter)
* Programmer:
*
* Modifications:
- * Vailin Choi; October 2009
- * Moved from print_dataset_info()
+ * Vailin Choi; October 2009
+ * Moved from print_dataset_info()
*
*-------------------------------------------------------------------------
*/
@@ -1178,20 +1222,20 @@ print_dset_dtype_meta(const iter_t *iter)
unsigned u; /* Local index variable */
if(iter->dset_ntypes) {
- printf("Dataset datatype information:\n");
- printf("\t# of unique datatypes used by datasets: %lu\n", iter->dset_ntypes);
- total = 0;
- for(u = 0; u < iter->dset_ntypes; u++) {
- H5Tencode(iter->dset_type_info[u].tid, NULL, &dtype_size);
- printf("\tDataset datatype #%u:\n", u);
- printf("\t\tCount (total/named) = (%lu/%lu)\n",
- iter->dset_type_info[u].count, iter->dset_type_info[u].named);
- printf("\t\tSize (desc./elmt) = (%lu/%lu)\n", (unsigned long)dtype_size,
- (unsigned long)H5Tget_size(iter->dset_type_info[u].tid));
- H5Tclose(iter->dset_type_info[u].tid);
- total += iter->dset_type_info[u].count;
- } /* end for */
- printf("\tTotal dataset datatype count: %lu\n", total);
+ printf("Dataset datatype information:\n");
+ printf("\t# of unique datatypes used by datasets: %lu\n", iter->dset_ntypes);
+ total = 0;
+ for(u = 0; u < iter->dset_ntypes; u++) {
+ H5Tencode(iter->dset_type_info[u].tid, NULL, &dtype_size);
+ printf("\tDataset datatype #%u:\n", u);
+ printf("\t\tCount (total/named) = (%lu/%lu)\n",
+ iter->dset_type_info[u].count, iter->dset_type_info[u].named);
+ printf("\t\tSize (desc./elmt) = (%lu/%lu)\n", (unsigned long)dtype_size,
+ (unsigned long)H5Tget_size(iter->dset_type_info[u].tid));
+ H5Tclose(iter->dset_type_info[u].tid);
+ total += iter->dset_type_info[u].count;
+ } /* end for */
+ printf("\tTotal dataset datatype count: %lu\n", total);
}
return 0;
@@ -1270,42 +1314,41 @@ print_storage_summary(const iter_t *iter)
HDfprintf(stdout, "File space management strategy: %s\n", FS_STRATEGY_NAME[iter->fs_strategy]);
printf("Summary of file space information:\n");
total_meta =
- iter->super_size + iter->super_ext_size + iter->ublk_size +
- iter->group_ohdr_info.total_size +
- iter->dset_ohdr_info.total_size +
- iter->dtype_ohdr_info.total_size +
- iter->groups_btree_storage_size +
- iter->groups_heap_storage_size +
- iter->attrs_btree_storage_size +
- iter->attrs_heap_storage_size +
- iter->datasets_index_storage_size +
- iter->datasets_heap_storage_size +
- iter->SM_hdr_storage_size +
- iter->SM_index_storage_size +
- iter->SM_heap_storage_size +
- iter->free_hdr;
+ iter->super_size + iter->super_ext_size + iter->ublk_size +
+ iter->group_ohdr_info.total_size +
+ iter->dset_ohdr_info.total_size +
+ iter->dtype_ohdr_info.total_size +
+ iter->groups_btree_storage_size +
+ iter->groups_heap_storage_size +
+ iter->attrs_btree_storage_size +
+ iter->attrs_heap_storage_size +
+ iter->datasets_index_storage_size +
+ iter->datasets_heap_storage_size +
+ iter->SM_hdr_storage_size +
+ iter->SM_index_storage_size +
+ iter->SM_heap_storage_size +
+ iter->free_hdr;
HDfprintf(stdout, " File metadata: %Hu bytes\n", total_meta);
HDfprintf(stdout, " Raw data: %Hu bytes\n", iter->dset_storage_size);
percent = ((float)iter->free_space / (float)iter->filesize) * 100;
HDfprintf(stdout, " Amount/Percent of tracked free space: %Hu bytes/%3.1f%\n",
- iter->free_space, percent);
+ iter->free_space, percent);
if(iter->filesize < (total_meta+iter->dset_storage_size+iter->free_space)) {
- unaccount = (total_meta + iter->dset_storage_size + iter->free_space) - iter->filesize;
- HDfprintf(stdout, " ??? File has %Hu more bytes accounted for than its size! ???\n", unaccount);
+ unaccount = (total_meta + iter->dset_storage_size + iter->free_space) - iter->filesize;
+ HDfprintf(stdout, " ??? File has %Hu more bytes accounted for than its size! ???\n", unaccount);
}
else {
- unaccount = iter->filesize - (total_meta + iter->dset_storage_size + iter->free_space);
- HDfprintf(stdout, " Unaccounted space: %Hu bytes\n", unaccount);
+ unaccount = iter->filesize - (total_meta + iter->dset_storage_size + iter->free_space);
+ HDfprintf(stdout, " Unaccounted space: %Hu bytes\n", unaccount);
}
- HDfprintf(stdout, "Total space: %Hu bytes\n",
- total_meta+iter->dset_storage_size+iter->free_space+unaccount);
+ HDfprintf(stdout, "Total space: %Hu bytes\n", total_meta+iter->dset_storage_size+iter->free_space+unaccount);
if(iter->nexternal)
- HDfprintf(stdout, "External raw data: %Hu bytes\n", iter->dset_external_storage_size);
+ HDfprintf(stdout, "External raw data: %Hu bytes\n", iter->dset_external_storage_size);
return 0;
@@ -1337,13 +1380,13 @@ print_file_metadata(const iter_t *iter)
HDfprintf(stdout, "\tObject headers: (total/unused)\n");
HDfprintf(stdout, "\t\tGroups: %Hu/%Hu\n",
iter->group_ohdr_info.total_size,
- iter->group_ohdr_info.free_size);
+ iter->group_ohdr_info.free_size);
HDfprintf(stdout, "\t\tDatasets(exclude compact data): %Hu/%Hu\n",
- iter->dset_ohdr_info.total_size,
- iter->dset_ohdr_info.free_size);
+ iter->dset_ohdr_info.total_size,
+ iter->dset_ohdr_info.free_size);
HDfprintf(stdout, "\t\tDatatypes: %Hu/%Hu\n",
iter->dtype_ohdr_info.total_size,
- iter->dtype_ohdr_info.free_size);
+ iter->dtype_ohdr_info.free_size);
HDfprintf(stdout, "\tGroups:\n");
HDfprintf(stdout, "\t\tB-tree/List: %Hu\n", iter->groups_btree_storage_size);
@@ -1391,7 +1434,7 @@ print_group_metadata(const iter_t *iter)
printf("File space information for groups' metadata (in bytes):\n");
HDfprintf(stdout, "\tObject headers (total/unused): %Hu/%Hu\n",
- iter->group_ohdr_info.total_size, iter->group_ohdr_info.free_size);
+ iter->group_ohdr_info.total_size, iter->group_ohdr_info.free_size);
HDfprintf(stdout, "\tB-tree/List: %Hu\n", iter->groups_btree_storage_size);
HDfprintf(stdout, "\tHeap: %Hu\n", iter->groups_heap_storage_size);
@@ -1419,10 +1462,10 @@ print_dset_metadata(const iter_t *iter)
printf("File space information for datasets' metadata (in bytes):\n");
HDfprintf(stdout, "\tObject headers (total/unused): %Hu/%Hu\n",
- iter->dset_ohdr_info.total_size, iter->dset_ohdr_info.free_size);
+ iter->dset_ohdr_info.total_size, iter->dset_ohdr_info.free_size);
HDfprintf(stdout, "\tIndex for Chunked datasets: %Hu\n",
- iter->datasets_index_storage_size);
+ iter->datasets_index_storage_size);
HDfprintf(stdout, "\tHeap: %Hu\n", iter->datasets_heap_storage_size);
return 0;
@@ -1442,9 +1485,9 @@ print_dset_metadata(const iter_t *iter)
* Saturday, August 12, 2006
*
* Modifications:
- * Vailin Choi; October 2009
- * Activate "display_group_metadata", "dislay_dset_metadata" and
- * "display_dset_dtype_info".
+ * Vailin Choi; October 2009
+ * Activate "display_group_metadata", "dislay_dset_metadata" and
+ * "display_dset_dtype_info".
*
*-------------------------------------------------------------------------
*/
@@ -1455,29 +1498,29 @@ print_file_statistics(const iter_t *iter)
display_file = TRUE;
display_group = TRUE;
display_dset = TRUE;
- display_dset_dtype_meta = TRUE;
+ display_dset_dtype_meta = TRUE;
display_attr = TRUE;
- display_free_sections = TRUE;
- display_summary = TRUE;
+ display_free_sections = TRUE;
+ display_summary = TRUE;
display_file_metadata = TRUE;
display_group_metadata = TRUE;
display_dset_metadata = TRUE;
}
- if(display_file) print_file_info(iter);
- if(display_file_metadata) print_file_metadata(iter);
+ if(display_file) print_file_info(iter);
+ if(display_file_metadata) print_file_metadata(iter);
- if(display_group) print_group_info(iter);
- if(!display_all && display_group_metadata) print_group_metadata(iter);
+ if(display_group) print_group_info(iter);
+ if(!display_all && display_group_metadata) print_group_metadata(iter);
- if(display_dset) print_dataset_info(iter);
+ if(display_dset) print_dataset_info(iter);
if(display_dset_dtype_meta) print_dset_dtype_meta(iter);
- if(!display_all && display_dset_metadata) print_dset_metadata(iter);
+ if(!display_all && display_dset_metadata) print_dset_metadata(iter);
- if(display_attr) print_attr_info(iter);
- if(display_free_sections) print_freespace_info(iter);
- if(display_summary) print_storage_summary(iter);
+ if(display_attr) print_attr_info(iter);
+ if(display_free_sections) print_freespace_info(iter);
+ if(display_summary) print_storage_summary(iter);
}
@@ -1533,12 +1576,13 @@ print_statistics(const char *name, const iter_t *iter)
int
main(int argc, const char *argv[])
{
- iter_t iter;
- const char *fname = NULL;
- hid_t fid;
- hid_t fcpl;
- struct handler_t *hand;
- H5F_info2_t finfo;
+ iter_t iter;
+ const char *fname = NULL;
+ hid_t fid;
+ hid_t fcpl;
+ struct handler_t *hand = NULL;
+ H5F_info2_t finfo;
+ int i;
h5tools_setprogname(PROGRAMNAME);
h5tools_setstatus(EXIT_SUCCESS);
@@ -1548,11 +1592,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];
@@ -1561,27 +1603,28 @@ 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 */
iter_init(&iter, fid);
if(H5Fget_filesize(fid, &iter.filesize) < 0)
- warn_msg("Unable to retrieve file size\n");
+ warn_msg("Unable to retrieve file size\n");
assert(iter.filesize != 0);
/* Get storge info for file-level structures */
if(H5Fget_info2(fid, &finfo) < 0)
- warn_msg("Unable to retrieve file info\n");
+ warn_msg("Unable to retrieve file info\n");
else {
- iter.super_size = finfo.super.super_size;
- iter.super_ext_size = finfo.super.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.free_space = finfo.free.tot_space;
- iter.free_hdr = finfo.free.meta_size;
+ iter.super_size = finfo.super.super_size;
+ iter.super_ext_size = finfo.super.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.free_space = finfo.free.tot_space;
+ iter.free_hdr = finfo.free.meta_size;
} /* end else */
if((fcpl = H5Fget_create_plist(fid)) < 0)
@@ -1605,26 +1648,36 @@ main(int argc, const char *argv[])
u = 0;
while(hand[u].obj) {
if (h5trav_visit(fid, hand[u].obj, TRUE, TRUE, obj_stats, lnk_stats, &iter) < 0)
- warn_msg("Unable to traverse object \"%s\"\n", hand[u].obj);
- else
- print_statistics(hand[u].obj, &iter);
+ warn_msg("Unable to traverse object \"%s\"\n", hand[u].obj);
+ else
+ print_statistics(hand[u].obj, &iter);
u++;
} /* end while */
} /* end if */
else {
if (h5trav_visit(fid, "/", TRUE, TRUE, obj_stats, lnk_stats, &iter) < 0)
- warn_msg("Unable to traverse objects/links in file \"%s\"\n", fname);
- else
- print_statistics("/", &iter);
+ warn_msg("Unable to traverse objects/links in file \"%s\"\n", fname);
+ else
+ print_statistics("/", &iter);
} /* end else */
- if (hand) free(hand);
-
- if(H5Fclose(fid) < 0) {
- error_msg("unable to close file \"%s\"\n", fname);
- leave(EXIT_FAILURE);
+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);
+ h5tools_setstatus(EXIT_FAILURE);
+ }
}
- leave(EXIT_SUCCESS);
+ 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
+