//http://www.neuron.yale.edu/phpBB/viewtopic.php?f=15&t=755&p=2458&hilit=+save+vector#p2458
//http://www.neuron.yale.edu/phpBB/viewtopic.php?f=15&t=626&p=2044&hilit=+save+vector#p2044
//http://www.neuron.yale.edu/phpBB/viewtopic.php?f=9&t=781&p=2549&hilit=+save+vector#p2549


objref dtime, dsv, d1v, d1cal, d1ip3, d1da, d1icalAMPA, d1icalNMDA, d1icalMGLU, d1ical, d1icalcaL, d1icalcaL13, d1icalcat, d4v, d4cal, d4ip3, d4da, d4icalAMPA, d4icalNMDA, d4icalMGLU, d4ical, d4icalcaL, d4icalcaL13, d4icalcat, d0v, d2v, d3v,d5v, d0cal, d2cal, d3cal, d5cal, s0v, s0cal, s0ip3, s0da, s0icalAMPA, s0icalNMDA, s0icalMGLU, s0ical, s0icalcaL, s0icalcaL13, s0icalcat, s1v, s1cal, s1ip3, s1da, s1icalAMPA, s1icalNMDA, s1icalMGLU, s1ical, s1icalcaL, s1icalcaL13, s1icalcat

dsv = new Vector()
dtime = new Vector()
d1v = new Vector()
d1cal = new Vector()
d1ip3 = new Vector()
d1da = new Vector()
d1icalAMPA = new Vector()
d1icalNMDA = new Vector()
d1icalMGLU = new Vector()
d1ical = new Vector()
d1icalcaL = new Vector()
d1icalcaL13 = new Vector()
d1icalcat = new Vector()

d4v = new Vector()
d4cal = new Vector()
d4ip3 = new Vector()
d4da = new Vector()
d4icalAMPA = new Vector()
d4icalNMDA = new Vector()
d4icalMGLU = new Vector()
d4ical = new Vector()
d4icalcaL = new Vector()
d4icalcaL13 = new Vector()
d4icalcat = new Vector()


d0v = new Vector()
d2v = new Vector()
d3v = new Vector()
d5v = new Vector()

d0cal = new Vector()
d2cal = new Vector()
d3cal = new Vector()
d5cal = new Vector()

s0v = new Vector()
s0cal = new Vector()
s0ip3 = new Vector()
s0da = new Vector()
s0icalAMPA = new Vector()
s0icalNMDA = new Vector()
s0icalMGLU = new Vector()
s0ical = new Vector()
s0icalcaL = new Vector()
s0icalcaL13 = new Vector()
s0icalcat = new Vector()

s1v = new Vector()
s1cal = new Vector()
s1ip3 = new Vector()
s1da = new Vector()
s1icalAMPA = new Vector()
s1icalNMDA = new Vector()
s1icalMGLU = new Vector()
s1ical = new Vector()
s1icalcaL = new Vector()
s1icalcaL13 = new Vector()
s1icalcat = new Vector()


objref savcurrent
savcurrent = new File()
//savcurrent.wopen("current_soma.txt")


objref current_matrix
current_matrix = new Matrix()

proc saveplots(){
//FNAME=$1


dtime.record(&t)
//dtime2.record(&dt)
dsv.record(&MSP_Cell[0].soma.v(0.5))
d1v.record(&MSP_Cell[0].dendrite[1].v(0.5))
d1cal.record(&MSP_Cell[0].dendrite[1].cali(0.5))
d1ip3.record(&MSP_Cell[0].dendrite[1].ip3ip_ER)
d1da.record(&DAsyn[7].msg)
d1icalAMPA.record(&AMPA[7].ical)
d1icalNMDA.record(&NMDA[7].ical)
d1icalMGLU.record(&MSP_Cell[0].dendrite[1].ical_ER)
d1ical.record(&MSP_Cell[0].dendrite[1].ical(0.5))
d1icalcaL.record(&MSP_Cell[0].dendrite[1].ical_caL(0.5))
d1icalcaL13.record(&MSP_Cell[0].dendrite[1].ical_caL13(0.5))
d1icalcat.record(&MSP_Cell[0].dendrite[1].ical_cat(0.5))


d4v.record(&MSP_Cell[0].dendrite[4].v(0.5))
d4cal.record(&MSP_Cell[0].dendrite[4].cali(0.5))
d4ip3.record(&MSP_Cell[0].dendrite[4].ip3ip_ER)
d4da.record(&DAsyn[107].msg)
d4icalAMPA.record(&AMPA[107].ical)
d4icalNMDA.record(&NMDA[107].ical)
d4icalMGLU.record(&MSP_Cell[0].dendrite[4].ical_ER)
d4ical.record(&MSP_Cell[0].dendrite[4].ical(0.5))
d4icalcaL.record(&MSP_Cell[0].dendrite[4].ical_caL(0.5))
d4icalcaL13.record(&MSP_Cell[0].dendrite[4].ical_caL13(0.5))
d4icalcat.record(&MSP_Cell[0].dendrite[4].ical_cat(0.5))


d0v.record(&MSP_Cell[0].dendrite[0].v(0.5))
d2v.record(&MSP_Cell[0].dendrite[2].v(0.5))
d3v.record(&MSP_Cell[0].dendrite[3].v(0.5))
d5v.record(&MSP_Cell[0].dendrite[5].v(0.5))

d0cal.record(&MSP_Cell[0].dendrite[0].cali(0.5))
d2cal.record(&MSP_Cell[0].dendrite[2].cali(0.5))
d3cal.record(&MSP_Cell[0].dendrite[3].cali(0.5))
d5cal.record(&MSP_Cell[0].dendrite[5].cali(0.5))

s0v.record(&MSP_Cell[0].spine[0].v(0.5))
s0cal.record(&MSP_Cell[0].spine[0].cali(0.5))
s0ip3.record(&MSP_Cell[0].spine[0].ip3ip_ER)
s0da.record(&DAsyn[155].msg)
s0icalAMPA.record(&AMPA[155].ical)
s0icalNMDA.record(&NMDA[155].ical)
s0icalMGLU.record(&MSP_Cell[0].spine[0].ical_ER)
s0ical.record(&MSP_Cell[0].spine[0].ical(0.5))
s0icalcaL.record(&MSP_Cell[0].spine[0].ical_caL(0.5))
s0icalcaL13.record(&MSP_Cell[0].spine[0].ical_caL13(0.5))
s0icalcat.record(&MSP_Cell[0].spine[0].ical_cat(0.5))

s1v.record(&MSP_Cell[0].spine[1].v(0.5))
s1cal.record(&MSP_Cell[0].spine[1].cali(0.5))
s1ip3.record(&MSP_Cell[0].spine[1].ip3ip_ER)
s1da.record(&DAsyn[156].msg)
s1icalAMPA.record(&AMPA[156].ical)
s1icalNMDA.record(&NMDA[156].ical)
s1icalMGLU.record(&MSP_Cell[0].spine[1].ical_ER)
s1ical.record(&MSP_Cell[0].spine[1].ical(0.5))
s1icalcaL.record(&MSP_Cell[0].spine[1].ical_caL(0.5))
s1icalcaL13.record(&MSP_Cell[0].spine[1].ical_caL13(0.5))
s1icalcat.record(&MSP_Cell[0].spine[1].ical_cat(0.5))


init()
run()

savcurrent.wopen($s1)
savcurrent.printf(" Time somaV dend1V dend1cal dend1ip3 dend1damsg dend1icalAMPA dend1icalNMDA dend1icalMGLU dend1ical dend1icalcaL dend1icalcaL13 dend1icalcat dend4V dend4cal dend4ip3 dend4damsg dend4icalAMPA dend4icalNMDA dend4icalMGLU dend4ical dend4icalcaL dend4icalcaL13 dend4icalcat dend0v dend2v dend3v dend5v dend0cal dend2cal dend3cal dend5cal spine0V spine0cal spine0ip3 spine0damsg spine0icalAMPA spine0icalNMDA spine0icalMGLU spine0ical spine0icalcaL spine0icalcaL13 spine0icalcat spine1V spine1cal spine1ip3 spine1damsg spine1icalAMPA spine1icalNMDA spine1icalMGLU spine1ical spine1icalcaL spine1icalcaL13 spine1icalcat\n")
current_matrix.resize(dtime.size(),54)
current_matrix.setcol(0, dtime)
current_matrix.setcol(1, dsv) 
current_matrix.setcol(2, d1v) 
current_matrix.setcol(3, d1cal)
current_matrix.setcol(4, d1ip3) 
current_matrix.setcol(5, d1da) 
current_matrix.setcol(6, d1icalAMPA) 
current_matrix.setcol(7, d1icalNMDA) 
current_matrix.setcol(8, d1icalMGLU) 
current_matrix.setcol(9, d1ical)
current_matrix.setcol(10, d1icalcaL) 
current_matrix.setcol(11, d1icalcaL13) 
current_matrix.setcol(12, d1icalcat) 



current_matrix.setcol(13, d4v) 
current_matrix.setcol(14, d4cal)
current_matrix.setcol(15, d4ip3) 
current_matrix.setcol(16, d4da) 
current_matrix.setcol(17, d4icalAMPA) 
current_matrix.setcol(18, d4icalNMDA) 
current_matrix.setcol(19, d4icalMGLU) 
current_matrix.setcol(20, d4ical)
current_matrix.setcol(21, d4icalcaL) 
current_matrix.setcol(22, d4icalcaL13) 
current_matrix.setcol(23, d4icalcat) 

current_matrix.setcol(24, d0v)
current_matrix.setcol(25, d2v)
current_matrix.setcol(26, d3v)
current_matrix.setcol(27, d5v)

current_matrix.setcol(28, d0cal)
current_matrix.setcol(29, d2cal)
current_matrix.setcol(30, d3cal)
current_matrix.setcol(31, d5cal)

current_matrix.setcol(32, s0v) 
current_matrix.setcol(33, s0cal)
current_matrix.setcol(34, s0ip3) 
current_matrix.setcol(35, s0da) 
current_matrix.setcol(36, s0icalAMPA) 
current_matrix.setcol(37, s0icalNMDA) 
current_matrix.setcol(38, s0icalMGLU) 
current_matrix.setcol(39, s0ical)
current_matrix.setcol(40, s0icalcaL) 
current_matrix.setcol(41, s0icalcaL13) 
current_matrix.setcol(42, s0icalcat) 

current_matrix.setcol(43, s1v) 
current_matrix.setcol(44, s1cal)
current_matrix.setcol(45, s1ip3) 
current_matrix.setcol(46, s1da) 
current_matrix.setcol(47, s1icalAMPA) 
current_matrix.setcol(48, s1icalNMDA) 
current_matrix.setcol(49, s1icalMGLU) 
current_matrix.setcol(50, s1ical)
current_matrix.setcol(51, s1icalcaL) 
current_matrix.setcol(52, s1icalcaL13) 
current_matrix.setcol(53, s1icalcat) 

current_matrix.fprint(savcurrent, " %g")
 
//savcurrent.printf("%g\t%g\n", t, MSP_Cell[0].soma.v(0.5))
savcurrent.close() 
}