#!/bin/sh
#
# ========================================================================
#
# *
# * This file is part of MARS, the MAGIC Analysis and Reconstruction
# * Software. It is distributed to you in the hope that it can be a useful
# * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
# * It is distributed WITHOUT ANY WARRANTY.
# *
# * Permission to use, copy, modify and distribute this software and its
# * documentation for any purpose is hereby granted without fee,
# * provided that the above copyright notice appear in all copies and
# * that both that copyright notice and this permission notice appear
# * in supporting documentation. It is provided "as is" without express
# * or implied warranty.
# *
#
#
#   Author(s): Daniela Dorner  05/2005 <mailto:dorner@astro.uni-wuerzburg.de>
#
#   Copyright: MAGIC Software Development, 2000-2006
#
#
# ========================================================================
#
# This a script, which launches other scripts
#

source `dirname $0`/sourcefile

errorlog=$logpath/scriptlauncher/`date +%Y/%m`/error`date +%F`.log
scriptslog=$logpath/scriptlauncher/`date +%Y/%m`/jobmanager`date +%F`.log

date  >> $scriptlog 2>&1

path=`dirname $0`
date=`date +%Y/%m/%d`
date2=`date +%Y-%m-%d`
condordir=$logpath/condor/$date
makedir $condordir

for i in $@
do 
   if [ "$i" = "allatthesametime" ]
   then 
      continue
   fi
   echo "launching $i..." >> $scriptlog 2>&1
   /usr/local/bin/condor_submit -a path=$path -a prog=$i -a date=$date2 -a dir=$condordir $path/run.condor >/dev/null  2>$errorlog
   if ! echo $@ | grep "allatthesametime" >/dev/null 2>$errorlog
   then
      echo " waiting for $i to be done..." >> $scriptlog 2>&1
      /usr/local/bin/condor_wait $condordir/condor-$date2.log >/dev/null 2>$errorlog
   fi
done

