#! /bin/tcsh -f

if ( $type_anal_bayesian == "bayesian" ) then
 if ( $baye == 1 ) then
  echo "analysis bayesian bin already done"
 else
  echo "******************************************" >>& $log_dir/analysis.log
  echo "*                                        *" >>& $log_dir/analysis.log
  echo "*  OUT TO SRC AND CLOSE TO SRC ANALYSIS  *" >>& $log_dir/analysis.log
  echo "*                                        *" >>& $log_dir/analysis.log
  echo "******************************************" >>& $log_dir/analysis.log

  echo "BEGIN START_STANDARD_BIN_BAYESIAN.CSH"
  echo start: `date`
  source $progr_dir/start_standard_bin_bayesian.csh >>& $log_dir/analysis.log
  echo end: `date`
  echo "END START_STANDARD_BIN_BAYESIAN.CSH"
  
  echo "BEGIN FILTER_BAYESIAN.CSH"
  echo start: `date`
  source $progr_dir/filter_bayesian.csh >>& $log_dir/analysis.log
  echo end: `date`
  echo "END FILTER_BAYESIAN.CSH"
  
  echo "BEGIN BAYESIAN_BLOCK.CSH"
  echo start: `date`
  source $progr_dir/bayesian_block.csh >>& $log_dir/analysis.log 
  echo end: `date`
  echo "END BAYESIAN_BLOCK.CSH"
 endif

 if ( $test_bayesian_3xmm != 0) then
  if ($ctrl_filt_bin_good == "yes") then
   echo "BEGIN ANALYSIS_BAYESIAN_BIN_3XMM.CSH"
   echo start: `date`
   source $progr_dir/analysis_bayesian_bin_3xmm.csh >>& $log_dir/analysis.log 
   echo end: `date`
   echo "END ANALYSIS_BAYESIAN_BIN_3XMM.CSH"
  else
   echo "WARNING: Skipping obs $dir0, N. of bayesian time bins ($ctrl_filt_bin) exceeds the limit of $baye_n_bin_max"
   echo "WARNING: Skipping obs $dir0, N. of bayesian time bins ($ctrl_filt_bin) exceeds the limit of $baye_n_bin_max" >> $log_dir/messages.log
  endif
 else
  echo "WARNING obs $dir0, cheesed with 3xmm catalogue, can not be analysed with bayesian time bin analysis"
  echo "WARNING obs $dir0, cheesed with 3xmm catalogue, can not be analysed with bayesian time bin analysis BAYESIAN" >> $log_dir/messages.log
 endif
endif
