#! /bin/ksh
#
# Script name:         exnam_pmgr.sh.sms
#
#  This script monitors the progress of the namfcst job
# J240 and releases the post jobs.
#

set -x

export PS4='$SECONDS + '
export tmmark=tm00

#
# Wait for all fcst hours to finish 
#
icnt=1
while [ $icnt -lt 1000 ]
do
  for fhr in $postjobs
  do
    if [ -s $DATA/fcstdone${fhr}.${tmmark} ]
    then
      $SMSBIN/setev release_post${fhr}
      # Remove current fhr from list
      postjobs=`echo $postjobs | sed s/${fhr}//g`
    fi
  done
  
  result_check=`echo $postjobs | wc -w`
  if [ $result_check -eq 0 ]
  then
     break
  fi

  sleep 10
  icnt=$((icnt + 1))
  if [ $icnt -ge 540 ]
  then
    msg="ABORTING after 1.5 hours of waiting for FIREWX FCST hours $postjobs."
    err_exit $msg
  fi

done

echo Exiting $0

exit
