#!/bin/sh

#############################
# Preliminary data setup step
#############################
set -xa

# ##############################
# SET SHELL PROCESSING VARIABLES
# ##############################
export PS4='$SECONDS + '
date

##########################
# Specify NET and RUN name
##########################
export NET=${NET:-stofs}
export RUN=${RUN:-stofs_2d_glo}

##########################################################
# obtain unique process id (pid) and make temp directories
##########################################################
export pid=$$
export DATA=${DATA:-${DATAROOT}/${jobid}}

mkdir $DATA
cd $DATA

export cycle=t${cyc}z

##################
# File To Log Msgs
##################

#####################################
# Determine Job Output Name on System
#####################################
export pgmout="OUTPUT.$$"

##############################################
# SENDECF  - Flag Events on ECF
# SENDCOM  - Copy Files From TMPDIR to $COMOUT
# SENDDBN  - Issue DBNet Client Calls
##############################################
export SENDCOM=${SENDCOM:-YES}
export SENDDBN=${SENDDBN:-YES}
export SENDECF=${SENDECF:-YES}

###################################
# Set up the UTILITIES
###################################
export EXECstofs=${EXECstofs:-$HOMEstofs/exec/${RUN}}
export FIXstofs=${FIXstofs:-$HOMEstofs/fix/${RUN}}
export PARMstofs=${PARMstofs:-$HOMEstofs/parm/${RUN}}
export SORCstofs=${SORCstofs:-$HOMEstofs/sorc/${RUN}}
export SCRIstofs=${SCRIstofs:-$HOMEstofs/scripts/${RUN}}
export USHstofs=${USHstofs:-$HOMEstofs/ush/${RUN}}

#Run setpdy and initialize PDY variables
setpdy.sh

. ./PDY

###############################################
# Define input and output com directories
###############################################
export COM=${COM:-$(compath.py -o ${NET}/${stofs_ver})}
export COMIN=${COMIN:-$(compath.py ${envir}/${NET}/${stofs_ver})/${RUN}.${PDY}}
export COMOUT=${COMOUT:-$(compath.py -o ${NET}/${stofs_ver}/${RUN}.${PDY})}
export COMGES=${COMGES:-$COM/nwges}
export COMINges=${COMINges:-$(compath.py gfs/${gfs_ver})} # real-time
export COMINgfs=${COMINgfs:-$(compath.py gfs/${gfs_ver})/gfs.${PDY}/${cyc}/atmos} # real-time
export COMOUTrerun=${COMOUTrerun:-${COMOUT}/${cyc}/rerun}
mkdir -p -m 775 $COM $COMIN $COMOUT $COMGES $COMOUTrerun

env
date

##############################################
# Execute the scrpit.
  $SCRIstofs/exstofs_2d_glo_fcst_forecast.sh 
##############################################

if [ -f $pgmout ]; then
    cat $pgmout
fi


cd ${DATAROOT}
if [ ${KEEPDATA}:-YES} = NO ] ; then rm -rf $DATA ; fi

date