#!/bin/tcsh
#
# This script checks if a program gga is running, if so, it checks for a 
# rescue file. For an added check it looks if the word Tot can be found
# int the stats file, this would mean the program was already finished.
# If all these are true the program is restarted.
#
# TODO
# * Remove the crontab entry when the program is finished.
#   doesn't work right now.
#
# Author: J.I.v.Hemert
#

setenv PATH ".:$PATH"
if ("x`ps -u jvhemert | grep gga`" == 'x') then
	if (-f project/results/rescue-$1) then
		if ("x`grep Tot project/results/stats-$1`" == 'x') then
			cd project/bin
			(nohup ./gga ../configs/config-$1.gga >&! ../results/errors-$1 & ) >& /dev/null
			renice %2 15 >& /dev/null
		else
			crontab -r >& /dev/null
		endif
	endif
endif
