From 614ae2dce6086a8966a26074f48644aa3c92f93c Mon Sep 17 00:00:00 2001 From: Robb Matzke Date: Mon, 13 Jul 1998 10:35:21 -0500 Subject: [svn-r485] Changes since 19980710 ---------------------- ./Makefile.in ./config/commence.in ./config/conclude.in ./config/depend.in ./src/Makefile.in ./test/Makefile.in Tests are no longer installed for `make install'. Added a new target `make tests' that builds the tests but doesn't run them. ./configure.in ./configure [REGENERATED] ./src/H5config.h.in [REGENERATED] Added detection of fork() and waitpid(). If present the contants HAVE_FORK and HAVE_WAITPID will be defined in H5config.h. ./test/dtypes.c Minor tweaks for systems that don't have fork() or waitpid(). ./MANIFEST ./tools [NEW] ./tools/Makefile.in [NEW] ./tools/h5debug.c [NEW] ./tools/h5import.c [NEW] ./tools/h5ls.c [NEW] ./tools/h5repart.c [NEW] Added a tools directory and moved tools from the src directory to here. --- MANIFEST | 8 +- Makefile.in | 10 +- config/commence.in | 4 +- config/conclude.in | 5 +- config/depend.in | 2 +- configure | 6 +- configure.in | 4 +- src/H5config.h.in | 6 + src/Makefile.in | 17 +-- src/debug.c | 178 ------------------------ src/h5ls.c | 197 --------------------------- src/h5repart.c | 388 ----------------------------------------------------- test/.distdep | 110 +++++++-------- test/Makefile.in | 117 +++++----------- test/dtypes.c | 15 ++- tools/Makefile.in | 32 +++++ tools/h5debug.c | 178 ++++++++++++++++++++++++ tools/h5import.c | 119 ++++++++++++++++ tools/h5ls.c | 197 +++++++++++++++++++++++++++ tools/h5repart.c | 388 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 20 files changed, 1042 insertions(+), 939 deletions(-) delete mode 100644 src/debug.c delete mode 100644 src/h5ls.c delete mode 100644 src/h5repart.c create mode 100644 tools/Makefile.in create mode 100644 tools/h5debug.c create mode 100644 tools/h5import.c create mode 100644 tools/h5ls.c create mode 100644 tools/h5repart.c diff --git a/MANIFEST b/MANIFEST index 6dc448d..6a29965 100644 --- a/MANIFEST +++ b/MANIFEST @@ -227,9 +227,6 @@ ./src/H5private.h ./src/H5public.h ./src/Makefile.in -./src/debug.c -./src/h5ls.c -./src/h5repart.c ./src/hdf5.h ./test/.distdep ./test/Makefile.in @@ -263,3 +260,8 @@ ./testpar/t_file.c ./testpar/testphdf5.c ./testpar/testphdf5.h +./tools/Makefile.in +./tools/h5debug.c +./tools/h5import.c +./tools/h5ls.c +./tools/h5repart.c diff --git a/Makefile.in b/Makefile.in index 6924d92..f7d947f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -11,13 +11,15 @@ @COMMENCE@ # Subdirectories in build-order -SUBDIRS=src test +SUBDIRS=src test tools ############################################################################## # T A R G E T S # -# all: Build libraries, header files, and programs in the various -# subdirectories but do not install them. +# all: Build libraries, header files, tests, and programs in the +# various subdirectories but does not run tests or install the +# library, header files, or programs. The components can be +# built individually with the targets lib, progs, and tests. # # test: Test the uninstalled library to make sure it works. # @@ -57,7 +59,7 @@ SUBDIRS=src test # make used in combination with gcc will maintain dependency # information automatically. # -lib progs test _test install uninstall TAGS dep depend: +lib progs tests test _test install uninstall TAGS dep depend: @@SETX@; for d in $(SUBDIRS); do \ (cd $$d && $(MAKE) $@) || exit 1; \ done diff --git a/config/commence.in b/config/commence.in index 72fb45c..6ec3133 100644 --- a/config/commence.in +++ b/config/commence.in @@ -33,8 +33,8 @@ bindir=@bindir@ libdir=@libdir@ includedir=@includedir@ -# The default is to build the programs which in turn builds the lib. -all: progs +# The default is to build the library and/or programs +all: lib tests progs # The following rules insure that the Makefile is up-to-date by rerunning # various autoconf components (although not all versions of make assume diff --git a/config/conclude.in b/config/conclude.in index 39da813..db45f5b 100644 --- a/config/conclude.in +++ b/config/conclude.in @@ -20,7 +20,8 @@ TAGS: $(LIB_SRC) -etags $(LIB_SRC) # Runs each test in order, passing $(TEST_FLAGS) to the program. -test _test: $(PROGS) +tests: $(TESTS) +test _test: tests @for test in $(TESTS) dummy; do \ if test $$test != dummy; then \ echo "Testing $$test $(TEST_FLAGS)"; \ @@ -72,7 +73,7 @@ mostlyclean: # is part of the HDF5 distribution. # clean: mostlyclean - $(RM) $(LIB) $(PROGS) $(CLEAN) + $(RM) $(LIB) $(TESTS) $(PROGS) $(CLEAN) # Like `clean' except it also removes files that were created by running # configure. If you've unpacked the source and built HDF5 without creating diff --git a/config/depend.in b/config/depend.in index 2bd98af..07d0245 100644 --- a/config/depend.in +++ b/config/depend.in @@ -27,7 +27,7 @@ dep depend: .distdep touch .distdep -perl -p $(ROOT)/bin/distdep .depend >.distdep -.depend: $(LIB_SRC) $(PROG_SRC) +.depend: $(LIB_SRC) $(TEST_SRC) $(PROG_SRC) @touch .depend @for dep in $? dummy; do \ if [ $$dep != "dummy" ]; then \ diff --git a/configure b/configure index 4e0704b..af5ee24 100755 --- a/configure +++ b/configure @@ -1873,7 +1873,7 @@ EOF esac -for ac_func in getpwuid gethostname system getrusage +for ac_func in getpwuid gethostname system getrusage fork waitpid do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo "configure:1880: checking for $ac_func" >&5 @@ -2512,7 +2512,7 @@ ac_given_srcdir=$srcdir ac_given_INSTALL="$INSTALL" trap 'rm -fr `echo "config/depend config/commence config/conclude \ - Makefile src/Makefile test/Makefile examples/Makefile src/H5config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 + Makefile src/Makefile test/Makefile tools/Makefile examples/Makefile src/H5config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 EOF cat >> $CONFIG_STATUS <> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then diff --git a/configure.in b/configure.in index d5dccc3..c6d7542 100644 --- a/configure.in +++ b/configure.in @@ -178,7 +178,7 @@ esac dnl ---------------------------------------------------------------------- dnl Check for functions. dnl -AC_CHECK_FUNCS(getpwuid gethostname system getrusage) +AC_CHECK_FUNCS(getpwuid gethostname system getrusage fork waitpid) AC_TRY_COMPILE([#include], [off64_t n = 0;], @@ -355,4 +355,4 @@ dnl before we generate them or the Makefiles. touch ./config/stamp1 ./config/stamp2 AC_OUTPUT(config/depend config/commence config/conclude \ - Makefile src/Makefile test/Makefile examples/Makefile) + Makefile src/Makefile test/Makefile tools/Makefile examples/Makefile) diff --git a/src/H5config.h.in b/src/H5config.h.in index ee4672c..5feabff 100644 --- a/src/H5config.h.in +++ b/src/H5config.h.in @@ -61,6 +61,9 @@ /* The number of bytes in a size_t. */ #undef SIZEOF_SIZE_T +/* Define if you have the fork function. */ +#undef HAVE_FORK + /* Define if you have the fseek64 function. */ #undef HAVE_FSEEK64 @@ -79,6 +82,9 @@ /* Define if you have the system function. */ #undef HAVE_SYSTEM +/* Define if you have the waitpid function. */ +#undef HAVE_WAITPID + /* Define if you have the header file. */ #undef HAVE_UNISTD_H diff --git a/src/Makefile.in b/src/Makefile.in index 10d360f..4eaebdd 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -10,9 +10,8 @@ TRACE=perl ../bin/trace # Add `-I.' to the C preprocessor flags. CPPFLAGS=-I. @CPPFLAGS@ -# These are our main targets: +# This is our main target: LIB=libhdf5.a -PROGS=debug h5ls h5repart # Source and object files for the library (lexicographically)... LIB_SRC=H5.c H5A.c H5AC.c H5B.c H5D.c H5E.c H5F.c H5Farray.c H5Fcore.c \ @@ -28,10 +27,6 @@ LIB_OBJ=$(LIB_SRC:.c=.o) # Temporary files MOSTLYCLEAN=H5detect.o H5detect H5Tinit.o H5Tinit.c -# Source and object files for programs... -PROG_SRC=debug.c h5ls.c h5repart.c -PROG_OBJ=$(PROG_SRC:.c=.o) - # Public header files (to be installed)... PUB_HDR=H5public.h H5Apublic.h H5ACpublic.h H5Bpublic.h H5Dpublic.h \ H5Epublic.h H5Fpublic.h H5Gpublic.h H5HGpublic.h H5HLpublic.h \ @@ -53,14 +48,4 @@ H5Tinit.c: H5detect H5detect: H5detect.o $(CC) $(CFLAGS) -o $@ H5detect.o $(LIBS) -# How to build the programs... -debug: debug.o $(LIB) - $(CC) $(CFLAGS) -o $@ debug.o $(LIB) $(LIBS) - -h5ls: h5ls.o $(LIB) - $(CC) $(CFLAGS) -o $@ h5ls.o $(LIB) $(LIBS) - -h5repart: h5repart.o $(LIB) - $(CC) $(CFLAGS) -o $@ h5repart.o $(LIB) $(LIBS) - @CONCLUDE@ diff --git a/src/debug.c b/src/debug.c deleted file mode 100644 index fdf21d9..0000000 --- a/src/debug.c +++ /dev/null @@ -1,178 +0,0 @@ -/*------------------------------------------------------------------------- - * Copyright (C) 1997 National Center for Supercomputing Applications. - * All rights reserved. - * - *------------------------------------------------------------------------- - * - * Created: debug.c - * Jul 18 1997 - * Robb Matzke - * - * Purpose: Debugs an existing HDF5 file at a low level. - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define INDENT 3 -#define VCOL 50 - - -/*------------------------------------------------------------------------- - * Function: main - * - * Usage: debug FILENAME [OFFSET] - * - * Return: Success: exit (0) - * - * Failure: exit (non-zero) - * - * Programmer: Robb Matzke - * matzke@llnl.gov - * Jul 18 1997 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -int -main(int argc, char *argv[]) -{ - hid_t fid, plist=H5P_DEFAULT; - H5F_t *f; - haddr_t addr; - uint8 sig[16]; - intn i, ndims; - herr_t status = SUCCEED; - haddr_t extra; - - /* - * Open the file and get the file descriptor. - */ - if (strchr (argv[1], '%')) { - plist = H5Pcreate (H5P_FILE_ACCESS); - H5Pset_family (plist, 0, H5P_DEFAULT); - } - if ((fid = H5Fopen(argv[1], H5F_ACC_RDONLY, plist)) < 0) { - fprintf(stderr, "cannot open file\n"); - HDexit(1); - } - if (NULL == (f = H5I_object(fid))) { - fprintf(stderr, "cannot obtain H5F_t pointer\n"); - HDexit(2); - } - - /* - * Parse command arguments. - */ - H5F_addr_reset(&addr); - H5F_addr_reset(&extra); - if (argc > 2) { - printf("New address: %s\n", argv[2]); - addr.offset = HDstrtoll(argv[2], NULL, 0); - } - if (argc > 3) { - extra.offset = HDstrtoll(argv[3], NULL, 0); - } - /* - * Read the signature at the specified file position. - */ - printf("Reading signature at address "); - H5F_addr_print(stdout, &addr); - printf(" (rel)\n"); - if (H5F_block_read(f, &addr, (hsize_t)sizeof(sig), H5D_XFER_DFLT, sig) < 0) { - fprintf(stderr, "cannot read signature\n"); - HDexit(3); - } - if (!HDmemcmp(sig, H5F_SIGNATURE, H5F_SIGNATURE_LEN)) { - /* - * Debug the boot block. - */ - status = H5F_debug(f, &addr, stdout, 0, VCOL); - - } else if (!HDmemcmp(sig, H5HL_MAGIC, H5HL_SIZEOF_MAGIC)) { - /* - * Debug a local heap. - */ - status = H5HL_debug(f, &addr, stdout, 0, VCOL); - - } else if (!HDmemcmp (sig, H5HG_MAGIC, H5HG_SIZEOF_MAGIC)) { - /* - * Debug a global heap collection. - */ - status = H5HG_debug (f, &addr, stdout, 0, VCOL); - - } else if (!HDmemcmp(sig, H5G_NODE_MAGIC, H5G_NODE_SIZEOF_MAGIC)) { - /* - * Debug a symbol table node. - */ - status = H5G_node_debug(f, &addr, stdout, 0, VCOL, &extra); - - } else if (!HDmemcmp(sig, H5B_MAGIC, H5B_SIZEOF_MAGIC)) { - /* - * Debug a B-tree. B-trees are debugged through the B-tree - * subclass. The subclass identifier is the byte immediately - * after the B-tree signature. - */ - H5B_subid_t subtype = (H5B_subid_t)sig[H5B_SIZEOF_MAGIC]; - - switch (subtype) { - case H5B_SNODE_ID: - status = H5G_node_debug(f, &addr, stdout, 0, VCOL, &extra); - break; - - case H5B_ISTORE_ID: - ndims = (int)extra.offset; - status = H5F_istore_debug (f, &addr, stdout, 0, VCOL, ndims); - break; - - default: - fprintf(stderr, "Unknown B-tree subtype %u\n", (unsigned) (subtype)); - HDexit(4); - } - - } else if (sig[0] == H5O_VERSION) { - /* - * This could be an object header. Since they don't have a signature - * it's a somewhat "ify" detection. - */ - status = H5O_debug(f, &addr, stdout, 0, VCOL); - - } else { - /* - * Got some other unrecognized signature. - */ - printf("%-*s ", VCOL, "Signature:"); - for (i = 0; i < 8; i++) { - if (sig[i] > ' ' && sig[i] <= '~' && '\\' != sig[i]) { - HDputchar(sig[i]); - } else if ('\\' == sig[i]) { - HDputchar('\\'); - HDputchar('\\'); - } else { - printf("\\%03o", sig[i]); - } - } - HDputchar('\n'); - - fprintf(stderr, "unknown signature\n"); - HDexit(4); - } - - if (status < 0) { - fprintf(stderr, "An error occurred\n"); - HDexit(5); - } - H5Fclose(fid); - return 0; -} diff --git a/src/h5ls.c b/src/h5ls.c deleted file mode 100644 index 4b0ea75..0000000 --- a/src/h5ls.c +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (C) 1998 NCSA - * All rights reserved. - * - * Programmer: Robb Matzke - * Monday, March 23, 1998 - */ -#include -#include -#include -#include - -#include -#ifndef HAVE_ATTRIBUTE -# undef __attribute__ -# define __attribute__(X) /*void*/ -# define __unused__ /*void*/ -#else -# define __unused__ __attribute__((unused)) -#endif - -static void -usage (const char *progname) -{ - fprintf (stderr, "usage: %s FILE [GROUP]\n", progname); - fprintf (stderr, " The file name may contain a printf integer format " - "to open a file family.\n"); - exit (1); -} - - -/*------------------------------------------------------------------------- - * Function: list_attr - * - * Purpose: Prints information about attributes. - * - * Return: Success: 0 - * - * Failure: -1 - * - * Programmer: Robb Matzke - * Friday, June 5, 1998 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -static herr_t -list_attr (hid_t obj, const char *attr_name, void __unused__ *op_data) -{ - hid_t attr; - int i; - - printf ("%*s%s", 26, "", attr_name); - if ((attr = H5Aopen_name (obj, attr_name))) { - hid_t space = H5Aget_space (attr); - hsize_t size[64]; - int ndims = H5Sget_dims (space, size, NULL); - H5Sclose (space); - printf (" {"); - for (i=0; i=0) { - sprintf (buf, "%lu:%lu:%lu:%lu", - statbuf.fileno[1], statbuf.fileno[0], - statbuf.objno[1], statbuf.objno[0]); - printf ("%-20s ", buf); - } - - if ((obj=H5Dopen (group, name))>=0) { - hsize_t size[64]; - hsize_t maxsize[64]; - hid_t space = H5Dget_space (obj); - int ndims = H5Sget_dims(space, size, maxsize); - printf ("Dataset {"); - for (i=0; i=0) { - printf ("Group\n"); - H5Aiterate (obj, NULL, list_attr, NULL); - H5Gclose (obj); - } else if (H5Gget_linkval (group, name, sizeof(buf), buf)>=0) { - if (NULL==HDmemchr (buf, 0, sizeof(buf))) { - strcpy (buf+sizeof(buf)-4, "..."); - } - printf (" -> %s\n", buf); - } else if ((obj=H5Topen (group, name))>=0) { - printf ("Data type\n"); - H5Aiterate (obj, NULL, list_attr, NULL); - H5Tclose (obj); - } else { - printf ("Unknown Type\n"); - } - - /* Restore error reporting */ - H5Eset_auto (func, edata); - return 0; -} - - - -/*------------------------------------------------------------------------- - * Function: main - * - * Purpose: Opens a file and lists the specified group - * - * Return: Success: 0 - * - * Failure: 1 - * - * Programmer: Robb Matzke - * Monday, March 23, 1998 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -int -main (int argc, char *argv[]) -{ - hid_t file, plist=H5P_DEFAULT; - const char *fname = NULL; - const char *gname = "/"; - const char *progname; - - /* Arguments */ - if ((progname=strrchr (argv[0], '/'))) progname++; - else progname = argv[0]; - if (argc<2 || argc>3) usage (progname); - fname = argv[1]; - if (argc>=3) gname = argv[2]; - - /* - * Open the file. If the file name contains a `%' then assume that a - * file family is being opened. - */ - if (strchr (fname, '%')) { - plist = H5Pcreate (H5P_FILE_ACCESS); - H5Pset_family (plist, 0, H5P_DEFAULT); - } - if ((file = H5Fopen (fname, H5F_ACC_RDONLY, plist))<0) exit (1); - if (H5Giterate (file, gname, NULL, list, NULL)<0) exit (1); - if (H5Fclose (file)<0) exit (1); - return 0; -} diff --git a/src/h5repart.c b/src/h5repart.c deleted file mode 100644 index 8faa9ea..0000000 --- a/src/h5repart.c +++ /dev/null @@ -1,388 +0,0 @@ -/* - * Copyright (C) 1998 NCSA - * All rights reserved. - * - * Programmer: Robb Matzke - * Wednesday, May 13, 1998 - * - * Purpose: Repartitions a file family. This program can be used to - * split a single file into a family of files, join a family of - * files into a single file, or copy one family to another while - * changing the size of the family members. It can also be used - * to copy a single file to a single file with holes. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define FALSE 0 -#define TRUE 1 -#define NAMELEN 4096 -#define GB *1024*1024*1024 - -#define MIN(X,Y) ((X)<(Y)?(X):(Y)) -#define MIN3(X,Y,Z) MIN(MIN(X,Y),Z) - - -/*------------------------------------------------------------------------- - * Function: usage - * - * Purpose: Prints a usage message. - * - * Return: void - * - * Programmer: Robb Matzke - * Wednesday, May 13, 1998 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -static void -usage (const char *progname) -{ - fprintf (stderr, "usage: %s [-[b|m] N[g|m|k]] SRC DST\n", progname); - fprintf (stderr, " -b N The I/O block size, defaults to 1kB\n"); - fprintf (stderr, " -m N The destination member size or 1GB\n"); - fprintf (stderr, " SRC The name of the source file\n"); - fprintf (stderr, " DST The name of the destination files\n"); - fprintf (stderr, "Sizes may be suffixed with `g' for GB, `m' for MB or " - "`k' for kB.\n"); - fprintf (stderr, "File family names include an integer printf " - "format such as `%%d'\n"); - exit (1); -} - - -/*------------------------------------------------------------------------- - * Function: get_size - * - * Purpose: Reads a size option of the form `-XNS' where `X' is any - * letter, `N' is a multi-character positive decimal number, and - * `S' is an optional suffix letter in the set [GgMmk]. The - * option may also be split among two arguments as: `-X NS'. - * The input value of ARGNO is the argument number for the - * switch in the ARGV vector and ARGC is the number of entries - * in that vector. - * - * Return: Success: The value N multiplied according to the - * suffix S. On return ARGNO will be the number - * of the next argument to process. - * - * Failure: Calls usage() which exits with a non-zero - * status. - * - * Programmer: Robb Matzke - * Wednesday, May 13, 1998 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -static off_t -get_size (const char *progname, int *argno, int argc, char *argv[]) -{ - off_t retval; - char *suffix; - - if (isdigit (argv[*argno][2])) { - retval = strtol (argv[*argno]+2, &suffix, 10); - (*argno)++; - } else if (argv[*argno][2] || *argno+1>=argc) { - usage (progname); - } else { - retval = strtol (argv[*argno+1], &suffix, 0); - if (suffix==argv[*argno+1]) usage (progname); - *argno += 2; - } - if (suffix && suffix[0] && !suffix[1]) { - switch (*suffix) { - case 'G': - case 'g': - retval *= 1024 * 1024 * 1024; - break; - case 'M': - case 'm': - retval *= 1024 * 1024; - break; - case 'k': - retval *= 1024; - break; - default: - usage (progname); - } - } else if (suffix && suffix[0]) { - usage (progname); - } - return retval; -} - - -/*------------------------------------------------------------------------- - * Function: main - * - * Purpose: Split an hdf5 file - * - * Return: Success: - * - * Failure: - * - * Programmer: Robb Matzke - * Wednesday, May 13, 1998 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -int -main (int argc, char *argv[]) -{ - const char *prog_name; /*program name */ - size_t blk_size=1024; /*size of each I/O block */ - char *buf=NULL; /*I/O block buffer */ - size_t n, i; /*counters */ - ssize_t nio; /*I/O return value */ - int argno=1; /*program argument number */ - int src, dst=-1; /*source & destination files */ - int need_seek=FALSE; /*destination needs to seek? */ - int need_write; /*data needs to be written? */ - struct stat sb; /*temporary file stat buffer */ - int verbose=FALSE; /*display file names? */ - size_t left_overs=0; /*amount of zeros left over */ - - const char *src_gen_name; /*general source name */ - char src_name[NAMELEN]; /*source member name */ - off_t src_offset=0; /*offset in source member */ - int src_is_family; /*is source name a family name? */ - int src_membno=0; /*source member number */ - off_t src_size; /*source logical member size */ - off_t src_act_size; /*source actual member size */ - - const char *dst_gen_name; /*general destination name */ - char dst_name[NAMELEN]; /*destination member name */ - off_t dst_offset=0; /*offset in destination member */ - int dst_is_family; /*is dst name a family name? */ - int dst_membno=0; /*destination member number */ - off_t dst_size=1 GB; /*destination logical memb size */ - - /* - * Get the program name from argv[0]. Use only the last component. - */ - if ((prog_name=strrchr (argv[0], '/'))) prog_name++; - else prog_name = argv[0]; - - /* - * Parse switches. - */ - while (argno=argc) usage (prog_name); - src_gen_name = argv[argno++]; - sprintf (src_name, src_gen_name, src_membno); - src_is_family = strcmp (src_name, src_gen_name); - if ((src=open (src_name, O_RDONLY))<0) { - perror (src_name); - exit (1); - } - if (fstat (src, &sb)<0) { - perror ("fstat"); - exit (1); - } - src_size = src_act_size = sb.st_size; - if (verbose) fprintf (stderr, "< %s\n", src_name); - - /* - * Get the name for the destination file and open the first member. - */ - if (argno>=argc) usage (prog_name); - dst_gen_name = argv[argno++]; - sprintf (dst_name, dst_gen_name, dst_membno); - dst_is_family = strcmp (dst_name, dst_gen_name); - if ((dst=open (dst_name, O_RDWR|O_CREAT|O_TRUNC, 0666))<0) { - perror (dst_name); - exit (1); - } - if (verbose) fprintf (stderr, "> %s\n", dst_name); - - /* No more arguments */ - if (argnosrc_size) { - fprintf (stderr, "%s: member truncated to %lu bytes\n", - src_name, (unsigned long)src_size); - } - src_offset = 0; - if (verbose) fprintf (stderr, "< %s\n", src_name); - } - - /* - * Update the destination offset, opening a new member if one will be - * needed. The first member is extended to the logical member size - * but other members might be smaller if they end with a hole. - */ - dst_offset += n; - if (dst_is_family && dst_offset==dst_size) { - if (0==dst_membno) { - if (lseek (dst, dst_size-1, SEEK_SET)<0) { - perror ("lseek"); - exit (1); - } - if (read (dst, buf, 1)<0) { - perror ("read"); - exit (1); - } - if (lseek (dst, dst_size-1, SEEK_SET)<0) { - perror ("lseek"); - exit (1); - } - if (write (dst, buf, 1)<0) { - perror ("write"); - exit (1); - } - } - close (dst); - sprintf (dst_name, dst_gen_name, ++dst_membno); - if ((dst=open (dst_name, O_RDWR|O_CREAT|O_TRUNC, 0666))<0) { - perror (dst_name); - exit (1); - } - dst_offset = 0; - need_seek = FALSE; - if (verbose) fprintf (stderr, "> %s\n", dst_name); - } - } - - /* - * Make sure the last family member is the right size and then close it. - * The last member can't end with a hole or hdf5 will think that the - * family has been truncated. - */ - if (need_seek) { - if (lseek (dst, dst_offset-1, SEEK_SET)<0) { - perror ("lseek"); - exit (1); - } - if (read (dst, buf, 1)<0) { - perror ("read"); - exit (1); - } - if (lseek (dst, dst_offset-1, SEEK_SET)<0) { - perror ("lseek"); - exit (1); - } - if (write (dst, buf, 1)<0) { - perror ("write"); - exit (1); - } - } - close (dst); - - /* Free resources and return */ - free (buf); - return 0; -} diff --git a/test/.distdep b/test/.distdep index 5706161..e99e3c0 100644 --- a/test/.distdep +++ b/test/.distdep @@ -1,9 +1,3 @@ -testhdf5.o: \ - testhdf5.c \ - testhdf5.h \ - ../src/H5private.h \ - ../src/H5public.h \ - ../src/H5config.h tattr.o: \ tattr.c \ testhdf5.h \ @@ -157,34 +151,6 @@ th5s.o: \ ../src/H5Zprivate.h \ ../src/H5Zpublic.h \ ../src/H5Pprivate.h -dtypes.o: \ - dtypes.c \ - ../src/hdf5.h \ - ../src/H5public.h \ - ../src/H5config.h \ - ../src/H5Ipublic.h \ - ../src/H5Apublic.h \ - ../src/H5ACpublic.h \ - ../src/H5Bpublic.h \ - ../src/H5Dpublic.h \ - ../src/H5Epublic.h \ - ../src/H5Fpublic.h \ - ../src/H5Gpublic.h \ - ../src/H5HGpublic.h \ - ../src/H5HLpublic.h \ - ../src/H5MFpublic.h \ - ../src/H5MMpublic.h \ - ../src/H5Opublic.h \ - ../src/H5Ppublic.h \ - ../src/H5Zpublic.h \ - ../src/H5Spublic.h \ - ../src/H5Tpublic.h \ - ../src/H5Tpkg.h \ - ../src/H5HGprivate.h \ - ../src/H5Fprivate.h \ - ../src/H5private.h \ - ../src/H5Tprivate.h \ - ../src/H5Gprivate.h hyperslab.o: \ hyperslab.c \ ../src/H5private.h \ @@ -238,27 +204,6 @@ dsets.o: \ ../src/H5Zpublic.h \ ../src/H5Spublic.h \ ../src/H5Tpublic.h -cmpd_dset.o: \ - cmpd_dset.c \ - ../src/hdf5.h \ - ../src/H5public.h \ - ../src/H5config.h \ - ../src/H5Ipublic.h \ - ../src/H5Apublic.h \ - ../src/H5ACpublic.h \ - ../src/H5Bpublic.h \ - ../src/H5Dpublic.h \ - ../src/H5Epublic.h \ - ../src/H5Fpublic.h \ - ../src/H5Gpublic.h \ - ../src/H5HGpublic.h \ - ../src/H5HLpublic.h \ - ../src/H5MFpublic.h \ - ../src/H5MMpublic.h \ - ../src/H5Opublic.h \ - ../src/H5Ppublic.h \ - ../src/H5Zpublic.h \ - ../src/H5Spublic.h extend.o: \ extend.c \ ../src/hdf5.h \ @@ -446,3 +391,58 @@ bittests.o: \ ../src/H5Gprivate.h \ ../src/H5Gpublic.h \ ../src/H5Bprivate.h +cmpd_dset.o: \ + cmpd_dset.c \ + ../src/hdf5.h \ + ../src/H5public.h \ + ../src/H5config.h \ + ../src/H5Ipublic.h \ + ../src/H5Apublic.h \ + ../src/H5ACpublic.h \ + ../src/H5Bpublic.h \ + ../src/H5Dpublic.h \ + ../src/H5Epublic.h \ + ../src/H5Fpublic.h \ + ../src/H5Gpublic.h \ + ../src/H5HGpublic.h \ + ../src/H5HLpublic.h \ + ../src/H5MFpublic.h \ + ../src/H5MMpublic.h \ + ../src/H5Opublic.h \ + ../src/H5Ppublic.h \ + ../src/H5Zpublic.h \ + ../src/H5Spublic.h +testhdf5.o: \ + testhdf5.c \ + testhdf5.h \ + ../src/H5private.h \ + ../src/H5public.h \ + ../src/H5config.h +dtypes.o: \ + dtypes.c \ + ../src/hdf5.h \ + ../src/H5public.h \ + ../src/H5config.h \ + ../src/H5Ipublic.h \ + ../src/H5Apublic.h \ + ../src/H5ACpublic.h \ + ../src/H5Bpublic.h \ + ../src/H5Dpublic.h \ + ../src/H5Epublic.h \ + ../src/H5Fpublic.h \ + ../src/H5Gpublic.h \ + ../src/H5HGpublic.h \ + ../src/H5HLpublic.h \ + ../src/H5MFpublic.h \ + ../src/H5MMpublic.h \ + ../src/H5Opublic.h \ + ../src/H5Ppublic.h \ + ../src/H5Zpublic.h \ + ../src/H5Spublic.h \ + ../src/H5Tpublic.h \ + ../src/H5Tpkg.h \ + ../src/H5HGprivate.h \ + ../src/H5Fprivate.h \ + ../src/H5private.h \ + ../src/H5Tprivate.h \ + ../src/H5Gprivate.h diff --git a/test/Makefile.in b/test/Makefile.in index 3a68a67..8ddd2d8 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -11,8 +11,6 @@ CPPFLAGS=-I. -I../src @CPPFLAGS@ # These are our main targets. They should be listed in the order to be # executed, generally most specific tests to least specific tests. -PROGS=testhdf5 gheap hyperslab istore bittests dtypes dsets cmpd_dset extend \ - external shtype iopipe big links chunk TESTS=testhdf5 gheap hyperslab istore bittests dtypes dsets cmpd_dset extend \ external shtype links TIMINGS=iopipe chunk @@ -26,62 +24,14 @@ MOSTLYCLEAN=cmpd_dset.h5 dataset.h5 extend.h5 istore.h5 tfile1.h5 tfile2.h5 \ gheap1.h5 gheap2.h5 gheap3.h5 gheap4.h5 shtype0.h5 shtype1.h5 \ shtype2a.h5 shtype2b.h5 shtype3.h5 links.h5 chunk.h5 -# Source and object files for programs... The PROG_SRC list contains all the +# Source and object files for programs... The TEST_SRC list contains all the # source files and is used for things like dependencies, archiving, etc. The # other source lists are for the individual tests, the files of which may # overlap with other tests. -PROG_SRC=testhdf5.c tattr.c tfile.c theap.c tmeta.c tohdr.c tstab.c th5s.c \ +TEST_SRC=testhdf5.c tattr.c tfile.c theap.c tmeta.c tohdr.c tstab.c th5s.c \ dtypes.c hyperslab.c istore.c dsets.c cmpd_dset.c extend.c external.c \ iopipe.c gheap.c shtype.c big.c links.c chunk.c bittests.c -PROG_OBJ=$(PROG_SRC:.c=.o) - -TESTHDF5_SRC=testhdf5.c tattr.c tfile.c theap.c tmeta.c tohdr.c tstab.c th5s.c -TESTHDF5_OBJ=$(TESTHDF5_SRC:.c=.o) - -GHEAP_SRC=gheap.c -GHEAP_OBJ=$(GHEAP_SRC:.c=.o) - -DSETS_SRC=dsets.c -DSETS_OBJ=$(DSETS_SRC:.c=.o) - -BITTESTS_SRC=bittests.c -BITTESTS_OBJ=$(BITTESTS_SRC:.c=.o) - -DTYPES_SRC=dtypes.c -DTYPES_OBJ=$(DTYPES_SRC:.c=.o) - -HYPERSLAB_SRC=hyperslab.c -HYPERSLAB_OBJ=$(HYPERSLAB_SRC:.c=.o) - -ISTORE_SRC=istore.c -ISTORE_OBJ=$(ISTORE_SRC:.c=.o) - -CMPD_DSET_SRC=cmpd_dset.c -CMPD_DSET_OBJ=$(CMPD_DSET_SRC:.c=.o) - -EXTEND_SRC=extend.c -EXTEND_OBJ=$(EXTEND_SRC:.c=.o) - -EXTERNAL_SRC=external.c -EXTERNAL_OBJ=$(EXTERNAL_SRC:.c=.o) - -GRPTIME_SRC=grptime.c -GRPTIME_OBJ=$(GRPTIME_SRC:.c=.o) - -SHTYPE_SRC=shtype.c -SHTYPE_OBJ=$(SHTYPE_SRC:.c=.o) - -IOPIPE_SRC=iopipe.c -IOPIPE_OBJ=$(IOPIPE_SRC:.c=.o) - -BIG_SRC=big.c -BIG_OBJ=$(BIG_SRC:.c=.o) - -LINKS_SRC=links.c -LINKS_OBJ=$(LINKS_SRC:.c=.o) - -CHUNK_SRC=chunk.c -CHUNK_OBJ=$(CHUNK_SRC:.c=.o) +TEST_OBJ=$(PROG_SRC:.c=.o) # Private header files (not to be installed)... PRIVATE_HDR=testhdf5.h @@ -97,52 +47,53 @@ timings _timings: $(TIMINGS) done; # How to build the programs... +TESTHDF5_OBJ=testhdf5.o tattr.o tfile.o theap.o tmeta.o tohdr.o tstab.o th5s.o testhdf5: $(TESTHDF5_OBJ) ../src/libhdf5.a $(CC) $(CFLAGS) -o $@ $(TESTHDF5_OBJ) ../src/libhdf5.a $(LIBS) -gheap: $(GHEAP_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(GHEAP_OBJ) ../src/libhdf5.a $(LIBS) +gheap: gheap.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ gheap.o ../src/libhdf5.a $(LIBS) -dsets: $(DSETS_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(DSETS_OBJ) ../src/libhdf5.a $(LIBS) +dsets: dsets.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ dsets.o ../src/libhdf5.a $(LIBS) -bittests: $(BITTESTS_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(BITTESTS_OBJ) ../src/libhdf5.a $(LIBS) +bittests: bittests.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ bittests.o ../src/libhdf5.a $(LIBS) -dtypes: $(DTYPES_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(DTYPES_OBJ) ../src/libhdf5.a $(LIBS) +dtypes: dtypes.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ dtypes.o ../src/libhdf5.a $(LIBS) -hyperslab: $(HYPERSLAB_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(HYPERSLAB_OBJ) ../src/libhdf5.a $(LIBS) +hyperslab: hyperslab.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ hyperslab.o ../src/libhdf5.a $(LIBS) -istore: $(ISTORE_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(ISTORE_OBJ) ../src/libhdf5.a $(LIBS) +istore: istore.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ istore.o ../src/libhdf5.a $(LIBS) -cmpd_dset: $(CMPD_DSET_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(CMPD_DSET_OBJ) ../src/libhdf5.a $(LIBS) +cmpd_dset: cmpd_dset.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ cmpd_dset.o ../src/libhdf5.a $(LIBS) -extend: $(EXTEND_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(EXTEND_OBJ) ../src/libhdf5.a $(LIBS) +extend: extend.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ extend.o ../src/libhdf5.a $(LIBS) -external: $(EXTERNAL_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(EXTERNAL_OBJ) ../src/libhdf5.a $(LIBS) +external: external.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ external.o ../src/libhdf5.a $(LIBS) -shtype: $(SHTYPE_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(SHTYPE_OBJ) ../src/libhdf5.a $(LIBS) +shtype: shtype.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ shtype.o ../src/libhdf5.a $(LIBS) -iopipe: $(IOPIPE_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(IOPIPE_OBJ) ../src/libhdf5.a $(LIBS) +iopipe: iopipe.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ iopipe.o ../src/libhdf5.a $(LIBS) -grptime: $(GRPTIME_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(GRPTIME_OBJ) ../src/libhdf5.a $(LIBS) +grptime: grptime.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ grptime.o ../src/libhdf5.a $(LIBS) -big: $(BIG_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(BIG_OBJ) ../src/libhdf5.a $(LIBS) +big: big.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ big.o ../src/libhdf5.a $(LIBS) -links: $(LINKS_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(LINKS_OBJ) ../src/libhdf5.a $(LIBS) +links: links.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ links.o ../src/libhdf5.a $(LIBS) -chunk: $(CHUNK_OBJ) ../src/libhdf5.a - $(CC) $(CFLAGS) -o $@ $(CHUNK_OBJ) ../src/libhdf5.a $(LIBS) +chunk: chunk.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ chunk.o ../src/libhdf5.a $(LIBS) @CONCLUDE@ diff --git a/test/dtypes.c b/test/dtypes.c index 9bd8747..8898adc 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -62,7 +62,9 @@ static int noverflows_g = 0; * signal. Therefore, if the following constant is defined then tests that * might raise SIGFPE are executed in a child process. */ -#define HANDLE_SIGFPE +#if defined(HAVE_FORK) && defined(HAVE_WAITPID) +# define HANDLE_SIGFPE +#endif /*------------------------------------------------------------------------- @@ -79,15 +81,17 @@ static int noverflows_g = 0; * *------------------------------------------------------------------------- */ -#ifdef HANDLE_SIGFPE static void fpe_handler(int __unused__ signo) { puts(" -SKIP-"); puts(" Test skipped due to SIGFPE from probable overflow."); +#ifndef HANDLE_SIGFPE + puts(" Remaining tests could not be run."); + puts(" Please turn off SIGFPE on overflows and try again."); +#endif exit(255); } -#endif /*------------------------------------------------------------------------- @@ -870,12 +874,13 @@ test_conv_flt_1 (const char *name, hid_t src, hid_t dst) return 1; } } +#endif /* - * The remainder of this function is executed only by the child. + * The remainder of this function is executed only by the child if + * HANDLE_SIGFPE is defined. */ signal(SIGFPE,fpe_handler); -#endif /* What are the names of the source and destination types */ if (H5Tequal(src, H5T_NATIVE_FLOAT)) { diff --git a/tools/Makefile.in b/tools/Makefile.in new file mode 100644 index 0000000..1f93b00 --- /dev/null +++ b/tools/Makefile.in @@ -0,0 +1,32 @@ +# HDF5 Library Makefile(.in) +# +# Copyright (C) 1997 National Center for Supercomputing Applications. +# All rights reserved. +# +# +@COMMENCE@ + +# Add include directory to the C preprocessor flags. +CPPFLAGS=-I../src @CPPFLAGS@ + +# These are our main targets: +PROGS=h5debug h5import h5ls h5repart + +# Source and object files for programs... +PROG_SRC=h5debug.c h5import.c h5ls.c h5repart.c +PROG_OBJ=$(PROG_SRC:.c=.o) + +# How to build the programs... +h5debug: h5debug.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ h5debug.o ../src/libhdf5.a $(LIBS) + +h5import: h5import.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ h5import.o ../src/libhdf5.a $(LIBS) + +h5ls: h5ls.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ h5ls.o ../src/libhdf5.a $(LIBS) + +h5repart: h5repart.o ../src/libhdf5.a + $(CC) $(CFLAGS) -o $@ h5repart.o ../src/libhdf5.a $(LIBS) + +@CONCLUDE@ diff --git a/tools/h5debug.c b/tools/h5debug.c new file mode 100644 index 0000000..fdf21d9 --- /dev/null +++ b/tools/h5debug.c @@ -0,0 +1,178 @@ +/*------------------------------------------------------------------------- + * Copyright (C) 1997 National Center for Supercomputing Applications. + * All rights reserved. + * + *------------------------------------------------------------------------- + * + * Created: debug.c + * Jul 18 1997 + * Robb Matzke + * + * Purpose: Debugs an existing HDF5 file at a low level. + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define INDENT 3 +#define VCOL 50 + + +/*------------------------------------------------------------------------- + * Function: main + * + * Usage: debug FILENAME [OFFSET] + * + * Return: Success: exit (0) + * + * Failure: exit (non-zero) + * + * Programmer: Robb Matzke + * matzke@llnl.gov + * Jul 18 1997 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +int +main(int argc, char *argv[]) +{ + hid_t fid, plist=H5P_DEFAULT; + H5F_t *f; + haddr_t addr; + uint8 sig[16]; + intn i, ndims; + herr_t status = SUCCEED; + haddr_t extra; + + /* + * Open the file and get the file descriptor. + */ + if (strchr (argv[1], '%')) { + plist = H5Pcreate (H5P_FILE_ACCESS); + H5Pset_family (plist, 0, H5P_DEFAULT); + } + if ((fid = H5Fopen(argv[1], H5F_ACC_RDONLY, plist)) < 0) { + fprintf(stderr, "cannot open file\n"); + HDexit(1); + } + if (NULL == (f = H5I_object(fid))) { + fprintf(stderr, "cannot obtain H5F_t pointer\n"); + HDexit(2); + } + + /* + * Parse command arguments. + */ + H5F_addr_reset(&addr); + H5F_addr_reset(&extra); + if (argc > 2) { + printf("New address: %s\n", argv[2]); + addr.offset = HDstrtoll(argv[2], NULL, 0); + } + if (argc > 3) { + extra.offset = HDstrtoll(argv[3], NULL, 0); + } + /* + * Read the signature at the specified file position. + */ + printf("Reading signature at address "); + H5F_addr_print(stdout, &addr); + printf(" (rel)\n"); + if (H5F_block_read(f, &addr, (hsize_t)sizeof(sig), H5D_XFER_DFLT, sig) < 0) { + fprintf(stderr, "cannot read signature\n"); + HDexit(3); + } + if (!HDmemcmp(sig, H5F_SIGNATURE, H5F_SIGNATURE_LEN)) { + /* + * Debug the boot block. + */ + status = H5F_debug(f, &addr, stdout, 0, VCOL); + + } else if (!HDmemcmp(sig, H5HL_MAGIC, H5HL_SIZEOF_MAGIC)) { + /* + * Debug a local heap. + */ + status = H5HL_debug(f, &addr, stdout, 0, VCOL); + + } else if (!HDmemcmp (sig, H5HG_MAGIC, H5HG_SIZEOF_MAGIC)) { + /* + * Debug a global heap collection. + */ + status = H5HG_debug (f, &addr, stdout, 0, VCOL); + + } else if (!HDmemcmp(sig, H5G_NODE_MAGIC, H5G_NODE_SIZEOF_MAGIC)) { + /* + * Debug a symbol table node. + */ + status = H5G_node_debug(f, &addr, stdout, 0, VCOL, &extra); + + } else if (!HDmemcmp(sig, H5B_MAGIC, H5B_SIZEOF_MAGIC)) { + /* + * Debug a B-tree. B-trees are debugged through the B-tree + * subclass. The subclass identifier is the byte immediately + * after the B-tree signature. + */ + H5B_subid_t subtype = (H5B_subid_t)sig[H5B_SIZEOF_MAGIC]; + + switch (subtype) { + case H5B_SNODE_ID: + status = H5G_node_debug(f, &addr, stdout, 0, VCOL, &extra); + break; + + case H5B_ISTORE_ID: + ndims = (int)extra.offset; + status = H5F_istore_debug (f, &addr, stdout, 0, VCOL, ndims); + break; + + default: + fprintf(stderr, "Unknown B-tree subtype %u\n", (unsigned) (subtype)); + HDexit(4); + } + + } else if (sig[0] == H5O_VERSION) { + /* + * This could be an object header. Since they don't have a signature + * it's a somewhat "ify" detection. + */ + status = H5O_debug(f, &addr, stdout, 0, VCOL); + + } else { + /* + * Got some other unrecognized signature. + */ + printf("%-*s ", VCOL, "Signature:"); + for (i = 0; i < 8; i++) { + if (sig[i] > ' ' && sig[i] <= '~' && '\\' != sig[i]) { + HDputchar(sig[i]); + } else if ('\\' == sig[i]) { + HDputchar('\\'); + HDputchar('\\'); + } else { + printf("\\%03o", sig[i]); + } + } + HDputchar('\n'); + + fprintf(stderr, "unknown signature\n"); + HDexit(4); + } + + if (status < 0) { + fprintf(stderr, "An error occurred\n"); + HDexit(5); + } + H5Fclose(fid); + return 0; +} diff --git a/tools/h5import.c b/tools/h5import.c new file mode 100644 index 0000000..de1af53 --- /dev/null +++ b/tools/h5import.c @@ -0,0 +1,119 @@ +/* + * Copyright (C) 1998 NCSA + * All rights reserved. + * + * Programmer: Robb Matzke + * Thursday, June 11, 1998 + * + * Purpose: Create an hdf5 file with a 1d dataset of uint8. + */ +#include +#include +#include +#include +#include +#include + + +/*------------------------------------------------------------------------- + * Function: usage + * + * Purpose: Print a usage message and exit with non-zero status + * + * Return: never returns + * + * Programmer: Robb Matzke + * Thursday, June 11, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static void +usage (const char *argv0) +{ + fprintf (stderr, "Usage: %s -f HDF5-FILE FILES...\n", argv0); + exit (1); +} + + +/*------------------------------------------------------------------------- + * Function: main + * + * Purpose: + * + * Return: Success: 0 + * + * Failure: 1 + * + * Programmer: Robb Matzke + * Thursday, June 11, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +int +main (int argc, char *argv[]) +{ + hid_t file, space, dset; + const char *output_name, *dset_name; + int argno, fd=-1; + hsize_t size[1]; + struct stat sb; + + /* Parse arguments */ + if (argc<4) usage (argv[0]); + if (strcmp (argv[1], "-f")) usage (argv[0]); + output_name = argv[2]; + + /* create the file */ + H5E_BEGIN_TRY { + if ((file = H5Fcreate (output_name, H5F_ACC_EXCL, + H5P_DEFAULT, H5P_DEFAULT))<0 && + (file = H5Fopen (output_name, H5F_ACC_RDWR, H5P_DEFAULT)<0)) { + fprintf (stderr, "%s: unable to create or open hdf5 file\n", + output_name); + exit (1); + } + } H5E_END_TRY; + + /* process files from command-line */ + for (argno=3; argno=0) close (fd); + fd = -1; + H5E_BEGIN_TRY { + H5Sclose (space); + H5Dclose (dset); + } H5E_END_TRY; + } + + /* Close the file */ + H5Fclose (file); + return 0; +} diff --git a/tools/h5ls.c b/tools/h5ls.c new file mode 100644 index 0000000..4b0ea75 --- /dev/null +++ b/tools/h5ls.c @@ -0,0 +1,197 @@ +/* + * Copyright (C) 1998 NCSA + * All rights reserved. + * + * Programmer: Robb Matzke + * Monday, March 23, 1998 + */ +#include +#include +#include +#include + +#include +#ifndef HAVE_ATTRIBUTE +# undef __attribute__ +# define __attribute__(X) /*void*/ +# define __unused__ /*void*/ +#else +# define __unused__ __attribute__((unused)) +#endif + +static void +usage (const char *progname) +{ + fprintf (stderr, "usage: %s FILE [GROUP]\n", progname); + fprintf (stderr, " The file name may contain a printf integer format " + "to open a file family.\n"); + exit (1); +} + + +/*------------------------------------------------------------------------- + * Function: list_attr + * + * Purpose: Prints information about attributes. + * + * Return: Success: 0 + * + * Failure: -1 + * + * Programmer: Robb Matzke + * Friday, June 5, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +list_attr (hid_t obj, const char *attr_name, void __unused__ *op_data) +{ + hid_t attr; + int i; + + printf ("%*s%s", 26, "", attr_name); + if ((attr = H5Aopen_name (obj, attr_name))) { + hid_t space = H5Aget_space (attr); + hsize_t size[64]; + int ndims = H5Sget_dims (space, size, NULL); + H5Sclose (space); + printf (" {"); + for (i=0; i=0) { + sprintf (buf, "%lu:%lu:%lu:%lu", + statbuf.fileno[1], statbuf.fileno[0], + statbuf.objno[1], statbuf.objno[0]); + printf ("%-20s ", buf); + } + + if ((obj=H5Dopen (group, name))>=0) { + hsize_t size[64]; + hsize_t maxsize[64]; + hid_t space = H5Dget_space (obj); + int ndims = H5Sget_dims(space, size, maxsize); + printf ("Dataset {"); + for (i=0; i=0) { + printf ("Group\n"); + H5Aiterate (obj, NULL, list_attr, NULL); + H5Gclose (obj); + } else if (H5Gget_linkval (group, name, sizeof(buf), buf)>=0) { + if (NULL==HDmemchr (buf, 0, sizeof(buf))) { + strcpy (buf+sizeof(buf)-4, "..."); + } + printf (" -> %s\n", buf); + } else if ((obj=H5Topen (group, name))>=0) { + printf ("Data type\n"); + H5Aiterate (obj, NULL, list_attr, NULL); + H5Tclose (obj); + } else { + printf ("Unknown Type\n"); + } + + /* Restore error reporting */ + H5Eset_auto (func, edata); + return 0; +} + + + +/*------------------------------------------------------------------------- + * Function: main + * + * Purpose: Opens a file and lists the specified group + * + * Return: Success: 0 + * + * Failure: 1 + * + * Programmer: Robb Matzke + * Monday, March 23, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +int +main (int argc, char *argv[]) +{ + hid_t file, plist=H5P_DEFAULT; + const char *fname = NULL; + const char *gname = "/"; + const char *progname; + + /* Arguments */ + if ((progname=strrchr (argv[0], '/'))) progname++; + else progname = argv[0]; + if (argc<2 || argc>3) usage (progname); + fname = argv[1]; + if (argc>=3) gname = argv[2]; + + /* + * Open the file. If the file name contains a `%' then assume that a + * file family is being opened. + */ + if (strchr (fname, '%')) { + plist = H5Pcreate (H5P_FILE_ACCESS); + H5Pset_family (plist, 0, H5P_DEFAULT); + } + if ((file = H5Fopen (fname, H5F_ACC_RDONLY, plist))<0) exit (1); + if (H5Giterate (file, gname, NULL, list, NULL)<0) exit (1); + if (H5Fclose (file)<0) exit (1); + return 0; +} diff --git a/tools/h5repart.c b/tools/h5repart.c new file mode 100644 index 0000000..8faa9ea --- /dev/null +++ b/tools/h5repart.c @@ -0,0 +1,388 @@ +/* + * Copyright (C) 1998 NCSA + * All rights reserved. + * + * Programmer: Robb Matzke + * Wednesday, May 13, 1998 + * + * Purpose: Repartitions a file family. This program can be used to + * split a single file into a family of files, join a family of + * files into a single file, or copy one family to another while + * changing the size of the family members. It can also be used + * to copy a single file to a single file with holes. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define FALSE 0 +#define TRUE 1 +#define NAMELEN 4096 +#define GB *1024*1024*1024 + +#define MIN(X,Y) ((X)<(Y)?(X):(Y)) +#define MIN3(X,Y,Z) MIN(MIN(X,Y),Z) + + +/*------------------------------------------------------------------------- + * Function: usage + * + * Purpose: Prints a usage message. + * + * Return: void + * + * Programmer: Robb Matzke + * Wednesday, May 13, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static void +usage (const char *progname) +{ + fprintf (stderr, "usage: %s [-[b|m] N[g|m|k]] SRC DST\n", progname); + fprintf (stderr, " -b N The I/O block size, defaults to 1kB\n"); + fprintf (stderr, " -m N The destination member size or 1GB\n"); + fprintf (stderr, " SRC The name of the source file\n"); + fprintf (stderr, " DST The name of the destination files\n"); + fprintf (stderr, "Sizes may be suffixed with `g' for GB, `m' for MB or " + "`k' for kB.\n"); + fprintf (stderr, "File family names include an integer printf " + "format such as `%%d'\n"); + exit (1); +} + + +/*------------------------------------------------------------------------- + * Function: get_size + * + * Purpose: Reads a size option of the form `-XNS' where `X' is any + * letter, `N' is a multi-character positive decimal number, and + * `S' is an optional suffix letter in the set [GgMmk]. The + * option may also be split among two arguments as: `-X NS'. + * The input value of ARGNO is the argument number for the + * switch in the ARGV vector and ARGC is the number of entries + * in that vector. + * + * Return: Success: The value N multiplied according to the + * suffix S. On return ARGNO will be the number + * of the next argument to process. + * + * Failure: Calls usage() which exits with a non-zero + * status. + * + * Programmer: Robb Matzke + * Wednesday, May 13, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static off_t +get_size (const char *progname, int *argno, int argc, char *argv[]) +{ + off_t retval; + char *suffix; + + if (isdigit (argv[*argno][2])) { + retval = strtol (argv[*argno]+2, &suffix, 10); + (*argno)++; + } else if (argv[*argno][2] || *argno+1>=argc) { + usage (progname); + } else { + retval = strtol (argv[*argno+1], &suffix, 0); + if (suffix==argv[*argno+1]) usage (progname); + *argno += 2; + } + if (suffix && suffix[0] && !suffix[1]) { + switch (*suffix) { + case 'G': + case 'g': + retval *= 1024 * 1024 * 1024; + break; + case 'M': + case 'm': + retval *= 1024 * 1024; + break; + case 'k': + retval *= 1024; + break; + default: + usage (progname); + } + } else if (suffix && suffix[0]) { + usage (progname); + } + return retval; +} + + +/*------------------------------------------------------------------------- + * Function: main + * + * Purpose: Split an hdf5 file + * + * Return: Success: + * + * Failure: + * + * Programmer: Robb Matzke + * Wednesday, May 13, 1998 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +int +main (int argc, char *argv[]) +{ + const char *prog_name; /*program name */ + size_t blk_size=1024; /*size of each I/O block */ + char *buf=NULL; /*I/O block buffer */ + size_t n, i; /*counters */ + ssize_t nio; /*I/O return value */ + int argno=1; /*program argument number */ + int src, dst=-1; /*source & destination files */ + int need_seek=FALSE; /*destination needs to seek? */ + int need_write; /*data needs to be written? */ + struct stat sb; /*temporary file stat buffer */ + int verbose=FALSE; /*display file names? */ + size_t left_overs=0; /*amount of zeros left over */ + + const char *src_gen_name; /*general source name */ + char src_name[NAMELEN]; /*source member name */ + off_t src_offset=0; /*offset in source member */ + int src_is_family; /*is source name a family name? */ + int src_membno=0; /*source member number */ + off_t src_size; /*source logical member size */ + off_t src_act_size; /*source actual member size */ + + const char *dst_gen_name; /*general destination name */ + char dst_name[NAMELEN]; /*destination member name */ + off_t dst_offset=0; /*offset in destination member */ + int dst_is_family; /*is dst name a family name? */ + int dst_membno=0; /*destination member number */ + off_t dst_size=1 GB; /*destination logical memb size */ + + /* + * Get the program name from argv[0]. Use only the last component. + */ + if ((prog_name=strrchr (argv[0], '/'))) prog_name++; + else prog_name = argv[0]; + + /* + * Parse switches. + */ + while (argno=argc) usage (prog_name); + src_gen_name = argv[argno++]; + sprintf (src_name, src_gen_name, src_membno); + src_is_family = strcmp (src_name, src_gen_name); + if ((src=open (src_name, O_RDONLY))<0) { + perror (src_name); + exit (1); + } + if (fstat (src, &sb)<0) { + perror ("fstat"); + exit (1); + } + src_size = src_act_size = sb.st_size; + if (verbose) fprintf (stderr, "< %s\n", src_name); + + /* + * Get the name for the destination file and open the first member. + */ + if (argno>=argc) usage (prog_name); + dst_gen_name = argv[argno++]; + sprintf (dst_name, dst_gen_name, dst_membno); + dst_is_family = strcmp (dst_name, dst_gen_name); + if ((dst=open (dst_name, O_RDWR|O_CREAT|O_TRUNC, 0666))<0) { + perror (dst_name); + exit (1); + } + if (verbose) fprintf (stderr, "> %s\n", dst_name); + + /* No more arguments */ + if (argnosrc_size) { + fprintf (stderr, "%s: member truncated to %lu bytes\n", + src_name, (unsigned long)src_size); + } + src_offset = 0; + if (verbose) fprintf (stderr, "< %s\n", src_name); + } + + /* + * Update the destination offset, opening a new member if one will be + * needed. The first member is extended to the logical member size + * but other members might be smaller if they end with a hole. + */ + dst_offset += n; + if (dst_is_family && dst_offset==dst_size) { + if (0==dst_membno) { + if (lseek (dst, dst_size-1, SEEK_SET)<0) { + perror ("lseek"); + exit (1); + } + if (read (dst, buf, 1)<0) { + perror ("read"); + exit (1); + } + if (lseek (dst, dst_size-1, SEEK_SET)<0) { + perror ("lseek"); + exit (1); + } + if (write (dst, buf, 1)<0) { + perror ("write"); + exit (1); + } + } + close (dst); + sprintf (dst_name, dst_gen_name, ++dst_membno); + if ((dst=open (dst_name, O_RDWR|O_CREAT|O_TRUNC, 0666))<0) { + perror (dst_name); + exit (1); + } + dst_offset = 0; + need_seek = FALSE; + if (verbose) fprintf (stderr, "> %s\n", dst_name); + } + } + + /* + * Make sure the last family member is the right size and then close it. + * The last member can't end with a hole or hdf5 will think that the + * family has been truncated. + */ + if (need_seek) { + if (lseek (dst, dst_offset-1, SEEK_SET)<0) { + perror ("lseek"); + exit (1); + } + if (read (dst, buf, 1)<0) { + perror ("read"); + exit (1); + } + if (lseek (dst, dst_offset-1, SEEK_SET)<0) { + perror ("lseek"); + exit (1); + } + if (write (dst, buf, 1)<0) { + perror ("write"); + exit (1); + } + } + close (dst); + + /* Free resources and return */ + free (buf); + return 0; +} -- cgit v0.12