Пример #1
0
void hoc_construct_point(Object* ob, int narg) {
	if (skip_) {
//printf("skipped hoc_construct_point\n");
		return;
	}
//printf("%s is a pointprocess\n", hoc_object_name(ob));
	int type = ob->ctemplate->symtable->last->subtype;
	int ptype = pnt_map[type];
	Point_process* pnt = (Point_process*)create_point_process(ptype, ob);
	ob->u.dataspace[ob->ctemplate->dataspace_size - 1]._pvoid = (void*)pnt;
	assert(last_created_pp_ob_ == nil);
	last_created_pp_ob_ = ob;
	if (narg > 0) {
		double x = hoc_look_inside_stack(narg-1, NUMBER)->val;
//printf("x=%g\n", x);
		Section* sec = chk_access();
		Node* nd = node_exact(sec, x);
//printf("ptype=%d pnt=%lx %s nd=%lx\n", ptype, (long)pnt, secname(sec), (long)nd);
//printf("type=%d pointsym=%lx\n", type, pointsym[ptype]);
//printf("type=%d from pointsym %s = %d\n", type, pointsym[ptype]->name,
//pointsym[ptype]->subtype);

		nrn_loc_point_process(ptype, pnt, sec, nd);
	}
}
Пример #2
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;
	}
}	
Пример #3
0
psection()
{
	Section *sec;
	Prop *p, *p1;
	
	sec = chk_access();
	p = sec->prop;
	Printf("%s {", secname(sec));
	Printf(" nseg=%d  L=%g  Ra=%g", sec->nnode - 1, section_length(sec),
		nrn_ra(sec));
	if (p->dparam[4].val != 1) {
		Printf(" rallbranch=%g", p->dparam[4].val);
	}
	Printf("\n");
	if (sec->parentsec) {
		Printf("	%s ",secname(sec->parentsec));
		Printf("connect %s (%g), %g\n",	secname(sec),
			p->dparam[3].val, p->dparam[1].val);
	} else {
		v_setup_vectors();
		/*SUPPRESS 440*/
		Printf("	/*location %g attached to cell %d*/\n",
			p->dparam[3].val, sec->parentnode->v_node_index);
	}
	if (sec->nnode) {
		/*SUPPRESS 440*/
		Printf("	/* First segment only */\n");
		p1 = sec->pnode[0]->prop;
		pnode(p1);
	}
	Printf("}\n");
	ret(1.);
}
Пример #4
0
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_);
}
Пример #5
0
PyObject* nrnpy_cas(PyObject* self, PyObject* args) {
	Section* sec = chk_access();
	//printf("nrnpy_cas %s\n", secname(sec));
	section_ref(sec);
	NPySecObj* pysec = NULL;
	if (sec->prop->dparam[PROP_PY_INDEX]._pvoid) {
		pysec = (NPySecObj*)sec->prop->dparam[PROP_PY_INDEX]._pvoid;
		Py_INCREF(pysec);
		assert(pysec->sec_ == sec);
	}else{
		pysec = (NPySecObj*)psection_type->tp_alloc(psection_type, 0);
		pysec->sec_ = sec;
		pysec->name_ = 0;
		pysec->cell_ = 0;
	}
	return (PyObject*)pysec;
}
Пример #6
0
fmatrix() {
	if (ifarg(1)) {
		extern Node* node_exact(Section*, double);
		double x = chkarg(1, 0., 1.);
		int id = (int)chkarg(2, 1., 4.);
		Node* nd = node_exact(chk_access(), x);
		NrnThread* _nt = nd->_nt;
		switch (id) {
		case 1: ret(NODEA(nd)); break;
		case 2: ret(NODED(nd)); break;
		case 3: ret(NODEB(nd)); break;
		case 4: ret(NODERHS(nd)); break;
		}
		return;
	}
	nrn_print_matrix(nrn_threads);
	ret(1.);
}
Пример #7
0
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.);
}
Пример #8
0
static int 
e3(void)
{
	int	p1;
	register unsigned char	*a;
	unsigned char	*p2;
	long long	ll_1, ll_2;

	a = nxtarg(0);
	if (eq(a, "("))
	{
		p1 = sexp();
		if (!eq(nxtarg(0), ")"))
			failed("test",") expected");
		return(p1);
	}
	p2 = nxtarg(1);
	ap--;
	if ((p2 == 0) || (!eq(p2, "=") && !eq(p2, "!=")))
	{
		if (eq(a, "-r"))
			return(chk_access(nxtarg(0), S_IREAD, 0) == 0);
		if (eq(a, "-w"))
			return(chk_access(nxtarg(0), S_IWRITE, 0) == 0);
		if (eq(a, "-x"))
			return(chk_access(nxtarg(0), S_IEXEC, 0) == 0);
#ifdef	SUS
		if (eq(a, "-e"))
			return(access(nxtarg(0), F_OK) == 0);
		if (eq(a, "-S"))
			return(filtyp(nxtarg(0), S_IFSOCK));
		if (eq(a, "!"))
			return(!e3());
#endif	/* SUS */
		if (eq(a, "-d"))
			return(filtyp(nxtarg(0), S_IFDIR));
		if (eq(a, "-c"))
			return(filtyp(nxtarg(0), S_IFCHR));
		if (eq(a, "-b"))
			return(filtyp(nxtarg(0), S_IFBLK));
		if (eq(a, "-f"))
			if (ucb_builtins) {
				struct stat statb;
			
				return(stat((char *)nxtarg(0), &statb) >= 0 &&
					(statb.st_mode & S_IFMT) != S_IFDIR);
			}
			else
				return(filtyp(nxtarg(0), S_IFREG));
		if (eq(a, "-u"))
			return(ftype(nxtarg(0), S_ISUID));
		if (eq(a, "-g"))
			return(ftype(nxtarg(0), S_ISGID));
		if (eq(a, "-k"))
			return(ftype(nxtarg(0), S_ISVTX));
		if (eq(a, "-p"))
			return(filtyp(nxtarg(0), S_IFIFO));
		if (eq(a, "-h") || eq(a, "-L"))
			return(filtyp(nxtarg(0), S_IFLNK));
   		if (eq(a, "-s"))
			return(fsizep(nxtarg(0)));
		if (eq(a, "-t"))
		{
			if (ap >= ac)		/* no args */
				return(isatty(1));
			else if (eq((a = nxtarg(0)), "-a") || eq(a, "-o"))
			{
				ap--;
				return(isatty(1));
			}
			else
				return(isatty(atoi((char *)a)));
		}
		if (eq(a, "-n"))
			return(!eq(nxtarg(0), ""));
		if (eq(a, "-z"))
			return(eq(nxtarg(0), ""));
	}

	p2 = nxtarg(1);
	if (p2 == 0)
		return(!eq(a, ""));
	if (eq(p2, "-a") || eq(p2, "-o"))
	{
		ap--;
		return(!eq(a, ""));
	}
	if (eq(p2, "="))
		return(eq(nxtarg(0), a));
	if (eq(p2, "!="))
		return(!eq(nxtarg(0), a));
	ll_1 = stoifll(a);
	ll_2 = stoifll(nxtarg(0));
	if (eq(p2, "-eq"))
		return (ll_1 == ll_2);
	if (eq(p2, "-ne"))
		return (ll_1 != ll_2);
	if (eq(p2, "-gt"))
		return (ll_1 > ll_2);
	if (eq(p2, "-lt"))
		return (ll_1 < ll_2);
	if (eq(p2, "-ge"))
		return (ll_1 >= ll_2);
	if (eq(p2, "-le"))
		return (ll_1 <= ll_2);

	bfailed(btest, badop, p2);
/* NOTREACHED */
	return 0;
}
Пример #9
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);
			}
		}
	}
}
Пример #10
0
VecPlayContinuous::VecPlayContinuous(const char* s, IvocVect* y, IvocVect* t, IvocVect* discon, Object* ppobj) : PlayRecord(&NODEV(chk_access()->pnode[0]), ppobj) {
//printf("VecPlayContinuous\n");
	init(y, t, discon);
	si_ = new StmtInfo(s);
}
Пример #11
0
VecPlayStep::VecPlayStep(const char* s, IvocVect* y, IvocVect* t, double dt, Object* ppobj) : PlayRecord(&NODEV(chk_access()->pnode[0]), ppobj) {
//printf("VecPlayStep\n");
	init(y, t, dt);
	si_ = new StmtInfo(s);
}