Esempio n. 1
0
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;
	}
}	
Esempio n. 2
0
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;
}
Esempio n. 3
0
static void* ste_cons(Object*) {
	int nstate = (int)chkarg(1, 1, 1e6);
	Point_process* pnt = NULL;
	if (ifarg(2)) {
		Object* obj = *hoc_objgetarg(2);
		pnt = ob2pntproc(obj);
	}
	StateTransitionEvent* ste = new StateTransitionEvent(nstate, pnt);
	return ste;
}
Esempio n. 4
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);
			}
		}
	}
}