#!/bin/sh

## Job Name
#PBS -N r_script

## Script to run a script in camelot, IPSL
#PBS -m ae
#PBS -M lluis.fita@lmd.jussieu.fr

## Joins standard and Error outputs in a single file
#PBS -j oe

## Queue
#PBS -q day

### Max run time
#PBS -l walltime=12:00:00

### Max memory
#PBS -l vmem=20gb
#PBS -l mem=20gb

## resources
#PBS -l nodes=1:ppn=1

cd $PBS_O_WORKDIR

Lscriptname=`expr length ${scriptname}0`
if test ${Lscriptname} -le 1; then
  echo "ERROR -- error -- ERROR -- error"
  echo "  No script name provided!!"
  exit
fi

echo "running '"${scriptname}"' ..."

dateval=`date "+%Y%m%d%H%M%S"`

rm ${PBS_JOBNAME}.o*
rm run_${scriptname}_*.log

date > run_${scriptname}_${dateval}.log
bash ${scriptname} >& r_script0_${dateval}.log
cat r_script0_${dateval}.log >> run_${scriptname}_${dateval}.log
rm r_script0_${dateval}.log
date >> run_${scriptname}_${dateval}.log

## e.g. # qsub -v scriptname='WRF_graphics.bash' run_script.pbs
