#! /bin/csh 
# Last edited on 1998-07-12 15:03:48 by stolfi

set usage = "$0 DIR LNUM RNUM VMIN VMAX"

set dir  = "$1"; shift;
set lnum = "$1"; shift;
set rnum = "$1"; shift;
set vmin  = "$1"; shift;
set vmax  = "$1"; shift;

@ order = ${lnum} + 1 + ${rnum}
@ place = ${lnum} + 1

if ( $#argv > 0 ) then
  echo "usage: ${usage}"; exit 1;
endif

set name = "${dir}/L${lnum}R${rnum}";
set tmp = "/tmp/$$"

echo "  extract-signif-chars|gather-tuples|uniq --> ${name}.cts"
cat ${dir}/full.txt \
  | extract-signif-chars \
      -v normal="-'" \
      -v errors='_' \
  | gather-tuples \
      -v order=${order} \
      -v filler='_' \
      -v lowercase=1 \
  | sort | uniq -c | expand \
  > ${name}.cts

echo "  compute-cond-tuple-info --> ${name}.inf"
cat ${name}.cts \
  | compute-cond-tuple-info \
      -v order=${order} \
      -v place=${place} \
      -v alphabetSize=71 \
  | sort +0 -1gr \
  > ${name}.inf

echo "  tuple-value-to-digits --> ${name}.digs"
cat ${name}.inf \
  | tuple-value-to-digits \
      -v order=${order} \
      -v place=${place} \
      -v vmin=${vmin} \
      -v vmax=${vmax} \
  | sort +1 -2 \
  > ${name}.digs
  
set ofile = "${name}.html"

echo "  extract-signif-chars|colorize-text-by-tuple --> ${ofile}"
echo "<html><head><title>${name} context: L ${lnum}  R ${rnum}  ord ${order}</title></head>" > ${ofile}
echo "<body bgcolor=#000000>" >> ${ofile}
echo "<b><tt><pre>" >> ${ofile}
cat ${dir}/page.txt \
  | extract-signif-chars \
      -v normal="-'" \
      -v errors='_'  \
  | colorize-text-by-tuple \
      -v order=${order} \
      -v filler='_' \
      -v table=${name}.digs \
      -v dmax=9 \
      -v ymin=0.250 \
  >> ${ofile}
echo "</pre></tt></b>" >> ${ofile}
echo "</body>" >> ${ofile}
echo "</html>" >> ${ofile}

# /bin/rm ${tmp}-full.txt ${tmp}-page.txt

