# UTILITY SCRIPT NAME : mkmercfax36.sh
#              AUTHOR : Mary Jacobs
# 
# ABSTRACT : This utility script produces the GFS mercator FAX CHARTS
#            using two input grib files.
#            NOTICE:  NO INPUTS, THE PG FILES ARE HARDCODED!!
#
# INPUT: 
#         4th argument - execparm - executable parm
#         5th argument - output file in products directory
#         
#

set -x
hour=$1
out=$2
sendkey=$3
num=$#

if test "$num" -eq 3
then
   set +x
   echo " Appropriate number of arguments were passed"
   set -x
   export EXECgraph=${EXECgraph:-/nwprod/util/exec}
   export PARMgraph=${PARMgraph:-/nwprod/util/parm}
   export FIXgraph=${FIXgraph:-/nwprod/util/fix}
   export envir=${envir:-prod}
   export jlogfile=${jlogfile:-jlogfile}
   export NET=${NET:-gfs}
   export RUN=${RUN:-gfs}
   export cyc=${cyc:-00}
   export cycle=${cycle:-t${cyc}z}
   export SENDCOM=${SENDCOM:-NO}
   export SENDDBN=${SENDDBN:-NO}
   if [ -z "$DATA" ]
   then
      export DATA=`pwd`
      cd $DATA
      /nwprod/util/ush/setup.sh
      /nwprod/util/ush/setpdy.sh
      . PDY
   fi
   export COMIN=${COMIN:-/com/$NET/$envir/$NET.$PDY}
   export pcom=${pcom:-/pcom/$NET}
   export job=${job:-interactive}
   export pgmout=${pgmout:-OUTPUT.$$} 
else
   set +x
   echo ""
   echo "Usage: mkmercfax.sh <hour> <out> <foreign>"
   echo ""
   exit 16
fi

set +x
echo "########################################################"
echo "#  Entering Utility  mkmercfax.sh"
echo "#  Make the VARIAN FAX CHART $out maps"
echo "########################################################"
set -x
   
msg="Enter Make MERCFAX utility."
postmsg "$jlogfile" "$msg"

export pgm=mercfaxv;. prep_step
 
case $hour in
 24)
  cp ${COMIN}/${RUN}.${cycle}.pgrbf18 pgrbf18
  cp ${COMIN}/${RUN}.${cycle}.pgrbif18 pgrbif18
  cp ${COMIN}/${RUN}.${cycle}.pgrbf24 pgrbf24
  cp ${COMIN}/${RUN}.${cycle}.pgrbif24 pgrbif24
  cp $FIXgraph/graph_mercfax24.ft8.${cycle} mercfax24.ft8.${cycle}
  cp $PARMgraph/graph_mercfax24.parm.${cycle} mercfax.parm.${cycle}
  export XLFUNIT_8="mercfax24.ft8.${cycle}"
  export XLFUNIT_32=pgrbif18
  export XLFUNIT_12=pgrbf18
  export XLFUNIT_33=pgrbif24
  export XLFUNIT_13=pgrbf24
 ;;
 36)
  cp ${COMIN}/${RUN}.${cycle}.pgrbf30 pgrbf30
  cp ${COMIN}/${RUN}.${cycle}.pgrbif30 pgrbif30
  cp ${COMIN}/${RUN}.${cycle}.pgrbf36 pgrbf36
  cp ${COMIN}/${RUN}.${cycle}.pgrbif36 pgrbif36
  cp $FIXgraph/graph_mercfax36.ft8.${cycle} mercfax36.ft8.${cycle}
  cp $PARMgraph/graph_mercfax36.parm.${cycle} mercfax.parm.${cycle}
  export XLFUNIT_8="mercfax36.ft8.${cycle}"
  export XLFUNIT_34=pgrbif30                     
  export XLFUNIT_14=pgrbf30                     
  export XLFUNIT_35=pgrbif36                   
  export XLFUNIT_15=pgrbf36                   
 ;;
esac

cp ${FIXgraph}/graph_gphbg/mr4002.pur mr4002.pur

export XLFUNIT_11="mr4002.pur"
export XLFUNIT_55="putlab.55"              
export XLFUNIT_60="f60"              
export XLFUNIT_61="f61"                    
export XLFUNIT_62="f62"                   
export XLFUNIT_63="f63"                 
export XLFUNIT_71="ras"                
export XLFUNIT_80="f80"               
export XLFUNIT_81="$out"             

startmsg 
$EXECgraph/mercfaxv < mercfax.parm.${cycle} >> $pgmout 2> errfile
err=$?;export err;err_chk
 
if test "$SENDCOM" = 'YES'
then
  cp $out $pcom/$out
  if test "$SENDDBN" = 'YES'
  then
    $utilities/snd2forgntbl.sh $sendkey $out $pcom
  else
    echo "SENDDBN=$SENDDBN, files not posted to db_net."
  fi
fi
 
set +x

echo " "
echo "LEAVING mkmercfax.sh"
echo " "
