Commit d02ff6a9 authored by Hendryk Bockelmann's avatar Hendryk Bockelmann
Browse files

add renaming of existing h5 output files

parent bbd67d36
......@@ -6,17 +6,31 @@
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error missing string.h header
#endif
#ifdef HAVE_STRINGS_H
#include <strings.h>
#else
#error missing strings.h header
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#else
#error missing unistd.h header
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#else
#error missing sys/stat.h header
#endif
#ifdef HAVE_LIBHDF5
#include "hdf5.h"
#endif
......@@ -540,14 +554,35 @@ static void report_hdf5(int timer_choice){
if (jcon == 0) {
/* open HDF5 file and set generic info */
if ( (file_id = H5Fcreate(outfilename, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
/* file already present, modify outfilename and retry */
fprintf(stderr, "# SCT-Warning: HDF5 file named '%s' already present\n",
outfilename);
strcat(outfilename, "_");
strcat(outfilename, strrchr(tmpnam(NULL),'/')+1);
fprintf(stderr, " using '%s' instead\n", outfilename);
if( access( outfilename, W_OK ) != -1 ) {
struct stat attr;
if (stat(outfilename, &attr) == -1)
sct_abort("not able to access stat of outputfile", __FILE__, __LINE__);
/* file already present, try to modify old file by datestring suffix and retry */
static char newoutfilename[256], date[20];
strcpy(newoutfilename, outfilename);
strcat(newoutfilename, "_");
strftime(date, 20, "%F_%T", localtime(&(attr.st_mtime)));
strcat(newoutfilename, date);
if ( rename(outfilename, newoutfilename) != 0 ) {
sct_abort("not able to rename existing HDF5 outputfile", __FILE__, __LINE__);
}
fprintf(stderr, " renaming old file to '%s'\n", newoutfilename);
} else {
/* need to use a different name for current file since no modification on old file is allowed */
strcat(outfilename, "_");
strcat(outfilename, strrchr(tmpnam(NULL),'/')+1);
fprintf(stderr, " using '%s' instead\n", outfilename);
}
/* now retry opening file */
if ( (file_id = H5Fcreate(outfilename, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
sct_abort("not able to create HDF5 output", __FILE__, __LINE__);
sct_abort("not able to create HDF5 output", __FILE__, __LINE__);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment