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

tvec = new Vector(record_vec_size)

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

// *** Process data and print out results

proc insert_iclamps_soma() { local i,j // 2 args - del dur
	for i = 0, nmitx-1 {
		for j = 0, nmity-1 {
			mit[i][j].soma input_soma[i][j] = new IClamp(0.5)
			input_soma[i][j].dur = tstop
			input_soma[i][j].del = 0
		}
  	}
}

insert_iclamps_soma(tstop)
for i=0,nmitx-1 {
	input_soma[i][0].amp = -0.1
	input_soma[i][0].dur = tstop
	input_soma[i][0].del = 500
}

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

xopen("fig1fg.ses")

xpanel("Control")
xbutton("Run fig 1fg", "run_fig1fg()")
xvalue("Shunt conductnace","shunt[0].amp", 1,"change_shuntg()", 0, 1)
xvalue("Input soma","input_soma[0][0].amp", 1,"change_input()", 0, 1)
xpanel(930,200)

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

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

proc run_fig1fg() {
	sprint(filename,"%s.dat","fig1fg")
	outfile.wopen(filename)

	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",vsoma[j].x[i])
		}
		outfile.printf("%8.7g \n",vsoma[nmitx-1].x[i])
	}
	outfile.close()
}