diff options
author | tradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a> | 2002-05-28 14:46:11 +0000 |
---|---|---|
committer | tradke <tradke@b32723a9-ab3a-4a60-88e2-2e5d99d7c17a> | 2002-05-28 14:46:11 +0000 |
commit | d9f60a2c43dab43f72b875fa493b00c9df08ccde (patch) | |
tree | e1c968a20cc80effa3b475d753d66ac4f5d0d4f7 /src/Utils.c | |
parent | fbfc1ccc144857418421096a267f9c1e7fac460c (diff) |
Added routine IOUtil_ParseOutputFrequency() and slightly changed the API
for the existing routine IOUtil_ParseVarsForOutput().
Both routines use the table API to parse option strings for the 'out_every'
option and for hyperslab options.
See the thornguide eg. for IOHDF5 for details.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusBase/IOUtil/trunk@166 b32723a9-ab3a-4a60-88e2-2e5d99d7c17a
Diffstat (limited to 'src/Utils.c')
-rw-r--r-- | src/Utils.c | 425 |
1 files changed, 248 insertions, 177 deletions
diff --git a/src/Utils.c b/src/Utils.c index 62f0395..d1b487d 100644 --- a/src/Utils.c +++ b/src/Utils.c @@ -15,8 +15,8 @@ #include "cctk.h" #include "cctk_Parameters.h" -#include "cctk_GNU.h" #include "util_String.h" +#include "util_Table.h" #include "ioGH.h" #include "ioutil_Utils.h" #include "ioutil_CheckpointRecovery.h" @@ -40,6 +40,9 @@ typedef struct { const cGH *GH; ioRequest **request_list; + const char *method_name; + const char *parameter_name; + int out_every_default; } info_t; @@ -49,13 +52,6 @@ typedef struct static void SetOutputVar (int vindex, const char *optstring, void *arg); -/******************************************************************** - ******************** External Routines ************************ - ********************************************************************/ -int CCTK_RegexMatch (const char *string, const char *pattern, const int nmatch, - regmatch_t *pmatch); - - /*@@ @routine IOUtil_ParseVarsForOutput @date Fri 26 April 2002 @@ -73,18 +69,35 @@ int CCTK_RegexMatch (const char *string, const char *pattern, const int nmatch, @vtype const cGH * @vio in @endvar + @var method_name + @vdesc name of the originating I/O method + @vtype const char * + @vio in + @endvar + @var parameter_name + @vdesc name of the originating I/O parameter to parse + @vtype const char * + @vio in + @endvar @var out_vars @vdesc string with list of variables and/or group names to parse @vtype const char * @vio in @endvar + @var out_every_default + @vdesc default output frequency to set the I/O request to + @vtype int + @vio in + @endvar @var request_list @vdesc list of I/O requests to fill out @vtype ioRequest *[] @vio out @endvar @@*/ -void IOUtil_ParseVarsForOutput (const cGH *GH, const char *out_vars, +void IOUtil_ParseVarsForOutput (const cGH *GH, const char *method_name, + const char *parameter_name, + const char *out_vars, int out_every_default, ioRequest *request_list[]) { int i; @@ -103,6 +116,9 @@ void IOUtil_ParseVarsForOutput (const cGH *GH, const char *out_vars, /* generate new list of I/O requests */ info.GH = GH; info.request_list = request_list; + info.method_name = method_name; + info.parameter_name = parameter_name; + info.out_every_default = out_every_default; CCTK_TraverseString (out_vars, SetOutputVar, &info, CCTK_GROUP_OR_VAR); } @@ -129,6 +145,109 @@ void IOUtil_FreeIORequest (ioRequest **request) } + /*@@ + @routine IOUtil_ParseOutputFrequency + @date Mon 27 May 2002 + @author Thomas Radke + @desc + Parses the option string for a given variable for the + 'out_every' option and sets its output frequency. + @enddesc + + @calls Util_TableCreateFromString + + @var method_name + @vdesc name of the originating I/O method + @vtype const char * + @vio in + @endvar + @var parameter_name + @vdesc name of the originating I/O parameter to parse + @vtype const char * + @vio in + @endvar + @var index + @vdesc index of the variable to set the output frequency + @vtype int + @vio in + @endvar + @var optstring + @vdesc option string to parse + @vtype const char * + @vio in + @endvar + @var out_every + @vdesc pointer to the variable's output frequency flag + @vtype int * + @vio out + @endvar +@@*/ +void IOUtil_ParseOutputFrequency (const char *method_name, + const char *parameter_name, + int vindex, const char *optstring, + CCTK_INT *out_every) +{ + int table, iterator; + char key[128]; + char *fullname; + CCTK_INT type, nelems; + + + fullname = CCTK_FullName (vindex); + table = Util_TableCreateFromString (optstring); + if (table >= 0) + { + if (Util_TableQueryValueInfo (table, &type, &nelems, "out_every") > 0) + { + if (type == CCTK_VARIABLE_INT && nelems == 1) + { + Util_TableGetInt (table, out_every, "out_every"); + } + else + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid value for option 'out_every' in option string " + "'%s' in parameter '%s' (must be an integer)", + optstring, parameter_name); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Option will be ignored for %s output of variable '%s'", + method_name, fullname); + } + Util_TableDeleteKey (table, "out_every"); + } + + /* 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, + "Found option with unrecognized key '%s' in option string " + "'%s' in parameter '%s'", + key, optstring, parameter_name); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Option will be ignored for %s output of variable '%s'", + method_name, fullname); + } + Util_TableItDestroy (iterator); + + Util_TableDestroy (table); + } + else + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Couldn't parse option string '%s' in parameter '%s'", + optstring, parameter_name); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Option string will be ignored for %s output of variable '%s'", + method_name, fullname); + } + free (fullname); +} + + /*@@ @routine IOUtil_1DLines @date July 4 2000 @@ -581,19 +700,19 @@ int IOUtil_CreateDirectory (const cGH *GH, const char *dirname, ********************************************************************/ static void SetOutputVar (int vindex, const char *optstring, void *arg) { - info_t *info; - regmatch_t gmatch[6], *dmatch; - int i, j, bytes, matched; - char *token, *separator, *fullname; - char *substring, *parsestring, *regexstring; + int table, iterator; + char key[128]; + CCTK_INT type, nelems; + char *fullname; + const info_t *info; ioRequest *request; DECLARE_CCTK_PARAMETERS - info = (info_t *) arg; + info = (const info_t *) arg; /* allocate a new I/O request structure and initialize it with defaults */ - request = IOUtil_DefaultIORequest (info->GH, vindex); + request = IOUtil_DefaultIORequest (info->GH, vindex, info->out_every_default); if (! optstring) { @@ -603,194 +722,143 @@ static void SetOutputVar (int vindex, const char *optstring, void *arg) fullname = CCTK_FullName (vindex); - /* parse the I/O request information */ - matched = CCTK_RegexMatch (optstring, - "\\{([0-9]*)\\}" /* dimension */ - "\\{([0-9,()]+)*\\}" /* direction */ - "\\{([0-9,]+)*\\}" /* origin */ - "\\{([-0-9,]+)*\\}" /* extent */ - "\\{([0-9,]+)*\\}", /* downsample */ - 6, gmatch); - if (matched <= 0) - { - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Couldn't parse I/O request options '%s' for variable '%s'", - optstring, fullname); - free (fullname); free (request); - return; - } - - /* SLAB DIMENSION */ - bytes = (int) (gmatch[1].rm_eo - gmatch[1].rm_so); - if (gmatch[1].rm_so != -1 && bytes > 0) + table = Util_TableCreateFromString (optstring); + if (table >= 0) { - request->hdim = atoi (optstring + gmatch[1].rm_so); - if (request->hdim <= 0 || request->hdim > request->vdim) + /* check for option 'out_every' */ + if (Util_TableQueryValueInfo (table, &type, &nelems, "out_every") > 0) { - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Invalid dimension given %d in I/O request options '%s' " - "for variable '%s'", request->hdim, optstring, fullname); - free (fullname); free (request); - return; - } - } - - /* DIRECTION */ - bytes = (int) (gmatch[2].rm_eo - gmatch[2].rm_so); - if (gmatch[2].rm_so != -1 && bytes > 0) - { - substring = strdup (optstring + gmatch[2].rm_so); - substring[bytes] = 0; - - dmatch = (regmatch_t *) malloc ((request->hdim + 1) * - sizeof (regmatch_t)); - regexstring = (char *) malloc (request->hdim * sizeof ("\\(([0-9,]+)\\)")); - regexstring[0] = 0; - for (i = 0; i < request->hdim; i++) - { - strcat (regexstring, "\\(([0-9,]+)\\)"); - } - matched = CCTK_RegexMatch (substring, regexstring, request->hdim + 1, - dmatch); - free (regexstring); - if (matched <= 0) - { - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Couldn't parse direction vectors in I/O request options '%s' " - "for variable '%s'.", optstring, fullname); - free (fullname); free (dmatch); free (request); - return; - } - - for (j = 0; j < request->hdim; j++) - { - i = 0; - bytes = (int) (dmatch[j + 1].rm_eo - dmatch[j + 1].rm_so); - if (dmatch[j + 1].rm_so != -1 && bytes > 0) + if (type == CCTK_VARIABLE_INT && nelems == 1) { - parsestring = strdup (substring + dmatch[j + 1].rm_so); - parsestring[bytes] = 0; - - token = parsestring; - while ((separator = strchr (token, ',')) != NULL) - { - *separator = 0; - request->direction[j * request->vdim + i] = atoi (token); - if (++i >= request->vdim) - { - break; - } - token = separator + 1; - } - request->direction[j * request->vdim + i++] = atoi (token); - free (parsestring); + Util_TableGetInt (table, &request->out_every, "out_every"); } - free (substring); - if (i < request->vdim) + else { - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Direction vectors are incomplete or missing in I/O request " - "options '%s' for variable '%s'.", optstring, fullname); - free (fullname); free (request); - return; + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid value for option 'out_every' in option string " + "'%s' in parameter '%s' (must be an integer)", + optstring, info->parameter_name); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Option 'out_every' will be ignored for %s output of " + "variable '%s'", info->method_name, fullname); } + Util_TableDeleteKey (table, "out_every"); } - } - - /* ORIGIN */ - bytes = (int) (gmatch[3].rm_eo - gmatch[3].rm_so); - if (gmatch[3].rm_so != -1 && bytes > 0) - { - substring = strdup (optstring + gmatch[3].rm_so); - substring[bytes] = 0; - i = 0; - token = substring; - while ((separator = strchr (token, ',')) != NULL) + /* check for hyperslab option 'direction' */ + if (Util_TableQueryValueInfo (table, &type, &nelems, "direction") > 0) { - *separator = 0; - request->origin[i] = atoi (token); - if (++i >= request->vdim) + if (type == CCTK_VARIABLE_INT && nelems > 0 && nelems <= request->vdim && + nelems % request->vdim == 0) { - break; + request->hdim = nelems / request->vdim; + Util_TableGetIntArray (table, nelems, request->direction, "direction"); } - token = separator + 1; - } - request->origin[i++] = atoi (token); - free (substring); - - if (i < request->vdim) - { - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Origin vector is incomplete or missing in I/O request " - "options '%s' for variable '%s'.", optstring, fullname); - free (fullname); free (request); - return; + else + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid value for option 'direction' in option string " + "'%s' in parameter '%s' (must be an integer array with " + "%d x hdim elements, 1 <= hdim <= %d)", + optstring, info->parameter_name, request->vdim, + request->vdim); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Option 'direction' will be ignored for %s output of " + "variable '%s'", info->method_name, fullname); + } + Util_TableDeleteKey (table, "direction"); } - } - /* LENGTH */ - bytes = (int) (gmatch[4].rm_eo - gmatch[4].rm_so); - if(gmatch[4].rm_so != -1 && bytes > 0) - { - substring = strdup (optstring + gmatch[4].rm_so); - substring[bytes] = 0; - - i = 0; - token = substring; - while ((separator = strchr (token, ',')) != NULL) + /* check for hyperslab option 'origin' */ + if (Util_TableQueryValueInfo (table, &type, &nelems, "origin") > 0) { - *separator = 0; - request->extent[i] = atoi (token); - if (++i >= request->hdim) + if (type == CCTK_VARIABLE_INT && nelems == request->vdim) { - break; + Util_TableGetIntArray (table, nelems, request->origin, "origin"); } - token = separator + 1; + else + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid value for option 'origin' in option string " + "'%s' in parameter '%s' (must be an integer array with " + "%d elements)", + optstring, info->parameter_name, request->vdim); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Option 'origin' will be ignored for %s output of " + "variable '%s'", info->method_name, fullname); + } + Util_TableDeleteKey (table, "origin"); } - request->extent[i++] = atoi (token); - free (substring); - if (i < request->hdim) + /* check for hyperslab option 'extent' */ + if (Util_TableQueryValueInfo (table, &type, &nelems, "extent") > 0) { - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Length vector is incomplete or missing in I/O request " - "options '%s' for variable '%s'.", optstring, fullname); - free (fullname); free (request); - return; + if (type == CCTK_VARIABLE_INT && nelems == request->hdim) + { + Util_TableGetIntArray (table, nelems, request->extent, "extent"); + } + else + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid value for option 'extent' in option string " + "'%s' in parameter '%s' (must be an integer array with " + "%d elements)", + optstring, info->parameter_name, request->hdim); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Option 'extent' will be ignored for %s output of " + "variable '%s'", info->method_name, fullname); + } + Util_TableDeleteKey (table, "extent"); } - } - - /* DOWNSAMPLING */ - bytes = (int) (gmatch[5].rm_eo - gmatch[5].rm_so); - if(gmatch[5].rm_so != -1 && bytes > 0) - { - substring = strdup (optstring + gmatch[5].rm_so); - substring[bytes] = 0; - i = 0; - token = substring; - while ((separator = strchr (token, ',')) != NULL) + /* check for hyperslab option 'downsample' */ + if (Util_TableQueryValueInfo (table, &type, &nelems, "downsample") > 0) { - *separator = 0; - request->downsample[i] = atoi (token); - if (++i >= request->hdim) + if (type == CCTK_VARIABLE_INT && nelems == request->hdim) { - break; + Util_TableGetIntArray (table, nelems, request->downsample,"downsample"); + } + else + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid value for option 'downsample' in option string " + "'%s' in parameter '%s' (must be an integer array with " + "%d elements)", + optstring, info->parameter_name, request->hdim); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Option 'downsample' will be ignored for %s output of " + "variable '%s'", info->method_name, fullname); } - token = separator + 1; + Util_TableDeleteKey (table, "downsample"); } - request->downsample[i++] = atoi (token); - free (substring); - if (i < request->hdim) + /* warn about unrecognized 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 (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Downsampling vector is incomplete or missing in I/O request " - "options '%s' for variable '%s'.", optstring, fullname); - free (fullname); free (request); - return; + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Found option with unrecognized key '%s' in option string " + "'%s' in parameter '%s'", + key, optstring, info->parameter_name); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Option will be ignored for %s output of variable '%s'", + info->method_name, fullname); } + Util_TableItDestroy (iterator); + + Util_TableDestroy (table); + } + else + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Couldn't parse option string '%s' in parameter '%s'", + optstring, info->parameter_name); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Option string will be ignored for %s output of variable '%s'", + info->method_name, fullname); } /* assign the new I/O request */ @@ -801,7 +869,9 @@ static void SetOutputVar (int vindex, const char *optstring, void *arg) } -ioRequest *IOUtil_DefaultIORequest (const cGH *GH, int vindex) +/* return the default I/O request description structure for a variable */ +ioRequest *IOUtil_DefaultIORequest (const cGH *GH, int vindex, + int out_every_default) { ioRequest *request; int *extent_int; @@ -818,6 +888,7 @@ ioRequest *IOUtil_DefaultIORequest (const cGH *GH, int vindex) request->vindex = vindex; request->timelevel = 0; request->check_exist = myGH->recovered; + request->out_every = out_every_default; /* get the I/O request datatype (will be single-precision if requested) */ request->hdatatype = CCTK_VarTypeI (vindex); |