From 1940d71782b4cc3519972ebf4504bbe4486cf7d0 Mon Sep 17 00:00:00 2001 From: allen Date: Tue, 21 Sep 1999 11:27:32 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2, which included commits to RCS files with non-trunk default branches. git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOBasic/trunk@3 b589c3ab-70e8-4b4d-a09f-cba2dd200880 --- src/Write.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/Write.c (limited to 'src/Write.c') diff --git a/src/Write.c b/src/Write.c new file mode 100644 index 0000000..d315610 --- /dev/null +++ b/src/Write.c @@ -0,0 +1,88 @@ +/*@@ + @routine Write.c + @date 18th September 1999 + @author Gabrielle Allen + @desc + Writes scalar grid variable data. + @enddesc + @calls + @calledby + @history + @hauthor @hdate + @hdesc + @hendhistory +@@*/ + +#include + +#include "cctk.h" +#include "cctk_parameters.h" +#include "cctk_Flesh.h" +#include "cctk_GHExtensions.h" +#include "cctk_Comm.h" +#include "cctk_Misc.h" +#include "cctk_WarnLevel.h" +#include "iobasicGH.h" + +void IOBasic_Write (cGH *GH, int index, const char *alias) +{ + DECLARE_CCTK_PARAMETERS + int reduce_handle; + char *openmode; + FILE *file; + CCTK_REAL *data_real; + CCTK_INT *data_int; + + /* Open the file (we write only on proc0) */ + if (CCTK_MyProc (GH) == 0) + { + char fname[256]; + int handle; + iobasicGH *myGH; + + myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")]; + + /* see if output files for this alias name were already created */ + if (GetNamedData (myGH->filenameListScalar, alias) == NULL) { + /* just store a non-NULL pointer in database */ + StoreNamedData (&myGH->filenameListScalar, alias, (void *) 1); + openmode = "w"; + } else + openmode = "a"; + + sprintf (fname, "%s/%s.tl", myGH->outpfx_Scalar, alias); + file = fopen(fname,openmode); + + if (*openmode == 'w') { + char title_start_char; + + if (CCTK_Equals(outScalar_style,"gnuplot")) + title_start_char = '#'; + else { + if (! CCTK_Equals(outScalar_style,"xgraph")) + CCTK_WARN(3,"Don't understand outScalar_style ... using xgraph"); + title_start_char = 34; + } + + fprintf (file,"%c%s v time\n",title_start_char,alias); + } + + switch (CCTK_VarTypeI(index)) { + case CCTK_VARIABLE_REAL: + data_real = ((CCTK_REAL ***) GH->data) [index][0]; + fprintf(file,"%f %25.13f\n",GH->cctk_time,*data_real); + break; + case CCTK_VARIABLE_INT: + data_int = ((CCTK_INT ***) GH->data) [index][0]; + fprintf(file,"%f %d\n",GH->cctk_time,*data_int); + break; + default: + CCTK_WARN (3, "Unsupported data type"); + return; + } + + fclose(file); + + } +} + -- cgit v1.2.3