echo "Stics4CarSolEl Job starting:"
date;

n_slots=${1};
csv_plan=${2};
sim_number=$(($(cat ${csv_plan} | wc -l) - 1));

b_size=1

echo "number of GALAXY_SLOTS: ${1}"

echo "expected simulations: ${sim_number}"
echo "cvle block size : ${b_size}"

cvle -b $b_size -i ${2} -w work -P Stics4AgFlow -P CarSolEl_sim CarSolEl.vpz

ls work_*/*_byUsm.txt | xargs -t -i tail -n +2 {} | sort -n -k 1 -t ';' > resWithoutHeader.csv

head -1 work_0/1_byUsm.txt > header.cvs

cat header.cvs resWithoutHeader.csv > res.csv

mv res.csv ${3}

echo "Stics4AgGlob Job ending:"
date;
