1 #include <../../nrnconf.h> 24 "Duke, Yale, and the BlueBrain Project -- Copyright 1984-2021\n\ 25 See http://neuron.yale.edu/neuron/credits\n";
28 #if defined(HAVE_DLFCN_H) && !defined(__MINGW32__) 33 extern void*
dlopen(
const char*
name,
int mode);
34 extern void*
dlsym(
void* handle,
char* name);
35 extern int dlclose(
void* handle);
43 #if defined(WIN32) || defined(NRNMECH_DLL_STYLE) 49 #undef DLL_DEFAULT_FNAME 50 #define DLL_DEFAULT_FNAME "nrnmech.dll" 53 #if defined(NRNMECH_DLL_STYLE) 56 #ifndef DLL_DEFAULT_FNAME 57 #define DLL_DEFAULT_FNAME "libnrnmech.dylib" 61 void nrn_possible_mismatched_arch(
const char* libname) {
62 if (strncmp(NRNHOSTCPU,
"arm64", 5) == 0) {
65 const char* we_are{
"arm64"};
67 const char* we_are{
"x86_64"};
72 cmd =
new char[strlen(libname) + 100];
73 sprintf(cmd,
"lipo -archs %s 2> /dev/null", libname);
74 char libname_arch[20]{0};
78 fgets(libname_arch, 18, p);
79 if (strlen(libname_arch) == 0) {
return;}
83 fprintf(stderr,
"libnrniv.dylib running as %s\n", we_are);
84 fprintf(stderr,
"but %s can only run as %s\n", libname, libname_arch);
98 #if defined(HAVE_DLFCN_H) && !defined(__MINGW32__) 102 #ifndef DLL_DEFAULT_FNAME 103 #define DLL_DEFAULT_FNAME "./libnrnmech.so" 106 #else // !defined(NRNMECH_DLL_STYLE) 107 #if defined(HAVE_DLFCN_H) && !defined(__MINGW32__) 112 # define CHECK(name) if (hoc_lookup(name) != (Symbol *)0){\ 113 IGNORE(fprintf(stderr, CHKmes, name));\ 116 static char CHKmes[] =
"The user defined name, %s, already exists\n";
137 "rallbranch", 1., 1e9,
139 "celsius", -273., 1e6,
246 char* abspath =
NULL;
251 #if defined(HAVE_REALPATH) 252 abspath = realpath(relpath,
NULL);
254 #if defined(__MINGW32__) 255 abspath = _fullpath(
NULL, relpath, 0);
257 abspath = strdup(relpath);
261 handle =
dlopen(abspath, flags);
264 nrn_possible_mismatched_arch(abspath);
270 handle =
dlopen(relpath, flags);
272 Fprintf(stderr,
"realpath failed errno=%d (%s) and dlopen failed with %s\n", patherr, strerror(patherr), relpath);
274 nrn_possible_mismatched_arch(abspath);
284 fprintf(stderr,
"loading membrane mechanisms from %s\n", cp1);
322 nrn_load_dll_called_ = (
Symlist*)0;
388 CHECK(
"i_membrane_");
407 #if !MAC && !defined(WIN32) 412 #if defined(WIN32) || defined(NRNMECH_DLL_STYLE) 415 FILE* ff =
fopen(DLL_DEFAULT_FNAME,
"r");
430 char*
retval = getcwd(buf, 4096);
432 strncat(buf,
"\\", 100);
439 for (cp2 = cp1; *cp2; ++cp2) {
454 s->
type = OBJECTFUNC;
485 int j,
k, modltype, pindx, modltypemax;
560 memb_func[
type].ode_count =
nullptr;
561 memb_func[
type].ode_map =
nullptr;
562 memb_func[
type].ode_spec =
nullptr;
563 memb_func[
type].ode_matsol =
nullptr;
564 memb_func[
type].ode_synonym =
nullptr;
565 memb_func[
type].singchan_ =
nullptr;
575 if (strcmp(m[0],
"0") == 0) {
576 }
else if (m[0][0] >
'9') {
577 Fprintf(stderr,
"Mechanism %s needs to be re-translated.\n\ 578 It's pre version 6.0 \"c\" code is incompatible with this neuron version.\n", m[0]);
585 Fprintf(stderr,
"Mechanism %s needs to be re-translated.\n\ 586 It's version %s \"c\" code is incompatible with this neuron version.\n",
600 if (nrnpointerindex == -1) {
605 for (k=0, j=0, modltype=
nrnocCONST; modltype<=modltypemax; modltype++, j++){
607 for (; m2[
j]; j++, k++) {
624 for (j=0, k=0, modltype=
nrnocCONST; modltype <= modltypemax; modltype++, j++) {
625 for (; m2[
j]; j++, k++) {
627 char buf[200], *cp;
int indx;
unsigned nsub=0;
630 cp = strchr(buf,
'[');
638 sscanf(cp+1,
"%d", &indx);
659 s2->
u.
rng.index = nrnpointerindex;
661 s2->
u.
rng.index = pindx;
675 nrnpointerindex +=
indx;
700 nrnpointerindex, vectorized);
702 (*nrnpy_reg_mech_p_)(
type);
707 static int lastion = EXTRACELL+1;
714 printf(
"%s reordered from %d to %d\n", memb_func[type].sym->name, type, lastion);
724 if (memb_func[type].dparam_semantics) {
725 free(memb_func[type].dparam_semantics);
741 if (strcmp(name,
"area") == 0) {
743 }
else if (strcmp(name,
"iontype") == 0) {
745 }
else if (strcmp(name,
"cvodeieq") == 0) {
747 }
else if (strcmp(name,
"netsend") == 0) {
749 }
else if (strcmp(name,
"pointer") == 0) {
751 }
else if (strcmp(name,
"pntproc") == 0) {
753 }
else if (strcmp(name,
"bbcorepointer") == 0) {
755 }
else if (strcmp(name,
"watch") == 0) {
757 }
else if (strcmp(name,
"diam") == 0) {
759 }
else if (strcmp(name,
"fornetcon") == 0) {
763 if (name[0] ==
'#') { i = 1; }
765 if (s && s->
type == MECHANISM) {
768 fprintf(stderr,
"mechanism %s : unknown semantics for %s\n", memb_func[type].sym->name, name);
773 printf(
"dparam semantics %s ix=%d %s %d\n", memb_func[type].sym->name,
786 memb_func[
i].ode_count =
cnt;
787 memb_func[
i].ode_map =
map;
788 memb_func[
i].ode_spec = spec;
789 memb_func[
i].ode_matsol =
matsol;
792 memb_func[
i].ode_synonym = syn;
815 int (*checkpoint)(
void **),
846 nrnpointerindex, vectorized);
856 double* makevector(
int nrows)
859 v = (
double*)
emalloc((
unsigned)(nrows*
sizeof(double)));
896 for (i=0; limits[
i].
name; ++
i) {
898 if (type && memb_func[type].is_point) {
917 for (i=0; units[
i].
name; ++
i) {
919 if (type && memb_func[type].is_point) {
944 printf(
"before-after processing type %d for %s not implemented\n", type, memb_func[mt].sym->name);
957 if (s && s[i]->extra) {
975 for (i = 0; tol[
i].
name; ++
i) {
976 if (memb_func[type].is_point) {
996 n = (*memb_func[
type].ode_count)(type);
999 pv = (
double**)
ecalloc(2*n,
sizeof(
double*));
1004 for (i=0; i <
n; ++
i) {
1005 for (p = pnode[0]->
prop;
p; p = p->
next) {
1007 index = pv[
i] - p->
param;
1016 msym = memb_func[p->
type].
sym;
1017 for (j=0; j < msym->
s_varn; ++
j) {
1019 if (vsym->
type == RANGEVAR && vsym->
u.
rng.index == index) {
1024 for (k=1; k < na; ++
k) {
1031 assert (j < msym->s_varn);
1045 }
else if (cons == 0) {
1047 }
else if (cons == 2) {
void * ecalloc(size_t n, size_t size)
void hoc_register_units(int type, HocParmUnits *units)
char * strstr(cs, ct) char *cs
hoc_List * hoc_l_newlist()
void nrn_verify_ion_charge_defined()
void * erealloc(void *ptr, size_t n)
static HocParmLimits _hoc_parm_limits[]
void(* pnt_receive_t)(Point_process *, double *, double)
void hoc_symbol_limits(Symbol *sym, float low, float high)
int point_reg_helper(Symbol *s2)
void nrn_mk_prop_pools(int)
const char * dlerror(void)
static HocParmLimits limits[]
short * nrn_artcell_qindex_
static void pnode(Prop *)
void hoc_reg_bbcore_write(int type, bbcore_write_t f)
void nrn_writes_conc(int type, int unused)
void register_destructor(Pvmp d)
Symbol * hoc_lookup(const char *)
const char ** nrn_nmodl_filename_
Represent main neuron object computed by single thread.
Symlist * nrn_load_dll_called_
int nrn_is_artificial(int pnttype)
int nrn_load_dll_recover_error()
const char * expand_env_var(const char *s)
void hoc_reg_nmodl_text(int type, const char *txt)
static int ode_count(int type)
void(* thread_cleanup_)(Datum *)
void morph_alloc(Prop *p)
void(* nrnpy_reg_mech_p_)(int)
static philox4x32_key_t k
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
void nrnunit_use_legacy()
int dlclose(void *handle)
Point_process ** point_process
bbcore_write_t * nrn_bbcore_read_
static void destruct(void *v)
static const char * morph_mech[]
#define BEFORE_AFTER_SIZE
Symbol * hoc_install(const char *, int, double, Symlist **)
int * nrn_prop_param_size_
static double map(void *v)
double hoc_call_func(Symbol *s, int narg)
const char ** nrn_nmodl_text_
pnt_receive_init_t * pnt_receive_init
cTemplate ** nrn_pnt_template_
int const size_t const size_t n
void(*)(double *, int *, int *, int *, double *, Datum *, Datum *, NrnThread *) bbcore_write_t
HocStruct Symbol ** ppsym
void _nrn_thread_reg(int i, int cons, void(*f)(Datum *))
static void destructor(void *v)
pnt_receive_t * pnt_receive
void(* nrn_bamech_t)(Node *, double *, Datum *, Datum *, struct NrnThread *)
void class2oc(const char *, void *(*cons)(Object *), void(*destruct)(void *), Member_func *, int(*checkpoint)(void **), Member_ret_obj_func *, Member_ret_str_func *)
FILE * popen(char *s1, char *s2)
Node ** node_construct(int)
void hoc_nrn_load_dll(void)
int point_register_mech(const char **m, Pvmp alloc, Pvmi cur, Pvmi jacob, Pvmi stat, Pvmi initialize, int nrnpointerindex, int vectorized, void *(*constructor)(Object *), void(*destructor)(void *), Member_func *fmember)
int * nrn_dparam_ptr_end_
void(* thread_mem_init_)(Datum *)
void hoc_register_prop_size(int type, int psize, int dpsize)
void nrn_register_mech_common(const char **m, Pvmp alloc, Pvmi cur, Pvmi jacob, Pvmi stat, Pvmi initialize, int nrnpointerindex, int vectorized)
void(* Pvmi)(struct NrnThread *, Memb_list *, int)
char * hoc_symbol_units(Symbol *, const char *)
void hoc_reg_nmodl_filename(int type, const char *filename)
Prop * prop_alloc(Prop **, int, Node *)
void hoc_execerror(const char *, const char *)
void hoc_reg_watch_allocate(int type, NrnWatchAllocateFunc_t waf)
void SectionList_reg(void)
fprintf(stderr, "Don't know the location of params at %p\, pp)
static HocParmUnits _hoc_parm_units[]
void state_discontinuity(int i, double *pd, double d)
void nrn_threads_create(int, int)
void add_nrn_artcell(int type, int qi)
static void * constructor(Object *ho)
void * dlopen(const char *path, int mode)
double nrn_call_mech_func(Symbol *s, int narg, Prop *p, int type)
void node_destruct(Node **, int)
char * emalloc(unsigned n)
void(* NrnWatchAllocateFunc_t)(Datum *)
Symlist * hoc_built_in_symlist
int nrn_pointing(double *pd)
void hoc_register_dparam_semantics(int type, int ix, const char *name)
static void * cons(Object *o)
void add_nrn_fornetcons(int type, int indx)
int mswin_load_dll(const char *cp1)
static int memb_func_size_
struct Symbol::@52::@53 rng
void _cvode_abstol(Symbol **s, double *tol, int i)
void hoc_register_cvode(int i, nrn_ode_count_t cnt, nrn_ode_map_t map, Pvmi spec, Pvmi matsol)
NrnWatchAllocateFunc_t * nrn_watch_allocate_
void(* _update_ion_pointers)(Datum *)
void hoc_register_var(DoubScal *scdoub, DoubVec *vdoub, VoidFunc *fn)
void hoc_register_limits(int type, HocParmLimits *limits)
short cpublic
Note: public is a reserved keyword.
int * nrn_prop_dparam_size_
int state_discon_allowed_
void steer_point_process(void *v)
double _modl_get_dt_thread(NrnThread *nt)
void hoc_register_synonym(int i, void(*syn)(int, double **, Datum **))
void _modl_set_dt(double newdt)
void hoc_register_tolerance(int type, HocStateTolerance *tol, Symbol ***stol)
HocStruct cTemplate * ctemplate
bbcore_write_t * nrn_bbcore_write_
Symbol * hoc_table_lookup(const char *, Symlist *)
void add_nrn_has_net_event(int type)
void register_mech(const char **m, Pvmp alloc, Pvmi cur, Pvmi jacob, Pvmi stat, Pvmi initialize, int nrnpointerindex, int vectorized)
int * nrn_dparam_ptr_start_
int * nrn_fornetcon_type_
void(* thread_table_check_)(double *, Datum *, Datum *, NrnThread *, int)
double hoc_default_dll_loaded_
static struct @32 flags[]
void hoc_reg_bbcore_read(int type, bbcore_write_t f)
static char nmodl_version_[]
void hoc_symbol_tolerance(Symbol *, double)
void hoc_reg_ba(int mt, nrn_bamech_t f, int type)
int nrn_netrec_state_adjust
void * dlsym(void *handle, const char *symbol)
void modl_reg(void)
Needed for compilation.
void _modl_set_dt_thread(double newdt, NrnThread *nt)
void _nrn_thread_table_reg(int i, void(*f)(double *, Datum *, Datum *, NrnThread *, int))
static struct @41 usrprop[]
int * nrn_fornetcon_index_
short * nrn_is_artificial_
void(* pnt_receive_init_t)(Point_process *, double *, double)
void(* nrn_ode_map_t)(int, double **, double **, double *, Datum *, double *, int)
#define BEFORE_BREAKPOINT
int(* nrn_ode_count_t)(int)
double chkarg(int, double low, double high)
void _nrn_setdata_reg(int i, void(*call)(Prop *))
void SectionRef_reg(void)
int nrn_noauto_dlopen_nrnmech
void nrn_load_name_check(const char *name)
void(* setdata_)(struct Prop *)
void * nrn_realpath_dlopen(const char *relpath, int flags)
int nrn_has_net_event_cnt_