//Network cell templates
//   C_Cell

AMPA_INDEX = 0 //* synlist synapse indices
GABA_INDEX = 1 //*

thresh_SpikeOut = -50	// (mV)
refrac_SpikeOut = 5	// (ms)
vrefrac_SpikeOut = -60	// (mV) reset potential
grefrac_SPikeOut = 100	// (uS) clamped at reset

begintemplate CobaCell
public is_art
public init, topol, basic_shape, subsets, geom, biophys, geom_nseg, biophys_inhomo
public synlist, x, y, z, position, connect2target, spkout

public soma
public all

objref synlist, spkout

create soma

proc init() {
  topol()
  subsets()
  geom()
  biophys()
  geom_nseg()
  synlist = new List()
  synapses()
  soma spkout = new SpikeOut(.5)
  x = y = z = 0 // only change via position
}

proc topol() { local i
  basic_shape()
}
proc basic_shape() {
  soma {pt3dclear() pt3dadd(0, 0, 0, 1) pt3dadd(15, 0, 0, 1)}
}

objref all
proc subsets() { local i
  objref all
  all = new SectionList()
    soma all.append()

}
proc geom() {
  forsec all {  /*area = 20000 */ L = diam = 79.7885  }
}
external lambda_f
proc geom_nseg() {
//* performance killer:  soma area(.5) // make sure diam reflects 3d points
}
proc biophys() {
  forsec all {
    cm = 1
    insert pas
      g_pas = 5e-05
      e_pas = -60
  }
}
proc biophys_inhomo(){}
proc position() { local i
  soma for i = 0, n3d()-1 {
    pt3dchange(i, $1-x+x3d(i), $2-y+y3d(i), $3-z+z3d(i), diam3d(i))
  }
  x = $1  y = $2  z = $3
}
proc connect2target() { //$o1 target point process, $o2 returned NetCon
  $o2 = new NetCon(spkout, $o1)
}
objref syn_
proc synapses() {
  /* E0 */   soma syn_ = new ExpSyn(0.5)  synlist.append(syn_)
//    syn_.tau = 10 // incorrect
    syn_.tau = 5
  /* I1 */   soma syn_ = new ExpSyn(0.5)  synlist.append(syn_)
//    syn_.tau = 20 // incorrect
    syn_.tau = 10
    syn_.e = -80
}
func is_art() { return 0 }

endtemplate CobaCell