Skip to content

Commit 047513d

Browse files
committed
More checks for warm start in run_ccam.py
1 parent 744f786 commit 047513d

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

run_ccam.py

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ def get_datetime():
404404
else:
405405
d['imthlst'] = imth-1
406406
d['iyrlst'] = iyr
407+
d['rest_iyrlst'] = iyr-1
407408

408409
# two-digit versions of previous and current month
409410
d['imthlst_2digit'] = mon_2digit(d['imthlst'])
@@ -932,9 +933,6 @@ def prep_iofiles():
932933

933934
# This function is called if simulation_test=T
934935

935-
# Define restart file:
936-
d['ifile'] = dict2str('Rest{name}.{iyrlst}{imthlst_2digit}')
937-
938936
# Define host model fields:
939937
d['mesonest'] = dict2str('{bcdom}{iyr}{imth_2digit}.nc')
940938
fpath = dict2str('{bcdir}/{mesonest}')
@@ -1101,14 +1099,52 @@ def set_mlev_params():
11011099
def config_initconds():
11021100
"Configure initial condition file"
11031101

1102+
# Default warm start
1103+
d['ifile'] = dict2str('Rest{name}.{iyrlst}{imthlst_2digit}')
11041104
d['nrungcm'] = 0
11051105

1106+
fname = dict2str('{wdir}/{ifile}.000000')
1107+
if not os.path.exists(fname):
1108+
fpath = dict2str('{hdir}/RESTART/{ifile}.tar')
1109+
if os.path.exists(fpath):
1110+
print("Missing restart in wdir, but found restart in RESTART directory")
1111+
run_cmdline('tar xvf '+fpath)
1112+
1113+
# Check for cold start
11061114
if d['iyr'] == d['iys']:
11071115
if d['imth'] == d['ims']:
1116+
1117+
# check for accidental cold start
1118+
fname = dict2str('{wdir}/{ifile}.000000')
1119+
if os.path.exists(fname):
1120+
print("ERROR: Restart file found with cold start")
1121+
print(" "+fname)
1122+
print(" Remove restart files in wdir and RESTART,")
1123+
print(" or change iys in run_ccam.sh")
1124+
sys.exit(1)
1125+
1126+
rest_ifile = dict2str('{hdir}/RESTART/Rest{name}.{rest_iyrlst}12.tar')
1127+
if os.path.exists(rest_ifile):
1128+
print("ERROR: Suspected warm start due to detection of")
1129+
print(" "+rest_ifile)
1130+
print(" Remove restart file for cold start, or change")
1131+
print(" iys in run_ccam.sh")
1132+
sys.exit(1)
1133+
1134+
# Configure cold start
11081135
if d['dmode'] in ["nudging_gcm", "nudging_ccam", "sst_6hour", "nudging_gcm_with_sst"]:
11091136
d.update({'ifile': d['mesonest']})
11101137
elif d['dmode'] == "sst_only":
11111138
d.update({'ifile': d['sstinit']})
1139+
fpath = dict2str('{sstinit}')
1140+
if os.path.exists(fpath):
1141+
run_cmdline('ln -s '+fpath+' .')
1142+
elif os.path.exists(fpath+'.000000'):
1143+
run_cmdline('ln -s '+fpath+'.?????? .')
1144+
elif os.path.exists(fpath+'.tar'):
1145+
run_cmdline('tar xvf '+fpath+'.tar')
1146+
else:
1147+
raise ValueError(dict2str('ERROR: Cannot locate file {sstinit}'))
11121148
else:
11131149
d.update({'ifile': "error"})
11141150
if d['bcsoil'] == "constant":
@@ -1123,7 +1159,7 @@ def config_initconds():
11231159
d['nrungcm'] = -4
11241160
check_file_exists(d['bcsoilfile']+'.000000')
11251161

1126-
# prepare ifile
1162+
# prepare mesonest file
11271163
if d['dmode'] in ["nudging_gcm", "nudging_ccam", "sst_6hour", "nudging_gcm_with_sst"]:
11281164
fpath = dict2str('{bcdir}/{mesonest}')
11291165
newpath = dict2str('{wdir}/{mesonest}')
@@ -1147,18 +1183,7 @@ def config_initconds():
11471183
raise ValueError("ERROR: Cannot assign calendar for leap=auto")
11481184
print(dict2str('Assign calendar {leap}'))
11491185

1150-
if (d['dmode']=="sst_only") and (d['iyr']==d['iys']) and (d['imth']==d['ims']):
1151-
fpath = dict2str('{sstinit}')
1152-
if os.path.exists(fpath):
1153-
run_cmdline('ln -s '+fpath+' .')
1154-
elif os.path.exists(fpath+'.000000'):
1155-
run_cmdline('ln -s '+fpath+'.?????? .')
1156-
elif os.path.exists(fpath+'.tar'):
1157-
run_cmdline('tar xvf '+fpath+'.tar')
1158-
else:
1159-
raise ValueError(dict2str('ERROR: Cannot locate file {sstinit}'))
1160-
1161-
# Check ifile
1186+
# prepare ifile
11621187
fname = d['ifile']
11631188
if not fname=="error":
11641189
if not os.path.exists(fname):
@@ -3135,13 +3160,14 @@ def cc_template_tracer():
31353160

31363161
parser.add_argument("--terread", type=str, help=" path of terread executable")
31373162
parser.add_argument("--igbpveg", type=str, help=" path of igbpveg executable")
3138-
parser.add_argument("--sibveg", type=str, help="depreciated")
31393163
parser.add_argument("--ocnbath", type=str, help=" path of ocnbath executable")
31403164
parser.add_argument("--casafield", type=str, help=" path of casafield executable")
31413165
parser.add_argument("--aeroemiss", type=str, help=" path of aeroemiss executable")
31423166
parser.add_argument("--model", type=str, help=" path of globpea executable")
31433167
parser.add_argument("--pcc2hist", type=str, help=" path of pcc2hist executable")
31443168

3169+
parser.add_argument("--sibveg", type=str, help="depreciated")
3170+
31453171
args = parser.parse_args()
31463172

31473173
main(args)

0 commit comments

Comments
 (0)