// *** Set-up recording
objref igabaa, tvec, iclamp

objref input[nmitx][nmity], delai[nmitx]
objref Iinj
Iinj = new Vector(3)
Iinj.x[0] = 0.5
Iinj.x[1] = 0.8
Iinj.x[2] = 1.8

insert_iclamps_reg()
insert_iclamp_ipsc(tstop)
delai = new Vector(10)

xopen("fig2bdf.ses")

for i=0,nmitx-1 {
	input_reg[i][0].amp  = 1.8 //1.8//0.8 //0.5//30Hz //1.5//40Hz 
	input_ipsc[i][0].del = 1000
}
w=0
for i=0,nmitx-1 {
	input_ipsc[i][0].amp = 0
	input_ipsc[i][0].del = 0
}

xpanel("Control")
xbutton("Run fig 2bdf", "run_fig2bdf()")
xvalue("Tau gGABAa","input_ipsc[0][0].tau", 1,"change_taugaba()", 0, 1)
xpanel(930,200)

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

proc run_fig2bdf() {
	for st = 0, 2 {
		sprint(filename,"fig2_%f.dat",Iinj.x[st])
		outfile.wopen(filename)
		for i=0,9 { 
			input_reg[i][0].amp = Iinj.x[st]
		}
		run()
		for i=0,nmitx-1 {
			mit[i][0].spiketimes.printf(outfile,"%10.3f")
			outfile.printf("\n")
			isi= mit[i][0].spiketimes.x[10]-mit[i][0].spiketimes.x[9]
			delai.x[i]=mit[i][0].spiketimes.x[9]
			if (isi<15) {
				isi= mit[i][0].spiketimes.x[11]-mit[i][0].spiketimes.x[10]
				input_ipsc[i][0].del = mit[i][0].spiketimes.x[10]
				delai.x[i]=mit[i][0].spiketimes.x[10]
				if (isi<15) {
					input_ipsc[i][0].del = mit[i][0].spiketimes.x[11]
					isi= mit[i][0].spiketimes.x[12]-mit[i][0].spiketimes.x[11]
					delai.x[i]=mit[i][0].spiketimes.x[11]
					if (isi<15) {
						input_ipsc[i][0].del = mit[i][0].spiketimes.x[12]
						isi= mit[i][0].spiketimes.x[13]-mit[i][0].spiketimes.x[12]
						delai.x[i]=mit[i][0].spiketimes.x[12]
					}
				}
			}
		print isi
		}

		print "w=", w
		for w = 1, 60 { 			// boucle sur le delai 55 
			run()
			for i=0,nmitx-1 {
				mit[i][0].spiketimes.printf(outfile,"%10.3f")
				outfile.printf("\n")
				input_ipsc[i][0].del = delai.x[i] + w
				input_ipsc[i][0].amp = -0.05

				print mit[i][0].spiketimes.x[10]-mit[i][0].spiketimes.x[9]
			}
			print "w=", w
		}
	outfile.close()
	}
}