// DECLARE OBJECTS TO BE ASSIGNED DURING initChannels() CALL
objref osec[10]


// LOAD PARAMETERS FOR CHANNELS
{
	load_file("channelParameters.hoc")
}

proc initChannels(){
	// add in voltage-gated channels
	{
		forall {
			insert pas  g_pas=1/(Rm)  Ra=global_ra  e_pas=Vleak
			insert id
		}
		
		soma.sec { 
            insert hd ghdbar_hd=ghd 
            //insert h gbar_h=ghd
			insert nax  gbar_nax=gnaSoma  
			insert kdr  gkdrbar_kdr=gkdr
			insert kap  gkabar_kap=gkap
			insert kad  gkabar_kad=0
			insert pas	e_pas=Vleak  g_pas=1/Rm   Ra=global_ra  cm=Cm
		}
		

		forsec basalList {
			insert pas	e_pas=Vleak  Ra=global_ra 
			for (x) {
				xdist=distance(x)
				if (xdist <= spinelimit) {
					g_pas(x) = 1/Rm
					cm(x) = Cm
				} else {
					g_pas(x) = spinefactor/Rm
					cm(x) = spinefactor*Cm
				}
			}
            insert tonic gtonic_tonic=gtonic 
            insert hd ghdbar_hd=ghd
			insert nax	
			insert kdr	gkdrbar_kdr=0 //gkdr //very low according to Kirizs et al., 2014
			insert kap
			insert kad
			gkabar_kap = 0
			gkabar_kad = 0
			
			for (x) {
				xdist = distance(x)
				xdistNoLimit = xdist
				if (xdist > dlimit) {
					xdist = dlimit
				}
				gkabar_kap(x) = 0
				gkabar_kad(x) = 0
				if (xdist > dprox) {
					gkabar_kad(x) = gkad*(1+xdist*dslope)
				} else {
					gkabar_kap(x) = gkap*(1+xdist*dslope)
				}
			}
			
		}
		
		soma.sec {
			area(0.5)
			distance()
		}
			
		forsec apicalList {
			insert pas	e_pas=Vleak  Ra=global_ra 
			for (x) {
				xdist=distance(x)
				if (xdist <= spinelimit) {
					g_pas(x) = 1/Rm
					cm(x) = Cm
				} else {
					g_pas(x) = spinefactor/Rm
					cm(x) = spinefactor*Cm
				}
			}
            insert tonic gtonic_tonic=gtonic 
            insert hd ghdbar_hd=ghd
			insert nax	
			insert kdr	gkdrbar_kdr= 0 //very low according to Kirizs et al., 2014
			insert kap
			insert kad
			gkabar_kap = 0
			gkabar_kad = 0
			
            for (x) {
				xdist = distance(x)
				xdistNoLimit = xdist
                if (xdist <= spinelimit) {
                    insert kdr	gkdrbar_kdr=gkdr //very low else where according to Kirizs et al., 2014
                }
                if (xdist>500) {xdist=500}
                ghdbar_hd(x) = ghd*(1+3*xdist/100)
                if (xdist > dlimit) {
					xdist = dlimit
				}
                gtonic_tonic(x) = gtonic*(1+3*xdist/100)
				gkabar_kap(x) = 0
				gkabar_kad(x) = 0
				if (xdist > dprox) {
					gkabar_kad(x) = gkad*(1+xdist*dslope)
				} else {
					gkabar_kap(x) = gkap*(1+xdist*dslope)
				}
			}
		}
		
		
		
		
		forsec obliqueList {
				for (x) {
					odist = distance(x) 	// odist is the distance of each segment along the oblique branch
					pdist_k = dlimit
					gkabar_kap(x) = gkap*(1+pdist_k*dslope+odist*okslope)
					gkabar_kad(x) = gkad*(1+pdist_k*dslope+odist*okslope)
				}
		}
		

		forsec tuftList {
			gbar_nax = gnaSlm
		}
		forsec ca3List {
			gbar_nax = gnaSr
		}
		soma.sec {
			gbar_nax = gnaSoma
		}
        
        forall {
        v=Vrest
        if (ismembrane("nax")) {ena=55}
        if (ismembrane("kdr") || ismembrane("kap") || ismembrane("kad")) {ek=-95}
        if (ismembrane("hd") ) {ehd_hd=-30 }
        if (ismembrane("tonic") ) {e_tonic=inhRev }
		}
        
		soma.sec { 
			distance()
		}

	}
}