#!/bin/ksh
################################################################################
####  UNIX Script Documentation Block
#                      .                                             .
# Script name:         exnam_prdgen.sh
# Script description:  Run nam product generator jobs
#
# Author:        Eric Rogers       Org: NP22         Date: 1999-06-23
#
# Abstract: This script runs the Nam PRDGEN jobs
#
# Script history log:
# 1999-06-23  Eric Rogers
# 1999-08-25  Brent Gordon  Modified for production, removed here file.
# 2003-03-21  Eric Rogers  Modified for special hourly output
# 2006-10-31  Eric Rogers  Added 6,7th PRDGEN step to make NAM grids for AFWA
#                          (3-hourly only)
# 2008-08-14  Eric Rogers  Added 8th PRDGEN step to make expanded 32 km output grid 
#                          (3-hourly only)
# 2010-12-07  Eric Rogers  Modified for NAM nested output
#

set -xa
msg="JOB $job HAS BEGUN"
postmsg "$jlogfile" "$msg"

cd $DATA

#
# Get needed variables from exnam_prelim.sh.sms
#
. $GESDIR/${RUN}.t${cyc}z.envir.sh

########################################################
# Create a script to be poe'd
#

for fhr in $fcsthrs
do
  ln -s -f $COMIN/${RUN}.${cycle}.${domain}nest.bgdawp${fhr}.tm00 ${domain}.BGDAWP${fhr}.tm00

  mkdir -p $DATA/prdgen_${domain}_${fhr}

  y=`expr $fhr % 3`

  if [ $domain != firewx ] 
  then
    cp $PARMnam/nam_master_${domain}nest.ctl $DATA/prdgen_${domain}_${fhr}/master1.${fhr}.ctl
  fi
  echo "$USHnam/nam_prdgen_nest.sh $fhr $y" >> $DATA/poescript_${domain}nest

done
chmod 775 $DATA/poescript_${domain}nest
export MP_PGMMODEL=mpmd
export MP_CMDFILE=$DATA/poescript_${domain}nest
#
# Execute the script.
poe
export err=$?; err_chk

########################################################

echo EXITING $0
exit
#
