#!/bin/csh -f

setenv LANG C

if ($#argv != 2) then
    echo Usage: $0 'matrix.txt noise_level'
    echo '    (over)writes matrix-noise_level-report.txt'
    echo '    (over)writes matrix-noise_level-scores.txt'
    echo '    (over)writes matrix-noise_level-ranked1.txt'
    echo '    (over)writes matrix-noise_level-ranked2.txt'
    exit $#argv
    endif

set inf = $1
set noise = $2
set infr = $inf:r
set outf = ${infr}-${noise}-report.txt

cat ${inf} | \
  pairs-compare.awksh -v units=1 -v noise=$noise  | \
  cat > $outf

cat $outf | \
  egrep '^MYTOT' | sort -n -r -k3,3 > ${infr}-${noise}-scores.txt

echo DOMIN > ${infr}-${noise}-ranked1.txt
cat $outf | \
  egrep '^MYDOMINS' | \
  sort -n -r -k3,3 >> ${infr}-${noise}-ranked1.txt

echo STRICT_DOMIN > ${infr}-${noise}-ranked2.txt
cat $outf | \
  egrep '^MYWINS' | \
  sort -n -r -k3,3 >> ${infr}-${noise}-ranked2.txt

exit 0
# awk '/^DOMIN/{go=1;next;} NF>=2&&go==1{go=2;next;} NF==0&&go==2{exit;} go==2{print $1, $2;next;}' | \
