#####################################################################
echo "-----------------------------------------------------"
echo " wfs_time_stat_processing.sh.sms" 
echo " DEC 2005 - Cooke - Generates a flat file for TOC containing"
echo "                    creation and receipt times by WMOID for"
echo "                    wfs gfs products ."
echo " DEC 2006 - Cooke - Modified for use on Mist/Dew"
echo " APR 2009 - Cooke - Modified for use on Cirrus/Stratus"
echo " DEC 2009 - Cooke - Modified to use new TOC push logs"
echo "-----------------------------------------------------"
#####################################################################

set -x

cd $DATA

msg="HAS BEGUN on `hostname`"
postmsg "$jlogfile" "$msg"


count=0
 
while [ $count -le 5 ]
do
   
  # Grab the TOC push logs from the dbnet nodes on Stratus and Cirrus 

  scp nwprod@192.58.3.205:/iodprod/dbnet/log/TOC_push.log.${PDY} stratus_toc_push.log.${PDY}
  scp nwprod@192.58.3.205:/iodprod/dbnet/log/TOC_push2.log.${PDY} stratus_toc_push2.log.${PDY}
  scp nwprod@140.90.226.205:/iodprod/dbnet/log/TOC_push.log.${PDY} cirrus_toc_push.log.${PDY}
  scp nwprod@140.90.226.205:/iodprod/dbnet/log/TOC_push2.log.${PDY} cirrus_toc_push2.log.${PDY}

  cat cirrus_toc_push.log.${PDY} cirrus_toc_push2.log.${PDY} \
      stratus_toc_push.log.${PDY} stratus_toc_push2.log.${PDY} > toc_push.log.${PDY} 

  # Call perl script to create output stat file

  ${USHGLOBAL}/wfs_stat_gathering.pl
 
  # If script returns error (missing data), wait 5 minutes and try again
 
  if [ $? -ne 0 ]
  then
    count=`expr $count + 1`
    sleep 300
    err=1;
  else
    err=0;
    break
  fi
done

   
if [ -s $COMOUT/wfsgfs_log_times.${PDY} ]
then 
   if test $SENDDBN = "YES"
   then
       $DBNROOT/bin/dbn_alert MODEL WFS_STATS $job $COMOUT/wfsgfs_log_times.${PDY}
   fi
fi

#  check if any problems with processing

${utilscript}/err_chk.sh
                                                                                                                
#####################################################################
                                                                                                                
# GOOD RUN
set +x
echo "**************JOB $job COMPLETED NORMALLY ON THE IBM"
set -x
                                                                                                                
msg="JOB $job HAS COMPLETED NORMALLY."
echo $msg
postmsg "$jlogfile" "$msg"
                                                                                                                
