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  Symbol* s;
55 
56  s = lookup(name);
57  if (s) {
59  Unit_push(unit);
60  if (!unit_cmp_exact()) {
61  Sprintf(
62  buf, "%s must have the units, %s, instead of %s.\n", name, unit, decode_units(s));
63  diag(buf, (char*) 0);
64  }
65  unit_pop();
66  unit_pop();
67  }
68 }
69 
70 void nrn_list(Item* qtype, Item* qlist) {
71  List** plist;
72  Item* q;
73 
74  switch (SYM(qtype)->type) {
75  case NONSPECIFIC:
76  case ELECTRODE_CURRENT:
77  plist = &current;
78  break;
79  case SUFFIX:
80  plist = (List**) 0;
81  if (strcmp(SYM(qtype)->name, "POINT_PROCESS") == 0) {
82  point_process = 1;
83  }
84  if (strcmp(SYM(qtype)->name, "ARTIFICIAL_CELL") == 0) {
85  point_process = 1;
86  }
87  break;
88  default:
89  plist = (List**) 0;
90  break;
91  }
92  if (plist && qlist) {
93  ITERATE(q, qlist) {
94  Lappendsym(*plist, SYM(q));
95  }
96  }
97 }
98 
99 void nrn_use(Item* qion, Item* qreadlist, Item* qwritelist) {
100  int i;
101  List* l;
102  Item* q;
103  Symbol* ion;
104 
105  ion = SYM(qion);
106  for (i = 0; i < 2; i++) {
107  if (i == 0) {
108  l = (List*) qreadlist;
109  } else {
110  l = (List*) qwritelist;
111  }
112  if (l)
113  ITERATE(q, l) {
114  switch (iontype(SYM(q)->name, ion->name)) {
115  case IONCUR:
116  Lappendsym(current, SYM(q));
117  break;
118  case IONEREV:
120  break;
121  case IONIN:
122  case IONOUT:
123  Lappendsym(concen, SYM(q));
124  break;
125  }
126  }
127  }
128 }
129 
130 static int iontype(char* s1, char* s2) /* returns index of variable in ion mechanism */
131 {
132  Sprintf(buf, "i%s", s2);
133  if (strcmp(buf, s1) == 0) {
134  return IONCUR;
135  }
136  Sprintf(buf, "e%s", s2);
137  if (strcmp(buf, s1) == 0) {
138  return IONEREV;
139  }
140  Sprintf(buf, "%si", s2);
141  if (strcmp(buf, s1) == 0) {
142  return IONIN;
143  }
144  Sprintf(buf, "%so", s2);
145  if (strcmp(buf, s1) == 0) {
146  return IONOUT;
147  }
148  Sprintf(buf, "%s is not a valid ionic variable for %s", s1, s2);
149  diag(buf, (char*) 0);
150  return -1;
151 }
152 
153 #endif /*NRNUNIT*/
short type
Definition: cabvars.h:9
#define diag(s)
Definition: fmenu.cpp:192
char buf[512]
Definition: init.cpp:13
#define i
Definition: md1redef.h:12
char * decode_units(Symbol *)
#define ITERATE(itm, lst)
Definition: model.h:25
#define SYM(q)
Definition: model.h:86
#define Sprintf
Definition: model.h:233
#define Lappendsym
Definition: model.h:244
char * name
Definition: init.cpp:16
List * newlist()
Definition: list.cpp:47
#define SUFFIX
Definition: units.cpp:63
int unit_cmp_exact()
Definition: units.cpp:416
void nrn_unit_chk()
void unit_pop()
Definition: units.cpp:212
void Unit_push(char *)
Definition: units.cpp:277
void nrn_list(Item *, Item *)
Definition: nocpout.cpp:1711
void nrn_use(Item *q1, Item *q2, Item *q3)
size_t q
int conductance_seen_
Definition: nrnunit.cpp:17
#define IONCUR
Definition: nrnunit.cpp:6
#define IONOUT
Definition: nrnunit.cpp:9
static List * concen
Definition: nrnunit.cpp:12
#define IONEREV
Definition: nrnunit.cpp:7
static int iontype(char *, char *)
Definition: nocpout.cpp:1885
static List * potential
Definition: nrnunit.cpp:12
#define IONIN
Definition: nrnunit.cpp:8
static List * current
Definition: nrnunit.cpp:12
void nrn_unit_init()
Definition: nrnunit.cpp:19
static int point_process
Definition: nrnunit.cpp:11
static void unit_chk(char *, char *)
int breakpoint_local_seen_
Definition: nrnunit.cpp:16
#define lookup
Definition: redef.h:90
Definition: model.h:15
Definition: model.h:57
char * name
Definition: model.h:72
Definition: units.h:2