From f4f0b7b3662ef4a79d8333d7bb915c5e87a318a2 Mon Sep 17 00:00:00 2001 From: tradke Date: Tue, 17 Oct 2000 14:35:55 +0000 Subject: Really evaluate the steerable parameter "IOBasic::outScalar_reductions". Also use the new filename scheme for scalar output files if selected. git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOBasic/trunk@74 b589c3ab-70e8-4b4d-a09f-cba2dd200880 --- src/WriteGF.c | 185 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 134 insertions(+), 51 deletions(-) diff --git a/src/WriteGF.c b/src/WriteGF.c index 89cff1e..946d593 100644 --- a/src/WriteGF.c +++ b/src/WriteGF.c @@ -3,19 +3,15 @@ @date Tue Apr 1 16:45:35 1997 @author Paul Walker @desc - Dumps the scalar data. + Dumps the scalar data of CCTK_ARRAY and CCTK_GF variables. @enddesc - @calls - @calledby - @history - @hauthor Thomas Radke @hdate 17 Mar 1999 - @hdesc included "cctk_Comm.h" to overload CCTK_GetMyProc() properly - @hendhistory + @version $Id$ @@*/ #include #include #include /* strlen(3) */ +#include /* isalpha(3) */ #include #include /* stat(2) */ @@ -26,49 +22,77 @@ #include "iobasicGH.h" -void IOBasic_WriteGF (cGH *GH, int index, const char *alias) +/* the rcs ID and its dummy function to use it */ +static char *rcsid = "$Id$"; +CCTK_FILEVERSION(CactusBase_IOBasic_WriteGF_c) + + + /*@@ + @routine IOBasic_WriteGF + @date Mon Jun 19 2000 + @author Thomas Radke + @desc + Apply the given reduction operators on the CCTK_ARRAY or + CCTK_GF variable and output the result into a text file + suitable for postprocessing by either gluplot or xgraph. + @enddesc + + @calls CCTK_QueryGroupStorageI + CCTK_Reduce + CCTK_ReductionHandle + IOUtil_RestartFromRecovery + IOUtil_AdvertiseFile + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype cGH * + @vio in + @endvar + @var index + @vdesc CCTK index of the variable to output + @vtype int + @vio in + @endvar + @var alias + @vdesc alias name to use for building the output filename + @vtype const char * + @vio in + @endvar +@@*/ +void IOBasic_WriteGF (cGH *GH, + int index, + const char *alias) { DECLARE_CCTK_PARAMETERS int ierr; - int i; + int reduction_handle; iobasicGH *myGH; FILE *file; char *openmode; char *filename; + char *reduction_op; + char *string_start; + char *string_end; char title_start_char; - int reduction_handle; char *format_str; + const char *file_extension; + char *fullname; struct stat fileinfo; - + ioAdvertisedFileDesc advertised_file; CCTK_REAL reduction_value; /* add more reductions to this table if you want, telling it - the reduction operator - the label for the file header - the filename extension (suffixed by ".tl" for trace line) */ - const struct - { - char *operator; - char *label; - char *extension; - } reductions [] = { - {"minimum", "min", "min"}, - {"maximum", "max", "max"}, - {"norm1", "norm1", "nm1"}, - {"norm2", "norm2", "nm2"}, - }; - -#define NUM_REDUCTIONS (sizeof (reductions) / sizeof (reductions [0])) /* first, check if variable has storage assigned */ if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (index))) { - char *fullname; - fullname = CCTK_FullName (index); CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "IOBasic_WriteGF: No 0D output for '%s' (no storage)", - fullname); + "IOBasic_WriteGF: No scalar output for '%s' (no storage)", + fullname); free (fullname); return; } @@ -76,42 +100,103 @@ void IOBasic_WriteGF (cGH *GH, int index, const char *alias) /* 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; + /* set the output file extension and the output style */ + if (CCTK_Equals (outScalar_style, "gnuplot")) + { + file_extension = ".asc"; + title_start_char = '#'; + } + else + { + file_extension = ".xg"; + title_start_char = 34; + } /* get the GH extension handle for IOBasic */ - myGH = (iobasicGH *) GH->extensions [CCTK_GHExtensionHandle ("IOBasic")]; + myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic"); - /* the extra characters should be sufficient - for the longest filename extension */ - filename = (char *) - malloc (strlen (myGH->outdirScalar) + strlen (alias) + 20); + /* allocate strings for the filename and the reduction operator */ + filename = (char *) malloc (strlen (myGH->outdirScalar) + strlen (alias) + + strlen (outScalar_reductions) + + strlen (file_extension) + 3); + reduction_op = (char *) malloc (strlen (outScalar_reductions) + 1); - /* now loop over all IOBasic reduction operations */ - for (i = 0; i < NUM_REDUCTIONS; i++) + /* now loop over all reduction operators */ + string_start = outScalar_reductions; + while (string_start && *string_start) { + /* skip leading spaces */ + while (isspace (*string_start)) + { + string_start++; + } + if (! *string_start) + { + break; + } + + /* advance to end of the operator string */ + string_end = string_start + 1; + while (*string_end && ! isspace (*string_end)) + { + string_end++; + } + + /* copy the operator string */ + strncpy (reduction_op, string_start, string_end - string_start); + reduction_op[string_end - string_start] = 0; + string_start = string_end; /* get the reduction handle from the reduction operator */ - reduction_handle = CCTK_ReductionHandle (reductions [i].operator); + reduction_handle = CCTK_ReductionHandle (reduction_op); if (reduction_handle < 0) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "IOBasic_WriteGF: Invalid reduction operator '%s'", - reductions [i].operator); + reduction_op); continue; } /* do the reduction (all processors) */ ierr = CCTK_Reduce (GH, 0, reduction_handle, 1, CCTK_VARIABLE_REAL, - &reduction_value, 1, index); + &reduction_value, 1, index); /* dump the reduction value to file by processor 0 */ if (ierr == 0 && CCTK_MyProc (GH) == 0) { /* build the filename */ - sprintf (filename, "%s/%s_%s.tl", myGH->outdirScalar, alias, - reductions [i].extension); + if (new_filename_scheme) + { + sprintf (filename, "%s/%s_%s%s", myGH->outdirScalar, alias, + reduction_op, file_extension); + } + else + { + /* FIXME: this check can go if we switch to the new filename scheme */ + if (strcmp (reduction_op, "minimum") == 0) + { + file_extension = "min"; + } + else if (strcmp (reduction_op, "maximum") == 0) + { + file_extension = "max"; + } + else if (strcmp (reduction_op, "norm1") == 0) + { + file_extension = "nm1"; + } + else if (strcmp (reduction_op, "norm2") == 0) + { + file_extension = "nm2"; + } + else + { + file_extension = "unknown"; + } + sprintf (filename, "%s/%s_%s.tl", myGH->outdirScalar, alias, + file_extension); + } /* see if output files for this alias name were already created */ if (GetNamedData (myGH->filenameListScalar, filename) == NULL) @@ -137,7 +222,7 @@ void IOBasic_WriteGF (cGH *GH, int index, const char *alias) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "IOBasic_WriteGF: Could not open output file '%s'", - filename); + filename); continue; } @@ -145,19 +230,16 @@ void IOBasic_WriteGF (cGH *GH, int index, const char *alias) advertise the file, and save the filename in the database */ if (*openmode == 'w') { - ioAdvertisedFileDesc advertised_file; - - fprintf (file, "%c%s %s v time\n", title_start_char, alias, - reductions [i].label); + reduction_op); /* advertise the file for downloading */ - advertised_file.slice = reductions [i].extension; + advertised_file.slice = reduction_op; 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"; + advertised_file.mimetype = CCTK_Equals (outScalar_style, "gnuplot") ? + "application/gnuplot" : "application/x-graph"; IOUtil_AdvertiseFile (GH, filename, &advertised_file); @@ -173,6 +255,7 @@ void IOBasic_WriteGF (cGH *GH, int index, const char *alias) } } - /* clean up */ + /* free allocated resources */ + free (reduction_op); free (filename); } -- cgit v1.2.3