NEURON
hocusr.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 
3 /* version 7.2.1 2-jan-89 */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include "hocdec.h"
7 #include "parse.hpp"
8 #if 1
9 #include "hocusr.h"
10 #endif
11 
12 #define CHECK(name) nrn_load_name_check(name)
13 
14 
15 static char CHKmes[] = "The user defined name, %s, already exists.\n";
16 
18 
19 /* Return 0 if nrn_load_dll_called_ == NULL, otherwise recover and return 1.
20  If 1 is returned, then can recover with a hoc_execerror.
21 */
24  /* recoverable error for nrn_load_dll interpreter call */
28  return 1;
29  }
30  return 0;
31 }
32 
33 void nrn_load_name_check(const char* name) {
34  if (hoc_lookup(name) != (Symbol*) 0) {
36  hoc_execerror("The user defined name already exists:", name);
37  } else {
38  fprintf(stderr, CHKmes, name);
39  nrn_exit(1);
40  }
41  }
42 }
43 
44 
45 static void arayinstal(Symbol* sp, int nsub, int sub1, int sub2, int sub3);
46 
47 extern "C" void hoc_spinit(void) /* install user variables and functions */
48 {
49  int i;
50  Symbol* s;
51 
53  for (i = 0; scint[i].name; i++) {
54  CHECK(scint[i].name);
55  s = hoc_install(scint[i].name, UNDEF, 0.0, &hoc_symlist);
56  s->type = VAR;
57  s->u.pvalint = scint[i].pint;
58  s->subtype = USERINT;
59  }
60  for (i = 0; scfloat[i].name; i++) {
61  CHECK(scfloat[i].name);
62  s = hoc_install(scfloat[i].name, UNDEF, 0.0, &hoc_symlist);
63  s->type = VAR;
64  s->u.pvalfloat = scfloat[i].pfloat;
65  s->subtype = USERFLOAT;
66  }
67  for (i = 0; vint[i].name; i++) {
68  CHECK(vint[i].name);
69  s = hoc_install(vint[i].name, UNDEF, 0.0, &hoc_symlist);
70  s->type = VAR;
71  arayinstal(s, 1, vint[i].index1, 0, 0);
72  s->u.pvalint = vint[i].pint;
73  s->subtype = USERINT;
74  }
75  for (i = 0; vfloat[i].name; i++) {
76  CHECK(vfloat[i].name);
77  s = hoc_install(vfloat[i].name, UNDEF, 0.0, &hoc_symlist);
78  s->type = VAR;
79  arayinstal(s, 1, vfloat[i].index1, 0, 0);
80  s->u.pvalfloat = vfloat[i].pfloat;
81  s->subtype = USERFLOAT;
82  }
83  for (i = 0; ardoub[i].name; i++) {
84  CHECK(ardoub[i].name);
85  s = hoc_install(ardoub[i].name, UNDEF, 0.0, &hoc_symlist);
86  s->type = VAR;
87  arayinstal(s, 2, ardoub[i].index1, ardoub[i].index2, 0);
88  s->u.pval = ardoub[i].pdoub;
89  s->subtype = USERDOUBLE;
90  }
91  for (i = 0; thredim[i].name; i++) {
92  CHECK(thredim[i].name);
93  s = hoc_install(thredim[i].name, UNDEF, 0.0, &hoc_symlist);
94  s->type = VAR;
96  s->u.pval = thredim[i].pdoub;
97  s->subtype = USERDOUBLE;
98  }
99  for (i = 0; functions[i].name; i++) {
100  if (!strncmp(functions[i].name, "init", 4)) {
102  (*functions[i].func)();
103  continue;
104  }
105  }
106  hoc_last_init();
107 }
108 
110  int i;
111  Symbol* s;
112 
113  if (scdoub)
114  for (i = 0; scdoub[i].name; i++) {
115  CHECK(scdoub[i].name);
116  s = hoc_install(scdoub[i].name, UNDEF, 0.0, &hoc_symlist);
117  s->type = VAR;
118  s->u.pval = scdoub[i].pdoub;
119  s->subtype = USERDOUBLE;
120  }
121  if (vdoub)
122  for (i = 0; vdoub[i].name; i++) {
123  CHECK(vdoub[i].name);
124  s = hoc_install(vdoub[i].name, UNDEF, 0.0, &hoc_symlist);
125  s->type = VAR;
126  arayinstal(s, 1, vdoub[i].index1, 0, 0);
127  s->u.pval = vdoub[i].pdoub;
128  s->subtype = USERDOUBLE;
129  }
130  if (fn)
131  for (i = 0; fn[i].name; i++) {
132  CHECK(fn[i].name);
133  s = hoc_install(fn[i].name, FUN_BLTIN, 0.0, &hoc_symlist);
134  s->u.u_proc->defn.pf = fn[i].func;
135  s->u.u_proc->nauto = 0;
136  s->u.u_proc->nobjauto = 0;
137  }
138 }
139 
140 /* set up arayinfo */
141 static void arayinstal(Symbol* sp, int nsub, int sub1, int sub2, int sub3) {
142  sp->type = VAR;
143  sp->s_varn = 0;
144  sp->arayinfo = (Arrayinfo*) emalloc((unsigned) (sizeof(Arrayinfo) + nsub * sizeof(int)));
145  sp->arayinfo->a_varn = (unsigned*) 0;
146  sp->arayinfo->nsub = nsub;
147  sp->arayinfo->sub[0] = sub1;
148  if (nsub > 1)
149  sp->arayinfo->sub[1] = sub2;
150  if (nsub > 2)
151  sp->arayinfo->sub[2] = sub3;
152 }
153 
154 extern "C" void hoc_retpushx(double x) { /* utility return for user functions */
155  hoc_ret();
156  hoc_pushx(x);
157 }
static DoubScal scdoub[]
Definition: eion.cpp:33
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:754
void nrn_exit(int)
Definition: hoc.cpp:219
void hoc_last_init(void)
Definition: init.cpp:302
void hoc_spinit(void)
Definition: hocusr.cpp:47
Symbol * hoc_install(const char *, int, double, Symlist **)
void hoc_register_var(DoubScal *scdoub, DoubVec *vdoub, VoidFunc *fn)
Definition: hocusr.cpp:109
void hoc_ret()
void hoc_retpushx(double x)
Definition: hocusr.cpp:154
void hoc_fake_call(Symbol *s)
Definition: code.cpp:1448
Symbol * hoc_lookup(const char *)
#define USERFLOAT
Definition: hocdec.h:95
#define USERDOUBLE
Definition: hocdec.h:93
struct Arrayinfo Arrayinfo
#define USERINT
Definition: hocdec.h:92
static struct @43 ardoub[]
int index2
Definition: hocmodl.h:26
static struct @44 thredim[]
int index3
Definition: hocmodl.h:34
static VoidFunc functions[]
Definition: hocmodl.h:4
int index1
Definition: hocmodl.h:15
static DoubVec vdoub[]
Definition: hocmodl.h:20
static struct @42 vint[]
static struct @41 scint[]
static void arayinstal(Symbol *sp, int nsub, int sub1, int sub2, int sub3)
Definition: hocusr.cpp:141
static char CHKmes[]
Definition: hocusr.cpp:15
#define CHECK(name)
Definition: hocusr.cpp:12
int nrn_load_dll_recover_error()
Definition: hocusr.cpp:22
void nrn_load_name_check(const char *name)
Definition: hocusr.cpp:33
Symlist * nrn_load_dll_called_
Definition: hocusr.cpp:17
Symlist * hoc_built_in_symlist
Definition: ivocmac.cpp:76
Symlist * hoc_symlist
void hoc_pushx(double)
#define i
Definition: md1redef.h:12
char * name
Definition: init.cpp:16
char * emalloc(unsigned n)
Definition: list.cpp:166
#define fprintf
Definition: mwprefix.h:30
unsigned * a_varn
Definition: hocdec.h:69
int nsub
Definition: hocdec.h:70
int sub[1]
Definition: hocdec.h:72
double * pdoub
Definition: hocdec.h:256
const char * name
Definition: hocdec.h:255
const char * name
Definition: hocdec.h:260
double * pdoub
Definition: hocdec.h:261
int nauto
Definition: hocdec.h:80
Inst defn
Definition: hocdec.h:76
int nobjauto
Definition: hocdec.h:81
Definition: model.h:57
Proc * u_proc
Definition: hocdec.h:145
short type
Definition: model.h:58
int * pvalint
Definition: hocdec.h:141
long subtype
Definition: model.h:59
float * pvalfloat
Definition: hocdec.h:142
union Symbol::@18 u
unsigned s_varn
Definition: hocdec.h:158
double * pval
Definition: hocdec.h:137
Arrayinfo * arayinfo
Definition: hocdec.h:159
Definition: hocdec.h:84
const char * name
Definition: hocdec.h:250
void(* func)(void)
Definition: hocdec.h:251
Pfrv pf
Definition: hocdec.h:52