#!/bin/bash

if [ $# -eq 0 ]; then
        echo "Usage example: $0 [file1] [file2] ..."
        exit 1
fi

for i in "$@"
do
    if [ ! -f "$i" ]; then
        echo "No file $i"
        exit 1
    fi
done

echo "Task was submitted."

NAME=`echo $1 | tail -c 14`

cat << EOF | qsub -r n
#!/bin/bash --login
#PBS -q normal
#PBS -l mem=2000MB
#PBS -l nodes=1:ppn=1
#PBS -N Nchr

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/wojek/libki:/home/wojek/libki/lib:/usr/lib64/

export CURRDIR=`pwd`

for i in $@
do
    mkdir -p /scratch/$USER/comp/\$i
    cd /scratch/$USER/comp
    cd \$i
    cp \${CURRDIR}/\$i ./
    hostname > _simulation_in_progress_please_wait
    Nchr2 ./\$i
    rm _simulation_in_progress_please_wait
done
EOF