//****************************************************************************
// basic_procs.hoc defines procedures for setting conductances and range
// variables of channels - these are primarily used to change variables
// from the gui

proc set_pas() {    NEW_GPAS = $1
    forall if (ismembrane("pas")) {g_pas = NEW_GPAS}
	nG_PAS = NEW_GPAS

//*******************Mid*******************
	MSP_Cell[0].dendrite[1] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[14] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[26] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[27] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[29] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[32] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[35] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[42] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[52] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[53] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[54] g_pas = nG_PAS*1.3

	MSP_Cell[0].dendrite[2] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[9] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[15] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[18] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[23] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[30] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[31] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[36] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[39] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[43] g_pas = nG_PAS*1.3
	MSP_Cell[0].dendrite[44] g_pas = nG_PAS*1.3
	
//*******************Dist*******************
	MSP_Cell[0].dendrite[3] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[8] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[10] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[11] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[16] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[17] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[19] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[20] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[37] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[38] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[40] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[41] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[45] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[50] g_pas = nG_PAS*3
	
	MSP_Cell[0].dendrite[4] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[7] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[12] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[13] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[21] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[22] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[46] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[47] g_pas = nG_PAS*3
	
	MSP_Cell[0].dendrite[5] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[6] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[48] g_pas = nG_PAS*3
	MSP_Cell[0].dendrite[49] g_pas = nG_PAS*3
	
	MSP_Cell[0].spine[0] g_pas = nG_PAS*1.3
	MSP_Cell[0].spine[1] g_pas = nG_PAS*3

}


//*****************
// Sodium conductance settings

proc set_naf() {		NEW_GBAR = $1
	nG_NAF = NEW_GBAR
	forsec "soma" {gnabar_naf = nG_NAF}

 }

proc set_nafd() {		NEW_GBAR = $1
	nG_NAFD = NEW_GBAR
//	forsec "dend.*" {gnabar_naf = nG_NAFD}
	forsec "dendrite.*" {gnabar_naf = nG_NAFD}
	forsec "spine.*" {gnabar_naf = nG_NAFD}
}

proc set_nap() {		NEW_GBAR = $1
	nG_NAP = NEW_GBAR
	forsec "soma" {gnabar_nap = nG_NAP}
	}

proc set_napd() {		NEW_GBAR = $1
	nG_NAPD = NEW_GBAR
//	forsec "dend.*" {gnabar_nap = nG_NAPD}
	forsec "dendrite.*" {gnabar_nap = nG_NAPD}
	forsec "spine.*" {gnabar_nap = nG_NAPD}
}

//*****************


	


//*****************
// Potassium conductance settings

proc set_ek() {	newEK = $1
	forsec "MSP" {ek = newEK}
	EK = newEK
}

proc set_kir() {		NEW_GBAR = $1
	nG_KIR = NEW_GBAR
	forall if (ismembrane("kir")) {gkbar_kir = nG_KIR}
}

proc set_kas() {		NEW_GBAR = $1
	nG_KAS = NEW_GBAR
	forsec "soma" {gkbar_kas = nG_KAS}
	MSP_Cell[0].dendrite[0] gkbar_kas = nG_KAS
	MSP_Cell[0].dendrite[24] gkbar_kas = nG_KAS
	MSP_Cell[0].dendrite[25] gkbar_kas = nG_KAS
	MSP_Cell[0].dendrite[28] gkbar_kas = nG_KAS
	MSP_Cell[0].dendrite[33] gkbar_kas = nG_KAS
	MSP_Cell[0].dendrite[34] gkbar_kas = nG_KAS
	MSP_Cell[0].dendrite[51] gkbar_kas = nG_KAS
 }

proc set_kasd() {		NEW_GBAR = $1
	nG_KASD = NEW_GBAR
	//forsec "dend._.*" {gkbar_kas = nG_KASD}
	MSP_Cell[0].dendrite[1] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[14] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[26] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[27] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[29] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[32] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[35] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[42] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[52] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[53] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[54] gkbar_kas = nG_KASD

	MSP_Cell[0].dendrite[2] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[9] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[15] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[18] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[23] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[30] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[31] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[36] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[39] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[43] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[44] gkbar_kas = nG_KASD
	
//*******************Dist*******************
	MSP_Cell[0].dendrite[3] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[8] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[10] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[11] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[16] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[17] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[19] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[20] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[37] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[38] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[40] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[41] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[45] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[50] gkbar_kas = nG_KASD
	
	MSP_Cell[0].dendrite[4] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[7] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[12] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[13] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[21] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[22] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[46] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[47] gkbar_kas = nG_KASD
	
	MSP_Cell[0].dendrite[5] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[6] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[48] gkbar_kas = nG_KASD
	MSP_Cell[0].dendrite[49] gkbar_kas = nG_KASD
	
	MSP_Cell[0].spine[0] gkbar_kas = nG_KASD
	MSP_Cell[0].spine[1] gkbar_kas = nG_KASD

}
proc set_kaf() {		NEW_GBAR = $1
	nG_KAF = NEW_GBAR
	forsec "soma" {gkbar_kaf = nG_KAF}
	MSP_Cell[0].dendrite[0] gkbar_kaf = nG_KAF
	MSP_Cell[0].dendrite[24] gkbar_kaf = nG_KAF
	MSP_Cell[0].dendrite[25] gkbar_kaf = nG_KAF
	MSP_Cell[0].dendrite[28] gkbar_kaf = nG_KAF
	MSP_Cell[0].dendrite[33] gkbar_kaf = nG_KAF
	MSP_Cell[0].dendrite[34] gkbar_kaf = nG_KAF
	MSP_Cell[0].dendrite[51] gkbar_kaf = nG_KAF


}

proc set_kafd() {		NEW_GBAR = $1
	nG_KAFD = NEW_GBAR
	forsec "dend._.*" {gkbar_kaf = nG_KAFD}
	MSP_Cell[0].dendrite[1] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[14] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[26] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[27] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[29] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[32] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[35] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[42] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[52] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[53] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[54] gkbar_kaf = nG_KAFD

	MSP_Cell[0].dendrite[2] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[9] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[15] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[18] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[23] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[30] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[31] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[36] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[39] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[43] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[44] gkbar_kaf = nG_KAFD
	
//*******************Dist*******************
	MSP_Cell[0].dendrite[3] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[8] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[10] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[11] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[16] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[17] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[19] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[20] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[37] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[38] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[40] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[41] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[45] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[50] gkbar_kaf = nG_KAFD
	
	MSP_Cell[0].dendrite[4] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[7] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[12] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[13] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[21] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[22] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[46] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[47] gkbar_kaf = nG_KAFD
	
	MSP_Cell[0].dendrite[5] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[6] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[48] gkbar_kaf = nG_KAFD
	MSP_Cell[0].dendrite[49] gkbar_kaf = nG_KAFD
	
	MSP_Cell[0].spine[0] gkbar_kaf = nG_KAFD
	MSP_Cell[0].spine[1] gkbar_kaf = nG_KAFD
}

proc set_krp() {		NEW_GBAR = $1
	nG_KRP = NEW_GBAR
	forall if (ismembrane("krp")) {gkbar_krp = NEW_GBAR}
}

proc set_bkkca() {		NEW_GBAR = $1
	nG_BKKCA = NEW_GBAR
	forall if(ismembrane("bkkca")) {gkbar_bkkca = NEW_GBAR}
}

proc set_skkca() {		NEW_GBAR = $1
	nG_SKKCA = NEW_GBAR
	forall if(ismembrane("skkca")) {gkbar_skkca = NEW_GBAR}
}

//*****************





//******************
// Calcium conductance settings


proc set_caL() {		NEW_PBAR = $1
	nP_CAL = NEW_PBAR
	forall if (ismembrane("caL")) {pbar_caL = NEW_PBAR}
}

proc set_caL13() {		NEW_PBAR = $1
	nP_CAL13 = NEW_PBAR
	forall if (ismembrane("caL13")) {pcaLbar_caL13 = NEW_PBAR}
}

proc set_can() {		NEW_PBAR = $1
	nP_CAN = NEW_PBAR
	forall if (ismembrane("can")) {pbar_can = NEW_PBAR}
}

proc set_caq() {		NEW_PBAR = $1
	nP_CAQ = NEW_PBAR
	forall if (ismembrane("caq")) {pcaqbar_caq = NEW_PBAR}
}

proc set_car() {		NEW_PBAR = $1
	nP_CAR = NEW_PBAR
	forall if (ismembrane("car")) {pcarbar_car = NEW_PBAR}
}
proc set_cat() {		NEW_PBAR = $1
	nP_CAT = NEW_PBAR
	forall if (ismembrane("cat")) {pcatbar_cat = NEW_PBAR}
}

//******************





//******************
// Calcium dynamics procs

proc set_cainf() {	NEW_CAINF = $1
	nCA_INF = NEW_CAINF
	forall if (ismembrane("cadyn")) {cainf_cadyn = NEW_CAINF}
	forall if (ismembrane("caldyn")) {cainf_caldyn = NEW_CAINF}
}

proc set_taur() {	NEW_TAUR = $1
	nCA_TAUR = NEW_TAUR
	forall if (ismembrane("cadyn")) {taur_cadyn = NEW_TAUR}
	forall if (ismembrane("caldyn")) {taur_caldyn = NEW_TAUR}
}
proc set_cadrive() { 	NEW_DRIVE = $1
	nCA_DRIVE = NEW_DRIVE
	forall if (ismembrane("cadyn")) {drive_cadyn = NEW_DRIVE}
	forall if (ismembrane("caldyn")) {drive_caldyn = NEW_DRIVE}
}
proc set_pump() {	NEW_PUMP = $1
	nCA_PUMP = NEW_PUMP
	forall if (ismembrane("cadyn")) {pump_cadyn = NEW_PUMP}
	forall if (ismembrane("caldyn")) {pump_caldyn = NEW_PUMP}
}
//******************


proc set_mu(){//	NEW_mu = $1
	//mu=1
	forall if (issection("caL")) {
		for (x,0) { // skip the nodes at 0 and 1
			//setpointer mu_caL(x), mu
			setpointer mu_caL(x), DAsyn[0].msg
		}
	}
	
	forall if (issection("kir")) {
		for (x,0) { // skip the nodes at 0 and 1
			//setpointer mu_kir(x), mu
			setpointer mu_kir(x), DAsyn[0].msg
		}
	}
}
 
 

 
//******************
// synaptic gbar procs
proc gampa() {	NEW = $1		// AMPA conductance
	nG_AMPA = NEW
	for j = 0, NGLU-1 {AMPA[j].gbar = NEW}
	for j = NGLU-2, NGLU-1 {AMPA[j].ca_ratio = 0.0001}
}

proc gnmda() {	NEW = $1		// NMDA conductance
	nG_NMDA = NEW
	for j = 0, NGLU-1 {NMDA[j].gbar = NEW}
	for j = NGLU-2, NGLU-1 {NMDA[j].ca_ratio = 0.002}
}

proc nmda_mg() {	NEW = $1		// NMDA conductance
//	MG_NMDA = NEW
	for j = 0, NGLU-1 {NMDA[j].mg = NEW}
}

//proc gmglu() {	NEW = $1		// mGluR conductance
//	nG_MGLU = NEW
//	for j = 0, NGLU-1 {MGLU[j].gbar = NEW}
//}

proc ggaba() {	NEW = $1		// GABA conductance
	nG_GABA = NEW
	for j = 0, NGABA-1 {GABA[j].gbar = nG_GABA}
}
//******************




//******************
// netstim variables
proc tstart() {		NEW = $1	// time of netstims to start spiking
	nT_START = NEW
	for i = 0, NSYN-1 {NS_NetStim[i].pp.start = NEW}
}

proc setnetn() {	NEW = $1	// number of times a netstim will spike
	nNET_N = NEW
	for i = 0, NSYN-1 { NS_NetStim[i].pp.number = nNET_N }
}

proc setnoise() { NEW = $1		// netstim noise - 1 = random, 0 = not
	nNOISE = NEW
	for i = 0, NSYN-1 { NS_NetStim[i].pp.noise = nNOISE }
}
//******************