aboutsummaryrefslogtreecommitdiff
path: root/src/SetupGroup.c
blob: 4290f5b7181af904352f0b5141dd2c1886914d7b (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
 /*@@
   @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);

 /*@@
   @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 returncode;
  switch(gtype)
  {
    case GROUP_SCALAR : returncode = pugh_SetupScalarGroup(newGH, 
							   vtype, 
							   n_variables); 
                        break;
    case GROUP_ARRAY  : returncode = pugh_SetupScalarGroup(newGH, 
							   vtype,
							   dim,
							   n_variables); 
                        break;
    case GROUP_GF     : returncode = pugh_SetupScalarGroup(newGH, 
							   vtype,
							   dim,
							   n_variables); 
                        break;
    default : fprintf(stderr, "Unknown group type in pugh_SetupGroup\n");
              returncode = 1;
  }

  return returncode;
}
  
int pugh_SetupScalarGroup(pGH *newGH, int vtype, int n_variables)
{
  int variable;

  int var_size;

  void **temp;

  int returncode;

  switch(vtype)
  {
    case VARIABLE_CHAR    : var_size = sizeof(char); break;
    case VARIABLE_INTEGER : var_size = sizeof(int) ; break;
    case VARIABLE_REAL    : var_size = sizeof(Double); break;
    case VARIABLE_COMPLEX : var_size = sizeof(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(var_size);

      if(newGH->variables[newGH->nvariables])
      {
	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)
{
  return 0;
}

int pugh_SetupGFGroup(pGH *newGH, int vtype, int dim, int n_variables)
{

  int variable;

  int var_size;

  void **temp;

  int returncode;

  switch(vtype)
  {
    case VARIABLE_CHAR    : var_size = sizeof(char); break;
    case VARIABLE_INTEGER : var_size = sizeof(int) ; break;
    case VARIABLE_REAL    : var_size = sizeof(Double); break;
    case VARIABLE_COMPLEX : var_size = sizeof(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] = SetupPGF(newGH, CCTK_GetVarName(n_variables), dim);
    }
  }

  return 0;
}