aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/Write.c158
-rw-r--r--src/WriteGF.c60
2 files changed, 137 insertions, 81 deletions
diff --git a/src/Write.c b/src/Write.c
index 4174304..65be41d 100644
--- a/src/Write.c
+++ b/src/Write.c
@@ -30,19 +30,21 @@ void IOBasic_Write (cGH *GH, int index, const char *alias)
DECLARE_CCTK_PARAMETERS
char *openmode;
FILE *file;
- CCTK_REAL *data_real;
- CCTK_INT *data_int;
+ void *data;
+ char *fname;
ioGH *ioUtilGH;
- int decnot;
+ iobasicGH *myGH;
+ char *format_str_real, *format_str_int;
+ struct stat fileinfo;
- ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")];
-
- /* check if decimal or exponential notation desired*/
- decnot=CCTK_Equals(out_format,"f")?1:0;
+ /* output is done by processor 0 only */
+ if (CCTK_MyProc (GH) != 0)
+ return;
/* first, check if variable has storage assigned */
- if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (index))) {
+ if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (index)))
+ {
char *fullname;
fullname = CCTK_FullName (index);
@@ -52,73 +54,105 @@ void IOBasic_Write (cGH *GH, int index, const char *alias)
return;
}
- /* Open the file (we write only on proc0) */
- if (CCTK_MyProc (GH) == 0)
+ /* set the output format string for the desired notation */
+ if (CCTK_Equals (out_format, "f"))
{
- char *fname;
- iobasicGH *myGH;
- struct stat fileinfo;
-
- myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")];
-
- fname = (char *) malloc (strlen (myGH->outdirScalar) + strlen (alias) + 5);
- 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) {
- /* if restart from recovery, all existing files are opened
- in append mode */
- if (ioUtilGH->recovered)
- openmode = stat (fname, &fileinfo) == 0 ? "a" : "w";
- else
- openmode = "w";
- } else
- openmode = "a";
-
- file = fopen (fname, openmode);
- if (file == NULL) {
- CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Could not open output file '%s'", fname);
- free (fname);
- return;
- }
+ 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";
+ }
- if (*openmode == 'w') {
- char title_start_char;
+ /* get the GH extensions for IOUtil and IOBasic */
+ ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")];
+ myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")];
- if (CCTK_Equals(outScalar_style,"gnuplot"))
- title_start_char = '#';
- else
- title_start_char = 34; /* this is for xgraph */
+ /* build the output filename */
+ fname = (char *) malloc (strlen (myGH->outdirScalar) + strlen (alias) + 5);
+ 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)
+ {
+ /* if restart from recovery, all existing files are opened
+ in append mode */
+ if (ioUtilGH->recovered)
+ openmode = stat (fname, &fileinfo) == 0 ? "a" : "w";
+ else
+ openmode = "w";
+ }
+ else
+ {
+ openmode = "a";
+ }
+
+ /* open the output file with the given mode */
+ file = fopen (fname, openmode);
+ if (file == NULL)
+ {
+ CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Could not open output file '%s'", fname);
+ free (fname);
+ return;
+ }
- fprintf (file,"%c%s v time\n",title_start_char,alias);
+ if (*openmode == 'w')
+ {
+ char title_start_char;
+ IOUtil_AdvertisedFileDesc_t advertised_file;
- /* just store a non-NULL pointer in database */
- StoreNamedData (&myGH->filenameListScalar, fname, (void *) 1);
+ if (CCTK_Equals (outScalar_style, "gnuplot"))
+ {
+ title_start_char = '#';
+ advertised_file.mimetype = "application/gnuplot";
}
+ else
+ {
+ title_start_char = 34; /* this is for xgraph */
+ advertised_file.mimetype = "application/x-graph";
+ }
+
+ /* write the header */
+ fprintf (file, "%c%s v time\n", title_start_char, alias);
- switch (CCTK_VarTypeI(index)) {
+ /* 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.description = "Scalar value";
+
+ IOUtil_AdvertiseFile (GH, fname, &advertised_file);
+
+ free (advertised_file.varname);
+ }
+
+ /* get the data pointer */
+ data = CCTK_VarDataPtrI (GH, 0, index);
+
+ switch (CCTK_VarTypeI (index))
+ {
case CCTK_VARIABLE_REAL:
- data_real = ((CCTK_REAL ***) GH->data) [index][0];
- if (decnot)
- fprintf(file,"%f %25.13f\n",GH->cctk_time,*data_real);
- else
- fprintf(file,"%e %25.13e\n",GH->cctk_time,*data_real);
+ fprintf (file, format_str_real, GH->cctk_time,
+ (double) *(CCTK_REAL *) data);
break;
case CCTK_VARIABLE_INT:
- data_int = ((CCTK_INT ***) GH->data) [index][0];
- if (decnot)
- fprintf(file,"%f %d\n",GH->cctk_time,*data_int);
- else
- fprintf(file,"%e %d\n",GH->cctk_time,*data_int);
+ fprintf (file, format_str_int, GH->cctk_time,
+ (int) *(CCTK_INT *) data);
break;
default:
CCTK_WARN (3, "Unsupported data type");
break;
- }
-
- fclose(file);
- free (fname);
-
}
+
+ /* close the output file */
+ fclose (file);
+
+ /* clean up */
+ free (fname);
}
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);
}