#!/bin/sh
YEAR=1981

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

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

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

mkdir -p $CASERUN'/run'
cp /project/MST107135/yhtseng00/model_output/cesm1/archive/b_20ct_ctrl_1/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 nyear
./xmlchange -file env_run.xml -id STOP_N        -val 1
./xmlchange DOUT_S_ROOT="/work1/yhtseng00/scratch/cesm_work/archive/$casename"
./xmlchange RUN_STARTDATE="1981-01-01"
./xmlchange RUN_REFDATE="1981-01-01"
./xmlchange RUN_REFCASE="b_20ct_ctrl_1"
#./xmlchange -file env_run.xml -id RUN_TYPE      -val branch
#./xmlchange -file env_run.xml -id RUN_REFCASE   -val ${casename} 
#./xmlchange -file env_run.xml -id RUN_REFDATE   -val ${YEAR}-01-01
#./xmlchange -file env_run.xml -id GET_REFCASE   -val FALSE


#sed -i "s/surfdata_0.9x1.25_simyr1850_c110921_modify.nc/\/project\/MST107135\/data\/inputdata\/lnd\/clm2\/surfdata\/surfdata_0.9x1.25_simyr1850_c110921.nc/g" user_nl_clm
./cesm_setup
./preview_namelists


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

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

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




