NEURON
discrete.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 
3 #include <stdlib.h>
4 #include "modl.h"
5 #include "parse1.hpp"
6 #include "symbol.h"
7 
8 void disc_var_seen(Item* q1, Item* q2, Item* q3, int array) /*NAME '@' NUMBER --- array flag*/
9 {
10  Symbol* s;
11  int num;
12 
13  num = atoi(STR(q3));
14  s = SYM(q1);
15  if (num < 1) {
16  diag("Discrete variable must have @index >= 1", (char*) 0);
17  }
18  num--;
19  if (!(s->subtype & STAT)) {
20  diag(s->name, "must be a STATE for use as discrete variable");
21  }
22  if (array && !(s->subtype & ARRAY)) {
23  diag(s->name, "must be a scalar discrete variable");
24  }
25  if (!array && (s->subtype & ARRAY)) {
26  diag(s->name, "must be an array discrete variable");
27  }
28  if (s->discdim <= num) {
29  s->discdim = num + 1;
30  }
31  Sprintf(buf, "__%s", s->name);
32  replacstr(q1, buf);
33  remove(q2);
34  Sprintf(buf, "[%d]", num);
35  replacstr(q3, buf);
36 }
37 
38 void massagediscblk(Item* q1, Item* q2, Item* q3, Item* q4) /*DISCRETE NAME stmtlist '}'*/
39 {
40  int i;
41  Symbol* s;
42  Item* qs;
43 
44  replacstr(q1, "void");
45  Insertstr(q3, "()\n{\n");
46  Insertstr(q4, "}\n");
47  SYM(q2)->subtype |= DISCF;
48  SYMITER(NAME) if (s->subtype & STAT && s->used && s->discdim) {
49  if (s->subtype & ARRAY) {
50  Sprintf(buf,
51  "{int _i, _j; for (_j=%d; _j >=0; _j--) {\n\
52 for (_i=%d; _i>0; _i--) __%s[_i][_j] = __%s[_i-1][_j];\n\
53  __%s[0][_j] = %s[_j];\n\
54 }}\n",
55  s->araydim - 1,
56  s->discdim - 1,
57  s->name,
58  s->name,
59  s->name,
60  s->name);
61  } else {
62  Sprintf(buf,
63  "{int _i; for (_i=%d; _i>0; _i--) __%s[_i] = __%s[_i-1];\n\
64  __%s[0] = %s;\n}\n",
65  s->discdim - 1,
66  s->name,
67  s->name,
68  s->name,
69  s->name);
70  }
71  Insertstr(q3, buf);
72  s->used = 0;
73  }
74  /*initialization and declaration done elsewhere*/
75  movelist(q1, q4, procfunc);
76 }
77 
79  int i;
80  Item* qs;
81  Symbol* s;
82  SYMITER(NAME) if (s->subtype & STAT && s->discdim) {
83  if (s->subtype & ARRAY) {
84  Sprintf(buf,
85  "{int _i, _j; for (_j=%d; _j >=0; _j--) {\n\
86 for (_i=%d; _i>=0; _i--) __%s[_i][_j] = %s0;}}\n",
87  s->araydim - 1,
88  s->discdim - 1,
89  s->name,
90  s->name);
92  Sprintf(buf, "static double __%s[%d][%d];\n", s->name, s->discdim, s->araydim);
94  } else {
95  Sprintf(buf,
96  "{int _i; for (_i=%d; _i>=0; _i--) __%s[_i] = %s0;}\n",
97  s->discdim - 1,
98  s->name,
99  s->name);
101  Sprintf(buf, "static double __%s[%d];\n", s->name, s->discdim);
103  }
104  }
105 }
#define i
Definition: md1redef.h:19
void init_disc_vars()
Definition: discrete.cpp:78
void massagediscblk(Item *q1, Item *q2, Item *q3, Item *q4)
Definition: discrete.cpp:38
void disc_var_seen(Item *q1, Item *q2, Item *q3, int array)
Definition: discrete.cpp:8
char buf[512]
Definition: init.cpp:13
#define STR(q)
Definition: model.h:76
#define STAT
Definition: model.h:106
#define DISCF
Definition: model.h:117
#define Linsertstr
Definition: model.h:220
#define Insertstr
Definition: model.h:217
#define SYM(q)
Definition: model.h:75
#define ARRAY
Definition: model.h:107
List * initfunc
Definition: init.cpp:8
List * procfunc
Definition: init.cpp:9
void movelist(Item *q1, Item *q2, List *s)
Definition: list.cpp:214
void replacstr(Item *q, const char *s)
Definition: list.cpp:219
#define SYMITER(arg1)
Definition: symbol.h:13
int Sprintf(char(&buf)[N], const char *fmt, Args &&... args)
Redirect sprintf to snprintf if the buffer size can be deduced.
Definition: wrap_sprintf.h:14
NMODL parser global flags / functions.
#define diag(s)
Definition: nonlin.cpp:19
s
Definition: multisend.cpp:521
static double remove(void *v)
Definition: ocdeck.cpp:205
Definition: model.h:8
Definition: model.h:47