#!/bin/sh
YEAR=1997

CCSMROOT=/project/MST107135/yhtseng00/models/cesm1/cesm1_2_2_1

SCRATCH=/work1/yhtseng00
mach_name=peta
casename=e97_mg0
CASERUN=$SCRATCH/scratch/cesm_work/$casename
CASEROOT=$SCRATCH'/scratch/cesm_work/case/'$casename
CLONEROOT='/work1/yhtseng00/scratch/cesm_work/case/c81_mg0'

rm -rf $CASEROOT $CASERUN
# -----------------
cd $CCSMROOT/scripts
./create_clone -case $CASEROOT -clone $CLONEROOT 

mkdir -p $CASERUN'/run'
cp /work1/yhtseng00/scratch/cesm_work/archive/c81_mg0/rest/${YEAR}-01-01-00000/* $CASERUN'/run/'
# -----------------
cd $CASEROOT
#./xmlchange NTASKS_ATM=200
#./xmlchange NTASKS_LND=200
#./xmlchange ROOTPE_LND=0
#./xmlchange NTASKS_ICE=200
#./xmlchange ROOTPE_ICE=0
#./xmlchange NTASKS_OCN=200
#./xmlchange ROOTPE_OCN=0
#./xmlchange NTASKS_CPL=200
#./xmlchange ROOTPE_CPL=0
#./xmlchange NTASKS_ROF=200
#./xmlchange ROOTPE_ROF=0
#./xmlchange NTASKS_GLC=1
#./xmlchange NTASKS_WAV=1
#./xmlchange DIN_LOC_ROOT=/project/MST107135/data/inputdata

./xmlchange -file env_run.xml -id CONTINUE_RUN  -val FALSE
./xmlchange -file env_run.xml -id STOP_OPTION   -val nmonth
./xmlchange -file env_run.xml -id STOP_N        -val 1
./xmlchange DOUT_S_ROOT="/work1/yhtseng00/scratch/cesm_work/archive/$casename"
./xmlchange RUN_STARTDATE="1997-01-01"

./xmlchange RUN_REFDATE="1997-01-01"
./xmlchange RUN_REFCASE="c81_mg0"


./cesm_setup
./preview_namelists


cd $CASEROOT
$CASEROOT/*.build
#sed -i "s/MST107192/ACD107096/g" *.run
#sed -i "s/ct800/dc20200053/g" *.run

sed -i "s/MST107192/GOV110049/g" *.run
sed -i "s/ct800/dc20210018/g" *.run

chmod -R u+wr $CASERUN/run/
./*.submit




