#!/bin/sh

currDir=`pwd`
application=`basename $currDir`
cases="kivaTest"

tutorialPath=`dirname $0`/..
. $tutorialPath/RunFunctions

runKivaToFoam ()
{
    if [ -f $1/log.kivaToFoam ] ; then
        echo "kivaToFoam already run on $1: remove log file to run"
    else
        echo "kivaToFoam: converting kiva file"
        kivaToFoam . $1 -file $2 > $1/log.kivaToFoam 2>&1
    fi
}

restartApplication ()
{
    if [ -f $2/log-2.$1 ] ; then
        echo "$1 already run on $2: remove log file to run"
    else
        echo "Running $1 on $2"
        $1 . $2 > $2/log-2.$1 2>&1
    fi
}

for case in $cases
do
    if [ "$case" = "kivaTest" ] ; then
       runKivaToFoam $case $case/otape17
       cp $case/system/controlDict.1st $case/system/controlDict
    fi
#
    runApplication $application $case
#
    if [ "$case" = "kivaTest" ] ; then
       cp $case/system/controlDict.2nd $case/system/controlDict
       restartApplication $application $case
    fi
done 
