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.; } }
static double ste_transition(void* v) { StateTransitionEvent* ste = (StateTransitionEvent*)v; int src = (int)chkarg(1, 0, ste->nstate()-1); int dest = (int)chkarg(2, 0, ste->nstate()-1); if (src == dest) { hoc_execerror("source and destination are the same", 0); } double* var1 = hoc_pgetarg(3); double* var2 = hoc_pgetarg(4); char* stmt = gargstr(5); Object* obj = nil; if (ifarg(6)) { obj = hoc_obj_get(6); } ste->transition(src, dest, var1, var2, 1, stmt, obj); return 1.; }
static double aoplay(void* v) { if (nrndaq_) { u32 ichan = (u32)chkarg(1, 0, 16); double* pvar = hoc_pgetarg(2); double scl = 1., offset = 0.0; if (ifarg(3)) { scl = chkarg(3, -1e9, 1e9); } if (ifarg(4)) { offset = chkarg(4, -1e9, 1e9); } nrndaq_->ao_play(ichan, pvar, scl, offset); } return 0.; }
static double ste_transition(void* v) { StateTransitionEvent* ste = (StateTransitionEvent*)v; int src = (int)chkarg(1, 0, ste->nstate()-1); int dest = (int)chkarg(2, 0, ste->nstate()-1); double* var1 = hoc_pgetarg(3); double* var2 = hoc_pgetarg(4); HocCommand* hc = NULL; if (ifarg(5)) { Object* obj = NULL; if (hoc_is_str_arg(5)) { char* stmt = NULL; stmt = gargstr(5); if (ifarg(6)) { obj = *hoc_objgetarg(6); } hc = new HocCommand(stmt, obj); }else{ obj = *hoc_objgetarg(5); hc = new HocCommand(obj); } } ste->transition(src, dest, var1, var2, hc); return 1.; }
static void* cons(Object*) { double* p; const char* s; if (hoc_is_pdouble_arg(1)) { p = hoc_pgetarg(1); s = "unknown"; }else{ s = gargstr(1); ParseTopLevel ptl; p = hoc_val_pointer(s); } if (!p) { hoc_execerror("Pointer constructor failed", 0); } OcPointer* ocp = new OcPointer(s, p); if (ifarg(2)) { ocp->sti_ = new StmtInfo(gargstr(2)); } return (void*)ocp; }
static void unpack_help(int i, OcBBS* bbs) { for (; ifarg(i); ++i) { if (hoc_is_pdouble_arg(i)) { *hoc_pgetarg(i) = bbs->upkdouble(); }else if (hoc_is_str_arg(i)) { char* s = bbs->upkstr(); char** ps = hoc_pgargstr(i); hoc_assign_str(ps, s); delete [] s; }else if (is_vector_arg(i)){ Vect* vec = vector_arg(i); int n = bbs->upkint(); vec->resize(n); bbs->upkvec(n, vec->vec()); }else{ hoc_execerror("pc.unpack can only unpack str, scalar, or Vector.", "use pc.upkpyobj to unpack a Python Object"); } } }
static double r_play(void* r){ new RandomPlay((Rand*)r, hoc_pgetarg(1)); return 0.; }
void nrn_vecsim_add(void* v, boolean record) { IvocVect* yvec, *tvec, *dvec; extern short* nrn_is_artificial_; double* pvar = nil; char* s = nil; double ddt; Object* ppobj = nil; int iarg = 0; yvec = (IvocVect*)v; if (hoc_is_object_arg(1)) { iarg = 1; ppobj = *hoc_objgetarg(1); if (!ppobj || ppobj->ctemplate->is_point_ <= 0 || nrn_is_artificial_[ob2pntproc(ppobj)->prop->type] ) { hoc_execerror("Optional first arg is not a POINT_PROCESS", 0); } } if (record == false && hoc_is_str_arg(iarg+1)) {//statement involving $1 // Vector.play("proced($1)", ...) s = gargstr(iarg+1); }else if (record == false && hoc_is_double_arg(iarg+1)) {// play that element // Vector.play(index) // must be a VecPlayStep and nothing else VecPlayStep* vps = (VecPlayStep*)net_cvode_instance->playrec_uses(v); if (vps) { int j = (int)chkarg(iarg+1, 0., yvec->capacity()-1); if (vps->si_) { vps->si_->play_one(yvec->elem(j)); } } return; }else{ // Vector.play(&SEClamp[0].amp1, ...) // Vector.record(&SEClamp[0].i, ...) pvar = hoc_pgetarg(iarg+1); } tvec = nil; dvec = nil; ddt = -1.; int con = 0; if (ifarg(iarg+2)) { if (hoc_is_object_arg(iarg+2)) { // Vector...(..., tvec) tvec = vector_arg(iarg+2); }else{ // Vector...(..., Dt) ddt = chkarg(iarg+2, 1e-9, 1e10); } if (ifarg(iarg+3)) { if (hoc_is_double_arg(iarg+3)) { con = (int)chkarg(iarg+3, 0., 1.); }else{ dvec = vector_arg(iarg+3); con = 1; } } } // tvec can be used for many record/play items // if (tvec) { nrn_vecsim_remove(tvec); } if (record) { // yvec can be used only for one record (but many play) if (yvec) { nrn_vecsim_remove(yvec); } if (tvec) { new VecRecordDiscrete(pvar, yvec, tvec, ppobj); } else if (ddt > 0.) { new VecRecordDt(pvar, yvec, ddt, ppobj); } else if (pvar == &t) { new TvecRecord(chk_access(), yvec, ppobj); } else { new YvecRecord(pvar, yvec, ppobj); } }else{ if (con) { if (s) { new VecPlayContinuous(s, yvec, tvec, dvec, ppobj); }else{ new VecPlayContinuous(pvar, yvec, tvec, dvec, ppobj); } }else{ if (!tvec && ddt == -1.) { chkarg(iarg+2, 1e-9, 1e10); } if (s) { new VecPlayStep(s, yvec, tvec, ddt, ppobj); }else{ new VecPlayStep(pvar, yvec, tvec, ddt, ppobj); } } } }
void fit_praxis(void) { extern Symbol* hoc_lookup(); extern char* gargstr(); char* after_quad; int i; double err, fmin; double* px; /* allow nested calls to fit_praxis. I.e. store all the needed statics specific to this invocation with proper reference counting and then unref/destoy on exit from this invocation. Before the prax call save the statics from earlier invocation without increasing the ref count and on exit restore without decreasing the ref count. */ /* save before setting statics, restore after prax */ double minerrsav, *minargsav, maxstepsizesav, tolerancesav; long int printmodesav, nvarsav; Symbol* efun_sym_sav; Object* efun_py_save, *efun_py_arg_save; void* vec_py_save_save; /* store statics specified by this invocation */ /* will be copied just before calling prax */ double minerr_, *minarg_; long int nvar_; Symbol* efun_sym_; Object* efun_py_, *efun_py_arg_; void* vec_py_save_; minerr_ = 0.0; nvar_ = 0; minarg_ = NULL; efun_sym_ = NULL; efun_py_ = NULL; efun_py_arg_ = NULL; vec_py_save_ = NULL; fmin = 0.; if (hoc_is_object_arg(1)) { assert(nrnpy_praxis_efun); efun_py_ = *hoc_objgetarg(1); hoc_obj_ref(efun_py_); efun_py_arg_ = *vector_pobj(vector_arg(2)); hoc_obj_ref(efun_py_arg_); vec_py_save_ = vector_new2(efun_py_arg_->u.this_pointer); nvar_ = vector_capacity(vec_py_save_); px = vector_vec(vec_py_save_); }else{ nvar_ = (int)chkarg(1, 0., 1e6); efun_sym_ = hoc_lookup(gargstr(2)); if (!efun_sym_ || (efun_sym_->type != FUNCTION && efun_sym_->type != FUN_BLTIN)) { hoc_execerror(gargstr(2), "not a function name"); } if (!hoc_is_pdouble_arg(3)) { void* vec = vector_arg(3); if (vector_capacity(vec) != nvar_) { hoc_execerror("first arg not equal to size of Vector",0); } px = vector_vec(vec); }else{ px = hoc_pgetarg(3); } } minarg_ = (double*)ecalloc(nvar_, sizeof(double)); if (maxstepsize == 0.) { hoc_execerror("call attr_praxis first to set attributes", 0); } machep = 1e-15; if (ifarg(4)) { after_quad = gargstr(4); }else{ after_quad = (char*)0; } /* save the values set by earlier invocation */ minerrsav = minerr; minargsav = minarg; tolerancesav = tolerance; maxstepsizesav = maxstepsize; printmodesav = printmode; nvarsav = nvar; efun_sym_sav = hoc_efun_sym; efun_py_save = efun_py; efun_py_arg_save = efun_py_arg; vec_py_save_save = vec_py_save; /* copy this invocation values to the statics */ minerr = minerr_; minarg = minarg_; nvar = nvar_; hoc_efun_sym = efun_sym_; efun_py = efun_py_; efun_py_arg = efun_py_arg_; vec_py_save = vec_py_save_; minerr=1e9; err = praxis(&tolerance, &machep, &maxstepsize, nvar, &printmode, px, efun, &fmin, after_quad); err = minerr; if (minerr < 1e9) { for (i=0; i<nvar; ++i) { px[i] = minarg[i]; } } /* restore the values set by earlier invocation */ minerr = minerrsav; minarg = minargsav; tolerance = tolerancesav; maxstepsize = maxstepsizesav; printmode = printmodesav; nvar = nvar_; /* in case one calls prax_pval */ hoc_efun_sym = efun_sym_sav; efun_py = efun_py_save; efun_py_arg = efun_py_arg_save; vec_py_save = vec_py_save_save; if (efun_py_) { double* px = vector_vec(efun_py_arg_->u.this_pointer); for (i=0; i < nvar_; ++i) { px[i] = minarg_[i]; } hoc_obj_unref(efun_py_); hoc_obj_unref(efun_py_arg_); vector_delete(vec_py_save_); } if (minarg_) { free(minarg_); } hoc_retpushx(err); }