#!/bin/sh
#SBATCH 
#SBATCH --error=stderr.err
#SBATCH --output=stdout.out
#SBATCH --cpus-per-task=20


source /project/ldv/Software/executor-venv-toil7/bin/activate

export CWL_SINGULARITY_CACHE=/project/ldv/Share/run-test/workflows/linc_target_mammoth_august/workflows

ulimit -n $(ulimit -Hn)
mkdir -p /tmp/tmpi0_mg7xq
srun cwltool --singularity --preserve-entire-environment --disable-pull --tmp-outdir-prefix /tmp/tmpi0_mg7xq/tmp --outdir /project/ldv/Share/run-test/2025/12/1/1143_267743 /project/ldv/Share/run-test/workflows/linc_target_mammoth_august/workflows/ldv_linc_target.cwl input.json

ERROR_CODE=$?

if [ $ERROR_CODE != '0' ]; then
    echo "JOB FAILED WITH ERROR CODE $ERROR_CODE" >&2
    echo "COMPRESSING TEMPORARY DIRECTORY" >&2
    tar -cvf /project/ldv/Share/run-test/2025/12/1/1143_267743/tmp.tar /tmp/tmpi0_mg7xq*
else
    echo Job finished successfully! >&2 
fi
exit $ERROR_CODE
        