#!/bin/sh
#########################################################################
#									#
# Script:  nam_bfr2gpk							#
#									#
#  This script reads nam BUFR output and transfers it into GEMPAK	#
#  surface and sounding data files.					#
#									#
# Log:									#
# K. Brill/HPC		11/28/01					#
#########################################################################  
set -x

# Set GEMPAK paths.

. /nwprod/gempak/.gempak

#  Go to a working directory.

cd $DATA

#  Set input file name.

INFILE=$COMIN/nam.t${cyc}z.class1.bufr.tm00
export INFILE

#  Set output directory:

OUTDIR=$COMAWP

outfilbase=nam_${PDY}${cyc}

namsnd << EOF > /dev/null
SNBUFR   = $INFILE
SNOUTF   = ${outfilbase}.snd
SFOUTF   = ${outfilbase}.sfc+
SNPRMF   = sneta.prm
SFPRMF   = sfeta.prm
TIMSTN   = 85/2000
r

exit
EOF

/bin/rm *.nts

snd=${outfilbase}.snd
sfc=${outfilbase}.sfc
aux=${outfilbase}.sfc_aux
cp $snd $OUTDIR/.$snd
cp $sfc $OUTDIR/.$sfc
cp $aux $OUTDIR/.$aux
mv $OUTDIR/.$snd $OUTDIR/$snd
mv $OUTDIR/.$sfc $OUTDIR/$sfc
mv $OUTDIR/.$aux $OUTDIR/$aux

if [ $SENDDBN = "YES" ]
then
   $DBNROOT/bin/dbn_alert MODEL SFC_NAM $job $OUTDIR/$sfc
   $DBNROOT/bin/dbn_alert MODEL SFC_NAM $job $OUTDIR/$aux
   $DBNROOT/bin/dbn_alert MODEL SND_NAM $job $OUTDIR/$snd
fi
echo done > $DATA/gembufr.done
