#!/bin/sh
#
# $Id: binary_test,v 1.8 2003/07/28 02:37:16 rauch Exp $
#
# Test script to test binary file handling.
#
. ./procs.sh
testing "binary file handling"

cleanup() { rm -f body*.dat energy*.dat; exit 0; }

# Display uniformly formatted conversion result.
# $1, $2 = conversion pair
binresult() { 
  conversion=`printf "%5s <==> %10s  conversion" $1 $2`
  result "$conversion" | sed '/^ $/d'
}

# Alias cmp to beautify error displays.
compare() { cmp $*; }


if tryexec $BIN/hnbody -q binary.hnb; then
  tryexec $BIN/hnconvert -d body1.dat   body1-d.dat
  tryexec $BIN/hnconvert -f body1-d.dat body1-f.dat
  tryexec compare body1-f.dat body1.dat
  binresult Float Double

  tryexec $BIN/hnconvert -s -c 2,3,4,5,6,7 body1.dat   body1-s.dat
  tryexec $BIN/hnconvert -T 8              body1-s.dat body1-t.dat
  tryexec $BIN/hnconvert -f                body1-t.dat body1-f.dat
  tryexec $BIN/hnconvert -t 8              body1-f.dat body1-t2.dat
  tryexec compare body1-t.dat body1-t2.dat
  tryexec binresult Float SmartFloat

  tryexec $BIN/hnconvert -t 9 body1.dat   body1-t.dat
  tryexec $BIN/hnconvert -f   body1-t.dat body1-f.dat
  tryexec $BIN/hnconvert -t 9 body1-f.dat body1-t2.dat
  tryexec compare body1-t.dat body1-t2.dat
  binresult Float Text

  tryexec $BIN/hnconvert -d   energy.dat   energy-d.dat
  tryexec $BIN/hnconvert -t 0 energy-d.dat energy-t.dat
  tryexec compare energy-t.dat energy.dat
  binresult Text Double
  if [ $status -gt 0  -a  -n "`$BIN/hnbody -v | grep -e -x86\)`" ]; then
    echo " "
    echo "NOTE: final test known to fail on this platform."
  fi
fi

echo " "
cleanup
