88
99# Disable these because this is our standard setup
1010# 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
1313
1414CIMEROOT = os .environ .get ("CIMEROOT" )
1515if CIMEROOT is None :
@@ -20,13 +20,13 @@ from standard_script_setup import *
2020from CIME .case import Case
2121from CIME .nmlgen import NamelistGenerator
2222from CIME .utils import expect
23- from CIME .buildnml import create_namelist_infile
23+ from CIME .buildnml import create_namelist_infile , parse_input
2424
2525logger = logging .getLogger (__name__ )
2626
2727# pylint: disable=too-many-arguments,too-many-locals,too-many-branches,too-many-statements
2828####################################################################################
29- def _create_namelists (case , confdir , inst_string , infile , nmlgen ):
29+ def _create_namelists (case , confdir , inst_string , infile , nmlgen , data_list_path ):
3030####################################################################################
3131 """Write out the namelist for this component.
3232
@@ -40,36 +40,29 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen):
4040 #----------------------------------------------------
4141 config = {}
4242 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" )
4444 config ['clm_accel' ] = case .get_value ("CLM_ACCELERATED_SPINUP" )
4545 config ['rof_grid' ] = case .get_value ("ROF_GRID" )
4646 config ['lnd_grid' ] = case .get_value ("LND_GRID" )
4747 config ['rof_ncpl' ] = case .get_value ("ROF_NCPL" )
4848 config ['simyr' ] = case .get_value ("MOSART_SIM_YEAR" )
4949
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' ])
5353
5454 #----------------------------------------------------
5555 # Check for incompatible options.
5656 #----------------------------------------------------
5757
5858 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" )
6760
6861 #----------------------------------------------------
6962 # Initialize namelist defaults
7063 #----------------------------------------------------
7164 nmlgen .init_defaults (infile , config )
72-
65+
7366 #----------------------------------------------------
7467 # Set values not obtained in the default settings
7568 #----------------------------------------------------
@@ -78,10 +71,10 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen):
7871 if run_type == 'branch' or run_type == 'hybrid' :
7972 run_refcase = case .get_value ("RUN_REFCASE" )
8073 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" )
8376 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 ) ):
8578 filename = "%s.mosart.r.%s-%s.nc" % (run_refcase , run_refdate , run_tod )
8679
8780 if run_type == "hybrid" :
@@ -95,7 +88,7 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen):
9588 else :
9689 nmlgen .add_default ("finidat_rtm" )
9790
98- ncpl_base_period = case .get_value ('NCPL_BASE_PERIOD' )
91+ ncpl_base_period = case .get_value ('NCPL_BASE_PERIOD' )
9992 if ncpl_base_period == 'hour' :
10093 basedt = 3600
10194 elif ncpl_base_period == 'day' :
@@ -118,7 +111,7 @@ def _create_namelists(case, confdir, inst_string, infile, nmlgen):
118111
119112 mosart_ncpl = case .get_value ("ROF_NCPL" )
120113 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 "
122115 % (mosart_ncpl , basedt ))
123116 else :
124117 coupling_period = basedt / mosart_ncpl
@@ -135,26 +128,26 @@ def buildnml(case, caseroot, compname):
135128###############################################################################
136129 """Build the mosart namelist """
137130
138- # Build the component namelist
131+ # Build the component namelist
139132 if compname != "mosart" :
140133 raise AttributeError
141134
142- srcroot = case .get_value ("SRCROOT" )
135+ srcroot = case .get_value ("SRCROOT" )
143136 rundir = case .get_value ("RUNDIR" )
144137 ninst = case .get_value ("NINST_ROF" )
145138
146139 # Determine configuration directory
147- confdir = os .path .join (caseroot ,"Buildconf" ,"mosartconf" )
140+ confdir = os .path .join (caseroot , "Buildconf" , "mosartconf" )
148141 if not os .path .isdir (confdir ):
149142 os .makedirs (confdir )
150143
151144 #----------------------------------------------------
152- # Construct the namelist generator
145+ # Construct the namelist generator
153146 #----------------------------------------------------
154147 # Determine directory for user modified namelist_definitions.xml and namelist_defaults.xml
155148 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 )
158151
159152 # NOTE: User definition *replaces* existing definition.
160153 namelist_xml_dir = os .path .join (srcroot , "components" , "mosart" , "cime_config" )
@@ -168,6 +161,12 @@ def buildnml(case, caseroot, compname):
168161 # Create the namelist generator object - independent of instance
169162 nmlgen = NamelistGenerator (case , definition_file )
170163
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 )
171170 #----------------------------------------------------
172171 # Loop over instances
173172 #----------------------------------------------------
@@ -180,9 +179,9 @@ def buildnml(case, caseroot, compname):
180179
181180 # If multi-instance case does not have restart file, use
182181 # 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 )))):
186185 shutil .copy (os .path .join (rundir , rpointer ),
187186 os .path .join (rundir , rpointer + inst_string ))
188187
@@ -199,16 +198,16 @@ def buildnml(case, caseroot, compname):
199198 namelist_infile = [infile ]
200199
201200 # 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 )
203202
204203 # copy namelist files and stream text files, to rundir
205204 if os .path .isdir (rundir ):
206- file_src = os .path .join (confdir , 'mosart_in' )
205+ file_src = os .path .join (confdir , 'mosart_in' )
207206 file_dest = os .path .join (rundir , 'mosart_in' )
208207 if inst_string :
209208 file_dest += inst_string
210209 shutil .copy (file_src , file_dest )
211-
210+
212211###############################################################################
213212def _main_func ():
214213
0 commit comments