//By Pirate Henry 2011 and modified by DK



proc ConnectTwoCells() { local targetid,sourceid,type,initW,delay,threshold localobj target,syn,nc,synlist,nclist

	sourceid = $1
	targetid = $2
	type = $3
	initW = $4
	delay = $5
//	threshold = $6
	synlist = $o6  //$o7
	nclist = $o7   //$o8

	if (!pc.gid_exists(targetid)) { continue }				// Can't connect to target if it doesn't exist 
		target = pc.gid2cell(targetid)
	           if (type == 1) {target.dend syn = new pyrD2pyrD_STFD(0.9)}   //P2P connection		 0.9 is original syn pos	                                  
											 
																   
   			    if (type == 2) {target.dend syn = new pyrD2interD_STFD(0.9)}  //P2I connection    0.9 is original syn pos
				                                     
				 
                if (type == 3) {target.soma syn = new interD2pyrD_STFD(0.9)}  //I2P connection   0.9 is original syn pos
														 
				if (type == 4) {target.soma syn = new interD2interD_STFD(0.9)}  //I2I connection    0.9 is original syn pos

				syn.pregid = sourceid
		syn.postgid = targetid
		syn.initW = initW
		target.synlist.append(syn)   // To save synapse data, weight and ca+ concentration
		syn.srcid= sourceid
		syn.destid= targetid
		nc = pc.gid_connect(sourceid,syn)
		nc.weight = 1
		nc.delay = delay
		nc.threshold = -10
		//printf("%d %d %d %d %d %d\n" ,syn.postgid,syn.pregid, syn.initW, nc.delay, nc.threshold, type)	     
		//saveM.printf("%d %d %f %f %d %d\n",syn.postgid, syn.pregid, syn.initW, nc.delay, nc.threshold, type) ///for printing out internal synaptic parameters into a file
        //saveM.close()		
		synlist.append(syn)
		nclist.append(nc)
		//{pc.barrier()}	

}