# This script is a modification of the "runext" script.  
# It performs a cycle based waveform average on a specific run file.
# This differs from "runext" in that it compares stimulator 3 against 
# stimulator 2.   
# The user must enter the waveform which contains the Stim Marker 
# captured as an (analogue) WF on the command line following the
# name of the runfile and file created containing the averages (binfile).

 if [ $# -ne 3 ]
then
	echo "script for WF average of response to stim 3 vs stim 2" >&2
	echo "Usage: $0 runfile binfile marker_wf" >&2
	exit 1
fi

analysis $1 <<!
w$3
sss1706.54
e0
dmax
tadqqqk
qawcsab1
qqsaw2,3,4,5,6,7,8,9,10,11,12
d-200ms
w500ms
qqqscw$3
qqsctyqqgb$2-stim

w$3
sss852.051
e0
d1816.41
tadqqqk
qawcsab1
qqsaw2,3,4,5,6,7,8,9,10,11,12
d-200ms
w500ms
qqqscw$3
qqsctyqqgb$2-ctrl

!
echo "y" | appendrun $2-stim $2-ctrl
qm $2-stim
