diff options
author | Jonathan Kim <jkm@hdfgroup.org> | 2011-03-09 15:26:20 (GMT) |
---|---|---|
committer | Jonathan Kim <jkm@hdfgroup.org> | 2011-03-09 15:26:20 (GMT) |
commit | 6dd040b2717ff3afc66b9ffebb4cc679533b37b8 (patch) | |
tree | 12770a4f0f37f64d8706f196cb044b3d548445c6 /tools/h5copy | |
parent | 8b8637d014f76f33b6e1c07a3fa5200dfe4fa200 (diff) | |
download | hdf5-6dd040b2717ff3afc66b9ffebb4cc679533b37b8.zip hdf5-6dd040b2717ff3afc66b9ffebb4cc679533b37b8.tar.gz hdf5-6dd040b2717ff3afc66b9ffebb4cc679533b37b8.tar.bz2 |
[svn-r20210] Purpose:
Fix Bug 2120 - h5copy: improve to copy an object into same HDF file
Description:
Merged from HDF5 trunk r20203.
Before the fix users can't copy an object (dataset or group) with
different name if input file (-i) and output file (-o) is same.
This feature would be useful to clone any object with different name and
reuse contents.
Tested:
jam (linux32-LE), amani (linux64-LE), heiwa (linuxppc64-BE), Cmake (jam)
Diffstat (limited to 'tools/h5copy')
-rw-r--r-- | tools/h5copy/CMakeLists.txt | 41 | ||||
-rw-r--r-- | tools/h5copy/h5copy.c | 14 | ||||
-rw-r--r-- | tools/h5copy/testh5copy.sh | 9 |
3 files changed, 56 insertions, 8 deletions
diff --git a/tools/h5copy/CMakeLists.txt b/tools/h5copy/CMakeLists.txt index 0cd273c..4d279b6 100644 --- a/tools/h5copy/CMakeLists.txt +++ b/tools/h5copy/CMakeLists.txt @@ -76,23 +76,26 @@ IF (BUILD_TESTING) ############################################################################## ############################################################################## - MACRO (ADD_H5_TEST testname resultcode testfile vparam srcname dstname) + # + # Perform h5copy according to passing parmeters + # + MACRO (ADD_H5COPY_TEST testname resultcode infile outfile vparam srcname dstname) IF (NOT "${ARGN}" STREQUAL "") ADD_TEST ( NAME H5COPY-${testname} - COMMAND $<TARGET_FILE:h5copy> -f ${ARGN} -i ./testfiles/${testfile}.h5 -o ./testfiles/${testfile}.out.h5 -${vparam} -s ${srcname} -d ${dstname} + COMMAND $<TARGET_FILE:h5copy> -f ${ARGN} -i ./testfiles/${infile} -o ./testfiles/${outfile} -${vparam} -s ${srcname} -d ${dstname} ) ELSE (NOT "${ARGN}" STREQUAL "") ADD_TEST ( NAME H5COPY-${testname} - COMMAND $<TARGET_FILE:h5copy> -i ./testfiles/${testfile}.h5 -o ./testfiles/${testfile}.out.h5 -${vparam} -s ${srcname} -d ${dstname} + COMMAND $<TARGET_FILE:h5copy> -i ./testfiles/${infile} -o ./testfiles/${outfile} -${vparam} -s ${srcname} -d ${dstname} ) ENDIF (NOT "${ARGN}" STREQUAL "") IF (NOT ${resultcode} STREQUAL "2") ADD_TEST ( NAME H5COPY-DIFF_${testname} - COMMAND $<TARGET_FILE:h5diff> -q ./testfiles/${testfile}.h5 ./testfiles/${testfile}.out.h5 ${srcname} ${dstname} + COMMAND $<TARGET_FILE:h5diff> -q ./testfiles/${infile} ./testfiles/${outfile} ${srcname} ${dstname} ) SET_TESTS_PROPERTIES(H5COPY-DIFF_${testname} PROPERTIES DEPENDS H5COPY-${testname}) IF (${resultcode} STREQUAL "1") @@ -103,8 +106,19 @@ IF (BUILD_TESTING) SET_TESTS_PROPERTIES (H5COPY-${testname} PROPERTIES DEPENDS ${last_test}) ENDIF (NOT "${last_test}" STREQUAL "") SET (last_test "H5COPY-DIFF_${testname}") + ENDMACRO (ADD_H5COPY_TEST) + + # + # call ADD_H5COPY_TEST macro with assumption that source and target file + # is different + # + MACRO (ADD_H5_TEST testname resultcode testfile vparam srcname dstname) + ADD_H5COPY_TEST (${testname} ${resultcode} ${testfile}.h5 ${testfile}.out.h5 ${vparam} ${srcname} ${dstname} ${ARGN}) ENDMACRO (ADD_H5_TEST testname resultcode testfile vparam srcname dstname) + # + # Test result with h5ls + # MACRO (ADD_H5LS_TEST file filetest) # If using memchecker add tests without using scripts IF (HDF5_ENABLE_USING_MEMCHECKER) @@ -129,6 +143,10 @@ IF (BUILD_TESTING) SET (last_test "H5COPY-H5LS_${file}-${filetest}") ENDMACRO (ADD_H5LS_TEST file filetest) + # + # Similiar to ADD_H5_TEST macro. Compare to outputs from source & target + # files instead of checking with h5ls. + # MACRO (ADD_H5_CMP_TEST testname resultcode testfile vparam srcname dstname) # If using memchecker add tests without using scripts IF (HDF5_ENABLE_USING_MEMCHECKER) @@ -166,6 +184,7 @@ IF (BUILD_TESTING) SET (HDF_FILE2 h5copy_ref) SET (HDF_EXT_SRC_FILE h5copy_extlinks_src) SET (HDF_EXT_TRG_FILE h5copy_extlinks_trg) + SET (HDF_FILE1_TMP h5copytst_tmp) # Remove any output file left over from previous test run ADD_TEST ( @@ -308,15 +327,29 @@ IF (BUILD_TESTING) ./testfiles/${HDF_FILE1}.out.h5 ./testfiles/${HDF_FILE1}.out.out ./testfiles/${HDF_FILE1}.out.out.err + ./testfiles/${HDF_FILE1_TMP}.h5 ) IF (NOT "${last_test}" STREQUAL "") SET_TESTS_PROPERTIES (H5COPY-clear-misc PROPERTIES DEPENDS ${last_test}) ENDIF (NOT "${last_test}" STREQUAL "") SET (last_test "H5COPY-clear-misc") + #----------------------------------------------------------------- # "Test copying object into group which doesn't exist, without -p" + # ADD_H5_CMP_TEST (h5copy_misc1 1 ${HDF_FILE1} v /simple /g1/g2/simple) + #------------------------------------------- + # "Test copying objects to the same file " + # + # create temporary test file with some objects + ADD_H5COPY_TEST (samefile1_pre 0 ${HDF_FILE1}.h5 ${HDF_FILE1_TMP}.h5 v /simple /simple) + ADD_H5COPY_TEST (samefile2_pre 0 ${HDF_FILE1}.h5 ${HDF_FILE1_TMP}.h5 v /grp_dsets /grp_dsets) + # actual test cases + # - dataset + ADD_H5COPY_TEST (samefile1 0 ${HDF_FILE1_TMP}.h5 ${HDF_FILE1_TMP}.h5 v /simple /simple_cp) + # - group with some datasets + ADD_H5COPY_TEST (samefile2 0 ${HDF_FILE1_TMP}.h5 ${HDF_FILE1_TMP}.h5 v /grp_dsets /grp_dsets_cp) ENDIF (BUILD_TESTING) ############################################################################## diff --git a/tools/h5copy/h5copy.c b/tools/h5copy/h5copy.c index 3760d6f..fb8bb81 100644 --- a/tools/h5copy/h5copy.c +++ b/tools/h5copy/h5copy.c @@ -319,6 +319,14 @@ main (int argc, const char *argv[]) leave(EXIT_FAILURE); } + /*------------------------------------------------------------------------- + * open output file + *-------------------------------------------------------------------------*/ + + /* Attempt to open an existing HDF5 file first. Need to open the dst file + before the src file just in case that the dst and src are the same file + */ + fid_dst = h5tools_fopen(fname_dst, H5F_ACC_RDWR, H5P_DEFAULT, NULL, NULL, 0); /*------------------------------------------------------------------------- * open input file @@ -337,13 +345,11 @@ main (int argc, const char *argv[]) leave(EXIT_FAILURE); } + /*------------------------------------------------------------------------- - * open output file + * create an output file when failed to open it *-------------------------------------------------------------------------*/ - /* Attempt to open an existing HDF5 file first */ - fid_dst = h5tools_fopen(fname_dst, H5F_ACC_RDWR, H5P_DEFAULT, NULL, NULL, 0); - /* If we couldn't open an existing file, try creating file */ /* (use "EXCL" instead of "TRUNC", so we don't blow away existing non-HDF5 file) */ if(fid_dst < 0) diff --git a/tools/h5copy/testh5copy.sh b/tools/h5copy/testh5copy.sh index 7d26b3b..d8838b0 100644 --- a/tools/h5copy/testh5copy.sh +++ b/tools/h5copy/testh5copy.sh @@ -443,6 +443,15 @@ TEST_MISC() echo "Test copying object into group which doesn't exist, without -p" TOOLTEST_FAIL h5copy_misc1.out -v -i $TESTFILE -o $FILEOUT -s /simple -d /g1/g2/simple + echo "Test copying objects to the same file " + rm -f $FILEOUT + # create temporary test file ($FILEOUT) with some objects + TOOLTEST -i $TESTFILE -o $FILEOUT -v -s /simple -d /simple + TOOLTEST -i $TESTFILE -o $FILEOUT -v -s /grp_dsets -d /grp_dsets + # actual test cases + TOOLTEST -i $FILEOUT -o $FILEOUT -v -s /simple -d /simple_cp + TOOLTEST -i $FILEOUT -o $FILEOUT -v -s /grp_dsets -d /grp_dsets_cp + # Remove output file created, if the "no cleanup" environment variable is # not defined if test -z "$HDF5_NOCLEANUP"; then |