# QSUB -q para1
# QSUB -x
# QSUB -eo -lM 35MW -lT 500 -r postqq
# QSUB -s /bin/sh
#
date
#-----------------------------------------------------------------------
# Initial setup.
# Each post job gets a unique .assign file (.asgn01, .asgn02, etc.)     .
# This was done so that multiple post jobs could run at the same
# time in the same directory.  This could happen if the model
# submits external post jobs.
#

# Convert the restrtxx file from its 2-dimensional form coming out
# of the model to the 1-dimensional form required by the post.
cd $DATA
ASSIGN=.asgnxx
FILENV=$ASSIGN
export FILENV

RESTRT=restrtxx
NCPUS=10
export FILENV NCPUS

fcsthr=qq
tmmark=tm00
export tmmark
cd $DATA
pwd
ls -x
#
#-----------------------------------------------------------------------
#   Set variables.  File restrtxx contains model variables from almost
#   all common blocks in the model.  This file and nfile nhb contain
#   everything needed to run the post or restart the model.  The
#   external post reads these files, posts requested fields on requested
#   grids, and then removes these files.  The remove is at the end of
#   this script.
#
#
#-----------------------------------------------------------------------
#   Copy control file, weights, lastjob cleanup script, and executable
#   to working directory.
#
#   NOTE:
#      When running the post after the model but within the same
#      job it is more efficient to place the copies below within
#      the script that runs the model.  Only if the post is run
#      as a separate batch job outside that which runs the model
#      are the copies below necessary.
#
#-----------------------------------------------------------------------
#   Assign the input/output files.  The control file (the file telling
#   the post what fields to post, what grid to post the fields to, and
#   the format of the posted data) is read from unit 4.  Runtime output
#   is written to unit 6.  For ON84 packing the actual ON84 labels packed
#   with the data is written to unit 86.  For Grib1 packing the unpacked
#   PDS is written to unit 85.  Both unit 85 and 86 runtime output are
#   holdovers from the debugging days of the post.  They are retained
#   just in case anything goes wrong.  Subroutine OUTPACK contains the
#   write to unit 86.  Subroutine GRIBIT contains the write to unit 85.
#   The post processor reserves units 5, 7, and 8 for input to the post.
#   Unit 7 reads nfile nhb from the model run.  Unit 5 reads namelist
#   fcstdata from the model run.  Unit 8 reads the restart file generated
#   from within the model by subroutine CHKOUT.  Weight file unit numbers
#   range from 20 to 29, starting at 20.  Lat-lon file unit numbers range
#   from 30 to 39, starting at 30.  Post processed output file unit
#   numbers start at 40.
#
assign -R
assign -a fcstdata.parm                               fort.11
assign -a nhb8038             fort.12
assign -a ${RESTRT}         fort.13
assign -a cntrl.parm                                  fort.14
assign -a wgts1                                       fort.20
assign -a wgts2                                       fort.21
assign -a wgts3                                       fort.22
assign -a wgts4                                       fort.23
assign -a wgts5                                       fort.24
assign -a wgts6                                       fort.25
assign -a omg                                         fort.81
assign -a all                                         fort.82
#
#-----------------------------------------------------------------------
#   Run etapost.
#
mpirun.lsf -p "%g of %G> " -np 6 $EXEC/etapost < $UCL/edspost.${fcsthr}.parm > outmeso.post
#
##mv outmeso.post $HOLDOUT/etapost.out${fcsthr}.${tmmark}
#------------------------------------------------------------------------
#   Clean up after output job.  If you don't want to delete the restart
#   file, comment out the rm $RESTRT.
#
##rm $RESTRT ${RESTRT}.post
rm $ASSIGN 
#
#----------------------------------------------------------------------
#   End of output job
#
date
echo "End of Output Job"
exit