summaryrefslogtreecommitdiff
path: root/src/main/SetParams.c
blob: 461f64714c82d885cecbb7b7a7160ef86b43c99d (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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*@@
   @file      SetParams.c
   @date      Tue Jan 12 19:16:38 1999
   @author    Tom Goodale
   @desc 
   
   @enddesc 
   @version $Header$
 @@*/

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

/* FIXME - remove this when ActiveThorns doesn't need it */
#include "SKBinTree.h"

#include "cctk_Types.h"
#include "cctki_ActiveThorns.h"
#include "cctk_ActiveThorns.h"
#include "cctk_WarnLevel.h"
#include "cctk_Misc.h"
#include "cctk_Flesh.h"
#include "cctk_Parameter.h"

#include "cctki_Parameter.h"

#include "ParameterBindings.h"

static char *rcsid = "$Header$";

CCTK_FILEVERSION(main_SetParams_c)

/********************************************************************
 *********************     Local Data Types   ***********************
 ********************************************************************/

/********************************************************************
 ********************* Local Routine Prototypes *********************
 ********************************************************************/

static int ReallySetParameter(const char *parameter, 
                              const char *value);

/********************************************************************
 ********************* Other Routine Prototypes *********************
 ********************************************************************/

/********************************************************************
 *********************     Local Data   *****************************
 ********************************************************************/

/********************************************************************
 *********************     External Routines   **********************
 ********************************************************************/

 /*@@
   @routine    CCTKi_SetParameter
   @date       Tue Jan 12 19:25:37 1999
   @author     Tom Goodale
   @desc 
   
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 
   @var     parameter
   @vdesc   Name of a parameter
   @vtype   const char *
   @vio     in
   @vcomment 
 
   @endvar 
   @var     value
   @vdesc   Value of the parameter
   @vtype   const char *
   @vio     in
   @vcomment 
 
   @endvar 

   @returntype int
   @returndesc
   0  - success
   -1 - unknown parameter
   -? - other error
   @endreturndesc
@@*/
int CCTKi_SetParameter(const char *parameter, const char *value)
{
  int retval;
  char thornname[101];
  const char *position;
  int length;
  int n_errors;
  
  retval = 0;
  
  if(CCTK_Equals(parameter, "ActiveThorns"))
  {
    n_errors = 0;
    position = value;

    while(*position)
    {
      length=0;
      
      for(;*position && *position != ' ';position++)
      {
        thornname[length] = *position;
        if(length < 100) length++;
      }
      
      if (length > 0)
      {
        thornname[length] = '\0';
        n_errors += CCTKi_ActivateThorn(thornname) != 0;
      }
      if(*position) position++;

    }
    
    if(n_errors)
    {
      CCTK_Warn(0,__LINE__,__FILE__,"Cactus",
                "CCTKi_SetParameter: Errors while activating thorns\n");
    }
  }
  else
  {     
    retval = ReallySetParameter(parameter, value); 
  }
  
  if(retval)
  {
    if(retval == -1)
    {
      fprintf(stderr, "Unknown parameter %s\n", parameter);
    }
    else
    {
      fprintf(stderr, "Error setting parameter %s to %s\n", parameter, value);
    }
  }

  return retval;
}

/********************************************************************
 *********************     Local Routines   *************************
 ********************************************************************/


 /*@@
   @routine    ReallySetParameter
   @date       Tue Jan 12 19:25:37 1999
   @author     Tom Goodale
   @desc 
   Really sets the parameter value.
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 
   @var     parameter
   @vdesc   Name of a parameter
   @vtype   const char *
   @vio     in
   @vcomment 
 
   @endvar 
   @var     value
   @vdesc   Value of the parameter
   @vtype   const char *
   @vio     in
   @vcomment 
 
   @endvar 

   @returntype int
   @returndesc
   0  - success
   -1 - unknown parameter
   @endreturndesc
@@*/
static int ReallySetParameter(const char *parameter, const char *value)
{
  int retval;
  const char *thorn;
  char *param;
  char *imp;

  int retval_imp;
  int retval_thorn;


  Util_SplitString(&imp, &param, parameter, "::");

  retval = -1;

  /* If param is null, there were no colons in the input */
  if(!param)
  {
    retval = CCTK_ParameterSet(parameter, imp, value);
  }
  else
  {
    /* Set if this is an implementation one */
    if(CCTK_IsImplementationActive(imp))
    {
      thorn = CCTK_ActivatingThorn(imp);
      retval_imp = CCTK_ParameterSet(param, thorn, value);
    }
    else
    {
      thorn = NULL;
      retval_imp = -1;
    }


    /* Set if this is a thorn one. */
    if(!thorn || !CCTK_Equals(thorn,imp))
    {
      if(CCTK_IsThornActive(imp))
      {
        retval_thorn = CCTK_ParameterSet(param, imp, value);
      }
      else
      {
        retval_thorn = -1;
      }
    }
    else
    {
      /* Don't need to set it twice if the name of the imp is the same as the thorn providing it */
      retval_thorn = retval_imp;
    }

    if(!retval_imp || !retval_thorn)
    {
      retval = 0;
    }
    else
    {
      retval = retval_imp ? retval_imp : retval_thorn;
    }
  }

  /* Free any allocated memory. */
  free(imp);
  free(param);

  return retval;
}