load_file("nrngui.hoc")

objectvar ocbox_, ocbox_list_, scene_, scene_list_
objref sph

{ocbox_list_ = new List()  scene_list_ = new List()}

vplot=1
gplot=0
if (passive==0) stateplot=1
shapeplot=0
syngrp=0


//open RunControl and set defaults
{
xpanel("RunControl", 0)
xvalue("Init","v_init", 1,"stdinit()", 1, 1 )
xbutton("Init & Run","run()")
xbutton("Stop","stoprun=1")
xvalue("Continue til","runStopAt", 1,"{continuerun(runStopAt) stoprun=1}", 1, 1 )
xvalue("Continue for","runStopIn", 1,"{continuerun(t + runStopIn) stoprun=1}", 1, 1 )
xbutton("Single Step","steprun()")
xvalue("t","t", 2 )
xvalue("Tstop","tstop", 1,"tstop_changed()", 0, 1 )
xvalue("dt","dt", 1,"setdt()", 0, 1 )
xvalue("Points plotted/ms","steps_per_ms", 1,"setdt()", 0, 1 )
xvalue("Scrn update invl","screen_update_invl", 1,"", 0, 1 )
xvalue("Real Time","realtime", 0,"", 0, 1 )
xpanel(680,8)
}

load_file("pointgrp.hoc")
objref ms
//Begin PointProcessGroupManager
if (syngrp == 1) {

	if (verbosity > 1) printf("this should not happen\n")

	ocbox_ = new PointProcessGroupManager(0)

	object_push(ocbox_)

	ms = new MechanismStandard("AlphaSynapse")
	ms.set("onset", 150, 0)
	ms.set("tau", 0.1, 0)
	ms.set("gmax", 0, 0)
	ms.set("e", 0, 0)
	mnews("AlphaSynapse", ms)
	select(0)
	execute("Tines[510] ocbox_.move(0.5)")


	ms = new MechanismStandard("AlphaSynapse")
	ms.set("onset", 50, 0)
	ms.set("tau", 0.1, 0)
	ms.set("gmax", 0, 0)
	ms.set("e", 0, 0)
	mnews("AlphaSynapse", ms)
	select(1)
	execute("Tines[510] ocbox_.move(0.5)")

	object_pop() doNotify()


	ocbox_ = ocbox_.v1
	ocbox_.map("PointProcessGroupManager", 989, 29, 556.8, 295.68)

	objref ocbox_
} //End PointProcessGroupManager


objref grph0
objref scene_vector_[8]

if (vplot) {
	grph0 = new Graph(0)
	scene_vector_[5] = grph0
	{grph0.view(0, -69, 500, 40, 800, 400, 800, 350)}
	//(mleft, mbottom, mwidth, mheight, wleft,wtop, wwidth, wheight)
	// in a window with user-specified location (5th and 6th args) and size (last 2 args)
	graphList[0].append(grph0)
	//addplot(g,0)
	//g.size(0, 500, -80, -50)        // specify coordinate system for the canvas drawing area
	//g.simgraph()
	//g.family(1)
	grph0.addvar("Axon[20].v(0.5)", 4,1)
	grph0.addvar("Tines[621].v(0.5)", 2,1)
	grph0.addvar("Handle[10].v(0.5)", 1,1)
	grph0.addvar("FieldC[22].v(0.5)", 7,1)
	grph0.addvar("FieldB[28].v(0.5)", 5,1)
	grph0.addvar("MainTrunk[0].v(0.5)", 3,1)
// 	grph0.addvar("Tines[786].v(0.5)", 4,1)
	grph0.addvar("soma.v(0.5)", 6,1)
}

if (gplot) {
	grph0 = new Graph(0)
	scene_vector_[4] = grph0
	{grph0.view(0, 0, 500, 0.001, 50, 400, 700, 350)}
	//(mleft, mbottom, mwidth, mheight, wleft,wtop, wwidth, wheight)
	// in a window with user-specified location (5th and 6th args) and size (last 2 args)
	graphList[0].append(grph0)

	grph0.addvar("Tines[621].g_h(0.5)", 2,1)
	grph0.addvar("Tines[786].g_h(0.5)", 4,1)
	grph0.addvar("Tines[621].g_KD(0.5)", 2,1)
	grph0.addvar("Tines[786].g_KD(0.5)", 4,1)
}

if (stateplot) {
	grph0 = new Graph(0)
	scene_vector_[6] = grph0
	{grph0.view(0, 0, 500, 1, 50, 400, 700, 350)}
	//(mleft, mbottom, mwidth, mheight, wleft,wtop, wwidth, wheight)
	// in a window with user-specified location (5th and 6th args) and size (last 2 args)
	graphList[0].append(grph0)

	if (synCa<3) {
		grph0.addvar("Tines[621].n_h(0.5)", 1,1)
	} else if (synCa == 3) {
		grph0.addvar("Tines[621].n_hcn(0.5)", 1,1)
	} else {
		grph0.addvar("Tines[621].m_h_ca(0.5)", 1,1)
	}
	{Tines[621] tmp = ismembrane("NaP")}
	if (tmp) grph0.addexpr("Tines[621].g_NaP(0.5)/Tines[621].gmax_NaP(0.5)", 5,1)
	//if (synCa) grph0.addexpr("Tines[621].g_KCa(0.5)/Tines[621].gmax_KCa(0.5)", 1,1)
	//grph0.addvar("Tines[786].l_KD_ca2(0.5)", 2,1)
	//grph0.addvar("Tines[786.n_KD_ca2(0.5)", 5,1)
	//grph0.addexpr("Handle[0].cai(0.5)*100", 9, 1)
	grph0.addexpr("Handle[15].g_KCa/Handle[15].gmax_KCa", 9,1)
	grph0.addexpr("Handle[15].g_CaT/Handle[15].gmax_CaT", 3,1)
	if (ismembrane("CaS"))	grph0.addexpr("Handle[15].g_CaS/Handle[15].gmax_CaS", 1,1)
	grph0.addexpr("Handle[15].g_M/Handle[15].gmax_M", 6,1)

	if (synCa==1) {
	grph0.addexpr("Tines[621].g_KD_ca2(0.5)/Tines[621].gmax_KD_ca2(0.5)", 2,1)
	grph0.addexpr("Tines[786].g_KD_ca2(0.5)/Tines[786].gmax_KD_ca2(0.5)", 4,1)
	grph0.addexpr("Tines[614].g_KD_ca2(0.5)/Tines[614].gmax_KD_ca2(0.5)", 6,1)
	grph0.addexpr("Tines[380].g_KD_ca2(0.5)/Tines[380].gmax_KD_ca2(0.5)", 9,1)
	} else if (synCa==2){
	grph0.addexpr("Tines[621].g_KD_cn(0.5)/Tines[621].gmax_KD_cn(0.5)", 2,1)
	grph0.addexpr("Tines[786].g_KD_cn(0.5)/Tines[786].gmax_KD_cn(0.5)", 4,1)
	grph0.addexpr("Tines[614].g_KD_cn(0.5)/Tines[614].gmax_KD_cn(0.5)", 6,1)
	grph0.addexpr("Tines[380].g_KD_cn(0.5)/Tines[380].gmax_KD_cn(0.5)", 9,1)
	} else if (synCa==3){
	//grph0.addexpr("Tines[621].g_KD_ca3(0.5)/Tines[621].gmax_KD_ca3(0.5)", 2,1)
	grph0.addexpr("Tines[786].g_KD_ca3(0.5)/Tines[786].gmax_KD_ca3(0.5)", 4,1)
	} else if (synCa>3){
	grph0.addexpr("Tines[621].g_KD_cn2(0.5)/Tines[621].gmax_KD_cn2(0.5)", 2,1)
	grph0.addexpr("Tines[786].g_KD_cn2(0.5)/Tines[786].gmax_KD_cn2(0.5)", 4,1)
	//grph0.addexpr("Tines[614].g_KD_cn2(0.5)/Tines[614].gmax_KD_cn2(0.5)", 6,1)
	//grph0.addexpr("Tines[380].g_KD_cn2(0.5)/Tines[380].gmax_KD_cn2(0.5)", 9,1)
	} else if (synCa==0){
		grph0.addexpr("Tines[621].g_KD/Tines[621].gmax_KD", 4,1)
//		grph0.addexpr("Tines[621].g_KA/Tines[621].gmax_KA", 2,1)
// 		grph0.addexpr("Tines[614].g_KD(0.5)/Tines[614].gmax_KD(0.5)", 6,1)
// 		grph0.addexpr("Tines[380].g_KD(0.5)/Tines[380].gmax_KD(0.5)", 4,1)
	}
}

if (shapeplot) {

	sph = new PlotShape(0)
	sph.size(60.6917,540.608,62.739,324.261)
//	if (acn) {
//		sph.variable("cni")
//		sph.scale(0, 1e-3)
//	} else {
		sph.variable("cai")
		sph.scale(0, 5e-3)
//	}
	sph.show(0)
	sph.observe(FieldA)
	scene_vector_[4] = sph
	{sph.view(66, 100, 420, 230, 960, 10, 640, 333)}
	fast_flush_list.append(sph)
	sph.save_name("fast_flush_list.")
	sph.rotate(0,0,0,0.7,0,0)
	sph.exec_menu("Shape Plot")

}

// dt = 0.02
// steps_per_ms = 25
// screen_update_invl = 0.1

/*0 white
1 black
2 red
3 blue
4 green
5 orange
6 brown
7 violet
8 yellow
9 gray*/
/*

objectvar gi
gi = new Graph(0)
scene_vector_[6] = gi
{gi.view(-10, 0, 500, 0, 100, 300, 700, 300)}
graphList[0].append(gi)
gi.addvar("Tines[786].g_KD( 0.5 )", 1, 1, 0.8, 0.9, 2)
gi.addvar("Tines[786].g_h( 0.5 )", 3, 1, 0.8, 0.9, 2)
*/