#!/usr/bin/ksh

set +x
#####################################################################
echo "----------------------------------------------------------"
echo "gfdl_post_swath_precip.sh  "
echo "----------------------------------------------------------"
echo "History: MAY 2005 - First implementation of this new script."
#####################################################################
set -x

PS4=' + gfdl_post_swath_precip.sh line $LINENO: '

#####################################################################
# MAKE UNIQUE DIRECTORY FOR PROCESSING TO RUN IN
#####################################################################
mkdir ${DATA}/swath_precip
cd ${DATA}/swath_precip

$utilities/setup.sh

ih_check=` cat $COMIN/$ATCFNAME.ihours`
if [ ${ih_check} -lt 0 ]
then
  echo "  1" >tmphrs
  mv tmphrs $COMIN/$ATCFNAME.ihours
fi
     
echo $NMO       > nmo
echo $HRIN      > hrin
echo $DAY       > day
echo $STORMENV  > stormenv
echo ${Y4PREFIX}$YEARA   > yeara
cp ${COMIN}/coupled_status.${ATCFNAME}.${PDY}${cyc} .

export pgm=gfdl_precip
. prep_step

ln -s -f coupled_status.${ATCFNAME}.${PDY}${cyc}   fort.2
ln -s -f $COMIN/$ATCFNAME.swath                    fort.9
ln -s -f $COMIN/$ATCFNAME.swathc                   fort.36
ln -s -f $COMIN/$stormenv.${PDY}${cyc}.precip.asci fort.77
ln -s -f $COMIN/$ATCFNAME.ihours                   fort.78
ln -s -f nmo                                       fort.31
ln -s -f hrin                                      fort.32
ln -s -f day                                       fort.33
ln -s -f stormenv                                  fort.34
ln -s -f yeara                                     fort.35

startmsg
$EXEChur/gfdl_precip >> $pgmout 2>errfile
export err=$?
if [ $err -ne 0 ] ; then
  postmsg "$jlogfile" "GFDL PRECIP PS FILE NOT AVAILABLE -- NON FATAL"
fi

if [ -e $COMIN/$stormenv.${PDY}${cyc}.precip.asci ] ; then
  if [ $SENDDBN = 'YES' ] ; then
    $DBNROOT/bin/dbn_alert MODEL GFDL_ASCII $job $COMIN/$stormenv.${PDY}${cyc}.precip.asci
  fi
else
  echo "FILE $COMIN/$stormenv.${PDY}${cyc}.precip.asci DOES NOT EXIST"
fi
     
rm stormenv yeara

#################################################################
# The generated meta file and postscript version will be stored in
# /com region for NHC to ftp to their site.....>
#################################################################
if test $SENDCOM = 'YES'
then
  cp gmeta gmeta.precip
  cp gmeta $COMOUT/$stormenv.${YMDH}.precip.meta
  ctrans -d ps.mono  gmeta   > precip
  mv precip $COMOUT/$stormenv.${YMDH}.precip.ps
fi
