#! /bin/tcsh -f

echo "******************************"
echo "*  start global_hk_3XMM.csh  *"
echo "******************************"
date

echo "===================================================="
echo "STARTING THE ANALYSIS WITH THE 3XMM ENGLISH APPROACH"
echo "===================================================="

setenv SAS_RAND_SEED $dir0
setenv SAS_ODF $pps_archive_dir/$dir0/pps

if ($barycentr == "no") then
set att1=`ls $data_dir/$dir0/*AttHk*`
if ( -e $att1 ) then
 echo "OK: the attitude file $att1 exists"
 echo "Start to create Global Hk file"
 tabgtigen expression="\!isNull(DAHFPNT) && DAHFPNT < 3.0/60.0" gtiset="$data_dir"/"$dir0"/"$dir0"_GlobalHK-Attitude_GTI.fits postfraction=0 prefraction=0 table="$att1":ATTHK -w "$warn" -V "$verb"
 chmod 766 "$data_dir"/"$dir0"/"$dir0"_GlobalHK-Attitude_GTI.fits
else
 echo "ERROR: the attitude file $att1 does not exist"
 echo "ERROR: the attitude file $att1 does not exist" >> $log_dir/messages.log
endif
else
 echo "The global Hk is not necessary. The event files barycentered is already filtered with global Hk"
endif

date
echo "stop global_hk_3XMM.csh"
