8
8
9
9
# Disable these because this is our standard setup
10
10
# pylint: disable=wildcard-import,unused-wildcard-import,wrong-import-position
11
-
12
- import os , shutil , sys , glob
11
+ # pylint: disable=multiple-imports
12
+ import os , shutil , sys
13
13
14
14
CIMEROOT = os .environ .get ("CIMEROOT" )
15
15
if CIMEROOT is None :
@@ -20,13 +20,13 @@ from standard_script_setup import *
20
20
from CIME .case import Case
21
21
from CIME .nmlgen import NamelistGenerator
22
22
from CIME .utils import expect
23
- from CIME .buildnml import create_namelist_infile
23
+ from CIME .buildnml import create_namelist_infile , parse_input
24
24
25
25
logger = logging .getLogger (__name__ )
26
26
27
27
# pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements
28
28
####################################################################################
29
- def _create_namelists (case , confdir , inst_string , infile , nmlgen ):
29
+ def _create_namelists (case , confdir , inst_string , infile , nmlgen , data_list_path ):
30
30
####################################################################################
31
31
"""Write out the namelist for this component.
32
32
@@ -40,36 +40,29 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen):
40
40
#----------------------------------------------------
41
41
config = {}
42
42
config ['mosart_mode' ] = case .get_value ("MOSART_MODE" )
43
- config ['mosart_flood_mode' ] = case .get_value ("MOSART_FLOOD_MODE" )
43
+ config ['mosart_flood_mode' ] = case .get_value ("MOSART_FLOOD_MODE" )
44
44
config ['clm_accel' ] = case .get_value ("CLM_ACCELERATED_SPINUP" )
45
45
config ['rof_grid' ] = case .get_value ("ROF_GRID" )
46
46
config ['lnd_grid' ] = case .get_value ("LND_GRID" )
47
47
config ['rof_ncpl' ] = case .get_value ("ROF_NCPL" )
48
48
config ['simyr' ] = case .get_value ("MOSART_SIM_YEAR" )
49
49
50
- logger .debug ("River Transport Model (MOSART) mode is %s " % ( config ['mosart_mode' ]) )
51
- logger .debug (" MOSART lnd grid is %s " % ( config ['lnd_grid' ]) )
52
- logger .debug (" MOSART rof grid is %s " % ( config ['rof_grid' ]) )
50
+ logger .debug ("River Transport Model (MOSART) mode is %s " , config ['mosart_mode' ])
51
+ logger .debug (" MOSART lnd grid is %s " , config ['lnd_grid' ])
52
+ logger .debug (" MOSART rof grid is %s " , config ['rof_grid' ])
53
53
54
54
#----------------------------------------------------
55
55
# Check for incompatible options.
56
56
#----------------------------------------------------
57
57
58
58
if config ["rof_grid" ] == "null" and config ["mosart_mode" ] != "NULL" :
59
- expect (False , "ROF_GRID is null MOSART_MODE not NULL" )
60
-
61
- #----------------------------------------------------
62
- # Clear out old data.
63
- #----------------------------------------------------
64
- data_list_path = os .path .join (case .get_case_root (), "Buildconf" , "mosart.input_data_list" )
65
- if os .path .exists (data_list_path ):
66
- os .remove (data_list_path )
59
+ expect (False , "ROF_GRID is null MOSART_MODE not NULL" )
67
60
68
61
#----------------------------------------------------
69
62
# Initialize namelist defaults
70
63
#----------------------------------------------------
71
64
nmlgen .init_defaults (infile , config )
72
-
65
+
73
66
#----------------------------------------------------
74
67
# Set values not obtained in the default settings
75
68
#----------------------------------------------------
@@ -78,10 +71,10 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen):
78
71
if run_type == 'branch' or run_type == 'hybrid' :
79
72
run_refcase = case .get_value ("RUN_REFCASE" )
80
73
run_refdate = case .get_value ("RUN_REFDATE" )
81
- run_tod = case .get_value ("RUN_REFTOD" )
82
- rundir = case .get_value ("RUNDIR" )
74
+ run_tod = case .get_value ("RUN_REFTOD" )
75
+ rundir = case .get_value ("RUNDIR" )
83
76
filename = "%s.mosart%s.r.%s-%s.nc" % (run_refcase , inst_string , run_refdate , run_tod )
84
- if not os .path .exists (os .path .join (rundir , filename ) ):
77
+ if not os .path .exists (os .path .join (rundir , filename ) ):
85
78
filename = "%s.mosart.r.%s-%s.nc" % (run_refcase , run_refdate , run_tod )
86
79
87
80
if run_type == "hybrid" :
@@ -95,7 +88,7 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen):
95
88
else :
96
89
nmlgen .add_default ("finidat_rtm" )
97
90
98
- ncpl_base_period = case .get_value ('NCPL_BASE_PERIOD' )
91
+ ncpl_base_period = case .get_value ('NCPL_BASE_PERIOD' )
99
92
if ncpl_base_period == 'hour' :
100
93
basedt = 3600
101
94
elif ncpl_base_period == 'day' :
@@ -118,7 +111,7 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen):
118
111
119
112
mosart_ncpl = case .get_value ("ROF_NCPL" )
120
113
if basedt % mosart_ncpl != 0 :
121
- expect (False , "mosart_ncpl %s doesn't divide evenly into basedt \n "
114
+ expect (False , "mosart_ncpl %s doesn't divide evenly into basedt %s \n "
122
115
% (mosart_ncpl , basedt ))
123
116
else :
124
117
coupling_period = basedt / mosart_ncpl
@@ -135,26 +128,26 @@ def buildnml(case, caseroot, compname):
135
128
###############################################################################
136
129
"""Build the mosart namelist """
137
130
138
- # Build the component namelist
131
+ # Build the component namelist
139
132
if compname != "mosart" :
140
133
raise AttributeError
141
134
142
- srcroot = case .get_value ("SRCROOT" )
135
+ srcroot = case .get_value ("SRCROOT" )
143
136
rundir = case .get_value ("RUNDIR" )
144
137
ninst = case .get_value ("NINST_ROF" )
145
138
146
139
# Determine configuration directory
147
- confdir = os .path .join (caseroot ,"Buildconf" ,"mosartconf" )
140
+ confdir = os .path .join (caseroot , "Buildconf" , "mosartconf" )
148
141
if not os .path .isdir (confdir ):
149
142
os .makedirs (confdir )
150
143
151
144
#----------------------------------------------------
152
- # Construct the namelist generator
145
+ # Construct the namelist generator
153
146
#----------------------------------------------------
154
147
# Determine directory for user modified namelist_definitions.xml and namelist_defaults.xml
155
148
user_xml_dir = os .path .join (caseroot , "SourceMods" , "src.mosart" )
156
- expect (os .path .isdir (user_xml_dir ),
157
- "user_xml_dir %s does not exist " % user_xml_dir )
149
+ expect (os .path .isdir (user_xml_dir ),
150
+ "user_xml_dir %s does not exist " % user_xml_dir )
158
151
159
152
# NOTE: User definition *replaces* existing definition.
160
153
namelist_xml_dir = os .path .join (srcroot , "components" , "mosart" , "cime_config" )
@@ -168,6 +161,12 @@ def buildnml(case, caseroot, compname):
168
161
# Create the namelist generator object - independent of instance
169
162
nmlgen = NamelistGenerator (case , definition_file )
170
163
164
+ #----------------------------------------------------
165
+ # Clear out old data.
166
+ #----------------------------------------------------
167
+ data_list_path = os .path .join (case .get_case_root (), "Buildconf" , "mosart.input_data_list" )
168
+ if os .path .exists (data_list_path ):
169
+ os .remove (data_list_path )
171
170
#----------------------------------------------------
172
171
# Loop over instances
173
172
#----------------------------------------------------
@@ -180,9 +179,9 @@ def buildnml(case, caseroot, compname):
180
179
181
180
# If multi-instance case does not have restart file, use
182
181
# single-case restart for each instance
183
- rpointer = "rpointer.rof"
184
- if (os .path .isfile (os .path .join (rundir ,rpointer )) and
185
- (not os .path .isfile (os .path .join (rundir ,rpointer + inst_string )))):
182
+ rpointer = "rpointer.rof"
183
+ if (os .path .isfile (os .path .join (rundir , rpointer )) and
184
+ (not os .path .isfile (os .path .join (rundir , rpointer + inst_string )))):
186
185
shutil .copy (os .path .join (rundir , rpointer ),
187
186
os .path .join (rundir , rpointer + inst_string ))
188
187
@@ -199,16 +198,16 @@ def buildnml(case, caseroot, compname):
199
198
namelist_infile = [infile ]
200
199
201
200
# create namelist and stream file(s) data component
202
- _create_namelists (case , confdir , inst_string , namelist_infile , nmlgen )
201
+ _create_namelists (case , confdir , inst_string , namelist_infile , nmlgen , data_list_path )
203
202
204
203
# copy namelist files and stream text files, to rundir
205
204
if os .path .isdir (rundir ):
206
- file_src = os .path .join (confdir , 'mosart_in' )
205
+ file_src = os .path .join (confdir , 'mosart_in' )
207
206
file_dest = os .path .join (rundir , 'mosart_in' )
208
207
if inst_string :
209
208
file_dest += inst_string
210
209
shutil .copy (file_src , file_dest )
211
-
210
+
212
211
###############################################################################
213
212
def _main_func ():
214
213
0 commit comments