diff options
author | tradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880> | 2002-03-16 22:04:30 +0000 |
---|---|---|
committer | tradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880> | 2002-03-16 22:04:30 +0000 |
commit | f1d419cc71594cd0e4bb2ae426af55000712bb28 (patch) | |
tree | de6cfaeaa3d576a2527aed111a7a3e4f6c2b09f9 /src/WriteScalar.c | |
parent | 297bfb0299ddc1d6bea56c14bf898fa409fe136b (diff) |
Allow individual reductions on variables by parsing the options string
in the 'IOBasic::outScalar_vars' parameter.
This closes PR CactusBase/895.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOBasic/trunk@116 b589c3ab-70e8-4b4d-a09f-cba2dd200880
Diffstat (limited to 'src/WriteScalar.c')
-rw-r--r-- | src/WriteScalar.c | 209 |
1 files changed, 109 insertions, 100 deletions
diff --git a/src/WriteScalar.c b/src/WriteScalar.c index 413463c..12083de 100644 --- a/src/WriteScalar.c +++ b/src/WriteScalar.c @@ -24,6 +24,8 @@ static const char *rcsid = "$Header$"; CCTK_FILEVERSION(CactusBase_IOBasic_WriteScalar_c) +static int IOBasic_WriteScalarGS (const cGH *GH, int vindex, const char *alias); +static int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias); static FILE *OpenScalarFile (const cGH *GH, int vindex, const char *filename, @@ -32,6 +34,75 @@ static FILE *OpenScalarFile (const cGH *GH, const char *aliasname); /*@@ + @routine IOBasic_WriteScalar + @date Mon Jun 19 2000 + @author Thomas Radke + @desc + Write a scalar value of a CCTK variable into an ASCII file + suitable for postprocessing by either gluplot or xgraph. + This routine just calls the appropriate output routine + according the the variable type. + @enddesc + + @calls CCTK_QueryGroupStorageI + CCTK_GroupIndexFromVarI + CCTK_GroupTypeFromVarI + IOBasic_WriteScalarGS + IOBasic_WriteScalarGA + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var vindex + @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 + + @returntype int + @returndesc + return code of either @seeroutine IOBasic_WriteScalarGS or + @seeroutine IOBasic_WriteScalarGA, or<BR> + -1 if variable has no storage assigned + @endreturndesc +@@*/ +int IOBasic_WriteScalar (const cGH *GH, int vindex, const char *alias) +{ + int retval; + char *fullname; + + + /* check if variable has storage assigned */ + if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex))) + { + fullname = CCTK_FullName (vindex); + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOBasic_WriteScalar: No scalar output for '%s' (no storage)", + fullname); + free (fullname); + retval = -1; + } + else if (CCTK_GroupTypeFromVarI (vindex) == CCTK_SCALAR) + { + retval = IOBasic_WriteScalarGS (GH, vindex, alias); + } + else + { + retval = IOBasic_WriteScalarGA (GH, vindex, alias); + } + + return (retval); +} + + + /*@@ @routine IOBasic_WriteScalarGA @date Mon Jun 19 2000 @author Thomas Radke @@ -41,8 +112,7 @@ static FILE *OpenScalarFile (const cGH *GH, suitable for postprocessing by either gluplot or xgraph. @enddesc - @calls CCTK_QueryGroupStorageI - CCTK_Reduce + @calls CCTK_Reduce CCTK_ReductionHandle IOUtil_RestartFromRecovery IOUtil_AdvertiseFile @@ -65,24 +135,17 @@ static FILE *OpenScalarFile (const cGH *GH, @returntype int @returndesc - 0 for success, or<BR> - -1 if variable has no storage assigned + 0 for success @endreturndesc @@*/ -int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias) +static int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias) { - int ierr; - int reduction_handle; iobasicGH *myGH; FILE *file; char *filename; - char *reduction_op; - char *string_start; - char *string_end; char format_str[15]; const char *file_extension; - char *fullname; - CCTK_REAL reduction_value; + iobasic_reduction_t *reduction; union { char *non_const_ptr; @@ -102,17 +165,6 @@ int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias) reductions.const_ptr = outScalar_reductions; GH_fake_const.const_ptr = GH; - /* first, check if variable has storage assigned */ - if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex))) - { - fullname = CCTK_FullName (vindex); - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "IOBasic_WriteScalarGA: No scalar output for '%s' (no storage)", - fullname); - free (fullname); - return (-1); - } - /* set output format */ sprintf (format_str, "%%%s\t%%%s\n", out_format, out_format); @@ -121,100 +173,71 @@ int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias) /* get the GH extension handle for IOBasic */ myGH = (iobasicGH *) CCTK_GHExtension (GH, "IOBasic"); - - /* allocate string for the reduction operator */ - reduction_op = (char *) malloc (strlen (reductions.const_ptr) + 1); + reduction = myGH->scalar_reductions[vindex].reductions; /* now loop over all reduction operators */ - string_start = reductions.non_const_ptr; - while (string_start && *string_start) + while (reduction) { - /* skip leading spaces */ - while (isspace ((int) *string_start)) - { - string_start++; - } - if (! *string_start) - { - break; - } - - /* advance to end of the operator string */ - string_end = string_start + 1; - while (*string_end && ! isspace ((int) *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 (reduction_op); - if (reduction_handle < 0) + /* do the reduction (all processors) */ + reduction->is_valid = CCTK_Reduce (GH_fake_const.non_const_ptr, 0, + reduction->handle, 1, + CCTK_VARIABLE_REAL, + &reduction->value, 1, vindex) == 0; + if (! reduction->is_valid) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "IOBasic_WriteScalarGA: Invalid reduction operator '%s'", - reduction_op); - continue; + "IOBasic_WriteInfo: Internal error in reduction '%s'", + reduction->name); } - - /* do the reduction (all processors) */ - ierr = CCTK_Reduce (GH_fake_const.non_const_ptr, 0, reduction_handle, 1, - CCTK_VARIABLE_REAL, &reduction_value, 1, vindex); - - /* dump the reduction value to file by processor 0 */ - if (ierr == 0 && CCTK_MyProc (GH) == 0) + else if (CCTK_MyProc (GH) == 0) { - + /* dump the reduction value to file by processor 0 */ if (new_filename_scheme) { /* allocate filename string buffer and build the filename */ - filename = (char *) malloc (strlen (myGH->outdirScalar) + - strlen (alias) + strlen (reduction_op) + + filename = (char *) malloc (strlen (myGH->outdir) + + strlen (alias) + strlen (reduction->name) + strlen (file_extension) + 2); - sprintf (filename, "%s%s_%s%s", myGH->outdirScalar, alias, - reduction_op, file_extension); + sprintf (filename, "%s%s_%s%s", myGH->outdir, alias, + reduction->name, file_extension); } else { /* FIXME: this check can go if we switch to the new filename scheme */ - if (strcmp (reduction_op, "minimum") == 0) + if (strcmp (reduction->name, "minimum") == 0) { file_extension = "min"; } - else if (strcmp (reduction_op, "maximum") == 0) + else if (strcmp (reduction->name, "maximum") == 0) { file_extension = "max"; } - else if (strcmp (reduction_op, "norm1") == 0) + else if (strcmp (reduction->name, "norm1") == 0) { file_extension = "nm1"; } - else if (strcmp (reduction_op, "norm2") == 0) + else if (strcmp (reduction->name, "norm2") == 0) { file_extension = "nm2"; } else { - file_extension = reduction_op; + file_extension = reduction->name; } /* allocate filename string buffer and build the filename */ - filename = (char *) malloc (strlen (myGH->outdirScalar) + + filename = (char *) malloc (strlen (myGH->outdir) + strlen (alias) + strlen (file_extension)+5); - sprintf (filename, "%s%s_%s.tl", myGH->outdirScalar, alias, + sprintf (filename, "%s%s_%s.tl", myGH->outdir, alias, file_extension); } - file = OpenScalarFile (GH, vindex, filename, reduction_op, + file = OpenScalarFile (GH, vindex, filename, reduction->name, "Reduction on Grid Arrays", alias); if (file) { /* write the data and close the file */ - fprintf (file, format_str, GH->cctk_time, reduction_value); + fprintf (file, format_str, GH->cctk_time, reduction->value); fclose (file); } else @@ -225,10 +248,9 @@ int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias) } free (filename); } - } - /* free allocated resources */ - free (reduction_op); + reduction = reduction->next; + } return (0); } @@ -243,8 +265,7 @@ int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias) suitable for postprocessing by either gluplot or xgraph. @enddesc - @calls CCTK_QueryGroupStorageI - CCTK_Reduce + @calls CCTK_Reduce CCTK_ReductionHandle IOUtil_RestartFromRecovery IOUtil_AdvertiseFile @@ -267,19 +288,18 @@ int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias) @returntype int @returndesc - 0 for success, or<BR> - -1 if variable has no storage assigned + 0 for success @endreturndesc @@*/ -int IOBasic_WriteScalarGS (const cGH *GH, int vindex, const char *alias) +static int IOBasic_WriteScalarGS (const cGH *GH, int vindex, const char *alias) { - DECLARE_CCTK_PARAMETERS FILE *file; void *data; iobasicGH *myGH; - char *fullname, *filename; + char *filename; const char *file_extension; char format_str_real[15], format_str_int[15]; + DECLARE_CCTK_PARAMETERS /* output is done by processor 0 only */ @@ -288,17 +308,6 @@ int IOBasic_WriteScalarGS (const cGH *GH, int vindex, const char *alias) return (0); } - /* first, check if variable has storage assigned */ - if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex))) - { - fullname = CCTK_FullName (vindex); - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "IOBasic_WriteScalarGS: No scalar output for '%s' (no storage)", - fullname); - free (fullname); - return (-1); - } - /* 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); @@ -317,9 +326,9 @@ int IOBasic_WriteScalarGS (const cGH *GH, int vindex, const char *alias) } /* build the output filename */ - filename = (char *) malloc (strlen (myGH->outdirScalar) + strlen (alias) + + filename = (char *) malloc (strlen (myGH->outdir) + strlen (alias) + strlen (file_extension) + 1); - sprintf (filename, "%s%s%s", myGH->outdirScalar, alias, file_extension); + sprintf (filename, "%s%s%s", myGH->outdir, alias, file_extension); /* create/reopen the file */ file = OpenScalarFile (GH, vindex, filename, "tl", "Scalar value", alias); |