#!/usr/bin/ksh

#----------------------------------------------------------------
#starts the batch job
#syntax:  cpu_q qlist.flist 
#where qlist is an flist of quick_start files
#The idea is not to have all the cpufinders running simultaneously
#but to send out packets when a cpu is available
#-----------------------------------------------------------------
#--------------------------------
#set environment variables
#--------------------------------
. $WFU_PATH/global.site.ksh


#--------------------------------
#set outputlog filenames
#--------------------------------
batchq=$1
qdir=`dirname $batchq`
qname=`basename $batchq`
cpuq=`echo _cpuq_outputlog`
output_cpuq=$qdir/$qname$cpuq
elog=`echo _cpuq_errorlog`
errorlog=`echo $qdir/$qname$elog`
cpu=`hostname`
user=`whoami`
#----------------------------
#get a current timestamp
#----------------------------
cdate=`date`
current_time=`$script_path/systime`
if test $rsh_flag -gt 0
	then cdate=`rsh $timekeeper date`
	current_time=`rsh $timekeeper $script_path/systime`
fi
db=`echo ' | ' `

echo -------------------------------------------------------------
echo This xterm is running an idl_spm99 batch process
echo batchq:    $batchq
echo username:  $user
echo hostcpu:   $cpu
echo date:      $cdate
echo systime:   $current_time 
echo If you kill it, then you kill the batch........
echo To check on the progress or to kill it use the idl command
echo               widget_batch
echo --------------------------------------------------------------

message1=`echo launch quickq $batchq$db initiated on $db$cpu$db$cdate$db$db$current_time $$`
echo $message1 > $output_cpuq
echo $message1 > $errorlog
cpu_q $batchq >>$output_cpuq 2>>$errorlog 
echo ALL DONE
exit
