1 #include <../../nrnconf.h>
8 #include <nrnpython_config.h>
17 #define symlist hoc_symlist
66 "prior to version 5.3 the section stack would not have been properly popped\n\
67 and the currently accessed section would have been ",
113 if (
sec->prop &&
sec->prop->dparam[0].sym) {
114 printf(
"pushsec %s\n",
sec->prop->dparam[0].sym->name);
116 printf(
"pushsec unnamed or deleted section\n");
130 if (
sec->prop &&
sec->prop->dparam[0].sym) {
131 printf(
"popsec %s\n",
sec->prop->dparam[0].sym->name);
133 printf(
"popsec unnamed or with no properties\n");
136 if (--
sec->refcount <= 0) {
138 printf(
"sec freed after pop\n");
150 static void free_point_process(
void) {
161 printf(
"clear_sectionlist not fixed yet, doing nothing\n");
165 free_point_process();
167 if (s->
type == SECTION) {
194 if (sym->
type == SECTION) {
197 for (
i = 0;
i < total; ++
i) {
206 "First time declaration of Section %s in %s "
207 "must happen at command level (not in method)",
229 printf(
" is a section name\n");
235 if (
sec->prop->dparam[6].obj) {
236 return sec->prop->dparam[6].obj;
250 if (
sec->prop->dparam[6].obj) {
251 return sec->prop->dparam[6].obj == obj;
271 prop->dparam[0].sym = sym;
272 prop->dparam[5].i =
i;
274 prop->dparam[6].obj = ob;
276 prop->dparam[6].obj =
nullptr;
291 for (
i = 0;
i < size; ++
i) {
303 sec->prop->dparam[8].itm = pitm[
i];
317 sec->prop->dparam[8].itm = itm;
330 "delete_section takes no positional arguments and deletes the HOC currently accessed "
331 "section. If using Python, did you mean a named arg of the form, sec=section?",
351 if (!
sec->prop->dparam[0].sym) {
352 hoc_execerror(
"Cannot delete an unnamed hoc section", (
char*) 0);
354 sym =
sec->prop->dparam[0].sym;
355 ob =
sec->prop->dparam[6].obj;
356 i =
sec->prop->dparam[5].i;
389 if (
sec->recalc_area_ &&
sec->npt3d) {
390 sec->prop->dparam[2].val =
sec->pt3d[
sec->npt3d - 1].arc;
392 x =
sec->prop->dparam[2].val;
394 x =
sec->prop->dparam[2].val = 1
e-9;
400 return ((
sec->prop->dparam[3].val) ? 0 : 1);
404 return sec->prop->dparam[7].val;
415 pd[1].
val = pd[3].
val = 0.;
439 if (s->
type != SECTION) {
462 execerror(
"Section access unspecified", (
char*) 0);
467 execerror(
"Accessing a deleted section", (
char*) 0);
505 if (
sec->parentsec) {
506 if (
sec->parentsec->child ==
sec) {
507 sec->parentsec->child =
sec->sibling;
510 for (s =
sec->parentsec->child; s; s = s->
sibling) {
521 if (
sec->parentsec) {
532 if (
sec->parentsec) {
534 s =
sec->parentsec->child;
537 sec->parentsec->child =
sec;
556 for (scnt = 0, ch =
sec->child; ch; ++scnt, ch = ch->
sibling) {
572 "disconnect takes no positional arguments and disconnects the HOC currently accessed "
573 "section. If using Python, did you mean a named arg of the form, sec=section? Or you "
574 "can use section.disconnect().",
585 for (
i = 0,
j =
sec->nnode - 2;
i <
j; ++
i, --
j) {
588 sec->pnode[
i]->sec_node_index_ =
i;
597 Node* oldpnode =
sec->parentnode;
618 Node* oldpnode =
sec->parentnode;
623 if (d1 != 0. && d1 != 1.) {
626 if (d2 < 0. || d2 > 1.) {
629 if (
sec->parentsec) {
632 " had previously been connected to parent %s(%g)\n",
641 pd =
sec->prop->dparam;
657 }
else if (oldpnode) {
714 printf(
"accessing %s with index %d\n", s->
name, access_index);
775 if (
n < 12 || strncmp(s,
"__nrnsec_0x", 11) != 0) {
778 if (sscanf(s + 9,
"%p", &vp) != 1) {
792 !
sec->prop->dparam[8].itm ||
sec->prop->dparam[8].itm->itemtype != SECTION) {
794 hoc_execerror(
"Section associated with internal name does not exist:", s);
796 hoc_warning(
"Section associated with internal name does not exist:", s);
826 hoc_execerror(
"section in the object was deleted", (
char*) 0);
890 for (
i =
n - 1;
i >= 0;
i--) {
894 if (
type == EXTRACELL) {
897 if (!
sec->parentsec) {
898 nd =
sec->parentnode;
936 hoc_execerror(
"Can't uninsert mechanisms when spatial method is non_zero", s->
name);
940 for (
i = 0;
i <
n; ++
i) {
941 mnext =
sec->pnode[
i]->prop;
947 for (m = mnext; m; m = mnext) {
986 for (
i = 0;
i <
n;
i++) {
1002 if (
sec->recalc_area_ && op != 0) {
1007 for (
i = 0;
i <
n;
i++) {
1015 sec->recalc_area_ = 1;
1019 if (s->
u.
rng.type == EXTRACELL) {
1020 if (s->
u.
rng.index == 0) {
1082 for (m = nd->
prop; m; m = m->
next) {
1098 "%s mechanism not inserted in section %s\n",
1137 if (s->
type == NRNPNTVAR) {
1172 if (
sec->recalc_area_ && op != 0) {
1184 sec->recalc_area_ = 1;
1189 if (s->
u.
rng.type == EXTRACELL && s->
u.
rng.index == 0) {
1197 short i, i1, i2, di;
1199 double y1, y2, x1, x2, x, dx, thet, y;
1208 hoc_execerror(
"Range variable interpolation not implemented",
1209 "for new spatial discretization methods");
1218 hoc_execerror(
"range variable notation r(x1:x2) requires",
" x1 > x2");
1226 if (x1 == 0. || x1 == 1.) {
1234 if (x2 == 1. || x2 == 0.) {
1242 for (
i = i1;
i != i2;
i += di) {
1244 x = ((double)
i + .5) / (
sec->nnode - 1);
1248 thet = (x - x1) / dx;
1249 if (thet >= -1
e-9 && thet <= 1. + 1
e-9) {
1250 y = y1 * (1. - thet) + y2 * thet;
1270 for (
i = i1;
i != i2;
i += di) {
1272 x = ((double)
i + .5) / (
sec->nnode - 1);
1276 thet = (x - x1) / dx;
1277 if (thet >= -1
e-9 && thet <= 1. + 1
e-9) {
1278 y = y1 * (1. - thet) + y2 * thet;
1287 sec->recalc_area_ = 1;
1291 if (s->
u.
rng.type == EXTRACELL && s->
u.
rng.index == 0) {
1294 if (s->
u.
rng.type == EXTRACELL) {
1295 if (x1 == 0. || x1 == 1.) {
1305 if (x2 == 1. || x2 == 0.) {
1355 "cvode.use_fast_imem(1) has not been executed so i_membrane_ does not exist", 0);
1360 if (s->
u.
rng.type == EXTRACELL) {
1397 if (s->
u.
rng.type == EXTRACELL) {
1436 "cvode.use_fast_imem(1) has not been executed so i_membrane_ does not exist", 0);
1444 if (s->
u.
rng.type == EXTRACELL) {
1476 if (x < 0. || x > 1.) {
1477 hoc_execerror(
"range variable domain is 0<=x<=1", (
char*) 0);
1484 n = (double) (
sec->nnode - 1);
1490 if (
sec->prop->dparam[3].val) {
1502 return sec->nnode - 1;
1504 }
else if (x == 1.) {
1506 return sec->nnode - 1;
1521 switch (sym->
u.
rng.type) {
1525 return (
double)
sec->nnode;
1528 return (
double)
sec->nnode - 1;
1530 return sec->prop->dparam[sym->
u.
rng.index].val;
1539 switch (sym->
u.
rng.type) {
1541 return &
sec->prop->dparam[sym->
u.
rng.index].val;
1560 fprintf(stderr,
"requesting %s.nseg=%d but the maximum value is 32767.\n",
secname(
sec),
n);
1561 hoc_warning(
"nseg too large, setting to 1.", (
char*) 0);
1571 if (
sec->nnode ==
n + 1) {
1578 int nold =
sec->nnode;
1582 sec->recalc_area_ = 1;
1592 for (
i = 0;
i <
n;
i++) {
1601 switch (sym->
u.
rng.type) {
1609 if (sym->
u.
rng.index == 2) {
1614 sec->prop->dparam[2].val = *pd;
1617 sec->recalc_area_ = 1;
1624 sec->recalc_area_ = 1;
1625 sec->prop->dparam[sym->
u.
rng.index].val = *pd;
1628 if (sym->
u.
rng.index == 7) {
1640 return sec->prop->dparam[1].val;
1645 return sec->prop->dparam[3].val;
1657 sec->parentnode->sec =
sec;
1659 if (
sec->pnode[0]->extnode) {
1668 for (psec =
sec->parentsec; psec; psec = psec->
parentsec) {
1692 for (
sec = s, psec =
sec->parentsec; psec;
sec = psec, psec =
sec->parentsec) {
1702 if (x == 1. || x == 0.) {
1710 if (true_parent == (
Section*) 0) {
1711 if (
sec->parentnode) {
1746 if (
sec->nnode < 1) {
1748 " has no segments");
1754 if (!
sec->parentsec) {
1763 for (
i = 0;
i < unconnected;
i++) {
1778 static char name[512];
1784 if (
sec->prop->dparam[0].sym) {
1785 s =
sec->prop->dparam[0].sym;
1786 indx =
sec->prop->dparam[5].i;
1787 ob =
sec->prop->dparam[6].obj;
1813 static char buf[256];
1838 static char name[200];
1841 if (
sec &&
sec->prop &&
sec->prop->dparam[0].sym) {
1842 s =
sec->prop->dparam[0].sym;
1843 indx =
sec->prop->dparam[5].i;
1844 ob =
sec->prop->dparam[6].obj;
1871 if (
sec->parentnode ==
node) {
1876 x = ((double) inode + .5) / ((double)
sec->nnode - 1.);
1896 x = (
i+1)/((
double)
n);
1899 x = (
i+.5)/((
double)
n);
1901 if (
sec->prop->dparam[3].val) {
1910 static char buf1[200];
1933 *pdx = l / ((double)
n);
1938 #define PI 3.14159265358979323846
1949 inode = (int) (x *
sec->nnode + .5);
1953 if (
sec->prop->dparam[3].val) {
1954 inode =
sec->nnode - inode;
1958 inode =
sec->parentnode;
1965 if (x <= 0. || x >= 1.) {
1966 x = (x < 0.) ? 0. : x;
1967 x = (x > 1.) ? 1. : x;
1968 if (
sec->prop->dparam[3].val) {
2004 if (s->
type == TEMPLATE) {
2029 if (s->
u.
rng.type != EXTRACELL) {
2050 if (
sec->pnode[0]->extnode) {
2068 if (m->
type == EXTRACELL && s->
u.
rng.index == 3 * (
nlayer) + 2) {
2070 if (m->
type == EXTRACELL && s->
u.
rng.index == 3 * (
nlayer) + 1) {
2072 return sec->pnode[inode]->extnode->v +
indx;
2103 if (m->
type == EXTRACELL && s->
u.
rng.index == 3 * (
nlayer) + 2) {
2105 if (m->
type == EXTRACELL && s->
u.
rng.index == 3 * (
nlayer) + 1) {
2107 return sec->pnode[inode]->extnode->v +
indx;
2126 static char buf[100];
2135 #define relative(pc) (pc + (pc)->i)
2183 for (qsec =
first; qsec != last;) {
2240 for (
p =
sec->pnode[0]->prop;
p;
p =
p->next) {
2274 static char*
buf = (
char*) 0;
2277 buf =
static_cast<char*
>(
emalloc(256 *
sizeof(
char)));
2289 size_t n = (size_t) vp;
2290 if (
sizeof(
void*) == 8) {
2291 size_t maxvoid2dbl = ((size_t) 1) << 53;
2293 printf(
"sizeof void*, size_t, and double = %zd, %zd, %zd\n",
2294 sizeof(
void*),
sizeof(
size_t),
sizeof(
double));
2295 printf(
"(double)((1<<53) - 1)=%.20g\n", (
double)(maxvoid2dbl - 1));
2296 printf(
"(double)((1<<53) + 0)=%.20g\n", (
double)(maxvoid2dbl));
2297 printf(
"(double)((1<<53) + 1)=%.20g\n", (
double)(maxvoid2dbl + 1));
2298 printf(
"(size_t)(vp) = %zd\n",
n);
2300 if (
n > maxvoid2dbl) {
2301 hoc_execerror(mes,
"pointer too large to be represented by a double");
2303 }
else if (
sizeof(
void*) > 8) {
2304 hoc_execerror(mes,
"not implemented for sizeof(void*) > 8");
2395 if (!
sec || !
sec->prop || !
sec->prop->dparam || !
sec->prop->dparam[8].itm ||
2396 sec->prop->dparam[8].itm->itemtype != SECTION) {
2413 if (sym && sym->
cpublic == 2) {
2421 if (sym->
type == SECTION) {
2442 char *str, *cp,
buf[100];
2453 if (sscanf(str,
"%[^[][%d",
buf, &
indx) == 2) {
void section_exists(void)
Object *(* nrnpy_pysec_cell_p_)(Section *)
int segment_limits(double *pdx)
double nrn_section_orientation(Section *sec)
const char * secname(Section *sec)
void hoc_sec_internal_push(void)
static double chk_void2dbl(void *vp, const char *mes)
void nrn_change_nseg(Section *sec, int n)
void delete_section(void)
void oc_save_cabcode(int *a1, int *a2)
static int range_vec_indx(Symbol *s)
void mech_uninsert1(Section *sec, Symbol *s)
const char * secaccessname(void)
static Section * secstack[NSECSTACK+1]
double * nrn_vext_pd(Symbol *s, int indx, Node *nd)
int hoc_execerror_messages
static void connectsec_impl(Section *parent, Section *sec)
void sec_access_pop(void)
static int skip_secstack_check
int node_index_exact(Section *sec, double x)
void nrn_rangeconst(Section *sec, Symbol *s, double *pd, int op)
static void nrn_rootnode_alloc(Section *sec)
Node * node_ptr(Section *sec, double x, double *parea)
void nrn_pushsec(Section *sec)
void nrn_parent_info(Section *s)
double nrn_arc_position(Section *sec, Node *node)
void parent_connection(void)
Prop * hoc_getdata_range(int type)
int has_membrane(char *mechanism_name, Section *sec)
double cable_prop_eval(Symbol *sym)
Section * nrn_trueparent(Section *sec)
void simpleconnectsection(void)
Prop * nrn_mechanism(int type, Node *nd)
void cable_prop_assign(Symbol *sym, double *pd, int op)
void setup_topology(void)
void range_interpolate(void)
void morph_alloc(Prop *p)
void forall_section(void)
double nrn_ra(Section *sec)
static Section * new_section(Object *ob, Symbol *sym, int i)
double section_length(Section *sec)
int node_index(Section *sec, double x)
double * dprop(Symbol *s, int indx, Section *sec, short inode)
int nrn_sec2cell_equals(Section *sec, Object *obj)
void connectsection(void)
double nrn_connection_position(Section *sec)
int nrn_exists(Symbol *s, Node *node)
Section * nrn_noerr_access(void)
int(* nrnpy_pysec_cell_equals_p_)(Section *, Object *)
static Section * Sec_access(void)
void keep_nseg_parm(void)
static void reverse_sibling_list(Section *sec)
int nrn_instance_count(int mechtype)
void range_interpolate_single(void)
int arc0at0(Section *sec)
void connectpointer(void)
void sec_access_push(void)
void sec_access_object(void)
Section * nrn_sec_pop(void)
static double ncp_abs(Section *sec)
Object * nrn_sec2cell(Section *sec)
int nrn_get_mechtype(const char *mechname)
double * nrn_rangepointer(Section *sec, Symbol *s, double d)
void rangevarevalpointer(void)
void section_orientation(void)
void nrn_chk_section(Symbol *s)
void nrn_remove_sibling_list(Section *sec)
void new_sections(Object *ob, Symbol *sym, Item **pitm, int size)
Section * chk_access(void)
Prop * nrn_mechanism_check(int type, Section *sec, int inode)
double nrn_diameter(Node *nd)
void hoc_level_pushsec(Section *sec)
const char * sec_and_position(Section *sec, Node *nd)
double * nrnpy_dprop(Symbol *s, int indx, Section *sec, short inode, int *err)
void oc_restore_cabcode(int *a1, int *a2)
void nrn_add_sibling_list(Section *sec)
char *(* nrnpy_pysec_name_p_)(Section *)
double * nrnpy_rangepointer(Section *sec, Symbol *s, double d, int *err)
void parent_section(void)
void nrn_disconnect(Section *sec)
char * hoc_section_pathname(Section *sec)
Node * node_exact(Section *sec, double x)
void mech_insert1(Section *sec, int type)
static char * objectname(void)
static void reverse_nodes(Section *sec)
double * cable_prop_eval_pointer(Symbol *sym)
static Datum * pdprop(Symbol *s, int indx, Section *sec, short inode)
void ob_sec_access_push(Item *qsec)
Section * nrn_section_exists(char *name, int indx, Object *cell)
const char * nrn_sec2pysecname(Section *sec)
int nrn_at_beginning(Section *sec)
static void free_clamp(void)
Symbol * hoc_table_lookup(const char *, Symlist *)
void clear_sectionlist(void)
Datum * nrn_prop_datum_alloc(int type, int count, Prop *p)
int nrn_is_valid_section_ptr(void *v)
void nrn_section_free(Section *s)
double * nrn_prop_data_alloc(int type, int count, Prop *p)
sprintf(buf, " if (secondorder) {\n" " int _i;\n" " for (_i = 0; _i < %d; ++_i) {\n" " _p[_slist%d[_i]] += dt*_p[_dlist%d[_i]];\n" " }}\n", numeqn, listnum, listnum)
double chkarg(int, double low, double high)
void extcell_2d_alloc(Section *sec)
void extcell_node_create(Node *nd)
int state_discon_allowed_
void hoc_execerror(const char *, const char *)
static void free_stim(void)
char * hoc_object_pathname(Object *ob)
void hoc_pushstr(char **d)
void hoc_execerr_ext(const char *fmt,...)
printf style specification of hoc_execerror message.
size_t hoc_total_array_data(Symbol *s, Objectdata *obd)
int hoc_arayinfo_install(Symbol *sp, int nsub)
void hoc_pushpx(double *d)
void hoc_pushobj(Object **d)
int hoc_regexp_search(const char *)
void hoc_freearay(Symbol *sp)
void * hoc_sec_internal_name2ptr(const char *s, int eflag)
int hoc_is_str_arg(int narg)
void hoc_regexp_compile(const char *)
Objectdata * hoc_objectdata
void hoc_assign_str(char **cpp, const char *buf)
size_t hoc_total_array(Symbol *s)
double hoc_opasgn(int op, double dest, double src)
void hoc_warning(const char *, const char *)
int hoc_is_double_arg(int narg)
void hoc_retpushx(double x)
char * hoc_object_name(Object *ob)
void * hoc_pysec_name2ptr(const char *s, int eflag)
void hoc_install_object_data_index(Symbol *sp)
Symbol * hoc_lookup(const char *)
char * hoc_araystr(Symbol *sym, int index, Objectdata *obd)
void hoc_push_object(Object *d)
char ** hoc_pgargstr(int narg)
Objectdata * hoc_objectdata_restore(Objectdata *obdsav)
Objectdata * hoc_objectdata_save(void)
Object ** hoc_objgetarg(int)
Symlist * hoc_top_level_symlist
Objectdata * hoc_top_level_data
int hoc_araypt(Symbol *, int)
#define ITERATE(itm, lst)
char * emalloc(unsigned n)
Prop * prop_alloc(Prop **, int, Node *)
void single_prop_free(Prop *)
static Node * node(Object *)
void nrn_relocate_old_points(Section *oldsec, Node *oldnode, Section *sec, Node *node)
void nrn_area_ri(Section *sec)
void section_ref(Section *)
void nrn_node_destruct1(Node *)
int can_change_morph(Section *)
void section_unref(Section *)
void sec_free(hoc_Item *)
void nrn_diam_change(Section *)
void nrn_seg_or_x_arg(int iarg, Section **psec, double *px)
void nrn_length_change(Section *, double)
int const size_t const size_t n
Node * nrn_node_construct1(void)
Section * nrnpy_newsection(NPySecObj *)
Item * lappendsec(List *list, Section *sec)
Item * insertsec(Item *item, Section *sec)
static double done(void *v)
static double cell(void *v)
static void pnode(Prop *)
Section * nrnpy_pysecname2sec(const char *name)
void node_alloc(Section *, short)
_nrn_Fast_Imem * _nrn_fast_imem
HocStruct hoc_Item * secelm_
struct Section * parentsec
short cpublic
Note: public is a reserved keyword.
struct Symbol::@37::@38 rng
HocStruct cTemplate * ctemplate
static void free_syn(void)
HocStruct hoc_Item ** psecitm