#/bin/bash

#Restart the run after it has finished one ensemble
#*****must manually assign pertlim value in user_nl_cam file *****

ExpName="ExpA"
str0="."
str1="/"
str2="rest/"
str3="run/"
str4="*"
jobStr="job."
#pointer_files="/home/ctrhodes/mydata2/CESM_Ensemble/Base_20081213/2009-01-02-00000/rpointer*"
#pointer_files="/home/ctrhodes/mydata2/CESM_Ensemble/Base/2005-12-10-00000/rpointer*"
pointer_files="/home/ctrhodes/mydata2/CESM_Ensemble/Base_20001215/2000-12-15-00000/rpointer*"
rest_dir=$str0$str1$ExpName$str1$str2$str4
run_dir=$str0$str1$ExpName$str1$str3
lastrun_files=$run_dir$ExpName$str4
job_files=$str0$str1$ExpName$str1$jobStr$str4

#rm restart files
rm $job_files
rm -r $rest_dir
rm $lastrun_files

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

cd $ExpName

./xmlchange CONTINUE_RUN=FALSE
./xmlchange RESUBMIT=0

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