#!/bin/sh

if [ ! -x evread ]; then
  echo "making evread ..."
  make evread
fi

PRE=foo
S=${HOME}/data/snr.ev
PROG=./evread
X=504
Y=512

while [ x"$1" != x ]; do
  case $1 in
  -P)
    PROG=./evread.pure
    shift
    continue;;
  -f)
    shift
    S=$1
    shift
    S=$1
    shift
    continue;;
  -x)
    shift
    X=$1
    shift
    continue;;
  -y)
    shift
    Y=$1
    shift
    continue;;
  *)
    shift
    continue;;
  esac
done

X2=`echo "$X + 10" | bc`
Y2=`echo "$Y + 10" | bc`
X3=`echo "$X + 20" | bc`
Y3=$Y
X4=`echo "$X + 10" | bc`
Y4=`echo "$Y - 10" | bc`

echo "${PRE}: array of structs, funtools alloc ..."
echo "${PRE}1: array of structs, user alloc ..."
echo "${PRE}2: struct of arrays, funtools alloc ..."
echo "${PRE}3: struct of arrays, user alloc ..."
echo "${PRE}4: struct of pointers, funtools alloc ..."
echo "${PRE}5: struct of pointers, user alloc ..."
echo "${PRE}6: array of pointers, funtools alloc ..."
echo "${PRE}7: array of pointers, user alloc ..."

IFS="	"
while read ARG1 ARG2 ARG3; do
  if [ x"$ARG1" = x ]; then
    continue
  fi
  if [ x`echo $ARG1 | sed 's/^#.*/YES/g'` = x"YES" ]; then
    continue
  fi
  eval "E=\"[$ARG2]\""
  echo FILE $S"$E" 
  ${PROG} -w ${PRE}.fits $S"$E" > ${PRE}.ls
  ${PROG} -u -w ${PRE}1.fits $S"$E" > ${PRE}1.ls
  ${PROG} -a -w ${PRE}2.fits $S"$E" > ${PRE}2.ls
  ${PROG} -a -u -w ${PRE}3.fits $S"$E" > ${PRE}3.ls
  ${PROG} -p -w ${PRE}4.fits $S"$E" > ${PRE}4.ls
  ${PROG} -p -u -w ${PRE}5.fits $S"$E" > ${PRE}5.ls
  ${PROG} -e -w ${PRE}6.fits $S"$E" > ${PRE}6.ls
  ${PROG} -e -u -w ${PRE}7.fits $S"$E" > ${PRE}7.ls
  for i in 1 2 3 4 5 6 7
  do
    echo "EXACT ${PRE} and ${PRE}${i} ..."
    cmp ${PRE}.fits ${PRE}${i}.fits
#    if [ $? != 0 ]; then
#      exit
#    fi
    diff ${PRE}.ls ${PRE}${i}.ls
#    if [ $? != 0 ]; then
#      exit
#    fi
  done
  rm -f ${PRE}*.fits
  rm -f ${PRE}*.ls

done

