aboutsummaryrefslogtreecommitdiff
path: root/src/Write.c
diff options
context:
space:
mode:
authortradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880>2000-04-12 14:13:21 +0000
committertradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880>2000-04-12 14:13:21 +0000
commitd0868bde35d7b95243f04b12acacb806052de6da (patch)
tree39d1fb9d91cc08feed7ab135fabe78483c859f64 /src/Write.c
parent51345f7a1f6f664e85cf40d6f92d8f7946a220fd (diff)
After successful recovery, already existing output files are opened
in append mode (and not truncated as it was before) to keep the old data. Note that there may exist multiple data entries for the same timestep now if the restart from recovery is earlier than the last timestep of the output. You'll see that in gnuplot and xgraph as a straight line. git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOBasic/trunk@49 b589c3ab-70e8-4b4d-a09f-cba2dd200880
Diffstat (limited to 'src/Write.c')
-rw-r--r--src/Write.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/Write.c b/src/Write.c
index 322cc62..a41e90c 100644
--- a/src/Write.c
+++ b/src/Write.c
@@ -15,9 +15,11 @@
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h> /* access(2) */
#include "cctk.h"
#include "cctk_Parameters.h"
+#include "CactusBase/IOUtil/src/ioGH.h"
#include "iobasicGH.h"
void IOBasic_Write (cGH *GH, int index, const char *alias)
@@ -27,8 +29,12 @@ void IOBasic_Write (cGH *GH, int index, const char *alias)
FILE *file;
CCTK_REAL *data_real;
CCTK_INT *data_int;
+ ioGH *ioUtilGH;
int decnot;
+
+ ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")];
+
/* check if decimal or exponential notation desired*/
decnot=CCTK_Equals(out_format,"f")?1:0;
@@ -55,19 +61,24 @@ void IOBasic_Write (cGH *GH, int index, const char *alias)
sprintf (fname, "%s/%s.tl", myGH->outdirScalar, alias);
/* see if output files for this alias name were already created */
- if (GetNamedData (myGH->filenameListScalar, fname) == NULL)
- openmode = "w";
- else
+ if (GetNamedData (myGH->filenameListScalar, fname) == NULL) {
+ /* if restart from recovery, all existing files are opened
+ in append mode */
+ if (ioUtilGH->recovered)
+ openmode = access (fname, F_OK) == 0 ? "a" : "w";
+ else
+ openmode = "w";
+ } else
openmode = "a";
- file = fopen(fname,openmode);
+ file = fopen (fname, openmode);
if (file == NULL) {
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"Could not open output file '%s'", fname);
free (fname);
return;
}
-
+
if (*openmode == 'w') {
char title_start_char;