//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//
//  NOTICE OF COPYRIGHT AND OWNERSHIP OF SOFTWARE
//
// Copyright 2010, The University Of Michigan
// 	
//   All rights reserved.
//   For research use only; commercial use prohibited.
//   No Distribution without permission of William Stacey
//   wstacey@umich.edu
//
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

// ### This file is not obsolete.  The gap junctions are placed within TGnet.tem using a different method.###

begintemplate GapObj

public add, get, getloc, addVar, remove_all, addPerArea, gapList

objref  gapList, loc
        



// =================================================================================================
//
// init()
//
// =================================================================================================
proc init() {
    gapList = new List()
    loc = new SectionRef()
}




// =================================================================================================
//
// add(sec ref preSynCell, ggap (nS))
//
// =================================================================================================
proc add() {
    
    if (numarg()==1) {
    
        loc.sec gapList.prepend(new HalfGap(0.5))
        
        gapList.object(0).g = $1
        //$o1.sec setpointer gapList.object(0).vgap, v(0.5)
        
    }else{
    
        print "USAGE: add(sec ref preSynCell, ggap (nS))"
    
    }
}




// =================================================================================================
//
// addPerArea(sec ref preSynCell, ggap (mS/cm2))
//
// =================================================================================================
proc addPerArea() {
    
    if (numarg()==2) {
    
        loc.sec gapList.prepend(new HalfGap(0.5))
        
        loc.sec gapList.object(0).ggap = $2 * area(0.5) * 1e-2 // -> nS 1e-8 * 1e6
        $o1.sec setpointer gapList.object(0).vgap, v(0.5)
        
    }else{
    
        print "USAGE: add(sec ref preSynCell, ggap (mS/cm2))"
    
    }
}



// =================================================================================================
//
// remove_all()
//
// ================================================================================================
proc remove_all() {

    gapList.remove_all()
}




// =================================================================================================
//
// addVar()
//
// ================================================================================================
proc addVar() {
    
    if (numarg()==2) {
    
        loc.sec gapList.prepend(new HalfGap(0.5))
        
        gapList.object(0).ggap = $2
        loc.sec setpointer gapList.object(0).vgap, $&1
        
    }else{
    
        print "USAGE: addGap(&var, ggap (nS))"
    
    }
}




// =================================================================================================
//
// getloc()
//
// ================================================================================================
proc getloc() {
    
    loc.sec print secname() 
}




// =================================================================================================
//
// get()
//
// ================================================================================================
proc get() {

    for i=0, gapList.count()-1 {
        loc.sec printf("%d, %s, vpre= %s, ggap= %g uS, loc= %s\n", i, gapList.object(i), gapList.object(i).vpre, gapList.object(i).ggap, secname())
    }
}

endtemplate GapObj