#!/bin/bash

PARALLELFILE="./parallel.file"

if [ ${#} -lt 2 ]
then
  echo "${0} plik-indeksu liczba-watkow [run_saper]"
  echo ""
  echo 'Nalezy podac sciezke do plikow indeksu qa!'
  exit
fi

if [ ! -f ${1} ]
then
  echo "Nie odnaleziono pliku indeksu: ${1}"
  exit
fi

if [ ${2} -lt 1 ]
then
  echo "Liczba watkow musi byc wieksza od zera!"
  exit
fi

rm -f ${PARALLELFILE}

for LINE in $(cat ${1}) 
do 
  QFILE=${LINE}.q
  AFILE=${LINE}.a
  if [ ${2} -eq 1 ]
  then
    `pwd`/runsentsim.sh ${QFILE} ${AFILE} $3 2> ${LINE}.csv
  else
    echo "`pwd`/runsentsim.sh ${QFILE} ${AFILE} $3 2> ${LINE}.csv" >> ${PARALLELFILE}
  fi
done 

if [ ${2} -gt 1 ]
then
  echo "parallel -a ${PARALLELFILE} -j ${2}"
fi
