Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move file stageing #10

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion WW3
51 changes: 0 additions & 51 deletions cime_config/buildlib
Original file line number Diff line number Diff line change
Expand Up @@ -75,57 +75,6 @@ def buildlib(bldroot, libroot, case, compname=None):
s,o,e = run_cmd("make install VERBOSE=1 DESTDIR={}".format(destdir), from_dir=bldroot, verbose=True)
expect(not s,"ERROR from make output={}, error={}".format(o,e))

#----------------------------------------------------
# Prestage necessary files to rundir
#----------------------------------------------------
rundir = case.get_value("RUNDIR")

# Create rundir/ww3_moddef_create
filename = "ww3_grid"
item = os.path.join(bldroot, filename)
if os.path.isfile(item):
ww3_moddef_dir = os.path.join(rundir, "ww3_moddef_create")
if not os.path.exists(ww3_moddef_dir):
os.makedirs(ww3_moddef_dir)
safe_copy(item, ww3_moddef_dir)

if case.get_value("WW3_MODDEF") == 'unset':
# Create output dir ww3_moddef_create if appropriate
output_dir = os.path.join(rundir, "ww3_moddef_create")
if not os.path.exists(output_dir):
os.makedirs(output_dir)

# Copy ww3_inp and other needed info to ww3_moddef_create directory
input_dir = case.get_value("WW3_GRID_INP_DIR")
files = os.listdir(input_dir)
for filename in files:
if not os.path.isfile(os.path.join(output_dir, filename)):
shutil.copy(os.path.join(input_dir, filename), os.path.join(output_dir, filename))

# Create mod_def file using ww3_grid and the grid_input files
os.chdir(output_dir)
os.scandir()
os.system("./ww3_grid > mod_def.ww3.log")

# Copy mod_def.ww3 to $RUNDIR
shutil.move("mod_def.ww3", os.path.join(rundir, "mod_def.ww3"))
shutil.move("mod_def.ww3.log", os.path.join(rundir, "mod_def.ww3.log"))

else:
# Use mod_def already created
mod_def_in = case.get_value("WW3_MODDEF")
if os.path.isfile(mod_def_in):
import filecmp
copy_file = False
if not os.path.isfile(os.path.join(rundir, "mod_def.ww3")):
copy_file = True
elif not filecmp.cmp(mod_def_in, os.path.join(rundir, "mod_def.ww3")):
copy_file = True
if copy_file:
shutil.copy(mod_def_in, os.path.join(rundir, "mod_def.ww3"))
else:
raise RuntimeError("mod_def_in {} does not exist on disk".format(mod_def_in))

def _main_func(args):
caseroot, libroot, bldroot = parse_input(args)
with Case(caseroot) as case:
Expand Down
58 changes: 58 additions & 0 deletions cime_config/buildnml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,64 @@ def buildnml(case, caseroot, compname):
logger.debug("WW3 namelist copy: file1 %s file2 %s ", file1, file2)
shutil.copy2(file1, file2)

_prestage_inputs(case)

###############################################################################
def _prestage_inputs(case):
###############################################################################
#----------------------------------------------------
# Prestage necessary files to rundir
#----------------------------------------------------
rundir = case.get_value("RUNDIR")

# Create rundir/ww3_moddef_create
filename = "ww3_grid"
bldroot = os.path.join(case.get_value("EXEROOT"),"wav","obj")
item = os.path.join(bldroot, filename)
if os.path.isfile(item):
ww3_moddef_dir = os.path.join(rundir, "ww3_moddef_create")
if not os.path.exists(ww3_moddef_dir):
os.makedirs(ww3_moddef_dir)
if not os.path.exists(os.path.join(ww3_moddef_dir,filename)):
safe_copy(item, ww3_moddef_dir)

if case.get_value("WW3_MODDEF") == 'unset':
# Create output dir ww3_moddef_create if appropriate
output_dir = os.path.join(rundir, "ww3_moddef_create")
if not os.path.exists(output_dir):
os.makedirs(output_dir)

# Copy ww3_inp and other needed info to ww3_moddef_create directory
input_dir = case.get_value("WW3_GRID_INP_DIR")
files = os.listdir(input_dir)
for filename in files:
if not os.path.isfile(os.path.join(output_dir, filename)):
safe_copy(os.path.join(input_dir, filename), os.path.join(output_dir, filename))

# Create mod_def file using ww3_grid and the grid_input files
if os.path.isfile(os.path.join(output_dir,"ww3_grid")):
run_cmd("./ww3_grid > mod_def.ww3.log", from_dir=output_dir)
if not os.path.isfile(os.path.join(output_dir,"mod_def.ww3")):
raise RuntimeError("mod_def.ww3 was not created, check mod_def.ww3.log for errors.")
shutil.move(os.path.join(output_dir,"mod_def.ww3"), os.path.join(rundir, "mod_def.ww3"))
else:
logger.warning("ww3_grid file not found. The mod_def.ww3 file will be created after the build phase.")

else:
# Use mod_def already created
mod_def_in = case.get_value("WW3_MODDEF")
if os.path.isfile(mod_def_in):
import filecmp
copy_file = False
if not os.path.isfile(os.path.join(rundir, "mod_def.ww3")):
copy_file = True
elif not filecmp.cmp(mod_def_in, os.path.join(rundir, "mod_def.ww3")):
copy_file = True
if copy_file:
shutil.copy(mod_def_in, os.path.join(rundir, "mod_def.ww3"))
else:
raise RuntimeError("mod_def_in {} does not exist on disk".format(mod_def_in))

###############################################################################
def _main_func():
###############################################################################
Expand Down