#!/bin/csh

if ( $#argv < 1 ) then
 set models="*TS[1-5]"
else
 set models=($1)
endif

set nmodel = 0
foreach f1 ($models)
 set nmodel = `expr $nmodel + 1 `
 set start = `grep CA $f1 | head -1 | awk '{print substr($0,23,4)}'`
 set end = `grep CA $f1 | tail -1 | awk '{print substr($0,23,4)}'`
# echo $start $end
 foreach f2 ($models)
 if ($f1 != $f2) then
  echo -n $f1 $f2 |awk '{printf "%-32s%-32s",$1,$2}' >> all.txt
  /users2/CASP13/scripts/suppdb_ca_dis $f1 $f2 ooo_${f1}_${f2}_ooo $start $end >& /dev/null
  tail -1 ooo_${f1}_${f2}_ooo >> all.txt
 endif
end
end
set nres=`expr $end - $start + 1`
echo $nres $nmodel
/users2/CASP13/scripts/klapaucjusz $nres $nmodel < all.txt > fragments.logfile
