#! /bin/tcsh -f

if ( $bin == 1 ) then
  echo "analysis bin fixed already done"
  echo "BEGIN ANALYSIS_BIN_3XMM.CSH"
  echo start: `date`
  source $progr_dir/analysis_bin_3xmm.csh >>& $log_dir/analysis.log 
  echo end: `date`
  echo "END ANALYSIS_BIN_3XMM.CSH"
else
  echo "***********************" >>& $log_dir/analysis.log
  echo "*                     *" >>& $log_dir/analysis.log
  echo "*  BINFIXED ANALYSIS  *" >>& $log_dir/analysis.log
  echo "*                     *" >>& $log_dir/analysis.log
  echo "***********************" >>& $log_dir/analysis.log

  echo "BEGIN START_STANDARD_BIN.CSH"
  echo start: `date`
  source $progr_dir/start_standard_bin.csh >>& $log_dir/analysis.log
  echo end: `date`
  echo "END START_STANDARD_BIN.CSH"

  echo "BEGIN SELECT_TIME_BIN.CSH"
  echo start: `date`
  source $progr_dir/select_time_bin.csh  >>& $log_dir/analysis.log
  echo end: `date`
  echo "END SELECT_TIME_BIN.CSH"

  echo "BEGIN TIMEBIN_STANDARD_BIN.CSH"
  echo start: `date`
  source $progr_dir/timebin_standard_bin.csh >>& $log_dir/analysis.log
  echo end: `date`
  echo "END TIMEBIN_STANDARD_BIN.CSH"
  #set test_bin = 1
  if ( $test_bin != 0) then
    echo "BEGIN ANALYSIS_BIN_3XMM.CSH"
    echo start: `date`
    source $progr_dir/analysis_bin_3xmm.csh >>& $log_dir/analysis.log 
    echo end: `date`
    echo "END ANALYSIS_BIN_3XMM.CSH"
  else
    echo "WARNING obs $dir0 can not be analysed with binfixed analysis in a common time bin"
    echo "WARNING obs $dir0 can not be analysed with binfixed analysis in a common time bin BINFIXED 3XMM" >> $log_dir/messages.log
  endif
endif
