diff options
author | goodale <goodale@1faa4e14-9dd3-4be0-9f0e-ffe519881164> | 2000-09-20 09:11:47 +0000 |
---|---|---|
committer | goodale <goodale@1faa4e14-9dd3-4be0-9f0e-ffe519881164> | 2000-09-20 09:11:47 +0000 |
commit | 6b1dd294583ff99e3c8a160e9c3c10ca0751b566 (patch) | |
tree | 6f05c46c113a842e8466482394cf1fc369d23c3e /src | |
parent | 8c06471068be650adc06b3bbaa7a8e2bab6d2002 (diff) |
Added parameters and control logic for run until iteration or simulation time
or expression.
Added parameter and logic for single stepping.
Tom
git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPD/trunk@57 1faa4e14-9dd3-4be0-9f0e-ffe519881164
Diffstat (limited to 'src')
-rw-r--r-- | src/Server.c | 234 |
1 files changed, 232 insertions, 2 deletions
diff --git a/src/Server.c b/src/Server.c index d3d865d..6c1da0b 100644 --- a/src/Server.c +++ b/src/Server.c @@ -12,10 +12,19 @@ #include <stdlib.h> #include "cctk.h" + +#include "cctk_Constants.h" +#include "cctk_Groups.h" +#include "cctk_GroupsOnGH.h" +#include "cctk_Parameter.h" + #include "util_Hash.h" +#include "util_String.h" #include "httpd.h" +#include "http_Expression.h" + static char *rcsid = "$Header$"; CCTK_FILEVERSION(DevThorns_httpd_Server_c) @@ -37,6 +46,13 @@ typedef struct static httpPage *CreatePageData(int (*function)(cGH *,httpRequest *, void *), void *data); static httpPage *FindPage(char *path, char **residual); +static int StatusUntilIt(cGH *cctkGH); +static int StatusUntilTime(cGH *cctkGH); +static int StatusUntilExpression(cGH *cctkGH); + +static double evaluator(const char *name, void *data); + + /******************************************************************** ********************* Other Routine Prototypes ********************* ********************************************************************/ @@ -207,13 +223,49 @@ int HTTP_UpdateState(cGH *cctkGH, httpState *state) { int type; CCTK_INT *value; + int pause_selected; + int until_it_selected; + int until_time_selected; + int until_expression_selected; + int stepping; static int steering = 1; static int last_steered = -1; + value = (CCTK_INT *)CCTK_ParameterGet("single_step",CCTK_THORNSTRING, &type); + + stepping = *value; + value = (CCTK_INT *)CCTK_ParameterGet("pause",CCTK_THORNSTRING, &type); - state->paused = *value; + pause_selected = *value; + + value = (CCTK_INT *)CCTK_ParameterGet("until_it_active",CCTK_THORNSTRING, &type); + + until_it_selected = *value; + + value = (CCTK_INT *)CCTK_ParameterGet("until_time_active",CCTK_THORNSTRING, &type); + + until_time_selected = *value; + + value = (CCTK_INT *)CCTK_ParameterGet("until_expression_active",CCTK_THORNSTRING, &type); + + until_expression_selected = *value; + + state->paused = (! stepping) && + (pause_selected || (cctkGH && + ((until_it_selected && StatusUntilIt(cctkGH)) || + (until_time_selected && StatusUntilTime(cctkGH)) || + (until_expression_selected && StatusUntilExpression(cctkGH))))); + + /* If single step is selected, need to reset the parameter to force a pause + * next time. + */ + if(stepping) + { + HTTP_SteerQueue(CCTK_THORNSTRING, "single_step", "no"); + } + if(cctkGH && ! state->paused) { @@ -246,7 +298,6 @@ int HTTP_UpdateState(cGH *cctkGH, httpState *state) } - value = (CCTK_INT *)CCTK_ParameterGet("terminate",CCTK_THORNSTRING, &type); state->terminate = *value; @@ -411,3 +462,182 @@ static httpPage *FindPage(char *path, char **residual) return pagedata; } + + /*@@ + @routine StatusUntilIt + @date Tue Sep 19 22:59:34 2000 + @author Tom Goodale + @desc + Is the iteration greater than the desired stop value ? + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +static int StatusUntilIt(cGH *cctkGH) +{ + int retval; + CCTK_INT *value; + int type; + + value = (CCTK_INT *)CCTK_ParameterGet("until_it",CCTK_THORNSTRING, &type); + + if(cctkGH && *value <= cctkGH->cctk_iteration) + { + retval = 1; + } + else + { + retval = 0; + } + + return retval; +} + + /*@@ + @routine StatusUntilTime + @date Tue Sep 19 23:00:16 2000 + @author Tom Goodale + @desc + Is the simulation time greater than the stop value ? + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +static int StatusUntilTime(cGH *cctkGH) +{ + int retval; + CCTK_REAL *value; + int type; + + value = (CCTK_REAL *)CCTK_ParameterGet("until_time",CCTK_THORNSTRING, &type); + + if(cctkGH && *value <= cctkGH->cctk_time) + { + retval = 1; + } + else + { + retval = 0; + } + + return retval; +} + + /*@@ + @routine StatusUntilExpression + @date Tue Sep 19 23:00:47 2000 + @author Tom Goodale + @desc + Is the stop expression true ? + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +static int StatusUntilExpression(cGH *cctkGH) +{ + static char *parsed_expression = NULL; + static int times_set = -1; + + int new_times_set; + int retval; + + const char *value; + int type; + char *copy; + + /* See if we need to parse the expression again. */ + new_times_set = CCTK_ParameterQueryTimesSet("until_expression", + CCTK_THORNSTRING); + + if(new_times_set > times_set) + { + times_set = new_times_set; + value = (const char *)CCTK_ParameterGet("until_expression",CCTK_THORNSTRING, &type); + + if(parsed_expression) + { + free(parsed_expression); + + parsed_expression = HTTP_ExpressionParse(value); + } + } + + /* Make a copy */ + copy = Util_Strdup(parsed_expression); + + if(cctkGH) + { + /* Evaluate the expression */ + retval = HTTP_ExpressionEvaluate(copy, evaluator, (void *)cctkGH); + } + else + { + retval = 0; + } + /* Free the copy */ + free(copy); + + return retval; +} + + + /*@@ + @routine evaluator + @date Tue Sep 19 23:07:20 2000 + @author Tom Goodale + @desc + Takes the name of a gridscalar and returns its value. + @enddesc + @calls + @calledby + @history + + @endhistory + +@@*/ +static double evaluator(const char *expression, void *data) +{ + double retval; + cGH *cctkGH; + void *pointer; + int varindex; + int vartype; + + cctkGH = (cGH *)data; + + + varindex = CCTK_VarIndex(expression); + vartype = CCTK_VarTypeI(varindex); + + pointer = CCTK_VarDataPtrI(cctkGH, 0, varindex); + + switch(vartype) + { + case CCTK_VARIABLE_CHAR : + retval = *((CCTK_CHAR *)pointer); + break; + case CCTK_VARIABLE_INT : + retval = *((CCTK_INT *)pointer); + break; + case CCTK_VARIABLE_REAL : + retval = *((CCTK_REAL *)pointer); + break; + default : + fprintf(stderr, "Unsupported variable type %d\n", vartype); + retval = 0; + } + + return retval; +} |