// Blocco di tipo 2: ingresso in alto a dx, uscita in basso a sin 


x0=10
y0=10
lx=21
ly=40
xm2=x0+14
xm1=x0+7

g1=7
g2=7
g3=7

sd_g1=0.2
sd_g2=0.2
sd_g3=0.2

drift_g1=0.1
drift_g2=0.1
drift_g3=0.1

tchange=300
sdtch=0

tchange1=tchange
tchange2=tchange
tchange3=tchange
sdtch1=sdtch
sdtch2=sdtch
sdtch3=sdtch

// 4 args are (i,j) position, direction (0,1,2,3 means 
// left, right, bottom, top),  and conductance (nS).

// fisso le ggap nella semi-area ischemica di ingresso 
for i= xm2+1, x0+lx-1 {
	for j= y0+1, y0+ly-1 {
		mygap( i, j, 0, g1, sd_g1, drift_g1, tchange1, sdtch1)
		mygap( i, j, 1, g1, sd_g1, drift_g1, tchange1, sdtch1)
		mygap( i, j, 2, g1, sd_g1, drift_g1, tchange1, sdtch1)
		mygap( i, j, 3, g1, sd_g1, drift_g1, tchange1, sdtch1)
	}
}

// fisso le ggap nella semi-area ischemica di centro 
for i= xm1+1, xm2-1 {
	for j= y0+1, y0+ly-1 {
		mygap( i, j, 0, g2, sd_g2, drift_g2, tchange2, sdtch2)
		mygap( i, j, 1, g2, sd_g2, drift_g2, tchange2, sdtch2)
		mygap( i, j, 2, g2, sd_g2, drift_g2, tchange2, sdtch2)
		mygap( i, j, 3, g2, sd_g2, drift_g2, tchange2, sdtch2)
	}
}

// fisso le ggap nella semi-area ischemica di uscita 
for i= x0+1, xm1-1 {
	for j= y0+1, y0+ly-1 {
		mygap( i, j, 0, g3, sd_g3, drift_g3, tchange3, sdtch3)
		mygap( i, j, 1, g3, sd_g3, drift_g3, tchange3, sdtch3)
		mygap( i, j, 2, g3, sd_g3, drift_g3, tchange3, sdtch3)
		mygap( i, j, 3, g3, sd_g3, drift_g3, tchange3, sdtch3)
	}
}


// fisso il blocco sopra e sotto con la mygap
for i= x0, x0+lx {
	for k=0, 3 {
		mygap( i, y0, k, 0, 0, 0, tchange, sdtch)
	}
	mygap( i, y0-1, 3, 0, 0, 0, tchange, sdtch)
	mygap( i, y0+1, 2, 0, 0, 0, tchange, sdtch)

	for k=0, 3 {
		mygap( i, y0+ly, k, 0, 0, 0, tchange, sdtch)
	}
	mygap( i, y0+ly+1, 2, 0, 0, 0, tchange, sdtch)
	mygap( i, y0+ly-1, 3, 0, 0, 0, tchange, sdtch)
}

// fisso il blocco a sinistra e a destra con la mygap
for i= y0, y0+ly {
	for k=0, 3 {
		mygap( x0, i, k, 0, 0, 0, tchange, sdtch)
	}
	mygap( x0-1, i, 1, 0, 0, 0, tchange, sdtch)
	mygap( x0+1, i, 0, 0, 0, 0, tchange, sdtch)

	for k=0, 3 {
		mygap( x0+lx, i, k, 0, 0, 0, tchange, sdtch)
	}
	mygap( x0+lx-1, i, 1, 0, 0, 0, tchange, sdtch)
	mygap( x0+lx+1, i, 0, 0, 0, 0, tchange, sdtch)
}

// fisso il primo blocco centrale con la mygap
for j= y0+1, y0+ly-5{
	for k=0, 3 {
		mygap( xm1, j, k, 0, 0, 0, tchange, sdtch)
	}
	mygap( xm1-1, j, 1, 0, 0, 0, tchange, sdtch)
	mygap( xm1+1, j, 0, 0, 0, 0, tchange, sdtch)
}

// fisso il secondo blocco centrale con la mygap
for j= y0+5, y0+ly-1{
	for k=0, 3 {
		mygap( xm2, j, k, 0, 0, 0, tchange, sdtch)
	}
	mygap( xm2-1, j, 1, 0, 0, 0, tchange, sdtch)
	mygap( xm2+1, j, 0, 0, 0, 0, tchange, sdtch)
}

// 4 args are (i,j) position, direction (0,1,2,3 means 
// left, right, bottom, top),  and conductance (nS).


// strutturo la porta di ingresso con la mygap
for i=1, 3 {
		mygap( x0+lx-i, y0+ly-1, 2, 0, 0, 0, tchange, sdtch)
		mygap( x0+lx-i, y0+ly-1, 3, 30, 0, 0, tchange, sdtch)
		mygap( x0+lx-i, y0+ly, 0, 30, 0, 0, tchange, sdtch)
		mygap( x0+lx-i, y0+ly, 1, 30, 0, 0, tchange, sdtch)
		mygap( x0+lx-i, y0+ly, 2, 0, 0, 0, tchange, sdtch)
		mygap( x0+lx-i, y0+ly, 3, 30, 0, 0, tchange, sdtch)
		mygap( x0+lx+i, y0+ly+1, 2, 0, 0, 0, tchange, sdtch)
}

// strutturo la porta di uscita con la mygap
for i=1, 3 {
//		mygap( x0+i, y0-1, 2, 0, 0, 0, tchange, sdtch)
		mygap( x0+i, y0-1, 3, 30, 0, 0, tchange, sdtch)
		mygap( x0+i, y0, 0, 30, 0, 0, tchange, sdtch)
		mygap( x0+i, y0, 1, 30, 0, 0, tchange, sdtch)
		mygap( x0+i, y0, 2, 0, 0, 0, tchange, sdtch)
		mygap( x0+i, y0, 3, 30, 0, 0, tchange, sdtch)
//		mygap( x0+i, y0+1, 2, 0, 0, 0, tchange, sdtch)
}


/*
		for i=x0-2, x0+2 {
			for j=y0-1, y0+2 {
				pgap(i,j)
			}
		}
*/

/*
for i= x0-2, x0+2 {
	for j= y0+1,  y0+4{
		pgap(i,j)
		pgap(i,j)
	}
}
*/