#! /bin/sh

#
# GIF Script : gempak_gif3.sh
#
# Log :
# D.W.Plummer/NCEP   2/97   Add log header
# D.W.Plummer/NCEP  12/97   Added NGM v. ETA plot comparison if NGM precedes ETA
# J. Carr/HPC        8/98   Changed map to medium resolution
# J. Carr/HPC        1/99   Changed contur from 1 to 2 per OM request
# J. Carr/HPC        2/99   Changed skip to 0 per OM request
# B. Gordon/NCO      5/00   Ported to IBM-SP, Standardized for production,
#                           changed gdplot_nc -> gdplot2_nc
# B. Gordon/NCO      4/01   Modified to make individual GIF images.
# L. Sager/NCO       8/07   Modified for African graphics
#

#set -xa

export PS4='GIF3:$MAPAREA$SECONDS + '

cd $DATA
if [ ! -d $DATA/gif3 ] ; then
  mkdir $DATA/gif3
fi
cd $DATA/gif3
sh $utilscript/setup.sh

RAN=r
if [ $MAPAREA = "samer" -o $MAPAREA = "africa" ]
then
   RAN=" "
fi

cp $FIXgempak/datatype.tbl datatype.tbl
#
# Need the next file in the current corking directory to create
# GIF images with a white background.
#
cp $FIXgempak/coltbl.xwp.wbg coltbl.xwp

#files=" 03 06 12 24 36  "
files=" 06 12 24 36  "
nx=$files
if [ $fhr -lt 38 ]
then
   nx=""
   for fxx in $files
   do
      if [ $fxx -le $fhr ]
      then
         nx=`echo $nx $fxx`
      fi
   done
fi

for nfile in $nx
do

  prec=$nfile
  if [ "$nfile" -eq 06 ]
     then
     prec=$precip_inc
  fi

  $GEMEXE/gdplot2_gif << EOF
\$MAPFIL= mepowo.gsf
GDFILE	= F-${MODEL2} | ${PDY2}/${cyc}00
GDATTIM	= F${fhr}      
PANEL	= 0
TEXT	= .8/2/2/c/sw
CONTUR	= 2
MAP	= 8     
CLEAR	= yes
CLRBAR  = 1|.8/2/2/sw

GAREA   = $GAREA
PROJ    = $PROJ
LATLON  = 0

restore ${USHgempak}/restore/p06m_pmsl.2.gif.nts
DEVICE  = gif | ${RUN}_p${nfile}_${fhr}s.gif  | 640  ; 480 
GDPFUN  = p${prec}i
TYPE    = f
TITLE   = 1/0/ $TITLEIT !0
CLEAR   = yes
$RAN
TITLE   = 1/2/~ ${MODEL} ${prec}-HR TOTAL PCPN!0
TEXT    =.8/2/2/c/sw
GDPFUN  =
CLEAR   =no
$RAN
restore ${USHgempak}/restore/p06m_pmsl.2.gif.nts
DEVICE  = gif | ${RUN}_p${nfile}_${fhr}m.gif  | 1024 ; 768
GDPFUN  = p${prec}i
TYPE    = f
TITLE   = 1/0/ $TITLEIT !0
CLEAR   = yes
r
TITLE   = 1/2/~ ${MODEL} ${prec}-HR TOTAL PCPN!0
TEXT    =.8/2/2/c/sw
GDPFUN  =
CLEAR   =no
r
restore ${USHgempak}/restore/p06m_pmsl.2.gif.nts
DEVICE  = gif | ${RUN}_p${nfile}_${fhr}l.gif  | 1280 ; 1024
GDPFUN  = p${prec}i
TYPE    = f
TITLE   = 1/0/ $TITLEIT !0
CLEAR   = yes
$RAN
TITLE   = 1/2/~ ${MODEL} ${prec}-HR TOTAL PCPN!0
TEXT    =.8/2/2/c/sw
GDPFUN  =
CLEAR   =no
$RAN


EOF

#####################################################
# GEMPAK DOES NOT ALWAYS HAVE A NON ZERO RETURN CODE
# WHEN IT CAN NOT PRODUCE THE DESIRED GRID.  CHECK
# FOR THIS CASE HERE.
#####################################################
ls -l *${fhr}*.gif
export err=$?
if [ $err -ne 0 ] ; then
  ps -ef
  cp /tmp/xlogfile $DATA/
fi
export pgm="GEMPAK CHECK FILE";err_chk

mv *${fhr}*.gif $DATA

#
done
