
./Tools/ccsm_check_lockedfiles || exit -1
source ./Tools/ccsm_getenv     || exit -2

if ($BUILD_COMPLETE != "TRUE") then
  echo "BUILD_COMPLETE is not TRUE"
  echo "Please rebuild the model interactively"
  exit -2
endif

# BATCHQUERY is in env_run.xml
setenv LBQUERY "TRUE"
if !($?BATCHQUERY) then
  setenv LBQUERY "FALSE"
  setenv BATCHQUERY "undefined"
else if ( "$BATCHQUERY" == 'UNSET' ) then
  setenv LBQUERY "FALSE"
  setenv BATCHQUERY "undefined"
endif

# BATCHSUBMIT is in env_run.xml
setenv LBSUBMIT "TRUE"
if !($?BATCHSUBMIT) then
  setenv LBSUBMIT "FALSE"
  setenv BATCHSUBMIT "undefined"
else if ( "$BATCHSUBMIT" == 'UNSET' ) then
  setenv LBSUBMIT "FALSE"
  setenv BATCHSUBMIT "undefined"
endif

# --- Create and cleanup the timing directories---

if !(-d $RUNDIR) mkdir -p $RUNDIR || "cannot make $RUNDIR" && exit -1
if (-d $RUNDIR/timing) rm -r -f $RUNDIR/timing
mkdir $RUNDIR/timing
mkdir $RUNDIR/timing/checkpoints

# --- Determine time-stamp/file-ID string ---
setenv LID "`date +%y%m%d-%H%M%S`"

set sdate = `date +"%Y-%m-%d %H:%M:%S"`
echo "run started $sdate" >>& $CASEROOT/CaseStatus

