// to show IPSP on M0 - no EPSP input

load_file("nrngui.hoc")
load_file("mitral-lss.hoc")
load_file("gc-ka.hoc")
cvode.active(1)

Vrest = -65
dt = 1
celsius=35
tstop=200

objref nconp[3], net, netp[3], g, b, synp, nil, stim, apc
objref mt[3], gc[3], train, outfile, coeff[3], table
objref nc[27]
//objref mitral, mitralt, tmitral, tmitralt, pmitral, pmitralt

for i=0, 1 {
mt[i] = new Mitral()
gc[i] = new GC()
}

weight=.1
amp=.03
rel=0.2
inh=13
synstr=3
nmdafactor=0.0035
frac=1

mt[0].soma {
stim = new IClamp(.5)
stim.amp=0.5
stim.dur=4
stim.del=2
}
temp=100
flag=0
b = new VBox()
b.intercept(1)
g = new Graph()
g.size(0,tstop,-70,0)
g.xaxis(1)
g.addvar("mt[0].soma.v(0.5)",1,1,0.7,1,2)
g.addvar("mt[1].soma.v(0.5)",2,2,0.7,0.98,2)
g.exec_menu("10% Zoom out")
xpanel("",1)
xvalue("distance (0-1000)","temp")
xbutton("runm", "runm()")
xstatebutton("GC1",&flag)
xpanel()
b.intercept(0)
b.map()


////////////////// circuit definition  

///// gc <-> mt

mt[0].secden[1]	nc[1]= new NetCon(&v(0),gc[0].synmt[0],-40,1,synstr*nmdafactor) 
mt[0].secden[1]	nc[2]= new NetCon(&v(0),gc[0].sampa[0],-40,1,synstr*1e-3) 
mt[0].secden[1]	nc[16]= new NetCon(&v(0.4),gc[1].synmt[2],-40,1,synstr*nmdafactor) 
mt[0].secden[1]	nc[17]= new NetCon(&v(0.4),gc[1].sampa[2],-40,1,synstr*1e-3) 

gc[0].dend[4]	nc[6]= new NetCon(&v(1),mt[1].igp[0][2],-40,1,inh*1e-3) 
gc[1].dend[0]	nc[9]= new NetCon(&v(1),mt[1].igp[1][0],-40,1,0*1e-3) 


////////////////// end circuit definition


proc init() {
	t=0
	finitialize(Vrest)
        fcurrent()
        forall {
		v=Vrest
		if (ismembrane("nax")) {e_pas=v+(ina+ik)/g_pas
		} else {
		e_pas=v+ik/g_pas
		}
	}
	cvode.re_init()
	g.begin()
	g.plot(t)
}

proc advance() {
	fadvance()
	g.plot(t)
	g.flush()
	doNotify()
}

proc runm() {
	if (temp>1000) temp=1000
	mt[1].secden[0] mt[1].igp[0][2].loc(temp/1000)
	nc[9].weight=flag*inh*1e-3
	init()
	run()
}