-
Notifications
You must be signed in to change notification settings - Fork 5
/
betacast.sh
executable file
·1387 lines (1212 loc) · 54 KB
/
betacast.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
##=======================================================================
#PBS -N wx-driver
#PBS -A P54048000
#PBS -l walltime=6:00:00
#PBS -q share
#PBS -k oe
#PBS -m a
#PBS -M [email protected]
#PBS -l select=1:ncpus=8
##=======================================================================
###################################################################################
# Colin Zarzycki ([email protected])
#
# Driver script for running CESM/CAM in "forecast" or "hindcast" mode.
# This code will either read UTC unix clock or read in a specified list of dates,
# download dataset, map to CAM grid, and run a forecast.
#
# Generally can be executed on login nodes or in the background, ex:
# $> nohup ./main-realtime.sh nl.neconus30x8 &
# but see above for example of PBS options to submit to batch nodes
#
# Details can be found in:
# C. M. Zarzycki and C. Jablonowski (2015), Experimental tropical cyclone forecasts
# using a variable-resolution global model. Mon. Weat. Rev., 143(10), 4012–4037.
# doi:10.1175/MWR-D-15-0159.1.
###################################################################################
script_start=$(date +%s)
set -e
#set -v
SCRIPTPATH=$(dirname "$(realpath "$0")")
echo "Our script path is $SCRIPTPATH"
source ${SCRIPTPATH}/utils.sh # Source external bash functions
source ${SCRIPTPATH}/datahelpers.sh # Source external bash functions
# Set files
MACHINEFILE=${1}
NAMELISTFILE=${2}
OUTPUTSTREAMS=${3}
# If relative path, convert to absolute path
if [[ "$MACHINEFILE" != /* ]] && [[ "$MACHINEFILE" != ~* ]]; then MACHINEFILE=${PWD}/${MACHINEFILE}; fi
if [[ "$NAMELISTFILE" != /* ]] && [[ "$NAMELISTFILE" != ~* ]]; then NAMELISTFILE=${PWD}/${NAMELISTFILE}; fi
if [[ "$OUTPUTSTREAMS" != /* ]] && [[ "$OUTPUTSTREAMS" != ~* ]]; then OUTPUTSTREAMS=${PWD}/${OUTPUTSTREAMS}; fi
exit_file_no_exist $MACHINEFILE
exit_file_no_exist $NAMELISTFILE
exit_file_no_exist $OUTPUTSTREAMS
echo $MACHINEFILE; echo $NAMELISTFILE; echo $OUTPUTSTREAMS
# Read namelists
read_bash_nl "${MACHINEFILE}"
read_bash_nl "${NAMELISTFILE}"
# Replace Betacast-specific placeholders. This allows a user to override these in NAMELISTFILE
path_to_case=$(replace_betacast_string "$path_to_case" "$casename" "!CASENAME!")
path_to_rundir=$(replace_betacast_string "$path_to_rundir" "$casename" "!CASENAME!")
sePreFilterIC=$(replace_betacast_string "$sePreFilterIC" "$casename" "!CASENAME!")
sePostFilterIC=$(replace_betacast_string "$sePostFilterIC" "$casename" "!CASENAME!")
sstFileIC=$(replace_betacast_string "$sstFileIC" "$casename" "!CASENAME!")
set -u # turn on crashes for unbound variables in bash
###################################################################################
############### OPTIONAL TO BE SET BY USER ########################################
path_to_nc_files=${path_to_rundir} # Path where .nc files are
outputdir=${path_to_rundir} # Path where .nc files are being written
tmparchivecdir=${path_to_rundir}/proc/ # Path to temporarily stage final data
landdir=${path_to_rundir}/landstart/ # Path to store land restart files
###################################################################################
### THESE COME WITH THE REPO, DO NOT CHANGE #######################################
gfs_to_cam_path=${SCRIPTPATH}/gfs_to_cam
era_to_cam_path=${SCRIPTPATH}/interim_to_cam
atm_to_cam_path=${SCRIPTPATH}/atm_to_cam
sst_to_cam_path=${SCRIPTPATH}/sst_to_cam
filter_path=${SCRIPTPATH}/filter
###################################################################################
### setting variables not included in namelist for backwards compat
if [ -z "${CIMEbatchargs+x}" ]; then CIMEbatchargs=""; fi
if [ -z "${do_runoff+x}" ]; then do_runoff=false; fi
if [ -z "${keep_land_restarts+x}" ]; then keep_land_restarts=true; fi
if [ -z "${perturb_namelist+x}" ]; then perturb_namelist=""; fi
if [ -z "${predict_docn+x}" ]; then predict_docn=false; fi
if [ -z "${archive_inic+x}" ]; then archive_inic=false; fi
if [ -z "${compress_history_nc+x}" ]; then compress_history_nc=true; fi
if [ -z "${add_vortex+x}" ]; then add_vortex=false; fi
if [ -z "${vortex_namelist+x}" ]; then vortex_namelist=""; fi
if [ -z "${save_nudging_files+x}" ]; then save_nudging_files=false; fi
if [ -z "${override_rest_check+x}" ]; then override_rest_check=false; fi
if [ -z "${tararchivedir+x}" ]; then tararchivedir=true; fi
if [ -z "${docnres+x}" ]; then docnres="180x360"; fi
if [ -z "${modelgridfile+x}" ]; then modelgridfile=""; fi
if [ -z "${anl2mdlWeights+x}" ]; then anl2mdlWeights=""; fi
if [ -z "${CIMEMAXTRIES+x}" ]; then CIMEMAXTRIES=1; fi
if [ -z "${add_noise+x}" ]; then add_noise=false; fi
if [ -z "${runmodel+x}" ]; then runmodel=true; fi
### Some defaults infrequently set
if [ -z "${debug+x}" ]; then debug=false; fi
if [ -z "${islive+x}" ]; then islive=false; fi
if [ -z "${datestemplate+x}" ]; then datestemplate=""; fi
if [ -z "${doFilter+x}" ]; then doFilter=false; fi
if [ -z "${filterOnly+x}" ]; then filterOnly=false; fi
if [ -z "${numHoursSEStart+x}" ]; then numHoursSEStart=3; fi
if [ -z "${filterHourLength+x}" ]; then filterHourLength=6; fi
if [ -z "${filtTcut+x}" ]; then filtTcut=6; fi
if [ -z "${add_perturbs+x}" ]; then add_perturbs=false; fi
if [ -z "${perturb_namelist+x}" ]; then perturb_namelist=""; fi
if [ -z "${land_spinup+x}" ]; then land_spinup=false; fi
if [ -z "${FILTERWALLCLOCK+x}" ]; then FILTERWALLCLOCK="00:29:00"; fi
if [ -z "${FILTERQUEUE+x}" ]; then FILTERQUEUE="batch"; fi
if [ -z "${RUNWALLCLOCK+x}" ]; then RUNWALLCLOCK="12:00:00"; fi
if [ -z "${RUNQUEUE+x}" ]; then RUNQUEUE="regular"; fi
if [ -z "${use_nsplit+x}" ]; then use_nsplit="true"; fi
if [ -z "${cime_coupler+x}" ]; then cime_coupler="mct"; fi
if [ -z "${nclPlotWeights+x}" ]; then nclPlotWeights="NULL"; fi
if [ -z "${landrawdir+x}" ]; then landrawdir="NULL"; fi
if [ -z "${sendplots+x}" ]; then sendplots=false; fi
if [ -z "${dotracking+x}" ]; then dotracking=false; fi
if [ -z "${m2m_gridfile+x}" ]; then m2m_gridfile=""; fi
if [ -z "${m2m_remap_file+x}" ]; then m2m_remap_file=""; fi
### Set correct E3SM/CESM split
if [ -z "${modelSystem+x}" ]; then modelSystem=0; fi
if [ $modelSystem -eq 0 ]; then
echo "Using CESM"
atmName="cam"
lndName="clm"
lndSpecialName="clm2"
rofName="mosart"
rofSpecialName="mosart"
elif [ $modelSystem -eq 1 ]; then
echo "Using E3SM"
atmName="eam"
lndName="elm"
lndSpecialName="elm"
rofName="mosart"
rofSpecialName="mosart"
else
echo "Unknown modeling system set for modelSystem: $modelSystem"
exit 1
fi
# Are we running with frankengrid?
do_frankengrid=false
if [ -n "${regional_src+x}" ]; then do_frankengrid=true ; fi
echo "do_frankengrid set to: $do_frankengrid"
# Figure out where to archive
if [ -z ${ARCHIVEDIR+x} ] || [[ -z "${ARCHIVEDIR// }" ]] ; then
ARCHIVEDIR=${outputdir}/
else
ARCHIVEDIR=${ARCHIVEDIR}/${casename}/
mkdir -v -p ${ARCHIVEDIR}
fi
echo "Files will be archived in ${ARCHIVEDIR}/YYYYMMDDHH/"
# Update SST filename based on docnres
sstFileIC=${sstFileIC/DOCNRES/$docnres}
echo "Actual sstFileIC: ${sstFileIC}"
### ERROR CHECKING BLOCK! #########################################################
# Exit if add_perturbs is turned on but no namelist is passed in with perturbation config settings
if ${add_perturbs} && { [ -z "$perturb_namelist" ] || [ ! -f "$perturb_namelist" ]; } ; then
echo "add_perturbs is true but can't find namelist: "$perturb_namelist
exit 1
fi
# Exit if add_perturbs is turned on but no namelist is passed in with perturbation config settings
if ${add_vortex} && { [ -z "$vortex_namelist" ] || [ ! -f "$vortex_namelist" ]; } ; then
echo "add_vortex is true but can't find namelist: "$vortex_namelist
exit 1
fi
# Check for deprecated namelist options
if [ -z ${anl2mdlWeights+x} ] && [ ${gfs2seWeights+x} ] ; then
echo "WARNING: Setting anl2mdlWeights to ${gfs2seWeights}"
echo "WARNING: This is deprecated and will be removed in the future! To fix, change 'gfs2seWeights' to 'anl2mdlWeights' in ${NAMELISTFILE}"
anl2mdlWeights=$gfs2seWeights
fi
# Check if ncl exists
if ! type ncl &> /dev/null ; then
echo "ERROR: ncl does not exist. Make sure ncl is in your path when betacast is invoked"
exit 1
fi
# Check if ncks exists for compression
ncks_exists=true
if ! type ncks &> /dev/null ; then
#echo "ERROR: ncks does not exist. Make sure ncks is in your path when betacast is invoked"
#exit 1
echo "WARNING: ncks does not exist, cannot compress. Setting compress_history_nc to 0 (false)"
echo "WARNING: if you'd like remedy, make sure ncks is in your path when betacast.sh is invoked"
compress_history_nc=0
ncks_exists=false
fi
# If we are using nuopc, we need to generate an ESMF mesh
if [ "${cime_coupler}" == "nuopc" ] && ! type ESMF_Scrip2Unstruct &> /dev/null; then
echo "ERROR: ESMF_Scrip2Unstruct does not exist, which is needed when cime_coupler is: ${cime_coupler}"
echo "ERROR: Install via conda/mamba or from source and add to PATH"
exit 1
fi
# Check to make sure required ATM variables are provided by the user if we are using model-to-model
if [[ "$atmDataType" -eq 9 ]]; then
if [[ -z "$m2m_topo_in" ]] || [[ -z "$m2m_parent_source" ]] || { [[ -z "$m2m_remap_file" ]] && [[ -z "$m2m_gridfile" ]]; }; then
echo "ERROR: For m2m ATM, one or more required variables (m2m_topo_in, m2m_parent_source, m2m_remap_file/m2m_gridfile pair) are not defined."
echo "ERROR: Ensure these are defined in the Betacast namelist"
exit 1
fi
fi
# Check to make sure required SST variables are provided by the user if we are using model-to-model
if [[ "$sstDataType" -eq 9 ]]; then
if [[ -z "$m2m_sst_grid_filename" ]] || [[ -z "$m2m_sstice_data_filename" ]] || [[ -z "$m2m_sstice_year_align" ]] || [[ -z "$m2m_sstice_year_start" ]] || [[ -z "$m2m_sstice_year_end" ]]; then
echo "ERROR: For m2m SST, one or more required variables (m2m_sst_grid_filename, m2m_sstice_data_filename, m2m_sstice_year_align, m2m_sstice_year_start, m2m_sstice_year_end) are not defined."
echo "ERROR: Ensure these are defined in the Betacast namelist"
exit 1
fi
fi
# Check Python version for 3+
python -c 'import sys; exit(sys.version_info.major != 3)' && echo "CHECK_PYTHON: Python 3 found" || { echo "CHECK_PYTHON: Please install Python 3+"; exit 25; }
# Check Python package dependencies
if ${do_frankengrid} ; then
check_python_dependency numpy
check_python_dependency netCDF4
check_python_dependency sklearn
fi
# Adjust bools (for backwards compatibility, 0 = false and 1 = true)
bools_to_check=("islive" "debug" "doFilter" "filterOnly" "do_runoff" "keep_land_restarts"
"predict_docn" "archive_inic" "compress_history_nc" "override_rest_check"
"tararchivedir" "save_nudging_files" "add_vortex")
for bool_to_check in ${bools_to_check[@]}; do
check_bool $bool_to_check ${!bool_to_check}
done
if [ $override_rest_check = false ]; then
echo "Checking for SourceMods permiting additional restart writes for land model"
echo "This check can be ignored with override_rest_check = true in the namelist."
exit_files_no_exist $path_to_case/SourceMods/src.${lndName}/lnd_comp_mct.F90 $path_to_case/SourceMods/src.${lndName}/lnd_comp_nuopc.F90
if [ $do_runoff = true ]; then
exit_files_no_exist $path_to_case/SourceMods/src.${rofName}/rof_comp_mct.F90 $path_to_case/SourceMods/src.${rofName}/rof_comp_nuopc.F90
fi
fi
### Check required variables
betacast_required_vars=("casename" "atmDataType" "sstDataType" "numLevels" "numdays"
"anl2mdlWeights" "PROJECTID" "DTIME" "FINERES" "USERSTAB")
check_required_vars "${betacast_required_vars[@]}"
###################################################################################
# do some stability calcs
# if USERSTAB is 0, use internal calcs.
# if USERSTAB is <0, use se_nsplit=-1
# If USERSTAB >0, use the value in seconds for dt_dyn and calculate nsplit accordingly from DTIME
USERSTABTF=$(python -c "print('TRUE' if ${USERSTAB} > 0 else 'FALSE')")
if [ ${USERSTABTF} == 'FALSE' ] ; then
if [ $(python -c "print('TRUE' if ${USERSTAB} < -0.001 else 'FALSE')") == 'FALSE' ]; then
STABILITY=$(python -c "print(30./${FINERES}*450.)")
VALIDSTABVAL=true
echo "Dynamic stability for ne${FINERES} to be ${STABILITY} seconds"
else
STABILITY=-1
VALIDSTABVAL=false # Setting to false means we won't calculate nsplit for SE/HOMME later
echo "Dynamic stability for ne${FINERES} to be ${STABILITY} and internal STABILITY setting"
fi
else
STABILITY=${USERSTAB}
VALIDSTABVAL=true
echo "User defined stability set to ${STABILITY}"
fi
echo "VALIDSTABVAL is set to "${VALIDSTABVAL}
## Create paths to generate initial files if they don't exist...
mkdir -p ${pathToINICfiles}
mkdir -p ${pathToSSTfiles}
# Set mapping file directory and make if needed
mapping_files_path=${path_to_inputdata}/mapping/ ; mkdir -p ${mapping_files_path}
# Set timestamp for backing up files, etc.
timestamp=$(date +%Y%m%d.%H%M)
uniqtime=$(date +"%s%N")
echo "We are using ${casename} for the case"
# Get the current time
currtime=$(date -u +%H%M)
if [ $islive = true ] ; then # Find most recent GFS forecast
## Here we get two digit strings for UTC time for month, day, year
## We also get current time in hoursminutes (because the GFS output lags by 3.5 hours)
monthstr=$(date -u +%m)
daystr=$(date -u +%d)
yearstr=$(date -u +%Y)
## Use currtime to figure out what is the latest cycle we have access to
if [ $currtime -lt 0328 ] ; then
echo "12Z cycle"
monthstr=$(date --date="yesterday" -u +%m)
daystr=$(date --date="yesterday" -u +%d)
yearstr=$(date --date="yesterday" -u +%Y)
cyclestr=12
elif [ $currtime -lt 0928 ] ; then
echo "00Z cycle"
cyclestr=00
elif [ $currtime -lt 1528 ] ; then
echo "00Z cycle"
cyclestr=00
elif [ $currtime -lt 2128 ] ; then
echo "12Z cycle"
cyclestr=12
elif [ $currtime -ge 2128 ] ; then
echo "12Z cycle"
cyclestr=12
else
echo "Can't figure out start time"
exit 1
fi
else # if not live, draw from head of dates.txt file
# Figure out if dates.CASE.txt exists and where it is located
datesbase=dates.${casename}.txt
if [ -f "./dates/${datesbase}" ]; then
# Preferred location is dates subdir as of 4/13/2022
echo "$datesbase exists in dates subdirectory"
datesfile=./dates/${datesbase}
else
if [ -f "./${datesbase}" ]; then
echo "WARNING! $datesbase isn't in dates subdir but exists in home dir!"
echo "This is allowed for backwards compatibility but is less organized!"
echo "You should create a subdir called 'dates' and put the dates.CASE.txt file there!"
datesfile=${datesbase}
else
if [[ ${datestemplate+x} && -f ./dates/${datestemplate} ]]; then
echo "Didn't find case dates, but you specified a datestemplate in the namelist..."
echo "So I'm copying $datestemplate to this case and using that..."
cp -v ./dates/${datestemplate} ./dates/${datesbase}
datesfile=./dates/${datesbase}
else
echo "Uh, oh. Can't find a dates file OR template AND run isn't live. Exiting..."
exit 1
fi
fi
fi
echo "Using dates in: "${datesfile}
longdate=$(get_top_line_from_dates "${datesfile}")
echo "Getting parsed time from $longdate"
parse_YYYYMMDDHH $longdate
echo "From datesfile, read in: "$yearstr' '$monthstr' '$daystr' '$cyclestr'Z'
fi
## Figure out the seconds which correspond to the cycle and zero pad if neces
get_cyclestrsec "$cyclestr"
## Figure out what the SE start time will be after filter
## These values are *only* used if do_filter is true
if [ $numHoursSEStart -lt 6 ] ; then
let se_cyclestr=$cyclestr+03
while [ ${#se_cyclestr} -lt 2 ];
do
se_cyclestr="0"$se_cyclestr
done
se_monthstr=$monthstr
se_daystr=$daystr
se_yearstr=$yearstr
let se_cyclestrsec=$((10#$se_cyclestr))*3600
while [ ${#se_cyclestrsec} -lt 5 ];
do
se_cyclestrsec="0"$se_cyclestrsec
done
else
echo "SE forecast lead time too long, 18Z cycle causes trouble"
echo "Not supported."
exit 1
fi
# Get time for pulling SST
getSSTtime $islive $currtime $monthstr $daystr $yearstr $cyclestr
yestmonthstr=$(date --date="yesterday" -u +%m)
yestdaystr=$(date --date="yesterday" -u +%d)
yestyearstr=$(date --date="yesterday" -u +%Y)
echo "We are using $yearstr $monthstr $daystr $cyclestr Z ($cyclestrsec seconds) for ATM init. data"
echo "We are using $sstyearstr $sstmonthstr $sstdaystr $sstcyclestr Z for SST init. data"
if $doFilter ; then
echo "Filter: True model init. will occur at $se_yearstr $se_monthstr $se_daystr $se_cyclestr Z ($se_cyclestrsec seconds)"
else
echo "No filter: True model init. will occur at $se_yearstr $se_monthstr $se_daystr $cyclestr Z ($cyclestrsec seconds)"
fi
if $runmodel ; then
############################### GET DYCORE INFO ###############################
cd $path_to_case
DYCORE=$(./xmlquery CAM_DYCORE | sed 's/^[^\:]\+\://' | xargs)
if [ -z "$DYCORE" ]; then
echo "Couldn't automagically figure out dycore, assuming SE/HOMME"
DYCORE="se"
fi
echo "DYCORE: "$DYCORE
if [ $debug = false ] ; then
############################### GET ATM DATA ###############################
# The keys are $atmDataType
declare -A atm_data_sources=(
["1"]="GFS"
["2"]="ERAI"
["3"]="CFSR"
["4"]="ERA5"
["9"]="CAM"
)
declare -A atm_data_glob_anl=(
["1"]="gfs_0.25x0.25"
["2"]=""
["3"]="gfs_0.50x0.50"
["4"]="era5_0.25x0.25"
["9"]=""
)
declare -A atm_file_paths=(
["1"]="${gfs_files_path}/gfs_atm_${yearstr}${monthstr}${daystr}${cyclestr}.grib2"
["2"]="${era_files_path}/ERA-Int_${yearstr}${monthstr}${daystr}${cyclestr}.nc"
["3"]="${gfs_files_path}/cfsr_atm_${yearstr}${monthstr}${daystr}${cyclestr}.grib2"
["4"]="${era_files_path}/ERA5_${yearstr}${monthstr}${daystr}${cyclestr}.nc"
["9"]=""
)
# Initialize any "global" variables needed when getting atmospheric data
RDADIR="" # Init to empty, but fill in if RDA available later
ERA5RDA=0 # Set whether or not ERA5 is local (0 = local, 1 = RDA)
case $atmDataType in
1)
get_gfs_atm
;;
2)
get_era_interim_atm
;;
3)
get_cfsr_atm
;;
4)
get_era5_atm
;;
9)
echo "User has specified a CESM/E3SM data file"
;;
*)
echo "Incorrect model IC entered"
exit 1
;;
esac
# If ERA5RDA flag toggled, set value w/ key to RDA data
if [ $ERA5RDA -eq 1 ] ; then
atm_data_sources["4"]="ERA5RDA"
atm_file_paths["4"]="${RDADIR}/e5.oper.invariant/197901/e5.oper.invariant.128_129_z.ll025sc.1979010100_1979010100.nc"
fi
############################### GET SST / NCL ###############################
case $sstDataType in
1)
get_gdas_sst
;;
2)
get_erai_sst
;;
3)
get_noaaoi_sst
;;
9)
echo "User has specified a CESM/E3SM data stream"
;;
*)
echo "Incorrect SST data type entered"
exit 1
;;
esac
# If not using data streams, we have to generate the SST forcing
if [ ${sstDataType} -ne 9 ] ; then
# Switch bash bool to int for NCL input
if [ $predict_docn = true ]; then INT_PREDICT_DOCN=1; else INT_PREDICT_DOCN=0; fi
cd ${sst_to_cam_path}
sst_domain_file=${sst_to_cam_path}/domains/domain.ocn.${docnres}.nc
sst_scrip_file=${sst_to_cam_path}/domains/scrip.ocn.${docnres}.nc
sst_ESMF_file=${sst_to_cam_path}/domains/ESMF.ocn.${docnres}.nc
# check if domain or SCRIP exist, if one is missing create both domain and scrip
if [ ! -f "$sst_domain_file" ] || [ ! -f "$sst_scrip_file" ]; then
echo "Creating SST domain file for: ${docnres}"
set +e
(set -x; ncl gen-sst-domain.ncl 'inputres="'${docnres}'"' ) ; exit_status=$?
check_ncl_exit "gen-sst-domain.ncl" $exit_status
set -e
compress_single_file "${sst_scrip_file}"
fi
# if the CIME coupler is nuopc, we need to generate a scrip file
if [ "${cime_coupler}" == "nuopc" ] && [ ! -f "$sst_ESMF_file" ]; then
ESMF_Scrip2Unstruct ${sst_scrip_file} ${sst_ESMF_file} 0 ; rm -fv PET0.ESMF_LogFile
compress_single_file "${sst_ESMF_file}"
fi
# Now generate the SST/ice datastream
set +e
(set -x; ncl sst_interp.ncl \
'initdate="'${yearstr}${monthstr}${daystr}${cyclestr}'"' \
predict_docn=${INT_PREDICT_DOCN} \
'inputres="'${docnres}'"' \
'datasource="'${SSTTYPE}'"' \
'sstDataFile = "'${sst_files_path}/${sstFile}'"' \
'iceDataFile = "'${sst_files_path}/${iceFile}'"' \
'SST_write_file = "'${sstFileIC}'"' \
) ; exit_status=$?
check_ncl_exit "sst_interp.ncl" $exit_status
set -e # Turn error checking back on
fi
############################### ATM NCL ###############################
cd $atm_to_cam_path ; echo "cd'ing to interpolation directory"
# Figure out which anl2mdlWeights we want to use. If the user gave us one
# we will just use that, otherwise we'll hope they gave us modelgridfile (SCRIP)
# and we will use that if not generated. Once it's been generated, keep reusing until
# purged from the mapping directory
if [[ -z "${anl2mdlWeights}" || ! -e "${anl2mdlWeights}" ]]; then
echo "User did not explicitly specify anl2mdlWeights, trying to generate from SCRIP grid"
if [ ! -f ${modelgridfile} ]; then
echo "modelgridfile --> ${modelgridfile} does not exist, exiting"
echo "specify this as a SCRIP file in the namelist or anl2mdlWeights"
exit 19
fi
# Get name without suffix
modelgridshortname=$(basename "${modelgridfile%.*}")
# If we are doing m2m, specify the target as ERA5, otherwise let user decide
if [[ "$atmDataType" -eq 9 ]]; then
RLLSOURCEGRID="era5_0.25x0.25"
else
RLLSOURCEGRID=${atm_data_glob_anl[$atmDataType]}
fi
# Define new anl2mdlWeights
anl2mdlWeights=${mapping_files_path}/map_${RLLSOURCEGRID}_TO_${modelgridshortname}_patc.nc
# Check if anl2mdlWeights exist or not, if not try to generate them
if [ ! -f ${anl2mdlWeights} ]; then
echo "Writing anl2mdlWeights --> ${anl2mdlWeights}"
set +e
(set -x; ncl ../remapping/gen_analysis_to_model_wgt_file.ncl \
'ANLGRID="'${RLLSOURCEGRID}'"' \
'ANLGRIDPATH="../remapping/anl_scrip/"' \
'DSTGRIDNAME="'${modelgridshortname}'"' \
'DSTGRIDFILE="'${modelgridfile}'"' \
'WGTFILEDIR="'${mapping_files_path}'"' \
) ; exit_status=$?
check_ncl_exit "gen_analysis_to_model_wgt_file.ncl" $exit_status
set -e
else
echo "Betacast-generated anl2mdlWeights --> ${anl2mdlWeights} already exists, using those!"
fi
else
echo "User has provided anl2mdlWeights --> ${anl2mdlWeights}, using those!"
fi # check if anl2mdlWeights is passed in
if [[ "$atmDataType" -eq 9 ]]; then
if [[ -z "${m2m_remap_file}" || ! -e "${m2m_remap_file}" ]]; then
echo "User did not explicitly specify m2m_remap_file, trying to generate from SCRIP grid"
if [ ! -f ${m2m_gridfile} ]; then
echo "m2m_gridfile --> ${m2m_gridfile} does not exist, exiting"
echo "specify this as a SCRIP file in the namelist or m2m_remap_file"
exit 19
fi
# Get name without suffix
m2mgridshortname=$(basename "${m2m_gridfile%.*}")
m2m_remap_file=${mapping_files_path}/map_${m2mgridshortname}_TO_era5_0.25x0.25_patc.nc
# Check if m2m_remap_file exist or not, if not try to generate them
if [ ! -f ${m2m_remap_file} ]; then
echo "Writing m2m_remap_file --> ${m2m_remap_file}"
set +e
(set -x; ncl ../remapping/gen_analysis_to_model_wgt_file.ncl \
'ANLGRID="era5_0.25x0.25"' \
'ANLGRIDPATH="../remapping/anl_scrip/"' \
'DSTGRIDNAME="'${m2mgridshortname}'"' \
'DSTGRIDFILE="'${m2m_gridfile}'"' \
'WGTFILEDIR="'${mapping_files_path}'"' \
FLIP_MODEL_AND_ANALYSIS=True \
) ; exit_status=$?
check_ncl_exit "gen_analysis_to_model_wgt_file.ncl" $exit_status
set -e
else
echo "Betacast-generated m2m_remap_file --> ${m2m_remap_file} already exists, using those!"
fi
else
echo "User has provided m2m_remap_file --> ${m2m_remap_file}, using those!"
fi
fi
if [[ "$atmDataType" -eq 9 ]]; then
# If do_model2model is true, then we need to find the file
if [[ -d "$m2m_parent_source" ]]; then
echo "m2m_parent_source ($m2m_parent_source) is provided as a dir of nc files."
set +e
(set -x; ncl find-time-file.ncl \
'DIR="'${m2m_parent_source}'"' \
YYYYMMDDHH=${yearstr}${monthstr}${daystr}${cyclestr} \
'UQSTR="'${uniqtime}'"' \
) ; exit_status=$?
check_ncl_exit "find-time-file.ncl" $exit_status
set -e
while IFS= read -r line || [[ -n "$line" ]]; do
atm_file_paths["9"]=$line
break # Exit after reading the first line
done < m2mfile.$uniqtime
[[ ! -f "${atm_file_paths["9"]}" ]] && { echo "File does not exist."; exit 1; }
elif [[ -f "$m2m_parent_source" ]]; then
echo "m2m_parent_source ($m2m_parent_source) is provided as a file."
atm_file_paths["9"]=$m2m_parent_source
else
echo "m2m_parent_source ($m2m_parent_source) is not a file or directory. Exiting."
exit 1
fi
fi
echo "Doing atm_to_cam"
set +e #Need to turn off error checking b/c NCL returns 0 even if fatal
(set -x; ncl -n atm_to_cam.ncl \
'datasource="'${atm_data_sources[$atmDataType]}'"' \
numlevels=${numLevels} \
YYYYMMDDHH=${yearstr}${monthstr}${daystr}${cyclestr} \
'dycore="'${DYCORE}'"' \
'data_filename="'${atm_file_paths[$atmDataType]}'"' \
'RDADIR="'${RDADIR}'"' \
'wgt_filename="'${anl2mdlWeights}'"' \
'model_topo_file="'${adjust_topo-}'"' \
'mod_remap_file="'${m2m_remap_file-}'"' \
'mod_in_topo="'${m2m_topo_in-}'"' \
'adjust_config="'${adjust_flags-}'"' \
'se_inic = "'${sePreFilterIC}'"'
) ; exit_status=$?
check_ncl_exit "atm_to_cam.ncl" $exit_status
set -e
if ${do_frankengrid} ; then
# Fill in "templated" information from regional_src
regional_src=${regional_src/YYYY/$yearstr}
regional_src=${regional_src/MM/$monthstr}
regional_src=${regional_src/DD/$daystr}
regional_src=${regional_src/HH/$cyclestr}
echo "Doing Frankengrid with $regional_src"
TMPWGTFILE="./map_hwrf_storm_TO_modelgrid_patc.nc"
set +e # Turn error checking off for NCL
echo "Generating a temporary SCRIP file for HWRF"
(set -x; ncl ../remapping/gen_reglatlon_SCRIP.ncl \
'DSTGRIDNAME="hwrf_storm_scrip.nc"' \
'DSTDIR="./"' \
'SRCFILENAME="'${regional_src}'"' ) ; exit_status=$?
check_ncl_exit "gen_reglatlon_SCRIP.ncl" $exit_status
echo "Generating a temporary map file for HWRF"
(set -x; ncl ../remapping/gen_analysis_to_model_wgt_file.ncl \
'ANLGRID="hwrf_storm"' \
'DSTGRIDNAME="modelgrid"' \
'ANLGRIDPATH="./"' \
'WGTFILEDIR="./"' \
'DSTGRIDFILE="'${model_scrip}'"' ) ; exit_status=$?
check_ncl_exit "gen_analysis_to_model_wgt_file.ncl" $exit_status
echo "Generating regional Frankengrid for HWRF"
(set -x; ncl -n atm_to_cam.ncl 'datasource="HWRF"' \
'dycore="'${DYCORE}'"' \
numlevels=${numLevels} \
YYYYMMDDHH=${yearstr}${monthstr}${daystr}${cyclestr} \
'data_filename = "'${regional_src}'"' \
'wgt_filename="'${TMPWGTFILE}'"' \
'adjust_config=""' \
'se_inic = "'${sePreFilterIC}_reg.nc'"' ) ; exit_status=$?
check_ncl_exit "atm_to_cam.ncl" $exit_status
set -e # Turn error checking back on
echo "Overlay regional file on top of basefile"
cp -v ${sePreFilterIC} ${sePreFilterIC}_base.nc
python overlay.py "${sePreFilterIC}" "${sePreFilterIC}_reg.nc" --maxLev 80.
echo "Cleaning up temporary ESMF files"
rm -v $TMPWGTFILE
rm -v hwrf_storm_scrip.nc
rm -v ${sePreFilterIC}_reg.nc
fi
fi #End debug if statement
############################### #### ###############################
##### ADD OR REMOVE VORTEX
if ${add_vortex} ; then
cd $atm_to_cam_path/tcseed
set +e
echo "Adding or removing a TC from initial condition based on ${vortex_namelist}"
(set -x; ncl -n find-tc-fill-params.ncl 'inic_file= "'${sePreFilterIC}'"' 'pthi = "'${vortex_namelist}'"' ) ; exit_status=$?
check_ncl_exit "find-tc-fill-params.ncl" $exit_status
(set -x; ncl -n seed-tc-in-ncdata.ncl 'seedfile = "'${sePreFilterIC}'"' 'pthi = "'${vortex_namelist}'"' ) ; exit_status=$?
check_ncl_exit "seed-tc-in-ncdata.ncl" $exit_status
set -e
fi
############################### #### ###############################
##### ADD WHITE NOISE PERTURBATIONS
if ${add_noise} ; then
set +e
echo "Adding white noise to initial condition"
cd $atm_to_cam_path
(set -x; ncl -n perturb_white_noise.ncl 'basFileName = "'${sePreFilterIC}'"' ) ; exit_status=$?
check_ncl_exit "perturb_white_noise.ncl" $exit_status
set -e
fi
############################### #### ###############################
##### ADD PERTURBATIONS
if ${add_perturbs} ; then
echo "Adding perturbations"
cd $atm_to_cam_path/perturb
set +e
## Add perturbations to SST file
sstFileIC_WPERT=${sstFileIC}_PERT.nc
(set -x; ncl -n add_perturbations_to_sst.ncl 'BEFOREPERTFILE="'${sstFileIC}'"' \
'AFTERPERTFILE = "'${sstFileIC_WPERT}'"' \
'pthi="'${perturb_namelist}'"' ) ; exit_status=$?
check_ncl_exit "add_perturbations_to_sst.ncl" $exit_status
echo "SST perturbations added successfully"
## Add perturbations to ATM file
sePreFilterIC_WPERT=${sePreFilterIC}_PERT.nc
(set -x; ncl -n add_perturbations_to_cam.ncl 'BEFOREPERTFILE="'${sePreFilterIC}'"' \
'AFTERPERTFILE = "'${sePreFilterIC_WPERT}'"' \
'gridfile = "'${modelgridfile}'"' \
'MAPFILEPATH = "'${mapping_files_path}'"' \
'pthi="'${perturb_namelist}'"' ) ; exit_status=$?
check_ncl_exit "add_perturbations_to_cam.ncl" $exit_status
echo "ATM NCL completed successfully"
set -e # Turn error checking back on
# move temp perturb files to overwrite unperturbed files
mv ${sstFileIC_WPERT} ${sstFileIC}
mv ${sePreFilterIC_WPERT} ${sePreFilterIC}
fi
cd $path_to_case
############################### CISM SETUP ###############################
if [ -f user_nl_cism ]; then
sed -i '/dt_count/d' user_nl_cism
echo "dt_count = 8" >> user_nl_cism
fi
############################### CLM SETUP ###############################
echo "................. configuring land and/or runoff"
## TEMPORARY CLM -> LAND FIX
## Check if clmstart exists but landstart doesn't, move if that is the case
if [[ ! -d ${landdir} ]] && [[ -d ${path_to_rundir}/clmstart/ ]] ; then
echo "Moving ${path_to_rundir}/clmstart/ to ${landdir}"
mv -v ${path_to_rundir}/clmstart/ ${landdir}
else
echo "No need to modify land directory, either appropriately exists or will be created later"
fi
## END TEMP FIX
echo "Setting input land dataset"
# Clean up file to delete any special interp lines that may be needed later (but aren't needed for native init)
sed -i '/init_interp_fill_missing_with_natveg/d' user_nl_${lndName}
sed -i '/use_init_interp/d' user_nl_${lndName}
# Create a temp directory for now
RUNTMPDIR=$path_to_nc_files/tmp/
[ -z "$RUNTMPDIR" ] && { echo "RUNTMPDIR is not set. Exiting."; exit 1; }
# Create directory and make sure it was actually generated (to prevent user from not having write perms)
mkdir -vp $RUNTMPDIR
[ -d "$RUNTMPDIR" ] || { echo "Failed to create $RUNTMPDIR. Exiting."; exit 1; }
# Delete files in RUNTMPDIR
find "$RUNTMPDIR" -type f -exec rm -v {} +
# We want to check ${landdir} for land restart file with exact date match. If so, use that.
landrestartfile=$(find "${landdir}" -maxdepth 1 -type f -name "${casename}.${lndSpecialName}.r.${yearstr}-${monthstr}-${daystr}-${cyclestrsec}.*" | head -n 1)
# Check to see if file exists on native SE land grid
if [ -n "${landrestartfile}" ] && [ -f "${landrestartfile}" ]; then
echo "File exists at exact time"
else
# If we don't have an exact match from above, trying 00Z first, then check landrawdir
echo "File does not exist at exact time"
landrestartfile=$(find "${landdir}" -maxdepth 1 -type f -name "${casename}.${lndSpecialName}.r.${yearstr}-${monthstr}-${daystr}-00000.*" | head -n 1)
if [ -n "${landrestartfile}" ] && [ -f "${landrestartfile}" ]; then
echo "File exists at 00Z"
else
rawlandrestartfile=$(find "${landrawdir}" -maxdepth 1 -type f -name "*.${lndSpecialName}.r.${yearstr}-${monthstr}-${daystr}-${cyclestrsec}.*" | head -n 1)
echo "rawlandrestartfile: ${rawlandrestartfile}"
if [ -n "${rawlandrestartfile}" ] && [ -f "${rawlandrestartfile}" ]; then
landrestartfile=${rawlandrestartfile}
else
echo "No LND restart file exists, setting landrestartfile to empty string."
landrestartfile=
fi
fi
fi
echo "landrestartfile: ${landrestartfile}"
if [ -f "${landrestartfile}" ] && [[ "${landrestartfile}" != *.nc ]]; then
echo "${landrestartfile} was found, but does not have an *.nc extension. Assuming compressed. Copying..."
cp -v ${landrestartfile} $RUNTMPDIR
try_uncompress $RUNTMPDIR/$(basename "${landrestartfile}")
landrestartfile=$(find "${RUNTMPDIR}" -maxdepth 1 -type f -name "*.${lndSpecialName}.r.${yearstr}-${monthstr}-${daystr}-*.nc" | head -n 1)
echo "Updated landrestartfile: ${landrestartfile}"
fi
## Now modify user_nl_${lndName}
xmlchange_verbose "${lndName^^}_FORCE_COLDSTART" "off"
if [ "${landrestartfile}" ] ; then
sed -i '/.*finidat/d' user_nl_${lndName}
echo "finidat='${landrestartfile}'" >> user_nl_${lndName}
if [ -n "${rawlandrestartfile-}" ] && [ -f "${rawlandrestartfile-}" ]; then
echo "Adding interpolation lines to user_nl_${lndName}"
echo "use_init_interp = .true." >> user_nl_${lndName}
echo "init_interp_fill_missing_with_natveg = .true." >> user_nl_${lndName}
fi
else
if [ -f user_nl_${lndName}_presave ] ; then
echo "Using pre-written user_nl_${lndName} file"
cp -v user_nl_${lndName}_presave user_nl_${lndName}
else
echo "WARNING: Land file DOES NOT EXIST, will use arbitrary user_nl_${lndName} already in folder"
echo "!!!!!!!!!!!!!"
sed -i '/.*finidat/d' user_nl_${lndName}
xmlchange_verbose "${lndName^^}_FORCE_COLDSTART" "on"
fi
fi
## Append a check error to ignore inconsistencies in the dataset
if [ $modelSystem -eq 0 ]; then # CLM/CTSM
sed -i '/check_finidat_pct_consistency/d' user_nl_${lndName}
sed -i '/check_finidat_year_consistency/d' user_nl_${lndName}
echo "check_finidat_pct_consistency = .false." >> user_nl_${lndName}
echo "check_finidat_year_consistency = .false." >> user_nl_${lndName}
elif [ $modelSystem -eq 1 ]; then # ELM
sed -i '/check_finidat_fsurdat_consistency/d' user_nl_${lndName}
echo "check_finidat_fsurdat_consistency = .false." >> user_nl_${lndName}
# 2/25/24 CMZ added since ELM doesn't have use_init_interp support for rawlandrestartfile
if [ -n "${rawlandrestartfile-}" ]; then # if rawlandrestartfile is SET *and* not empty...
echo "WARNING USER_NL: We used a rawlandrestartfile, but ELM doesn't support interpolation, removing relevant lines"
echo "WARNING USER_NL: If your model fails, check to make sure the rawlandrestartfile supports your target land grid"
sed -i '/use_init_interp/d' user_nl_${lndName}
sed -i '/init_interp_fill_missing_with_natveg/d' user_nl_${lndName}
fi
else
echo "Unknown modeling system set for modelSystem: $modelSystem"
exit 1
fi
############################### ROF SETUP ###############################
if [ $do_runoff = true ]; then
echo "USER_NL: Setting input ${rofName} dataset"
# Delete any existing input data
sed -i '/.*finidat_rtm/d' user_nl_${rofName}
# We want to check ${landdir} for land restart files. If so, use those.
rofrestartfile=$(find "${landdir}" -maxdepth 1 -type f -name "${casename}.${rofSpecialName}.r.${yearstr}-${monthstr}-${daystr}-${cyclestrsec}.*" | head -n 1)
echo $rofrestartfile
# Check to see if file exists on native SE land grid
if [ -n "${rofrestartfile}" ] && [ -f "${rofrestartfile}" ]; then
echo "USER_NL: ${rofName} file exists at exact time"
else
echo "USER_NL: ${rofName} file does not exist at exact time"
rofrestartfile=$(find "${landdir}" -maxdepth 1 -type f -name "${casename}.${rofSpecialName}.r.${yearstr}-${monthstr}-${daystr}-00000.*" | head -n 1)
if [ -n "${rofrestartfile}" ] && [ -f "${rofrestartfile}" ]; then
echo "USER_NL: ${rofName} file exists at 00Z"
else
rawrofrestartfile=$(find "${landrawdir}" -maxdepth 1 -type f -name "*.${rofSpecialName}.r.${yearstr}-${monthstr}-${daystr}-${cyclestrsec}.*" | head -n 1)
echo "rawrofrestartfile: ${rawrofrestartfile}"
if [ -n "${rawrofrestartfile}" ] && [ -f "${rawrofrestartfile}" ]; then
rofrestartfile=${rawrofrestartfile}
else
echo "No ROF restart file exists, setting rofrestartfile to empty string."
rofrestartfile=
fi
fi
fi
echo "USER_NL: rofrestartfile: ${rofrestartfile}"
if [ -f "${rofrestartfile}" ] && [[ "${rofrestartfile}" != *.nc ]]; then
echo "${rofrestartfile} was found, but does not have an *.nc extension. Assuming compressed. Copying..."
cp -v ${rofrestartfile} $RUNTMPDIR
try_uncompress $RUNTMPDIR/$(basename "${rofrestartfile}")
rofrestartfile=$(find "${RUNTMPDIR}" -maxdepth 1 -type f -name "*.${rofSpecialName}.r.${yearstr}-${monthstr}-${daystr}-*.nc" | head -n 1)
echo "Updated rofrestartfile: ${rofrestartfile}"
fi
## Now modify user_nl_${rofName}
if [ ${rofrestartfile} ] ; then
echo "USER_NL: Adding ${rofrestartfile} to user_nl_${rofName}"
echo "finidat_rtm='${rofrestartfile}'" >> user_nl_${rofName}
else
# Check to see if there is a raw ROF file in the landrawdir given by the user
rawrofrestartfile=$(ls ${landrawdir}/*.${rofSpecialName}.r.${yearstr}-${monthstr}-${daystr}-${cyclestrsec}.nc || true) # check for file, suppress failed ls error if true
echo "rawrofrestartfile: ${rawrofrestartfile}"
if [ ! -z ${rawrofrestartfile} ]; then # if rawrofrestartfile string is NOT empty, add it.
echo "WARNING USER_NL: Adding rawrofrestartfile for runoff, although no check to see if grid is consistent!"
echo "USER_NL: Adding ${rawrofrestartfile} to user_nl_${rofName}"
echo "finidat_rtm='${rawrofrestartfile}'" >> user_nl_${rofName}
else
echo "USER_NL: No ${rofName} restart file added, cold start"
fi
fi
fi # if do_runoff
echo "................. done configuring land and/or runoff"
############################### GENERIC CAM SETUP ###############################
# Setting projectID and queue
xmlchange_verbose "PROJECT" "$PROJECTID"
xmlchange_verbose "JOB_QUEUE" "$RUNQUEUE" "--force"
# Turning off archiving and restart file output in env_run.xml
xmlchange_verbose "DOUT_S" "FALSE"
xmlchange_verbose "REST_OPTION" "nyears"
xmlchange_verbose "REST_N" "9999"
if [ ${sstDataType} -ne 9 ] ; then
# We are using some sort of analysis SST
# Setting SST domain file
if [ "${cime_coupler}" == "nuopc" ] ; then
xmlchange_verbose "SSTICE_MESH_FILENAME" "${sst_ESMF_file}"
else
xmlchange_verbose "SSTICE_GRID_FILENAME" "${sst_domain_file}"
fi
# Setting SST from default to our SST
xmlchange_verbose "SSTICE_DATA_FILENAME" "${sstFileIC}"
# Standardizing streams for SST
xmlchange_verbose "SSTICE_YEAR_START" "1"
xmlchange_verbose "SSTICE_YEAR_END" "1"
else
# We already have a DOCN stream available to use (sstDataType 9)
# Reproducing previous DOCN configuration as specified by m2m_sst* in namelist
if [ "${cime_coupler}" == "nuopc" ] ; then
xmlchange_verbose "SSTICE_MESH_FILENAME" "${m2m_sst_grid_filename}"
else
xmlchange_verbose "SSTICE_GRID_FILENAME" "${m2m_sst_grid_filename}"
fi
xmlchange_verbose "SSTICE_DATA_FILENAME" "${m2m_sstice_data_filename}"
xmlchange_verbose "SSTICE_YEAR_ALIGN" "${m2m_sstice_year_align}"
xmlchange_verbose "SSTICE_YEAR_START" "${m2m_sstice_year_start}"
xmlchange_verbose "SSTICE_YEAR_END" "${m2m_sstice_year_end}"
# This is a cheat so that the m2m_sstice_data_filename is archived correctly.
#sstFileIC=$m2m_sstice_data_filename
fi
# Getting GLC coupling to handle forecasts across calendar years
xmlchange_verbose "GLC_AVG_PERIOD" "glc_coupling_period"
#######
if [ "$land_spinup" = true ] ; then
xmlchange_verbose "REST_OPTION" "ndays"