Skip to content

Commit

Permalink
Merge branch 'dev/esmg' into esmg_work
Browse files Browse the repository at this point in the history
  • Loading branch information
kshedstrom committed Sep 16, 2024
2 parents f643205 + 5fc90eb commit 4dc4c86
Show file tree
Hide file tree
Showing 66 changed files with 2,966 additions and 1,474 deletions.
114 changes: 69 additions & 45 deletions ac/makedep
Original file line number Diff line number Diff line change
Expand Up @@ -214,68 +214,91 @@ def create_deps(src_dirs, skip_dirs, makefile, debug, exec_target, fc_rule,
# Create new makefile
with open(makefile, 'w') as file:
print("# %s created by makedep" % (makefile), file=file)
print("", file=file)
print(file=file)
print("# Invoked as", file=file)
print('# '+' '.join(sys.argv), file=file)
print("", file=file)
print(file=file)
print("all:", " ".join(targets), file=file)
print("", file=file)

# print(file=file)
# print("# SRC_DIRS is usually set in the parent Makefile but in case is it not we", file=file)
# print("# record it here from when makedep was previously invoked.", file=file)
# print("SRC_DIRS ?= ${SRC_DIRS}", file=file)
# print("", file=file)

# print(file=file)
# print("# all_files:", ' '.join(all_files), file=file)
# print("", file=file)

# Write rule for each object from Fortran
for o in sorted(o2F90.keys()):
found_mods = [m for m in o2uses[o] if m in all_modules]
found_objs = [mod2o[m] for m in o2uses[o] if m in all_modules]
for obj in sorted(o2F90.keys()):
found_mods = [m for m in o2uses[obj] if m in all_modules]
found_objs = [mod2o[m] for m in o2uses[obj] if m in all_modules]
found_deps = [
dep for pair in zip(found_mods, found_objs) for dep in pair
]
missing_mods = [m for m in o2uses[o] if m not in all_modules]
missing_mods = [m for m in o2uses[obj] if m not in all_modules]

incs, inc_used = nested_inc(o2h[o] + o2inc[o], f2F, defines)
inc_mods = [u for u in inc_used if u not in found_mods and u in all_modules]
incs, inc_used = nested_inc(o2h[obj] + o2inc[obj], f2F, defines)
inc_mods = [
u for u in inc_used if u not in found_mods and u in all_modules
]

incdeps = sorted(set([f2F[f] for f in incs if f in f2F]))
incargs = sorted(set(['-I'+os.path.dirname(f) for f in incdeps]))
incargs = sorted(set(['-I' + os.path.dirname(f) for f in incdeps]))

# Header
print(file=file)
if debug:
print("# Source file {} produces:".format(o2F90[o]), file=file)
print("# object:", o, file=file)
print("# modules:", ' '.join(o2mods[o]), file=file)
print("# uses:", ' '.join(o2uses[o]), file=file)
print("# Source file {} produces:".format(o2F90[obj]), file=file)
print("# object:", obj, file=file)
print("# modules:", ' '.join(o2mods[obj]), file=file)
print("# uses:", ' '.join(o2uses[obj]), file=file)
print("# found mods:", ' '.join(found_mods), file=file)
print("# found objs:", ' '.join(found_objs), file=file)
print("# missing:", ' '.join(missing_mods), file=file)
print("# includes_all:", ' '.join(incs), file=file)
print("# includes_pth:", ' '.join(incdeps), file=file)
print("# incargs:", ' '.join(incargs), file=file)
print("# program:", ' '.join(o2prg[o]), file=file)
if o2mods[o]:
print(' '.join(o2mods[o])+':', o, file=file)
print(o + ':', o2F90[o], ' '.join(inc_mods + incdeps + found_deps), file=file)
print('\t'+fc_rule, ' '.join(incargs), file=file)
print("# program:", ' '.join(o2prg[obj]), file=file)

# Fortran Module dependencies
if o2mods[obj]:
print(' '.join(o2mods[obj]) + ':', obj, file=file)

# Fortran object dependencies
obj_incs = ' '.join(inc_mods + incdeps + found_deps)
print(obj + ':', o2F90[obj], obj_incs, file=file)

# Fortran object build rule
obj_rule = ' '.join([fc_rule] + incargs + ['-c', '$<'])
print('\t' + obj_rule, file=file)

# Write rule for each object from C
for o in sorted(o2c.keys()):
incdeps = sorted(set([f2F[h] for h in o2h[o] if h in f2F]))
incargs = sorted(set(['-I'+os.path.dirname(f) for f in incdeps]))
for obj in sorted(o2c.keys()):
incdeps = sorted(set([f2F[h] for h in o2h[obj] if h in f2F]))
incargs = sorted(set(['-I' + os.path.dirname(f) for f in incdeps]))

# Header
print(file=file)
if debug:
print("# Source file %s produces:" % (o2c[o]), file=file)
print("# object:", o, file=file)
print("# includes_all:", ' '.join(o2h[o]), file=file)
print("# Source file %s produces:" % (o2c[obj]), file=file)
print("# object:", obj, file=file)
print("# includes_all:", ' '.join(o2h[obj]), file=file)
print("# includes_pth:", ' '.join(incdeps), file=file)
print("# incargs:", ' '.join(incargs), file=file)
print(o+':', o2c[o], ' '.join(incdeps), file=file)
print('\t$(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) -c $<', ' '.join(incargs), file=file)

# C object dependencies
print(obj + ':', o2c[obj], ' '.join(incdeps), file=file)

# C object build rule
c_rule = ' '.join(
['$(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS)'] + incargs + ['-c', '$<']
)
#print('\t' + c_rule, ' '.join(incargs), '-c', '$<', file=file)
print('\t' + c_rule, file=file)

# Externals (so called)
if link_externals:
print("", file=file)
print(file=file)
print("# Note: The following object files are not associated with "
"modules so we assume we should link with them:", file=file)
print("# ", ' '.join(externals), file=file)
Expand All @@ -286,23 +309,23 @@ def create_deps(src_dirs, skip_dirs, makefile, debug, exec_target, fc_rule,
# Write rules for linking executables
for p in sorted(prg2o.keys()):
o = prg2o[p]
print("", file=file)
print(file=file)
print(p+':', ' '.join(link_obj(o, o2uses, mod2o, all_modules) + externals), file=file)
print('\t$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)', file=file)

# Write rules for building libraries
for lb in sorted(targ_libs):
print("", file=file)
print(file=file)
print(lb+':', ' '.join(list(o2F90.keys()) + list(o2c.keys())), file=file)
print('\t$(AR) $(ARFLAGS) $@ $^', file=file)

# Write cleanup rules
print("", file=file)
print(file=file)
print("clean:", file=file)
print('\trm -f *.mod *.o', ' '.join(list(prg2o.keys()) + targ_libs), file=file)

# Write re-generation rules
print("", file=file)
print(file=file)
print("remakedep:", file=file)
print('\t'+' '.join(sys.argv), file=file)

Expand Down Expand Up @@ -366,24 +389,23 @@ def scan_fortran_file(src_file, defines=None):

cpp_defines = defines if defines is not None else []

#cpp_macros = [define.split('=')[0] for define in cpp_defines]
cpp_macros = dict([t.split('=') for t in cpp_defines])
cpp_group_stack = []

with io.open(src_file, 'r', errors='replace') as file:
lines = file.readlines()

external_namespace = True
# True if we are in the external (i.e. global) namespace
# True if we are in the external (i.e. global) namespace

file_has_externals = False
# True if the file contains any external objects
# True if the file contains any external objects

cpp_exclude = False
# True if the parser excludes the subsequent lines
# True if the parser excludes the subsequent lines

cpp_group_stack = []
# Stack of condition group exclusion states
# Stack of condition group exclusion states

for line in lines:
# Start of #ifdef condition group
Expand Down Expand Up @@ -446,14 +468,16 @@ def scan_fortran_file(src_file, defines=None):
if match:
new_macro = line.lstrip()[1:].split()[1]
try:
cpp_macros.remove(new_macro)
except:
# Ignore missing macros (for now?)
cpp_macros.pop(new_macro)
except KeyError:
# C99: "[A macro] is ignored if the specified identifier is
# not currently defined as a macro name."
continue

match = re_module.match(line.lower())
if match:
if match.group(1) not in 'procedure': # avoid "module procedure" statements
# Avoid "module procedure" statements
if match.group(1) not in 'procedure':
module_decl.append(match.group(1))
external_namespace = False

Expand Down Expand Up @@ -632,9 +656,9 @@ parser.add_argument(
)
parser.add_argument(
'-f', '--fc_rule',
default="$(FC) $(DEFS) $(FCFLAGS) $(CPPFLAGS) -c $<",
default="$(FC) $(DEFS) $(CPPFLAGS) $(FCFLAGS)",
help="String to use in the compilation rule. Default is: "
"'$(FC) $(DEFS) $(FCFLAGS) $(CPPFLAGS) -c $<'"
"'$(FC) $(DEFS) $(CPPFLAGS) $(FCFLAGS)'"
)
parser.add_argument(
'-x', '--exec_target',
Expand Down
14 changes: 7 additions & 7 deletions config_src/drivers/FMS_cap/MOM_surface_forcing_gfdl.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1099,10 +1099,10 @@ subroutine extract_IOB_stresses(IOB, index_bounds, Time, G, US, CS, taux, tauy,
tau_mag = 0.0 ; gustiness = CS%gust_const
if (((G%mask2dBu(I,J) + G%mask2dBu(I-1,J-1)) + &
(G%mask2dBu(I,J-1) + G%mask2dBu(I-1,J))) > 0.0) then
tau_mag = sqrt(((G%mask2dBu(I,J)*(taux_in_B(I,J)**2 + tauy_in_B(I,J)**2) + &
G%mask2dBu(I-1,J-1)*(taux_in_B(I-1,J-1)**2 + tauy_in_B(I-1,J-1)**2)) + &
(G%mask2dBu(I,J-1)*(taux_in_B(I,J-1)**2 + tauy_in_B(I,J-1)**2) + &
G%mask2dBu(I-1,J)*(taux_in_B(I-1,J)**2 + tauy_in_B(I-1,J)**2)) ) / &
tau_mag = sqrt(((G%mask2dBu(I,J)*((taux_in_B(I,J)**2) + (tauy_in_B(I,J)**2)) + &
G%mask2dBu(I-1,J-1)*((taux_in_B(I-1,J-1)**2) + (tauy_in_B(I-1,J-1)**2))) + &
(G%mask2dBu(I,J-1)*((taux_in_B(I,J-1)**2) + (tauy_in_B(I,J-1)**2)) + &
G%mask2dBu(I-1,J)*((taux_in_B(I-1,J)**2) + (tauy_in_B(I-1,J)**2))) ) / &
((G%mask2dBu(I,J) + G%mask2dBu(I-1,J-1)) + (G%mask2dBu(I,J-1) + G%mask2dBu(I-1,J))) )
if (CS%read_gust_2d) gustiness = CS%gust(i,j)
endif
Expand All @@ -1117,7 +1117,7 @@ subroutine extract_IOB_stresses(IOB, index_bounds, Time, G, US, CS, taux, tauy,
enddo ; enddo
elseif (wind_stagger == AGRID) then
do j=js,je ; do i=is,ie
tau_mag = G%mask2dT(i,j) * sqrt(taux_in_A(i,j)**2 + tauy_in_A(i,j)**2)
tau_mag = G%mask2dT(i,j) * sqrt((taux_in_A(i,j)**2) + (tauy_in_A(i,j)**2))
gustiness = CS%gust_const
if (CS%read_gust_2d .and. (G%mask2dT(i,j) > 0.0)) gustiness = CS%gust(i,j)
if (do_ustar) ustar(i,j) = sqrt(gustiness*IRho0 + IRho0 * tau_mag)
Expand All @@ -1133,10 +1133,10 @@ subroutine extract_IOB_stresses(IOB, index_bounds, Time, G, US, CS, taux, tauy,
do j=js,je ; do i=is,ie
taux2 = 0.0 ; tauy2 = 0.0
if ((G%mask2dCu(I-1,j) + G%mask2dCu(I,j)) > 0.0) &
taux2 = (G%mask2dCu(I-1,j)*taux_in_C(I-1,j)**2 + G%mask2dCu(I,j)*taux_in_C(I,j)**2) / &
taux2 = (G%mask2dCu(I-1,j)*(taux_in_C(I-1,j)**2) + G%mask2dCu(I,j)*(taux_in_C(I,j)**2)) / &
(G%mask2dCu(I-1,j) + G%mask2dCu(I,j))
if ((G%mask2dCv(i,J-1) + G%mask2dCv(i,J)) > 0.0) &
tauy2 = (G%mask2dCv(i,J-1)*tauy_in_C(i,J-1)**2 + G%mask2dCv(i,J)*tauy_in_C(i,J)**2) / &
tauy2 = (G%mask2dCv(i,J-1)*(tauy_in_C(i,J-1)**2) + G%mask2dCv(i,J)*(tauy_in_C(i,J)**2)) / &
(G%mask2dCv(i,J-1) + G%mask2dCv(i,J))
tau_mag = sqrt(taux2 + tauy2)

Expand Down
20 changes: 10 additions & 10 deletions config_src/drivers/STALE_mct_cap/mom_surface_forcing_mct.F90
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,10 @@ subroutine convert_IOB_to_forces(IOB, forces, index_bounds, Time, G, US, CS)
tau_mag = 0.0 ; gustiness = CS%gust_const
if (((G%mask2dBu(I,J) + G%mask2dBu(I-1,J-1)) + &
(G%mask2dBu(I,J-1) + G%mask2dBu(I-1,J))) > 0.0) then
tau_mag = sqrt(((G%mask2dBu(I,J)*(taux_at_q(I,J)**2 + tauy_at_q(I,J)**2) + &
G%mask2dBu(I-1,J-1)*(taux_at_q(I-1,J-1)**2 + tauy_at_q(I-1,J-1)**2)) + &
(G%mask2dBu(I,J-1)*(taux_at_q(I,J-1)**2 + tauy_at_q(I,J-1)**2) + &
G%mask2dBu(I-1,J)*(taux_at_q(I-1,J)**2 + tauy_at_q(I-1,J)**2)) ) / &
tau_mag = sqrt(((G%mask2dBu(I,J)*((taux_at_q(I,J)**2) + (tauy_at_q(I,J)**2)) + &
G%mask2dBu(I-1,J-1)*((taux_at_q(I-1,J-1)**2) + (tauy_at_q(I-1,J-1)**2))) + &
(G%mask2dBu(I,J-1)*((taux_at_q(I,J-1)**2) + (tauy_at_q(I,J-1)**2)) + &
G%mask2dBu(I-1,J)*((taux_at_q(I-1,J)**2) + (tauy_at_q(I-1,J)**2))) ) / &
((G%mask2dBu(I,J) + G%mask2dBu(I-1,J-1)) + (G%mask2dBu(I,J-1) + G%mask2dBu(I-1,J))) )
if (CS%read_gust_2d) gustiness = CS%gust(i,j)
endif
Expand Down Expand Up @@ -800,9 +800,9 @@ subroutine convert_IOB_to_forces(IOB, forces, index_bounds, Time, G, US, CS)
do j=js,je ; do i=is,ie
gustiness = CS%gust_const
if (CS%read_gust_2d .and. (G%mask2dT(i,j) > 0.0)) gustiness = CS%gust(i,j)
forces%tau_mag(i,j) = gustiness + G%mask2dT(i,j) * sqrt(taux_at_h(i,j)**2 + tauy_at_h(i,j)**2)
forces%tau_mag(i,j) = gustiness + G%mask2dT(i,j) * sqrt((taux_at_h(i,j)**2) + (tauy_at_h(i,j)**2))
forces%ustar(i,j) = sqrt(gustiness*Irho0 + Irho0 * G%mask2dT(i,j) * &
sqrt(taux_at_h(i,j)**2 + tauy_at_h(i,j)**2))
sqrt((taux_at_h(i,j)**2) + (tauy_at_h(i,j)**2)))
enddo ; enddo

else ! C-grid wind stresses.
Expand All @@ -813,13 +813,13 @@ subroutine convert_IOB_to_forces(IOB, forces, index_bounds, Time, G, US, CS)
do j=js,je ; do i=is,ie
taux2 = 0.0
if ((G%mask2dCu(I-1,j) + G%mask2dCu(I,j)) > 0.0) &
taux2 = (G%mask2dCu(I-1,j)*forces%taux(I-1,j)**2 + &
G%mask2dCu(I,j)*forces%taux(I,j)**2) / (G%mask2dCu(I-1,j) + G%mask2dCu(I,j))
taux2 = (G%mask2dCu(I-1,j)*(forces%taux(I-1,j)**2) + &
G%mask2dCu(I,j)*(forces%taux(I,j)**2)) / (G%mask2dCu(I-1,j) + G%mask2dCu(I,j))

tauy2 = 0.0
if ((G%mask2dCv(i,J-1) + G%mask2dCv(i,J)) > 0.0) &
tauy2 = (G%mask2dCv(i,J-1)*forces%tauy(i,J-1)**2 + &
G%mask2dCv(i,J)*forces%tauy(i,J)**2) / (G%mask2dCv(i,J-1) + G%mask2dCv(i,J))
tauy2 = (G%mask2dCv(i,J-1)*(forces%tauy(i,J-1)**2) + &
G%mask2dCv(i,J)*(forces%tauy(i,J)**2)) / (G%mask2dCv(i,J-1) + G%mask2dCv(i,J))

if (CS%read_gust_2d) then
forces%tau_mag(i,j) = CS%gust(i,j) + sqrt(taux2 + tauy2)
Expand Down
20 changes: 10 additions & 10 deletions config_src/drivers/nuopc_cap/mom_surface_forcing_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -829,10 +829,10 @@ subroutine convert_IOB_to_forces(IOB, forces, index_bounds, Time, G, US, CS)
tau_mag = 0.0 ; gustiness = CS%gust_const
if (((G%mask2dBu(I,J) + G%mask2dBu(I-1,J-1)) + &
(G%mask2dBu(I,J-1) + G%mask2dBu(I-1,J))) > 0.0) then
tau_mag = sqrt(((G%mask2dBu(I,J)*(taux_at_q(I,J)**2 + tauy_at_q(I,J)**2) + &
G%mask2dBu(I-1,J-1)*(taux_at_q(I-1,J-1)**2 + tauy_at_q(I-1,J-1)**2)) + &
(G%mask2dBu(I,J-1)*(taux_at_q(I,J-1)**2 + tauy_at_q(I,J-1)**2) + &
G%mask2dBu(I-1,J)*(taux_at_q(I-1,J)**2 + tauy_at_q(I-1,J)**2)) ) / &
tau_mag = sqrt(((G%mask2dBu(I,J)*((taux_at_q(I,J)**2) + (tauy_at_q(I,J)**2)) + &
G%mask2dBu(I-1,J-1)*((taux_at_q(I-1,J-1)**2) + (tauy_at_q(I-1,J-1)**2))) + &
(G%mask2dBu(I,J-1)*((taux_at_q(I,J-1)**2) + (tauy_at_q(I,J-1)**2)) + &
G%mask2dBu(I-1,J)*((taux_at_q(I-1,J)**2) + (tauy_at_q(I-1,J)**2))) ) / &
((G%mask2dBu(I,J) + G%mask2dBu(I-1,J-1)) + (G%mask2dBu(I,J-1) + G%mask2dBu(I-1,J))) )
if (CS%read_gust_2d) gustiness = CS%gust(i,j)
endif
Expand Down Expand Up @@ -862,9 +862,9 @@ subroutine convert_IOB_to_forces(IOB, forces, index_bounds, Time, G, US, CS)
do j=js,je ; do i=is,ie
gustiness = CS%gust_const
if (CS%read_gust_2d .and. (G%mask2dT(i,j) > 0.0)) gustiness = CS%gust(i,j)
forces%tau_mag(i,j) = gustiness + G%mask2dT(i,j) * sqrt(taux_at_h(i,j)**2 + tauy_at_h(i,j)**2)
forces%tau_mag(i,j) = gustiness + G%mask2dT(i,j) * sqrt((taux_at_h(i,j)**2) + (tauy_at_h(i,j)**2))
forces%ustar(i,j) = sqrt(gustiness*Irho0 + Irho0 * G%mask2dT(i,j) * &
sqrt(taux_at_h(i,j)**2 + tauy_at_h(i,j)**2))
sqrt((taux_at_h(i,j)**2) + (tauy_at_h(i,j)**2)))
!forces%omega_w2x(i,j) = atan(tauy_at_h(i,j), taux_at_h(i,j))
enddo ; enddo
call pass_vector(forces%taux, forces%tauy, G%Domain, halo=1)
Expand All @@ -876,13 +876,13 @@ subroutine convert_IOB_to_forces(IOB, forces, index_bounds, Time, G, US, CS)
do j=js,je ; do i=is,ie
taux2 = 0.0
if ((G%mask2dCu(I-1,j) + G%mask2dCu(I,j)) > 0.0) &
taux2 = (G%mask2dCu(I-1,j)*forces%taux(I-1,j)**2 + &
G%mask2dCu(I,j)*forces%taux(I,j)**2) / (G%mask2dCu(I-1,j) + G%mask2dCu(I,j))
taux2 = (G%mask2dCu(I-1,j)*(forces%taux(I-1,j)**2) + &
G%mask2dCu(I,j)*(forces%taux(I,j)**2)) / (G%mask2dCu(I-1,j) + G%mask2dCu(I,j))

tauy2 = 0.0
if ((G%mask2dCv(i,J-1) + G%mask2dCv(i,J)) > 0.0) &
tauy2 = (G%mask2dCv(i,J-1)*forces%tauy(i,J-1)**2 + &
G%mask2dCv(i,J)*forces%tauy(i,J)**2) / (G%mask2dCv(i,J-1) + G%mask2dCv(i,J))
tauy2 = (G%mask2dCv(i,J-1)*(forces%tauy(i,J-1)**2) + &
G%mask2dCv(i,J)*(forces%tauy(i,J)**2)) / (G%mask2dCv(i,J-1) + G%mask2dCv(i,J))

if (CS%read_gust_2d) then
forces%tau_mag(i,j) = CS%gust(i,j) + sqrt(taux2 + tauy2)
Expand Down
Loading

0 comments on commit 4dc4c86

Please sign in to comment.