Ejemplo n.º 1
0
void make_mechanism() {
	char buf[256];
	int i, cnt;
	Symbol* sp;
	char* mname = gargstr(1);
//printf("mname=%s\n", mname);
	check(mname);
	char* classname = gargstr(2);
//printf("classname=%s\n", classname);
	char* parnames = nil;
	if (ifarg(3)) {
		parnames = new char[strlen(gargstr(3)) + 1];
		strcpy(parnames, gargstr(3));
	}
//if(parnames) printf("parnames=%s\n", parnames);
	Symbol* classsym = hoc_lookup(classname);
	if (classsym->type != TEMPLATE) {
		hoc_execerror(classname, "not a template");
	}
	cTemplate* tp = classsym->u.ctemplate;
	Symlist* slist = tp->symtable;
	char** m = make_m(true, cnt, slist, mname, parnames);

	common_register(m, classsym, slist, alloc_mech, i);
		
	for (sp = slist->first; sp; sp = sp->next) {
		if (sp->type == VAR && sp->cpublic) {
			sprintf(buf, "%s_%s", sp->name, m[1]);
			Symbol* sp1 = hoc_lookup(buf);
			sp1->u.rng.index = sp->u.oboff;
		}
	}
	for (i=0; i < cnt; ++i) {
		if (m[i]) {
			delete [] m[i];
		}
	}
	delete [] m;
	delete [] parnames;
	ret(1.);
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: Flyswat/wmmp
mat make_Y(uint Nv, uint Ns, uint Nc, mat U, double wcr)
{
	uint i;
	mat Y = mat_new(Nv,Ns);
	it_randomize();
	for (i=0; i < Ns; i++) {
		vec x, y, w;
		bvec m;

		x = make_x( Nv );
		m = make_m( Nc );
		w = make_w( U, m );

		y = make_y( x, w, wcr );
		mat_set_col(Y,i,y);

		vec_delete( x );
		vec_delete( w );
		vec_delete( y );
		bvec_delete( m );
	}

	return Y;
}
Ejemplo n.º 3
0
void make_pointprocess() {
	char buf[256];
	int i, cnt, type, ptype;
	Symbol* sp, *s2;
	char* classname = gargstr(1);
//printf("classname=%s\n", classname);
	char* parnames = nil;
	if (ifarg(2)) {
		parnames = new char[strlen(gargstr(2)) + 1];
		strcpy(parnames, gargstr(2));
	}
//if(parnames) printf("parnames=%s\n", parnames);
	Symbol* classsym = hoc_lookup(classname);
	if (classsym->type != TEMPLATE) {
		hoc_execerror(classname, "not a template");
	}
	cTemplate* tp = classsym->u.ctemplate;
	Symlist* slist = tp->symtable;
	// increase the dataspace by 1 void pointer. The last element
	// is where the Point_process pointer can be found and when
	// the object dataspace is freed, so is the Point_process.
	if (tp->count > 0) {
fprintf(stderr, "%d object(s) of type %s already exist.\n", tp->count, classsym->name);
hoc_execerror("Can't make a template into a PointProcess when instances already exist", 0);
	}
	++tp->dataspace_size;
	char** m = make_m(false, cnt, slist, classsym->name, parnames);
	
	check_list("loc", slist);
	check_list("get_loc", slist);
	check_list("has_loc", slist);
	//so far we need only the name and type
	sp = hoc_install("loc", FUNCTION, 0., &slist); sp->cpublic = 1;
	sp = hoc_install("get_loc", FUNCTION, 0., &slist); sp->cpublic = 1;
	sp = hoc_install("has_loc", FUNCTION, 0., &slist); sp->cpublic = 1;

	Symlist* slsav = hoc_symlist;
	hoc_symlist = nil;
	HocMech* hm = common_register(m, classsym, slist, alloc_pnt, type);
	hm->slist = hoc_symlist;
	hoc_symlist = slsav;
	s2 = hoc_table_lookup(m[1], hm->slist);
	assert(s2->subtype == type);
//	type = s2->subtype;
	ptype = point_reg_helper(s2);
//printf("type=%d pointtype=%d %s %lx\n", type, ptype, s2->name, (long)s2);
	classsym->u.ctemplate->is_point_ = ptype;

	// classsym->name is already in slist as an undef, Remove it and
	// move s2 out of HocMech->slist and into slist.
	// That is the one with the u.ppsym.
	// The only reason it needs to be in slist is to find the
	// mechanims type. And it needs to be LAST in that list.
	// The only reason for the u.ppsym is for ndatclas.c and we
	// need to fill those symbols with oboff.
	sp = hoc_table_lookup(classsym->name, slist);
	hoc_unlink_symbol(sp, slist);
	hoc_unlink_symbol(s2, hm->slist);
	hoc_link_symbol(s2, slist);
	hoc_link_symbol(sp, hm->slist); // just so it isn't counted as leakage
	for (i=0; i < s2->s_varn; ++i) {
		Symbol* sp = hoc_table_lookup(s2->u.ppsym[i]->name, slist);
		s2->u.ppsym[i]->cpublic = 2;
		s2->u.ppsym[1]->u.oboff = sp->u.oboff;
	}
	for (i=0; i < cnt; ++i) {
		if (m[i]) {
			delete [] m[i];
		}
	}
	delete [] m;
	if (parnames) {
		delete [] parnames;
	}
	ret(1.);
}