#!/bin/sh
#
#
eCode=0
temp_success="1"
/bin/rm  -f  dout.txt err_dout.txt \
             vcs_eqilibrate_res.csv \
             diff_csv.txt  diff_dout.txt
#
# Create a symbolic link to mpequil, if none exists already
#

testName=nacl_equil

BINDIR=../../../bin

#
# There are different answers depending on whether DEBUG_MODE was
# turned on in the compile
goodFile=good_dout.txt
if test $# -gt 0
then
if test $1 = "DEBUG_MODE"
then
   goodFile=good_dout_dm.txt
fi
fi
#################################################################
#
#################################################################
MPEQUIL_EXE=${MPEQUIL_EXE:=nacl_equil}

./$MPEQUIL_EXE -d 5 > dout.txt 2>err_dout.txt
retnStat=$?
if test $retnStat != "0" 
then
  echo "mpequil returned with bad status, $retnStat, check output"
fi

diff -w $goodFile dout.txt  > diff_dout.txt
retnStat_txt=$?
$BINDIR/csvdiff -a 1.0E-50 vcs_equilibrate_blessed.csv vcs_equilibrate_res.csv  > diff_csv.txt
retnStat_csv=$?

if test $retnStat_csv = "1"  
then
  echo "Successful test comparison on "`pwd`
  if [ $retnStat_txt != "0" ]
  then
     echo "   But, text output files have differences. See diff_dout.txt"
  fi
else
  echo "Unsuccessful test comparison on "`pwd` " test"
  if test $retnStat_csv != "1"  
  then
     echo "      csv files are different - see diff_csv.txt"
  fi
  if test $retnStat_txt != "0" 
  then
     echo "      And, text output files have differences. See diff_dout.txt"
  fi
fi
#
# return 0 for no errors, 1 for errors
#
exit $eCode

