From d3c5ab50fc8fba8ff72417b125feaac8a3faed68 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Tue, 13 Feb 2007 17:42:43 -0500 Subject: [svn-r13292] Description: Add feature to h5copy to allow it to add an object to an existing file, instead of blowing away existing file. Modify h5tools_fopen() routine to take access flags, so it can be used to open an existing file for writing. Added check to h5copy test script that verifies it has produced a file with the correct structure. Tested on: Linux/32 2.6 (chicago) Linux/64 2.6 (chicago2) --- tools/h5copy/h5copy.c | 10 +- tools/h5copy/h5copygentest.c | 435 +++++++++++++++++++-------------------- tools/h5copy/testh5copy.sh | 76 +++++-- tools/h5dump/h5dump.c | 2 +- tools/h5ls/h5ls.c | 2 +- tools/h5repack/h5repack_copy.c | 2 +- tools/h5repack/h5repack_list.c | 2 +- tools/lib/h5tools.c | 8 +- tools/lib/h5tools.h | 4 +- tools/testfiles/h5copytst.out.ls | 55 +++++ 10 files changed, 354 insertions(+), 242 deletions(-) create mode 100644 tools/testfiles/h5copytst.out.ls diff --git a/tools/h5copy/h5copy.c b/tools/h5copy/h5copy.c index 5ca21e5..9b4f629 100644 --- a/tools/h5copy/h5copy.c +++ b/tools/h5copy/h5copy.c @@ -272,7 +272,7 @@ main (int argc, const char *argv[]) * open input file *-------------------------------------------------------------------------*/ - fid_src = h5tools_fopen(fname_src, NULL, NULL, 0); + fid_src = h5tools_fopen(fname_src, H5F_ACC_RDONLY, NULL, NULL, 0); /*------------------------------------------------------------------------- * test for error in opening input file @@ -289,7 +289,13 @@ main (int argc, const char *argv[]) * open output file *-------------------------------------------------------------------------*/ - fid_dst = H5Fcreate(fname_dst, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + /* Attempt to open an existing HDF5 file first */ + fid_dst = h5tools_fopen(fname_dst, H5F_ACC_RDWR, 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) + fid_dst = H5Fcreate(fname_dst, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT); /*------------------------------------------------------------------------- * test for error in opening output file diff --git a/tools/h5copy/h5copygentest.c b/tools/h5copy/h5copygentest.c index 84ce931..79f43ef 100644 --- a/tools/h5copy/h5copygentest.c +++ b/tools/h5copy/h5copygentest.c @@ -34,276 +34,274 @@ /*------------------------------------------------------------------------- * Function: gent_simple * - * Purpose: Generate a simple dataset in FID + * Purpose: Generate a simple dataset in LOC_ID * *------------------------------------------------------------------------- */ -static void gent_simple(hid_t fid) +static void gent_simple(hid_t loc_id) { - hid_t sid, did; - hsize_t dims[1] = {6}; - int buf[6] = {1,2,3,4,5,6}; - - /* create dataspace */ - sid = H5Screate_simple(1, dims, NULL); - - /* create dataset */ - did = H5Dcreate(fid, DATASET_SIMPLE, H5T_NATIVE_INT, sid, H5P_DEFAULT); - - /* write */ - H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); - - /* close */ - H5Sclose(sid); - H5Dclose(did); + hid_t sid, did; + hsize_t dims[1] = {6}; + int buf[6] = {1,2,3,4,5,6}; + + /* create dataspace */ + sid = H5Screate_simple(1, dims, NULL); + + /* create dataset */ + did = H5Dcreate(loc_id, DATASET_SIMPLE, H5T_NATIVE_INT, sid, H5P_DEFAULT); + + /* write */ + H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); + + /* close */ + H5Sclose(sid); + H5Dclose(did); } /*------------------------------------------------------------------------- * Function: gent_chunked * - * Purpose: Generate a chunked dataset in FID + * Purpose: Generate a chunked dataset in LOC_ID * *------------------------------------------------------------------------- */ -static void gent_chunked(hid_t fid) +static void gent_chunked(hid_t loc_id) { - hid_t sid, did, pid; - hsize_t dims[1] = {6}; - hsize_t chunk_dims[1] = {2}; - int buf[6] = {1,2,3,4,5,6}; - - /* create dataspace */ - sid = H5Screate_simple(1, dims, NULL); - - /* create property plist */ - pid = H5Pcreate(H5P_DATASET_CREATE); - H5Pset_chunk(pid, 1, chunk_dims); - - /* create dataset */ - did = H5Dcreate(fid, DATASET_CHUNK, H5T_NATIVE_INT, sid, pid); - - /* write */ - H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); - - /* close */ - H5Sclose(sid); - H5Dclose(did); - H5Pclose(pid); + hid_t sid, did, pid; + hsize_t dims[1] = {6}; + hsize_t chunk_dims[1] = {2}; + int buf[6] = {1,2,3,4,5,6}; + + /* create dataspace */ + sid = H5Screate_simple(1, dims, NULL); + + /* create property plist */ + pid = H5Pcreate(H5P_DATASET_CREATE); + H5Pset_chunk(pid, 1, chunk_dims); + + /* create dataset */ + did = H5Dcreate(loc_id, DATASET_CHUNK, H5T_NATIVE_INT, sid, pid); + + /* write */ + H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); + + /* close */ + H5Sclose(sid); + H5Dclose(did); + H5Pclose(pid); } /*------------------------------------------------------------------------- * Function: gent_compact * - * Purpose: Generate a compact dataset in FID + * Purpose: Generate a compact dataset in LOC_ID * *------------------------------------------------------------------------- */ -static void gent_compact(hid_t fid) +static void gent_compact(hid_t loc_id) { - hid_t sid, did, pid; - hsize_t dims[1] = {6}; - int buf[6] = {1,2,3,4,5,6}; - - /* create dataspace */ - sid = H5Screate_simple(1, dims, NULL); - - /* create property plist */ - pid = H5Pcreate(H5P_DATASET_CREATE); - H5Pset_layout (pid,H5D_COMPACT); - - /* create dataset */ - did = H5Dcreate(fid, DATASET_COMPACT, H5T_NATIVE_INT, sid, pid); - - /* write */ - H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); - - /* close */ - H5Sclose(sid); - H5Dclose(did); - H5Pclose(pid); + hid_t sid, did, pid; + hsize_t dims[1] = {6}; + int buf[6] = {1,2,3,4,5,6}; + + /* create dataspace */ + sid = H5Screate_simple(1, dims, NULL); + + /* create property plist */ + pid = H5Pcreate(H5P_DATASET_CREATE); + H5Pset_layout (pid,H5D_COMPACT); + + /* create dataset */ + did = H5Dcreate(loc_id, DATASET_COMPACT, H5T_NATIVE_INT, sid, pid); + + /* write */ + H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); + + /* close */ + H5Sclose(sid); + H5Dclose(did); + H5Pclose(pid); } /*------------------------------------------------------------------------- * Function: gent_compound * - * Purpose: Generate a compound dataset in FID + * Purpose: Generate a compound dataset in LOC_ID * *------------------------------------------------------------------------- */ -static void gent_compound(hid_t fid) +static void gent_compound(hid_t loc_id) { - typedef struct s_t - { - char str1[20]; - char str2[20]; - } s_t; - hid_t sid, did, tid_c, tid_s; - hsize_t dims[1] = {2}; - s_t buf[2] = {{"str1","str2"},{"str3","str4"}}; - - /* create dataspace */ - sid = H5Screate_simple(1, dims, NULL); - - /* create a compound type */ - tid_c = H5Tcreate (H5T_COMPOUND, sizeof(s_t)); - tid_s = H5Tcopy (H5T_C_S1); - H5Tset_size (tid_s, 20); - - H5Tinsert (tid_c, "str1", HOFFSET(s_t,str1), tid_s); - H5Tinsert (tid_c, "str2", HOFFSET(s_t,str2), tid_s); - - /* create dataset */ - did = H5Dcreate(fid, DATASET_COMPOUND, tid_c, sid, H5P_DEFAULT); - - /* write */ - H5Dwrite(did, tid_c, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); - - /* close */ - H5Sclose(sid); - H5Dclose(did); - H5Tclose(tid_c); - H5Tclose(tid_s); + typedef struct s_t + { + char str1[20]; + char str2[20]; + } s_t; + hid_t sid, did, tid_c, tid_s; + hsize_t dims[1] = {2}; + s_t buf[2] = {{"str1", "str2"}, {"str3", "str4"}}; + + /* create dataspace */ + sid = H5Screate_simple(1, dims, NULL); + + /* create a compound type */ + tid_c = H5Tcreate(H5T_COMPOUND, sizeof(s_t)); + tid_s = H5Tcopy(H5T_C_S1); + H5Tset_size(tid_s, 20); + + H5Tinsert(tid_c, "str1", HOFFSET(s_t,str1), tid_s); + H5Tinsert(tid_c, "str2", HOFFSET(s_t,str2), tid_s); + + /* create dataset */ + did = H5Dcreate(loc_id, DATASET_COMPOUND, tid_c, sid, H5P_DEFAULT); + + /* write */ + H5Dwrite(did, tid_c, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); + + /* close */ + H5Sclose(sid); + H5Dclose(did); + H5Tclose(tid_c); + H5Tclose(tid_s); } /*------------------------------------------------------------------------- * Function: gent_compressed * - * Purpose: Generate a compressed dataset in FID + * Purpose: Generate a compressed dataset in LOC_ID * *------------------------------------------------------------------------- */ -static void gent_compressed(hid_t fid) +static void gent_compressed(hid_t loc_id) { - hid_t sid, did, pid; - hsize_t dims[1] = {6}; - hsize_t chunk_dims[1] = {2}; - int buf[6] = {1,2,3,4,5,6}; + hid_t sid, did, pid; + hsize_t dims[1] = {6}; + hsize_t chunk_dims[1] = {2}; + int buf[6] = {1,2,3,4,5,6}; - /* create dataspace */ - sid = H5Screate_simple(1, dims, NULL); + /* create dataspace */ + sid = H5Screate_simple(1, dims, NULL); - /* create property plist for chunk*/ - pid = H5Pcreate(H5P_DATASET_CREATE); - H5Pset_chunk(pid, 1, chunk_dims); + /* create property plist for chunk*/ + pid = H5Pcreate(H5P_DATASET_CREATE); + H5Pset_chunk(pid, 1, chunk_dims); - /* set the deflate filter */ + /* set the deflate filter */ #if defined (H5_HAVE_FILTER_DEFLATE) - H5Pset_deflate(pid, 1); + H5Pset_deflate(pid, 1); #endif - - /* create dataset */ - did = H5Dcreate(fid, DATASET_COMPRESSED, H5T_NATIVE_INT, sid, pid); - - /* write */ - H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); - - /* close */ - H5Sclose(sid); - H5Dclose(did); - H5Pclose(pid); + + /* create dataset */ + did = H5Dcreate(loc_id, DATASET_COMPRESSED, H5T_NATIVE_INT, sid, pid); + + /* write */ + H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); + + /* close */ + H5Sclose(sid); + H5Dclose(did); + H5Pclose(pid); } /*------------------------------------------------------------------------- * Function: gent_named_vl * - * Purpose: Generate a variable lenght named datatype for a dataset in FID + * Purpose: Generate a variable lenght named datatype for a dataset in LOC_ID * *------------------------------------------------------------------------- */ -static void gent_named_vl(hid_t fid) +static void gent_named_vl(hid_t loc_id) { - hid_t sid, did, tid; - hsize_t dims[1] = {2}; - hvl_t buf[2]; - - /* allocate and initialize VL dataset to write */ - buf[0].len = 1; - buf[0].p = malloc( 1 * sizeof(int)); - ((int *)buf[0].p)[0]=1; - buf[1].len = 2; - buf[1].p = malloc( 2 * sizeof(int)); - ((int *)buf[1].p)[0]=2; - ((int *)buf[1].p)[1]=3; - - /* create dataspace */ - sid = H5Screate_simple(1, dims, NULL); - - /* create datatype */ - tid = H5Tvlen_create(H5T_NATIVE_INT); - - /* create named datatype */ - H5Tcommit(fid, "vl", tid); - - /* create dataset */ - did = H5Dcreate(fid, DATASET_NAMED_VL, tid, sid, H5P_DEFAULT); - - /* write */ - H5Dwrite(did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); - - /* close */ - H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf); - H5Sclose(sid); - H5Dclose(did); - H5Tclose(tid); - + hid_t sid, did, tid; + hsize_t dims[1] = {2}; + hvl_t buf[2]; + + /* allocate and initialize VL dataset to write */ + buf[0].len = 1; + buf[0].p = malloc( 1 * sizeof(int)); + ((int *)buf[0].p)[0]=1; + buf[1].len = 2; + buf[1].p = malloc( 2 * sizeof(int)); + ((int *)buf[1].p)[0]=2; + ((int *)buf[1].p)[1]=3; + + /* create dataspace */ + sid = H5Screate_simple(1, dims, NULL); + + /* create datatype */ + tid = H5Tvlen_create(H5T_NATIVE_INT); + + /* create named datatype */ + H5Tcommit(loc_id, "vl", tid); + + /* create dataset */ + did = H5Dcreate(loc_id, DATASET_NAMED_VL, tid, sid, H5P_DEFAULT); + + /* write */ + H5Dwrite(did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); + + /* close */ + H5Dvlen_reclaim(tid,sid,H5P_DEFAULT,buf); + H5Sclose(sid); + H5Dclose(did); + H5Tclose(tid); } /*------------------------------------------------------------------------- * Function: gent_nested_vl * - * Purpose: Generate a nested variable lenght dataset in FID + * Purpose: Generate a nested variable length dataset in LOC_ID * *------------------------------------------------------------------------- */ -static void gent_nested_vl(hid_t fid) +static void gent_nested_vl(hid_t loc_id) { - hid_t sid, did, tid1, tid2; - hsize_t dims[1] = {2}; - hvl_t buf[2]; - hvl_t *tvl; - - /* allocate and initialize VL dataset to write */ - buf[0].len = 1; - buf[0].p = malloc( 1 * sizeof(hvl_t)); - tvl = buf[0].p; - tvl->p = malloc( 1 * sizeof(int) ); - tvl->len = 1; - ((int *)tvl->p)[0]=1; - - buf[1].len = 1; - buf[1].p = malloc( 1 * sizeof(hvl_t)); - tvl = buf[1].p; - tvl->p = malloc( 2 * sizeof(int) ); - tvl->len = 2; - ((int *)tvl->p)[0]=2; - ((int *)tvl->p)[1]=3; - - /* create dataspace */ - sid = H5Screate_simple(1, dims, NULL); - - /* create datatype */ - tid1 = H5Tvlen_create(H5T_NATIVE_INT); - - /* create nested VL datatype */ - tid2 = H5Tvlen_create(tid1); - - /* create dataset */ - did = H5Dcreate(fid, DATASET_NESTED_VL, tid2, sid, H5P_DEFAULT); - - /* write */ - H5Dwrite(did, tid2, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); - - /* close */ - H5Dvlen_reclaim(tid2,sid,H5P_DEFAULT,buf); - H5Sclose(sid); - H5Dclose(did); - H5Tclose(tid1); - H5Tclose(tid2); - + hid_t sid, did, tid1, tid2; + hsize_t dims[1] = {2}; + hvl_t buf[2]; + hvl_t *tvl; + + /* allocate and initialize VL dataset to write */ + buf[0].len = 1; + buf[0].p = malloc( 1 * sizeof(hvl_t)); + tvl = buf[0].p; + tvl->p = malloc( 1 * sizeof(int) ); + tvl->len = 1; + ((int *)tvl->p)[0]=1; + + buf[1].len = 1; + buf[1].p = malloc( 1 * sizeof(hvl_t)); + tvl = buf[1].p; + tvl->p = malloc( 2 * sizeof(int) ); + tvl->len = 2; + ((int *)tvl->p)[0]=2; + ((int *)tvl->p)[1]=3; + + /* create dataspace */ + sid = H5Screate_simple(1, dims, NULL); + + /* create datatype */ + tid1 = H5Tvlen_create(H5T_NATIVE_INT); + + /* create nested VL datatype */ + tid2 = H5Tvlen_create(tid1); + + /* create dataset */ + did = H5Dcreate(loc_id, DATASET_NESTED_VL, tid2, sid, H5P_DEFAULT); + + /* write */ + H5Dwrite(did, tid2, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); + + /* close */ + H5Dvlen_reclaim(tid2,sid,H5P_DEFAULT,buf); + H5Sclose(sid); + H5Dclose(did); + H5Tclose(tid1); + H5Tclose(tid2); } @@ -315,20 +313,21 @@ static void gent_nested_vl(hid_t fid) int main(void) { - hid_t fid; - - - fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); - - gent_simple(fid); - gent_chunked(fid); - gent_compact(fid); - gent_compound(fid); - gent_compressed(fid); - gent_named_vl(fid); - gent_nested_vl(fid); - - H5Fclose(fid); - return 0; + hid_t fid; + + /* Create source file */ + fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + gent_simple(fid); + gent_chunked(fid); + gent_compact(fid); + gent_compound(fid); + gent_compressed(fid); + gent_named_vl(fid); + gent_nested_vl(fid); + H5Fclose(fid); + + /* Create destination file with all datasets in root group */ + + return 0; } diff --git a/tools/h5copy/testh5copy.sh b/tools/h5copy/testh5copy.sh index d363906..af8fb4b 100644 --- a/tools/h5copy/testh5copy.sh +++ b/tools/h5copy/testh5copy.sh @@ -21,13 +21,20 @@ H5COPY=h5copy # The tool name H5COPY_BIN=`pwd`/$H5COPY # The path of the tool binary -H5DIFF=../h5diff/h5diff # The h5diff tool name -H5DIFF_BIN=`pwd`/$H5DIFF # The path of the h5diff tool binary +H5DIFF=h5diff # The h5diff tool name +H5DIFF_BIN=`pwd`/../h5diff/$H5DIFF # The path of the h5diff tool binary +H5LS=h5ls # The h5ls tool name +H5LS_ARGS=-vr # Arguments to the h5ls tool +H5LS_BIN=`pwd`/../h5ls/$H5LS # The path of the h5ls tool binary TESTFILE=$srcdir/../testfiles/h5copytst.h5 FILEOUT=h5copytst.out.h5 nerrors=0 +verbose=yes + +CMP='cmp -s' +DIFF='diff -c' # The build (current) directory might be different than the source directory. if test -z "$srcdir"; then @@ -52,6 +59,15 @@ VERIFY() echo "Verifying h5diff output $* $SPACES" | cut -c1-70 | tr -d '\012' } +# Print a line-line message left justified in a field of 70 characters +# beginning with the word "Verifying". +# +VERIFY_H5LS() +{ + SPACES=" " + echo "Verifying h5diff file structure $* $SPACES" | cut -c1-70 | tr -d '\012' +} + # Run a test and print PASS or *FAIL*. If h5copy can complete # with exit status 0, consider it pass. If a test fails then increment # the `nerrors' global variable. @@ -84,13 +100,13 @@ TOOLTEST() $RUNSERIAL $H5COPY_BIN $@ ) > output.out RET=$? - if [ $RET != 0 ] ; then - echo "*FAILED*" - echo "failed result is:" - cat output.out - nerrors="`expr $nerrors + 1`" + if [ $RET != 0 ]; then + echo "*FAILED*" + echo "failed result is:" + cat output.out + nerrors="`expr $nerrors + 1`" else - echo " PASSED" + echo " PASSED" fi if [ $runh5diff != no ]; then @@ -104,9 +120,9 @@ H5DIFFTEST() { VERIFY $@ if [ "`uname -s`" = "TFLOPS O/S" ]; then - $RUNSERIAL $H5DIFF_BIN $@ -q + $RUNSERIAL $H5DIFF_BIN $@ -q else - $RUNSERIAL $H5DIFF_BIN "$@" -q + $RUNSERIAL $H5DIFF_BIN "$@" -q fi RET=$? if [ $RET != 0 ] ; then @@ -117,10 +133,45 @@ H5DIFFTEST() fi } +# Call the h5ls tool to verify the correct output data in the destination file +# +H5LSTEST() +{ + expect="$srcdir/../testfiles/`basename $1 .h5`.ls" + actual="../testfiles/`basename $1 .h5`.out" + actual_err="../testfiles/`basename $1 .h5`.err" + + VERIFY_H5LS $@ + + ( + echo "#############################" + echo "Expected output for '$H5LS $@'" + echo "#############################" + $RUNSERIAL $H5LS_BIN $H5LS_ARGS $@ + ) >$actual 2>$actual_err + cat $actual_err >> $actual + + + if [ ! -f $expect ]; then + # Create the expect file if it doesn't yet exist. + echo " CREATED" + cp $actual $expect + elif $CMP $expect $actual; then + echo " PASSED" + else + echo "*FAILED*" + echo " Expected result (*.ls) differs from actual result (*.out)" + nerrors="`expr $nerrors + 1`" + test yes = "$verbose" && $DIFF $expect $actual |sed 's/^/ /' + fi +} + ############################################################################## ### T H E T E S T S ### ############################################################################## +# Copy single datasets of various forms from one root group to another, +# adding new object to the destination file each time 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 @@ -129,6 +180,9 @@ 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 +# Verify that the file created above is correct +H5LSTEST $FILEOUT +rm -f $FILEOUT @@ -139,5 +193,3 @@ fi exit $nerrors - - diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c index d19febd..1f34b65 100644 --- a/tools/h5dump/h5dump.c +++ b/tools/h5dump/h5dump.c @@ -3775,7 +3775,7 @@ main(int argc, const char *argv[]) } fname = HDstrdup(argv[opt_ind]); - fid = h5tools_fopen(fname, driver, NULL, 0); + fid = h5tools_fopen(fname, H5F_ACC_RDONLY, driver, NULL, 0); if (fid < 0) { error_msg(progname, "unable to open file \"%s\"\n", fname); diff --git a/tools/h5ls/h5ls.c b/tools/h5ls/h5ls.c index 75de816..c8ce958 100644 --- a/tools/h5ls/h5ls.c +++ b/tools/h5ls/h5ls.c @@ -2280,7 +2280,7 @@ main (int argc, const char *argv[]) file = -1; while (fname && *fname) { - file = h5tools_fopen(fname, preferred_driver, drivername, sizeof drivername); + file = h5tools_fopen(fname, H5F_ACC_RDONLY, preferred_driver, drivername, sizeof drivername); if (file>=0) { if (verbose_g) { diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c index 827c2c3..e43831e 100644 --- a/tools/h5repack/h5repack_copy.c +++ b/tools/h5repack/h5repack_copy.c @@ -181,7 +181,7 @@ int copy_objects(const char* fnamein, * open the files *------------------------------------------------------------------------- */ - if ((fidin=h5tools_fopen(fnamein, NULL, NULL, 0))<0 ){ + if ((fidin=h5tools_fopen(fnamein, H5F_ACC_RDONLY, NULL, NULL, 0))<0 ){ error_msg(progname, "<%s>: %s\n", fnamein, H5FOPENERROR ); goto out; } diff --git a/tools/h5repack/h5repack_list.c b/tools/h5repack/h5repack_list.c index 5aa127b..b1d8ee9 100644 --- a/tools/h5repack/h5repack_list.c +++ b/tools/h5repack/h5repack_list.c @@ -51,7 +51,7 @@ int check_objects(const char* fname, * open the file *------------------------------------------------------------------------- */ - if ((fid=h5tools_fopen(fname, NULL, NULL, 0))<0){ + if ((fid=h5tools_fopen(fname, H5F_ACC_RDONLY, NULL, NULL, 0))<0){ printf("<%s>: %s\n", fname, H5FOPENERROR ); return -1; } diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c index c11718e..429898a 100644 --- a/tools/lib/h5tools.c +++ b/tools/lib/h5tools.c @@ -308,8 +308,8 @@ error: *------------------------------------------------------------------------- */ hid_t -h5tools_fopen(const char *fname, const char *driver, char *drivername, - size_t drivername_size) +h5tools_fopen(const char *fname, unsigned flags, const char *driver, + char *drivername, size_t drivername_size) { unsigned drivernum; hid_t fid = FAIL; @@ -321,7 +321,7 @@ h5tools_fopen(const char *fname, const char *driver, char *drivername, goto done; H5E_BEGIN_TRY { - fid = H5Fopen(fname, H5F_ACC_RDONLY, fapl); + fid = H5Fopen(fname, flags, fapl); } H5E_END_TRY; if (fid == FAIL) @@ -335,7 +335,7 @@ h5tools_fopen(const char *fname, const char *driver, char *drivername, goto done; H5E_BEGIN_TRY { - fid = H5Fopen(fname, H5F_ACC_RDONLY, fapl); + fid = H5Fopen(fname, flags, fapl); } H5E_END_TRY; if (fid != FAIL) diff --git a/tools/lib/h5tools.h b/tools/lib/h5tools.h index 49e7090..929cdd5 100644 --- a/tools/lib/h5tools.h +++ b/tools/lib/h5tools.h @@ -387,8 +387,8 @@ extern int bin_form; /* binary form */ /* Definitions of useful routines */ extern void h5tools_init(void); extern void h5tools_close(void); -extern hid_t h5tools_fopen(const char *fname, const char *driver, - char *drivername, size_t drivername_len); +extern hid_t h5tools_fopen(const char *fname, unsigned flags, + const char *driver, char *drivername, size_t drivername_len); extern int h5tools_dump_dset(FILE *stream, const h5tool_format_t *info, hid_t dset, hid_t p_typ, struct subset_t *sset, int indentlevel); extern int h5tools_dump_mem(FILE *stream, const h5tool_format_t *info, hid_t obj_id, diff --git a/tools/testfiles/h5copytst.out.ls b/tools/testfiles/h5copytst.out.ls new file mode 100644 index 0000000..81cc181 --- /dev/null +++ b/tools/testfiles/h5copytst.out.ls @@ -0,0 +1,55 @@ +############################# +Expected output for 'h5ls h5copytst.out.h5' +############################# +Opened "h5copytst.out.h5" with sec2 driver. +/chunk Dataset {6/6} + Location: 1:6216 + Links: 1 + Modified: 2006-10-17 15:55:17 CDT + Chunks: {2} 8 bytes + Storage: 24 logical bytes, 24 allocated bytes, 100.00% utilization + Type: native int +/compact Dataset {6/6} + Location: 1:6344 + Links: 1 + Modified: 2006-10-17 15:55:17 CDT + Storage: 24 logical bytes, 24 allocated bytes, 100.00% utilization + Type: native int +/compound Dataset {2/2} + Location: 1:8528 + Links: 1 + Modified: 2006-10-17 15:55:17 CDT + Storage: 80 logical bytes, 80 allocated bytes, 100.00% utilization + Type: struct { + "str1" +0 20-byte null-terminated ASCII string + "str2" +20 20-byte null-terminated ASCII string + } 40 bytes +/compressed Dataset {6/6} + Location: 1:12888 + Links: 1 + Modified: 2006-10-17 15:55:17 CDT + Chunks: {2} 8 bytes + Storage: 24 logical bytes, 42 allocated bytes, 57.14% utilization + Filter-0: deflate-1 OPT {1} + Type: native int +/named_vl Dataset {2/2} + Location: 1:13104 + Links: 1 + Modified: 2006-10-17 15:55:17 CDT + Storage: 16 logical bytes, 32 allocated bytes, 50.00% utilization + Type: shared-1:13056 variable length of + native int +/nested_vl Dataset {2/2} + Location: 1:27392 + Links: 1 + Modified: 2006-10-17 15:55:17 CDT + Storage: 16 logical bytes, 32 allocated bytes, 50.00% utilization + Type: variable length of + variable length of + native int +/simple Dataset {6/6} + Location: 1:808 + Links: 1 + Modified: 2006-10-17 15:55:17 CDT + Storage: 24 logical bytes, 24 allocated bytes, 100.00% utilization + Type: native int -- cgit v0.12