#!/bin/bash


while [ $# -ne 0 ]
do
        case $1 in
       -h|--help|-help)
                echo "----------------------------------------------------------------------------"
		echo "Description:"
		echo "tar a full simulation"
		echo "----------------------------------------------------------------------------"
		exit ;;
        -*)
                `dirname $0`/tar_full_simu.sh -h
                exit ;;
        *)
                break ;;
        esac
done

dirin=$1
dirout=$2
config_card=$3
eval $(grep JobName  ${config_card}) 


if [[ ! -f $PATH_SIMU/tar_full_simul.list  ]] ; then
        `dirname $0`/tar_full_simu.sh -h
        exit
fi

fileout=${JobName}.tar
filefirst=`head -n 1 $PATH_SIMU/tar_full_simul.list`
dirinputfile=`dirname $filefirst`
diroutputfile=`dirname $filefirst | sed -e "s%$dirin%$dirout%"`	

outputfile=$diroutputfile/${fileout}
mkdir -p $diroutputfile


tarcmd=tar
taroptions="--format=posix -W -cf"

cd $dirinputfile

set_local="tar_full_simul.local"
for file in $( cat $PATH_SIMU/tar_full_simul.list ) ; do
    basename $file >> "tar_full_simul.local" 
done

$tarcmd $taroptions $outputfile --dereference --files-from tar_full_simul.local 
echo "====> TAR full simulation ${JobName}"  
rm -f tar_full_simul.local