#!/bin/ksh
######################################################
echo "-----------------------------------------------" 
echo "     exhwrf_nmm_gsi_d2.sh.sms                  "
echo "   Hurricane model control script              "
echo "-----------------------------------------------" 
######################################################
set -x

PS4=' + exhwrf_nmm_gsi_d2.sh.sms line $LINENO: ' 

#-----------------------------------------------------
# Be sure that there is a holdvars.txt file, and source 
# it because it contains needed environmental variables 
# from the JHWRF_PRE_MASTER job that need to be passed 
# into this script
#----------------------------------------------------- 
sh ${utilscript}/setup.sh
export pgm=exhwrf_nmm_gsi_d2.sh.sms
. prep_step
startmsg

if test -f ${COMOUT}/${stormlabel}.holdvars.txt
then
   . ${COMOUT}/${stormlabel}.holdvars.txt
else
   set +x
   echo " "
   echo "!!! ERROR: holdvars.txt file missing"
   echo " "
   set -x
   msg="Hurricane to Run But No ${stormlabel}.holdvars.txt file found."
   postmsg "$jlogfile" "$msg"
   export err=911;err_chk
   err_exit "Hurricane to Run But No ${stormlabel}.holdvars.txt file found."
fi
#-------------------------------------------------------

# Run the script  
if [ ${GSI} == YES ]; then
    ${USHhwrf}/hwrf_nmm_gsi_d2.sh $STORM $YYYY $MM $DD $CYC $STORM_LAT $STORM_LON  
    export err="$?";err_chk

    msg="GSI script hwrf_nmm_gsi_d2.sh failed with exit status $err"
    if [[ "$err" != 0 ]] ; then
        postmsg "$jlogfile" "$msg.  Will continue, but possibly without data assimilation."
        if [[ "$PARAFLAG" == YES ]] ; then
            # In para mode, abort here.
            err_exit "$msg"
        fi
    fi
else
   echo 'GSI/3DVAR not requested.  GSI = $GSI This script need not be run'
   msg="Hurricane to Run But GSI is not requested."
   postmsg "$jlogfile" "$msg"
   export err=0;err_chk
fi

# end of script 
