{load_file("nrngui.hoc")}
{load_file("mitral.hoc")}
{load_file("granule.hoc")}
celsius = 35
objref nil, pc
pc = new ParallelContext()

// if iterator does not exist load the default one.
if (!name_declared("cell_gids")) { load_file("iterator.hoc") }

// line of nmitral mitral cells distributed from position 0 to len.
// No wrap-around. Each mitral cell assumed to have two
// secondary dendrites along the line with length len.

//network size parameters
len = 1000 // size of the linear domain, mitral positions range from 0 to len
Lsec = 1000 // mitral secden length
ngranule = 100 // distributed uniformly over the linear domain
// positions of mitral cells (and defined nmitral)
objref mitral_x
mitral_x = new Vector()
mitral_x.append(100,300,500,700,900)

nmitral=mitral_x.size

// networksize assigned variables
// see comment on global GIDs assigned to cells

nmitral_begin = 0
ngranule_begin = nmitral_begin + nmitral
ncell = ngranule_begin + ngranule

//variables
// each cpu will have its own cell objects

objref cells  //mitrals and granules on this cpu
cells = new List()

// for initialization
Vrest=-65
proc init() {
	finitialize(Vrest)
	forall {
		if (ismembrane("nax")) {
			e_pas=v+(ina+ik)/g_pas
		} else if (ismembrane("k_ion")){
			e_pas=v+ik/g_pas
		}
	}
	fcurrent()
	cvode.re_init()
	frecord_init()
}

//parallel network object

{load_file("mgrs.hoc")}
{load_file("connect.hoc")}

// distribute GIDs and create cells

proc create_cells() { local gid, i, j, nm   localobj cell, nc
    for cell_gids(&gid, &i) {    //iterator returns changed value of address &gid in each loop
	
	pc.set_gid2node(gid, pc.id) //here the return value of iterator (gid) is used
	if (gid < nmitral) {
	    cell = new Mitral()
	    cell.position(mitral_x.x[gid], gid*20, 0)
	    cell.soma nc = new NetCon(&v(.5),nil)
	    for j=0,1 cell.secden[j].L = Lsec
	} else {
	    cell = new Granule()
	    cell.position(((gid-ngranule_begin)+.5)*len/ngranule, -100, 0)
	    cell.soma nc = new NetCon(&v(.5),nil)
	}
	cells.append(cell)
	print pc.id, gid, cell
 
	pc.cell(gid, nc)
    }
}

create_cells()

connect_cells()

//load_file("control_net_graphics.hoc")
//load_file("control_net3.hoc")
for i=0, mgrs_list.count-1 mgrs_list.object(i).pr()