aboutsummaryrefslogtreecommitdiff
path: root/src/ParseVars.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ParseVars.c')
-rw-r--r--src/ParseVars.c411
1 files changed, 0 insertions, 411 deletions
diff --git a/src/ParseVars.c b/src/ParseVars.c
deleted file mode 100644
index 2c58703..0000000
--- a/src/ParseVars.c
+++ /dev/null
@@ -1,411 +0,0 @@
- /*@@
- @file GHExtension.c
- @date Tue 9th Feb 1999
- @author Gabrielle Allen
- @desc
- IOUtil GH extension stuff.
- @enddesc
- @version $Id$
- @@*/
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "cctk.h"
-#include "util_String.h"
-#include "cctk_Parameters.h"
-#include "cctk_GNU.h"
-#include "CactusBase/IOUtil/src/ioGH.h"
-#include "ioHDF5UtilGH.h"
-
-
-/* the rcs ID and its dummy function to use it */
-static const char *rcsid = "$Id$";
-CCTK_FILEVERSION(BetaThorns_IOHDF5Util_ParseVars_c)
-
-
-typedef struct
-{
- const cGH *GH;
- ioSlab **slablist;
-} info_t;
-
-/* prototypes of routines defined in this source file */
-static void SetOutputVar (int vindex, const char *optstring, void *arg);
-static ioSlab *DefaultIOHyperslab (const cGH *GH, int vindex);
-
-/* prototypes of external routines for which no header files exist */
-int CCTK_RegexMatch (const char *string,
- const char *pattern,
- const int nmatch,
- regmatch_t *pmatch);
-
-
-/* ===============================================================
- utility routines used by other IO thorns
- ===============================================================*/
-
- /*@@
- @routine IOUtil_ParseVarsForOutput
- @date Sat March 6 1999
- @author Gabrielle Allen
- @desc
- Sets each flag in the do_output[] do_output to true
- if var[i] could be found in the list of variable names.
- var_list my also contain group names of variables as well as the
- special keyword "all" which indicates that output is requested
- on all variables.
- @enddesc
-
- @var out_vars
- @vdesc list of variables and/or group names
- @vtype const char *
- @vio in
- @endvar
- @var do_output
- @vdesc do_output of flags indicating output was requested for var[i]
- @vtype char []
- @vio out
- @endvar
-@@*/
-void IOHDF5Util_ParseVarsForOutput (const cGH *GH, const char *out_vars,
- ioSlab *slablist[])
-{
- int i;
- info_t info;
-
-
- /* free current list of hyperslabs */
- for (i = CCTK_NumVars () - 1; i >= 0; i--)
- {
- if (slablist[i])
- {
- free (slablist[i]->vectors);
- free (slablist[i]);
- slablist[i] = NULL;
- }
- }
-
- /* generate new list of hyperslabs */
- info.GH = GH;
- info.slablist = slablist;
- CCTK_TraverseString (out_vars, SetOutputVar, &info, CCTK_GROUP_OR_VAR);
-}
-
-
-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;
- ioSlab *slab;
- DECLARE_CCTK_PARAMETERS
-
-
- info = (info_t *) arg;
-
- /* allocate a new I/O hyperslab structure and initialize it with defaults */
- slab = DefaultIOHyperslab (info->GH, vindex);
-
- if (! optstring)
- {
- info->slablist[vindex] = slab;
- return;
- }
-
- /* parse the hyperslab 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)
- {
- fullname = CCTK_FullName (vindex);
- CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Couldn't parse hyperslab options '%s' for variable '%s'",
- optstring, fullname);
- free (fullname);
- free (slab);
- return;
- }
-
- /* SLAB DIMENSION */
- bytes = (int) (gmatch[1].rm_eo - gmatch[1].rm_so);
- if (gmatch[1].rm_so != -1 && bytes > 0)
- {
- slab->hdim = atoi (optstring + gmatch[1].rm_so);
- if (slab->hdim <= 0 || slab->hdim > slab->vdim)
- {
- fullname = CCTK_FullName (vindex);
- CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Invalid dimension given %d in hyperslab options '%s' "
- "for variable '%s'", slab->hdim, optstring, fullname);
- free (fullname);
- free (slab);
- 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 ((slab->hdim + 1) *
- sizeof (regmatch_t));
- regexstring = (char *) malloc (slab->hdim * sizeof ("\\(([0-9,]+)\\)"));
- regexstring[0] = 0;
- for (i = 0; i < slab->hdim; i++)
- {
- strcat (regexstring, "\\(([0-9,]+)\\)");
- }
- matched = CCTK_RegexMatch (substring, regexstring, slab->hdim + 1,
- dmatch);
- free (regexstring);
- if (matched <= 0)
- {
- fullname = CCTK_FullName (vindex);
- CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Couldn't parse direction vectors in hyperslab options '%s' "
- "for variable '%s'.", optstring, fullname);
- free (fullname);
- free (dmatch);
- free (slab);
- return;
- }
-
- for (j = 0; j < slab->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)
- {
- parsestring = strdup (substring + dmatch[j + 1].rm_so);
- parsestring[bytes] = 0;
-
- token = parsestring;
- while ((separator = strchr (token, ',')) != NULL)
- {
- *separator = 0;
- slab->direction[j * slab->vdim + i] = atoi (token);
- if (++i >= slab->vdim)
- {
- break;
- }
- token = separator + 1;
- }
- slab->direction[j * slab->vdim + i++] = atoi (token);
- free (parsestring);
- }
- free (substring);
- if (i < slab->vdim)
- {
- fullname = CCTK_FullName (vindex);
- CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Direction vectors are incomplete or missing in hyperslab "
- "options '%s' for variable '%s'.", optstring, fullname);
- free (fullname);
- free (slab);
- return;
- }
- }
- }
-
- /* 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)
- {
- *separator = 0;
- slab->origin[i] = atoi (token);
- if (++i >= slab->vdim)
- {
- break;
- }
- token = separator + 1;
- }
- slab->origin[i++] = atoi (token);
- free (substring);
-
- if (i < slab->vdim)
- {
- fullname = CCTK_FullName (vindex);
- CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Origin vector is incomplete or missing in hyperslab "
- "options '%s' for variable '%s'.", optstring, fullname);
- free (fullname);
- free (slab);
- return;
- }
- }
-
- /* 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)
- {
- *separator = 0;
- slab->extent[i] = atoi (token);
- if (++i >= slab->hdim)
- {
- break;
- }
- token = separator + 1;
- }
- slab->extent[i++] = atoi (token);
- free (substring);
-
- if (i < slab->hdim)
- {
- fullname = CCTK_FullName (vindex);
- CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Length vector is incomplete or missing in hyperslab "
- "options '%s' for variable '%s'.", optstring, fullname);
- free (fullname);
- free (slab);
- return;
- }
- }
-
- /* 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)
- {
- *separator = 0;
- slab->downsample[i] = atoi (token);
- if (++i >= slab->hdim)
- {
- break;
- }
- token = separator + 1;
- }
- slab->downsample[i++] = atoi (token);
- free (substring);
-
- if (i < slab->hdim)
- {
- fullname = CCTK_FullName (vindex);
- CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
- "Downsampling vector is incomplete or missing in hyperslab "
- "options '%s' for variable '%s'.", optstring, fullname);
- free (fullname);
- free (slab);
- return;
- }
- }
-
- /* assign the new hyperslab */
- info->slablist[vindex] = slab;
-}
-
-
-static ioSlab *DefaultIOHyperslab (const cGH *GH, int vindex)
-{
- ioSlab *slab;
- int *extent_int;
- const ioGH *ioUtilGH;
- DECLARE_CCTK_PARAMETERS
-
-
- ioUtilGH = (const ioGH *) CCTK_GHExtension (GH, "IO");
-
- /* allocate a new I/O hyperslab structure */
- slab = (ioSlab *) malloc (sizeof (ioSlab));
-
- /* fill out the basics */
- slab->vindex = vindex;
- slab->timelevel = 0;
- slab->check_exist = ioUtilGH->recovered;
-
- /* get the hyperslab datatype (will be single-precision if requested) */
- slab->hdatatype = CCTK_VarTypeI (vindex);
- if (ioUtilGH->out_single)
- {
- if (slab->hdatatype == CCTK_VARIABLE_REAL)
- {
- slab->hdatatype = CCTK_VARIABLE_REAL4;
- }
- else if (slab->hdatatype == CCTK_VARIABLE_COMPLEX)
- {
- slab->hdatatype = CCTK_VARIABLE_COMPLEX8;
- }
-#ifdef CCTK_INT2
- else if (slab->hdatatype == CCTK_VARIABLE_INT)
- {
- slab->hdatatype = CCTK_VARIABLE_INT2;
- }
-#endif
- }
-
- /* get the variable's dimension and extents */
- slab->vdim = CCTK_GroupDimFromVarI (vindex);
- extent_int = (int *) malloc (slab->vdim * sizeof (int));
- CCTK_GroupgshVI (GH, slab->vdim, extent_int, vindex);
-
- /* allocate the arrays all in one go
- only initialize those which are mandatory for the Hyperslab API */
- slab->vectors = (CCTK_INT *) calloc ((slab->vdim + 6) * slab->vdim + 1,
- sizeof (CCTK_INT));
- slab->hoffset = slab->vectors + 0*slab->vdim;
- slab->hsize = slab->vectors + 1*slab->vdim;
- slab->hsize_chunk = slab->vectors + 2*slab->vdim;
- slab->origin = slab->vectors + 3*slab->vdim + 1;
- slab->extent = slab->vectors + 4*slab->vdim + 1;
- slab->downsample = slab->vectors + 5*slab->vdim + 1;
- slab->direction = slab->vectors + 6*slab->vdim + 1;
-
- for (slab->hdim = 0; slab->hdim < slab->vdim; slab->hdim++)
- {
- slab->extent[slab->hdim] = extent_int[slab->hdim];
- slab->direction[slab->hdim * (slab->vdim + 1)] = 1;
-
- /* take the downsampling parameters from IOUtil */
- if (slab->hdim == 0)
- {
- slab->downsample[slab->hdim] = out3D_downsample_x;
- }
- else if (slab->hdim == 1)
- {
- slab->downsample[slab->hdim] = out3D_downsample_y;
- }
- else if (slab->hdim == 2)
- {
- slab->downsample[slab->hdim] = out3D_downsample_z;
- }
- else
- {
- slab->downsample[slab->hdim] = 1;
- }
- }
-
- /* clean up */
- free (extent_int);
-
- return (slab);
-}