aboutsummaryrefslogtreecommitdiff
path: root/src/WriteScalar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/WriteScalar.c')
-rw-r--r--src/WriteScalar.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/WriteScalar.c b/src/WriteScalar.c
index dbd1ab3..c34143c 100644
--- a/src/WriteScalar.c
+++ b/src/WriteScalar.c
@@ -118,10 +118,7 @@ void IOBasic_WriteScalarGA (const cGH *GH,
/* get the GH extension handle for IOBasic */
myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic");
- /* allocate strings for the filename and the reduction operator */
- filename = (char *) malloc (strlen (myGH->outdirScalar) + strlen (alias) +
- strlen (reductions.const_ptr) +
- strlen (file_extension) + 3);
+ /* allocate string for the reduction operator */
reduction_op = (char *) malloc (strlen (reductions.const_ptr) + 1);
/* now loop over all reduction operators */
@@ -168,9 +165,12 @@ void IOBasic_WriteScalarGA (const cGH *GH,
if (ierr == 0 && CCTK_MyProc (GH) == 0)
{
- /* build the filename */
if (new_filename_scheme)
{
+ /* allocate filename string buffer and build the filename */
+ filename = (char *) malloc (strlen (myGH->outdirScalar) +
+ strlen (alias) + strlen (reduction_op) +
+ strlen (file_extension) + 2);
sprintf (filename, "%s%s_%s%s", myGH->outdirScalar, alias,
reduction_op, file_extension);
}
@@ -195,8 +195,12 @@ void IOBasic_WriteScalarGA (const cGH *GH,
}
else
{
- file_extension = "unknown";
+ file_extension = reduction_op;
}
+
+ /* allocate filename string buffer and build the filename */
+ filename = (char *) malloc (strlen (myGH->outdirScalar) +
+ strlen (alias) + strlen (file_extension)+5);
sprintf (filename, "%s%s_%s.tl", myGH->outdirScalar, alias,
file_extension);
}
@@ -215,12 +219,12 @@ void IOBasic_WriteScalarGA (const cGH *GH,
"IOBasic_WriteScalarGA: Could not open output file '%s'",
filename);
}
+ free (filename);
}
}
/* free allocated resources */
free (reduction_op);
- free (filename);
}