#!/bin/ksh
################################################################################
####  UNIX Script Documentation Block
#                      .                                             .
# Script name:         exhiresw_prelim.sh.sms
# Script description:  Gets all input fields for NDAS run
#
# Author:        Eric Rogers       Org: NP22         Date: 1999-06-23
#
# Abstract: The scripts gets all the input files needed for the Nam hiresw run
#           and runs the code which interpolates the operational Nam initial condition
#           to the nested Nam domain
#
# Script description:  Runs interpolation code to create boundary conditions for the
#                      Nam hiresw run

#
# Script history log:
# 1999-06-23  Eric Rogers
# 1999-07-30  Brent Gordon  - Modified for production.
# 2000-03-03  Eric Rogers modified scripts for 60-h Nam forecast
# 2001-04-19  Eric Rogers modified NDAS scripts for hiresw runs
# 2001-11-19  Eric Rogers modified for interface w/Nam-12
# 2002-03-15  Eric Rogers modified 8-km and 4-km Meso hires window runs
# 2006-05-17  Eric Rogers modified script for creating 4-km grids from ops NAM input
#

set -x

msg="JOB $job FOR NEST=$NEST HAS BEGUN"
postmsg "$jlogfile" "$msg"

cd $DATA

echo $NEST > nestname
test4km=`cut -c 1-2 nestname`

#
# Check to see how many storms are being run by the GFDL hurricane model.
# If number is >2, do not run this hires window model.
#
if [ "$NEST" != "pr08" -a "$NEST" != "hi08" ] ; then
  $USHhiresw/hiresw_chkhur.sh
  err=$?
  if [ $err -eq 99 ] ; then
    exit
  fi
  echo "export NEST=$NEST" > $COMOUT/${RUN}.t${cyc}z.envir.sh
fi

export CYCLE=$PDY$cyc
echo "export CYCLE=$CYCLE" >> $COMOUT/${RUN}.t${cyc}z.envir.sh

if [ $test4km = hs ]
then
   export MESO4KM=YES
   echo "export MESO4KM=YES" >> $COMOUT/${RUN}.t${cyc}z.envir.sh
else
   export MESO4KM=NO
   echo "export MESO4KM=NO" >> $COMOUT/${RUN}.t${cyc}z.envir.sh
fi

#
# Check to see if 18-h NAM GRIB file is available
#
if [ -s ${COMNAM}/nam.t${cyc}z.egdawp18.tm00 ]
then
  echo "nam.t${cyc}z.egdawp18.tm00 found, continue"
else
  err_exit "nam.t${cyc}z.egdawp18.tm00 file not found.  FATAL ERROR"
fi

msg="JOB $job FOR NEST=$NEST HAS COMPLETED NORMALLY."
postmsg "$jlogfile" "$msg"
