NEURON
nrnunit.cpp
Go to the documentation of this file.
1 #include <../../nmodlconf.h>
2 #include "model.h"
3 #include "units.h"
4 #include "parse1.hpp"
5 
6 #define IONCUR 0
7 #define IONEREV 1
8 #define IONIN 2
9 #define IONOUT 3
10 
11 static int point_process = 0;
13 static void unit_chk(char*, char*);
14 static int iontype(char*, char*);
15 
18 
19 void nrn_unit_init() {
20  current = newlist();
21  concen = newlist();
22  potential = newlist();
23 }
24 
25 #if NRNUNIT
26 void nrn_unit_chk() {
27  Item *q;
28 
29  unit_chk("v", "millivolt");
30  unit_chk("t", "ms");
31  unit_chk("dt", "ms");
32  unit_chk("celsius", "degC");
33  unit_chk("diam", "micron");
34  unit_chk("area", "micron2");
35 
36  if (breakpoint_local_seen_ == 0 || conductance_seen_ == 0) {
37  ITERATE(q, current) {
38  if (point_process) {
39  unit_chk(SYM(q)->name, "nanoamp");
40  }else{
41  unit_chk(SYM(q)->name, "milliamp/cm2");
42  }
43  }
44  }
45  ITERATE(q, concen) {
46  unit_chk(SYM(q)->name, "milli/liter");
47  }
48  ITERATE(q, potential) {
49  unit_chk(SYM(q)->name, "millivolt");
50  }
51 }
52 
53 static void unit_chk(char* name, char* unit)
54 {
55  Symbol *s;
56 
57  s = lookup(name);
58  if (s) {
60  Unit_push(unit);
61  if (!unit_cmp_exact()) {
62 Sprintf(buf, "%s must have the units, %s, instead of %s.\n",
63  name, unit, decode_units(s));
64  diag(buf, (char *)0);
65  }
66  unit_pop();
67  unit_pop();
68  }
69 }
70 
71 void nrn_list(Item* qtype, Item* qlist)
72 {
73  List **plist;
74  Item *q;
75 
76  switch (SYM(qtype)->type) {
77  case NONSPECIFIC:
78  case ELECTRODE_CURRENT:
79  plist = &current;
80  break;
81  case SUFFIX:
82  plist = (List **)0;
83  if (strcmp(SYM(qtype)->name, "POINT_PROCESS") == 0) {
84  point_process = 1;
85  }
86  if (strcmp(SYM(qtype)->name, "ARTIFICIAL_CELL") == 0) {
87  point_process = 1;
88  }
89  break;
90  default:
91  plist = (List **)0;
92  break;
93  }
94  if (plist && qlist) {
95  ITERATE(q, qlist) {
96  Lappendsym(*plist, SYM(q));
97  }
98  }
99 }
100 
101 void nrn_use(Item* qion, Item* qreadlist, Item* qwritelist)
102 {
103  int i;
104  List *l;
105  Item *q;
106  Symbol *ion;
107 
108  ion = SYM(qion);
109  for (i=0; i<2; i++) {
110  if (i == 0) {
111  l = (List *)qreadlist;
112  }else{
113  l = (List *)qwritelist;
114  }
115  if (l) ITERATE(q, l) {
116  switch (iontype(SYM(q)->name, ion->name)) {
117  case IONCUR:
118  Lappendsym(current, SYM(q));
119  break;
120  case IONEREV:
121  Lappendsym(potential, SYM(q));
122  break;
123  case IONIN:
124  case IONOUT:
125  Lappendsym(concen, SYM(q));
126  break;
127  }
128  }
129  }
130 }
131 
132 static
133 int iontype(char* s1, char* s2) /* returns index of variable in ion mechanism */
134 {
135  Sprintf(buf, "i%s", s2);
136  if (strcmp(buf, s1) == 0) {
137  return IONCUR;
138  }
139  Sprintf(buf, "e%s", s2);
140  if (strcmp(buf, s1) == 0) {
141  return IONEREV;
142  }
143  Sprintf(buf, "%si", s2);
144  if (strcmp(buf, s1) == 0) {
145  return IONIN;
146  }
147  Sprintf(buf, "%so", s2);
148  if (strcmp(buf, s1) == 0) {
149  return IONOUT;
150  }
151  Sprintf(buf, "%s is not a valid ionic variable for %s", s1, s2);
152  diag(buf, (char *)0);
153  return -1;
154 }
155 
156 #endif /*NRNUNIT*/
static List * potential
Definition: nrnunit.cpp:12
Definition: units.h:2
#define Lappendsym
Definition: model.h:259
short type
Definition: cabvars.h:10
static int point_process
Definition: nrnunit.cpp:11
#define diag(s)
Definition: fmenu.cpp:188
#define ITERATE(itm, lst)
Definition: model.h:25
#define SYM(q)
Definition: model.h:86
void Unit_push(char *)
Definition: units.cpp:284
char * name
Definition: model.h:72
void nrn_unit_init()
Definition: nrnunit.cpp:19
#define SUFFIX
Definition: units.cpp:58
Definition: model.h:15
_CONST char * s
Definition: system.cpp:74
void nrn_unit_chk()
void nrn_use(Item *q1, Item *q2, Item *q3)
int breakpoint_local_seen_
Definition: nrnunit.cpp:16
static int iontype(char *, char *)
Definition: nocpout.cpp:1730
Definition: model.h:57
char * name
Definition: init.cpp:16
List * newlist()
Definition: list.cpp:50
#define lookup
Definition: redef.h:90
int conductance_seen_
Definition: nrnunit.cpp:17
static List * current
Definition: nrnunit.cpp:12
static void unit_chk(char *, char *)
int unit_cmp_exact()
Definition: units.cpp:427
static List * concen
Definition: nrnunit.cpp:12
#define IONOUT
Definition: nrnunit.cpp:9
#define i
Definition: md1redef.h:12
char buf[512]
Definition: init.cpp:13
#define IONIN
Definition: nrnunit.cpp:8
void unit_pop()
Definition: units.cpp:216
void nrn_list(Item *, Item *)
Definition: nocpout.cpp:1557
#define Sprintf
Definition: model.h:248
#define IONEREV
Definition: nrnunit.cpp:7
size_t q
#define IONCUR
Definition: nrnunit.cpp:6
char * decode_units(Symbol *)