aboutsummaryrefslogtreecommitdiff
path: root/src/WriteGF.c
diff options
context:
space:
mode:
authortradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880>2000-05-26 09:43:21 +0000
committertradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880>2000-05-26 09:43:21 +0000
commit86a1038da146965a4c62239de20ea4fdc96211f6 (patch)
tree5564392600e3e1bc09de5204cfda0086b9ca2c5c /src/WriteGF.c
parent5e4946d84f9abf20ab498c1759d510a5e23b65f1 (diff)
Advertise output files.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOBasic/trunk@58 b589c3ab-70e8-4b4d-a09f-cba2dd200880
Diffstat (limited to 'src/WriteGF.c')
-rw-r--r--src/WriteGF.c60
1 files changed, 41 insertions, 19 deletions
diff --git a/src/WriteGF.c b/src/WriteGF.c
index 7e1e254..28560f0 100644
--- a/src/WriteGF.c
+++ b/src/WriteGF.c
@@ -36,7 +36,7 @@ void IOBasic_WriteGF (cGH *GH, int index, const char *alias)
char *filename;
char title_start_char;
int reduction_handle;
- int decnot;
+ char *format_str;
struct stat fileinfo;
CCTK_REAL reduction_value;
@@ -57,8 +57,6 @@ void IOBasic_WriteGF (cGH *GH, int index, const char *alias)
#define NUM_REDUCTIONS (sizeof (reductions) / sizeof (reductions [0]))
- /* check if decimal or exponential format desired */
- decnot = CCTK_Equals(out_format,"f")?1:0;
/* first, check if variable has storage assigned */
if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (index))) {
@@ -71,11 +69,13 @@ void IOBasic_WriteGF (cGH *GH, int index, const char *alias)
return;
}
- if (CCTK_Equals (outScalar_style, "gnuplot"))
- title_start_char = '#';
- else
- title_start_char = 34; /* this is for xgraph */
+ /* check if decimal or exponential format desired */
+ format_str = CCTK_Equals (out_format, "f") ? "%f %25.13f\n" : "%e %25.13e\n";
+
+ /* set the output style */
+ title_start_char = CCTK_Equals (outScalar_style, "gnuplot") ? '#' : 34;
+ /* get the GH extension handles for IOUtil and IOBasic */
ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")];
myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")];
@@ -85,7 +85,8 @@ void IOBasic_WriteGF (cGH *GH, int index, const char *alias)
malloc (strlen (myGH->outdirScalar) + strlen (alias) + 20);
/* now loop over all IOBasic reduction operations */
- for (i = 0; i < NUM_REDUCTIONS; i++) {
+ for (i = 0; i < NUM_REDUCTIONS; i++)
+ {
/* get the reduction handle from the reduction operator */
reduction_handle = CCTK_ReductionHandle (reductions [i].operator);
@@ -100,47 +101,68 @@ void IOBasic_WriteGF (cGH *GH, int index, const char *alias)
&reduction_value, 1, index);
/* dump the reduction value to file by processor 0 */
- if (CCTK_MyProc (GH) == 0) {
+ if (CCTK_MyProc (GH) == 0)
+ {
/* build the filename */
sprintf (filename, "%s/%s_%s.tl", myGH->outdirScalar, alias,
reductions [i].extension);
/* see if output files for this alias name were already created */
- if (GetNamedData (myGH->filenameListScalar, filename) == NULL) {
+ if (GetNamedData (myGH->filenameListScalar, filename) == NULL)
+ {
/* if restart from recovery, all existing files are opened
in append mode */
if (ioUtilGH->recovered)
openmode = stat (filename, &fileinfo) == 0 ? "a" : "w";
else
openmode = "w";
- } else
+ }
+ else
+ {
openmode = "a";
+ }
file = fopen (filename, openmode);
- if (file == NULL) {
+ if (file == NULL)
+ {
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"Could not open output file '%s'", filename);
continue;
}
- /* when creating the file, write the header
- and also save the filename in the database */
- if (*openmode == 'w') {
+ /* when creating the file, write the header,
+ advertise the file, and save the filename in the database */
+ if (*openmode == 'w')
+ {
+ IOUtil_AdvertisedFileDesc_t advertised_file;
+
+
fprintf (file, "%c%s %s v time\n", title_start_char, alias,
reductions [i].label);
+
+ /* advertise the file for downloading */
+ advertised_file.slice = reductions [i].extension;
+ advertised_file.thorn = CCTK_THORNSTRING;
+ advertised_file.varname = CCTK_FullName (index);
+ advertised_file.description = "Reduction on Grid Functions";
+ advertised_file.mimetype = CCTK_Equals (outScalar_style, "gnuplot") ?
+ "application/gnuplot" : "application/x-graph";
+
+ IOUtil_AdvertiseFile (GH, filename, &advertised_file);
+
+ free (advertised_file.varname);
+
/* just store a non-NULL pointer in database */
StoreNamedData (&myGH->filenameListScalar, filename, (void *) 1);
}
/* write the data and close the file */
- if (decnot)
- fprintf (file, "%f %25.13f\n", GH->cctk_time, reduction_value);
- else
- fprintf (file, "%e %25.13e\n", GH->cctk_time, reduction_value);
+ fprintf (file, format_str, GH->cctk_time, reduction_value);
fclose (file);
}
}
+ /* clean up */
free (filename);
}