summaryrefslogtreecommitdiffstats
path: root/tools/misc
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2009-09-14 19:52:42 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2009-09-14 19:52:42 (GMT)
commit43db8230440604cac42af68264465c8a24605647 (patch)
tree1fc8f9d2969ab3a4243ce2f64316e028ed11fd7e /tools/misc
parentfa3eab20dddb1b816e36c41d8bdb189ec34bbd0a (diff)
downloadhdf5-43db8230440604cac42af68264465c8a24605647.zip
hdf5-43db8230440604cac42af68264465c8a24605647.tar.gz
hdf5-43db8230440604cac42af68264465c8a24605647.tar.bz2
[svn-r17475] Added error handling to h5dump and region reference handling functions in the tools lib. Bring back from NPOESS. Added missing tests to h5dump test script for region references.
Tested: local linux
Diffstat (limited to 'tools/misc')
-rw-r--r--tools/misc/Makefile.am2
-rw-r--r--tools/misc/Makefile.in19
-rw-r--r--tools/misc/talign.c191
3 files changed, 207 insertions, 5 deletions
diff --git a/tools/misc/Makefile.am b/tools/misc/Makefile.am
index 7f78465..fe1acbd 100644
--- a/tools/misc/Makefile.am
+++ b/tools/misc/Makefile.am
@@ -24,7 +24,7 @@ include $(top_srcdir)/config/commence.am
INCLUDES=-I$(top_srcdir)/src -I$(top_srcdir)/tools/lib
#test script and program
-TEST_PROG=h5repart_gentest
+TEST_PROG=h5repart_gentest talign
TEST_SCRIPT=testh5repart.sh $(srcdir)/testh5mkgrp.sh
check_PROGRAMS=$(TEST_PROG) repart_test
diff --git a/tools/misc/Makefile.in b/tools/misc/Makefile.in
index dd8fce6..17502af 100644
--- a/tools/misc/Makefile.in
+++ b/tools/misc/Makefile.in
@@ -69,8 +69,15 @@ CONFIG_HEADER = $(top_builddir)/src/H5config.h
CONFIG_CLEAN_FILES = h5cc testh5repart.sh
CONFIG_CLEAN_VPATH_FILES =
am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(bindir)"
-am__EXEEXT_1 = h5repart_gentest$(EXEEXT)
+am__EXEEXT_1 = h5repart_gentest$(EXEEXT) talign$(EXEEXT)
PROGRAMS = $(bin_PROGRAMS)
+talign_SOURCES = talign.c
+talign_OBJECTS = talign.$(OBJEXT)
+talign_LDADD = $(LDADD)
+talign_DEPENDENCIES = $(LIBH5TOOLS) $(LIBHDF5)
+talign_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(talign_LDFLAGS) \
+ $(LDFLAGS) -o $@
h5debug_SOURCES = h5debug.c
h5debug_OBJECTS = h5debug.$(OBJEXT)
h5debug_LDADD = $(LDADD)
@@ -136,9 +143,9 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = h5debug.c h5mkgrp.c h5repart.c h5repart_gentest.c \
- repart_test.c
+ repart_test.c talign.c
DIST_SOURCES = h5debug.c h5mkgrp.c h5repart.c h5repart_gentest.c \
- repart_test.c
+ repart_test.c talign.c
ETAGS = etags
CTAGS = ctags
am__tty_colors = \
@@ -404,7 +411,7 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog *.h5 \
INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/tools/lib
#test script and program
-TEST_PROG = h5repart_gentest
+TEST_PROG = h5repart_gentest talign.c
TEST_SCRIPT = testh5repart.sh $(srcdir)/testh5mkgrp.sh
check_SCRIPTS = $(TEST_SCRIPT)
SCRIPT_DEPEND = h5repart$(EXEEXT) h5mkgrp$(EXEEXT)
@@ -549,6 +556,9 @@ h5repart_gentest$(EXEEXT): $(h5repart_gentest_OBJECTS) $(h5repart_gentest_DEPEND
repart_test$(EXEEXT): $(repart_test_OBJECTS) $(repart_test_DEPENDENCIES)
@rm -f repart_test$(EXEEXT)
$(LINK) $(repart_test_OBJECTS) $(repart_test_LDADD) $(LIBS)
+talign$(EXEEXT): $(talign_OBJECTS) $(talign_DEPENDENCIES)
+ @rm -f talign$(EXEEXT)
+ $(LINK) $(talign_OBJECTS) $(talign_LDADD) $(LIBS)
install-binSCRIPTS: $(bin_SCRIPTS)
@$(NORMAL_INSTALL)
test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
@@ -595,6 +605,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5repart.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5repart_gentest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/repart_test.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/talign.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
diff --git a/tools/misc/talign.c b/tools/misc/talign.c
new file mode 100644
index 0000000..6c1bd81
--- /dev/null
+++ b/tools/misc/talign.c
@@ -0,0 +1,191 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * 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://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * Small program to illustrate the "misalignment" of members within a compound
+ * datatype, in a datatype fixed by H5Tget_native_type().
+ */
+#include <string.h>
+#include <stdlib.h>
+/*#include <unistd.h> *//* Required for unlink() */
+
+#include "hdf5.h"
+#include "H5private.h"
+#include "h5tools.h"
+
+const char *fname = "talign.h5";
+const char *setname = "align";
+
+/*
+ * This program assumes that there is no extra space between the members 'Ok'
+ * and 'Not Ok', (there shouldn't be because they are of the same atomic type
+ * H5T_NATIVE_FLOAT, and they are placed within the compound next to one
+ * another per construction)
+ */
+
+int main(void)
+{
+ hid_t fil,spc,set;
+ hid_t cs6, cmp, fix;
+ hid_t cmp1, cmp2, cmp3;
+ hid_t plist;
+ hid_t array_dt;
+
+ hsize_t dim[2];
+ hsize_t cdim[4];
+
+ char string5[5];
+ float fok[2] = {1234., 2341.};
+ float fnok[2] = {5678., 6785.};
+ float *fptr;
+
+ char *data;
+ char *mname;
+
+ int result = 0;
+
+ printf("%-70s", "Testing alignment in compound datatypes");
+
+ strcpy(string5, "Hi!");
+ HDunlink(fname);
+ fil = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+
+ if (fil < 0) {
+ puts("*FAILED*");
+ return 1;
+ }
+
+ H5E_BEGIN_TRY {
+ H5Ldelete(fil, setname, H5P_DEFAULT);
+ } H5E_END_TRY;
+
+ cs6 = H5Tcopy(H5T_C_S1);
+ H5Tset_size(cs6, sizeof(string5));
+ H5Tset_strpad(cs6, H5T_STR_NULLPAD);
+
+ cmp = H5Tcreate(H5T_COMPOUND, sizeof(fok) + sizeof(string5) + sizeof(fnok));
+ H5Tinsert(cmp, "Awkward length", 0, cs6);
+
+ cdim[0] = sizeof(fok) / sizeof(float);
+ array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim);
+ H5Tinsert(cmp, "Ok", sizeof(string5), array_dt);
+ H5Tclose(array_dt);
+
+ cdim[0] = sizeof(fnok) / sizeof(float);
+ array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim);
+ H5Tinsert(cmp, "Not Ok", sizeof(fok) + sizeof(string5), array_dt);
+ H5Tclose(array_dt);
+
+ fix=h5tools_get_native_type(cmp);
+
+ cmp1 = H5Tcreate(H5T_COMPOUND, sizeof(fok));
+
+ cdim[0] = sizeof(fok) / sizeof(float);
+ array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim);
+ H5Tinsert(cmp1, "Ok", 0, array_dt);
+ H5Tclose(array_dt);
+
+ cmp2 = H5Tcreate(H5T_COMPOUND, sizeof(string5));
+ H5Tinsert(cmp2, "Awkward length", 0, cs6);
+
+ cmp3 = H5Tcreate(H5T_COMPOUND, sizeof(fnok));
+
+ cdim[0] = sizeof(fnok) / sizeof(float);
+ array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim);
+ H5Tinsert(cmp3, "Not Ok", 0, array_dt);
+ H5Tclose(array_dt);
+
+ plist = H5Pcreate(H5P_DATASET_XFER);
+ H5Pset_preserve(plist, 1);
+
+ /*
+ * Create a small dataset, and write data into it we write each field
+ * in turn so that we are avoid alignment issues at this point
+ */
+ dim[0] = 1;
+ spc = H5Screate_simple(1, dim, NULL);
+ set = H5Dcreate2(fil, setname, cmp, spc, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+
+ H5Dwrite(set, cmp1, spc, H5S_ALL, plist, fok);
+ H5Dwrite(set, cmp2, spc, H5S_ALL, plist, string5);
+ H5Dwrite(set, cmp3, spc, H5S_ALL, plist, fnok);
+
+ H5Dclose(set);
+
+ /* Now open the set, and read it back in */
+ data = malloc(H5Tget_size(fix));
+
+ if(!data) {
+ perror("malloc() failed");
+ abort();
+ }
+
+ set = H5Dopen2(fil, setname, H5P_DEFAULT);
+
+ H5Dread(set, fix, spc, H5S_ALL, H5P_DEFAULT, data);
+ fptr = (float *)(data + H5Tget_member_offset(fix, 1));
+
+ if(fok[0] != fptr[0] || fok[1] != fptr[1]
+ || fnok[0] != fptr[2] || fnok[1] != fptr[3]) {
+ result = 1;
+ printf("%14s (%2d) %6s = %s\n",
+ mname = H5Tget_member_name(fix, 0), (int)H5Tget_member_offset(fix,0),
+ string5, (char *)(data + H5Tget_member_offset(fix, 0)));
+ free(mname);
+ fptr = (float *)(data + H5Tget_member_offset(fix, 1));
+ printf("Data comparison:\n"
+ "%14s (%2d) %6f = %f\n"
+ " %6f = %f\n",
+ mname = H5Tget_member_name(fix, 1), (int)H5Tget_member_offset(fix,1),
+ fok[0], fptr[0],
+ fok[1], fptr[1]);
+ free(mname);
+ fptr = (float *)(data + H5Tget_member_offset(fix, 2));
+ printf("%14s (%2d) %6f = %f\n"
+ " %6f = %6f\n",
+ mname = H5Tget_member_name(fix, 2), (int)H5Tget_member_offset(fix,2),
+ fnok[0], fptr[0],
+ fnok[1], fptr[1]);
+ free(mname);
+
+ fptr = (float *)(data + H5Tget_member_offset(fix, 1));
+ printf("\n"
+ "Short circuit\n"
+ " %6f = %f\n"
+ " %6f = %f\n"
+ " %6f = %f\n"
+ " %6f = %f\n",
+ fok[0], fptr[0],
+ fok[1], fptr[1],
+ fnok[0], fptr[2],
+ fnok[1], fptr[3]);
+ puts("*FAILED*");
+ } else {
+ puts(" PASSED");
+ }
+
+ free(data);
+ H5Sclose(spc);
+ H5Tclose(cmp);
+ H5Tclose(cmp1);
+ H5Tclose(cmp2);
+ H5Tclose(cmp3);
+ H5Pclose(plist);
+ H5Fclose(fil);
+ HDunlink(fname);
+ fflush(stdout);
+ return result;
+}
+