objref inp
numodors=6
double odors[numodors][5]

	inp=new File()
	inp.ropen("odors.txt")
	for od=0, numodors-1 {
		for tf=0, 4 {
			odors[od][tf]=inp.scanvar()
			print " odor ",od, " mitral ",tf, odors[od][tf]
		}
	}
	inp.close()

begintemplate OBStim
public nc, mgid, exists, ww,si,sw, endod, start, odors
external cvode
objref nc, rinterval, rweight, fih, this

proc init(){localobj cell, pc, nil
	pc = new ParallelContext()
	exists = 0
	// $1 is mitral_gid
	mgid = $1
	si=1
	sw=1
	ww=0
	endod=10000
	start = 2
    if (pc.gid_exists(mgid)) {
	exists = 1
	seed_interval = si*10000 + 1
	seed_weight = sw*10000 + 5000
//	seed_interval = mgid*10000 + 1
//	seed_weight = mgid*10000 + 5000
	cell = pc.gid2cell(mgid)
	nc = new NetCon(nil, cell.synodor)
	nc.delay = 0.5
	fih = new FInitializeHandler(0, "init_ev()", this)
    }
}

proc init_ev() {
	printf("%s t=%g %g\n", this, t, start)

	rinterval = new Random()
	rinterval.MCellRan4(seed_interval)
	rinterval.uniform(100, 250)

	rweight = new Random()
	rweight.MCellRan4(seed_interval)
	rweight.uniform(0.4, 0.5)

	cvode.event(t + start, "ev()")//, this)
	nc.event(t + start + nc.delay)
	nc.weight = 0
}

proc ev() {local next
	if (1) {
		nc.weight = ww*rweight.repick()*1e-3
	}
	next = rinterval.repick()
//	next = 220
	printf("%s t=%g %g w=%g\n", this, t, next, nc.weight)
	next += t

	if (next<endod) {
		cvode.event(next, "ev()")//, this)
		nc.event(next + nc.delay)
	}
}

endtemplate OBStim

objref stim_list_

proc create_stim() {localobj nil, wl, wh
	stim_list_ = new List()
	od=2
	index=0
	for i=0, nmitral-1 {
		stim_list_.append(new OBStim(i)) 
		stim_list_.o(index).ww=odors[od][i]
		stim_list_.o(index).sw=i
		stim_list_.o(index).start=2
		stim_list_.o(index).endod=20000
		index=index+1
	}
	od=0
	j=nmitral
	for i=0, nmitral-1 {
		stim_list_.append(new OBStim(i)) 
		stim_list_.o(index).ww=odors[od][i]
		stim_list_.o(index).sw=i
		stim_list_.o(index).start=20000
		stim_list_.o(index).endod=40000
		index=index+1
	}
	od=3
	j=nmitral
	for i=0, nmitral-1 {
		stim_list_.append(new OBStim(i)) 
		stim_list_.o(index).ww=odors[od][i]
		stim_list_.o(index).sw=i
		stim_list_.o(index).start=40000
		stim_list_.o(index).endod=60000
		index=index+1
	}
}

create_stim()