#!/bin/sh
## \section{hips2viff}
## 
## \subsection*{Purpose}
## Convert from HIPS to VIFF (Khoros) format
## 
## \subsection*{Usage }
## \begin{verbatim}
## hips2viff [-byte|-int|-float|-scale]
## \end{verbatim}
## \begin{description}
##   \item[-byte]
## 	Convert using byte format
##   \item[-int]
## 	Convert using integer format
##   \item[-float]
## 	Convert using floating point format
##   \item[-scale]
## 	Convert using byte format, scaled to the maximum dynamic range
## \end{description}
## 
## \subsection*{Date created}
## March 1994

# Default parameters:
FORMAT=byte
CONVERT=htob

# Temporary files:
RAW_FILE=`tempnam`
VIFF_FILE=`tempnam`


print_usage ()
{
  echo "hips2viff:"
  echo "\tParameters:"
  echo "\t -byte 	Use byte format (default)"
  echo "\t -int  	Use integer format"
  echo "\t -float	Use floating point format"
  echo "\t -scale	Scale to max range and then use byte format"
  exit
}

while [ $# ]; do
  case "${1}" in
    -U		) shift; print_usage ;;
    -byte	) shift; FORMAT=byte;  CONVERT=htob;;
    -int	) shift; FORMAT=int;   CONVERT=htoi;;
    -float	) shift; FORMAT=float; CONVERT=htof;;
    -scale	) shift; FORMAT=scale; CONVERT="scale -e";;
    -*          ) shift; print_usage ;;
    *           ) FILE=${1}; break;;
  esac
done

FRAMES=`hsize -frames ${FILE}`
ROWS=`hsize -rows ${FILE}`
COLS=`hsize -cols ${FILE}`

${CONVERT} ${FILE} | stripheader > $RAW_FILE
raw2viff -i $RAW_FILE -o $VIFF_FILE -r ${ROWS} -c ${COLS} -t ${FORMAT} \
	-b ${FRAMES}

cat $VIFF_FILE
rm -f $RAW_FILE $VIFF_FILE
