#!/bin/sh
USAGE="usage: postrdr.sh filename mach dir test"
#VERS="version: ${USHutil}/runcacaf 2000-03-21 06:35L"
#in production $USHutil}=/nwprod/util/ush/
#
#______________________________________________________________________________
# NAME     : postrdr.sh
# Author   : Peter Henrichsen
# Purpose  : The postrdr.sh is the parent script for sndrdr.sh .
#          : postrdr.sh sets up and exports the files, scripts and
#          : directories needed by sndrdr.sh. Then it llsubmit's a job  
#          : to run the sndrdr.sh script which sends the
#          : OSO radar summary chart to NCDC .
#
#          : The postrdr.sh script requires two arguements, the full 
#          : path of the OSO fax radar summary chart nad the machine name.
#
# Started  : by dbnet
#
# History  : 97-04-18 15:15L Peter Henrichsen
#          : 1999-07-06 Peter Henrichsen modify to run on the IBN NCO SP
#          : 1999-12-02 Peter Henrichsen modify to use USHutil.
#          : 2000-03-21 Peter Henrichsen modified so that
#            dbnet can run the script.
#
# Location : This script is found on hp36 as:
#          : /tmp_mnt/export/sgi73/peterhen/util/scripts/ibm/postrdr.sh
#          : & on ncosp as          
#          : /nwprod/util/ush/postrdr.sh or
#          : /nfsuser/g02/wx12ph/util/ush/postrdr.sh           
#
#Argumemts:  'filename' input FAX radar file (fullpath)
#          .  obtained from OSO's tgsv1 work station by dbnet.
#          : 'mach' is the name of the workstation where FAX  
#          : file was obtained.
#          : The 3th & 4th args are optional "dir" & "test" are used in
#          : testing.
#          : Arg 3 is the test base dir for the fix, ush, sorc & exec.
#           ie /nfsuser/g01/wx12ph or /nwtest.
#          : Arg 4 is used to send in test mode if it is "send".       
#
# Example  :
#           postrdr.sh /pcom/foreign/faxx/FAXRADAE.1234 tgsv1   
#           where:
#	      "/pcom/foreign/faxx/FAXRADAE.1234" is the input FAX radar file
#               obtained from OSO's tgsv1 work station by dbnet.
#
#
#_______________________________________________________________________________

#
integer   istat
export PATH=${PATH}:
set -x

# export child script name.


export MEMBER=sndrdr.sh
 
#___________________________________________________________________________
#    get varables to exportation to child scripts $MEMBER .
#___________________________________________________________________________

export INFILE="$1"
export MACH="$2"
export USR="$2"
export NAME=faxrdr
export whatdir=faxrdr
  
 if test $# -ge 3
 then
  envir=test
  export homedir="$3"
  export HOMEutil=$homedir 
  comout=$HOMEutil/com/foreign/$envir 
  export HOMEout=/tmpuser/$LOGNAME
  pcom=$HOMEutil/pcom/foreign/faxx 
   if test $# -eq 4
   then

    what="$4"
     if test "$what" = 'send'
     then
      envir=prod
      SENDCOM=YES
      SENDDBN=YES
     else 
      envir=test
      SENDCOM=NO
      SENDDBN=NO
     fi   
   fi  
  else
   envir=prod
   SENDCOM=YES
   SENDDBN=YES
   who=$LOGNAME
    if test "$who" = 'dbnprd'
    then
      export HOMEout=/tmpnwprd/dbnprd
    else
      export HOMEout=/tmpuser/dbnprd    
    fi
    export HOMEutil=/nwprod  
    comout=/com/foreign/$envir
    pcom=/pcom/foreign/faxx
 fi
#
# ########################################
# Set up this job's temporary directory to
# store processing files.
# ########################################

export DATA=$HOMEout/$whatdir.$$
mkdir -m 775 -p $DATA  >/dev/null 2>&1  
export FIXutil=$HOMEutil/util/fix
export EXECutil=$HOMEutil/util/exec
export USHutil=$HOMEutil/util/ush
export utilities=$HOMEutil/util/ush

export envir SENDCOM SENDDBN
mkdir -m 775 -p  $pcom >/dev/null 2>&1
mkdir -m 775 -p  $comout >/dev/null 2>&1 
cd $DATA 
  
echo "  set the CYCLE"
CYCLE=t00z
cycle=$CYCLE
export CYCLE cycle

# run setup to initialize working directory and utility scripts
 
export utilexec=/nwprod/util/exec
export utilscript=/nwprod/util/ush

# Run setup to initialize working directory and utility scripts
sh $utilscript/setup.sh

# Run setpdy and initialize PDY variables
sh $utilscript/setpdy.sh

. ./PDY

job=FN$MACH

jlogfile=/com/logs/snd2forgn_log 

export time=`date +"%d%H%M%S` 
export pid=$$ 
export reqid=${$}

export pgmout=$job.$NAME.$pid
jobid="${job}.o${reqid}"

model=osoRADAR

export output=output.$job.$NAME.$pid
export comout envir jlogfile jobid model pcom job  

# _______________________________________________________________________
#   start the $MEMBER 
# _______________________________________________________________________

$USHutil/$MEMBER>>$DATA/$pgmout 1>>$DATA/$pgmout 2>>$DATA/$pgmout

 cd
rm -rf  $DATA

exit 

