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