#!/bin/csh -f
# convert ps file to Gif
#
#set PSTOPPM = 'usr/lib/local/ghostscript/pstoppm.ps'
set PSTOPPM = '/usr/lib/ghostscript/pstoppm.ps'
set resolution = 95
set function = 'ppm1run'
set quantcmd = "cat"
set transcmd = "giftrans -t #ffffff "
#
if ($#argv < 1) then
  echo "Usage:"
  echo "  ps2gif [ -col ] [ -res RESOLUTION ] [ -notrans ] psfile.ps"
  echo " "
  exit 1
endif
#
while ( $#argv )
  switch ( $argv[1] )
  case "-col" :
    set function = 'ppm24run'
    breaksw
  case "-quant" :
    set quantcmd = "ppmquant 50"
    breaksw
  case "-notrans" :
    set transcmd = "cat"
    breaksw
  case "-res" :
    shift
    if ( ! $#argv ) then
      echo "ps2gif: no resolution specified"
      exit 1
    endif
    set resolution = $argv[1]
    breaksw
  default:
    set fig = $argv[1]
    breaksw
  endsw
  shift
end
if ($fig:e != ps) then
  echo "ps2gif: Filename must have extension .ps!"
  exit 1;
else
  set fig = $fig:r
endif
#
gs -q -dNODISPLAY $PSTOPPM << ND
$resolution $resolution ppmsetdensity
($fig) $function
ND
pnmcrop $fig.ppm | $quantcmd | ppmtogif -interlace | $transcmd > $fig.gif
rm $fig.ppm
echo "Done"
