summaryrefslogtreecommitdiff
path: root/src/main/SetParams.c
diff options
context:
space:
mode:
authortradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2002-01-02 12:24:42 +0000
committertradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac>2002-01-02 12:24:42 +0000
commita2a57e189b6f7af4b38f724733f095e753fedcde (patch)
tree077488fae9fbb66e7420dcf9f59e444308a4cc14 /src/main/SetParams.c
parent41af9e8cc55c4be04e72d4ea033115ecef047ea1 (diff)
The callback routine, CCTKi_SetParameter(), passed to the ParseFile() routine
now takes the current line number in the parameter file as a third argument. CCTKi_SetParameter() is now able to tell you what line in the parameter file was erroneous. This closes PR Cactus-838. git-svn-id: http://svn.cactuscode.org/flesh/trunk@2555 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/main/SetParams.c')
-rw-r--r--src/main/SetParams.c345
1 files changed, 136 insertions, 209 deletions
diff --git a/src/main/SetParams.c b/src/main/SetParams.c
index efd62020..47c336ba 100644
--- a/src/main/SetParams.c
+++ b/src/main/SetParams.c
@@ -2,55 +2,41 @@
@file SetParams.c
@date Tue Jan 12 19:16:38 1999
@author Tom Goodale
- @desc
-
- @enddesc
- @version $Header$
+ @desc
+ Callback functions for the parameter file parser.
+ @enddesc
+ @version $Id$
@@*/
#include <stdio.h>
#include <stdlib.h>
-/* FIXME - remove this when ActiveThorns doesn't need it */
-#include "SKBinTree.h"
-
-#include "cctk_Types.h"
-#include "cctki_ActiveThorns.h"
-#include "cctk_ActiveThorns.h"
-#include "cctk_WarnLevel.h"
#include "cctk_Misc.h"
#include "cctk_Flesh.h"
+#include "cctk_WarnLevel.h"
+#include "cctk_CommandLine.h"
#include "cctk_Parameter.h"
-
#include "cctki_Parameter.h"
+#include "cctk_ActiveThorns.h"
+#include "cctki_ActiveThorns.h"
-#include "ParameterBindings.h"
static const char *rcsid = "$Header$";
CCTK_FILEVERSION(main_SetParams_c)
/********************************************************************
- ********************* Local Data Types ***********************
- ********************************************************************/
-
-/********************************************************************
********************* Local Routine Prototypes *********************
********************************************************************/
+static int ReallySetParameter (const char *parameter, const char *value);
-static int ReallySetParameter(const char *parameter,
- const char *value);
-
-/********************************************************************
- ********************* Other Routine Prototypes *********************
- ********************************************************************/
/********************************************************************
********************* Local Data *****************************
********************************************************************/
+static int num_0errors = 0; /* number of level 0 errors in parameter file */
+static int num_1errors = 0; /* number of level 1 errors in parameter file */
-static int num_0errors=0; /* number of level 0 errors in parameter file */
-static int num_1errors=0; /* number of level 1 errors in parameter file */
/********************************************************************
********************* External Routines **********************
@@ -60,251 +46,193 @@ static int num_1errors=0; /* number of level 1 errors in parameter file */
@routine CCTKi_SetParameter
@date Tue Jan 12 19:25:37 1999
@author Tom Goodale
- @desc
-
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
- @var parameter
- @vdesc Name of a parameter
- @vtype const char *
- @vio in
- @vcomment
-
- @endvar
- @var value
- @vdesc Value of the parameter
- @vtype const char *
- @vio in
- @vcomment
-
- @endvar
+ @desc
+ Callback routine for @seeroutine ParseFile.<BR>
+ It sets a single parameter to a given value (treating the
+ "ActiveThorns" parameter as a special one).
+ In case of an error a warning is printed, and the internal
+ counter for the appropriate warning level is incremented.
+ @enddesc
+ @calls CCTKi_ActivateThorns
+ ReallySetParameter
+
+ @var parameter
+ @vdesc Name of a parameter
+ @vtype const char *
+ @vio in
+ @endvar
+ @var value
+ @vdesc Value of the parameter
+ @vtype const char *
+ @vio in
+ @endvar
+ @var lineno
+ @vdesc current line number in the parameter file
+ @vtype int
+ @vio in
+ @endvar
@returntype int
@returndesc
- 0 - success
- -1 - unknown parameter
- -? - other error
+ 0 for success, or return code of @seeroutine ReallySetParameter
@endreturndesc
@@*/
-int CCTKi_SetParameter(const char *parameter, const char *value)
+int CCTKi_SetParameter (const char *parameter, const char *value, int lineno)
{
- int retval;
-#if 0
- char thornname[101];
- const char *position;
- int length;
-#endif
- int n_errors;
- int parameter_check;
+ int retval, parameter_check;
+ char parfile[256];
- parameter_check = CCTK_ParameterLevel();
-
- retval = 0;
-
- if(CCTK_Equals(parameter, "ActiveThorns"))
- {
-#if 0
- n_errors = 0;
- position = value;
-
- while(*position)
- {
- length=0;
-
- for(;*position && *position != ' ';position++)
- {
- thornname[length] = *position;
- if(length < 100) length++;
- }
-
- if (length > 0)
- {
- thornname[length] = '\0';
- n_errors += CCTKi_ActivateThorn(thornname) != 0;
- }
- if(*position) position++;
-
- }
-#endif /*0*/
+ parameter_check = CCTK_ParameterLevel ();
+ CCTK_ParameterFilename (sizeof (parfile), parfile);
- n_errors = CCTKi_ActivateThorns(value);
-
- if(n_errors)
+ if (CCTK_Equals (parameter, "ActiveThorns"))
+ {
+ if (CCTKi_ActivateThorns (value))
{
- CCTK_Warn(0,__LINE__,__FILE__,"Cactus",
- "CCTKi_SetParameter: Errors while activating thorns\n");
+ CCTK_Warn (0, __LINE__, __FILE__, "Cactus",
+ "CCTKi_SetParameter: Errors while activating thorns\n");
}
+ retval = 0;
}
else
- {
- retval = ReallySetParameter(parameter, value);
+ {
+ retval = ReallySetParameter (parameter, value);
}
if (retval == -1)
{
- fprintf(stderr,"Range error setting parameter %s to %s\n",parameter,value);
+ CCTK_VWarn (1, __LINE__, __FILE__, "Cactus",
+ "In parameter file '%s' line %d: Range error setting parameter "
+ "'%s' to '%s'", parfile, lineno, parameter, value);
num_0errors++;
}
else if (retval == -2)
{
/* Parameter not defined in thorn */
- if (parameter_check==CCTK_PARAMETER_RELAXED)
+ CCTK_VWarn (1, __LINE__, __FILE__, "Cactus",
+ "In parameter file '%s' line %d:: Parameter '%s' not found",
+ parfile, lineno, parameter);
+ if (parameter_check == CCTK_PARAMETER_RELAXED)
{
- fprintf(stderr,"Parameter %s not found\n",parameter);
num_1errors++;
}
- else
+ else
{
- fprintf(stderr,"Parameter %s not found\n",parameter);
num_0errors++;
}
}
else if (retval == -4)
{
/* Setting parameter twice */
- if (parameter_check==CCTK_PARAMETER_RELAXED)
+ CCTK_VWarn (1, __LINE__, __FILE__, "Cactus",
+ "In parameter file '%s' line %d: Parameter '%s' set in two "
+ "different thorns", parfile, lineno, parameter);
+ if (parameter_check == CCTK_PARAMETER_RELAXED)
{
- fprintf(stderr,"Parameter %s set in two different thorns\n",parameter);
num_1errors++;
}
- else
+ else
{
- fprintf(stderr,"Parameter %s set in two different thorns\n",parameter);
num_0errors++;
}
}
else if (retval == -5)
{
/* Parameter not defined by any active thorn */
- if (parameter_check==CCTK_PARAMETER_STRICT)
+ CCTK_VWarn (1, __LINE__, __FILE__, "Cactus",
+ "In parameter file '%s' line %d: Parameter '%s' is not "
+ "associated with an active thorn", parfile, lineno, parameter);
+ if (parameter_check == CCTK_PARAMETER_STRICT)
{
- fprintf(stderr,"Parameter %s is not associated with an active thorn\n",
- parameter);
num_0errors++;
}
- else if (parameter_check==CCTK_PARAMETER_NORMAL)
+ else if (parameter_check == CCTK_PARAMETER_NORMAL)
{
- fprintf(stderr,"Parameter %s is not associated with an active thorn\n",
- parameter);
num_1errors++;
}
}
- /* if(retval)
- {
- if(retval == -1)
- {
- fprintf(stderr, "Unknown parameter %s\n", parameter);
- }
- else
- {
- fprintf(stderr, "Error setting parameter %s to %s\n", parameter, value);
- }
- }*/
-
- return retval;
+ return (retval);
}
+
/*@@
@routine CCTKi_NumParameterFileErrors
@date Mon Dec 3 2001
@author Gabrielle Allen
- @desc
- Returns the number of errors in the parameter file with a
- given level
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
- @var level
- @vdesc Level of errors to report
- @vtype int
- @vio in
- @vcomment
-
- @endvar
- @var value
- @vdesc Value of the parameter
- @vtype const char *
- @vio in
- @vcomment
-
- @endvar
+ @desc
+ Returns the number of errors in the parameter file with a
+ given level
+ @enddesc
+
+ @var level
+ @vdesc Level of errors to report
+ @vtype int
+ @vio in
+ @endvar
@returntype int
@returndesc
- number of errors in parameter file with this level
+ number of errors in parameter file with this level
@endreturndesc
@@*/
-
-int CCTKi_NumParameterFileErrors(int level)
+int CCTKi_NumParameterFileErrors (int level)
{
int retval;
- switch (level)
+
+ if (level == 0)
{
- case 0:
retval = num_0errors;
- break;
- case 1:
+ }
+ else if (level == 1)
+ {
retval = num_1errors;
- break;
- default:
+ }
+ else
+ {
retval = 0;
}
- return retval;
-
+ return (retval);
}
/********************************************************************
********************* Local Routines *************************
********************************************************************/
-
-
/*@@
@routine ReallySetParameter
@date Tue Jan 12 19:25:37 1999
@author Tom Goodale
- @desc
- Really sets the parameter value.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
- @var parameter
- @vdesc Name of a parameter
- @vtype const char *
- @vio in
- @vcomment
-
- @endvar
- @var value
- @vdesc Value of the parameter
- @vtype const char *
- @vio in
- @vcomment
-
- @endvar
+ @desc
+ Really sets the parameter value.
+ @enddesc
+ @calls CCTK_IsImplementationActive
+ CCTK_IsThornActive
+ CCTK_ActivatingThorn
+ CCTK_ParameterSet
+
+ @var parameter
+ @vdesc Name of a parameter
+ @vtype const char *
+ @vio in
+ @endvar
+ @var value
+ @vdesc Value of the parameter
+ @vtype const char *
+ @vio in
+ @endvar
@returntype int
@returndesc
- 0 = success
- -5 = thorn/imp not active
- -4 = tried to set parameter in two different thorns
- -3 = tried to steer nonsteerable parameter
- -2 = parameter not defined in the active thorn
- -1 = parameter out of range
+ 0 = success,<BR>
+ -5 = thorn/imp not active,<BR>
+ -4 = tried to set parameter in two different thorns,<BR>
+ -3 = tried to steer nonsteerable parameter,<BR>
+ -2 = parameter not defined in the active thorn,<BR>
+ -1 = parameter out of range
@endreturndesc
@@*/
static int ReallySetParameter(const char *parameter, const char *value)
@@ -314,70 +242,69 @@ static int ReallySetParameter(const char *parameter, const char *value)
int found = 0;
int retval_imp=0;
const char *thorn;
- char *param;
- char *imp;
+ char *param, *imp;
retval = 0;
- Util_SplitString(&imp, &param, parameter, "::");
+ Util_SplitString (&imp, &param, parameter, "::");
- if (!param)
+ if (! param)
{
/* must be global parameter */
- retval = CCTK_ParameterSet(parameter, imp, value);
+ retval = CCTK_ParameterSet (parameter, imp, value);
}
- else
+ else
{
/* try and set parameter from implementation */
- if (CCTK_IsImplementationActive(imp))
+ if (CCTK_IsImplementationActive (imp))
{
- thorn = CCTK_ActivatingThorn(imp);
+ thorn = CCTK_ActivatingThorn (imp);
/* only do it if the thorn name is different to the imp */
- if (!CCTK_Equals(thorn,imp))
+ if (! CCTK_Equals (thorn, imp))
{
- found++;
- retval_imp = CCTK_ParameterSet(param, thorn, value);
+ found++;
+ retval_imp = CCTK_ParameterSet (param, thorn, value);
}
}
/* try and set parameter from thorn */
- if (CCTK_IsThornActive(imp))
+ if (CCTK_IsThornActive (imp))
{
found++;
- retval_thorn = CCTK_ParameterSet(param, imp, value);
+ retval_thorn = CCTK_ParameterSet (param, imp, value);
}
- if (!found)
+ if (! found)
{
/* imp or thorn not found */
retval = -5;
}
- else if (found==2 && retval_imp>-1 && retval_thorn >-1)
+ else if (found == 2 && retval_imp >= 0 && retval_thorn >= 0)
{
/* tried to set parameter for both imp and thorn */
retval = -4;
}
- else if (found==2 && retval_imp<0 && retval_thorn <0)
+ else if (found == 2 && retval_imp < 0 && retval_thorn < 0)
{
/* failed to set parameter for both imp and thorn */
/* FIXME: returning imp but loosing thorn info*/
retval = retval_imp;
}
- else if (found==2)
+ else if (found == 2)
{
/* Only one succeeded */
- retval = (retval_imp>-1 ? retval_imp : retval_thorn);
+ retval = retval_imp >= 0 ? retval_imp : retval_thorn;
}
- else if (found==1)
+ else if (found == 1)
{
retval = retval_imp + retval_thorn;
}
}
/* Free any allocated memory. */
- free(imp);
- free(param);
+ free (imp);
+ free (param);
- return retval;
+ return (retval);
}