// Sequential deleting dendrites and their childs
// Papoutsi, 2017


objref list_primary[basal.count()]
//Find primary dendrites 
proc find_prim_dendrites () {
	prim=0
	for i=0, basal.count()-1 {
		//If the parent node is the root (=> primary basal dendrite)
		if (!basal.o(i).has_trueparent()) {
			list_primary[prim]=new List()
			basal.o(i).sec list_primary[prim].append(new SectionRef())
			//If this dendrite has childs
			if (basal.o(i).nchild()) {
				for j=0, basal.o(i).nchild()-1 {
					access basal.o(i).child[j] list_primary[prim].append(new SectionRef())
				}
			}
			prim=prim+1
		}
	}
}

proc delete_primary_dendrites () {
	dend_id11=$1
	dend_id22=$2
	if (list_primary[dend_id11].o(0).exists()) {
		for j=0, list_primary[dend_id11].count()-1 {
			access list_primary[dend_id11].o(j).sec 
			delete_section()
		}
	}
	if (dend_id22>dend_id11) {
		if (list_primary[dend_id22].o(0).exists()) {
			for j=0, list_primary[dend_id22].count()-1 {
				access list_primary[dend_id22].o(j).sec 
				delete_section()
			}
		}
	}
}

proc delete_apical() {
	for i=0, apical.count()-1 {
			access apical.o(i).sec 
			delete_section()
	}
}