NEURON
init.cpp
Go to the documentation of this file.
1 #include <../../nmodlconf.h>
2 /* /local/src/master/nrn/src/nmodl/init.c,v 4.5 1998/03/25 14:33:42 hines Exp */
3 
4 #include "modl.h"
5 #include "parse1.hpp"
6 
7 extern List* firstlist;
8 extern List* syminorder;
11 char buf[NRN_BUFSIZE]; /* volatile temporary buffer */
12 
13 static struct { /* Keywords */
14  char* name;
15  short kval;
16 } keywords[] = {"VERBATIM",
17  VERBATIM,
18  "COMMENT",
19  COMMENT,
20  "TITLE",
21  MODEL,
22  "CONSTANT",
23  CONSTANT,
24  "PARAMETER",
25  PARAMETER,
26  "INDEPENDENT",
27  INDEPENDENT,
28  "ASSIGNED",
29  DEPENDENT,
30  "INITIAL",
31  INITIAL1,
32  "TERMINAL",
33  TERMINAL,
34  "DERIVATIVE",
35  DERIVATIVE,
36  "EQUATION",
37  EQUATION,
38  "BREAKPOINT",
39  BREAKPOINT,
40  "CONDUCTANCE",
41  CONDUCTANCE,
42  "SOLVE",
43  SOLVE,
44  "STATE",
45  STATE,
46  "STEPPED",
47  STEPPED,
48  "LINEAR",
49  LINEAR,
50  "NONLINEAR",
51  NONLINEAR,
52  "DISCRETE",
53  DISCRETE,
54  "FUNCTION",
55  FUNCTION1,
56  "FUNCTION_TABLE",
57  FUNCTION_TABLE,
58  "PROCEDURE",
59  PROCEDURE,
60  "PARTIAL",
61  PARTIAL,
62  "INT",
63  INT,
64  "DEL2",
65  DEL2,
66  "DEL",
67  DEL,
68  "LOCAL",
69  LOCAL,
70  "METHOD",
71  USING,
72  "STEADYSTATE",
73  USING,
74  "SENS",
75  SENS,
76  "STEP",
77  STEP,
78  "WITH",
79  WITH,
80  "FROM",
81  FROM,
82  "FORALL",
83  FORALL1,
84  "TO",
85  TO,
86  "BY",
87  BY,
88  "if",
89  IF,
90  "else",
91  ELSE,
92  "while",
93  WHILE,
94  "START",
95  START1,
96  "DEFINE",
97  DEFINE1,
98  "KINETIC",
99  KINETIC,
100  "CONSERVE",
101  CONSERVE,
102  "PLOT",
103  PLOT,
104  "VS",
105  VS,
106  "LAG",
107  LAG,
108  "RESET",
109  RESET,
110  "MATCH",
111  MATCH,
112  "MODEL_LEVEL",
113  MODEL_LEVEL, /* inserted by merge */
114  "SWEEP",
115  SWEEP,
116  "FIRST",
117  FIRST,
118  "LAST",
119  LAST,
120  "COMPARTMENT",
121  COMPARTMENT,
122  "LONGITUDINAL_DIFFUSION",
123  LONGDIFUS,
124  "PUTQ",
125  PUTQ,
126  "GETQ",
127  GETQ,
128  "IFERROR",
129  IFERROR,
130  "SOLVEFOR",
131  SOLVEFOR,
132  "UNITS",
133  UNITS,
134  "UNITSON",
135  UNITSON,
136  "UNITSOFF",
137  UNITSOFF,
138  "TABLE",
139  TABLE,
140  "DEPEND",
141  DEPEND,
142  "NEURON",
143  NEURON,
144  "SUFFIX",
145  SUFFIX,
146  "POINT_PROCESS",
147  SUFFIX,
148  "ARTIFICIAL_CELL",
149  SUFFIX,
150  "NONSPECIFIC_CURRENT",
151  NONSPECIFIC,
152  "ELECTRODE_CURRENT",
153  ELECTRODE_CURRENT,
154  "SECTION",
155  SECTION,
156  "RANGE",
157  RANGE,
158  "USEION",
159  USEION,
160  "READ",
161  READ,
162  "WRITE",
163  WRITE,
164  "VALENCE",
165  VALENCE,
166  "CHARGE",
167  VALENCE,
168  "GLOBAL",
169  GLOBAL,
170  "POINTER",
171  POINTER,
172  "BBCOREPOINTER",
173  BBCOREPOINTER,
174  "EXTERNAL",
175  EXTERNAL,
176  "INCLUDE",
177  INCLUDE1,
178  "CONSTRUCTOR",
179  CONSTRUCTOR,
180  "DESTRUCTOR",
181  DESTRUCTOR,
182  "NET_RECEIVE",
183  NETRECEIVE,
184  "BEFORE",
185  BEFORE, /* before NEURON sets up cy' = f(y,t) */
186  "AFTER",
187  AFTER, /* after NEURON solves cy' = f(y, t) */
188  "WATCH",
189  WATCH,
190  "FOR_NETCONS",
191  FOR_NETCONS,
192  "THREADSAFE",
193  THREADSAFE,
194  "PROTECT",
195  PROTECT,
196  "MUTEXLOCK",
197  NRNMUTEXLOCK,
198  "MUTEXUNLOCK",
199  NRNMUTEXUNLOCK,
200  "REPRESENTS",
201  REPRESENTS,
202  0,
203  0};
204 
205 /*
206  * the following special output tokens are used to make the .c file barely
207  * readable
208  */
209 static struct { /* special output tokens */
210  char* name;
211  short subtype;
213 } special[] = {";", SEMI, &semi, "{", BEGINBLK, &beginblk, "}", ENDBLK, &endblk, 0, 0, 0};
214 
215 static struct { /* numerical methods */
216  char* name;
217  long subtype; /* All the types that will work with this */
218  short varstep;
219 } methods[] = {"adams",
220  DERF | KINF,
221  0,
222  "runge",
223  DERF | KINF,
224  0,
225  "euler",
226  DERF | KINF,
227  0,
228  "adeuler",
229  DERF | KINF,
230  1,
231  "heun",
232  DERF | KINF,
233  0,
234  "adrunge",
235  DERF | KINF,
236  1,
237  "gear",
238  DERF | KINF,
239  1,
240  "newton",
241  NLINF,
242  0,
243  "simplex",
244  NLINF,
245  0,
246  "simeq",
247  LINF,
248  0,
249  "seidel",
250  LINF,
251  0,
252  "_advance",
253  KINF,
254  0,
255  "sparse",
256  KINF,
257  0,
258  "derivimplicit",
259  DERF,
260  0, /* name hard wired in deriv.c */
261  "cnexp",
262  DERF,
263  0, /* see solve.c */
264  "clsoda",
265  DERF | KINF,
266  1, /* Tolerance built in to scopgear.c */
267  "after_cvode",
268  0,
269  0,
270  "cvode_t",
271  0,
272  0,
273  "cvode_t_v",
274  0,
275  0,
276  0,
277  0,
278  0};
279 
280 static char* extdef[] = {/* external names that can be used as doubles
281  * without giving an error message */
282 #include "extdef.h"
283  0};
284 
285 static char* extdef2[] = {/* external function names that can be used
286  * with array and function name arguments */
287 #include "extdef2.h"
288  0};
289 
290 static char* extdef3[] = {/* function names that get two reset arguments
291  * added */
292  "threshold",
293  "squarewave",
294  "sawtooth",
295  "revsawtooth",
296  "ramp",
297  "pulse",
298  "perpulse",
299  "step",
300  "perstep",
301  "stepforce",
302  "schedule",
303  0};
304 
305 static char* extdef4[] = {/* functions that need a first arg of NrnThread* */
306  "at_time",
307  0};
308 
309 static char* extdef5[] = {/* the extdef names that are not threadsafe */
310 #include "extdef5.h"
311  0};
312 
314 
315 void init() {
316  int i;
317  Symbol* s;
318 
319  symbol_init();
320  for (i = 0; keywords[i].name; i++) {
321  s = install(keywords[i].name, keywords[i].kval);
322  s->subtype = KEYWORD;
323  }
324  for (i = 0; methods[i].name; i++) {
325  s = install(methods[i].name, METHOD);
326  s->subtype = methods[i].subtype;
327  s->u.i = methods[i].varstep;
328  }
329  for (i = 0; special[i].name; i++) {
330  s = install(special[i].name, SPECIAL);
331  *(special[i].p) = s;
332  s->subtype = special[i].subtype;
333  }
334  for (i = 0; extdef[i]; i++) {
335  s = install(extdef[i], NAME);
336  s->subtype = EXTDEF;
337  }
338  for (i = 0; extdef2[i]; i++) {
339  s = install(extdef2[i], NAME);
340  s->subtype = EXTDEF2;
341  }
342  for (i = 0; extdef3[i]; i++) {
343  s = lookup(extdef3[i]);
344  assert(s && (s->subtype & EXTDEF));
345  s->subtype |= EXTDEF3;
346  }
347  for (i = 0; extdef4[i]; i++) {
348  s = lookup(extdef4[i]);
349  assert(s && (s->subtype & EXTDEF));
350  s->subtype |= EXTDEF4;
351  }
352  for (i = 0; extdef5[i]; i++) {
353  s = lookup(extdef5[i]);
354  assert(s);
355  s->subtype |= EXTDEF5;
356  }
357  intoken = newlist();
358  initfunc = newlist();
359  modelfunc = newlist();
360  termfunc = newlist();
361  procfunc = newlist();
362  initlist = newlist();
363  firstlist = newlist();
364  syminorder = newlist();
365  plotlist = newlist();
368 #if NMODL
369  nrninit();
370 #endif
371 }
#define EXTDEF4
Definition: modl.h:214
#define EXTDEF5
Definition: modl.h:215
#define EXTDEF2
Definition: modl.h:210
char buf[512]
Definition: init.cpp:13
Symbol * semi
Definition: init.cpp:11
List * intoken
Definition: init.cpp:12
#define EXTDEF3
Definition: modl.h:212
#define assert(ex)
Definition: hocassrt.h:32
#define i
Definition: md1redef.h:12
#define STATE
Definition: membfunc.h:71
#define DERF
Definition: model.h:125
#define LINF
Definition: model.h:126
#define ENDBLK
Definition: model.h:124
#define SPECIAL
Definition: model.h:100
#define EXTDEF
Definition: model.h:131
#define KINF
Definition: model.h:132
#define BEGINBLK
Definition: model.h:123
#define SEMI
Definition: model.h:122
#define KEYWORD
Definition: model.h:113
#define NRN_BUFSIZE
Definition: model.h:13
#define NLINF
Definition: model.h:127
NMODL parser global flags / functions.
void init()
Definition: init.cpp:291
List * plotlist
Definition: init.cpp:9
List * initfunc
Definition: init.cpp:8
List * procfunc
Definition: init.cpp:9
char * name
Definition: init.cpp:16
Symbol * beginblk
Definition: init.cpp:11
List * firstlist
Definition: init.cpp:8
Symbol ** p
Definition: init.cpp:216
List * syminorder
Definition: init.cpp:10
List * initlist
Definition: init.cpp:8
short kval
Definition: init.cpp:17
List * termfunc
Definition: init.cpp:8
Symbol * endblk
Definition: init.cpp:11
long subtype
Definition: init.cpp:215
List * modelfunc
Definition: init.cpp:8
short varstep
Definition: init.cpp:222
List * newlist()
Definition: list.cpp:47
#define SUFFIX
Definition: units.cpp:63
void symbol_init()
Definition: symbol.cpp:13
List * destructorfunc
Definition: init.cpp:313
static char * extdef5[]
Definition: init.cpp:309
static char * extdef4[]
Definition: init.cpp:305
static struct @21 methods[]
static struct @19 keywords[]
static char * extdef[]
Definition: init.cpp:280
List * constructorfunc
Definition: init.cpp:313
static char * extdef3[]
Definition: init.cpp:290
static char * extdef2[]
Definition: init.cpp:285
static struct @20 special[]
void nrninit()
Definition: nocpout.cpp:211
#define MATCH(cond)
static int PLOT(int, int, double, double)
Definition: axis.cpp:268
#define INT
Definition: bbslsrv.cpp:7
#define lookup
Definition: redef.h:90
#define install
Definition: redef.h:82
Definition: model.h:15
Definition: model.h:57
int i
Definition: model.h:62
long subtype
Definition: model.h:59
union Symbol::@18 u