// fig10a.hoc
// recreates figure 10a from Oltedal et al 2007

// synthetic conductance wave form files will be played into the
// synthetic conductance mechanism

objref Gsynth_files[3]
for i=0,2 {
	Gsynth_files[i]=new File()
}
{Gsynth_files[0].ropen("gsynth_1ms__.dat")}
{Gsynth_files[1].ropen("gsynth_5ms__.dat")}
{Gsynth_files[2].ropen("gsynth_10ms__.dat")}

// single electrode voltage clamp
objref rs_vec
{rs_vec=new Vector()}
{rs_vec.append(1,10,20,40,80,160,320,640,1000)}

// place synthetic conductance into terminal
objref pp // pp will be a point process
// typical placement gets moved between 
Term pp=new Gsynth(0.5)
// Term and Soma

objref time_vec, Gsynth_vec
time_vec = new Vector(100001)
Gsynth_vec = new Vector(100001)

// waves read later will be played into the
// synthetic conductance mechanism

Gsynth_vec.play(&pp.g, time_vec)

tstop=100
SEClamp[0].amp2=-60 // default was -70
SEClamp[0].dur3=80 // make go at least out to 100ms

objref vbox, hbox[3], graphs[3][3]
{vbox=new VBox()}
{vbox.intercept(1)}

// record the SEClamp[0] in a 
objref current_vec
{current_vec = new Vector()}
{current_vec.record(&SEClamp[0].i)}

for i=0,2 {
	hbox[i] = new HBox()
}
print "Creating fig 10a please wait:"

for i=0,2 {
	for j=0,100000 {
		{time_vec.x[j]=Gsynth_files[i].scanvar()}
		{Gsynth_vec.x[j]=Gsynth_files[i].scanvar()}
	}
	print " row ",i+1,"/3"
	// print Gsynth_vec.max(),time_vec.max()
	// synaptic conductance waveforms
	{hbox[i].intercept(1)}
	{graphs[i][0]=new Graph()}
	{Gsynth_vec.line(graphs[i][0], time_vec)}
	{graphs[i][0].exec_menu("View = plot")}
	print "graph 1"
	// currents in terminal end recordings
	{Term pp=new Gsynth(0.5)}
	{Gsynth_vec.play(&pp.g, time_vec)}
	{graphs[i][1]=new Graph()}
	{graphs[i][1].exec_menu("Keep Lines")}
	for j=0,rs_vec.size()-1 {
		{SEClamp[0].rs=rs_vec.x[j]}
		init()
		run()
		{current_vec.line(graphs[i][1],time_vec)}		
	}
	{graphs[i][1].size(-1,60,-0.03,0.)}// or exec_menu("View = plot")}
	print "graph 2"

	// currents in soma-end recordings
	{graphs[i][2]=new Graph()}
	{graphs[i][2].exec_menu("Keep Lines")}
	{Soma pp=new Gsynth(0.5)}
	{Gsynth_vec.play(&pp.g, time_vec)}
	for j=0,rs_vec.size()-1 {
		{SEClamp[0].rs=rs_vec.x[j]}
		init()
		run()
		{current_vec.line(graphs[i][2],time_vec)}
	}
	{graphs[i][2].size(-1,60,-0.03,0.)} // or exec_menu("View = plot")}
	{hbox[i].intercept(0)}
	{hbox[i].map()}
	print "graph 3"
}
vbox.intercept(0)
vbox.map()