#!/bin/csh -f
if ( $1 == '' ) then
  echo Syntax: presel.csh ../Log_03JUN04-crap01.dat
  exit
endif
echo Start preselection at `date`
set INFOLD=`echo $IN| cut -d/ -f1`
if ( $INFOLD == '' ) then
  set INFOLD=.
endif
set INFILE=`echo $IN| cut -d/ -f2|cut -d. -f1`
set INEXT=`echo $IN| cut -d/ -f2|cut -d. -f2`
set OUT1=$INFILE.occ
set OUT2=$INFILE.cor
echo "Scanning data..."
grep trigg $INFOLD/$INFILE.$INEXT|awk '{print $5" "$10}' > presel1.tmp
grep Col   $INFOLD/$INFILE.$INEXT|awk '{print $8" "$9}' > presel2.tmp
paste presel1.tmp presel2.tmp > $OUT1
#
echo "Extracting correlations..."
grep A $OUT1 > A.tmp
grep B $OUT1 > B.tmp
grep C $OUT1 > C.tmp
grep D $OUT1 > D.tmp
paste A.tmp B.tmp C.tmp D.tmp > $OUT2
sed -e s/A/1/ $OUT2 > presel1.tmp
sed -e s/B/2/ presel1.tmp > presel2.tmp
sed -e s/C/3/ presel2.tmp > presel1.tmp
sed -e s/D/4/ presel1.tmp > $OUT2
rm -f A.tmp B.tmp C.tmp D.tmp
#
sed -e s/A/1/ $OUT1 > presel1.tmp
sed -e s/B/2/ presel1.tmp > presel2.tmp
sed -e s/C/3/ presel2.tmp > presel1.tmp
sed -e s/D/4/ presel1.tmp > $OUT1
rm -f presel1.tmp presel2.tmp
echo "Done!"
exit
