#!/bin/sh
#
#  $Id$
#
#  Script to adapt a new run directory,
#  start the job and check it in.
#
#----------------------------------------------------------
#  Exit if there is no CVS directory
#
if [ ! -e "CVS" ]; then
  echo
  echo "This directory is not under CVS"
  echo
  exit
fi
#
#----------------------------------------------------------
#  Exit if the executable does not exist
#
if [ ! -e "master/src/start.x" ]; then
  echo
  echo "The is no executable"
  echo
  exit
fi
#
#----------------------------------------------------------
#  name of the new run directory
#
oldrun=master
newrun=$1
#
#  set up new run directory by modifying an existing one,
#  using the executable in it.
#
pc_newrun -s $oldrun $newrun
#
#  adapt run.in file in the new run directory
#
modfile='run.in'
str='s/XX/'$1'/g'
sed -e $str templates/$modfile > $newrun/$modfile
#
#  adapt parameters.pro file in the new run directory
#
modfile='parameters.pro'
str='s/XX/'$newrun'/g'
sed -e $str templates/$modfile > $newrun/$modfile
#
# go into run directory, run start.csh and run N.csh (background job)
#
cd $newrun
start.csh
run_background.csh
sleep 20
cvsci_run
#
