#!/bin/csh -f

#
#  grab a series of images
#

onintr FINISH

set OPT =  (	"v 0 VERBOSE"	\
		"w 1 WIDTH"	\
		"h 1 HEIGHT"	\
		"t 1 TIME"	\
		"p 1 PATTERN"	\
		"m 1 MACHINE"	\
	   )

set USAGE = ( '[-t hh:mm:ss:ff] [-p pattern] [-w width -h height]' \
'                                   [-m machine] [start [end [inc]]]' \
'  ' \
'  -m specifies the host on which the VLAN device is located' \
'' \
'  vfgrab -t 00:01:20:00 -p $JOB/Pic/\$F.tif 1 150 2          1 to 150 on 2s'\
'  vfgrab -r 320 243 -t 00:01:20:00 -p $JOB/Pic/\$F.tif 1 150  ... at 320 x 243'\
	    )

set FRAMES 
set PATTERN = '$F.pic'

source /ufs/prisms/support/templates/args.sh

if ( $status ) exit $status

if ( ! $?TIME ) then
	echo specify time code with -t hh:mm:ss:ff
	exit 1
endif

if ( $?SETUP ) then
	set SETUP = "setup $SETUP"
else
	set SETUP = ""
endif

if ( $?MACHINE ) then
	set MACHINE = ${MACHINE}:
else
	set MACHINE = ""
endif

if ( $?WIDTH && $?HEIGHT ) then
	set RES = "-f -w $WIDTH -h $HEIGHT"
else
	set RES = ""
endif

set START = $F

vlangoto $TIME
@ FF = $F - 1
vlanadvance $FF

while ( $F <= $FEND )
	echo frame $F ...
	( echo ; echo n )  | vfrsnap >& /dev/null
	fc $RES `eval echo $PATTERN` = ${MACHINE}vf
	vlanadvance $FINC
	@ F = $F + $FINC
end

FINISH:
rm -f /tmp/vf.lock
