#! /bin/csh -f

set tstart=`date`
echo "************************************"
echo "*  start timebin_standard_bin.csh  *"
echo "************************************"

cd $result_dir/
set det = $result_dir/$dir0/detection
set an_dir = $result_dir/$dir0/binT
rm $an_dir/"$dir0"_start_bin.txt
rm $an_dir/"$dir0"_stop_bin.txt

echo "OBS $dir0"

set min=`cat $an_dir/"$dir0"_ref_start.txt`
set max=`cat $an_dir/"$dir0"_ref_stop.txt`
set c=$min

echo "extract tstart and tstop"
while ( $c <= $max )
  set start=$c
  @ c = $c + $deltat
  if ($c <= $max) then
    set stop=$c
  else
    set stop=$max
  endif
  echo $start >> $an_dir/"$dir0"_start_bin.txt
  echo $stop >> $an_dir/"$dir0"_stop_bin.txt
end
if ( -e $an_dir/"$dir0"_start_bin.txt) then
  set test_bin = 1
else
  set test_bin = 0
endif
cd $result_dir/
cd $start_dir/

date
echo "stop timebin_standard_bin.csh"
