static void Initplot(void) { #if !defined(__GO32__) registerfarbgidriver(EGAVGA_driver_far); registerfarbgidriver(CGA_driver_far); registerfarbgidriver(Herc_driver_far); registerfarbgifont(triplex_font_far); #endif graphdev = DETECT; initgraph(&graphdev, &graphmode,"c:\\bc\\bgi"); {int err; graphdev=1; err = graphresult(); if (err != grOk) { hoc_execerror("Error in initializing graphics adaptor\n", (char *)0); } xres = (double)(getmaxx()+1); yres = (double)(getmaxy()+1); grx_txt_clear(); return; } if (graphdev > 0) { xres = (double)(getmaxx()+1); yres = (double)(getmaxy()+1); restorecrtmode(); } else { hoc_execerror("Error in initializing graphics adaptor\n", (char *)0); } }
static double abstol(void* v) { NetCvode* d = (NetCvode*)v; Symbol* sym; if (hoc_is_str_arg(1)) { sym = d->name2sym(gargstr(1)); }else{ hoc_pgetarg(1); sym = hoc_get_last_pointer_symbol(); if (!sym) { hoc_execerror("Cannot find the symbol associated with the pointer when called from Python", "Use a string instead of pointer argument"); } if (nrn_vartype(sym) != STATE && sym->u.rng.type != VINDEX) { hoc_execerror(sym->name, "is not a STATE"); } } if (ifarg(2)) { hoc_symbol_tolerance(sym, chkarg(2, 1e-30, 1e30)); d->structure_change(); } if (sym->extra && sym->extra->tolerance > 0.) { return sym->extra->tolerance; }else{ return 1.; } }
Psym *hoc_getsym(const char* cp) { Symbol *sp, *sym; Symlist *symlist = (Symlist *)0; Inst *last, *pcsav; int i, n; char s[256]; Psym *p=0; Sprintf(s, "{%s}\n", cp); sp = hoc_install("", PROCEDURE, 0., &symlist); sp->u.u_proc->defn.in = STOP; sp->u.u_proc->list = (Symlist *)0; sp->u.u_proc->nauto = 0; n = hoc_xopen_run(sp, s); last = (Inst *)sp->u.u_proc->defn.in + n; if (n < 5 || last[-3].pf != hoc_eval) { hoc_execerror(s, " not a variable"); } last[-3].in = STOP; /*before doing last EVAL*/ pcsav = hoc_pc; hoc_execute(sp->u.u_proc->defn.in); hoc_pc = pcsav; sym = hoc_spop(); switch(sym->type) { case UNDEF: hoc_execerror(s, " is undefined"); case VAR: if (ISARRAY(sym)) { Arrayinfo* a; if (sym->subtype == NOTUSER) { a = OPARINFO(sym); }else{ a = sym->arayinfo; } p = (Psym *)emalloc((unsigned)(sizeof(Psym) + a->nsub)); p->arayinfo = a; ++a->refcount; p->nsub = a->nsub; for (i=p->nsub; i > 0;) { p->sub[--i] = hoc_xpop(); } } else { p = (Psym *)emalloc(sizeof(Psym)); p->arayinfo = 0; p->nsub = 0; } p->sym = sym; break; case AUTO: hoc_execerror(s, " is local variable"); default: hoc_execerror(s, " not a variable"); } hoc_free_list(&symlist); return p; }
static void o2loc(Object* o, Section** psec, double* px) { if (o->ctemplate->sym != nrnpy_pyobj_sym_) { hoc_execerror("not a Python nrn.Segment", 0); } PyObject* po = nrnpy_hoc2pyobject(o); if (!PyObject_TypeCheck(po, psegment_type)) { hoc_execerror("not a Python nrn.Segment", 0); } NPySegObj* pyseg = (NPySegObj*)po; *psec = pyseg->pysec_->sec_; *px = pyseg->x_; }
static double r_sequence(void* r) { Rand* x = (Rand*)r; if (x->type_ != 2 && x->type_ != 4) { hoc_execerror("Random.seq() can only be used if the random generator was MCellRan4 or Random123", 0); } if (x->type_ == 4) { uint32_t seq; char which; if (ifarg(1)) { double s = chkarg(1, 0., 17179869183.); /* 2^34 - 1 */ seq = (uint32_t)(s/4.); which = char(s - seq*4.); NrnRandom123* nr = (NrnRandom123*)x->gen; nrnran123_setseq(nr->s_, seq, which); } nrnran123_getseq(((NrnRandom123*)x->gen)->s_, &seq, &which); return double(seq)*4. + double(which); } MCellRan4* mcr = (MCellRan4*)x->gen; if (ifarg(1)) { mcr->ihigh_ = (long)(*getarg(1)); } return (double)mcr->ihigh_; }
NrnProperty::NrnProperty(const char* name) { Symbol* sym = hoc_table_lookup(name, hoc_built_in_symlist); if (!sym) { sym = hoc_table_lookup(name, hoc_top_level_symlist); } if(sym) { if (sym->type == MECHANISM) { /*EMPTY*/ }else if (sym->type == TEMPLATE && sym->u.ctemplate->is_point_){ sym = hoc_table_lookup(name, sym->u.ctemplate->symtable); }else{ sym = 0; } } if (sym) { Prop* p, *p0 = 0, *p1; //printf("prop_alloc %s %p type=%d\n", sym->name, sym, sym->subtype); // need to do this with no args hoc_push_frame(sym, 0); p = prop_alloc(&p0, sym->subtype, NULL); hoc_pop_frame(); for (; p0 != p; p0 = p1) { p1 = p0->next; single_prop_free(p0); } npi_ = new NrnPropertyImpl(p); npi_->del_ = true; }else{ npi_ = NULL; hoc_execerror(name, "is not a Mechanism or Point Process"); } }
static void* finithnd_cons(Object*) { int type = 1; // default is after INITIAL blocks are called int ia = 1; if (hoc_is_double_arg(ia)) { type = (int)chkarg(ia, 0, 3); ++ia; } char* s = NULL; Object* pyact = NULL; if (hoc_is_object_arg(ia)) { pyact = *hoc_objgetarg(ia); if (!pyact) { hoc_execerror("arg is None", 0); } }else{ s =gargstr(ia); } ++ia; Object* obj = NULL; if (ifarg(ia)) { obj = *hoc_objgetarg(ia); } FInitialHandler* f = new FInitialHandler(type, s, obj, pyact); return f; }
Point_process* ob2pntproc(Object* ob) { Point_process* pp = ob2pntproc_0(ob); if (!pp || !pp->prop) { hoc_execerror(hoc_object_name(ob),"point process not located in a section"); } return pp; }
static double tstop_event(void* v) { NetCvode* d = (NetCvode*)v; double x = *getarg(1); if (!cvode_active_) { // watch out for fixed step roundoff if x // close to n*dt double y = x/nrn_threads->_dt; if (y > 1 && fabs(floor(y + 1e-6) - y) < 1e-6) { //printf("reduce %g to avoid fixed step roundoff\n", x); x -= nrn_threads->_dt/4.; } } if (ifarg(2)) { Object* ppobj = nil; int reinit = 0; if (ifarg(3)) { ppobj = *hoc_objgetarg(3); if (!ppobj || ppobj->ctemplate->is_point_ <= 0 || nrn_is_artificial_[ob2pntproc(ppobj)->prop->type] ){ hoc_execerror(hoc_object_name(ppobj), "is not a POINT_PROCESS"); } reinit = int(chkarg(4, 0, 1)); } if (hoc_is_object_arg(2)) { d->hoc_event(x, nil, ppobj, reinit, *hoc_objgetarg(2)); }else{ d->hoc_event(x, gargstr(2), ppobj, reinit); } }else{ //d->tstop_event(x); d->hoc_event(x, 0, 0, 0); } return x; }
boolean special_pnt_call(Object* ob, Symbol* sym, int narg) { char* name = sym->name; if (strcmp(name, "loc") == 0) { int type = ob->ctemplate->symtable->last->subtype; int ptype = pnt_map[type]; if (narg != 1) { hoc_execerror("no argument", 0); } double x = hoc_look_inside_stack(narg-1, NUMBER)->val; Section* sec = chk_access(); Node* node = node_exact(sec, x); nrn_loc_point_process(ptype, ob2pntproc(ob), sec, node); hoc_pushx(x); return true; }else if (strcmp(name, "has_loc") == 0) { Point_process* p = ob2pntproc(ob); hoc_pushx(double(p != nil && p->sec != nil)); return true; }else if (strcmp(name, "get_loc") == 0) { hoc_pushx(get_loc_point_process(ob2pntproc(ob))); return true; }else{ return false; } }
int NrnProperty::prop_index(const Symbol* s)const { assert(s); if (s->type != RANGEVAR) { hoc_execerror(s->name , "not a range variable"); } return s->u.rng.index; }
void nrnpy_reg_mech(int type) { int i; char* s; Memb_func* mf = memb_func + type; if (!nrnmodule_) { return; } if (mf->is_point) { if (nrn_is_artificial_[type] == 0) { Symlist* sl = nrn_pnt_template_[type]->symtable; Symbol* s = hoc_table_lookup("get_segment", sl); if (!s) { s = hoc_install("get_segment", OBFUNCTION, 0, &sl); #if MAC s->u.u_proc->defn.pfo = (Object**(*)(...))pp_get_segment; #else s->u.u_proc->defn.pfo = (Object**(*)())pp_get_segment; #endif } } return; } s = mf->sym->name; //printf("nrnpy_reg_mech %s %d\n", s, type); if (PyDict_GetItemString(pmech_types, s)) { hoc_execerror(s, "mechanism already exists"); } Py_INCREF(&nrnpy_MechanismType); PyModule_AddObject(nrnmodule_, s, (PyObject *)pmech_generic_type); PyDict_SetItemString(pmech_types, s, Py_BuildValue("i", type)); for (i = 0; i < mf->sym->s_varn; ++i) { Symbol* sym = mf->sym->u.ppsym[i]; rangevars_add(sym); } }
int hoc_retrieve_audit(int id) #endif { #if !OCSMALL RetrieveAudit save; char buf[200]; char retdir[200]; save = retrieve_audit; /*printf("retrieve audit id=%d\n", id);*/ retrieve_audit.mode = 1; retrieve_audit.id = id; sprintf(buf, "%s/retrieve.sh %d %s", AUDIT_SCRIPT_DIR, id, AUDIT_DIR); if ((retrieve_audit.pipe = popen(buf, "r")) == (FILE*)0) { hoc_execerror("Could not connect via pipe:", buf); } assert(fgets(retdir, 200, retrieve_audit.pipe)); xopen_audit(); assert(!fgets(buf, 200, retrieve_audit.pipe)); /* pclose(retrieve_audit.pipe);*/ retrieve_audit = save; fprintf(stderr, "should now delete %s", retdir); #endif return 1; }
void NrnDAQ::nrndaq_init() { if (bus) { return; } // needs the devicePCI_ID which can be found from // nilsdev --verbose // to determine the PCI Bus and PCI Device values. From those look // at cat /proc/pci and from the Bus - device section the // devicePCI_ID is the 8 digit number after PCI device. int devicePCI_ID = 0x109370aa; //printf("trying devicePCI_ID = 0x%x\n", devicePCI_ID); bus = acquireBoard(devicePCI_ID); if (bus == NULL) { hoc_execerror("Could not access PCI device.", 0); return; } // Initialize Mite Chip. initMite(); // read eeprom for calibration information eeprom_read(); // create register map bar1 = bus->createAddressSpace(kPCI_BAR1); board = new tMSeries(bar1); ai_reset(); // ao_reset(); }
static void steer_val(void* v) { OcPointer* ocp = (OcPointer*)v; hoc_spop(); if (!ocp->valid_) { hoc_execerror("Pointer points to freed address:", ocp->s_); } hoc_pushpx(ocp->p_); }
void NonLinImp::compute(double omega, double deltafac, int maxiter) { v_setup_vectors(); nrn_rhs(nrn_threads); if (rep_ && rep_->scnt_ != structure_change_cnt) { delete rep_; rep_ = NULL; } if (!rep_) { rep_ = new NonLinImpRep(); } rep_->maxiter_ = maxiter; if (rep_->neq_ == 0) { return; } if (nrndae_extra_eqn_count() > 0) { hoc_execerror("Impedance calculation with LinearMechanism not implemented", 0); } if (nrn_threads->_ecell_memb_list) { hoc_execerror("Impedance calculation with extracellular not implemented", 0); } rep_->omega_ = 1000.* omega; rep_->delta(deltafac); // fill matrix cmplx_spClear(rep_->m_); rep_->didv(); rep_->dsds(); #if 1 // when 0 equivalent to standard method rep_->dids(); rep_->dsdv(); #endif // cmplx_spPrint(rep_->m_, 0, 1, 1); // for (int i=0; i < rep_->neq_; ++i) { // printf("i=%d %g %g\n", i, rep_->diag_[i][0], rep_->diag_[i][1]); // } int e = cmplx_spFactor(rep_->m_); switch (e) { case spZERO_DIAG: hoc_execerror("cmplx_spFactor error:", "Zero Diagonal"); case spNO_MEMORY: hoc_execerror("cmplx_spFactor error:", "No Memory"); case spSINGULAR: hoc_execerror("cmplx_spFactor error:", "Singular"); } rep_->iloc_ = -2; }
static double assign(void* v) { OcPointer* ocp = (OcPointer*)v; if (!ocp->valid_) { hoc_execerror("Pointer points to freed address:", ocp->s_); } ocp->assign(*getarg(1)); return *ocp->p_; }
static double subworlds(void* v) { int n = int(chkarg(1, 1, nrnmpi_numprocs_world)); if (nrnmpi_numprocs_world%n) { hoc_execerror("nhost_world must be an integer multiple of subworld size", 0); } #if NRNMPI nrnmpi_subworld_size(n); #endif return 0.; }
HocCommand::HocCommand(Object* pobj) { // must wrap a PyObject method or tuple of (method, arg1, ...) // hold a reference to the wrapped PyObject if (strcmp(pobj->ctemplate->sym->name, "PythonObject") != 0) { hoc_execerror(hoc_object_name(pobj), "not a PythonObject"); } po_ = pobj; hoc_obj_ref(po_); s_ = NULL; obj_ = NULL; }
double NonLinImp::transfer_phase(int curloc, int vloc) { if (nrnmpi_numprocs > 1 && nrnthread_v_transfer_ && curloc != rep_->iloc_) { hoc_execerror("current injection site change not allowed with both gap junctions and nhost > 1", 0); } if (curloc != rep_->iloc_) { solve(curloc); } double x = rep_->rv_[vloc]; double y = rep_->jv_[vloc]; return atan2(y, x); }
double NonLinImp::input_phase(int curloc) { if (nrnmpi_numprocs > 1 && nrnthread_v_transfer_) { hoc_execerror("not allowed with both gap junctions and nhost>1", 0); } if (curloc != rep_->iloc_) { solve(curloc); } if (curloc < 0) { return 0.0; } double x = rep_->rv_[curloc]; double y = rep_->jv_[curloc]; return atan2(y,x); }
static void overloaded(Object* ho, Symbol* method) { int n = strlen(method->name); printf("%s.%s Overloaded. Use one of:\n", hoc_object_name(ho), method->name); for (Symbol* s = ho->ctemplate->symtable->first; s; s = s->next) { if (s != method && strncmp(s->name, method->name, n) == 0 && isdigit(s->name[n]) ) { printf(" %s\n", s->name); } } hoc_execerror(method->name, "Overloaded. Disambiguate using a more specific method."); }
void nrn_extra_scatter_gather(int direction, int tid) { ExtraScatterList* esl = extra_scatterlist[direction]; if (esl) { nrn_thread_error("extra_scatter_gather not allowed with multiple threads"); for (int i=0; i < esl->count(); ++i) { Object* callable = esl->item(i); if (!(*nrnpy_hoccommand_exec)(callable)) { hoc_execerror("extra_scatter_gather runtime error", 0); } } } }
void nrnmpi_assert_opstep(int opstep, double tt) { /* all machines in comm should have same opstep and same tt. */ double buf[2]; if (nrnmpi_numprocs < 2) { return; } buf[0] = (double)opstep; buf[1] = tt; MPI_Bcast(buf, 2, MPI_DOUBLE, 0, nrnmpi_comm); if (opstep != (int)buf[0] || tt != buf[1]) { printf("%d opstep=%d %d t=%g t-troot=%g\n", nrnmpi_myid, opstep, (int)buf[0], tt, tt-buf[1]); hoc_execerror("nrnmpi_assert_opstep failed", (char*)0); } }
/** invoke java method returning double */ static double java2nrn_dmeth(Object* ho, Symbol* method) { // printf("java2nrn_dmeth invoking %s.%s\n", hoc_object_name(ho), method->name); if (method->s_varn) {overloaded(ho, method);} double d = (double) nrnjava_env->CallStaticDoubleMethod( neuronCls, invokeDoubleMethodID, (jobject)ho->u.this_pointer, -(jint)ho->ctemplate->id - 1, (jint)method->u.u_auto, (jint)method->s_varn); errno = 0; if (d == -1e98) { hoc_execerror("Java Exception for", method->name); } return d; }
static void arayonstack(Psym* p) { int i; double d; if (p->nsub) { if (!ISARRAY(p->sym) || p->nsub != p->arayinfo->nsub) { hoc_execerror("wrong number of subscripts for ", p->sym->name); } for (i=0; i < p->nsub; i++) { d = p->sub[i]; hoc_pushx(d); } } }
fsyn() { int i; if (nrn_nthread > 1) { hoc_execerror("fsyn does not allow threads", ""); } i = chkarg(1, 0., 10000.); if (ifarg(2)) { if (i >= maxstim) { hoc_execerror("index out of range", (char *)0); } pstim[i].loc = chkarg(2, 0., 1.); pstim[i].delay = chkarg(3, 0., 1e21); pstim[i].duration = chkarg(4, 0., 1e21); pstim[i].mag = *getarg(5); pstim[i].erev = *getarg(6); pstim[i].sec = chk_access(); section_ref(pstim[i].sec); stim_record(i); } else { free_syn(); maxstim = i; if (maxstim) { pstim = (Stimulus *)emalloc((unsigned)(maxstim * sizeof(Stimulus))); } for (i = 0; i<maxstim; i++) { pstim[i].loc = 0; pstim[i].mag = 0.; pstim[i].delay = 1e20; pstim[i].duration = 0.; pstim[i].erev = 0.; pstim[i].sec = 0; stim_record(i); } } ret(0.); }
void cvode_fadvance(double tstop) { // tstop = -1 means single step #if USECVODE int err; if (net_cvode_instance) { nrn_random_play(); err = net_cvode_instance->solve(tstop); if (err != 0) { printf("err=%d\n", err); hoc_execerror("variable step integrator error", 0); } t = nt_t; dt = nt_dt; } #endif }
static void* cons(Object*) { #if 0 NetCvode* d; if (net_cvode_instance) { hoc_execerror("Only one CVode instance allowed", 0); }else{ d = new NetCvode(1); net_cvode_instance = d; } active(nil); return (void*) d; #else return (void*)net_cvode_instance; #endif }
static double solve(void* v) { NetCvode* d = (NetCvode*)v; double tstop = -1.; if (ifarg(1)) { tstop = *getarg(1); } tstopunset; int i = d->solve(tstop); tstopunset; if (i != SUCCESS) { hoc_execerror("variable step integrator error", 0); } t = nt_t; dt = nt_dt; return double(i); }