#!/bin/bash -f
#
#
#

source /home/mrasel/.bashrc
# (0) define dir
im=06
script_dir=/scratch/mrasel/data/scripts/mcip
wrf_dir=/scratch/mrasel/data/WRF_runs/wrfout/2020${im}
export tmp_dir=/scratch/mrasel/data/mcip/tmp
export mcp_dir=/scratch/mrasel/data/mcip/out
promcp_dir=/scratch/mrasel/data/CMAQdata/AQF5X/mcip_anal

# (1) read date in date.txt
date1=20200601
echo "START TIME: " ${date1}

# (2) prepare dates
cd ${script_dir}

d1=`date -d "+0 day $date1" +%Y-%m-%d`
d2=`date -d "+1 day $date1" +%Y-%m-%d`

# (3) copy wrf
if [[ ! -e ${tmp_dir}/wrfout_d01_${d1}_11:00:00 ]]; then
  cp ${wrf_dir}/wrfout_d01_${d1}_11:00:00 ${tmp_dir}/
fi

# (4) run mcip
echo ${d1} ${d2} ${date1:2}
./run_mcip_ddm.csh ${d1} ${d2} ${date1:2}

# (5) check
if [[ ! -e ${mcp_dir}/METCRO3D_${date1:2} ]]; then
  echo "ERROR, file on ${date1} not produced"
  exit
else
  rm -rf ${tmp_dir}/wrfout_d01_${d1}_00:00:00
  mv ${mcp_dir}/*${date1:2}*  ${promcp_dir}
fi
