#!/bin/sh
#$ -o /afs/in2p3.fr/group/virgo/www/WOD/V1/2009/12/15/23/944955111.000/job.o
#$ -e /afs/in2p3.fr/group/virgo/www/WOD/V1/2009/12/15/23/944955111.000/job.e
#$ -P P_virgo
#$ -l os=sl6,ct=10000,fsize=5000M,vmem=4096M,sps=1,xrootd=1
#$ -N WOD-944955111.000

if [ ! -d /afs/in2p3.fr/group/virgo/www/WOD/V1/2009/12/15/23/944955111.000 ]; then
    echo "ERROR! /afs/in2p3.fr/group/virgo/www/WOD/V1/2009/12/15/23/944955111.000 does not exist"
    exit 1
fi


# Load omega
source /afs/in2p3.fr/throng/virgo/virgoApp/omega/v2r1/cmt/setup.sh

if [ ${#TMPDIR} -eq 0 ]; then
    TMPDIR=/scratch/mabizoua
fi

echo $TMPDIR
# working directory
workdir=${TMPDIR}/944955111.000
mkdir $workdir

# to load MATLAB runtime libraries
export MCRJRE=${MATLABROOT}/sys/java/jre/glnxa64/jre/lib/amd64

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${MATLABROOT}/runtime/glnxa64:${MATLABROOT}/bin/glnxa64:${MATLABROOT}/sys/os/glnxa64:${MATLABROOT}/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:${MATLABROOT}/sys/java/jre/glnxa64/jre/lib/amd64/server:${MATLABROOT}/sys/java/jre/glnxa64/jre/lib/amd64/client:${MATLABROOT}/sys/java/jre/glnxa64/jre/lib/amd64

export XAPPLRESDIR=${MATLABROOT}/X11/app-defaults

# Xrootd
source /usr/local/shared/bin/xrootd_env.sh

# run scan
wpipeline scan --report --configuration /afs/in2p3.fr/throng/virgo/virgoApp/omega/v2r1//scripts/config.STD.txt --framecache /afs/in2p3.fr/group/virgo/BKDB/VSR2/VSR2_raw.ffl --debug 5 --outdir ${workdir} 944955111.000 

# move output
unset LD_PRELOAD
if [ ! -d /afs/in2p3.fr/group/virgo/www/WOD/V1/2009/12/15/23/944955111.000 ]; then
    echo "ERROR! /afs/in2p3.fr/group/virgo/www/WOD/V1/2009/12/15/23/944955111.000 does not exist"
    exit 1
fi
mv -f ${workdir}/* /afs/in2p3.fr/group/virgo/www/WOD/V1/2009/12/15/23/944955111.000
rm -f  /afs/in2p3.fr/group/virgo/www/WOD/V1/2009/12/15/23/944955111.000/lock

# exits
exit 0
