begintemplate GapJunction
public gj1,gj2,g,loc,reset_loc,reset_g
// An electrical connection placed between two compartments

objref this,sec1,sec2,gj1,gj2

proc init(){
    sec1 = $o1 // section pointer to first connected section
    sec2 = $o2 // section pointer to second connected section
    loc = $3 // location within sections to put gj, same for both for now
    g = $4 // conductance of gj
    
    sec1.sec{ gj1 = new Gap(loc) }
    sec2.sec{ gj2 = new Gap(loc) }
    
    setpointer gj1.vgap, sec2.sec.v(loc)
    setpointer gj2.vgap, sec1.sec.v(loc)
    
    gj1.g = g
    gj2.g = g
}

proc reset_loc(){
    // place gap junction between two BranchDistCell's
    loc = $1
    if(numarg()>1){
        sec1 = $o2
        sec2 = $o3
    }
    
    sec1.sec{ gj1 = new Gap(loc) }
    sec2.sec{ gj2 = new Gap(loc) }
    
    setpointer gj1.vgap, sec2.sec.v(loc)
    setpointer gj2.vgap, sec1.sec.v(loc)
    
    gj1.g = g
    gj2.g = g
}

proc reset_g(){
    g = $1
    
    gj1.g = g
    gj2.g = g
}

endtemplate GapJunction