#!/bin/bash
#
# Script to run all the Testing executables that are
# generated by just issuing the command
#     make
# the script takes a single argument that specifies the
# directory name to be used within the Results/Testing
# directory for storing the generated results files.
#
# If the directory name already exists, the user is required
# to confirm his intention to overwrite existing files.
#

# Check we have at least one argument and take the first if 
# more than one. If no arguments output error message
# and exit
if [ $# -eq 0 ];
then
  echo "runTests called without directory argument"
  echo "Exiting without running executables"
  exit
fi

# Set up the relative directory name given the argument
Prefix=../Results/Testing/$1/

# If directory requested already exists ask user for 
# confirmation. If it doesn't exist, create it.
if [ -d ${Prefix} ];
then 
  read -p "Directory ${Prefix} exists, continue [Yn]:" x
  if [ "$x" = "Y" ]; 
  then
    echo "Overwriting existing results files"
  else
    echo "Exiting without executing test codes"
    exit
  fi
else
  echo "Creating directory: ${Prefix}"
  mkdir -p ${Prefix}
fi

# Set name for separate error LOG
ERRORLOG=RunErrorLog

#./sdCheckTrue > ${Prefix}CheckTrue.txt 2>${ERRORLOG}
./sdTestHybrid > ${Prefix}Hybrid.txt 2>>${ERRORLOG}
./sdTestOrigKahan > ${Prefix}OrigKahan.txt 2>>${ERRORLOG}
./sdTestOnePassKahan > ${Prefix}OnePassKahan.txt 2>>${ERRORLOG}
./sdTestLa > ${Prefix}Lapack.txt 2>>${ERRORLOG}
./sdTestLaCsum > ${Prefix}LapackCsum.txt 2>>${ERRORLOG}
./sdTestLaCsSc > ${Prefix}LapackCsSc.txt 2>>${ERRORLOG}
./sdTestNorm2 > ${Prefix}Norm2.txt 2>>${ERRORLOG}
./sdTestNewOrig > ${Prefix}NewOrig.txt 2>>${ERRORLOG}
./sdTestBlue > ${Prefix}Blue.txt 2>>${ERRORLOG}
./sdTestNewBlue > ${Prefix}NewBlue.txt 2>>${ERRORLOG}
./sdTestNewOrigCsum > ${Prefix}NewOrigCsum.txt 2>>${ERRORLOG}
./sdTestBlueCsum > ${Prefix}BlueCsum.txt 2>>${ERRORLOG}
./sdTestOrigBLAS > ${Prefix}OrigBLAS.txt 2>>${ERRORLOG}
./sdTestCInterface > ${Prefix}CInterface.txt 2>>${ERRORLOG}
