aboutsummaryrefslogtreecommitdiff
path: root/src/SetupGroup.c
blob: ce3f4e3202751c30d65ee859d289b2f84e275379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
 /*@@
   @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 <stdio.h>
#include <stdlib.h>

#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(CCTK_CHAR); break;
    case CCTK_VARIABLE_INTEGER : var_size = sizeof(CCTK_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(CCTK_CHAR); break;
    case CCTK_VARIABLE_INTEGER : var_size = sizeof(CCTK_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;
}