aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--src/Write.c21
-rw-r--r--src/WriteGF.c15
2 files changed, 28 insertions, 8 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;
diff --git a/src/WriteGF.c b/src/WriteGF.c
index 2e7e073..73be217 100644
--- a/src/WriteGF.c
+++ b/src/WriteGF.c
@@ -15,15 +15,18 @@
#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_WriteGF (cGH *GH, int index, const char *alias)
{
DECLARE_CCTK_PARAMETERS
int i;
+ ioGH *ioUtilGH;
iobasicGH *myGH;
FILE *file;
char *openmode;
@@ -69,6 +72,7 @@ void IOBasic_WriteGF (cGH *GH, int index, const char *alias)
else
title_start_char = 34; /* this is for xgraph */
+ ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")];
myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")];
/* the extra characters should be sufficient
@@ -99,9 +103,14 @@ void IOBasic_WriteGF (cGH *GH, int index, const char *alias)
reductions [i].extension);
/* see if output files for this alias name were already created */
- if (GetNamedData (myGH->filenameListScalar, filename) == NULL)
- openmode = "w";
- else
+ if (GetNamedData (myGH->filenameListScalar, filename) == NULL) {
+ /* if restart from recovery, all existing files are opened
+ in append mode */
+ if (ioUtilGH->recovered)
+ openmode = access (filename, F_OK) == 0 ? "a" : "w";
+ else
+ openmode = "w";
+ } else
openmode = "a";
file = fopen (filename, openmode);