#!/bin/sh
export member=afoscmpanl.sh
USAGE="usage: afoscmpanl.sh afosfile control passcards "
DATE="$member 2000-01-21 16:30L "
VERS="Starting: ${USHutil}/${DATE}"
#______________________________________________________________________________
# NAME     : afoscmpanl.sh
# Author   : Peter Henrichsen
# Purpose  : This script runs the afcmpanl program to make the passcards
#            file into two AFOS MAPS. They are:
#          : L0F (freezing level analysis) and 
#            I0P (precipitable water analysis)
# History  : 97-08-04 Peter Henrichsen
#           :1999-11-03 Peter Henrichsen modify to run on IBM SP.
#           :1999-12-15 Peter Henrichsen modify to pass sndfrc to script
#            snd2forgn and to use USHutil
#           :2000-01-21 Peter Henrichsen modify to change afrg "job" to lower
#            case and to change 'pillist1' to graph_pillist1 .
#
# Location : This script is found on hp36 as:
#          : /tmp_mnt/export/sgi73/peterhen/util/scripts/ibm/afoscmpanl.sh
#          : & on ncosp as :
#          : /nwprod/util/ush/afoscmpanl.sh
#          : /user/g02/wx12ph/util/ush/afoscmpanl.sh
#
#             
# Usage    : This script runs in both cycles of job 314.  
#
# Arguments: afosfile   - output afos filename
#            control    - input data cards file in PARMgraph  
#            passcards  - the passed card file form previous airpltaf step      
#                       
#______________________________________________________________________________
#
integer istat
cd $DATA

print "$USAGE"
print "$VERS"

num=$#
if test $num -ne 3
then
  echo "You need 3 input variables."
  err_exit
fi
postmsg  "$jlogfile" "$VERS"

afosfile=$1
control=$2
passcards=$3

echo afosfile=$afosfile
echo control=$control
echo passcards=$passcards

set -x 
pgm=afcmpanl

export pgm; prep_step

export XLFRTEOPTS="unit_vars=yes"


# input files

export XLFUNIT_10="$DATA/$passcards"            # passed card file
export XLFUNIT_16="$PARMutil/$control"         # control cards 
#export XLFUNIT_20="$FIXutil/graph_pillist1"     # AFOS pillist file
export XLFUNIT_20="/nwprod/util/fix/graph_pillist1"     # AFOS pillist file

#   out put files

export XLFUNIT_71="$DATA/$afosfile"            # the output AFOS file
export XLFUNIT_75="$DATA/afanalmsg.$pid"       # the consol message file.
  
startmsg

 
$EXECutil/afcmpanl PARM="C" >> $pgmout 2> errfile
istat=$? 
echo ${pgm}: Ended with return code = $istat

if [ "$istat" -eq 0 ]
then
  msg=`grep -i MADE $DATA/afanalmsg.$pid \
  | awk '{for(i=4;i<=NF;i++) printf("%s ", $i)}'`
   msg3="${pgm} ${msg}"   
   postmsg  "$jlogfile" "$msg3"
   err=$?;export err;err_chk 
      
   msg1=`grep -i MADE $DATA/afanalmsg.$pid \
  | awk '{for(i=12;i<=NF;i++) printf("%s ", $i)}'` 
     
   if test "$SENDCOM" = 'YES'
   then
     cp $afosfile $pcom/$afosfile
   fi

   if test "$SENDDBN" = 'YES'
   then

    sndfrc=0
     echo $sndfrc >$DATA/sndfrc 
     
     $USHutil/snd2forgn AFOS ${model} $job $pcom/$afosfile
            
       read sndfrc < $DATA/sndfrc
       
      if test $sndfrc -eq '0'
      then         
        msg="Afosmaps $msg1 WERE POSTED!" 
        postmsg "$jlogfile" "$msg"
        msg="$member HAS COMPLETED NORMALLY!" 
      else
        msg="ERROR AFOS MAPS $msg1 NOT POSTED!"
        postmsg "$jlogfile" "$msg"
        msg="${pgm}: ABNORMAL STOP = $sndfrc!:" 
      fi
      rm  $DATA/sndfrc
      
   fi
else
  msg3="${pgm}: ERROR AFOS MAPS, L0F and I0P, NOT MADE!:"
  postmsg "$jlogfile" "$msg3"
  msg3="${pgm}: ABNORMAL STOP = $istat!:"
  postmsg "$jlogfile" "$msg3"
fi
set -x 

echo " "
echo "Leaving shell script afoscmpanl.sh"
echo " "
 
