#!/bin/sh
#
# Script to start off a sequence grab in pixcel
#
# Andrew J. Dean 19th Oct, 2000

# Check for appropriate input
if [ ! $4 ] 
	then 
	echo "Usage: $0 file_name loops reads exposure" 
	exit 1 
fi 

pixelprog="/home/cirpass/cirpass_software/bin/pixel";

# Check pixel is ready
pixelreply=`$pixelprog status`
if test $pixelreply != READY
	then
	echo "PixCel status is $pixelreply, should be READY, waiting 3s then trying again"
	sleep 3
	pixelreply=`$pixelprog status`
	if test $pixelreply != READY
	    then
	    echo "PixCel status is $pixelreply, not READY, quitting"
	    exit 1
	fi
fi

# Set object name
pixelreply=`$pixelprog "object $1"`
# echo Object name = $pixelreply
if test $pixelreply != $1
	then
	echo "Could not set object name to $1 in PixCel"
	exit 1
fi

#Set loops
pixelreply=`$pixelprog "loops $2"`
# echo Loops = $pixelreply
if test $pixelreply != $2
	then
	echo "Could not set loops to $2 in PixCel"
	exit 1
fi

#Set reads
pixelreply=`$pixelprog "reads $3"`
# echo reads = $pixelreply
if test $pixelreply != $3
	then
	echo "Could not set number of reads to $3 in PixCel"
	exit 1
fi

#Set exposure
pixelreply=`$pixelprog "exptime $4"`
# echo exposure = $pixelreply
if  test "$pixelreply" != "$4" 
	then
	echo "Could not set Exposure to $4 in PixCel"
	echo "Exposure is actually $pixelreply"
fi

#Find out run number
runnum=`$pixelprog run`
#Start the run
echo Starting Sequence grab
echo Run number = $runnum
if  [ `$pixelprog go >& /dev/null` ] 
	then
	echo "Sequence grab failed"
	exit 1
fi

echo Exposure Successful
# beep
exit 0






