From 7235d480563efd9a6a5e8b32a8901e2e550fb070 Mon Sep 17 00:00:00 2001 From: lanfer Date: Tue, 1 Aug 2000 19:23:32 +0000 Subject: Stuff to parse hyperslab parameters. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOStreamedHDF5/trunk@14 0888f3d4-9f52-45d2-93bc-d00801ff5e46 --- src/ParseGeometry.c | 347 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ParseVars.c | 204 ++++++++++++++++++++++++++++++ 2 files changed, 551 insertions(+) create mode 100644 src/ParseGeometry.c create mode 100644 src/ParseVars.c diff --git a/src/ParseGeometry.c b/src/ParseGeometry.c new file mode 100644 index 0000000..8db56f8 --- /dev/null +++ b/src/ParseGeometry.c @@ -0,0 +1,347 @@ + +#include +#include +#include + +#include "cctk.h" +#include "cctk_Arguments.h" +#include "cctk_Parameters.h" +#include "cctk_GNU.h" +#include "util_String.h" + +#include "StreamedHDF5GH.h" + +/* CCTK_NO_AUTOUSE_MACRO */ + +/*#define DEBUG*/ + + +int GeometryParser(const char *before, char **outname, StreamGeo_t *geo) +{ + DECLARE_CCTK_PARAMETERS + + regmatch_t pmatch[3],gmatch[6]; + int matched,ierr=0,retval=0, verb=0, deb=0; + + const char *argument; + char *varname=NULL, *geo_s=NULL, *token=NULL; + char *dim_s=NULL, *ori_s=NULL, *dir_s=NULL; + char *len_s=NULL, *down_s=NULL; + + int dim, idim, iidim; + int index; + + char *info; + + + /* Debugging switches */ + if (CCTK_Equals(h5verbose,"debug")) { + deb =1; + verb =1; + } + if (CCTK_Equals(h5verbose,"yes")) + verb =1; + + + info = (char*) malloc (8000*sizeof(char)); + sprintf(info,"\n\nGeometryParser \nargument: >%s<\n",before); + + if((matched = CCTK_RegexMatch(before, + "(\\w*:?:?\\w*)\\[?(.*)?\\]?", 3, pmatch)) != 0) { + +#ifdef HEAVYDEBUG + printf("matched %d rm_so/rm_eo: %d %d; %d %d\n", + matched, + pmatch[1].rm_so,pmatch[1].rm_eo, + pmatch[2].rm_so,pmatch[2].rm_eo); +#endif + + if(pmatch[1].rm_so != -1 && + (pmatch[1].rm_eo-pmatch[1].rm_so > 0)) + { + varname = (char*) malloc((int)(pmatch[1].rm_eo-pmatch[1].rm_so+1) + *sizeof(char)); + strncpy(varname,before+pmatch[1].rm_so, + (int)(pmatch[1].rm_eo-pmatch[1].rm_so)); + varname[(int)(pmatch[1].rm_eo-pmatch[1].rm_so)]='\0'; + + *outname = varname; + sprintf(info,"%sOUTNAME : >%s< \n",info,*outname); + + if ((index = CCTK_VarIndex(varname))>=0) { + geo->vdim = CCTK_GroupDimI(CCTK_GroupIndexFromVarI(index)); + geo->sdim = geo->vdim; + } + else + { + sprintf(info,"%sOUTNAME : no appropriate gridfunction found. \n", + info,*outname); + geo->vdim = -1; + geo->sdim = -1; + } + } + else + { + CCTK_WARN(1,"No variable name found in StreamedHDF5::out_vars"); + retval = -1; + } + + if(pmatch[2].rm_so != -1 && + (pmatch[2].rm_eo-pmatch[2].rm_so > 0)) + { + geo_s = (char*) malloc((int)(pmatch[2].rm_eo-pmatch[2].rm_so+1) + *sizeof(char)); + strncpy(geo_s,before+pmatch[2].rm_so, + (int)(pmatch[2].rm_eo-pmatch[2].rm_so)); + geo_s[(int)(pmatch[2].rm_eo-pmatch[2].rm_so)]='\0'; + sprintf(info,"%sGEOMETRY: >%s< \n",info,geo_s); + } else { + sprintf(info,"%sGEOMETRY: No geometry specified -> use default\n",info); + } + } + else { + retval=-1; + } + + /* Pattern match the hyperslab string geo_s*/ + if (geo_s) { + if((matched = CCTK_RegexMatch(geo_s, + "\\{(.*)\\},\\{(.*)\\},\\{(.*)\\},\\{(.*)\\},\\{(.*)\\}", + 6, gmatch)) != 0) + { + + /* SLAB DIMENSION */ + if(gmatch[1].rm_so != -1 && + (gmatch[1].rm_eo-gmatch[1].rm_so > 0)) + { + dim_s = (char*) malloc((int)(gmatch[1].rm_eo-gmatch[1].rm_so+1) + *sizeof(char)); + strncpy(dim_s,geo_s+gmatch[1].rm_so, + (int)(gmatch[1].rm_eo-gmatch[1].rm_so)); + dim_s[(int)(gmatch[1].rm_eo-gmatch[1].rm_so)]='\0'; + + if (deb) + sprintf(info,"%sDIMENSION: >%s< \n",info,dim_s); + + dim = atoi(dim_s); + geo->sdim = dim; + } + else { + if (deb) + sprintf(info,"%s","DIMENSION: No dimension\n"); + retval = -1; + } + free(dim_s); + + /* DIRECTION */ + ierr = -1; + if(gmatch[2].rm_so != -1 && + (gmatch[2].rm_eo-gmatch[2].rm_so > 0)) + { + dir_s = (char*) malloc((int)(gmatch[2].rm_eo-gmatch[2].rm_so+1) + *sizeof(char)); + strncpy(dir_s,geo_s+gmatch[2].rm_so, + (int)(gmatch[2].rm_eo-gmatch[2].rm_so)); + dir_s[(int)(gmatch[2].rm_eo-gmatch[2].rm_so)]='\0'; + + if (deb) + sprintf(info,"%sDIRECTION: >%s< \n",info,dir_s); + + idim = 0; + argument = dir_s; + while((token = Util_StrSep(&argument,","))) { + geo->direction[idim++]=atoi(token); + } + geo->direction[idim] = atoi(argument); + if (idim==dim-1) ierr = 0; + } + if (ierr<0) { + sprintf(info,"%sDIRECTION: dimension not consistent: >%s< \n", + info,dir_s); + retval = -1; + } + free(dir_s); + + /* ORIGIN */ + ierr = -1; + if(gmatch[3].rm_so != -1 && + (gmatch[3].rm_eo-gmatch[3].rm_so > 0)) + { + ori_s = (char*) malloc((int)(gmatch[3].rm_eo-gmatch[3].rm_so+1) + *sizeof(char)); + strncpy(ori_s,geo_s+gmatch[3].rm_so, + (int)(gmatch[3].rm_eo-gmatch[3].rm_so)); + ori_s[(int)(gmatch[3].rm_eo-gmatch[3].rm_so)]='\0'; + + if (deb) + sprintf(info,"%sDIRECTION: >%s< \n",info,ori_s); + + idim=0; + argument = ori_s; + while((token = Util_StrSep(&argument,","))) { + geo->origin[idim++]=atoi(token); + } + geo->origin[idim] = atoi(argument); + if (idim==(geo->vdim-1)) ierr = 0; + else if (idim==0) { + for (iidim=1;iidimvdim;iidim++) + geo->origin[iidim] = geo->origin[0]; + ierr = 0; + } + } + if (ierr<0) { + sprintf(info,"%sORIGIN: dimension not consistent: >%s< \n", + info,ori_s); + ierr = -1; + } + free(ori_s); + + /* LENGTH */ + ierr = -1; + if(gmatch[4].rm_so != -1 && + (gmatch[4].rm_eo-gmatch[4].rm_so > 0)) + { + len_s = (char*) malloc((int)(gmatch[4].rm_eo-gmatch[4].rm_so+1) + *sizeof(char)); + strncpy(len_s,geo_s+gmatch[4].rm_so, + (int)(gmatch[4].rm_eo-gmatch[4].rm_so)); + len_s[(int)(gmatch[4].rm_eo-gmatch[4].rm_so)]='\0'; + + if (deb) + sprintf(info,"%sLENGTH: >%s< \n",info,len_s); + + idim = 0; + argument = len_s; + while((token = Util_StrSep(&argument,","))) { + geo->length[idim++]=atoi(token); + } + geo->length[idim] = atoi(argument); + if (idim==dim-1) ierr = 0; + else if (idim==0) { + for (iidim=1;iidimlength[iidim] = geo->length[0]; + ierr = 0; + } + } + if (ierr<0) { + sprintf(info,"%sLENGTH: dimension not consistent: >%s< \n", + info,len_s); + retval =-1; + } + free(len_s); + + + /* DOWNSAMPLING */ + ierr = -1; + if(gmatch[5].rm_so != -1 && + (gmatch[5].rm_eo-gmatch[5].rm_so > 0)) { + + down_s = (char*) malloc((int)(gmatch[5].rm_eo-gmatch[5].rm_so+1) + *sizeof(char)); + strncpy(down_s,geo_s+gmatch[5].rm_so, + (int)(gmatch[5].rm_eo-gmatch[5].rm_so)); + down_s[(int)(gmatch[5].rm_eo-gmatch[5].rm_so)]='\0'; + + if (deb) + sprintf(info,"%sDOWNSAMPLING: >%s< \n",info,down_s); + + + idim=0; + argument = down_s; + while((token = Util_StrSep(&argument,","))) { + geo->downs[idim++]=atoi(token); + } + geo->downs[idim] = atoi(argument); + if (idim==dim-1) ierr =0; + else if (idim==0) { + for (iidim=1;iidimdowns[iidim] = geo->downs[0]; + ierr = 0; + } + } + if (ierr<0) { + sprintf(info,"%sDOWNSAMPLING: dimension not consistent: >%s< \n", + info,down_s); + ierr =-1; + } + free(down_s); + } + if (geo_s) free(geo_s); + } + + sprintf(info, "%sGeometry Data: \n",info); + sprintf(info, "%s Argument/Slab dimension: %d / %d \n", + info,geo->vdim,geo->sdim); + sprintf(info, "%s Origin: ",info); + for (idim=0;idimvdim;idim++) + sprintf(info,"%s %d ",info,geo->origin[idim]); + sprintf(info,"%s\n Downs : ",info); + for (idim=0;idimsdim;idim++) + sprintf(info,"%s %d ",info,geo->downs[idim]); + sprintf(info,"%s\n Length: ",info); + for (idim=0;idimsdim;idim++) + sprintf(info,"%s %d ",info,geo->length[idim]); + sprintf(info,"%s\n Dirs : ",info); + for (idim=0;idimsdim;idim++) + sprintf(info,"%s %d ",info,geo->direction[idim]); + sprintf(info,"%s\n\n",info); + + + printf("%s",info); + free(info); + info=NULL; + + USE_CCTK_PARAMETERS + + return(retval); +} + +void SetDefaultGeo(StreamGeo_t *geo) { + DECLARE_CCTK_PARAMETERS + + int idim; + char *argument, *token; + + geo->vdim = -1; + geo->sdim = -1; + + /* Origin */ + idim=0; + argument = origin; + while((token = Util_StrSep(&argument,","))) { + geo->origin[idim++]=atoi(token); + } + geo->downs[idim] = atoi(argument); + + /* Direction */ + idim=0; + argument = direction; + while((token = Util_StrSep(&argument,","))) { + geo->direction[idim++]=atoi(token); + } + geo->downs[idim] = atoi(argument); + + /* Downsample */ + idim=0; + argument = origin; + while((token = Util_StrSep(&argument,","))) { + geo->downs[idim++]=atoi(token); + } + geo->downs[idim] = atoi(argument); + + /* Length */ + idim=0; + argument = origin; + while((token = Util_StrSep(&argument,","))) { + geo->length[idim++]=atoi(token); + } + geo->length[idim] = atoi(argument); + + for (idim=0;idimdirection[idim] = idim; + geo->origin[idim] = 0; + geo->length[idim] =-1; + geo->downs[idim] = 1; + } +} + diff --git a/src/ParseVars.c b/src/ParseVars.c new file mode 100644 index 0000000..f441234 --- /dev/null +++ b/src/ParseVars.c @@ -0,0 +1,204 @@ + /*@@ + @file GHExtension.c + @date Tue 9th Feb 1999 + @author Gabrielle Allen + @desc + IOUtil GH extension stuff. + @enddesc + @history + @endhistory + @@*/ + +/*#define DEBUG_IO*/ + +#include +#include +#include + +#include "cctk.h" +#include "util_String.h" +#include "cctk_Parameters.h" + +#include "StreamedHDF5GH.h" + + +static char *rcsid = "$Header$"; + + +/* =============================================================== + 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 + @history + @endhistory + @var var_list + @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 ParseVarsForOutput (StreamedHDF5GH *h5GH, const char *var_list) +{ + char *outname=NULL; + char *before=NULL; + char *after=NULL; + char *splitstring; + int first,groupnum,i,last,index,varnum; + StreamGeo_t geo_tmp; + int ierr=0; + + /* First initialise every variable to no output */ + for (i=0; ido_output[i] = 0; + } + + /* Initialize geometry structure with default */ + SetDefaultGeo(&geo_tmp); + + splitstring = (char *) var_list; + + /* split string at blanks */ + while(Util_SplitString(&before,&after,splitstring," ")==0) { + +#ifdef DEBUG_IO + printf(" String is -%s-\n",splitstring); + printf(" Split is -%s- and -%s-\n",before,after); +#endif + + if (CCTK_Equals(before," ")) continue; + + if (strlen(before) > 0) + { + /* Extract geometry information */ + ierr=GeometryParser(before, &outname, &geo_tmp); + if (ierr<0) printf("GeometryParser failed: >%s<\n",before); + + /* Look for any special tokens */ + if (CCTK_Equals(outname,"all")) + { + int ilab; + for (ilab=0;ilabgeo_output[ilab]= geo_tmp; + h5GH->do_output[ilab] = 1; + } + } + else + { + /* See if this name is implementation::variable */ + varnum = CCTK_VarIndex(outname); + if ( varnum < 0 ) + { + /* See if this name is implementation::group */ + groupnum = CCTK_GroupIndex(outname); + if (groupnum < 0) + { + char *msg; + msg = (char *)malloc((100+strlen(outname))*sizeof(char)); + sprintf(msg,"Ignoring <%s> in IO string (invalid token)",outname); + CCTK_WARN(2,msg); + free(msg); + } + else + { + /* We have a group so now need all the variables in the group */ + first = CCTK_FirstVarIndexI(groupnum); + last = first+CCTK_NumVarsInGroupI(groupnum)-1; + for (index=first;index<=last;index++) { + h5GH->geo_output[index]=geo_tmp; + h5GH->do_output[index] =1; + } + } + } + else + { + h5GH->geo_output[varnum]= geo_tmp; + h5GH->do_output[varnum] = 1; + } + } + } + if(before) + { + free(before); + before = NULL; + } + if(outname) + { + free(outname); + outname = NULL; + } + if(splitstring != var_list) + { + free(splitstring); + } + + splitstring = after; + + } + + if (strlen(splitstring)>0) { + + /* Extract geometry information */ + ierr=GeometryParser(splitstring, &outname, &geo_tmp); + if (ierr<0) printf("GeometryParser failed: >%s<\n",before); + + /* Special cases */ + if (CCTK_Equals(splitstring,"all")) { + int ilab; + for (ilab=0;ilabgeo_output[ilab]=geo_tmp; + h5GH->do_output [ilab]=1; + } + } else { + + varnum = CCTK_VarIndex(splitstring); + if (varnum < 0) { + groupnum = CCTK_GroupIndex(splitstring); + if (groupnum < 0) { + char *msg; + msg = (char *)malloc((100+strlen(splitstring))*sizeof(char)); + sprintf(msg,"Ignoring %s in IO string (invalid token)",splitstring); + CCTK_WARN(2,msg); + free(msg); + } else { + /* We have a group so now need all the variables in the group */ + first = CCTK_FirstVarIndexI(groupnum); + last = first+CCTK_NumVarsInGroupI(groupnum)-1; + for (index=first;index<=last;index++) { + h5GH->geo_output[index]=geo_tmp; + h5GH->do_output[index] =1; + } + } + } + else { + h5GH->geo_output[varnum]=geo_tmp; + h5GH->do_output[varnum] =1; + } + } + } + + if (before) free(before); + if (after) free(after); + if(splitstring != var_list) + { + free(splitstring); + } + +} -- cgit v1.2.3