Skip to content

Commit

Permalink
Merge branch 'master' into jedwards/solar_zenith_angle_correction
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b authored Jan 6, 2022
2 parents 70009ce + 4ebc156 commit 11a48c8
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Contributors other than yourself, if any:

CMEPS Issues Fixed (include github issue #):
CDEPS Issues Fixed (include github issue #):

Are there dependencies on other component PRs
- [ ] CIME (list)
Expand Down
216 changes: 110 additions & 106 deletions cime_config/buildlib
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,51 @@ _LIBDIR = os.path.join(_CIMEROOT, "scripts", "lib")
sys.path.append(_LIBDIR)

from standard_script_setup import *
from CIME.buildlib import parse_input
from CIME.case import Case
from CIME.utils import run_cmd, symlink_force, expect
from CIME.build import get_standard_cmake_args
from CIME.XML.machines import Machines
from CIME.XML.compilers import Compilers

logger = logging.getLogger(__name__)

def buildlib(bldroot, libroot, case, compname=None):
if bldroot.endswith("obj") and not compname:
compname = os.path.basename(os.path.abspath(os.path.join(bldroot,os.pardir)))
def parse_command_line(args, description):
###############################################################################
parser = argparse.ArgumentParser(
usage="""\n{0} [--debug]
OR
{0} --verbose
OR
{0} --help
\033[1mEXAMPLES:\033[0m
\033[1;32m# Run \033[0m
> {0}
""" .format (os.path.basename(args[0])),

description=description,

formatter_class=argparse.ArgumentDefaultsHelpFormatter
)

CIME.utils.setup_standard_logging_options(parser)

parser.add_argument("buildroot",
help="build path root")

parser.add_argument("installpath",
help="install path ")

parser.add_argument("caseroot", nargs="?", default=os.getcwd(),
help="Case directory to build")

args = CIME.utils.parse_args_and_handle_standard_logging_options(args, parser)

return args.buildroot, args.installpath, args.caseroot


def buildlib(bldroot, libroot, case):
expect(not bldroot.endswith("obj"),
"It appears that the main CDEPS buildlib is being called for a specific component\n"
"(specific data model components should use buildlib_comps)")

if case.get_value("DEBUG"):
strdebug = "debug"
Expand All @@ -41,88 +74,76 @@ def buildlib(bldroot, libroot, case, compname=None):
sharedpath = os.path.join(case.get_value("COMPILER"),mpilib,
strdebug, strthread, "nuopc")

exe_root = case.get_value("EXEROOT")

if compname:
s, o, e = run_cmd("make d{}".format(compname), from_dir=bldroot, verbose=True)
libname = "lib{}.a".format(compname)
dlibname = "libd{}.a".format(compname)
dlibpath = os.path.join(bldroot, dlibname)
if os.path.exists(dlibpath):
symlink_force(os.path.join(bldroot,dlibname), os.path.join(libroot,libname))
else:
expect(False, "ERROR in {} build {} {}".format(compname,o,e))
logger.info("Running cmake for CDEPS")
srcpath = os.path.abspath(os.path.join(os.path.dirname(__file__),os.pardir))
cmake_flags = get_standard_cmake_args(case, os.path.join(sharedpath,"cdeps"), shared_lib=True)
# base path of install to be completed by setting DESTDIR in make install
cmake_flags += " -DCMAKE_INSTALL_PREFIX:PATH=/"
cmake_flags += " -DLIBROOT={} ".format(libroot)
cmake_flags += " -DMPILIB={} ".format(mpilib)
cmake_flags += " -DPIO_C_LIBRARY={path}/lib -DPIO_C_INCLUDE_DIR={path}/include ".format(path=os.path.join(case.get_value("EXEROOT"),sharedpath))
cmake_flags += " -DPIO_Fortran_LIBRARY={path}/lib -DPIO_Fortran_INCLUDE_DIR={path}/include ".format(path=os.path.join(case.get_value("EXEROOT"),sharedpath))
cmake_flags += srcpath
all_src_files = list(all_files_under(srcpath, ignoredirs=[".git","cmake","test",".github","cime_config","fox"]))
# Search SourceMods path for CDEPS files. We only look in the data component directories for these, files in cdeps share
# directories should be added to one of the data component directories
srcmodsdir = os.path.join(case.get_value("CASEROOT"),"SourceMods")
all_files_in_srcmods = []
for comp_class in case.get_values("COMP_CLASSES"):
if comp_class == "CPL":
continue
comp = case.get_value("COMP_{}".format(comp_class))
cdeps_comp_name = "d"+comp_class.lower()
if comp == cdeps_comp_name:
all_files_in_srcmods.extend(list(all_files_under(os.path.join(srcmodsdir,"src."+cdeps_comp_name))))

basenames1 = [os.path.basename(f) for f in all_src_files]
basenames2 = [os.path.basename(f) for f in all_files_in_srcmods]
srcmods = list(set(basenames1).intersection(set(basenames2)))
if srcmods:
logger.info("Found SourceMods {}".format(srcmods))
for i, v in enumerate(all_src_files):
for sfile in all_files_in_srcmods:
if os.path.basename(sfile) == os.path.basename(v):
all_src_files[i] = v.replace(os.path.dirname(v), os.path.dirname(sfile))
logger.debug("all_src_files: {}".format(all_src_files))
latest_src_file = max(all_src_files, key=os.path.getmtime)

src_time = os.path.getmtime(latest_src_file)
if os.path.exists(os.path.join(bldroot,"CMakeFiles")):
bld_time = os.path.getmtime(os.path.join(bldroot,"CMakeFiles"))
else:
bld_time = src_time - 1

# if any file in src is newer than CmakeFiles in the build directory, rerun cmake

if src_time > bld_time:
logger.info("cmake_flags {}".format(cmake_flags))
s,o,e = run_cmd("cmake {} ".format(cmake_flags), from_dir=bldroot, verbose=True)
expect(not s,"ERROR from cmake output={}, error={}".format(o,e))
else:
logger.info("Running cmake for CDEPS")
srcpath = os.path.abspath(os.path.join(os.path.dirname(__file__),os.pardir))
cmake_flags = get_standard_cmake_args(case, os.path.join(sharedpath,"cdeps"), shared_lib=True)
# base path of install to be completed by setting DESTDIR in make install
cmake_flags += " -DCMAKE_INSTALL_PREFIX:PATH=/"
cmake_flags += " -DLIBROOT={} ".format(libroot)
cmake_flags += " -DMPILIB={} ".format(mpilib)
cmake_flags += " -DPIO_C_LIBRARY={path}/lib -DPIO_C_INCLUDE_DIR={path}/include ".format(path=os.path.join(case.get_value("EXEROOT"),sharedpath))
cmake_flags += " -DPIO_Fortran_LIBRARY={path}/lib -DPIO_Fortran_INCLUDE_DIR={path}/include ".format(path=os.path.join(case.get_value("EXEROOT"),sharedpath))
cmake_flags += srcpath
all_src_files = list(all_files_under(srcpath, ignoredirs=[".git","cmake","test",".github","cime_config","fox"]))
# Search SourceMods path for CDEPS files. We only look in the data component directories for these, files in cdeps share
# directories should be added to one of the data component directories
srcmodsdir = os.path.join(case.get_value("CASEROOT"),"SourceMods")
all_files_in_srcmods = []
for comp_class in case.get_values("COMP_CLASSES"):
if comp_class == "CPL":
continue
comp = case.get_value("COMP_{}".format(comp_class))
cdeps_comp_name = "d"+comp_class.lower()
if comp == cdeps_comp_name:
all_files_in_srcmods.extend(list(all_files_under(os.path.join(srcmodsdir,"src."+cdeps_comp_name))))

basenames1 = [os.path.basename(f) for f in all_src_files]
basenames2 = [os.path.basename(f) for f in all_files_in_srcmods]
srcmods = list(set(basenames1).intersection(set(basenames2)))
if srcmods:
logger.info("Found SourceMods {}".format(srcmods))
for i, v in enumerate(all_src_files):
for sfile in all_files_in_srcmods:
if os.path.basename(sfile) == os.path.basename(v):
all_src_files[i] = v.replace(os.path.dirname(v), os.path.dirname(sfile))
logger.debug("all_src_files: {}".format(all_src_files))
latest_src_file = max(all_src_files, key=os.path.getmtime)

src_time = os.path.getmtime(latest_src_file)
if os.path.exists(os.path.join(bldroot,"CMakeFiles")):
bld_time = os.path.getmtime(os.path.join(bldroot,"CMakeFiles"))
else:
bld_time = src_time - 1

# if any file in src is newer than CmakeFiles in the build directory, rerun cmake

if src_time > bld_time:
logger.info("cmake_flags {}".format(cmake_flags))
s,o,e = run_cmd("cmake {} ".format(cmake_flags), from_dir=bldroot, verbose=True)
expect(not s,"ERROR from cmake output={}, error={}".format(o,e))
else:
# The dwav_lib is the last file built in cdeps, wait for it to be built
dwav_lib = os.path.join(bldroot,"dwav","libdwav.a")
time_to_wait = 300
time_counter = 0
while not os.path.exists(dwav_lib):
time.sleep(1)
time_counter += 1
if time_counter > time_to_wait:
break
expect(time_counter <= time_to_wait," Timeout waiting for {}".format(dwav_lib))

s,o,e = run_cmd("make install VERBOSE=1 DESTDIR={}".format(libroot), from_dir=bldroot, verbose=True)
expect(not s,"ERROR from make output={}, error={}".format(o,e))

# Link the CDEPS component directories to the location expected by cime
for comp in ("atm", "lnd", "ice", "ocn", "rof", "wav"):
compname = case.get_value("COMP_{}".format(comp.upper()))
comppath = os.path.join(case.get_value("EXEROOT"),comp,"obj")
if compname == "d"+comp:
if not os.path.islink(comppath):
os.rmdir(comppath)
symlink_force(os.path.join(bldroot,compname), comppath)
# The dwav_lib is the last file built in cdeps, wait for it to be built
dwav_lib = os.path.join(bldroot,"dwav","libdwav.a")
time_to_wait = 300
time_counter = 0
while not os.path.exists(dwav_lib):
time.sleep(1)
time_counter += 1
if time_counter > time_to_wait:
break
expect(time_counter <= time_to_wait," Timeout waiting for {}".format(dwav_lib))

s,o,e = run_cmd("make install VERBOSE=1 DESTDIR={}".format(libroot), from_dir=bldroot, verbose=True)
expect(not s,"ERROR from make output={}, error={}".format(o,e))

# Link the CDEPS component directories to the location expected by cime
for comp in ("atm", "lnd", "ice", "ocn", "rof", "wav"):
compname = case.get_value("COMP_{}".format(comp.upper()))
comppath = os.path.join(case.get_value("EXEROOT"),comp,"obj")
if compname == "d"+comp:
if not os.path.islink(comppath):
os.rmdir(comppath)
symlink_force(os.path.join(bldroot,compname), comppath)

def all_files_under(path, ignoredirs=[]):
"""Iterates through all files that are under the given path."""
Expand All @@ -131,27 +152,10 @@ def all_files_under(path, ignoredirs=[]):
for filename in filenames:
yield os.path.join(cur_path, filename)

def get_compiler_names(case):
machine=case.get_value("MACH")
machobj = Machines(machine=machine)
compobj = Compilers(machobj)
compiler = case.get_value("COMPILER")
if case.get_value("MPILIB") == 'mpi-serial':
ccomp = compobj.get_value("SCC",{"COMPILER":compiler,"MACH":machine}).strip()
cxxcomp = compobj.get_value("SCXX",{"COMPILER":compiler}).strip()
fcomp = compobj.get_value("SFC",{"COMPILER":compiler}).strip()
else:
ccomp = compobj.get_value("MPICC",{"COMPILER":compiler}).strip()
cxxcomp = compobj.get_value("MPICXX",{"COMPILER":compiler}).strip()
fcomp = compobj.get_value("MPIFC",{"COMPILER":compiler}).strip()

return ccomp, cxxcomp, fcomp


def _main_func(args):
caseroot, libroot, bldroot = parse_input(args)
bldroot, installpath, caseroot = parse_command_line(args, __doc__)
with Case(caseroot) as case:
buildlib(bldroot, libroot, case)
buildlib(bldroot, installpath, case)

if __name__ == "__main__":
_main_func(sys.argv)
46 changes: 46 additions & 0 deletions cime_config/buildlib_comps
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3

"""
build cime component model library. This buildlib script is used by all CDEPS components.
"""

import sys, os

_CIMEROOT = os.environ.get("CIMEROOT")
if _CIMEROOT is None:
raise SystemExit("ERROR: must set CIMEROOT environment variable")
sys.path.append(os.path.join(_CIMEROOT, "scripts", "Tools"))

_LIBDIR = os.path.join(_CIMEROOT, "scripts", "lib")
sys.path.append(_LIBDIR)

from standard_script_setup import *
from CIME.buildlib import parse_input
from CIME.case import Case
from CIME.utils import run_cmd, symlink_force, expect

logger = logging.getLogger(__name__)

def buildlib(bldroot, libroot, case, compname=None):
if not compname:
expect(bldroot.endswith("obj"),
"It appears that buildlib_comps is being called for the main CDEPS build\n"
"(the main CDEPS build should use buildlib, not buildlib_comps)")
compname = os.path.basename(os.path.abspath(os.path.join(bldroot,os.pardir)))

_, o, e = run_cmd("make d{}".format(compname), from_dir=bldroot, verbose=True)
libname = "lib{}.a".format(compname)
dlibname = "libd{}.a".format(compname)
dlibpath = os.path.join(bldroot, dlibname)
if os.path.exists(dlibpath):
symlink_force(os.path.join(bldroot,dlibname), os.path.join(libroot,libname))
else:
expect(False, "ERROR in {} build {} {}".format(compname,o,e))

def _main_func(args):
caseroot, libroot, bldroot = parse_input(args)
with Case(caseroot) as case:
buildlib(bldroot, libroot, case)

if __name__ == "__main__":
_main_func(sys.argv)
8 changes: 4 additions & 4 deletions cime_config/stream_cdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"""

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

Expand Down Expand Up @@ -94,7 +94,7 @@ def create_stream_xml(self, stream_names, case, streams_xml_file, data_list_file
break
# endif
# end while
index += 1
index += 1
lines_input_new.append(line)
#end while

Expand All @@ -104,9 +104,9 @@ def create_stream_xml(self, stream_names, case, streams_xml_file, data_list_file
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,
expect (stream in stream_names,
"{} contains a streamname \'{}\' that is not part of valid streamnames {}".
format(user_mods_file,stream,stream_names))
format(user_mods_file,stream,stream_names))
if stream not in stream_mod_dict:
stream_mod_dict[stream] = {}
# var=value and check the validity
Expand Down
2 changes: 1 addition & 1 deletion datm/cime_config/buildlib
2 changes: 1 addition & 1 deletion dice/cime_config/buildlib
2 changes: 1 addition & 1 deletion dlnd/cime_config/buildlib
2 changes: 1 addition & 1 deletion docn/cime_config/buildlib
2 changes: 1 addition & 1 deletion drof/cime_config/buildlib
2 changes: 1 addition & 1 deletion dwav/cime_config/buildlib
1 change: 1 addition & 0 deletions streams/dshr_stream_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ subroutine shr_stream_init_from_esmfconfig(streamfilename, streamdat, logunit,
streamdat(i)%varlist(n)%nameinfile = strm_tmpstrings(n)(1:index(trim(strm_tmpstrings(n)), " "))
streamdat(i)%varlist(n)%nameinmodel = strm_tmpstrings(n)(index(trim(strm_tmpstrings(n)), " ", .true.)+1:)
enddo
deallocate(strm_tmpstrings)
else
call shr_sys_abort("stream data variables must be provided")
endif
Expand Down

0 comments on commit 11a48c8

Please sign in to comment.