{load_file("nrngui.hoc")}  // load the GUI and standard run libraries

{load_file("../cells/pyramidal_cell.hoc")} //load axoaxonic cell

{xopen("kblock.hoc")} //execute open.load_file just reads

strdef temp_mkdir, temp_dir
// Create the directory
sprint(temp_dir, "SynapticProperties/")
sprint(temp_mkdir, "mkdir -p %s", temp_dir)
system(temp_mkdir)

objectvar 	Cell1, Cell2, Cell3
objectvar 	syn1, syn2, syn3
objectvar   nclist, stim, sn1, sn2, sn3
objectvar   clamp1, clamp2, clamp3
objref 		sn1, i1_ca1, i2_ca1, i3_ca1
objref      FILE1, FILE2, FILE3
strdef 		tmp1, tmp2, tmp3


Cell1 = new PyramidalCell()  // template for synapse EC NMDA to PC
Cell2 = new PyramidalCell()  // template for synapse CA3 NMDA to APICAL PC
Cell3 = new PyramidalCell()  // template for synapse CA3 NMDA to BASAL PC

stim = new NetStim (0.5)
stim.interval 	= 1
stim.number		= 1
stim.start		= 900


// Time parameters///////////////////////////////
tstop = 2000 //stop time in ms
steps_per_ms = 10
dt    = 0.1
n     = tstop*steps_per_ms


//Vclamp for NMDA
print "Vclamp"
factor2 = 1.0

//making EC NMDA synapse to PC at lm_medium1 dendrite
//weigth_ECnmdatoPC 
w1 =0.80*2.0e-4

Cell1.lm_medium1  syn1 = new NMDA(0.5) 
syn1.tcon = 2.3 
syn1.tcoff = 100
syn1.gNMDAmax = 1
//making the netcon
sn1	= new NetCon(stim, syn1, -20, 1, w1)



//making CA3 NMDA synapse to PC at rad_medium1 dendrite (apical)
//weigth_CA3nmdatoapicalPC 
w2 = 0.80*2.0e-4

Cell2.rad_medium1 syn2 = new NMDA(0.5)
syn2.tcon = 2.3 
syn2.tcoff = 100
syn2.gNMDAmax = 1
//making the netcon 
sn2	= new NetCon (stim,syn2,-20, 1, w2)  //..threshold,delay,weight)



//making CA3 NMDA synapse to PC at oriProx1 dendrite (basal)
//weigth_CA3nmdatobasalPC 
w3 = 0.80*2.0e-4

Cell3.oriprox1  syn3 = new NMDA(0.5) 
syn3.tcon = 2.3 
syn3.tcoff = 100
syn3.gNMDAmax = 1
//making the netcon
sn3	= new NetCon(stim, syn3, -20, 1, w3)



//Vclamp at soma
Cell1.soma clamp1 = new VClamp(0.5)  
Cell2.soma clamp2 = new VClamp(0.5)  
Cell3.soma clamp3 = new VClamp(0.5)  


clamp1.dur[0]= 2000			//duration of clamp in ms
clamp1.amp[0]= 40      //voltage clamp amplitude / near to Vrest

clamp2.dur[0]= 2000			
clamp2.amp[0]= 40

clamp3.dur[0]= 2000			
clamp3.amp[0]= 40


//cutting potasium
k_block()
//making the vectors	
i1_ca1 = new Vector(n)
i2_ca1 = new Vector(n)
i3_ca1 = new Vector(n)


//recording
i1_ca1.record(&clamp1.i)
i2_ca1.record(&clamp2.i)
i3_ca1.record(&clamp3.i)


run()

FILE1 = new File()
sprint(tmp1, "SynapticProperties/nmdaECtoPC_i_rec_soma.txt")
FILE1.wopen(tmp1)
for i=0, i1_ca1.size()-1 {FILE1.printf("%f\n",i1_ca1.x[i])}
FILE1.close()

FILE2 = new File()
sprint(tmp2, "SynapticProperties/nmdaCA3toapicalPC_i_rec_soma.txt")
FILE2.wopen(tmp2)
for i=0, i2_ca1.size()-1 {FILE2.printf("%f\n",i2_ca1.x[i])}
FILE2.close()	

FILE3 = new File()
sprint(tmp3, "SynapticProperties/nmdaCA3tobasalPC_i_rec_soma.txt")
FILE3.wopen(tmp3)
for i=0, i3_ca1.size()-1 {FILE3.printf("%f\n",i3_ca1.x[i])}
FILE3.close()