#! /bin/tcsh -f

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

if ( $type_anal_bayesian == "bayesian" ) then
 set baye = 1
 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"
 #set test_bayesian = 1
 if ( $test_bayesian != 0) then
  if ($ctrl_filt_bin_good == "yes") then
   echo "BEGIN ANALYSIS_BAYESIAN_BIN.CSH"
   echo start: `date`
   source $progr_dir/analysis_bayesian_bin.csh >>& $log_dir/analysis.log 
   echo end: `date`
   echo "END ANALYSIS_BAYESIAN_BIN.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 fulldet catalogue, can not be analysed with bayesian analysis in a time bin"
  echo "WARNING obs $dir0, cheesed with fulldet catalogue, can not be analysed with bayesian analysis in a time bin BAYESIAN" >> $log_dir/messages.log
 endif
endif
