summaryrefslogtreecommitdiff
path: root/src/main/CreateGroup.c
blob: 8157505c711c268d738c53023b3608831476d4cf (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
 /*@@
   @file      CreateGroup.c
   @date      Thu Jan 14 11:17:00 1999
   @author    Tom Goodale
   @desc 
   
   @enddesc 
 @@*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

#include "flesh.h"
#include "Misc.h"

cGroupDefinition *CCTK_SetupGroup(const char *implementation, const char *group_name, int n_variables);


 /*@@
   @routine    CCTK_CreateGroup
   @date       Thu Jan 14 15:25:54 1999
   @author     Tom Goodale
   @desc 
   
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
int CCTK_CreateGroup(const char *fullname,
		     const char *gtype,
		     const char *vtype,
		     int dimension,
		     int n_variables,
		     ...)
{
  int retval;

  va_list ap;
  char *position;
  char *implementation;
  char *group_name;

  char *variable_name;

  cGroupDefinition *group;

  int variable;

  /* Find the name of the implementation and of the group. */
  CCTK_SplitString(&implementation, &group_name, fullname, "::");

  if(implementation)
  {
    /* Allocate storage for the group and setup some stuff. */
    if((group = CCTK_SetupGroup(implementation, group_name, n_variables)))
    {
      group->dim = dimension;
      group->gtype = CCTK_GTypeNumber(gtype);
      group->vtype = CCTK_VTypeNumber(vtype);

      /* Extract the variable names from the argument list. */
      va_start(ap, n_variables);

      for(variable = 0; variable < n_variables; variable++)
      {
	variable_name = va_arg(ap, char *);

	group->variables[variable].name = (char *)malloc((strlen(variable_name)+1*sizeof(char)));
	
	if(group->variables[variable].name)
	{
	  strcpy(group->variables[variable].name, variable_name);
	}
	else
	{
	  break;
	}
      }

      va_end(ap);

      if(variable < n_variables)
      {
	retval = 3;
      };
    }
    else
    {
      retval = 2;
    }
  }
  else
  {
    retval = 1;
  }

  if(retval)
  {
    fprintf(stderr, "Error %d in CCTK_CreateGroup\n", retval);
  }

  return retval;

}


/* Need to define constants for all these. */

int CCTK_GTypeNumber(const char *type)
{
  int retval;

  if(!strcmp(type, "SCALAR"))
  {
    retval = 1;
  }

  if(!strcmp(type, "GF"))
  {
    retval = 2;
  }

  if(!strcmp(type, "ARRAY"))
  {
    retval = 3;
  }

  return retval;
}

int CCTK_VTypeNumber(const char *type)
{
  int retval;

  if(!strcmp(type, "INTEGER"))
  {
    retval = 1;
  }

  if(!strcmp(type, "REAL"))
  {
    retval = 2;
  }

  if(!strcmp(type, "LOGICAL"))
  {
    retval = 3;
  }

  if(!strcmp(type, "COMPLEX"))
  {
    retval = 4;
  }

  return retval;
}