NEURON
init.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.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  const char* name;
15  short kval;
16 } keywords[] = {{"VERBATIM", VERBATIM},
17  {"COMMENT", COMMENT},
18  {"TITLE", MODEL},
19  {"CONSTANT", CONSTANT},
20  {"PARAMETER", PARAMETER},
21  {"INDEPENDENT", INDEPENDENT},
22  {"ASSIGNED", DEPENDENT},
23  {"INITIAL", INITIAL1},
24  {"DERIVATIVE", DERIVATIVE},
25  {"EQUATION", EQUATION},
26  {"BREAKPOINT", BREAKPOINT},
27  {"CONDUCTANCE", CONDUCTANCE},
28  {"SOLVE", SOLVE},
29  {"STATE", STATE},
30  {"LINEAR", LINEAR},
31  {"NONLINEAR", NONLINEAR},
32  {"DISCRETE", DISCRETE},
33  {"FUNCTION", FUNCTION1},
34  {"FUNCTION_TABLE", FUNCTION_TABLE},
35  {"PROCEDURE", PROCEDURE},
36  {"INT", INT},
37  {"DEL2", DEL2},
38  {"DEL", DEL},
39  {"LOCAL", LOCAL},
40  {"METHOD", USING},
41  {"STEADYSTATE", USING},
42  {"STEP", STEP},
43  {"WITH", WITH},
44  {"FROM", FROM},
45  {"TO", TO},
46  {"BY", BY},
47  {"if", IF},
48  {"else", ELSE},
49  {"while", WHILE},
50  {"START", START1},
51  {"DEFINE", DEFINE1},
52  {"KINETIC", KINETIC},
53  {"CONSERVE", CONSERVE},
54  {"VS", VS},
55  {"LAG", LAG},
56  {"SWEEP", SWEEP},
57  {"COMPARTMENT", COMPARTMENT},
58  {"LONGITUDINAL_DIFFUSION", LONGDIFUS},
59  {"SOLVEFOR", SOLVEFOR},
60  {"UNITS", UNITS},
61  {"UNITSON", UNITSON},
62  {"UNITSOFF", UNITSOFF},
63  {"TABLE", TABLE},
64  {"DEPEND", DEPEND},
65  {"NEURON", NEURON},
66  {"SUFFIX", SUFFIX},
67  {"POINT_PROCESS", SUFFIX},
68  {"ARTIFICIAL_CELL", SUFFIX},
69  {"NONSPECIFIC_CURRENT", NONSPECIFIC},
70  {"ELECTRODE_CURRENT", ELECTRODE_CURRENT},
71  {"RANGE", RANGE},
72  {"USEION", USEION},
73  {"READ", READ},
74  {"WRITE", WRITE},
75  {"VALENCE", VALENCE},
76  {"CHARGE", VALENCE},
77  {"GLOBAL", GLOBAL},
78  {"POINTER", POINTER},
79  {"BBCOREPOINTER", BBCOREPOINTER},
80  {"EXTERNAL", EXTERNAL},
81  {"INCLUDE", INCLUDE1},
82  {"CONSTRUCTOR", CONSTRUCTOR},
83  {"DESTRUCTOR", DESTRUCTOR},
84  {"NET_RECEIVE", NETRECEIVE},
85  {"BEFORE", BEFORE}, /* before NEURON sets up cy' = f(y,t) */
86  {"AFTER", AFTER}, /* after NEURON solves cy' = f(y, t) */
87  {"WATCH", WATCH},
88  {"FOR_NETCONS", FOR_NETCONS},
89  {"THREADSAFE", THREADSAFE},
90  {"PROTECT", PROTECT},
91  {"MUTEXLOCK", NRNMUTEXLOCK},
92  {"MUTEXUNLOCK", NRNMUTEXUNLOCK},
93  {"REPRESENTS", REPRESENTS},
94  {"RANDOM", RANDOM},
95  {0, 0}};
96 
97 /*
98  * the following special output tokens are used to make the .c file barely
99  * readable
100  */
101 static struct { /* special output tokens */
102  const char* name;
103  short subtype;
105 } special[] = {{";", SEMI, &semi}, {"{", BEGINBLK, &beginblk}, {"}", ENDBLK, &endblk}, {0, 0, 0}};
106 
107 static struct { /* numerical methods */
108  const char* name;
109  long subtype; /* All the types that will work with this */
110  short varstep;
111 } methods[] = {{"runge", DERF | KINF, 0},
112  {"euler", DERF | KINF, 0},
113  {"newton", NLINF, 0},
114  {"simeq", LINF, 0},
115  {"_advance", KINF, 0},
116  {"sparse", KINF, 0},
117  {"derivimplicit", DERF, 0}, /* name hard wired in deriv.c */
118  {"cnexp", DERF, 0}, /* see solve.c */
119  {"after_cvode", 0, 0},
120  {"cvode_t", 0, 0},
121  {"cvode_t_v", 0, 0},
122  {0, 0, 0}};
123 
124 static const char* extdef[] = {/* external names that can be used as doubles
125  * without giving an error message */
126 #include "extdef.h"
127  0};
128 
129 static const char* extdef2[] = {/* external function names that can be used
130  * with array and function name arguments */
131 #include "extdef2.h"
132  0};
133 
134 static const char* extdef3[] = {/* function names that get two reset arguments
135  * added */
136  "threshold",
137  "squarewave",
138  "sawtooth",
139  "revsawtooth",
140  "ramp",
141  "pulse",
142  "perpulse",
143  "step",
144  "perstep",
145  "stepforce",
146  "schedule",
147  0};
148 
149 static const char* extdef4[] = {/* functions that need a first arg of NrnThread* */
150  "at_time",
151  0};
152 
153 static const char* extdef5[] = {/* the extdef names that are not threadsafe */
154 #include "extdef5.h"
155  0};
156 
157 /* random to nrnran123 functions */
158 std::map<std::string, const char*> extdef_rand = {
159  {"random_setseq", "nrnran123_setseq"},
160  {"random_setids", "nrnran123_setids"},
161  {"random_uniform", "nrnran123_uniform"},
162  {"random_negexp", "nrnran123_negexp"},
163  {"random_normal", "nrnran123_normal"},
164  {"random_ipick", "nrnran123_ipick"},
165  {"random_dpick", "nrnran123_dblpick"},
166 };
167 
169 
170 void init() {
171  int i;
172  Symbol* s;
173 
174  symbol_init();
175  for (i = 0; keywords[i].name; i++) {
177  s->subtype = KEYWORD;
178  }
179  for (i = 0; methods[i].name; i++) {
180  s = install(methods[i].name, METHOD);
181  s->subtype = methods[i].subtype;
182  s->u.i = methods[i].varstep;
183  }
184  for (i = 0; special[i].name; i++) {
185  s = install(special[i].name, SPECIAL);
186  *(special[i].p) = s;
187  s->subtype = special[i].subtype;
188  }
189  for (i = 0; extdef[i]; i++) {
190  s = install(extdef[i], NAME);
191  s->subtype = EXTDEF;
192  }
193  for (i = 0; extdef2[i]; i++) {
194  s = install(extdef2[i], NAME);
195  s->subtype = EXTDEF2;
196  }
197  for (i = 0; extdef3[i]; i++) {
198  s = lookup(extdef3[i]);
199  assert(s && (s->subtype & EXTDEF));
200  s->subtype |= EXTDEF3;
201  }
202  for (i = 0; extdef4[i]; i++) {
203  s = lookup(extdef4[i]);
204  assert(s && (s->subtype & EXTDEF));
205  s->subtype |= EXTDEF4;
206  }
207  for (i = 0; extdef5[i]; i++) {
208  s = lookup(extdef5[i]);
209  assert(s);
210  s->subtype |= EXTDEF5;
211  }
212  for (auto it: extdef_rand) {
213  s = install(it.first.c_str(), NAME);
214  s->subtype = EXTDEF_RANDOM;
215  }
216  intoken = newlist();
217  initfunc = newlist();
218  modelfunc = newlist();
219  termfunc = newlist();
220  procfunc = newlist();
221  initlist = newlist();
222  firstlist = newlist();
223  syminorder = newlist();
224  plotlist = newlist();
227  nrninit();
228 }
#define INT
Definition: bbslsrv.cpp:7
#define i
Definition: md1redef.h:19
#define STEP
Definition: errcodes.h:33
#define RANGE
Definition: errcodes.h:62
#define EXTDEF4
Definition: modl.h:206
#define EXTDEF5
Definition: modl.h:207
std::map< std::string, const char * > extdef_rand
Definition: init.cpp:158
char buf[512]
Definition: init.cpp:13
#define EXTDEF2
Definition: modl.h:202
Symbol * semi
Definition: init.cpp:11
List * intoken
Definition: init.cpp:12
#define EXTDEF3
Definition: modl.h:204
#define EXTDEF_RANDOM
Definition: modl.h:208
@ EXTERNAL
type of ast::External
@ ELECTRODE_CURRENT
type of ast::ElectrodeCurrent
@ GLOBAL
type of ast::Global
@ MODEL
type of ast::Model
@ POINTER
type of ast::Pointer
@ VERBATIM
type of ast::Verbatim
@ USEION
type of ast::Useion
@ VALENCE
type of ast::Valence
@ SUFFIX
type of ast::Suffix
@ NONSPECIFIC
type of ast::Nonspecific
@ CONSERVE
type of ast::Conserve
@ WATCH
type of ast::Watch
@ COMPARTMENT
type of ast::Compartment
#define assert(ex)
Definition: hocassrt.h:24
#define STATE
Definition: membfunc.hpp:65
#define DERF
Definition: model.h:114
#define LINF
Definition: model.h:115
#define ENDBLK
Definition: model.h:113
#define SPECIAL
Definition: model.h:89
#define EXTDEF
Definition: model.h:119
#define KINF
Definition: model.h:120
#define BEGINBLK
Definition: model.h:112
#define SEMI
Definition: model.h:111
#define KEYWORD
Definition: model.h:102
Symbol * lookup(const char *)
#define NRN_BUFSIZE
Definition: model.h:6
#define NLINF
Definition: model.h:116
Symbol * install(const char *, int)
void init()
Definition: init.cpp:141
List * plotlist
Definition: init.cpp:9
List * initfunc
Definition: init.cpp:8
List * procfunc
Definition: init.cpp:9
Symbol * beginblk
Definition: init.cpp:11
List * firstlist
Definition: init.cpp:8
Symbol ** p
Definition: init.cpp:108
List * syminorder
Definition: init.cpp:10
const char * name
Definition: init.cpp:16
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:107
List * modelfunc
Definition: init.cpp:8
short varstep
Definition: init.cpp:117
void symbol_init()
Definition: symbol.cpp:14
List * newlist()
The following routines support the concept of a list.
@ ELSE
else sub-block
void nrninit()
Definition: nocpout.cpp:193
List * destructorfunc
Definition: init.cpp:168
static const char * extdef3[]
Definition: init.cpp:134
static const char * extdef5[]
Definition: init.cpp:153
List * constructorfunc
Definition: init.cpp:168
static const char * extdef2[]
Definition: init.cpp:129
static struct @31 methods[]
static const char * extdef[]
Definition: init.cpp:124
static struct @29 keywords[]
static struct @30 special[]
static const char * extdef4[]
Definition: init.cpp:149
NMODL parser global flags / functions.
s
Definition: multisend.cpp:521
Definition: model.h:8
Definition: model.h:47