#! /bin/csh -f

# Check parameters, and verify file structure:
###############################################
set IP=172.16.34.179 #  mdfl1-hub1
#set IP=172.16.34.172 #mdfl2-hub2
if ($#argv != 2) then
	echo "Usage: $0 temperature A/B"; exit 1
endif
if (! -d ~/Results/STF) then
	echo "No ~/Results/STF directory found"; exit 1
endif
cd ~/Results/STF
if (! -d ~/Results/STF/$1$2) then
	mkdir $1$2
endif 
cd $1$2
 if (-e stf_results.txt) then
 	mv stf_results.txt stf_results.txt.old
 endif 
 if (-e stf_failures.txt) then
	mv stf_failures.txt stf_failures.txt.old
 endif
echo Starting stf in $1. results in : 
pwd

# cp ~/properties/dh.properties ~/properties/dh.before-stf.properties
####################################################
# Starting stfA
####################################################

echo "0" > /proc/driver/domhub/blocking
echo "starting stf on T doms..."
# cp ~/properties/stfA.properties ~/properties/dh.properties
killall dtsx
off all
on all
gotoiceboot
dtsxallA
java icecube.daq.stf.STF ~/all-tests true 1 $1 $IP  5001 64
   

####################################################
# Starting stfB
####################################################
echo "0" > /proc/driver/domhub/blocking
echo "Starting STF on U doms"
# cp ~/properties/stfB.properties ~/properties/dh.properties
killall dtsx
dtsxallB
java icecube.daq.stf.STF ~/all-tests true 1 $1 $IP 5001 64   

###################################################
# Initial analysis - count DOMS and tests
###################################################
echo "Starting analysis....check ~/Results/STF/$1$2/stf_final_$1$2.txt"
~/hagar/stf.pl 
cat stf_summary.txt stf_fail.txt > stf_final_$1$2.txt

