#! /bin/csh -f
#A simple script to check that all the dithers for a VIRUSP 
#detection are from the same parent field (6 dither bundle). 
#If not, a 1 is output. This is used to communicate with Niv and 
#his cure detections. The flag is output third, the first is the 
#field number set of the first element, the second is the number of 
#elements.
set scname=$0
if($#argv != 1) then
   echo Usage: $scname:t 'dither list'
   exit(1)
endif
set ind_dith = ( 0 0 0 0 0 0 )
set cnt_i = "0"
set num_elem = `echo $1 | awk -F"," '{print NF}'`
while ($cnt_i < $num_elem)
   @ cnt_i = $cnt_i + 1
   set ind_dith[$cnt_i] = `echo $1 | awk '{split($0,a,","); print a[cnt_awk]}' cnt_awk="$cnt_i"`
end
set flag_out = "0"
set dset1 = `echo "$ind_dith[1]" | awk '{print int(($1-1)/6)}'`
set cnt_i = "0"
while ($cnt_i < $num_elem)
   @ cnt_i = $cnt_i + 1
   set dset2 = `echo "$ind_dith[$cnt_i]" | awk '{print int(($1-1)/6)}'`
   set tru_test = `echo "$dset1==$dset2" | bc -l`
   if ($tru_test != 1) then
      set flag_out = "1"
      set cnt_i = $num_elem
   endif
end
@ dset1 = $dset1 + 1
echo "$dset1 $cnt_i $flag_out"
exit(0)
