diff options
author | tradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880> | 2001-12-28 21:22:52 +0000 |
---|---|---|
committer | tradke <tradke@b589c3ab-70e8-4b4d-a09f-cba2dd200880> | 2001-12-28 21:22:52 +0000 |
commit | feb8726f2ab8a7004de5a3a9117d91d916ca86ae (patch) | |
tree | a268e18148368a30529419935604808475b365c3 | |
parent | 246994c0b838df1ce00b5bd31c7b355a961089f6 (diff) |
Fixed return code of I/O methods.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOBasic/trunk@110 b589c3ab-70e8-4b4d-a09f-cba2dd200880
-rw-r--r-- | src/OutputInfo.c | 41 | ||||
-rw-r--r-- | src/OutputScalar.c | 184 | ||||
-rw-r--r-- | src/WriteInfo.c | 28 | ||||
-rw-r--r-- | src/WriteScalar.c | 30 | ||||
-rw-r--r-- | src/iobasicGH.h | 6 |
5 files changed, 177 insertions, 112 deletions
diff --git a/src/OutputInfo.c b/src/OutputInfo.c index 5b9fe5b..96af228 100644 --- a/src/OutputInfo.c +++ b/src/OutputInfo.c @@ -79,15 +79,16 @@ static void PrintHeader (iobasicGH *myGH, int num_vars); @returntype int @returndesc - 0 for success + the number of variables which were output at this iteration + (or 0 if it wasn't time to output yet) @endreturndesc @@*/ int IOBasic_InfoOutputGH (const cGH *GH) { - DECLARE_CCTK_PARAMETERS - int vindex, num_vars; + int vindex, num_vars, retval; iobasic_reduction_t *reduction; iobasicGH *myGH; + DECLARE_CCTK_PARAMETERS /* get the GH extensions for IOBasic */ @@ -105,7 +106,7 @@ int IOBasic_InfoOutputGH (const cGH *GH) /* print header if neccessary */ num_vars = CCTK_NumVars (); if (myGH->info_reductions_changed) - { + { PrintHeader (myGH, num_vars); } @@ -120,7 +121,7 @@ int IOBasic_InfoOutputGH (const cGH *GH) } /* loop over all variables */ - for (vindex = 0; vindex < num_vars; vindex++) + for (vindex = retval = 0; vindex < num_vars; vindex++) { /* check this variable should be output */ if (myGH->info_reductions[vindex].num_reductions == 0) @@ -139,10 +140,12 @@ int IOBasic_InfoOutputGH (const cGH *GH) #endif /* get the data to output */ - IOBasic_WriteInfo (GH, vindex); - - /* register variable as having info output this iteration */ - myGH->outInfo_last[vindex] = GH->cctk_iteration; + if (IOBasic_WriteInfo (GH, vindex) == 0) + { + /* register variable as having info output this iteration */ + myGH->outInfo_last[vindex] = GH->cctk_iteration; + retval++; + } } /* finally print the stuff to screen */ @@ -158,7 +161,7 @@ int IOBasic_InfoOutputGH (const cGH *GH) putchar ('\n'); fflush (stdout); - return (0); + return (retval); } @@ -189,10 +192,10 @@ int IOBasic_InfoOutputGH (const cGH *GH) @@*/ int IOBasic_TimeForInfoOutput (const cGH *GH, int vindex) { - DECLARE_CCTK_PARAMETERS int retval; char *fullname; iobasicGH *myGH; + DECLARE_CCTK_PARAMETERS /* get the GH extensions for IOBasic */ @@ -247,13 +250,14 @@ int IOBasic_TimeForInfoOutput (const cGH *GH, int vindex) @returntype int @returndesc - 0 for success + return code of @seeroutine IOBasic_WriteInfo @endreturndesc @@*/ int IOBasic_TriggerInfoOutput (const cGH *GH, int vindex) { - DECLARE_CCTK_PARAMETERS + int retval; iobasicGH *myGH; + DECLARE_CCTK_PARAMETERS /* get the GH extension for IOBasic */ @@ -266,12 +270,15 @@ int IOBasic_TriggerInfoOutput (const cGH *GH, int vindex) #endif /* get the data values to output */ - IOBasic_WriteInfo (GH, vindex); + retval = IOBasic_WriteInfo (GH, vindex); - /* gegister variable as having Info output at this iteration */ - myGH->outInfo_last[vindex] = GH->cctk_iteration; + if (retval == 0) + { + /* gegister variable as having Info output at this iteration */ + myGH->outInfo_last[vindex] = GH->cctk_iteration; + } - return (0); + return (retval); } diff --git a/src/OutputScalar.c b/src/OutputScalar.c index cee1375..663dbeb 100644 --- a/src/OutputScalar.c +++ b/src/OutputScalar.c @@ -2,11 +2,11 @@ @file Output.c @date Mon 21 September @author Gabrielle Allen - @desc + @desc Functions to deal with scalar output of grid variables - @enddesc + @enddesc @@*/ - + /* #define IOBASIC_DEBUG 1 */ #include <stdio.h> @@ -22,7 +22,10 @@ static const char *rcsid = "$Header$"; CCTK_FILEVERSION(CactusBase_IOBasic_OutputScalar_c) -/* function prototypes */ + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ static void CheckSteerableParameters (iobasicGH *myGH); static void SetOutputFlag (int vindex, const char *optstring, void *arg); @@ -32,21 +35,27 @@ static void SetOutputFlag (int vindex, const char *optstring, void *arg); @date Sat March 6 1999 @author Gabrielle Allen @desc - Loops over all variables and outputs them if necessary + Loops over all variables and outputs them if necessary @enddesc - @calledby CCTK_OutputGH ("IOBasic") - @history - - @endhistory - @var GH - @vdesc Pointer to CCTK GH - @vtype const cGH * - @vio in + @calls IOBasic_TimeForScalarOutput + IOBasic_WriteScalarGS + IOBasic_WriteScalarGA + + @var GH + @vdesc Pointer to CCTK GH + @vtype const cGH * + @vio in @endvar + + @returntype int + @returndesc + the number of variables which were output at this iteration + (or 0 if it wasn't time to output yet) + @endreturndesc @@*/ int IOBasic_ScalarOutputGH (const cGH *GH) { - int vindex; + int i, vindex, retval; const char *name; iobasicGH *myGH; @@ -63,9 +72,8 @@ int IOBasic_ScalarOutputGH (const cGH *GH) } /* Loop over all variables */ - for (vindex = 0; vindex < CCTK_NumVars (); vindex++) + for (vindex = retval = 0; vindex < CCTK_NumVars (); vindex++) { - /* Is it time for output ? */ if (! IOBasic_TimeForScalarOutput (GH, vindex)) { @@ -81,23 +89,25 @@ int IOBasic_ScalarOutputGH (const cGH *GH) printf(" Variable = -%s-\n",name); printf(" Last output iteration was = %d\n",myGH->outScalar_last[vindex]); #endif - + /* Make the IO call */ if (CCTK_GroupTypeFromVarI (vindex) == CCTK_SCALAR) { - IOBasic_WriteScalarGS (GH, vindex, name); + i = IOBasic_WriteScalarGS (GH, vindex, name); } else { - IOBasic_WriteScalarGA (GH, vindex, name); + i = IOBasic_WriteScalarGA (GH, vindex, name); + } + if (i == 0) + { + /* Register GF as having 0D output this iteration */ + myGH->outScalar_last [vindex] = GH->cctk_iteration; + retval++; } - - /* Register GF as having 0D output this iteration */ - myGH->outScalar_last [vindex] = GH->cctk_iteration; - } /* end of loop over all variables */ - return (0); + return (retval); } @@ -106,31 +116,37 @@ int IOBasic_ScalarOutputGH (const cGH *GH) @date Sat March 6 1999 @author Gabrielle Allen @desc - unconditional output of a variable using the IOBasic output method + Unconditional output of a variable using IOBasic's SCALAR + output method @enddesc - @calledby IOBasic_ScalarOutputGH, CCTK_OutputVarAsByMethod ("IOBasic") - @var GH - @vdesc Pointer to CCTK GH - @vtype const cGH * - @vio in - @vcomment + @calls IOBasic_WriteScalarGS + IOBasic_WriteScalarGA + + @var GH + @vdesc Pointer to CCTK GH + @vtype const cGH * + @vio in @endvar - @var fullname - @vdesc complete name of variable to output - @vtype const char * - @vio in - @vcomment + @var fullname + @vdesc complete name of variable to output + @vtype const char * + @vio in @endvar - @var alias - @vdesc alias name of variable to output (used to generate output filename) - @vtype const char * - @vio in - @vcomment + @var alias + @vdesc alias name of variable to output (used to generate output filename) + @vtype const char * + @vio in @endvar + + @returntype int + @returndesc + return code of @seeroutine IOBasic_WriteScalarGS or + @seeroutine IOBasic_WriteScalarGA + @endreturndesc @@*/ int IOBasic_ScalarOutputVarAs (const cGH *GH, const char *fullname, const char *alias) { - int vindex; + int vindex, retval; vindex = CCTK_VarIndex (fullname); @@ -144,14 +160,14 @@ int IOBasic_ScalarOutputVarAs (const cGH *GH, const char *fullname, const char * if (CCTK_GroupTypeFromVarI (vindex) == CCTK_SCALAR) { - IOBasic_WriteScalarGS (GH, vindex, alias); + retval = IOBasic_WriteScalarGS (GH, vindex, alias); } else { - IOBasic_WriteScalarGA (GH, vindex, alias); + retval = IOBasic_WriteScalarGA (GH, vindex, alias); } - return (0); + return (retval); } @@ -159,29 +175,26 @@ int IOBasic_ScalarOutputVarAs (const cGH *GH, const char *fullname, const char * @routine IOBasic_TimeForScalarOutput @date Sat March 6 1999 @author Gabrielle Allen - @desc - Decides if it is time to output a variable using Scalar output - method - @enddesc - @calls CCTK_GHExtension - CCTK_GroupTypeFromVar - CCTK_WARN - @calledby - @history - - @endhistory - @var GH - @vdesc Pointer to CCTK GH - @vtype const cGH * - @vio in - @vcomment - @endvar - @var vindex - @vdesc index of variable - @vtype int - @vio in - @vcomment - @endvar + @desc + Decides if it is time to do Scalar output. + @enddesc + + @var GH + @vdesc Pointer to CCTK GH + @vtype const cGH * + @vio in + @endvar + @var vindex + @vdesc index of variable + @vtype int + @vio in + @endvar + + @returntype int + @returndesc + 1 if output should take place at this iteration, or<BR> + 0 if not + @endreturndesc @@*/ int IOBasic_TimeForScalarOutput (const cGH *GH, int vindex) { @@ -232,26 +245,30 @@ int IOBasic_TimeForScalarOutput (const cGH *GH, int vindex) @date Sat March 6 1999 @author Gabrielle Allen @desc - Triggers the output a variable using IOBasic's Scalar + Triggers the output of a variable using IOBasic's Scalar output method - method @enddesc - @calledby CCTK scheduler + @var GH @vdesc Pointer to CCTK GH @vtype const cGH * @vio in - @vcomment @endvar @var vindex @vdesc index of variable to output @vtype int @vio in - @vcomment @endvar + + @returntype int + @returndesc + return code of @seeroutine IOBasic_WriteScalarGS or + @seeroutine IOBasic_WriteScalarGA + @endreturndesc @@*/ int IOBasic_TriggerScalarOutput (const cGH *GH, int vindex) { + int retval; const char *name; iobasicGH *myGH; @@ -266,21 +283,24 @@ int IOBasic_TriggerScalarOutput (const cGH *GH, int vindex) printf (" Index = %d\n", vindex); printf (" Variable = -%s-\n", name); #endif - + /* Do the Scalar output */ if (CCTK_GroupTypeFromVarI (vindex) == CCTK_SCALAR) { - IOBasic_WriteScalarGS (GH, vindex, name); + retval = IOBasic_WriteScalarGS (GH, vindex, name); } else { - IOBasic_WriteScalarGA (GH, vindex, name); + retval = IOBasic_WriteScalarGA (GH, vindex, name); + } + + if (retval == 0) + { + /* Register variable as having Scalar output this iteration */ + myGH->outScalar_last [vindex] = GH->cctk_iteration; } - /* Register variable as having Scalar output this iteration */ - myGH->outScalar_last [vindex] = GH->cctk_iteration; - - return (0); + return (retval); } @@ -288,11 +308,11 @@ int IOBasic_TriggerScalarOutput (const cGH *GH, int vindex) /* check if steerable parameters have changed */ static void CheckSteerableParameters (iobasicGH *myGH) { - DECLARE_CCTK_PARAMETERS int i, num_vars, out_old; int times_set; char *fullname, *msg; static int outScalar_vars_lastset = -1; + DECLARE_CCTK_PARAMETERS /* How often to output */ @@ -347,7 +367,7 @@ static void CheckSteerableParameters (iobasicGH *myGH) CCTK_INFO (msg); free (msg); } - } + } /* Save the last setting of 'outScalar_vars' parameter */ outScalar_vars_lastset = times_set; diff --git a/src/WriteInfo.c b/src/WriteInfo.c index 37a986d..27bc3ce 100644 --- a/src/WriteInfo.c +++ b/src/WriteInfo.c @@ -31,8 +31,30 @@ CCTK_FILEVERSION(CactusBase_IOBasic_WriteInfo_c) @calls CCTK_VarDataPtrI CCTK_Reduce + + @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 + 0 for success, or<BR> + -1 if variable has no storage assigned + @endreturndesc @@*/ -void IOBasic_WriteInfo (const cGH *GH, int vindex) +int IOBasic_WriteInfo (const cGH *GH, int vindex) { int vtype; char *fullname; @@ -67,7 +89,7 @@ void IOBasic_WriteInfo (const cGH *GH, int vindex) reduction->is_valid = 0; reduction = reduction->next; } - return; + return (-1); } /* CCTK scalars are printed by their value, cast into a C double */ @@ -175,4 +197,6 @@ void IOBasic_WriteInfo (const cGH *GH, int vindex) reduction = reduction->next; } } + + return (0); } diff --git a/src/WriteScalar.c b/src/WriteScalar.c index d857af4..d9dfb65 100644 --- a/src/WriteScalar.c +++ b/src/WriteScalar.c @@ -62,12 +62,15 @@ static FILE *OpenScalarFile (const cGH *GH, @vtype const char * @vio in @endvar + + @returntype int + @returndesc + 0 for success, or<BR> + -1 if variable has no storage assigned + @endreturndesc @@*/ -void IOBasic_WriteScalarGA (const cGH *GH, - int vindex, - const char *alias) +int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias) { - DECLARE_CCTK_PARAMETERS int ierr; int reduction_handle; iobasicGH *myGH; @@ -91,6 +94,7 @@ void IOBasic_WriteScalarGA (const cGH *GH, const cGH *const_ptr; cGH *non_const_ptr; } GH_fake_const; + DECLARE_CCTK_PARAMETERS /* this union helps us to avoid compiler warning about discarding @@ -106,7 +110,7 @@ void IOBasic_WriteScalarGA (const cGH *GH, "IOBasic_WriteScalarGA: No scalar output for '%s' (no storage)", fullname); free (fullname); - return; + return (-1); } /* set output format */ @@ -225,6 +229,8 @@ void IOBasic_WriteScalarGA (const cGH *GH, /* free allocated resources */ free (reduction_op); + + return (0); } @@ -258,8 +264,14 @@ void IOBasic_WriteScalarGA (const cGH *GH, @vtype const char * @vio in @endvar + + @returntype int + @returndesc + 0 for success, or<BR> + -1 if variable has no storage assigned + @endreturndesc @@*/ -void IOBasic_WriteScalarGS (const cGH *GH, int vindex, const char *alias) +int IOBasic_WriteScalarGS (const cGH *GH, int vindex, const char *alias) { DECLARE_CCTK_PARAMETERS FILE *file; @@ -273,7 +285,7 @@ void IOBasic_WriteScalarGS (const cGH *GH, int vindex, const char *alias) /* output is done by processor 0 only */ if (CCTK_MyProc (GH) != 0) { - return; + return (0); } /* first, check if variable has storage assigned */ @@ -284,7 +296,7 @@ void IOBasic_WriteScalarGS (const cGH *GH, int vindex, const char *alias) "IOBasic_WriteScalarGS: No scalar output for '%s' (no storage)", fullname); free (fullname); - return; + return (-1); } /* set the output format string for the desired notation */ @@ -343,6 +355,8 @@ void IOBasic_WriteScalarGS (const cGH *GH, int vindex, const char *alias) /* clean up */ free (filename); + + return (0); } diff --git a/src/iobasicGH.h b/src/iobasicGH.h index 059042a..c75b70e 100644 --- a/src/iobasicGH.h +++ b/src/iobasicGH.h @@ -62,6 +62,6 @@ int IOBasic_TimeForScalarOutput (const cGH *GH, int vindex); int IOBasic_ScalarOutputVarAs (const cGH *GH, const char *vname, const char *alias); /* other function prototypes */ -void IOBasic_WriteInfo (const cGH *GH, int vindex); -void IOBasic_WriteScalarGS (const cGH *GH, int vindex, const char *alias); -void IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias); +int IOBasic_WriteInfo (const cGH *GH, int vindex); +int IOBasic_WriteScalarGS (const cGH *GH, int vindex, const char *alias); +int IOBasic_WriteScalarGA (const cGH *GH, int vindex, const char *alias); |