

nproc=1.
let nproc=2+0
echo nproc=$proc
outp=1.
xmlp=1.
let xmlold=0
while [ $nproc -gt 0 ]
do
	sleep 10
	outp=`ls | grep out | grep out.gz -v -c`
	let outp=outp-1
	xmlp=`ls | grep xml | grep xml.gz -v -c`
	let xmlp=xmlp
	nproc=`ps -ef | grep icecube.daq.domcal.DOMCal | grep -v grep -c`

 echo xml $xmlp    out $outp      proc $nproc

	if [ $outp -ne $1 ]; then
	    echo "missing out files. restart domcal?"
	fi
#	if [ $outp -eq $1 ]; then
	   # echo "Right number of out file created"
#	fi
	if [ $xmlold -ne $xmlp ]; then
	    echo "$xmlp doms finished (out of $outp)";
	    let xmlold=xmlp
	fi
	if [ $outp -eq $xmlp  ]; then
	    echo "calibration finished"
	    sleep 10
	    iceboot=`tail *.out | grep Iceboot -ic`
# make sure calibration finished and all doms are back:
	    if [ $iceboot -eq $xmlp ]; then 
		nproc=`ps -ef | grep icecube.daq.domcal.DOMCal | grep -v grep -c`
	    	if [ $nproc -gt 0 ]; then
			killall java
		fi
	     fi
	 echo "calibration finished"
	fi
done
exit
