From f47de8d88998ed5b0fd4eb211dfa29745177852e Mon Sep 17 00:00:00 2001 From: tradke Date: Mon, 27 May 2002 08:27:23 +0000 Subject: Use key/value tables to parse option strings in the IOBasic::out*_vars parameter. The only allowed option is "reductions = 'reduction list'". Note that the syntax for specifying reductions for individual variables slightly changed (see the thorn documentation for details). git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOBasic/trunk@129 b589c3ab-70e8-4b4d-a09f-cba2dd200880 --- src/Startup.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/src/Startup.c b/src/Startup.c index ab26165..069c0aa 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -14,6 +14,7 @@ #include "cctk.h" #include "cctk_Parameters.h" +#include "util_Table.h" #include "CactusBase/IOUtil/src/ioutil_Utils.h" #include "iobasicGH.h" @@ -148,9 +149,7 @@ static void *IOBasic_SetupGH (tFleshConfig *config, int conv_level, cGH *GH) /* get the name of IOBasic's output directory */ if (*out_dir == 0) { - out_dir = *(const char **) - CCTK_ParameterGet ("out_dir", CCTK_ImplementationThorn ("IO"), - NULL); + out_dir = io_out_dir; } /* skip the directory pathname if output goes into current directory */ @@ -221,9 +220,11 @@ static void *IOBasic_SetupGH (tFleshConfig *config, int conv_level, cGH *GH) @@*/ void IOBasic_AssignReductionList (int vindex, const char *optstring, void *arg) { + int table, iterator, reduction_handle; + char key[128]; + CCTK_INT type, nelems; const char *string_start, *string_end; - char *reduction_op, *reduction_op_list; - int reduction_handle; + char *fullname, *reduction_op, *reduction_op_list; iobasic_reductionlist_t *list; iobasic_reduction_t **new_reduction; const iobasic_parseinfo_t *info; @@ -269,18 +270,56 @@ void IOBasic_AssignReductionList (int vindex, const char *optstring, void *arg) if (optstring) { - if (strncmp (optstring, "reductions=<", 12) == 0 && - optstring[strlen (optstring) - 1] == '>') + reduction_op_list = NULL; + fullname = CCTK_FullName (vindex); + + table = Util_TableCreateFromString (optstring); + if (table >= 0) { - reduction_op_list = strdup (optstring + 12); - reduction_op_list[strlen (reduction_op_list) - 1] = 0; + if (Util_TableQueryValueInfo (table, &type, &nelems, "reductions") > 0) + { + if (type == CCTK_VARIABLE_CHAR && nelems > 0) + { + reduction_op_list = malloc (nelems + 1); + Util_TableGetString (table, nelems + 1, reduction_op_list, + "reductions"); + } + else + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Key 'reductions' in option string '%s' for variable " + "'%s' must have a non-empty string value", + optstring, fullname); + } + Util_TableDeleteKey (table, "reductions"); + } + + /* warn about other options */ + iterator = Util_TableItCreate (table); + for (iterator = Util_TableItCreate (table); + Util_TableItQueryIsNonNull (iterator) > 0 && + Util_TableItQueryKeyValueInfo (iterator, sizeof(key), key, 0, 0) > 0; + Util_TableItAdvance (iterator)) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Option with key '%s' in option string '%s' for variable " + "'%s' not recognized", key, optstring, fullname); + } + Util_TableItDestroy (iterator); + + Util_TableDestroy (table); } else { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "IOBasic_AssignReductionList: invalid syntax for option list " - "'%s'", optstring); - return; + "Option string '%s' for variable '%s' couldn't be parsed", + optstring, fullname); + } + free (fullname); + + if (! reduction_op_list) + { + reduction_op_list = strdup (info->reductions_string); } } else -- cgit v1.2.3