##################################################################
echo "------------------------------------------------"
echo "MAG test area on WCOSS maint. & cleanup script" 
echo "------------------------------------------------"
#####################################################################

# History: APRIL 2013 - Added for ecflow mag server trials
#  Paula Freeman 2/2019 Phase 3 Migration. Use $LOGROOT
#                       Do not create prod and para log dirs,
#                       just test"

cd $DATA

#####################################################################
#
# START FLOW OF CONTROL
#
# 1) Manage /com/output directories.
#####################################################################

########################################
set -x
##########################################
#

# LIST PDYs
echo PDY="$PDY"
echo PDYm1="$PDYm1"
echo PDYm2="$PDYm2"
echo PDYm3="$PDYm3"
echo PDYm4="$PDYm4"
echo PDYm5="$PDYm5"
echo PDYm6="$PDYm6"
echo PDYm7="$PDYm7"

#####################################################################
#  Set up output directories if it is a new day.
#####################################################################
export out_dir=${LOGROOT}/output
export out_tdir=${LOGROOT}/output/transfer

if [ ! -e $out_dir/test/$PDY ]; then
   mkdir -p $out_dir/test/$PDY
   chmod 775 $out_dir/test/$PDY

   ln -Tsf $out_dir/test/$PDY $out_dir/test/today

   mkdir -p $out_tdir/$PDY
   chmod 775 $out_tdir/$PDY

   ln -Tsf $out_tdir/$PDY $out_tdir/today

fi
#####################################################################

# GOOD RUN
set +x
echo "**************JOB MAG_SETUP COMPLETED NORMALLY ON THE WCOSS System"
echo "**************JOB MAG_SETUP COMPLETED NORMALLY ON THE WCOSS System"
echo "**************JOB MAG_SETUP COMPLETED NORMALLY ON THE WCOSS System"
set -x

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

############## END OF SCRIPT #######################
