# Script for testing abinis in charge (TC = Test Charge)
# Before running this script, read README in this directory.

# Copyright (C) 2000-2005 ABINIT group (XG,LSi)
# This file is distributed under the terms of the
# GNU General Public License, see ~ABINIT/Infos/copyright
# or http://www.gnu.org/copyleft/gpl.txt .
# For the initials of contributors, see ~ABINIT/Infos/contributors .
#
# For the same input file, test the execution of 1 to 4
# concurrent executions, then analyze the results.

# Usage under unix:
# C-shell: ( RunTC machine_name [First_test] >& log_file )
# bash: RunTC machine_name [First_test] > log_file 2>&1 
#

#*****************************************************************************

set -v

# Set codename for sequential version
CODE_SEQ=../../abinis
# Set pseudopotential directory
PSPS=../../Psps_for_tests
# Define the pseudopotential
PSP=$PSPS'/14si.psp'
# Set utilities directory
UTIL=../../Utilities
# Set machine name
MACH=$1

echo "testing the Abinit code on the $MACH platform"

#*******************************************************************************

#################################################
# set a date flag to make a new directory today #
#################################################

YYMMDD=`date "+DATE %y%m%d" | cut -d" " -f2`

WORK_DIR=,"$MACH"_20"$YYMMDD"
if test ! -d $WORK_DIR
then
  mkdir $WORK_DIR
else
  echo "Can not create directory"
  echo $WORK_DIR
  echo "already exists"
#  exit 1
fi

# **************************************** 
# Make preliminary operations in the working directory
cd $WORK_DIR

rm -f ab.files* 
tests="0 1 2 3 4 5 6 7 8 9"
for Tnum in $tests
do
cat >ab.files$Tnum <<End1
../t9.in
t9$Tnum.out
t9$Tnum.i
t9$Tnum.o
t9$Tnum
$PSP
End1
done
# ****************************************
# Jump to test to be run
#Case_1
#if test $2 -eq 1    This test does not work under C-shell ?!
#then
rm -f t90*
echo Case1
time $CODE_SEQ < ab.files0 2>&1 1> t90.log 
sleep 5
#exit
#fi

#Case_2
#if test $2 -le 2
#then
echo Case2
rm -f t91* t92*
time $CODE_SEQ < ab.files1 2>&1 1> t91.log &
time $CODE_SEQ < ab.files2 2>&1 1> t92.log 
sleep 5
#exit
#fi

#Case_3
#if test $2 -le 3
#then
rm -f t93* t94* t95*
time $CODE_SEQ < ab.files3 2>&1 1> t93.log &
time $CODE_SEQ < ab.files4 2>&1 1> t94.log &
time $CODE_SEQ < ab.files5 2>&1 1> t95.log
sleep 5
#exit
#fi

#Case_4
#if test $2 -le 4
#then
rm -f t96* t97* t98* t99*
time $CODE_SEQ < ab.files6 2>&1 1> t96.log &
time $CODE_SEQ < ab.files7 2>&1 1> t97.log &
time $CODE_SEQ < ab.files8 2>&1 1> t98.log &
time $CODE_SEQ < ab.files9 2>&1 1> t99.log 
sleep 5
#exit
#fi

#Case_5
#if test $2 -le 5
#then
#Analyze the output files
rm -f fldiff.set9.report
for Tnum in $tests
do
diff -b t9$Tnum.out ../Refs/t90.out > diff.t9$Tnum
echo " " >> fldiff.set9.report
echo "Case_9$Tnum" >> fldiff.set9.report
$UTIL/fldiff -ignore t9$Tnum.out ../Refs/t90.out >> fldiff.set9.report
done
#fi

exit
