summaryrefslogtreecommitdiff
path: root/src/main/SetParams.c
blob: 2ab5011d911523395c17b90a40d811ced9ec0f62 (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
/*@@
   @file      SetParams.c
   @date      Tue Jan 12 19:16:38 1999
   @author    Tom Goodale
   @desc 
   
   @enddesc 
 @@*/

#include <stdio.h>
#include <malloc.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 "ParameterBindings.h"

static int ReallySetParameter(
   const char *parameter, 
   const char *value
   );
int CCTK_ParameterSet(
   const char *name,
   const char *thorn,
   const char *value
   );
       
static char *rcsid = "$Header$";

CCTK_FILEVERSION(main_SetParams_c)

 /*@@
   @routine    CCTKi_SetParameter
   @date       Tue Jan 12 19:25:37 1999
   @author     Tom Goodale
   @desc 
   
   @enddesc 
   @calls     
   @calledby   
   @history 
 
   @endhistory 

@@*/
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",
                "Errors while activating thorns\n");
    }
  }
  else
  {     
    /*   retval = CCTKi_BindingsParameterSet(parameter, value);*/
    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;
}

static int ReallySetParameter(const char *parameter, const char *value)
{
  int retval;
  const char *thorn;
  char *param;
  char *imp;

  int retval_imp;
  int retval_thorn;


  /*
    CCTKi_BindingsParameterHelp(optarg,"%s",stdout);
  */
 
  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;

}