objref tvec, iclamp, vgran,  i_soma_br[nmitx], random1
record_step = 0.1
record_vec_size = int(tstop/record_step)+1
objref Iinj
Iinj = new Vector(3)
Iinj.x[0] = 0.5
Iinj.x[1] = 0.8
Iinj.x[2] = 1.8

i_soma_br = new Vector(nmitx)

a = startsw() //sert a generer la seed

random1 = new Random(a)
random1.uniform(0,50)

record_step = 0.1

insert_iclamps_reg(tstop)
connect_cell()

xopen("fig5.ses")

bruit_step = 0.1
 
mit[0][0].soma	i_soma_br[0] = new current_gauss(0.5)
i_soma_br[0].dur   = 4000
i_soma_br[0].std0  = 0.9
i_soma_br[0].f0    = 4000
i_soma_br[0].tau_f = 1

GabaAGr_Gran2Mit.tau = 5
gran.d2g.Ra = 1500000 
GabaAGr_Gran2Mit.gmax = 0
nbnoise = 20

xpanel("Choose parameters")
xvalue("Noise realizations","nbnoise",1,"change_nbnoise()",0,1)
xbutton("Run fig5", "run_fig5()")
xpanel(930,200)

proc change_nbnoise() {
	nbnoise = nbnoise
}

proc run_fig5() {
	for i=0, 2 {
		input_reg[0][0].amp = Iinj.x[i] 
		sprint(filename,"%s%f.dat","fig5_",Iinj.x[i])
		outfile.wopen(filename)
		// BOUCLE SUR LE BRUITLoop for the noise
		for w = 0, nbnoise-1 {
			// loop for the inhibition weight
			for p= 0,10 {
				i_soma_br[0].seed(a+w)
				GabaAGr_Gran2Mit.gmax = 0.02 * (10^(0.3775*p)-1)
			        run()
				print mit[0][0].spiketimes.x[0], mit[0][0].spiketimes.x[1], mit[0][0].spiketimes.x[2]
				mit[0][0].spiketimes.printf(outfile,"%10.3f")
				outfile.printf("\n")
			}
		print "w=", w
		}
		outfile.close()
	}
}