/* test of extracellular cable such that extracellular replaces
intracellular */
/* hoc.pascab1 -- steady state infinite passive cable.
   Test of cable using units of lambda and tau.
   Compare steady state analytic solution, voltage clamp,
   and current injection. */
/* lambda = sqrt(1e4/4 * diam / (Ra * gl)) microns */
/* tau    =  1e-3 * cm / gl msec */

// physical properties of the cell
create a,b
a connect b(0), 1
access a
forall {nseg = 10   insert pas   insert extracellular}

// experimental tools
objref e
e = new VClamp(0)

// graphical interface appearance
length = 2
objref g
g = new Graph()
g.size(0,length,0,1)	
g.color(0)
g.color(1)
proc label() {
	g.vfixed
	g.label(.315,.01, "x (Lambda)")
	g.label(0, .5, "V")
	g.label(0,.95,"Steady state voltage as function of distance for infinite cable")
	g.label("  Compare current injection, voltage clamp, and analytic sol'n.")
}
label()
// simulation control
proc geometry() { local i
	L = length/2
	diam = 1
}

proc membrane() { local i, temp
	g_pas = .001
	e_pas = 0

	xg=.001
	xgaxial=(PI*diam^2/4)/Ra * nseg/(length/2) * 100
	 /* since conductance to parent */
	/*b xgaxial(.001) = xgaxial*2*/
	xraxial=Ra/(PI*diam^2/4)*100
	temp = xgaxial/(PI*diam*length/2/nseg/2*1e-2)
	g_pas=1e-9 g_pas(.001)=temp
	b g_pas=1.e-9
	xc=1 cm=0
}

proc analytic() {local x,y,z
	g.beginline()
	z = exp(length) + exp(-length)
	for (x=0; x<=length; x=x+.1) {
		y = (exp(length - x) + exp(x - length))/z
		g.line(x,y)
	}
	g.flush()
}

proc plotvolt() { local x, i
	g.beginline()
	a for (x) {
		g.line(x*length/2, vext(x))
	}
	b for (x) {
		g.line((1+x)*length/2, vext(x))
	}
	g.flush()
}

proc run() {
	forall Ra = 1e7/4
	forall {geometry() membrane()}
	forall Ra=1
	forall v = 0
	t = 0 dt = 1e9
	g.color(1)
	g.vfixed(1)
	g.label(.5,.8,"Analytic")
	analytic()
	g.color(2)
	g.label("voltage clamp")
	e.dur[0]=1e9 e.amp[0]=1
	fadvance()
	plot(1) plotvolt()
	print v+vext, "\n"
	g.color(3)
	g.label("Current injection")
	e = new IClamp(0) e.dur=1e20 e.amp=PI*1e-5
	fadvance()
	plot(1) plotvolt()
	g.flush()
}

// run simulation
run()









