aboutsummaryrefslogtreecommitdiff
path: root/src/Write.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Write.c')
-rw-r--r--src/Write.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/Write.c b/src/Write.c
index 388a37f..18abe0e 100644
--- a/src/Write.c
+++ b/src/Write.c
@@ -26,15 +26,15 @@
#include "iobasicGH.h"
-void IOBasic_Write (cGH *GH, int index, const char *alias)
+void IOBasic_Write (cGH *GH, int vindex, const char *alias)
{
DECLARE_CCTK_PARAMETERS
char *openmode;
FILE *file;
void *data;
- char *fname;
+ char *fname, buffer[128];
iobasicGH *myGH;
- char *format_str_real, *format_str_int;
+ char format_str_real[15], format_str_int[15];
struct stat fileinfo;
@@ -45,11 +45,11 @@ void IOBasic_Write (cGH *GH, int index, const char *alias)
}
/* first, check if variable has storage assigned */
- if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (index)))
+ if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex)))
{
char *fullname;
- fullname = CCTK_FullName (index);
+ fullname = CCTK_FullName (vindex);
CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
"IOBasic_Write: No scalar output for '%s' (no storage)",
fullname);
@@ -58,16 +58,8 @@ void IOBasic_Write (cGH *GH, int index, const char *alias)
}
/* set the output format string for the desired notation */
- if (CCTK_Equals (out_format, "f"))
- {
- format_str_real = "%f %25.13f\n";
- format_str_int = "%f %d\n";
- }
- else
- {
- format_str_real = "%e %25.13e\n";
- format_str_int = "%e %d\n";
- }
+ sprintf (format_str_real, "%%%s\t%%%s\n", out_format, out_format);
+ sprintf (format_str_int, "%%%s\t%%d\n", out_format);
/* get the GH extensions for IOBasic */
myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")];
@@ -103,41 +95,47 @@ void IOBasic_Write (cGH *GH, int index, const char *alias)
if (*openmode == 'w')
{
- char title_start_char;
+ char comment_char;
ioAdvertisedFileDesc advertised_file;
if (CCTK_Equals (outScalar_style, "gnuplot"))
{
- title_start_char = '#';
+ comment_char = '#';
advertised_file.mimetype = "application/gnuplot";
}
else
{
- title_start_char = 34; /* this is for xgraph */
+ comment_char = '"'; /* this is for xgraph */
advertised_file.mimetype = "application/x-graph";
}
- /* write the header */
- fprintf (file, "%c%s v time\n", title_start_char, alias);
-
/* just store a non-NULL pointer in database */
StoreNamedData (&myGH->filenameListScalar, fname, (void *) 1);
/* advertise the file for downloading */
advertised_file.slice = "tl";
advertised_file.thorn = CCTK_THORNSTRING;
- advertised_file.varname = CCTK_FullName (index);
+ advertised_file.varname = CCTK_FullName (vindex);
advertised_file.description = "Scalar value";
IOUtil_AdvertiseFile (GH, fname, &advertised_file);
+ /* write the file info and the header */
+ CCTK_ParameterFilename (sizeof (buffer), buffer);
+ fprintf (file, "%cParameter file %s\n", comment_char, buffer);
+ Util_CurrentTime (sizeof (buffer), buffer);
+ fprintf (file, "%cCreated %s\n", comment_char, buffer);
+ fprintf (file, "%cx-label time\n", comment_char);
+ fprintf (file, "%cy-label %s\n", comment_char, advertised_file.varname);
+ fprintf (file, "%c%s v time\n", comment_char, alias);
+
free (advertised_file.varname);
}
/* get the data pointer */
- data = CCTK_VarDataPtrI (GH, 0, index);
+ data = CCTK_VarDataPtrI (GH, 0, vindex);
- switch (CCTK_VarTypeI (index))
+ switch (CCTK_VarTypeI (vindex))
{
case CCTK_VARIABLE_REAL:
fprintf (file, format_str_real, GH->cctk_time,