#!/bin/csh -f

setenv LANG C

# See mkmatrix.awksh for input format

if ($#argv != 1) then
	echo Usage: $0 spreadsheet.txt
	echo '    (over)writes spreadsheet-trim.txt'
	echo '    (over)writes spreadsheet-matrix.txt'
	echo '    (over)writes spreadsheet-solverlist.txt'
	echo '    E.g.,' $0 'sat09-applications.txt'
	echo '    E.g.,' $0 'app-phase2.txt'
	exit $#argv
	endif

set ss = $1
set ssr = $ss:r

cat $ss | \
  awk -F'|' '/^Instance/{next;}/^_____/{next;} {print $1,$2,$3,$4,$5,$6;}' | \
  sed -e 's/^ //' -e 's/\([^ ]\) \([^ ]\)/\1_\2/g' | \
  awk '{print $1, $2, $3, $4, $5 "_" $6;}' | \
  awk '{if($2=="UNSAT"||$2=="SAT") t=$3; else t="Inf"; print $1, $5, t;}' | \
  sort | \
  cat > ${ssr}-trim.txt

cat ${ssr}-trim.txt | \
  mkmatrix.awksh | \
  cat > ${ssr}-matrix.txt


head -1 ${ssr}-matrix.txt | \
  tr ' ' '\012' | \
  egrep -v SOLVER | \
  egrep -v '^$' | \
  cat -n | \
  tr -d ':'  | \
  cat > ${ssr}-solverlist.txt
# Let us hope names are unique with colons deleted
exit 0

