#!/usr/bin/ksh
# $Id$
######################################################
# Original : C. Talandier for ESOPA
# Contact  : opatlod@locean-ipsl.upmc.fr
#
# This script is launched by the lance_batch.ksh script
# for a given configuration.
# It aims to (for each standard configuration) check if
# there are jobs in queue associated with the considered 
# configuration. 
# If jobs are still in queue it re-launched itself either
# it launchs the assessment.ksh script 
######################################################

#set -xv

CONF=$1
LJOBS=qstat

if [ ${CONF} == 'ORCA2_LIM' ] ; then
CONFS=ORCA2
elif [ ${CONF} == 'GYRE_LOBSTER' ] ; then
CONFS=GYRE_
elif [ ${CONF} == 'ZAGRIF' ] ; then
CONFS=ZAGRI
else
CONFS=${CONF}
fi

JOBS_LIST=` ${LJOBS} |  grep -c ${CONFS}`
if [ ${JOBS_LIST} = 0 ]
then
    sleep 60
    ./assessment.ksh ${CONF} yes &
    exit
fi
sleep 300
./cron_jobs.ksh ${CONF} &
exit

