#!/bin/sh
#############################################
# Print out the model
# theTab = Dir/file/recno
# 
#############################################

if test -z "$theTab"; then
    test -z "$3" && set $1 $2 1
    theTab="$1/$2/$3"
fi

#ls -l `which tabmap`

NR1=`basename $theTab`
file=`dirname $theTab`
test -z "$NR1" && NR1=1

echo1 "\underline{{\bf\large Model from {\fg{red4}$file}}}\par"
#echo1 "...Execute: tabmap -htx +$NR1 ./$file"
#echo1 '\begin{verbatim}'
#tabmap -ascii\| +$NR1 ./$file | gawk 'BEGIN{FS="|"}/^#/{next}\
#  /^ *[0-9]/{ if(Mo==0) Mo=$2; if($2==Mo) print; next }\
#  { print  }'
#echo1 '\end{verbatim}'
tabmap -keep -htx\| +$NR1 ./$file | gawk 'BEGIN{FS="&"}\
   /subsection/{next}\
   /logMi/{ sub(/logMi/, "{\\fg{blue3}logMi}") }\
   /^[#%]/{next}/^$/{next}\
   /^ *[0-9]/{ if(Mo==0) { Mo=$2; v="{\\fg{blue3}" $2 "}"; sub($2, v); print}\
                  else if($2==Mo){v="{\\fg{blue3}" $2 "}"; sub($2, v); print}\
       next }\
   { print  }'  | tee /tmp/mod1
