#! /bin/tcsh -f

echo "********************"
echo "*  check_epic.csh  *"
echo "********************"
date

if ( $DET == 1 ) then
  if ( `ls -1 $data_dir/$dir0/*Imaging* | grep MOS` !='' ) then   
   set check_epic1="OK"
   echo "ATTENTION: in $dir0 there are MOS event files, the obs $dir0 can be analysed in DET=$DET analysis" 
  else
   set check_epic1="NO"
   echo "ATTENTION: in $dir0 there are not MOS event files, the obs $dir0 can not be analysed in DET=$DET analysis" 
   echo "in $dir0 there are not MOS event file"  >> $log_dir/bad_check_epic.txt
  endif
  set check_epic="$check_epic1"
endif

if ( $DET == 01 ) then
  if ( `ls -1 $data_dir/$dir0/*Imaging* | grep MOS1` !='' ) then   
   set check_epic1="OK"
   echo "ATTENTION: in $dir0 there are MOS1 event files, the obs $dir0 can be analysed in DET=$DET analysis" 
  else
   set check_epic1="NO"
   echo "ATTENTION: in $dir0 there are not MOS1 event file, the obs $dir0 can not be analysed in DET=$DET analysis" 
   echo "in $dir0 there are not pn event file"  >> $log_dir/bad_check_epic.txt
  endif
  set check_epic="$check_epic1"
endif

if ( $DET == 02 ) then
  if ( `ls -1 $data_dir/$dir0/*Imaging* | grep MOS2` !='' ) then   
   set check_epic1="OK"
   echo "ATTENTION: in $dir0 there are MOS2 event files, the obs $dir0 can be analysed in DET=$DET analysis" 
  else
   set check_epic1="NO"
   echo "ATTENTION: in $dir0 there are not MOS2 event file, the obs $dir0 can not be analysed in DET=$DET analysis" 
   echo "in $dir0 there are not pn event file"  >> $log_dir/bad_check_epic.txt
  endif
  set check_epic="$check_epic1"
endif

if ( $DET == 03 ) then
  if ( `ls -1 $data_dir/$dir0/*Imaging* | grep PN` !='' ) then   
   set check_epic1="OK"
   echo "ATTENTION: in $dir0 there are pn event files, the obs $dir0 can be analysed in DET=$DET analysis" 
  else
   set check_epic1="NO"
   echo "ATTENTION: in $dir0 there are not pn event file, the obs $dir0 can not be analysed in DET=$DET analysis" 
   echo "in $dir0 there are not pn event file"  >> $log_dir/bad_check_epic.txt
  endif
  set check_epic="$check_epic1"
endif

if ( $DET == 2 ) then
  if ( `ls -1 $data_dir/$dir0/*Imaging* | grep MOS` !='' ) then   
   set check_epic1="OK"
   echo "ATTENTION: in $dir0 there are MOS event files, the obs $dir0 can be analysed in DET=$DET analysis" 
  else
   set check_epic1="NO"
   echo "ATTENTION: in $dir0 there are not MOS event files, the obs $dir0 can not be analysed in DET=$DET analysis" 
   echo "in $dir0 there are not MOS event file"  >> $log_dir/bad_check_epic.txt
  endif

  if ( `ls -1 $data_dir/$dir0/*Imaging* | grep PN` !='' ) then   
   set check_epic2="OK"
   echo "ATTENTION: in $dir0 there are pn event files, the obs $dir0 can be analysed in DET=$DET analysis" 
  else
   set check_epic2="NO"
   echo "ATTENTION: in $dir0 there are not pn event file, the obs $dir0 can not be analysed in DET=$DET analysis" 
   echo "in $dir0 there are not pn event file"  >> $log_dir/bad_check_epic.txt
  endif

  if ( $check_epic1 == "NO" && $check_epic2 == "NO") then
   set check_epic="NO"
   echo "ATTENTION: in $dir0 there are not MOS and pn event file, the obs $dir0 can not be analysed in DET=$DET analysis" 
  else
   set check_epic="OK"
  endif 
endif

date
echo "stop check_epic.csh"
