#!/bin/sh
# #################################
# SETUP SHELL  PROCESSING VARIABLES
# #################################
export PS4='$SECONDS + '
date
env
set -xa

export DATA=${DATA:-${DATAROOT}/${jobid}}
mkdir $DATA
cd $DATA

#######################################
# Specify NET and RUN Name and model ID
#######################################
export NET=rtofs
export RUN=rtofs
export modID=glo
export RUN_MODE=gzip
#export HOMErtofs=${HOMErtofs:-${NWROOT:?}/rtofs_glo.${rtofs_glo_ver}}
export PARMrtofs=${HOMErtofs}/parm

####################################
# Determine Job Output Name on System
####################################
export pgmout="OUTPUT.$$"
export cycle=t${cyc}z
export CYC=$cyc       # remove and use $cyc in scripts/exrtofs_glo_gzip.sh !

#############################
# Set up the UTILITIES
##############################
export USHutil=${UTILROOT:?}/ush
export EXECutil=${UTILROOT:?}/exec
export utilexec=$EXECutil    # needed by some scripts in USHutil

###########################################################
# Run setpdy and initialize PDY variables
# For any retrospecitve run, set the PDY in the ECF script
###########################################################
setpdy.sh
. ./PDY

#################################
# Define Input/Output directories
#################################
export COMIN=${COMIN:-$(compath.py ${envir}/com/${NET}/${rtofs_glo_ver})/${RUN}.${PDY}}
export COMOUT=${COMOUT:-$(compath.py -o ${NET}/${rtofs_glo_ver})/${RUN}.${PDY}}
mkdir -m 775 -p $COMOUT

###################
# Define model grid
###################
export inputgrid=navy_0.08

#########################################
# Check how many days to run the gzip for (affect fcst1 only)
#########################################
. $PARMrtofs/${RUN}_${modID}.${inputgrid}.config

#################################################################
#  Send a message indicating the start of the job
#################################################################
msg="JOB $job HAS BEGUN on $(hostname)"
postmsg "$msg"

####################
# execute the script
####################
export CFP_VERBOSE=1
${HOMErtofs}/scripts/exrtofs_glo_gzip.sh

msg="JOB $job HAS COMPLETED NORMALLY." 
postmsg "$msg"

cd $DATAROOT
if [ "$KEEPDATA" != YES ]; then
    rm -rf $DATA
fi

date