#year=${1}          # Year to be run
#mon=${2}           # Month to be run

year=`date +%Y`
mon=`date -d "1 month ago" +%m`

echo "year=" $year "  mon=" $mon

ROOT=/home/tanpv/Progs/Dr_VN_Ope/DATA/PDF_Ope/
NC_DIR=${ROOT}${year}${mon}
file1=${NC_DIR}/Dr_Prob.nc
file2=${NC_DIR}/Forecast_Ope_Pr_T2_and_Anomaly.nc

if [ $((mon)) -eq 12 ] ; then
   year=$(( $((year)) - 1 ))
fi

echo "year=" $year "  mon=" $mon

if [[ -e ${file1} && -e ${file2} ]] ; then
   echo "Running for "${year}${mon}" has been done !"
   exit
fi

timerun=`date +%Y%m%d%H`

# Checking for enough files to run:
DIR=/home/tanpv/Data/562_VNU/0.25_VN/Operational/monthly/${year}/${mon}
MEMS=" 01 02 03 04 05 06 "
MODELS=" clWRF RegCM "
icount=0
echo "Run at "${timerun}
for Model in ${MODELS} ; do
   for mem in ${MEMS} ; do
       Fname=${Model}_${mem}.nc
       if [[ -e ${DIR}/${Fname} ]] ; then
          echo "File "${DIR}/${Fname}" exists"
       else
          icount=$((icount + 1))
          echo "File "${DIR}/${Fname}" does not exist"
       fi
   done
done
if [ $((icount)) -ne 0 ] ; then
   echo "Run at "${timerun}
   echo "Not enough files to run for "${year}-${mon} 
   echo "Number of missing files is "${icount}
   echo "Not enough files to run for "${year}-${mon}". Number of missing files is "${icount} | mailx -s "Operational Drought forecast" remoclic@hus.edu.vn
   exit
fi

