load_file("nrngui.hoc")
cvode_active(0)

Vrest = -55

dt = 0.1
gna = 0.08
gkdr = 0.01
gka = 0.02
celsius = 35.0  //temperature change not implemented

Rm = 15000
Cm    = 1

RaAll= 150
RaAx = 50

numaxon=104
numsoma=6
numdend=44


xopen("n257-noaxon.hoc")
xopen("fixnseg.hoc")           

nfreq=512

objref stim,apc,b,g,tempo,nil,apct

apc = new APCount(0.5)
apc.thresh=-20





forsec "axon" {insert pas e_pas=Vrest g_pas = 1/Rm Ra=RaAx cm=Cm}
forsec "soma" {insert pas e_pas=Vrest g_pas = 1/Rm Ra=RaAll cm=Cm}
forsec "dend" {insert pas e_pas=Vrest g_pas = 1/Rm Ra=RaAll cm=Cm}




geom_nseg()
tot=0
forall {tot=tot+nseg}
distance()

maxdist=0
forsec "dend" for(x) {if (distance(x)>maxdist) {maxdist=distance(x)}}





access soma[1]

stim = new IClamp(0.5)
stim.del=10
stim.dur=200

tstop=200

access soma[1]
distance()

apc = new APCount(0.5)
apc.thresh=-20

tempo = new Vector()

soma {
apct = new NetCon(&v(0.5),nil,0,0,0)
apct.record(tempo)
}






forall {              
 insert na3 gbar_na3=gna
              insert kdr gkdrbar_kdr=gkdr
              insert kap gkabar_kap = gka
              insert pas e_pas=Vrest 
}
forsec "dend" {              
              gbar_na3=gna*0.2
              gkdrbar_kdr=gkdr*0.2
              gkabar_kap = gka*0.2
   }



b = new VBox()
b.intercept(1)
g = new Graph()
g.size(0,tstop,-80,20)
g.xaxis(1)
g.exec_menu("10% Zoom out")
g.addexpr("MOPP v_soma","soma.v(0.5)",1,1, 0.2,0.9,2)
xpanel("",1)
xbutton("init & run", "runa()")
xvalue("stim.amp")
xpanel()
b.intercept(0)
b.map()


//cvode.re_init()

proc advance() {
	fadvance()
	g.plot(t)
	g.flush()
	doNotify()
}


proc init() {
t=0



forall {ena=50 ek=-90 v=Vrest}
	finitialize(Vrest)
        fcurrent()
        forall {e_pas=Vrest+(ina+ik)/g_pas}
	cvode.re_init()
}

proc runa() {
run()
print "stim.amp ", stim.amp, "nA ==> ", (tempo.size-1)*(1000/(tempo.x[tempo.size-1]-tempo.x[0])), "Hz "
g.begin()
init()
}