#
# should be run as ./do_test oofem_target_dir_path
#
RESULT=$1/test_results

#test if param provided
if [ -z $1 ]
then
echo "usage: do_test oofem_target_dir_path"
exit
fi

#test if valid target provided
if [ ! -d $1 ]
then
echo "invalid oofem_target_dir_path"
exit 
fi

# determine oofem version to use
if [ ! -f $1/bin/oofem ]
then
echo "oofem executable not found" >> ${RESULT}
exit
fi

# determine poofem version to use
if [ ! -f $1/bin/poofem ]
then
echo "poofem executable not found" >> ${RESULT}
exit
fi

ln -s $1/bin/oofem  ./oofem
ln -s $1/bin/poofem ./poofem

FILENAME="bar03.oofem.in"
INPUT="-f $FILENAME"
echo ""
echo "Running: ./oofem $INPUT"
echo ""
./oofem $INPUT
python ../../../tools/extractor.py -c -f $FILENAME >> ${RESULT}

FILENAME="bar03.statics.oofem.in"
INPUT="-f $FILENAME"
echo ""
echo "Running: ./oofem $INPUT"
echo ""
./oofem $INPUT
python ../../../tools/extractor.py -c -f $FILENAME >> ${RESULT}

FILENAME="bar03.oofem.in"
INPUT="-f $FILENAME"
NP="2"
echo ""
echo "Running: mpirun -np $NP ./poofem $INPUT"
echo ""
mpirun -np $NP ./poofem $INPUT
for i in *.in??; do python ../../../tools/extractor.py -c -f $i; done >> ${RESULT}

rm *.oofem.out
rm *.oofem.out.*

rm oofem
rm poofem
