aboutsummaryrefslogtreecommitdiff
path: root/src/ParseVars.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ParseVars.c')
-rw-r--r--src/ParseVars.c269
1 files changed, 125 insertions, 144 deletions
diff --git a/src/ParseVars.c b/src/ParseVars.c
index fb70525..de99c3e 100644
--- a/src/ParseVars.c
+++ b/src/ParseVars.c
@@ -10,12 +10,12 @@
#include <stdlib.h>
#include <string.h>
-#include <stdio.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"
@@ -24,13 +24,15 @@ 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 */
-void IOHDF5Util_ParseVarsForOutput (const char *output_varstring,
- ioHDF5Geo_t *output_request_list[]);
-static void IOHDF5Util_ParseOutputRequest (int vindex,
- const char *optstring,
- void *arg);
-static ioHDF5Geo_t *IOHDF5Util_DefaultIORequest (int vindex);
+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,
@@ -54,9 +56,8 @@ int CCTK_RegexMatch (const char *string,
special keyword "all" which indicates that output is requested
on all variables.
@enddesc
- @history
- @endhistory
- @var var_list
+
+ @var out_vars
@vdesc list of variables and/or group names
@vtype const char *
@vio in
@@ -67,50 +68,50 @@ int CCTK_RegexMatch (const char *string,
@vio out
@endvar
@@*/
-
-void IOHDF5Util_ParseVarsForOutput (const char *output_varstring,
- ioHDF5Geo_t *output_request_list[])
+void IOHDF5Util_ParseVarsForOutput (const cGH *GH, const char *out_vars,
+ ioSlab *slablist[])
{
int i;
+ info_t info;
- /* free current list of output requests */
+ /* free current list of hyperslabs */
for (i = CCTK_NumVars () - 1; i >= 0; i--)
{
- if (output_request_list[i])
+ if (slablist[i])
{
- free (output_request_list[i]->origin);
- free (output_request_list[i]);
- output_request_list[i] = NULL;
+ free (slablist[i]->vectors);
+ free (slablist[i]);
+ slablist[i] = NULL;
}
}
- /* generate new list of output requests */
- CCTK_TraverseString (output_varstring, IOHDF5Util_ParseOutputRequest,
- output_request_list, CCTK_GROUP_OR_VAR);
+ /* generate new list of hyperslabs */
+ info.GH = GH;
+ info.slablist = slablist;
+ CCTK_TraverseString (out_vars, SetOutputVar, &info, CCTK_GROUP_OR_VAR);
}
-static void IOHDF5Util_ParseOutputRequest (int vindex,
- const char *optstring,
- void *arg)
+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;
- ioHDF5Geo_t **output_requests, *new_request;
+ ioSlab *slab;
DECLARE_CCTK_PARAMETERS
- output_requests = (ioHDF5Geo_t **) arg;
+ info = (info_t *) arg;
- /* allocate a new IO request structure and initialize it with defaults */
- new_request = IOHDF5Util_DefaultIORequest (vindex);
+ /* allocate a new I/O hyperslab structure and initialize it with defaults */
+ slab = DefaultIOHyperslab (info->GH, vindex);
if (! optstring)
{
- output_requests[vindex] = new_request;
+ info->slablist[vindex] = slab;
return;
}
@@ -119,7 +120,7 @@ static void IOHDF5Util_ParseOutputRequest (int vindex,
"\\{([0-9]*)\\}" /* dimension */
"\\{([0-9,()]+)*\\}" /* direction */
"\\{([0-9,]+)*\\}" /* origin */
- "\\{([-0-9,]+)*\\}" /* length */
+ "\\{([-0-9,]+)*\\}" /* extent */
"\\{([0-9,]+)*\\}", /* downsample */
6, gmatch);
if (matched <= 0)
@@ -129,7 +130,7 @@ static void IOHDF5Util_ParseOutputRequest (int vindex,
"Couldn't parse hyperslab options '%s' for variable '%s'",
optstring, fullname);
free (fullname);
- free (new_request);
+ free (slab);
return;
}
@@ -137,15 +138,15 @@ static void IOHDF5Util_ParseOutputRequest (int vindex,
bytes = (int) (gmatch[1].rm_eo - gmatch[1].rm_so);
if (gmatch[1].rm_so != -1 && bytes > 0)
{
- new_request->sdim = atoi (optstring + gmatch[1].rm_so);
- if (new_request->sdim <= 0 || new_request->sdim > new_request->vdim)
+ 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'", new_request->sdim, optstring, fullname);
+ "for variable '%s'", slab->hdim, optstring, fullname);
free (fullname);
- free (new_request);
+ free (slab);
return;
}
}
@@ -157,15 +158,15 @@ static void IOHDF5Util_ParseOutputRequest (int vindex,
substring = strdup (optstring + gmatch[2].rm_so);
substring[bytes] = 0;
- dmatch = (regmatch_t *) malloc ((new_request->sdim + 1) *
+ dmatch = (regmatch_t *) malloc ((slab->hdim + 1) *
sizeof (regmatch_t));
- regexstring = (char *) malloc (new_request->sdim * sizeof ("\\(([0-9,]+)\\)"));
+ regexstring = (char *) malloc (slab->hdim * sizeof ("\\(([0-9,]+)\\)"));
regexstring[0] = 0;
- for (i = 0; i < new_request->sdim; i++)
+ for (i = 0; i < slab->hdim; i++)
{
strcat (regexstring, "\\(([0-9,]+)\\)");
}
- matched = CCTK_RegexMatch (substring, regexstring, new_request->sdim + 1,
+ matched = CCTK_RegexMatch (substring, regexstring, slab->hdim + 1,
dmatch);
free (regexstring);
if (matched <= 0)
@@ -176,11 +177,11 @@ static void IOHDF5Util_ParseOutputRequest (int vindex,
"for variable '%s'.", optstring, fullname);
free (fullname);
free (dmatch);
- free (new_request);
+ free (slab);
return;
}
- for (j = 0; j < new_request->sdim; j++)
+ for (j = 0; j < slab->hdim; j++)
{
i = 0;
bytes = (int) (dmatch[j + 1].rm_eo - dmatch[j + 1].rm_so);
@@ -193,25 +194,25 @@ static void IOHDF5Util_ParseOutputRequest (int vindex,
while ((separator = strchr (token, ',')) != NULL)
{
*separator = 0;
- new_request->direction[j * new_request->vdim + i] = atoi (token);
- if (++i >= new_request->vdim)
+ slab->direction[j * slab->vdim + i] = atoi (token);
+ if (++i >= slab->vdim)
{
break;
}
token = separator + 1;
}
- new_request->direction[j * new_request->vdim + i++] = atoi (token);
+ slab->direction[j * slab->vdim + i++] = atoi (token);
free (parsestring);
}
free (substring);
- if (i < new_request->vdim)
+ 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 (new_request);
+ free (slab);
return;
}
}
@@ -229,24 +230,24 @@ static void IOHDF5Util_ParseOutputRequest (int vindex,
while ((separator = strchr (token, ',')) != NULL)
{
*separator = 0;
- new_request->origin[i] = atoi (token);
- if (++i >= new_request->vdim)
+ slab->origin[i] = atoi (token);
+ if (++i >= slab->vdim)
{
break;
}
token = separator + 1;
}
- new_request->origin[i++] = atoi (token);
+ slab->origin[i++] = atoi (token);
free (substring);
- if (i < new_request->vdim)
+ 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 (new_request);
+ free (slab);
return;
}
}
@@ -263,24 +264,24 @@ static void IOHDF5Util_ParseOutputRequest (int vindex,
while ((separator = strchr (token, ',')) != NULL)
{
*separator = 0;
- new_request->length[i] = atoi (token);
- if (++i >= new_request->sdim)
+ slab->extent[i] = atoi (token);
+ if (++i >= slab->hdim)
{
break;
}
token = separator + 1;
}
- new_request->length[i++] = atoi (token);
+ slab->extent[i++] = atoi (token);
free (substring);
- if (i < new_request->sdim)
+ 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 (new_request);
+ free (slab);
return;
}
}
@@ -297,134 +298,114 @@ static void IOHDF5Util_ParseOutputRequest (int vindex,
while ((separator = strchr (token, ',')) != NULL)
{
*separator = 0;
- new_request->downsample[i] = atoi (token);
- if (++i >= new_request->sdim)
+ slab->downsample[i] = atoi (token);
+ if (++i >= slab->hdim)
{
break;
}
token = separator + 1;
}
- new_request->downsample[i++] = atoi (token);
+ slab->downsample[i++] = atoi (token);
free (substring);
- if (i < new_request->sdim)
+ 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 (new_request);
+ free (slab);
return;
}
}
- /* assign the output request */
- output_requests[vindex] = new_request;
-
-
-#ifdef IOHDF5UTIL_DEBUG
- printf("Geometry Data: \n");
- printf(" Argument/Slab dimension: %d / %d \n", new_request->vdim,new_request->sdim);
- printf(" Origin: ");
- for (i=0;i<new_request->vdim;i++)
- printf("%s %d ", new_request->origin[i]);
- printf("\n Downs : ");
- for (i=0;i<new_request->sdim;i++)
- printf(" %d ", new_request->downsample[i]);
- printf("\n Length: ");
- for (i=0;i<new_request->sdim;i++)
- printf(" %d ", new_request->length[i]);
- printf("\n Dirs : ");
- for (i=0;i<new_request->sdim;i++)
- printf(" %d ", new_request->direction[i]);
- printf("\n\n");
-#endif
+ /* assign the new hyperslab */
+ info->slablist[vindex] = slab;
}
-static ioHDF5Geo_t *IOHDF5Util_DefaultIORequest (int vindex)
+static ioSlab *DefaultIOHyperslab (const cGH *GH, int vindex)
{
+ ioSlab *slab;
+ int *extent_int;
+ const ioGH *ioUtilGH;
DECLARE_CCTK_PARAMETERS
- int i;
- ioHDF5Geo_t *request;
-#if 0
- const char *argument, *token;
-#endif
- /* allocate a new IO request structure */
- request = (ioHDF5Geo_t *) malloc (sizeof (ioHDF5Geo_t));
+ ioUtilGH = (const ioGH *) CCTK_GHExtension (GH, "IO");
- /* get the variable's dimension
- set it also to be the default hyperslab dimension */
- request->vdim = request->sdim = CCTK_GroupDimFromVarI (vindex);
+ /* allocate a new I/O hyperslab structure */
+ slab = (ioSlab *) malloc (sizeof (ioSlab));
- request->origin = (int *) calloc (4 + request->sdim,
- request->vdim * sizeof (int));
- request->length = request->origin + 1 * request->vdim;
- request->downsample = request->origin + 2 * request->vdim;
- request->actlen = request->origin + 3 * request->vdim;
- request->direction = request->origin + 4 * request->vdim;
+ /* fill out the basics */
+ slab->vindex = vindex;
+ slab->timelevel = 0;
+ slab->check_exist = ioUtilGH->recovered;
- for (i = 0; i < request->vdim; i++)
+ /* get the hyperslab datatype (will be single-precision if requested) */
+ slab->hdatatype = CCTK_VarTypeI (vindex);
+ if (ioUtilGH->out_single)
{
- request->length[i] = -1;
- request->direction[i * request->vdim + i] = 1;
+ 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 * 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;
+ slab->extent = slab->vectors + 4*slab->vdim;
+ slab->downsample = slab->vectors + 5*slab->vdim;
+ slab->direction = slab->vectors + 6*slab->vdim;
+
+ for (slab->hdim = 0; slab->hdim < slab->vdim; slab->hdim++)
+ {
+ slab->extent[slab->hdim] = extent_int[slab->hdim];
+ slab->direction[slab->hdim] = slab->hdim * (slab->vdim + 1);
/* take the downsampling parameters from IOUtil */
- if (i == 0)
+ if (slab->hdim == 0)
{
- request->downsample[i] = out3D_downsample_x;
+ slab->downsample[slab->hdim] = out3D_downsample_x;
}
- else if (i == 1)
+ else if (slab->hdim == 1)
{
- request->downsample[i] = out3D_downsample_y;
+ slab->downsample[slab->hdim] = out3D_downsample_y;
}
- else if (i == 2)
+ else if (slab->hdim == 2)
{
- request->downsample[i] = out3D_downsample_z;
+ slab->downsample[slab->hdim] = out3D_downsample_z;
}
else
{
- request->downsample[i] = 1;
+ slab->downsample[slab->hdim] = 1;
}
}
-#if 0
- FIXME: parse default hyperslab parameters
- /* Origin */
- i=0;
- argument = origin;
- while((token = Util_StrSep(&argument,","))) {
- request->origin[i++]=atoi(token);
- }
- request->downsample[i] = atoi(argument);
-
- /* Direction */
- i=0;
- argument = direction;
- while((token = Util_StrSep(&argument,","))) {
- request->direction[i++]=atoi(token);
- }
- request->downsample[i] = atoi(argument);
-
- /* Downsample */
- i=0;
- argument = downsampling;
- while((token = Util_StrSep(&argument,","))) {
- request->downsample[i++]=atoi(token);
- }
- request->downsample[i] = atoi(argument);
-
- /* Length */
- i=0;
- argument = length;
- while((token = Util_StrSep(&argument,","))) {
- request->length[i++]=atoi(token);
- }
- request->length[i] = atoi(argument);
-#endif
+ /* clean up */
+ free (extent_int);
- return (request);
+ return (slab);
}