#!/bin/tcsh

# 
# renders a Standard Lattice Format (SLF) file and shows it using the VIEWER
# requires Ubuntu package 'graphviz'
#

set SCRIPT = `readlink -f "$0"`
set SOURCE = `dirname "$SCRIPT"`  # location where the script is stored 
                           # (even if we start via a symbolic link)
set TEMP = /tmp
setenv LANG en_US.UTF-8  # defines the behavior of text processing, sorting etc.
setenv SOX_OPTS "-D" # this prevents sox version 14.3 and higher to use
                     # automatic dithering in rate conversions which causes
                     # MAUS results to fluctuate randomly


set VIEWER = 'eog'

if ( $1 == "" || ( ${1:e} != "slf" && ${1:e} != "SLF" )) then 
  echo "usage: $0 <file>.slf"
  echo "       plots a rendered graphic version of the lattice to X"
  exit 1
endif
which dot
if ( $status != 0 ) then 
  echo "${0:t} requires the tool 'dot' (package 'graphviz') - exiting"
  echo "If your are on Ubuntu try 'sudo apt-get install graphviz'"
  exit 1
endif
which $VIEWER
if ( $status != 0 ) then
  echo "${0:t} viewer $VIEWER not found - exiting"
  exit 1
endif

$SOURCE/LatticeToDot.pl $1 >! $TEMP/$$ViewLattice.dot
chmod 666 $TEMP/$$ViewLattice.dot
dot -Tpng $TEMP/$$ViewLattice.dot >! $TEMP/$$ViewLattice.png
chmod 666 $TEMP/$$ViewLattice.png
$VIEWER $TEMP/$$ViewLattice.png

rm -f $TEMP/$$ViewLattice.do $TEMP/$$ViewLattice.png

exit 0
