Skip to content

Commit

Permalink
Impelement code review requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
nusbaume committed Apr 18, 2024
1 parent d1de970 commit f6e6a34
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 48 deletions.
26 changes: 6 additions & 20 deletions src/data/write_init_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,9 @@ def __init__(self, message):
#################

##############################################################################
def _find_and_add_host_variable(stdname, host_dict, const_dicts, var_dict):
def _find_and_add_host_variable(stdname, host_dict, var_dict):
"""Find <stdname> in <host_dict> and add it to <var_dict> if found and
not of type, 'host'.
If <stdname> is not in <host_dict> but is in one of the <const_dicts>,
it is considered found but not added to <var_dict>.
If not found, add <stdname> to <missing_vars>.
If found and added to <var_dict>, also process the standard names of
any intrinsic sub-elements of <stdname>.
Expand All @@ -289,22 +287,13 @@ def _find_and_add_host_variable(stdname, host_dict, const_dicts, var_dict):
if isinstance(ielem, list):
for sname in ielem:
smissing = _find_and_add_host_variable(sname, host_dict,
const_dicts, var_dict)
var_dict)
missing_vars.extend(smissing)
# end for
# end if
# end if
if not hvar:
cvar = None
for cdict in const_dicts:
cvar = cdict.find_variable(stdname)
if cvar:
break
# end if
# end for
if not cvar:
missing_vars.append(stdname)
# end if
missing_vars.append(stdname)
# end if
return missing_vars

Expand All @@ -330,9 +319,6 @@ def gather_ccpp_req_vars(cap_database):
retmsg = ""
# Host model dictionary
host_dict = cap_database.host_model_dict()
# Constituent dictionaries
const_dicts = [cap_database.constituent_dictionary(s)
for s in cap_database.suite_list()]

# Create CCPP datatable required variables-listing object:
# XXgoldyXX: Choose only some phases here?
Expand All @@ -355,7 +341,7 @@ def gather_ccpp_req_vars(cap_database):
else:
# We need to work with the host model version of this variable
missing = _find_and_add_host_variable(stdname, host_dict,
const_dicts, req_vars)
req_vars)
missing_vars.update(missing)
# end if
# end if (do not include output variables)
Expand Down Expand Up @@ -1002,7 +988,7 @@ def write_phys_read_subroutine(outfile, host_dict, host_vars, host_imports,
outfile.blank_line()
outfile.comment("Check if constituent standard name in registered SIMA standard names list:", 6)
outfile.write("if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then", 6)
outfile.comment("Find array index to extract coorect input names:", 7)
outfile.comment("Find array index to extract correct input names:", 7)
outfile.write("do n=1, phys_var_num", 7)
outfile.write("if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then", 8)
outfile.write("const_input_idx = n", 9)
Expand Down Expand Up @@ -1287,7 +1273,7 @@ def write_phys_check_subroutine(outfile, host_dict, host_vars, host_imports,
outfile.blank_line()
outfile.comment("Check if constituent standard name in registered SIMA standard names list:", 5)
outfile.write("if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then", 5)
outfile.comment("Find array index to extract coorect input names:", 6)
outfile.comment("Find array index to extract correct input names:", 6)
outfile.write("do n=1, phys_var_num", 6)
outfile.write("if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then", 7)
outfile.write("const_input_idx = n", 8)
Expand Down
4 changes: 2 additions & 2 deletions test/unit/sample_files/write_init_files/physics_inputs_4D.F90
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down Expand Up @@ -303,7 +303,7 @@ subroutine physics_check_data(file_name, suite_names, timestep, min_difference,

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down Expand Up @@ -303,7 +303,7 @@ subroutine physics_check_data(file_name, suite_names, timestep, min_difference,

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down Expand Up @@ -303,7 +303,7 @@ subroutine physics_check_data(file_name, suite_names, timestep, min_difference,

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down Expand Up @@ -303,7 +303,7 @@ subroutine physics_check_data(file_name, suite_names, timestep, min_difference,

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down Expand Up @@ -303,7 +303,7 @@ subroutine physics_check_data(file_name, suite_names, timestep, min_difference,

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down Expand Up @@ -303,7 +303,7 @@ subroutine physics_check_data(file_name, suite_names, timestep, min_difference,

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down Expand Up @@ -300,7 +300,7 @@ subroutine physics_check_data(file_name, suite_names, timestep, min_difference,

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down
4 changes: 2 additions & 2 deletions test/unit/sample_files/write_init_files/physics_inputs_mf.F90
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down Expand Up @@ -305,7 +305,7 @@ subroutine physics_check_data(file_name, suite_names, timestep, min_difference,

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down Expand Up @@ -303,7 +303,7 @@ subroutine physics_check_data(file_name, suite_names, timestep, min_difference,

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down Expand Up @@ -295,7 +295,7 @@ subroutine physics_check_data(file_name, suite_names, timestep, min_difference,

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down Expand Up @@ -306,7 +306,7 @@ subroutine physics_check_data(file_name, suite_names, timestep, min_difference,

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down Expand Up @@ -303,7 +303,7 @@ subroutine physics_check_data(file_name, suite_names, timestep, min_difference,

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down Expand Up @@ -303,7 +303,7 @@ subroutine physics_check_data(file_name, suite_names, timestep, min_difference,

! Check if constituent standard name in registered SIMA standard names list:
if(any(phys_var_stdnames == ccpp_required_data(req_idx))) then
! Find array index to extract coorect input names:
! Find array index to extract correct input names:
do n=1, phys_var_num
if(trim(phys_var_stdnames(n)) == trim(ccpp_required_data(req_idx))) then
const_input_idx = n
Expand Down
Loading

0 comments on commit f6e6a34

Please sign in to comment.