/*@@ @file SetupGroup.c @date Mon Feb 8 19:31:45 1999 @author Tom Goodale @desc Subroutines for setting up a group on a pGH. @enddesc @@*/ #include #include #include "cctk.h" #include "flesh.h" #include "Groups.h" #include "pugh.h" static char *rcisd = "$Header$"; pGF *SetupPGF(pGH *GH, const char *name, int dim, int varsize, int vtype); int pugh_SetupScalarGroup(pGH *newGH, int vtype, int n_variables, int n_timelevels); int pugh_SetupArrayGroup(pGH *newGH, int vtype, int dim, int n_variables, int n_timelevels); int pugh_SetupGFGroup(pGH *newGH, int vtype, int dim, int n_variables, int n_timelevels); /*@@ @routine pugh_SetupGroup @date Mon Feb 8 19:37:55 1999 @author Tom Goodale @desc Sets up a group on a pGH @enddesc @calls @calledby @history @endhistory @@*/ int pugh_SetupGroup(pGH *newGH, int gtype, int vtype, int dim, int n_variables, int n_timelevels) { int returncode; switch(gtype) { case GROUP_SCALAR : returncode = pugh_SetupScalarGroup(newGH, vtype, n_variables, n_timelevels); break; case GROUP_ARRAY : returncode = pugh_SetupArrayGroup(newGH, vtype, dim, n_variables, n_timelevels); break; case GROUP_GF : returncode = pugh_SetupGFGroup(newGH, vtype, dim, n_variables, n_timelevels); break; default : fprintf(stderr, "Unknown group type in pugh_SetupGroup\n"); returncode = 1; } return returncode; } /*@@ @routine pugh_SetupScalarGroup @date Wed Feb 17 04:45:49 1999 @author Tom Goodale @desc Set up a group of scalar variables on a pGH. @enddesc @calls @calledby @history @endhistory @@*/ int pugh_SetupScalarGroup(pGH *newGH, int vtype, int n_variables, int n_timelevels) { int variable; int var_size; int level; void ***temp; int returncode; switch(vtype) { case CCTK_VARIABLE_CHAR : var_size = sizeof(char); break; case CCTK_VARIABLE_INTEGER : var_size = sizeof(int) ; break; case CCTK_VARIABLE_REAL : var_size = sizeof(CCTK_REAL); break; case CCTK_VARIABLE_COMPLEX : var_size = sizeof(CCTK_COMPLEX); break; default : fprintf(stderr, "Unknown variable type in pugh_SetupScalarGroup\n"); var_size = 1; } temp = (void ***)realloc(newGH->variables, (newGH->nvariables+n_variables)*sizeof(void **)); if(temp) { newGH->variables = temp; for(variable = 0; variable < n_variables; variable++) { newGH->variables[newGH->nvariables] = (void **)malloc(n_timelevels*sizeof(void *)); if(newGH->variables[newGH->nvariables]) { for(level = 0; level < n_timelevels; level++) { newGH->variables[newGH->nvariables][level] = (void *)malloc(var_size); } newGH->nvariables++; } else { fprintf(stderr, "Memory error in SetupScalarGroup at line %d\n", __LINE__); break; } } } else { fprintf(stderr, "Memory error in SetupScalarGroup at line %d\n", __LINE__); } return 0; } int pugh_SetupArrayGroup(pGH *newGH, int vtype, int dim, int n_variables, int n_timelevels) { return 0; } /*@@ @routine pugh_SetupGFGroup @date Wed Feb 17 04:45:49 1999 @author Tom Goodale @desc Set up a group of GF variables on a pGH. @enddesc @calls @calledby @history @endhistory @@*/ int pugh_SetupGFGroup(pGH *newGH, int vtype, int dim, int n_variables, int n_timelevels) { int variable; int var_size; void ***temp; int returncode; int level; switch(vtype) { case CCTK_VARIABLE_CHAR : var_size = sizeof(char); break; case CCTK_VARIABLE_INTEGER : var_size = sizeof(int) ; break; case CCTK_VARIABLE_REAL : var_size = sizeof(CCTK_REAL); break; case CCTK_VARIABLE_COMPLEX : var_size = sizeof(CCTK_COMPLEX); break; default : fprintf(stderr, "Unknown variable type in pugh_SetupScalarGroup\n"); var_size = 1; } temp = (void ***)realloc(newGH->variables, (newGH->nvariables+n_variables)*sizeof(void **)); if(temp) { newGH->variables = temp; for(variable = 0; variable < n_variables; variable++) { newGH->variables[newGH->nvariables] = (void **)malloc(n_timelevels*sizeof(void *)); if(newGH->variables[newGH->nvariables]) { for(level = 0; level < n_timelevels; level++) { newGH->variables[newGH->nvariables][level] = SetupPGF(newGH, CCTK_GetVarName(newGH->nvariables), dim, var_size, vtype); } newGH->nvariables++; } } } return 0; }