summaryrefslogtreecommitdiffstats
path: root/tools/h5copy
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2007-02-14 16:31:11 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2007-02-14 16:31:11 (GMT)
commitf6a22fb0de3b415d3c7fe9ad2e3c1a72bd0334ab (patch)
tree23a2cf7c8b2af26745b0613b112e1e2ae401a2f9 /tools/h5copy
parent8891e2433a9849571373a9512b6e292ba4cde54e (diff)
downloadhdf5-f6a22fb0de3b415d3c7fe9ad2e3c1a72bd0334ab.zip
hdf5-f6a22fb0de3b415d3c7fe9ad2e3c1a72bd0334ab.tar.gz
hdf5-f6a22fb0de3b415d3c7fe9ad2e3c1a72bd0334ab.tar.bz2
[svn-r13301] Description:
Add '-p' flag to h5copy tool, to create intermediate "parent" groups that don't exist in destination file yet. Add more tests to h5copy script. Tested on: Linux/32 2.6 (chicago) Linux/64 2.6 (chicago2)
Diffstat (limited to 'tools/h5copy')
-rw-r--r--tools/h5copy/h5copy.c164
-rw-r--r--tools/h5copy/h5copygentest.c24
-rw-r--r--tools/h5copy/testh5copy.sh61
3 files changed, 154 insertions, 95 deletions
diff --git a/tools/h5copy/h5copy.c b/tools/h5copy/h5copy.c
index cbbb738..cadb0d0 100644
--- a/tools/h5copy/h5copy.c
+++ b/tools/h5copy/h5copy.c
@@ -14,7 +14,6 @@
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-#include "hdf5.h"
#include "h5tools.h"
#include "h5tools_utils.h"
#include <string.h>
@@ -23,23 +22,45 @@
const char *progname="h5copy";
int d_status;
-static void leave(int ret);
-
/* command-line options: short and long-named parameters */
-static const char *s_opts = "hvf:Vi:o:s:d:";
+static const char *s_opts = "d:f:hi:o:ps:vV";
static struct long_options l_opts[] = {
- { "help", no_arg, 'h' },
- { "verbose", no_arg, 'v' },
+ { "destination", require_arg, 'd' },
{ "flag", require_arg, 'f' },
- { "version", no_arg, 'V' },
+ { "help", no_arg, 'h' },
{ "input", require_arg, 'i' },
{ "output", require_arg, 'o' },
+ { "parents", no_arg, 'p' },
{ "source", require_arg, 's' },
- { "destination", require_arg, 'd' },
+ { "verbose", no_arg, 'v' },
+ { "version", no_arg, 'V' },
{ NULL, 0, '\0' }
};
/*-------------------------------------------------------------------------
+ * Function: leave
+ *
+ * Purpose: Shutdown MPI & HDF5 and call exit()
+ *
+ * Return: Does not return
+ *
+ * Programmer: Quincey Koziol
+ * Saturday, 31. January 2004
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static void
+leave(int ret)
+{
+ h5tools_close();
+
+ exit(ret);
+}
+
+
+/*-------------------------------------------------------------------------
* Function: usage
*
* Purpose: Prints a usage message on stderr and then returns.
@@ -64,6 +85,7 @@ usage: h5copy [OPTIONS] [OBJECTS...]\n\
-d, --destination destination object name\n\
OPTIONS\n\
-h, --help Print a usage message and exit\n\
+ -p, --parents No error if existing, make parent groups as needed\n\
-v, --verbose Print information about OBJECTS and OPTIONS\n\
-V, --version Print version number and exit\n\
-f, --flag Flag type\n\n\
@@ -144,7 +166,7 @@ static int parse_flag(const char* str_flag, unsigned *flag)
}
else
{
- printf("Error in input flag\n");
+ error_msg(progname, "Error in input flag\n");
return -1;
}
@@ -175,8 +197,10 @@ main (int argc, const char *argv[])
char *oname_src=NULL;
char *oname_dst=NULL;
unsigned flag=0;
- int verbose=0;
- hid_t pid;
+ unsigned verbose=0;
+ unsigned parents=0;
+ hid_t ocpl_id; /* Object copy property list */
+ hid_t lcpl_id; /* Link creation property list */
char str_flag[20];
int opt;
@@ -194,20 +218,10 @@ main (int argc, const char *argv[])
{
switch ((char)opt)
{
- case 'h':
- usage();
- leave(EXIT_SUCCESS);
- break;
-
- case 'V':
- print_version(progname);
- leave(EXIT_SUCCESS);
- break;
-
- case 'v':
- verbose = 1;
+ case 'd':
+ oname_dst = strdup(opt_arg);
break;
-
+
case 'f':
/* validate flag */
if (parse_flag(opt_arg,&flag)<0)
@@ -218,6 +232,11 @@ main (int argc, const char *argv[])
strcpy(str_flag,opt_arg);
break;
+ case 'h':
+ usage();
+ leave(EXIT_SUCCESS);
+ break;
+
case 'i':
fname_src = strdup(opt_arg);
break;
@@ -226,15 +245,23 @@ main (int argc, const char *argv[])
fname_dst = strdup(opt_arg);
break;
+ case 'p':
+ parents = 1;
+ break;
+
case 's':
oname_src = strdup(opt_arg);
break;
- case 'd':
- oname_dst = strdup(opt_arg);
+ case 'V':
+ print_version(progname);
+ leave(EXIT_SUCCESS);
break;
-
- case '?':
+
+ case 'v':
+ verbose = 1;
+ break;
+
default:
usage();
leave(EXIT_FAILURE);
@@ -247,28 +274,28 @@ main (int argc, const char *argv[])
if (fname_src==NULL)
{
- printf("Input file name missing\n");
+ error_msg(progname, "Input file name missing\n");
usage();
leave(EXIT_FAILURE);
}
if (fname_dst==NULL)
{
- printf("Output file name missing\n");
+ error_msg(progname, "Output file name missing\n");
usage();
leave(EXIT_FAILURE);
}
if (oname_src==NULL)
{
- printf("Input object name missing\n");
+ error_msg(progname, "Source object name missing\n");
usage();
leave(EXIT_FAILURE);
}
if (oname_dst==NULL)
{
- printf("Destination object name missing\n");
+ error_msg(progname, "Destination object name missing\n");
usage();
leave(EXIT_FAILURE);
}
@@ -285,7 +312,7 @@ main (int argc, const char *argv[])
*-------------------------------------------------------------------------*/
if (fid_src==-1)
{
- printf("Could not open input file <%s>...Exiting\n",fname_src);
+ error_msg(progname, "Could not open input file <%s>...Exiting\n", fname_src);
if (fname_src)
free(fname_src);
leave(EXIT_FAILURE);
@@ -308,7 +335,7 @@ main (int argc, const char *argv[])
*-------------------------------------------------------------------------*/
if (fid_dst==-1)
{
- printf("Could not open output file <%s>...Exiting\n",fname_dst);
+ error_msg(progname, "Could not open output file <%s>...Exiting\n", fname_dst);
if (fname_src)
free(fname_src);
if (fname_dst)
@@ -333,34 +360,55 @@ main (int argc, const char *argv[])
/*-------------------------------------------------------------------------
- * create a property list for copy
+ * create property lists for copy
*-------------------------------------------------------------------------*/
/* create property to pass copy options */
- if ( (pid = H5Pcreate(H5P_OBJECT_COPY)) < 0)
+ if ( (ocpl_id = H5Pcreate(H5P_OBJECT_COPY)) < 0)
goto error;
/* set options for object copy */
if (flag)
{
- if ( H5Pset_copy_object(pid, flag) < 0)
+ if ( H5Pset_copy_object(ocpl_id, flag) < 0)
goto error;
}
+ /* Create link creation property list */
+ if((lcpl_id = H5Pcreate(H5P_LINK_CREATE)) < 0) {
+ error_msg(progname, "Could not create link creation property list\n");
+ goto error;
+ } /* end if */
+
+ /* Check for creating intermediate groups */
+ if(parents) {
+ /* Set the intermediate group creation property */
+ if(H5Pset_create_intermediate_group(lcpl_id, 1) < 0) {
+ error_msg(progname, "Could not set property for creating parent groups\n");
+ goto error;
+ } /* end if */
+
+ /* Display some output if requested */
+ if(verbose)
+ printf("%s: Creating parent groups\n", progname);
+ } /* end if */
+
/*-------------------------------------------------------------------------
* do the copy
*-------------------------------------------------------------------------*/
- if (H5Ocopy(fid_src, /* Source file or group identifier */
- oname_src, /* Name of the source object to be copied */
- fid_dst, /* Destination file or group identifier */
- oname_dst, /* Name of the destination object */
- pid, /* Properties which apply to the copy */
- H5P_DEFAULT)<0) /* Properties which apply to the new hard link */
+ if (H5Ocopy(fid_src, /* Source file or group identifier */
+ oname_src, /* Name of the source object to be copied */
+ fid_dst, /* Destination file or group identifier */
+ oname_dst, /* Name of the destination object */
+ ocpl_id, /* Object copy property list */
+ lcpl_id)<0) /* Link creation property list */
goto error;
- /* close property */
- if (H5Pclose(pid)<0)
+ /* close propertis */
+ if(H5Pclose(ocpl_id)<0)
+ goto error;
+ if(H5Pclose(lcpl_id)<0)
goto error;
/* close files */
@@ -385,7 +433,8 @@ main (int argc, const char *argv[])
error:
printf("Error in copy...Exiting\n");
H5E_BEGIN_TRY {
- H5Pclose(pid);
+ H5Pclose(ocpl_id);
+ H5Pclose(lcpl_id);
H5Fclose(fid_src);
H5Fclose(fid_dst);
} H5E_END_TRY;
@@ -403,26 +452,3 @@ error:
return 1;
}
-
-/*-------------------------------------------------------------------------
- * Function: leave
- *
- * Purpose: Shutdown MPI & HDF5 and call exit()
- *
- * Return: Does not return
- *
- * Programmer: Quincey Koziol
- * Saturday, 31. January 2004
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static void
-leave(int ret)
-{
- h5tools_close();
-
- exit(ret);
-}
-
diff --git a/tools/h5copy/h5copygentest.c b/tools/h5copy/h5copygentest.c
index c9dc01f..ee6862a 100644
--- a/tools/h5copy/h5copygentest.c
+++ b/tools/h5copy/h5copygentest.c
@@ -29,6 +29,7 @@
#define DATASET_NESTED_VL "nested_vl"
#define GROUP_EMPTY "grp_empty"
#define GROUP_DATASETS "grp_dsets"
+#define GROUP_NESTED "grp_nested"
/*-------------------------------------------------------------------------
@@ -364,6 +365,28 @@ static void gent_nested_datasets(hid_t loc_id)
}
/*-------------------------------------------------------------------------
+ * Function: gent_nested_group
+ *
+ * Purpose: Generate a group in a location and populate it with another group
+ * containing the "standard" datasets
+ *
+ *-------------------------------------------------------------------------
+ */
+static void gent_nested_group(hid_t loc_id)
+{
+ hid_t gid;
+
+ /* Create group in location */
+ gid = H5Gcreate(loc_id, GROUP_NESTED, (size_t)0);
+
+ /* Add datasets to group created */
+ gent_nested_datasets(gid);
+
+ /* Release resources */
+ H5Gclose(gid);
+}
+
+/*-------------------------------------------------------------------------
* Function: main
*
*-------------------------------------------------------------------------
@@ -378,6 +401,7 @@ int main(void)
gent_datasets(fid);
gent_empty_group(fid);
gent_nested_datasets(fid);
+ gent_nested_group(fid);
H5Fclose(fid);
return 0;
diff --git a/tools/h5copy/testh5copy.sh b/tools/h5copy/testh5copy.sh
index b8fbb79..61839bb 100644
--- a/tools/h5copy/testh5copy.sh
+++ b/tools/h5copy/testh5copy.sh
@@ -169,35 +169,50 @@ H5LSTEST()
# adding object copied to the destination file each time
#
# Assumed arguments:
-# $1 is test "variation" (a single letter, normally)
-# $2 is group within source file
-# $3 is group within destination file
+# <none>
COPYOBJECTS()
{
TESTFILE="$INDIR/$SRCFILE"
- FILEOUT="$OUTDIR/`basename $SRCFILE .h5`.$1.out.h5"
+ FILEOUT="$OUTDIR/`basename $SRCFILE .h5`.out.h5"
# Remove any output file left over from previous test run
rm -f $FILEOUT
- # Test copying various forms of datasets
- TOOLTEST -i $TESTFILE -o $FILEOUT -v -s "$2"simple -d "$3"simple
- TOOLTEST -i $TESTFILE -o $FILEOUT -v -s "$2"chunk -d "$3"chunk
- TOOLTEST -i $TESTFILE -o $FILEOUT -v -s "$2"compact -d "$3"compact
- TOOLTEST -i $TESTFILE -o $FILEOUT -v -s "$2"compound -d "$3"compound
- TOOLTEST -i $TESTFILE -o $FILEOUT -v -s "$2"compressed -d "$3"compressed
- TOOLTEST -i $TESTFILE -o $FILEOUT -v -s "$2"named_vl -d "$3"named_vl
- TOOLTEST -i $TESTFILE -o $FILEOUT -v -s "$2"nested_vl -d "$3"nested_vl
+ echo "Test copying various forms of datasets"
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s simple -d simple
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s chunk -d chunk
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s compact -d compact
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s compound -d compound
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s compressed -d compressed
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s named_vl -d named_vl
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s nested_vl -d nested_vl
- # Test copying & renaming dataset
- TOOLTEST -i $TESTFILE -o $FILEOUT -v -s "$2"compound -d "$3"rename
+ echo "Test copying dataset within group in source file to root of destination"
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s grp_dsets/simple -d simple_top
- # Test copying empty & "full" groups
- TOOLTEST -i $TESTFILE -o $FILEOUT -v -s "$2"grp_empty -d "$3"grp_empty
- TOOLTEST -i $TESTFILE -o $FILEOUT -v -s "$2"grp_dsets -d "$3"grp_dsets
+ echo "Test copying & renaming dataset"
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s compound -d rename
- # Test copying & renaming group
- TOOLTEST -i $TESTFILE -o $FILEOUT -v -s "$2"grp_dsets -d "$3"grp_rename
+ echo "Test copying empty, 'full' & 'nested' groups"
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s grp_empty -d grp_empty
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s grp_dsets -d grp_dsets
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s grp_nested -d grp_nested
+
+ echo "Test copying dataset within group in source file to group in destination"
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s /grp_dsets/simple -d /grp_dsets/simple_group
+
+ echo "Test copying & renaming group"
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s grp_dsets -d grp_rename
+
+ echo "Test copying 'full' group hierarchy into group in destination file"
+ TOOLTEST -i $TESTFILE -o $FILEOUT -v -s grp_dsets -d /grp_rename/grp_dsets
+
+ echo "Test copying objects into group hier. that doesn't exist yet in destination file"
+ TOOLTEST -i $TESTFILE -o $FILEOUT -vp -s simple -d /A/B1/simple
+ TOOLTEST -i $TESTFILE -o $FILEOUT -vp -s simple -d /A/B2/simple2
+ TOOLTEST -i $TESTFILE -o $FILEOUT -vp -s /grp_dsets/simple -d /C/D/simple
+ TOOLTEST -i $TESTFILE -o $FILEOUT -vp -s /grp_dsets -d /E/F/grp_dsets
+ TOOLTEST -i $TESTFILE -o $FILEOUT -vp -s /grp_nested -d /G/H/grp_nested
# Verify that the file created above is correct
H5LSTEST $FILEOUT
@@ -213,13 +228,7 @@ COPYOBJECTS()
### T H E T E S T S ###
##############################################################################
-echo "Copy objects from root group of source file to root of destination file"
-echo "(with implicit root group paths)"
-COPYOBJECTS a "" ""
-
-echo "Copy objects from root group of source file to root of destination file"
-echo "(with explicit root group paths)"
-COPYOBJECTS b "/" "/"
+COPYOBJECTS
if test $nerrors -eq 0 ; then