#/bin/bash

#Restart the run after it has finished one ensemble
#*****must manually assign pertlim value in user_nl_cam file *****
#*****must manually change start MERRA data filename in user_nl_cam file ****
ExpName="ExpC"
startDate="2000-12-15" #in YYYY-MM-DD
Base_dir="/home/ctrhodes/mydata2/CESM_Ensemble/Base_20001215/2000-12-15-00000/"
Base_name="Base_1DayRes"
str0="."
str1="/"
str2="rest/"
str3="run/"
str4="*"
str5="rpointer*"
str6="*.nc"
str7="*.bin"
jobStr="job."

pointer_files=$Base_dir$str5
rest_dir=$str0$str1$ExpName$str1$str2$str4
run_dir=$str0$str1$ExpName$str1$str3
lastrun_files1=$run_dir$str5
lastrun_files2=$run_dir$str6
lastrun_files3=$run_dir$str7
job_files=$str0$str1$ExpName$str1$jobStr$str4

#rm restart files
rm $job_files
rm -r $rest_dir
rm $lastrun_files1 $lastrun_files2 $lastrun_files3

#recopy in pointer variables (they were overwritten in last run)
cp $Base_dir$str4 $run_dir

cd $ExpName

./xmlchange CONTINUE_RUN=FALSE
./xmlchange RESUBMIT=0
./xmlchange RUN_REFDATE=$startDate
./xmlchange RUN_STARTDATE=$startDate
./xmlchange RUN_REFCASE=$Base_name

./$ExpName.clean_build
./$ExpName.build
./$ExpName.submit
