#!/bin/bash

#input FP exec
test_dir=$1  # name of dir with pathname and options to be used 
FP_exec=$2   # path to executable to be run
base_dir=$3  # base for the output
options_default=$4

echo run test '>' input
echo $1
echo $2
echo $3
echo $4

#  echo name= $name
#  echo working dir= $path_tests/test_$name
#  echo executable= $FP_exec 
#  echo default options from $options_default 
 
#echo FP_exec=$FP_exec
echo env var FLEXOUT_TMP=$FLEXOUT_TP

#suffix=$(date "+%y-%m-%d_%H%M%S")
test_tmp=${FLEXOUT_TMP}${base_dir}${test_dir}
#_${suffix}

current_dir=$(pwd)
#echo test_tmp=$test_tmp
mkdir $test_tmp

echo run test '>' copy default options to temp dir
echo from  $options_default  to $test_tmp/options
cp -r $options_default $test_tmp/options
#override default options
echo copy test options files to temp dir
echo ${test_dir}/options/* $test_tmp/options/
cp   ${test_dir}/options/* $test_tmp/options/
echo copy test options/SPECIES to temp dir if needed

if [ -d "${test_dir}/options/SPECIES" ]; then
echo from ${test_dir}/options/SPECIES/* to $test_tmp/options/SPECIES/
cp        ${test_dir}/options/SPECIES/*    $test_tmp/options/SPECIES/
fi

# copy paths form repo source exec tmp dir 
echo copy test pathnames to temp dir
cp ${test_dir}/pathnames $test_tmp
echo create output dir ${test_tmp}/output
mkdir ${test_tmp}/output

#cp test_1/run $test_tmp

cd $test_tmp
#echo $(pwd)
#echo $FP_exec
#  '&>' o is bash for both out and err
#echo run $FP_exec   to  out.log #&
#$FP_exec   &> out.log #&
echo execute test
$FP_exec > stdout.log 2> stderr.log #&
echo flexpart terminated



