diff options
Diffstat (limited to 'src/ParseGeometry.c')
-rw-r--r-- | src/ParseGeometry.c | 347 |
1 files changed, 0 insertions, 347 deletions
diff --git a/src/ParseGeometry.c b/src/ParseGeometry.c deleted file mode 100644 index 2241f6c..0000000 --- a/src/ParseGeometry.c +++ /dev/null @@ -1,347 +0,0 @@ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "cctk.h" -#include "cctk_Arguments.h" -#include "cctk_Parameters.h" -#include "cctk_GNU.h" -#include "util_String.h" - -#include "StreamedHDF5GH.h" - -/* Do not apply the USE marcro, parser will get confused - by curly braces in quoted strings */ - -/* CCTK_NO_AUTOUSE_MACRO */ - -/*$#define HEAVYDEBUG$*/ - - -int GeometryParserH5stream(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; - const char *token=NULL; - char *dim_s=NULL, *ori_s=NULL, *dir_s=NULL; - char *len_s=NULL, *down_s=NULL; - - int dim = 0, idim, iidim; - int index; - - char info[8000]; - - /* Debugging switches */ - if (CCTK_Equals(h5verbose,"debug")) { - deb =1; - verb =1; - } - if (CCTK_Equals(h5verbose,"yes")) - verb =1; - - sprintf(info,"\n\nHDF5stream GeometryParser \nargument: >%s<\n",before); - - if((matched = CCTK_RegexMatch(before, - "([A-Za-z][A-Za-z0-9_]*::[A-Za-z][A-Za-z0-9_]*)\\[?(.*)?\\]?", 3, pmatch)) != 0) { - if (matched<0) CCTK_WARN(1,"Error matching in GeometryParser"); -#ifdef HEAVYDEBUG - printf("matched %d rm_so/rm_eo: %d %d; %d %d\n", - matched, - (int)pmatch[1].rm_so,(int)pmatch[1].rm_eo, - (int)pmatch[2].rm_so,(int)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)); - } - else - { - sprintf(info,"%sOUTNAME : no appropriate gridfunction found:>%s< \n", - info,*outname); - geo->vdim = -1; - } - } - else - { - CCTK_WARN(1,"No variable name found in StreamedHDF5::out_vars"); - retval = -1; - return(retval); - } - - 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; - return(retval); - } - - /* 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< (Use default)\n", - info,dir_s); - } - 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;iidim<geo->vdim;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;iidim<dim;iidim++) - geo->length[iidim] = geo->length[0]; - ierr = 0; - } - } - if (ierr<0) { - sprintf(info,"%sLENGTH: dimension not consistent: >%s< (Use Default)\n", - info,len_s); - } - 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;iidim<dim;iidim++) - geo->downs[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); - } - - if (verb) { - 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;idim<geo->vdim;idim++) - sprintf(info,"%s %d ",info,geo->origin[idim]); - sprintf(info,"%s\n Downs : ",info); - for (idim=0;idim<geo->sdim;idim++) - sprintf(info,"%s %d ",info,geo->downs[idim]); - sprintf(info,"%s\n Length: ",info); - for (idim=0;idim<geo->sdim;idim++) - sprintf(info,"%s %d ",info,geo->length[idim]); - sprintf(info,"%s\n Dirs : ",info); - for (idim=0;idim<geo->sdim;idim++) - sprintf(info,"%s %d ",info,geo->direction[idim]); - sprintf(info,"%s\n\n",info); - - printf("%s",info); - } - - USE_CCTK_PARAMETERS - - return(retval); -} - -void SetDefaultGeoH5stream(StreamGeo_t *geo) { - DECLARE_CCTK_PARAMETERS - - int idim; - const char *argument, *token; - - geo->vdim = -1; - geo->sdim = slabdim; - - /* 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;idim<STREAM_MAXDIM;idim++) { - geo->direction[idim] = idim; - geo->origin[idim] = 0; - geo->length[idim] =-1; - geo->downs[idim] = 1; - } - - USE_CCTK_PARAMETERS -} - |