Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
7b74a93
remove unused variable in conflict
jedwards4b Jun 7, 2021
237b5f9
Merge pull request #99 from jedwards4b/no_esmf_calendar1
jedwards4b Jun 10, 2021
bb5b02f
Merge pull request #3 from NOAA-EMC/develop
uturuncoglu Jun 10, 2021
f60af54
fix for diro and logfile attributes
Jun 11, 2021
4fc8395
added stream name for inline initialization
Jun 15, 2021
a425b0a
Merge branch 'master' into feature/add_inline_option
Jun 15, 2021
c00c198
try adding apt-get update
jedwards4b Jun 15, 2021
b977da1
Merge pull request #100 from mvertens/feature/add_inline_option
jedwards4b Jun 15, 2021
8d879db
update ERA5 data mode
Jun 18, 2021
4179ba4
fixed log output encountered in ctsm
Jun 22, 2021
bc411dc
Merge pull request #102 from mvertens/feature/fix_logout
jedwards4b Jun 23, 2021
5160f6b
working now
jedwards4b Jun 24, 2021
f972caf
add code to check neon data availability and populate the stream xml …
jedwards4b Jun 25, 2021
bfe8e84
use simple list instead of hash
jedwards4b Jun 25, 2021
094a929
improve file path check
jedwards4b Jun 28, 2021
765f932
needed for cime
jedwards4b Jun 29, 2021
e8ecf06
needed for cime
jedwards4b Jun 29, 2021
c999578
missed one python to python3
jedwards4b Jun 30, 2021
47525be
Merge branch 'master' of https://github.com/ESCOMP/CDEPS into neon_da…
jedwards4b Jul 12, 2021
284ac16
add testmod to 1PT test
jedwards4b Jul 12, 2021
663135a
Merge pull request #103 from jedwards4b/neon_data_chk
jedwards4b Jul 13, 2021
de586eb
Merge pull request #4 from hafs-community/feature/hafs_couplehycom_cdeps
BinLiu-NOAA Jul 19, 2021
3eba409
CDEPS was not incorporating SourceMods
jedwards4b Jul 22, 2021
b09a6ee
improved technique
jedwards4b Jul 22, 2021
fa5c909
only search cdeps SourceMods directories
jedwards4b Jul 22, 2021
e32614f
Merge pull request #106 from jedwards4b/cdeps_SourceMods_fix
jedwards4b Jul 22, 2021
9ba1ba3
fix for long directory and file names
Jul 23, 2021
98d4182
Merge branch 'master' into feature/pr
uturuncoglu Jul 26, 2021
e9e072d
Merge pull request #108 from hafs-community/feature/pr
uturuncoglu Jul 26, 2021
f96a605
format of neon data listing changed
jedwards4b Aug 1, 2021
a9625cd
Merge pull request #110 from jedwards4b/neon_csv_format
jedwards4b Aug 1, 2021
340392c
allow flexibility in neon site name, does not affect any other config…
jedwards4b Aug 4, 2021
c95ee91
add support for REST_OPTION end and always write a restart at end of …
jedwards4b Aug 5, 2021
62e0716
add documentation, rename variable
jedwards4b Aug 6, 2021
8b5db51
initialize fieldbundle to 1 in map creation
Aug 6, 2021
46c3e80
add ispresent and isset, set logical correctly
jedwards4b Aug 6, 2021
6ec3acf
Merge pull request #111 from jedwards4b/add_rest_option_end
jedwards4b Aug 6, 2021
4303cf5
fixed bug for aquaplanet constant
Aug 6, 2021
3438556
Merge branch 'master' into feature/fixes_for_failedtests
Aug 6, 2021
930f0f6
cleanup of incorrect merge to cdeps master
Aug 7, 2021
b72ef9b
Merge pull request #112 from mvertens/feature/fixes_for_failedtests
mvertens Aug 7, 2021
53d85d4
avoid a pgi compiler error
jedwards4b Aug 16, 2021
56b165a
first set of changes for new stream mods
Aug 20, 2021
56489ba
introduction of user_nl_dxxx_streams
Aug 22, 2021
162c2d7
fixed compilation issues and generalize user_nl_xxx_streams to compon…
Aug 23, 2021
9634d8a
updates for error checking
Aug 24, 2021
7f6161b
added more error checking
Aug 24, 2021
0fcb83c
fix problems in testing
Aug 25, 2021
3a8f069
added continuation line support for user_nl_xxx_stream files
Aug 25, 2021
d3c5e67
Merge pull request #117 from mvertens/feature/new_stream_mod
jedwards4b Aug 26, 2021
3daa3d5
fix issues with streams
jedwards4b Aug 26, 2021
a05c3ec
Merge pull request #118 from jedwards4b/jedwards/fixes_for_cdeps_streams
jedwards4b Aug 27, 2021
503fbe3
abort if any single column data is _Fillvalue
jedwards4b Aug 27, 2021
3ffc516
Merge pull request #119 from jedwards4b/fillvalue_chk_for_scol_data
jedwards4b Sep 1, 2021
c15a99d
remove debug print statements
jedwards4b Sep 2, 2021
8cc01f9
fixed multi-instance for cesm
Sep 21, 2021
6129767
Merge pull request #121 from mvertens/feature/fix_multi_instance
mvertens Sep 21, 2021
8774e97
Merge branch 'master' into develop
binli2337 Sep 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 110 additions & 29 deletions cime_config/stream_cdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,37 @@

_ymd_re = re.compile(r"%(?P<digits>[1-9][0-9]*)?y(?P<month>m(?P<day>d)?)?")

_stream_nuopc_file_template = """
_stream_file_template = """
<stream_info name="{streamname}">
<taxmode>{stream_taxmode}</taxmode>
<tInterpAlgo>{stream_tintalgo}</tInterpAlgo>
<readMode>{stream_readmode}</readMode>
<tintalgo>{stream_tintalgo}</tintalgo>
<readmode>{stream_readmode}</readmode>
<mapalgo>{stream_mapalgo}</mapalgo>
<dtlimit>{stream_dtlimit}</dtlimit>
<yearFirst>{stream_year_first}</yearFirst>
<yearLast>{stream_year_last}</yearLast>
<yearAlign>{stream_year_align}</yearAlign>
<stream_vectors>{stream_vectors}</stream_vectors>
<stream_mesh_file>{stream_meshfile}</stream_mesh_file>
<stream_lev_dimname>{stream_lev_dimname}</stream_lev_dimname>
<stream_data_files>
<year_first>{stream_year_first}</year_first>
<year_last>{stream_year_last}</year_last>
<year_align>{stream_year_align}</year_align>
<vectors>{stream_vectors}</vectors>
<meshfile>{stream_meshfile}</meshfile>
<lev_dimname>{stream_lev_dimname}</lev_dimname>
<datafiles>
{stream_datafiles}
</stream_data_files>
<stream_data_variables>
</datafiles>
<datavars>
{stream_datavars}
</stream_data_variables>
<stream_offset>{stream_offset}</stream_offset>
</stream_info>
</datavars>
<offset>{stream_offset}</offset>
</stream_info>

"""

valid_values = {}
valid_values["mapalgo"] = ["bilinear", "nn", "redist", "mapconsd", "mapconf"]
valid_values["tintalgo"] = ["lower", "upper", "nearest", "linear", "coszen"]
valid_values["taxmode"] = ["cycle", "extend", "limit"]

xml_scalar_names = ["stream_meshfile", "stream_mapalgo", "stream_tintalgo", "stream_taxmode", "stream_dtlimit"]

class StreamCDEPS(GenericXML):

def __init__(self, infile, schema):
Expand All @@ -54,16 +61,77 @@ def __init__(self, infile, schema):
if os.path.exists(infile):
GenericXML.read(self, infile, schema)

def create_stream_xml(self, stream_names, case, streams_xml_file, data_list_file, available_neon_data=None):
def create_stream_xml(self, stream_names, case, streams_xml_file, data_list_file, user_mods_file,
available_neon_data=None):
"""
Create the stream xml file and append the required stream input data to the input data list file
available_neon_data is an optional list of NEON tower data available for the given case, if provided
this data will be used to populate the NEON streamdata list
"""

# determine if there are user mods
lines_input = []
expect (os.path.isfile(user_mods_file),
"No file {} found in case directory".format(user_mods_file))
with open(user_mods_file, "r", encoding='utf-8') as stream_mods_file:
lines_input = stream_mods_file.readlines()
stream_mod_dict = {}
n = len(lines_input)

index = 0
lines_input_new = []
while index < len(lines_input):
line = lines_input[index].strip()
if line.startswith('!') or (not line):
index = index + 1
continue
while line[-1] == '\\':
index += 1
if index < len(lines_input):
line = line[:-1].strip() + ' ' + lines_input[index].strip()
else:
line = line.replace('\\', '').strip()
break
# endif
# end while
index += 1
lines_input_new.append(line)
#end while

for line in lines_input_new:
# read in a single line in user_nl_xxx_streams and parse it if it is not a comment
stream_mods = [x.strip() for x in line.strip().split(":") if x]
expect(len(stream_mods) == 2,
"input stream mod can only be of the form streamname:var=value(s)")
stream,varmod = stream_mods
expect (stream in stream_names,
"{} contains a streamname \'{}\' that is not part of valid streamnames {}".
format(user_mods_file,stream,stream_names))
if stream not in stream_mod_dict:
stream_mod_dict[stream] = {}
# var=value and check the validity
varmod_args = [x.strip() for x in varmod.split("=") if x]
expect(len(varmod_args) == 2,
"input stream mod can only be of the form streamname:var=value(s)")
# allow multiple entries for varmod_args, most recent wins
varname,varval = varmod_args
if varname in stream_mod_dict[stream]:
logger.warning("varname {} is already in stream mod dictionary".format(varname))

if varname == "datavars" or varname == "datafiles":
if varname == "datavars":
varvals = ["<var>{}</var>".format(x.strip()) for x in varval.split(",") if x]
if varname == "datafiles":
varvals = ["<file>{}</file>".format(x.strip()) for x in varval.split(",") if x]
varval = " " + "\n ".join(varvals)
varval = varval.strip()
stream_mod_dict[stream][varname] = varval

# write header of stream file
with open(streams_xml_file, 'w') as stream_file:
with open(streams_xml_file, 'w', encoding='utf-8') as stream_file:
stream_file.write('<?xml version="1.0"?>\n')
stream_file.write('<file id="stream" version="2.0">\n')

# write contents of stream file
for stream_name in stream_names:
if stream_name.startswith("NEON."):
Expand Down Expand Up @@ -131,11 +199,8 @@ def create_stream_xml(self, stream_names, case, streams_xml_file, data_list_file
stream_vars[node_name] += "\n " + self._add_xml_delimiter(stream_datafiles.split("\n"), "file")
else:
stream_vars[node_name] = self._add_xml_delimiter(stream_datafiles.split("\n"), "file")
elif ( node_name == 'stream_meshfile'
or node_name == 'stream_mapalgo'
or node_name == 'stream_tintalgo'
or node_name == 'stream_taxmode'
or node_name == 'stream_dtlimit'):
#endif
elif (node_name in xml_scalar_names):
attributes['model_grid'] = case.get_value("GRID")
attributes['compset'] = case.get_value("COMPSET")
value = self._get_value_match(node, node_name[7:], attributes=attributes)
Expand All @@ -148,18 +213,34 @@ def create_stream_xml(self, stream_names, case, streams_xml_file, data_list_file
# Get the other dependencies
stream_dict = self._add_value_to_dict(stream_vars, case, node)

# substitute user_mods in generated stream file (i.e. stream_vars)
mod_dict = {}
if stream_vars['streamname'] in stream_mod_dict:
mod_dict = stream_mod_dict[stream_vars['streamname']]
for var_key in mod_dict:
expect( 'stream_' + var_key in stream_vars,
"stream mod {} is not a valid name in {}".format(var_key,user_mods_file))
if var_key in valid_values:
expect(mod_dict[var_key] in valid_values[var_key],
"{} can only have values of {} for stream {} in file {}".
format(var_key, valid_values[var_key], stream_name, user_mods_file))
stream_vars['stream_' + var_key] = mod_dict[var_key]
if var_key == 'datafiles':
stream_datafiles = mod_dict[var_key]
stream_datafiles = stream_datafiles.replace('<file>','').replace('</file>','')

# append to stream xml file
stream_file_text = _stream_nuopc_file_template.format(**stream_vars)
with open(streams_xml_file, 'a') as stream_file:
stream_file.write(stream_file_text)
stream_file_text = _stream_file_template.format(**stream_vars)
with open(streams_xml_file, 'a', encoding='utf-8') as stream_file:
stream_file.write(case.get_resolved_value(stream_file_text))

# append to input_data_list
if stream_vars['stream_meshfile']:
stream_meshfile = stream_vars['stream_meshfile'].strip()
self._add_entries_to_inputdata_list(stream_meshfile, stream_datafiles.split("\n"), data_list_file)

# write close of stream xml file
with open(streams_xml_file, 'a') as stream_file:
with open(streams_xml_file, 'a', encoding='utf-8') as stream_file:
stream_file.write("</file>\n")

def _get_stream_first_and_last_dates(self, stream, case):
Expand All @@ -181,7 +262,7 @@ def _add_entries_to_inputdata_list(self, stream_meshfile, stream_datafiles, data
and writes out the new file
"""
lines_hash = self._get_input_file_hash(data_list_file)
with open(data_list_file, 'a') as input_data_list:
with open(data_list_file, 'a', encoding='utf-8') as input_data_list:
# write out the mesh file separately
string = "mesh = {}\n".format(stream_meshfile)
hashValue = hashlib.md5(string.rstrip().encode('utf-8')).hexdigest()
Expand All @@ -191,7 +272,7 @@ def _add_entries_to_inputdata_list(self, stream_meshfile, stream_datafiles, data
for i, filename in enumerate(stream_datafiles):
if filename.strip() == '':
continue
string = "file{:d} = {}\n".format(i+1, filename)
string = "file{:d} = {}\n".format(i+1, filename.strip())
hashValue = hashlib.md5(string.rstrip().encode('utf-8')).hexdigest()
if hashValue not in lines_hash:
input_data_list.write(string)
Expand All @@ -202,7 +283,7 @@ def _get_input_file_hash(self, data_list_file):
"""
lines_hash = set()
if os.path.isfile(data_list_file):
with open(data_list_file, "r") as input_data_list:
with open(data_list_file, "r", encoding='utf-8') as input_data_list:
for line in input_data_list:
hashValue = hashlib.md5(line.rstrip().encode('utf-8')).hexdigest()
logger.debug( "Found line {} with hash {}".format(line,hashValue))
Expand Down
58 changes: 29 additions & 29 deletions cime_config/streams.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@
<!-- simple elements -->
<!-- ======================== -->

<xs:element name="taxmode" type="xs:string"/>
<xs:element name="tInterpAlgo" type="xs:string"/>
<xs:element name="readMode" type="xs:string"/>
<xs:element name="mapalgo" type="xs:string"/>
<xs:element name="dtlimit" type="xs:double"/>
<xs:element name="yearFirst" type="xs:integer"/>
<xs:element name="yearLast" type="xs:integer"/>
<xs:element name="yearAlign" type="xs:integer"/>
<xs:element name="stream_offset" type="xs:integer"/>
<xs:element name="stream_vectors" type="xs:string"/>
<xs:element name="stream_mesh_file" type="xs:anyURI"/>
<xs:element name="stream_lev_dimname" type="xs:string"/>
<xs:element name="var" type="xs:string"/>
<xs:element name="taxmode" type="xs:string"/>
<xs:element name="tintalgo" type="xs:string"/>
<xs:element name="readmode" type="xs:string"/>
<xs:element name="mapalgo" type="xs:string"/>
<xs:element name="dtlimit" type="xs:double"/>
<xs:element name="year_first" type="xs:integer"/>
<xs:element name="year_last" type="xs:integer"/>
<xs:element name="year_align" type="xs:integer"/>
<xs:element name="offset" type="xs:integer"/>
<xs:element name="vectors" type="xs:string"/>
<xs:element name="meshfile" type="xs:anyURI"/>
<xs:element name="lev_dimname" type="xs:string"/>
<xs:element name="var" type="xs:string"/>

<!-- ======================== -->
<!-- complex elements -->
<!-- ======================== -->

<xs:element name="stream_data_files">
<xs:element name="datafiles">
<xs:complexType>
<xs:sequence>
<xs:element name="file" type="xs:anyURI" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="stream_data_variables">
<xs:element name="datavars">
<xs:complexType>
<xs:sequence>
<xs:element ref="var" minOccurs="1" maxOccurs="unbounded"/>
Expand All @@ -49,20 +49,20 @@
<xs:element name="stream_info">
<xs:complexType>
<xs:sequence>
<xs:element ref="taxmode"/>
<xs:element ref="tInterpAlgo" />
<xs:element ref="readMode" />
<xs:element ref="mapalgo" />
<xs:element ref="dtlimit" />
<xs:element ref="yearFirst" />
<xs:element ref="yearLast" />
<xs:element ref="yearAlign" />
<xs:element ref="stream_vectors" />
<xs:element ref="stream_mesh_file" />
<xs:element ref="stream_lev_dimname"/>
<xs:element ref="stream_data_files" />
<xs:element ref="stream_data_variables" />
<xs:element ref="stream_offset" />
<xs:element ref="taxmode" />
<xs:element ref="tintalgo" />
<xs:element ref="readmode" />
<xs:element ref="mapalgo" />
<xs:element ref="dtlimit" />
<xs:element ref="year_first" />
<xs:element ref="year_last" />
<xs:element ref="year_align" />
<xs:element ref="vectors" />
<xs:element ref="meshfile" />
<xs:element ref="lev_dimname" />
<xs:element ref="datafiles" />
<xs:element ref="datavars" />
<xs:element ref="offset" />
</xs:sequence>
<xs:attribute ref="name" />
</xs:complexType>
Expand Down
17 changes: 4 additions & 13 deletions datm/atm_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module cdeps_datm_comp
use dshr_strdata_mod , only : shr_strdata_get_stream_pointer, shr_strdata_setOrbs
use dshr_mod , only : dshr_model_initphase, dshr_init
use dshr_mod , only : dshr_state_setscalar, dshr_set_runclock, dshr_log_clock_advance
use dshr_mod , only : dshr_restart_read, dshr_restart_write, dshr_mesh_init
use dshr_mod , only : dshr_mesh_init, dshr_check_restart_alarm
use dshr_mod , only : dshr_orbital_init, dshr_orbital_update
use dshr_dfield_mod , only : dfield_type, dshr_dfield_add, dshr_dfield_copy
use dshr_fldlist_mod , only : fldlist_type, dshr_fldlist_add, dshr_fldlist_realize
Expand Down Expand Up @@ -448,7 +448,7 @@ subroutine ModelAdvance(gcomp, rc)
type(ESMF_Time) :: nextTime
type(ESMF_TimeInterval) :: timeStep
real(r8) :: nextsw_cday
logical :: restart_write ! restart alarm is ringing
logical :: restart_write ! restart alarm is ringing
integer :: next_ymd ! model date
integer :: next_tod ! model sec into model date
integer :: yr, mon, day ! year, month, day
Expand Down Expand Up @@ -485,18 +485,9 @@ subroutine ModelAdvance(gcomp, rc)
orbEccen, orbObliqr, orbLambm0, orbMvelpp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! determine if will write restart
call ESMF_ClockGetAlarm(clock, alarmname='alarm_restart', alarm=alarm, rc=rc)
restart_write = dshr_check_restart_alarm(clock, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (ESMF_AlarmIsRinging(alarm, rc=rc)) then
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_AlarmRingerOff( alarm, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
restart_write = .true.
else
restart_write = .false.
endif


! Run datm
call ESMF_TraceRegionEnter('datm_run')
call datm_comp_run(importstate, exportstate, next_ymd, next_tod, mon, &
Expand Down
Loading