#! /bin/csh 
# Last edited on 2025-05-01 18:23:54 by stolfi

set usage = "$0 DIR LNUM RNUM HMIN NCOLORS HMAX"

set dir  = "$1"; shift;
set lnum = "$1"; shift;
set rnum = "$1"; shift;
set hmin  = "$1"; shift;
set ncol  = "$1"; shift;
set hmax  = "$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 \
  | nice extract-signif-chars \
      -v normal="-'" \
      -v errors='_' \
  | nice gather-tuples \
      -v order=${order} \
      -v filler='_' \
      -v lowercase=1 \
  | sort | uniq -c | expand \
  > ${name}.cts

echo "  compute-cond-tuple-info --> ${name}-test.inf"
 ( cat ${name}.cts \
    | nice compute-cond-tuple-info-test \
        -v order=${order} \
        -v place=${place} \
        -v alphabetSize=71 \
    | sort -k1gr \
    > ${name}-test.inf \
 ) >& ${name}-test.cmt

set ofile = "${name}-test.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}
echo "<font color=#b4b4b4>" >> ${ofile}
cat ${dir}/page.txt \
  | nice extract-signif-chars \
      -v normal="-'" \
      -v errors='_'  \
  | nice colorize-text-by-tuple-new \
      -v order=${order} \
      -v place=${place} \
      -v filler='_' \
      -v table=${name}-test.inf \
      -v hmin=${hmin} \
      -v hmax=${hmax} \
      -v ymin=0.350 \
      -v colors=${ncol} \
  >> ${ofile}
cat ${name}-test.cmt \
  >> ${ofile}
echo "</font>" >> ${ofile}
echo "</pre></tt></b>" >> ${ofile}
echo "</body>" >> ${ofile}
echo "</html>" >> ${ofile}

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

