summaryrefslogtreecommitdiffstats
path: root/tools/h5dump
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2006-06-26 14:41:59 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2006-06-26 14:41:59 (GMT)
commit8846157e5985458fd0a3ddb47658a14d10fb97b2 (patch)
treef542f006bbe7cfa82455610de5e329b3667c6284 /tools/h5dump
parent4dfad81062f0b195ee9fd10f0b4e5ba2f6056aeb (diff)
downloadhdf5-8846157e5985458fd0a3ddb47658a14d10fb97b2.zip
hdf5-8846157e5985458fd0a3ddb47658a14d10fb97b2.tar.gz
hdf5-8846157e5985458fd0a3ddb47658a14d10fb97b2.tar.bz2
[svn-r12437] Purpose:
new feature. h5dump output of binary data Description: a new switch -b FILE_NAME that dumps the contents of memory data to file FILE_NAME in binary form new program binread.c that reads the contents of this file and outputs it to stdout added a test for the h5dump shell script that does a run of -b the binread.c program reads the data used in this run, usage is ./binread FILE_NAME Solution: Platforms tested: linux solaris AIX Misc. update:
Diffstat (limited to 'tools/h5dump')
-rw-r--r--tools/h5dump/Makefile.am2
-rw-r--r--tools/h5dump/Makefile.in20
-rw-r--r--tools/h5dump/binread.c100
-rw-r--r--tools/h5dump/h5dump.c62
-rw-r--r--tools/h5dump/testh5dump.sh.in3
5 files changed, 165 insertions, 22 deletions
diff --git a/tools/h5dump/Makefile.am b/tools/h5dump/Makefile.am
index 0cdc47b..94a6d73 100644
--- a/tools/h5dump/Makefile.am
+++ b/tools/h5dump/Makefile.am
@@ -26,7 +26,7 @@ INCLUDES=-I$(top_srcdir)/src -I$(top_srcdir)/tools/lib
TEST_PROG=h5dumpgentest
TEST_SCRIPT=testh5dump.sh testh5dumpxml.sh
-check_PROGRAMS=$(TEST_PROG)
+check_PROGRAMS=$(TEST_PROG) binread
check_SCRIPTS=$(TEST_SCRIPT)
SCRIPT_DEPEND=h5dump$(EXEEXT)
diff --git a/tools/h5dump/Makefile.in b/tools/h5dump/Makefile.in
index 897ad53..3c78e7e 100644
--- a/tools/h5dump/Makefile.in
+++ b/tools/h5dump/Makefile.in
@@ -30,7 +30,7 @@
# HDF5 Library Makefile(.in)
#
-SOURCES = h5dump.c h5dumpgentest.c
+SOURCES = binread.c h5dump.c h5dumpgentest.c
srcdir = @srcdir@
top_srcdir = @top_srcdir@
@@ -58,7 +58,7 @@ DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/testh5dump.sh.in $(srcdir)/testh5dumpxml.sh.in \
$(top_srcdir)/config/commence.am \
$(top_srcdir)/config/conclude.am
-check_PROGRAMS = $(am__EXEEXT_1)
+check_PROGRAMS = $(am__EXEEXT_1) binread$(EXEEXT)
bin_PROGRAMS = h5dump$(EXEEXT)
subdir = tools/h5dump
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -72,11 +72,15 @@ am__installdirs = "$(DESTDIR)$(bindir)"
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
am__EXEEXT_1 = h5dumpgentest$(EXEEXT)
PROGRAMS = $(bin_PROGRAMS)
+binread_SOURCES = binread.c
+binread_OBJECTS = binread.$(OBJEXT)
+binread_LDADD = $(LDADD)
+am__DEPENDENCIES_1 = $(top_builddir)/tools/lib/libh5tools.la
+am__DEPENDENCIES_2 = $(top_builddir)/src/libhdf5.la
+binread_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
h5dump_SOURCES = h5dump.c
h5dump_OBJECTS = h5dump.$(OBJEXT)
h5dump_LDADD = $(LDADD)
-am__DEPENDENCIES_1 = $(top_builddir)/tools/lib/libh5tools.la
-am__DEPENDENCIES_2 = $(top_builddir)/src/libhdf5.la
h5dump_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2)
h5dumpgentest_SOURCES = h5dumpgentest.c
h5dumpgentest_OBJECTS = h5dumpgentest.$(OBJEXT)
@@ -94,8 +98,8 @@ LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
-SOURCES = h5dump.c h5dumpgentest.c
-DIST_SOURCES = h5dump.c h5dumpgentest.c
+SOURCES = binread.c h5dump.c h5dumpgentest.c
+DIST_SOURCES = binread.c h5dump.c h5dumpgentest.c
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -434,6 +438,9 @@ clean-checkPROGRAMS:
echo " rm -f $$p $$f"; \
rm -f $$p $$f ; \
done
+binread$(EXEEXT): $(binread_OBJECTS) $(binread_DEPENDENCIES)
+ @rm -f binread$(EXEEXT)
+ $(LINK) $(binread_LDFLAGS) $(binread_OBJECTS) $(binread_LDADD) $(LIBS)
h5dump$(EXEEXT): $(h5dump_OBJECTS) $(h5dump_DEPENDENCIES)
@rm -f h5dump$(EXEEXT)
$(LINK) $(h5dump_LDFLAGS) $(h5dump_OBJECTS) $(h5dump_LDADD) $(LIBS)
@@ -447,6 +454,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/binread.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5dump.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5dumpgentest.Po@am__quote@
diff --git a/tools/h5dump/binread.c b/tools/h5dump/binread.c
new file mode 100644
index 0000000..d3b43a9
--- /dev/null
+++ b/tools/h5dump/binread.c
@@ -0,0 +1,100 @@
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the files COPYING and Copyright.html. COPYING can be found at the root *
+ * of the source code distribution tree; Copyright.html can be found at the *
+ * root level of an installed copy of the electronic HDF5 document set and *
+ * is linked from the top-level documents page. It can also be found at *
+ * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ This program reads binary output from h5dump (-b option).
+ To use change the following 3 symbols accordingly.
+ For example, to read 6 elements of a float type from a file "out.dat", define
+
+ #define NELMTS 6
+ #define TYPE float
+ #define FORMAT "%f "
+
+*/
+
+#define NELMTS 2
+#define TYPE int
+#define FORMAT "%d "
+
+/*-------------------------------------------------------------------------
+ * Function: usage
+ *
+ * Purpose: Prints a usage message on stderr and then returns.
+ *
+ * Return: void
+ *
+ * Programmer: Pedro Vicente Nunes
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+usage (void)
+{
+ fprintf(stderr, "\
+ usage: binread FILE_NAME\n");
+}
+
+/*-------------------------------------------------------------------------
+ * Function: main
+ *
+ * Purpose: main program.
+ *
+ *-------------------------------------------------------------------------
+ */
+
+int
+main (int argc, const char *argv[])
+{
+ FILE *stream;
+ int numread;
+ TYPE buf[NELMTS];
+ size_t i, nelmts = NELMTS;
+ char *fname=NULL;
+
+ if (argc != 2)
+ {
+ usage();
+ exit(1);
+ }
+
+ fname = strdup(argv[1]);
+
+ if( (stream = fopen(fname, "rb" )) != NULL )
+ {
+ numread = fread( buf, sizeof( TYPE ), nelmts, stream );
+ printf( "Number of items read = %d\n", numread );
+
+ for (i = 0; i < nelmts; i++)
+ {
+ printf(FORMAT,buf[i]);
+ }
+ printf("\n");
+
+ fclose( stream );
+ }
+ else
+ printf( "File %s could not be opened\n",fname );
+
+ free(fname);
+
+ return 0;
+}
+
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index 2a6b33a..c2bc761 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -351,7 +351,7 @@ struct handler_t {
* 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 = "hnpeyBHirVa:c:d:f:g:k:l:t:w:xD:uX:o:s:S:A";
+static const char *s_opts = "hnpeyBHirVa:c:d:f:g:k:l:t:w:xD:uX:o:b:s:S:A";
static struct long_options l_opts[] = {
{ "help", no_arg, 'h' },
{ "hel", no_arg, 'h' },
@@ -600,6 +600,7 @@ usage(const char *prog)
fprintf(stdout, " -g P, --group=P Print the specified group and all members\n");
fprintf(stdout, " -l P, --soft-link=P Print the value(s) of the specified soft link\n");
fprintf(stdout, " -o F, --output=F Output raw data into file F\n");
+ fprintf(stdout, " -b F Output raw data into file F in binary form (use with -d)\n");
fprintf(stdout, " -t P, --datatype=P Print the specified named data type\n");
fprintf(stdout, " -w N, --width=N Set the number of columns of output\n");
fprintf(stdout, " -x, --xml Output in XML using Schema\n");
@@ -1952,7 +1953,7 @@ dump_subsetting_header(struct subset_t *sset, int dims)
*-------------------------------------------------------------------------
*/
static void
-dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int pindex)
+dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int display_ai)
{
h5tool_format_t *outputformat = &dataformat;
int status = -1;
@@ -1967,7 +1968,7 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int pindex)
outputformat->line_ncols = nCols;
outputformat->do_escape=display_escape;
/* print the matrix indices */
- outputformat->pindex=pindex;
+ outputformat->pindex=display_ai;
if (outputformat->pindex) {
outputformat->idx_fmt = "(%s): ";
outputformat->idx_n_fmt = "%lu";
@@ -2001,7 +2002,7 @@ dump_data(hid_t obj_id, int obj_data, struct subset_t *sset, int pindex)
/* Print all the values. */
if (obj_data == DATASET_DATA) {
- hid_t f_type = H5Dget_type(obj_id);
+ hid_t f_type = H5Dget_type(obj_id);
char string_prefix[64];
h5tool_format_t string_dataformat;
@@ -2665,21 +2666,40 @@ static void dump_fcontents(hid_t fid)
* Programmer: Albert Cheng, 2000/09/30
*
* Modifications:
+ * pvn June, 1, 2006. Add a switch for binary output
*
*-------------------------------------------------------------------------
*/
static int
-set_output_file(const char *fname)
+set_output_file(const char *fname, int is_bin)
{
- FILE *f; /* temporary holding place for the stream pointer
- * so that rawdatastream is changed only when succeeded */
-
- if ((f = fopen(fname, "w")) != NULL) {
- rawdatastream = f;
- return 0;
- }
-
- return -1;
+ FILE *f; /* temporary holding place for the stream pointer
+* so that rawdatastream is changed only when succeeded */
+
+ if (rawdatastream && rawdatastream != stdout) {
+ if (fclose(rawdatastream))
+ perror("closing rawdatastream");
+ else
+ rawdatastream = NULL;
+ }
+
+ /* binary output */
+ if (is_bin)
+ {
+ if ((f = fopen(fname, "wb")) != NULL) {
+ rawdatastream = f;
+ return 0;
+ }
+ }
+ else
+ {
+ if ((f = fopen(fname, "w")) != NULL) {
+ rawdatastream = f;
+ return 0;
+ }
+ }
+
+ return -1;
}
/*-------------------------------------------------------------------------
@@ -3110,6 +3130,7 @@ handle_datatypes(hid_t fid, char *type, void UNUSED * data)
* Tuesday, 20. February 2001
*
* Modifications:
+ * pvn June, 1, 2006. Add a switch for binary output
*
*-------------------------------------------------------------------------
*/
@@ -3234,7 +3255,7 @@ parse_start:
last_was_dset = FALSE;
break;
case 'o':
- if (set_output_file(opt_arg) < 0){
+ if (set_output_file(opt_arg, 0) < 0){
/* failed to set output file */
usage(progname);
leave(EXIT_FAILURE);
@@ -3244,6 +3265,17 @@ parse_start:
last_was_dset = FALSE;
break;
+ case 'b':
+ if (set_output_file(opt_arg, 1) < 0){
+ /* failed to set output file */
+ usage(progname);
+ leave(EXIT_FAILURE);
+ }
+
+ bin_output = TRUE;
+ last_was_dset = FALSE;
+ break;
+
/** begin XML parameters **/
case 'x':
/* select XML output */
diff --git a/tools/h5dump/testh5dump.sh.in b/tools/h5dump/testh5dump.sh.in
index c23651b..f390110 100644
--- a/tools/h5dump/testh5dump.sh.in
+++ b/tools/h5dump/testh5dump.sh.in
@@ -320,6 +320,9 @@ TOOLTEST tlonglinks.ddl tlonglinks.h5
# test for vms
TOOLTEST tvms.ddl tvms.h5
+# test for binary output
+TOOLTEST tbin.ddl -d integer -b out.bin test1.h5
+
if test $nerrors -eq 0 ; then
echo "All $DUMPER tests passed."
fi