diff options
Diffstat (limited to 'src/Write.c')
-rw-r--r-- | src/Write.c | 185 |
1 files changed, 0 insertions, 185 deletions
diff --git a/src/Write.c b/src/Write.c deleted file mode 100644 index ba1a4c4..0000000 --- a/src/Write.c +++ /dev/null @@ -1,185 +0,0 @@ -/*@@ - @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 <stdio.h> -#include <stdlib.h> -#include <string.h> /* strlen(3) */ -#include <sys/types.h> -#include <sys/stat.h> /* stat(2) */ - -#include "cctk.h" -#include "cctk_Parameters.h" -#include "CactusBase/IOUtil/src/ioutil_AdvertisedFiles.h" -#include "CactusBase/IOUtil/src/ioutil_CheckpointRecovery.h" -#include "iobasicGH.h" - -static const char *rcsid = "$Header$"; - -CCTK_FILEVERSION(CactusBase_IOBasic_Write_c) - -void IOBasic_Write (cGH *GH, int vindex, const char *alias) -{ - DECLARE_CCTK_PARAMETERS - char *openmode; - FILE *file; - void *data; - char *fname, buffer[128]; - iobasicGH *myGH; - char format_str_real[15], format_str_int[15]; - struct stat fileinfo; - - - /* 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 (vindex))) - { - char *fullname; - - fullname = CCTK_FullName (vindex); - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "IOBasic_Write: No scalar output for '%s' (no storage)", - fullname); - free (fullname); - return; - } - - /* set the output format string for the desired notation */ - 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")]; - - /* build the output filename */ - /* skip the pathname if output goes into current directory */ - fname = (char *) malloc (strlen (myGH->outdirScalar) + strlen (alias) + 5); - if (strcmp (myGH->outdirScalar, ".")) - { - sprintf (fname, "%s/%s.tl", myGH->outdirScalar, alias); - } - else - { - sprintf (fname, "%s.tl", 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 (IOUtil_RestartFromRecovery (GH)) - 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; - } - - if (*openmode == 'w') - { - char comment_char; - ioAdvertisedFileDesc advertised_file; - - if (CCTK_Equals (outScalar_style, "gnuplot")) - { - comment_char = '#'; - advertised_file.mimetype = "application/gnuplot"; - } - else - { - comment_char = '"'; /* this is for xgraph */ - advertised_file.mimetype = "application/x-graph"; - } - - /* 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 (vindex); - advertised_file.description = "Scalar value"; - - IOUtil_AdvertiseFile (GH, fname, &advertised_file); - - /* write the file info and the header */ - if (CCTK_Equals (out_fileinfo, "parameter filename") || - CCTK_Equals (out_fileinfo, "all")) - { - buffer[0] = 0; - CCTK_ParameterFilename (sizeof (buffer), buffer); - fprintf (file, "%cParameter file %s\n", comment_char, buffer); - } - if (CCTK_Equals (out_fileinfo, "creation date") || - CCTK_Equals (out_fileinfo, "all")) - { - buffer[0] = 0; - Util_CurrentDate (sizeof (buffer), buffer); - fprintf (file, "%cCreated %s ", comment_char, buffer); - Util_CurrentTime (sizeof (buffer), buffer); - fprintf (file, "%s\n", buffer); - } - if (CCTK_Equals (out_fileinfo, "axis labels") || - CCTK_Equals (out_fileinfo, "all")) - { - 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, vindex); - - switch (CCTK_VarTypeI (vindex)) - { - case CCTK_VARIABLE_REAL: - fprintf (file, format_str_real, GH->cctk_time, - (double) *(CCTK_REAL *) data); - break; - case CCTK_VARIABLE_INT: - fprintf (file, format_str_int, GH->cctk_time, - (int) *(CCTK_INT *) data); - break; - default: - CCTK_WARN (3, "Unsupported data type"); - break; - } - - /* close the output file */ - fclose (file); - - /* clean up */ - free (fname); -} |