#! /bin/tcsh -f

echo "******************************"
echo "*  start bayesian_block.csh  *"
echo "******************************"
date

cd $result_dir/
set filter_dir = $result_dir/$dir0/filter
set filter_dir_closetosrc = $filter_dir/closetosrc

if ($outtosrc == "yes") then
 cd $filter_dir/
 if (-e "$dir0"_start_bin_3xmm.txt) then
  rm "$dir0"_start_bin_3xmm.txt 
 endif
 if (-e "$dir0"_stop_bin_3xmm.txt) then
  rm "$dir0"_stop_bin_3xmm.txt
 endif
 if (-e "$dir0"_start_bin_3xmm_deg.txt) then
  rm "$dir0"_start_bin_3xmm_deg.txt 
 endif
 if (-e "$dir0"_stop_bin_3xmm_deg.txt) then
  rm "$dir0"_stop_bin_3xmm_deg.txt
 endif
 if (-e "$dir0"_start_bin_3xmm_orig.txt) then
  rm "$dir0"_start_bin_3xmm_orig.txt 
 endif
 if (-e "$dir0"_stop_bin_3xmm_orig.txt) then
  rm "$dir0"_stop_bin_3xmm_orig.txt
 endif
 if (-e check_bayesian_3xmm.txt) then
  rm check_bayesian_3xmm.txt
 endif
 if (-e "$dir0"_start_bin.txt) then
  rm "$dir0"_start_bin.txt 
 endif
 if (-e "$dir0"_stop_bin.txt) then
  rm "$dir0"_stop_bin.txt 
 endif
 if (-e "$dir0"_start_bin_deg.txt) then
  rm "$dir0"_start_bin_deg.txt 
 endif
 if (-e "$dir0"_stop_bin_deg.txt) then
  rm "$dir0"_stop_bin_deg.txt
 endif
 if (-e "$dir0"_start_bin_orig.txt) then
  rm "$dir0"_start_bin_orig.txt 
 endif
 if (-e "$dir0"_stop_bin_orig.txt) then
  rm "$dir0"_stop_bin_orig.txt
 endif
 if (-e check_bayesian.txt) then
  rm check_bayesian.txt
 endif
endif

if ($closetosrc == "yes") then
 cd $filter_dir_closetosrc/
 if (-e "$dir0"_start_bin_3xmm.txt) then
  rm "$dir0"_start_bin_3xmm.txt 
 endif
 if (-e "$dir0"_stop_bin_3xmm.txt) then
  rm "$dir0"_stop_bin_3xmm.txt
 endif
 if (-e "$dir0"_start_bin_3xmm_deg.txt) then
  rm "$dir0"_start_bin_3xmm_deg.txt 
 endif
 if (-e "$dir0"_stop_bin_3xmm_deg.txt) then
  rm "$dir0"_stop_bin_3xmm_deg.txt
 endif
 if (-e "$dir0"_start_bin_3xmm_orig.txt) then
  rm "$dir0"_start_bin_3xmm_orig.txt 
 endif
 if (-e "$dir0"_stop_bin_3xmm_orig.txt) then
  rm "$dir0"_stop_bin_3xmm_orig.txt
 endif
 if (-e check_bayesian_3xmm.txt) then
  rm check_bayesian_3xmm.txt
 endif
 if (-e "$dir0"_start_bin.txt) then
  rm "$dir0"_start_bin.txt 
 endif
 if (-e "$dir0"_stop_bin.txt) then
  rm "$dir0"_stop_bin.txt 
 endif
 if (-e "$dir0"_start_bin_deg.txt) then
  rm "$dir0"_start_bin_deg.txt 
 endif
 if (-e "$dir0"_stop_bin_deg.txt) then
  rm "$dir0"_stop_bin_deg.txt
 endif
 if (-e "$dir0"_start_bin_orig.txt) then
  rm "$dir0"_start_bin_orig.txt 
 endif
 if (-e "$dir0"_stop_bin_orig.txt) then
  rm "$dir0"_stop_bin_orig.txt
 endif
 if (-e check_bayesian.txt) then
  rm check_bayesian.txt
 endif
endif

set ctrl_expo = 0
if ($type_baye_cat2 == "3xmm") then
 if ($outtosrc == "yes") then
   cp $xmmdac_dir/xtdac.py $filter_dir/
   chmod 755 $filter_dir/xtdac.py
   cp $xmmdac_dir/xtcheesemask.py $filter_dir/
   chmod 755 $filter_dir/xtcheesemask.py
   cp $xmmdac_dir/xtfixtimestamps.py $filter_dir/
   chmod 755 $filter_dir/xtfixtimestamps.py
   set list_evt="list_evt_filtered_baye_cheese_3xmm.txt"
 endif
 if ($closetosrc == "yes") then
   cp $xmmdac_dir/xtfbs.py $filter_dir_closetosrc/
   chmod 755 $filter_dir_closetosrc/xtfbs.py
   set list_evt="list_evt_filtered_baye_cheese_3xmm.txt"
 endif

 if ($outtosrc == "yes") then
  cd $filter_dir/
  set ctrl = `wc $filter_dir/$list_evt | awk '{print $1}'`
  if ( $ctrl == 0) then
      echo "============================================================"
      echo "FATAL ERROR: no events files in $filter_dir"
      echo "============================================================"
      echo "FATAL ERROR: no events files in $filter_dir" >> $log_dir/messages.log
      break
  else
      echo ""
      echo "******************************"
      echo "* OUT TO SRC ANALYSIS (3XMM) * "
      echo "******************************"
      echo ""
      foreach evt (`cat $filter_dir/$list_evt`)
       fkeypar ${evt}+1 NAXIS2
       set evt_rows = `pget fkeypar.par value`
       if (${evt_rows} == 0) then
        set base_name_evt = `echo $evt | cut -d'.' -f1`
        echo "#RA Dec Tstart Tstop Probability" > ${base_name_evt}_res.txt
        set epic_new = `echo $evt | cut -c 9-10`
        set epic_fin = `echo $evt | cut -c 11-12`
        set epic = `echo $evt | cut -c 9-12`
        set type = `echo $evt | cut -c 14-17`
        set ccd_n = `echo $evt | cut -d'.' -f1 | cut -d'_' -f7`
        if (${epic_new} == "PN") then
          echo " PN QUADRANT: ${ccd_n}"
        else
         if (${epic_fin} == "S1") then
          set epic_new = "M1" 
          echo " MOS1 CCD: ${ccd_n}"
         endif
         if (${epic_fin} == "S2") then
          set epic_new = "M2" 
          echo " MOS2 CCD: ${ccd_n}"
         endif
        endif
        echo "WARNING: the event file ${evt} is empty after filtering"
        echo "Skipping the analysis of the event file ${evt} with xtdac.py task..."
        set ctrl_expo = 1
       else
       set ctrl_PNexpo_cheese1 = 0 
       set ctrl_PNexpo_cheese2 = 0
       set ctrl_PNexpo_cheese3 = 0
       set ctrl_M1expo_cheese1 = 0
       set ctrl_M1expo_cheese2 = 0
       set ctrl_M1expo_cheese3 = 0
       set ctrl_M2expo_cheese1 = 0
       set ctrl_M2expo_cheese2 = 0
       set ctrl_M2expo_cheese3 = 0
       set epic_new = `echo $evt | cut -c 9-10`
       set epic_fin = `echo $evt | cut -c 11-12`
       set epic = `echo $evt | cut -c 9-12`
       set type = `echo $evt | cut -c 14-17`
       set base_name_evt = `echo $evt | cut -d'.' -f1`
       set ccd_n = `echo $evt | cut -d'.' -f1 | cut -d'_' -f7`
       set mask="${filter_dir}/${epic}200_12000_${type}_${ccd_n}.mask"
       if (${epic_new} == "PN") then
        echo " PN QUADRANT: ${ccd_n}"
       else
        if (${epic_fin} == "S1") then
         set epic_new = "M1" 
         echo " MOS1 CCD: ${ccd_n}"
        endif
        if (${epic_fin} == "S2") then
         set epic_new = "M2" 
         echo " MOS2 CCD: ${ccd_n}"
        endif
       endif
       set nband_tot = 8000
       set expo_expo0="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband_tot}.FTZ"
       if ( -e ${expo_expo0} ) then
          echo "Starting to perform the bayesian blocks analysis..."
          set filtered=$evt
          set emin=`echo $filtered | grep "$type" | cut -d'_' -f3 | cut -d' ' -f1`
          set emax=`echo $filtered | grep "$type" | cut -d'_' -f4 | cut -d' ' -f1`
          set nband_baye = `cat $result_dir/$dir0/energy_band_bayesian.txt | wc -l`
          if ($emin == 200 && $emax == 12000) then
            echo "ENERGY BAND (eV): ${emin} - ${emax}"
            set nband = 8000
            set expo_expo0="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband}.FTZ"
            set expo_mask1="${dir0}${epic_new}${type}EXPMAP_1.fits"
            set expo_mask="${dir0}${epic_new}${type}EXPMAP_1_${ccd_n}.fits"
            set expo_mask_cheese="${dir0}${epic_new}${type}EXPMAP_1_cheese_${ccd_n}.fits"
            if (-e $expo_expo0) then
             if (-e $expo_mask) then
              echo "$expo_mask already done"
              set ctrl_expo = 1
             else
              gunzip -c $expo_expo0 > $expo_mask1
              if (-e $expo_mask1) then
               ftimgcalc a=A=${expo_mask1} b=B=${mask} expr="(A * B)" outfile=${expo_mask}
              endif
              set ctrl_expo = 1
             endif
            else
             echo "WARNING: ${expo_expo0} does not exist !"
             set ctrl_expo = 0
            endif
             if ($epic_new == "PN" && $ctrl_PNexpo_cheese1 == 0) then
             if ( -e ${expo_expo0}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for pn instrument..."
              set ctrl_PNexpo_cheese1 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p ./xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
             if ($epic_new == "M1" && $ctrl_M1expo_cheese1 == 0) then
             if ( -e ${expo_expo0}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for MOS1 instrument..."
              set ctrl_M1expo_cheese1 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
             if ($epic_new == "M2" && $ctrl_M2expo_cheese1 == 0) then
             if ( -e ${expo_expo0}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for MOS2 instrument..."
              set ctrl_M2expo_cheese1 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
          endif
          if ($emin == 500 && $emax == 2000) then
            echo "ENERGY BAND (eV): ${emin} - ${emax}"
            set nband1 = 2000
            set nband2 = 3000
            set expo_expo1="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband1}.FTZ"
            set expo_expo2="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband2}.FTZ"
            set expo_expo1new="P${dir0}${epic_new}${type}EXPMAP${nband1}.fits"
            set expo_expo2new="P${dir0}${epic_new}${type}EXPMAP${nband2}.fits"
            set expo_mask1="${dir0}${epic_new}${type}EXPMAP_2.fits"
            set expo_mask="${dir0}${epic_new}${type}EXPMAP_2_${ccd_n}.fits"
            set expo_mask_cheese="${dir0}${epic_new}${type}EXPMAP_2_cheese_${ccd_n}.fits"
            if (-e $expo_expo1 && -e $expo_expo2) then
             if (-e $expo_mask) then
              echo "$expo_mask already done"
              set ctrl_expo = 1
             else
              gunzip -c $expo_expo1 > $expo_expo1new
              gunzip -c $expo_expo2 > $expo_expo2new
              echo "imweightadd imagesets=' ${expo_expo1new} ${expo_expo2new} ' outimageset=${expo_mask1} tempset=temporary.fits withweights=no -w "$warn" -V "$verb"" > imweightadd.csh
              source imweightadd.csh
              rm imweightadd.csh
              rm $expo_expo1new
              rm $expo_expo2new
              if (-e $expo_mask1) then
               ftimgcalc a=A=${expo_mask1} b=B=${mask} expr="(A * B)" outfile=${expo_mask}
              endif
              set ctrl_expo = 1
             endif
            else
             echo "WARNING: ${expo_expo1} and ${expo_expo2} do not exist !"
             set ctrl_expo = 0
            endif
             if ($epic_new == "PN" && $ctrl_PNexpo_cheese2 == 0) then
             if ( -e ${expo_expo1} && -e ${expo_expo2}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for pn instrument..."
              set ctrl_PNexpo_cheese2 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
             if ($epic_new == "M1" && $ctrl_M1expo_cheese2 == 0) then
             if ( -e ${expo_expo1} && -e ${expo_expo2}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for MOS1 instrument..."
              set ctrl_M1expo_cheese2 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
             if ($epic_new == "M2" && $ctrl_M2expo_cheese2 == 0) then
             if ( -e ${expo_expo1} && -e ${expo_expo2}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for MOS2 instrument..."
              set ctrl_M2expo_cheese2 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
          endif
          if ($emin == 2000 && $emax == 10000) then
            echo "ENERGY BAND (eV): ${emin} - ${emax}"
            set nband = 4000
            set expo_expo3="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband}.FTZ"
            set expo_mask1="${dir0}${epic_new}${type}EXPMAP_3.fits"
            set expo_mask="${dir0}${epic_new}${type}EXPMAP_3_${ccd_n}.fits"
            set expo_mask_cheese="${dir0}${epic_new}${type}EXPMAP_3_cheese_${ccd_n}.fits"
            if (-e $expo_expo3) then
             if (-e $expo_mask) then
              echo "$expo_mask already done"
              set ctrl_expo = 1
             else
              gunzip -c $expo_expo3 > $expo_mask1
              if (-e $expo_mask1) then
               ftimgcalc a=A=${expo_mask1} b=B=${mask} expr="(A * B)" outfile=${expo_mask}
              endif
              set ctrl_expo = 1
             endif
            else
             echo "WARNING: ${expo_expo3} does not exist !"
             set ctrl_expo = 0
            endif
             if ($epic_new == "PN" && $ctrl_PNexpo_cheese3 == 0) then
             if ( -e ${expo_expo3}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for pn instrument..."
              set ctrl_PNexpo_cheese3 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
             if ($epic_new == "M1" && $ctrl_M1expo_cheese3 == 0) then
             if ( -e ${expo_expo3}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for MOS1 instrument..."
              set ctrl_M1expo_cheese3 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
             if ($epic_new == "M2" && $ctrl_M2expo_cheese3 == 0) then
             if ( -e ${expo_expo3}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for MOS2 instrument..."
              set ctrl_M2expo_cheese3 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
          endif

          if ($ctrl_expo == 1) then 
           echo "Starting to perform the bayesian blocks analysis on $filtered event file cheesed with 3XMM catalog and on exposure map $expo_mask_cheese"
           if ($ambient == "cluster") then
            echo "#\!/bin/bash" > ${filter_dir}/xtdac.csh
            ##In order to correct RuntimeError: Non-unique time stamps in event file
            echo "/usr/bin/time -p python xtfixtimestamps.py --eventfile ${filter_dir}/${filtered} --verbosity $info" >> ${filter_dir}/xtdac.csh
            echo "/usr/bin/time -p python xtdac.py --eventfile ${filter_dir}/${filtered} -x $expo_mask_cheese --ncpus $ncpu --typeIerror $Ierror -s $stss_out --regionsize $regionsize -m $multiplicity --writeRegionFiles $writeReg --verbosity $info --no-html" >> ${filter_dir}/xtdac.csh
            chmod 755 ${filter_dir}/xtdac.csh
            source ${filter_dir}/xtdac.csh 
            rm ${filter_dir}/xtdac.csh
           endif
           if ($ambient == "mac") then
            echo "/usr/bin/time -p python xtfixtimestamps.py --eventfile ${filter_dir}/${filtered} --verbosity $info" >> ${filter_dir}/xtdac.csh
            echo "/usr/bin/time -p python xtdac.py --eventfile ${filter_dir}/${filtered} -x $expo_mask_cheese --ncpus $ncpu --typeIerror $Ierror -s $stss_out --regionsize $regionsize -m $multiplicity --writeRegionFiles $writeReg --verbosity $info --no-html" >> ${filter_dir}/xtdac.csh
            source ${filter_dir}/xtdac.csh
            rm ${filter_dir}/xtdac.csh
           endif
          else
           echo "WARNING: PPS exposure maps do not exist or the event file ${evt} is empty !"
          endif
       else
        echo "WARNING: ${expo_expo0} does not exist. No PPS exposure maps are ready to use !"
        set ctrl_expo = 0
       endif
       endif
      end
  endif
 endif
 if ($closetosrc == "yes") then
  cd $filter_dir_closetosrc/
  set ctrl = `wc $filter_dir_closetosrc/$list_evt | awk '{print $1}'`
  if ( $ctrl == 0) then
      echo "============================================================"
      echo "FATAL ERROR: no events files in $filter_dir_closetosrc"
      echo "============================================================"
      echo "FATAL ERROR: no events files in $filter_dir_closetosrc" >> $log_dir/messages.log
      break
  else
      echo ""
      echo "********************************"
      echo "* CLOSE TO SRC ANALYSIS (3XMM) *"
      echo "********************************"
      echo ""
      foreach evt (`cat $filter_dir_closetosrc/$list_evt`)
       fkeypar ${evt}+1 NAXIS2
       set evt_rows = `pget fkeypar.par value`
       if (${evt_rows} == 0) then
        set base_name_evt = `echo $evt | cut -d'.' -f1`
        echo "#RA Dec Tstart Tstop Probability" > ${base_name_evt}_unique_res.txt
        set epic_new = `echo $evt | cut -c 9-10`
        set epic_fin = `echo $evt | cut -c 11-12`
        set epic = `echo $evt | cut -c 9-12`
        set type = `echo $evt | cut -c 14-17`
        set ccd_n = `echo $evt | cut -d'.' -f1 | cut -d'_' -f7`
        if (${epic_new} == "PN") then
          echo " PN QUADRANT: ${ccd_n}"
        else
         if (${epic_fin} == "S1") then
          set epic_new = "M1" 
          echo " MOS1 CCD: ${ccd_n}"
         endif
         if (${epic_fin} == "S2") then
          set epic_new = "M2" 
          echo " MOS2 CCD: ${ccd_n}"
         endif
        endif
        echo "WARNING: the event file ${evt} is empty after filtering"
        echo "Skipping the analysis of the event file ${evt} with xtfbs.py task..."
        set ctrl_expo = 1
       else
       set epic_new = `echo $evt | cut -c 9-10`
       set epic_fin = `echo $evt | cut -c 11-12`
       set epic = `echo $evt | cut -c 9-12`
       set type = `echo $evt | cut -c 14-17`
       set base_name_evt = `echo $evt | cut -d'.' -f1`
       set ccd_n = `echo $evt | cut -d'.' -f1 | cut -d'_' -f7`
       set mask="${filter_dir}/${epic}200_12000_${type}_${ccd_n}.mask"
       if (${epic_new} == "PN") then
         echo " PN QUADRANT: ${ccd_n}"
       else
        if (${epic_fin} == "S1") then
         set epic_new = "M1" 
         echo " MOS1 CCD: ${ccd_n}"
        endif
        if (${epic_fin} == "S2") then
         set epic_new = "M2" 
         echo " MOS2 CCD: ${ccd_n}"
        endif
       endif
       set nband_tot = 8000
       set expo_expo0="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband_tot}.FTZ"
       if ( -e ${expo_expo0} ) then
       echo "Starting to perform the analysis..."
          set filtered=$evt
          set emin=`echo $filtered | grep "$type" | cut -d'_' -f3 | cut -d' ' -f1`
          set emax=`echo $filtered | grep "$type" | cut -d'_' -f4 | cut -d' ' -f1`
          set nband_baye = `cat $result_dir/$dir0/energy_band_bayesian.txt | wc -l`
          if ($emin == 200 && $emax == 12000) then
            echo "ENERGY BAND (eV): ${emin} - ${emax}"
            set nband = 8000
            set expo_expo0="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband}.FTZ"
            set expo_mask1="${dir0}${epic_new}${type}EXPMAP_1.fits"
            set expo_mask="${dir0}${epic_new}${type}EXPMAP_1_${ccd_n}.fits"
            if (-e $expo_expo0) then
             if (-e $expo_mask) then
              echo "$expo_mask already done"
              set ctrl_expo = 1
             else
              gunzip -c $expo_expo0 > $expo_mask1
              if (-e $expo_mask1) then
               ftimgcalc a=A=${expo_mask1} b=B=${mask} expr="(A * B)" outfile=${expo_mask}
              endif
              set ctrl_expo = 1
             endif
            else
             echo "WARNING: ${expo_expo0} does not exist !"
             set ctrl_expo = 0
            endif
          endif
          if ($emin == 500 && $emax == 2000) then
            echo "ENERGY BAND (eV): ${emin} - ${emax}"
            set nband1 = 2000
            set nband2 = 3000
            set expo_expo1="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband1}.FTZ"
            set expo_expo2="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband2}.FTZ"
            set expo_expo1new="P${dir0}${epic_new}${type}EXPMAP${nband1}.fits"
            set expo_expo2new="P${dir0}${epic_new}${type}EXPMAP${nband2}.fits"
            set expo_mask1="${dir0}${epic_new}${type}EXPMAP_2.fits"
            set expo_mask="${dir0}${epic_new}${type}EXPMAP_2_${ccd_n}.fits"
            if (-e $expo_expo1 && -e $expo_expo2) then
             if (-e $expo_mask) then
              echo "$expo_mask already done"
              set ctrl_expo = 1
             else
              gunzip -c $expo_expo1 > $expo_expo1new
              gunzip -c $expo_expo2 > $expo_expo2new
              echo "imweightadd imagesets=' ${expo_expo1new} ${expo_expo2new} ' outimageset=${expo_mask1} tempset=temporary.fits withweights=no -w "$warn" -V "$verb"" > imweightadd.csh
              source imweightadd.csh
              rm imweightadd.csh
              rm $expo_expo1new
              rm $expo_expo2new
              if (-e $expo_mask1) then
               ftimgcalc a=A=${expo_mask1} b=B=${mask} expr="(A * B)" outfile=${expo_mask}
              endif
              set ctrl_expo = 1
             endif
            else
             echo "WARNING: ${expo_expo1} and ${expo_expo2} do not exist !"
             set ctrl_expo = 0
            endif
          endif
          if ($emin == 2000 && $emax == 10000) then
            echo "ENERGY BAND (eV): ${emin} - ${emax}"
            set nband = 4000
            set expo_expo3="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband}.FTZ"
            set expo_mask1="${dir0}${epic_new}${type}EXPMAP_3.fits"
            set expo_mask="${dir0}${epic_new}${type}EXPMAP_3_${ccd_n}.fits"
            if (-e $expo_expo3) then
             if (-e $expo_mask) then
              echo "$expo_mask already done"
              set ctrl_expo = 1
             else
              gunzip -c $expo_expo3 > $expo_mask1
              if (-e $expo_mask1) then
               ftimgcalc a=A=${expo_mask1} b=B=${mask} expr="(A * B)" outfile=${expo_mask}
              endif
              set ctrl_expo = 1
             endif
            else
             echo "WARNING: ${expo_expo3} does not exist !"
             set ctrl_expo = 0
            endif
          endif

          if ($ctrl_expo == 1) then 
           echo "Starting to perform the analysis on $filtered event file cheesed with 3XMM catalog and on exposure map $expo_mask"
           if ($ambient == "cluster") then
            echo "#\!/bin/bash" > ${filter_dir_closetosrc}/xtfbs.csh
            echo "/usr/bin/time -p xtfbs.py -t ${sftb} -s ${stss} -m ${msz} -e ${filter_dir_closetosrc}/${filtered} -x ${filter_dir_closetosrc}/${expo_mask} -v ${info}" >> ${filter_dir_closetosrc}/xtfbs.csh
            chmod 755 ${filter_dir_closetosrc}/xtfbs.csh
            source ${filter_dir_closetosrc}/xtfbs.csh 
            rm ${filter_dir_closetosrc}/xtfbs.csh
           endif
           if ($ambient == "mac") then
            echo "/usr/bin/time -p xtfbs.py -t ${sftb} -s ${stss} -m ${msz} -e ${filter_dir_closetosrc}/${filtered} -x ${filter_dir_closetosrc}/${expo_mask} -v ${info}" > ${filter_dir_closetosrc}/xtfbs.csh
            source ${filter_dir_closetosrc}/xtfbs.csh
            rm ${filter_dir_closetosrc}/xtfbs.csh
           endif
           if (-e ${base_name_evt}_unique.txt) then
            cp ${base_name_evt}_unique.txt ${base_name_evt}_unique_res.txt
            rm ${base_name_evt}_unique.txt 
           endif
          else
           echo "WARNING: exposure maps $expo_expo0 $expo_expo1 $expo_expo2 $expo_expo3 do not exist or the event file ${evt} is empty !"
          endif
       else
        echo "WARNING: ${expo_expo0} does not exist. No PPS exposure maps are ready to use !"
        set ctrl_expo = 0
       endif
       endif
      end
  endif
 endif
endif
cd $start_dir/

if ($type_baye_cat2 == "3xmm") then
 if ($ctrl_expo == 1) then 
  if ($outtosrc == "yes") then
   echo "OUT TO SRC (3XMM) time bins check..."
   set check_bayesian_3xmm=`ls ${filter_dir}/filtered*_res.txt`
   set N_check_bayesian_3xmm=`cat ${check_bayesian_3xmm} | sed -e "s/#RA Dec Tstart Tstop Probability/ /g" | sed 's/^ *//; s/ *$//; /^$/d' | wc -l | awk '{print $0}'`
   if ($N_check_bayesian_3xmm != 0) then
    echo "OUT TO SRC: there are ${N_check_bayesian_3xmm} time bins found with 3XMM analysis for the observation ${dir0}"
    set ba = 1
    while($ba <= $N_check_bayesian_3xmm)
     set baye_start=`cat ${check_bayesian_3xmm} | sed -e "s/#RA Dec Tstart Tstop Probability/ /g" | sed 's/^ *//; s/ *$//; /^$/d' | awk -v nr=$ba '{ if (NR==nr) print $3}'`
     set baye_stop=`cat ${check_bayesian_3xmm} | sed -e "s/#RA Dec Tstart Tstop Probability/ /g" | sed 's/^ *//; s/ *$//; /^$/d' | awk -v nr=$ba '{ if (NR==nr) print $4}'` 
     set baye_delta=`echo $baye_stop $baye_start | awk '{print int($1-$2)}'`
     if ($baye_delta <= $bayesian_max1) then
      echo ${baye_start} >> $filter_dir/"$dir0"_start_bin_3xmm_deg.txt
      echo ${baye_stop} >> $filter_dir/"$dir0"_stop_bin_3xmm_deg.txt
      echo ${baye_start} >> $filter_dir/"$dir0"_start_bin_3xmm_orig.txt
      echo ${baye_stop} >> $filter_dir/"$dir0"_stop_bin_3xmm_orig.txt
      echo "OK: $baye_delta sec (tstop-tstart) < $bayesian_max1 (threshold)"
    # set test_bayesian_3xmm = 1
     else
      echo "WARNING: $baye_delta sec (tstop-tstart) > $bayesian_max1 (threshold)"
      echo "${baye_start} ${baye_stop} ${baye_delta}" >> $filter_dir/time_bin_filtered.txt
     endif
    set ba=`expr $ba + 1`
    end
    if (-e "$filter_dir"/"$dir0"_start_bin_3xmm_deg.txt) then
     set filt_bin=`cat $filter_dir/"$dir0"_start_bin_3xmm_deg.txt | wc -l`
     echo "Starting removing tstart and tstop degeneration..."
     echo "N. of time bins before removing tstart and tstop degeneration: $filt_bin"
     paste $filter_dir/"$dir0"_start_bin_3xmm_deg.txt $filter_dir/"$dir0"_stop_bin_3xmm_deg.txt | awk '{print $1"-"$2}' > $filter_dir/TSTART_TSTOP.txt
     set N_deg = 1
     while($N_deg <= $filt_bin)
      set tstart_tstop_deg=`cat $filter_dir/TSTART_TSTOP.txt | awk -v nr=$N_deg '{ if (NR==nr) print $1}'`   
      set tstart_deg=`cat $filter_dir/TSTART_TSTOP.txt | awk -F \- -v nr=$N_deg '{ if (NR==nr) print $1}'`   
      set tstop_deg=`cat $filter_dir/TSTART_TSTOP.txt | awk -F \- -v nr=$N_deg '{ if (NR==nr) print $2}'`   
      
      set N_tstart_deg=`grep "$tstart_tstop_deg" $filter_dir/TSTART_TSTOP.txt | wc -l`
      if ($N_tstart_deg == 1) then
       echo "There is not tstart-tstop degeneration"
       echo ${tstart_deg} >> $filter_dir/"$dir0"_start_bin_3xmm.txt
       echo ${tstop_deg} >> $filter_dir/"$dir0"_stop_bin_3xmm.txt
      endif
      if ($N_tstart_deg > 1 && ${tstart_tstop_deg} != "degT") then
       echo "There is tstart-tstop degeneration"
       echo "The tstart-tstop $tstart_tstop_deg degenerates $N_tstart_deg times"
       echo ${tstart_deg} >> $filter_dir/"$dir0"_start_bin_3xmm.txt
       echo ${tstop_deg} >> $filter_dir/"$dir0"_stop_bin_3xmm.txt
       cat ${filter_dir}/TSTART_TSTOP.txt | sed -e "s/"$tstart_tstop_deg"/degT/g" > $filter_dir/deg.txt 
       cp $filter_dir/deg.txt ${filter_dir}/TSTART_TSTOP.txt
       rm $filter_dir/deg.txt
      endif
     set N_deg = `expr $N_deg + 1` 
     end
     rm ${filter_dir}/${dir0}_start_bin_3xmm_deg.txt
     rm ${filter_dir}/${dir0}_stop_bin_3xmm_deg.txt
     rm ${filter_dir}/TSTART_TSTOP.txt

     set filt_bin_notdeg=`cat $filter_dir/"$dir0"_start_bin_3xmm.txt | wc -l`
     echo "N. of time bins after removing tstart and tstop degeneration: $filt_bin_notdeg"
     echo "N. time bin < $bayesian_max1 sec: $filt_bin_notdeg"
    else
  #   set test_bayesian_3xmm = 0
     echo "N. time bin < $bayesian_max1 sec: 0"
    endif
   else
    echo "WARNING: no bayesian time bins after removing tstart and tstop degeneration with the out to src analysis for the observation $dir0" >> $prod_dir_final/NO_TRANSIENT_OUT_TO_SRC.txt
    echo "The 3XMM bayesian analysis does not find anything for the observation ${dir0} : there are not time bins"
    echo "The 3XMM bayesian analysis does not find anything for the observation ${dir0} : there are not time bins" >> $log_dir/messages.log
  # set test_bayesian_3xmm = 0
   endif
   mkdir ${filter_dir}/3xmm_bin
   mv ${filter_dir}/filtered*.txt ${filter_dir}/3xmm_bin
   mv ${filter_dir}/filtered*.reg ${filter_dir}/3xmm_bin
   mv ${filter_dir}/filtered*.html ${filter_dir}/3xmm_bin
   mv ${filter_dir}/filtered*_3xmm*.ds ${filter_dir}/3xmm_bin
   mv ${filter_dir}/${dir0}*EXPMAP_*_cheese_*.fits ${filter_dir}/3xmm_bin
  endif

  if ($closetosrc == "yes") then
   echo "CLOSE TO SRC (3XMM) time bins check..."
   set check_bayesian_3xmm=`ls ${filter_dir_closetosrc}/filtered*_unique_res.txt`
   set N_check_bayesian_3xmm=`cat ${check_bayesian_3xmm} | sed -e "s/#RA Dec Tstart Tstop Probability/ /g" | sed 's/^ *//; s/ *$//; /^$/d' | wc -l | awk '{print $0}'`
   if ($N_check_bayesian_3xmm != 0) then
    echo "CLOSE TO SRC: there are ${N_check_bayesian_3xmm} time bins found with 3XMM analysis for the observation ${dir0}"
    set ba = 1
    while($ba <= $N_check_bayesian_3xmm)
     set baye_start=`cat ${check_bayesian_3xmm} | sed -e "s/#RA Dec Tstart Tstop Probability/ /g" | sed 's/^ *//; s/ *$//; /^$/d' | awk -v nr=$ba '{ if (NR==nr) print $3}'`
     set baye_stop=`cat ${check_bayesian_3xmm} | sed -e "s/#RA Dec Tstart Tstop Probability/ /g" | sed 's/^ *//; s/ *$//; /^$/d' | awk -v nr=$ba '{ if (NR==nr) print $4}'` 
     set baye_delta=`echo $baye_stop $baye_start | awk '{print int($1-$2)}'`
     if ($baye_delta <= $bayesian_max2) then
      echo ${baye_start} >> $filter_dir_closetosrc/"$dir0"_start_bin_3xmm_deg.txt
      echo ${baye_stop} >> $filter_dir_closetosrc/"$dir0"_stop_bin_3xmm_deg.txt
      echo ${baye_start} >> $filter_dir_closetosrc/"$dir0"_start_bin_3xmm_orig.txt
      echo ${baye_stop} >> $filter_dir_closetosrc/"$dir0"_stop_bin_3xmm_orig.txt
      echo "OK: $baye_delta sec (tstop-tstart) < $bayesian_max2 (threshold)"
    # set test_bayesian_3xmm = 1
     else
      echo "WARNING: $baye_delta sec (tstop-tstart) > $bayesian_max2 (threshold)"
      echo "${baye_start} ${baye_stop} ${baye_delta}" >> $filter_dir_closetosrc/time_bin_filtered.txt
     endif
    set ba=`expr $ba + 1`
    end
    if (-e "$filter_dir_closetosrc"/"$dir0"_start_bin_3xmm_deg.txt) then
     set filt_bin=`cat $filter_dir_closetosrc/"$dir0"_start_bin_3xmm_deg.txt | wc -l`
     echo "Starting removing tstart and tstop degeneration..."
     echo "N. of time bins before removing tstart and tstop degeneration: $filt_bin"
     paste $filter_dir_closetosrc/"$dir0"_start_bin_3xmm_deg.txt $filter_dir_closetosrc/"$dir0"_stop_bin_3xmm_deg.txt | awk '{print $1"-"$2}' > $filter_dir_closetosrc/TSTART_TSTOP.txt
     set N_deg = 1
     while($N_deg <= $filt_bin)
      set tstart_tstop_deg=`cat $filter_dir_closetosrc/TSTART_TSTOP.txt | awk -v nr=$N_deg '{ if (NR==nr) print $1}'`   
      set tstart_deg=`cat $filter_dir_closetosrc/TSTART_TSTOP.txt | awk -F \- -v nr=$N_deg '{ if (NR==nr) print $1}'`   
      set tstop_deg=`cat $filter_dir_closetosrc/TSTART_TSTOP.txt | awk -F \- -v nr=$N_deg '{ if (NR==nr) print $2}'`   
      
      set N_tstart_deg=`grep "$tstart_tstop_deg" $filter_dir_closetosrc/TSTART_TSTOP.txt | wc -l`
      if ($N_tstart_deg == 1) then
       echo "There is not tstart-tstop degeneration"
       echo ${tstart_deg} >> $filter_dir_closetosrc/"$dir0"_start_bin_3xmm.txt
       echo ${tstop_deg} >> $filter_dir_closetosrc/"$dir0"_stop_bin_3xmm.txt
      endif
      if ($N_tstart_deg > 1 && ${tstart_tstop_deg} != "degT") then
       echo "There is tstart-tstop degeneration"
       echo "The tstart-tstop $tstart_tstop_deg degenerates $N_tstart_deg times"
       echo ${tstart_deg} >> $filter_dir_closetosrc/"$dir0"_start_bin_3xmm.txt
       echo ${tstop_deg} >> $filter_dir_closetosrc/"$dir0"_stop_bin_3xmm.txt
       cat ${filter_dir_closetosrc}/TSTART_TSTOP.txt | sed -e "s/"$tstart_tstop_deg"/degT/g" > $filter_dir_closetosrc/deg.txt 
       cp $filter_dir_closetosrc/deg.txt ${filter_dir_closetosrc}/TSTART_TSTOP.txt
       rm $filter_dir_closetosrc/deg.txt
      endif
     set N_deg = `expr $N_deg + 1` 
     end
     rm ${filter_dir_closetosrc}/${dir0}_start_bin_3xmm_deg.txt
     rm ${filter_dir_closetosrc}/${dir0}_stop_bin_3xmm_deg.txt
     rm ${filter_dir_closetosrc}/TSTART_TSTOP.txt

     set filt_bin_notdeg=`cat $filter_dir_closetosrc/"$dir0"_start_bin_3xmm.txt | wc -l`
     echo "N. of time bins after removing tstart and tstop degeneration: $filt_bin_notdeg"
     echo "N. time bin < $bayesian_max2 sec: $filt_bin_notdeg"
    else
    # set test_bayesian_3xmm = 0
     echo "N. time bin < $bayesian_max2 sec: 0"
    endif
   else
    echo "WARNING: no bayesian time bins after removing tstart and tstop degeneration with the close to src analysis for the observation $dir0" >> $prod_dir_final/NO_TRANSIENT_CLOSE_TO_SRC.txt
    echo "The 3XMM analysis does not find anything for the observation ${dir0} : there are not time bins"
    echo "The 3XMM analysis does not find anything for the observation ${dir0} : there are not time bins" >> $log_dir/messages.log
  # set test_bayesian_3xmm = 0
   endif
   mkdir ${filter_dir_closetosrc}/3xmm_bin
   mv ${filter_dir_closetosrc}/filtered*.txt ${filter_dir_closetosrc}/3xmm_bin
   mv ${filter_dir_closetosrc}/filtered*.png ${filter_dir_closetosrc}/3xmm_bin
   mv ${filter_dir_closetosrc}/filtered*_3xmm*.ds ${filter_dir_closetosrc}/3xmm_bin
   mv ${filter_dir_closetosrc}/*PSF*.fits ${filter_dir_closetosrc}/3xmm_bin
   mv ${filter_dir_closetosrc}/${dir0}*EXPMAP_*_cheese_*.fits ${filter_dir_closetosrc}/3xmm_bin
  endif

  if ($outtosrc == "yes" && $closetosrc == "no") then
   if (-e $filter_dir/"$dir0"_start_bin_3xmm.txt) then
    set test_bayesian_3xmm = 1
    echo "OK: $filter_dir/"$dir0"_start_bin_3xmm.txt and $filter_dir/"$dir0"_stop_bin_3xmm.txt are already in $filter_dir"
   else
    set test_bayesian_3xmm = 0
   endif
  endif
  if ($outtosrc == "no" && $closetosrc == "yes") then
   if (-e $filter_dir_closetosrc/"$dir0"_start_bin_3xmm.txt) then
    set test_bayesian_3xmm = 1
    mkdir ${filter_dir}/3xmm_bin
    cp ${filter_dir_closetosrc}/3xmm_bin/filtered*_unique_res.txt $filter_dir/3xmm_bin
    cp $filter_dir_closetosrc/"$dir0"_start_bin_3xmm.txt $filter_dir 
    cp $filter_dir_closetosrc/"$dir0"_stop_bin_3xmm.txt $filter_dir
    echo "OK: $filter_dir_closetosrc/"$dir0"_start_bin_3xmm.txt and $filter_dir_closetosrc/"$dir0"_stop_bin_3xmm.txt are copied in $filter_dir"
   else
    set test_bayesian_3xmm = 0
   endif
  endif
  if ($outtosrc == "yes" && $closetosrc == "yes") then
   if (-e $filter_dir_closetosrc/"$dir0"_start_bin_3xmm.txt) then
    set test_bayesian_3xmm_closetosrc = 1
    cd $filter_dir_closetosrc/
    cat "$dir0"_start_bin_3xmm.txt >> $filter_dir/"$dir0"_start_bin_3xmm.txt 
    cat "$dir0"_stop_bin_3xmm.txt >> $filter_dir/"$dir0"_stop_bin_3xmm.txt
    cp ${filter_dir_closetosrc}/3xmm_bin/filtered*_unique_res.txt $filter_dir/3xmm_bin
    echo "OK: $filter_dir_closetosrc/"$dir0"_start_bin_3xmm.txt and $filter_dir_closetosrc/"$dir0"_stop_bin_3xmm.txt are copied in $filter_dir/"$dir0"_start_bin_3xmm.txt and $filter_dir/"$dir0"_stop_bin_3xmm.txt respectively"
    cd $filter_dir/
   else
    set test_bayesian_3xmm_closetosrc = 0
   endif
   if (-e $filter_dir/"$dir0"_start_bin_3xmm.txt) then
    set test_bayesian_3xmm_outtosrc = 1
   else
    set test_bayesian_3xmm_outtosrc = 0
   endif
   if ($test_bayesian_3xmm_closetosrc == 1 || $test_bayesian_3xmm_outtosrc == 1) then
    set test_bayesian_3xmm = 1
   else
    set test_bayesian_3xmm = 0
   endif
  endif
 else
  echo "WARNING: no exposure maps are present in PPS/"
  set test_bayesian_3xmm = 0
 endif
endif

if ($type_baye_cat2 == "3xmm") then
 if (-e $filter_dir/"$dir0"_start_bin_3xmm.txt) then
  set ctrl_filt_bin=`cat $filter_dir/"$dir0"_start_bin_3xmm.txt | wc -l`
  if ($ctrl_filt_bin <= $baye_n_bin_max) then
   echo "WARNING: N. of bayesian time bins after removing tstart and tstop degeneration is ${ctrl_filt_bin}"
   echo "WARNING: maximum N. of bayesian time bins is ${baye_n_bin_max}"
   if ($ctrl_filt_bin != 0) then
    echo "WARNING: Starting to perform the single bayesian time bins analysis..."
   endif
   set ctrl_filt_bin_good = "yes"
   if ($ctrl_filt_bin == 0) then
    echo "WARNING: no bayesian time bins after removing tstart and tstop degeneration, no transients are detected for the observation $dir0" >> $prod_dir_final/NO_TRANSIENT.txt
    echo "WARNING: no bayesian time bins after removing tstart and tstop degeneration, no transients are detected for the observation $dir0" 
    set ctrl_filt_bin_good = "no"
   endif
  else
   echo "WARNING: N. of bayesian time bins after removing tstart and tstop degeneration is ${ctrl_filt_bin}"
   echo "WARNING: maximum N. of bayesian time bins is ${baye_n_bin_max}"
   echo "WARNING: Skipping single bayesian time bins analysis of the obs ${dir0}..."
   echo "${dir0}" >> $log_dir/observations_skiped.log 
   echo "WARNING: bayesian time bins number higer than time bins limit, no transients are detected for the observation $dir0" >> $prod_dir_final/NO_TRANSIENT.txt
   set ctrl_filt_bin_good = "no"
  endif
 endif
endif

set ctrl_expo = 0
if ($type_baye_cat1 == "full") then
 if ($outtosrc == "yes") then
   cp $xmmdac_dir/xtdac.py $filter_dir/
   chmod 755 $filter_dir/xtdac.py
   cp $xmmdac_dir/xtcheesemask.py $filter_dir/
   chmod 755 $filter_dir/xtcheesemask.py
   cp $xmmdac_dir/xtfixtimestamps.py $filter_dir/
   chmod 755 $filter_dir/xtfixtimestamps.py
   set list_evt="list_evt_filtered_baye_cheese.txt"
 endif
 if ($closetosrc == "yes") then
   cp $xmmdac_dir/xtfbs.py $filter_dir_closetosrc/
   chmod 755 $filter_dir_closetosrc/xtfbs.py
   set list_evt="list_evt_filtered_baye_cheese.txt"
 endif

 if ($outtosrc == "yes") then
  cd $filter_dir/
  set ctrl = `wc $filter_dir/$list_evt | awk '{print $1}'`
  if ( $ctrl == 0) then
      echo "============================================================"
      echo "FATAL ERROR: no events files in $filter_dir"
      echo "============================================================"
      echo "FATAL ERROR: no events files in $filter_dir" >> $log_dir/messages.log
      break
  else
      echo ""
      echo "******************************"
      echo "* OUT TO SRC ANALYSIS (FULL) *"
      echo "******************************"
      echo ""
      foreach evt (`cat $filter_dir/$list_evt`)
       fkeypar ${evt}+1 NAXIS2
       set evt_rows = `pget fkeypar.par value`
       if (${evt_rows} == 0) then
        set base_name_evt = `echo $evt | cut -d'.' -f1`
        echo "#RA Dec Tstart Tstop Probability" > ${base_name_evt}_res.txt
        set epic_new = `echo $evt | cut -c 9-10`
        set epic_fin = `echo $evt | cut -c 11-12`
        set epic = `echo $evt | cut -c 9-12`
        set type = `echo $evt | cut -c 14-17`
        set ccd_n = `echo $evt | cut -d'.' -f1 | cut -d'_' -f6`
        if (${epic_new} == "PN") then
          echo " PN QUADRANT: ${ccd_n}"
        else
         if (${epic_fin} == "S1") then
          set epic_new = "M1" 
          echo " MOS1 CCD: ${ccd_n}"
         endif
         if (${epic_fin} == "S2") then
          set epic_new = "M2" 
          echo " MOS2 CCD: ${ccd_n}"
         endif
        endif
        echo "WARNING: the event file ${evt} is empty after filtering"
        echo "Skipping the analysis of the event file ${evt} with xtdac.py task..."
        set ctrl_expo = 1
       else
       set ctrl_PNexpo_cheese1 = 0 
       set ctrl_PNexpo_cheese2 = 0
       set ctrl_PNexpo_cheese3 = 0
       set ctrl_M1expo_cheese1 = 0
       set ctrl_M1expo_cheese2 = 0
       set ctrl_M1expo_cheese3 = 0
       set ctrl_M2expo_cheese1 = 0
       set ctrl_M2expo_cheese2 = 0
       set ctrl_M2expo_cheese3 = 0
       set epic_new = `echo $evt | cut -c 9-10`
       set epic_fin = `echo $evt | cut -c 11-12`
       set epic = `echo $evt | cut -c 9-12`
       set type = `echo $evt | cut -c 14-17`
       set base_name_evt = `echo $evt | cut -d'.' -f1`
       set ccd_n = `echo $evt | cut -d'.' -f1 | cut -d'_' -f6`
       set mask="${filter_dir}/${epic}200_12000_${type}_${ccd_n}.mask"
       if (${epic_new} == "PN") then
        echo " PN QUADRANT: ${ccd_n}"
       else
        if (${epic_fin} == "S1") then
         set epic_new = "M1" 
         echo " MOS1 CCD: ${ccd_n}"
        endif
        if (${epic_fin} == "S2") then
         set epic_new = "M2" 
         echo " MOS2 CCD: ${ccd_n}"
        endif
       endif
       set nband_tot = 8000
       set expo_expo0="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband_tot}.FTZ"
       if ( -e ${expo_expo0} ) then
          echo "Starting to perform the bayesian blocks analysis..."
          set filtered=$evt
          set emin=`echo $filtered | grep "$type" | cut -d'_' -f3 | cut -d' ' -f1`
          set emax=`echo $filtered | grep "$type" | cut -d'_' -f4 | cut -d' ' -f1`
          set nband_baye = `cat $result_dir/$dir0/energy_band_bayesian.txt | wc -l`
          if ($emin == 200 && $emax == 12000) then
            echo "ENERGY BAND (eV): ${emin} - ${emax}"
            set nband = 8000
            set expo_expo0="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband}.FTZ"
            set expo_mask1="${dir0}${epic_new}${type}EXPMAP_1.fits"
            set expo_mask="${dir0}${epic_new}${type}EXPMAP_1_${ccd_n}.fits"
            set expo_mask_cheese="${dir0}${epic_new}${type}EXPMAP_1_cheese_${ccd_n}.fits"
            if (-e $expo_expo0) then
             if (-e $expo_mask) then
              echo "$expo_mask already done"
              set ctrl_expo = 1
             else
              gunzip -c $expo_expo0 > $expo_mask1
              if (-e $expo_mask1) then
               ftimgcalc a=A=${expo_mask1} b=B=${mask} expr="(A * B)" outfile=${expo_mask}
              endif
              set ctrl_expo = 1
             endif
            else
             echo "WARNING: ${expo_expo0} does not exist !"
             set ctrl_expo = 0
            endif
             if ($epic_new == "PN" && $ctrl_PNexpo_cheese1 == 0) then
             if ( -e ${expo_expo0}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for pn instrument..."
              set ctrl_PNexpo_cheese1 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
             if ($epic_new == "M1" && $ctrl_M1expo_cheese1 == 0) then
             if ( -e ${expo_expo0}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for MOS1 instrument..."
              set ctrl_M1expo_cheese1 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
             if ($epic_new == "M2" && $ctrl_M2expo_cheese1 == 0) then
             if ( -e ${expo_expo0}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for MOS2 instrument..."
              set ctrl_M2expo_cheese1 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
          endif
          if ($emin == 500 && $emax == 2000) then
            echo "ENERGY BAND (eV): ${emin} - ${emax}"
            set nband1 = 2000
            set nband2 = 3000
            set expo_expo1="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband1}.FTZ"
            set expo_expo2="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband2}.FTZ"
            set expo_expo1new="P${dir0}${epic_new}${type}EXPMAP${nband1}.fits"
            set expo_expo2new="P${dir0}${epic_new}${type}EXPMAP${nband2}.fits"
            set expo_mask1="${dir0}${epic_new}${type}EXPMAP_2.fits"
            set expo_mask="${dir0}${epic_new}${type}EXPMAP_2_${ccd_n}.fits"
            set expo_mask_cheese="${dir0}${epic_new}${type}EXPMAP_2_cheese_${ccd_n}.fits"
            if (-e $expo_expo1 && -e $expo_expo2) then
             if (-e $expo_mask) then
              echo "$expo_mask already done"
              set ctrl_expo = 1
             else
              gunzip -c $expo_expo1 > $expo_expo1new
              gunzip -c $expo_expo2 > $expo_expo2new
              echo "imweightadd imagesets=' ${expo_expo1new} ${expo_expo2new} ' outimageset=${expo_mask1} tempset=temporary.fits withweights=no -w "$warn" -V "$verb"" > imweightadd.csh
              source imweightadd.csh
              rm imweightadd.csh
              rm $expo_expo1new
              rm $expo_expo2new
              if (-e $expo_mask1) then
               ftimgcalc a=A=${expo_mask1} b=B=${mask} expr="(A * B)" outfile=${expo_mask}
              endif
              set ctrl_expo = 1
             endif
            else
             echo "WARNING: ${expo_expo1} and ${expo_expo2} do not exist !"
             set ctrl_expo = 0
            endif
             if ($epic_new == "PN" && $ctrl_PNexpo_cheese2 == 0) then
             if ( -e ${expo_expo1} && -e ${expo_expo2}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for pn instrument..."
              set ctrl_PNexpo_cheese2 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
             if ($epic_new == "M1" && $ctrl_M1expo_cheese2 == 0) then
             if ( -e ${expo_expo1} && -e ${expo_expo2}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for MOS1 instrument..."
              set ctrl_M1expo_cheese2 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
             if ($epic_new == "M2" && $ctrl_M2expo_cheese2 == 0) then
             if ( -e ${expo_expo1} && -e ${expo_expo2}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for MOS2 instrument..."
              set ctrl_M2expo_cheese2 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
          endif
          if ($emin == 2000 && $emax == 10000) then
            echo "ENERGY BAND (eV): ${emin} - ${emax}"
            set nband = 4000
            set expo_expo3="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband}.FTZ"
            set expo_mask1="${dir0}${epic_new}${type}EXPMAP_3.fits"
            set expo_mask="${dir0}${epic_new}${type}EXPMAP_3_${ccd_n}.fits"
            set expo_mask_cheese="${dir0}${epic_new}${type}EXPMAP_3_cheese_${ccd_n}.fits"
            if (-e $expo_expo3) then
             if (-e $expo_mask) then
              echo "$expo_mask already done"
              set ctrl_expo = 1
             else
              gunzip -c $expo_expo3 > $expo_mask1
              if (-e $expo_mask1) then
               ftimgcalc a=A=${expo_mask1} b=B=${mask} expr="(A * B)" outfile=${expo_mask}
              endif
              set ctrl_expo = 1
             endif
            else
             echo "WARNING: ${expo_expo3} does not exist !"
             set ctrl_expo = 0
            endif
             if ($epic_new == "PN" && $ctrl_PNexpo_cheese3 == 0) then
             if ( -e ${expo_expo3}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for pn instrument..."
              set ctrl_PNexpo_cheese3 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
             if ($epic_new == "M1" && $ctrl_M1expo_cheese3 == 0) then
             if ( -e ${expo_expo3}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for MOS1 instrument..."
              set ctrl_M1expo_cheese3 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
             if ($epic_new == "M2" && $ctrl_M2expo_cheese3 == 0) then
             if ( -e ${expo_expo3}) then
              echo "Making exposure map cheesed in the energy band $emin - $emax eV for MOS2 instrument..."
              set ctrl_M2expo_cheese3 = 1
              if ($ambient == "cluster") then
               echo "#\!/bin/bash" > ${filter_dir}/xtcheesemask.csh
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" >> ${filter_dir}/xtcheesemask.csh
               chmod 755 ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
              if ($ambient == "mac") then
               echo "/usr/bin/time -p xtcheesemask.py -i $expo_mask --no-reverse -r ${filtered} -o $expo_mask_cheese -v $info" > ${filter_dir}/xtcheesemask.csh
               source ${filter_dir}/xtcheesemask.csh
               rm ${filter_dir}/xtcheesemask.csh
              endif
             endif
             endif
          endif

          if ($ctrl_expo == 1) then 
           echo "Starting to perform the bayesian blocks analysis on $filtered event file cheesed with FULL catalog and on exposure map $expo_mask_cheese"
           if ($ambient == "cluster") then
            echo "#\!/bin/bash" > ${filter_dir}/xtdac.csh
            echo "/usr/bin/time -p python xtfixtimestamps.py --eventfile ${filter_dir}/${filtered} --verbosity $info" >> ${filter_dir}/xtdac.csh
            echo "/usr/bin/time -p python xtdac.py --eventfile ${filter_dir}/${filtered} -x $expo_mask_cheese --ncpus $ncpu --typeIerror $Ierror -s $stss_out --regionsize $regionsize -m $multiplicity --writeRegionFiles $writeReg --verbosity $info --no-html" >> ${filter_dir}/xtdac.csh
            chmod 755 ${filter_dir}/xtdac.csh
            source ${filter_dir}/xtdac.csh 
            rm ${filter_dir}/xtdac.csh
           endif
           if ($ambient == "mac") then
            echo "/usr/bin/time -p python xtfixtimestamps.py --eventfile ${filter_dir}/${filtered} --verbosity $info" >> ${filter_dir}/xtdac.csh
            echo "/usr/bin/time -p python xtdac.py --eventfile ${filter_dir}/${filtered} -x $expo_mask_cheese --ncpus $ncpu --typeIerror $Ierror -s $stss_out --regionsize $regionsize -m $multiplicity --writeRegionFiles $writeReg --verbosity $info --no-html" >> ${filter_dir}/xtdac.csh
            source ${filter_dir}/xtdac.csh
            rm ${filter_dir}/xtdac.csh
           endif
          else
           echo "WARNING: PPS exposure maps do not exist or the event file ${evt} is empty !"
          endif
       else
        echo "WARNING: ${expo_expo0} does not exist. No PPS exposure maps are ready to use !"
        set ctrl_expo = 0
       endif
       endif
      end
  endif
 endif
 if ($closetosrc == "yes") then
  cd $filter_dir_closetosrc/
  set ctrl = `wc $filter_dir_closetosrc/$list_evt | awk '{print $1}'`
  if ( $ctrl == 0) then
      echo "============================================================"
      echo "FATAL ERROR: no events files in $filter_dir_closetosrc"
      echo "============================================================"
      echo "FATAL ERROR: no events files in $filter_dir_closetosrc" >> $log_dir/messages.log
      break
  else
      echo ""
      echo "********************************"
      echo "* CLOSE TO SRC ANALYSIS (FULL) *"
      echo "********************************"
      echo ""
      foreach evt (`cat $filter_dir_closetosrc/$list_evt`)
       fkeypar ${evt}+1 NAXIS2
       set evt_rows = `pget fkeypar.par value`
       if (${evt_rows} == 0) then
        set base_name_evt = `echo $evt | cut -d'.' -f1`
        echo "#RA Dec Tstart Tstop Probability" > ${base_name_evt}_unique_res.txt
        set epic_new = `echo $evt | cut -c 9-10`
        set epic_fin = `echo $evt | cut -c 11-12`
        set epic = `echo $evt | cut -c 9-12`
        set type = `echo $evt | cut -c 14-17`
        set ccd_n = `echo $evt | cut -d'.' -f1 | cut -d'_' -f6`
        if (${epic_new} == "PN") then
          echo " PN QUADRANT: ${ccd_n}"
        else
         if (${epic_fin} == "S1") then
          set epic_new = "M1" 
          echo " MOS1 CCD: ${ccd_n}"
         endif
         if (${epic_fin} == "S2") then
          set epic_new = "M2" 
          echo " MOS2 CCD: ${ccd_n}"
         endif
        endif
        echo "WARNING: the event file ${evt} is empty after filtering"
        echo "Skipping the analysis of the event file ${evt} with xtfbs.py task..."
        set ctrl_expo = 1
       else
       set epic_new = `echo $evt | cut -c 9-10`
       set epic_fin = `echo $evt | cut -c 11-12`
       set epic = `echo $evt | cut -c 9-12`
       set type = `echo $evt | cut -c 14-17`
       set base_name_evt = `echo $evt | cut -d'.' -f1`
       set ccd_n = `echo $evt | cut -d'.' -f1 | cut -d'_' -f6`
       set mask="${filter_dir}/${epic}200_12000_${type}_${ccd_n}.mask"
       echo $mask
       if (${epic_new} == "PN") then
         echo " PN QUADRANT: ${ccd_n}"
       else
        if (${epic_fin} == "S1") then
         set epic_new = "M1" 
         echo " MOS1 CCD: ${ccd_n}"
        endif
        if (${epic_fin} == "S2") then
         set epic_new = "M2" 
         echo " MOS2 CCD: ${ccd_n}"
        endif
       endif
       set nband_tot = 8000
       set expo_expo0="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband_tot}.FTZ"
       if ( -e ${expo_expo0} ) then
       echo "Starting to perform the analysis..."
          set filtered=$evt
          set emin=`echo $filtered | grep "$type" | cut -d'_' -f3 | cut -d' ' -f1`
          set emax=`echo $filtered | grep "$type" | cut -d'_' -f4 | cut -d' ' -f1`
          set nband_baye = `cat $result_dir/$dir0/energy_band_bayesian.txt | wc -l`
          if ($emin == 200 && $emax == 12000) then
            echo "ENERGY BAND (eV): ${emin} - ${emax}"
            set nband = 8000
            set expo_expo0="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband}.FTZ"
            set expo_mask1="${dir0}${epic_new}${type}EXPMAP_1.fits"
            set expo_mask="${dir0}${epic_new}${type}EXPMAP_1_${ccd_n}.fits"
            if (-e $expo_expo0) then
             if (-e $expo_mask) then
              echo "$expo_mask already done"
              set ctrl_expo = 1
             else
              gunzip -c $expo_expo0 > $expo_mask1
              if (-e $expo_mask1) then
               ftimgcalc a=A=${expo_mask1} b=B=${mask} expr="(A * B)" outfile=${expo_mask}
              endif
              set ctrl_expo = 1
             endif
            else
             echo "WARNING: ${expo_expo0} does not exist !"
             set ctrl_expo = 0
            endif
          endif
          if ($emin == 500 && $emax == 2000) then
            echo "ENERGY BAND (eV): ${emin} - ${emax}"
            set nband1 = 2000
            set nband2 = 3000
            set expo_expo1="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband1}.FTZ"
            set expo_expo2="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband2}.FTZ"
            set expo_expo1new="P${dir0}${epic_new}${type}EXPMAP${nband1}.fits"
            set expo_expo2new="P${dir0}${epic_new}${type}EXPMAP${nband2}.fits"
            set expo_mask1="${dir0}${epic_new}${type}EXPMAP_2.fits"
            set expo_mask="${dir0}${epic_new}${type}EXPMAP_2_${ccd_n}.fits"
            if (-e $expo_expo1 && -e $expo_expo2) then
             if (-e $expo_mask) then
              echo "$expo_mask already done"
              set ctrl_expo = 1
             else
              gunzip -c $expo_expo1 > $expo_expo1new
              gunzip -c $expo_expo2 > $expo_expo2new
              echo "imweightadd imagesets=' ${expo_expo1new} ${expo_expo2new} ' outimageset=${expo_mask1} tempset=temporary.fits withweights=no -w "$warn" -V "$verb"" > imweightadd.csh
              source imweightadd.csh
              rm imweightadd.csh
              rm $expo_expo1new
              rm $expo_expo2new
              if (-e $expo_mask1) then
               ftimgcalc a=A=${expo_mask1} b=B=${mask} expr="(A * B)" outfile=${expo_mask}
              endif
              set ctrl_expo = 1
             endif
            else
             echo "WARNING: ${expo_expo1} and ${expo_expo2} do not exist !"
             set ctrl_expo = 0
            endif
          endif
          if ($emin == 2000 && $emax == 10000) then
            echo "ENERGY BAND (eV): ${emin} - ${emax}"
            set nband = 4000
            set expo_expo3="${pps_archive_dir}"/"${dir0}"/pps/"P${dir0}${epic_new}${type}EXPMAP${nband}.FTZ"
            set expo_mask1="${dir0}${epic_new}${type}EXPMAP_3.fits"
            set expo_mask="${dir0}${epic_new}${type}EXPMAP_3_${ccd_n}.fits"
            if (-e $expo_expo3) then
             if (-e $expo_mask) then
              echo "$expo_mask already done"
              set ctrl_expo = 1
             else
              gunzip -c $expo_expo3 > $expo_mask1
              if (-e $expo_mask1) then
               ftimgcalc a=A=${expo_mask1} b=B=${mask} expr="(A * B)" outfile=${expo_mask}
              endif
              set ctrl_expo = 1
             endif
            else
             echo "WARNING: ${expo_expo3} does not exist !"
             set ctrl_expo = 0
            endif
          endif

          if ($ctrl_expo == 1) then 
           echo "Starting to perform the analysis on $filtered event file cheesed with FULL catalog and on exposure map $expo_mask"
           if ($ambient == "cluster") then
            echo "#\!/bin/bash" > ${filter_dir_closetosrc}/xtfbs.csh
            echo "/usr/bin/time -p xtfbs.py -t ${sftb} -s ${stss} -m ${msz} -e ${filter_dir_closetosrc}/${filtered} -x ${filter_dir_closetosrc}/${expo_mask} -v ${info}" >> ${filter_dir_closetosrc}/xtfbs.csh
            chmod 755 ${filter_dir_closetosrc}/xtfbs.csh
            source ${filter_dir_closetosrc}/xtfbs.csh 
            rm ${filter_dir_closetosrc}/xtfbs.csh
           endif
           if ($ambient == "mac") then
            echo "/usr/bin/time -p xtfbs.py -t ${sftb} -s ${stss} -m ${msz} -e ${filter_dir_closetosrc}/${filtered} -x ${filter_dir_closetosrc}/${expo_mask} -v ${info}" > ${filter_dir_closetosrc}/xtfbs.csh
            source ${filter_dir_closetosrc}/xtfbs.csh
            rm ${filter_dir_closetosrc}/xtfbs.csh
           endif
           if (-e ${base_name_evt}_unique.txt) then
            cp ${base_name_evt}_unique.txt ${base_name_evt}_unique_res.txt
            rm ${base_name_evt}_unique.txt 
           endif
          else
           echo "WARNING: exposure maps $expo_expo0 $expo_expo1 $expo_expo2 $expo_expo3 do not exist or the event file ${evt} is empty !"
          endif
       else
        echo "WARNING: ${expo_expo0} does not exist. No PPS exposure maps are ready to use !"
        set ctrl_expo = 0
       endif
       endif
      end
  endif
 endif
endif
cd $start_dir/

if ($type_baye_cat1 == "full") then
 if ($ctrl_expo == 1) then 
  if ($outtosrc == "yes") then
   echo "OUT TO SRC (FULL) time bins check..."
   set check_bayesian=`ls ${filter_dir}/filtered*.txt`
   set N_check_bayesian=`cat ${check_bayesian} | sed -e "s/#RA Dec Tstart Tstop Probability/ /g" | sed 's/^ *//; s/ *$//; /^$/d' | wc -l | awk '{print $0}'`
   if ($N_check_bayesian != 0) then
    echo "OUT TO SRC: there are ${N_check_bayesian} time bins found with FULL analysis for the observation ${dir0}"
    set ba = 1
    while($ba <= $N_check_bayesian)
     set baye_start=`cat ${check_bayesian} | sed -e "s/#RA Dec Tstart Tstop Probability/ /g" | sed 's/^ *//; s/ *$//; /^$/d' | awk -v nr=$ba '{ if (NR==nr) print $3}'`
     set baye_stop=`cat ${check_bayesian} | sed -e "s/#RA Dec Tstart Tstop Probability/ /g" | sed 's/^ *//; s/ *$//; /^$/d' | awk -v nr=$ba '{ if (NR==nr) print $4}'` 
     set baye_delta=`echo $baye_stop $baye_start | awk '{print int($1-$2)}'`
     if ($baye_delta <= $bayesian_max1) then
      echo ${baye_start} >> $filter_dir/"$dir0"_start_bin_deg.txt
      echo ${baye_stop} >> $filter_dir/"$dir0"_stop_bin_deg.txt
      echo ${baye_start} >> $filter_dir/"$dir0"_start_bin_orig.txt
      echo ${baye_stop} >> $filter_dir/"$dir0"_stop_bin_orig.txt
      echo "OK: $baye_delta sec (tstop-tstart) < $bayesian_max1 (threshold)"
   #  set test_bayesian = 1
     else
      echo "WARNING: $baye_delta sec (tstop-tstart) > $bayesian_max1 (threshold)"
     endif
    set ba=`expr $ba + 1`
    end
    if (-e "$filter_dir"/"$dir0"_start_bin_deg.txt) then
     set filt_bin=`cat $filter_dir/"$dir0"_start_bin_deg.txt | wc -l`
     echo "Starting removing tstart and tstop degeneration..."
     echo "N. of time bins before removing tstart and tstop degeneration: $filt_bin"
     paste $filter_dir/"$dir0"_start_bin_deg.txt $filter_dir/"$dir0"_stop_bin_deg.txt | awk '{print $1"-"$2}' > $filter_dir/TSTART_TSTOP.txt
     set N_deg = 1
     while($N_deg <= $filt_bin)
      set tstart_tstop_deg=`cat $filter_dir/TSTART_TSTOP.txt | awk -v nr=$N_deg '{ if (NR==nr) print $1}'`   
      set tstart_deg=`cat $filter_dir/TSTART_TSTOP.txt | awk -F \- -v nr=$N_deg '{ if (NR==nr) print $1}'`   
      set tstop_deg=`cat $filter_dir/TSTART_TSTOP.txt | awk -F \- -v nr=$N_deg '{ if (NR==nr) print $2}'`   
      
      set N_tstart_deg=`grep "$tstart_tstop_deg" $filter_dir/TSTART_TSTOP.txt | wc -l`
      if ($N_tstart_deg == 1) then
       echo "There is not tstart-tstop degeneration"
       echo ${tstart_deg} >> $filter_dir/"$dir0"_start_bin.txt
       echo ${tstop_deg} >> $filter_dir/"$dir0"_stop_bin.txt
      endif
      if ($N_tstart_deg > 1 && ${tstart_tstop_deg} != "degT") then
       echo "There is tstart-tstop degeneration"
       echo "The tstart-tstop $tstart_tstop_deg degenerates $N_tstart_deg times"
       echo ${tstart_deg} >> $filter_dir/"$dir0"_start_bin.txt
       echo ${tstop_deg} >> $filter_dir/"$dir0"_stop_bin.txt
       cat ${filter_dir}/TSTART_TSTOP.txt | sed -e "s/"$tstart_tstop_deg"/degT/g" > $filter_dir/deg.txt 
       cp $filter_dir/deg.txt ${filter_dir}/TSTART_TSTOP.txt
       rm $filter_dir/deg.txt
      endif
     set N_deg = `expr $N_deg + 1` 
     end
     rm ${filter_dir}/${dir0}_start_bin_deg.txt
     rm ${filter_dir}/${dir0}_stop_bin_deg.txt
     rm ${filter_dir}/TSTART_TSTOP.txt

     set filt_bin_notdeg=`cat $filter_dir/"$dir0"_start_bin.txt | wc -l`
     echo "N. of time bins after removing tstart and tstop degeneration: $filt_bin_notdeg"
     echo "N. time bin < $bayesian_max1 sec: $filt_bin_notdeg"
    else
   #  set test_bayesian = 0
     echo "N. time bin < $bayesian_max1 sec: 0"
    endif
   else
    echo "WARNING: no bayesian time bins after removing tstart and tstop degeneration with the out to src analysis for the observation $dir0" >> $prod_dir_final/NO_TRANSIENT_OUT_TO_SRC.txt
    echo "The FULL analysis does not find anything for the observation ${dir0} : there are not time bins"
    echo "The FULL analysis does not find anything for the observation ${dir0} : there are not time bins" >> $log_dir/messages.log
  # set test_bayesian = 0
   endif
   mkdir ${filter_dir}/full_bin
   mv ${filter_dir}/filtered*.txt ${filter_dir}/full_bin
   mv ${filter_dir}/filtered*.reg ${filter_dir}/full_bin
   mv ${filter_dir}/filtered*.html ${filter_dir}/full_bin
   mv ${filter_dir}/filtered*.ds ${filter_dir}/full_bin
   mv ${filter_dir}/${dir0}*EXPMAP_1_cheese_*.fits ${filter_dir}/full_bin
  endif

  if ($closetosrc == "yes") then
   echo "CLOSE TO SRC (FULL) time bins check..."
   set check_bayesian=`ls ${filter_dir_closetosrc}/filtered*_unique_res.txt`
   set N_check_bayesian=`cat ${check_bayesian} | sed -e "s/#RA Dec Tstart Tstop Probability/ /g" | sed 's/^ *//; s/ *$//; /^$/d' | wc -l | awk '{print $0}'`
   if ($N_check_bayesian != 0) then
    echo "CLOSE TO SRC: there are ${N_check_bayesian} time bins found with FULL analysis for the observation ${dir0}"
    set ba = 1
    while($ba <= $N_check_bayesian)
     set baye_start=`cat ${check_bayesian} | sed -e "s/#RA Dec Tstart Tstop Probability/ /g" | sed 's/^ *//; s/ *$//; /^$/d' | awk -v nr=$ba '{ if (NR==nr) print $3}'`
     set baye_stop=`cat ${check_bayesian} | sed -e "s/#RA Dec Tstart Tstop Probability/ /g" | sed 's/^ *//; s/ *$//; /^$/d' | awk -v nr=$ba '{ if (NR==nr) print $4}'` 
     set baye_delta=`echo $baye_stop $baye_start | awk '{print int($1-$2)}'`
     if ($baye_delta <= $bayesian_max2) then
      echo ${baye_start} >> $filter_dir_closetosrc/"$dir0"_start_bin_deg.txt
      echo ${baye_stop} >> $filter_dir_closetosrc/"$dir0"_stop_bin_deg.txt
      echo ${baye_start} >> $filter_dir_closetosrc/"$dir0"_start_bin_orig.txt
      echo ${baye_stop} >> $filter_dir_closetosrc/"$dir0"_stop_bin_orig.txt
      echo "OK: $baye_delta sec (tstop-tstart) < $bayesian_max2 (threshold)"
  #   set test_bayesian = 1
     else
      echo "WARNING: $baye_delta sec (tstop-tstart) > $bayesian_max2 (threshold)"
     endif
    set ba=`expr $ba + 1`
    end
    if (-e "$filter_dir_closetosrc"/"$dir0"_start_bin_deg.txt) then
     set filt_bin=`cat $filter_dir_closetosrc/"$dir0"_start_bin_deg.txt | wc -l`
     echo "Starting removing tstart and tstop degeneration..."
     echo "N. of time bins before removing tstart and tstop degeneration: $filt_bin"
     paste $filter_dir_closetosrc/"$dir0"_start_bin_deg.txt $filter_dir_closetosrc/"$dir0"_stop_bin_deg.txt | awk '{print $1"-"$2}' > $filter_dir_closetosrc/TSTART_TSTOP.txt
     set N_deg = 1
     while($N_deg <= $filt_bin)
      set tstart_tstop_deg=`cat $filter_dir_closetosrc/TSTART_TSTOP.txt | awk -v nr=$N_deg '{ if (NR==nr) print $1}'`   
      set tstart_deg=`cat $filter_dir_closetosrc/TSTART_TSTOP.txt | awk -F \- -v nr=$N_deg '{ if (NR==nr) print $1}'`   
      set tstop_deg=`cat $filter_dir_closetosrc/TSTART_TSTOP.txt | awk -F \- -v nr=$N_deg '{ if (NR==nr) print $2}'`   
      
      set N_tstart_deg=`grep "$tstart_tstop_deg" $filter_dir_closetosrc/TSTART_TSTOP.txt | wc -l`
      if ($N_tstart_deg == 1) then
       echo "There is not tstart-tstop degeneration"
       echo ${tstart_deg} >> $filter_dir_closetosrc/"$dir0"_start_bin.txt
       echo ${tstop_deg} >> $filter_dir_closetosrc/"$dir0"_stop_bin.txt
      endif
      if ($N_tstart_deg > 1 && ${tstart_tstop_deg} != "degT") then
       echo "There is tstart-tstop degeneration"
       echo "The tstart-tstop $tstart_tstop_deg degenerates $N_tstart_deg times"
       echo ${tstart_deg} >> $filter_dir_closetosrc/"$dir0"_start_bin.txt
       echo ${tstop_deg} >> $filter_dir_closetosrc/"$dir0"_stop_bin.txt
       cat ${filter_dir_closetosrc}/TSTART_TSTOP.txt | sed -e "s/"$tstart_tstop_deg"/degT/g" > $filter_dir_closetosrc/deg.txt 
       cp $filter_dir_closetosrc/deg.txt ${filter_dir_closetosrc}/TSTART_TSTOP.txt
       rm $filter_dir_closetosrc/deg.txt
      endif
     set N_deg = `expr $N_deg + 1` 
     end
     rm ${filter_dir_closetosrc}/${dir0}_start_bin_deg.txt
     rm ${filter_dir_closetosrc}/${dir0}_stop_bin_deg.txt
     rm ${filter_dir_closetosrc}/TSTART_TSTOP.txt

     set filt_bin_notdeg=`cat $filter_dir_closetosrc/"$dir0"_start_bin.txt | wc -l`
     echo "N. of time bins after removing tstart and tstop degeneration: $filt_bin_notdeg"
     echo "N. time bin < $bayesian_max2 sec: $filt_bin_notdeg"
    else
 #    set test_bayesian = 0
     echo "N. time bin < $bayesian_max2 sec: 0"
    endif
   else
    echo "WARNING: no bayesian time bins after removing tstart and tstop degeneration with the close to src analysis for the observation $dir0" >> $prod_dir_final/NO_TRANSIENT_CLOSE_TO_SRC.txt
    echo "The FULL analysis does not find anything for the observation ${dir0} : there are not time bins"
    echo "The FULL analysis does not find anything for the observation ${dir0} : there are not time bins" >> $log_dir/messages.log
#   set test_bayesian = 0
   endif
   mkdir ${filter_dir_closetosrc}/full_bin
   mv ${filter_dir_closetosrc}/filtered*.txt ${filter_dir_closetosrc}/full_bin
   mv ${filter_dir_closetosrc}/filtered*.png ${filter_dir_closetosrc}/full_bin
   mv ${filter_dir_closetosrc}/filtered*.ds ${filter_dir_closetosrc}/full_bin
   mv ${filter_dir_closetosrc}/*PSF*.fits ${filter_dir_closetosrc}/full_bin
   mv ${filter_dir_closetosrc}/${dir0}*EXPMAP_1_cheese_*.fits ${filter_dir_closetosrc}/full_bin
  endif

  if ($outtosrc == "yes" && $closetosrc == "no") then
   if (-e $filter_dir/"$dir0"_start_bin.txt) then
    set test_bayesian = 1
    echo "OK: $filter_dir/"$dir0"_start_bin.txt and $filter_dir/"$dir0"_stop_bin.txt are already in $filter_dir"
   else
    set test_bayesian = 0
   endif
  endif
  if ($outtosrc == "no" && $closetosrc == "yes") then
   if (-e $filter_dir_closetosrc/"$dir0"_start_bin.txt) then
    set test_bayesian = 1
    mkdir ${filter_dir}/full_bin
    cp $filter_dir_closetosrc/full_bin/filtered*_unique_res.txt $filter_dir/full_bin
    cp $filter_dir_closetosrc/"$dir0"_start_bin.txt $filter_dir 
    cp $filter_dir_closetosrc/"$dir0"_stop_bin.txt $filter_dir
    echo "OK: $filter_dir_closetosrc/"$dir0"_start_bin.txt and $filter_dir_closetosrc/"$dir0"_stop_bin.txt are copied in $filter_dir"
   else
    set test_bayesian = 0
   endif
  endif
  if ($outtosrc == "yes" && $closetosrc == "yes") then
   if (-e $filter_dir_closetosrc/"$dir0"_start_bin.txt) then
    set test_bayesian_closetosrc = 1
    cd $filter_dir_closetosrc/
    cat "$dir0"_start_bin.txt >> $filter_dir/"$dir0"_start_bin.txt 
    cat "$dir0"_stop_bin.txt >> $filter_dir/"$dir0"_stop_bin.txt
    cp $filter_dir_closetosrc/full_bin/filtered*_unique_res.txt $filter_dir/full_bin
    echo "OK: $filter_dir_closetosrc/"$dir0"_start_bin.txt and $filter_dir_closetosrc/"$dir0"_stop_bin.txt are copied in $filter_dir/"$dir0"_start_bin.txt and $filter_dir/"$dir0"_stop_bin.txt respectively"
    cd $filter_dir/
   else
    set test_bayesian_closetosrc = 0
   endif
   if (-e $filter_dir/"$dir0"_start_bin.txt) then
    set test_bayesian_outtosrc = 1
   else
    set test_bayesian_outtosrc = 0
   endif
   if ($test_bayesian_closetosrc == 1 || $test_bayesian_outtosrc == 1) then
    set test_bayesian = 1
   else
    set test_bayesian = 0
   endif
  endif
 else
  echo "WARNING: no exposure maps are present in PPS/"
  set test_bayesian = 0
 endif
endif

if ($type_baye_cat1 == "full") then
 if (-e $filter_dir/"$dir0"_start_bin.txt) then
  set ctrl_filt_bin=`cat $filter_dir/"$dir0"_start_bin.txt | wc -l`
  if ($ctrl_filt_bin <= $baye_n_bin_max) then
   echo "WARNING: N. of bayesian time bins after removing tstart and tstop degeneration is ${ctrl_filt_bin}"
   echo "WARNING: maximum N. of bayesian time bins is ${baye_n_bin_max}"
   if ($ctrl_filt_bin != 0) then
    echo "WARNING: Starting to perform the single bayesian time bins analysis..."
   endif
   set ctrl_filt_bin_good = "yes"
   if ($ctrl_filt_bin == 0) then
    echo "WARNING: no bayesian time bins after removing tstart and tstop degeneration, no transients are detected for the observation $dir0" >> $prod_dir_final/NO_TRANSIENT.txt
    echo "WARNING: no bayesian time bins after removing tstart and tstop degeneration, no transients are detected for the observation $dir0" 
    set ctrl_filt_bin_good = "no"
   endif
  else
   echo "WARNING: N. of bayesian time bins after removing tstart and tstop degeneration is ${ctrl_filt_bin}"
   echo "WARNING: maximum N. of bayesian time bins is ${baye_n_bin_max}"
   echo "WARNING: Skipping single bayesian time bins analysis of the obs ${dir0}..."
   echo "${dir0}" >> $log_dir/observations_skiped.log 
   echo "WARNING: bayesian time bins number higer than time bins limit, no transients are detected for the observation $dir0" >> $prod_dir_final/NO_TRANSIENT.txt
   set ctrl_filt_bin_good = "no"
  endif
 endif
endif

cd $start_dir/
date
echo "stop bayesian_block.csh"
