#! /usr/local/bin/gdsh

# capture data
gds-open /dev/ttyACM0

if [ $# = 0 ] ; then
 channels=$(gds-channels -a)
else
 channels="$@"
fi

echo "Capturing channels: $channels" >&2
TMP=$(mktemp -u)

SCAL=`:chan1:scal_`
FILES=
:stop
for ch in $channels ; do
 :acq${ch}:mem_ -0 -h -V $SCAL > ${TMP}-${ch}
 FILES="$FILES ${TMP}-${ch}"
done
:run
gds-close

# parse temporary files
tabs 10

paste $FILES | \
 sed s/'\t'/'\ '/g | \
 cut -d\  -f 1,2,4,6,8 | \
 sed s/'\ '/'\t'/g

rm $FILES

echo "OK" >&2
