####################################################################
echo "-----------------------------------------------------------"
echo "jgfs_meteogrm - " generate gfs BUFR format meteogram file
echo "-----------------------------------------------------------"
echo "History: AUG 2002 - First implementation of this new script."
#####################################################################

cd $DATA

#####################################################################
#
# START FLOW OF CONTROL
#
# 1) Get the Date and set COM dirs
# 2) Execute meteomrf
#    Makes BUFR format meteogram files for GFS
#
#####################################################################

set -x

########################################
msg="HAS BEGUN"
postmsg "$jlogfile" "$msg"
########################################

   set +x
   echo "##################################################"
   echo "# Run meteogram generator                         "
   echo "##################################################"
   set -x

   export JCAP=254
   export LEVS=64
   export LATB=384
   export LONB=768
   export FSTART=00
   export FEND=84
   export FINT=3
   export OUTFILE=meteomrf
   export MAKEBUFR=NO
   export F00FLAG=YES
   $USHbufr/meteomrf.sh

# Check the availability of GFS 120 hour file 
ic=0
while [ $ic -lt 1000 ]
do
   if [ ! -f $COMIN/${RUN}.${cycle}.sf120 ]; then
       sleep 10 
       ic=`expr $ic + 1`
   else
       break
   fi
done
##################################################
#  Add the T170 results
##################################################

   export JCAP=170
   export LEVS=64
   export LATB=256
   export LONB=512
   export FSTART=84
   export FEND=120
   export FINT=3
   export OUTFILE=meteomrf
   export MAKEBUFR=YES
   export F00FLAG=NO
   $USHbufr/meteomrf.sh

   if test $SENDCOM = "YES"
   then
      cp $OUTFILE $COMOUT/${RUN}.${cycle}.meteogram

      if test $SENDDBN = "YES"
      then
         # Add an entry to the OSO status file.
#
         $DBNROOT/bin/dbn_alert BUFRDUMP $NET $job \
            $COMOUT/${RUN}.${cycle}.meteogram
      fi
   fi

#####################################################################
# GOOD RUN
set +x
echo "**************JOB gfs_meteogrm COMPLETED NORMALLY ON THE IBM"
echo "**************JOB gfs_meteogrm COMPLETED NORMALLY ON THE IBM"
echo "**************JOB gfs_meteogrm COMPLETED NORMALLY ON THE IBM"
set -x
#####################################################################

msg='HAS COMPLETED NORMALLY.'
postmsg "$jlogfile" "$msg"

############## END OF SCRIPT #######################
