From d886ba692ec67c560e71405e82db986f33617c27 Mon Sep 17 00:00:00 2001 From: tradke Date: Wed, 9 Jun 2004 10:42:22 +0000 Subject: After setup, do an initial I/O parameter parsing and warn/stop on parsing errors (depending on IO::strict_io_parameter_check). You will also need to update CactusBase/IOUtil. git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOBasic/trunk@156 b589c3ab-70e8-4b4d-a09f-cba2dd200880 --- src/OutputInfo.c | 34 ++++++------ src/OutputScalar.c | 152 ++++++++++++++++++++++++++--------------------------- src/Startup.c | 144 ++++++++++++++++++++++++++------------------------ src/iobasicGH.h | 5 ++ 4 files changed, 173 insertions(+), 162 deletions(-) diff --git a/src/OutputInfo.c b/src/OutputInfo.c index c704ac2..252dd48 100644 --- a/src/OutputInfo.c +++ b/src/OutputInfo.c @@ -57,7 +57,6 @@ CCTK_FILEVERSION(CactusBase_IOBasic_OutputInfo_c) /******************************************************************** ******************** Internal Routines ************************ ********************************************************************/ -static void CheckSteerableParameters (iobasicGH *myGH); static void PrintHeader (iobasicGH *myGH, int num_vars); static int TimeForOutput (const cGH *cctkGH); @@ -72,7 +71,7 @@ static int TimeForOutput (const cGH *cctkGH) myGH = CCTK_GHExtension (cctkGH, "IOBasic"); /* check if steerable parameters changed */ - CheckSteerableParameters (myGH); + IOBasic_CheckSteerableInfoParameters (myGH); /* how to decide when to output? */ /* (return if no output is required) */ @@ -130,7 +129,7 @@ static int TimeForOutput (const cGH *cctkGH) @desc Loops over all variables and prints output if requested @enddesc - @calls CheckSteerableParameters + @calls IOBasic_CheckSteerableInfoParameters PrintHeader IOBasic_WriteInfo @@ -157,7 +156,7 @@ int IOBasic_InfoOutputGH (const cGH *GH) myGH = CCTK_GHExtension (GH, "IOBasic"); /* check if steerable parameters changed */ - CheckSteerableParameters (myGH); + IOBasic_CheckSteerableInfoParameters (myGH); if (! TimeForOutput(GH)) return 0; @@ -232,7 +231,7 @@ int IOBasic_InfoOutputGH (const cGH *GH) @desc Decides if it is time to output a variable using info output @enddesc - @calls CheckSteerableParameters + @calls IOBasic_CheckSteerableInfoParameters @var GH @vdesc Pointer to CCTK GH @@ -260,7 +259,7 @@ int IOBasic_TimeForInfoOutput (const cGH *GH, int vindex) myGH = CCTK_GHExtension (GH, "IOBasic"); /* check if steerable parameters changed */ - CheckSteerableParameters (myGH); + IOBasic_CheckSteerableInfoParameters (myGH); if (myGH->info_reductions[vindex].num_reductions == 0) { @@ -337,11 +336,8 @@ int IOBasic_TriggerInfoOutput (const cGH *GH, int vindex) } -/******************************************************************** - ******************** Internal Routines ************************ - ********************************************************************/ /*@@ - @routine CheckSteerableParameters + @routine IOBasic_CheckSteerableInfoParameters @date Tue 31 Jul 2001 @author Thomas Radke @desc @@ -359,7 +355,7 @@ int IOBasic_TriggerInfoOutput (const cGH *GH, int vindex) @vio in @endvar @@*/ -static void CheckSteerableParameters (iobasicGH *myGH) +void IOBasic_CheckSteerableInfoParameters (iobasicGH *myGH) { int vindex, out_old, times_set, update_reductions_list; CCTK_REAL outdt_old; @@ -385,12 +381,12 @@ static void CheckSteerableParameters (iobasicGH *myGH) { if (myGH->outInfo_every > 0) { - CCTK_VInfo (CCTK_THORNSTRING, "Info: Periodic output every %d iterations", + CCTK_VInfo (CCTK_THORNSTRING, "Periodic info output every %d iterations", myGH->outInfo_every); } else { - CCTK_INFO ("Info: Periodic output turned off"); + CCTK_INFO ("Periodic info output turned off"); } } @@ -411,12 +407,12 @@ static void CheckSteerableParameters (iobasicGH *myGH) { if (myGH->outInfo_dt >= 0) { - CCTK_VInfo (CCTK_THORNSTRING, "Info: Periodic output dt %g", + CCTK_VInfo (CCTK_THORNSTRING, "Periodic info output dt %g", (double)myGH->outInfo_dt); } else { - CCTK_INFO ("Info: Periodic output turned off"); + CCTK_INFO ("Periodic info output turned off"); } } @@ -467,7 +463,8 @@ static void CheckSteerableParameters (iobasicGH *myGH) if (CCTK_TraverseString (outInfo_vars, IOBasic_AssignReductionList, &info, CCTK_GROUP_OR_VAR) < 0) { - CCTK_WARN (1, "Failed to parse 'IOBasic::outInfo_vars' parameter"); + CCTK_WARN (myGH->stop_on_parse_errors ? 0 : 1, + "error while parsing parameter 'IOBasic::outInfo_vars'"); } myGH->info_reductions_changed = 1; @@ -475,6 +472,9 @@ static void CheckSteerableParameters (iobasicGH *myGH) } +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ /*@@ @routine PrintHeader @date Tue 31 Jul 2001 @@ -517,7 +517,7 @@ static void PrintHeader (iobasicGH *myGH, int num_vars) fullname = CCTK_FullName (vindex); if (! msg) { - Util_asprintf (&msg, "Info: Periodic output requested for '%s'", + Util_asprintf (&msg, "Periodic info output requested for '%s'", fullname); } else diff --git a/src/OutputScalar.c b/src/OutputScalar.c index e83a065..243ebb2 100644 --- a/src/OutputScalar.c +++ b/src/OutputScalar.c @@ -33,72 +33,9 @@ CCTK_FILEVERSION(CactusBase_IOBasic_OutputScalar_c) /******************************************************************** ******************** Internal Routines ************************ ********************************************************************/ -static void CheckSteerableParameters (iobasicGH *myGH); static int TimeForOutput (const cGH *cctkGH); -static int TimeForOutput (const cGH *cctkGH) -{ - DECLARE_CCTK_ARGUMENTS; - DECLARE_CCTK_PARAMETERS; - iobasicGH *myGH; - - - /* get the GH extensions for IOBasic */ - myGH = CCTK_GHExtension (cctkGH, "IOBasic"); - - /* check if steerable parameters changed */ - CheckSteerableParameters (myGH); - - /* how to decide when to output? */ - /* (return if no output is required) */ - if (CCTK_EQUALS(outScalar_criterion, "never")) - { - return 0; - } - else if (CCTK_EQUALS(outScalar_criterion, "iteration")) - { - if (myGH->outScalar_every <= 0 || cctk_iteration % myGH->outScalar_every) - { - return 0; - } - } - else if (CCTK_EQUALS(outScalar_criterion, "time")) - { - if (myGH->outScalar_dt < 0) - { - return 0; - } - if (myGH->outScalar_dt > 0) - { - static int output_iteration = -1; - static int output_this_iteration; - assert (cctk_iteration >= output_iteration); - if (cctk_iteration > output_iteration) - { - output_iteration = cctk_iteration; - output_this_iteration - = cctk_time >= *next_scalar_output_time - 1.0e-12 * cctk_delta_time; - if (output_this_iteration) - { - *next_scalar_output_time += myGH->outScalar_dt; - } - } - if (! output_this_iteration) - { - return 0; - } - } - } - else - { - assert (0); - } - - return 1; -} - - /******************************************************************** ******************** External Routines ************************ ********************************************************************/ @@ -134,7 +71,7 @@ int IOBasic_ScalarOutputGH (const cGH *GH) myGH = CCTK_GHExtension (GH, "IOBasic"); /* check if steerable parameters changed */ - CheckSteerableParameters (myGH); + IOBasic_CheckSteerableScalarParameters (myGH); if (! TimeForOutput(GH)) return 0; @@ -290,7 +227,7 @@ int IOBasic_TimeForScalarOutput (const cGH *GH, int vindex) myGH = CCTK_GHExtension (GH, "IOBasic"); /* check if steerable parameters changed */ - CheckSteerableParameters (myGH); + IOBasic_CheckSteerableScalarParameters (myGH); if (myGH->scalar_reductions[vindex].num_reductions == 0) { @@ -372,11 +309,8 @@ int IOBasic_TriggerScalarOutput (const cGH *GH, int vindex) } -/******************************************************************** - ******************** Internal Routines ************************ - ********************************************************************/ /*@@ - @routine CheckSteerableParameters + @routine IOBasic_CheckSteerableScalarParameters @date Tue 31 Jul 2001 @author Thomas Radke @desc @@ -393,7 +327,7 @@ int IOBasic_TriggerScalarOutput (const cGH *GH, int vindex) @vio in @endvar @@*/ -static void CheckSteerableParameters (iobasicGH *myGH) +void IOBasic_CheckSteerableScalarParameters (iobasicGH *myGH) { int vindex, out_old, times_set, update_reductions_list, num_vars; CCTK_REAL outdt_old; @@ -420,12 +354,12 @@ static void CheckSteerableParameters (iobasicGH *myGH) { if (myGH->outScalar_every > 0) { - CCTK_VInfo (CCTK_THORNSTRING, "Scalar: Periodic output every %d iterations", + CCTK_VInfo (CCTK_THORNSTRING, "Periodic scalar output every %d iterations", myGH->outScalar_every); } else { - CCTK_INFO ("Scalar: Periodic output turned off"); + CCTK_INFO ("Periodic scalar output turned off"); } } @@ -446,12 +380,12 @@ static void CheckSteerableParameters (iobasicGH *myGH) { if (myGH->outScalar_dt >= 0) { - CCTK_VInfo (CCTK_THORNSTRING, "Scalar: Periodic output dt %g", + CCTK_VInfo (CCTK_THORNSTRING, "Periodic scalar output dt %g", (double)myGH->outScalar_dt); } else { - CCTK_INFO ("Scalar: Periodic output turned off"); + CCTK_INFO ("Periodic scalar output turned off"); } } @@ -503,7 +437,8 @@ static void CheckSteerableParameters (iobasicGH *myGH) if (CCTK_TraverseString (outScalar_vars, IOBasic_AssignReductionList, &info, CCTK_GROUP_OR_VAR) < 0) { - CCTK_WARN (1, "Failed to parse 'IOBasic::outScalar_vars' parameter"); + CCTK_WARN (myGH->stop_on_parse_errors ? 0 : 1, + "error while parsing parameter 'IOBasic::outScalar_vars'"); } else if (! CCTK_Equals (verbose, "none")) { @@ -515,7 +450,7 @@ static void CheckSteerableParameters (iobasicGH *myGH) fullname = CCTK_FullName (vindex); if (! msg) { - Util_asprintf (&msg, "Scalar: Periodic output requested for '%s'", + Util_asprintf (&msg, "Periodic scalar output requested for '%s'", fullname); } else @@ -535,3 +470,68 @@ static void CheckSteerableParameters (iobasicGH *myGH) } } } + + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static int TimeForOutput (const cGH *cctkGH) +{ + DECLARE_CCTK_ARGUMENTS; + DECLARE_CCTK_PARAMETERS; + iobasicGH *myGH; + + + /* get the GH extensions for IOBasic */ + myGH = CCTK_GHExtension (cctkGH, "IOBasic"); + + /* check if steerable parameters changed */ + IOBasic_CheckSteerableScalarParameters (myGH); + + /* how to decide when to output? */ + /* (return if no output is required) */ + if (CCTK_EQUALS(outScalar_criterion, "never")) + { + return 0; + } + else if (CCTK_EQUALS(outScalar_criterion, "iteration")) + { + if (myGH->outScalar_every <= 0 || cctk_iteration % myGH->outScalar_every) + { + return 0; + } + } + else if (CCTK_EQUALS(outScalar_criterion, "time")) + { + if (myGH->outScalar_dt < 0) + { + return 0; + } + if (myGH->outScalar_dt > 0) + { + static int output_iteration = -1; + static int output_this_iteration; + assert (cctk_iteration >= output_iteration); + if (cctk_iteration > output_iteration) + { + output_iteration = cctk_iteration; + output_this_iteration + = cctk_time >= *next_scalar_output_time - 1.0e-12 * cctk_delta_time; + if (output_this_iteration) + { + *next_scalar_output_time += myGH->outScalar_dt; + } + } + if (! output_this_iteration) + { + return 0; + } + } + } + else + { + assert (0); + } + + return 1; +} diff --git a/src/Startup.c b/src/Startup.c index 7101634..3ac52ea 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -123,7 +123,6 @@ static void *IOBasic_SetupGH (tFleshConfig *config, int conv_level, cGH *GH) int i; iobasicGH *myGH; const char *my_out_dir; - char dirname[1000]; DECLARE_CCTK_PARAMETERS @@ -134,85 +133,92 @@ static void *IOBasic_SetupGH (tFleshConfig *config, int conv_level, cGH *GH) /* allocate the GH extension and its components */ myGH = malloc (sizeof (iobasicGH)); - if (myGH) + if (! myGH) { - /* Register the IOBasic routines as output methods */ - i = CCTK_RegisterIOMethod ("Scalar"); - CCTK_RegisterIOMethodOutputGH (i, IOBasic_ScalarOutputGH); - CCTK_RegisterIOMethodOutputVarAs (i, IOBasic_OutputVarAs); - CCTK_RegisterIOMethodTimeToOutput (i, IOBasic_TimeForScalarOutput); - CCTK_RegisterIOMethodTriggerOutput (i, IOBasic_TriggerScalarOutput); - - i = CCTK_RegisterIOMethod ("Info"); - CCTK_RegisterIOMethodOutputGH (i, IOBasic_InfoOutputGH); - CCTK_RegisterIOMethodTimeToOutput (i, IOBasic_TimeForInfoOutput); - CCTK_RegisterIOMethodTriggerOutput (i, IOBasic_TriggerInfoOutput); - - if (! CCTK_Equals (verbose, "none")) - { - CCTK_INFO ("I/O Method 'Scalar' registered"); - CCTK_INFO ("Scalar: Output of scalar quantities (grid scalars, " - "reductions) to ASCII files"); - CCTK_INFO ("I/O Method 'Info' registered"); - CCTK_INFO ("Info: Output of scalar quantities (grid scalars, " - "reductions) to screen"); - } + return (NULL); + } - i = CCTK_NumVars (); + /* Register the IOBasic routines as output methods */ + i = CCTK_RegisterIOMethod ("Scalar"); + CCTK_RegisterIOMethodOutputGH (i, IOBasic_ScalarOutputGH); + CCTK_RegisterIOMethodOutputVarAs (i, IOBasic_OutputVarAs); + CCTK_RegisterIOMethodTimeToOutput (i, IOBasic_TimeForScalarOutput); + CCTK_RegisterIOMethodTriggerOutput (i, IOBasic_TriggerScalarOutput); - myGH->info_reductions = calloc (2 * i, sizeof (iobasic_reductionlist_t)); - myGH->scalar_reductions = myGH->info_reductions + i; - myGH->outInfo_last = malloc (2 * i * sizeof (int)); - myGH->outScalar_last = myGH->outInfo_last + i; + i = CCTK_RegisterIOMethod ("Info"); + CCTK_RegisterIOMethodOutputGH (i, IOBasic_InfoOutputGH); + CCTK_RegisterIOMethodTimeToOutput (i, IOBasic_TimeForInfoOutput); + CCTK_RegisterIOMethodTriggerOutput (i, IOBasic_TriggerInfoOutput); - /* initialize counters for how often to do output with a value different - to the current parameter values - this forces info output about periodic output */ - myGH->outInfo_every = outInfo_every >= 0 ? outInfo_every : out_every; - myGH->outScalar_every = outScalar_every >= 0 ? outScalar_every : out_every; - myGH->outInfo_dt = outInfo_dt >= 0 ? outInfo_dt : out_dt; - myGH->outScalar_dt = outScalar_dt >= 0 ? outScalar_dt : out_dt; + i = CCTK_NumVars (); - memset (myGH->outInfo_last, -1, 2 * i * sizeof (int)); + myGH->info_reductions = calloc (2 * i, sizeof (iobasic_reductionlist_t)); + myGH->scalar_reductions = myGH->info_reductions + i; + myGH->outInfo_last = malloc (2 * i * sizeof (int)); + myGH->outScalar_last = myGH->outInfo_last + i; - myGH->filenameListScalar = NULL; + /* initialize counters for how often to do output with a value different + to the current parameter values + this forces info output about periodic output */ + myGH->outInfo_every = outInfo_every >= 0 ? outInfo_every : out_every; + myGH->outScalar_every = outScalar_every >= 0 ? outScalar_every : out_every; + myGH->outInfo_dt = outInfo_dt >= 0 ? outInfo_dt : out_dt; + myGH->outScalar_dt = outScalar_dt >= 0 ? outScalar_dt : out_dt; - /* get the name of IOBasic's output directory */ - my_out_dir = out_dir; - if (*my_out_dir == 0) - { - my_out_dir = io_out_dir; - } + memset (myGH->outInfo_last, -1, 2 * i * sizeof (int)); - /* skip the directory pathname if output goes into current directory */ - if (strcmp (my_out_dir, ".")) - { - i = strlen (my_out_dir); - myGH->out_dir = malloc (i + 2); - strcpy (myGH->out_dir, my_out_dir); - myGH->out_dir[i] = '/'; - myGH->out_dir[i+1] = 0; - } - else + myGH->filenameListScalar = NULL; + + myGH->stop_on_parse_errors = strict_io_parameter_check; + if (! CCTK_Equals (verbose, "none")) + { + CCTK_INFO ("I/O Method 'Scalar' registered: output of scalar quantities " + "(grid scalars, reductions) to ASCII files"); + } + IOBasic_CheckSteerableInfoParameters (myGH); + if (! CCTK_Equals (verbose, "none")) + { + CCTK_INFO ("I/O Method 'Info' registered: output of scalar quantities " + "(grid scalars, reductions) to screen"); + } + IOBasic_CheckSteerableInfoParameters (myGH); + myGH->stop_on_parse_errors = 0; + + /* get the name of IOBasic's output directory */ + my_out_dir = out_dir; + if (*my_out_dir == 0) + { + my_out_dir = io_out_dir; + } + + /* skip the directory pathname if output goes into current directory */ + if (strcmp (my_out_dir, ".")) + { + i = strlen (my_out_dir); + myGH->out_dir = malloc (i + 2); + strcpy (myGH->out_dir, my_out_dir); + myGH->out_dir[i] = '/'; + myGH->out_dir[i+1] = 0; + } + else + { + myGH->out_dir = strdup (""); + } + + /* create the output dir */ + if (*myGH->out_dir && CCTK_MyProc (GH) == 0) + { + i = IOUtil_CreateDirectory (GH, myGH->out_dir, 0, 0); + if (i < 0) { - myGH->out_dir = strdup (""); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOBasic_SetupGH: Couldn't create Scalar output directory " + "'%s'", myGH->out_dir); } - - /* create the output dir */ - if (*myGH->out_dir && CCTK_MyProc (GH) == 0) + else if (i >= 0 && CCTK_Equals (verbose, "full")) { - i = IOUtil_CreateDirectory (GH, myGH->out_dir, 0, 0); - if (i < 0) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "IOBasic_SetupGH: Couldn't create Scalar output directory " - "'%s'", myGH->out_dir); - } - else if (i >= 0 && CCTK_Equals (verbose, "full")) - { - CCTK_VInfo (CCTK_THORNSTRING, "Scalar: Output to directory '%s'", - myGH->out_dir); - } + CCTK_VInfo (CCTK_THORNSTRING, "Scalar: Output to directory '%s'", + myGH->out_dir); } } diff --git a/src/iobasicGH.h b/src/iobasicGH.h index 5c3cb99..a5b464a 100644 --- a/src/iobasicGH.h +++ b/src/iobasicGH.h @@ -54,6 +54,9 @@ typedef struct IOBASIC_GH /* database for names of output files that were already created */ pNamedData *filenameListScalar; + /* stop on I/O parameter parsing errors ? */ + int stop_on_parse_errors; + } iobasicGH; @@ -70,5 +73,7 @@ int IOBasic_TimeForScalarOutput (const cGH *GH, int vindex); void IOBasic_AssignReductionList (int vindex, const char *optstring, void *arg); int IOBasic_WriteInfo (const cGH *GH, int vindex); int IOBasic_WriteScalar (const cGH *GH, int vindex, const char *alias); +void IOBasic_CheckSteerableInfoParameters (iobasicGH *myGH); +void IOBasic_CheckSteerableScalarParameters (iobasicGH *myGH); #endif /* _IOBASIC_IOBASICGH_H_ */ -- cgit v1.2.3