#!/bin/ksh

retcode=0

REALTIME=`date +%T`
echo "REALTIME = "$REALTIME

CURDAY=`date +%A`
echo "CURDAY = "$CURDAY
MON=`date +%b`
YY=`date +%y`
MM=`date +%m`
echo "month = "$MM  $YY
YYYY=`date +%Y`
DD=`date +%d`
CURY=$YYYY$MM$DD
echo "CURDATE = "$CURY $YY  $MM   $DD

ls /data/new_SMOKE/arrH/ |grep prelim  > /data/new_SMOKE/arrH/test1

numfile=$(cat /data/new_SMOKE/arrH/test1 | wc -l)
echo 'numfile=' $numfile
x=1
missing_record=0
while [ $x -le  $numfile ]
  do
  
    FILENEW=$(head -$((x)) /data/new_SMOKE/arrH/test1 |tail -1)
    time1=`echo  $FILENEW |cut -c 11-18`
#    echo 'time1='$time1  $CURY
    if [ $time1 -lt $CURY ]
    then
      ls /data/new_SMOKE/arrH/ |grep $time1.txt > /data/new_SMOKE/arrH/test2
      check_file=$(cat /data/new_SMOKE/arrH/test2  | wc -l)
#      echo 'test1111' $check_file
      if [ $check_file -eq 0 ]
      then
       cp /data/new_SMOKE/arrH/hmshysplit$time1.prelim.txt /data/new_SMOKE/arrH/hmshysplit$time1.txt
       echo "copy" hmshysplit$time1.prelim.txt to hmshysplit$time1.txt
       export missing_record=1
      fi
    fi
    x=$x+1
 done

 echo 'missing_record =' $missing_record
 if [ $missing_record -ne 0 ]
 then
 /bin/mail -s 'smoke_hms_error' Liang.chen@noaa.gov < /home/oper/new_SMOKE/smoke_hms_error
# /bin/mail -s 'smoke_hms_error' mattew.seybold@noaa.gov < /home/oper/new_SMOKE/smoke_hms_error

# /bin/mail -s 'smoke_hms_error' jianbin.yang@noaa.gov < /home/oper/new_SMOKE/smoke_hms_error
# /bin/mail -s 'smoke_hms_error' sabsupervisor@noaa.gov < /home/oper/new_SMOKE/smoke_hms_error
# /bin/mail -s 'smoke_hms_error' espcoperations@noaa.gov < /home/oper/new_SMOKE/smoke_hms_error

 else
  /bin/mail -s 'smoke_hms_OK' Liang.chen@noaa.gov < /home/oper/new_SMOKE/smoke_hms_ok
#  /bin/mail -s 'smoke_hms_OK' Liang.chen@noaa.gov < /home/oper/new_SMOKE/smoke_hms_ok

 fi
exit
