// *** Set-up recording
objref igabaa, tvec, vmit[nmitx],  shunt[nmitx]
record_step = 0.01
record_vec_size = int(tstop/record_step)+1

tvec = new Vector(record_vec_size)
for i=0,nmitx-1 {
	vmit[i]= new Vector(record_vec_size)
	vmit[i].record(&mit[i][0].soma.v(0.5),record_step)
}
tvec.record(&t,record_step)

insert_iclamps_reg(tstop)
for i = 0, nmitx-1 {
	input_reg[i][0].amp = 0 
	input_reg[i][0].dur = tstop
	input_reg[i][0].del = 0
}

insert_iclamp_ipsc()

xpanel("Control")
xvalue("Axial Resistance","mit[0][0].dend[0].Ra", 1,"change_raxial()", 0, 1)
xvalue("GABA Time constant (bde)","input_ipsc[0][0].tau", 1,"change_taugaba()", 0, 1)
xvalue("GABA conductance (for bde)","input_ipsc[0][0].amp", 1,"change_ggaba()", 0, 1)
xbutton("Run fig 1bde", "run_fig1bde()")
xbutton("Run fig 1fg", "run_fig1fg()")
xpanel(930,200)

proc change_raxial() {
	for i=0,nmitx-1 {
		for j=0,ndend-1 {
			mit[i][0].dend[j].Ra = mit[0][0].dend[0].Ra
		}
	}
}

proc change_taugaba() {
	for i = 0, nmitx-1 {
		input_ipsc[i][0].tau = input_ipsc[0][0].tau
	}
}

proc change_ggaba() {
	for i = 0, nmitx-1 {
		input_ipsc[i][0].amp = input_ipsc[0][0].amp
	}
}

proc run_fig1bde() {
	sprint(filename,"%s.dat","fig1bde")
	outfile.wopen(filename)
	for i = 0, nmitx-1 {
      		input_ipsc[i][0].amp = -0.05
      		input_ipsc[i][0].dur = tstop
      		input_ipsc[i][0].del = 150
      		input_ipsc[i][0].tau = 5
	}
	xopen("fig1bde.ses")
	run()
	for i = 0, tvec.size()-1 {
		outfile.printf("%8.7g \t",tvec.x[i])
		for j = 0, nmitx-2 {
			outfile.printf("%8.7g \t",vmit[j].x[i])
		}
		outfile.printf("%8.7g \n",vmit[nmitx-1].x[i])
	}
	outfile.close()
}

proc run_fig1fg() {
	sprint(filename,"%s.dat","fig1fg")
	outfile.wopen(filename)
	tstop = 1000
	for i=0,nmitx-1 {
		input_reg[i][0].amp = -0.1
		input_reg[i][0].dur = tstop
		input_reg[i][0].del = 500

		input_ipsc[i][0].amp = 0
	}

	for j=0,nmitx-1 {
		ind = 5*(j+1)-1
		mit[j][0].dend[ind] shunt[j] = new shuntI(0.5)
		shunt[j].amp = 1
		shunt[j].del = 20
		shunt[j].dur = 1000
	}

	xopen("fig1fg.ses")
	run()
	for i = 0, tvec.size()-1 {
		outfile.printf("%8.7g \t",tvec.x[i])
		for j = 0, nmitx-2 {
			outfile.printf("%8.7g \t",vmit[j].x[i])
		}
		outfile.printf("%8.7g \n",vmit[nmitx-1].x[i])
	}
	outfile.close()
}