diff options
author | knarf <knarf@fb53df36-e548-4a1e-8150-ab98cbd5e786> | 2015-02-23 17:24:40 +0000 |
---|---|---|
committer | knarf <knarf@fb53df36-e548-4a1e-8150-ab98cbd5e786> | 2015-02-23 17:24:40 +0000 |
commit | 85800df1c500ca2c280f83818f042b82239b2b99 (patch) | |
tree | adb72e5597def3c950f6e47e2f6a191cea13ac3e | |
parent | bb4ffc26c1cd38c581738ad9c73eafa82dc7804d (diff) |
Don't open all files at the same time, as this might fail (too many open files)
git-svn-id: http://svn.cactuscode.org/projects/ExternalLibraries/HDF5/trunk@102 fb53df36-e548-4a1e-8150-ab98cbd5e786
-rw-r--r-- | src/util/hdf5_merge.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/util/hdf5_merge.c b/src/util/hdf5_merge.c index 2d6a0fd..0af1918 100644 --- a/src/util/hdf5_merge.c +++ b/src/util/hdf5_merge.c @@ -92,7 +92,7 @@ static herr_t CopyAttribute (hid_t src, const char *attr_name, void *arg); int main (int argc, char *argv[]) { int i; - hid_t *infiles, outfile; + hid_t infile, outfile; /* give some help if called with incorrect number of parameters */ @@ -106,17 +106,18 @@ int main (int argc, char *argv[]) H5E_BEGIN_TRY { - /* open the input files */ - infiles = (hid_t *) malloc ((argc - 2) * sizeof (hid_t)); + /* open the input files as early test that this works */ for (i = 0; i < argc - 2; i++) { - infiles[i] = H5Fopen (argv[i + 1], H5F_ACC_RDONLY, H5P_DEFAULT); - if (infiles[i] < 0) + infile = H5Fopen (argv[i + 1], H5F_ACC_RDONLY, H5P_DEFAULT); + if (infile < 0) { fprintf (stderr, "ERROR: Cannot open HDF5 input file '%s' !\n\n", argv[i + 1]); return (-1); } + /* close them again, or we might have too many open files and fail */ + H5Fclose (infile); } /* try to open an existing outfile file in append mode, @@ -145,16 +146,21 @@ int main (int argc, char *argv[]) printf ("\n Merging objects from input file '%s' into output file '%s'\n", argv[i + 1], argv[argc-1]); pathname = ""; - CHECK_ERROR (H5Giterate (infiles[i], "/", NULL, CopyObject, &outfile)); + H5E_BEGIN_TRY + { + infile = H5Fopen (argv[i + 1], H5F_ACC_RDONLY, H5P_DEFAULT); + if (infile < 0) + { + fprintf (stderr, "ERROR: Cannot open HDF5 input file '%s' !\n\n", + argv[i + 1]); + return (-1); + } + } H5E_END_TRY + CHECK_ERROR (H5Giterate (infile, "/", NULL, CopyObject, &outfile)); + CHECK_ERROR (H5Fclose (infile)); } - /* finally, close all open files */ - for (i = 0; i < argc - 2; i++) - { - CHECK_ERROR (H5Fclose (infiles[i])); - } CHECK_ERROR (H5Fclose (outfile)); - free (infiles); /* report status */ if (nerrors == 0) |