#! /bin/tcsh -f

echo "**********************************"
echo "*  start start_standard_bin.csh  *"
echo "**********************************"
date
cd $result_dir/

if ( -r $bin_dir ) then
  echo "directory $bin_dir exists"
else
  mkdir $bin_dir
endif
mkdir $bin_dir/$dir0

if ($type_bin_cat2 == "3xmm") then
 if ( -r $bin_dir/$dir0/3XMM ) then 
  echo "$bin_dir/$dir0/3XMM dir exists"
 else
  mkdir $bin_dir/$dir0/3XMM
 endif
 if ( -r $bin_dir/$dir0/3XMM/BAD ) then 
  echo "$bin_dir/$dir0/3XMM/BAD dir exists"
 else
  mkdir $bin_dir/$dir0/3XMM/BAD
 endif
endif
set det=$result_dir/$dir0/detection
if (-e $det/emllist_singsrc_"$b_tot".txt) then
 cp $det/emllist_singsrc_"$b_tot".txt $bin_dir/$dir0
else
  if ($type_bin_cat1 == "full") then
   echo "FATAL ERROR $dir0 emllist_singsrc_"$b_tot".txt does not exist"
   echo "FATAL ERROR $dir0 emllist_singsrc_"$b_tot".txt does not exist FULLDET" >> $log_dir/messages.log
   echo "FATAL ERROR the bin fixed analysis with fulldet catalog can not start without the fulldet analysis"
   break
  endif
endif
cd $start_dir/

date
echo "stop start_standard_bin.csh"
