// The below function is designed to return a voltage integral, with the offset
// removed, in accordance with Yujin's analysis.  
// NOTE: requires a fixed time step.
// INPUT 1: vector of voltages
// INPUT 2: step size, in msec, used in experiments
// INPUT 3: time that indicates the beginning of the integral
// INPUT 4: time that indicates the end of the integral
// OUTPUT: the integral of the voltage response

objref theVec // copy of voltage trace
objref theVecSub // subset of voltage trace used for integral
objref theVecInt // the integral of voltage neighbourhood

func getVoltageIntegral() {local step

	// copy the voltage trace to theVec
	theVec = new Vector()
	theVec.copy($o1)
	
	// get step size
	step = $2
	
	// subtract baseline
	initTime = $3 // index to calculate baseline voltage
	baseVolt = theVec.x[initTime/step-1]
	baseVolt = baseVolt*-1
	theVec.add(baseVolt)
	
	// extract the neighbourhood of interest
	termTime = $4 // terminal index
	theVecSub = new Vector()
	theVecSub.copy(theVec,initTime/step,termTime/step)
		
	// integrate the neighbourhood of interest
	theVecInt = new Vector()
	theVecInt.integral(theVecSub,step)
	
	// return full integral, found in last entry of integrated vector
	theInt = theVecInt.x[theVecInt.size()-1]
	return theInt
}


//foo = getVoltageIntegral(somaVolt,dt,ccDel,ccDel+ccDur+100)