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; }
void LinearMechanism::create() { int i; lmfree(); i = 0; Object* o = *hoc_objgetarg(++i); if (strcmp(o->ctemplate->sym->name, "PythonObject") == 0) { f_callable_ = o; hoc_obj_ref(o); c_ = matrix_arg(++i); } else { f_callable_ = NULL; c_ = matrix_arg(1); } g_ = matrix_arg(++i); y_ = vector_arg(++i); if (ifarg(i + 2) && hoc_is_object_arg(i + 2) && is_vector_arg(i + 2)) { y0_ = vector_arg(++i); } b_ = vector_arg(++i); if (ifarg(++i)) { #if HAVE_IV Oc oc; #endif if (hoc_is_double_arg(i)) { nnode_ = 1; nodes_ = new Node*[1]; double x = chkarg(i, 0., 1.); Section* sec = chk_access(); nodes_[0] = node_exact(sec, x); nrn_notify_when_double_freed(&NODEV(nodes_[0]), this); }else{ Object* o = *hoc_objgetarg(i); check_obj_type(o, "SectionList"); SectionList* sl = new SectionList(o); sl->ref(); Vect* x = vector_arg(i+1); Section* sec; nnode_ = 0; nodes_ = new Node*[x->capacity()]; for (sec = sl->begin(); sec; sec = sl->next()) { nodes_[nnode_] = node_exact(sec, x->elem(nnode_)); nrn_notify_when_double_freed(&NODEV(nodes_[nnode_]), this); ++nnode_; } if (ifarg(i+2)) { elayer_ = vector_arg(i+2); } sl->unref(); } } model_ = new LinearModelAddition(c_, g_, y_, y0_, b_, nnode_, nodes_, elayer_, f_callable_); }
JNIEXPORT jdouble JNICALL Java_neuron_Neuron_getHocDoubleArg( JNIEnv *env, jclass cls, jint idx, jint type) { double ret; if (!ifarg(idx)) { printf("error - missing double as arg %d\n", idx); illegalArg(env, "missing double"); return (jdouble)-1.0E98; } if (hoc_is_double_arg( idx )) { ret = *(getarg( idx )); } else { printf("error - expecting double as arg %d\n", idx); illegalArg(env, "expecting double"); return (jdouble)-1.0E98; } if (type == 1) { ret = hoc_integer(ret); } return (jdouble)ret; }
static void pack_help(int i, OcBBS* bbs) { if (!posting_) { bbs->pkbegin(); posting_ = true; } for (; ifarg(i); ++i) { if (hoc_is_double_arg(i)) { bbs->pkdouble(*getarg(i)); }else if (hoc_is_str_arg(i)) { bbs->pkstr(gargstr(i)); }else if (is_vector_arg(i)){ int n; double* px; n = vector_arg_px(i, &px); bbs->pkint(n); bbs->pkvec(n, px); }else{ // must be a PythonObject size_t size; char* s = nrnpy_po2pickle(*hoc_objgetarg(i), &size); bbs->pkpickle(s, size); delete [] s; } } }
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); } } } }
static int submit_help(OcBBS* bbs) { int id, i, firstarg, style; char* pname = 0; // if using Python callable posting_ = true; bbs->pkbegin(); i = 1; if (hoc_is_double_arg(i)) { bbs->pkint((id = (int)chkarg(i++, 0, 1e7))); }else{ bbs->pkint((id = --bbs->next_local_)); } if (ifarg(i+1)) { #if 1 int argtypes = 0; int ii = 1; if (hoc_is_str_arg(i)) { style = 1; bbs->pkint(style); // "fname", arg1, ... style bbs->pkstr(gargstr(i++)); }else{ Object* ob = *hoc_objgetarg(i++); size_t size; if (nrnpy_po2pickle) { pname = (*nrnpy_po2pickle)(ob, &size); } if (pname) { style = 3; bbs->pkint(style); // pyfun, arg1, ... style bbs->pkpickle(pname, size); delete [] pname; }else{ style = 2; bbs->pkint(style); // [object],"fname", arg1, ... style bbs->pkstr(ob->ctemplate->sym->name); bbs->pkint(ob->index); //printf("ob=%s\n", hoc_object_name(ob)); bbs->pkstr(gargstr(i++)); } } firstarg = i; for (; ifarg(i); ++i) { // first is least significant if (hoc_is_double_arg(i)) { argtypes += 1*ii; }else if (hoc_is_str_arg(i)) { argtypes += 2*ii; }else if (is_vector_arg(i)) { //hoc Vector argtypes += 3*ii; }else{ // must be a PythonObject argtypes += 4*ii; } ii *= 5; } //printf("submit style %d %s argtypes=%o\n", style, gargstr(firstarg-1), argtypes); bbs->pkint(argtypes); pack_help(firstarg, bbs); #endif }else{ if (hoc_is_str_arg(i)) { bbs->pkint(0); // hoc statement style bbs->pkstr(gargstr(i)); }else if (nrnpy_po2pickle) { size_t size; pname = (*nrnpy_po2pickle)(*hoc_objgetarg(i), &size); bbs->pkint(3); // pyfun with no arg style bbs->pkpickle(pname, size); bbs->pkint(0); // argtypes delete [] pname; } } posting_ = false; return id; }