#!/bin/bash
#
# March-2020 RPadilla & JHAlves                                       +
#           - For GEFSv12.0                                           +
#                                                                     +
######################################################################
set -xa
# #### 08/25/1999 ###################
# SET SHELL PROCESSING VARIABLES
# ###################################
export PS4='+ $SECONDS + ' 
date

export DATA=${DATA:-${DATAROOT:?}/${jobid}}
if [ ! -d $DATA ]
then
  mkdir -p $DATA
fi
cd $DATA

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

export cycle=t${cyc}z 

export SENDCOM=${SENDCOM:-YES}
export SENDDBN=${SENDDBN:-YES}
export SENDECF=${SENDECF:-YES}

export sigMODE=post # Only post-processing done here, but may need to be revised by NCO

####################################
# Path to HOME Directory
####################################

export HOMEwave=${HOMEwave_nfcens}
export GEMwave=${GEMwave:-$HOMEwave/gempak}
export FIXwave=${FIXwave:-$HOMEwave/fix}

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

#
# Set up model and cycle specific variables
#
export NET=wave_nfcens
export RUN=nfcens
export fend=00
export finc=1
export fstart=00
export GRIB=grib
export EXT=""
export DBN_ALERT_TYPE=NFC_WAVEENS_GEMPAK

export COMIN=${COMIN:-$(compath.py ${NET}/${wave_nfcens_ver}/${RUN}).${PDY}}
export COMOUT=${COMOUT:-$(compath.py -o ${NET}/${wave_nfcens_ver})/${RUN}.${PDY}}
export COMOUTgempak=${COMOUTgempak:-${COMOUT}/gempak}

mkdir -p -m 775 $COMOUT $COMOUTgempak

#######################
# Copy job specific GEMPAK table for FNMOC grib2 files
#######################
cp ${GEMwave}/fix/g2varswmo5.tbl .
cp ${GEMwave}/fix/g2vcrdwmo5.tbl .
cp ${GEMwave}/fix/g2varswmo2.tbl .
cp ${GEMwave}/fix/g2vcrdwmo2.tbl .
 
env
export wavelog=${COMOUT}/wave.log

########################################################
# Execute the script.
${HOMEwave}/scripts/exnawips_nfcens.sh
########################################################

export err=$?; err_chk

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

if [ -e "$pgmout" ]; then
  cat $pgmout
fi

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

date