*ID GSM1U406
*/ U.M. 4.6 unix / source code change form / header   version 06/01/99
*/ CODE WRITERS MUST READ THE ACCOMPANYING INSTRUCTIONS FOR THIS BUILD:
*/  - See http://fr0800/umdoc/hegui/t3e4.6.html#chgfinst
*/ 
*/SOC:-> Modset for vn4.5.1 of UMUI to allow autoresub and STEP=2
*/
*/ vn4.5.1 includes number of modifications to the submit process
*/ to allow the roving job system to work. These require similar
*/ changes to the resubmit process whether or not job is roving.
*/
*/ Has an entry been lodged in the Problem Reporting System? [N]      
*/
*/ THIS CODE IS INTENDED FOR INCLUSION IN THE 4.6 BUILD      [N]
*/ .....................................................................
*/   Author[s]:-> E-mail:-> sdmullerworth@meto.gov.uk 
*/ Reviewer[s]:-> E-mail:-> @meto.gov.uk
*/
*/    "I have checked this change. When provided, the advance design 
*/  specification was agreed and adequate, and the new code conforms to
*/  Unified Model standards."
*/
*/  DESIGN SPEC. WAS REVIEWED ON: ......      REVIEWER[S] SIGNATURES
*/                                            ----------------------
*/    DATE CODE REVIEWED: ......
*/  .....................................................................
*/
*/  WILL CHANGES AFFECT ANCILLARY FILES?         [N]
*/  ARE ANY CHANGES TO STASHMASTER FILES NEEDED? [N] 
*/  USER INTERFACE ACTION REQUIRED?              [Y]
*/ 
*/  TESTED IN CONFIGURATIONS:->atmos, coupled
*/  TESTS RUN BY [PERSON]:->sdmullerworth
*/ 
*/  WILL THE CHANGES SLOW DOWN THE MODEL?        [Y|N]
*/  -> Further details
*/  CHANGES WILL INCREASE MEMORY CONSUMPTION?    [Y|N]   
*/  -> Further details
*/
*/ | Re-start dumps bit compare with those created without the change 
*/ V MARK [Y| ] BELOW; leave rest of lines untouched.
*/
*/   Control Code    loses bit comparison
*/   Atmosphere (assuming same science options chosen)   loses b.c.
*/   Ocean       loses bit comparison
*/   Wave        loses bit comparison
*/   Reconfiguration   loses bit comparison
*/   Diagnostics      lose bit comparison
*/ For Y2K compliance checking:  
*/ DOES THIS CHANGE INTERACT WITH DATE CALCULATIONS IN ANY WAY? [N]   
*/ 
*/  SECTIONS (TO BE) CHANGED:
*/
*/  SECTIONS (TO BE) DELETED? 
*/
*/  NEW SECTIONS?  Fill in form http://www-hc/~hadmk/STASHmaster_change.html,
*/  and give section numbers below:
*/  
*/  *DEFS ADDED OR REMOVED: 
*/
*/  **Existing** decks being changed [with *I, *D, *B directives]
*/ ->
*/
*/  Decks being created or purged [with *DECK, *COMDECK, *PURGEDK]
*/ *......K  Deck name   Section#.vr
*/ -> 
*/ ......................................................................
*/ ANY REFERENCES TO EXTERNAL DOCUMENTS-> instead of design spec.
*/  ...OR ... ADVANCE DESIGN SPECIFICATION (optional) 
*/ ->    
*//////////////////////////////////////////////////////////////////////// 
*DECLARE qsmain
*I ARR5U405.15
#LL    4.5+   23/02/00 Roving Jobs mod. S.D.Mullerworth
*I qsmain.272   
if test "$ROVING" = true; then
  # Test that LOADMODULE's existence or not, and pathname are consistent
  # with the STEP and Location File.
  if test $STEP -le 2; then
    fileReady=0
  else
    fileReady=1
  fi
#  checkRovingFile $RUNID exe $LOADMODULE $fileReady
#  returnCode=$?
#  if test $returnCode -ne 0; then
#    return $returnCode
#  fi
fi ;# End test $ROVING = true
      

*I gex3u405.28    
    if test "$ROVING" = true; then
      setLocation $RUNID exeLocation `hostname`
      returnCode=$?
      if test $returnCode -ne 0; then
        echo Cannot store location information for new executable
        echo Therefore exiting.
        exit $returnCode
      fi
    fi
*D GKR3U405.26,GKR3U405.28   
*D GKR3U405.31,GKR3U405.32   
    export OPRESTART=3  # indicates run automatically resubmitted
    ROVING=$ROVING
    if test "$ROVING" = true; then
      echo "Resubmit roving job"
      echo "Synchronising files across platform:"
      syncFiles $USER $RUNID $DATAW exeLocation
      if test $ATMOS = true -a $RECONA = true; then
        syncFiles $USER $RUNID $DATAW astartLocation
      fi
      if test $OCEAN = true -a $RECONO = true; then
        syncFiles $USER $RUNID $DATAW ostartLocation
      fi
      echo "Subsequent run may work even if the above failed because"
      echo "they will retry to synchronise if they need to"
      qsubCmd1="qsub -x -r $JOBNAME -o $OUTFILE -s \
                            /bin/ksh $JOBDIR/qsubmit.$thisHost"
      qsubCmd2="qsub -x -r $JOBNAME -o $OUTFILE -s \
                            /bin/ksh $JOBDIR/qsubmit.$otherHost"
      setRoving "\$qsubCmd1" "\$qsubCmd2" $(basename $OUTFILE)
      returnCode=\$?
      if test \$returnCode -eq 0; then
        echo "Run successfully submitted as roving job"
      elif test \$returnCode -eq 2; then
        echo "Run submitted as a non-roving job"
      else
       echo "Run not submitted to either machine"
      fi
    else
      thisHost=`hostname`
      qsub -x -r $JOBNAME -o $OUTFILE -s \
            /bin/ksh $JOBDIR/qsubmit.\$thisHost
      CC=\$?
*D GKR3U405.34,GKR3U405.44   
      if test \$CC -eq 0
      then
        echo "qsresubmit: submitted job successfully"
      elif test \$CC -eq 1
      then
        echo "qsresubmit: job not resubmitted due to user error:"
        echo qsub -x -r $JOBNAME -o $OUTFILE -s /bin/ksh \
        $JOBDIR/qsubmit.\$thisHost
      elif test \$CC -eq 2
      then
        echo "qsresubmit: job not resubmitted due to NQS error"
      fi
*D GKR3U405.46
*D GKR3U405.50
*DC qsprelim
*I ARR5U405.2
#LL    4.5+   23/02/00 Roving Jobs mod. S.D.Mullerworth
*D qsprelim.463
UNIT02=$PPXREFU
*D qsprelim.464
UNIT18=$AGRIB
*D qsprelim.468
export UNIT02 UNIT18
*D GLW2U402.10
  if test $RECONA = true
*D GLW2U402.13
*I qsprelim.497   
    # Roving Job: Set current location information for start dump
    if test "$ROVING" = true; then
      setLocation $RUNID astartLocation `hostname`
      returnCode=$?
      if test $returnCode -ne 0; then
        echo Cannot store location information for new atmos start dump
        echo Therefore exiting.
        exit $returnCode
      fi
    fi
*D GLW2U402.19

  if test $RECONO = true
*I GLW2U402.21    
    # Roving Job: Set current location information for start dump
    if test "$ROVING" = true; then
      setLocation $RUNID ostartLocation NONE
      returnCode=$?
      if test $returnCode -ne 0; then
        echo Cannot store location information for new ocean start dump
        echo Therefore exiting.
        exit $returnCode
      fi
    fi
*I qsprelim.518   
    fi
    # Roving Job: Set current location information for start dump
    if test "$ROVING" = true; then
      setLocation $RUNID ostartLocation `hostname`
      returnCode=$?
      if test $returnCode -ne 0; then
        echo Cannot store location information for new ocean start dump
        echo Therefore exiting.
        exit $returnCode
      fi
*DC qsresubmit
*I GKR3U404.47
#LL    4.5+   23/02/00 Roving Jobs mod. S.D.Mullerworth
*D GLW6U400.4,GLW6U400.6    
OUTPUT_D=`date +%y%j`
OUTPUT_T=`date +%H%M%S`
OUTPUT_SUBID=d$OUTPUT_D.t$OUTPUT_T
*D GSM0U403.2
*D GLW6U400.22,GKR3U304.29   
    ROVING=$ROVING
    if test "$ROVING" = true; then
      echo "Automatic resubmission of roving job"
      echo "Synchronising files across platform:"
      syncFiles $USER $RUNID $DATAW exeLocation
      syncFiles $USER $RUNID $DATAW restartLocation
      echo "Subsequent run may work even if the above failed"
      qsubCmd1="qsub -x -r $JOBNAME -o $OUTFILE -s \
                            /bin/ksh $JOBDIR/qsubmit.$thisHost"
      qsubCmd2="qsub -x -r $JOBNAME -o $OUTFILE -s \
                            /bin/ksh $JOBDIR/qsubmit.$otherHost"
      setRoving "\$qsubCmd1" "\$qsubCmd2" $(basename $OUTFILE)
      returnCode=\$?
      if test \$returnCode -eq 0; then
        echo "Run successfully submitted as roving job"
      elif test \$returnCode -eq 2; then
        echo "Run submitted as a non-roving job"
      else
       echo "Run not submitted to either machine"
      fi
    else
      thisHost=`hostname`
      qsub -x -r $JOBNAME -o $OUTFILE -s \
            /bin/ksh $JOBDIR/qsubmit.\$thisHost
      CC=\$?
*D GKR3U304.31,GGH2U401.19   
      if test \$CC -eq 0
      then
        echo "qsresubmit: submitted job successfully"
      elif test \$CC -eq 1
      then
        echo "qsresubmit: job not resubmitted due to user error:"
        echo qsub -x -r $JOBNAME -o $OUTFILE -s /bin/ksh \
        $JOBDIR/qsubmit.\$thisHost
      elif test \$CC -eq 2
      then
        echo "qsresubmit: job not resubmitted due to NQS error"
      fi
    fi
